41 |
extern "C" void _SHFree (void *p); |
extern "C" void _SHFree (void *p); |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
/* Insert a new item into the menu @hm at position @pos. */ |
46 |
|
void |
47 |
|
insert_menu_item (HMENU hm, int pos, UINT m_id, const char *text) |
48 |
|
{ |
49 |
|
MENUITEMINFO mi; |
50 |
|
|
51 |
|
memset (&mi, 0, sizeof mi); |
52 |
|
mi.cbSize = sizeof mi; |
53 |
|
mi.fType = MF_STRING; |
54 |
|
mi.dwTypeData = (char *)text; |
55 |
|
mi.cch = strlen (text); |
56 |
|
mi.wID = m_id; |
57 |
|
mi.fMask = MIIM_ID|MIIM_DATA| MIIM_TYPE; |
58 |
|
InsertMenuItem (hm, pos, FALSE, &mi); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
static void |
static void |
63 |
set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text) |
set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text) |
64 |
{ |
{ |
126 |
id can be either FILE_OPEN or FILE_SAVE. |
id can be either FILE_OPEN or FILE_SAVE. |
127 |
The return value is the file name or NULL if cancel was chosen. */ |
The return value is the file name or NULL if cancel was chosen. */ |
128 |
const char * |
const char * |
129 |
get_filename_dlg (HWND hwnd, int id, const char * title, |
get_filename_dlg (HWND hwnd, int id, const char *title, |
130 |
const char * filter, const char * name) |
const char *filter, const char *name) |
131 |
{ |
{ |
132 |
static char file[512] = ""; |
static char file[512] = ""; |
133 |
OPENFILENAME open; |
OPENFILENAME open; |
137 |
else |
else |
138 |
memset (file, 0, sizeof (file)); |
memset (file, 0, sizeof (file)); |
139 |
if (!filter) |
if (!filter) |
140 |
filter = _("All Files (*.*)\0*.*\0\0"); |
filter = "All Files (*.*)\0*.*\0\0"; |
141 |
/* XXX: problem with gettext because of the 'artificial' |
/* XXX: problem with gettext because of the 'artificial' |
142 |
double string termination!. */ |
double string termination!. */ |
143 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
256 |
BUG (NULL); |
BUG (NULL); |
257 |
p = (char *) GlobalLock (clipmem); |
p = (char *) GlobalLock (clipmem); |
258 |
if (p == NULL) { |
if (p == NULL) { |
259 |
rc = WPTERR_GENERAL;; |
CloseClipboard (); |
260 |
goto leave; |
GlobalFree (clipmem); |
261 |
|
return WPTERR_GENERAL; |
262 |
} |
} |
263 |
memcpy (p, text, nbytes); |
memcpy (p, text, nbytes); |
264 |
p[nbytes] = '\0'; |
p[nbytes] = '\0'; |
265 |
|
|
|
GlobalUnlock (clipmem); |
|
266 |
SetClipboardData (CF_TEXT, clipmem); |
SetClipboardData (CF_TEXT, clipmem); |
267 |
|
GlobalUnlock (clipmem); |
|
leave: |
|
268 |
CloseClipboard (); |
CloseClipboard (); |
269 |
|
GlobalFree (clipmem); |
270 |
|
|
271 |
return rc; |
return rc; |
272 |
} /* set_clip_text */ |
} |
273 |
|
|
274 |
|
|
275 |
/* Append or prepend some text to the clipboard contents. |
/* Append or prepend some text to the clipboard contents. |
328 |
} |
} |
329 |
|
|
330 |
|
|
331 |
|
/* Generate a file name from a special dirctory. */ |
332 |
|
char* |
333 |
|
make_special_filename (int folder, const char *file, const char *ext) |
334 |
|
{ |
335 |
|
BOOL ec; |
336 |
|
char path[MAX_PATH], *p; |
337 |
|
size_t n=0; |
338 |
|
|
339 |
|
/* MSDN: buf must be at least MAX_PATH=256 bytes */ |
340 |
|
ec = SHGetSpecialFolderPath (HWND_DESKTOP, path, folder, TRUE); |
341 |
|
if (ec != 1) { |
342 |
|
log_debug ("SHGetSpecialFolderPath() failed\r\n", (int)GetLastError ()); |
343 |
|
return NULL; |
344 |
|
} |
345 |
|
|
346 |
|
n = strlen (path)+1; |
347 |
|
if (file) |
348 |
|
n += strlen (file)+1; |
349 |
|
if (ext) |
350 |
|
n += strlen (ext)+1; |
351 |
|
p = new char[n+2]; |
352 |
|
if (!p) |
353 |
|
BUG (0); |
354 |
|
memset (p, 0, n+2); |
355 |
|
strcpy (p, path); |
356 |
|
if (file) { |
357 |
|
strcat (p, "\\"); |
358 |
|
strcat (p, file); |
359 |
|
} |
360 |
|
if (ext) |
361 |
|
strcat (p, ext); |
362 |
|
return p; |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
/* return 0 if the file @fname exists, otherwise >0. */ |
/* return 0 if the file @fname exists, otherwise >0. */ |
367 |
int |
int |
368 |
file_exist_check (const char *fname) |
file_exist_check (const char *fname) |
408 |
} |
} |
409 |
|
|
410 |
|
|
|
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 */ |
|
|
|
|
|
|
|
411 |
/* 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 |
412 |
dialog is not already openened. */ |
dialog is not already openened. */ |
413 |
int |
int |
561 |
} |
} |
562 |
|
|
563 |
|
|
564 |
|
/* Generate a temporary file name by using the users |
565 |
|
temp path and optionally a name @name provided by the caller. |
566 |
|
Return value: 0 on success. */ |
567 |
|
int |
568 |
|
get_temp_name (char *buf, DWORD buflen, const char *name) |
569 |
|
{ |
570 |
|
char tmp[32]; |
571 |
|
|
572 |
|
if (!name) { |
573 |
|
sprintf (tmp, "%08lX", GetTickCount ()); |
574 |
|
name = tmp; |
575 |
|
} |
576 |
|
|
577 |
|
/* in the mobile mode we use a local temp folder |
578 |
|
with the fixed name 'temp'. */ |
579 |
|
if (mobile_mode_active) { |
580 |
|
_snprintf (buf, buflen-1, "temp\\%s", name); |
581 |
|
return 0; |
582 |
|
} |
583 |
|
|
584 |
|
if (!GetTempPath (buflen - strlen (name) -2, buf)) { |
585 |
|
log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ()); |
586 |
|
return -1; |
587 |
|
} |
588 |
|
strcat (buf, name); |
589 |
|
return 0; |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
struct reminder_hd_s { |
struct reminder_hd_s { |
594 |
int msecs; |
int msecs; |
595 |
HWND dlg; |
HWND dlg; |