1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FileOpenDlg.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _FILEOPENDLG_HXX_
32 #define _FILEOPENDLG_HXX_
34 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
38 #include <sal/types.h>
40 #ifndef _RTL_USTRING_HXX_
41 #include <rtl/ustring>
43 #include <rtl/ustrbuf.hxx>
45 #include "platform_xp.h"
46 #include "getfilenamewrapper.hxx"
48 // because we don't want to import the new W2k platform skd
49 // into our build environment if have stolen the definition
50 // for the new OPENFILENAME structure from the new headers
52 #ifndef _CDSIZEOF_STRUCT
53 #define _CDSIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
56 typedef struct _tagOFNA
{
61 LPSTR lpstrCustomFilter
;
68 LPCSTR lpstrInitialDir
;
75 LPOFNHOOKPROC lpfnHook
;
76 LPCSTR lpTemplateName
;
78 LPEDITMENU lpEditInfo
;
81 #if (_WIN32_WINNT >= 0x0500)
85 #endif // (_WIN32_WINNT >= 0x0500)
86 } _OPENFILENAMEA
, *_LPOPENFILENAMEA
;
88 typedef struct _tagOFNW
{
93 LPWSTR lpstrCustomFilter
;
98 LPWSTR lpstrFileTitle
;
100 LPCWSTR lpstrInitialDir
;
107 LPOFNHOOKPROC lpfnHook
;
108 LPCWSTR lpTemplateName
;
109 #if (_WIN32_WINNT >= 0x0500)
113 #endif // (_WIN32_WINNT >= 0x0500)
114 } _OPENFILENAMEW
, *_LPOPENFILENAMEW
;
117 typedef _OPENFILENAMEW _OPENFILENAME
;
118 typedef _LPOPENFILENAMEW _LPOPENFILENAME
;
120 typedef _OPENFILENAMEA _OPENFILENAME
;
121 typedef _LPOPENFILENAMEA _LPOPENFILENAME
;
124 #if (_WIN32_WINNT >= 0x0500)
125 #define _OPENFILENAME_SIZE_VERSION_400A _CDSIZEOF_STRUCT(_OPENFILENAMEA,lpTemplateName)
126 #define _OPENFILENAME_SIZE_VERSION_400W _CDSIZEOF_STRUCT(_OPENFILENAMEW,lpTemplateName)
128 #define _OPENFILENAME_SIZE_VERSION_400 _OPENFILENAME_SIZE_VERSION_400W
130 #define _OPENFILENAME_SIZE_VERSION_400 _OPENFILENAME_SIZE_VERSION_400A
133 #error _WIN32_WINNT seams not to be valid.
134 #endif // (_WIN32_WINNT >= 0x0500)
137 //-------------------------------------------------------------
138 // A simple wrapper class around the Win32 GetOpenFileName API.
139 // This class is not thread-safe and only one instance at a
141 //-------------------------------------------------------------
143 class CFileOpenDialog
147 // bFileOpenDialog idicates if we want a FileOpen or FileSave
149 // dwFlags see OPENFILENAME
150 // dwTemplateId - an ID for custom templates
151 // hInstance - an instance handle for the module
152 // which provides the custom template, unused if dwTemplateId
155 bool bFileOpenDialog
= sal_True
,
156 sal_uInt32 dwFlags
= OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
157 sal_uInt32 dwTemplateId
= 0,
158 HINSTANCE hInstance
= 0);
160 virtual ~CFileOpenDialog();
162 virtual void SAL_CALL
setTitle(const rtl::OUString
& aTitle
);
164 // to set a filter string using the M$ format
165 // e.g. FltName\0*.txt;*.rtf\0...\0\0
166 void SAL_CALL
setFilter(const rtl::OUString
& aFilter
);
168 // set the index of the current filter when the
169 // dialog is about to shown, the index starts with 1
170 // the function succeeded if the given filter index
171 // is greater than zero and is a valid position
172 // within filter string that was previously set
173 bool SAL_CALL
setFilterIndex(sal_uInt32 aIndex
);
175 // get the index of the currently selected filter
176 // the index of the returned filter starts with 1
177 sal_uInt32 SAL_CALL
getSelectedFilterIndex() const;
179 // set the name and optional the path of the
180 // file that will be initially be shown when
181 // the dialog will be displayed
182 virtual void SAL_CALL
setDefaultName(const rtl::OUString
& aName
);
184 // set the initial directory
185 virtual void SAL_CALL
setDisplayDirectory(const rtl::OUString
& aDirectory
);
187 // returns only the path of the selected file
188 virtual rtl::OUString SAL_CALL
getLastDisplayDirectory() const;
190 // returns the full file name including drive letter, path
191 // file name and file extension
192 virtual rtl::OUString SAL_CALL
getFullFileName() const;
194 // returns the file name and the file extension without
195 // drive letter and path
196 rtl::OUString SAL_CALL
getFileName() const;
198 // returns the file extension of the selected file
199 rtl::OUString SAL_CALL
getFileExtension();
201 // set a default extension, only the first three letters of
202 // the given extension will be used; the given extension
203 // should not contain a '.'
204 void SAL_CALL
setDefaultFileExtension(const rtl::OUString
& aExtension
);
206 // enables or disables the multiselection mode for
207 // the FileOpen/FileSave dialog
208 void SAL_CALL
setMultiSelectionMode(bool bMode
);
210 // returns whether multi-selection mode is enabled or not
211 bool SAL_CALL
getMultiSelectionMode() const;
213 // shows the dialog, calls preModal before
214 // showing the dialog and postModal after
215 // showing the dialog
216 // the method returns:
217 // 0 - when the dialog was canceled by the user
218 // 1 - when the dialog was closed with ok
219 // -1 - when an error occured
220 sal_Int16 SAL_CALL
doModal();
222 // returns the last dialog error that occured
223 sal_uInt32 SAL_CALL
getLastDialogError() const;
225 // retrievs the currently selected file
226 // including path and drive information
227 // can be called only if the dialog is
229 rtl::OUString SAL_CALL
getCurrentFilePath() const;
231 // retrievs the currently selected folder
232 rtl::OUString SAL_CALL
getCurrentFolderPath() const;
234 // retrievs the currently selected file name
235 // without drive and path
236 rtl::OUString SAL_CALL
getCurrentFileName() const;
239 // have to be overwritten when subclasses
240 // want to do special pre- and post-modal
243 // if preModal return true processing will
244 // continue else doModal exit without showing
245 // a dialog and returns -1
246 virtual bool SAL_CALL
preModal();
248 // post modal processing
249 // the function should accept only values returned from
250 // doModal and act appropriately
251 virtual void SAL_CALL
postModal(sal_Int16 nDialogResult
);
253 // message handler, to be overwritten by subclasses
254 virtual sal_uInt32 SAL_CALL
onShareViolation(const rtl::OUString
& aPathName
);
255 virtual sal_uInt32 SAL_CALL
onFileOk();
256 virtual void SAL_CALL
onSelChanged(HWND hwndListBox
);
257 virtual void SAL_CALL
onHelp();
259 // only called back if OFN_EXPLORER is set
260 virtual void SAL_CALL
onInitDone();
261 virtual void SAL_CALL
onFolderChanged();
262 virtual void SAL_CALL
onTypeChanged(sal_uInt32 nFilterIndex
);
264 virtual void SAL_CALL
onInitDialog(HWND hwndDlg
) = 0;
266 virtual sal_uInt32 SAL_CALL
onCtrlCommand(HWND hwndDlg
, sal_uInt16 ctrlId
, sal_uInt16 notifyCode
);
268 sal_uInt32 SAL_CALL
onWMNotify(HWND hwndChild
, LPOFNOTIFYW lpOfNotify
);
270 // we use non-virtual functions to do necessary work before
271 // calling the virtual funtions (see Gamma: Template method)
272 void SAL_CALL
handleInitDialog(HWND hwndDlg
, HWND hwndChild
);
276 // handle to the window of the
277 // FileOpen/FileSave dialog
278 // will be set on message
279 // WM_INITDIALOG, before this
280 // value is undefined
281 HWND m_hwndFileOpenDlg
;
282 HWND m_hwndFileOpenDlgChild
;
286 // we connect the instance with the dialog window using
287 // SetProp, with this function we can reconnect from
288 // callback functions to this instance
289 static CFileOpenDialog
* SAL_CALL
getCurrentInstance(HWND hwnd
);
291 void SAL_CALL
centerPositionToParent() const;
294 // FileOpen or FileSaveDialog
295 bool m_bFileOpenDialog
;
296 rtl::OUString m_dialogTitle
;
297 rtl::OUString m_displayDirectory
;
298 rtl::OUString m_defaultExtension
;
300 mutable rtl::OUStringBuffer m_filterBuffer
;
301 mutable rtl::OUStringBuffer m_fileTitleBuffer
;
302 mutable rtl::OUStringBuffer m_helperBuffer
;
303 mutable rtl::OUStringBuffer m_fileNameBuffer
;
305 CGetFileNameWrapper m_GetFileNameWrapper
;
307 WNDPROC m_pfnBaseDlgProc
;
310 static unsigned int CALLBACK
ofnHookProc(
311 HWND hChildDlg
, // handle to child dialog box
312 unsigned int uiMsg
, // message identifier
313 WPARAM wParam
, // message parameter
314 LPARAM lParam
// message parameter
317 // we have to subclass the dialog in order
318 // to clean up the window property we are
319 // using to connect the window with a class
320 // instance in WM_NCDESTROY
321 static LRESULT CALLBACK
BaseDlgProc(
322 HWND hWnd
, UINT wMessage
, WPARAM wParam
, LPARAM lParam
);
325 // avoid copy and assignment
326 CFileOpenDialog(const CFileOpenDialog
&);
327 CFileOpenDialog
& operator=(const CFileOpenDialog
&);