29 |
#include <shellapi.h> |
#include <shellapi.h> |
30 |
#include <shlobj.h> |
#include <shlobj.h> |
31 |
#include <commctrl.h> |
#include <commctrl.h> |
32 |
|
#include <time.h> |
33 |
|
|
34 |
#include "wptNLS.h" |
#include "wptNLS.h" |
35 |
#include "wptW32API.h" |
#include "wptW32API.h" |
57 |
|
|
58 |
/* Set the text of a menu item @m_uid to @text. */ |
/* Set the text of a menu item @m_uid to @text. */ |
59 |
void |
void |
60 |
set_menu_text (HMENU menu, int m_uid, const char *text) |
set_menu_text (HMENU menu, UINT m_uid, const char *text) |
61 |
{ |
{ |
62 |
set_menu_text_ext (menu, 0, m_uid, text); |
set_menu_text_ext (menu, 0, m_uid, text); |
63 |
} |
} |
65 |
|
|
66 |
/* Set the text of a menu item with the position @pos to @text. */ |
/* Set the text of a menu item with the position @pos to @text. */ |
67 |
void |
void |
68 |
set_menu_text_bypos (HMENU menu, int pos, const char *text) |
set_menu_text_bypos (HMENU menu, UINT pos, const char *text) |
69 |
{ |
{ |
70 |
set_menu_text_ext (menu, 1, pos, text); |
set_menu_text_ext (menu, 1, pos, text); |
71 |
} |
} |
73 |
|
|
74 |
/* Set the state of a menu item @m_uid to @state. */ |
/* Set the state of a menu item @m_uid to @state. */ |
75 |
void |
void |
76 |
set_menu_state (HMENU menu, int m_uid, int state) |
set_menu_state (HMENU menu, UINT m_uid, UINT state) |
77 |
{ |
{ |
78 |
MENUITEMINFO mii; |
MENUITEMINFO mii; |
79 |
|
|
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
|
/* Retrieve the state of the menu item @m_uid and return it. */ |
89 |
|
UINT |
90 |
|
get_menu_state (HMENU menu, UINT m_uid) |
91 |
|
{ |
92 |
|
MENUITEMINFO mii; |
93 |
|
|
94 |
|
memset (&mii, 0, sizeof (mii)); |
95 |
|
mii.cbSize = sizeof (mii); |
96 |
|
mii.fMask = MIIM_STATE; |
97 |
|
GetMenuItemInfo (menu, m_uid, FALSE, &mii); |
98 |
|
return mii.fState; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
enum { |
enum { |
103 |
CDLG_FILE_OPEN = 0, |
CDLG_FILE_OPEN = 0, |
104 |
CDLG_FILE_SAVE = 1 |
CDLG_FILE_SAVE = 1 |
119 |
else |
else |
120 |
memset (file, 0, sizeof (file)); |
memset (file, 0, sizeof (file)); |
121 |
if (!filter) |
if (!filter) |
122 |
filter = _("All Files (*.*)\0*.*\0\0"); |
filter = "All Files (*.*)\0*.*\0\0"; |
123 |
/* XXX: problem with gettext because of the 'artificial' |
/* XXX: problem with gettext because of the 'artificial' |
124 |
double string termination!. */ |
double string termination!. */ |
125 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
309 |
} |
} |
310 |
|
|
311 |
|
|
312 |
|
/* Generate a file name from a special dirctory. */ |
313 |
|
char* |
314 |
|
make_special_filename (int folder, const char *file, const char *ext) |
315 |
|
{ |
316 |
|
BOOL ec; |
317 |
|
char path[MAX_PATH], *p; |
318 |
|
size_t n=0; |
319 |
|
|
320 |
|
/* MSDN: buf must be at least MAX_PATH=256 bytes */ |
321 |
|
ec = SHGetSpecialFolderPath (HWND_DESKTOP, path, folder, TRUE); |
322 |
|
if (ec != 1) { |
323 |
|
log_debug ("SHGetSpecialFolderPath() failed\r\n", (int)GetLastError ()); |
324 |
|
return NULL; |
325 |
|
} |
326 |
|
|
327 |
|
n = strlen (path)+1; |
328 |
|
if (file) |
329 |
|
n += strlen (file)+1; |
330 |
|
if (ext) |
331 |
|
n += strlen (ext)+1; |
332 |
|
p = new char[n+2]; |
333 |
|
if (!p) |
334 |
|
BUG (0); |
335 |
|
memset (p, 0, n+2); |
336 |
|
strcpy (p, path); |
337 |
|
if (file) { |
338 |
|
strcat (p, "\\"); |
339 |
|
strcat (p, file); |
340 |
|
} |
341 |
|
if (ext) |
342 |
|
strcat (p, ext); |
343 |
|
return p; |
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
/* return 0 if the file @fname exists, otherwise >0. */ |
/* return 0 if the file @fname exists, otherwise >0. */ |
348 |
int |
int |
349 |
file_exist_check (const char *fname) |
file_exist_check (const char *fname) |
389 |
} |
} |
390 |
|
|
391 |
|
|
|
int |
|
|
init_file_lock( LOCK *ctx, const char *file ) |
|
|
{ |
|
|
|
|
|
ctx->size = get_file_size( file ); |
|
|
ctx->file = m_strdup( file ); |
|
|
ctx->fh = CreateFile( file, GENERIC_READ, FILE_SHARE_READ, NULL, |
|
|
OPEN_ALWAYS, 0, NULL ); |
|
|
if( ctx->fh == INVALID_HANDLE_VALUE ) |
|
|
return WPTERR_GENERAL; |
|
|
if( LockFile( ctx->fh, 0, 0, ctx->size, 0 ) == FALSE ) { |
|
|
CloseHandle( ctx->fh ); |
|
|
ctx->fh = INVALID_HANDLE_VALUE; |
|
|
ctx->size = 0; |
|
|
free( ctx->file ); |
|
|
return WPTERR_GENERAL; |
|
|
} |
|
|
return 0; |
|
|
} /* init_file_lock */ |
|
|
|
|
|
|
|
|
void |
|
|
release_file_lock( LOCK *ctx ) |
|
|
{ |
|
|
free_if_alloc( ctx->file ); |
|
|
ctx->file = NULL; |
|
|
ctx->size = 0; |
|
|
CloseHandle( ctx->fh ); |
|
|
} /* release_file_lock */ |
|
|
|
|
|
|
|
392 |
/* Start a dialog with the exception that before it is checked that the |
/* Start a dialog with the exception that before it is checked that the |
393 |
dialog is not already openened. */ |
dialog is not already openened. */ |
394 |
int |
int |
521 |
} |
} |
522 |
|
|
523 |
|
|
524 |
void |
/* Return date in a format which complies with the |
525 |
set_active_window( HWND dlg) |
system locale settings. */ |
526 |
{ |
const char* |
527 |
activ_hwnd = dlg; |
get_locale_date (long tm_t, char *buf, DWORD buflen) |
528 |
} /* set_active_window */ |
{ |
529 |
|
SYSTEMTIME st; |
530 |
void |
struct tm *ptm; |
531 |
reset_active_window( void ) |
|
532 |
{ |
ptm = localtime (&tm_t); |
533 |
activ_hwnd = NULL; |
st.wYear = (WORD)ptm->tm_year; |
534 |
} /* reset_active_window */ |
st.wMonth = (WORD)ptm->tm_mon; |
535 |
|
st.wDay = (WORD)ptm->tm_mday; |
536 |
|
st.wYear += 1900; |
537 |
|
st.wMonth += 1; |
538 |
|
if (!GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, |
539 |
|
NULL, buf, buflen)) |
540 |
|
return NULL; |
541 |
|
return buf; |
542 |
|
} |
543 |
|
|
544 |
|
|
545 |
static DWORD CALLBACK |
struct reminder_hd_s { |
546 |
reminder_thread (void *ctx) |
int msecs; |
547 |
{ |
HWND dlg; |
548 |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
HANDLE hd; |
549 |
|
}; |
550 |
|
|
|
Sleep( c->msecs ); |
|
|
SetForegroundWindow( activ_hwnd ); |
|
551 |
|
|
552 |
|
static DWORD CALLBACK |
553 |
|
foreground_reminder_thread (void *c) |
554 |
|
{ |
555 |
|
struct reminder_hd_s *ctx = (struct reminder_hd_s *)c; |
556 |
|
Sleep (ctx->msecs); |
557 |
|
SetForegroundWindow (ctx->dlg); |
558 |
|
CloseHandle (ctx->hd); |
559 |
|
delete ctx; |
560 |
|
ExitThread (0); |
561 |
return 0; |
return 0; |
562 |
} /* reminder_thread */ |
} |
|
|
|
563 |
|
|
564 |
HANDLE |
/* Try to force the window @dlg to the foreground. |
565 |
window_reminder( struct reminder_ctx_s *ctx ) |
On NT5 or later this will not work if the user |
566 |
|
is working in another window (console for example). */ |
567 |
|
void |
568 |
|
force_foreground_window (HWND dlg, int msecs) |
569 |
{ |
{ |
570 |
DWORD tid = 0; |
struct reminder_hd_s *hd; |
571 |
|
DWORD tid; |
572 |
return CreateThread( NULL, 0, reminder_thread, ctx, 0, &tid ); |
|
573 |
} /* window_reminder */ |
hd = new reminder_hd_s; |
574 |
|
hd->dlg = dlg; |
575 |
|
hd->msecs = msecs; |
576 |
|
hd->hd = CreateThread (NULL, 0, foreground_reminder_thread, |
577 |
|
hd, NULL, &tid); |
578 |
|
} |