update dev300-m58
[ooovba.git] / svx / source / gallery2 / galbrws2.cxx
blobca5df8ff162a758f76999d6ec961b74a61c6e64e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: galbrws2.cxx,v $
10 * $Revision: 1.57 $
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>
47 #include "impgrf.hxx"
48 #include <svx/brshitem.hxx>
49 #include "helpid.hrc"
50 #include "gallery1.hxx"
51 #include "galtheme.hxx"
52 #include "galmisc.hxx"
53 #include "galdlg.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
60 // -----------
61 // - Defines -
62 // -----------
64 #undef GALLERY_USE_CLIPBOARD
66 #define TBX_ID_ICON 1
67 #define TBX_ID_LIST 2
69 // -----------
70 // - statics -
71 // -----------
73 GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON;
75 // --------------------------
76 // - GalleryBackgroundPopup -
77 // --------------------------
79 class GalleryBackgroundPopup : public PopupMenu, public SfxControllerItem
81 const GalleryTheme* mpTheme;
82 ULONG mnObjectPos;
84 virtual void Select();
85 virtual void StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState );
87 public:
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() ),
97 mpTheme ( pTheme ),
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;
119 PopupMenu::Clear();
121 if( ( pStrLstItem = PTR_CAST( SfxStringListItem, pItem ) ) != NULL )
123 List* pList = pStrLstItem->GetList();
125 if( pList )
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() );
131 else
133 DBG_ERROR( "SgaBGPopup::StateChanged(...): Wrong item type!" );
138 // ------------------------------------------------------------------------
140 void GalleryBackgroundPopup::Select()
142 Menu::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;
162 ULONG mnObjectPos;
163 BOOL mbPreview;
165 virtual void StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState );
167 public:
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 ),
179 mpTheme ( pTheme ),
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();
186 INetURLObject aURL;
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 );
210 else
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 ) )
233 bEnable = TRUE;
237 if( !bEnable )
238 EnableItem( MN_PASTECLIPBOARD, FALSE );
240 #else
241 EnableItem( MN_COPYCLIPBOARD, FALSE );
242 EnableItem( MN_PASTECLIPBOARD, FALSE );
243 #endif
245 if( !maBackgroundPopup.GetItemCount() || ( eObjKind == SGA_OBJ_SVDRAW ) || ( eObjKind == SGA_OBJ_SOUND ) )
246 pAddMenu->EnableItem( MN_BACKGROUND, FALSE );
247 else
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 ),
308 mpCurTheme ( NULL ),
309 mpIconView ( new GalleryIconView( this, NULL ) ),
310 mpListView ( new GalleryListView( this, NULL ) ),
311 mpPreview ( new GalleryPreview( this, NULL ) ),
312 maViewBox ( this ),
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 )
320 Image aDummyImage;
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 );
337 MiscHdl( NULL );
338 maViewBox.SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
339 maViewBox.Show();
341 maInfoBar.Show();
342 maSeparator.Show();
344 mpIconView->SetSelectHdl( aSelectHdl );
345 mpListView->SetSelectHdl( aSelectHdl );
347 InitSettings();
349 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON );
352 // -----------------------------------------------------------------------------
354 GalleryBrowser2::~GalleryBrowser2()
356 maMiscOptions.RemoveListener( LINK( this, GalleryBrowser2, MiscHdl ) );
358 delete mpPreview;
359 delete mpListView;
360 delete mpIconView;
362 if( mpCurTheme )
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 ) )
389 InitSettings();
390 else
391 Control::DataChanged( rDCEvt );
394 // -----------------------------------------------------------------------------
396 void GalleryBrowser2::Resize()
398 Control::Resize();
400 mpIconView->Hide();
401 mpListView->Hide();
402 mpPreview->Hide();
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 );
418 switch( GetMode() )
420 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
421 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
422 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
424 default:
425 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 );
444 break;
446 default:
447 break;
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;
471 else
472 nRet = DND_ACTION_COPY;
475 return nRet;
478 // -----------------------------------------------------------------------------
480 sal_Int8 GalleryBrowser2::ExecuteDrop( DropTargetHelper&, const ExecuteDropEvent& rEvt )
482 sal_Int8 nRet = DND_ACTION_NONE;
484 if( mpCurTheme )
486 Point aSelPos;
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 );
492 else
493 nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos );
496 return nRet;
499 // -----------------------------------------------------------------------------
501 void GalleryBrowser2::StartDrag( Window*, const Point* pDragPoint )
503 if( mpCurTheme )
505 Point aSelPos;
506 const ULONG nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos );
508 if( nItemId )
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 )
525 Point aSelPos;
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 )
549 Point aSelPos;
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 );
557 INetURLObject aURL;
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;
566 BOOL bTitle = FALSE;
568 if( !mpCurTheme->IsReadOnly() && mpCurTheme->GetObjectCount() )
570 bDelete = ( GALLERYBROWSERMODE_PREVIEW != GetMode() );
571 bTitle = TRUE;
574 switch( rKEvt.GetKeyCode().GetCode() )
576 case( KEY_SPACE ):
577 case( KEY_RETURN ):
578 case( KEY_P ):
580 if( bPreview )
582 TogglePreview( pWindow );
583 bRet = TRUE;
586 break;
588 case( KEY_INSERT ):
589 case( KEY_I ):
591 if( bAddLink && rKEvt.GetKeyCode().IsShift() && rKEvt.GetKeyCode().IsMod1() )
592 nExecuteId = MN_ADD_LINK;
593 else if( bAdd )
594 nExecuteId = MN_ADD;
596 break;
598 case( KEY_DELETE ):
599 case( KEY_D ):
601 if( bDelete )
602 nExecuteId = MN_DELETE;
604 break;
606 case( KEY_T ):
608 if( bTitle )
609 nExecuteId = MN_TITLE;
611 break;
613 default:
614 break;
617 if( nExecuteId )
619 ImplExecute( nExecuteId );
620 bRet = TRUE;
624 return bRet;
627 // -----------------------------------------------------------------------------
629 void GalleryBrowser2::SelectTheme( const String& rThemeName )
631 delete mpIconView, mpIconView = NULL;
632 delete mpListView, mpListView = NULL;
633 delete mpPreview, mpPreview = NULL;
635 if( mpCurTheme )
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() )
650 meMode = meLastMode;
652 Resize();
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();
668 switch( eMode )
670 case( GALLERYBROWSERMODE_ICON ):
672 mpListView->Hide();
674 mpPreview->Hide();
675 mpPreview->SetGraphic( Graphic() );
676 mpPreview->PreviewMedia( INetURLObject() );
678 mpIconView->Show();
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 );
686 break;
688 case( GALLERYBROWSERMODE_LIST ):
690 mpIconView->Hide();
692 mpPreview->Hide();
693 mpPreview->SetGraphic( Graphic() );
694 mpPreview->PreviewMedia( INetURLObject() );
696 mpListView->Show();
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 );
704 break;
706 case( GALLERYBROWSERMODE_PREVIEW ):
708 Graphic aGraphic;
709 Point aSelPos;
710 const ULONG nItemId = ImplGetSelectedItemId( NULL, aSelPos );
712 if( nItemId )
714 const ULONG nPos = nItemId - 1;
716 mpIconView->Hide();
717 mpListView->Hide();
719 if( mpCurTheme )
720 mpCurTheme->GetGraphic( nPos, aGraphic );
722 mpPreview->SetGraphic( aGraphic );
723 mpPreview->Show();
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 );
732 break;
734 default:
735 break;
738 GalleryBrowser2::meInitMode = meMode = eMode;
742 // -----------------------------------------------------------------------------
744 Window* GalleryBrowser2::GetViewWindow() const
746 Window* pRet;
748 switch( GetMode() )
750 case( GALLERYBROWSERMODE_LIST ): pRet = mpListView; break;
751 case( GALLERYBROWSERMODE_PREVIEW ): pRet = mpPreview; break;
753 default:
754 pRet = mpIconView;
755 break;
758 return pRet;
761 // -----------------------------------------------------------------------------
763 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )
765 if( mpCurTheme )
767 Point aSelPos;
768 const ULONG nItemId = ImplGetSelectedItemId( NULL, aSelPos );
770 if( nItemId )
772 ULONG nNewItemId = nItemId;
774 switch( eTravel )
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;
780 default:
781 break;
784 if( nNewItemId < 1 )
785 nNewItemId = 1;
786 else if( nNewItemId > mpCurTheme->GetObjectCount() )
787 nNewItemId = mpCurTheme->GetObjectCount();
789 if( nNewItemId != nItemId )
791 ImplSelectItemId( nNewItemId );
792 ImplUpdateInfoBar();
794 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
796 Graphic aGraphic;
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 )
816 mpIconView->Hide();
817 mpListView->Hide();
818 mpPreview->Hide();
820 mpIconView->Clear();
821 mpListView->Clear();
823 if( mpCurTheme )
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 ) );
834 switch( GetMode() )
836 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
837 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
838 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
840 default:
841 break;
844 ImplUpdateInfoBar();
847 // -----------------------------------------------------------------------------
849 void GalleryBrowser2::ImplUpdateInfoBar()
851 String aInfoText;
853 if( mpCurTheme )
855 Point aSelPos;
856 const ULONG nItemId = ImplGetSelectedItemId( NULL, aSelPos );
858 if( nItemId )
860 const ULONG nPos = nItemId - 1;
862 aInfoText = mpCurTheme->GetName();
864 if( nPos < mpCurTheme->GetObjectCount() )
866 SgaObject* pObj = mpCurTheme->AcquireObject( nPos );
868 if( pObj )
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() );
885 ULONG nRet = 0;
887 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
889 nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mpIconView->GetSelectItemId() : ( mpListView->FirstSelectedRow() + 1 ) );
891 if( pSelPos )
892 rSelPos = GetPointerPosPixel();
893 else
894 rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
896 else if( GALLERYBROWSERMODE_ICON == GetMode() )
898 if( pSelPos )
900 nRet = mpIconView->GetItemId( *pSelPos );
901 rSelPos = GetPointerPosPixel();
903 else
905 nRet = mpIconView->GetSelectItemId();
906 rSelPos = mpIconView->GetItemRect( (USHORT) nRet ).Center();
909 else
911 if( pSelPos )
913 nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1;
914 rSelPos = GetPointerPosPixel();
916 else
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() ) ) )
928 nRet = 0;
931 return nRet;
934 // -----------------------------------------------------------------------------
936 void GalleryBrowser2::ImplSelectItemId( ULONG nItemId )
938 if( nItemId )
941 mpIconView->SelectItem( (USHORT) nItemId );
942 mpListView->SelectRow( nItemId - 1 );
946 // -----------------------------------------------------------------------------
948 void GalleryBrowser2::ImplExecute( USHORT nId )
950 Point aSelPos;
951 const ULONG nItemId = ImplGetSelectedItemId( NULL, aSelPos );
953 if( mpCurTheme && nItemId )
955 mnCurActionPos = nItemId - 1;
957 switch( nId )
959 case( MN_ADD ):
960 case( MN_ADD_LINK ):
962 sal_uInt32 nFormat = 0;
964 mbCurActionIsLinkage = ( MN_ADD_LINK == nId );
966 switch( mpCurTheme->GetObjectKind( mnCurActionPos ) )
968 case( SGA_OBJ_BMP ):
969 case( SGA_OBJ_ANIM ):
970 case( SGA_OBJ_INET ):
971 nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_STRING;
972 break;
974 case ( SGA_OBJ_SOUND ) :
975 nFormat = SGA_FORMAT_SOUND | SGA_FORMAT_STRING;
976 break;
978 case( SGA_OBJ_SVDRAW ):
979 nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_SVDRAW | SGA_FORMAT_STRING;
980 break;
982 default :
983 break;
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 );
990 break;
992 case( MN_PREVIEW ):
993 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
994 break;
996 case( MN_DELETE ):
998 if( !mpCurTheme->IsReadOnly() &&
999 QueryBox( NULL, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETEOBJ ) ) ).Execute() == RET_YES )
1001 mpCurTheme->RemoveObject( mnCurActionPos );
1004 break;
1006 case( MN_TITLE ):
1008 SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos );
1010 if( pObj )
1012 const String aOldTitle( GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_TITLE ) );
1013 //CHINA001 TitleDialog aDlg( this, aOldTitle );
1014 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1015 if(pFact)
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
1038 break;
1040 case( MN_COPYCLIPBOARD ):
1042 Window* pWindow;
1044 switch( GetMode() )
1046 case( GALLERYBROWSERMODE_ICON ): pWindow = (Window*) mpIconView; break;
1047 case( GALLERYBROWSERMODE_LIST ): pWindow = (Window*) mpListView; break;
1048 case( GALLERYBROWSERMODE_PREVIEW ): pWindow = (Window*) mpPreview; break;
1050 default:
1051 pWindow = NULL;
1052 break;
1055 mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos );
1057 break;
1059 case( MN_PASTECLIPBOARD ):
1061 if( !mpCurTheme->IsReadOnly() )
1063 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1064 mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos );
1067 break;
1069 default:
1070 break;
1075 // -----------------------------------------------------------------------------
1077 String GalleryBrowser2::GetItemText( const GalleryTheme& rTheme, const SgaObject& rObj, ULONG nItemTextFlags )
1079 INetURLObject aURL;
1080 String aRet;
1082 if( rTheme.IsImported() )
1084 aURL = rTheme.GetParent()->GetImportURL( rTheme.GetName() );
1086 aURL.removeSegment();
1087 aURL.Append( rObj.GetURL().GetName() );
1089 else
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() );
1102 if( !aTitle.Len() )
1103 aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
1105 if( !aTitle.Len() )
1107 aTitle = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1108 aTitle = aTitle.GetToken( aTitle.GetTokenCount( '/' ) - 1, '/' );
1111 aRet += aTitle;
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 ) )
1124 aRet += ')';
1127 return aRet;
1130 // -----------------------------------------------------------------------------
1132 INetURLObject GalleryBrowser2::GetURL() const
1134 INetURLObject aURL;
1136 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1137 aURL = mpCurTheme->GetObjectURL( mnCurActionPos );
1139 return aURL;
1142 // -----------------------------------------------------------------------------
1144 String GalleryBrowser2::GetFilterName() const
1146 String aFilterName;
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 );
1163 return aFilterName;
1166 // -----------------------------------------------------------------------------
1168 Graphic GalleryBrowser2::GetGraphic() const
1170 Graphic aGraphic;
1172 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1173 mpCurTheme->GetGraphic( mnCurActionPos, aGraphic );
1175 return aGraphic;
1178 // -----------------------------------------------------------------------------
1180 BOOL GalleryBrowser2::GetVCDrawModel( FmFormModel& rModel ) const
1182 BOOL bRet = FALSE;
1184 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1185 bRet = mpCurTheme->GetModel( mnCurActionPos, rModel );
1187 return bRet;
1190 // -----------------------------------------------------------------------------
1192 BOOL GalleryBrowser2::IsLinkage() const
1194 return mbCurActionIsLinkage;
1197 // -----------------------------------------------------------------------------
1199 IMPL_LINK( GalleryBrowser2, MenuSelectHdl, Menu*, pMenu )
1201 if( pMenu )
1202 ImplExecute( pMenu->GetCurItemId() );
1204 return 0;
1207 // -----------------------------------------------------------------------------
1209 IMPL_LINK( GalleryBrowser2, SelectObjectHdl, void*, EMPTYARG )
1211 ImplUpdateInfoBar();
1212 return 0L;
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 );
1224 return 0L;
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() );
1250 Resize();
1252 return 0L;