1b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b557fc96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b557fc96SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b557fc96SAndrew Rist * distributed with this work for additional information
6b557fc96SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b557fc96SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b557fc96SAndrew Rist * "License"); you may not use this file except in compliance
9b557fc96SAndrew Rist * with the License. You may obtain a copy of the License at
10b557fc96SAndrew Rist *
11b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b557fc96SAndrew Rist *
13b557fc96SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b557fc96SAndrew Rist * software distributed under the License is distributed on an
15b557fc96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b557fc96SAndrew Rist * KIND, either express or implied. See the License for the
17b557fc96SAndrew Rist * specific language governing permissions and limitations
18b557fc96SAndrew Rist * under the License.
19b557fc96SAndrew Rist *
20b557fc96SAndrew Rist *************************************************************/
21b557fc96SAndrew Rist
22b557fc96SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir //-----------------------------------------------------------------------------
25cdf0e10cSrcweir // includes
26cdf0e10cSrcweir //-----------------------------------------------------------------------------
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "VistaFilePickerImpl.hxx"
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ControlActions.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/StringPair.hpp>
34cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
35cdf0e10cSrcweir #include <osl/file.hxx>
36cdf0e10cSrcweir #include <osl/mutex.hxx>
37cdf0e10cSrcweir #ifdef __MINGW32__
38cdf0e10cSrcweir #include <limits.h>
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #include "..\misc\WinImplHelper.hxx"
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <Shlguid.h>
43cdf0e10cSrcweir
is_current_process_window(HWND hwnd)44cdf0e10cSrcweir inline bool is_current_process_window(HWND hwnd)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir DWORD pid;
47cdf0e10cSrcweir GetWindowThreadProcessId(hwnd, &pid);
48cdf0e10cSrcweir return (pid == GetCurrentProcessId());
49cdf0e10cSrcweir }
50cdf0e10cSrcweir
choose_parent_window()51cdf0e10cSrcweir HWND choose_parent_window()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir HWND hwnd_parent = GetForegroundWindow();
54cdf0e10cSrcweir if (!is_current_process_window(hwnd_parent))
55cdf0e10cSrcweir hwnd_parent = GetDesktopWindow();
56cdf0e10cSrcweir return hwnd_parent;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir //-----------------------------------------------------------------------------
60cdf0e10cSrcweir // namespace
61cdf0e10cSrcweir //-----------------------------------------------------------------------------
62cdf0e10cSrcweir
63cdf0e10cSrcweir namespace fpicker{
64cdf0e10cSrcweir namespace win32{
65cdf0e10cSrcweir namespace vista{
66cdf0e10cSrcweir
67cdf0e10cSrcweir namespace css = ::com::sun::star;
68cdf0e10cSrcweir
69cdf0e10cSrcweir //-----------------------------------------------------------------------------
70cdf0e10cSrcweir // types, const etcpp.
71cdf0e10cSrcweir //-----------------------------------------------------------------------------
72cdf0e10cSrcweir
73cdf0e10cSrcweir
74cdf0e10cSrcweir static const ::sal_Int16 INVALID_CONTROL_ID = -1;
75cdf0e10cSrcweir static const ::sal_Int16 INVALID_CONTROL_ACTION = -1;
76cdf0e10cSrcweir
77cdf0e10cSrcweir typedef ::comphelper::SequenceAsVector< ::rtl::OUString > TStringList;
78cdf0e10cSrcweir
79cdf0e10cSrcweir // Guids used for IFileDialog::SetClientGuid
80cdf0e10cSrcweir static const GUID CLIENTID_FILEDIALOG_SIMPLE = {0xB8628FD3, 0xA3F5, 0x4845, 0x9B, 0x62, 0xD5, 0x1E, 0xDF, 0x97, 0xC4, 0x83};
81cdf0e10cSrcweir static const GUID CLIENTID_FILEDIALOG_OPTIONS = {0x93ED486F, 0x0D04, 0x4807, 0x8C, 0x44, 0xAC, 0x26, 0xCB, 0x6C, 0x5D, 0x36};
82cdf0e10cSrcweir static const GUID CLIENTID_FILESAVE = {0x3B2E2261, 0x402D, 0x4049, 0xB0, 0xC0, 0x91, 0x13, 0xF8, 0x6E, 0x84, 0x7C};
83cdf0e10cSrcweir static const GUID CLIENTID_FILESAVE_PASSWORD = {0xC12D4F4C, 0x4D41, 0x4D4F, 0x97, 0xEF, 0x87, 0xF9, 0x8D, 0xB6, 0x1E, 0xA6};
84cdf0e10cSrcweir static const GUID CLIENTID_FILESAVE_SELECTION = {0x5B2482B3, 0x0358, 0x4E09, 0xAA, 0x64, 0x2B, 0x76, 0xB2, 0xA0, 0xDD, 0xFE};
85cdf0e10cSrcweir static const GUID CLIENTID_FILESAVE_TEMPLATE = {0x9996D877, 0x20D5, 0x424B, 0x9C, 0x2E, 0xD3, 0xB6, 0x31, 0xEC, 0xF7, 0xCE};
86cdf0e10cSrcweir static const GUID CLIENTID_FILEOPEN_LINK_TEMPLATE = {0x32237796, 0x1509, 0x49D1, 0xBB, 0x7E, 0x63, 0xAD, 0x36, 0xAE, 0x86, 0x8C};
87cdf0e10cSrcweir static const GUID CLIENTID_FILEOPEN_PLAY = {0x32CFB147, 0xF5AE, 0x4F90, 0xA1, 0xF1, 0x81, 0x20, 0x72, 0xBB, 0x2F, 0xC5};
88cdf0e10cSrcweir static const GUID CLIENTID_FILEOPEN_LINK = {0x39AC4BAE, 0x7D2D, 0x46BC, 0xBE, 0x2E, 0xF8, 0x8C, 0xB5, 0x65, 0x5E, 0x6A};
89cdf0e10cSrcweir
90cdf0e10cSrcweir //-----------------------------------------------------------------------------
lcl_getURLFromShellItem(IShellItem * pItem)91cdf0e10cSrcweir ::rtl::OUString lcl_getURLFromShellItem (IShellItem* pItem)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir LPOLESTR pStr = NULL;
94cdf0e10cSrcweir ::rtl::OUString sURL;
95cdf0e10cSrcweir
96cdf0e10cSrcweir SIGDN eConversion = SIGDN_FILESYSPATH;
97cdf0e10cSrcweir HRESULT hr = pItem->GetDisplayName ( eConversion, &pStr );
98cdf0e10cSrcweir
99cdf0e10cSrcweir if ( FAILED(hr) )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir eConversion = SIGDN_URL;
102cdf0e10cSrcweir hr = pItem->GetDisplayName ( eConversion, &pStr );
103cdf0e10cSrcweir
104cdf0e10cSrcweir if ( FAILED(hr) )
105cdf0e10cSrcweir return ::rtl::OUString();
106cdf0e10cSrcweir
107cdf0e10cSrcweir sURL = ::rtl::OUString(reinterpret_cast<sal_Unicode*>(pStr));
108cdf0e10cSrcweir }
109cdf0e10cSrcweir else
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ::osl::FileBase::getFileURLFromSystemPath( reinterpret_cast<sal_Unicode*>(pStr), sURL );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir CoTaskMemFree (pStr);
115cdf0e10cSrcweir return sURL;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
lcl_buildFilterList(CFilterContainer & rContainer)119cdf0e10cSrcweir ::std::vector< COMDLG_FILTERSPEC > lcl_buildFilterList(CFilterContainer& rContainer)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir const sal_Int32 c = rContainer.numFilter();
122cdf0e10cSrcweir sal_Int32 i = 0;
123cdf0e10cSrcweir ::std::vector< COMDLG_FILTERSPEC > lList ;
124cdf0e10cSrcweir CFilterContainer::FILTER_ENTRY_T aFilter;
125cdf0e10cSrcweir
126cdf0e10cSrcweir rContainer.beginEnumFilter( );
127cdf0e10cSrcweir while( rContainer.getNextFilter(aFilter) )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir COMDLG_FILTERSPEC aSpec;
130cdf0e10cSrcweir
131cdf0e10cSrcweir aSpec.pszName = reinterpret_cast<LPCTSTR>(aFilter.first.getStr()) ;
132cdf0e10cSrcweir aSpec.pszSpec = reinterpret_cast<LPCTSTR>(aFilter.second.getStr());
133cdf0e10cSrcweir
134cdf0e10cSrcweir lList.push_back(aSpec);
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir return lList;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
VistaFilePickerImpl()141cdf0e10cSrcweir VistaFilePickerImpl::VistaFilePickerImpl()
142cdf0e10cSrcweir : m_iDialogOpen ()
143cdf0e10cSrcweir , m_iDialogSave ()
144cdf0e10cSrcweir , m_hLastResult ()
145cdf0e10cSrcweir , m_lFilters ()
146cdf0e10cSrcweir , m_lLastFiles ()
147cdf0e10cSrcweir , m_iEventHandler(new VistaFilePickerEventHandler(this))
148cdf0e10cSrcweir , m_bInExecute (sal_False)
149cdf0e10cSrcweir , m_bWasExecuted (sal_False)
150cdf0e10cSrcweir , m_sDirectory ()
151cdf0e10cSrcweir , m_sFilename ()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir m_hParentWindow = choose_parent_window();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir //-------------------------------------------------------------------------------
~VistaFilePickerImpl()157cdf0e10cSrcweir VistaFilePickerImpl::~VistaFilePickerImpl()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir //-------------------------------------------------------------------------------
before()162cdf0e10cSrcweir void VistaFilePickerImpl::before()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir // SYNCHRONIZED->
165cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
166cdf0e10cSrcweir
167cdf0e10cSrcweir // TRICKY .-)
168cdf0e10cSrcweir // osl::Thread class initializes COm already in MTA mode because it's needed
169cdf0e10cSrcweir // by VCL and UNO so. There is no way to change that from outside ...
170cdf0e10cSrcweir // but we need a STA environment ...
171cdf0e10cSrcweir // So we make it by try-and-error ...
172cdf0e10cSrcweir // If first CoInitialize will fail .. we unitialize COM initialize it new .-)
173cdf0e10cSrcweir
174cdf0e10cSrcweir m_hLastResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
175cdf0e10cSrcweir if ( FAILED(m_hLastResult) )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir CoUninitialize();
178cdf0e10cSrcweir m_hLastResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
179cdf0e10cSrcweir }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir //-------------------------------------------------------------------------------
doRequest(const RequestRef & rRequest)183cdf0e10cSrcweir void VistaFilePickerImpl::doRequest(const RequestRef& rRequest)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir try
186cdf0e10cSrcweir {
187cdf0e10cSrcweir switch(rRequest->getRequest())
188cdf0e10cSrcweir {
189cdf0e10cSrcweir case E_ADD_PICKER_LISTENER :
190cdf0e10cSrcweir impl_sta_addFilePickerListener(rRequest);
191cdf0e10cSrcweir break;
192cdf0e10cSrcweir
193cdf0e10cSrcweir case E_REMOVE_PICKER_LISTENER :
194cdf0e10cSrcweir impl_sta_removeFilePickerListener(rRequest);
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir
197cdf0e10cSrcweir case E_APPEND_FILTER :
198cdf0e10cSrcweir impl_sta_appendFilter(rRequest);
199cdf0e10cSrcweir break;
200cdf0e10cSrcweir
201cdf0e10cSrcweir case E_APPEND_FILTERGROUP :
202cdf0e10cSrcweir impl_sta_appendFilterGroup(rRequest);
203cdf0e10cSrcweir break;
204cdf0e10cSrcweir
205cdf0e10cSrcweir case E_SET_CURRENT_FILTER :
206cdf0e10cSrcweir impl_sta_setCurrentFilter(rRequest);
207cdf0e10cSrcweir break;
208cdf0e10cSrcweir
209cdf0e10cSrcweir case E_GET_CURRENT_FILTER :
210cdf0e10cSrcweir impl_sta_getCurrentFilter(rRequest);
211cdf0e10cSrcweir break;
212cdf0e10cSrcweir
213cdf0e10cSrcweir case E_CREATE_OPEN_DIALOG :
214cdf0e10cSrcweir impl_sta_CreateOpenDialog(rRequest);
215cdf0e10cSrcweir break;
216cdf0e10cSrcweir
217cdf0e10cSrcweir case E_CREATE_SAVE_DIALOG :
218cdf0e10cSrcweir impl_sta_CreateSaveDialog(rRequest);
219cdf0e10cSrcweir break;
220cdf0e10cSrcweir
221cdf0e10cSrcweir case E_SET_MULTISELECTION_MODE :
222cdf0e10cSrcweir impl_sta_SetMultiSelectionMode(rRequest);
223cdf0e10cSrcweir break;
224cdf0e10cSrcweir
225cdf0e10cSrcweir case E_SET_TITLE :
226cdf0e10cSrcweir impl_sta_SetTitle(rRequest);
227cdf0e10cSrcweir break;
228cdf0e10cSrcweir
229cdf0e10cSrcweir case E_SET_FILENAME:
230cdf0e10cSrcweir impl_sta_SetFileName(rRequest);
231cdf0e10cSrcweir break;
232cdf0e10cSrcweir
233cdf0e10cSrcweir case E_SET_DIRECTORY :
234cdf0e10cSrcweir impl_sta_SetDirectory(rRequest);
235cdf0e10cSrcweir break;
236cdf0e10cSrcweir
237cdf0e10cSrcweir case E_GET_DIRECTORY :
238cdf0e10cSrcweir impl_sta_GetDirectory(rRequest);
239cdf0e10cSrcweir break;
240cdf0e10cSrcweir
241cdf0e10cSrcweir case E_SET_DEFAULT_NAME :
242cdf0e10cSrcweir impl_sta_SetDefaultName(rRequest);
243cdf0e10cSrcweir break;
244cdf0e10cSrcweir
245cdf0e10cSrcweir case E_GET_SELECTED_FILES :
246cdf0e10cSrcweir impl_sta_getSelectedFiles(rRequest);
247cdf0e10cSrcweir break;
248cdf0e10cSrcweir
249cdf0e10cSrcweir case E_SHOW_DIALOG_MODAL :
250cdf0e10cSrcweir impl_sta_ShowDialogModal(rRequest);
251cdf0e10cSrcweir break;
252cdf0e10cSrcweir
253cdf0e10cSrcweir case E_SET_CONTROL_VALUE :
254cdf0e10cSrcweir impl_sta_SetControlValue(rRequest);
255cdf0e10cSrcweir break;
256cdf0e10cSrcweir
257cdf0e10cSrcweir case E_GET_CONTROL_VALUE :
258cdf0e10cSrcweir impl_sta_GetControlValue(rRequest);
259cdf0e10cSrcweir break;
260cdf0e10cSrcweir
261cdf0e10cSrcweir case E_SET_CONTROL_LABEL :
262cdf0e10cSrcweir impl_sta_SetControlLabel(rRequest);
263cdf0e10cSrcweir break;
264cdf0e10cSrcweir
265cdf0e10cSrcweir case E_GET_CONTROL_LABEL :
266cdf0e10cSrcweir impl_sta_GetControlLabel(rRequest);
267cdf0e10cSrcweir break;
268cdf0e10cSrcweir
269cdf0e10cSrcweir case E_ENABLE_CONTROL :
270cdf0e10cSrcweir impl_sta_EnableControl(rRequest);
271cdf0e10cSrcweir break;
272cdf0e10cSrcweir
273cdf0e10cSrcweir // no default: let the compiler detect changes on enum ERequest !
274cdf0e10cSrcweir }
275cdf0e10cSrcweir }
276cdf0e10cSrcweir catch(...)
277cdf0e10cSrcweir {}
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir //-------------------------------------------------------------------------------
after()281cdf0e10cSrcweir void VistaFilePickerImpl::after()
282cdf0e10cSrcweir {
283cdf0e10cSrcweir CoUninitialize();
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_addFilePickerListener(const RequestRef & rRequest)287cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_addFilePickerListener(const RequestRef& rRequest)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir // SYNCHRONIZED outside !
290cdf0e10cSrcweir const css::uno::Reference< css::ui::dialogs::XFilePickerListener > xListener = rRequest->getArgumentOrDefault(PROP_PICKER_LISTENER, css::uno::Reference< css::ui::dialogs::XFilePickerListener >());
291cdf0e10cSrcweir if ( ! xListener.is())
292cdf0e10cSrcweir return;
293cdf0e10cSrcweir
294cdf0e10cSrcweir // SYNCHRONIZED->
295cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
296cdf0e10cSrcweir TFileDialogEvents iHandler = m_iEventHandler;
297cdf0e10cSrcweir aLock.clear();
298cdf0e10cSrcweir // <- SYNCHRONIZED
299cdf0e10cSrcweir
300cdf0e10cSrcweir VistaFilePickerEventHandler* pHandlerImpl = (VistaFilePickerEventHandler*)iHandler.get();
301cdf0e10cSrcweir if (pHandlerImpl)
302cdf0e10cSrcweir pHandlerImpl->addFilePickerListener(xListener);
303cdf0e10cSrcweir }
304cdf0e10cSrcweir
305cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_removeFilePickerListener(const RequestRef & rRequest)306cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_removeFilePickerListener(const RequestRef& rRequest)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir // SYNCHRONIZED outside !
309cdf0e10cSrcweir const css::uno::Reference< css::ui::dialogs::XFilePickerListener > xListener = rRequest->getArgumentOrDefault(PROP_PICKER_LISTENER, css::uno::Reference< css::ui::dialogs::XFilePickerListener >());
310cdf0e10cSrcweir if ( ! xListener.is())
311cdf0e10cSrcweir return;
312cdf0e10cSrcweir
313cdf0e10cSrcweir // SYNCHRONIZED->
314cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
315cdf0e10cSrcweir TFileDialogEvents iHandler = m_iEventHandler;
316cdf0e10cSrcweir aLock.clear();
317cdf0e10cSrcweir // <- SYNCHRONIZED
318cdf0e10cSrcweir
319cdf0e10cSrcweir VistaFilePickerEventHandler* pHandlerImpl = (VistaFilePickerEventHandler*)iHandler.get();
320cdf0e10cSrcweir if (pHandlerImpl)
321cdf0e10cSrcweir pHandlerImpl->removeFilePickerListener(xListener);
322cdf0e10cSrcweir }
323cdf0e10cSrcweir
324cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_appendFilter(const RequestRef & rRequest)325cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_appendFilter(const RequestRef& rRequest)
326cdf0e10cSrcweir {
327cdf0e10cSrcweir const ::rtl::OUString sTitle = rRequest->getArgumentOrDefault(PROP_FILTER_TITLE, ::rtl::OUString());
328cdf0e10cSrcweir const ::rtl::OUString sFilter = rRequest->getArgumentOrDefault(PROP_FILTER_VALUE, ::rtl::OUString());
329cdf0e10cSrcweir
330cdf0e10cSrcweir // SYNCHRONIZED->
331cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
332cdf0e10cSrcweir
333cdf0e10cSrcweir m_lFilters.addFilter(sTitle, sFilter);
334cdf0e10cSrcweir }
335cdf0e10cSrcweir
336cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_appendFilterGroup(const RequestRef & rRequest)337cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_appendFilterGroup(const RequestRef& rRequest)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir const css::uno::Sequence< css::beans::StringPair > aFilterGroup =
340cdf0e10cSrcweir rRequest->getArgumentOrDefault(PROP_FILTER_GROUP, css::uno::Sequence< css::beans::StringPair >());
341cdf0e10cSrcweir
342cdf0e10cSrcweir // SYNCHRONIZED->
343cdf0e10cSrcweir ::rtl::OUString aEmpty;
344cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
345cdf0e10cSrcweir
346cdf0e10cSrcweir if ( m_lFilters.numFilter() > 0 && aFilterGroup.getLength() > 0 )
347cdf0e10cSrcweir m_lFilters.addFilter( STRING_SEPARATOR, aEmpty, sal_True );
348cdf0e10cSrcweir
349cdf0e10cSrcweir ::sal_Int32 c = aFilterGroup.getLength();
350cdf0e10cSrcweir ::sal_Int32 i = 0;
351cdf0e10cSrcweir for (i=0; i<c; ++i)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir const css::beans::StringPair& rFilter = aFilterGroup[i];
354cdf0e10cSrcweir m_lFilters.addFilter(rFilter.First, rFilter.Second);
355cdf0e10cSrcweir }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir
358cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_setCurrentFilter(const RequestRef & rRequest)359cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_setCurrentFilter(const RequestRef& rRequest)
360cdf0e10cSrcweir {
361cdf0e10cSrcweir const ::rtl::OUString sTitle = rRequest->getArgumentOrDefault(PROP_FILTER_TITLE, ::rtl::OUString());
362cdf0e10cSrcweir
363cdf0e10cSrcweir // SYNCHRONIZED->
364cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
365cdf0e10cSrcweir
366cdf0e10cSrcweir m_lFilters.setCurrentFilter(sTitle);
367cdf0e10cSrcweir }
368cdf0e10cSrcweir
369cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_getCurrentFilter(const RequestRef & rRequest)370cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_getCurrentFilter(const RequestRef& rRequest)
371cdf0e10cSrcweir {
372cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
373cdf0e10cSrcweir UINT nIndex = UINT_MAX;
374cdf0e10cSrcweir HRESULT hResult = iDialog->GetFileTypeIndex(&nIndex);
375cdf0e10cSrcweir if (
376cdf0e10cSrcweir ( FAILED(hResult) ) ||
377cdf0e10cSrcweir ( nIndex == UINT_MAX ) // COM dialog sometimes return S_OK for empty filter lists .-(
378cdf0e10cSrcweir )
379cdf0e10cSrcweir return;
380cdf0e10cSrcweir
381cdf0e10cSrcweir // SYNCHRONIZED->
382cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
383cdf0e10cSrcweir
384cdf0e10cSrcweir ::rtl::OUString sTitle;
385cdf0e10cSrcweir ::sal_Int32 nRealIndex = (nIndex-1); // COM dialog base on 1 ... filter container on 0 .-)
386cdf0e10cSrcweir if (
387cdf0e10cSrcweir (nRealIndex >= 0 ) &&
388cdf0e10cSrcweir (m_lFilters.getFilter(nRealIndex, sTitle))
389cdf0e10cSrcweir )
390cdf0e10cSrcweir rRequest->setArgument(PROP_FILTER_TITLE, sTitle);
391cdf0e10cSrcweir else if ( nRealIndex == -1 ) // Dialog not visible yet
392cdf0e10cSrcweir {
393cdf0e10cSrcweir sTitle = m_lFilters.getCurrentFilter();
394cdf0e10cSrcweir rRequest->setArgument(PROP_FILTER_TITLE, sTitle);
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir aLock.clear();
398cdf0e10cSrcweir // <- SYNCHRONIZED
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
401cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_CreateOpenDialog(const RequestRef & rRequest)402cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_CreateOpenDialog(const RequestRef& rRequest)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir // SYNCHRONIZED->
405cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
406cdf0e10cSrcweir
407cdf0e10cSrcweir m_hLastResult = m_iDialogOpen.create();
408cdf0e10cSrcweir if (FAILED(m_hLastResult))
409cdf0e10cSrcweir return;
410cdf0e10cSrcweir
411cdf0e10cSrcweir TFileDialog iDialog;
412cdf0e10cSrcweir #ifdef __MINGW32__
413cdf0e10cSrcweir m_iDialogOpen->QueryInterface(IID_IFileDialog, (void **)(&iDialog));
414cdf0e10cSrcweir #else
415cdf0e10cSrcweir m_iDialogOpen.query(&iDialog);
416cdf0e10cSrcweir #endif
417cdf0e10cSrcweir
418cdf0e10cSrcweir TFileDialogEvents iHandler = m_iEventHandler;
419cdf0e10cSrcweir
420cdf0e10cSrcweir aLock.clear();
421cdf0e10cSrcweir // <- SYNCHRONIZED
422cdf0e10cSrcweir
423cdf0e10cSrcweir DWORD nFlags = 0;
424cdf0e10cSrcweir iDialog->GetOptions ( &nFlags );
425cdf0e10cSrcweir
426cdf0e10cSrcweir nFlags &= ~FOS_FORCESHOWHIDDEN;
427cdf0e10cSrcweir nFlags |= FOS_PATHMUSTEXIST;
428cdf0e10cSrcweir nFlags |= FOS_FILEMUSTEXIST;
429cdf0e10cSrcweir nFlags |= FOS_OVERWRITEPROMPT;
430cdf0e10cSrcweir nFlags |= FOS_DONTADDTORECENT;
431cdf0e10cSrcweir
432cdf0e10cSrcweir iDialog->SetOptions ( nFlags );
433cdf0e10cSrcweir
434cdf0e10cSrcweir ::sal_Int32 nFeatures = rRequest->getArgumentOrDefault(PROP_FEATURES, (::sal_Int32)0);
435cdf0e10cSrcweir ::sal_Int32 nTemplate = rRequest->getArgumentOrDefault(PROP_TEMPLATE_DESCR, (::sal_Int32)0);
436cdf0e10cSrcweir impl_sta_enableFeatures(nFeatures, nTemplate);
437cdf0e10cSrcweir
438cdf0e10cSrcweir VistaFilePickerEventHandler* pHandlerImpl = (VistaFilePickerEventHandler*)iHandler.get();
439cdf0e10cSrcweir if (pHandlerImpl)
440cdf0e10cSrcweir pHandlerImpl->startListening(iDialog);
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
443cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_CreateSaveDialog(const RequestRef & rRequest)444cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_CreateSaveDialog(const RequestRef& rRequest)
445cdf0e10cSrcweir {
446cdf0e10cSrcweir // SYNCHRONIZED->
447cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
448cdf0e10cSrcweir
449cdf0e10cSrcweir m_hLastResult = m_iDialogSave.create();
450cdf0e10cSrcweir if (FAILED(m_hLastResult))
451cdf0e10cSrcweir return;
452cdf0e10cSrcweir
453cdf0e10cSrcweir TFileDialogEvents iHandler = m_iEventHandler;
454cdf0e10cSrcweir TFileDialog iDialog;
455cdf0e10cSrcweir #ifdef __MINGW32__
456cdf0e10cSrcweir m_iDialogSave->QueryInterface(IID_IFileDialog, (void **)(&iDialog));
457cdf0e10cSrcweir #else
458cdf0e10cSrcweir m_iDialogSave.query(&iDialog);
459cdf0e10cSrcweir #endif
460cdf0e10cSrcweir
461cdf0e10cSrcweir aLock.clear();
462cdf0e10cSrcweir // <- SYNCHRONIZED
463cdf0e10cSrcweir
464cdf0e10cSrcweir DWORD nFlags = 0;
465cdf0e10cSrcweir iDialog->GetOptions ( &nFlags );
466cdf0e10cSrcweir
467cdf0e10cSrcweir nFlags &= ~FOS_FORCESHOWHIDDEN;
468cdf0e10cSrcweir nFlags |= FOS_PATHMUSTEXIST;
469cdf0e10cSrcweir nFlags |= FOS_FILEMUSTEXIST;
470cdf0e10cSrcweir nFlags |= FOS_OVERWRITEPROMPT;
471cdf0e10cSrcweir nFlags |= FOS_DONTADDTORECENT;
472cdf0e10cSrcweir
473cdf0e10cSrcweir iDialog->SetOptions ( nFlags );
474cdf0e10cSrcweir
475cdf0e10cSrcweir ::sal_Int32 nFeatures = rRequest->getArgumentOrDefault(PROP_FEATURES, (::sal_Int32)0);
476cdf0e10cSrcweir ::sal_Int32 nTemplate = rRequest->getArgumentOrDefault(PROP_TEMPLATE_DESCR, (::sal_Int32)0);
477cdf0e10cSrcweir impl_sta_enableFeatures(nFeatures, nTemplate);
478cdf0e10cSrcweir
479cdf0e10cSrcweir VistaFilePickerEventHandler* pHandlerImpl = (VistaFilePickerEventHandler*)iHandler.get();
480cdf0e10cSrcweir if (pHandlerImpl)
481cdf0e10cSrcweir pHandlerImpl->startListening(iDialog);
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir //-------------------------------------------------------------------------------
485cdf0e10cSrcweir static const ::sal_Int32 GROUP_VERSION = 1;
486cdf0e10cSrcweir static const ::sal_Int32 GROUP_TEMPLATE = 2;
487cdf0e10cSrcweir static const ::sal_Int32 GROUP_IMAGETEMPLATE = 3;
488cdf0e10cSrcweir static const ::sal_Int32 GROUP_CHECKBOXES = 4;
489cdf0e10cSrcweir
490cdf0e10cSrcweir //-------------------------------------------------------------------------------
setLabelToControl(CResourceProvider & rResourceProvider,TFileDialogCustomize iCustom,sal_uInt16 nControlId)491cdf0e10cSrcweir static void setLabelToControl(CResourceProvider& rResourceProvider, TFileDialogCustomize iCustom, sal_uInt16 nControlId)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir ::rtl::OUString aLabel = rResourceProvider.getResString(nControlId);
494cdf0e10cSrcweir aLabel = SOfficeToWindowsLabel(aLabel);
495cdf0e10cSrcweir iCustom->SetControlLabel(nControlId, reinterpret_cast<LPCWSTR>(aLabel.getStr()) );
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_enableFeatures(::sal_Int32 nFeatures,::sal_Int32 nTemplate)499cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_enableFeatures(::sal_Int32 nFeatures, ::sal_Int32 nTemplate)
500cdf0e10cSrcweir {
501cdf0e10cSrcweir GUID aGUID = {};
502cdf0e10cSrcweir switch (nTemplate)
503cdf0e10cSrcweir {
504cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE :
505cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE :
506cdf0e10cSrcweir aGUID = CLIENTID_FILEDIALOG_SIMPLE;
507cdf0e10cSrcweir break;
508cdf0e10cSrcweir
509cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION :
510cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS :
511cdf0e10cSrcweir aGUID = CLIENTID_FILEDIALOG_OPTIONS;
512cdf0e10cSrcweir break;
513cdf0e10cSrcweir
514cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION :
515cdf0e10cSrcweir aGUID = CLIENTID_FILESAVE;
516cdf0e10cSrcweir break;
517cdf0e10cSrcweir
518cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD :
519cdf0e10cSrcweir aGUID = CLIENTID_FILESAVE_PASSWORD;
520cdf0e10cSrcweir break;
521cdf0e10cSrcweir
522cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION :
523cdf0e10cSrcweir aGUID = CLIENTID_FILESAVE_SELECTION;
524cdf0e10cSrcweir break;
525cdf0e10cSrcweir
526cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE :
527cdf0e10cSrcweir aGUID = CLIENTID_FILESAVE_TEMPLATE;
528cdf0e10cSrcweir break;
529cdf0e10cSrcweir
530cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE :
531cdf0e10cSrcweir aGUID = CLIENTID_FILEOPEN_LINK_TEMPLATE;
532cdf0e10cSrcweir break;
533cdf0e10cSrcweir
534cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY :
535cdf0e10cSrcweir aGUID = CLIENTID_FILEOPEN_PLAY;
536cdf0e10cSrcweir break;
537cdf0e10cSrcweir
538cdf0e10cSrcweir case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW :
539cdf0e10cSrcweir aGUID = CLIENTID_FILEOPEN_LINK;
540cdf0e10cSrcweir break;
541cdf0e10cSrcweir }
542cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
543cdf0e10cSrcweir iDialog->SetClientGuid ( aGUID );
544cdf0e10cSrcweir
545cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
546cdf0e10cSrcweir
547cdf0e10cSrcweir if ((nFeatures & FEATURE_VERSION) == FEATURE_VERSION)
548cdf0e10cSrcweir {
549cdf0e10cSrcweir iCustom->StartVisualGroup (GROUP_VERSION, L"Version");
550cdf0e10cSrcweir iCustom->AddComboBox (css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_VERSION);
551cdf0e10cSrcweir iCustom->EndVisualGroup ();
552cdf0e10cSrcweir iCustom->MakeProminent (GROUP_VERSION);
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
555cdf0e10cSrcweir if ((nFeatures & FEATURE_TEMPLATE) == FEATURE_TEMPLATE)
556cdf0e10cSrcweir {
557cdf0e10cSrcweir iCustom->StartVisualGroup (GROUP_TEMPLATE, L"Template");
558cdf0e10cSrcweir iCustom->AddComboBox (css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_TEMPLATE);
559cdf0e10cSrcweir iCustom->EndVisualGroup ();
560cdf0e10cSrcweir iCustom->MakeProminent (GROUP_TEMPLATE);
561cdf0e10cSrcweir }
562cdf0e10cSrcweir
563cdf0e10cSrcweir if ((nFeatures & FEATURE_IMAGETEMPLATE) == FEATURE_IMAGETEMPLATE)
564cdf0e10cSrcweir {
565cdf0e10cSrcweir iCustom->StartVisualGroup (GROUP_IMAGETEMPLATE, L"Style");
566cdf0e10cSrcweir iCustom->AddComboBox (css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE);
567cdf0e10cSrcweir iCustom->EndVisualGroup ();
568cdf0e10cSrcweir iCustom->MakeProminent (GROUP_IMAGETEMPLATE);
569cdf0e10cSrcweir }
570cdf0e10cSrcweir
571cdf0e10cSrcweir iCustom->StartVisualGroup (GROUP_CHECKBOXES, L"");
572cdf0e10cSrcweir
573cdf0e10cSrcweir sal_uInt16 nControlId(0);
574cdf0e10cSrcweir if ((nFeatures & FEATURE_AUTOEXTENSION) == FEATURE_AUTOEXTENSION)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION;
577cdf0e10cSrcweir iCustom->AddCheckButton (nControlId, L"Auto Extension", true);
578cdf0e10cSrcweir setLabelToControl(m_ResProvider, iCustom, nControlId);
579cdf0e10cSrcweir }
580cdf0e10cSrcweir
581cdf0e10cSrcweir if ((nFeatures & FEATURE_PASSWORD) == FEATURE_PASSWORD)
582cdf0e10cSrcweir {
583cdf0e10cSrcweir nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD;
584cdf0e10cSrcweir iCustom->AddCheckButton (nControlId, L"Password", false);
585cdf0e10cSrcweir setLabelToControl(m_ResProvider, iCustom, nControlId);
586cdf0e10cSrcweir }
587cdf0e10cSrcweir
588cdf0e10cSrcweir if ((nFeatures & FEATURE_READONLY) == FEATURE_READONLY)
589cdf0e10cSrcweir {
590cdf0e10cSrcweir nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY;
591cdf0e10cSrcweir iCustom->AddCheckButton (nControlId, L"Readonly", false);
592cdf0e10cSrcweir setLabelToControl(m_ResProvider, iCustom, nControlId);
593cdf0e10cSrcweir }
594cdf0e10cSrcweir
595cdf0e10cSrcweir if ((nFeatures & FEATURE_FILTEROPTIONS) == FEATURE_FILTEROPTIONS)
596cdf0e10cSrcweir {
597cdf0e10cSrcweir nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS;
598cdf0e10cSrcweir iCustom->AddCheckButton (nControlId, L"Filter Options", false);
599cdf0e10cSrcweir setLabelToControl(m_ResProvider, iCustom, nControlId);
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir if ((nFeatures & FEATURE_LINK) == FEATURE_LINK)
603cdf0e10cSrcweir {
604cdf0e10cSrcweir nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK;
605cdf0e10cSrcweir iCustom->AddCheckButton (nControlId, L"Link", false);
606cdf0e10cSrcweir setLabelToControl(m_ResProvider, iCustom, nControlId);
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
609cdf0e10cSrcweir if ((nFeatures & FEATURE_SELECTION) == FEATURE_SELECTION)
610cdf0e10cSrcweir {
611cdf0e10cSrcweir nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION;
612cdf0e10cSrcweir iCustom->AddCheckButton (nControlId, L"Selection", false);
613cdf0e10cSrcweir setLabelToControl(m_ResProvider, iCustom, nControlId);
614cdf0e10cSrcweir }
615cdf0e10cSrcweir
616cdf0e10cSrcweir /* can be ignored ... new COM dialog supports preview native now !
617cdf0e10cSrcweir if ((nFeatures & FEATURE_PREVIEW) == FEATURE_PREVIEW)
618cdf0e10cSrcweir iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, L"Preview", false);
619cdf0e10cSrcweir */
620cdf0e10cSrcweir
621cdf0e10cSrcweir iCustom->EndVisualGroup();
622cdf0e10cSrcweir
623cdf0e10cSrcweir if ((nFeatures & FEATURE_PLAY) == FEATURE_PLAY)
624cdf0e10cSrcweir iCustom->AddPushButton (css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY, L"Play");
625cdf0e10cSrcweir
626cdf0e10cSrcweir }
627cdf0e10cSrcweir
628cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetMultiSelectionMode(const RequestRef & rRequest)629cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetMultiSelectionMode(const RequestRef& rRequest)
630cdf0e10cSrcweir {
631cdf0e10cSrcweir const ::sal_Bool bMultiSelection = rRequest->getArgumentOrDefault(PROP_MULTISELECTION_MODE, (::sal_Bool)sal_True);
632cdf0e10cSrcweir
633cdf0e10cSrcweir // SYNCHRONIZED->
634cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
635cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
636cdf0e10cSrcweir aLock.clear();
637cdf0e10cSrcweir // <- SYNCHRONIZED
638cdf0e10cSrcweir
639cdf0e10cSrcweir DWORD nFlags = 0;
640cdf0e10cSrcweir m_hLastResult = iDialog->GetOptions ( &nFlags );
641cdf0e10cSrcweir
642cdf0e10cSrcweir if (bMultiSelection)
643cdf0e10cSrcweir nFlags |= FOS_ALLOWMULTISELECT;
644cdf0e10cSrcweir else
645cdf0e10cSrcweir nFlags &= ~FOS_ALLOWMULTISELECT;
646cdf0e10cSrcweir
647cdf0e10cSrcweir iDialog->SetOptions ( nFlags );
648cdf0e10cSrcweir }
649cdf0e10cSrcweir
650cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetTitle(const RequestRef & rRequest)651cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetTitle(const RequestRef& rRequest)
652cdf0e10cSrcweir {
653cdf0e10cSrcweir ::rtl::OUString sTitle = rRequest->getArgumentOrDefault(PROP_TITLE, ::rtl::OUString());
654cdf0e10cSrcweir
655cdf0e10cSrcweir // SYNCHRONIZED->
656cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
657cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
658cdf0e10cSrcweir aLock.clear();
659cdf0e10cSrcweir // <- SYNCHRONIZED
660cdf0e10cSrcweir
661cdf0e10cSrcweir iDialog->SetTitle(reinterpret_cast<LPCTSTR>(sTitle.getStr()));
662cdf0e10cSrcweir }
663cdf0e10cSrcweir
664cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetFileName(const RequestRef & rRequest)665cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetFileName(const RequestRef& rRequest)
666cdf0e10cSrcweir {
667cdf0e10cSrcweir ::rtl::OUString sFileName = rRequest->getArgumentOrDefault(PROP_FILENAME, ::rtl::OUString());
668cdf0e10cSrcweir
669cdf0e10cSrcweir // SYNCHRONIZED->
670cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
671cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
672cdf0e10cSrcweir aLock.clear();
673cdf0e10cSrcweir // <- SYNCHRONIZED
674cdf0e10cSrcweir
675cdf0e10cSrcweir iDialog->SetFileName(reinterpret_cast<LPCTSTR>(sFileName.getStr()));
676cdf0e10cSrcweir }
677cdf0e10cSrcweir
678cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetDirectory(const RequestRef & rRequest)679cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetDirectory(const RequestRef& rRequest)
680cdf0e10cSrcweir {
681cdf0e10cSrcweir ::rtl::OUString sDirectory = rRequest->getArgumentOrDefault(PROP_DIRECTORY, ::rtl::OUString());
682cdf0e10cSrcweir bool bForce = rRequest->getArgumentOrDefault(PROP_FORCE, false);
683cdf0e10cSrcweir
684cdf0e10cSrcweir if( !m_bInExecute)
685cdf0e10cSrcweir {
686cdf0e10cSrcweir // Vista stores last used folders for file dialogs
687cdf0e10cSrcweir // so we don't want the application to change the folder
688cdf0e10cSrcweir // in most cases.
689cdf0e10cSrcweir // Store the requested folder in the mean time and decide later
690cdf0e10cSrcweir // what to do
691cdf0e10cSrcweir m_sDirectory = sDirectory;
692cdf0e10cSrcweir }
693cdf0e10cSrcweir
694cdf0e10cSrcweir // SYNCHRONIZED->
695cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
696cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
697cdf0e10cSrcweir aLock.clear();
698cdf0e10cSrcweir // <- SYNCHRONIZED
699cdf0e10cSrcweir
700cdf0e10cSrcweir ComPtr< IShellItem > pFolder;
701cdf0e10cSrcweir #ifdef __MINGW32__
70231835a35SMichael Stahl HRESULT hResult = SHCreateItemFromParsingName ( reinterpret_cast<LPCTSTR>(sDirectory.getStr()), NULL, IID_IShellItem, reinterpret_cast<void**>(&pFolder) );
703cdf0e10cSrcweir #else
704*24c56ab9SHerbert Dürr HRESULT hResult = SHCreateItemFromParsingName( sDirectory.getStr(), NULL, IID_PPV_ARGS(&pFolder) );
705cdf0e10cSrcweir #endif
706cdf0e10cSrcweir if ( FAILED(hResult) )
707cdf0e10cSrcweir return;
708cdf0e10cSrcweir
709cdf0e10cSrcweir if ( m_bInExecute || bForce )
710cdf0e10cSrcweir iDialog->SetFolder(pFolder);
711cdf0e10cSrcweir else
712cdf0e10cSrcweir {
713cdf0e10cSrcweir // Use set default folder as Microsoft recommends in the IFileDialog documentation.
714cdf0e10cSrcweir iDialog->SetDefaultFolder(pFolder);
715cdf0e10cSrcweir }
716cdf0e10cSrcweir }
717cdf0e10cSrcweir
impl_sta_GetDirectory(const RequestRef & rRequest)718cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_GetDirectory(const RequestRef& rRequest)
719cdf0e10cSrcweir {
720cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
721cdf0e10cSrcweir ComPtr< IShellItem > pFolder;
722cdf0e10cSrcweir HRESULT hResult = iDialog->GetFolder( &pFolder );
723cdf0e10cSrcweir if ( FAILED(hResult) )
724cdf0e10cSrcweir return;
725cdf0e10cSrcweir ::rtl::OUString sFolder = lcl_getURLFromShellItem ( pFolder );
726cdf0e10cSrcweir if( sFolder.getLength())
727cdf0e10cSrcweir rRequest->setArgument( PROP_DIRECTORY, sFolder );
728cdf0e10cSrcweir }
729cdf0e10cSrcweir
730cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetDefaultName(const RequestRef & rRequest)731cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetDefaultName(const RequestRef& rRequest)
732cdf0e10cSrcweir {
733cdf0e10cSrcweir ::rtl::OUString sFilename = rRequest->getArgumentOrDefault(PROP_FILENAME, ::rtl::OUString());
734cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
735cdf0e10cSrcweir
736cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
737cdf0e10cSrcweir if ( ! iCustom.is())
738cdf0e10cSrcweir return;
739cdf0e10cSrcweir
740cdf0e10cSrcweir // if we have the autoextension check box set, remove (or change ???) the extension of the filename
741cdf0e10cSrcweir // so that the autoextension mechanism can do its job
742cdf0e10cSrcweir BOOL bValue = FALSE;
743cdf0e10cSrcweir HRESULT hResult = iCustom->GetCheckButtonState( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, &bValue);
744cdf0e10cSrcweir if ( bValue )
745cdf0e10cSrcweir {
746cdf0e10cSrcweir sal_Int32 nSepPos = sFilename.lastIndexOf( '.' );
747cdf0e10cSrcweir if ( -1 != nSepPos )
748cdf0e10cSrcweir sFilename = sFilename.copy(0, nSepPos);
749cdf0e10cSrcweir }
750cdf0e10cSrcweir
751cdf0e10cSrcweir iDialog->SetFileName ( reinterpret_cast<LPCTSTR>(sFilename.getStr()));
752cdf0e10cSrcweir m_sFilename = sFilename;
753cdf0e10cSrcweir }
754cdf0e10cSrcweir
755cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_setFiltersOnDialog()756cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_setFiltersOnDialog()
757cdf0e10cSrcweir {
758cdf0e10cSrcweir // SYNCHRONIZED->
759cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
760cdf0e10cSrcweir
761cdf0e10cSrcweir ::std::vector< COMDLG_FILTERSPEC > lFilters = lcl_buildFilterList(m_lFilters);
762cdf0e10cSrcweir ::rtl::OUString sCurrentFilter = m_lFilters.getCurrentFilter();
763cdf0e10cSrcweir sal_Int32 nCurrentFilter = m_lFilters.getFilterPos(sCurrentFilter);
764cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
765cdf0e10cSrcweir TFileDialogCustomize iCustomize = impl_getCustomizeInterface();
766cdf0e10cSrcweir
767cdf0e10cSrcweir aLock.clear();
768cdf0e10cSrcweir // <- SYNCHRONIZED
769cdf0e10cSrcweir
7701f5d742fSAndre Fischer if (lFilters.empty())
7711f5d742fSAndre Fischer return;
7721f5d742fSAndre Fischer
773cdf0e10cSrcweir COMDLG_FILTERSPEC *pFilt = &lFilters[0];
774cdf0e10cSrcweir iDialog->SetFileTypes(lFilters.size(), pFilt/*&lFilters[0]*/);
775cdf0e10cSrcweir iDialog->SetFileTypeIndex(nCurrentFilter + 1);
776cdf0e10cSrcweir
777cdf0e10cSrcweir BOOL bValue = FALSE;
778cdf0e10cSrcweir HRESULT hResult = iCustomize->GetCheckButtonState( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, &bValue);
779cdf0e10cSrcweir
780cdf0e10cSrcweir if ( bValue )
781cdf0e10cSrcweir {
782cdf0e10cSrcweir LPCWSTR lpFilterExt = lFilters[0].pszSpec;
783cdf0e10cSrcweir
784cdf0e10cSrcweir lpFilterExt = wcsrchr( lpFilterExt, '.' );
785cdf0e10cSrcweir if ( lpFilterExt )
786cdf0e10cSrcweir lpFilterExt++;
787cdf0e10cSrcweir iDialog->SetDefaultExtension( lpFilterExt );
788cdf0e10cSrcweir }
789cdf0e10cSrcweir
790cdf0e10cSrcweir }
791cdf0e10cSrcweir
792cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_getSelectedFiles(const RequestRef & rRequest)793cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_getSelectedFiles(const RequestRef& rRequest)
794cdf0e10cSrcweir {
795cdf0e10cSrcweir // SYNCHRONIZED->
796cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
797cdf0e10cSrcweir
798cdf0e10cSrcweir TFileOpenDialog iOpen = m_iDialogOpen;
799cdf0e10cSrcweir TFileSaveDialog iSave = m_iDialogSave;
800cdf0e10cSrcweir ::sal_Bool bInExecute = m_bInExecute;
801cdf0e10cSrcweir
802cdf0e10cSrcweir aLock.clear();
803cdf0e10cSrcweir // <- SYNCHRONIZED
804cdf0e10cSrcweir
805cdf0e10cSrcweir // ask dialog for results
806cdf0e10cSrcweir // Note : we must differ between single/multi selection !
807cdf0e10cSrcweir // Note further: we must react different if dialog is in execute or not .-(
808cdf0e10cSrcweir ComPtr< IShellItem > iItem;
809cdf0e10cSrcweir ComPtr< IShellItemArray > iItems;
810cdf0e10cSrcweir HRESULT hResult = E_FAIL;
811cdf0e10cSrcweir
812cdf0e10cSrcweir if (iOpen.is())
813cdf0e10cSrcweir {
814cdf0e10cSrcweir if (bInExecute)
815cdf0e10cSrcweir hResult = iOpen->GetSelectedItems(&iItems);
816cdf0e10cSrcweir else
817cdf0e10cSrcweir {
818cdf0e10cSrcweir hResult = iOpen->GetResults(&iItems);
819cdf0e10cSrcweir if (FAILED(hResult))
820cdf0e10cSrcweir hResult = iOpen->GetResult(&iItem);
821cdf0e10cSrcweir }
822cdf0e10cSrcweir }
823cdf0e10cSrcweir else
824cdf0e10cSrcweir if (iSave.is())
825cdf0e10cSrcweir {
826cdf0e10cSrcweir if (bInExecute)
827cdf0e10cSrcweir hResult = iSave->GetCurrentSelection(&iItem);
828cdf0e10cSrcweir else
829cdf0e10cSrcweir hResult = iSave->GetResult(&iItem);
830cdf0e10cSrcweir }
831cdf0e10cSrcweir
832cdf0e10cSrcweir if (FAILED(hResult))
833cdf0e10cSrcweir return;
834cdf0e10cSrcweir
835cdf0e10cSrcweir // convert and pack results
836cdf0e10cSrcweir TStringList lFiles;
837cdf0e10cSrcweir if (iItem.is())
838cdf0e10cSrcweir {
839cdf0e10cSrcweir const ::rtl::OUString sURL = lcl_getURLFromShellItem(iItem);
840cdf0e10cSrcweir if (sURL.getLength() > 0)
841cdf0e10cSrcweir lFiles.push_back(sURL);
842cdf0e10cSrcweir }
843cdf0e10cSrcweir
844cdf0e10cSrcweir if (iItems.is())
845cdf0e10cSrcweir {
846cdf0e10cSrcweir DWORD nCount;
847cdf0e10cSrcweir hResult = iItems->GetCount(&nCount);
848cdf0e10cSrcweir if ( SUCCEEDED(hResult) )
849cdf0e10cSrcweir {
850cdf0e10cSrcweir for (DWORD i=0; i<nCount; ++i)
851cdf0e10cSrcweir {
852cdf0e10cSrcweir hResult = iItems->GetItemAt(i, &iItem);
853cdf0e10cSrcweir if ( SUCCEEDED(hResult) )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir const ::rtl::OUString sURL = lcl_getURLFromShellItem(iItem);
856cdf0e10cSrcweir if (sURL.getLength() > 0)
857cdf0e10cSrcweir lFiles.push_back(sURL);
858cdf0e10cSrcweir }
859cdf0e10cSrcweir }
860cdf0e10cSrcweir }
861cdf0e10cSrcweir }
862cdf0e10cSrcweir
863cdf0e10cSrcweir rRequest->setArgument(PROP_SELECTED_FILES, lFiles.getAsConstList());
864cdf0e10cSrcweir }
865cdf0e10cSrcweir
866cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_ShowDialogModal(const RequestRef & rRequest)867cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_ShowDialogModal(const RequestRef& rRequest)
868cdf0e10cSrcweir {
869cdf0e10cSrcweir impl_sta_setFiltersOnDialog();
870cdf0e10cSrcweir
871cdf0e10cSrcweir // SYNCHRONIZED->
872cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
873cdf0e10cSrcweir
874cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
875cdf0e10cSrcweir TFileOpenDialog iOpen = m_iDialogOpen;
876cdf0e10cSrcweir TFileSaveDialog iSave = m_iDialogSave;
877cdf0e10cSrcweir
878cdf0e10cSrcweir // it's important to know if we are showing the dialog.
879cdf0e10cSrcweir // Some dialog interface methods cant be called then or some
880cdf0e10cSrcweir // tasks must be done differently .-) (e.g. see impl_sta_getSelectedFiles())
881cdf0e10cSrcweir m_bInExecute = sal_True;
882cdf0e10cSrcweir
883cdf0e10cSrcweir m_bWasExecuted = sal_True;
884cdf0e10cSrcweir
885cdf0e10cSrcweir aLock.clear();
886cdf0e10cSrcweir // <- SYNCHRONIZED
887cdf0e10cSrcweir
888cdf0e10cSrcweir // we set the directory only if we have a save dialog and a filename
889cdf0e10cSrcweir // for the other cases, the file dialog remembers its last location
890cdf0e10cSrcweir // according to its client guid.
891cdf0e10cSrcweir if( m_sDirectory.getLength())
892cdf0e10cSrcweir {
893cdf0e10cSrcweir ComPtr< IShellItem > pFolder;
894cdf0e10cSrcweir #ifdef __MINGW32__
89531835a35SMichael Stahl HRESULT hResult = SHCreateItemFromParsingName ( reinterpret_cast<LPCTSTR>(m_sDirectory.getStr()), NULL, IID_IShellItem, reinterpret_cast<void**>(&pFolder) );
896cdf0e10cSrcweir #else
897*24c56ab9SHerbert Dürr HRESULT hResult = SHCreateItemFromParsingName( m_sDirectory.getStr(), NULL, IID_PPV_ARGS(&pFolder) );
898cdf0e10cSrcweir #endif
899cdf0e10cSrcweir if ( SUCCEEDED(hResult) )
900cdf0e10cSrcweir {
901cdf0e10cSrcweir if (m_sFilename.getLength())
902cdf0e10cSrcweir {
903cdf0e10cSrcweir ::rtl::OUString aFileURL(m_sDirectory);
904cdf0e10cSrcweir sal_Int32 nIndex = aFileURL.lastIndexOf('/');
905cdf0e10cSrcweir if (nIndex != aFileURL.getLength()-1)
906cdf0e10cSrcweir aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/"));
907cdf0e10cSrcweir aFileURL += m_sFilename;
908cdf0e10cSrcweir
909cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
910cdf0e10cSrcweir
911cdf0e10cSrcweir BOOL bValue = FALSE;
912cdf0e10cSrcweir HRESULT hResult = iCustom->GetCheckButtonState( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, &bValue);
913cdf0e10cSrcweir if ( bValue )
914cdf0e10cSrcweir {
915cdf0e10cSrcweir ::rtl::OUString aExt;
916cdf0e10cSrcweir UINT nFileType;
917cdf0e10cSrcweir hResult = iDialog->GetFileTypeIndex(&nFileType);
918fb76aa18SAriel Constenla-Haile if ( SUCCEEDED(hResult) && nFileType > 0 )
919cdf0e10cSrcweir {
920cdf0e10cSrcweir ::sal_Int32 nRealIndex = (nFileType-1); // COM dialog base on 1 ... filter container on 0 .-)
921cdf0e10cSrcweir ::std::vector< COMDLG_FILTERSPEC > lFilters = lcl_buildFilterList(m_lFilters);
922fb76aa18SAriel Constenla-Haile if ( nRealIndex < lFilters.size() )
923fb76aa18SAriel Constenla-Haile {
924fb76aa18SAriel Constenla-Haile LPCWSTR lpFilterExt = lFilters[nRealIndex].pszSpec;
925fb76aa18SAriel Constenla-Haile
926fb76aa18SAriel Constenla-Haile lpFilterExt = wcsrchr( lpFilterExt, '.' );
927fb76aa18SAriel Constenla-Haile if ( lpFilterExt )
928fb76aa18SAriel Constenla-Haile aFileURL += reinterpret_cast<const sal_Unicode*>(lpFilterExt);
929fb76aa18SAriel Constenla-Haile }
930cdf0e10cSrcweir }
931cdf0e10cSrcweir }
932cdf0e10cSrcweir
933cdf0e10cSrcweir // Check existence of file. Set folder only for this special case
934cdf0e10cSrcweir ::rtl::OUString aSystemPath;
935cdf0e10cSrcweir osl_getSystemPathFromFileURL( aFileURL.pData, &aSystemPath.pData );
936cdf0e10cSrcweir
937cdf0e10cSrcweir WIN32_FIND_DATA aFindFileData;
938cdf0e10cSrcweir HANDLE hFind = FindFirstFile( reinterpret_cast<LPCWSTR>(aSystemPath.getStr()), &aFindFileData );
939cdf0e10cSrcweir if (hFind != INVALID_HANDLE_VALUE)
940cdf0e10cSrcweir iDialog->SetFolder(pFolder);
941cdf0e10cSrcweir else
942cdf0e10cSrcweir hResult = iDialog->AddPlace(pFolder, FDAP_TOP);
943cdf0e10cSrcweir
944cdf0e10cSrcweir FindClose( hFind );
945cdf0e10cSrcweir }
946cdf0e10cSrcweir else
947cdf0e10cSrcweir hResult = iDialog->AddPlace(pFolder, FDAP_TOP);
948cdf0e10cSrcweir }
949cdf0e10cSrcweir }
950cdf0e10cSrcweir
951cdf0e10cSrcweir
952cdf0e10cSrcweir HRESULT hResult = E_FAIL;
953cdf0e10cSrcweir try
954cdf0e10cSrcweir {
955cdf0e10cSrcweir // show dialog and wait for user decision
956cdf0e10cSrcweir if (iOpen.is())
957cdf0e10cSrcweir hResult = iOpen->Show( m_hParentWindow ); // parent window needed
958cdf0e10cSrcweir else
959cdf0e10cSrcweir if (iSave.is())
960cdf0e10cSrcweir hResult = iSave->Show( m_hParentWindow ); // parent window needed
961cdf0e10cSrcweir }
962cdf0e10cSrcweir catch(...)
963cdf0e10cSrcweir {}
964cdf0e10cSrcweir
965cdf0e10cSrcweir // SYNCHRONIZED->
966cdf0e10cSrcweir aLock.reset();
967cdf0e10cSrcweir m_bInExecute = sal_False;
968cdf0e10cSrcweir aLock.clear();
969cdf0e10cSrcweir // <- SYNCHRONIZED
970cdf0e10cSrcweir
971cdf0e10cSrcweir if ( FAILED(hResult) )
972cdf0e10cSrcweir return;
973cdf0e10cSrcweir
974cdf0e10cSrcweir impl_sta_getSelectedFiles(rRequest);
975cdf0e10cSrcweir rRequest->setArgument(PROP_DIALOG_SHOW_RESULT, sal_True);
976cdf0e10cSrcweir }
977cdf0e10cSrcweir
978cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_getBaseDialogInterface()979cdf0e10cSrcweir TFileDialog VistaFilePickerImpl::impl_getBaseDialogInterface()
980cdf0e10cSrcweir {
981cdf0e10cSrcweir TFileDialog iDialog;
982cdf0e10cSrcweir
983cdf0e10cSrcweir // SYNCHRONIZED->
984cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
985cdf0e10cSrcweir
986cdf0e10cSrcweir if (m_iDialogOpen.is())
987cdf0e10cSrcweir #ifdef __MINGW32__
988cdf0e10cSrcweir m_iDialogOpen->QueryInterface(IID_IFileDialog, (void**)(&iDialog));
989cdf0e10cSrcweir #else
990cdf0e10cSrcweir m_iDialogOpen.query(&iDialog);
991cdf0e10cSrcweir #endif
992cdf0e10cSrcweir if (m_iDialogSave.is())
993cdf0e10cSrcweir #ifdef __MINGW32__
994cdf0e10cSrcweir m_iDialogSave->QueryInterface(IID_IFileDialog, (void**)(&iDialog));
995cdf0e10cSrcweir #else
996cdf0e10cSrcweir m_iDialogSave.query(&iDialog);
997cdf0e10cSrcweir #endif
998cdf0e10cSrcweir
999cdf0e10cSrcweir return iDialog;
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_getCustomizeInterface()1003cdf0e10cSrcweir TFileDialogCustomize VistaFilePickerImpl::impl_getCustomizeInterface()
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir TFileDialogCustomize iCustom;
1006cdf0e10cSrcweir
1007cdf0e10cSrcweir // SYNCHRONIZED->
1008cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
1009cdf0e10cSrcweir
1010cdf0e10cSrcweir if (m_iDialogOpen.is())
1011cdf0e10cSrcweir #ifdef __MINGW32__
1012cdf0e10cSrcweir m_iDialogOpen->QueryInterface(IID_IFileDialogCustomize, (void**)(&iCustom));
1013cdf0e10cSrcweir #else
1014cdf0e10cSrcweir m_iDialogOpen.query(&iCustom);
1015cdf0e10cSrcweir #endif
1016cdf0e10cSrcweir else
1017cdf0e10cSrcweir if (m_iDialogSave.is())
1018cdf0e10cSrcweir #ifdef __MINGW32__
1019cdf0e10cSrcweir m_iDialogSave->QueryInterface(IID_IFileDialogCustomize, (void**)(&iCustom));
1020cdf0e10cSrcweir #else
1021cdf0e10cSrcweir m_iDialogSave.query(&iCustom);
1022cdf0e10cSrcweir #endif
1023cdf0e10cSrcweir
1024cdf0e10cSrcweir return iCustom;
1025cdf0e10cSrcweir }
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir //-------------------------------------------------------------------------------
lcl_removeControlItemsWorkaround(const TFileDialogCustomize & iCustom,::sal_Int16 nControlId)1028cdf0e10cSrcweir void lcl_removeControlItemsWorkaround(const TFileDialogCustomize& iCustom ,
1029cdf0e10cSrcweir ::sal_Int16 nControlId)
1030cdf0e10cSrcweir {
1031cdf0e10cSrcweir ::sal_Int32 i = 0;
1032cdf0e10cSrcweir HRESULT hResult;
1033cdf0e10cSrcweir
1034cdf0e10cSrcweir hResult = iCustom->SetSelectedControlItem(nControlId, 1000);
1035cdf0e10cSrcweir hResult = S_OK;
1036cdf0e10cSrcweir while ( SUCCEEDED(hResult) )
1037cdf0e10cSrcweir hResult = iCustom->RemoveControlItem(nControlId, i++);
1038cdf0e10cSrcweir }
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetControlValue(const RequestRef & rRequest)1041cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetControlValue(const RequestRef& rRequest)
1042cdf0e10cSrcweir {
1043cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID );
1044cdf0e10cSrcweir ::sal_Int16 nAction = rRequest->getArgumentOrDefault(PROP_CONTROL_ACTION, INVALID_CONTROL_ACTION);
1045cdf0e10cSrcweir css::uno::Any aValue = rRequest->getArgumentOrDefault(PROP_CONTROL_VALUE , css::uno::Any() );
1046cdf0e10cSrcweir
1047cdf0e10cSrcweir // dont check for right values here ...
1048cdf0e10cSrcweir // most parameters are optional !
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
1051cdf0e10cSrcweir if ( ! iCustom.is())
1052cdf0e10cSrcweir return;
1053cdf0e10cSrcweir
1054cdf0e10cSrcweir switch (nId)
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
1057cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
1058cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY :
1059cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
1060cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK :
1061cdf0e10cSrcweir //case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW : // can be ignored ... preview is supported native now !
1062cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir ::sal_Bool bValue = sal_False;
1065cdf0e10cSrcweir aValue >>= bValue;
1066cdf0e10cSrcweir iCustom->SetCheckButtonState(nId, bValue);
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir break;
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_VERSION :
1071cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
1072cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir HRESULT hResult;
1075cdf0e10cSrcweir switch (nAction)
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir case css::ui::dialogs::ControlActions::DELETE_ITEMS :
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir hResult = iCustom->RemoveAllControlItems(nId);
1080cdf0e10cSrcweir if ( FAILED(hResult) )
1081cdf0e10cSrcweir lcl_removeControlItemsWorkaround(iCustom, nId);
1082cdf0e10cSrcweir }
1083cdf0e10cSrcweir break;
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir case css::ui::dialogs::ControlActions::ADD_ITEMS :
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lItems;
1088cdf0e10cSrcweir aValue >>= lItems;
1089cdf0e10cSrcweir for (::sal_Int32 i=0; i<lItems.getLength(); ++i)
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir const ::rtl::OUString& sItem = lItems[i];
1092cdf0e10cSrcweir hResult = iCustom->AddControlItem(nId, i, reinterpret_cast<LPCTSTR>(sItem.getStr()));
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir break;
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir case css::ui::dialogs::ControlActions::SET_SELECT_ITEM :
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir ::sal_Int32 nItem = 0;
1100cdf0e10cSrcweir aValue >>= nItem;
1101cdf0e10cSrcweir hResult = iCustom->SetSelectedControlItem(nId, nItem);
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir break;
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir break;
1107cdf0e10cSrcweir
1108cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
1109cdf0e10cSrcweir {
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir break;
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir
1115cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_GetControlValue(const RequestRef & rRequest)1116cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_GetControlValue(const RequestRef& rRequest)
1117cdf0e10cSrcweir {
1118cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID );
1119cdf0e10cSrcweir ::sal_Int16 nAction = rRequest->getArgumentOrDefault(PROP_CONTROL_ACTION, INVALID_CONTROL_ACTION);
1120cdf0e10cSrcweir
1121cdf0e10cSrcweir // dont check for right values here ...
1122cdf0e10cSrcweir // most parameters are optional !
1123cdf0e10cSrcweir
1124cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
1125cdf0e10cSrcweir if ( ! iCustom.is())
1126cdf0e10cSrcweir return;
1127cdf0e10cSrcweir
1128cdf0e10cSrcweir css::uno::Any aValue;
1129cdf0e10cSrcweir if( m_bWasExecuted )
1130cdf0e10cSrcweir switch (nId)
1131cdf0e10cSrcweir {
1132cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
1133cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY :
1134cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
1135cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK :
1136cdf0e10cSrcweir //case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW : // can be ignored ... preview is supported native now !
1137cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
1138cdf0e10cSrcweir {
1139cdf0e10cSrcweir BOOL bValue = FALSE;
1140cdf0e10cSrcweir HRESULT hResult = iCustom->GetCheckButtonState(nId, &bValue);
1141cdf0e10cSrcweir if ( SUCCEEDED(hResult) )
1142cdf0e10cSrcweir aValue = css::uno::makeAny((sal_Bool)bValue);
1143cdf0e10cSrcweir }
1144cdf0e10cSrcweir break;
1145cdf0e10cSrcweir }
1146cdf0e10cSrcweir
1147cdf0e10cSrcweir if (aValue.hasValue())
1148cdf0e10cSrcweir rRequest->setArgument(PROP_CONTROL_VALUE, aValue);
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_SetControlLabel(const RequestRef & rRequest)1152cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetControlLabel(const RequestRef& rRequest)
1153cdf0e10cSrcweir {
1154cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID );
1155cdf0e10cSrcweir ::rtl::OUString sLabel = rRequest->getArgumentOrDefault(PROP_CONTROL_LABEL, ::rtl::OUString() );
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir // dont check for right values here ...
1158cdf0e10cSrcweir // most parameters are optional !
1159cdf0e10cSrcweir
1160cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
1161cdf0e10cSrcweir if ( ! iCustom.is())
1162cdf0e10cSrcweir return;
1163cdf0e10cSrcweir iCustom->SetControlLabel ( nId, reinterpret_cast<LPCTSTR>(sLabel.getStr()));
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_GetControlLabel(const RequestRef &)1167cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_GetControlLabel(const RequestRef& /*rRequest*/)
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir
1171cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_sta_EnableControl(const RequestRef & rRequest)1172cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_EnableControl(const RequestRef& rRequest)
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID );
1175cdf0e10cSrcweir ::sal_Bool bEnabled = rRequest->getArgumentOrDefault(PROP_CONTROL_ENABLE, (::sal_Bool)sal_True);
1176cdf0e10cSrcweir
1177cdf0e10cSrcweir // dont check for right values here ...
1178cdf0e10cSrcweir // most parameters are optional !
1179cdf0e10cSrcweir
1180cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface();
1181cdf0e10cSrcweir if ( ! iCustom.is())
1182cdf0e10cSrcweir return;
1183cdf0e10cSrcweir
1184cdf0e10cSrcweir CDCONTROLSTATEF eState = CDCS_VISIBLE;
1185cdf0e10cSrcweir if (bEnabled)
1186cdf0e10cSrcweir eState |= CDCS_ENABLED;
1187cdf0e10cSrcweir else
1188cdf0e10cSrcweir eState |= CDCS_INACTIVE;
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir iCustom->SetControlState(nId, eState);
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir //-------------------------------------------------------------------------------
impl_SetDefaultExtension(const rtl::OUString & currentFilter)1193cdf0e10cSrcweir void VistaFilePickerImpl::impl_SetDefaultExtension( const rtl::OUString& currentFilter )
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
1196cdf0e10cSrcweir if (currentFilter.getLength())
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir rtl::OUString FilterExt;
1199cdf0e10cSrcweir m_lFilters.getFilter(currentFilter, FilterExt);
1200cdf0e10cSrcweir
1201cdf0e10cSrcweir sal_Int32 posOfPoint = FilterExt.indexOf(L'.');
1202cdf0e10cSrcweir const sal_Unicode* pFirstExtStart = FilterExt.getStr() + posOfPoint + 1;
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir sal_Int32 posOfSemiColon = FilterExt.indexOf(L';') - 1;
1205cdf0e10cSrcweir if (posOfSemiColon < 0)
1206cdf0e10cSrcweir posOfSemiColon = FilterExt.getLength() - 1;
1207cdf0e10cSrcweir
1208cdf0e10cSrcweir FilterExt = rtl::OUString(pFirstExtStart, posOfSemiColon - posOfPoint);
1209cdf0e10cSrcweir iDialog->SetDefaultExtension ( reinterpret_cast<LPCTSTR>(FilterExt.getStr()) );
1210cdf0e10cSrcweir }
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir
impl_refreshFileDialog(TFileDialog iDialog)1213cdf0e10cSrcweir static void impl_refreshFileDialog( TFileDialog iDialog )
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir if ( SUCCEEDED(iDialog->SetFileName(L"")) &&
1216cdf0e10cSrcweir SUCCEEDED(iDialog->SetFileName(L"*.*")) )
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir IOleWindow* iOleWindow;
121931835a35SMichael Stahl #ifdef __MINGW32__
122031835a35SMichael Stahl if (SUCCEEDED(iDialog->QueryInterface(IID_IOleWindow, reinterpret_cast<void**>(&iOleWindow))))
122131835a35SMichael Stahl #else
1222cdf0e10cSrcweir if (SUCCEEDED(iDialog->QueryInterface(IID_PPV_ARGS(&iOleWindow))))
122331835a35SMichael Stahl #endif
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir HWND hwnd;
1226cdf0e10cSrcweir if (SUCCEEDED(iOleWindow->GetWindow(&hwnd)))
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir PostMessage(hwnd, WM_COMMAND, IDOK, 0);
1229cdf0e10cSrcweir }
1230cdf0e10cSrcweir iOleWindow->Release();
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir
1235cdf0e10cSrcweir //-------------------------------------------------------------------------------
onAutoExtensionChanged(bool bChecked)1236cdf0e10cSrcweir void VistaFilePickerImpl::onAutoExtensionChanged (bool bChecked)
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir // SYNCHRONIZED->
1239cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex);
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir const ::rtl::OUString sFilter = m_lFilters.getCurrentFilter ();
1242cdf0e10cSrcweir ::rtl::OUString sExt ;
1243cdf0e10cSrcweir if ( !m_lFilters.getFilter (sFilter, sExt))
1244cdf0e10cSrcweir return;
1245cdf0e10cSrcweir
1246cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface();
1247cdf0e10cSrcweir
1248cdf0e10cSrcweir aLock.clear();
1249cdf0e10cSrcweir // <- SYNCHRONIZED
1250cdf0e10cSrcweir
1251cdf0e10cSrcweir LPCWSTR pExt = 0;
1252cdf0e10cSrcweir if ( bChecked )
1253cdf0e10cSrcweir {
1254cdf0e10cSrcweir pExt = reinterpret_cast<LPCTSTR>(sExt.getStr());
1255cdf0e10cSrcweir pExt = wcsrchr( pExt, '.' );
1256cdf0e10cSrcweir if ( pExt )
1257cdf0e10cSrcweir pExt++;
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir iDialog->SetDefaultExtension( pExt );
1260cdf0e10cSrcweir }
1261cdf0e10cSrcweir
onFileTypeChanged(UINT)1262cdf0e10cSrcweir bool VistaFilePickerImpl::onFileTypeChanged( UINT /*nTypeIndex*/ )
1263cdf0e10cSrcweir {
1264cdf0e10cSrcweir return true;
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir
1267cdf0e10cSrcweir } // namespace vista
1268cdf0e10cSrcweir } // namespace win32
1269cdf0e10cSrcweir } // namespace fpicker
1270