1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: galbrws2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include <sot/formats.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <svtools/valueset.hxx>
38 #include <svtools/urlbmk.hxx>
39 #include <svtools/stritem.hxx>
40 #include <svtools/intitem.hxx>
41 #include <svtools/eitem.hxx>
42 #include <svtools/transfer.hxx>
43 #include <sfx2/bindings.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/viewfrm.hxx>
46 #include <sfx2/sfxsids.hrc>
48 #include <svx/brshitem.hxx>
50 #include "gallery1.hxx"
51 #include "galtheme.hxx"
52 #include "galmisc.hxx"
54 #include "galbrws2.hxx"
55 #include <vcl/svapp.hxx>
56 #include <svx/fmmodel.hxx>
57 #include <svx/svxdlg.hxx> //CHINA001
58 //CHINA001 #include <svx/dialogs.hrc> //CHINA001
64 #undef GALLERY_USE_CLIPBOARD
73 GalleryBrowserMode
GalleryBrowser2::meInitMode
= GALLERYBROWSERMODE_ICON
;
75 // --------------------------
76 // - GalleryBackgroundPopup -
77 // --------------------------
79 class GalleryBackgroundPopup
: public PopupMenu
, public SfxControllerItem
81 const GalleryTheme
* mpTheme
;
84 virtual void Select();
85 virtual void StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
89 GalleryBackgroundPopup( const GalleryTheme
* pTheme
, ULONG nObjectPos
);
90 ~GalleryBackgroundPopup();
93 // ------------------------------------------------------------------------
95 GalleryBackgroundPopup::GalleryBackgroundPopup( const GalleryTheme
* pTheme
, ULONG nObjectPos
) :
96 SfxControllerItem ( SID_GALLERY_BG_BRUSH
, SfxViewFrame::Current()->GetBindings() ),
98 mnObjectPos ( nObjectPos
)
100 SfxViewFrame::Current()->GetBindings().Update( SID_GALLERY_BG_BRUSH
);
101 RemoveDisabledEntries();
104 // ------------------------------------------------------------------------
106 GalleryBackgroundPopup::~GalleryBackgroundPopup()
110 // ------------------------------------------------------------------------
112 void GalleryBackgroundPopup::StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pItem
)
114 if ( ( nSID
== SID_GALLERY_BG_BRUSH
) && pItem
&& ( eState
!= SFX_ITEM_DISABLED
) )
116 SfxStringListItem
* pStrLstItem
;
117 SfxStringItem
* pStrItem
;
121 if( ( pStrLstItem
= PTR_CAST( SfxStringListItem
, pItem
) ) != NULL
)
123 List
* pList
= pStrLstItem
->GetList();
126 for ( ULONG i
= 0, nCount
= pList
->Count(); i
< nCount
; i
++ )
127 InsertItem( (USHORT
) i
+ 1, *(String
*) pList
->GetObject( i
) );
129 else if( ( pStrItem
= PTR_CAST( SfxStringItem
, pItem
) ) != NULL
)
130 InsertItem( 1, pStrItem
->GetValue() );
133 DBG_ERROR( "SgaBGPopup::StateChanged(...): Wrong item type!" );
138 // ------------------------------------------------------------------------
140 void GalleryBackgroundPopup::Select()
144 const INetURLObject
aURL( mpTheme
->GetObjectURL( mnObjectPos
) );
145 const SvxBrushItem
aBrushItem( aURL
.GetMainURL( INetURLObject::NO_DECODE
), String(), GPOS_TILED
, SID_GALLERY_BG_BRUSH
);
146 const SfxUInt16Item
aPosItem( SID_GALLERY_BG_POS
, GetCurItemId() - 1 );
147 const SfxStringItem
aPathItem( SID_FILE_NAME
, aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
149 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_GALLERY_BG_BRUSH
,
150 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
151 &aBrushItem
, &aPosItem
, &aPathItem
, 0L );
154 // ---------------------
155 // - GalleryThemePopup -
156 // ---------------------
158 class GalleryThemePopup
: public PopupMenu
, public SfxControllerItem
160 GalleryBackgroundPopup maBackgroundPopup
;
161 const GalleryTheme
* mpTheme
;
165 virtual void StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
169 GalleryThemePopup( const GalleryTheme
* pTheme
, ULONG nObjectPos
, BOOL bPreview
);
170 ~GalleryThemePopup();
173 // ------------------------------------------------------------------------
175 GalleryThemePopup::GalleryThemePopup( const GalleryTheme
* pTheme
, ULONG nObjectPos
, BOOL bPreview
) :
176 PopupMenu ( GAL_RESID( RID_SVXMN_GALLERY2
) ),
177 SfxControllerItem ( SID_GALLERY_ENABLE_ADDCOPY
, SfxViewFrame::Current()->GetBindings() ),
178 maBackgroundPopup ( pTheme
, nObjectPos
),
180 mnObjectPos ( nObjectPos
),
181 mbPreview ( bPreview
)
183 const SgaObjKind eObjKind
= mpTheme
->GetObjectKind( mnObjectPos
);
184 PopupMenu
* pAddMenu
= GetPopupMenu( MN_ADDMENU
);
185 SfxBindings
& rBindings
= SfxViewFrame::Current()->GetBindings();
188 const_cast< GalleryTheme
* >( mpTheme
)->GetURL( mnObjectPos
, aURL
);
189 const BOOL bValidURL
= ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
);
191 pAddMenu
->EnableItem( MN_ADD
, bValidURL
&& SGA_OBJ_SOUND
!= eObjKind
);
192 pAddMenu
->EnableItem( MN_ADD_LINK
, bValidURL
&& SGA_OBJ_SVDRAW
!= eObjKind
);
194 EnableItem( MN_ADDMENU
, pAddMenu
->IsItemEnabled( MN_ADD
) || pAddMenu
->IsItemEnabled( MN_ADD_LINK
) );
195 EnableItem( MN_PREVIEW
, bValidURL
);
197 CheckItem( MN_PREVIEW
, mbPreview
);
199 if( mpTheme
->IsReadOnly() || !mpTheme
->GetObjectCount() )
201 EnableItem( MN_DELETE
, FALSE
);
202 EnableItem( MN_TITLE
, FALSE
);
204 if( mpTheme
->IsReadOnly() )
205 EnableItem( MN_PASTECLIPBOARD
, FALSE
);
207 if( !mpTheme
->GetObjectCount() )
208 EnableItem( MN_COPYCLIPBOARD
, FALSE
);
212 EnableItem( MN_DELETE
, !bPreview
);
213 EnableItem( MN_TITLE
, TRUE
);
214 EnableItem( MN_COPYCLIPBOARD
, TRUE
);
215 EnableItem( MN_PASTECLIPBOARD
, TRUE
);
218 #ifdef GALLERY_USE_CLIPBOARD
219 if( IsItemEnabled( MN_PASTECLIPBOARD
) )
221 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
222 BOOL bEnable
= FALSE
;
224 if( aDataHelper
.GetFormatCount() )
226 if( aDataHelper
.HasFormat( SOT_FORMATSTR_ID_DRAWING
) ||
227 aDataHelper
.HasFormat( SOT_FORMAT_FILE_LIST
) ||
228 aDataHelper
.HasFormat( FORMAT_FILE
) ||
229 aDataHelper
.HasFormat( SOT_FORMATSTR_ID_SVXB
) ||
230 aDataHelper
.HasFormat( FORMAT_GDIMETAFILE
) ||
231 aDataHelper
.HasFormat( FORMAT_BITMAP
) )
238 EnableItem( MN_PASTECLIPBOARD
, FALSE
);
241 EnableItem( MN_COPYCLIPBOARD
, FALSE
);
242 EnableItem( MN_PASTECLIPBOARD
, FALSE
);
245 if( !maBackgroundPopup
.GetItemCount() || ( eObjKind
== SGA_OBJ_SVDRAW
) || ( eObjKind
== SGA_OBJ_SOUND
) )
246 pAddMenu
->EnableItem( MN_BACKGROUND
, FALSE
);
249 pAddMenu
->EnableItem( MN_BACKGROUND
, TRUE
);
250 pAddMenu
->SetPopupMenu( MN_BACKGROUND
, &maBackgroundPopup
);
253 rBindings
.Update( SID_GALLERY_ENABLE_ADDCOPY
);
254 RemoveDisabledEntries();
257 // ------------------------------------------------------------------------
259 GalleryThemePopup::~GalleryThemePopup()
263 // ------------------------------------------------------------------------
265 void GalleryThemePopup::StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pItem
)
267 if( ( nSID
== SID_GALLERY_ENABLE_ADDCOPY
) && pItem
&& ( eState
!= SFX_ITEM_DISABLED
) )
269 SfxBoolItem
* pBoolItem
= PTR_CAST( SfxBoolItem
, pItem
);
270 const SgaObjKind eObjKind
= mpTheme
->GetObjectKind( mnObjectPos
);
272 DBG_ASSERT( pBoolItem
|| pBoolItem
== 0, "SfxBoolItem erwartet!");
274 GetPopupMenu( MN_ADDMENU
)->EnableItem( MN_ADD
, pBoolItem
->GetValue() && ( eObjKind
!= SGA_OBJ_SOUND
) );
278 // ------------------
279 // - GalleryToolBox -
280 // ------------------
282 GalleryToolBox::GalleryToolBox( GalleryBrowser2
* pParent
) :
283 ToolBox( pParent
, WB_TABSTOP
)
287 // ------------------------------------------------------------------------
289 GalleryToolBox::~GalleryToolBox()
293 // ------------------------------------------------------------------------
295 void GalleryToolBox::KeyInput( const KeyEvent
& rKEvt
)
297 if( !static_cast< GalleryBrowser2
* >( GetParent() )->KeyInput( rKEvt
, this ) )
298 ToolBox::KeyInput( rKEvt
);
301 // -------------------
302 // - GalleryBrowser2 -
303 // -------------------
305 GalleryBrowser2::GalleryBrowser2( GalleryBrowser
* pParent
, const ResId
& rResId
, Gallery
* pGallery
) :
306 Control ( pParent
, rResId
),
307 mpGallery ( pGallery
),
309 mpIconView ( new GalleryIconView( this, NULL
) ),
310 mpListView ( new GalleryListView( this, NULL
) ),
311 mpPreview ( new GalleryPreview( this, NULL
) ),
313 maSeparator ( this, WB_VERT
),
314 maInfoBar ( this, WB_LEFT
| WB_VCENTER
),
315 mnCurActionPos ( 0xffffffff ),
316 meMode ( GALLERYBROWSERMODE_NONE
),
317 meLastMode ( GALLERYBROWSERMODE_NONE
),
318 mbCurActionIsLinkage( FALSE
)
321 const Link
aSelectHdl( LINK( this, GalleryBrowser2
, SelectObjectHdl
) );
322 Font
aInfoFont( maInfoBar
.GetControlFont() );
324 maMiscOptions
.AddListener( LINK( this, GalleryBrowser2
, MiscHdl
) );
326 maViewBox
.InsertItem( TBX_ID_ICON
, aDummyImage
);
327 maViewBox
.SetItemBits( TBX_ID_ICON
, TIB_RADIOCHECK
| TIB_AUTOCHECK
);
328 maViewBox
.SetHelpId( TBX_ID_ICON
, HID_GALLERY_ICONVIEW
);
329 maViewBox
.SetQuickHelpText( TBX_ID_ICON
, String( GAL_RESID( RID_SVXSTR_GALLERY_ICONVIEW
) ) );
331 maViewBox
.InsertItem( TBX_ID_LIST
, aDummyImage
);
332 maViewBox
.SetItemBits( TBX_ID_LIST
, TIB_RADIOCHECK
| TIB_AUTOCHECK
);
333 maViewBox
.SetHelpId( TBX_ID_LIST
, HID_GALLERY_LISTVIEW
);
334 maViewBox
.SetQuickHelpText( TBX_ID_LIST
, String( GAL_RESID( RID_SVXSTR_GALLERY_LISTVIEW
) ) );
336 maViewBox
.SetBorder( 0, 1 );
338 maViewBox
.SetSelectHdl( LINK( this, GalleryBrowser2
, SelectTbxHdl
) );
344 mpIconView
->SetSelectHdl( aSelectHdl
);
345 mpListView
->SetSelectHdl( aSelectHdl
);
349 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GalleryBrowser2::meInitMode
) ? GalleryBrowser2::meInitMode
: GALLERYBROWSERMODE_ICON
);
352 // -----------------------------------------------------------------------------
354 GalleryBrowser2::~GalleryBrowser2()
356 maMiscOptions
.RemoveListener( LINK( this, GalleryBrowser2
, MiscHdl
) );
363 mpGallery
->ReleaseTheme( mpCurTheme
, *this );
366 // -----------------------------------------------------------------------------
368 void GalleryBrowser2::InitSettings()
370 Font
aInfoFont( maInfoBar
.GetControlFont() );
372 aInfoFont
.SetWeight( WEIGHT_BOLD
);
373 aInfoFont
.SetColor( GALLERY_FG_COLOR
);
374 maInfoBar
.SetControlFont( aInfoFont
);
376 maInfoBar
.SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
377 maInfoBar
.SetControlBackground( GALLERY_DLG_COLOR
);
379 maSeparator
.SetBackground( Wallpaper( GALLERY_BG_COLOR
) );
380 maSeparator
.SetControlBackground( GALLERY_BG_COLOR
);
381 maSeparator
.SetControlForeground( GALLERY_FG_COLOR
);
384 // -----------------------------------------------------------------------------
386 void GalleryBrowser2::DataChanged( const DataChangedEvent
& rDCEvt
)
388 if ( ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && ( rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
391 Control::DataChanged( rDCEvt
);
394 // -----------------------------------------------------------------------------
396 void GalleryBrowser2::Resize()
404 const Size
aOutSize( GetOutputSizePixel() );
405 const Size
aBoxSize( maViewBox
.GetOutputSizePixel() );
406 const long nOffset
= 2, nSepWidth
= 2;
407 const long nInfoBarX
= aBoxSize
.Width() + ( nOffset
* 3 ) + nSepWidth
;
408 const Point
aPt( 0, aBoxSize
.Height() + 3 );
409 const Size
aSz( aOutSize
.Width(), aOutSize
.Height() - aPt
.Y() );
411 maSeparator
.SetPosSizePixel( Point( aBoxSize
.Width() + nOffset
, 0 ), Size( nSepWidth
, aBoxSize
.Height() ) );
412 maInfoBar
.SetPosSizePixel( Point( nInfoBarX
, 0 ), Size( aOutSize
.Width() - nInfoBarX
, aBoxSize
.Height() ) );
414 mpIconView
->SetPosSizePixel( aPt
, aSz
);
415 mpListView
->SetPosSizePixel( aPt
, aSz
);
416 mpPreview
->SetPosSizePixel( aPt
, aSz
);
420 case( GALLERYBROWSERMODE_ICON
): mpIconView
->Show(); break;
421 case( GALLERYBROWSERMODE_LIST
): mpListView
->Show(); break;
422 case( GALLERYBROWSERMODE_PREVIEW
): mpPreview
->Show(); break;
429 // -----------------------------------------------------------------------------
431 void GalleryBrowser2::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
433 const GalleryHint
& rGalleryHint
= (const GalleryHint
&) rHint
;
435 switch( rGalleryHint
.GetType() )
437 case( GALLERY_HINT_THEME_UPDATEVIEW
):
439 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
440 SetMode( meLastMode
);
442 ImplUpdateViews( (USHORT
) rGalleryHint
.GetData1() + 1 );
451 // -----------------------------------------------------------------------------
453 sal_Int8
GalleryBrowser2::AcceptDrop( DropTargetHelper
& rTarget
, const AcceptDropEvent
& )
455 sal_Int8 nRet
= DND_ACTION_NONE
;
457 if( mpCurTheme
&& !mpCurTheme
->IsReadOnly() && !mpCurTheme
->IsImported() )
459 if( !mpCurTheme
->IsDragging() )
461 if( rTarget
.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING
) ||
462 rTarget
.IsDropFormatSupported( SOT_FORMAT_FILE_LIST
) ||
463 rTarget
.IsDropFormatSupported( FORMAT_FILE
) ||
464 rTarget
.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB
) ||
465 rTarget
.IsDropFormatSupported( FORMAT_GDIMETAFILE
) ||
466 rTarget
.IsDropFormatSupported( FORMAT_BITMAP
) )
468 nRet
= DND_ACTION_COPY
;
472 nRet
= DND_ACTION_COPY
;
478 // -----------------------------------------------------------------------------
480 sal_Int8
GalleryBrowser2::ExecuteDrop( DropTargetHelper
&, const ExecuteDropEvent
& rEvt
)
482 sal_Int8 nRet
= DND_ACTION_NONE
;
487 const ULONG nItemId
= ImplGetSelectedItemId( &rEvt
.maPosPixel
, aSelPos
);
488 const ULONG nInsertPos
= ( nItemId
? ( nItemId
- 1 ) : LIST_APPEND
);
490 if( mpCurTheme
->IsDragging() )
491 mpCurTheme
->ChangeObjectPos( mpCurTheme
->GetDragPos(), nInsertPos
);
493 nRet
= mpCurTheme
->InsertTransferable( rEvt
.maDropEvent
.Transferable
, nInsertPos
);
499 // -----------------------------------------------------------------------------
501 void GalleryBrowser2::StartDrag( Window
*, const Point
* pDragPoint
)
506 const ULONG nItemId
= ImplGetSelectedItemId( pDragPoint
, aSelPos
);
509 mpCurTheme
->StartDrag( this, nItemId
- 1 );
513 // -----------------------------------------------------------------------------
515 void GalleryBrowser2::TogglePreview( Window
*, const Point
* )
517 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() ) ? GALLERYBROWSERMODE_PREVIEW
: meLastMode
);
518 GetViewWindow()->GrabFocus();
521 // -----------------------------------------------------------------------------
523 void GalleryBrowser2::ShowContextMenu( Window
*, const Point
* pContextPoint
)
526 const ULONG nItemId
= ImplGetSelectedItemId( pContextPoint
, aSelPos
);
528 if( mpCurTheme
&& nItemId
&& ( nItemId
<= mpCurTheme
->GetObjectCount() ) )
530 ImplSelectItemId( nItemId
);
532 SfxViewFrame
* pCurrentViewFrame
= SfxViewFrame::Current();
533 if ( pCurrentViewFrame
)
535 SfxBindings
& rBindings
= pCurrentViewFrame
->GetBindings();
536 rBindings
.ENTERREGISTRATIONS();
537 GalleryThemePopup
aMenu( mpCurTheme
, nItemId
- 1, GALLERYBROWSERMODE_PREVIEW
== GetMode() );
538 rBindings
.LEAVEREGISTRATIONS();
539 aMenu
.SetSelectHdl( LINK( this, GalleryBrowser2
, MenuSelectHdl
) );
540 aMenu
.Execute( this, aSelPos
);
545 // -----------------------------------------------------------------------------
547 BOOL
GalleryBrowser2::KeyInput( const KeyEvent
& rKEvt
, Window
* pWindow
)
550 const ULONG nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
551 BOOL bRet
= static_cast< GalleryBrowser
* >( GetParent() )->KeyInput( rKEvt
, pWindow
);
553 if( !bRet
&& !maViewBox
.HasFocus() && nItemId
&& mpCurTheme
)
555 USHORT nExecuteId
= 0;
556 const SgaObjKind eObjKind
= mpCurTheme
->GetObjectKind( nItemId
- 1 );
559 const_cast< GalleryTheme
* >( mpCurTheme
)->GetURL( nItemId
- 1, aURL
);
561 const BOOL bValidURL
= ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
);
562 BOOL bPreview
= bValidURL
;
563 BOOL bAdd
= bValidURL
;
564 BOOL bAddLink
= ( bValidURL
&& SGA_OBJ_SVDRAW
!= eObjKind
);
565 BOOL bDelete
= FALSE
;
568 if( !mpCurTheme
->IsReadOnly() && mpCurTheme
->GetObjectCount() )
570 bDelete
= ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() );
574 switch( rKEvt
.GetKeyCode().GetCode() )
582 TogglePreview( pWindow
);
591 if( bAddLink
&& rKEvt
.GetKeyCode().IsShift() && rKEvt
.GetKeyCode().IsMod1() )
592 nExecuteId
= MN_ADD_LINK
;
602 nExecuteId
= MN_DELETE
;
609 nExecuteId
= MN_TITLE
;
619 ImplExecute( nExecuteId
);
627 // -----------------------------------------------------------------------------
629 void GalleryBrowser2::SelectTheme( const String
& rThemeName
)
631 delete mpIconView
, mpIconView
= NULL
;
632 delete mpListView
, mpListView
= NULL
;
633 delete mpPreview
, mpPreview
= NULL
;
636 mpGallery
->ReleaseTheme( mpCurTheme
, *this );
638 mpCurTheme
= mpGallery
->AcquireTheme( rThemeName
, *this );
640 mpIconView
= new GalleryIconView( this, mpCurTheme
);
641 mpListView
= new GalleryListView( this, mpCurTheme
);
642 mpPreview
= new GalleryPreview( this, mpCurTheme
);
644 const Link
aSelectHdl( LINK( this, GalleryBrowser2
, SelectObjectHdl
) );
646 mpIconView
->SetSelectHdl( aSelectHdl
);
647 mpListView
->SetSelectHdl( aSelectHdl
);
649 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
653 ImplUpdateViews( 1 );
655 maViewBox
.EnableItem( TBX_ID_ICON
, TRUE
);
656 maViewBox
.EnableItem( TBX_ID_LIST
, TRUE
);
657 maViewBox
.CheckItem( ( GALLERYBROWSERMODE_ICON
== GetMode() ) ? TBX_ID_ICON
: TBX_ID_LIST
, TRUE
);
660 // -----------------------------------------------------------------------------
662 void GalleryBrowser2::SetMode( GalleryBrowserMode eMode
)
664 if( GetMode() != eMode
)
666 meLastMode
= GetMode();
670 case( GALLERYBROWSERMODE_ICON
):
675 mpPreview
->SetGraphic( Graphic() );
676 mpPreview
->PreviewMedia( INetURLObject() );
680 maViewBox
.EnableItem( TBX_ID_ICON
, TRUE
);
681 maViewBox
.EnableItem( TBX_ID_LIST
, TRUE
);
683 maViewBox
.CheckItem( TBX_ID_ICON
, TRUE
);
684 maViewBox
.CheckItem( TBX_ID_LIST
, FALSE
);
688 case( GALLERYBROWSERMODE_LIST
):
693 mpPreview
->SetGraphic( Graphic() );
694 mpPreview
->PreviewMedia( INetURLObject() );
698 maViewBox
.EnableItem( TBX_ID_ICON
, TRUE
);
699 maViewBox
.EnableItem( TBX_ID_LIST
, TRUE
);
701 maViewBox
.CheckItem( TBX_ID_ICON
, FALSE
);
702 maViewBox
.CheckItem( TBX_ID_LIST
, TRUE
);
706 case( GALLERYBROWSERMODE_PREVIEW
):
710 const ULONG nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
714 const ULONG nPos
= nItemId
- 1;
720 mpCurTheme
->GetGraphic( nPos
, aGraphic
);
722 mpPreview
->SetGraphic( aGraphic
);
725 if( mpCurTheme
&& mpCurTheme
->GetObjectKind( nPos
) == SGA_OBJ_SOUND
)
726 mpPreview
->PreviewMedia( mpCurTheme
->GetObjectURL( nPos
) );
728 maViewBox
.EnableItem( TBX_ID_ICON
, FALSE
);
729 maViewBox
.EnableItem( TBX_ID_LIST
, FALSE
);
738 GalleryBrowser2::meInitMode
= meMode
= eMode
;
742 // -----------------------------------------------------------------------------
744 Window
* GalleryBrowser2::GetViewWindow() const
750 case( GALLERYBROWSERMODE_LIST
): pRet
= mpListView
; break;
751 case( GALLERYBROWSERMODE_PREVIEW
): pRet
= mpPreview
; break;
761 // -----------------------------------------------------------------------------
763 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel
)
768 const ULONG nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
772 ULONG nNewItemId
= nItemId
;
776 case( GALLERYBROWSERTRAVEL_FIRST
): nNewItemId
= 1; break;
777 case( GALLERYBROWSERTRAVEL_LAST
): nNewItemId
= mpCurTheme
->GetObjectCount(); break;
778 case( GALLERYBROWSERTRAVEL_PREVIOUS
): nNewItemId
--; break;
779 case( GALLERYBROWSERTRAVEL_NEXT
): nNewItemId
++; break;
786 else if( nNewItemId
> mpCurTheme
->GetObjectCount() )
787 nNewItemId
= mpCurTheme
->GetObjectCount();
789 if( nNewItemId
!= nItemId
)
791 ImplSelectItemId( nNewItemId
);
794 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
797 const ULONG nPos
= nNewItemId
- 1;
799 mpCurTheme
->GetGraphic( nPos
, aGraphic
);
800 mpPreview
->SetGraphic( aGraphic
);
802 if( SGA_OBJ_SOUND
== mpCurTheme
->GetObjectKind( nPos
) )
803 mpPreview
->PreviewMedia( mpCurTheme
->GetObjectURL( nPos
) );
805 mpPreview
->Invalidate();
812 // -----------------------------------------------------------------------------
814 void GalleryBrowser2::ImplUpdateViews( USHORT nSelectionId
)
825 for( ULONG i
= 0, nCount
= mpCurTheme
->GetObjectCount(); i
< nCount
; )
827 mpListView
->RowInserted( i
++ );
828 mpIconView
->InsertItem( (USHORT
) i
);
831 ImplSelectItemId( ( ( nSelectionId
> mpCurTheme
->GetObjectCount() ) ? mpCurTheme
->GetObjectCount() : nSelectionId
) );
836 case( GALLERYBROWSERMODE_ICON
): mpIconView
->Show(); break;
837 case( GALLERYBROWSERMODE_LIST
): mpListView
->Show(); break;
838 case( GALLERYBROWSERMODE_PREVIEW
): mpPreview
->Show(); break;
847 // -----------------------------------------------------------------------------
849 void GalleryBrowser2::ImplUpdateInfoBar()
856 const ULONG nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
860 const ULONG nPos
= nItemId
- 1;
862 aInfoText
= mpCurTheme
->GetName();
864 if( nPos
< mpCurTheme
->GetObjectCount() )
866 SgaObject
* pObj
= mpCurTheme
->AcquireObject( nPos
);
870 aInfoText
= GetItemText( *mpCurTheme
, *pObj
, GALLERY_ITEM_THEMENAME
| GALLERY_ITEM_TITLE
| GALLERY_ITEM_PATH
);
871 mpCurTheme
->ReleaseObject( pObj
);
877 maInfoBar
.SetText( aInfoText
);
880 // -----------------------------------------------------------------------------
882 ULONG
GalleryBrowser2::ImplGetSelectedItemId( const Point
* pSelPos
, Point
& rSelPos
)
884 const Size
aOutputSizePixel( GetOutputSizePixel() );
887 if( GALLERYBROWSERMODE_PREVIEW
== GetMode() )
889 nRet
= ( ( GALLERYBROWSERMODE_ICON
== meLastMode
) ? mpIconView
->GetSelectItemId() : ( mpListView
->FirstSelectedRow() + 1 ) );
892 rSelPos
= GetPointerPosPixel();
894 rSelPos
= Point( aOutputSizePixel
.Width() >> 1, aOutputSizePixel
.Height() >> 1 );
896 else if( GALLERYBROWSERMODE_ICON
== GetMode() )
900 nRet
= mpIconView
->GetItemId( *pSelPos
);
901 rSelPos
= GetPointerPosPixel();
905 nRet
= mpIconView
->GetSelectItemId();
906 rSelPos
= mpIconView
->GetItemRect( (USHORT
) nRet
).Center();
913 nRet
= mpListView
->GetRowAtYPosPixel( pSelPos
->Y() ) + 1;
914 rSelPos
= GetPointerPosPixel();
918 nRet
= mpListView
->FirstSelectedRow() + 1;
919 rSelPos
= mpListView
->GetFieldRectPixel( (USHORT
) nRet
, 1 ).Center();
923 rSelPos
.X() = Max( Min( rSelPos
.X(), aOutputSizePixel
.Width() - 1L ), 0L );
924 rSelPos
.Y() = Max( Min( rSelPos
.Y(), aOutputSizePixel
.Height() - 1L ), 0L );
926 if( nRet
&& ( !mpCurTheme
|| ( nRet
> mpCurTheme
->GetObjectCount() ) ) )
934 // -----------------------------------------------------------------------------
936 void GalleryBrowser2::ImplSelectItemId( ULONG nItemId
)
941 mpIconView
->SelectItem( (USHORT
) nItemId
);
942 mpListView
->SelectRow( nItemId
- 1 );
946 // -----------------------------------------------------------------------------
948 void GalleryBrowser2::ImplExecute( USHORT nId
)
951 const ULONG nItemId
= ImplGetSelectedItemId( NULL
, aSelPos
);
953 if( mpCurTheme
&& nItemId
)
955 mnCurActionPos
= nItemId
- 1;
962 sal_uInt32 nFormat
= 0;
964 mbCurActionIsLinkage
= ( MN_ADD_LINK
== nId
);
966 switch( mpCurTheme
->GetObjectKind( mnCurActionPos
) )
969 case( SGA_OBJ_ANIM
):
970 case( SGA_OBJ_INET
):
971 nFormat
= SGA_FORMAT_GRAPHIC
| SGA_FORMAT_STRING
;
974 case ( SGA_OBJ_SOUND
) :
975 nFormat
= SGA_FORMAT_SOUND
| SGA_FORMAT_STRING
;
978 case( SGA_OBJ_SVDRAW
):
979 nFormat
= SGA_FORMAT_GRAPHIC
| SGA_FORMAT_SVDRAW
| SGA_FORMAT_STRING
;
986 const SfxUInt32Item
aItem( SID_GALLERY_FORMATS
, nFormat
);
987 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute(
988 SID_GALLERY_FORMATS
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aItem
, 0L );
993 SetMode( ( GALLERYBROWSERMODE_PREVIEW
!= GetMode() ) ? GALLERYBROWSERMODE_PREVIEW
: meLastMode
);
998 if( !mpCurTheme
->IsReadOnly() &&
999 QueryBox( NULL
, WB_YES_NO
, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETEOBJ
) ) ).Execute() == RET_YES
)
1001 mpCurTheme
->RemoveObject( mnCurActionPos
);
1008 SgaObject
* pObj
= mpCurTheme
->AcquireObject( mnCurActionPos
);
1012 const String
aOldTitle( GetItemText( *mpCurTheme
, *pObj
, GALLERY_ITEM_TITLE
) );
1013 //CHINA001 TitleDialog aDlg( this, aOldTitle );
1014 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
1017 AbstractTitleDialog
* aDlg
= pFact
->CreateTitleDialog( this, aOldTitle
, RID_SVXDLG_GALLERY_TITLE
);
1018 DBG_ASSERT(aDlg
, "Dialogdiet fail!");//CHINA001
1019 if( aDlg
->Execute() == RET_OK
)//CHINA001 if( aDlg.Execute() == RET_OK )
1021 String
aNewTitle( aDlg
->GetTitle() );//CHINA001 String aNewTitle( aDlg.GetTitle() );
1023 if( ( !aNewTitle
.Len() && pObj
->GetTitle().Len() ) || ( aNewTitle
!= aOldTitle
) )
1025 if( !aNewTitle
.Len() )
1026 aNewTitle
= String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) );
1028 pObj
->SetTitle( aNewTitle
);
1029 mpCurTheme
->InsertObject( *pObj
);
1033 mpCurTheme
->ReleaseObject( pObj
);
1034 delete aDlg
; //add CHINA001
1040 case( MN_COPYCLIPBOARD
):
1046 case( GALLERYBROWSERMODE_ICON
): pWindow
= (Window
*) mpIconView
; break;
1047 case( GALLERYBROWSERMODE_LIST
): pWindow
= (Window
*) mpListView
; break;
1048 case( GALLERYBROWSERMODE_PREVIEW
): pWindow
= (Window
*) mpPreview
; break;
1055 mpCurTheme
->CopyToClipboard( pWindow
, mnCurActionPos
);
1059 case( MN_PASTECLIPBOARD
):
1061 if( !mpCurTheme
->IsReadOnly() )
1063 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1064 mpCurTheme
->InsertTransferable( aDataHelper
.GetTransferable(), mnCurActionPos
);
1075 // -----------------------------------------------------------------------------
1077 String
GalleryBrowser2::GetItemText( const GalleryTheme
& rTheme
, const SgaObject
& rObj
, ULONG nItemTextFlags
)
1082 if( rTheme
.IsImported() )
1084 aURL
= rTheme
.GetParent()->GetImportURL( rTheme
.GetName() );
1086 aURL
.removeSegment();
1087 aURL
.Append( rObj
.GetURL().GetName() );
1090 aURL
= rObj
.GetURL();
1092 if( nItemTextFlags
& GALLERY_ITEM_THEMENAME
)
1094 aRet
+= rTheme
.GetName();
1095 aRet
+= String( RTL_CONSTASCII_USTRINGPARAM( " - " ) );
1098 if( nItemTextFlags
& GALLERY_ITEM_TITLE
)
1100 String
aTitle( rObj
.GetTitle() );
1103 aTitle
= aURL
.getBase( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_UNAMBIGUOUS
);
1107 aTitle
= aURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
1108 aTitle
= aTitle
.GetToken( aTitle
.GetTokenCount( '/' ) - 1, '/' );
1114 if( nItemTextFlags
& GALLERY_ITEM_PATH
)
1116 const String
aPath( aURL
.getFSysPath( INetURLObject::FSYS_DETECT
) );
1118 if( aPath
.Len() && ( nItemTextFlags
& GALLERY_ITEM_TITLE
) )
1119 aRet
+= String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
1121 aRet
+= String(aURL
.getFSysPath( INetURLObject::FSYS_DETECT
));
1123 if( aPath
.Len() && ( nItemTextFlags
& GALLERY_ITEM_TITLE
) )
1130 // -----------------------------------------------------------------------------
1132 INetURLObject
GalleryBrowser2::GetURL() const
1136 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1137 aURL
= mpCurTheme
->GetObjectURL( mnCurActionPos
);
1142 // -----------------------------------------------------------------------------
1144 String
GalleryBrowser2::GetFilterName() const
1148 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1150 const SgaObjKind eObjKind
= mpCurTheme
->GetObjectKind( mnCurActionPos
);
1152 if( ( SGA_OBJ_BMP
== eObjKind
) || ( SGA_OBJ_ANIM
== eObjKind
) )
1154 GraphicFilter
* pFilter
= GetGrfFilter();
1155 INetURLObject aURL
; mpCurTheme
->GetURL( mnCurActionPos
, aURL
);
1156 sal_uInt16 nFilter
= pFilter
->GetImportFormatNumberForShortName( aURL
.GetExtension() );
1158 if( GRFILTER_FORMAT_DONTKNOW
!= nFilter
)
1159 aFilterName
= pFilter
->GetImportFormatName( nFilter
);
1166 // -----------------------------------------------------------------------------
1168 Graphic
GalleryBrowser2::GetGraphic() const
1172 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1173 mpCurTheme
->GetGraphic( mnCurActionPos
, aGraphic
);
1178 // -----------------------------------------------------------------------------
1180 BOOL
GalleryBrowser2::GetVCDrawModel( FmFormModel
& rModel
) const
1184 if( mpCurTheme
&& mnCurActionPos
!= 0xffffffff )
1185 bRet
= mpCurTheme
->GetModel( mnCurActionPos
, rModel
);
1190 // -----------------------------------------------------------------------------
1192 BOOL
GalleryBrowser2::IsLinkage() const
1194 return mbCurActionIsLinkage
;
1197 // -----------------------------------------------------------------------------
1199 IMPL_LINK( GalleryBrowser2
, MenuSelectHdl
, Menu
*, pMenu
)
1202 ImplExecute( pMenu
->GetCurItemId() );
1207 // -----------------------------------------------------------------------------
1209 IMPL_LINK( GalleryBrowser2
, SelectObjectHdl
, void*, EMPTYARG
)
1211 ImplUpdateInfoBar();
1215 // -----------------------------------------------------------------------------
1217 IMPL_LINK( GalleryBrowser2
, SelectTbxHdl
, ToolBox
*, pBox
)
1219 if( pBox
->GetCurItemId() == TBX_ID_ICON
)
1220 SetMode( GALLERYBROWSERMODE_ICON
);
1221 else if( pBox
->GetCurItemId() == TBX_ID_LIST
)
1222 SetMode( GALLERYBROWSERMODE_LIST
);
1227 // -----------------------------------------------------------------------------
1229 IMPL_LINK( GalleryBrowser2
, MiscHdl
, void*, EMPTYARG
)
1231 const sal_Bool bHC
= GALLERY_DLG_COLOR
.IsDark();
1233 maViewBox
.SetOutStyle( maMiscOptions
.GetToolboxStyle() );
1235 BitmapEx aIconBmpEx
= BitmapEx( Image( GAL_RESID( bHC
? RID_SVXIMG_GALLERY_VIEW_ICON_HC
: RID_SVXIMG_GALLERY_VIEW_ICON
) ).GetBitmapEx() );
1236 BitmapEx aListBmpEx
= BitmapEx( Image( GAL_RESID( bHC
? RID_SVXIMG_GALLERY_VIEW_LIST_HC
: RID_SVXIMG_GALLERY_VIEW_LIST
) ).GetBitmapEx() );
1238 if( maMiscOptions
.AreCurrentSymbolsLarge() )
1240 const Size
aLargeSize( 24, 24);
1242 aIconBmpEx
.Scale( aLargeSize
);
1243 aListBmpEx
.Scale( aLargeSize
);
1246 maViewBox
.SetItemImage( TBX_ID_ICON
, aIconBmpEx
);
1247 maViewBox
.SetItemImage( TBX_ID_LIST
, aListBmpEx
);
1248 maViewBox
.SetSizePixel( maViewBox
.CalcWindowSizePixel() );