33 |
#include "wptTypes.h" |
#include "wptTypes.h" |
34 |
|
|
35 |
|
|
36 |
/* |
extern "C" void _SHFree (void *p); |
37 |
* The the text of a menu item. |
|
38 |
*/ |
/* 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 |
|
|
128 |
il = SHBrowseForFolder (&bi); |
il = SHBrowseForFolder (&bi); |
129 |
if (il) { |
if (il) { |
130 |
SHGetPathFromIDList (il, folder); |
SHGetPathFromIDList (il, folder); |
131 |
|
_SHFree (il); |
132 |
return folder; |
return folder; |
133 |
} |
} |
134 |
return NULL; |
return NULL; |
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; |
260 |
/* return 0 if it exists, otherwise >0. */ |
/* return 0 if it exists, otherwise >0. */ |
261 |
int |
int |
262 |
file_exist_check (const char * fname) |
file_exist_check (const char * fname) |
263 |
{ |
{ |
264 |
HANDLE fh; |
struct stat st; |
265 |
|
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 ) |
|
266 |
return WPTERR_FILE_EXIST; |
return WPTERR_FILE_EXIST; |
|
CloseHandle( fh ); |
|
267 |
return 0; |
return 0; |
268 |
} /* file_exist_check */ |
} |
269 |
|
|
270 |
|
|
271 |
|
/* Check if the current folder exists. |
272 |
|
Return 0 for success. */ |
273 |
int |
int |
274 |
dir_exist_check( const char *dir ) |
dir_exist_check (const char *dir) |
275 |
{ |
{ |
276 |
struct stat statbuf; |
struct stat statbuf; |
277 |
|
|
280 |
if( statbuf.st_mode & _S_IFDIR ) |
if( statbuf.st_mode & _S_IFDIR ) |
281 |
return 0; |
return 0; |
282 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
283 |
} /* dir_exist_check */ |
} |
284 |
|
|
285 |
|
|
286 |
|
/* Return the file size of the given file. */ |
287 |
size_t |
size_t |
288 |
get_file_size( const char *fname ) |
get_file_size (const char *fname) |
289 |
{ |
{ |
290 |
size_t fsize; |
size_t fsize; |
291 |
HANDLE fh; |
HANDLE fh; |
333 |
} /* release_file_lock */ |
} /* release_file_lock */ |
334 |
|
|
335 |
|
|
336 |
|
/* Start a dialog with the exception that before it is checked that the |
337 |
|
dialog is not already openened. */ |
338 |
int |
int |
339 |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc, |
340 |
LPARAM param, LPCTSTR title, int title_id ) |
LPARAM param, LPCTSTR title, int title_id ) |
341 |
{ |
{ |
342 |
#ifndef LANG_DE |
#ifndef LANG_DE |
343 |
if( FindWindowEx( GetDesktopWindow(), NULL, NULL, title ) ) |
if( FindWindowEx( GetDesktopWindow(), NULL, NULL, title ) ) |
344 |
return -1; |
return -1; |
345 |
#else |
#else |
346 |
char strdesc[256]; |
char strdesc[256]; |
347 |
LoadString( glob_hinst, title_id, strdesc, sizeof (strdesc) -1 ); |
LoadString( glob_hinst, title_id, strdesc, sizeof (strdesc) -1 ); |
348 |
if( FindWindowEx( GetDesktopWindow(), NULL, NULL, strdesc ) ) |
if( FindWindowEx( GetDesktopWindow(), NULL, NULL, strdesc ) ) |
349 |
return -1; |
return -1; |
350 |
#endif |
#endif |
351 |
|
|
352 |
return DialogBoxParam( hinst, name, parent, fnc, param ); |
return DialogBoxParam( hinst, name, parent, fnc, param ); |
353 |
} /* dialog_box_param */ |
} /* dialog_box_param */ |
354 |
|
|
355 |
|
|
356 |
|
/* Wrapper for message box which forces the message box into the |
357 |
|
foreground and it is displayed always on top. */ |
358 |
int |
int |
359 |
msg_box( HWND hwnd, const char *text, const char *title, int mode ) |
msg_box (HWND hwnd, const char *text, const char *title, int mode) |
360 |
{ |
{ |
361 |
mode |= MB_SETFOREGROUND; |
mode |= MB_SETFOREGROUND; |
362 |
mode |= MB_TASKMODAL; |
mode |= MB_TASKMODAL; |
363 |
mode |= MB_TOPMOST; |
mode |= MB_TOPMOST; |
364 |
return MessageBox(hwnd, text, title, mode); |
return MessageBox(hwnd, text, title, mode); |
365 |
} /* msg_box */ |
} |
366 |
|
|
367 |
|
|
368 |
void |
void |
369 |
set_active_window( HWND dlg ) |
set_active_window( HWND dlg) |
370 |
{ |
{ |
371 |
activ_hwnd = dlg; |
activ_hwnd = dlg; |
372 |
} /* set_active_window */ |
} /* set_active_window */ |
379 |
|
|
380 |
|
|
381 |
static DWORD CALLBACK |
static DWORD CALLBACK |
382 |
reminder_thread( void *ctx ) |
reminder_thread (void *ctx) |
383 |
{ |
{ |
384 |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
385 |
|
|
389 |
return 0; |
return 0; |
390 |
} /* reminder_thread */ |
} /* reminder_thread */ |
391 |
|
|
392 |
|
|
393 |
HANDLE |
HANDLE |
394 |
window_reminder( struct reminder_ctx_s *ctx ) |
window_reminder( struct reminder_ctx_s *ctx ) |
395 |
{ |
{ |
399 |
} /* window_reminder */ |
} /* window_reminder */ |
400 |
|
|
401 |
|
|
402 |
char * |
char* |
403 |
m_strdup( const char *str ) |
m_strdup (const char *str) |
404 |
{ |
{ |
405 |
char * p = new char[strlen( str ) + 1]; |
char * p = new char[strlen (str) + 1]; |
406 |
if( p ) |
if (p) |
407 |
strcpy( p, str ); |
strcpy (p, str); |
408 |
return p; |
return p; |
409 |
} /* m_strdup */ |
} /* m_strdup */ |
410 |
|
|
411 |
|
|
412 |
|
/* Center the hwndChild relative to parent. |
413 |
|
The style param allows to specificy additional styles (like topmost). */ |
414 |
void |
void |
415 |
center_window2 (HWND hwndChild, HWND style) |
center_window2 (HWND hwndChild, HWND parent, HWND style) |
416 |
{ |
{ |
417 |
HWND hwndParent; |
HWND hwndParent; |
418 |
RECT rChild, rParent; |
RECT rChild, rParent; |
421 |
int wScreen, hScreen, xNew, yNew; |
int wScreen, hScreen, xNew, yNew; |
422 |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
int flags = SWP_NOSIZE | SWP_NOZORDER; |
423 |
|
|
424 |
hwndParent = GetDesktopWindow (); |
hwndParent = parent; |
425 |
|
if (hwndParent == NULL) |
426 |
|
hwndParent = GetDesktopWindow (); |
427 |
GetWindowRect (hwndChild, &rChild); |
GetWindowRect (hwndChild, &rChild); |
428 |
wChild = rChild.right - rChild.left; |
wChild = rChild.right - rChild.left; |
429 |
hChild = rChild.bottom - rChild.top; |
hChild = rChild.bottom - rChild.top; |
449 |
if (style == HWND_TOPMOST || style == HWND_NOTOPMOST) |
if (style == HWND_TOPMOST || style == HWND_NOTOPMOST) |
450 |
flags = SWP_NOMOVE | SWP_NOSIZE; |
flags = SWP_NOMOVE | SWP_NOSIZE; |
451 |
SetWindowPos (hwndChild, style? style : NULL, xNew, yNew, 0, 0, flags); |
SetWindowPos (hwndChild, style? style : NULL, xNew, yNew, 0, 0, flags); |
|
|
|
452 |
} |
} |
453 |
|
|
454 |
|
|
455 |
|
/* Center the given hwndChild window with no special style. */ |
456 |
void |
void |
457 |
center_window (HWND hwndChild) |
center_window (HWND hwndChild, HWND hwndParent) |
458 |
{ |
{ |
459 |
center_window2 (hwndChild, NULL); |
center_window2 (hwndChild, hwndParent, NULL); |
460 |
} |
} |