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