fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / gallery2 / galbrws2.cxx
blobbaba4094bc115ee3ef01640353e3e5d33310e1cb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
35 #include "helpid.hrc"
36 #include "svx/gallery.hxx"
37 #include "galobj.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
53 #define TBX_ID_ICON 1
54 #define TBX_ID_LIST 2
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 );
66 public:
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() ),
76 mpTheme ( pTheme ),
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;
95 PopupMenu::Clear();
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]);
103 return;
105 SfxStringItem* pStrItem = PTR_CAST( SfxStringItem, pItem );
106 if (pStrItem)
107 InsertItem( 1, pStrItem->GetValue() );
108 else
110 OSL_FAIL( "SgaBGPopup::StateChanged(...): Wrong item type!" );
115 void GalleryBackgroundPopup::Select()
117 Menu::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;
134 sal_Bool mbPreview;
136 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
138 public:
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 ),
150 mpTheme ( pTheme ),
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();
159 INetURLObject aURL;
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 );
183 else
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 ) )
206 bEnable = sal_True;
210 if( !bEnable )
211 EnableItem( MN_PASTECLIPBOARD, sal_False );
213 #else
214 EnableItem( MN_COPYCLIPBOARD, sal_False );
215 EnableItem( MN_PASTECLIPBOARD, sal_False );
216 #endif
218 if( !maBackgroundPopup.GetItemCount() || ( eObjKind == SGA_OBJ_SVDRAW ) || ( eObjKind == SGA_OBJ_SOUND ) )
219 pAddMenu->EnableItem( MN_BACKGROUND, sal_False );
220 else
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 ),
272 mpCurTheme ( NULL ),
273 mpIconView ( new GalleryIconView( this, NULL ) ),
274 mpListView ( new GalleryListView( this, NULL ) ),
275 mpPreview ( new GalleryPreview( this, NULL ) ),
276 maViewBox ( this ),
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);
286 Image aDummyImage;
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) );
302 MiscHdl( NULL );
303 maViewBox.SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
304 maViewBox.Show();
306 mpIconView->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS));
307 mpListView->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERY_THEMEITEMS));
309 maInfoBar.Show();
310 maSeparator.Show();
312 mpIconView->SetSelectHdl( aSelectHdl );
313 mpListView->SetSelectHdl( aSelectHdl );
315 InitSettings();
317 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON );
319 if(maInfoBar.GetText().isEmpty())
320 mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
321 else
322 mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
323 mpIconView->SetAccessibleRelationMemberOf(mpIconView);
326 GalleryBrowser2::~GalleryBrowser2()
328 maMiscOptions.RemoveListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
330 delete mpPreview;
331 delete mpListView;
332 delete mpIconView;
334 if( mpCurTheme )
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 ) )
359 InitSettings();
360 else
361 Control::DataChanged( rDCEvt );
364 void GalleryBrowser2::Resize()
366 Control::Resize();
368 mpIconView->Hide();
369 mpListView->Hide();
370 mpPreview->Hide();
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 );
386 switch( GetMode() )
388 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
389 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
390 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
392 default:
393 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 );
410 break;
412 default:
413 break;
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;
435 else
436 nRet = DND_ACTION_COPY;
439 return nRet;
442 sal_Int8 GalleryBrowser2::ExecuteDrop( DropTargetHelper&, const ExecuteDropEvent& rEvt )
444 sal_Int8 nRet = DND_ACTION_NONE;
446 if( mpCurTheme )
448 Point aSelPos;
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 );
454 else
455 nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos );
458 return nRet;
461 void GalleryBrowser2::StartDrag( Window*, const Point* pDragPoint )
463 if( mpCurTheme )
465 Point aSelPos;
466 const sal_uIntPtr nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos );
468 if( nItemId )
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 )
481 Point aSelPos;
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 )
503 Point aSelPos;
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 );
509 else
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 );
520 INetURLObject aURL;
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() );
534 bTitle = sal_True;
537 switch( rKEvt.GetKeyCode().GetCode() )
539 case( KEY_SPACE ):
540 case( KEY_RETURN ):
541 case( KEY_P ):
543 if( bPreview )
545 TogglePreview( pWindow );
546 bRet = sal_True;
549 break;
551 case( KEY_INSERT ):
552 case( KEY_I ):
554 if( bAddLink && rKEvt.GetKeyCode().IsShift() && rKEvt.GetKeyCode().IsMod1() )
555 nExecuteId = MN_ADD_LINK;
556 else if( bAdd )
557 nExecuteId = MN_ADD;
559 break;
561 case( KEY_DELETE ):
562 case( KEY_D ):
564 if( bDelete )
565 nExecuteId = MN_DELETE;
567 break;
569 case( KEY_T ):
571 if( bTitle )
572 nExecuteId = MN_TITLE;
574 break;
576 default:
577 break;
580 if( nExecuteId )
582 ImplExecute( nExecuteId );
583 bRet = sal_True;
587 return bRet;
590 void GalleryBrowser2::SelectTheme( const String& rThemeName )
592 delete mpIconView, mpIconView = NULL;
593 delete mpListView, mpListView = NULL;
594 delete mpPreview, mpPreview = NULL;
596 if( mpCurTheme )
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() )
615 meMode = meLastMode;
617 Resize();
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);
626 else
627 mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
628 mpIconView->SetAccessibleRelationMemberOf(mpIconView);
631 void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
633 if( GetMode() != eMode )
635 meLastMode = GetMode();
637 switch( eMode )
639 case( GALLERYBROWSERMODE_ICON ):
641 mpListView->Hide();
643 mpPreview->Hide();
644 mpPreview->SetGraphic( Graphic() );
645 mpPreview->PreviewMedia( INetURLObject() );
647 mpIconView->Show();
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 );
655 break;
657 case( GALLERYBROWSERMODE_LIST ):
659 mpIconView->Hide();
661 mpPreview->Hide();
662 mpPreview->SetGraphic( Graphic() );
663 mpPreview->PreviewMedia( INetURLObject() );
665 mpListView->Show();
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 );
673 break;
675 case( GALLERYBROWSERMODE_PREVIEW ):
677 Graphic aGraphic;
678 Point aSelPos;
679 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
681 if( nItemId )
683 const sal_uIntPtr nPos = nItemId - 1;
685 mpIconView->Hide();
686 mpListView->Hide();
688 if( mpCurTheme )
689 mpCurTheme->GetGraphic( nPos, aGraphic );
691 mpPreview->SetGraphic( aGraphic );
692 mpPreview->Show();
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 );
701 break;
703 default:
704 break;
707 GalleryBrowser2::meInitMode = meMode = eMode;
711 Window* GalleryBrowser2::GetViewWindow() const
713 Window* pRet;
715 switch( GetMode() )
717 case( GALLERYBROWSERMODE_LIST ): pRet = mpListView; break;
718 case( GALLERYBROWSERMODE_PREVIEW ): pRet = mpPreview; break;
720 default:
721 pRet = mpIconView;
722 break;
725 return pRet;
728 void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )
730 if( mpCurTheme )
732 Point aSelPos;
733 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
735 if( nItemId )
737 sal_uIntPtr nNewItemId = nItemId;
739 switch( eTravel )
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;
745 default:
746 break;
749 if( nNewItemId < 1 )
750 nNewItemId = 1;
751 else if( nNewItemId > mpCurTheme->GetObjectCount() )
752 nNewItemId = mpCurTheme->GetObjectCount();
754 if( nNewItemId != nItemId )
756 ImplSelectItemId( nNewItemId );
757 ImplUpdateInfoBar();
759 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
761 Graphic aGraphic;
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 )
779 mpIconView->Hide();
780 mpListView->Hide();
781 mpPreview->Hide();
783 mpIconView->Clear();
784 mpListView->Clear();
786 if( mpCurTheme )
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 ) );
797 switch( GetMode() )
799 case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
800 case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
801 case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
803 default:
804 break;
807 ImplUpdateInfoBar();
810 void GalleryBrowser2::ImplUpdateInfoBar()
812 String aInfoText;
814 if( mpCurTheme )
816 Point aSelPos;
817 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
819 if( nItemId )
821 const sal_uIntPtr nPos = nItemId - 1;
823 aInfoText = mpCurTheme->GetName();
825 if( nPos < mpCurTheme->GetObjectCount() )
827 SgaObject* pObj = mpCurTheme->AcquireObject( nPos );
829 if( pObj )
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 ) );
850 if( pSelPos )
851 rSelPos = GetPointerPosPixel();
852 else
853 rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
855 else if( GALLERYBROWSERMODE_ICON == GetMode() )
857 if( pSelPos )
859 nRet = mpIconView->GetItemId( *pSelPos );
860 rSelPos = GetPointerPosPixel();
862 else
864 nRet = mpIconView->GetSelectItemId();
865 rSelPos = mpIconView->GetItemRect( (sal_uInt16) nRet ).Center();
868 else
870 if( pSelPos )
872 nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1;
873 rSelPos = GetPointerPosPixel();
875 else
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() ) ) )
887 nRet = 0;
890 return nRet;
893 void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId )
895 if( nItemId )
898 mpIconView->SelectItem( (sal_uInt16) nItemId );
899 mpListView->SelectRow( nItemId - 1 );
903 void GalleryBrowser2::ImplExecute( sal_uInt16 nId )
905 Point aSelPos;
906 const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
908 if( mpCurTheme && nItemId )
910 mnCurActionPos = nItemId - 1;
912 switch( nId )
914 case( MN_ADD ):
915 case( MN_ADD_LINK ):
917 sal_uInt32 nFormat = 0;
919 mbCurActionIsLinkage = ( MN_ADD_LINK == nId );
921 switch( mpCurTheme->GetObjectKind( mnCurActionPos ) )
923 case( SGA_OBJ_BMP ):
924 case( SGA_OBJ_ANIM ):
925 case( SGA_OBJ_INET ):
926 nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_STRING;
927 break;
929 case ( SGA_OBJ_SOUND ) :
930 nFormat = SGA_FORMAT_SOUND | SGA_FORMAT_STRING;
931 break;
933 case( SGA_OBJ_SVDRAW ):
934 nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_SVDRAW | SGA_FORMAT_STRING;
935 break;
937 default :
938 break;
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 );
945 break;
947 case( MN_PREVIEW ):
948 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
949 break;
951 case( MN_DELETE ):
953 if( !mpCurTheme->IsReadOnly() &&
954 QueryBox(NULL, WB_YES_NO, GAL_RESSTR(RID_SVXSTR_GALLERY_DELETEOBJ)).Execute() == RET_YES )
956 mpCurTheme->RemoveObject( mnCurActionPos );
959 break;
961 case( MN_TITLE ):
963 SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos );
965 if( pObj )
967 const String aOldTitle( GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_TITLE ) );
969 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
970 if(pFact)
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 );
989 delete aDlg;
993 break;
995 case( MN_COPYCLIPBOARD ):
997 Window* pWindow;
999 switch( GetMode() )
1001 case( GALLERYBROWSERMODE_ICON ): pWindow = (Window*) mpIconView; break;
1002 case( GALLERYBROWSERMODE_LIST ): pWindow = (Window*) mpListView; break;
1003 case( GALLERYBROWSERMODE_PREVIEW ): pWindow = (Window*) mpPreview; break;
1005 default:
1006 pWindow = NULL;
1007 break;
1010 mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos );
1012 break;
1014 case( MN_PASTECLIPBOARD ):
1016 if( !mpCurTheme->IsReadOnly() )
1018 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1019 mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos );
1022 break;
1024 default:
1025 break;
1030 String GalleryBrowser2::GetItemText( const GalleryTheme& rTheme, const SgaObject& rObj, sal_uIntPtr nItemTextFlags )
1032 String aRet;
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() );
1046 if( !aTitle.Len() )
1047 aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
1049 if( !aTitle.Len() )
1051 aTitle = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1052 aTitle = aTitle.GetToken( comphelper::string::getTokenCount(aTitle, '/') - 1, '/' );
1055 aRet += aTitle;
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 ) )
1068 aRet += ')';
1071 return aRet;
1074 INetURLObject GalleryBrowser2::GetURL() const
1076 INetURLObject aURL;
1078 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1079 aURL = mpCurTheme->GetObjectURL( mnCurActionPos );
1081 return aURL;
1084 String GalleryBrowser2::GetFilterName() const
1086 String aFilterName;
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 );
1103 return aFilterName;
1106 Graphic GalleryBrowser2::GetGraphic() const
1108 Graphic aGraphic;
1110 if( mpCurTheme && mnCurActionPos != 0xffffffff )
1111 mpCurTheme->GetGraphic( mnCurActionPos, aGraphic );
1113 return aGraphic;
1116 sal_Bool GalleryBrowser2::IsLinkage() const
1118 return mbCurActionIsLinkage;
1121 IMPL_LINK( GalleryBrowser2, MenuSelectHdl, Menu*, pMenu )
1123 if( pMenu )
1124 ImplExecute( pMenu->GetCurItemId() );
1126 return 0;
1129 IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectHdl)
1131 ImplUpdateInfoBar();
1132 return 0L;
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 );
1142 return 0L;
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() );
1164 Resize();
1166 return 0L;
1169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */