Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/commdlg.dll16/filedlg.c
4388 views
1
/*
2
* COMMDLG - File Dialogs
3
*
4
* Copyright 1994 Martin Ayotte
5
* Copyright 1996 Albrecht Kleine
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#include <assert.h>
23
#include <stdarg.h>
24
#include "windef.h"
25
#include "winbase.h"
26
#include "wine/winbase16.h"
27
#include "wingdi.h"
28
#include "winuser.h"
29
#include "winternl.h"
30
#include "commdlg.h"
31
#include "cdlg16.h"
32
#include "wine/debug.h"
33
34
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
35
36
37
static inline WORD get_word( const char **ptr )
38
{
39
WORD ret = *(WORD *)*ptr;
40
*ptr += sizeof(WORD);
41
return ret;
42
}
43
44
static inline void copy_string( WORD **out, const char **in, DWORD maxlen )
45
{
46
DWORD len = MultiByteToWideChar( CP_ACP, 0, *in, -1, *out, maxlen );
47
*in += strlen(*in) + 1;
48
*out += len;
49
}
50
51
static inline void copy_dword( WORD **out, const char **in )
52
{
53
*(DWORD *)*out = *(DWORD *)*in;
54
*in += sizeof(DWORD);
55
*out += sizeof(DWORD) / sizeof(WORD);
56
}
57
58
static LPDLGTEMPLATEA convert_dialog( const char *p, DWORD size )
59
{
60
LPDLGTEMPLATEA dlg;
61
WORD len, count, *out, *end;
62
63
if (!(dlg = HeapAlloc( GetProcessHeap(), 0, size * 2 ))) return NULL;
64
out = (WORD *)dlg;
65
end = out + size;
66
copy_dword( &out, &p ); /* style */
67
*out++ = 0; *out++ = 0; /* exstyle */
68
*out++ = count = (BYTE)*p++; /* count */
69
*out++ = get_word( &p ); /* x */
70
*out++ = get_word( &p ); /* y */
71
*out++ = get_word( &p ); /* cx */
72
*out++ = get_word( &p ); /* cy */
73
74
if ((BYTE)*p == 0xff) /* menu */
75
{
76
p++;
77
*out++ = 0xffff;
78
*out++ = get_word( &p );
79
}
80
else copy_string( &out, &p, end - out );
81
82
copy_string( &out, &p, end - out ); /* class */
83
copy_string( &out, &p, end - out ); /* caption */
84
85
if (dlg->style & DS_SETFONT)
86
{
87
*out++ = get_word( &p ); /* point size */
88
copy_string( &out, &p, end - out ); /* face name */
89
}
90
91
/* controls */
92
while (count--)
93
{
94
WORD x = get_word( &p );
95
WORD y = get_word( &p );
96
WORD cx = get_word( &p );
97
WORD cy = get_word( &p );
98
WORD id = get_word( &p );
99
100
out = (WORD *)(((UINT_PTR)out + 3) & ~3);
101
102
copy_dword( &out, &p ); /* style */
103
*out++ = 0; *out++ = 0; /* exstyle */
104
*out++ = x;
105
*out++ = y;
106
*out++ = cx;
107
*out++ = cy;
108
*out++ = id;
109
110
if (*p & 0x80) /* class */
111
{
112
*out++ = 0xffff;
113
*out++ = (BYTE)*p++;
114
}
115
else copy_string( &out, &p, end - out );
116
117
if ((BYTE)*p == 0xff) /* window */
118
{
119
*out++ = 0xffff;
120
*out++ = get_word( &p );
121
}
122
else copy_string( &out, &p, end - out );
123
124
len = (BYTE)*p++; /* data */
125
*out++ = (len + 1) & ~1;
126
memcpy( out, p, len );
127
p += len;
128
out += (len + 1) / sizeof(WORD);
129
}
130
131
assert( out <= end );
132
return dlg;
133
}
134
135
static void RECT16to32( const RECT16 *from, RECT *to )
136
{
137
to->left = from->left;
138
to->top = from->top;
139
to->right = from->right;
140
to->bottom = from->bottom;
141
}
142
143
static void RECT32to16( const RECT *from, RECT16 *to )
144
{
145
to->left = from->left;
146
to->top = from->top;
147
to->right = from->right;
148
to->bottom = from->bottom;
149
}
150
151
static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
152
{
153
to->ptReserved.x = from->ptReserved.x;
154
to->ptReserved.y = from->ptReserved.y;
155
to->ptMaxSize.x = from->ptMaxSize.x;
156
to->ptMaxSize.y = from->ptMaxSize.y;
157
to->ptMaxPosition.x = from->ptMaxPosition.x;
158
to->ptMaxPosition.y = from->ptMaxPosition.y;
159
to->ptMinTrackSize.x = from->ptMinTrackSize.x;
160
to->ptMinTrackSize.y = from->ptMinTrackSize.y;
161
to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
162
to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
163
}
164
165
static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
166
{
167
to->ptReserved.x = from->ptReserved.x;
168
to->ptReserved.y = from->ptReserved.y;
169
to->ptMaxSize.x = from->ptMaxSize.x;
170
to->ptMaxSize.y = from->ptMaxSize.y;
171
to->ptMaxPosition.x = from->ptMaxPosition.x;
172
to->ptMaxPosition.y = from->ptMaxPosition.y;
173
to->ptMinTrackSize.x = from->ptMinTrackSize.x;
174
to->ptMinTrackSize.y = from->ptMinTrackSize.y;
175
to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
176
to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
177
}
178
179
static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
180
{
181
to->hwnd = HWND_16(from->hwnd);
182
to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
183
to->x = from->x;
184
to->y = from->y;
185
to->cx = from->cx;
186
to->cy = from->cy;
187
to->flags = from->flags;
188
}
189
190
static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
191
{
192
to->hwnd = HWND_32(from->hwnd);
193
to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
194
HWND_TOPMOST : HWND_32(from->hwndInsertAfter);
195
to->x = from->x;
196
to->y = from->y;
197
to->cx = from->cx;
198
to->cy = from->cy;
199
to->flags = from->flags;
200
}
201
202
static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
203
{
204
to->lpCreateParams = (SEGPTR)from->lpCreateParams;
205
to->hInstance = 0;
206
to->hMenu = HMENU_16(from->hMenu);
207
to->hwndParent = HWND_16(from->hwndParent);
208
to->cy = from->cy;
209
to->cx = from->cx;
210
to->y = from->y;
211
to->x = from->x;
212
to->style = from->style;
213
to->dwExStyle = from->dwExStyle;
214
}
215
216
static LRESULT call_hook16( WNDPROC16 hook, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
217
{
218
CONTEXT context;
219
WORD params[5];
220
221
TRACE( "%p: %p %08x %x %Ix: stub\n", hook, hwnd, msg, wp, lp );
222
223
memset( &context, 0, sizeof(context) );
224
context.SegDs = context.SegEs = CURRENT_SS;
225
context.SegCs = SELECTOROF( hook );
226
context.Eip = OFFSETOF( hook );
227
context.Ebp = CURRENT_SP + FIELD_OFFSET( STACK16FRAME, bp );
228
context.Eax = context.SegDs;
229
230
params[4] = HWND_16( hwnd );
231
params[3] = msg;
232
params[2] = wp;
233
params[1] = HIWORD( lp );
234
params[0] = LOWORD( lp );
235
WOWCallback16Ex( 0, WCB16_REGS, sizeof(params), params, (DWORD *)&context );
236
return LOWORD( context.Eax );
237
}
238
239
static UINT_PTR CALLBACK call_hook_proc( WNDPROC16 hook, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
240
{
241
LRESULT ret = 0;
242
243
switch (msg)
244
{
245
case WM_NCCREATE:
246
case WM_CREATE:
247
{
248
CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lp;
249
CREATESTRUCT16 cs;
250
251
CREATESTRUCT32Ato16( cs32, &cs );
252
cs.lpszName = MapLS( (void *)cs32->lpszName );
253
cs.lpszClass = MapLS( (void *)cs32->lpszClass );
254
lp = MapLS( &cs );
255
ret = call_hook16( hook, hwnd, msg, wp, lp );
256
UnMapLS( lp );
257
UnMapLS( cs.lpszName );
258
UnMapLS( cs.lpszClass );
259
}
260
break;
261
case WM_GETMINMAXINFO:
262
{
263
MINMAXINFO *mmi32 = (MINMAXINFO *)lp;
264
MINMAXINFO16 mmi;
265
266
MINMAXINFO32to16( mmi32, &mmi );
267
lp = MapLS( &mmi );
268
ret = call_hook16( hook, hwnd, msg, wp, lp );
269
UnMapLS( lp );
270
MINMAXINFO16to32( &mmi, mmi32 );
271
}
272
break;
273
case WM_NCCALCSIZE:
274
{
275
NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lp;
276
NCCALCSIZE_PARAMS16 nc;
277
WINDOWPOS16 winpos;
278
279
RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
280
if (wp)
281
{
282
RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
283
RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
284
WINDOWPOS32to16( nc32->lppos, &winpos );
285
nc.lppos = MapLS( &winpos );
286
}
287
lp = MapLS( &nc );
288
ret = call_hook16( hook, hwnd, msg, wp, lp );
289
UnMapLS( lp );
290
RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
291
if (wp)
292
{
293
RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
294
RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
295
WINDOWPOS16to32( &winpos, nc32->lppos );
296
UnMapLS( nc.lppos );
297
}
298
}
299
break;
300
case WM_WINDOWPOSCHANGING:
301
case WM_WINDOWPOSCHANGED:
302
{
303
WINDOWPOS *winpos32 = (WINDOWPOS *)lp;
304
WINDOWPOS16 winpos;
305
306
WINDOWPOS32to16( winpos32, &winpos );
307
lp = MapLS( &winpos );
308
ret = call_hook16( hook, hwnd, msg, wp, lp );
309
UnMapLS( lp );
310
WINDOWPOS16to32( &winpos, winpos32 );
311
}
312
break;
313
case WM_COMPAREITEM:
314
{
315
COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lp;
316
COMPAREITEMSTRUCT16 cis;
317
cis.CtlType = cis32->CtlType;
318
cis.CtlID = cis32->CtlID;
319
cis.hwndItem = HWND_16( cis32->hwndItem );
320
cis.itemID1 = cis32->itemID1;
321
cis.itemData1 = cis32->itemData1;
322
cis.itemID2 = cis32->itemID2;
323
cis.itemData2 = cis32->itemData2;
324
lp = MapLS( &cis );
325
ret = call_hook16( hook, hwnd, msg, wp, lp );
326
UnMapLS( lp );
327
}
328
break;
329
case WM_DELETEITEM:
330
{
331
DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lp;
332
DELETEITEMSTRUCT16 dis;
333
dis.CtlType = dis32->CtlType;
334
dis.CtlID = dis32->CtlID;
335
dis.itemID = dis32->itemID;
336
dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
337
: HWND_16( dis32->hwndItem );
338
dis.itemData = dis32->itemData;
339
lp = MapLS( &dis );
340
ret = call_hook16( hook, hwnd, msg, wp, lp );
341
UnMapLS( lp );
342
}
343
break;
344
case WM_DRAWITEM:
345
{
346
DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lp;
347
DRAWITEMSTRUCT16 dis;
348
dis.CtlType = dis32->CtlType;
349
dis.CtlID = dis32->CtlID;
350
dis.itemID = dis32->itemID;
351
dis.itemAction = dis32->itemAction;
352
dis.itemState = dis32->itemState;
353
dis.hwndItem = HWND_16( dis32->hwndItem );
354
dis.hDC = HDC_16( dis32->hDC );
355
dis.itemData = dis32->itemData;
356
dis.rcItem.left = dis32->rcItem.left;
357
dis.rcItem.top = dis32->rcItem.top;
358
dis.rcItem.right = dis32->rcItem.right;
359
dis.rcItem.bottom = dis32->rcItem.bottom;
360
lp = MapLS( &dis );
361
ret = call_hook16( hook, hwnd, msg, wp, lp );
362
UnMapLS( lp );
363
}
364
break;
365
case WM_MEASUREITEM:
366
{
367
MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lp;
368
MEASUREITEMSTRUCT16 mis;
369
mis.CtlType = mis32->CtlType;
370
mis.CtlID = mis32->CtlID;
371
mis.itemID = mis32->itemID;
372
mis.itemWidth = mis32->itemWidth;
373
mis.itemHeight = mis32->itemHeight;
374
mis.itemData = mis32->itemData;
375
lp = MapLS( &mis );
376
ret = call_hook16( hook, hwnd, msg, wp, lp );
377
UnMapLS( lp );
378
mis32->itemWidth = mis.itemWidth;
379
mis32->itemHeight = mis.itemHeight;
380
}
381
break;
382
case WM_COPYDATA:
383
{
384
COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lp;
385
COPYDATASTRUCT16 cds;
386
387
cds.dwData = cds32->dwData;
388
cds.cbData = cds32->cbData;
389
cds.lpData = MapLS( cds32->lpData );
390
lp = MapLS( &cds );
391
ret = call_hook16( hook, hwnd, msg, wp, lp );
392
UnMapLS( lp );
393
UnMapLS( cds.lpData );
394
}
395
break;
396
case WM_GETDLGCODE:
397
if (lp)
398
{
399
MSG *msg32 = (MSG *)lp;
400
MSG16 msg16;
401
402
msg16.hwnd = HWND_16( msg32->hwnd );
403
msg16.message = msg32->message;
404
msg16.wParam = msg32->wParam;
405
msg16.lParam = msg32->lParam;
406
msg16.time = msg32->time;
407
msg16.pt.x = msg32->pt.x;
408
msg16.pt.y = msg32->pt.y;
409
lp = MapLS( &msg16 );
410
ret = call_hook16( hook, hwnd, msg, wp, lp );
411
UnMapLS( lp );
412
}
413
else
414
ret = call_hook16( hook, hwnd, msg, wp, lp );
415
break;
416
case WM_NEXTMENU:
417
{
418
LRESULT result;
419
MDINEXTMENU *next = (MDINEXTMENU *)lp;
420
ret = call_hook16( hook, hwnd, msg, wp, (LPARAM)next->hmenuIn );
421
result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
422
next->hmenuNext = HMENU_32( LOWORD(result) );
423
next->hwndNext = HWND_32( HIWORD(result) );
424
SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, 0 );
425
}
426
break;
427
case WM_GETTEXT:
428
case WM_ASKCBFORMATNAME:
429
wp = min( wp, 0xff80 ); /* Must be < 64K */
430
/* fall through */
431
case WM_NOTIFY:
432
case WM_SETTEXT:
433
case WM_WININICHANGE:
434
case WM_DEVMODECHANGE:
435
lp = MapLS( (void *)lp );
436
ret = call_hook16( hook, hwnd, msg, wp, lp );
437
UnMapLS( lp );
438
break;
439
case WM_ACTIVATE:
440
case WM_CHARTOITEM:
441
case WM_COMMAND:
442
case WM_VKEYTOITEM:
443
ret = call_hook16( hook, hwnd, msg, wp, MAKELPARAM( (HWND16)lp, HIWORD(wp) ));
444
break;
445
case WM_HSCROLL:
446
case WM_VSCROLL:
447
ret = call_hook16( hook, hwnd, msg, wp, MAKELPARAM( HIWORD(wp), (HWND16)lp ));
448
break;
449
case WM_CTLCOLORMSGBOX:
450
case WM_CTLCOLOREDIT:
451
case WM_CTLCOLORLISTBOX:
452
case WM_CTLCOLORBTN:
453
case WM_CTLCOLORDLG:
454
case WM_CTLCOLORSCROLLBAR:
455
case WM_CTLCOLORSTATIC:
456
ret = call_hook16( hook, hwnd, WM_CTLCOLOR, wp, MAKELPARAM( (HWND16)lp, msg - WM_CTLCOLORMSGBOX ));
457
break;
458
case WM_MENUSELECT:
459
if(HIWORD(wp) & MF_POPUP)
460
{
461
HMENU hmenu;
462
if ((HIWORD(wp) != 0xffff) || lp)
463
{
464
if ((hmenu = GetSubMenu( (HMENU)lp, LOWORD(wp) )))
465
{
466
ret = call_hook16( hook, hwnd, msg, HMENU_16(hmenu),
467
MAKELPARAM( HIWORD(wp), (HMENU16)lp ) );
468
break;
469
}
470
}
471
}
472
/* fall through */
473
case WM_MENUCHAR:
474
ret = call_hook16( hook, hwnd, msg, wp, MAKELPARAM( HIWORD(wp), (HMENU16)lp ));
475
break;
476
case WM_PARENTNOTIFY:
477
if ((LOWORD(wp) == WM_CREATE) || (LOWORD(wp) == WM_DESTROY))
478
ret = call_hook16( hook, hwnd, msg, wp, MAKELPARAM( (HWND16)lp, HIWORD(wp) ));
479
else
480
ret = call_hook16( hook, hwnd, msg, wp, lp );
481
break;
482
case WM_ACTIVATEAPP:
483
ret = call_hook16( hook, hwnd, msg, wp, HTASK_16( lp ));
484
break;
485
case WM_INITDIALOG:
486
{
487
OPENFILENAMEA *ofn = (OPENFILENAMEA *)lp;
488
ret = call_hook16( hook, hwnd, msg, wp, ofn->lCustData );
489
break;
490
}
491
default:
492
ret = call_hook16( hook, hwnd, msg, wp, lp );
493
break;
494
}
495
return LOWORD(ret);
496
}
497
498
499
#pragma pack(push,1)
500
struct hook_proc
501
{
502
BYTE popl_eax; /* popl %eax */
503
BYTE pushl_hook; /* pushl $hook_ptr */
504
LPOFNHOOKPROC16 hook_ptr;
505
BYTE pushl_eax; /* pushl %eax */
506
BYTE jmp; /* jmp call_hook */
507
DWORD call_hook;
508
};
509
#pragma pack(pop)
510
511
static LPOFNHOOKPROC alloc_hook( LPOFNHOOKPROC16 hook16 )
512
{
513
static struct hook_proc *hooks;
514
static unsigned int count;
515
SIZE_T size = 0x1000;
516
unsigned int i;
517
518
if (!hooks && !(hooks = VirtualAlloc( NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
519
return NULL;
520
521
for (i = 0; i < count; i++)
522
if (hooks[i].hook_ptr == hook16)
523
return (LPOFNHOOKPROC)&hooks[i];
524
525
if (count >= size / sizeof(*hooks))
526
{
527
FIXME( "all hooks are in use\n" );
528
return NULL;
529
}
530
531
hooks[count].popl_eax = 0x58;
532
hooks[count].pushl_hook = 0x68;
533
hooks[count].hook_ptr = hook16;
534
hooks[count].pushl_eax = 0x50;
535
hooks[count].jmp = 0xe9;
536
hooks[count].call_hook = (char *)call_hook_proc - (char *)(&hooks[count].call_hook + 1);
537
return (LPOFNHOOKPROC)&hooks[count++];
538
}
539
540
static UINT_PTR CALLBACK dummy_hook( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
541
{
542
return FALSE;
543
}
544
545
/***********************************************************************
546
* FileOpenDlgProc (COMMDLG.6)
547
*/
548
BOOL16 CALLBACK FileOpenDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
549
{
550
FIXME( "%04x %04x %04x %08Ix: stub\n", hWnd16, wMsg, wParam, lParam );
551
return FALSE;
552
}
553
554
/***********************************************************************
555
* FileSaveDlgProc (COMMDLG.7)
556
*/
557
BOOL16 CALLBACK FileSaveDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
558
{
559
FIXME( "%04x %04x %04x %08Ix: stub\n", hWnd16, wMsg, wParam, lParam );
560
return FALSE;
561
}
562
563
/***********************************************************************
564
* GetOpenFileName (COMMDLG.1)
565
*
566
* Creates a dialog box for the user to select a file to open.
567
*
568
* RETURNS
569
* TRUE on success: user selected a valid file
570
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
571
*
572
* BUGS
573
* unknown, there are some FIXMEs left.
574
*/
575
BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn ) /* [in/out] address of structure with data*/
576
{
577
LPOPENFILENAME16 lpofn = MapSL(ofn);
578
LPDLGTEMPLATEA template = NULL;
579
OPENFILENAMEA ofn32;
580
BOOL ret;
581
582
if (!lpofn) return FALSE;
583
584
ofn32.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
585
ofn32.hwndOwner = HWND_32( lpofn->hwndOwner );
586
ofn32.lpstrFilter = MapSL( lpofn->lpstrFilter );
587
ofn32.lpstrCustomFilter = MapSL( lpofn->lpstrCustomFilter );
588
ofn32.nMaxCustFilter = lpofn->nMaxCustFilter;
589
ofn32.nFilterIndex = lpofn->nFilterIndex;
590
ofn32.lpstrFile = MapSL( lpofn->lpstrFile );
591
ofn32.nMaxFile = lpofn->nMaxFile;
592
ofn32.lpstrFileTitle = MapSL( lpofn->lpstrFileTitle );
593
ofn32.nMaxFileTitle = lpofn->nMaxFileTitle;
594
ofn32.lpstrInitialDir = MapSL( lpofn->lpstrInitialDir );
595
ofn32.lpstrTitle = MapSL( lpofn->lpstrTitle );
596
ofn32.Flags = (lpofn->Flags & ~OFN_ENABLETEMPLATE) | OFN_ENABLEHOOK;
597
ofn32.nFileOffset = lpofn->nFileOffset;
598
ofn32.nFileExtension = lpofn->nFileExtension;
599
ofn32.lpstrDefExt = MapSL( lpofn->lpstrDefExt );
600
ofn32.lCustData = ofn; /* See WM_INITDIALOG in the hook proc */
601
ofn32.lpfnHook = dummy_hook; /* this is to force old 3.1 dialog style */
602
603
if (lpofn->Flags & OFN_ENABLETEMPLATE)
604
{
605
HRSRC16 res = FindResource16( lpofn->hInstance, MapSL(lpofn->lpTemplateName), (LPCSTR)RT_DIALOG );
606
HGLOBAL16 handle = LoadResource16( lpofn->hInstance, res );
607
DWORD size = SizeofResource16( lpofn->hInstance, res );
608
void *ptr = LockResource16( handle );
609
610
if (ptr && (template = convert_dialog( ptr, size )))
611
{
612
ofn32.hInstance = (HINSTANCE)template;
613
ofn32.Flags |= OFN_ENABLETEMPLATEHANDLE;
614
}
615
FreeResource16( handle );
616
}
617
618
if (lpofn->Flags & OFN_ENABLEHOOK) ofn32.lpfnHook = alloc_hook( lpofn->lpfnHook );
619
620
if ((ret = GetOpenFileNameA( &ofn32 )))
621
{
622
lpofn->nFilterIndex = ofn32.nFilterIndex;
623
lpofn->nFileOffset = ofn32.nFileOffset;
624
lpofn->nFileExtension = ofn32.nFileExtension;
625
}
626
HeapFree( GetProcessHeap(), 0, template );
627
return ret;
628
}
629
630
/***********************************************************************
631
* GetSaveFileName (COMMDLG.2)
632
*
633
* Creates a dialog box for the user to select a file to save.
634
*
635
* RETURNS
636
* TRUE on success: user enters a valid file
637
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
638
*
639
* BUGS
640
* unknown. There are some FIXMEs left.
641
*/
642
BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn ) /* [in/out] address of structure with data*/
643
{
644
LPOPENFILENAME16 lpofn = MapSL(ofn);
645
LPDLGTEMPLATEA template = NULL;
646
OPENFILENAMEA ofn32;
647
BOOL ret;
648
649
if (!lpofn) return FALSE;
650
651
ofn32.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
652
ofn32.hwndOwner = HWND_32( lpofn->hwndOwner );
653
ofn32.lpstrFilter = MapSL( lpofn->lpstrFilter );
654
ofn32.lpstrCustomFilter = MapSL( lpofn->lpstrCustomFilter );
655
ofn32.nMaxCustFilter = lpofn->nMaxCustFilter;
656
ofn32.nFilterIndex = lpofn->nFilterIndex;
657
ofn32.lpstrFile = MapSL( lpofn->lpstrFile );
658
ofn32.nMaxFile = lpofn->nMaxFile;
659
ofn32.lpstrFileTitle = MapSL( lpofn->lpstrFileTitle );
660
ofn32.nMaxFileTitle = lpofn->nMaxFileTitle;
661
ofn32.lpstrInitialDir = MapSL( lpofn->lpstrInitialDir );
662
ofn32.lpstrTitle = MapSL( lpofn->lpstrTitle );
663
ofn32.Flags = (lpofn->Flags & ~OFN_ENABLETEMPLATE) | OFN_ENABLEHOOK;
664
ofn32.nFileOffset = lpofn->nFileOffset;
665
ofn32.nFileExtension = lpofn->nFileExtension;
666
ofn32.lpstrDefExt = MapSL( lpofn->lpstrDefExt );
667
ofn32.lCustData = ofn; /* See WM_INITDIALOG in the hook proc */
668
ofn32.lpfnHook = dummy_hook; /* this is to force old 3.1 dialog style */
669
670
if (lpofn->Flags & OFN_ENABLETEMPLATE)
671
{
672
HRSRC16 res = FindResource16( lpofn->hInstance, MapSL(lpofn->lpTemplateName), (LPCSTR)RT_DIALOG );
673
HGLOBAL16 handle = LoadResource16( lpofn->hInstance, res );
674
DWORD size = SizeofResource16( lpofn->hInstance, res );
675
void *ptr = LockResource16( handle );
676
677
if (ptr && (template = convert_dialog( ptr, size )))
678
{
679
ofn32.hInstance = (HINSTANCE)template;
680
ofn32.Flags |= OFN_ENABLETEMPLATEHANDLE;
681
}
682
FreeResource16( handle );
683
}
684
685
if (lpofn->Flags & OFN_ENABLEHOOK) ofn32.lpfnHook = alloc_hook( lpofn->lpfnHook );
686
687
if ((ret = GetSaveFileNameA( &ofn32 )))
688
{
689
lpofn->nFilterIndex = ofn32.nFilterIndex;
690
lpofn->nFileOffset = ofn32.nFileOffset;
691
lpofn->nFileExtension = ofn32.nFileExtension;
692
}
693
HeapFree( GetProcessHeap(), 0, template );
694
return ret;
695
}
696
697
698
/***********************************************************************
699
* GetFileTitle (COMMDLG.27)
700
*/
701
short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
702
{
703
return GetFileTitleA(lpFile, lpTitle, cbBuf);
704
}
705
706