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
26 #include "wine/winbase16.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
;
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;
51 static inline void copy_dword( WORD
**out
, const char **in
)
53 *(DWORD
*)*out
= *(DWORD
*)*in
;
55 *out
+= sizeof(DWORD
) / sizeof(WORD
);
58 static LPDLGTEMPLATEA
convert_dialog( const char *p
, DWORD size
)
61 WORD len
, count
, *out
, *end
;
63 if (!(dlg
= HeapAlloc( GetProcessHeap(), 0, size
* 2 ))) return NULL
;
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 */
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 */
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 */
110 if (*p
& 0x80) /* class */
115 else copy_string( &out
, &p
, end
- out
);
117 if (*p
& 0x80) /* window */
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
);
128 out
+= (len
+ 1) / sizeof(WORD
);
131 assert( out
<= end
);
135 static UINT_PTR CALLBACK
dummy_hook( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
140 /***********************************************************************
141 * FileOpenDlgProc (COMMDLG.6)
143 BOOL16 CALLBACK
FileOpenDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
145 FIXME( "%04x %04x %04x %08lx: stub\n", hWnd16
, wMsg
, wParam
, lParam
);
149 /***********************************************************************
150 * FileSaveDlgProc (COMMDLG.7)
152 BOOL16 CALLBACK
FileSaveDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
154 FIXME( "%04x %04x %04x %08lx: stub\n", hWnd16
, wMsg
, wParam
, lParam
);
158 /***********************************************************************
159 * GetOpenFileName (COMMDLG.1)
161 * Creates a dialog box for the user to select a file to open.
164 * TRUE on success: user selected a valid file
165 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
168 * unknown, there are some FIXMEs left.
170 BOOL16 WINAPI
GetOpenFileName16( SEGPTR ofn
) /* [in/out] address of structure with data*/
172 LPOPENFILENAME16 lpofn
= MapSL(ofn
);
173 LPDLGTEMPLATEA
template = NULL
;
177 if (!lpofn
) return FALSE
;
179 ofn32
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
180 ofn32
.hwndOwner
= HWND_32( lpofn
->hwndOwner
);
181 ofn32
.lpstrFilter
= MapSL( lpofn
->lpstrFilter
);
182 ofn32
.lpstrCustomFilter
= MapSL( lpofn
->lpstrCustomFilter
);
183 ofn32
.nMaxCustFilter
= lpofn
->nMaxCustFilter
;
184 ofn32
.nFilterIndex
= lpofn
->nFilterIndex
;
185 ofn32
.lpstrFile
= MapSL( lpofn
->lpstrFile
);
186 ofn32
.nMaxFile
= lpofn
->nMaxFile
;
187 ofn32
.lpstrFileTitle
= MapSL( lpofn
->lpstrFileTitle
);
188 ofn32
.nMaxFileTitle
= lpofn
->nMaxFileTitle
;
189 ofn32
.lpstrInitialDir
= MapSL( lpofn
->lpstrInitialDir
);
190 ofn32
.lpstrTitle
= MapSL( lpofn
->lpstrTitle
);
191 ofn32
.Flags
= (lpofn
->Flags
& ~OFN_ENABLETEMPLATE
) | OFN_ENABLEHOOK
;
192 ofn32
.nFileOffset
= lpofn
->nFileOffset
;
193 ofn32
.nFileExtension
= lpofn
->nFileExtension
;
194 ofn32
.lpstrDefExt
= MapSL( lpofn
->lpstrDefExt
);
195 ofn32
.lCustData
= lpofn
->lCustData
;
196 ofn32
.lpfnHook
= dummy_hook
; /* this is to force old 3.1 dialog style */
198 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
200 HRSRC16 res
= FindResource16( lpofn
->hInstance
, MapSL(lpofn
->lpTemplateName
), (LPCSTR
)RT_DIALOG
);
201 HGLOBAL16 handle
= LoadResource16( lpofn
->hInstance
, res
);
202 DWORD size
= SizeofResource16( lpofn
->hInstance
, res
);
203 void *ptr
= LockResource16( handle
);
205 if (ptr
&& (template = convert_dialog( ptr
, size
)))
207 ofn32
.hInstance
= (HINSTANCE
)template;
208 ofn32
.Flags
|= OFN_ENABLETEMPLATEHANDLE
;
210 FreeResource16( handle
);
213 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
214 FIXME( "custom hook %p no longer supported\n", lpofn
->lpfnHook
);
216 if ((ret
= GetOpenFileNameA( &ofn32
)))
218 lpofn
->nFilterIndex
= ofn32
.nFilterIndex
;
219 lpofn
->nFileOffset
= ofn32
.nFileOffset
;
220 lpofn
->nFileExtension
= ofn32
.nFileExtension
;
222 HeapFree( GetProcessHeap(), 0, template );
226 /***********************************************************************
227 * GetSaveFileName (COMMDLG.2)
229 * Creates a dialog box for the user to select a file to save.
232 * TRUE on success: user enters a valid file
233 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
236 * unknown. There are some FIXMEs left.
238 BOOL16 WINAPI
GetSaveFileName16( SEGPTR ofn
) /* [in/out] address of structure with data*/
240 LPOPENFILENAME16 lpofn
= MapSL(ofn
);
241 LPDLGTEMPLATEA
template = NULL
;
245 if (!lpofn
) return FALSE
;
247 ofn32
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
248 ofn32
.hwndOwner
= HWND_32( lpofn
->hwndOwner
);
249 ofn32
.lpstrFilter
= MapSL( lpofn
->lpstrFilter
);
250 ofn32
.lpstrCustomFilter
= MapSL( lpofn
->lpstrCustomFilter
);
251 ofn32
.nMaxCustFilter
= lpofn
->nMaxCustFilter
;
252 ofn32
.nFilterIndex
= lpofn
->nFilterIndex
;
253 ofn32
.lpstrFile
= MapSL( lpofn
->lpstrFile
);
254 ofn32
.nMaxFile
= lpofn
->nMaxFile
;
255 ofn32
.lpstrFileTitle
= MapSL( lpofn
->lpstrFileTitle
);
256 ofn32
.nMaxFileTitle
= lpofn
->nMaxFileTitle
;
257 ofn32
.lpstrInitialDir
= MapSL( lpofn
->lpstrInitialDir
);
258 ofn32
.lpstrTitle
= MapSL( lpofn
->lpstrTitle
);
259 ofn32
.Flags
= (lpofn
->Flags
& ~OFN_ENABLETEMPLATE
) | OFN_ENABLEHOOK
;
260 ofn32
.nFileOffset
= lpofn
->nFileOffset
;
261 ofn32
.nFileExtension
= lpofn
->nFileExtension
;
262 ofn32
.lpstrDefExt
= MapSL( lpofn
->lpstrDefExt
);
263 ofn32
.lCustData
= lpofn
->lCustData
;
264 ofn32
.lpfnHook
= dummy_hook
; /* this is to force old 3.1 dialog style */
266 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
268 HRSRC16 res
= FindResource16( lpofn
->hInstance
, MapSL(lpofn
->lpTemplateName
), (LPCSTR
)RT_DIALOG
);
269 HGLOBAL16 handle
= LoadResource16( lpofn
->hInstance
, res
);
270 DWORD size
= SizeofResource16( lpofn
->hInstance
, res
);
271 void *ptr
= LockResource16( handle
);
273 if (ptr
&& (template = convert_dialog( ptr
, size
)))
275 ofn32
.hInstance
= (HINSTANCE
)template;
276 ofn32
.Flags
|= OFN_ENABLETEMPLATEHANDLE
;
278 FreeResource16( handle
);
281 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
282 FIXME( "custom hook %p no longer supported\n", lpofn
->lpfnHook
);
284 if ((ret
= GetSaveFileNameA( &ofn32
)))
286 lpofn
->nFilterIndex
= ofn32
.nFilterIndex
;
287 lpofn
->nFileOffset
= ofn32
.nFileOffset
;
288 lpofn
->nFileExtension
= ofn32
.nFileExtension
;
290 HeapFree( GetProcessHeap(), 0, template );
295 /***********************************************************************
296 * GetFileTitle (COMMDLG.27)
298 short WINAPI
GetFileTitle16(LPCSTR lpFile
, LPSTR lpTitle
, UINT16 cbBuf
)
300 return GetFileTitleA(lpFile
, lpTitle
, cbBuf
);