1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_fpicker.hxx" 30 31 //------------------------------------------------------------------------ 32 // includes 33 //------------------------------------------------------------------------ 34 35 #ifdef _MSC_VER 36 #pragma warning (disable:4917) 37 #endif 38 39 #include "VistaFilePicker.hxx" 40 #include "WinFileOpenImpl.hxx" 41 #include "..\misc\WinImplHelper.hxx" 42 #include "shared.hxx" 43 44 #include <com/sun/star/lang/DisposedException.hpp> 45 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 46 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp> 47 #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp> 48 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 49 50 #include <cppuhelper/interfacecontainer.h> 51 #include <comphelper/configurationhelper.hxx> 52 #include <osl/diagnose.h> 53 #include <osl/mutex.hxx> 54 #include <osl/file.hxx> 55 #include <tchar.h> 56 57 #ifdef _MSC_VER 58 #pragma warning (push, 1) 59 #endif 60 #include <shlobj.h> 61 #ifdef _MSC_VER 62 #pragma warning (pop) 63 #endif 64 65 //------------------------------------------------------------------------ 66 // namespace directives 67 //------------------------------------------------------------------------ 68 69 namespace css = ::com::sun::star; 70 71 namespace fpicker{ 72 namespace win32{ 73 namespace vista{ 74 75 //------------------------------------------------------------------------ 76 // defines 77 //------------------------------------------------------------------------ 78 79 #define FILE_PICKER_DLL_NAME TEXT("fps.dll") 80 81 //------------------------------------------------------------------------ 82 // helper functions 83 //------------------------------------------------------------------------ 84 85 namespace 86 { 87 // controling event notifications 88 const bool STARTUP_SUSPENDED = true; 89 const bool STARTUP_ALIVE = false; 90 91 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker_getSupportedServiceNames() 92 { 93 css::uno::Sequence< ::rtl::OUString > aRet(2); 94 aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.FilePicker"); 95 aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFilePicker"); 96 return aRet; 97 } 98 } 99 100 //----------------------------------------------------------------------------------------- 101 #define ENABLE_LOGGING 102 103 #define LOGFILE_VISTA "c:\\temp\\vistafiledialog.log" 104 105 #ifdef ENABLE_LOGGING 106 107 #define LOG_FILE(PARAM_MESSAGE) \ 108 { \ 109 FILE* pFile = fopen(LOGFILE_VISTA, "a"); \ 110 fprintf(pFile, PARAM_MESSAGE); \ 111 fclose(pFile); \ 112 } 113 114 #define LOG_FILE_1_PARAM(PARAM_MESSAGE, PARAM_1) \ 115 { \ 116 FILE* pFile = fopen(LOGFILE_VISTA, "a"); \ 117 fprintf(pFile, PARAM_MESSAGE, PARAM_1); \ 118 fclose(pFile); \ 119 } 120 121 #define LOG_FILE_2_PARAM(PARAM_MESSAGE, PARAM_1, PARAM_2) \ 122 { \ 123 FILE* pFile = fopen(LOGFILE_VISTA, "a"); \ 124 fprintf(pFile, PARAM_MESSAGE, PARAM_1, PARAM_2); \ 125 fclose(pFile); \ 126 } 127 128 #else 129 130 #define LOG_FILE(PARAM_MESSAGE) 131 #define LOG_FILE_1_PARAM(PARAM_MESSAGE, PARAM_1) 132 #define LOG_FILE_2_PARAM(PARAM_MESSAGE, PARAM_1, PARAM_2) 133 134 #endif 135 136 //----------------------------------------------------------------------------------------- 137 #define VISTAFILEDIALOG_CHECKED_COMCALL(PARAM_CODE, PARAM_LOGMESSAGE, PARAM_ERRORMESSAGE) \ 138 { \ 139 HRESULT aResult; \ 140 VISTAFILEDIALOG_CHECKED_COMCALL_WITH_RETURN(aResult, PARAM_CODE, PARAM_LOGMESSAGE, PARAM_ERRORMESSAGE) \ 141 } 142 143 //----------------------------------------------------------------------------------------- 144 #define VISTAFILEDIALOG_CHECKED_COMCALL_WITH_RETURN(RETURN_HR, PARAM_CODE, PARAM_LOGMESSAGE, PARAM_ERRORMESSAGE) \ 145 { \ 146 LOG_FILE(PARAM_LOGMESSAGE) \ 147 RETURN_HR = PARAM_CODE; \ 148 if ( FAILED(RETURN_HR) ) \ 149 { \ 150 LOG_FILE_1_PARAM("will throw exception for checked COM call:\n%s", PARAM_ERRORMESSAGE) \ 151 throw css::uno::RuntimeException( \ 152 ::rtl::OUString::createFromAscii(PARAM_ERRORMESSAGE), \ 153 css::uno::Reference< css::ui::dialogs::XFilePicker >()); \ 154 } \ 155 } 156 157 158 159 //----------------------------------------------------------------------------------------- 160 VistaFilePicker::VistaFilePicker(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) 161 : TVistaFilePickerBase (m_aMutex ) 162 , m_xSMGR (xSMGR ) 163 , m_rDialog (new VistaFilePickerImpl()) 164 , m_aAsyncExecute (m_rDialog ) 165 , m_nFilePickerThreadId (0 ) 166 , m_bInitialized (false ) 167 { 168 } 169 170 //----------------------------------------------------------------------------------------- 171 VistaFilePicker::~VistaFilePicker() 172 { 173 } 174 175 //------------------------------------------------------------------------------------ 176 void SAL_CALL VistaFilePicker::addFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener) 177 throw(css::uno::RuntimeException) 178 { 179 RequestRef rRequest(new Request()); 180 rRequest->setRequest (VistaFilePickerImpl::E_ADD_PICKER_LISTENER); 181 rRequest->setArgument(PROP_PICKER_LISTENER, xListener); 182 183 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 184 } 185 186 //----------------------------------------------------------------------------------------- 187 void SAL_CALL VistaFilePicker::removeFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) 188 throw(css::uno::RuntimeException) 189 { 190 RequestRef rRequest(new Request()); 191 rRequest->setRequest (VistaFilePickerImpl::E_REMOVE_PICKER_LISTENER); 192 rRequest->setArgument(PROP_PICKER_LISTENER, xListener); 193 194 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 195 } 196 197 // ------------------------------------------------- 198 void SAL_CALL VistaFilePicker::disposing(const css::lang::EventObject& /*aEvent*/) 199 throw(css::uno::RuntimeException) 200 { 201 } 202 203 //------------------------------------------------------------------------------------ 204 void SAL_CALL VistaFilePicker::setMultiSelectionMode(::sal_Bool bMode) 205 throw(css::uno::RuntimeException) 206 { 207 RequestRef rRequest(new Request()); 208 rRequest->setRequest (VistaFilePickerImpl::E_SET_MULTISELECTION_MODE); 209 rRequest->setArgument(PROP_MULTISELECTION_MODE, bMode); 210 211 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 212 } 213 214 //----------------------------------------------------------------------------------------- 215 void SAL_CALL VistaFilePicker::setTitle(const ::rtl::OUString& sTitle) 216 throw(css::uno::RuntimeException) 217 { 218 RequestRef rRequest(new Request()); 219 rRequest->setRequest (VistaFilePickerImpl::E_SET_TITLE); 220 rRequest->setArgument(PROP_TITLE, sTitle); 221 222 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 223 } 224 225 //----------------------------------------------------------------------------------------- 226 void SAL_CALL VistaFilePicker::appendFilter(const ::rtl::OUString& sTitle , 227 const ::rtl::OUString& sFilter) 228 throw(css::lang::IllegalArgumentException, 229 css::uno::RuntimeException ) 230 { 231 RequestRef rRequest(new Request()); 232 rRequest->setRequest (VistaFilePickerImpl::E_APPEND_FILTER); 233 rRequest->setArgument(PROP_FILTER_TITLE, sTitle ); 234 rRequest->setArgument(PROP_FILTER_VALUE, sFilter); 235 236 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 237 } 238 239 //----------------------------------------------------------------------------------------- 240 void SAL_CALL VistaFilePicker::setCurrentFilter(const ::rtl::OUString& sTitle) 241 throw(css::lang::IllegalArgumentException, 242 css::uno::RuntimeException ) 243 { 244 RequestRef rRequest(new Request()); 245 rRequest->setRequest (VistaFilePickerImpl::E_SET_CURRENT_FILTER); 246 rRequest->setArgument(PROP_FILTER_TITLE, sTitle); 247 248 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 249 } 250 251 //----------------------------------------------------------------------------------------- 252 ::rtl::OUString SAL_CALL VistaFilePicker::getCurrentFilter() 253 throw(css::uno::RuntimeException) 254 { 255 RequestRef rRequest(new Request()); 256 rRequest->setRequest (VistaFilePickerImpl::E_GET_CURRENT_FILTER); 257 258 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED); 259 260 const ::rtl::OUString sTitle = rRequest->getArgumentOrDefault(PROP_FILTER_TITLE, ::rtl::OUString()); 261 return sTitle; 262 } 263 264 //----------------------------------------------------------------------------------------- 265 void SAL_CALL VistaFilePicker::appendFilterGroup(const ::rtl::OUString& /*sGroupTitle*/, 266 const css::uno::Sequence< css::beans::StringPair >& rFilters ) 267 throw (css::lang::IllegalArgumentException, 268 css::uno::RuntimeException ) 269 { 270 RequestRef rRequest(new Request()); 271 rRequest->setRequest (VistaFilePickerImpl::E_APPEND_FILTERGROUP); 272 rRequest->setArgument(PROP_FILTER_GROUP, rFilters); 273 274 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 275 } 276 277 //----------------------------------------------------------------------------------------- 278 void SAL_CALL VistaFilePicker::setDefaultName(const ::rtl::OUString& sName ) 279 throw(css::uno::RuntimeException) 280 { 281 RequestRef rRequest(new Request()); 282 rRequest->setRequest (VistaFilePickerImpl::E_SET_DEFAULT_NAME); 283 rRequest->setArgument(PROP_FILENAME, sName); 284 285 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 286 } 287 288 //----------------------------------------------------------------------------------------- 289 void SAL_CALL VistaFilePicker::setDisplayDirectory(const ::rtl::OUString& sDirectory) 290 throw (css::lang::IllegalArgumentException, 291 css::uno::RuntimeException ) 292 { 293 const ::rtl::OUString aPackage( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/")); 294 const ::rtl::OUString aRelPath( RTL_CONSTASCII_USTRINGPARAM("Path/Info")); 295 const ::rtl::OUString aKey( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged")); 296 297 css::uno::Any aValue = ::comphelper::ConfigurationHelper::readDirectKey( 298 m_xSMGR, aPackage, aRelPath, aKey, ::comphelper::ConfigurationHelper::E_READONLY); 299 300 bool bChanged(false); 301 if (( aValue >>= bChanged ) && bChanged ) 302 { 303 ::comphelper::ConfigurationHelper::writeDirectKey( 304 m_xSMGR, aPackage, aRelPath, aKey, css::uno::makeAny(false), ::comphelper::ConfigurationHelper::E_STANDARD); 305 } 306 307 RequestRef rRequest(new Request()); 308 rRequest->setRequest (VistaFilePickerImpl::E_SET_DIRECTORY); 309 rRequest->setArgument(PROP_DIRECTORY, sDirectory); 310 rRequest->setArgument(PROP_FORCE, bChanged); 311 312 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 313 } 314 315 //----------------------------------------------------------------------------------------- 316 ::rtl::OUString SAL_CALL VistaFilePicker::getDisplayDirectory() 317 throw(css::uno::RuntimeException) 318 { 319 RequestRef rRequest(new Request()); 320 rRequest->setRequest (VistaFilePickerImpl::E_GET_DIRECTORY); 321 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 322 const ::rtl::OUString sDirectory = rRequest->getArgumentOrDefault(PROP_FILENAME, ::rtl::OUString()); 323 324 return sDirectory; 325 } 326 327 //----------------------------------------------------------------------------------------- 328 // @deprecated cant be supported any longer ... see IDL description for further details 329 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker::getFiles() 330 throw(css::uno::RuntimeException) 331 { 332 RequestRef rRequest(new Request()); 333 rRequest->setRequest (VistaFilePickerImpl::E_GET_SELECTED_FILES); 334 335 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED); 336 337 const css::uno::Sequence< ::rtl::OUString > lFiles = rRequest->getArgumentOrDefault(PROP_SELECTED_FILES, css::uno::Sequence< ::rtl::OUString >()); 338 m_lLastFiles = lFiles; 339 return lFiles; 340 } 341 342 //----------------------------------------------------------------------------------------- 343 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker::getSelectedFiles() 344 throw(css::uno::RuntimeException) 345 { 346 RequestRef rRequest(new Request()); 347 rRequest->setRequest (VistaFilePickerImpl::E_GET_SELECTED_FILES); 348 349 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED); 350 351 const css::uno::Sequence< ::rtl::OUString > lFiles = rRequest->getArgumentOrDefault(PROP_SELECTED_FILES, css::uno::Sequence< ::rtl::OUString >()); 352 m_lLastFiles = lFiles; 353 return lFiles; 354 } 355 356 //----------------------------------------------------------------------------------------- 357 ::sal_Int16 SAL_CALL VistaFilePicker::execute() 358 throw(css::uno::RuntimeException) 359 { 360 bool bInitialized(false); 361 { 362 osl::MutexGuard aGuard(m_aMutex); 363 bInitialized = m_bInitialized; 364 } 365 366 if ( !bInitialized ) 367 { 368 sal_Int16 nTemplateDescription = css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; 369 css::uno::Sequence < css::uno::Any > aInitArguments(1); 370 aInitArguments[0] <<= nTemplateDescription; 371 initialize(aInitArguments); 372 } 373 374 RequestRef rRequest(new Request()); 375 rRequest->setRequest (VistaFilePickerImpl::E_SHOW_DIALOG_MODAL); 376 377 // if we want to show a modal window, the calling thread needs to process messages 378 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::PROCESS_MESSAGES); 379 380 const ::sal_Bool bOK = rRequest->getArgumentOrDefault(PROP_DIALOG_SHOW_RESULT, (::sal_Bool)sal_False ); 381 m_lLastFiles = rRequest->getArgumentOrDefault(PROP_SELECTED_FILES , css::uno::Sequence< ::rtl::OUString >()); 382 383 ::sal_Int16 nResult = css::ui::dialogs::ExecutableDialogResults::CANCEL; 384 if (bOK) 385 nResult = css::ui::dialogs::ExecutableDialogResults::OK; 386 return nResult; 387 } 388 389 //------------------------------------------------------------------------------------ 390 // XFilePicker functions 391 //------------------------------------------------------------------------------------ 392 393 void SAL_CALL VistaFilePicker::setValue( ::sal_Int16 nControlId , 394 ::sal_Int16 nControlAction, 395 const css::uno::Any& aValue ) 396 throw(css::uno::RuntimeException) 397 { 398 RequestRef rRequest(new Request()); 399 rRequest->setRequest (VistaFilePickerImpl::E_SET_CONTROL_VALUE); 400 rRequest->setArgument(PROP_CONTROL_ID , nControlId ); 401 rRequest->setArgument(PROP_CONTROL_ACTION, nControlAction); 402 rRequest->setArgument(PROP_CONTROL_VALUE , aValue ); 403 404 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 405 } 406 407 //----------------------------------------------------------------------------------------- 408 // 409 //----------------------------------------------------------------------------------------- 410 411 css::uno::Any SAL_CALL VistaFilePicker::getValue(::sal_Int16 nControlId , 412 ::sal_Int16 nControlAction) 413 throw(css::uno::RuntimeException) 414 { 415 RequestRef rRequest(new Request()); 416 rRequest->setRequest (VistaFilePickerImpl::E_GET_CONTROL_VALUE); 417 rRequest->setArgument(PROP_CONTROL_ID , nControlId ); 418 rRequest->setArgument(PROP_CONTROL_ACTION, nControlAction); 419 420 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED); 421 const css::uno::Any aValue = rRequest->getArgumentOrDefault(PROP_CONTROL_VALUE, css::uno::Any()); 422 return aValue; 423 } 424 425 //----------------------------------------------------------------------------------------- 426 // 427 //----------------------------------------------------------------------------------------- 428 429 void SAL_CALL VistaFilePicker::enableControl(::sal_Int16 nControlId, 430 ::sal_Bool bEnable ) 431 throw(css::uno::RuntimeException) 432 { 433 RequestRef rRequest(new Request()); 434 rRequest->setRequest (VistaFilePickerImpl::E_ENABLE_CONTROL); 435 rRequest->setArgument(PROP_CONTROL_ID , nControlId); 436 rRequest->setArgument(PROP_CONTROL_ENABLE, bEnable ); 437 438 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 439 } 440 441 //----------------------------------------------------------------------------------------- 442 // 443 //----------------------------------------------------------------------------------------- 444 445 void SAL_CALL VistaFilePicker::setLabel( ::sal_Int16 nControlId, 446 const ::rtl::OUString& sLabel ) 447 throw (css::uno::RuntimeException) 448 { 449 RequestRef rRequest(new Request()); 450 rRequest->setRequest (VistaFilePickerImpl::E_SET_CONTROL_LABEL); 451 rRequest->setArgument(PROP_CONTROL_ID , nControlId); 452 rRequest->setArgument(PROP_CONTROL_LABEL, sLabel ); 453 454 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 455 } 456 457 //----------------------------------------------------------------------------------------- 458 // 459 //----------------------------------------------------------------------------------------- 460 461 ::rtl::OUString SAL_CALL VistaFilePicker::getLabel(::sal_Int16 nControlId) 462 throw (css::uno::RuntimeException) 463 { 464 RequestRef rRequest(new Request()); 465 rRequest->setRequest (VistaFilePickerImpl::E_GET_CONTROL_LABEL); 466 rRequest->setArgument(PROP_CONTROL_ID, nControlId); 467 468 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED); 469 const ::rtl::OUString sLabel = rRequest->getArgumentOrDefault(PROP_CONTROL_LABEL, ::rtl::OUString()); 470 return sLabel; 471 } 472 473 //------------------------------------------------------------------------------------ 474 // 475 //------------------------------------------------------------------------------------ 476 477 css::uno::Sequence< ::sal_Int16 > SAL_CALL VistaFilePicker::getSupportedImageFormats() 478 throw (css::uno::RuntimeException) 479 { 480 return css::uno::Sequence< sal_Int16 >(); 481 } 482 483 //------------------------------------------------------------------------------------ 484 // 485 //------------------------------------------------------------------------------------ 486 487 sal_Int32 SAL_CALL VistaFilePicker::getTargetColorDepth() 488 throw (css::uno::RuntimeException) 489 { 490 return 0; 491 } 492 493 //------------------------------------------------------------------------------------ 494 // 495 //------------------------------------------------------------------------------------ 496 497 sal_Int32 SAL_CALL VistaFilePicker::getAvailableWidth() 498 throw (css::uno::RuntimeException) 499 { 500 return 0; 501 } 502 503 //------------------------------------------------------------------------------------ 504 // 505 //------------------------------------------------------------------------------------ 506 507 sal_Int32 SAL_CALL VistaFilePicker::getAvailableHeight() 508 throw (css::uno::RuntimeException) 509 { 510 return 0; 511 } 512 513 //------------------------------------------------------------------------------------ 514 // 515 //------------------------------------------------------------------------------------ 516 517 void SAL_CALL VistaFilePicker::setImage( sal_Int16 /*nImageFormat*/, 518 const css::uno::Any& /*aImage */) 519 throw (css::lang::IllegalArgumentException, 520 css::uno::RuntimeException ) 521 { 522 } 523 524 //------------------------------------------------------------------------------------ 525 // 526 //------------------------------------------------------------------------------------ 527 528 sal_Bool SAL_CALL VistaFilePicker::setShowState(sal_Bool /*bShowState*/) 529 throw (css::uno::RuntimeException) 530 { 531 return sal_False; 532 } 533 534 //------------------------------------------------------------------------------------ 535 // 536 //------------------------------------------------------------------------------------ 537 538 sal_Bool SAL_CALL VistaFilePicker::getShowState() 539 throw (css::uno::RuntimeException) 540 { 541 return sal_False; 542 } 543 544 //------------------------------------------------------------------------------------ 545 // 546 //------------------------------------------------------------------------------------ 547 548 void SAL_CALL VistaFilePicker::initialize(const css::uno::Sequence< css::uno::Any >& lArguments) 549 throw(css::uno::Exception , 550 css::uno::RuntimeException) 551 { 552 /* 553 // called twice ? 554 if (m_pDlg) 555 throw css::uno::Exception( 556 ::rtl::OUString::createFromAscii( "XInitialization::initialize() called twice." ), 557 static_cast< css::ui::dialogs::XFilePicker* >( this )); 558 */ 559 560 if (lArguments.getLength() < 1) 561 throw css::lang::IllegalArgumentException( 562 ::rtl::OUString::createFromAscii( "XInitialization::initialize() called without arguments." ), 563 static_cast< css::ui::dialogs::XFilePicker2* >( this ), 564 1); 565 566 sal_Int32 nTemplate = -1; 567 lArguments[0] >>= nTemplate; 568 569 ::sal_Bool bFileOpenDialog = sal_True; 570 ::sal_Int32 nFeatures = 0; 571 572 switch(nTemplate) 573 { 574 case css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE : 575 { 576 bFileOpenDialog = sal_True; 577 } 578 break; 579 580 case css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE : 581 { 582 bFileOpenDialog = sal_False; 583 } 584 break; 585 586 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD : 587 { 588 bFileOpenDialog = sal_False; 589 nFeatures |= FEATURE_AUTOEXTENSION; 590 nFeatures |= FEATURE_PASSWORD; 591 } 592 break; 593 594 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS : 595 { 596 bFileOpenDialog = sal_False; 597 nFeatures |= FEATURE_AUTOEXTENSION; 598 nFeatures |= FEATURE_PASSWORD; 599 nFeatures |= FEATURE_FILTEROPTIONS; 600 } 601 break; 602 603 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION : 604 { 605 bFileOpenDialog = sal_False; 606 nFeatures |= FEATURE_AUTOEXTENSION; 607 nFeatures |= FEATURE_SELECTION; 608 } 609 break; 610 611 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE : 612 { 613 bFileOpenDialog = sal_False; 614 nFeatures |= FEATURE_AUTOEXTENSION; 615 nFeatures |= FEATURE_TEMPLATE; 616 } 617 break; 618 619 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE : 620 { 621 bFileOpenDialog = sal_True; 622 nFeatures |= FEATURE_LINK; 623 nFeatures |= FEATURE_PREVIEW; 624 nFeatures |= FEATURE_IMAGETEMPLATE; 625 } 626 break; 627 628 case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY : 629 { 630 bFileOpenDialog = sal_True; 631 nFeatures |= FEATURE_PLAY; 632 } 633 break; 634 635 case css::ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION : 636 { 637 bFileOpenDialog = sal_True; 638 nFeatures |= FEATURE_READONLY; 639 nFeatures |= FEATURE_VERSION; 640 } 641 break; 642 643 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW : 644 { 645 bFileOpenDialog = sal_True; 646 nFeatures |= FEATURE_LINK; 647 nFeatures |= FEATURE_PREVIEW; 648 } 649 break; 650 651 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION : 652 { 653 bFileOpenDialog = sal_False; 654 nFeatures |= FEATURE_AUTOEXTENSION; 655 } 656 break; 657 } 658 659 RequestRef rRequest(new Request()); 660 if (bFileOpenDialog) 661 rRequest->setRequest (VistaFilePickerImpl::E_CREATE_OPEN_DIALOG); 662 else 663 rRequest->setRequest (VistaFilePickerImpl::E_CREATE_SAVE_DIALOG); 664 rRequest->setArgument(PROP_FEATURES, nFeatures); 665 rRequest->setArgument(PROP_TEMPLATE_DESCR, nTemplate); 666 if ( ! m_aAsyncExecute.isRunning()) 667 m_aAsyncExecute.create(); 668 m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED); 669 670 { 671 osl::MutexGuard aGuard(m_aMutex); 672 m_bInitialized = true; 673 } 674 } 675 676 //------------------------------------------------------------------------------------ 677 // 678 //------------------------------------------------------------------------------------ 679 680 void SAL_CALL VistaFilePicker::cancel() 681 throw(css::uno::RuntimeException) 682 { 683 } 684 685 // ------------------------------------------------- 686 // XServiceInfo 687 // ------------------------------------------------- 688 689 ::rtl::OUString SAL_CALL VistaFilePicker::getImplementationName() 690 throw(css::uno::RuntimeException) 691 { 692 return ::rtl::OUString::createFromAscii("com.sun.star.comp.fpicker.VistaFileDialog"); 693 } 694 695 // ------------------------------------------------- 696 // XServiceInfo 697 // ------------------------------------------------- 698 699 sal_Bool SAL_CALL VistaFilePicker::supportsService(const ::rtl::OUString& sServiceName) 700 throw(css::uno::RuntimeException ) 701 { 702 css::uno::Sequence< ::rtl::OUString > lSupportedServicesNames = VistaFilePicker_getSupportedServiceNames(); 703 704 for (sal_Int32 n = lSupportedServicesNames.getLength(); n--;) 705 if (lSupportedServicesNames[n].compareTo(sServiceName) == 0) 706 return sal_True; 707 708 return sal_False; 709 } 710 711 // ------------------------------------------------- 712 // XServiceInfo 713 // ------------------------------------------------- 714 715 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker::getSupportedServiceNames() 716 throw(css::uno::RuntimeException) 717 { 718 return VistaFilePicker_getSupportedServiceNames(); 719 } 720 721 } // namespace vista 722 } // namespace win32 723 } // namespace fpicker 724