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 10cdf0e10cSrcweir * 11*b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*b557fc96SAndrew Rist *************************************************************/ 21*b557fc96SAndrew Rist 22*b557fc96SAndrew 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 44cdf0e10cSrcweir inline bool is_current_process_window(HWND hwnd) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir DWORD pid; 47cdf0e10cSrcweir GetWindowThreadProcessId(hwnd, &pid); 48cdf0e10cSrcweir return (pid == GetCurrentProcessId()); 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 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 //----------------------------------------------------------------------------- 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 //----------------------------------------------------------------------------------------- 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 //----------------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 157cdf0e10cSrcweir VistaFilePickerImpl::~VistaFilePickerImpl() 158cdf0e10cSrcweir { 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 281cdf0e10cSrcweir void VistaFilePickerImpl::after() 282cdf0e10cSrcweir { 283cdf0e10cSrcweir CoUninitialize(); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 704cdf0e10cSrcweir HRESULT hResult = SHCreateItemFromParsingName ( sDirectory, 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 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 //------------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------- 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 770cdf0e10cSrcweir COMDLG_FILTERSPEC *pFilt = &lFilters[0]; 771cdf0e10cSrcweir iDialog->SetFileTypes(lFilters.size(), pFilt/*&lFilters[0]*/); 772cdf0e10cSrcweir iDialog->SetFileTypeIndex(nCurrentFilter + 1); 773cdf0e10cSrcweir 774cdf0e10cSrcweir BOOL bValue = FALSE; 775cdf0e10cSrcweir HRESULT hResult = iCustomize->GetCheckButtonState( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, &bValue); 776cdf0e10cSrcweir 777cdf0e10cSrcweir if ( bValue ) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir LPCWSTR lpFilterExt = lFilters[0].pszSpec; 780cdf0e10cSrcweir 781cdf0e10cSrcweir lpFilterExt = wcsrchr( lpFilterExt, '.' ); 782cdf0e10cSrcweir if ( lpFilterExt ) 783cdf0e10cSrcweir lpFilterExt++; 784cdf0e10cSrcweir iDialog->SetDefaultExtension( lpFilterExt ); 785cdf0e10cSrcweir } 786cdf0e10cSrcweir 787cdf0e10cSrcweir } 788cdf0e10cSrcweir 789cdf0e10cSrcweir //------------------------------------------------------------------------------- 790cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_getSelectedFiles(const RequestRef& rRequest) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir // SYNCHRONIZED-> 793cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex); 794cdf0e10cSrcweir 795cdf0e10cSrcweir TFileOpenDialog iOpen = m_iDialogOpen; 796cdf0e10cSrcweir TFileSaveDialog iSave = m_iDialogSave; 797cdf0e10cSrcweir ::sal_Bool bInExecute = m_bInExecute; 798cdf0e10cSrcweir 799cdf0e10cSrcweir aLock.clear(); 800cdf0e10cSrcweir // <- SYNCHRONIZED 801cdf0e10cSrcweir 802cdf0e10cSrcweir // ask dialog for results 803cdf0e10cSrcweir // Note : we must differ between single/multi selection ! 804cdf0e10cSrcweir // Note further: we must react different if dialog is in execute or not .-( 805cdf0e10cSrcweir ComPtr< IShellItem > iItem; 806cdf0e10cSrcweir ComPtr< IShellItemArray > iItems; 807cdf0e10cSrcweir HRESULT hResult = E_FAIL; 808cdf0e10cSrcweir 809cdf0e10cSrcweir if (iOpen.is()) 810cdf0e10cSrcweir { 811cdf0e10cSrcweir if (bInExecute) 812cdf0e10cSrcweir hResult = iOpen->GetSelectedItems(&iItems); 813cdf0e10cSrcweir else 814cdf0e10cSrcweir { 815cdf0e10cSrcweir hResult = iOpen->GetResults(&iItems); 816cdf0e10cSrcweir if (FAILED(hResult)) 817cdf0e10cSrcweir hResult = iOpen->GetResult(&iItem); 818cdf0e10cSrcweir } 819cdf0e10cSrcweir } 820cdf0e10cSrcweir else 821cdf0e10cSrcweir if (iSave.is()) 822cdf0e10cSrcweir { 823cdf0e10cSrcweir if (bInExecute) 824cdf0e10cSrcweir hResult = iSave->GetCurrentSelection(&iItem); 825cdf0e10cSrcweir else 826cdf0e10cSrcweir hResult = iSave->GetResult(&iItem); 827cdf0e10cSrcweir } 828cdf0e10cSrcweir 829cdf0e10cSrcweir if (FAILED(hResult)) 830cdf0e10cSrcweir return; 831cdf0e10cSrcweir 832cdf0e10cSrcweir // convert and pack results 833cdf0e10cSrcweir TStringList lFiles; 834cdf0e10cSrcweir if (iItem.is()) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir const ::rtl::OUString sURL = lcl_getURLFromShellItem(iItem); 837cdf0e10cSrcweir if (sURL.getLength() > 0) 838cdf0e10cSrcweir lFiles.push_back(sURL); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir if (iItems.is()) 842cdf0e10cSrcweir { 843cdf0e10cSrcweir DWORD nCount; 844cdf0e10cSrcweir hResult = iItems->GetCount(&nCount); 845cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir for (DWORD i=0; i<nCount; ++i) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir hResult = iItems->GetItemAt(i, &iItem); 850cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir const ::rtl::OUString sURL = lcl_getURLFromShellItem(iItem); 853cdf0e10cSrcweir if (sURL.getLength() > 0) 854cdf0e10cSrcweir lFiles.push_back(sURL); 855cdf0e10cSrcweir } 856cdf0e10cSrcweir } 857cdf0e10cSrcweir } 858cdf0e10cSrcweir } 859cdf0e10cSrcweir 860cdf0e10cSrcweir rRequest->setArgument(PROP_SELECTED_FILES, lFiles.getAsConstList()); 861cdf0e10cSrcweir } 862cdf0e10cSrcweir 863cdf0e10cSrcweir //------------------------------------------------------------------------------- 864cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_ShowDialogModal(const RequestRef& rRequest) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir impl_sta_setFiltersOnDialog(); 867cdf0e10cSrcweir 868cdf0e10cSrcweir // SYNCHRONIZED-> 869cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex); 870cdf0e10cSrcweir 871cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface(); 872cdf0e10cSrcweir TFileOpenDialog iOpen = m_iDialogOpen; 873cdf0e10cSrcweir TFileSaveDialog iSave = m_iDialogSave; 874cdf0e10cSrcweir 875cdf0e10cSrcweir // it's important to know if we are showing the dialog. 876cdf0e10cSrcweir // Some dialog interface methods cant be called then or some 877cdf0e10cSrcweir // tasks must be done differently .-) (e.g. see impl_sta_getSelectedFiles()) 878cdf0e10cSrcweir m_bInExecute = sal_True; 879cdf0e10cSrcweir 880cdf0e10cSrcweir m_bWasExecuted = sal_True; 881cdf0e10cSrcweir 882cdf0e10cSrcweir aLock.clear(); 883cdf0e10cSrcweir // <- SYNCHRONIZED 884cdf0e10cSrcweir 885cdf0e10cSrcweir // we set the directory only if we have a save dialog and a filename 886cdf0e10cSrcweir // for the other cases, the file dialog remembers its last location 887cdf0e10cSrcweir // according to its client guid. 888cdf0e10cSrcweir if( m_sDirectory.getLength()) 889cdf0e10cSrcweir { 890cdf0e10cSrcweir ComPtr< IShellItem > pFolder; 891cdf0e10cSrcweir #ifdef __MINGW32__ 89231835a35SMichael Stahl HRESULT hResult = SHCreateItemFromParsingName ( reinterpret_cast<LPCTSTR>(m_sDirectory.getStr()), NULL, IID_IShellItem, reinterpret_cast<void**>(&pFolder) ); 893cdf0e10cSrcweir #else 894cdf0e10cSrcweir HRESULT hResult = SHCreateItemFromParsingName ( m_sDirectory, NULL, IID_PPV_ARGS(&pFolder) ); 895cdf0e10cSrcweir #endif 896cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 897cdf0e10cSrcweir { 898cdf0e10cSrcweir if (m_sFilename.getLength()) 899cdf0e10cSrcweir { 900cdf0e10cSrcweir ::rtl::OUString aFileURL(m_sDirectory); 901cdf0e10cSrcweir sal_Int32 nIndex = aFileURL.lastIndexOf('/'); 902cdf0e10cSrcweir if (nIndex != aFileURL.getLength()-1) 903cdf0e10cSrcweir aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/")); 904cdf0e10cSrcweir aFileURL += m_sFilename; 905cdf0e10cSrcweir 906cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface(); 907cdf0e10cSrcweir 908cdf0e10cSrcweir BOOL bValue = FALSE; 909cdf0e10cSrcweir HRESULT hResult = iCustom->GetCheckButtonState( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, &bValue); 910cdf0e10cSrcweir if ( bValue ) 911cdf0e10cSrcweir { 912cdf0e10cSrcweir ::rtl::OUString aExt; 913cdf0e10cSrcweir UINT nFileType; 914cdf0e10cSrcweir hResult = iDialog->GetFileTypeIndex(&nFileType); 915cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 916cdf0e10cSrcweir { 917cdf0e10cSrcweir ::sal_Int32 nRealIndex = (nFileType-1); // COM dialog base on 1 ... filter container on 0 .-) 918cdf0e10cSrcweir ::std::vector< COMDLG_FILTERSPEC > lFilters = lcl_buildFilterList(m_lFilters); 919cdf0e10cSrcweir LPCWSTR lpFilterExt = lFilters[nRealIndex].pszSpec; 920cdf0e10cSrcweir 921cdf0e10cSrcweir lpFilterExt = wcsrchr( lpFilterExt, '.' ); 922cdf0e10cSrcweir if ( lpFilterExt ) 923cdf0e10cSrcweir aFileURL += reinterpret_cast<const sal_Unicode*>(lpFilterExt); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir } 926cdf0e10cSrcweir 927cdf0e10cSrcweir // Check existence of file. Set folder only for this special case 928cdf0e10cSrcweir ::rtl::OUString aSystemPath; 929cdf0e10cSrcweir osl_getSystemPathFromFileURL( aFileURL.pData, &aSystemPath.pData ); 930cdf0e10cSrcweir 931cdf0e10cSrcweir WIN32_FIND_DATA aFindFileData; 932cdf0e10cSrcweir HANDLE hFind = FindFirstFile( reinterpret_cast<LPCWSTR>(aSystemPath.getStr()), &aFindFileData ); 933cdf0e10cSrcweir if (hFind != INVALID_HANDLE_VALUE) 934cdf0e10cSrcweir iDialog->SetFolder(pFolder); 935cdf0e10cSrcweir else 936cdf0e10cSrcweir hResult = iDialog->AddPlace(pFolder, FDAP_TOP); 937cdf0e10cSrcweir 938cdf0e10cSrcweir FindClose( hFind ); 939cdf0e10cSrcweir } 940cdf0e10cSrcweir else 941cdf0e10cSrcweir hResult = iDialog->AddPlace(pFolder, FDAP_TOP); 942cdf0e10cSrcweir } 943cdf0e10cSrcweir } 944cdf0e10cSrcweir 945cdf0e10cSrcweir 946cdf0e10cSrcweir HRESULT hResult = E_FAIL; 947cdf0e10cSrcweir try 948cdf0e10cSrcweir { 949cdf0e10cSrcweir // show dialog and wait for user decision 950cdf0e10cSrcweir if (iOpen.is()) 951cdf0e10cSrcweir hResult = iOpen->Show( m_hParentWindow ); // parent window needed 952cdf0e10cSrcweir else 953cdf0e10cSrcweir if (iSave.is()) 954cdf0e10cSrcweir hResult = iSave->Show( m_hParentWindow ); // parent window needed 955cdf0e10cSrcweir } 956cdf0e10cSrcweir catch(...) 957cdf0e10cSrcweir {} 958cdf0e10cSrcweir 959cdf0e10cSrcweir // SYNCHRONIZED-> 960cdf0e10cSrcweir aLock.reset(); 961cdf0e10cSrcweir m_bInExecute = sal_False; 962cdf0e10cSrcweir aLock.clear(); 963cdf0e10cSrcweir // <- SYNCHRONIZED 964cdf0e10cSrcweir 965cdf0e10cSrcweir if ( FAILED(hResult) ) 966cdf0e10cSrcweir return; 967cdf0e10cSrcweir 968cdf0e10cSrcweir impl_sta_getSelectedFiles(rRequest); 969cdf0e10cSrcweir rRequest->setArgument(PROP_DIALOG_SHOW_RESULT, sal_True); 970cdf0e10cSrcweir } 971cdf0e10cSrcweir 972cdf0e10cSrcweir //------------------------------------------------------------------------------- 973cdf0e10cSrcweir TFileDialog VistaFilePickerImpl::impl_getBaseDialogInterface() 974cdf0e10cSrcweir { 975cdf0e10cSrcweir TFileDialog iDialog; 976cdf0e10cSrcweir 977cdf0e10cSrcweir // SYNCHRONIZED-> 978cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex); 979cdf0e10cSrcweir 980cdf0e10cSrcweir if (m_iDialogOpen.is()) 981cdf0e10cSrcweir #ifdef __MINGW32__ 982cdf0e10cSrcweir m_iDialogOpen->QueryInterface(IID_IFileDialog, (void**)(&iDialog)); 983cdf0e10cSrcweir #else 984cdf0e10cSrcweir m_iDialogOpen.query(&iDialog); 985cdf0e10cSrcweir #endif 986cdf0e10cSrcweir if (m_iDialogSave.is()) 987cdf0e10cSrcweir #ifdef __MINGW32__ 988cdf0e10cSrcweir m_iDialogSave->QueryInterface(IID_IFileDialog, (void**)(&iDialog)); 989cdf0e10cSrcweir #else 990cdf0e10cSrcweir m_iDialogSave.query(&iDialog); 991cdf0e10cSrcweir #endif 992cdf0e10cSrcweir 993cdf0e10cSrcweir return iDialog; 994cdf0e10cSrcweir } 995cdf0e10cSrcweir 996cdf0e10cSrcweir //------------------------------------------------------------------------------- 997cdf0e10cSrcweir TFileDialogCustomize VistaFilePickerImpl::impl_getCustomizeInterface() 998cdf0e10cSrcweir { 999cdf0e10cSrcweir TFileDialogCustomize iCustom; 1000cdf0e10cSrcweir 1001cdf0e10cSrcweir // SYNCHRONIZED-> 1002cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex); 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir if (m_iDialogOpen.is()) 1005cdf0e10cSrcweir #ifdef __MINGW32__ 1006cdf0e10cSrcweir m_iDialogOpen->QueryInterface(IID_IFileDialogCustomize, (void**)(&iCustom)); 1007cdf0e10cSrcweir #else 1008cdf0e10cSrcweir m_iDialogOpen.query(&iCustom); 1009cdf0e10cSrcweir #endif 1010cdf0e10cSrcweir else 1011cdf0e10cSrcweir if (m_iDialogSave.is()) 1012cdf0e10cSrcweir #ifdef __MINGW32__ 1013cdf0e10cSrcweir m_iDialogSave->QueryInterface(IID_IFileDialogCustomize, (void**)(&iCustom)); 1014cdf0e10cSrcweir #else 1015cdf0e10cSrcweir m_iDialogSave.query(&iCustom); 1016cdf0e10cSrcweir #endif 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir return iCustom; 1019cdf0e10cSrcweir } 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir //------------------------------------------------------------------------------- 1022cdf0e10cSrcweir void lcl_removeControlItemsWorkaround(const TFileDialogCustomize& iCustom , 1023cdf0e10cSrcweir ::sal_Int16 nControlId) 1024cdf0e10cSrcweir { 1025cdf0e10cSrcweir ::sal_Int32 i = 0; 1026cdf0e10cSrcweir HRESULT hResult; 1027cdf0e10cSrcweir 1028cdf0e10cSrcweir hResult = iCustom->SetSelectedControlItem(nControlId, 1000); 1029cdf0e10cSrcweir hResult = S_OK; 1030cdf0e10cSrcweir while ( SUCCEEDED(hResult) ) 1031cdf0e10cSrcweir hResult = iCustom->RemoveControlItem(nControlId, i++); 1032cdf0e10cSrcweir } 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir //------------------------------------------------------------------------------- 1035cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetControlValue(const RequestRef& rRequest) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID ); 1038cdf0e10cSrcweir ::sal_Int16 nAction = rRequest->getArgumentOrDefault(PROP_CONTROL_ACTION, INVALID_CONTROL_ACTION); 1039cdf0e10cSrcweir css::uno::Any aValue = rRequest->getArgumentOrDefault(PROP_CONTROL_VALUE , css::uno::Any() ); 1040cdf0e10cSrcweir 1041cdf0e10cSrcweir // dont check for right values here ... 1042cdf0e10cSrcweir // most parameters are optional ! 1043cdf0e10cSrcweir 1044cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface(); 1045cdf0e10cSrcweir if ( ! iCustom.is()) 1046cdf0e10cSrcweir return; 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir switch (nId) 1049cdf0e10cSrcweir { 1050cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION : 1051cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD : 1052cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY : 1053cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS : 1054cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK : 1055cdf0e10cSrcweir //case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW : // can be ignored ... preview is supported native now ! 1056cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION : 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir ::sal_Bool bValue = sal_False; 1059cdf0e10cSrcweir aValue >>= bValue; 1060cdf0e10cSrcweir iCustom->SetCheckButtonState(nId, bValue); 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir break; 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_VERSION : 1065cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_TEMPLATE : 1066cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE : 1067cdf0e10cSrcweir { 1068cdf0e10cSrcweir HRESULT hResult; 1069cdf0e10cSrcweir switch (nAction) 1070cdf0e10cSrcweir { 1071cdf0e10cSrcweir case css::ui::dialogs::ControlActions::DELETE_ITEMS : 1072cdf0e10cSrcweir { 1073cdf0e10cSrcweir hResult = iCustom->RemoveAllControlItems(nId); 1074cdf0e10cSrcweir if ( FAILED(hResult) ) 1075cdf0e10cSrcweir lcl_removeControlItemsWorkaround(iCustom, nId); 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir break; 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir case css::ui::dialogs::ControlActions::ADD_ITEMS : 1080cdf0e10cSrcweir { 1081cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lItems; 1082cdf0e10cSrcweir aValue >>= lItems; 1083cdf0e10cSrcweir for (::sal_Int32 i=0; i<lItems.getLength(); ++i) 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir const ::rtl::OUString& sItem = lItems[i]; 1086cdf0e10cSrcweir hResult = iCustom->AddControlItem(nId, i, reinterpret_cast<LPCTSTR>(sItem.getStr())); 1087cdf0e10cSrcweir } 1088cdf0e10cSrcweir } 1089cdf0e10cSrcweir break; 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir case css::ui::dialogs::ControlActions::SET_SELECT_ITEM : 1092cdf0e10cSrcweir { 1093cdf0e10cSrcweir ::sal_Int32 nItem = 0; 1094cdf0e10cSrcweir aValue >>= nItem; 1095cdf0e10cSrcweir hResult = iCustom->SetSelectedControlItem(nId, nItem); 1096cdf0e10cSrcweir } 1097cdf0e10cSrcweir break; 1098cdf0e10cSrcweir } 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir break; 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY : 1103cdf0e10cSrcweir { 1104cdf0e10cSrcweir } 1105cdf0e10cSrcweir break; 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir } 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir //------------------------------------------------------------------------------- 1110cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_GetControlValue(const RequestRef& rRequest) 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID ); 1113cdf0e10cSrcweir ::sal_Int16 nAction = rRequest->getArgumentOrDefault(PROP_CONTROL_ACTION, INVALID_CONTROL_ACTION); 1114cdf0e10cSrcweir 1115cdf0e10cSrcweir // dont check for right values here ... 1116cdf0e10cSrcweir // most parameters are optional ! 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface(); 1119cdf0e10cSrcweir if ( ! iCustom.is()) 1120cdf0e10cSrcweir return; 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir css::uno::Any aValue; 1123cdf0e10cSrcweir if( m_bWasExecuted ) 1124cdf0e10cSrcweir switch (nId) 1125cdf0e10cSrcweir { 1126cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD : 1127cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY : 1128cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS : 1129cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK : 1130cdf0e10cSrcweir //case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW : // can be ignored ... preview is supported native now ! 1131cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION : 1132cdf0e10cSrcweir { 1133cdf0e10cSrcweir BOOL bValue = FALSE; 1134cdf0e10cSrcweir HRESULT hResult = iCustom->GetCheckButtonState(nId, &bValue); 1135cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 1136cdf0e10cSrcweir aValue = css::uno::makeAny((sal_Bool)bValue); 1137cdf0e10cSrcweir } 1138cdf0e10cSrcweir break; 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir if (aValue.hasValue()) 1142cdf0e10cSrcweir rRequest->setArgument(PROP_CONTROL_VALUE, aValue); 1143cdf0e10cSrcweir } 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir //------------------------------------------------------------------------------- 1146cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_SetControlLabel(const RequestRef& rRequest) 1147cdf0e10cSrcweir { 1148cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID ); 1149cdf0e10cSrcweir ::rtl::OUString sLabel = rRequest->getArgumentOrDefault(PROP_CONTROL_LABEL, ::rtl::OUString() ); 1150cdf0e10cSrcweir 1151cdf0e10cSrcweir // dont check for right values here ... 1152cdf0e10cSrcweir // most parameters are optional ! 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface(); 1155cdf0e10cSrcweir if ( ! iCustom.is()) 1156cdf0e10cSrcweir return; 1157cdf0e10cSrcweir iCustom->SetControlLabel ( nId, reinterpret_cast<LPCTSTR>(sLabel.getStr())); 1158cdf0e10cSrcweir } 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir //------------------------------------------------------------------------------- 1161cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_GetControlLabel(const RequestRef& /*rRequest*/) 1162cdf0e10cSrcweir { 1163cdf0e10cSrcweir } 1164cdf0e10cSrcweir 1165cdf0e10cSrcweir //------------------------------------------------------------------------------- 1166cdf0e10cSrcweir void VistaFilePickerImpl::impl_sta_EnableControl(const RequestRef& rRequest) 1167cdf0e10cSrcweir { 1168cdf0e10cSrcweir ::sal_Int16 nId = rRequest->getArgumentOrDefault(PROP_CONTROL_ID , INVALID_CONTROL_ID ); 1169cdf0e10cSrcweir ::sal_Bool bEnabled = rRequest->getArgumentOrDefault(PROP_CONTROL_ENABLE, (::sal_Bool)sal_True); 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir // dont check for right values here ... 1172cdf0e10cSrcweir // most parameters are optional ! 1173cdf0e10cSrcweir 1174cdf0e10cSrcweir TFileDialogCustomize iCustom = impl_getCustomizeInterface(); 1175cdf0e10cSrcweir if ( ! iCustom.is()) 1176cdf0e10cSrcweir return; 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir CDCONTROLSTATEF eState = CDCS_VISIBLE; 1179cdf0e10cSrcweir if (bEnabled) 1180cdf0e10cSrcweir eState |= CDCS_ENABLED; 1181cdf0e10cSrcweir else 1182cdf0e10cSrcweir eState |= CDCS_INACTIVE; 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir iCustom->SetControlState(nId, eState); 1185cdf0e10cSrcweir } 1186cdf0e10cSrcweir //------------------------------------------------------------------------------- 1187cdf0e10cSrcweir void VistaFilePickerImpl::impl_SetDefaultExtension( const rtl::OUString& currentFilter ) 1188cdf0e10cSrcweir { 1189cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface(); 1190cdf0e10cSrcweir if (currentFilter.getLength()) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir rtl::OUString FilterExt; 1193cdf0e10cSrcweir m_lFilters.getFilter(currentFilter, FilterExt); 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir sal_Int32 posOfPoint = FilterExt.indexOf(L'.'); 1196cdf0e10cSrcweir const sal_Unicode* pFirstExtStart = FilterExt.getStr() + posOfPoint + 1; 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir sal_Int32 posOfSemiColon = FilterExt.indexOf(L';') - 1; 1199cdf0e10cSrcweir if (posOfSemiColon < 0) 1200cdf0e10cSrcweir posOfSemiColon = FilterExt.getLength() - 1; 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir FilterExt = rtl::OUString(pFirstExtStart, posOfSemiColon - posOfPoint); 1203cdf0e10cSrcweir iDialog->SetDefaultExtension ( reinterpret_cast<LPCTSTR>(FilterExt.getStr()) ); 1204cdf0e10cSrcweir } 1205cdf0e10cSrcweir } 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir static void impl_refreshFileDialog( TFileDialog iDialog ) 1208cdf0e10cSrcweir { 1209cdf0e10cSrcweir if ( SUCCEEDED(iDialog->SetFileName(L"")) && 1210cdf0e10cSrcweir SUCCEEDED(iDialog->SetFileName(L"*.*")) ) 1211cdf0e10cSrcweir { 1212cdf0e10cSrcweir IOleWindow* iOleWindow; 121331835a35SMichael Stahl #ifdef __MINGW32__ 121431835a35SMichael Stahl if (SUCCEEDED(iDialog->QueryInterface(IID_IOleWindow, reinterpret_cast<void**>(&iOleWindow)))) 121531835a35SMichael Stahl #else 1216cdf0e10cSrcweir if (SUCCEEDED(iDialog->QueryInterface(IID_PPV_ARGS(&iOleWindow)))) 121731835a35SMichael Stahl #endif 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir HWND hwnd; 1220cdf0e10cSrcweir if (SUCCEEDED(iOleWindow->GetWindow(&hwnd))) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir PostMessage(hwnd, WM_COMMAND, IDOK, 0); 1223cdf0e10cSrcweir } 1224cdf0e10cSrcweir iOleWindow->Release(); 1225cdf0e10cSrcweir } 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir } 1228cdf0e10cSrcweir 1229cdf0e10cSrcweir //------------------------------------------------------------------------------- 1230cdf0e10cSrcweir void VistaFilePickerImpl::onAutoExtensionChanged (bool bChecked) 1231cdf0e10cSrcweir { 1232cdf0e10cSrcweir // SYNCHRONIZED-> 1233cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aMutex); 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir const ::rtl::OUString sFilter = m_lFilters.getCurrentFilter (); 1236cdf0e10cSrcweir ::rtl::OUString sExt ; 1237cdf0e10cSrcweir if ( !m_lFilters.getFilter (sFilter, sExt)) 1238cdf0e10cSrcweir return; 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir TFileDialog iDialog = impl_getBaseDialogInterface(); 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir aLock.clear(); 1243cdf0e10cSrcweir // <- SYNCHRONIZED 1244cdf0e10cSrcweir 1245cdf0e10cSrcweir LPCWSTR pExt = 0; 1246cdf0e10cSrcweir if ( bChecked ) 1247cdf0e10cSrcweir { 1248cdf0e10cSrcweir pExt = reinterpret_cast<LPCTSTR>(sExt.getStr()); 1249cdf0e10cSrcweir pExt = wcsrchr( pExt, '.' ); 1250cdf0e10cSrcweir if ( pExt ) 1251cdf0e10cSrcweir pExt++; 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir iDialog->SetDefaultExtension( pExt ); 1254cdf0e10cSrcweir } 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir bool VistaFilePickerImpl::onFileTypeChanged( UINT /*nTypeIndex*/ ) 1257cdf0e10cSrcweir { 1258cdf0e10cSrcweir return true; 1259cdf0e10cSrcweir } 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir } // namespace vista 1262cdf0e10cSrcweir } // namespace win32 1263cdf0e10cSrcweir } // namespace fpicker 1264