1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //------------------------------------------------------------------------
32*cdf0e10cSrcweir // includes
33*cdf0e10cSrcweir //------------------------------------------------------------------------
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "shared.hxx"
36*cdf0e10cSrcweir #include "WinFileOpenImpl.hxx"
37*cdf0e10cSrcweir #include <osl/diagnose.h>
38*cdf0e10cSrcweir #include <osl/file.hxx>
39*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ListBoxControlActions.hpp>
45*cdf0e10cSrcweir #include "..\misc\WinImplHelper.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #ifndef _FILEPICKER_HXX_
48*cdf0e10cSrcweir #include "filepicker.hxx"
49*cdf0e10cSrcweir #endif
50*cdf0e10cSrcweir #include "controlaccess.hxx"
51*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
52*cdf0e10cSrcweir #include <rtl/string.hxx>
53*cdf0e10cSrcweir #include <osl/thread.hxx>
54*cdf0e10cSrcweir #include "filepickerstate.hxx"
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //------------------------------------------------------------------------
57*cdf0e10cSrcweir // namespace directives
58*cdf0e10cSrcweir //------------------------------------------------------------------------
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir using namespace com::sun::star;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir using com::sun::star::ui::dialogs::FilePickerEvent;
63*cdf0e10cSrcweir using com::sun::star::lang::IllegalArgumentException;
64*cdf0e10cSrcweir using com::sun::star::ui::dialogs::XFilePicker2;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
67*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
68*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::ListboxControlActions;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir //-------------------------------------------------------------------------
71*cdf0e10cSrcweir // to distinguish what to do in the enum child window callback function
72*cdf0e10cSrcweir //-------------------------------------------------------------------------
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir enum ECW_ACTION_T
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     INIT_CUSTOM_CONTROLS,
77*cdf0e10cSrcweir     CACHE_CONTROL_VALUES
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir struct EnumParam
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     ECW_ACTION_T        m_action;
83*cdf0e10cSrcweir     CWinFileOpenImpl*   m_instance;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     EnumParam( ECW_ACTION_T action, CWinFileOpenImpl* instance ):
86*cdf0e10cSrcweir         m_action( action ),
87*cdf0e10cSrcweir         m_instance( instance )
88*cdf0e10cSrcweir     {}
89*cdf0e10cSrcweir };
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir //-------------------------------------------------------------------------
92*cdf0e10cSrcweir // ctor
93*cdf0e10cSrcweir //-------------------------------------------------------------------------
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir CWinFileOpenImpl::CWinFileOpenImpl(
96*cdf0e10cSrcweir 	CFilePicker* aFilePicker,
97*cdf0e10cSrcweir 	sal_Bool bFileOpenDialog,
98*cdf0e10cSrcweir 	sal_uInt32 dwFlags,
99*cdf0e10cSrcweir 	sal_uInt32 dwTemplateId,
100*cdf0e10cSrcweir 	HINSTANCE hInstance) :
101*cdf0e10cSrcweir 	CFileOpenDialog(bFileOpenDialog, dwFlags, dwTemplateId, hInstance),
102*cdf0e10cSrcweir 	m_filterContainer(new CFilterContainer()),
103*cdf0e10cSrcweir 	m_Preview(new CPreviewAdapter(hInstance)),
104*cdf0e10cSrcweir 	m_CustomControlFactory(new CCustomControlFactory()),
105*cdf0e10cSrcweir 	m_CustomControls(m_CustomControlFactory->CreateCustomControlContainer()),
106*cdf0e10cSrcweir 	m_FilePicker(aFilePicker),
107*cdf0e10cSrcweir     m_bInitialSelChanged(sal_True),
108*cdf0e10cSrcweir     m_HelpPopupWindow(hInstance, m_hwndFileOpenDlg),
109*cdf0e10cSrcweir     m_ExecuteFilePickerState(new CExecuteFilePickerState()),
110*cdf0e10cSrcweir     m_NonExecuteFilePickerState(new CNonExecuteFilePickerState())
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir     m_FilePickerState = m_NonExecuteFilePickerState;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir //------------------------------------------------------------------------
116*cdf0e10cSrcweir // dtor
117*cdf0e10cSrcweir //------------------------------------------------------------------------
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir CWinFileOpenImpl::~CWinFileOpenImpl()
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir     delete m_ExecuteFilePickerState;
122*cdf0e10cSrcweir     delete m_NonExecuteFilePickerState;
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir //------------------------------------------------------------------------
126*cdf0e10cSrcweir // we expect the directory in URL format
127*cdf0e10cSrcweir //------------------------------------------------------------------------
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir void CWinFileOpenImpl::setDisplayDirectory(const rtl::OUString& aDirectory)
130*cdf0e10cSrcweir 	throw( IllegalArgumentException, uno::RuntimeException )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     rtl::OUString aSysDirectory;
133*cdf0e10cSrcweir 	if( aDirectory.getLength() > 0)
134*cdf0e10cSrcweir 	{
135*cdf0e10cSrcweir         if ( ::osl::FileBase::E_None !=
136*cdf0e10cSrcweir              ::osl::FileBase::getSystemPathFromFileURL(aDirectory,aSysDirectory))
137*cdf0e10cSrcweir             throw IllegalArgumentException(
138*cdf0e10cSrcweir 				rtl::OUString::createFromAscii("Invalid directory"),
139*cdf0e10cSrcweir 				static_cast<XFilePicker2*>(m_FilePicker), 1);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         // we ensure that there is a trailing '/' at the end of
142*cdf0e10cSrcweir         // he given file url, because the windows functions only
143*cdf0e10cSrcweir         // works correctly when providing "c:\" or an environment
144*cdf0e10cSrcweir         // variable like "=c:=c:\.." etc. is set, else the
145*cdf0e10cSrcweir         // FolderPicker would stand in the root of the shell
146*cdf0e10cSrcweir         // hierarchie which is the desktop folder
147*cdf0e10cSrcweir         if ( aSysDirectory.lastIndexOf(BACKSLASH) != (aSysDirectory.getLength() - 1))
148*cdf0e10cSrcweir             aSysDirectory += BACKSLASH;
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	// call base class method
152*cdf0e10cSrcweir 	CFileOpenDialog::setDisplayDirectory(aSysDirectory);
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir //------------------------------------------------------------------------
156*cdf0e10cSrcweir // we return the directory in URL format
157*cdf0e10cSrcweir //------------------------------------------------------------------------
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir rtl::OUString CWinFileOpenImpl::getDisplayDirectory() throw(uno::RuntimeException)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     return m_FilePickerState->getDisplayDirectory(this);
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
165*cdf0e10cSrcweir //
166*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::setDefaultName(const rtl::OUString& aName)
169*cdf0e10cSrcweir 	throw( IllegalArgumentException, uno::RuntimeException )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     // we don't set the default name directly
172*cdf0e10cSrcweir     // because this influences how the file open
173*cdf0e10cSrcweir     // dialog sets the initial path when it is about
174*cdf0e10cSrcweir     // to open (see MSDN: OPENFILENAME)
175*cdf0e10cSrcweir     // so we save the default name which should
176*cdf0e10cSrcweir     // appear in the file-name-box and set
177*cdf0e10cSrcweir     // this name when processing onInitDone
178*cdf0e10cSrcweir     m_defaultName = aName;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
182*cdf0e10cSrcweir // return format: URL
183*cdf0e10cSrcweir // if multiselection is allowed there are two different cases
184*cdf0e10cSrcweir // 1. one file selected: the sequence contains one entry path\filename.ext
185*cdf0e10cSrcweir // 2. multiple files selected: the sequence contains multiple entries
186*cdf0e10cSrcweir //    the first entry is the path url, all other entries are file names
187*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL CWinFileOpenImpl::getFiles()
190*cdf0e10cSrcweir 	throw(uno::RuntimeException)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     return m_FilePickerState->getFiles(this);
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
196*cdf0e10cSrcweir // shows the FileOpen/FileSave dialog
197*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir sal_Int16 SAL_CALL CWinFileOpenImpl::execute(  ) throw(uno::RuntimeException)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	sal_Int16 rc = CFileOpenDialog::doModal();
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	if (1 == rc)
204*cdf0e10cSrcweir         rc = ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK;
205*cdf0e10cSrcweir 	else if (0 == rc)
206*cdf0e10cSrcweir         rc = ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
207*cdf0e10cSrcweir 	else
208*cdf0e10cSrcweir 		throw uno::RuntimeException(
209*cdf0e10cSrcweir 			rtl::OUString::createFromAscii("Error executing dialog"),
210*cdf0e10cSrcweir 			static_cast<XFilePicker2*>(m_FilePicker));
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	return rc;
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
216*cdf0e10cSrcweir // appends a new filter
217*cdf0e10cSrcweir // returns false if the title (aTitle) was already added or the title or the filter are
218*cdf0e10cSrcweir // empty
219*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::appendFilter(const rtl::OUString& aTitle, const rtl::OUString& aFilter)
222*cdf0e10cSrcweir 	throw(IllegalArgumentException, uno::RuntimeException)
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	sal_Bool bRet = m_filterContainer->addFilter(aTitle, aFilter);
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     if (!bRet)
227*cdf0e10cSrcweir         throw IllegalArgumentException(
228*cdf0e10cSrcweir             rtl::OUString::createFromAscii("filter already exists"),
229*cdf0e10cSrcweir             static_cast<XFilePicker2*>(m_FilePicker), 1);
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     // #95345# see MSDN OPENFILENAME
232*cdf0e10cSrcweir     // If nFilterIndex is zero and lpstrCustomFilter is NULL,
233*cdf0e10cSrcweir     // the system uses the first filter in the lpstrFilter buffer.
234*cdf0e10cSrcweir     // to reflect this we must set the filter index so that calls
235*cdf0e10cSrcweir     // to getSelectedFilterIndex without explicitly calling
236*cdf0e10cSrcweir     // setFilterIndex before does not return 0 which leads to a
237*cdf0e10cSrcweir     // false state
238*cdf0e10cSrcweir     if (0 == getSelectedFilterIndex())
239*cdf0e10cSrcweir         CFileOpenDialog::setFilterIndex(1);
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
243*cdf0e10cSrcweir // sets a current filter
244*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::setCurrentFilter(const rtl::OUString& aTitle)
247*cdf0e10cSrcweir 	throw( IllegalArgumentException, uno::RuntimeException)
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir 	sal_Int32 filterPos = m_filterContainer->getFilterPos(aTitle);
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	if (filterPos < 0)
252*cdf0e10cSrcweir 		throw IllegalArgumentException(
253*cdf0e10cSrcweir 			rtl::OUString::createFromAscii("filter doesn't exist"),
254*cdf0e10cSrcweir 			static_cast<XFilePicker2*>(m_FilePicker), 1);
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 	// filter index of the base class starts with 1
257*cdf0e10cSrcweir 	CFileOpenDialog::setFilterIndex(filterPos + 1);
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
261*cdf0e10cSrcweir // returns the currently selected filter
262*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir rtl::OUString SAL_CALL CWinFileOpenImpl::getCurrentFilter() throw(uno::RuntimeException)
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	sal_uInt32 nIndex = getSelectedFilterIndex();
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	rtl::OUString currentFilter;
269*cdf0e10cSrcweir 	if (nIndex > 0)
270*cdf0e10cSrcweir 	{
271*cdf0e10cSrcweir 		// filter index of the base class starts with 1
272*cdf0e10cSrcweir 		if (!m_filterContainer->getFilter(nIndex - 1, currentFilter)) {
273*cdf0e10cSrcweir             OSL_ASSERT(false);
274*cdf0e10cSrcweir         }
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	return currentFilter;
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
281*cdf0e10cSrcweir //
282*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir inline void SAL_CALL CWinFileOpenImpl::appendFilterGroupSeparator()
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir     m_filterContainer->addFilter(FILTER_SEPARATOR, ALL_FILES_WILDCARD, ALLOW_DUPLICATES);
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
290*cdf0e10cSrcweir // XFilterGroupManager
291*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::appendFilterGroup(const rtl::OUString& sGroupTitle, const uno::Sequence<beans::StringPair>& aFilters)
294*cdf0e10cSrcweir     throw (IllegalArgumentException, uno::RuntimeException)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir     (void) sGroupTitle; // avoid warning
297*cdf0e10cSrcweir     OSL_ENSURE(0 == sGroupTitle.getLength(), "appendFilterGroup: Parameter 'GroupTitle' currently ignored");
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     sal_Int32 nFilters = aFilters.getLength();
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     OSL_PRECOND(nFilters > 0, "Empty filter list");
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     if (nFilters > 0)
304*cdf0e10cSrcweir     {
305*cdf0e10cSrcweir         // append a separator before the next group if
306*cdf0e10cSrcweir         // there is already a group of filters
307*cdf0e10cSrcweir         if (m_filterContainer->numFilter() > 0)
308*cdf0e10cSrcweir             appendFilterGroupSeparator();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir         for (int i = 0; i < nFilters; i++)
311*cdf0e10cSrcweir             appendFilter(aFilters[i].First, aFilters[i].Second);
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir //=================================================================================================================
316*cdf0e10cSrcweir // XExtendedFilePicker
317*cdf0e10cSrcweir //=================================================================================================================
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir // #i90917: Due to a different feature set for the system-dependent file pickers
320*cdf0e10cSrcweir // it's possible that generic code (e.g. sfx2) provides control ids
321*cdf0e10cSrcweir // (see ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR) which are NOT
322*cdf0e10cSrcweir // available on all platforms. This filter function should filter out control ids
323*cdf0e10cSrcweir // which are only available on KDE/GTK file pickers.
324*cdf0e10cSrcweir static bool filterControlCommand( sal_Int16 nControlId )
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir 	if ( nControlId == LISTBOX_FILTER_SELECTOR )
327*cdf0e10cSrcweir 		return true;
328*cdf0e10cSrcweir 	return false;
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::setValue(sal_Int16 aControlId, sal_Int16 aControlAction, const uno::Any& aValue)
332*cdf0e10cSrcweir 	throw(uno::RuntimeException)
333*cdf0e10cSrcweir {
334*cdf0e10cSrcweir     OSL_ASSERT(m_FilePickerState);
335*cdf0e10cSrcweir 	if ( !filterControlCommand( aControlId ))
336*cdf0e10cSrcweir 		m_FilePickerState->setValue(aControlId, aControlAction, aValue);
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
340*cdf0e10cSrcweir // returns the value of an custom template element
341*cdf0e10cSrcweir // we assume that there are only checkboxes or comboboxes
342*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir uno::Any SAL_CALL CWinFileOpenImpl::getValue(sal_Int16 aControlId, sal_Int16 aControlAction)
345*cdf0e10cSrcweir 	throw(uno::RuntimeException)
346*cdf0e10cSrcweir {
347*cdf0e10cSrcweir     OSL_ASSERT(m_FilePickerState);
348*cdf0e10cSrcweir 	if ( !filterControlCommand( aControlId ))
349*cdf0e10cSrcweir 		return m_FilePickerState->getValue(aControlId, aControlAction);
350*cdf0e10cSrcweir 	else
351*cdf0e10cSrcweir 		return uno::Any();
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
355*cdf0e10cSrcweir // enables a custom template element
356*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::enableControl(sal_Int16 ControlID, sal_Bool bEnable)
359*cdf0e10cSrcweir 	throw(uno::RuntimeException)
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     OSL_ASSERT(m_FilePickerState);
362*cdf0e10cSrcweir     if ( !filterControlCommand( ControlID ))
363*cdf0e10cSrcweir 		m_FilePickerState->enableControl(ControlID, bEnable);
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
367*cdf0e10cSrcweir //
368*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::setLabel( sal_Int16 aControlId, const rtl::OUString& aLabel )
371*cdf0e10cSrcweir     throw (uno::RuntimeException)
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     OSL_ASSERT(m_FilePickerState);
374*cdf0e10cSrcweir 	if ( !filterControlCommand( aControlId ))
375*cdf0e10cSrcweir 		m_FilePickerState->setLabel(aControlId, aLabel);
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
379*cdf0e10cSrcweir //
380*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir rtl::OUString SAL_CALL CWinFileOpenImpl::getLabel( sal_Int16 aControlId )
383*cdf0e10cSrcweir 		throw (uno::RuntimeException)
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir     OSL_ASSERT(m_FilePickerState);
386*cdf0e10cSrcweir 	if ( !filterControlCommand( aControlId ))
387*cdf0e10cSrcweir 		return m_FilePickerState->getLabel(aControlId);
388*cdf0e10cSrcweir 	else
389*cdf0e10cSrcweir 		return rtl::OUString();
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
393*cdf0e10cSrcweir //
394*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir uno::Sequence<sal_Int16> SAL_CALL CWinFileOpenImpl::getSupportedImageFormats()
397*cdf0e10cSrcweir     throw (uno::RuntimeException)
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir     return m_Preview->getSupportedImageFormats();
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
403*cdf0e10cSrcweir //
404*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir sal_Int32 SAL_CALL CWinFileOpenImpl::getTargetColorDepth()
407*cdf0e10cSrcweir     throw (uno::RuntimeException)
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir     return m_Preview->getTargetColorDepth();
410*cdf0e10cSrcweir }
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
413*cdf0e10cSrcweir //
414*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableWidth()
417*cdf0e10cSrcweir         throw (uno::RuntimeException)
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir     return m_Preview->getAvailableWidth();
420*cdf0e10cSrcweir }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
423*cdf0e10cSrcweir //
424*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableHeight()
427*cdf0e10cSrcweir     throw (uno::RuntimeException)
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir     return m_Preview->getAvailableHeight();
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
433*cdf0e10cSrcweir //
434*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::setImage(sal_Int16 aImageFormat, const uno::Any& aImage)
437*cdf0e10cSrcweir     throw (IllegalArgumentException, uno::RuntimeException)
438*cdf0e10cSrcweir {
439*cdf0e10cSrcweir     m_Preview->setImage(aImageFormat,aImage);
440*cdf0e10cSrcweir }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
443*cdf0e10cSrcweir //
444*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir sal_Bool SAL_CALL CWinFileOpenImpl::setShowState(sal_Bool bShowState)
447*cdf0e10cSrcweir         throw (uno::RuntimeException)
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     return m_Preview->setShowState(bShowState);
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
453*cdf0e10cSrcweir //
454*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir sal_Bool SAL_CALL CWinFileOpenImpl::getShowState()
457*cdf0e10cSrcweir     throw (uno::RuntimeException)
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     return m_Preview->getShowState();
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
463*cdf0e10cSrcweir //
464*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::cancel()
467*cdf0e10cSrcweir {
468*cdf0e10cSrcweir     if (IsWindow(m_hwndFileOpenDlg))
469*cdf0e10cSrcweir     {
470*cdf0e10cSrcweir         // simulate a mouse click to the
471*cdf0e10cSrcweir         // cancel button
472*cdf0e10cSrcweir         PostMessage(
473*cdf0e10cSrcweir             m_hwndFileOpenDlg,
474*cdf0e10cSrcweir             WM_COMMAND,
475*cdf0e10cSrcweir             MAKEWPARAM(IDCANCEL,BN_CLICKED),
476*cdf0e10cSrcweir             (LPARAM)GetDlgItem(m_hwndFileOpenDlg, IDCANCEL));
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
481*cdf0e10cSrcweir // returns the id of a custom template element
482*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir sal_Int16 SAL_CALL CWinFileOpenImpl::getFocused()
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir 	int nID = GetDlgCtrlID(GetFocus());
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 	// we don't forward id's of standard file open
489*cdf0e10cSrcweir     // dialog elements (ctlFirst is defined in dlgs.h
490*cdf0e10cSrcweir     // in MS Platform SDK)
491*cdf0e10cSrcweir 	if (nID >= ctlFirst)
492*cdf0e10cSrcweir 		nID = 0;
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 	return sal::static_int_cast< sal_Int16 >(nID);
495*cdf0e10cSrcweir }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
498*cdf0e10cSrcweir //
499*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir inline sal_Bool SAL_CALL CWinFileOpenImpl::IsCustomControlHelpRequested(LPHELPINFO lphi) const
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir 	return ((lphi->iCtrlId != IDOK) && (lphi->iCtrlId != IDCANCEL) && (lphi->iCtrlId < ctlFirst));
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
507*cdf0e10cSrcweir // our own DlgProc because we do subclass the dialog
508*cdf0e10cSrcweir // we catch the WM_NCDESTROY message in order to erase an entry in our static map
509*cdf0e10cSrcweir // if one instance dies
510*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir LRESULT CALLBACK CWinFileOpenImpl::SubClassFunc(
513*cdf0e10cSrcweir     HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	unsigned int lResult = 0;
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     CWinFileOpenImpl* pImpl = dynamic_cast<CWinFileOpenImpl*>(getCurrentInstance(hWnd));
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 	switch(wMessage)
520*cdf0e10cSrcweir 	{
521*cdf0e10cSrcweir 	case WM_HELP:
522*cdf0e10cSrcweir 	{
523*cdf0e10cSrcweir         LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir         if (pImpl->IsCustomControlHelpRequested(lphi))
526*cdf0e10cSrcweir 		    pImpl->onCustomControlHelpRequest(lphi);
527*cdf0e10cSrcweir         else
528*cdf0e10cSrcweir             lResult = CallWindowProc(
529*cdf0e10cSrcweir 			    reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
530*cdf0e10cSrcweir 			    hWnd,wMessage,wParam,lParam);
531*cdf0e10cSrcweir 	}
532*cdf0e10cSrcweir 	break;
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 	case WM_SIZE:
535*cdf0e10cSrcweir 		lResult = CallWindowProc(
536*cdf0e10cSrcweir 			reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
537*cdf0e10cSrcweir 			hWnd,wMessage,wParam,lParam);
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 		pImpl->onWMSize();
540*cdf0e10cSrcweir 		break;
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 	case WM_WINDOWPOSCHANGED:
543*cdf0e10cSrcweir 		lResult = CallWindowProc(
544*cdf0e10cSrcweir 			reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
545*cdf0e10cSrcweir 			hWnd,wMessage,wParam,lParam);
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 		pImpl->onWMWindowPosChanged();
548*cdf0e10cSrcweir 		break;
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir 	case WM_SHOWWINDOW:
551*cdf0e10cSrcweir 		lResult = CallWindowProc(
552*cdf0e10cSrcweir 			reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
553*cdf0e10cSrcweir 			hWnd,wMessage,wParam,lParam);
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 		pImpl->onWMShow((sal_Bool)wParam);
556*cdf0e10cSrcweir 		break;
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir     case WM_NCDESTROY:
559*cdf0e10cSrcweir 		// restore the old window proc
560*cdf0e10cSrcweir 		SetWindowLong(hWnd, GWL_WNDPROC,
561*cdf0e10cSrcweir 			reinterpret_cast<LONG>(pImpl->m_pfnOldDlgProc));
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 		lResult = CallWindowProc(
564*cdf0e10cSrcweir 			reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
565*cdf0e10cSrcweir 			hWnd,wMessage,wParam,lParam);
566*cdf0e10cSrcweir 		break;
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 	default:
569*cdf0e10cSrcweir 		lResult = CallWindowProc(
570*cdf0e10cSrcweir 			reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
571*cdf0e10cSrcweir 			hWnd,wMessage,wParam,lParam);
572*cdf0e10cSrcweir 	break;
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 	} // switch
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 	return lResult;
577*cdf0e10cSrcweir }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir //-----------------------------------------------------------------
580*cdf0e10cSrcweir //
581*cdf0e10cSrcweir //-----------------------------------------------------------------
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::InitControlLabel(HWND hWnd)
584*cdf0e10cSrcweir {
585*cdf0e10cSrcweir     //-----------------------------------------
586*cdf0e10cSrcweir     // set the labels for all extendet controls
587*cdf0e10cSrcweir     //-----------------------------------------
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir     sal_Int16 aCtrlId = sal::static_int_cast< sal_Int16 >(GetDlgCtrlID(hWnd));
590*cdf0e10cSrcweir     rtl::OUString aLabel = m_ResProvider.getResString(aCtrlId);
591*cdf0e10cSrcweir     if (aLabel.getLength())
592*cdf0e10cSrcweir         setLabel(aCtrlId, aLabel);
593*cdf0e10cSrcweir }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir //-----------------------------------------------------------------
596*cdf0e10cSrcweir // There may be problems with the layout of our custom controls,
597*cdf0e10cSrcweir // so that they are not aligned with the standard controls of the
598*cdf0e10cSrcweir // FileOpen dialog.
599*cdf0e10cSrcweir // We use a simple algorithm to move the custom controls to their
600*cdf0e10cSrcweir // proper position and resize them.
601*cdf0e10cSrcweir // Our approach is to align all static text controls with the
602*cdf0e10cSrcweir // static text control "File name" of the FileOpen dialog,
603*cdf0e10cSrcweir // all checkboxes and all list/comboboxes will be left aligned with
604*cdf0e10cSrcweir // the standard combobox edt1 (defined in MS platform sdk dlgs.h)
605*cdf0e10cSrcweir // and all push buttons will be left aligned with the standard
606*cdf0e10cSrcweir // "OK" button
607*cdf0e10cSrcweir //-----------------------------------------------------------------
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::InitCustomControlContainer(HWND hCustomControl)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir 	m_CustomControls->AddControl(
612*cdf0e10cSrcweir 		m_CustomControlFactory->CreateCustomControl(hCustomControl,m_hwndFileOpenDlg));
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir //-----------------------------------------------------------------
616*cdf0e10cSrcweir //
617*cdf0e10cSrcweir //-----------------------------------------------------------------
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::CacheControlState(HWND hWnd)
620*cdf0e10cSrcweir {
621*cdf0e10cSrcweir     OSL_ASSERT(m_FilePickerState && m_NonExecuteFilePickerState);
622*cdf0e10cSrcweir     m_ExecuteFilePickerState->cacheControlState(hWnd, m_NonExecuteFilePickerState);
623*cdf0e10cSrcweir }
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir //-----------------------------------------------------------------
626*cdf0e10cSrcweir //
627*cdf0e10cSrcweir //-----------------------------------------------------------------
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir BOOL CALLBACK CWinFileOpenImpl::EnumChildWndProc(HWND hWnd, LPARAM lParam)
630*cdf0e10cSrcweir {
631*cdf0e10cSrcweir     EnumParam* enumParam    = (EnumParam*)lParam;
632*cdf0e10cSrcweir     CWinFileOpenImpl* pImpl = enumParam->m_instance;
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir     OSL_ASSERT(pImpl);
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir     sal_Bool bRet = sal_True;
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir     switch(enumParam->m_action)
639*cdf0e10cSrcweir     {
640*cdf0e10cSrcweir     case INIT_CUSTOM_CONTROLS:
641*cdf0e10cSrcweir         pImpl->InitControlLabel(hWnd);
642*cdf0e10cSrcweir 		pImpl->InitCustomControlContainer(hWnd);
643*cdf0e10cSrcweir 		break;
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     case CACHE_CONTROL_VALUES:
646*cdf0e10cSrcweir         pImpl->CacheControlState(hWnd);
647*cdf0e10cSrcweir     break;
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir     default:
650*cdf0e10cSrcweir         // should not end here
651*cdf0e10cSrcweir         OSL_ASSERT(sal_False);
652*cdf0e10cSrcweir     }
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir     return bRet;
655*cdf0e10cSrcweir }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir //-----------------------------------------------------------------
658*cdf0e10cSrcweir //
659*cdf0e10cSrcweir //-----------------------------------------------------------------
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir sal_uInt32 SAL_CALL CWinFileOpenImpl::onFileOk()
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir     m_NonExecuteFilePickerState->reset();
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir     EnumParam enumParam(CACHE_CONTROL_VALUES,this);
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir     EnumChildWindows(
668*cdf0e10cSrcweir 		m_hwndFileOpenDlgChild,
669*cdf0e10cSrcweir 		CWinFileOpenImpl::EnumChildWndProc,
670*cdf0e10cSrcweir 		(LPARAM)&enumParam);
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 	return 0;
673*cdf0e10cSrcweir }
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir //-----------------------------------------------------------------
676*cdf0e10cSrcweir //
677*cdf0e10cSrcweir //-----------------------------------------------------------------
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::onSelChanged(HWND)
680*cdf0e10cSrcweir {
681*cdf0e10cSrcweir     // the windows file open dialog sends an initial
682*cdf0e10cSrcweir     // SelChanged message after the InitDone message
683*cdf0e10cSrcweir     // when the dialog is about to be opened
684*cdf0e10cSrcweir     // if the lpstrFile buffer of the OPENFILENAME is
685*cdf0e10cSrcweir     // empty (zero length string) the windows file open
686*cdf0e10cSrcweir     // dialog sends a WM_SETTEXT message with an empty
687*cdf0e10cSrcweir     // string to the file name edit line
688*cdf0e10cSrcweir     // this would overwritte our text when we would set
689*cdf0e10cSrcweir     // the default name in onInitDone, so we have to
690*cdf0e10cSrcweir     // remeber that this is the first SelChanged message
691*cdf0e10cSrcweir     // and set the default name here to overwrite the
692*cdf0e10cSrcweir     // windows setting
693*cdf0e10cSrcweir     InitialSetDefaultName();
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 	FilePickerEvent evt;
696*cdf0e10cSrcweir 	m_FilePicker->fileSelectionChanged(evt);
697*cdf0e10cSrcweir }
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir // #i40865# The size of the standard labels 'File name'
700*cdf0e10cSrcweir // and 'File type' is to short in some cases when the
701*cdf0e10cSrcweir // label will be changed (e.g. in the Brazil version).
702*cdf0e10cSrcweir // We just make sure that the labels are using the maximum
703*cdf0e10cSrcweir // available space.
704*cdf0e10cSrcweir void CWinFileOpenImpl::EnlargeStdControlLabels() const
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir     HWND hFilterBoxLabel = GetDlgItem(m_hwndFileOpenDlg, stc2);
707*cdf0e10cSrcweir     HWND hFileNameBoxLabel = GetDlgItem(m_hwndFileOpenDlg, stc3);
708*cdf0e10cSrcweir     HWND hFileNameBox = GetDlgItem(m_hwndFileOpenDlg, cmb13);
709*cdf0e10cSrcweir     if (!hFileNameBox)
710*cdf0e10cSrcweir         hFileNameBox = GetDlgItem(m_hwndFileOpenDlg, edt1); // under Win98 it is edt1 instead of cmb13
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir     HWND hFilterBox = GetDlgItem(m_hwndFileOpenDlg, cmb1);
713*cdf0e10cSrcweir     HWND hOkButton = GetDlgItem(m_hwndFileOpenDlg, IDOK);
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir     // Move filter and file name box nearer to OK and Cancel button
716*cdf0e10cSrcweir     RECT rcOkButton;
717*cdf0e10cSrcweir     GetWindowRect(hOkButton, &rcOkButton);
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir     const int MAX_GAP = IsWindows98() ? 5 : 10;
720*cdf0e10cSrcweir     const int OFFSET = IsWindows98() ? 10 : 0;
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir     RECT rcFileNameBox;
723*cdf0e10cSrcweir     GetWindowRect(hFileNameBox, &rcFileNameBox);
724*cdf0e10cSrcweir     int w = rcFileNameBox.right - rcFileNameBox.left;
725*cdf0e10cSrcweir     int h = rcFileNameBox.bottom - rcFileNameBox.top;
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     int gap = rcOkButton.left - rcFileNameBox.right;
728*cdf0e10cSrcweir     gap = (gap > MAX_GAP) ? gap - MAX_GAP : gap;
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir     ScreenToClient(m_hwndFileOpenDlg, (LPPOINT)&rcFileNameBox);
731*cdf0e10cSrcweir     MoveWindow(hFileNameBox, rcFileNameBox.left + gap + OFFSET, rcFileNameBox.top, w - OFFSET, h, true);
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir     RECT rcFilterBox;
734*cdf0e10cSrcweir     GetWindowRect(hFilterBox, &rcFilterBox);
735*cdf0e10cSrcweir     w = rcFilterBox.right - rcFilterBox.left;
736*cdf0e10cSrcweir     h = rcFilterBox.bottom - rcFilterBox.top;
737*cdf0e10cSrcweir     ScreenToClient(m_hwndFileOpenDlg, (LPPOINT)&rcFilterBox);
738*cdf0e10cSrcweir     MoveWindow(hFilterBox, rcFilterBox.left + gap + OFFSET, rcFilterBox.top, w - OFFSET, h, true);
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir     // get the new window rect
741*cdf0e10cSrcweir     GetWindowRect(hFileNameBox, &rcFileNameBox);
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     RECT rcFilterBoxLabel;
744*cdf0e10cSrcweir     GetWindowRect(hFilterBoxLabel, &rcFilterBoxLabel);
745*cdf0e10cSrcweir     int offset = rcFileNameBox.left - rcFilterBoxLabel.right - 1;
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     w = rcFilterBoxLabel.right - rcFilterBoxLabel.left + offset;
748*cdf0e10cSrcweir     h = rcFilterBoxLabel.bottom - rcFilterBoxLabel.top;
749*cdf0e10cSrcweir     ScreenToClient(m_hwndFileOpenDlg, (LPPOINT)&rcFilterBoxLabel);
750*cdf0e10cSrcweir     MoveWindow(hFilterBoxLabel, rcFilterBoxLabel.left, rcFilterBoxLabel.top, w, h, true);
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir     RECT rcFileNameBoxLabel;
753*cdf0e10cSrcweir     GetWindowRect(hFileNameBoxLabel, &rcFileNameBoxLabel);
754*cdf0e10cSrcweir     w = rcFileNameBoxLabel.right - rcFileNameBoxLabel.left + offset;
755*cdf0e10cSrcweir     h = rcFileNameBoxLabel.bottom - rcFileNameBoxLabel.top;
756*cdf0e10cSrcweir     ScreenToClient(m_hwndFileOpenDlg, (LPPOINT)&rcFileNameBoxLabel);
757*cdf0e10cSrcweir     MoveWindow(hFileNameBoxLabel, rcFileNameBoxLabel.left, rcFileNameBoxLabel.top, w, h, true);
758*cdf0e10cSrcweir }
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::onInitDone()
761*cdf0e10cSrcweir {
762*cdf0e10cSrcweir 	m_Preview->setParent(m_hwndFileOpenDlg);
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 	// but now we have a valid parent handle
765*cdf0e10cSrcweir     m_HelpPopupWindow.setParent(m_hwndFileOpenDlg);
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir     EnlargeStdControlLabels();
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir     // #99826
770*cdf0e10cSrcweir     // Set the online filepicker state before initializing
771*cdf0e10cSrcweir     // the control labels from the resource else we are
772*cdf0e10cSrcweir     // overriding the offline settings
773*cdf0e10cSrcweir     m_ExecuteFilePickerState->setHwnd(m_hwndFileOpenDlgChild);
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir     m_FilePickerState = m_ExecuteFilePickerState;
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir     // initialize controls from cache
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir     EnumParam enumParam(INIT_CUSTOM_CONTROLS,this);
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir     EnumChildWindows(
782*cdf0e10cSrcweir 		m_hwndFileOpenDlgChild,
783*cdf0e10cSrcweir 		CWinFileOpenImpl::EnumChildWndProc,
784*cdf0e10cSrcweir 		(LPARAM)&enumParam);
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir     m_ExecuteFilePickerState->initFilePickerControls(
787*cdf0e10cSrcweir         m_NonExecuteFilePickerState->getControlCommand());
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir     SetDefaultExtension();
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir 	m_CustomControls->Align();
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir 	m_CustomControls->SetFont(
794*cdf0e10cSrcweir 		reinterpret_cast<HFONT>(SendMessage(m_hwndFileOpenDlg, WM_GETFONT, 0, 0)));
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir     // resume event notification that was
797*cdf0e10cSrcweir     // defered in onInitDialog
798*cdf0e10cSrcweir     m_FilePicker->resumeEventNotification();
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir     //#105996 let vcl know that now a system window is active
801*cdf0e10cSrcweir     PostMessage(
802*cdf0e10cSrcweir         HWND_BROADCAST,
803*cdf0e10cSrcweir         RegisterWindowMessage(TEXT("SYSTEM_WINDOW_ACTIVATED")),
804*cdf0e10cSrcweir         0,
805*cdf0e10cSrcweir         0);
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir     // call the parent function to center the
808*cdf0e10cSrcweir     // dialog to it's parent
809*cdf0e10cSrcweir     CFileOpenDialog::onInitDone();
810*cdf0e10cSrcweir }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir //-----------------------------------------------------------------
813*cdf0e10cSrcweir //
814*cdf0e10cSrcweir //-----------------------------------------------------------------
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::onFolderChanged()
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir 	FilePickerEvent evt;
819*cdf0e10cSrcweir 	m_FilePicker->directoryChanged(evt);
820*cdf0e10cSrcweir }
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir //-----------------------------------------------------------------
823*cdf0e10cSrcweir //
824*cdf0e10cSrcweir //-----------------------------------------------------------------
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::onTypeChanged(sal_uInt32)
827*cdf0e10cSrcweir {
828*cdf0e10cSrcweir     SetDefaultExtension();
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     FilePickerEvent evt;
831*cdf0e10cSrcweir     evt.ElementId = LISTBOX_FILTER;
832*cdf0e10cSrcweir     m_FilePicker->controlStateChanged(evt);
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
836*cdf0e10cSrcweir // onMessageCommand handler
837*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir sal_uInt32 SAL_CALL CWinFileOpenImpl::onCtrlCommand(
840*cdf0e10cSrcweir 	HWND, sal_uInt16 ctrlId, sal_uInt16)
841*cdf0e10cSrcweir {
842*cdf0e10cSrcweir     SetDefaultExtension();
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir     if (ctrlId < ctlFirst)
845*cdf0e10cSrcweir     {
846*cdf0e10cSrcweir 	    FilePickerEvent evt;
847*cdf0e10cSrcweir         evt.ElementId = ctrlId;
848*cdf0e10cSrcweir         m_FilePicker->controlStateChanged(evt);
849*cdf0e10cSrcweir     }
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir 	return 0;
852*cdf0e10cSrcweir }
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
855*cdf0e10cSrcweir //
856*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir void CWinFileOpenImpl::onWMSize()
859*cdf0e10cSrcweir {
860*cdf0e10cSrcweir 	m_Preview->notifyParentSizeChanged();
861*cdf0e10cSrcweir 	m_CustomControls->Align();
862*cdf0e10cSrcweir 	m_FilePicker->dialogSizeChanged();
863*cdf0e10cSrcweir }
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
866*cdf0e10cSrcweir //
867*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir void CWinFileOpenImpl::onWMShow(sal_Bool bShow)
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir 	m_Preview->notifyParentShow(bShow);
872*cdf0e10cSrcweir }
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
875*cdf0e10cSrcweir //
876*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir void CWinFileOpenImpl::onWMWindowPosChanged()
879*cdf0e10cSrcweir {
880*cdf0e10cSrcweir 	m_Preview->notifyParentWindowPosChanged();
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
884*cdf0e10cSrcweir //
885*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir void CWinFileOpenImpl::onCustomControlHelpRequest(LPHELPINFO lphi)
888*cdf0e10cSrcweir {
889*cdf0e10cSrcweir 	FilePickerEvent evt;
890*cdf0e10cSrcweir     evt.ElementId = sal::static_int_cast< sal_Int16 >(lphi->iCtrlId);
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir 	rtl::OUString aPopupHelpText = m_FilePicker->helpRequested(evt);
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir     if (aPopupHelpText.getLength())
895*cdf0e10cSrcweir     {
896*cdf0e10cSrcweir 		m_HelpPopupWindow.setText(aPopupHelpText);
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir         DWORD dwMsgPos = GetMessagePos();
899*cdf0e10cSrcweir         m_HelpPopupWindow.show(LOWORD(dwMsgPos),HIWORD(dwMsgPos));
900*cdf0e10cSrcweir     }
901*cdf0e10cSrcweir }
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
904*cdf0e10cSrcweir //
905*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::onInitDialog(HWND hwndDlg)
908*cdf0e10cSrcweir {
909*cdf0e10cSrcweir 	// subclass the dialog window
910*cdf0e10cSrcweir 	m_pfnOldDlgProc =
911*cdf0e10cSrcweir 		reinterpret_cast<WNDPROC>(
912*cdf0e10cSrcweir 			SetWindowLong( hwndDlg, GWL_WNDPROC,
913*cdf0e10cSrcweir 			reinterpret_cast<LONG>(SubClassFunc)));
914*cdf0e10cSrcweir }
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
917*cdf0e10cSrcweir // processing before showing the dialog
918*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir bool SAL_CALL CWinFileOpenImpl::preModal()
921*cdf0e10cSrcweir {
922*cdf0e10cSrcweir 	CFileOpenDialog::setFilter(
923*cdf0e10cSrcweir 		makeWinFilterBuffer(*m_filterContainer.get()));
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir 	return true;
926*cdf0e10cSrcweir }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
929*cdf0e10cSrcweir // processing after showing the dialog
930*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir void CWinFileOpenImpl::postModal(sal_Int16 nDialogResult)
933*cdf0e10cSrcweir {
934*cdf0e10cSrcweir 	CFileOpenDialog::postModal(nDialogResult);
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir 	// empty the container in order to get rid off
937*cdf0e10cSrcweir 	// invalid controls in case someone calls execute
938*cdf0e10cSrcweir 	// twice in sequence with the same instance
939*cdf0e10cSrcweir 	m_CustomControls->RemoveAllControls();
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir     m_FilePickerState = m_NonExecuteFilePickerState;
942*cdf0e10cSrcweir }
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
945*cdf0e10cSrcweir //
946*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::SetDefaultExtension()
949*cdf0e10cSrcweir {
950*cdf0e10cSrcweir     HWND hwndChkSaveWithExt = GetDlgItem(m_hwndFileOpenDlgChild, 100);
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir     if (hwndChkSaveWithExt)
953*cdf0e10cSrcweir     {
954*cdf0e10cSrcweir 		uno::Any aAny = CheckboxGetState(hwndChkSaveWithExt);
955*cdf0e10cSrcweir         sal_Bool bChecked = *reinterpret_cast<const sal_Bool*>(aAny.getValue());
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir         if (bChecked)
958*cdf0e10cSrcweir         {
959*cdf0e10cSrcweir             sal_uInt32 nIndex = getSelectedFilterIndex();
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir 	        rtl::OUString currentFilter;
962*cdf0e10cSrcweir 	        if (nIndex > 0)
963*cdf0e10cSrcweir 	        {
964*cdf0e10cSrcweir 		        // filter index of the base class starts with 1
965*cdf0e10cSrcweir 		        m_filterContainer->getFilter(nIndex - 1, currentFilter);
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir                 if (currentFilter.getLength())
968*cdf0e10cSrcweir                 {
969*cdf0e10cSrcweir 		            rtl::OUString FilterExt;
970*cdf0e10cSrcweir                     m_filterContainer->getFilter(currentFilter, FilterExt);
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir                     sal_Int32 posOfPoint = FilterExt.indexOf(L'.');
973*cdf0e10cSrcweir                     const sal_Unicode* pFirstExtStart = FilterExt.getStr() + posOfPoint + 1;
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir                     sal_Int32 posOfSemiColon = FilterExt.indexOf(L';') - 1;
976*cdf0e10cSrcweir                     if (posOfSemiColon < 0)
977*cdf0e10cSrcweir                         posOfSemiColon = FilterExt.getLength() - 1;
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir                     FilterExt = rtl::OUString(pFirstExtStart, posOfSemiColon - posOfPoint);
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir                     SendMessage(m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, reinterpret_cast<LPARAM>(FilterExt.getStr()));
982*cdf0e10cSrcweir                  }
983*cdf0e10cSrcweir 	        }
984*cdf0e10cSrcweir         }
985*cdf0e10cSrcweir         else
986*cdf0e10cSrcweir         {
987*cdf0e10cSrcweir             SendMessage(m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, reinterpret_cast<LPARAM>(TEXT("")));
988*cdf0e10cSrcweir         }
989*cdf0e10cSrcweir     }
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir     // !!! HACK !!!
992*cdf0e10cSrcweir }
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
995*cdf0e10cSrcweir //
996*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir void SAL_CALL CWinFileOpenImpl::InitialSetDefaultName()
999*cdf0e10cSrcweir {
1000*cdf0e10cSrcweir     // manually setting the file name that appears
1001*cdf0e10cSrcweir     // initially in the file-name-box of the file
1002*cdf0e10cSrcweir     // open dialog (reason: see above setDefaultName)
1003*cdf0e10cSrcweir     if (m_bInitialSelChanged && m_defaultName.getLength())
1004*cdf0e10cSrcweir     {
1005*cdf0e10cSrcweir         sal_Int32 edt1Id = edt1;
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir         // under W2k the there is a combobox instead
1008*cdf0e10cSrcweir         // of an edit field for the file name edit field
1009*cdf0e10cSrcweir         // the control id of this box is cmb13 and not
1010*cdf0e10cSrcweir         // edt1 as before so we must use this id
1011*cdf0e10cSrcweir         if (IsWindows2000Platform())
1012*cdf0e10cSrcweir             edt1Id = cmb13;
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir         HWND hwndEdt1 = GetDlgItem(m_hwndFileOpenDlg, edt1Id);
1015*cdf0e10cSrcweir         SetWindowText(hwndEdt1, reinterpret_cast<LPCTSTR>(m_defaultName.getStr()));
1016*cdf0e10cSrcweir     }
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir     m_bInitialSelChanged = sal_False;
1019*cdf0e10cSrcweir }
1020