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