1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 28 #include <sot/formats.hxx> 29 #include <vcl/msgbox.hxx> 30 #include <svtools/valueset.hxx> 31 #include <svl/urlbmk.hxx> 32 #include <svl/stritem.hxx> 33 #include <svl/intitem.hxx> 34 #include <svl/eitem.hxx> 35 #include <svtools/transfer.hxx> 36 #include <sfx2/bindings.hxx> 37 #include <sfx2/dispatch.hxx> 38 #include <sfx2/viewfrm.hxx> 39 #include <sfx2/sfxsids.hrc> 40 #include "svtools/filter.hxx" 41 #include <editeng/brshitem.hxx> 42 #include "helpid.hrc" 43 #include "svx/gallery.hxx" 44 #include "galobj.hxx" 45 #include "svx/gallery1.hxx" 46 #include "svx/galtheme.hxx" 47 #include "svx/galctrl.hxx" 48 #include "svx/galmisc.hxx" 49 #include "galbrws2.hxx" 50 #include "gallery.hrc" 51 #include <vcl/svapp.hxx> 52 #include <svx/fmmodel.hxx> 53 #include <svx/dialmgr.hxx> 54 #include <svx/svxdlg.hxx> 55 #include <svx/dialogs.hrc> 56 #include "GalleryControl.hxx" 57 58 #include <svx/svxcommands.h> 59 #include <svx/galleryitem.hxx> 60 #include <comphelper/processfactory.hxx> 61 #include <com/sun/star/frame/FrameSearchFlag.hpp> 62 #include <com/sun/star/gallery/GalleryItemType.hpp> 63 #include <com/sun/star/graphic/XGraphic.hpp> 64 #include <com/sun/star/style/GraphicLocation.hpp> 65 #include <map> 66 67 // ----------- 68 // - Defines - 69 // ----------- 70 71 #undef GALLERY_USE_CLIPBOARD 72 73 #define TBX_ID_ICON 1 74 #define TBX_ID_LIST 2 75 76 #define C2U( cstr ) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(cstr))) 77 78 namespace css = ::com::sun::star; 79 using rtl::OUString; 80 81 // ----------- 82 // - statics - 83 // ----------- 84 85 GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON; 86 87 struct DispatchInfo 88 { 89 css::util::URL TargetURL; 90 css::uno::Sequence< css::beans::PropertyValue > Arguments; 91 css::uno::Reference< css::frame::XDispatch > Dispatch; 92 }; 93 94 IMPL_STATIC_LINK_NOINSTANCE( GalleryBrowser2, AsyncDispatch_Impl, DispatchInfo*, pDispatchInfo ) 95 { 96 if ( pDispatchInfo && pDispatchInfo->Dispatch.is() ) 97 { 98 try 99 { 100 pDispatchInfo->Dispatch->dispatch( pDispatchInfo->TargetURL, 101 pDispatchInfo->Arguments ); 102 } 103 catch ( const css::uno::Exception& ) 104 { 105 } 106 } 107 108 delete pDispatchInfo; 109 return 0; 110 } 111 112 namespace 113 { 114 115 struct CommandInfo 116 { 117 css::util::URL URL; 118 css::uno::Reference< css::frame::XDispatch > Dispatch; 119 120 CommandInfo( const OUString &rURL ) 121 { 122 URL.Complete = rURL; 123 } 124 }; 125 126 class GalleryThemePopup : public ::cppu::WeakImplHelper1< css::frame::XStatusListener > 127 { 128 private: 129 const GalleryTheme* mpTheme; 130 sal_uIntPtr mnObjectPos; 131 sal_Bool mbPreview; 132 PopupMenu maPopupMenu; 133 PopupMenu maBackgroundPopup; 134 GalleryBrowser2* mpBrowser; 135 136 typedef std::map< int, CommandInfo > CommandInfoMap; 137 CommandInfoMap m_aCommandInfo; 138 139 void Execute( const CommandInfo &rCmdInfo, 140 const css::uno::Sequence< css::beans::PropertyValue > &rArguments ); 141 142 DECL_LINK( MenuSelectHdl, Menu* pMenu ); 143 DECL_LINK( BackgroundMenuSelectHdl, Menu* pMenu ); 144 public: 145 GalleryThemePopup( const GalleryTheme* pTheme, 146 sal_uIntPtr nObjectPos, 147 sal_Bool bPreview, 148 GalleryBrowser2* pBrowser ); 149 ~GalleryThemePopup(); 150 151 void ExecutePopup( Window *pParent, const ::Point &aPos ); 152 153 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent &rEvent) throw ( css::uno::RuntimeException ); 154 virtual void SAL_CALL disposing( const css::lang::EventObject &rSource) throw ( css::uno::RuntimeException ); 155 }; 156 157 DBG_NAME(GalleryThemePopup) 158 159 GalleryThemePopup::GalleryThemePopup( 160 const GalleryTheme* pTheme, 161 sal_uIntPtr nObjectPos, 162 sal_Bool bPreview, 163 GalleryBrowser2* pBrowser ) 164 : mpTheme( pTheme ) 165 , mnObjectPos( nObjectPos ) 166 , mbPreview( bPreview ) 167 , maPopupMenu( GAL_RESID( RID_SVXMN_GALLERY2 ) ) 168 , maBackgroundPopup() 169 , mpBrowser( pBrowser ) 170 { 171 DBG_CTOR(GalleryThemePopup,NULL); 172 173 // SID_GALLERY_ENABLE_ADDCOPY 174 m_aCommandInfo.insert( 175 CommandInfoMap::value_type( 176 SID_GALLERY_ENABLE_ADDCOPY, 177 CommandInfo( C2U(CMD_SID_GALLERY_ENABLE_ADDCOPY )))); 178 // SID_GALLERY_BG_BRUSH 179 m_aCommandInfo.insert( 180 CommandInfoMap::value_type( 181 SID_GALLERY_BG_BRUSH, 182 CommandInfo(C2U(CMD_SID_GALLERY_BG_BRUSH )))); 183 // SID_GALLERY_FORMATS 184 m_aCommandInfo.insert( 185 CommandInfoMap::value_type( 186 SID_GALLERY_FORMATS, 187 CommandInfo(C2U(CMD_SID_GALLERY_FORMATS )))); 188 189 } 190 191 GalleryThemePopup::~GalleryThemePopup() 192 { 193 DBG_DTOR(GalleryThemePopup,NULL); 194 } 195 196 void SAL_CALL GalleryThemePopup::statusChanged( 197 const css::frame::FeatureStateEvent &rEvent ) 198 throw ( css::uno::RuntimeException ) 199 { 200 const OUString &rURL = rEvent.FeatureURL.Complete; 201 if ( rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_SID_GALLERY_ENABLE_ADDCOPY ) ) ) 202 { 203 if ( !rEvent.IsEnabled ) 204 { 205 PopupMenu *pAddMenu = maPopupMenu.GetPopupMenu( MN_ADDMENU ); 206 pAddMenu->EnableItem( MN_ADD, sal_False ); 207 pAddMenu->EnableItem( MN_ADD_LINK, sal_False ); 208 } 209 } 210 else if ( rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_SID_GALLERY_BG_BRUSH ) ) ) 211 { 212 maBackgroundPopup.Clear(); 213 if ( rEvent.IsEnabled ) 214 { 215 OUString sItem; 216 css::uno::Sequence< OUString > sItems; 217 if ( ( rEvent.State >>= sItem ) && sItem.getLength() ) 218 { 219 maBackgroundPopup.InsertItem( 1, sItem ); 220 } 221 else if ( ( rEvent.State >>= sItems ) && sItems.getLength() ) 222 { 223 const OUString *pStr = sItems.getConstArray(); 224 const OUString *pEnd = pStr + sItems.getLength(); 225 for ( sal_uInt16 nId = 1; pStr != pEnd; pStr++, nId++ ) 226 { 227 maBackgroundPopup.InsertItem( nId, *pStr ); 228 } 229 } 230 } 231 } 232 } 233 234 void SAL_CALL GalleryThemePopup::disposing( 235 const css::lang::EventObject &/*rSource*/) 236 throw ( css::uno::RuntimeException ) 237 { 238 } 239 240 void GalleryThemePopup::Execute( 241 const CommandInfo &rCmdInfo, 242 const css::uno::Sequence< css::beans::PropertyValue > &rArguments ) 243 { 244 if ( rCmdInfo.Dispatch.is() ) 245 { 246 DispatchInfo *pInfo = new DispatchInfo; 247 pInfo->TargetURL = rCmdInfo.URL; 248 pInfo->Arguments = rArguments; 249 pInfo->Dispatch = rCmdInfo.Dispatch; 250 251 if ( !Application::PostUserEvent( 252 STATIC_LINK( 0, GalleryBrowser2, AsyncDispatch_Impl), pInfo ) ) 253 delete pInfo; 254 } 255 } 256 257 void GalleryThemePopup::ExecutePopup( Window *pWindow, const ::Point &aPos ) 258 { 259 css::uno::Reference< css::frame::XStatusListener > xThis( this ); 260 261 const SgaObjKind eObjKind = mpTheme->GetObjectKind( mnObjectPos ); 262 PopupMenu* pAddMenu = maPopupMenu.GetPopupMenu( MN_ADDMENU ); 263 INetURLObject aURL; 264 265 const_cast< GalleryTheme* >( mpTheme )->GetURL( mnObjectPos, aURL ); 266 const sal_Bool bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID ); 267 268 pAddMenu->EnableItem( MN_ADD, bValidURL && SGA_OBJ_SOUND != eObjKind ); 269 pAddMenu->EnableItem( MN_ADD_LINK, bValidURL && SGA_OBJ_SVDRAW != eObjKind ); 270 271 maPopupMenu.EnableItem( MN_ADDMENU, pAddMenu->IsItemEnabled( MN_ADD ) || pAddMenu->IsItemEnabled( MN_ADD_LINK ) ); 272 maPopupMenu.EnableItem( MN_PREVIEW, bValidURL ); 273 274 maPopupMenu.CheckItem( MN_PREVIEW, mbPreview ); 275 276 if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() ) 277 { 278 maPopupMenu.EnableItem( MN_DELETE, sal_False ); 279 maPopupMenu.EnableItem( MN_TITLE, sal_False ); 280 281 if( mpTheme->IsReadOnly() ) 282 maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_False ); 283 284 if( !mpTheme->GetObjectCount() ) 285 maPopupMenu.EnableItem( MN_COPYCLIPBOARD, sal_False ); 286 } 287 else 288 { 289 maPopupMenu.EnableItem( MN_DELETE, !mbPreview ); 290 maPopupMenu.EnableItem( MN_TITLE, sal_True ); 291 maPopupMenu.EnableItem( MN_COPYCLIPBOARD, sal_True ); 292 maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_True ); 293 } 294 295 #ifdef GALLERY_USE_CLIPBOARD 296 if( maPopupMenu.IsItemEnabled( MN_PASTECLIPBOARD ) ) 297 { 298 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) ); 299 sal_Bool bEnable = sal_False; 300 301 if( aDataHelper.GetFormatCount() ) 302 { 303 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) || 304 aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) || 305 aDataHelper.HasFormat( FORMAT_FILE ) || 306 aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) || 307 aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) || 308 aDataHelper.HasFormat( FORMAT_BITMAP ) ) 309 { 310 bEnable = sal_True; 311 } 312 } 313 314 if( !bEnable ) 315 maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_False ); 316 } 317 #else 318 maPopupMenu.EnableItem( MN_COPYCLIPBOARD, sal_False ); 319 maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_False ); 320 #endif 321 322 // update status 323 css::uno::Reference< css::frame::XDispatchProvider> xDispatchProvider( 324 mpBrowser->GetFrame(), css::uno::UNO_QUERY ); 325 css::uno::Reference< css::util::XURLTransformer > xTransformer( 326 mpBrowser->GetURLTransformer() ); 327 for ( CommandInfoMap::iterator it = m_aCommandInfo.begin(); 328 it != m_aCommandInfo.end(); it++ ) 329 { 330 try 331 { 332 CommandInfo &rCmdInfo = it->second; 333 if ( xTransformer.is() ) 334 xTransformer->parseStrict( rCmdInfo.URL ); 335 336 if ( xDispatchProvider.is() ) 337 { 338 rCmdInfo.Dispatch = xDispatchProvider->queryDispatch( 339 rCmdInfo.URL, 340 C2U( "_self" ), 341 css::frame::FrameSearchFlag::SELF ); 342 } 343 344 if ( rCmdInfo.Dispatch.is() ) 345 { 346 rCmdInfo.Dispatch->addStatusListener( this, rCmdInfo.URL ); 347 rCmdInfo.Dispatch->removeStatusListener( this, rCmdInfo.URL ); 348 } 349 } 350 catch ( ... ) 351 {} 352 } 353 354 if( !maBackgroundPopup.GetItemCount() || ( eObjKind == SGA_OBJ_SVDRAW ) || ( eObjKind == SGA_OBJ_SOUND ) ) 355 pAddMenu->EnableItem( MN_BACKGROUND, sal_False ); 356 else 357 { 358 pAddMenu->EnableItem( MN_BACKGROUND, sal_True ); 359 pAddMenu->SetPopupMenu( MN_BACKGROUND, &maBackgroundPopup ); 360 maBackgroundPopup.SetSelectHdl( LINK( this, GalleryThemePopup, BackgroundMenuSelectHdl ) ); 361 } 362 363 pAddMenu->RemoveDisabledEntries(); 364 if ( !pAddMenu->GetItemCount() ) 365 maPopupMenu.EnableItem( MN_ADDMENU, sal_False ); 366 maPopupMenu.RemoveDisabledEntries(); 367 368 maPopupMenu.SetSelectHdl( LINK( this, GalleryThemePopup, MenuSelectHdl ) ); 369 maPopupMenu.Execute( pWindow, aPos ); 370 } 371 372 IMPL_LINK( GalleryThemePopup, MenuSelectHdl, Menu*, pMenu ) 373 { 374 if( !pMenu ) 375 return 0; 376 377 sal_uInt16 nId( pMenu->GetCurItemId() ); 378 switch ( nId ) 379 { 380 case( MN_ADD ): 381 case( MN_ADD_LINK ): 382 { 383 const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_FORMATS ); 384 if ( it != m_aCommandInfo.end() ) 385 mpBrowser->Dispatch( nId, 386 it->second.Dispatch, 387 it->second.URL ); 388 } 389 break; 390 391 default: 392 mpBrowser->Execute( nId ); 393 } 394 395 return 0; 396 } 397 398 IMPL_LINK( GalleryThemePopup, BackgroundMenuSelectHdl, Menu*, pMenu ) 399 { 400 if( !pMenu ) 401 return 0; 402 403 sal_uInt16 nPos( pMenu->GetCurItemId() - 1 ); 404 OUString aURL( mpBrowser->GetURL().GetMainURL( INetURLObject::NO_DECODE ) ); 405 OUString aFilterName( mpBrowser->GetFilterName() ); 406 407 css::uno::Sequence< css::beans::PropertyValue > aArgs( 6 ); 408 aArgs[0].Name = C2U( "Background.Transparent" ); 409 aArgs[0].Value <<= sal_Int32( 0 ); // 0 - 100 410 aArgs[1].Name = C2U( "Background.BackColor" ); 411 aArgs[1].Value <<= sal_Int32( - 1 ); 412 aArgs[2].Name = C2U( "Background.URL" ); 413 aArgs[2].Value <<= aURL; 414 aArgs[3].Name = C2U( "Background.Filtername" ); // FIXME should be FilterName 415 aArgs[3].Value <<= aFilterName; 416 aArgs[4].Name = C2U( "Background.Position" ); 417 aArgs[4].Value <<= css::style::GraphicLocation_TILED; 418 aArgs[5].Name = C2U( "Position" ); 419 aArgs[5].Value <<= nPos; 420 421 const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_BG_BRUSH ); 422 if ( it != m_aCommandInfo.end() ) 423 Execute( it->second, aArgs ); 424 425 return 0; 426 } 427 428 } // end anonymous namespace 429 430 // ------------------ 431 // - GalleryToolBox - 432 // ------------------ 433 DBG_NAME(GalleryToolBox) 434 435 GalleryToolBox::GalleryToolBox( GalleryBrowser2* pParent ) : 436 ToolBox( pParent, WB_TABSTOP ) 437 { 438 DBG_CTOR(GalleryToolBox,NULL); 439 440 } 441 442 // ------------------------------------------------------------------------ 443 444 GalleryToolBox::~GalleryToolBox() 445 { 446 447 DBG_DTOR(GalleryToolBox,NULL); 448 } 449 450 // ------------------------------------------------------------------------ 451 452 void GalleryToolBox::KeyInput( const KeyEvent& rKEvt ) 453 { 454 if( !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) ) 455 ToolBox::KeyInput( rKEvt ); 456 } 457 458 // ------------------- 459 // - GalleryBrowser2 - 460 // ------------------- 461 DBG_NAME(GalleryBrowser2) 462 463 GalleryBrowser2::GalleryBrowser2( Window* pParent, const ResId& rResId, Gallery* pGallery ) : 464 Control ( pParent, rResId ), 465 mpGallery ( pGallery ), 466 mpCurTheme ( NULL ), 467 mpIconView ( new GalleryIconView( this, NULL ) ), 468 mpListView ( new GalleryListView( this, NULL ) ), 469 mpPreview ( new GalleryPreview( this, NULL ) ), 470 maViewBox ( this ), 471 maSeparator ( this, WB_VERT ), 472 maInfoBar ( this, WB_LEFT | WB_VCENTER ), 473 mnCurActionPos ( 0xffffffff ), 474 meMode ( GALLERYBROWSERMODE_NONE ), 475 meLastMode ( GALLERYBROWSERMODE_NONE ) 476 { 477 DBG_CTOR(GalleryBrowser2,NULL); 478 479 m_xContext.set( ::comphelper::getProcessComponentContext() ); 480 481 m_xTransformer.set( 482 m_xContext->getServiceManager()->createInstanceWithContext( 483 C2U( "com.sun.star.util.URLTransformer" ), m_xContext ), 484 css::uno::UNO_QUERY ); 485 486 Image aDummyImage; 487 const Link aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) ); 488 Font aInfoFont( maInfoBar.GetControlFont() ); 489 490 maMiscOptions.AddListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) ); 491 492 maViewBox.InsertItem( TBX_ID_ICON, aDummyImage ); 493 maViewBox.SetItemBits( TBX_ID_ICON, TIB_RADIOCHECK | TIB_AUTOCHECK ); 494 maViewBox.SetHelpId( TBX_ID_ICON, HID_GALLERY_ICONVIEW ); 495 maViewBox.SetQuickHelpText( TBX_ID_ICON, String( GAL_RESID( RID_SVXSTR_GALLERY_ICONVIEW ) ) ); 496 497 maViewBox.InsertItem( TBX_ID_LIST, aDummyImage ); 498 maViewBox.SetItemBits( TBX_ID_LIST, TIB_RADIOCHECK | TIB_AUTOCHECK ); 499 maViewBox.SetHelpId( TBX_ID_LIST, HID_GALLERY_LISTVIEW ); 500 maViewBox.SetQuickHelpText( TBX_ID_LIST, String( GAL_RESID( RID_SVXSTR_GALLERY_LISTVIEW ) ) ); 501 502 maViewBox.SetBorder( 0, 1 ); 503 MiscHdl( NULL ); 504 maViewBox.SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) ); 505 maViewBox.Show(); 506 507 mpIconView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) )); 508 mpListView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) )); 509 510 maInfoBar.Show(); 511 maSeparator.Show(); 512 513 mpIconView->SetSelectHdl( aSelectHdl ); 514 mpListView->SetSelectHdl( aSelectHdl ); 515 516 InitSettings(); 517 518 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON ); 519 520 if(maInfoBar.GetText().Len() == 0) 521 mpIconView->SetAccessibleRelationLabeledBy(mpIconView); 522 else 523 mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar); 524 mpIconView->SetAccessibleRelationMemberOf(mpIconView); 525 } 526 527 // ----------------------------------------------------------------------------- 528 529 GalleryBrowser2::~GalleryBrowser2() 530 { 531 maMiscOptions.RemoveListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) ); 532 533 delete mpPreview; 534 delete mpListView; 535 delete mpIconView; 536 537 if( mpCurTheme ) 538 mpGallery->ReleaseTheme( mpCurTheme, *this ); 539 540 DBG_DTOR(GalleryBrowser2,NULL); 541 } 542 543 // ----------------------------------------------------------------------------- 544 545 void GalleryBrowser2::InitSettings() 546 { 547 Font aInfoFont( maInfoBar.GetControlFont() ); 548 549 aInfoFont.SetWeight( WEIGHT_BOLD ); 550 aInfoFont.SetColor( GALLERY_FG_COLOR ); 551 maInfoBar.SetControlFont( aInfoFont ); 552 553 maInfoBar.SetBackground( Wallpaper( GALLERY_DLG_COLOR ) ); 554 maInfoBar.SetControlBackground( GALLERY_DLG_COLOR ); 555 556 maSeparator.SetBackground( Wallpaper( GALLERY_BG_COLOR ) ); 557 maSeparator.SetControlBackground( GALLERY_BG_COLOR ); 558 maSeparator.SetControlForeground( GALLERY_FG_COLOR ); 559 } 560 561 // ----------------------------------------------------------------------------- 562 563 void GalleryBrowser2::DataChanged( const DataChangedEvent& rDCEvt ) 564 { 565 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) ) 566 InitSettings(); 567 else 568 Control::DataChanged( rDCEvt ); 569 } 570 571 // ----------------------------------------------------------------------------- 572 573 void GalleryBrowser2::Resize() 574 { 575 Control::Resize(); 576 577 mpIconView->Hide(); 578 mpListView->Hide(); 579 mpPreview->Hide(); 580 581 const Size aOutSize( GetOutputSizePixel() ); 582 const Size aBoxSize( maViewBox.GetOutputSizePixel() ); 583 const long nOffset = 2, nSepWidth = 2; 584 const long nInfoBarX = aBoxSize.Width() + ( nOffset * 3 ) + nSepWidth; 585 const Point aPt( 0, aBoxSize.Height() + 3 ); 586 const Size aSz( aOutSize.Width(), aOutSize.Height() - aPt.Y() ); 587 588 maSeparator.SetPosSizePixel( Point( aBoxSize.Width() + nOffset, 0 ), Size( nSepWidth, aBoxSize.Height() ) ); 589 maInfoBar.SetPosSizePixel( Point( nInfoBarX, 0 ), Size( aOutSize.Width() - nInfoBarX, aBoxSize.Height() ) ); 590 591 mpIconView->SetPosSizePixel( aPt, aSz ); 592 mpListView->SetPosSizePixel( aPt, aSz ); 593 mpPreview->SetPosSizePixel( aPt, aSz ); 594 595 switch( GetMode() ) 596 { 597 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break; 598 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break; 599 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break; 600 601 default: 602 break; 603 } 604 } 605 606 // ----------------------------------------------------------------------------- 607 608 void GalleryBrowser2::Notify( SfxBroadcaster&, const SfxHint& rHint ) 609 { 610 const GalleryHint& rGalleryHint = (const GalleryHint&) rHint; 611 612 switch( rGalleryHint.GetType() ) 613 { 614 case( GALLERY_HINT_THEME_UPDATEVIEW ): 615 { 616 if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) 617 SetMode( meLastMode ); 618 619 ImplUpdateViews( (sal_uInt16) rGalleryHint.GetData1() + 1 ); 620 } 621 break; 622 623 default: 624 break; 625 } 626 } 627 628 // ----------------------------------------------------------------------------- 629 630 sal_Int8 GalleryBrowser2::AcceptDrop( DropTargetHelper& rTarget, const AcceptDropEvent& ) 631 { 632 sal_Int8 nRet = DND_ACTION_NONE; 633 634 if( mpCurTheme && !mpCurTheme->IsReadOnly() && !mpCurTheme ->IsImported() ) 635 { 636 if( !mpCurTheme->IsDragging() ) 637 { 638 if( rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING ) || 639 rTarget.IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) || 640 rTarget.IsDropFormatSupported( FORMAT_FILE ) || 641 rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB ) || 642 rTarget.IsDropFormatSupported( FORMAT_GDIMETAFILE ) || 643 rTarget.IsDropFormatSupported( FORMAT_BITMAP ) ) 644 { 645 nRet = DND_ACTION_COPY; 646 } 647 } 648 else 649 nRet = DND_ACTION_COPY; 650 } 651 652 return nRet; 653 } 654 655 // ----------------------------------------------------------------------------- 656 657 sal_Int8 GalleryBrowser2::ExecuteDrop( DropTargetHelper&, const ExecuteDropEvent& rEvt ) 658 { 659 sal_Int8 nRet = DND_ACTION_NONE; 660 661 if( mpCurTheme ) 662 { 663 Point aSelPos; 664 const sal_uIntPtr nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos ); 665 const sal_uIntPtr nInsertPos = ( nItemId ? ( nItemId - 1 ) : LIST_APPEND ); 666 667 if( mpCurTheme->IsDragging() ) 668 mpCurTheme->ChangeObjectPos( mpCurTheme->GetDragPos(), nInsertPos ); 669 else 670 nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos ); 671 } 672 673 return nRet; 674 } 675 676 // ----------------------------------------------------------------------------- 677 678 void GalleryBrowser2::StartDrag( Window*, const Point* pDragPoint ) 679 { 680 if( mpCurTheme ) 681 { 682 Point aSelPos; 683 const sal_uIntPtr nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos ); 684 685 if( nItemId ) 686 mpCurTheme->StartDrag( this, nItemId - 1 ); 687 } 688 } 689 690 // ----------------------------------------------------------------------------- 691 692 void GalleryBrowser2::TogglePreview( Window*, const Point* ) 693 { 694 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode ); 695 GetViewWindow()->GrabFocus(); 696 } 697 698 // ----------------------------------------------------------------------------- 699 700 void GalleryBrowser2::ShowContextMenu( Window*, const Point* pContextPoint ) 701 { 702 Point aSelPos; 703 const sal_uIntPtr nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos ); 704 705 if( mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() ) ) 706 { 707 ImplSelectItemId( nItemId ); 708 709 css::uno::Reference< css::frame::XFrame > xFrame( GetFrame() ); 710 if ( xFrame.is() ) 711 { 712 mnCurActionPos = nItemId - 1; 713 rtl::Reference< GalleryThemePopup > rPopup( 714 new GalleryThemePopup( 715 mpCurTheme, 716 mnCurActionPos, 717 GALLERYBROWSERMODE_PREVIEW == GetMode(), 718 this ) ); 719 rPopup->ExecutePopup( this, aSelPos ); 720 } 721 } 722 } 723 724 // ----------------------------------------------------------------------------- 725 726 sal_Bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, Window* pWindow ) 727 { 728 Point aSelPos; 729 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos ); 730 GalleryBrowser* pParentBrowser = dynamic_cast<GalleryBrowser*>(GetParent()); 731 sal_Bool bRet = sal_False; 732 if (pParentBrowser != NULL) 733 bRet = pParentBrowser->KeyInput( rKEvt, pWindow ); 734 else 735 { 736 svx::sidebar::GalleryControl* pParentControl = dynamic_cast<svx::sidebar::GalleryControl*>(GetParent()); 737 if (pParentControl != NULL) 738 bRet = pParentControl->KeyInput(rKEvt, pWindow); 739 } 740 741 if( !bRet && !maViewBox.HasFocus() && nItemId && mpCurTheme ) 742 { 743 sal_uInt16 nExecuteId = 0; 744 const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( nItemId - 1 ); 745 INetURLObject aURL; 746 747 const_cast< GalleryTheme* >( mpCurTheme )->GetURL( nItemId - 1, aURL ); 748 749 const sal_Bool bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID ); 750 sal_Bool bPreview = bValidURL; 751 sal_Bool bAdd = bValidURL; 752 sal_Bool bAddLink = ( bValidURL && SGA_OBJ_SVDRAW != eObjKind ); 753 sal_Bool bDelete = sal_False; 754 sal_Bool bTitle = sal_False; 755 756 if( !mpCurTheme->IsReadOnly() && mpCurTheme->GetObjectCount() ) 757 { 758 bDelete = ( GALLERYBROWSERMODE_PREVIEW != GetMode() ); 759 bTitle = sal_True; 760 } 761 762 switch( rKEvt.GetKeyCode().GetCode() ) 763 { 764 case( KEY_SPACE ): 765 case( KEY_RETURN ): 766 case( KEY_P ): 767 { 768 if( bPreview ) 769 { 770 TogglePreview( pWindow ); 771 bRet = sal_True; 772 } 773 } 774 break; 775 776 case( KEY_INSERT ): 777 case( KEY_I ): 778 { 779 // Inserting a gallery item in the document must be dispatched 780 if( bAddLink && rKEvt.GetKeyCode().IsShift() && rKEvt.GetKeyCode().IsMod1() ) 781 nExecuteId = MN_ADD_LINK; 782 else if( bAdd ) 783 nExecuteId = MN_ADD; 784 if( nExecuteId ) 785 { 786 Dispatch( nExecuteId ); 787 return sal_True; 788 } 789 } 790 break; 791 792 case( KEY_DELETE ): 793 case( KEY_D ): 794 { 795 if( bDelete ) 796 nExecuteId = MN_DELETE; 797 } 798 break; 799 800 case( KEY_T ): 801 { 802 if( bTitle ) 803 nExecuteId = MN_TITLE; 804 } 805 break; 806 807 default: 808 break; 809 } 810 811 if( nExecuteId ) 812 { 813 Execute( nExecuteId ); 814 bRet = sal_True; 815 } 816 } 817 818 return bRet; 819 } 820 821 // ----------------------------------------------------------------------------- 822 823 void GalleryBrowser2::SelectTheme( const String& rThemeName ) 824 { 825 delete mpIconView, mpIconView = NULL; 826 delete mpListView, mpListView = NULL; 827 delete mpPreview, mpPreview = NULL; 828 829 if( mpCurTheme ) 830 mpGallery->ReleaseTheme( mpCurTheme, *this ); 831 832 mpCurTheme = mpGallery->AcquireTheme( rThemeName, *this ); 833 834 mpIconView = new GalleryIconView( this, mpCurTheme ); 835 mpListView = new GalleryListView( this, mpCurTheme ); 836 mpPreview = new GalleryPreview( this, mpCurTheme ); 837 838 mpIconView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) )); 839 mpListView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) )); 840 mpPreview->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_PREVIEW ) )); 841 842 const Link aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) ); 843 844 mpIconView->SetSelectHdl( aSelectHdl ); 845 mpListView->SetSelectHdl( aSelectHdl ); 846 847 if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) 848 meMode = meLastMode; 849 850 Resize(); 851 ImplUpdateViews( 1 ); 852 853 maViewBox.EnableItem( TBX_ID_ICON, sal_True ); 854 maViewBox.EnableItem( TBX_ID_LIST, sal_True ); 855 maViewBox.CheckItem( ( GALLERYBROWSERMODE_ICON == GetMode() ) ? TBX_ID_ICON : TBX_ID_LIST, sal_True ); 856 857 if(maInfoBar.GetText().Len() == 0) 858 mpIconView->SetAccessibleRelationLabeledBy(mpIconView); 859 else 860 mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar); 861 mpIconView->SetAccessibleRelationMemberOf(mpIconView); 862 } 863 864 // ----------------------------------------------------------------------------- 865 866 void GalleryBrowser2::SetMode( GalleryBrowserMode eMode ) 867 { 868 if( GetMode() != eMode ) 869 { 870 meLastMode = GetMode(); 871 872 switch( eMode ) 873 { 874 case( GALLERYBROWSERMODE_ICON ): 875 { 876 mpListView->Hide(); 877 878 mpPreview->Hide(); 879 mpPreview->SetGraphic( Graphic() ); 880 mpPreview->PreviewMedia( INetURLObject() ); 881 882 mpIconView->Show(); 883 884 maViewBox.EnableItem( TBX_ID_ICON, sal_True ); 885 maViewBox.EnableItem( TBX_ID_LIST, sal_True ); 886 887 maViewBox.CheckItem( TBX_ID_ICON, sal_True ); 888 maViewBox.CheckItem( TBX_ID_LIST, sal_False ); 889 } 890 break; 891 892 case( GALLERYBROWSERMODE_LIST ): 893 { 894 mpIconView->Hide(); 895 896 mpPreview->Hide(); 897 mpPreview->SetGraphic( Graphic() ); 898 mpPreview->PreviewMedia( INetURLObject() ); 899 900 mpListView->Show(); 901 902 maViewBox.EnableItem( TBX_ID_ICON, sal_True ); 903 maViewBox.EnableItem( TBX_ID_LIST, sal_True ); 904 905 maViewBox.CheckItem( TBX_ID_ICON, sal_False ); 906 maViewBox.CheckItem( TBX_ID_LIST, sal_True ); 907 } 908 break; 909 910 case( GALLERYBROWSERMODE_PREVIEW ): 911 { 912 Graphic aGraphic; 913 Point aSelPos; 914 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos ); 915 916 if( nItemId ) 917 { 918 const sal_uIntPtr nPos = nItemId - 1; 919 920 mpIconView->Hide(); 921 mpListView->Hide(); 922 923 if( mpCurTheme ) 924 mpCurTheme->GetGraphic( nPos, aGraphic ); 925 926 mpPreview->SetGraphic( aGraphic ); 927 mpPreview->Show(); 928 929 if( mpCurTheme && mpCurTheme->GetObjectKind( nPos ) == SGA_OBJ_SOUND ) 930 mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) ); 931 932 maViewBox.EnableItem( TBX_ID_ICON, sal_False ); 933 maViewBox.EnableItem( TBX_ID_LIST, sal_False ); 934 } 935 } 936 break; 937 938 default: 939 break; 940 } 941 942 GalleryBrowser2::meInitMode = meMode = eMode; 943 } 944 } 945 946 // ----------------------------------------------------------------------------- 947 948 Window* GalleryBrowser2::GetViewWindow() const 949 { 950 Window* pRet; 951 952 switch( GetMode() ) 953 { 954 case( GALLERYBROWSERMODE_LIST ): pRet = mpListView; break; 955 case( GALLERYBROWSERMODE_PREVIEW ): pRet = mpPreview; break; 956 957 default: 958 pRet = mpIconView; 959 break; 960 } 961 962 return pRet; 963 } 964 965 // ----------------------------------------------------------------------------- 966 967 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel ) 968 { 969 if( mpCurTheme ) 970 { 971 Point aSelPos; 972 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos ); 973 974 if( nItemId ) 975 { 976 sal_uIntPtr nNewItemId = nItemId; 977 978 switch( eTravel ) 979 { 980 case( GALLERYBROWSERTRAVEL_FIRST ): nNewItemId = 1; break; 981 case( GALLERYBROWSERTRAVEL_LAST ): nNewItemId = mpCurTheme->GetObjectCount(); break; 982 case( GALLERYBROWSERTRAVEL_PREVIOUS ): nNewItemId--; break; 983 case( GALLERYBROWSERTRAVEL_NEXT ): nNewItemId++; break; 984 default: 985 break; 986 } 987 988 if( nNewItemId < 1 ) 989 nNewItemId = 1; 990 else if( nNewItemId > mpCurTheme->GetObjectCount() ) 991 nNewItemId = mpCurTheme->GetObjectCount(); 992 993 if( nNewItemId != nItemId ) 994 { 995 ImplSelectItemId( nNewItemId ); 996 ImplUpdateInfoBar(); 997 998 if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) 999 { 1000 Graphic aGraphic; 1001 const sal_uIntPtr nPos = nNewItemId - 1; 1002 1003 mpCurTheme->GetGraphic( nPos, aGraphic ); 1004 mpPreview->SetGraphic( aGraphic ); 1005 1006 if( SGA_OBJ_SOUND == mpCurTheme->GetObjectKind( nPos ) ) 1007 mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) ); 1008 1009 mpPreview->Invalidate(); 1010 } 1011 } 1012 } 1013 } 1014 } 1015 1016 // ----------------------------------------------------------------------------- 1017 1018 void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId ) 1019 { 1020 mpIconView->Hide(); 1021 mpListView->Hide(); 1022 mpPreview->Hide(); 1023 1024 mpIconView->Clear(); 1025 mpListView->Clear(); 1026 1027 if( mpCurTheme ) 1028 { 1029 for( sal_uIntPtr i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; ) 1030 { 1031 mpListView->RowInserted( i++ ); 1032 mpIconView->InsertItem( (sal_uInt16) i ); 1033 } 1034 1035 ImplSelectItemId( ( ( nSelectionId > mpCurTheme->GetObjectCount() ) ? mpCurTheme->GetObjectCount() : nSelectionId ) ); 1036 } 1037 1038 switch( GetMode() ) 1039 { 1040 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break; 1041 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break; 1042 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break; 1043 1044 default: 1045 break; 1046 } 1047 1048 ImplUpdateInfoBar(); 1049 } 1050 1051 // ----------------------------------------------------------------------------- 1052 1053 void GalleryBrowser2::ImplUpdateInfoBar() 1054 { 1055 String aInfoText; 1056 1057 if( mpCurTheme ) 1058 { 1059 Point aSelPos; 1060 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos ); 1061 1062 if( nItemId ) 1063 { 1064 const sal_uIntPtr nPos = nItemId - 1; 1065 1066 aInfoText = mpCurTheme->GetName(); 1067 1068 if( nPos < mpCurTheme->GetObjectCount() ) 1069 { 1070 SgaObject* pObj = mpCurTheme->AcquireObject( nPos ); 1071 1072 if( pObj ) 1073 { 1074 aInfoText = GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_THEMENAME | GALLERY_ITEM_TITLE | GALLERY_ITEM_PATH ); 1075 mpCurTheme->ReleaseObject( pObj ); 1076 } 1077 } 1078 } 1079 } 1080 1081 maInfoBar.SetText( aInfoText ); 1082 } 1083 1084 // ----------------------------------------------------------------------------- 1085 1086 sal_uIntPtr GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos ) 1087 { 1088 const Size aOutputSizePixel( GetOutputSizePixel() ); 1089 sal_uIntPtr nRet = 0; 1090 1091 if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) 1092 { 1093 nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mpIconView->GetSelectItemId() : ( mpListView->FirstSelectedRow() + 1 ) ); 1094 1095 if( pSelPos ) 1096 rSelPos = GetPointerPosPixel(); 1097 else 1098 rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 ); 1099 } 1100 else if( GALLERYBROWSERMODE_ICON == GetMode() ) 1101 { 1102 if( pSelPos ) 1103 { 1104 nRet = mpIconView->GetItemId( *pSelPos ); 1105 rSelPos = GetPointerPosPixel(); 1106 } 1107 else 1108 { 1109 nRet = mpIconView->GetSelectItemId(); 1110 rSelPos = mpIconView->GetItemRect( (sal_uInt16) nRet ).Center(); 1111 } 1112 } 1113 else 1114 { 1115 if( pSelPos ) 1116 { 1117 nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1; 1118 rSelPos = GetPointerPosPixel(); 1119 } 1120 else 1121 { 1122 nRet = mpListView->FirstSelectedRow() + 1; 1123 rSelPos = mpListView->GetFieldRectPixel( (sal_uInt16) nRet, 1 ).Center(); 1124 } 1125 } 1126 1127 rSelPos.X() = Max( Min( rSelPos.X(), aOutputSizePixel.Width() - 1L ), 0L ); 1128 rSelPos.Y() = Max( Min( rSelPos.Y(), aOutputSizePixel.Height() - 1L ), 0L ); 1129 1130 if( nRet && ( !mpCurTheme || ( nRet > mpCurTheme->GetObjectCount() ) ) ) 1131 { 1132 nRet = 0; 1133 } 1134 1135 return nRet; 1136 } 1137 1138 // ----------------------------------------------------------------------------- 1139 1140 void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId ) 1141 { 1142 if( nItemId ) 1143 { 1144 1145 mpIconView->SelectItem( (sal_uInt16) nItemId ); 1146 mpListView->SelectRow( nItemId - 1 ); 1147 } 1148 } 1149 1150 // ----------------------------------------------------------------------------- 1151 1152 css::uno::Reference< css::frame::XFrame > 1153 GalleryBrowser2::GetFrame() const 1154 { 1155 css::uno::Reference< css::frame::XFrame > xFrame; 1156 SfxViewFrame* pCurrentViewFrame = SfxViewFrame::Current(); 1157 if ( pCurrentViewFrame ) 1158 { 1159 SfxBindings& rBindings = pCurrentViewFrame->GetBindings(); 1160 xFrame.set( rBindings.GetActiveFrame() ); 1161 } 1162 1163 return xFrame; 1164 } 1165 1166 void GalleryBrowser2::Dispatch( 1167 sal_uInt16 nId, 1168 const css::uno::Reference< css::frame::XDispatch > &rxDispatch, 1169 const css::util::URL &rURL ) 1170 { 1171 Point aSelPos; 1172 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos ); 1173 1174 if( !mpCurTheme || !nItemId ) 1175 return; 1176 1177 mnCurActionPos = nItemId - 1; 1178 1179 switch( nId ) 1180 { 1181 case( MN_ADD ): 1182 case( MN_ADD_LINK ): 1183 { 1184 css::uno::Reference< css::frame::XDispatch > xDispatch( rxDispatch ); 1185 css::util::URL aURL = rURL; 1186 1187 if ( !xDispatch.is() ) 1188 { 1189 css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider( 1190 GetFrame(), css::uno::UNO_QUERY ); 1191 if ( !xDispatchProvider.is() || !m_xTransformer.is() ) 1192 return; 1193 1194 aURL.Complete = C2U( CMD_SID_GALLERY_FORMATS ); 1195 m_xTransformer->parseStrict( aURL ); 1196 xDispatch = xDispatchProvider->queryDispatch( 1197 aURL, 1198 C2U( "_self" ), 1199 css::frame::FrameSearchFlag::SELF ); 1200 } 1201 1202 if ( !xDispatch.is() ) 1203 return; 1204 1205 sal_Int8 nType = 0; 1206 sal_Bool bIsLink( MN_ADD_LINK == nId ); 1207 OUString aFileURL, aFilterName; 1208 css::uno::Reference< css::lang::XComponent > xDrawing; 1209 css::uno::Reference< css::graphic::XGraphic > xGraphic; 1210 1211 aFilterName = GetFilterName(); 1212 1213 switch( mpCurTheme->GetObjectKind( mnCurActionPos ) ) 1214 { 1215 case( SGA_OBJ_BMP ): 1216 case( SGA_OBJ_ANIM ): 1217 case( SGA_OBJ_INET ): 1218 // TODO drawing objects are inserted as drawings only via drag&drop 1219 case( SGA_OBJ_SVDRAW ): 1220 nType = css::gallery::GalleryItemType::GRAPHIC; 1221 break; 1222 1223 case ( SGA_OBJ_SOUND ) : 1224 nType = css::gallery::GalleryItemType::MEDIA; 1225 break; 1226 1227 default: 1228 nType = css::gallery::GalleryItemType::EMPTY; 1229 break; 1230 } 1231 1232 if ( bIsLink ) 1233 { 1234 aFileURL = mpCurTheme->GetObjectURL( mnCurActionPos ).GetMainURL( INetURLObject::NO_DECODE ); 1235 OSL_ENSURE( aFileURL.getLength(), "gallery item is link but no URL!" ); 1236 } 1237 1238 Graphic aGraphic; 1239 sal_Bool bGraphic = mpCurTheme->GetGraphic( mnCurActionPos, aGraphic ); 1240 if ( bGraphic && !!aGraphic ) 1241 xGraphic.set( aGraphic.GetXGraphic() ); 1242 OSL_ENSURE( xGraphic.is(), "gallery item is graphic, but the reference is invalid!" ); 1243 1244 css::uno::Sequence< css::beans::PropertyValue > aSeq( SVXGALLERYITEM_PARAMS ); 1245 1246 aSeq[0].Name = C2U( SVXGALLERYITEM_TYPE ); 1247 aSeq[0].Value <<= nType; 1248 aSeq[1].Name = C2U( SVXGALLERYITEM_LINK ); 1249 aSeq[1].Value <<= bIsLink; 1250 aSeq[2].Name = C2U( SVXGALLERYITEM_URL ); 1251 aSeq[2].Value <<= aFileURL; 1252 aSeq[3].Name = C2U( SVXGALLERYITEM_FILTER ); 1253 aSeq[3].Value <<= aFilterName; 1254 aSeq[4].Name = C2U( SVXGALLERYITEM_DRAWING ); 1255 aSeq[4].Value <<= xDrawing; 1256 aSeq[5].Name = C2U( SVXGALLERYITEM_GRAPHIC ); 1257 aSeq[5].Value <<= xGraphic; 1258 1259 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 ); 1260 aArgs[0].Name = C2U( SVXGALLERYITEM_ARGNAME ); 1261 aArgs[0].Value <<= aSeq; 1262 1263 DispatchInfo *pInfo = new DispatchInfo; 1264 pInfo->TargetURL = aURL; 1265 pInfo->Arguments = aArgs; 1266 pInfo->Dispatch = xDispatch; 1267 1268 if ( !Application::PostUserEvent( 1269 STATIC_LINK( 0, GalleryBrowser2, AsyncDispatch_Impl), pInfo ) ) 1270 delete pInfo; 1271 } 1272 break; 1273 1274 default: 1275 break; 1276 } 1277 } 1278 1279 void GalleryBrowser2::Execute( sal_uInt16 nId ) 1280 { 1281 Point aSelPos; 1282 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos ); 1283 1284 if( mpCurTheme && nItemId ) 1285 { 1286 mnCurActionPos = nItemId - 1; 1287 1288 switch( nId ) 1289 { 1290 case( MN_PREVIEW ): 1291 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode ); 1292 break; 1293 1294 case( MN_DELETE ): 1295 { 1296 if( !mpCurTheme->IsReadOnly() && 1297 QueryBox( NULL, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETEOBJ ) ) ).Execute() == RET_YES ) 1298 { 1299 mpCurTheme->RemoveObject( mnCurActionPos ); 1300 } 1301 } 1302 break; 1303 1304 case( MN_TITLE ): 1305 { 1306 SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos ); 1307 1308 if( pObj ) 1309 { 1310 const String aOldTitle( GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_TITLE ) ); 1311 //CHINA001 TitleDialog aDlg( this, aOldTitle ); 1312 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 1313 if(pFact) 1314 { 1315 AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldTitle ); 1316 DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001 1317 if( aDlg->Execute() == RET_OK )//CHINA001 if( aDlg.Execute() == RET_OK ) 1318 { 1319 String aNewTitle( aDlg->GetTitle() );//CHINA001 String aNewTitle( aDlg.GetTitle() ); 1320 1321 if( ( !aNewTitle.Len() && pObj->GetTitle().Len() ) || ( aNewTitle != aOldTitle ) ) 1322 { 1323 if( !aNewTitle.Len() ) 1324 aNewTitle = String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) ); 1325 1326 pObj->SetTitle( aNewTitle ); 1327 mpCurTheme->InsertObject( *pObj ); 1328 } 1329 } 1330 1331 mpCurTheme->ReleaseObject( pObj ); 1332 delete aDlg; //add CHINA001 1333 } 1334 } 1335 } 1336 break; 1337 1338 case( MN_COPYCLIPBOARD ): 1339 { 1340 Window* pWindow; 1341 1342 switch( GetMode() ) 1343 { 1344 case( GALLERYBROWSERMODE_ICON ): pWindow = (Window*) mpIconView; break; 1345 case( GALLERYBROWSERMODE_LIST ): pWindow = (Window*) mpListView; break; 1346 case( GALLERYBROWSERMODE_PREVIEW ): pWindow = (Window*) mpPreview; break; 1347 1348 default: 1349 pWindow = NULL; 1350 break; 1351 } 1352 1353 mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos ); 1354 } 1355 break; 1356 1357 case( MN_PASTECLIPBOARD ): 1358 { 1359 if( !mpCurTheme->IsReadOnly() ) 1360 { 1361 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) ); 1362 mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos ); 1363 } 1364 } 1365 break; 1366 1367 default: 1368 break; 1369 } 1370 } 1371 } 1372 1373 // ----------------------------------------------------------------------------- 1374 1375 String GalleryBrowser2::GetItemText( const GalleryTheme& rTheme, const SgaObject& rObj, sal_uIntPtr nItemTextFlags ) 1376 { 1377 INetURLObject aURL; 1378 String aRet; 1379 1380 if( rTheme.IsImported() ) 1381 { 1382 aURL = rTheme.GetParent()->GetImportURL( rTheme.GetName() ); 1383 1384 aURL.removeSegment(); 1385 aURL.Append( rObj.GetURL().GetName() ); 1386 } 1387 else 1388 aURL = rObj.GetURL(); 1389 1390 if( nItemTextFlags & GALLERY_ITEM_THEMENAME ) 1391 { 1392 aRet += rTheme.GetName(); 1393 aRet += String( RTL_CONSTASCII_USTRINGPARAM( " - " ) ); 1394 } 1395 1396 if( nItemTextFlags & GALLERY_ITEM_TITLE ) 1397 { 1398 String aTitle( rObj.GetTitle() ); 1399 1400 if( !aTitle.Len() ) 1401 aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS ); 1402 1403 if( !aTitle.Len() ) 1404 { 1405 aTitle = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ); 1406 aTitle = aTitle.GetToken( aTitle.GetTokenCount( '/' ) - 1, '/' ); 1407 } 1408 1409 aRet += aTitle; 1410 } 1411 1412 if( nItemTextFlags & GALLERY_ITEM_PATH ) 1413 { 1414 const String aPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) ); 1415 1416 if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) ) 1417 aRet += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) ); 1418 1419 aRet += String(aURL.getFSysPath( INetURLObject::FSYS_DETECT )); 1420 1421 if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) ) 1422 aRet += ')'; 1423 } 1424 1425 return aRet; 1426 } 1427 1428 // ----------------------------------------------------------------------------- 1429 1430 INetURLObject GalleryBrowser2::GetURL() const 1431 { 1432 INetURLObject aURL; 1433 1434 if( mpCurTheme && mnCurActionPos != 0xffffffff ) 1435 aURL = mpCurTheme->GetObjectURL( mnCurActionPos ); 1436 1437 return aURL; 1438 } 1439 1440 // ----------------------------------------------------------------------------- 1441 1442 String GalleryBrowser2::GetFilterName() const 1443 { 1444 String aFilterName; 1445 1446 if( mpCurTheme && mnCurActionPos != 0xffffffff ) 1447 { 1448 const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( mnCurActionPos ); 1449 1450 if( ( SGA_OBJ_BMP == eObjKind ) || ( SGA_OBJ_ANIM == eObjKind ) ) 1451 { 1452 GraphicFilter* pFilter = GraphicFilter::GetGraphicFilter(); 1453 INetURLObject aURL; mpCurTheme->GetURL( mnCurActionPos, aURL ); 1454 sal_uInt16 nFilter = pFilter->GetImportFormatNumberForShortName( aURL.GetExtension() ); 1455 1456 if( GRFILTER_FORMAT_DONTKNOW != nFilter ) 1457 aFilterName = pFilter->GetImportFormatName( nFilter ); 1458 } 1459 } 1460 1461 return aFilterName; 1462 } 1463 1464 // ----------------------------------------------------------------------------- 1465 1466 Graphic GalleryBrowser2::GetGraphic() const 1467 { 1468 Graphic aGraphic; 1469 1470 if( mpCurTheme && mnCurActionPos != 0xffffffff ) 1471 mpCurTheme->GetGraphic( mnCurActionPos, aGraphic ); 1472 1473 return aGraphic; 1474 } 1475 1476 // ----------------------------------------------------------------------------- 1477 1478 sal_Bool GalleryBrowser2::GetVCDrawModel( FmFormModel& rModel ) const 1479 { 1480 sal_Bool bRet = sal_False; 1481 1482 if( mpCurTheme && mnCurActionPos != 0xffffffff ) 1483 bRet = mpCurTheme->GetModel( mnCurActionPos, rModel ); 1484 1485 return bRet; 1486 } 1487 1488 // ----------------------------------------------------------------------------- 1489 1490 IMPL_LINK( GalleryBrowser2, SelectObjectHdl, void*, EMPTYARG ) 1491 { 1492 ImplUpdateInfoBar(); 1493 return 0L; 1494 } 1495 1496 // ----------------------------------------------------------------------------- 1497 1498 IMPL_LINK( GalleryBrowser2, SelectTbxHdl, ToolBox*, pBox ) 1499 { 1500 if( pBox->GetCurItemId() == TBX_ID_ICON ) 1501 SetMode( GALLERYBROWSERMODE_ICON ); 1502 else if( pBox->GetCurItemId() == TBX_ID_LIST ) 1503 SetMode( GALLERYBROWSERMODE_LIST ); 1504 1505 return 0L; 1506 } 1507 1508 // ----------------------------------------------------------------------------- 1509 1510 IMPL_LINK( GalleryBrowser2, MiscHdl, void*, EMPTYARG ) 1511 { 1512 const sal_Bool bHC = maViewBox.GetSettings().GetStyleSettings().GetHighContrastMode(); 1513 1514 maViewBox.SetOutStyle( maMiscOptions.GetToolboxStyle() ); 1515 1516 BitmapEx aIconBmpEx = BitmapEx( Image( GAL_RESID( bHC? RID_SVXIMG_GALLERY_VIEW_ICON_HC : RID_SVXIMG_GALLERY_VIEW_ICON ) ).GetBitmapEx() ); 1517 BitmapEx aListBmpEx = BitmapEx( Image( GAL_RESID( bHC? RID_SVXIMG_GALLERY_VIEW_LIST_HC : RID_SVXIMG_GALLERY_VIEW_LIST ) ).GetBitmapEx() ); 1518 1519 if( maMiscOptions.AreCurrentSymbolsLarge() ) 1520 { 1521 const Size aLargeSize( 24, 24); 1522 1523 aIconBmpEx.Scale( aLargeSize ); 1524 aListBmpEx.Scale( aLargeSize ); 1525 } 1526 1527 maViewBox.SetItemImage( TBX_ID_ICON, aIconBmpEx ); 1528 maViewBox.SetItemImage( TBX_ID_LIST, aListBmpEx ); 1529 maViewBox.SetSizePixel( maViewBox.CalcWindowSizePixel() ); 1530 1531 Resize(); 1532 1533 return 0L; 1534 } 1535