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 |
{ |
{ |
71 |
} /* set_menu_state */ |
} /* set_menu_state */ |
72 |
|
|
73 |
|
|
74 |
|
/* Use the common dialog to request a file from the user. |
75 |
|
id can be either FILE_OPEN or FILE_SAVE. |
76 |
|
The return value is the file name or NULL if cancel was chosen. */ |
77 |
const char * |
const char * |
78 |
get_filename_dlg (HWND hwnd, int id, const char * title, |
get_filename_dlg (HWND hwnd, int id, const char * title, |
79 |
const char * filter, const char * name) |
const char * filter, const char * name) |
86 |
else |
else |
87 |
memset (file, 0, sizeof (file)); |
memset (file, 0, sizeof (file)); |
88 |
if (!filter) |
if (!filter) |
89 |
filter = _("All Files (*.*)\0*.*"); |
filter = _("All Files (*.*)\0*.*\0\0"); |
90 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
91 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
92 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
95 |
open.hwndOwner = hwnd; |
open.hwndOwner = hwnd; |
96 |
open.lpstrFile = file; |
open.lpstrFile = file; |
97 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
98 |
open.Flags = 0; |
if (id == FILE_OPEN) |
99 |
|
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
100 |
|
else |
101 |
|
open.Flags = OFN_OVERWRITEPROMPT; |
102 |
|
|
103 |
if (id == 0 && GetOpenFileName (&open)) |
if (id == FILE_OPEN && GetOpenFileName (&open)) |
104 |
return open.lpstrFile; |
return open.lpstrFile; |
105 |
else if (id == 1 && GetSaveFileName (&open)) |
else if (id == FILE_SAVE && GetSaveFileName (&open)) |
106 |
return open.lpstrFile; |
return open.lpstrFile; |
107 |
|
|
108 |
return NULL; |
return NULL; |
109 |
} /* get_filename_dlg */ |
} |
|
|
|
110 |
|
|
111 |
const char * |
/* Use the common dialog to allow the user to select a folder. |
112 |
|
The return value is either the folder path or NULL if cancel was chosen. */ |
113 |
|
const char* |
114 |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
115 |
{ |
{ |
116 |
static char folder[MAX_PATH] = ""; |
static char folder[MAX_PATH+1] = ""; |
117 |
BROWSEINFO bi; |
BROWSEINFO bi; |
118 |
ITEMIDLIST * il; |
ITEMIDLIST * il; |
119 |
|
|
135 |
} |
} |
136 |
|
|
137 |
|
|
138 |
|
/* Return the clipboard contents as a string or NULL |
139 |
|
if the clipboard does not contain text. */ |
140 |
char* |
char* |
141 |
get_clip_text (HWND hwnd) |
get_clip_text (HWND hwnd) |
142 |
{ |
{ |
168 |
leave: |
leave: |
169 |
CloseClipboard (); |
CloseClipboard (); |
170 |
return p; |
return p; |
171 |
} /* get_clip_text */ |
} |
172 |
|
|
173 |
|
|
174 |
|
/* Set the the given text to the clipboard. */ |
175 |
int |
int |
176 |
set_clip_text (HWND hwnd, const char *text, int nbytes) |
set_clip_text (HWND hwnd, const char *text, int nbytes) |
177 |
{ |
{ |
203 |
} /* set_clip_text */ |
} /* set_clip_text */ |
204 |
|
|
205 |
|
|
206 |
|
/* Append or prepend some text to the clipboard contents. |
207 |
|
If as_footer = 1, append the text otherwise prepend. */ |
208 |
int |
int |
209 |
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) |
210 |
{ |
{ |
211 |
char *p, *new_text; |
char *p, *new_text; |
212 |
|
|
216 |
new_text = new char [strlen (p)+strlen (text)+8]; |
new_text = new char [strlen (p)+strlen (text)+8]; |
217 |
if (!new_text) |
if (!new_text) |
218 |
BUG (0); |
BUG (0); |
219 |
if (head_foot == 0) |
if (as_footer == 0) |
220 |
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); |
221 |
else |
else |
222 |
sprintf (new_text, "%s\n%s\n\n", p, text); |
sprintf (new_text, "%s\n%s\n\n", p, text); |
227 |
} |
} |
228 |
|
|
229 |
|
|
230 |
|
/* Make a file name out of the path, the file and an extension. */ |
231 |
char* |
char* |
232 |
make_filename( const char *path, const char *file, const char *ext ) |
make_filename (const char *path, const char *file, const char *ext) |
233 |
{ |
{ |
234 |
char *p; |
char *p; |
235 |
size_t size = 0; |
size_t size = 0; |
269 |
return WPTERR_FILE_EXIST; |
return WPTERR_FILE_EXIST; |
270 |
CloseHandle( fh ); |
CloseHandle( fh ); |
271 |
return 0; |
return 0; |
272 |
} /* file_exist_check */ |
} |
273 |
|
|
274 |
|
|
275 |
|
/* Check if the current folder exists. |
276 |
|
Return 0 for success. */ |
277 |
int |
int |
278 |
dir_exist_check( const char *dir ) |
dir_exist_check (const char *dir) |
279 |
{ |
{ |
280 |
struct stat statbuf; |
struct stat statbuf; |
281 |
|
|
284 |
if( statbuf.st_mode & _S_IFDIR ) |
if( statbuf.st_mode & _S_IFDIR ) |
285 |
return 0; |
return 0; |
286 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
287 |
} /* dir_exist_check */ |
} |
288 |
|
|
289 |
|
|
290 |
|
/* Return the file size of the given file. */ |
291 |
size_t |
size_t |
292 |
get_file_size( const char *fname ) |
get_file_size (const char *fname) |
293 |
{ |
{ |
294 |
size_t fsize; |
size_t fsize; |
295 |
HANDLE fh; |
HANDLE fh; |
337 |
} /* release_file_lock */ |
} /* release_file_lock */ |
338 |
|
|
339 |
|
|
340 |
|
/* Start a dialog with the exception that before it is checked that the |
341 |
|
dialog is not already openened. */ |
342 |
int |
int |
343 |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
344 |
LPARAM param, LPCTSTR title, int title_id ) |
LPARAM param, LPCTSTR title, int title_id ) |
357 |
} /* dialog_box_param */ |
} /* dialog_box_param */ |
358 |
|
|
359 |
|
|
360 |
|
/* Wrapper for message box which forces the message box into the |
361 |
|
foreground and it is displayed always on top. */ |
362 |
int |
int |
363 |
msg_box( HWND hwnd, const char *text, const char *title, int mode ) |
msg_box (HWND hwnd, const char *text, const char *title, int mode) |
364 |
{ |
{ |
365 |
mode |= MB_SETFOREGROUND; |
mode |= MB_SETFOREGROUND; |
366 |
mode |= MB_TASKMODAL; |
mode |= MB_TASKMODAL; |
367 |
mode |= MB_TOPMOST; |
mode |= MB_TOPMOST; |
368 |
return MessageBox(hwnd, text, title, mode); |
return MessageBox(hwnd, text, title, mode); |
369 |
} /* msg_box */ |
} |
370 |
|
|
371 |
|
|
372 |
void |
void |
373 |
set_active_window( HWND dlg ) |
set_active_window( HWND dlg) |
374 |
{ |
{ |
375 |
activ_hwnd = dlg; |
activ_hwnd = dlg; |
376 |
} /* set_active_window */ |
} /* set_active_window */ |
383 |
|
|
384 |
|
|
385 |
static DWORD CALLBACK |
static DWORD CALLBACK |
386 |
reminder_thread( void *ctx ) |
reminder_thread (void *ctx) |
387 |
{ |
{ |
388 |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
389 |
|
|
393 |
return 0; |
return 0; |
394 |
} /* reminder_thread */ |
} /* reminder_thread */ |
395 |
|
|
396 |
|
|
397 |
HANDLE |
HANDLE |
398 |
window_reminder( struct reminder_ctx_s *ctx ) |
window_reminder( struct reminder_ctx_s *ctx ) |
399 |
{ |
{ |
403 |
} /* window_reminder */ |
} /* window_reminder */ |
404 |
|
|
405 |
|
|
406 |
char * |
char* |
407 |
m_strdup (const char *str) |
m_strdup (const char *str) |
408 |
{ |
{ |
409 |
char * p = new char[strlen (str) + 1]; |
char * p = new char[strlen (str) + 1]; |
413 |
} /* m_strdup */ |
} /* m_strdup */ |
414 |
|
|
415 |
|
|
416 |
|
/* Center the hwndChild relative to parent. |
417 |
|
The style param allows to specificy additional styles (like topmost). */ |
418 |
void |
void |
419 |
center_window2 (HWND hwndChild, HWND style) |
center_window2 (HWND hwndChild, HWND parent, HWND style) |
420 |
{ |
{ |
421 |
HWND hwndParent; |
HWND hwndParent; |
422 |
RECT rChild, rParent; |
RECT rChild, rParent; |
425 |
int wScreen, hScreen, xNew, yNew; |
int wScreen, hScreen, xNew, yNew; |
426 |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
427 |
|
|
428 |
hwndParent = GetDesktopWindow (); |
hwndParent = parent; |
429 |
|
if (hwndParent == NULL) |
430 |
|
hwndParent = GetDesktopWindow (); |
431 |
GetWindowRect (hwndChild, &rChild); |
GetWindowRect (hwndChild, &rChild); |
432 |
wChild = rChild.right - rChild.left; |
wChild = rChild.right - rChild.left; |
433 |
hChild = rChild.bottom - rChild.top; |
hChild = rChild.bottom - rChild.top; |
456 |
} |
} |
457 |
|
|
458 |
|
|
459 |
|
/* Center the given hwndChild window with no special style. */ |
460 |
void |
void |
461 |
center_window (HWND hwndChild) |
center_window (HWND hwndChild, HWND hwndParent) |
462 |
{ |
{ |
463 |
center_window2 (hwndChild, NULL); |
center_window2 (hwndChild, hwndParent, NULL); |
464 |
} |
} |