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>
45 #include "svx/gallery.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>
63 #undef GALLERY_USE_CLIPBOARD
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
);
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() ),
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
;
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() );
131 OSL_FAIL( "SgaBGPopup::StateChanged(...): Wrong item type!" );
136 // ------------------------------------------------------------------------
138 void GalleryBackgroundPopup::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
;
163 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
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
),
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();
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
);
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
) )
236 EnableItem( MN_PASTECLIPBOARD
, sal_False
);
239 EnableItem( MN_COPYCLIPBOARD
, sal_False
);
240 EnableItem( MN_PASTECLIPBOARD
, sal_False
);
243 if( !maBackgroundPopup
.GetItemCount() || ( eObjKind
== SGA_OBJ_SVDRAW
) || ( eObjKind
== SGA_OBJ_SOUND
) )
244 pAddMenu
->EnableItem( MN_BACKGROUND
, sal_False
);
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
),
307 mpIconView ( new GalleryIconView( this, NULL
) ),
308 mpListView ( new GalleryListView( this, NULL
) ),
309 mpPreview ( new GalleryPreview( this, NULL
) ),
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
)
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 );
336 maViewBox
.SetSelectHdl( LINK( this, GalleryBrowser2
, SelectTbxHdl
) );
339 mpIconView
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS
));
340 mpListView
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS
));
345 mpIconView
->SetSelectHdl( aSelectHdl
);
346 mpListView
->SetSelectHdl( aSelectHdl
);
350 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GalleryBrowser2::meInitMode
) ? GalleryBrowser2::meInitMode
: GALLERYBROWSERMODE_ICON
);
352 if(maInfoBar
.GetText().Len() == 0)
353 mpIconView
->SetAccessibleRelationLabeledBy(mpIconView
);
355 mpIconView
->SetAccessibleRelationLabeledBy(&maInfoBar
);
356 mpIconView
->SetAccessibleRelationMemberOf(mpIconView
);
359 // -----------------------------------------------------------------------------
361 GalleryBrowser2::~GalleryBrowser2()
363 maMiscOptions
.RemoveListenerLink( LINK( this, GalleryBrowser2
, MiscHdl
) );
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
) )
398 Control::DataChanged( rDCEvt
);
401 // -----------------------------------------------------------------------------
403 void GalleryBrowser2::Resize()
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
);
427 case( GALLERYBROWSERMODE_ICON
): mpIconView
->Show(); break;
428 case( GALLERYBROWSERMODE_LIST
): mpListView
->Show(); break;
429 case( GALLERYBROWSERMODE_PREVIEW
): mpPreview
->Show(); 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 );
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
;
479 nRet
= DND_ACTION_COPY
;
485 // -----------------------------------------------------------------------------
487 sal_Int8
GalleryBrowser2::ExecuteDrop( DropTargetHelper
&, const ExecuteDropEvent
& rEvt
)
489 sal_Int8 nRet
= DND_ACTION_NONE
;
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
);
500 nRet
= mpCurTheme
->InsertTransferable( rEvt
.maDropEvent
.Transferable
, nInsertPos
);
506 // -----------------------------------------------------------------------------
508 void GalleryBrowser2::StartDrag( Window
*, const Point
* pDragPoint
)
513 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( pDragPoint
, aSelPos
);
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
)
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
)
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 );
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() );
581 switch( rKEvt
.GetKeyCode().GetCode() )
589 TogglePreview( pWindow
);
598 if( bAddLink
&& rKEvt
.GetKeyCode().IsShift() && rKEvt
.GetKeyCode().IsMod1() )
599 nExecuteId
= MN_ADD_LINK
;
609 nExecuteId
= MN_DELETE
;
616 nExecuteId
= MN_TITLE
;
626 ImplExecute( nExecuteId
);
634 // -----------------------------------------------------------------------------
636 void GalleryBrowser2::SelectTheme( const String
& rThemeName
)
638 delete mpIconView
, mpIconView
= NULL
;
639 delete mpListView
, mpListView
= NULL
;
640 delete mpPreview
, mpPreview
= NULL
;
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() )
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
);
673 mpIconView
->SetAccessibleRelationLabeledBy(&maInfoBar
);
674 mpIconView
->SetAccessibleRelationMemberOf(mpIconView
);
677 // -----------------------------------------------------------------------------
679 void GalleryBrowser2::SetMode( GalleryBrowserMode eMode
)
681 if( GetMode() != eMode
)
683 meLastMode
= GetMode();
687 case( GALLERYBROWSERMODE_ICON
):
692 mpPreview
->SetGraphic( Graphic() );
693 mpPreview
->PreviewMedia( INetURLObject() );
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
);
705 case( GALLERYBROWSERMODE_LIST
):
710 mpPreview
->SetGraphic( Graphic() );
711 mpPreview
->PreviewMedia( INetURLObject() );
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
);
723 case( GALLERYBROWSERMODE_PREVIEW
):
727 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
731 const sal_uIntPtr nPos
= nItemId
- 1;
737 mpCurTheme
->GetGraphic( nPos
, aGraphic
);
739 mpPreview
->SetGraphic( aGraphic
);
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
);
755 GalleryBrowser2::meInitMode
= meMode
= eMode
;
759 // -----------------------------------------------------------------------------
761 Window
* GalleryBrowser2::GetViewWindow() const
767 case( GALLERYBROWSERMODE_LIST
): pRet
= mpListView
; break;
768 case( GALLERYBROWSERMODE_PREVIEW
): pRet
= mpPreview
; break;
778 // -----------------------------------------------------------------------------
780 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel
)
785 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
789 sal_uIntPtr nNewItemId
= nItemId
;
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;
803 else if( nNewItemId
> mpCurTheme
->GetObjectCount() )
804 nNewItemId
= mpCurTheme
->GetObjectCount();
806 if( nNewItemId
!= nItemId
)
808 ImplSelectItemId( nNewItemId
);
811 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
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
)
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
) );
853 case( GALLERYBROWSERMODE_ICON
): mpIconView
->Show(); break;
854 case( GALLERYBROWSERMODE_LIST
): mpListView
->Show(); break;
855 case( GALLERYBROWSERMODE_PREVIEW
): mpPreview
->Show(); break;
864 // -----------------------------------------------------------------------------
866 void GalleryBrowser2::ImplUpdateInfoBar()
873 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
877 const sal_uIntPtr nPos
= nItemId
- 1;
879 aInfoText
= mpCurTheme
->GetName();
881 if( nPos
< mpCurTheme
->GetObjectCount() )
883 SgaObject
* pObj
= mpCurTheme
->AcquireObject( nPos
);
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 ) );
909 rSelPos
= GetPointerPosPixel();
911 rSelPos
= Point( aOutputSizePixel
.Width() >> 1, aOutputSizePixel
.Height() >> 1 );
913 else if( GALLERYBROWSERMODE_ICON
== GetMode() )
917 nRet
= mpIconView
->GetItemId( *pSelPos
);
918 rSelPos
= GetPointerPosPixel();
922 nRet
= mpIconView
->GetSelectItemId();
923 rSelPos
= mpIconView
->GetItemRect( (sal_uInt16
) nRet
).Center();
930 nRet
= mpListView
->GetRowAtYPosPixel( pSelPos
->Y() ) + 1;
931 rSelPos
= GetPointerPosPixel();
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() ) ) )
951 // -----------------------------------------------------------------------------
953 void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId
)
958 mpIconView
->SelectItem( (sal_uInt16
) nItemId
);
959 mpListView
->SelectRow( nItemId
- 1 );
963 // -----------------------------------------------------------------------------
965 void GalleryBrowser2::ImplExecute( sal_uInt16 nId
)
968 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
970 if( mpCurTheme
&& nItemId
)
972 mnCurActionPos
= nItemId
- 1;
979 sal_uInt32 nFormat
= 0;
981 mbCurActionIsLinkage
= ( MN_ADD_LINK
== nId
);
983 switch( mpCurTheme
->GetObjectKind( mnCurActionPos
) )
986 case( SGA_OBJ_ANIM
):
987 case( SGA_OBJ_INET
):
988 nFormat
= SGA_FORMAT_GRAPHIC
| SGA_FORMAT_STRING
;
991 case ( SGA_OBJ_SOUND
) :
992 nFormat
= SGA_FORMAT_SOUND
| SGA_FORMAT_STRING
;
995 case( SGA_OBJ_SVDRAW
):
996 nFormat
= SGA_FORMAT_GRAPHIC
| SGA_FORMAT_SVDRAW
| SGA_FORMAT_STRING
;
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 );
1010 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() ) ? GALLERYBROWSERMODE_PREVIEW
: meLastMode
);
1015 if( !mpCurTheme
->IsReadOnly() &&
1016 QueryBox(NULL
, WB_YES_NO
, GAL_RESSTR(RID_SVXSTR_GALLERY_DELETEOBJ
)).Execute() == RET_YES
)
1018 mpCurTheme
->RemoveObject( mnCurActionPos
);
1025 SgaObject
* pObj
= mpCurTheme
->AcquireObject( mnCurActionPos
);
1029 const String
aOldTitle( GetItemText( *mpCurTheme
, *pObj
, GALLERY_ITEM_TITLE
) );
1031 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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
);
1057 case( MN_COPYCLIPBOARD
):
1063 case( GALLERYBROWSERMODE_ICON
): pWindow
= (Window
*) mpIconView
; break;
1064 case( GALLERYBROWSERMODE_LIST
): pWindow
= (Window
*) mpListView
; break;
1065 case( GALLERYBROWSERMODE_PREVIEW
): pWindow
= (Window
*) mpPreview
; break;
1072 mpCurTheme
->CopyToClipboard( pWindow
, mnCurActionPos
);
1076 case( MN_PASTECLIPBOARD
):
1078 if( !mpCurTheme
->IsReadOnly() )
1080 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1081 mpCurTheme
->InsertTransferable( aDataHelper
.GetTransferable(), mnCurActionPos
);
1092 // -----------------------------------------------------------------------------
1094 String
GalleryBrowser2::GetItemText( const GalleryTheme
& rTheme
, const SgaObject
& rObj
, sal_uIntPtr nItemTextFlags
)
1099 if( rTheme
.IsImported() )
1101 aURL
= rTheme
.GetParent()->GetImportURL( rTheme
.GetName() );
1103 aURL
.removeSegment();
1104 aURL
.Append( rObj
.GetURL().GetName() );
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() );
1120 aTitle
= aURL
.getBase( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_UNAMBIGUOUS
);
1124 aTitle
= aURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
1125 aTitle
= aTitle
.GetToken( comphelper::string::getTokenCount(aTitle
, '/') - 1, '/' );
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
) )
1147 // -----------------------------------------------------------------------------
1149 INetURLObject
GalleryBrowser2::GetURL() const
1153 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1154 aURL
= mpCurTheme
->GetObjectURL( mnCurActionPos
);
1159 // -----------------------------------------------------------------------------
1161 String
GalleryBrowser2::GetFilterName() const
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
);
1183 // -----------------------------------------------------------------------------
1185 Graphic
GalleryBrowser2::GetGraphic() const
1189 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1190 mpCurTheme
->GetGraphic( mnCurActionPos
, aGraphic
);
1195 // -----------------------------------------------------------------------------
1197 sal_Bool
GalleryBrowser2::IsLinkage() const
1199 return mbCurActionIsLinkage
;
1202 // -----------------------------------------------------------------------------
1204 IMPL_LINK( GalleryBrowser2
, MenuSelectHdl
, Menu
*, pMenu
)
1207 ImplExecute( pMenu
->GetCurItemId() );
1212 // -----------------------------------------------------------------------------
1214 IMPL_LINK_NOARG(GalleryBrowser2
, SelectObjectHdl
)
1216 ImplUpdateInfoBar();
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
);
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() );
1258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */