35 |
|
|
36 |
extern "C" void _SHFree (void *p); |
extern "C" void _SHFree (void *p); |
37 |
|
|
38 |
/* |
|
39 |
* The the text of a menu item. |
static void |
40 |
*/ |
set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text) |
|
void |
|
|
set_menu_text (HMENU menu, int m_uid, const char *text) |
|
41 |
{ |
{ |
42 |
MENUITEMINFO mii; |
MENUITEMINFO mii; |
|
char menu_text[80]; |
|
|
|
|
|
memset (&mii, 0, sizeof (mii)); |
|
|
mii.cbSize = sizeof (mii); |
|
|
mii.fMask = MIIM_TYPE; |
|
|
mii.dwTypeData = menu_text; |
|
|
mii.cch = sizeof (menu_text); |
|
|
GetMenuItemInfo (menu, m_uid, FALSE, &mii); |
|
43 |
|
|
44 |
memset (&mii, 0, sizeof mii); |
memset (&mii, 0, sizeof mii); |
45 |
mii.cbSize = sizeof mii; |
mii.cbSize = sizeof mii; |
46 |
mii.fMask = MIIM_TYPE; |
mii.fMask = MIIM_TYPE; |
47 |
mii.fType = MFT_STRING; |
mii.fType = MFT_STRING; |
48 |
mii.dwTypeData = (char *) text; |
mii.dwTypeData = (char *) text; |
49 |
SetMenuItemInfo (menu, m_uid, FALSE, &mii); |
SetMenuItemInfo (menu, m_uid, by_pos? TRUE : FALSE, &mii); |
50 |
} /* set_menu_text */ |
} |
51 |
|
|
52 |
|
|
53 |
|
/* Set the text of a menu item @m_uid to @text. */ |
54 |
|
void |
55 |
|
set_menu_text (HMENU menu, int m_uid, const char *text) |
56 |
|
{ |
57 |
|
set_menu_text_ext (menu, 0, m_uid, text); |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
/* Set the text of a menu item with the position @pos to @text. */ |
62 |
|
void |
63 |
|
set_menu_text_bypos (HMENU menu, int pos, const char *text) |
64 |
|
{ |
65 |
|
set_menu_text_ext (menu, 1, pos, text); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
/* Set the state of a menu item @m_uid to @state. */ |
70 |
void |
void |
71 |
set_menu_state (HMENU menu, int m_uid, int state) |
set_menu_state (HMENU menu, int m_uid, int state) |
72 |
{ |
{ |
77 |
mii.fMask = MIIM_STATE; |
mii.fMask = MIIM_STATE; |
78 |
mii.fState = state; |
mii.fState = state; |
79 |
SetMenuItemInfo (menu, m_uid, FALSE, &mii); |
SetMenuItemInfo (menu, m_uid, FALSE, &mii); |
80 |
} /* set_menu_state */ |
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
/* Use the common dialog to request a file from the user. |
85 |
|
id can be either FILE_OPEN or FILE_SAVE. |
86 |
|
The return value is the file name or NULL if cancel was chosen. */ |
87 |
const char * |
const char * |
88 |
get_filename_dlg (HWND hwnd, int id, const char * title, |
get_filename_dlg (HWND hwnd, int id, const char * title, |
89 |
const char * filter, const char * name) |
const char * filter, const char * name) |
96 |
else |
else |
97 |
memset (file, 0, sizeof (file)); |
memset (file, 0, sizeof (file)); |
98 |
if (!filter) |
if (!filter) |
99 |
filter = _("All Files (*.*)\0*.*"); |
filter = _("All Files (*.*)\0*.*\0\0"); |
100 |
|
/* XXX: problem with gettext because of the 'artificial' |
101 |
|
double string termination!. */ |
102 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
103 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
104 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
107 |
open.hwndOwner = hwnd; |
open.hwndOwner = hwnd; |
108 |
open.lpstrFile = file; |
open.lpstrFile = file; |
109 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
110 |
open.Flags = 0; |
if (id == FILE_OPEN) |
111 |
|
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
112 |
|
else |
113 |
|
open.Flags = OFN_OVERWRITEPROMPT; |
114 |
|
|
115 |
if (id == 0 && GetOpenFileName (&open)) |
if (id == FILE_OPEN && GetOpenFileName (&open)) |
116 |
return open.lpstrFile; |
return open.lpstrFile; |
117 |
else if (id == 1 && GetSaveFileName (&open)) |
else if (id == FILE_SAVE && GetSaveFileName (&open)) |
118 |
return open.lpstrFile; |
return open.lpstrFile; |
119 |
|
|
120 |
return NULL; |
return NULL; |
121 |
} /* get_filename_dlg */ |
} |
122 |
|
|
123 |
|
const char* |
124 |
|
get_filesave_dlg (HWND hwnd, const char *title, |
125 |
|
const char *filter, const char *name) |
126 |
|
{ |
127 |
|
return get_filename_dlg (hwnd, FILE_SAVE, title, filter, name); |
128 |
|
} |
129 |
|
|
130 |
|
const char * |
131 |
|
get_fileopen_dlg (HWND hwnd, const char *title, const char *filter, |
132 |
|
const char *name) |
133 |
|
{ |
134 |
|
return get_filename_dlg (hwnd, FILE_OPEN, title, filter, name); |
135 |
|
} |
136 |
|
|
137 |
const char * |
|
138 |
|
/* Use the common dialog to allow the user to select a folder. |
139 |
|
The return value is either the folder path or NULL if cancel was chosen. */ |
140 |
|
const char* |
141 |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
142 |
{ |
{ |
143 |
static char folder[MAX_PATH] = ""; |
static char folder[MAX_PATH+1] = ""; |
144 |
BROWSEINFO bi; |
BROWSEINFO bi; |
145 |
ITEMIDLIST * il; |
ITEMIDLIST * il; |
146 |
|
|
162 |
} |
} |
163 |
|
|
164 |
|
|
165 |
|
/* Return the clipboard contents as a string or NULL |
166 |
|
if the clipboard does not contain text. */ |
167 |
char* |
char* |
168 |
get_clip_text (HWND hwnd) |
get_clip_text (HWND hwnd) |
169 |
{ |
{ |
195 |
leave: |
leave: |
196 |
CloseClipboard (); |
CloseClipboard (); |
197 |
return p; |
return p; |
198 |
} /* get_clip_text */ |
} |
199 |
|
|
200 |
|
|
201 |
|
/* Set @text as the new clipboard content. */ |
202 |
int |
int |
203 |
set_clip_text (HWND hwnd, const char *text, int nbytes) |
set_clip_text (HWND hwnd, const char *text, int nbytes) |
204 |
{ |
{ |
230 |
} /* set_clip_text */ |
} /* set_clip_text */ |
231 |
|
|
232 |
|
|
233 |
|
/* Append or prepend some text to the clipboard contents. |
234 |
|
If as_footer = 1, append the text otherwise prepend. */ |
235 |
int |
int |
236 |
set_clip_text2 (HWND hwnd, const char *text, int nbytes, int head_foot) |
set_clip_text2 (HWND hwnd, const char *text, int nbytes, int as_footer) |
237 |
{ |
{ |
238 |
char *p, *new_text; |
char *p, *new_text; |
239 |
|
|
243 |
new_text = new char [strlen (p)+strlen (text)+8]; |
new_text = new char [strlen (p)+strlen (text)+8]; |
244 |
if (!new_text) |
if (!new_text) |
245 |
BUG (0); |
BUG (0); |
246 |
if (head_foot == 0) |
if (as_footer == 0) |
247 |
sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p); |
sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p); |
248 |
else |
else |
249 |
sprintf (new_text, "%s\n%s\n\n", p, text); |
sprintf (new_text, "%s\n%s\n\n", p, text); |
254 |
} |
} |
255 |
|
|
256 |
|
|
257 |
|
/* Make a file name out of the path, the file and an extension. */ |
258 |
char* |
char* |
259 |
make_filename( const char *path, const char *file, const char *ext ) |
make_filename (const char *path, const char *file, const char *ext) |
260 |
{ |
{ |
261 |
char *p; |
char *p; |
262 |
size_t size = 0; |
size_t size = 0; |
287 |
/* return 0 if it exists, otherwise >0. */ |
/* return 0 if it exists, otherwise >0. */ |
288 |
int |
int |
289 |
file_exist_check (const char * fname) |
file_exist_check (const char * fname) |
290 |
{ |
{ |
291 |
HANDLE fh; |
struct stat st; |
292 |
|
if (stat (fname, &st) == -1) |
|
fh = CreateFile( fname, GENERIC_READ, FILE_SHARE_READ, |
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); |
|
|
if( fh == INVALID_HANDLE_VALUE ) |
|
293 |
return WPTERR_FILE_EXIST; |
return WPTERR_FILE_EXIST; |
|
CloseHandle( fh ); |
|
294 |
return 0; |
return 0; |
295 |
} /* file_exist_check */ |
} |
296 |
|
|
297 |
|
|
298 |
|
/* Check if the current folder exists. |
299 |
|
Return 0 for success. */ |
300 |
int |
int |
301 |
dir_exist_check( const char *dir ) |
dir_exist_check (const char *dir) |
302 |
{ |
{ |
303 |
struct stat statbuf; |
struct stat statbuf; |
304 |
|
|
307 |
if( statbuf.st_mode & _S_IFDIR ) |
if( statbuf.st_mode & _S_IFDIR ) |
308 |
return 0; |
return 0; |
309 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
310 |
} /* dir_exist_check */ |
} |
311 |
|
|
312 |
|
|
313 |
|
/* Return the file size of the given file. */ |
314 |
size_t |
size_t |
315 |
get_file_size( const char *fname ) |
get_file_size (const char *fname) |
316 |
{ |
{ |
317 |
size_t fsize; |
size_t fsize; |
318 |
HANDLE fh; |
HANDLE fh; |
360 |
} /* release_file_lock */ |
} /* release_file_lock */ |
361 |
|
|
362 |
|
|
363 |
|
/* Start a dialog with the exception that before it is checked that the |
364 |
|
dialog is not already openened. */ |
365 |
int |
int |
366 |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
367 |
LPARAM param, LPCTSTR title, int title_id ) |
LPARAM param, LPCTSTR title, int title_id ) |
380 |
} /* dialog_box_param */ |
} /* dialog_box_param */ |
381 |
|
|
382 |
|
|
383 |
|
/* Wrapper for message box which forces the message box into the |
384 |
|
foreground and it is displayed always on top. */ |
385 |
int |
int |
386 |
msg_box( HWND hwnd, const char *text, const char *title, int mode ) |
msg_box (HWND hwnd, const char *text, const char *title, int mode) |
387 |
{ |
{ |
388 |
mode |= MB_SETFOREGROUND; |
mode |= MB_SETFOREGROUND; |
389 |
mode |= MB_TASKMODAL; |
mode |= MB_TASKMODAL; |
390 |
mode |= MB_TOPMOST; |
mode |= MB_TOPMOST; |
391 |
return MessageBox(hwnd, text, title, mode); |
return MessageBox(hwnd, text, title, mode); |
392 |
} /* msg_box */ |
} |
393 |
|
|
394 |
|
|
395 |
void |
void |
396 |
set_active_window( HWND dlg ) |
set_active_window( HWND dlg) |
397 |
{ |
{ |
398 |
activ_hwnd = dlg; |
activ_hwnd = dlg; |
399 |
} /* set_active_window */ |
} /* set_active_window */ |
406 |
|
|
407 |
|
|
408 |
static DWORD CALLBACK |
static DWORD CALLBACK |
409 |
reminder_thread( void *ctx ) |
reminder_thread (void *ctx) |
410 |
{ |
{ |
411 |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
412 |
|
|
416 |
return 0; |
return 0; |
417 |
} /* reminder_thread */ |
} /* reminder_thread */ |
418 |
|
|
419 |
|
|
420 |
HANDLE |
HANDLE |
421 |
window_reminder( struct reminder_ctx_s *ctx ) |
window_reminder( struct reminder_ctx_s *ctx ) |
422 |
{ |
{ |
426 |
} /* window_reminder */ |
} /* window_reminder */ |
427 |
|
|
428 |
|
|
429 |
char * |
char* |
430 |
m_strdup (const char *str) |
m_strdup (const char *str) |
431 |
{ |
{ |
432 |
char * p = new char[strlen (str) + 1]; |
char * p = new char[strlen (str) + 1]; |
436 |
} /* m_strdup */ |
} /* m_strdup */ |
437 |
|
|
438 |
|
|
439 |
|
/* Center the hwndChild relative to parent. |
440 |
|
The style param allows to specificy additional styles (like topmost). */ |
441 |
void |
void |
442 |
center_window2 (HWND hwndChild, HWND style) |
center_window2 (HWND hwndChild, HWND parent, HWND style) |
443 |
{ |
{ |
444 |
HWND hwndParent; |
HWND hwndParent; |
445 |
RECT rChild, rParent; |
RECT rChild, rParent; |
448 |
int wScreen, hScreen, xNew, yNew; |
int wScreen, hScreen, xNew, yNew; |
449 |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
450 |
|
|
451 |
hwndParent = GetDesktopWindow (); |
hwndParent = parent; |
452 |
|
if (hwndParent == NULL) |
453 |
|
hwndParent = GetDesktopWindow (); |
454 |
GetWindowRect (hwndChild, &rChild); |
GetWindowRect (hwndChild, &rChild); |
455 |
wChild = rChild.right - rChild.left; |
wChild = rChild.right - rChild.left; |
456 |
hChild = rChild.bottom - rChild.top; |
hChild = rChild.bottom - rChild.top; |
479 |
} |
} |
480 |
|
|
481 |
|
|
482 |
|
/* Center the given hwndChild window with no special style. */ |
483 |
void |
void |
484 |
center_window (HWND hwndChild) |
center_window (HWND hwndChild, HWND hwndParent) |
485 |
{ |
{ |
486 |
center_window2 (hwndChild, NULL); |
center_window2 (hwndChild, hwndParent, NULL); |
487 |
} |
} |