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