widl: Generate helper macros for WinRT implementation.
[wine/zf.git] / dlls / commdlg.dll16 / filedlg.c
blob4fa62c15d6cb8d3906a2fb3535b07ca68d37d1aa
1 /*
2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
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.
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.
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
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"
34 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
37 static inline WORD get_word( const char **ptr )
39 WORD ret = *(WORD *)*ptr;
40 *ptr += sizeof(WORD);
41 return ret;
44 static inline void copy_string( WORD **out, const char **in, DWORD maxlen )
46 DWORD len = MultiByteToWideChar( CP_ACP, 0, *in, -1, *out, maxlen );
47 *in += strlen(*in) + 1;
48 *out += len;
51 static inline void copy_dword( WORD **out, const char **in )
53 *(DWORD *)*out = *(DWORD *)*in;
54 *in += sizeof(DWORD);
55 *out += sizeof(DWORD) / sizeof(WORD);
58 static LPDLGTEMPLATEA convert_dialog( const char *p, DWORD size )
60 LPDLGTEMPLATEA dlg;
61 WORD len, count, *out, *end;
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 */
74 if ((BYTE)*p == 0xff) /* menu */
76 p++;
77 *out++ = 0xffff;
78 *out++ = get_word( &p );
80 else copy_string( &out, &p, end - out );
82 copy_string( &out, &p, end - out ); /* class */
83 copy_string( &out, &p, end - out ); /* caption */
85 if (dlg->style & DS_SETFONT)
87 *out++ = get_word( &p ); /* point size */
88 copy_string( &out, &p, end - out ); /* face name */
91 /* controls */
92 while (count--)
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 );
100 out = (WORD *)(((UINT_PTR)out + 3) & ~3);
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;
110 if (*p & 0x80) /* class */
112 *out++ = 0xffff;
113 *out++ = (BYTE)*p++;
115 else copy_string( &out, &p, end - out );
117 if (*p & 0x80) /* window */
119 *out++ = 0xffff;
120 *out++ = get_word( &p );
122 else copy_string( &out, &p, end - out );
124 len = (BYTE)*p++; /* data */
125 *out++ = (len + 1) & ~1;
126 memcpy( out, p, len );
127 p += len;
128 out += (len + 1) / sizeof(WORD);
131 assert( out <= end );
132 return dlg;
135 static void RECT16to32( const RECT16 *from, RECT *to )
137 to->left = from->left;
138 to->top = from->top;
139 to->right = from->right;
140 to->bottom = from->bottom;
143 static void RECT32to16( const RECT *from, RECT16 *to )
145 to->left = from->left;
146 to->top = from->top;
147 to->right = from->right;
148 to->bottom = from->bottom;
151 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
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;
165 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
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;
179 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
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;
190 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
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;
202 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
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;
216 static LRESULT call_hook16( WNDPROC16 hook, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
218 CONTEXT context;
219 WORD params[5];
221 TRACE( "%p: %p %08x %lx %lx: stub\n", hook, hwnd, msg, wp, lp );
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;
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 );
239 static UINT_PTR CALLBACK call_hook_proc( WNDPROC16 hook, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
241 LRESULT ret = 0;
243 switch (msg)
245 case WM_NCCREATE:
246 case WM_CREATE:
248 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lp;
249 CREATESTRUCT16 cs;
251 CREATESTRUCT32Ato16( cs32, &cs );
252 cs.lpszName = MapLS( cs32->lpszName );
253 cs.lpszClass = MapLS( 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 );
260 break;
261 case WM_GETMINMAXINFO:
263 MINMAXINFO *mmi32 = (MINMAXINFO *)lp;
264 MINMAXINFO16 mmi;
266 MINMAXINFO32to16( mmi32, &mmi );
267 lp = MapLS( &mmi );
268 ret = call_hook16( hook, hwnd, msg, wp, lp );
269 UnMapLS( lp );
270 MINMAXINFO16to32( &mmi, mmi32 );
272 break;
273 case WM_NCCALCSIZE:
275 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lp;
276 NCCALCSIZE_PARAMS16 nc;
277 WINDOWPOS16 winpos;
279 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
280 if (wp)
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 );
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)
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 );
299 break;
300 case WM_WINDOWPOSCHANGING:
301 case WM_WINDOWPOSCHANGED:
303 WINDOWPOS *winpos32 = (WINDOWPOS *)lp;
304 WINDOWPOS16 winpos;
306 WINDOWPOS32to16( winpos32, &winpos );
307 lp = MapLS( &winpos );
308 ret = call_hook16( hook, hwnd, msg, wp, lp );
309 UnMapLS( lp );
310 WINDOWPOS16to32( &winpos, winpos32 );
312 break;
313 case WM_COMPAREITEM:
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 );
328 break;
329 case WM_DELETEITEM:
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 );
343 break;
344 case WM_DRAWITEM:
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 );
364 break;
365 case WM_MEASUREITEM:
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;
381 break;
382 case WM_COPYDATA:
384 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lp;
385 COPYDATASTRUCT16 cds;
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 );
395 break;
396 case WM_GETDLGCODE:
397 if (lp)
399 MSG *msg32 = (MSG *)lp;
400 MSG16 msg16;
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 );
413 else
414 ret = call_hook16( hook, hwnd, msg, wp, lp );
415 break;
416 case WM_NEXTMENU:
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 );
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)
461 HMENU hmenu;
462 if ((HIWORD(wp) != 0xffff) || lp)
464 if ((hmenu = GetSubMenu( (HMENU)lp, LOWORD(wp) )))
466 ret = call_hook16( hook, hwnd, msg, HMENU_16(hmenu),
467 MAKELPARAM( HIWORD(wp), (HMENU16)lp ) );
468 break;
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 default:
486 ret = call_hook16( hook, hwnd, msg, wp, lp );
487 break;
489 return LOWORD(ret);
493 #include "pshpack1.h"
494 struct hook_proc
496 BYTE popl_eax; /* popl %eax */
497 BYTE pushl_hook; /* pushl $hook_ptr */
498 LPOFNHOOKPROC16 hook_ptr;
499 BYTE pushl_eax; /* pushl %eax */
500 BYTE jmp; /* jmp call_hook */
501 DWORD call_hook;
503 #include "poppack.h"
505 static LPOFNHOOKPROC alloc_hook( LPOFNHOOKPROC16 hook16 )
507 static struct hook_proc *hooks;
508 static unsigned int count;
509 SIZE_T size = 0x1000;
510 unsigned int i;
512 if (!hooks && !(hooks = VirtualAlloc( NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
513 return NULL;
515 for (i = 0; i < count; i++)
516 if (hooks[i].hook_ptr == hook16)
517 return (LPOFNHOOKPROC)&hooks[i];
519 if (count >= size / sizeof(*hooks))
521 FIXME( "all hooks are in use\n" );
522 return NULL;
525 hooks[count].popl_eax = 0x58;
526 hooks[count].pushl_hook = 0x68;
527 hooks[count].hook_ptr = hook16;
528 hooks[count].pushl_eax = 0x50;
529 hooks[count].jmp = 0xe9;
530 hooks[count].call_hook = (char *)call_hook_proc - (char *)(&hooks[count].call_hook + 1);
531 return (LPOFNHOOKPROC)&hooks[count++];
534 static UINT_PTR CALLBACK dummy_hook( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
536 return FALSE;
539 /***********************************************************************
540 * FileOpenDlgProc (COMMDLG.6)
542 BOOL16 CALLBACK FileOpenDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
544 FIXME( "%04x %04x %04x %08lx: stub\n", hWnd16, wMsg, wParam, lParam );
545 return FALSE;
548 /***********************************************************************
549 * FileSaveDlgProc (COMMDLG.7)
551 BOOL16 CALLBACK FileSaveDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
553 FIXME( "%04x %04x %04x %08lx: stub\n", hWnd16, wMsg, wParam, lParam );
554 return FALSE;
557 /***********************************************************************
558 * GetOpenFileName (COMMDLG.1)
560 * Creates a dialog box for the user to select a file to open.
562 * RETURNS
563 * TRUE on success: user selected a valid file
564 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
566 * BUGS
567 * unknown, there are some FIXMEs left.
569 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn ) /* [in/out] address of structure with data*/
571 LPOPENFILENAME16 lpofn = MapSL(ofn);
572 LPDLGTEMPLATEA template = NULL;
573 OPENFILENAMEA ofn32;
574 BOOL ret;
576 if (!lpofn) return FALSE;
578 ofn32.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
579 ofn32.hwndOwner = HWND_32( lpofn->hwndOwner );
580 ofn32.lpstrFilter = MapSL( lpofn->lpstrFilter );
581 ofn32.lpstrCustomFilter = MapSL( lpofn->lpstrCustomFilter );
582 ofn32.nMaxCustFilter = lpofn->nMaxCustFilter;
583 ofn32.nFilterIndex = lpofn->nFilterIndex;
584 ofn32.lpstrFile = MapSL( lpofn->lpstrFile );
585 ofn32.nMaxFile = lpofn->nMaxFile;
586 ofn32.lpstrFileTitle = MapSL( lpofn->lpstrFileTitle );
587 ofn32.nMaxFileTitle = lpofn->nMaxFileTitle;
588 ofn32.lpstrInitialDir = MapSL( lpofn->lpstrInitialDir );
589 ofn32.lpstrTitle = MapSL( lpofn->lpstrTitle );
590 ofn32.Flags = (lpofn->Flags & ~OFN_ENABLETEMPLATE) | OFN_ENABLEHOOK;
591 ofn32.nFileOffset = lpofn->nFileOffset;
592 ofn32.nFileExtension = lpofn->nFileExtension;
593 ofn32.lpstrDefExt = MapSL( lpofn->lpstrDefExt );
594 ofn32.lCustData = lpofn->lCustData;
595 ofn32.lpfnHook = dummy_hook; /* this is to force old 3.1 dialog style */
597 if (lpofn->Flags & OFN_ENABLETEMPLATE)
599 HRSRC16 res = FindResource16( lpofn->hInstance, MapSL(lpofn->lpTemplateName), (LPCSTR)RT_DIALOG );
600 HGLOBAL16 handle = LoadResource16( lpofn->hInstance, res );
601 DWORD size = SizeofResource16( lpofn->hInstance, res );
602 void *ptr = LockResource16( handle );
604 if (ptr && (template = convert_dialog( ptr, size )))
606 ofn32.hInstance = (HINSTANCE)template;
607 ofn32.Flags |= OFN_ENABLETEMPLATEHANDLE;
609 FreeResource16( handle );
612 if (lpofn->Flags & OFN_ENABLEHOOK) ofn32.lpfnHook = alloc_hook( lpofn->lpfnHook );
614 if ((ret = GetOpenFileNameA( &ofn32 )))
616 lpofn->nFilterIndex = ofn32.nFilterIndex;
617 lpofn->nFileOffset = ofn32.nFileOffset;
618 lpofn->nFileExtension = ofn32.nFileExtension;
620 HeapFree( GetProcessHeap(), 0, template );
621 return ret;
624 /***********************************************************************
625 * GetSaveFileName (COMMDLG.2)
627 * Creates a dialog box for the user to select a file to save.
629 * RETURNS
630 * TRUE on success: user enters a valid file
631 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
633 * BUGS
634 * unknown. There are some FIXMEs left.
636 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn ) /* [in/out] address of structure with data*/
638 LPOPENFILENAME16 lpofn = MapSL(ofn);
639 LPDLGTEMPLATEA template = NULL;
640 OPENFILENAMEA ofn32;
641 BOOL ret;
643 if (!lpofn) return FALSE;
645 ofn32.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
646 ofn32.hwndOwner = HWND_32( lpofn->hwndOwner );
647 ofn32.lpstrFilter = MapSL( lpofn->lpstrFilter );
648 ofn32.lpstrCustomFilter = MapSL( lpofn->lpstrCustomFilter );
649 ofn32.nMaxCustFilter = lpofn->nMaxCustFilter;
650 ofn32.nFilterIndex = lpofn->nFilterIndex;
651 ofn32.lpstrFile = MapSL( lpofn->lpstrFile );
652 ofn32.nMaxFile = lpofn->nMaxFile;
653 ofn32.lpstrFileTitle = MapSL( lpofn->lpstrFileTitle );
654 ofn32.nMaxFileTitle = lpofn->nMaxFileTitle;
655 ofn32.lpstrInitialDir = MapSL( lpofn->lpstrInitialDir );
656 ofn32.lpstrTitle = MapSL( lpofn->lpstrTitle );
657 ofn32.Flags = (lpofn->Flags & ~OFN_ENABLETEMPLATE) | OFN_ENABLEHOOK;
658 ofn32.nFileOffset = lpofn->nFileOffset;
659 ofn32.nFileExtension = lpofn->nFileExtension;
660 ofn32.lpstrDefExt = MapSL( lpofn->lpstrDefExt );
661 ofn32.lCustData = lpofn->lCustData;
662 ofn32.lpfnHook = dummy_hook; /* this is to force old 3.1 dialog style */
664 if (lpofn->Flags & OFN_ENABLETEMPLATE)
666 HRSRC16 res = FindResource16( lpofn->hInstance, MapSL(lpofn->lpTemplateName), (LPCSTR)RT_DIALOG );
667 HGLOBAL16 handle = LoadResource16( lpofn->hInstance, res );
668 DWORD size = SizeofResource16( lpofn->hInstance, res );
669 void *ptr = LockResource16( handle );
671 if (ptr && (template = convert_dialog( ptr, size )))
673 ofn32.hInstance = (HINSTANCE)template;
674 ofn32.Flags |= OFN_ENABLETEMPLATEHANDLE;
676 FreeResource16( handle );
679 if (lpofn->Flags & OFN_ENABLEHOOK) ofn32.lpfnHook = alloc_hook( lpofn->lpfnHook );
681 if ((ret = GetSaveFileNameA( &ofn32 )))
683 lpofn->nFilterIndex = ofn32.nFilterIndex;
684 lpofn->nFileOffset = ofn32.nFileOffset;
685 lpofn->nFileExtension = ofn32.nFileExtension;
687 HeapFree( GetProcessHeap(), 0, template );
688 return ret;
692 /***********************************************************************
693 * GetFileTitle (COMMDLG.27)
695 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
697 return GetFileTitleA(lpFile, lpTitle, cbBuf);