1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <comphelper/string.hxx>
22 #include <sot/formats.hxx>
23 #include <vcl/msgbox.hxx>
24 #include <svl/urlbmk.hxx>
25 #include <svl/stritem.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/eitem.hxx>
28 #include <svtools/transfer.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <sfx2/sfxsids.hrc>
33 #include <vcl/graphicfilter.hxx>
34 #include <editeng/brushitem.hxx>
36 #include "svx/gallery.hxx"
38 #include "svx/gallery1.hxx"
39 #include "svx/galtheme.hxx"
40 #include "svx/galctrl.hxx"
41 #include "svx/galmisc.hxx"
42 #include "galbrws2.hxx"
43 #include "gallery.hrc"
44 #include <vcl/svapp.hxx>
45 #include <svx/fmmodel.hxx>
46 #include <svx/dialmgr.hxx>
47 #include <svx/svxdlg.hxx>
48 #include <svx/dialogs.hrc>
49 #include "GalleryControl.hxx"
51 #undef GALLERY_USE_CLIPBOARD
56 GalleryBrowserMode
GalleryBrowser2::meInitMode
= GALLERYBROWSERMODE_ICON
;
58 class GalleryBackgroundPopup
: public PopupMenu
, public SfxControllerItem
60 const GalleryTheme
* mpTheme
;
61 sal_uIntPtr mnObjectPos
;
63 virtual void Select();
64 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
68 GalleryBackgroundPopup( const GalleryTheme
* pTheme
, sal_uIntPtr nObjectPos
);
69 ~GalleryBackgroundPopup();
72 DBG_NAME(GalleryBackgroundPopup
)
74 GalleryBackgroundPopup::GalleryBackgroundPopup( const GalleryTheme
* pTheme
, sal_uIntPtr nObjectPos
) :
75 SfxControllerItem ( SID_GALLERY_BG_BRUSH
, SfxViewFrame::Current()->GetBindings() ),
77 mnObjectPos ( nObjectPos
)
79 DBG_CTOR(GalleryBackgroundPopup
,NULL
);
80 SfxViewFrame::Current()->GetBindings().Update( SID_GALLERY_BG_BRUSH
);
81 RemoveDisabledEntries();
84 GalleryBackgroundPopup::~GalleryBackgroundPopup()
86 DBG_DTOR(GalleryBackgroundPopup
,NULL
);
89 void GalleryBackgroundPopup::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pItem
)
91 if ( ( nSID
== SID_GALLERY_BG_BRUSH
) && pItem
&& ( eState
!= SFX_ITEM_DISABLED
) )
93 SfxStringListItem
* pStrLstItem
;
97 if ( ( pStrLstItem
= PTR_CAST( SfxStringListItem
, pItem
) ) != NULL
)
99 const std::vector
<String
> &aList
= pStrLstItem
->GetList();
101 for ( sal_uIntPtr i
= 0, nCount
= aList
.size(); i
< nCount
; i
++ )
102 InsertItem( (sal_uInt16
) i
+ 1, aList
[i
]);
105 SfxStringItem
* pStrItem
= PTR_CAST( SfxStringItem
, pItem
);
107 InsertItem( 1, pStrItem
->GetValue() );
110 OSL_FAIL( "SgaBGPopup::StateChanged(...): Wrong item type!" );
115 void GalleryBackgroundPopup::Select()
119 const INetURLObject
aURL( mpTheme
->GetObjectURL( mnObjectPos
) );
120 const SvxBrushItem
aBrushItem( aURL
.GetMainURL( INetURLObject::NO_DECODE
), String(), GPOS_TILED
, SID_GALLERY_BG_BRUSH
);
121 const SfxUInt16Item
aPosItem( SID_GALLERY_BG_POS
, GetCurItemId() - 1 );
122 const SfxStringItem
aPathItem( SID_FILE_NAME
, aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
124 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_GALLERY_BG_BRUSH
,
125 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
126 &aBrushItem
, &aPosItem
, &aPathItem
, 0L );
129 class GalleryThemePopup
: public PopupMenu
, public SfxControllerItem
131 GalleryBackgroundPopup maBackgroundPopup
;
132 const GalleryTheme
* mpTheme
;
133 sal_uIntPtr mnObjectPos
;
136 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
140 GalleryThemePopup( const GalleryTheme
* pTheme
, sal_uIntPtr nObjectPos
, sal_Bool bPreview
);
141 ~GalleryThemePopup();
144 DBG_NAME(GalleryThemePopup
)
146 GalleryThemePopup::GalleryThemePopup( const GalleryTheme
* pTheme
, sal_uIntPtr nObjectPos
, sal_Bool bPreview
) :
147 PopupMenu ( GAL_RES( RID_SVXMN_GALLERY2
) ),
148 SfxControllerItem ( SID_GALLERY_ENABLE_ADDCOPY
, SfxViewFrame::Current()->GetBindings() ),
149 maBackgroundPopup ( pTheme
, nObjectPos
),
151 mnObjectPos ( nObjectPos
),
152 mbPreview ( bPreview
)
154 DBG_CTOR(GalleryThemePopup
,NULL
);
156 const SgaObjKind eObjKind
= mpTheme
->GetObjectKind( mnObjectPos
);
157 PopupMenu
* pAddMenu
= GetPopupMenu( MN_ADDMENU
);
158 SfxBindings
& rBindings
= SfxViewFrame::Current()->GetBindings();
161 const_cast< GalleryTheme
* >( mpTheme
)->GetURL( mnObjectPos
, aURL
);
162 const sal_Bool bValidURL
= ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
);
164 pAddMenu
->EnableItem( MN_ADD
, bValidURL
&& SGA_OBJ_SOUND
!= eObjKind
);
165 pAddMenu
->EnableItem( MN_ADD_LINK
, bValidURL
&& SGA_OBJ_SVDRAW
!= eObjKind
);
167 EnableItem( MN_ADDMENU
, pAddMenu
->IsItemEnabled( MN_ADD
) || pAddMenu
->IsItemEnabled( MN_ADD_LINK
) );
168 EnableItem( MN_PREVIEW
, bValidURL
);
170 CheckItem( MN_PREVIEW
, mbPreview
);
172 if( mpTheme
->IsReadOnly() || !mpTheme
->GetObjectCount() )
174 EnableItem( MN_DELETE
, sal_False
);
175 EnableItem( MN_TITLE
, sal_False
);
177 if( mpTheme
->IsReadOnly() )
178 EnableItem( MN_PASTECLIPBOARD
, sal_False
);
180 if( !mpTheme
->GetObjectCount() )
181 EnableItem( MN_COPYCLIPBOARD
, sal_False
);
185 EnableItem( MN_DELETE
, !bPreview
);
186 EnableItem( MN_TITLE
, sal_True
);
187 EnableItem( MN_COPYCLIPBOARD
, sal_True
);
188 EnableItem( MN_PASTECLIPBOARD
, sal_True
);
191 #ifdef GALLERY_USE_CLIPBOARD
192 if( IsItemEnabled( MN_PASTECLIPBOARD
) )
194 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
195 sal_Bool bEnable
= sal_False
;
197 if( aDataHelper
.GetFormatCount() )
199 if( aDataHelper
.HasFormat( SOT_FORMATSTR_ID_DRAWING
) ||
200 aDataHelper
.HasFormat( SOT_FORMAT_FILE_LIST
) ||
201 aDataHelper
.HasFormat( FORMAT_FILE
) ||
202 aDataHelper
.HasFormat( SOT_FORMATSTR_ID_SVXB
) ||
203 aDataHelper
.HasFormat( FORMAT_GDIMETAFILE
) ||
204 aDataHelper
.HasFormat( FORMAT_BITMAP
) )
211 EnableItem( MN_PASTECLIPBOARD
, sal_False
);
214 EnableItem( MN_COPYCLIPBOARD
, sal_False
);
215 EnableItem( MN_PASTECLIPBOARD
, sal_False
);
218 if( !maBackgroundPopup
.GetItemCount() || ( eObjKind
== SGA_OBJ_SVDRAW
) || ( eObjKind
== SGA_OBJ_SOUND
) )
219 pAddMenu
->EnableItem( MN_BACKGROUND
, sal_False
);
222 pAddMenu
->EnableItem( MN_BACKGROUND
, sal_True
);
223 pAddMenu
->SetPopupMenu( MN_BACKGROUND
, &maBackgroundPopup
);
226 rBindings
.Update( SID_GALLERY_ENABLE_ADDCOPY
);
227 RemoveDisabledEntries();
230 GalleryThemePopup::~GalleryThemePopup()
232 DBG_DTOR(GalleryThemePopup
,NULL
);
235 void GalleryThemePopup::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pItem
)
237 if( ( nSID
== SID_GALLERY_ENABLE_ADDCOPY
) && pItem
&& ( eState
!= SFX_ITEM_DISABLED
) )
239 SfxBoolItem
* pBoolItem
= PTR_CAST( SfxBoolItem
, pItem
);
240 const SgaObjKind eObjKind
= mpTheme
->GetObjectKind( mnObjectPos
);
242 DBG_ASSERT( pBoolItem
|| pBoolItem
== 0, "SfxBoolItem erwartet!");
244 GetPopupMenu( MN_ADDMENU
)->EnableItem( MN_ADD
, pBoolItem
->GetValue() && ( eObjKind
!= SGA_OBJ_SOUND
) );
248 DBG_NAME(GalleryToolBox
)
250 GalleryToolBox::GalleryToolBox( GalleryBrowser2
* pParent
) :
251 ToolBox( pParent
, WB_TABSTOP
)
253 DBG_CTOR(GalleryToolBox
,NULL
);
256 GalleryToolBox::~GalleryToolBox()
258 DBG_DTOR(GalleryToolBox
,NULL
);
261 void GalleryToolBox::KeyInput( const KeyEvent
& rKEvt
)
263 if( !static_cast< GalleryBrowser2
* >( GetParent() )->KeyInput( rKEvt
, this ) )
264 ToolBox::KeyInput( rKEvt
);
267 DBG_NAME(GalleryBrowser2
)
269 GalleryBrowser2::GalleryBrowser2( Window
* pParent
, const ResId
& rResId
, Gallery
* pGallery
) :
270 Control ( pParent
, rResId
),
271 mpGallery ( pGallery
),
273 mpIconView ( new GalleryIconView( this, NULL
) ),
274 mpListView ( new GalleryListView( this, NULL
) ),
275 mpPreview ( new GalleryPreview( this, NULL
) ),
277 maSeparator ( this, WB_VERT
),
278 maInfoBar ( this, WB_LEFT
| WB_VCENTER
),
279 mnCurActionPos ( 0xffffffff ),
280 meMode ( GALLERYBROWSERMODE_NONE
),
281 meLastMode ( GALLERYBROWSERMODE_NONE
),
282 mbCurActionIsLinkage( sal_False
)
284 DBG_CTOR(GalleryBrowser2
,NULL
);
287 const Link
aSelectHdl( LINK( this, GalleryBrowser2
, SelectObjectHdl
) );
288 Font
aInfoFont( maInfoBar
.GetControlFont() );
290 maMiscOptions
.AddListenerLink( LINK( this, GalleryBrowser2
, MiscHdl
) );
292 maViewBox
.InsertItem( TBX_ID_ICON
, aDummyImage
);
293 maViewBox
.SetItemBits( TBX_ID_ICON
, TIB_RADIOCHECK
| TIB_AUTOCHECK
);
294 maViewBox
.SetHelpId( TBX_ID_ICON
, HID_GALLERY_ICONVIEW
);
295 maViewBox
.SetQuickHelpText( TBX_ID_ICON
, GAL_RESSTR(RID_SVXSTR_GALLERY_ICONVIEW
) );
297 maViewBox
.InsertItem( TBX_ID_LIST
, aDummyImage
);
298 maViewBox
.SetItemBits( TBX_ID_LIST
, TIB_RADIOCHECK
| TIB_AUTOCHECK
);
299 maViewBox
.SetHelpId( TBX_ID_LIST
, HID_GALLERY_LISTVIEW
);
300 maViewBox
.SetQuickHelpText( TBX_ID_LIST
, GAL_RESSTR(RID_SVXSTR_GALLERY_LISTVIEW
) );
303 maViewBox
.SetSelectHdl( LINK( this, GalleryBrowser2
, SelectTbxHdl
) );
306 mpIconView
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS
));
307 mpListView
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS
));
312 mpIconView
->SetSelectHdl( aSelectHdl
);
313 mpListView
->SetSelectHdl( aSelectHdl
);
317 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GalleryBrowser2::meInitMode
) ? GalleryBrowser2::meInitMode
: GALLERYBROWSERMODE_ICON
);
319 if(maInfoBar
.GetText().isEmpty())
320 mpIconView
->SetAccessibleRelationLabeledBy(mpIconView
);
322 mpIconView
->SetAccessibleRelationLabeledBy(&maInfoBar
);
323 mpIconView
->SetAccessibleRelationMemberOf(mpIconView
);
326 GalleryBrowser2::~GalleryBrowser2()
328 maMiscOptions
.RemoveListenerLink( LINK( this, GalleryBrowser2
, MiscHdl
) );
335 mpGallery
->ReleaseTheme( mpCurTheme
, *this );
337 DBG_DTOR(GalleryBrowser2
,NULL
);
340 void GalleryBrowser2::InitSettings()
342 Font
aInfoFont( maInfoBar
.GetControlFont() );
344 aInfoFont
.SetWeight( WEIGHT_BOLD
);
345 aInfoFont
.SetColor( GALLERY_FG_COLOR
);
346 maInfoBar
.SetControlFont( aInfoFont
);
348 maInfoBar
.SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
349 maInfoBar
.SetControlBackground( GALLERY_DLG_COLOR
);
351 maSeparator
.SetBackground( Wallpaper( GALLERY_BG_COLOR
) );
352 maSeparator
.SetControlBackground( GALLERY_BG_COLOR
);
353 maSeparator
.SetControlForeground( GALLERY_FG_COLOR
);
356 void GalleryBrowser2::DataChanged( const DataChangedEvent
& rDCEvt
)
358 if ( ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && ( rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
361 Control::DataChanged( rDCEvt
);
364 void GalleryBrowser2::Resize()
372 const Size
aOutSize( GetOutputSizePixel() );
373 const Size
aBoxSize( maViewBox
.GetOutputSizePixel() );
374 const long nOffset
= 2, nSepWidth
= 2;
375 const long nInfoBarX
= aBoxSize
.Width() + ( nOffset
* 3 ) + nSepWidth
;
376 const Point
aPt( 0, aBoxSize
.Height() + 3 );
377 const Size
aSz( aOutSize
.Width(), aOutSize
.Height() - aPt
.Y() );
379 maSeparator
.SetPosSizePixel( Point( aBoxSize
.Width() + nOffset
, 0 ), Size( nSepWidth
, aBoxSize
.Height() ) );
380 maInfoBar
.SetPosSizePixel( Point( nInfoBarX
, 0 ), Size( aOutSize
.Width() - nInfoBarX
, aBoxSize
.Height() ) );
382 mpIconView
->SetPosSizePixel( aPt
, aSz
);
383 mpListView
->SetPosSizePixel( aPt
, aSz
);
384 mpPreview
->SetPosSizePixel( aPt
, aSz
);
388 case( GALLERYBROWSERMODE_ICON
): mpIconView
->Show(); break;
389 case( GALLERYBROWSERMODE_LIST
): mpListView
->Show(); break;
390 case( GALLERYBROWSERMODE_PREVIEW
): mpPreview
->Show(); break;
397 void GalleryBrowser2::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
399 const GalleryHint
& rGalleryHint
= (const GalleryHint
&) rHint
;
401 switch( rGalleryHint
.GetType() )
403 case( GALLERY_HINT_THEME_UPDATEVIEW
):
405 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
406 SetMode( meLastMode
);
408 ImplUpdateViews( (sal_uInt16
) rGalleryHint
.GetData1() + 1 );
417 sal_Int8
GalleryBrowser2::AcceptDrop( DropTargetHelper
& rTarget
, const AcceptDropEvent
& )
419 sal_Int8 nRet
= DND_ACTION_NONE
;
421 if( mpCurTheme
&& !mpCurTheme
->IsReadOnly() )
423 if( !mpCurTheme
->IsDragging() )
425 if( rTarget
.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING
) ||
426 rTarget
.IsDropFormatSupported( SOT_FORMAT_FILE_LIST
) ||
427 rTarget
.IsDropFormatSupported( FORMAT_FILE
) ||
428 rTarget
.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB
) ||
429 rTarget
.IsDropFormatSupported( FORMAT_GDIMETAFILE
) ||
430 rTarget
.IsDropFormatSupported( FORMAT_BITMAP
) )
432 nRet
= DND_ACTION_COPY
;
436 nRet
= DND_ACTION_COPY
;
442 sal_Int8
GalleryBrowser2::ExecuteDrop( DropTargetHelper
&, const ExecuteDropEvent
& rEvt
)
444 sal_Int8 nRet
= DND_ACTION_NONE
;
449 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( &rEvt
.maPosPixel
, aSelPos
);
450 const sal_uIntPtr nInsertPos
= (nItemId
? (nItemId
- 1) : mpCurTheme
->GetObjectCount());
452 if( mpCurTheme
->IsDragging() )
453 mpCurTheme
->ChangeObjectPos( mpCurTheme
->GetDragPos(), nInsertPos
);
455 nRet
= mpCurTheme
->InsertTransferable( rEvt
.maDropEvent
.Transferable
, nInsertPos
);
461 void GalleryBrowser2::StartDrag( Window
*, const Point
* pDragPoint
)
466 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( pDragPoint
, aSelPos
);
469 mpCurTheme
->StartDrag( this, nItemId
- 1 );
473 void GalleryBrowser2::TogglePreview( Window
*, const Point
* )
475 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() ) ? GALLERYBROWSERMODE_PREVIEW
: meLastMode
);
476 GetViewWindow()->GrabFocus();
479 void GalleryBrowser2::ShowContextMenu( Window
*, const Point
* pContextPoint
)
482 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( pContextPoint
, aSelPos
);
484 if( mpCurTheme
&& nItemId
&& ( nItemId
<= mpCurTheme
->GetObjectCount() ) )
486 ImplSelectItemId( nItemId
);
488 SfxViewFrame
* pCurrentViewFrame
= SfxViewFrame::Current();
489 if ( pCurrentViewFrame
)
491 SfxBindings
& rBindings
= pCurrentViewFrame
->GetBindings();
492 rBindings
.ENTERREGISTRATIONS();
493 GalleryThemePopup
aMenu( mpCurTheme
, nItemId
- 1, GALLERYBROWSERMODE_PREVIEW
== GetMode() );
494 rBindings
.LEAVEREGISTRATIONS();
495 aMenu
.SetSelectHdl( LINK( this, GalleryBrowser2
, MenuSelectHdl
) );
496 aMenu
.Execute( this, aSelPos
);
501 sal_Bool
GalleryBrowser2::KeyInput( const KeyEvent
& rKEvt
, Window
* pWindow
)
504 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
505 GalleryBrowser
* pParentBrowser
= dynamic_cast<GalleryBrowser
*>(GetParent());
506 sal_Bool bRet
= sal_False
;
507 if (pParentBrowser
!= NULL
)
508 bRet
= pParentBrowser
->KeyInput( rKEvt
, pWindow
);
511 svx::sidebar::GalleryControl
* pParentControl
= dynamic_cast<svx::sidebar::GalleryControl
*>(GetParent());
512 if (pParentControl
!= NULL
)
513 bRet
= pParentControl
->GalleryKeyInput(rKEvt
, pWindow
);
516 if( !bRet
&& !maViewBox
.HasFocus() && nItemId
&& mpCurTheme
)
518 sal_uInt16 nExecuteId
= 0;
519 const SgaObjKind eObjKind
= mpCurTheme
->GetObjectKind( nItemId
- 1 );
522 const_cast< GalleryTheme
* >( mpCurTheme
)->GetURL( nItemId
- 1, aURL
);
524 const sal_Bool bValidURL
= ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
);
525 sal_Bool bPreview
= bValidURL
;
526 sal_Bool bAdd
= bValidURL
;
527 sal_Bool bAddLink
= ( bValidURL
&& SGA_OBJ_SVDRAW
!= eObjKind
);
528 sal_Bool bDelete
= sal_False
;
529 sal_Bool bTitle
= sal_False
;
531 if( !mpCurTheme
->IsReadOnly() && mpCurTheme
->GetObjectCount() )
533 bDelete
= ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() );
537 switch( rKEvt
.GetKeyCode().GetCode() )
545 TogglePreview( pWindow
);
554 if( bAddLink
&& rKEvt
.GetKeyCode().IsShift() && rKEvt
.GetKeyCode().IsMod1() )
555 nExecuteId
= MN_ADD_LINK
;
565 nExecuteId
= MN_DELETE
;
572 nExecuteId
= MN_TITLE
;
582 ImplExecute( nExecuteId
);
590 void GalleryBrowser2::SelectTheme( const String
& rThemeName
)
592 delete mpIconView
, mpIconView
= NULL
;
593 delete mpListView
, mpListView
= NULL
;
594 delete mpPreview
, mpPreview
= NULL
;
597 mpGallery
->ReleaseTheme( mpCurTheme
, *this );
599 mpCurTheme
= mpGallery
->AcquireTheme( rThemeName
, *this );
601 mpIconView
= new GalleryIconView( this, mpCurTheme
);
602 mpListView
= new GalleryListView( this, mpCurTheme
);
603 mpPreview
= new GalleryPreview( this, mpCurTheme
);
605 mpIconView
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS
));
606 mpListView
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS
));
607 mpPreview
->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_PREVIEW
));
609 const Link
aSelectHdl( LINK( this, GalleryBrowser2
, SelectObjectHdl
) );
611 mpIconView
->SetSelectHdl( aSelectHdl
);
612 mpListView
->SetSelectHdl( aSelectHdl
);
614 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
618 ImplUpdateViews( 1 );
620 maViewBox
.EnableItem( TBX_ID_ICON
, sal_True
);
621 maViewBox
.EnableItem( TBX_ID_LIST
, sal_True
);
622 maViewBox
.CheckItem( ( GALLERYBROWSERMODE_ICON
== GetMode() ) ? TBX_ID_ICON
: TBX_ID_LIST
, sal_True
);
624 if(maInfoBar
.GetText().isEmpty())
625 mpIconView
->SetAccessibleRelationLabeledBy(mpIconView
);
627 mpIconView
->SetAccessibleRelationLabeledBy(&maInfoBar
);
628 mpIconView
->SetAccessibleRelationMemberOf(mpIconView
);
631 void GalleryBrowser2::SetMode( GalleryBrowserMode eMode
)
633 if( GetMode() != eMode
)
635 meLastMode
= GetMode();
639 case( GALLERYBROWSERMODE_ICON
):
644 mpPreview
->SetGraphic( Graphic() );
645 mpPreview
->PreviewMedia( INetURLObject() );
649 maViewBox
.EnableItem( TBX_ID_ICON
, sal_True
);
650 maViewBox
.EnableItem( TBX_ID_LIST
, sal_True
);
652 maViewBox
.CheckItem( TBX_ID_ICON
, sal_True
);
653 maViewBox
.CheckItem( TBX_ID_LIST
, sal_False
);
657 case( GALLERYBROWSERMODE_LIST
):
662 mpPreview
->SetGraphic( Graphic() );
663 mpPreview
->PreviewMedia( INetURLObject() );
667 maViewBox
.EnableItem( TBX_ID_ICON
, sal_True
);
668 maViewBox
.EnableItem( TBX_ID_LIST
, sal_True
);
670 maViewBox
.CheckItem( TBX_ID_ICON
, sal_False
);
671 maViewBox
.CheckItem( TBX_ID_LIST
, sal_True
);
675 case( GALLERYBROWSERMODE_PREVIEW
):
679 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
683 const sal_uIntPtr nPos
= nItemId
- 1;
689 mpCurTheme
->GetGraphic( nPos
, aGraphic
);
691 mpPreview
->SetGraphic( aGraphic
);
694 if( mpCurTheme
&& mpCurTheme
->GetObjectKind( nPos
) == SGA_OBJ_SOUND
)
695 mpPreview
->PreviewMedia( mpCurTheme
->GetObjectURL( nPos
) );
697 maViewBox
.EnableItem( TBX_ID_ICON
, sal_False
);
698 maViewBox
.EnableItem( TBX_ID_LIST
, sal_False
);
707 GalleryBrowser2::meInitMode
= meMode
= eMode
;
711 Window
* GalleryBrowser2::GetViewWindow() const
717 case( GALLERYBROWSERMODE_LIST
): pRet
= mpListView
; break;
718 case( GALLERYBROWSERMODE_PREVIEW
): pRet
= mpPreview
; break;
728 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel
)
733 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
737 sal_uIntPtr nNewItemId
= nItemId
;
741 case( GALLERYBROWSERTRAVEL_FIRST
): nNewItemId
= 1; break;
742 case( GALLERYBROWSERTRAVEL_LAST
): nNewItemId
= mpCurTheme
->GetObjectCount(); break;
743 case( GALLERYBROWSERTRAVEL_PREVIOUS
): nNewItemId
--; break;
744 case( GALLERYBROWSERTRAVEL_NEXT
): nNewItemId
++; break;
751 else if( nNewItemId
> mpCurTheme
->GetObjectCount() )
752 nNewItemId
= mpCurTheme
->GetObjectCount();
754 if( nNewItemId
!= nItemId
)
756 ImplSelectItemId( nNewItemId
);
759 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
762 const sal_uIntPtr nPos
= nNewItemId
- 1;
764 mpCurTheme
->GetGraphic( nPos
, aGraphic
);
765 mpPreview
->SetGraphic( aGraphic
);
767 if( SGA_OBJ_SOUND
== mpCurTheme
->GetObjectKind( nPos
) )
768 mpPreview
->PreviewMedia( mpCurTheme
->GetObjectURL( nPos
) );
770 mpPreview
->Invalidate();
777 void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId
)
788 for( sal_uIntPtr i
= 0, nCount
= mpCurTheme
->GetObjectCount(); i
< nCount
; )
790 mpListView
->RowInserted( i
++ );
791 mpIconView
->InsertItem( (sal_uInt16
) i
);
794 ImplSelectItemId( ( ( nSelectionId
> mpCurTheme
->GetObjectCount() ) ? mpCurTheme
->GetObjectCount() : nSelectionId
) );
799 case( GALLERYBROWSERMODE_ICON
): mpIconView
->Show(); break;
800 case( GALLERYBROWSERMODE_LIST
): mpListView
->Show(); break;
801 case( GALLERYBROWSERMODE_PREVIEW
): mpPreview
->Show(); break;
810 void GalleryBrowser2::ImplUpdateInfoBar()
817 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
821 const sal_uIntPtr nPos
= nItemId
- 1;
823 aInfoText
= mpCurTheme
->GetName();
825 if( nPos
< mpCurTheme
->GetObjectCount() )
827 SgaObject
* pObj
= mpCurTheme
->AcquireObject( nPos
);
831 aInfoText
= GetItemText( *mpCurTheme
, *pObj
, GALLERY_ITEM_THEMENAME
| GALLERY_ITEM_TITLE
| GALLERY_ITEM_PATH
);
832 mpCurTheme
->ReleaseObject( pObj
);
838 maInfoBar
.SetText( aInfoText
);
841 sal_uIntPtr
GalleryBrowser2::ImplGetSelectedItemId( const Point
* pSelPos
, Point
& rSelPos
)
843 const Size
aOutputSizePixel( GetOutputSizePixel() );
844 sal_uIntPtr nRet
= 0;
846 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
848 nRet
= ( ( GALLERYBROWSERMODE_ICON
== meLastMode
) ? mpIconView
->GetSelectItemId() : ( mpListView
->FirstSelectedRow() + 1 ) );
851 rSelPos
= GetPointerPosPixel();
853 rSelPos
= Point( aOutputSizePixel
.Width() >> 1, aOutputSizePixel
.Height() >> 1 );
855 else if( GALLERYBROWSERMODE_ICON
== GetMode() )
859 nRet
= mpIconView
->GetItemId( *pSelPos
);
860 rSelPos
= GetPointerPosPixel();
864 nRet
= mpIconView
->GetSelectItemId();
865 rSelPos
= mpIconView
->GetItemRect( (sal_uInt16
) nRet
).Center();
872 nRet
= mpListView
->GetRowAtYPosPixel( pSelPos
->Y() ) + 1;
873 rSelPos
= GetPointerPosPixel();
877 nRet
= mpListView
->FirstSelectedRow() + 1;
878 rSelPos
= mpListView
->GetFieldRectPixel( (sal_uInt16
) nRet
, 1 ).Center();
882 rSelPos
.X() = std::max( std::min( rSelPos
.X(), aOutputSizePixel
.Width() - 1L ), 0L );
883 rSelPos
.Y() = std::max( std::min( rSelPos
.Y(), aOutputSizePixel
.Height() - 1L ), 0L );
885 if( nRet
&& ( !mpCurTheme
|| ( nRet
> mpCurTheme
->GetObjectCount() ) ) )
893 void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId
)
898 mpIconView
->SelectItem( (sal_uInt16
) nItemId
);
899 mpListView
->SelectRow( nItemId
- 1 );
903 void GalleryBrowser2::ImplExecute( sal_uInt16 nId
)
906 const sal_uIntPtr nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
908 if( mpCurTheme
&& nItemId
)
910 mnCurActionPos
= nItemId
- 1;
917 sal_uInt32 nFormat
= 0;
919 mbCurActionIsLinkage
= ( MN_ADD_LINK
== nId
);
921 switch( mpCurTheme
->GetObjectKind( mnCurActionPos
) )
924 case( SGA_OBJ_ANIM
):
925 case( SGA_OBJ_INET
):
926 nFormat
= SGA_FORMAT_GRAPHIC
| SGA_FORMAT_STRING
;
929 case ( SGA_OBJ_SOUND
) :
930 nFormat
= SGA_FORMAT_SOUND
| SGA_FORMAT_STRING
;
933 case( SGA_OBJ_SVDRAW
):
934 nFormat
= SGA_FORMAT_GRAPHIC
| SGA_FORMAT_SVDRAW
| SGA_FORMAT_STRING
;
941 const SfxUInt32Item
aItem( SID_GALLERY_FORMATS
, nFormat
);
942 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute(
943 SID_GALLERY_FORMATS
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aItem
, 0L );
948 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() ) ? GALLERYBROWSERMODE_PREVIEW
: meLastMode
);
953 if( !mpCurTheme
->IsReadOnly() &&
954 QueryBox(NULL
, WB_YES_NO
, GAL_RESSTR(RID_SVXSTR_GALLERY_DELETEOBJ
)).Execute() == RET_YES
)
956 mpCurTheme
->RemoveObject( mnCurActionPos
);
963 SgaObject
* pObj
= mpCurTheme
->AcquireObject( mnCurActionPos
);
967 const String
aOldTitle( GetItemText( *mpCurTheme
, *pObj
, GALLERY_ITEM_TITLE
) );
969 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
972 AbstractTitleDialog
* aDlg
= pFact
->CreateTitleDialog( this, aOldTitle
);
973 DBG_ASSERT(aDlg
, "Dialogdiet fail!");
974 if( aDlg
->Execute() == RET_OK
)
976 String
aNewTitle( aDlg
->GetTitle() );
978 if( ( !aNewTitle
.Len() && pObj
->GetTitle().Len() ) || ( aNewTitle
!= aOldTitle
) )
980 if( !aNewTitle
.Len() )
981 aNewTitle
= String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) );
983 pObj
->SetTitle( aNewTitle
);
984 mpCurTheme
->InsertObject( *pObj
);
988 mpCurTheme
->ReleaseObject( pObj
);
995 case( MN_COPYCLIPBOARD
):
1001 case( GALLERYBROWSERMODE_ICON
): pWindow
= (Window
*) mpIconView
; break;
1002 case( GALLERYBROWSERMODE_LIST
): pWindow
= (Window
*) mpListView
; break;
1003 case( GALLERYBROWSERMODE_PREVIEW
): pWindow
= (Window
*) mpPreview
; break;
1010 mpCurTheme
->CopyToClipboard( pWindow
, mnCurActionPos
);
1014 case( MN_PASTECLIPBOARD
):
1016 if( !mpCurTheme
->IsReadOnly() )
1018 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1019 mpCurTheme
->InsertTransferable( aDataHelper
.GetTransferable(), mnCurActionPos
);
1030 String
GalleryBrowser2::GetItemText( const GalleryTheme
& rTheme
, const SgaObject
& rObj
, sal_uIntPtr nItemTextFlags
)
1034 INetURLObject
aURL(rObj
.GetURL());
1036 if( nItemTextFlags
& GALLERY_ITEM_THEMENAME
)
1038 aRet
+= rTheme
.GetName();
1039 aRet
+= String( RTL_CONSTASCII_USTRINGPARAM( " - " ) );
1042 if( nItemTextFlags
& GALLERY_ITEM_TITLE
)
1044 String
aTitle( rObj
.GetTitle() );
1047 aTitle
= aURL
.getBase( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_UNAMBIGUOUS
);
1051 aTitle
= aURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
1052 aTitle
= aTitle
.GetToken( comphelper::string::getTokenCount(aTitle
, '/') - 1, '/' );
1058 if( nItemTextFlags
& GALLERY_ITEM_PATH
)
1060 const String
aPath( aURL
.getFSysPath( INetURLObject::FSYS_DETECT
) );
1062 if( aPath
.Len() && ( nItemTextFlags
& GALLERY_ITEM_TITLE
) )
1063 aRet
+= String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
1065 aRet
+= String(aURL
.getFSysPath( INetURLObject::FSYS_DETECT
));
1067 if( aPath
.Len() && ( nItemTextFlags
& GALLERY_ITEM_TITLE
) )
1074 INetURLObject
GalleryBrowser2::GetURL() const
1078 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1079 aURL
= mpCurTheme
->GetObjectURL( mnCurActionPos
);
1084 String
GalleryBrowser2::GetFilterName() const
1088 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1090 const SgaObjKind eObjKind
= mpCurTheme
->GetObjectKind( mnCurActionPos
);
1092 if( ( SGA_OBJ_BMP
== eObjKind
) || ( SGA_OBJ_ANIM
== eObjKind
) )
1094 GraphicFilter
& rFilter
= GraphicFilter::GetGraphicFilter();
1095 INetURLObject aURL
; mpCurTheme
->GetURL( mnCurActionPos
, aURL
);
1096 sal_uInt16 nFilter
= rFilter
.GetImportFormatNumberForShortName( aURL
.GetExtension() );
1098 if( GRFILTER_FORMAT_DONTKNOW
!= nFilter
)
1099 aFilterName
= rFilter
.GetImportFormatName( nFilter
);
1106 Graphic
GalleryBrowser2::GetGraphic() const
1110 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1111 mpCurTheme
->GetGraphic( mnCurActionPos
, aGraphic
);
1116 sal_Bool
GalleryBrowser2::IsLinkage() const
1118 return mbCurActionIsLinkage
;
1121 IMPL_LINK( GalleryBrowser2
, MenuSelectHdl
, Menu
*, pMenu
)
1124 ImplExecute( pMenu
->GetCurItemId() );
1129 IMPL_LINK_NOARG(GalleryBrowser2
, SelectObjectHdl
)
1131 ImplUpdateInfoBar();
1135 IMPL_LINK( GalleryBrowser2
, SelectTbxHdl
, ToolBox
*, pBox
)
1137 if( pBox
->GetCurItemId() == TBX_ID_ICON
)
1138 SetMode( GALLERYBROWSERMODE_ICON
);
1139 else if( pBox
->GetCurItemId() == TBX_ID_LIST
)
1140 SetMode( GALLERYBROWSERMODE_LIST
);
1145 IMPL_LINK_NOARG(GalleryBrowser2
, MiscHdl
)
1147 maViewBox
.SetOutStyle( maMiscOptions
.GetToolboxStyle() );
1149 BitmapEx aIconBmpEx
= BitmapEx( Image( GAL_RES( RID_SVXIMG_GALLERY_VIEW_ICON
) ).GetBitmapEx() );
1150 BitmapEx aListBmpEx
= BitmapEx( Image( GAL_RES( RID_SVXIMG_GALLERY_VIEW_LIST
) ).GetBitmapEx() );
1152 if( maMiscOptions
.AreCurrentSymbolsLarge() )
1154 const Size
aLargeSize( 24, 24);
1156 aIconBmpEx
.Scale( aLargeSize
);
1157 aListBmpEx
.Scale( aLargeSize
);
1160 maViewBox
.SetItemImage( TBX_ID_ICON
, aIconBmpEx
);
1161 maViewBox
.SetItemImage( TBX_ID_LIST
, aListBmpEx
);
1162 maViewBox
.SetSizePixel( maViewBox
.CalcWindowSizePixel() );
1169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */