Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / gallery2 / galbrws2.cxx
blob70cd6578be3731057afd17cf848d2daa6611b253
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <comphelper/string.hxx>
31 #include <sot/formats.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svl/urlbmk.hxx>
34 #include <svl/stritem.hxx>
35 #include <svl/intitem.hxx>
36 #include <svl/eitem.hxx>
37 #include <svtools/transfer.hxx>
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/sfxsids.hrc>
42 #include "svtools/filter.hxx"
43 #include <editeng/brshitem.hxx>
44 #include "helpid.hrc"
45 #include "svx/gallery.hxx"
46 #include "galobj.hxx"
47 #include "svx/gallery1.hxx"
48 #include "svx/galtheme.hxx"
49 #include "svx/galctrl.hxx"
50 #include "svx/galmisc.hxx"
51 #include "galbrws2.hxx"
52 #include "gallery.hrc"
53 #include <vcl/svapp.hxx>
54 #include <svx/fmmodel.hxx>
55 #include <svx/dialmgr.hxx>
56 #include <svx/svxdlg.hxx>
57 #include <svx/dialogs.hrc>
59 // -----------
60 // - Defines -
61 // -----------
63 #undef GALLERY_USE_CLIPBOARD
65 #define TBX_ID_ICON 1
66 #define TBX_ID_LIST 2
68 // -----------
69 // - statics -
70 // -----------
72 GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON;
74 // --------------------------
75 // - GalleryBackgroundPopup -
76 // --------------------------
78 class GalleryBackgroundPopup : public PopupMenu, public SfxControllerItem
80 const GalleryTheme* mpTheme;
81 sal_uIntPtr mnObjectPos;
83 virtual void Select();
84 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
86 public:
88 GalleryBackgroundPopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos );
89 ~GalleryBackgroundPopup();
92 // ------------------------------------------------------------------------
94 GalleryBackgroundPopup::GalleryBackgroundPopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos ) :
95 SfxControllerItem ( SID_GALLERY_BG_BRUSH, SfxViewFrame::Current()->GetBindings() ),
96 mpTheme ( pTheme ),
97 mnObjectPos ( nObjectPos )
99 SfxViewFrame::Current()->GetBindings().Update( SID_GALLERY_BG_BRUSH );
100 RemoveDisabledEntries();
103 // ------------------------------------------------------------------------
105 GalleryBackgroundPopup::~GalleryBackgroundPopup()
109 // ------------------------------------------------------------------------
111 void GalleryBackgroundPopup::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pItem )
113 if ( ( nSID == SID_GALLERY_BG_BRUSH ) && pItem && ( eState != SFX_ITEM_DISABLED ) )
115 SfxStringListItem* pStrLstItem;
116 SfxStringItem* pStrItem;
118 PopupMenu::Clear();
120 if( ( pStrLstItem = PTR_CAST( SfxStringListItem, pItem ) ) != NULL )
122 const std::vector<String> &aList = pStrLstItem->GetList();
124 for ( sal_uIntPtr i = 0, nCount = aList.size(); i < nCount; i++ )
125 InsertItem( (sal_uInt16) i + 1, aList[i]);
127 else if( ( pStrItem = PTR_CAST( SfxStringItem, pItem ) ) != NULL )
128 InsertItem( 1, pStrItem->GetValue() );
129 else
131 OSL_FAIL( "SgaBGPopup::StateChanged(...): Wrong item type!" );
136 // ------------------------------------------------------------------------
138 void GalleryBackgroundPopup::Select()
140 Menu::Select();
142 const INetURLObject aURL( mpTheme->GetObjectURL( mnObjectPos ) );
143 const SvxBrushItem aBrushItem( aURL.GetMainURL( INetURLObject::NO_DECODE ), String(), GPOS_TILED, SID_GALLERY_BG_BRUSH );
144 const SfxUInt16Item aPosItem( SID_GALLERY_BG_POS, GetCurItemId() - 1 );
145 const SfxStringItem aPathItem( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE ) );
147 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_GALLERY_BG_BRUSH,
148 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
149 &aBrushItem, &aPosItem, &aPathItem, 0L );
152 // ---------------------
153 // - GalleryThemePopup -
154 // ---------------------
156 class GalleryThemePopup : public PopupMenu, public SfxControllerItem
158 GalleryBackgroundPopup maBackgroundPopup;
159 const GalleryTheme* mpTheme;
160 sal_uIntPtr mnObjectPos;
161 sal_Bool mbPreview;
163 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
165 public:
167 GalleryThemePopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos, sal_Bool bPreview );
168 ~GalleryThemePopup();
171 // ------------------------------------------------------------------------
173 GalleryThemePopup::GalleryThemePopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos, sal_Bool bPreview ) :
174 PopupMenu ( GAL_RES( RID_SVXMN_GALLERY2 ) ),
175 SfxControllerItem ( SID_GALLERY_ENABLE_ADDCOPY, SfxViewFrame::Current()->GetBindings() ),
176 maBackgroundPopup ( pTheme, nObjectPos ),
177 mpTheme ( pTheme ),
178 mnObjectPos ( nObjectPos ),
179 mbPreview ( bPreview )
181 const SgaObjKind eObjKind = mpTheme->GetObjectKind( mnObjectPos );
182 PopupMenu* pAddMenu = GetPopupMenu( MN_ADDMENU );
183 SfxBindings& rBindings = SfxViewFrame::Current()->GetBindings();
184 INetURLObject aURL;
186 const_cast< GalleryTheme* >( mpTheme )->GetURL( mnObjectPos, aURL );
187 const sal_Bool bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID );
189 pAddMenu->EnableItem( MN_ADD, bValidURL && SGA_OBJ_SOUND != eObjKind );
190 pAddMenu->EnableItem( MN_ADD_LINK, bValidURL && SGA_OBJ_SVDRAW != eObjKind );
192 EnableItem( MN_ADDMENU, pAddMenu->IsItemEnabled( MN_ADD ) || pAddMenu->IsItemEnabled( MN_ADD_LINK ) );
193 EnableItem( MN_PREVIEW, bValidURL );
195 CheckItem( MN_PREVIEW, mbPreview );
197 if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() )
199 EnableItem( MN_DELETE, sal_False );
200 EnableItem( MN_TITLE, sal_False );
202 if( mpTheme->IsReadOnly() )
203 EnableItem( MN_PASTECLIPBOARD, sal_False );
205 if( !mpTheme->GetObjectCount() )
206 EnableItem( MN_COPYCLIPBOARD, sal_False );
208 else
210 EnableItem( MN_DELETE, !bPreview );
211 EnableItem( MN_TITLE, sal_True );
212 EnableItem( MN_COPYCLIPBOARD, sal_True );
213 EnableItem( MN_PASTECLIPBOARD, sal_True );
216 #ifdef GALLERY_USE_CLIPBOARD
217 if( IsItemEnabled( MN_PASTECLIPBOARD ) )
219 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
220 sal_Bool bEnable = sal_False;
222 if( aDataHelper.GetFormatCount() )
224 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) ||
225 aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
226 aDataHelper.HasFormat( FORMAT_FILE ) ||
227 aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) ||
228 aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) ||
229 aDataHelper.HasFormat( FORMAT_BITMAP ) )
231 bEnable = sal_True;
235 if( !bEnable )
236 EnableItem( MN_PASTECLIPBOARD, sal_False );
238 #else
239 EnableItem( MN_COPYCLIPBOARD, sal_False );
240 EnableItem( MN_PASTECLIPBOARD, sal_False );
241 #endif
243 if( !maBackgroundPopup.GetItemCount() || ( eObjKind == SGA_OBJ_SVDRAW ) || ( eObjKind == SGA_OBJ_SOUND ) )
244 pAddMenu->EnableItem( MN_BACKGROUND, sal_False );
245 else
247 pAddMenu->EnableItem( MN_BACKGROUND, sal_True );
248 pAddMenu->SetPopupMenu( MN_BACKGROUND, &maBackgroundPopup );
251 rBindings.Update( SID_GALLERY_ENABLE_ADDCOPY );
252 RemoveDisabledEntries();
255 // ------------------------------------------------------------------------
257 GalleryThemePopup::~GalleryThemePopup()
261 // ------------------------------------------------------------------------
263 void GalleryThemePopup::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pItem )
265 if( ( nSID == SID_GALLERY_ENABLE_ADDCOPY ) && pItem && ( eState != SFX_ITEM_DISABLED ) )
267 SfxBoolItem* pBoolItem = PTR_CAST( SfxBoolItem, pItem );
268 const SgaObjKind eObjKind = mpTheme->GetObjectKind( mnObjectPos );
270 DBG_ASSERT( pBoolItem || pBoolItem == 0, "SfxBoolItem erwartet!");
272 GetPopupMenu( MN_ADDMENU )->EnableItem( MN_ADD, pBoolItem->GetValue() && ( eObjKind != SGA_OBJ_SOUND ) );
276 // ------------------
277 // - GalleryToolBox -
278 // ------------------
280 GalleryToolBox::GalleryToolBox( GalleryBrowser2* pParent ) :
281 ToolBox( pParent, WB_TABSTOP )
285 // ------------------------------------------------------------------------
287 GalleryToolBox::~GalleryToolBox()
291 // ------------------------------------------------------------------------
293 void GalleryToolBox::KeyInput( const KeyEvent& rKEvt )
295 if( !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
296 ToolBox::KeyInput( rKEvt );
299 // -------------------
300 // - GalleryBrowser2 -
301 // -------------------
303 GalleryBrowser2::GalleryBrowser2( GalleryBrowser* pParent, const ResId& rResId, Gallery* pGallery ) :
304 Control ( pParent, rResId ),
305 mpGallery ( pGallery ),
306 mpCurTheme ( NULL ),
307 mpIconView ( new GalleryIconView( this, NULL ) ),
308 mpListView ( new GalleryListView( this, NULL ) ),
309 mpPreview ( new GalleryPreview( this, NULL ) ),
310 maViewBox ( this ),
311 maSeparator ( this, WB_VERT ),
312 maInfoBar ( this, WB_LEFT | WB_VCENTER ),
313 mnCurActionPos ( 0xffffffff ),
314 meMode ( GALLERYBROWSERMODE_NONE ),
315 meLastMode ( GALLERYBROWSERMODE_NONE ),
316 mbCurActionIsLinkage( sal_False )
318 Image aDummyImage;
319 const Link aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
320 Font aInfoFont( maInfoBar.GetControlFont() );
322 maMiscOptions.AddListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
324 maViewBox.InsertItem( TBX_ID_ICON, aDummyImage );
325 maViewBox.SetItemBits( TBX_ID_ICON, TIB_RADIOCHECK | TIB_AUTOCHECK );
326 maViewBox.SetHelpId( TBX_ID_ICON, HID_GALLERY_ICONVIEW );
327 maViewBox.SetQuickHelpText( TBX_ID_ICON, GAL_RESSTR(RID_SVXSTR_GALLERY_ICONVIEW) );
329 maViewBox.InsertItem( TBX_ID_LIST, aDummyImage );
330 maViewBox.SetItemBits( TBX_ID_LIST, TIB_RADIOCHECK | TIB_AUTOCHECK );
331 maViewBox.SetHelpId( TBX_ID_LIST, HID_GALLERY_LISTVIEW );
332 maViewBox.SetQuickHelpText( TBX_ID_LIST, GAL_RESSTR(RID_SVXSTR_GALLERY_LISTVIEW) );
334 maViewBox.SetBorder( 0, 1 );
335 MiscHdl( NULL );
336 maViewBox.SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
337 maViewBox.Show();
339 mpIconView->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS));
340 mpListView->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS));
342 maInfoBar.Show();
343 maSeparator.Show();
345 mpIconView->SetSelectHdl( aSelectHdl );
346 mpListView->SetSelectHdl( aSelectHdl );
348 InitSettings();
350 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON );
352 if(maInfoBar.GetText().Len() == 0)
353 mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
354 else
355 mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
356 mpIconView->SetAccessibleRelationMemberOf(mpIconView);
359 // -----------------------------------------------------------------------------
361 GalleryBrowser2::~GalleryBrowser2()
363 maMiscOptions.RemoveListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
365 delete mpPreview;
366 delete mpListView;
367 delete mpIconView;
369 if( mpCurTheme )
370 mpGallery->ReleaseTheme( mpCurTheme, *this );
373 // -----------------------------------------------------------------------------
375 void GalleryBrowser2::InitSettings()
377 Font aInfoFont( maInfoBar.GetControlFont() );
379 aInfoFont.SetWeight( WEIGHT_BOLD );
380 aInfoFont.SetColor( GALLERY_FG_COLOR );
381 maInfoBar.SetControlFont( aInfoFont );
383 maInfoBar.SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
384 maInfoBar.SetControlBackground( GALLERY_DLG_COLOR );
386 maSeparator.SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
387 maSeparator.SetControlBackground( GALLERY_BG_COLOR );
388 maSeparator.SetControlForeground( GALLERY_FG_COLOR );
391 // -----------------------------------------------------------------------------
393 void GalleryBrowser2::DataChanged( const DataChangedEvent& rDCEvt )
395 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
396 InitSettings();
397 else
398 Control::DataChanged( rDCEvt );
401 // -----------------------------------------------------------------------------
403 void GalleryBrowser2::Resize()
405 Control::Resize();
407 mpIconView->Hide();
408 mpListView->Hide();
409 mpPreview->Hide();
411 const Size aOutSize( GetOutputSizePixel() );
412 const Size aBoxSize( maViewBox.GetOutputSizePixel() );
413 const long nOffset = 2, nSepWidth = 2;
414 const long nInfoBarX = aBoxSize.Width() + ( nOffset * 3 ) + nSepWidth;
415 const Point aPt( 0, aBoxSize.Height() + 3 );
416 const Size aSz( aOutSize.Width(), aOutSize.Height() - aPt.Y() );
418 maSeparator.SetPosSizePixel( Point( aBoxSize.Width() + nOffset, 0 ), Size( nSepWidth, aBoxSize.Height() ) );
419 maInfoBar.SetPosSizePixel( Point( nInfoBarX, 0 ), Size( aOutSize.Width() - nInfoBarX, aBoxSize.Height() ) );
421 mpIconView->SetPosSizePixel( aPt, aSz );
422 mpListView->SetPosSizePixel( aPt, aSz );
423 mpPreview->SetPosSizePixel( aPt, aSz );
425 switch( GetMode() )
427 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
428 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
429 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
431 default:
432 break;
436 // -----------------------------------------------------------------------------
438 void GalleryBrowser2::Notify( SfxBroadcaster&, const SfxHint& rHint )
440 const GalleryHint& rGalleryHint = (const GalleryHint&) rHint;
442 switch( rGalleryHint.GetType() )
444 case( GALLERY_HINT_THEME_UPDATEVIEW ):
446 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
447 SetMode( meLastMode );
449 ImplUpdateViews( (sal_uInt16) rGalleryHint.GetData1() + 1 );
451 break;
453 default:
454 break;
458 // -----------------------------------------------------------------------------
460 sal_Int8 GalleryBrowser2::AcceptDrop( DropTargetHelper& rTarget, const AcceptDropEvent& )
462 sal_Int8 nRet = DND_ACTION_NONE;
464 if( mpCurTheme && !mpCurTheme->IsReadOnly() && !mpCurTheme ->IsImported() )
466 if( !mpCurTheme->IsDragging() )
468 if( rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING ) ||
469 rTarget.IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) ||
470 rTarget.IsDropFormatSupported( FORMAT_FILE ) ||
471 rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB ) ||
472 rTarget.IsDropFormatSupported( FORMAT_GDIMETAFILE ) ||
473 rTarget.IsDropFormatSupported( FORMAT_BITMAP ) )
475 nRet = DND_ACTION_COPY;
478 else
479 nRet = DND_ACTION_COPY;
482 return nRet;
485 // -----------------------------------------------------------------------------
487 sal_Int8 GalleryBrowser2::ExecuteDrop( DropTargetHelper&, const ExecuteDropEvent& rEvt )
489 sal_Int8 nRet = DND_ACTION_NONE;
491 if( mpCurTheme )
493 Point aSelPos;
494 const sal_uIntPtr nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos );
495 const sal_uIntPtr nInsertPos = (nItemId ? (nItemId - 1) : mpCurTheme->GetObjectCount());
497 if( mpCurTheme->IsDragging() )
498 mpCurTheme->ChangeObjectPos( mpCurTheme->GetDragPos(), nInsertPos );
499 else
500 nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos );
503 return nRet;
506 // -----------------------------------------------------------------------------
508 void GalleryBrowser2::StartDrag( Window*, const Point* pDragPoint )
510 if( mpCurTheme )
512 Point aSelPos;
513 const sal_uIntPtr nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos );
515 if( nItemId )
516 mpCurTheme->StartDrag( this, nItemId - 1 );
520 // -----------------------------------------------------------------------------
522 void GalleryBrowser2::TogglePreview( Window*, const Point* )
524 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
525 GetViewWindow()->GrabFocus();
528 // -----------------------------------------------------------------------------
530 void GalleryBrowser2::ShowContextMenu( Window*, const Point* pContextPoint )
532 Point aSelPos;
533 const sal_uIntPtr nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos );
535 if( mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() ) )
537 ImplSelectItemId( nItemId );
539 SfxViewFrame* pCurrentViewFrame = SfxViewFrame::Current();
540 if ( pCurrentViewFrame )
542 SfxBindings& rBindings = pCurrentViewFrame->GetBindings();
543 rBindings.ENTERREGISTRATIONS();
544 GalleryThemePopup aMenu( mpCurTheme, nItemId - 1, GALLERYBROWSERMODE_PREVIEW == GetMode() );
545 rBindings.LEAVEREGISTRATIONS();
546 aMenu.SetSelectHdl( LINK( this, GalleryBrowser2, MenuSelectHdl ) );
547 aMenu.Execute( this, aSelPos );
552 // -----------------------------------------------------------------------------
554 sal_Bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, Window* pWindow )
556 Point aSelPos;
557 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
558 sal_Bool bRet = static_cast< GalleryBrowser* >( GetParent() )->KeyInput( rKEvt, pWindow );
560 if( !bRet && !maViewBox.HasFocus() && nItemId && mpCurTheme )
562 sal_uInt16 nExecuteId = 0;
563 const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( nItemId - 1 );
564 INetURLObject aURL;
566 const_cast< GalleryTheme* >( mpCurTheme )->GetURL( nItemId - 1, aURL );
568 const sal_Bool bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID );
569 sal_Bool bPreview = bValidURL;
570 sal_Bool bAdd = bValidURL;
571 sal_Bool bAddLink = ( bValidURL && SGA_OBJ_SVDRAW != eObjKind );
572 sal_Bool bDelete = sal_False;
573 sal_Bool bTitle = sal_False;
575 if( !mpCurTheme->IsReadOnly() && mpCurTheme->GetObjectCount() )
577 bDelete = ( GALLERYBROWSERMODE_PREVIEW != GetMode() );
578 bTitle = sal_True;
581 switch( rKEvt.GetKeyCode().GetCode() )
583 case( KEY_SPACE ):
584 case( KEY_RETURN ):
585 case( KEY_P ):
587 if( bPreview )
589 TogglePreview( pWindow );
590 bRet = sal_True;
593 break;
595 case( KEY_INSERT ):
596 case( KEY_I ):
598 if( bAddLink && rKEvt.GetKeyCode().IsShift() && rKEvt.GetKeyCode().IsMod1() )
599 nExecuteId = MN_ADD_LINK;
600 else if( bAdd )
601 nExecuteId = MN_ADD;
603 break;
605 case( KEY_DELETE ):
606 case( KEY_D ):
608 if( bDelete )
609 nExecuteId = MN_DELETE;
611 break;
613 case( KEY_T ):
615 if( bTitle )
616 nExecuteId = MN_TITLE;
618 break;
620 default:
621 break;
624 if( nExecuteId )
626 ImplExecute( nExecuteId );
627 bRet = sal_True;
631 return bRet;
634 // -----------------------------------------------------------------------------
636 void GalleryBrowser2::SelectTheme( const String& rThemeName )
638 delete mpIconView, mpIconView = NULL;
639 delete mpListView, mpListView = NULL;
640 delete mpPreview, mpPreview = NULL;
642 if( mpCurTheme )
643 mpGallery->ReleaseTheme( mpCurTheme, *this );
645 mpCurTheme = mpGallery->AcquireTheme( rThemeName, *this );
647 mpIconView = new GalleryIconView( this, mpCurTheme );
648 mpListView = new GalleryListView( this, mpCurTheme );
649 mpPreview = new GalleryPreview( this, mpCurTheme );
651 mpIconView->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS));
652 mpListView->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS));
653 mpPreview->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_PREVIEW));
655 const Link aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
657 mpIconView->SetSelectHdl( aSelectHdl );
658 mpListView->SetSelectHdl( aSelectHdl );
660 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
661 meMode = meLastMode;
663 Resize();
664 ImplUpdateViews( 1 );
666 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
667 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
668 maViewBox.CheckItem( ( GALLERYBROWSERMODE_ICON == GetMode() ) ? TBX_ID_ICON : TBX_ID_LIST, sal_True );
670 if(maInfoBar.GetText().Len() == 0)
671 mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
672 else
673 mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
674 mpIconView->SetAccessibleRelationMemberOf(mpIconView);
677 // -----------------------------------------------------------------------------
679 void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
681 if( GetMode() != eMode )
683 meLastMode = GetMode();
685 switch( eMode )
687 case( GALLERYBROWSERMODE_ICON ):
689 mpListView->Hide();
691 mpPreview->Hide();
692 mpPreview->SetGraphic( Graphic() );
693 mpPreview->PreviewMedia( INetURLObject() );
695 mpIconView->Show();
697 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
698 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
700 maViewBox.CheckItem( TBX_ID_ICON, sal_True );
701 maViewBox.CheckItem( TBX_ID_LIST, sal_False );
703 break;
705 case( GALLERYBROWSERMODE_LIST ):
707 mpIconView->Hide();
709 mpPreview->Hide();
710 mpPreview->SetGraphic( Graphic() );
711 mpPreview->PreviewMedia( INetURLObject() );
713 mpListView->Show();
715 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
716 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
718 maViewBox.CheckItem( TBX_ID_ICON, sal_False );
719 maViewBox.CheckItem( TBX_ID_LIST, sal_True );
721 break;
723 case( GALLERYBROWSERMODE_PREVIEW ):
725 Graphic aGraphic;
726 Point aSelPos;
727 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
729 if( nItemId )
731 const sal_uIntPtr nPos = nItemId - 1;
733 mpIconView->Hide();
734 mpListView->Hide();
736 if( mpCurTheme )
737 mpCurTheme->GetGraphic( nPos, aGraphic );
739 mpPreview->SetGraphic( aGraphic );
740 mpPreview->Show();
742 if( mpCurTheme && mpCurTheme->GetObjectKind( nPos ) == SGA_OBJ_SOUND )
743 mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );
745 maViewBox.EnableItem( TBX_ID_ICON, sal_False );
746 maViewBox.EnableItem( TBX_ID_LIST, sal_False );
749 break;
751 default:
752 break;
755 GalleryBrowser2::meInitMode = meMode = eMode;
759 // -----------------------------------------------------------------------------
761 Window* GalleryBrowser2::GetViewWindow() const
763 Window* pRet;
765 switch( GetMode() )
767 case( GALLERYBROWSERMODE_LIST ): pRet = mpListView; break;
768 case( GALLERYBROWSERMODE_PREVIEW ): pRet = mpPreview; break;
770 default:
771 pRet = mpIconView;
772 break;
775 return pRet;
778 // -----------------------------------------------------------------------------
780 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )
782 if( mpCurTheme )
784 Point aSelPos;
785 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
787 if( nItemId )
789 sal_uIntPtr nNewItemId = nItemId;
791 switch( eTravel )
793 case( GALLERYBROWSERTRAVEL_FIRST ): nNewItemId = 1; break;
794 case( GALLERYBROWSERTRAVEL_LAST ): nNewItemId = mpCurTheme->GetObjectCount(); break;
795 case( GALLERYBROWSERTRAVEL_PREVIOUS ): nNewItemId--; break;
796 case( GALLERYBROWSERTRAVEL_NEXT ): nNewItemId++; break;
797 default:
798 break;
801 if( nNewItemId < 1 )
802 nNewItemId = 1;
803 else if( nNewItemId > mpCurTheme->GetObjectCount() )
804 nNewItemId = mpCurTheme->GetObjectCount();
806 if( nNewItemId != nItemId )
808 ImplSelectItemId( nNewItemId );
809 ImplUpdateInfoBar();
811 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
813 Graphic aGraphic;
814 const sal_uIntPtr nPos = nNewItemId - 1;
816 mpCurTheme->GetGraphic( nPos, aGraphic );
817 mpPreview->SetGraphic( aGraphic );
819 if( SGA_OBJ_SOUND == mpCurTheme->GetObjectKind( nPos ) )
820 mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );
822 mpPreview->Invalidate();
829 // -----------------------------------------------------------------------------
831 void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId )
833 mpIconView->Hide();
834 mpListView->Hide();
835 mpPreview->Hide();
837 mpIconView->Clear();
838 mpListView->Clear();
840 if( mpCurTheme )
842 for( sal_uIntPtr i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; )
844 mpListView->RowInserted( i++ );
845 mpIconView->InsertItem( (sal_uInt16) i );
848 ImplSelectItemId( ( ( nSelectionId > mpCurTheme->GetObjectCount() ) ? mpCurTheme->GetObjectCount() : nSelectionId ) );
851 switch( GetMode() )
853 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
854 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
855 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
857 default:
858 break;
861 ImplUpdateInfoBar();
864 // -----------------------------------------------------------------------------
866 void GalleryBrowser2::ImplUpdateInfoBar()
868 String aInfoText;
870 if( mpCurTheme )
872 Point aSelPos;
873 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
875 if( nItemId )
877 const sal_uIntPtr nPos = nItemId - 1;
879 aInfoText = mpCurTheme->GetName();
881 if( nPos < mpCurTheme->GetObjectCount() )
883 SgaObject* pObj = mpCurTheme->AcquireObject( nPos );
885 if( pObj )
887 aInfoText = GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_THEMENAME | GALLERY_ITEM_TITLE | GALLERY_ITEM_PATH );
888 mpCurTheme->ReleaseObject( pObj );
894 maInfoBar.SetText( aInfoText );
897 // -----------------------------------------------------------------------------
899 sal_uIntPtr GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos )
901 const Size aOutputSizePixel( GetOutputSizePixel() );
902 sal_uIntPtr nRet = 0;
904 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
906 nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mpIconView->GetSelectItemId() : ( mpListView->FirstSelectedRow() + 1 ) );
908 if( pSelPos )
909 rSelPos = GetPointerPosPixel();
910 else
911 rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
913 else if( GALLERYBROWSERMODE_ICON == GetMode() )
915 if( pSelPos )
917 nRet = mpIconView->GetItemId( *pSelPos );
918 rSelPos = GetPointerPosPixel();
920 else
922 nRet = mpIconView->GetSelectItemId();
923 rSelPos = mpIconView->GetItemRect( (sal_uInt16) nRet ).Center();
926 else
928 if( pSelPos )
930 nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1;
931 rSelPos = GetPointerPosPixel();
933 else
935 nRet = mpListView->FirstSelectedRow() + 1;
936 rSelPos = mpListView->GetFieldRectPixel( (sal_uInt16) nRet, 1 ).Center();
940 rSelPos.X() = Max( Min( rSelPos.X(), aOutputSizePixel.Width() - 1L ), 0L );
941 rSelPos.Y() = Max( Min( rSelPos.Y(), aOutputSizePixel.Height() - 1L ), 0L );
943 if( nRet && ( !mpCurTheme || ( nRet > mpCurTheme->GetObjectCount() ) ) )
945 nRet = 0;
948 return nRet;
951 // -----------------------------------------------------------------------------
953 void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId )
955 if( nItemId )
958 mpIconView->SelectItem( (sal_uInt16) nItemId );
959 mpListView->SelectRow( nItemId - 1 );
963 // -----------------------------------------------------------------------------
965 void GalleryBrowser2::ImplExecute( sal_uInt16 nId )
967 Point aSelPos;
968 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
970 if( mpCurTheme && nItemId )
972 mnCurActionPos = nItemId - 1;
974 switch( nId )
976 case( MN_ADD ):
977 case( MN_ADD_LINK ):
979 sal_uInt32 nFormat = 0;
981 mbCurActionIsLinkage = ( MN_ADD_LINK == nId );
983 switch( mpCurTheme->GetObjectKind( mnCurActionPos ) )
985 case( SGA_OBJ_BMP ):
986 case( SGA_OBJ_ANIM ):
987 case( SGA_OBJ_INET ):
988 nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_STRING;
989 break;
991 case ( SGA_OBJ_SOUND ) :
992 nFormat = SGA_FORMAT_SOUND | SGA_FORMAT_STRING;
993 break;
995 case( SGA_OBJ_SVDRAW ):
996 nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_SVDRAW | SGA_FORMAT_STRING;
997 break;
999 default :
1000 break;
1003 const SfxUInt32Item aItem( SID_GALLERY_FORMATS, nFormat );
1004 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute(
1005 SID_GALLERY_FORMATS, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
1007 break;
1009 case( MN_PREVIEW ):
1010 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
1011 break;
1013 case( MN_DELETE ):
1015 if( !mpCurTheme->IsReadOnly() &&
1016 QueryBox(NULL, WB_YES_NO, GAL_RESSTR(RID_SVXSTR_GALLERY_DELETEOBJ)).Execute() == RET_YES )
1018 mpCurTheme->RemoveObject( mnCurActionPos );
1021 break;
1023 case( MN_TITLE ):
1025 SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos );
1027 if( pObj )
1029 const String aOldTitle( GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_TITLE ) );
1031 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1032 if(pFact)
1034 AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldTitle );
1035 DBG_ASSERT(aDlg, "Dialogdiet fail!");
1036 if( aDlg->Execute() == RET_OK )
1038 String aNewTitle( aDlg->GetTitle() );
1040 if( ( !aNewTitle.Len() && pObj->GetTitle().Len() ) || ( aNewTitle != aOldTitle ) )
1042 if( !aNewTitle.Len() )
1043 aNewTitle = String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) );
1045 pObj->SetTitle( aNewTitle );
1046 mpCurTheme->InsertObject( *pObj );
1050 mpCurTheme->ReleaseObject( pObj );
1051 delete aDlg;
1055 break;
1057 case( MN_COPYCLIPBOARD ):
1059 Window* pWindow;
1061 switch( GetMode() )
1063 case( GALLERYBROWSERMODE_ICON ): pWindow = (Window*) mpIconView; break;
1064 case( GALLERYBROWSERMODE_LIST ): pWindow = (Window*) mpListView; break;
1065 case( GALLERYBROWSERMODE_PREVIEW ): pWindow = (Window*) mpPreview; break;
1067 default:
1068 pWindow = NULL;
1069 break;
1072 mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos );
1074 break;
1076 case( MN_PASTECLIPBOARD ):
1078 if( !mpCurTheme->IsReadOnly() )
1080 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1081 mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos );
1084 break;
1086 default:
1087 break;
1092 // -----------------------------------------------------------------------------
1094 String GalleryBrowser2::GetItemText( const GalleryTheme& rTheme, const SgaObject& rObj, sal_uIntPtr nItemTextFlags )
1096 INetURLObject aURL;
1097 String aRet;
1099 if( rTheme.IsImported() )
1101 aURL = rTheme.GetParent()->GetImportURL( rTheme.GetName() );
1103 aURL.removeSegment();
1104 aURL.Append( rObj.GetURL().GetName() );
1106 else
1107 aURL = rObj.GetURL();
1109 if( nItemTextFlags & GALLERY_ITEM_THEMENAME )
1111 aRet += rTheme.GetName();
1112 aRet += String( RTL_CONSTASCII_USTRINGPARAM( " - " ) );
1115 if( nItemTextFlags & GALLERY_ITEM_TITLE )
1117 String aTitle( rObj.GetTitle() );
1119 if( !aTitle.Len() )
1120 aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
1122 if( !aTitle.Len() )
1124 aTitle = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1125 aTitle = aTitle.GetToken( comphelper::string::getTokenCount(aTitle, '/') - 1, '/' );
1128 aRet += aTitle;
1131 if( nItemTextFlags & GALLERY_ITEM_PATH )
1133 const String aPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
1135 if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) )
1136 aRet += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
1138 aRet += String(aURL.getFSysPath( INetURLObject::FSYS_DETECT ));
1140 if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) )
1141 aRet += ')';
1144 return aRet;
1147 // -----------------------------------------------------------------------------
1149 INetURLObject GalleryBrowser2::GetURL() const
1151 INetURLObject aURL;
1153 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1154 aURL = mpCurTheme->GetObjectURL( mnCurActionPos );
1156 return aURL;
1159 // -----------------------------------------------------------------------------
1161 String GalleryBrowser2::GetFilterName() const
1163 String aFilterName;
1165 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1167 const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( mnCurActionPos );
1169 if( ( SGA_OBJ_BMP == eObjKind ) || ( SGA_OBJ_ANIM == eObjKind ) )
1171 GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
1172 INetURLObject aURL; mpCurTheme->GetURL( mnCurActionPos, aURL );
1173 sal_uInt16 nFilter = rFilter.GetImportFormatNumberForShortName( aURL.GetExtension() );
1175 if( GRFILTER_FORMAT_DONTKNOW != nFilter )
1176 aFilterName = rFilter.GetImportFormatName( nFilter );
1180 return aFilterName;
1183 // -----------------------------------------------------------------------------
1185 Graphic GalleryBrowser2::GetGraphic() const
1187 Graphic aGraphic;
1189 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1190 mpCurTheme->GetGraphic( mnCurActionPos, aGraphic );
1192 return aGraphic;
1195 // -----------------------------------------------------------------------------
1197 sal_Bool GalleryBrowser2::IsLinkage() const
1199 return mbCurActionIsLinkage;
1202 // -----------------------------------------------------------------------------
1204 IMPL_LINK( GalleryBrowser2, MenuSelectHdl, Menu*, pMenu )
1206 if( pMenu )
1207 ImplExecute( pMenu->GetCurItemId() );
1209 return 0;
1212 // -----------------------------------------------------------------------------
1214 IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectHdl)
1216 ImplUpdateInfoBar();
1217 return 0L;
1220 // -----------------------------------------------------------------------------
1222 IMPL_LINK( GalleryBrowser2, SelectTbxHdl, ToolBox*, pBox )
1224 if( pBox->GetCurItemId() == TBX_ID_ICON )
1225 SetMode( GALLERYBROWSERMODE_ICON );
1226 else if( pBox->GetCurItemId() == TBX_ID_LIST )
1227 SetMode( GALLERYBROWSERMODE_LIST );
1229 return 0L;
1232 // -----------------------------------------------------------------------------
1234 IMPL_LINK_NOARG(GalleryBrowser2, MiscHdl)
1236 maViewBox.SetOutStyle( maMiscOptions.GetToolboxStyle() );
1238 BitmapEx aIconBmpEx = BitmapEx( Image( GAL_RES( RID_SVXIMG_GALLERY_VIEW_ICON ) ).GetBitmapEx() );
1239 BitmapEx aListBmpEx = BitmapEx( Image( GAL_RES( RID_SVXIMG_GALLERY_VIEW_LIST ) ).GetBitmapEx() );
1241 if( maMiscOptions.AreCurrentSymbolsLarge() )
1243 const Size aLargeSize( 24, 24);
1245 aIconBmpEx.Scale( aLargeSize );
1246 aListBmpEx.Scale( aLargeSize );
1249 maViewBox.SetItemImage( TBX_ID_ICON, aIconBmpEx );
1250 maViewBox.SetItemImage( TBX_ID_LIST, aListBmpEx );
1251 maViewBox.SetSizePixel( maViewBox.CalcWindowSizePixel() );
1253 Resize();
1255 return 0L;
1258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */