35 |
|
|
36 |
extern "C" void _SHFree (void *p); |
extern "C" void _SHFree (void *p); |
37 |
|
|
38 |
/* |
/* The the text of a menu item. */ |
|
* The the text of a menu item. |
|
|
*/ |
|
39 |
void |
void |
40 |
set_menu_text (HMENU menu, int m_uid, const char *text) |
set_menu_text (HMENU menu, int m_uid, const char *text) |
41 |
{ |
{ |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
/* Use the common dialog to request a file from the user. |
76 |
|
id can be either FILE_OPEN or FILE_SAVE. |
77 |
|
The return value is the file name or NULL if cancel was chosen. */ |
78 |
const char * |
const char * |
79 |
get_filename_dlg (HWND hwnd, int id, const char * title, |
get_filename_dlg (HWND hwnd, int id, const char * title, |
80 |
const char * filter, const char * name) |
const char * filter, const char * name) |
87 |
else |
else |
88 |
memset (file, 0, sizeof (file)); |
memset (file, 0, sizeof (file)); |
89 |
if (!filter) |
if (!filter) |
90 |
filter = _("All Files (*.*)\0*.*"); |
filter = _("All Files (*.*)\0*.*\0\0"); |
91 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
92 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
93 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
96 |
open.hwndOwner = hwnd; |
open.hwndOwner = hwnd; |
97 |
open.lpstrFile = file; |
open.lpstrFile = file; |
98 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
99 |
open.Flags = 0; |
if (id == FILE_OPEN) |
100 |
|
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
101 |
|
else |
102 |
|
open.Flags = OFN_OVERWRITEPROMPT; |
103 |
|
|
104 |
if (id == 0 && GetOpenFileName (&open)) |
if (id == FILE_OPEN && GetOpenFileName (&open)) |
105 |
return open.lpstrFile; |
return open.lpstrFile; |
106 |
else if (id == 1 && GetSaveFileName (&open)) |
else if (id == FILE_SAVE && GetSaveFileName (&open)) |
107 |
return open.lpstrFile; |
return open.lpstrFile; |
108 |
|
|
109 |
return NULL; |
return NULL; |
110 |
} /* get_filename_dlg */ |
} |
111 |
|
|
112 |
|
const char* |
113 |
|
get_filesave_dlg (HWND hwnd, const char *title, |
114 |
|
const char *filter, const char *name) |
115 |
|
{ |
116 |
|
return get_filename_dlg (hwnd, FILE_SAVE, title, filter, name); |
117 |
|
} |
118 |
|
|
119 |
|
const char * |
120 |
|
get_fileopen_dlg (HWND hwnd, const char *title, const char *filter, |
121 |
|
const char *name) |
122 |
|
{ |
123 |
|
return get_filename_dlg (hwnd, FILE_OPEN, title, filter, name); |
124 |
|
} |
125 |
|
|
126 |
const char * |
|
127 |
|
/* Use the common dialog to allow the user to select a folder. |
128 |
|
The return value is either the folder path or NULL if cancel was chosen. */ |
129 |
|
const char* |
130 |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
131 |
{ |
{ |
132 |
static char folder[MAX_PATH] = ""; |
static char folder[MAX_PATH+1] = ""; |
133 |
BROWSEINFO bi; |
BROWSEINFO bi; |
134 |
ITEMIDLIST * il; |
ITEMIDLIST * il; |
135 |
|
|
151 |
} |
} |
152 |
|
|
153 |
|
|
154 |
|
/* Return the clipboard contents as a string or NULL |
155 |
|
if the clipboard does not contain text. */ |
156 |
char* |
char* |
157 |
get_clip_text (HWND hwnd) |
get_clip_text (HWND hwnd) |
158 |
{ |
{ |
184 |
leave: |
leave: |
185 |
CloseClipboard (); |
CloseClipboard (); |
186 |
return p; |
return p; |
187 |
} /* get_clip_text */ |
} |
188 |
|
|
189 |
|
|
190 |
|
/* Set the the given text to the clipboard. */ |
191 |
int |
int |
192 |
set_clip_text (HWND hwnd, const char *text, int nbytes) |
set_clip_text (HWND hwnd, const char *text, int nbytes) |
193 |
{ |
{ |
219 |
} /* set_clip_text */ |
} /* set_clip_text */ |
220 |
|
|
221 |
|
|
222 |
|
/* Append or prepend some text to the clipboard contents. |
223 |
|
If as_footer = 1, append the text otherwise prepend. */ |
224 |
int |
int |
225 |
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) |
226 |
{ |
{ |
227 |
char *p, *new_text; |
char *p, *new_text; |
228 |
|
|
232 |
new_text = new char [strlen (p)+strlen (text)+8]; |
new_text = new char [strlen (p)+strlen (text)+8]; |
233 |
if (!new_text) |
if (!new_text) |
234 |
BUG (0); |
BUG (0); |
235 |
if (head_foot == 0) |
if (as_footer == 0) |
236 |
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); |
237 |
else |
else |
238 |
sprintf (new_text, "%s\n%s\n\n", p, text); |
sprintf (new_text, "%s\n%s\n\n", p, text); |
243 |
} |
} |
244 |
|
|
245 |
|
|
246 |
|
/* Make a file name out of the path, the file and an extension. */ |
247 |
char* |
char* |
248 |
make_filename( const char *path, const char *file, const char *ext ) |
make_filename (const char *path, const char *file, const char *ext) |
249 |
{ |
{ |
250 |
char *p; |
char *p; |
251 |
size_t size = 0; |
size_t size = 0; |
276 |
/* return 0 if it exists, otherwise >0. */ |
/* return 0 if it exists, otherwise >0. */ |
277 |
int |
int |
278 |
file_exist_check (const char * fname) |
file_exist_check (const char * fname) |
279 |
{ |
{ |
280 |
HANDLE fh; |
struct stat st; |
281 |
|
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 ) |
|
282 |
return WPTERR_FILE_EXIST; |
return WPTERR_FILE_EXIST; |
|
CloseHandle( fh ); |
|
283 |
return 0; |
return 0; |
284 |
} /* file_exist_check */ |
} |
285 |
|
|
286 |
|
|
287 |
|
/* Check if the current folder exists. |
288 |
|
Return 0 for success. */ |
289 |
int |
int |
290 |
dir_exist_check( const char *dir ) |
dir_exist_check (const char *dir) |
291 |
{ |
{ |
292 |
struct stat statbuf; |
struct stat statbuf; |
293 |
|
|
296 |
if( statbuf.st_mode & _S_IFDIR ) |
if( statbuf.st_mode & _S_IFDIR ) |
297 |
return 0; |
return 0; |
298 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
299 |
} /* dir_exist_check */ |
} |
300 |
|
|
301 |
|
|
302 |
|
/* Return the file size of the given file. */ |
303 |
size_t |
size_t |
304 |
get_file_size( const char *fname ) |
get_file_size (const char *fname) |
305 |
{ |
{ |
306 |
size_t fsize; |
size_t fsize; |
307 |
HANDLE fh; |
HANDLE fh; |
349 |
} /* release_file_lock */ |
} /* release_file_lock */ |
350 |
|
|
351 |
|
|
352 |
|
/* Start a dialog with the exception that before it is checked that the |
353 |
|
dialog is not already openened. */ |
354 |
int |
int |
355 |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
356 |
LPARAM param, LPCTSTR title, int title_id ) |
LPARAM param, LPCTSTR title, int title_id ) |
369 |
} /* dialog_box_param */ |
} /* dialog_box_param */ |
370 |
|
|
371 |
|
|
372 |
|
/* Wrapper for message box which forces the message box into the |
373 |
|
foreground and it is displayed always on top. */ |
374 |
int |
int |
375 |
msg_box( HWND hwnd, const char *text, const char *title, int mode ) |
msg_box (HWND hwnd, const char *text, const char *title, int mode) |
376 |
{ |
{ |
377 |
mode |= MB_SETFOREGROUND; |
mode |= MB_SETFOREGROUND; |
378 |
mode |= MB_TASKMODAL; |
mode |= MB_TASKMODAL; |
379 |
mode |= MB_TOPMOST; |
mode |= MB_TOPMOST; |
380 |
return MessageBox(hwnd, text, title, mode); |
return MessageBox(hwnd, text, title, mode); |
381 |
} /* msg_box */ |
} |
382 |
|
|
383 |
|
|
384 |
void |
void |
385 |
set_active_window( HWND dlg ) |
set_active_window( HWND dlg) |
386 |
{ |
{ |
387 |
activ_hwnd = dlg; |
activ_hwnd = dlg; |
388 |
} /* set_active_window */ |
} /* set_active_window */ |
395 |
|
|
396 |
|
|
397 |
static DWORD CALLBACK |
static DWORD CALLBACK |
398 |
reminder_thread( void *ctx ) |
reminder_thread (void *ctx) |
399 |
{ |
{ |
400 |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
401 |
|
|
405 |
return 0; |
return 0; |
406 |
} /* reminder_thread */ |
} /* reminder_thread */ |
407 |
|
|
408 |
|
|
409 |
HANDLE |
HANDLE |
410 |
window_reminder( struct reminder_ctx_s *ctx ) |
window_reminder( struct reminder_ctx_s *ctx ) |
411 |
{ |
{ |
415 |
} /* window_reminder */ |
} /* window_reminder */ |
416 |
|
|
417 |
|
|
418 |
char * |
char* |
419 |
m_strdup (const char *str) |
m_strdup (const char *str) |
420 |
{ |
{ |
421 |
char * p = new char[strlen (str) + 1]; |
char * p = new char[strlen (str) + 1]; |
425 |
} /* m_strdup */ |
} /* m_strdup */ |
426 |
|
|
427 |
|
|
428 |
|
/* Center the hwndChild relative to parent. |
429 |
|
The style param allows to specificy additional styles (like topmost). */ |
430 |
void |
void |
431 |
center_window2 (HWND hwndChild, HWND style) |
center_window2 (HWND hwndChild, HWND parent, HWND style) |
432 |
{ |
{ |
433 |
HWND hwndParent; |
HWND hwndParent; |
434 |
RECT rChild, rParent; |
RECT rChild, rParent; |
437 |
int wScreen, hScreen, xNew, yNew; |
int wScreen, hScreen, xNew, yNew; |
438 |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
439 |
|
|
440 |
hwndParent = GetDesktopWindow (); |
hwndParent = parent; |
441 |
|
if (hwndParent == NULL) |
442 |
|
hwndParent = GetDesktopWindow (); |
443 |
GetWindowRect (hwndChild, &rChild); |
GetWindowRect (hwndChild, &rChild); |
444 |
wChild = rChild.right - rChild.left; |
wChild = rChild.right - rChild.left; |
445 |
hChild = rChild.bottom - rChild.top; |
hChild = rChild.bottom - rChild.top; |
468 |
} |
} |
469 |
|
|
470 |
|
|
471 |
|
/* Center the given hwndChild window with no special style. */ |
472 |
void |
void |
473 |
center_window (HWND hwndChild) |
center_window (HWND hwndChild, HWND hwndParent) |
474 |
{ |
{ |
475 |
center_window2 (hwndChild, NULL); |
center_window2 (hwndChild, hwndParent, NULL); |
476 |
} |
} |