xref: /trunk/main/svx/source/gallery2/galbrws2.cxx (revision 65908a7e1f9ca9aa63df49ee1aa63f712b100da9)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <sot/formats.hxx>
29cdf0e10cSrcweir #include <vcl/msgbox.hxx>
30cdf0e10cSrcweir #include <svtools/valueset.hxx>
31cdf0e10cSrcweir #include <svl/urlbmk.hxx>
32cdf0e10cSrcweir #include <svl/stritem.hxx>
33cdf0e10cSrcweir #include <svl/intitem.hxx>
34cdf0e10cSrcweir #include <svl/eitem.hxx>
35cdf0e10cSrcweir #include <svtools/transfer.hxx>
36cdf0e10cSrcweir #include <sfx2/bindings.hxx>
37cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
38cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
39cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
40cdf0e10cSrcweir #include "svtools/filter.hxx"
41cdf0e10cSrcweir #include <editeng/brshitem.hxx>
42cdf0e10cSrcweir #include "helpid.hrc"
43cdf0e10cSrcweir #include "svx/gallery.hxx"
44cdf0e10cSrcweir #include "galobj.hxx"
45cdf0e10cSrcweir #include "svx/gallery1.hxx"
46cdf0e10cSrcweir #include "svx/galtheme.hxx"
47cdf0e10cSrcweir #include "svx/galctrl.hxx"
48cdf0e10cSrcweir #include "svx/galmisc.hxx"
49cdf0e10cSrcweir #include "galbrws2.hxx"
50cdf0e10cSrcweir #include "gallery.hrc"
51cdf0e10cSrcweir #include <vcl/svapp.hxx>
52cdf0e10cSrcweir #include <svx/fmmodel.hxx>
53cdf0e10cSrcweir #include <svx/dialmgr.hxx>
54cdf0e10cSrcweir #include <svx/svxdlg.hxx>
55cdf0e10cSrcweir #include <svx/dialogs.hrc>
56*65908a7eSAndre Fischer #include "GalleryControl.hxx"
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // -----------
59cdf0e10cSrcweir // - Defines -
60cdf0e10cSrcweir // -----------
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #undef GALLERY_USE_CLIPBOARD
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #define TBX_ID_ICON 1
65cdf0e10cSrcweir #define TBX_ID_LIST 2
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------
68cdf0e10cSrcweir // - statics -
69cdf0e10cSrcweir // -----------
70cdf0e10cSrcweir 
71cdf0e10cSrcweir GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // --------------------------
74cdf0e10cSrcweir // - GalleryBackgroundPopup -
75cdf0e10cSrcweir // --------------------------
76cdf0e10cSrcweir 
77cdf0e10cSrcweir class GalleryBackgroundPopup : public PopupMenu, public SfxControllerItem
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     const GalleryTheme* mpTheme;
80cdf0e10cSrcweir     sal_uIntPtr             mnObjectPos;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     virtual void        Select();
83cdf0e10cSrcweir     virtual void        StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir 
87cdf0e10cSrcweir                     GalleryBackgroundPopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos );
88cdf0e10cSrcweir                     ~GalleryBackgroundPopup();
89cdf0e10cSrcweir };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // ------------------------------------------------------------------------
92cdf0e10cSrcweir DBG_NAME(GalleryBackgroundPopup)
93cdf0e10cSrcweir 
94cdf0e10cSrcweir GalleryBackgroundPopup::GalleryBackgroundPopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos ) :
95cdf0e10cSrcweir             SfxControllerItem   ( SID_GALLERY_BG_BRUSH, SfxViewFrame::Current()->GetBindings() ),
96cdf0e10cSrcweir             mpTheme             ( pTheme ),
97cdf0e10cSrcweir             mnObjectPos         ( nObjectPos )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     DBG_CTOR(GalleryBackgroundPopup,NULL);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     SfxViewFrame::Current()->GetBindings().Update( SID_GALLERY_BG_BRUSH );
102cdf0e10cSrcweir     RemoveDisabledEntries();
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // ------------------------------------------------------------------------
106cdf0e10cSrcweir 
107cdf0e10cSrcweir GalleryBackgroundPopup::~GalleryBackgroundPopup()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     DBG_DTOR(GalleryBackgroundPopup,NULL);
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // ------------------------------------------------------------------------
114cdf0e10cSrcweir 
115cdf0e10cSrcweir void GalleryBackgroundPopup::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pItem )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     if ( ( nSID == SID_GALLERY_BG_BRUSH ) && pItem && ( eState != SFX_ITEM_DISABLED ) )
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         SfxStringListItem*  pStrLstItem;
120cdf0e10cSrcweir         SfxStringItem*      pStrItem;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         PopupMenu::Clear();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         if( ( pStrLstItem = PTR_CAST( SfxStringListItem, pItem ) ) != NULL )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             List* pList = pStrLstItem->GetList();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             if( pList )
129cdf0e10cSrcweir                 for ( sal_uIntPtr i = 0, nCount = pList->Count(); i < nCount; i++ )
130cdf0e10cSrcweir                     InsertItem( (sal_uInt16) i + 1, *(String*) pList->GetObject( i ) );
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         else if( ( pStrItem = PTR_CAST( SfxStringItem, pItem ) ) != NULL )
133cdf0e10cSrcweir             InsertItem( 1, pStrItem->GetValue() );
134cdf0e10cSrcweir         else
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             DBG_ERROR( "SgaBGPopup::StateChanged(...): Wrong item type!" );
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // ------------------------------------------------------------------------
142cdf0e10cSrcweir 
143cdf0e10cSrcweir void GalleryBackgroundPopup::Select()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     Menu::Select();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     const INetURLObject aURL( mpTheme->GetObjectURL( mnObjectPos ) );
148cdf0e10cSrcweir     const SvxBrushItem  aBrushItem( aURL.GetMainURL( INetURLObject::NO_DECODE ), String(), GPOS_TILED, SID_GALLERY_BG_BRUSH );
149cdf0e10cSrcweir     const SfxUInt16Item aPosItem( SID_GALLERY_BG_POS, GetCurItemId() - 1 );
150cdf0e10cSrcweir     const SfxStringItem aPathItem( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE ) );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_GALLERY_BG_BRUSH,
153cdf0e10cSrcweir                               SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
154cdf0e10cSrcweir                               &aBrushItem, &aPosItem, &aPathItem, 0L );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // ---------------------
158cdf0e10cSrcweir // - GalleryThemePopup -
159cdf0e10cSrcweir // ---------------------
160cdf0e10cSrcweir 
161cdf0e10cSrcweir class GalleryThemePopup : public PopupMenu, public SfxControllerItem
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     GalleryBackgroundPopup  maBackgroundPopup;
164cdf0e10cSrcweir     const GalleryTheme*     mpTheme;
165cdf0e10cSrcweir     sal_uIntPtr                 mnObjectPos;
166cdf0e10cSrcweir     sal_Bool                    mbPreview;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     virtual void            StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir public:
171cdf0e10cSrcweir 
172cdf0e10cSrcweir                             GalleryThemePopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos, sal_Bool bPreview );
173cdf0e10cSrcweir                             ~GalleryThemePopup();
174cdf0e10cSrcweir };
175cdf0e10cSrcweir 
176cdf0e10cSrcweir // ------------------------------------------------------------------------
177cdf0e10cSrcweir DBG_NAME(GalleryThemePopup)
178cdf0e10cSrcweir 
179cdf0e10cSrcweir GalleryThemePopup::GalleryThemePopup( const GalleryTheme* pTheme, sal_uIntPtr nObjectPos, sal_Bool bPreview ) :
180cdf0e10cSrcweir     PopupMenu           ( GAL_RESID( RID_SVXMN_GALLERY2 ) ),
181cdf0e10cSrcweir     SfxControllerItem   ( SID_GALLERY_ENABLE_ADDCOPY, SfxViewFrame::Current()->GetBindings() ),
182cdf0e10cSrcweir     maBackgroundPopup   ( pTheme, nObjectPos ),
183cdf0e10cSrcweir     mpTheme             ( pTheme ),
184cdf0e10cSrcweir     mnObjectPos         ( nObjectPos ),
185cdf0e10cSrcweir     mbPreview           ( bPreview )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     DBG_CTOR(GalleryThemePopup,NULL);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     const SgaObjKind    eObjKind = mpTheme->GetObjectKind( mnObjectPos );
190cdf0e10cSrcweir     PopupMenu*          pAddMenu = GetPopupMenu( MN_ADDMENU );
191cdf0e10cSrcweir     SfxBindings&        rBindings = SfxViewFrame::Current()->GetBindings();
192cdf0e10cSrcweir     INetURLObject       aURL;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     const_cast< GalleryTheme* >( mpTheme )->GetURL( mnObjectPos, aURL );
195cdf0e10cSrcweir     const sal_Bool bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     pAddMenu->EnableItem( MN_ADD, bValidURL && SGA_OBJ_SOUND != eObjKind );
198cdf0e10cSrcweir     pAddMenu->EnableItem( MN_ADD_LINK, bValidURL && SGA_OBJ_SVDRAW != eObjKind );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     EnableItem( MN_ADDMENU, pAddMenu->IsItemEnabled( MN_ADD ) || pAddMenu->IsItemEnabled( MN_ADD_LINK ) );
201cdf0e10cSrcweir     EnableItem( MN_PREVIEW, bValidURL );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     CheckItem( MN_PREVIEW, mbPreview );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         EnableItem( MN_DELETE, sal_False );
208cdf0e10cSrcweir         EnableItem( MN_TITLE, sal_False );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         if( mpTheme->IsReadOnly() )
211cdf0e10cSrcweir             EnableItem( MN_PASTECLIPBOARD, sal_False );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         if( !mpTheme->GetObjectCount() )
214cdf0e10cSrcweir             EnableItem( MN_COPYCLIPBOARD, sal_False );
215cdf0e10cSrcweir     }
216cdf0e10cSrcweir     else
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         EnableItem( MN_DELETE, !bPreview );
219cdf0e10cSrcweir         EnableItem( MN_TITLE, sal_True );
220cdf0e10cSrcweir         EnableItem( MN_COPYCLIPBOARD, sal_True );
221cdf0e10cSrcweir         EnableItem( MN_PASTECLIPBOARD, sal_True );
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir #ifdef GALLERY_USE_CLIPBOARD
225cdf0e10cSrcweir     if( IsItemEnabled( MN_PASTECLIPBOARD ) )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         TransferableDataHelper  aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
228cdf0e10cSrcweir         sal_Bool                    bEnable = sal_False;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         if( aDataHelper.GetFormatCount() )
231cdf0e10cSrcweir         {
232cdf0e10cSrcweir             if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) ||
233cdf0e10cSrcweir                 aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
234cdf0e10cSrcweir                 aDataHelper.HasFormat( FORMAT_FILE ) ||
235cdf0e10cSrcweir                 aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) ||
236cdf0e10cSrcweir                 aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) ||
237cdf0e10cSrcweir                 aDataHelper.HasFormat( FORMAT_BITMAP ) )
238cdf0e10cSrcweir             {
239cdf0e10cSrcweir                 bEnable = sal_True;
240cdf0e10cSrcweir             }
241cdf0e10cSrcweir         }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         if( !bEnable )
244cdf0e10cSrcweir             EnableItem( MN_PASTECLIPBOARD, sal_False );
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir #else
247cdf0e10cSrcweir     EnableItem( MN_COPYCLIPBOARD, sal_False );
248cdf0e10cSrcweir     EnableItem( MN_PASTECLIPBOARD, sal_False );
249cdf0e10cSrcweir #endif
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     if( !maBackgroundPopup.GetItemCount() || ( eObjKind == SGA_OBJ_SVDRAW ) || ( eObjKind == SGA_OBJ_SOUND ) )
252cdf0e10cSrcweir         pAddMenu->EnableItem( MN_BACKGROUND, sal_False );
253cdf0e10cSrcweir     else
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         pAddMenu->EnableItem( MN_BACKGROUND, sal_True );
256cdf0e10cSrcweir         pAddMenu->SetPopupMenu( MN_BACKGROUND, &maBackgroundPopup );
257cdf0e10cSrcweir     }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     rBindings.Update( SID_GALLERY_ENABLE_ADDCOPY );
260cdf0e10cSrcweir     RemoveDisabledEntries();
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir // ------------------------------------------------------------------------
264cdf0e10cSrcweir 
265cdf0e10cSrcweir GalleryThemePopup::~GalleryThemePopup()
266cdf0e10cSrcweir {
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     DBG_DTOR(GalleryThemePopup,NULL);
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir // ------------------------------------------------------------------------
272cdf0e10cSrcweir 
273cdf0e10cSrcweir void GalleryThemePopup::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pItem )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     if( ( nSID == SID_GALLERY_ENABLE_ADDCOPY ) && pItem && ( eState != SFX_ITEM_DISABLED ) )
276cdf0e10cSrcweir     {
277cdf0e10cSrcweir         SfxBoolItem*        pBoolItem = PTR_CAST( SfxBoolItem, pItem );
278cdf0e10cSrcweir         const SgaObjKind    eObjKind = mpTheme->GetObjectKind( mnObjectPos );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         DBG_ASSERT( pBoolItem || pBoolItem == 0, "SfxBoolItem erwartet!");
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         GetPopupMenu( MN_ADDMENU )->EnableItem( MN_ADD, pBoolItem->GetValue() && ( eObjKind != SGA_OBJ_SOUND ) );
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir // ------------------
287cdf0e10cSrcweir // - GalleryToolBox -
288cdf0e10cSrcweir // ------------------
289cdf0e10cSrcweir DBG_NAME(GalleryToolBox)
290cdf0e10cSrcweir 
291cdf0e10cSrcweir GalleryToolBox::GalleryToolBox( GalleryBrowser2* pParent ) :
292cdf0e10cSrcweir     ToolBox( pParent, WB_TABSTOP )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     DBG_CTOR(GalleryToolBox,NULL);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir // ------------------------------------------------------------------------
299cdf0e10cSrcweir 
300cdf0e10cSrcweir GalleryToolBox::~GalleryToolBox()
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     DBG_DTOR(GalleryToolBox,NULL);
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir // ------------------------------------------------------------------------
307cdf0e10cSrcweir 
308cdf0e10cSrcweir void GalleryToolBox::KeyInput( const KeyEvent& rKEvt )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     if( !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
311cdf0e10cSrcweir         ToolBox::KeyInput( rKEvt );
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir // -------------------
315cdf0e10cSrcweir // - GalleryBrowser2 -
316cdf0e10cSrcweir // -------------------
317cdf0e10cSrcweir DBG_NAME(GalleryBrowser2)
318cdf0e10cSrcweir 
31902c50d82SAndre Fischer GalleryBrowser2::GalleryBrowser2( Window* pParent, const ResId& rResId, Gallery* pGallery ) :
320cdf0e10cSrcweir     Control             ( pParent, rResId ),
321cdf0e10cSrcweir     mpGallery           ( pGallery ),
322cdf0e10cSrcweir     mpCurTheme          ( NULL ),
323cdf0e10cSrcweir     mpIconView          ( new GalleryIconView( this, NULL ) ),
324cdf0e10cSrcweir     mpListView          ( new GalleryListView( this, NULL ) ),
325cdf0e10cSrcweir     mpPreview           ( new GalleryPreview( this, NULL ) ),
326cdf0e10cSrcweir     maViewBox           ( this ),
327cdf0e10cSrcweir     maSeparator         ( this, WB_VERT ),
328cdf0e10cSrcweir     maInfoBar           ( this, WB_LEFT | WB_VCENTER ),
329cdf0e10cSrcweir     mnCurActionPos      ( 0xffffffff ),
330cdf0e10cSrcweir     meMode              ( GALLERYBROWSERMODE_NONE ),
331cdf0e10cSrcweir     meLastMode          ( GALLERYBROWSERMODE_NONE ),
332cdf0e10cSrcweir     mbCurActionIsLinkage( sal_False )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     DBG_CTOR(GalleryBrowser2,NULL);
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     Image       aDummyImage;
337cdf0e10cSrcweir     const Link  aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
338cdf0e10cSrcweir     Font        aInfoFont( maInfoBar.GetControlFont() );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir     maMiscOptions.AddListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     maViewBox.InsertItem( TBX_ID_ICON, aDummyImage );
343cdf0e10cSrcweir     maViewBox.SetItemBits( TBX_ID_ICON, TIB_RADIOCHECK | TIB_AUTOCHECK );
344cdf0e10cSrcweir     maViewBox.SetHelpId( TBX_ID_ICON, HID_GALLERY_ICONVIEW );
345cdf0e10cSrcweir     maViewBox.SetQuickHelpText( TBX_ID_ICON, String( GAL_RESID( RID_SVXSTR_GALLERY_ICONVIEW ) ) );
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     maViewBox.InsertItem( TBX_ID_LIST, aDummyImage );
348cdf0e10cSrcweir     maViewBox.SetItemBits( TBX_ID_LIST, TIB_RADIOCHECK | TIB_AUTOCHECK );
349cdf0e10cSrcweir     maViewBox.SetHelpId( TBX_ID_LIST, HID_GALLERY_LISTVIEW );
350cdf0e10cSrcweir     maViewBox.SetQuickHelpText( TBX_ID_LIST, String( GAL_RESID( RID_SVXSTR_GALLERY_LISTVIEW ) ) );
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     maViewBox.SetBorder( 0, 1 );
353cdf0e10cSrcweir     MiscHdl( NULL );
354cdf0e10cSrcweir     maViewBox.SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
355cdf0e10cSrcweir     maViewBox.Show();
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     mpIconView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
358cdf0e10cSrcweir     mpListView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     maInfoBar.Show();
361cdf0e10cSrcweir     maSeparator.Show();
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     mpIconView->SetSelectHdl( aSelectHdl );
364cdf0e10cSrcweir     mpListView->SetSelectHdl( aSelectHdl );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     InitSettings();
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     if(maInfoBar.GetText().Len() == 0)
371cdf0e10cSrcweir         mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
372cdf0e10cSrcweir     else
373cdf0e10cSrcweir         mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
374cdf0e10cSrcweir     mpIconView->SetAccessibleRelationMemberOf(mpIconView);
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir // -----------------------------------------------------------------------------
378cdf0e10cSrcweir 
379cdf0e10cSrcweir GalleryBrowser2::~GalleryBrowser2()
380cdf0e10cSrcweir {
381cdf0e10cSrcweir     maMiscOptions.RemoveListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     delete mpPreview;
384cdf0e10cSrcweir     delete mpListView;
385cdf0e10cSrcweir     delete mpIconView;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     if( mpCurTheme )
388cdf0e10cSrcweir         mpGallery->ReleaseTheme( mpCurTheme, *this );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     DBG_DTOR(GalleryBrowser2,NULL);
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir // -----------------------------------------------------------------------------
394cdf0e10cSrcweir 
395cdf0e10cSrcweir void GalleryBrowser2::InitSettings()
396cdf0e10cSrcweir {
397cdf0e10cSrcweir     Font  aInfoFont( maInfoBar.GetControlFont() );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     aInfoFont.SetWeight( WEIGHT_BOLD );
400cdf0e10cSrcweir     aInfoFont.SetColor( GALLERY_FG_COLOR );
401cdf0e10cSrcweir     maInfoBar.SetControlFont( aInfoFont );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     maInfoBar.SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
404cdf0e10cSrcweir     maInfoBar.SetControlBackground( GALLERY_DLG_COLOR );
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     maSeparator.SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
407cdf0e10cSrcweir     maSeparator.SetControlBackground( GALLERY_BG_COLOR );
408cdf0e10cSrcweir     maSeparator.SetControlForeground( GALLERY_FG_COLOR );
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir // -----------------------------------------------------------------------------
412cdf0e10cSrcweir 
413cdf0e10cSrcweir void GalleryBrowser2::DataChanged( const DataChangedEvent& rDCEvt )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
416cdf0e10cSrcweir         InitSettings();
417cdf0e10cSrcweir     else
418cdf0e10cSrcweir         Control::DataChanged( rDCEvt );
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir // -----------------------------------------------------------------------------
422cdf0e10cSrcweir 
423cdf0e10cSrcweir void GalleryBrowser2::Resize()
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     Control::Resize();
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     mpIconView->Hide();
428cdf0e10cSrcweir     mpListView->Hide();
429cdf0e10cSrcweir     mpPreview->Hide();
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     const Size  aOutSize( GetOutputSizePixel() );
432cdf0e10cSrcweir     const Size  aBoxSize( maViewBox.GetOutputSizePixel() );
433cdf0e10cSrcweir     const long  nOffset = 2, nSepWidth = 2;
434cdf0e10cSrcweir     const long  nInfoBarX = aBoxSize.Width() + ( nOffset * 3 ) + nSepWidth;
435cdf0e10cSrcweir     const Point aPt( 0, aBoxSize.Height() + 3 );
436cdf0e10cSrcweir     const Size  aSz( aOutSize.Width(), aOutSize.Height() - aPt.Y() );
437cdf0e10cSrcweir 
438cdf0e10cSrcweir     maSeparator.SetPosSizePixel( Point( aBoxSize.Width() + nOffset, 0 ), Size( nSepWidth, aBoxSize.Height() ) );
439cdf0e10cSrcweir     maInfoBar.SetPosSizePixel( Point( nInfoBarX, 0 ), Size( aOutSize.Width() - nInfoBarX, aBoxSize.Height() ) );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     mpIconView->SetPosSizePixel( aPt, aSz );
442cdf0e10cSrcweir     mpListView->SetPosSizePixel( aPt, aSz );
443cdf0e10cSrcweir     mpPreview->SetPosSizePixel( aPt, aSz );
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     switch( GetMode() )
446cdf0e10cSrcweir     {
447cdf0e10cSrcweir         case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
448cdf0e10cSrcweir         case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
449cdf0e10cSrcweir         case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
450cdf0e10cSrcweir 
451cdf0e10cSrcweir         default:
452cdf0e10cSrcweir         break;
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir // -----------------------------------------------------------------------------
457cdf0e10cSrcweir 
458cdf0e10cSrcweir void GalleryBrowser2::Notify( SfxBroadcaster&, const SfxHint& rHint )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir     const GalleryHint& rGalleryHint = (const GalleryHint&) rHint;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     switch( rGalleryHint.GetType() )
463cdf0e10cSrcweir     {
464cdf0e10cSrcweir         case( GALLERY_HINT_THEME_UPDATEVIEW ):
465cdf0e10cSrcweir         {
466cdf0e10cSrcweir             if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
467cdf0e10cSrcweir                 SetMode( meLastMode );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir             ImplUpdateViews( (sal_uInt16) rGalleryHint.GetData1() + 1 );
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir         break;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir         default:
474cdf0e10cSrcweir         break;
475cdf0e10cSrcweir     }
476cdf0e10cSrcweir }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir // -----------------------------------------------------------------------------
479cdf0e10cSrcweir 
480cdf0e10cSrcweir sal_Int8 GalleryBrowser2::AcceptDrop( DropTargetHelper& rTarget, const AcceptDropEvent& )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     sal_Int8 nRet = DND_ACTION_NONE;
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     if( mpCurTheme && !mpCurTheme->IsReadOnly() && !mpCurTheme ->IsImported() )
485cdf0e10cSrcweir     {
486cdf0e10cSrcweir         if( !mpCurTheme->IsDragging() )
487cdf0e10cSrcweir         {
488cdf0e10cSrcweir             if( rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING ) ||
489cdf0e10cSrcweir                 rTarget.IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) ||
490cdf0e10cSrcweir                 rTarget.IsDropFormatSupported( FORMAT_FILE ) ||
491cdf0e10cSrcweir                 rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB ) ||
492cdf0e10cSrcweir                 rTarget.IsDropFormatSupported( FORMAT_GDIMETAFILE ) ||
493cdf0e10cSrcweir                 rTarget.IsDropFormatSupported( FORMAT_BITMAP ) )
494cdf0e10cSrcweir             {
495cdf0e10cSrcweir                 nRet = DND_ACTION_COPY;
496cdf0e10cSrcweir             }
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir         else
499cdf0e10cSrcweir             nRet = DND_ACTION_COPY;
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     return nRet;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir // -----------------------------------------------------------------------------
506cdf0e10cSrcweir 
507cdf0e10cSrcweir sal_Int8 GalleryBrowser2::ExecuteDrop( DropTargetHelper&, const ExecuteDropEvent& rEvt )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     sal_Int8 nRet = DND_ACTION_NONE;
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     if( mpCurTheme )
512cdf0e10cSrcweir     {
513cdf0e10cSrcweir         Point       aSelPos;
514cdf0e10cSrcweir         const sal_uIntPtr nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos );
515cdf0e10cSrcweir         const sal_uIntPtr   nInsertPos = ( nItemId ? ( nItemId - 1 ) : LIST_APPEND );
516cdf0e10cSrcweir 
517cdf0e10cSrcweir         if( mpCurTheme->IsDragging() )
518cdf0e10cSrcweir             mpCurTheme->ChangeObjectPos( mpCurTheme->GetDragPos(), nInsertPos );
519cdf0e10cSrcweir         else
520cdf0e10cSrcweir             nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos );
521cdf0e10cSrcweir     }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     return nRet;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir // -----------------------------------------------------------------------------
527cdf0e10cSrcweir 
528cdf0e10cSrcweir void GalleryBrowser2::StartDrag( Window*, const Point* pDragPoint )
529cdf0e10cSrcweir {
530cdf0e10cSrcweir     if( mpCurTheme )
531cdf0e10cSrcweir     {
532cdf0e10cSrcweir         Point       aSelPos;
533cdf0e10cSrcweir         const sal_uIntPtr nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos );
534cdf0e10cSrcweir 
535cdf0e10cSrcweir         if( nItemId )
536cdf0e10cSrcweir             mpCurTheme->StartDrag( this, nItemId - 1 );
537cdf0e10cSrcweir     }
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir // -----------------------------------------------------------------------------
541cdf0e10cSrcweir 
542cdf0e10cSrcweir void GalleryBrowser2::TogglePreview( Window*, const Point* )
543cdf0e10cSrcweir {
544cdf0e10cSrcweir     SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
545cdf0e10cSrcweir     GetViewWindow()->GrabFocus();
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir // -----------------------------------------------------------------------------
549cdf0e10cSrcweir 
550cdf0e10cSrcweir void GalleryBrowser2::ShowContextMenu( Window*, const Point* pContextPoint )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir     Point       aSelPos;
553cdf0e10cSrcweir     const sal_uIntPtr nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos );
554cdf0e10cSrcweir 
555cdf0e10cSrcweir     if( mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() ) )
556cdf0e10cSrcweir     {
557cdf0e10cSrcweir         ImplSelectItemId( nItemId );
558cdf0e10cSrcweir 
559cdf0e10cSrcweir         SfxViewFrame* pCurrentViewFrame = SfxViewFrame::Current();
560cdf0e10cSrcweir         if ( pCurrentViewFrame )
561cdf0e10cSrcweir         {
562cdf0e10cSrcweir             SfxBindings& rBindings = pCurrentViewFrame->GetBindings();
563cdf0e10cSrcweir             rBindings.ENTERREGISTRATIONS();
564cdf0e10cSrcweir             GalleryThemePopup aMenu( mpCurTheme, nItemId - 1, GALLERYBROWSERMODE_PREVIEW == GetMode() );
565cdf0e10cSrcweir             rBindings.LEAVEREGISTRATIONS();
566cdf0e10cSrcweir             aMenu.SetSelectHdl( LINK( this, GalleryBrowser2, MenuSelectHdl ) );
567cdf0e10cSrcweir             aMenu.Execute( this, aSelPos  );
568cdf0e10cSrcweir         }
569cdf0e10cSrcweir     }
570cdf0e10cSrcweir }
571cdf0e10cSrcweir 
572cdf0e10cSrcweir // -----------------------------------------------------------------------------
573cdf0e10cSrcweir 
574cdf0e10cSrcweir sal_Bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, Window* pWindow )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     Point       aSelPos;
577cdf0e10cSrcweir     const sal_uIntPtr   nItemId = ImplGetSelectedItemId( NULL, aSelPos );
578*65908a7eSAndre Fischer     GalleryBrowser* pParentBrowser = dynamic_cast<GalleryBrowser*>(GetParent());
579*65908a7eSAndre Fischer     sal_Bool bRet = sal_False;
580*65908a7eSAndre Fischer     if (pParentBrowser != NULL)
581*65908a7eSAndre Fischer         bRet = pParentBrowser->KeyInput( rKEvt, pWindow );
582*65908a7eSAndre Fischer     else
583*65908a7eSAndre Fischer     {
584*65908a7eSAndre Fischer         svx::sidebar::GalleryControl* pParentControl = dynamic_cast<svx::sidebar::GalleryControl*>(GetParent());
585*65908a7eSAndre Fischer         if (pParentControl != NULL)
586*65908a7eSAndre Fischer             bRet = pParentControl->KeyInput(rKEvt, pWindow);
587*65908a7eSAndre Fischer     }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir     if( !bRet && !maViewBox.HasFocus() && nItemId && mpCurTheme )
590cdf0e10cSrcweir     {
591cdf0e10cSrcweir         sal_uInt16              nExecuteId = 0;
592cdf0e10cSrcweir         const SgaObjKind    eObjKind = mpCurTheme->GetObjectKind( nItemId - 1 );
593cdf0e10cSrcweir         INetURLObject       aURL;
594cdf0e10cSrcweir 
595cdf0e10cSrcweir         const_cast< GalleryTheme* >( mpCurTheme )->GetURL( nItemId - 1, aURL );
596cdf0e10cSrcweir 
597cdf0e10cSrcweir         const sal_Bool  bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID );
598cdf0e10cSrcweir         sal_Bool        bPreview = bValidURL;
599cdf0e10cSrcweir         sal_Bool        bAdd = bValidURL;
600cdf0e10cSrcweir         sal_Bool        bAddLink = ( bValidURL && SGA_OBJ_SVDRAW != eObjKind );
601cdf0e10cSrcweir         sal_Bool        bDelete = sal_False;
602cdf0e10cSrcweir         sal_Bool        bTitle = sal_False;
603cdf0e10cSrcweir 
604cdf0e10cSrcweir         if( !mpCurTheme->IsReadOnly() && mpCurTheme->GetObjectCount() )
605cdf0e10cSrcweir         {
606cdf0e10cSrcweir             bDelete = ( GALLERYBROWSERMODE_PREVIEW != GetMode() );
607cdf0e10cSrcweir             bTitle = sal_True;
608cdf0e10cSrcweir         }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir         switch( rKEvt.GetKeyCode().GetCode() )
611cdf0e10cSrcweir         {
612cdf0e10cSrcweir             case( KEY_SPACE ):
613cdf0e10cSrcweir             case( KEY_RETURN ):
614cdf0e10cSrcweir             case( KEY_P ):
615cdf0e10cSrcweir             {
616cdf0e10cSrcweir                 if( bPreview )
617cdf0e10cSrcweir                 {
618cdf0e10cSrcweir                     TogglePreview( pWindow );
619cdf0e10cSrcweir                     bRet = sal_True;
620cdf0e10cSrcweir                 }
621cdf0e10cSrcweir             }
622cdf0e10cSrcweir             break;
623cdf0e10cSrcweir 
624cdf0e10cSrcweir             case( KEY_INSERT ):
625cdf0e10cSrcweir             case( KEY_I ):
626cdf0e10cSrcweir             {
627cdf0e10cSrcweir                 if( bAddLink && rKEvt.GetKeyCode().IsShift() && rKEvt.GetKeyCode().IsMod1() )
628cdf0e10cSrcweir                     nExecuteId = MN_ADD_LINK;
629cdf0e10cSrcweir                 else if( bAdd )
630cdf0e10cSrcweir                     nExecuteId = MN_ADD;
631cdf0e10cSrcweir             }
632cdf0e10cSrcweir             break;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir             case( KEY_DELETE ):
635cdf0e10cSrcweir             case( KEY_D ):
636cdf0e10cSrcweir             {
637cdf0e10cSrcweir                 if( bDelete )
638cdf0e10cSrcweir                     nExecuteId = MN_DELETE;
639cdf0e10cSrcweir             }
640cdf0e10cSrcweir             break;
641cdf0e10cSrcweir 
642cdf0e10cSrcweir             case( KEY_T ):
643cdf0e10cSrcweir             {
644cdf0e10cSrcweir                 if( bTitle )
645cdf0e10cSrcweir                     nExecuteId = MN_TITLE;
646cdf0e10cSrcweir             }
647cdf0e10cSrcweir             break;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir             default:
650cdf0e10cSrcweir             break;
651cdf0e10cSrcweir         }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir         if( nExecuteId )
654cdf0e10cSrcweir         {
655cdf0e10cSrcweir             ImplExecute( nExecuteId );
656cdf0e10cSrcweir             bRet = sal_True;
657cdf0e10cSrcweir         }
658cdf0e10cSrcweir     }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir     return bRet;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir // -----------------------------------------------------------------------------
664cdf0e10cSrcweir 
665cdf0e10cSrcweir void GalleryBrowser2::SelectTheme( const String& rThemeName )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     delete mpIconView, mpIconView = NULL;
668cdf0e10cSrcweir     delete mpListView, mpListView = NULL;
669cdf0e10cSrcweir     delete mpPreview, mpPreview = NULL;
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     if( mpCurTheme )
672cdf0e10cSrcweir         mpGallery->ReleaseTheme( mpCurTheme, *this );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     mpCurTheme = mpGallery->AcquireTheme( rThemeName, *this );
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     mpIconView = new GalleryIconView( this, mpCurTheme );
677cdf0e10cSrcweir     mpListView = new GalleryListView( this, mpCurTheme );
678cdf0e10cSrcweir     mpPreview = new GalleryPreview( this, mpCurTheme );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     mpIconView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
681cdf0e10cSrcweir     mpListView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
682cdf0e10cSrcweir     mpPreview->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_PREVIEW ) ));
683cdf0e10cSrcweir 
684cdf0e10cSrcweir     const Link aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
685cdf0e10cSrcweir 
686cdf0e10cSrcweir     mpIconView->SetSelectHdl( aSelectHdl );
687cdf0e10cSrcweir     mpListView->SetSelectHdl( aSelectHdl );
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
690cdf0e10cSrcweir         meMode = meLastMode;
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     Resize();
693cdf0e10cSrcweir     ImplUpdateViews( 1 );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir     maViewBox.EnableItem( TBX_ID_ICON, sal_True );
696cdf0e10cSrcweir     maViewBox.EnableItem( TBX_ID_LIST, sal_True );
697cdf0e10cSrcweir     maViewBox.CheckItem( ( GALLERYBROWSERMODE_ICON == GetMode() ) ? TBX_ID_ICON : TBX_ID_LIST, sal_True );
698cdf0e10cSrcweir 
699cdf0e10cSrcweir     if(maInfoBar.GetText().Len() == 0)
700cdf0e10cSrcweir         mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
701cdf0e10cSrcweir     else
702cdf0e10cSrcweir         mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
703cdf0e10cSrcweir     mpIconView->SetAccessibleRelationMemberOf(mpIconView);
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir // -----------------------------------------------------------------------------
707cdf0e10cSrcweir 
708cdf0e10cSrcweir void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
709cdf0e10cSrcweir {
710cdf0e10cSrcweir     if( GetMode() != eMode )
711cdf0e10cSrcweir     {
712cdf0e10cSrcweir         meLastMode = GetMode();
713cdf0e10cSrcweir 
714cdf0e10cSrcweir         switch( eMode )
715cdf0e10cSrcweir         {
716cdf0e10cSrcweir             case( GALLERYBROWSERMODE_ICON ):
717cdf0e10cSrcweir             {
718cdf0e10cSrcweir                 mpListView->Hide();
719cdf0e10cSrcweir 
720cdf0e10cSrcweir                 mpPreview->Hide();
721cdf0e10cSrcweir                 mpPreview->SetGraphic( Graphic() );
722cdf0e10cSrcweir                 mpPreview->PreviewMedia( INetURLObject() );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir                 mpIconView->Show();
725cdf0e10cSrcweir 
726cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
727cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
728cdf0e10cSrcweir 
729cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_ICON, sal_True );
730cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_LIST, sal_False );
731cdf0e10cSrcweir             }
732cdf0e10cSrcweir             break;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir             case( GALLERYBROWSERMODE_LIST ):
735cdf0e10cSrcweir             {
736cdf0e10cSrcweir                 mpIconView->Hide();
737cdf0e10cSrcweir 
738cdf0e10cSrcweir                 mpPreview->Hide();
739cdf0e10cSrcweir                 mpPreview->SetGraphic( Graphic() );
740cdf0e10cSrcweir                 mpPreview->PreviewMedia( INetURLObject() );
741cdf0e10cSrcweir 
742cdf0e10cSrcweir                 mpListView->Show();
743cdf0e10cSrcweir 
744cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
745cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
746cdf0e10cSrcweir 
747cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_ICON, sal_False );
748cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_LIST, sal_True );
749cdf0e10cSrcweir             }
750cdf0e10cSrcweir             break;
751cdf0e10cSrcweir 
752cdf0e10cSrcweir             case( GALLERYBROWSERMODE_PREVIEW ):
753cdf0e10cSrcweir             {
754cdf0e10cSrcweir                 Graphic     aGraphic;
755cdf0e10cSrcweir                 Point       aSelPos;
756cdf0e10cSrcweir                 const sal_uIntPtr   nItemId = ImplGetSelectedItemId( NULL, aSelPos );
757cdf0e10cSrcweir 
758cdf0e10cSrcweir                 if( nItemId )
759cdf0e10cSrcweir                 {
760cdf0e10cSrcweir                     const sal_uIntPtr nPos = nItemId - 1;
761cdf0e10cSrcweir 
762cdf0e10cSrcweir                     mpIconView->Hide();
763cdf0e10cSrcweir                     mpListView->Hide();
764cdf0e10cSrcweir 
765cdf0e10cSrcweir                     if( mpCurTheme )
766cdf0e10cSrcweir                         mpCurTheme->GetGraphic( nPos, aGraphic );
767cdf0e10cSrcweir 
768cdf0e10cSrcweir                     mpPreview->SetGraphic( aGraphic );
769cdf0e10cSrcweir                     mpPreview->Show();
770cdf0e10cSrcweir 
771cdf0e10cSrcweir                     if( mpCurTheme && mpCurTheme->GetObjectKind( nPos ) == SGA_OBJ_SOUND )
772cdf0e10cSrcweir                         mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );
773cdf0e10cSrcweir 
774cdf0e10cSrcweir                     maViewBox.EnableItem( TBX_ID_ICON, sal_False );
775cdf0e10cSrcweir                     maViewBox.EnableItem( TBX_ID_LIST, sal_False );
776cdf0e10cSrcweir                 }
777cdf0e10cSrcweir             }
778cdf0e10cSrcweir             break;
779cdf0e10cSrcweir 
780cdf0e10cSrcweir             default:
781cdf0e10cSrcweir                 break;
782cdf0e10cSrcweir         }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir         GalleryBrowser2::meInitMode = meMode = eMode;
785cdf0e10cSrcweir     }
786cdf0e10cSrcweir }
787cdf0e10cSrcweir 
788cdf0e10cSrcweir // -----------------------------------------------------------------------------
789cdf0e10cSrcweir 
790cdf0e10cSrcweir Window* GalleryBrowser2::GetViewWindow() const
791cdf0e10cSrcweir {
792cdf0e10cSrcweir     Window* pRet;
793cdf0e10cSrcweir 
794cdf0e10cSrcweir     switch( GetMode() )
795cdf0e10cSrcweir     {
796cdf0e10cSrcweir         case( GALLERYBROWSERMODE_LIST ): pRet = mpListView; break;
797cdf0e10cSrcweir         case( GALLERYBROWSERMODE_PREVIEW ): pRet = mpPreview; break;
798cdf0e10cSrcweir 
799cdf0e10cSrcweir         default:
800cdf0e10cSrcweir             pRet = mpIconView;
801cdf0e10cSrcweir         break;
802cdf0e10cSrcweir     }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir     return pRet;
805cdf0e10cSrcweir }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir // -----------------------------------------------------------------------------
808cdf0e10cSrcweir 
809cdf0e10cSrcweir void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )
810cdf0e10cSrcweir {
811cdf0e10cSrcweir     if( mpCurTheme )
812cdf0e10cSrcweir     {
813cdf0e10cSrcweir         Point       aSelPos;
814cdf0e10cSrcweir         const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         if( nItemId )
817cdf0e10cSrcweir         {
818cdf0e10cSrcweir             sal_uIntPtr nNewItemId = nItemId;
819cdf0e10cSrcweir 
820cdf0e10cSrcweir             switch( eTravel )
821cdf0e10cSrcweir             {
822cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_FIRST ):     nNewItemId = 1; break;
823cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_LAST ):      nNewItemId = mpCurTheme->GetObjectCount(); break;
824cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_PREVIOUS ):  nNewItemId--; break;
825cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_NEXT ):      nNewItemId++; break;
826cdf0e10cSrcweir                 default:
827cdf0e10cSrcweir                     break;
828cdf0e10cSrcweir             }
829cdf0e10cSrcweir 
830cdf0e10cSrcweir             if( nNewItemId < 1 )
831cdf0e10cSrcweir                 nNewItemId = 1;
832cdf0e10cSrcweir             else if( nNewItemId > mpCurTheme->GetObjectCount() )
833cdf0e10cSrcweir                 nNewItemId = mpCurTheme->GetObjectCount();
834cdf0e10cSrcweir 
835cdf0e10cSrcweir             if( nNewItemId != nItemId )
836cdf0e10cSrcweir             {
837cdf0e10cSrcweir                 ImplSelectItemId( nNewItemId );
838cdf0e10cSrcweir                 ImplUpdateInfoBar();
839cdf0e10cSrcweir 
840cdf0e10cSrcweir                 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
841cdf0e10cSrcweir                 {
842cdf0e10cSrcweir                     Graphic     aGraphic;
843cdf0e10cSrcweir                     const sal_uIntPtr nPos = nNewItemId - 1;
844cdf0e10cSrcweir 
845cdf0e10cSrcweir                     mpCurTheme->GetGraphic( nPos, aGraphic );
846cdf0e10cSrcweir                     mpPreview->SetGraphic( aGraphic );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir                     if( SGA_OBJ_SOUND == mpCurTheme->GetObjectKind( nPos ) )
849cdf0e10cSrcweir                         mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );
850cdf0e10cSrcweir 
851cdf0e10cSrcweir                     mpPreview->Invalidate();
852cdf0e10cSrcweir                 }
853cdf0e10cSrcweir             }
854cdf0e10cSrcweir         }
855cdf0e10cSrcweir     }
856cdf0e10cSrcweir }
857cdf0e10cSrcweir 
858cdf0e10cSrcweir // -----------------------------------------------------------------------------
859cdf0e10cSrcweir 
860cdf0e10cSrcweir void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId )
861cdf0e10cSrcweir {
862cdf0e10cSrcweir     mpIconView->Hide();
863cdf0e10cSrcweir     mpListView->Hide();
864cdf0e10cSrcweir     mpPreview->Hide();
865cdf0e10cSrcweir 
866cdf0e10cSrcweir     mpIconView->Clear();
867cdf0e10cSrcweir     mpListView->Clear();
868cdf0e10cSrcweir 
869cdf0e10cSrcweir     if( mpCurTheme )
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir         for( sal_uIntPtr i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; )
872cdf0e10cSrcweir         {
873cdf0e10cSrcweir             mpListView->RowInserted( i++ );
874cdf0e10cSrcweir             mpIconView->InsertItem( (sal_uInt16) i );
875cdf0e10cSrcweir         }
876cdf0e10cSrcweir 
877cdf0e10cSrcweir         ImplSelectItemId( ( ( nSelectionId > mpCurTheme->GetObjectCount() ) ? mpCurTheme->GetObjectCount() : nSelectionId ) );
878cdf0e10cSrcweir     }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir     switch( GetMode() )
881cdf0e10cSrcweir     {
882cdf0e10cSrcweir         case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
883cdf0e10cSrcweir         case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
884cdf0e10cSrcweir         case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
885cdf0e10cSrcweir 
886cdf0e10cSrcweir         default:
887cdf0e10cSrcweir         break;
888cdf0e10cSrcweir     }
889cdf0e10cSrcweir 
890cdf0e10cSrcweir     ImplUpdateInfoBar();
891cdf0e10cSrcweir }
892cdf0e10cSrcweir 
893cdf0e10cSrcweir // -----------------------------------------------------------------------------
894cdf0e10cSrcweir 
895cdf0e10cSrcweir void GalleryBrowser2::ImplUpdateInfoBar()
896cdf0e10cSrcweir {
897cdf0e10cSrcweir     String aInfoText;
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     if( mpCurTheme )
900cdf0e10cSrcweir     {
901cdf0e10cSrcweir         Point       aSelPos;
902cdf0e10cSrcweir         const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
903cdf0e10cSrcweir 
904cdf0e10cSrcweir         if( nItemId )
905cdf0e10cSrcweir         {
906cdf0e10cSrcweir             const sal_uIntPtr nPos = nItemId - 1;
907cdf0e10cSrcweir 
908cdf0e10cSrcweir             aInfoText = mpCurTheme->GetName();
909cdf0e10cSrcweir 
910cdf0e10cSrcweir             if( nPos < mpCurTheme->GetObjectCount() )
911cdf0e10cSrcweir             {
912cdf0e10cSrcweir                 SgaObject* pObj = mpCurTheme->AcquireObject( nPos );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir                 if( pObj )
915cdf0e10cSrcweir                 {
916cdf0e10cSrcweir                     aInfoText = GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_THEMENAME | GALLERY_ITEM_TITLE | GALLERY_ITEM_PATH );
917cdf0e10cSrcweir                     mpCurTheme->ReleaseObject( pObj );
918cdf0e10cSrcweir                 }
919cdf0e10cSrcweir             }
920cdf0e10cSrcweir         }
921cdf0e10cSrcweir     }
922cdf0e10cSrcweir 
923cdf0e10cSrcweir     maInfoBar.SetText( aInfoText );
924cdf0e10cSrcweir }
925cdf0e10cSrcweir 
926cdf0e10cSrcweir // -----------------------------------------------------------------------------
927cdf0e10cSrcweir 
928cdf0e10cSrcweir sal_uIntPtr GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos )
929cdf0e10cSrcweir {
930cdf0e10cSrcweir     const Size  aOutputSizePixel( GetOutputSizePixel() );
931cdf0e10cSrcweir     sal_uIntPtr       nRet = 0;
932cdf0e10cSrcweir 
933cdf0e10cSrcweir     if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
934cdf0e10cSrcweir     {
935cdf0e10cSrcweir         nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mpIconView->GetSelectItemId() : ( mpListView->FirstSelectedRow() + 1 ) );
936cdf0e10cSrcweir 
937cdf0e10cSrcweir         if( pSelPos )
938cdf0e10cSrcweir             rSelPos = GetPointerPosPixel();
939cdf0e10cSrcweir         else
940cdf0e10cSrcweir             rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
941cdf0e10cSrcweir     }
942cdf0e10cSrcweir     else if( GALLERYBROWSERMODE_ICON == GetMode() )
943cdf0e10cSrcweir     {
944cdf0e10cSrcweir         if( pSelPos )
945cdf0e10cSrcweir         {
946cdf0e10cSrcweir             nRet = mpIconView->GetItemId( *pSelPos );
947cdf0e10cSrcweir             rSelPos = GetPointerPosPixel();
948cdf0e10cSrcweir         }
949cdf0e10cSrcweir         else
950cdf0e10cSrcweir         {
951cdf0e10cSrcweir             nRet = mpIconView->GetSelectItemId();
952cdf0e10cSrcweir             rSelPos = mpIconView->GetItemRect( (sal_uInt16) nRet ).Center();
953cdf0e10cSrcweir         }
954cdf0e10cSrcweir     }
955cdf0e10cSrcweir     else
956cdf0e10cSrcweir     {
957cdf0e10cSrcweir         if( pSelPos )
958cdf0e10cSrcweir         {
959cdf0e10cSrcweir             nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1;
960cdf0e10cSrcweir             rSelPos = GetPointerPosPixel();
961cdf0e10cSrcweir         }
962cdf0e10cSrcweir         else
963cdf0e10cSrcweir         {
964cdf0e10cSrcweir             nRet = mpListView->FirstSelectedRow() + 1;
965cdf0e10cSrcweir             rSelPos = mpListView->GetFieldRectPixel( (sal_uInt16) nRet, 1 ).Center();
966cdf0e10cSrcweir         }
967cdf0e10cSrcweir     }
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     rSelPos.X() = Max( Min( rSelPos.X(), aOutputSizePixel.Width() - 1L ), 0L );
970cdf0e10cSrcweir     rSelPos.Y() = Max( Min( rSelPos.Y(), aOutputSizePixel.Height() - 1L ), 0L );
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     if( nRet && ( !mpCurTheme || ( nRet > mpCurTheme->GetObjectCount() ) ) )
973cdf0e10cSrcweir     {
974cdf0e10cSrcweir         nRet = 0;
975cdf0e10cSrcweir     }
976cdf0e10cSrcweir 
977cdf0e10cSrcweir     return nRet;
978cdf0e10cSrcweir }
979cdf0e10cSrcweir 
980cdf0e10cSrcweir // -----------------------------------------------------------------------------
981cdf0e10cSrcweir 
982cdf0e10cSrcweir void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId )
983cdf0e10cSrcweir {
984cdf0e10cSrcweir     if( nItemId )
985cdf0e10cSrcweir     {
986cdf0e10cSrcweir 
987cdf0e10cSrcweir         mpIconView->SelectItem( (sal_uInt16) nItemId );
988cdf0e10cSrcweir         mpListView->SelectRow( nItemId - 1 );
989cdf0e10cSrcweir     }
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir // -----------------------------------------------------------------------------
993cdf0e10cSrcweir 
994cdf0e10cSrcweir void GalleryBrowser2::ImplExecute( sal_uInt16 nId )
995cdf0e10cSrcweir {
996cdf0e10cSrcweir     Point       aSelPos;
997cdf0e10cSrcweir     const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
998cdf0e10cSrcweir 
999cdf0e10cSrcweir     if( mpCurTheme && nItemId )
1000cdf0e10cSrcweir     {
1001cdf0e10cSrcweir         mnCurActionPos = nItemId - 1;
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir         switch( nId )
1004cdf0e10cSrcweir         {
1005cdf0e10cSrcweir             case( MN_ADD ):
1006cdf0e10cSrcweir             case( MN_ADD_LINK ):
1007cdf0e10cSrcweir             {
1008cdf0e10cSrcweir                 sal_uInt32 nFormat = 0;
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir                 mbCurActionIsLinkage = ( MN_ADD_LINK == nId );
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir                 switch( mpCurTheme->GetObjectKind( mnCurActionPos ) )
1013cdf0e10cSrcweir                 {
1014cdf0e10cSrcweir                     case( SGA_OBJ_BMP ):
1015cdf0e10cSrcweir                     case( SGA_OBJ_ANIM ):
1016cdf0e10cSrcweir                     case( SGA_OBJ_INET ):
1017cdf0e10cSrcweir                         nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_STRING;
1018cdf0e10cSrcweir                     break;
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir                     case ( SGA_OBJ_SOUND ) :
1021cdf0e10cSrcweir                         nFormat = SGA_FORMAT_SOUND | SGA_FORMAT_STRING;
1022cdf0e10cSrcweir                     break;
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir                     case( SGA_OBJ_SVDRAW ):
1025cdf0e10cSrcweir                         nFormat = SGA_FORMAT_GRAPHIC | SGA_FORMAT_SVDRAW | SGA_FORMAT_STRING;
1026cdf0e10cSrcweir                     break;
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir                     default :
1029cdf0e10cSrcweir                     break;
1030cdf0e10cSrcweir                 }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir                 const SfxUInt32Item aItem( SID_GALLERY_FORMATS, nFormat );
1033cdf0e10cSrcweir                 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute(
1034cdf0e10cSrcweir                     SID_GALLERY_FORMATS, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
1035cdf0e10cSrcweir             }
1036cdf0e10cSrcweir             break;
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir             case( MN_PREVIEW ):
1039cdf0e10cSrcweir                 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
1040cdf0e10cSrcweir             break;
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir             case( MN_DELETE ):
1043cdf0e10cSrcweir             {
1044cdf0e10cSrcweir                 if( !mpCurTheme->IsReadOnly() &&
1045cdf0e10cSrcweir                     QueryBox( NULL, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETEOBJ ) ) ).Execute() == RET_YES )
1046cdf0e10cSrcweir                 {
1047cdf0e10cSrcweir                     mpCurTheme->RemoveObject( mnCurActionPos );
1048cdf0e10cSrcweir                 }
1049cdf0e10cSrcweir             }
1050cdf0e10cSrcweir             break;
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir             case( MN_TITLE ):
1053cdf0e10cSrcweir             {
1054cdf0e10cSrcweir                 SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos );
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir                 if( pObj )
1057cdf0e10cSrcweir                 {
1058cdf0e10cSrcweir                     const String    aOldTitle( GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_TITLE ) );
1059cdf0e10cSrcweir                     //CHINA001 TitleDialog      aDlg( this, aOldTitle );
1060cdf0e10cSrcweir                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1061cdf0e10cSrcweir                     if(pFact)
1062cdf0e10cSrcweir                     {
1063cdf0e10cSrcweir                         AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldTitle );
1064cdf0e10cSrcweir                         DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
1065cdf0e10cSrcweir                         if( aDlg->Execute() == RET_OK )//CHINA001 if( aDlg.Execute() == RET_OK )
1066cdf0e10cSrcweir                         {
1067cdf0e10cSrcweir                             String aNewTitle( aDlg->GetTitle() );//CHINA001 String aNewTitle( aDlg.GetTitle() );
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir                             if( ( !aNewTitle.Len() && pObj->GetTitle().Len() ) || ( aNewTitle != aOldTitle ) )
1070cdf0e10cSrcweir                             {
1071cdf0e10cSrcweir                                 if( !aNewTitle.Len() )
1072cdf0e10cSrcweir                                     aNewTitle = String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) );
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir                                 pObj->SetTitle( aNewTitle );
1075cdf0e10cSrcweir                                 mpCurTheme->InsertObject( *pObj );
1076cdf0e10cSrcweir                             }
1077cdf0e10cSrcweir                         }
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir                         mpCurTheme->ReleaseObject( pObj );
1080cdf0e10cSrcweir                         delete aDlg; //add CHINA001
1081cdf0e10cSrcweir                     }
1082cdf0e10cSrcweir                 }
1083cdf0e10cSrcweir             }
1084cdf0e10cSrcweir             break;
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir             case( MN_COPYCLIPBOARD ):
1087cdf0e10cSrcweir             {
1088cdf0e10cSrcweir                 Window* pWindow;
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir                 switch( GetMode() )
1091cdf0e10cSrcweir                 {
1092cdf0e10cSrcweir                     case( GALLERYBROWSERMODE_ICON ): pWindow = (Window*) mpIconView; break;
1093cdf0e10cSrcweir                     case( GALLERYBROWSERMODE_LIST ): pWindow = (Window*) mpListView; break;
1094cdf0e10cSrcweir                     case( GALLERYBROWSERMODE_PREVIEW ): pWindow = (Window*) mpPreview; break;
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir                     default:
1097cdf0e10cSrcweir                         pWindow = NULL;
1098cdf0e10cSrcweir                     break;
1099cdf0e10cSrcweir                 }
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir                 mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos );
1102cdf0e10cSrcweir             }
1103cdf0e10cSrcweir             break;
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir             case( MN_PASTECLIPBOARD ):
1106cdf0e10cSrcweir             {
1107cdf0e10cSrcweir                 if( !mpCurTheme->IsReadOnly() )
1108cdf0e10cSrcweir                 {
1109cdf0e10cSrcweir                     TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1110cdf0e10cSrcweir                     mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos );
1111cdf0e10cSrcweir                 }
1112cdf0e10cSrcweir             }
1113cdf0e10cSrcweir             break;
1114cdf0e10cSrcweir 
1115cdf0e10cSrcweir             default:
1116cdf0e10cSrcweir             break;
1117cdf0e10cSrcweir         }
1118cdf0e10cSrcweir     }
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir // -----------------------------------------------------------------------------
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir String GalleryBrowser2::GetItemText( const GalleryTheme& rTheme, const SgaObject& rObj, sal_uIntPtr nItemTextFlags )
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir     INetURLObject   aURL;
1126cdf0e10cSrcweir     String          aRet;
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir     if( rTheme.IsImported() )
1129cdf0e10cSrcweir     {
1130cdf0e10cSrcweir         aURL = rTheme.GetParent()->GetImportURL( rTheme.GetName() );
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir         aURL.removeSegment();
1133cdf0e10cSrcweir         aURL.Append( rObj.GetURL().GetName() );
1134cdf0e10cSrcweir     }
1135cdf0e10cSrcweir     else
1136cdf0e10cSrcweir         aURL = rObj.GetURL();
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir     if( nItemTextFlags & GALLERY_ITEM_THEMENAME )
1139cdf0e10cSrcweir     {
1140cdf0e10cSrcweir         aRet += rTheme.GetName();
1141cdf0e10cSrcweir         aRet += String( RTL_CONSTASCII_USTRINGPARAM( " - " ) );
1142cdf0e10cSrcweir     }
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir     if( nItemTextFlags & GALLERY_ITEM_TITLE )
1145cdf0e10cSrcweir     {
1146cdf0e10cSrcweir         String aTitle( rObj.GetTitle() );
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir         if( !aTitle.Len() )
1149cdf0e10cSrcweir             aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir         if( !aTitle.Len() )
1152cdf0e10cSrcweir         {
1153cdf0e10cSrcweir             aTitle = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1154cdf0e10cSrcweir             aTitle = aTitle.GetToken( aTitle.GetTokenCount( '/' ) - 1, '/' );
1155cdf0e10cSrcweir         }
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir         aRet += aTitle;
1158cdf0e10cSrcweir     }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir     if( nItemTextFlags & GALLERY_ITEM_PATH )
1161cdf0e10cSrcweir     {
1162cdf0e10cSrcweir         const String aPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir         if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) )
1165cdf0e10cSrcweir             aRet += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir         aRet += String(aURL.getFSysPath( INetURLObject::FSYS_DETECT ));
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir         if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) )
1170cdf0e10cSrcweir             aRet += ')';
1171cdf0e10cSrcweir     }
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir     return aRet;
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir // -----------------------------------------------------------------------------
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir INetURLObject GalleryBrowser2::GetURL() const
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir     INetURLObject aURL;
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir     if( mpCurTheme && mnCurActionPos != 0xffffffff )
1183cdf0e10cSrcweir         aURL = mpCurTheme->GetObjectURL( mnCurActionPos );
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir     return aURL;
1186cdf0e10cSrcweir }
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir // -----------------------------------------------------------------------------
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir String GalleryBrowser2::GetFilterName() const
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir     String aFilterName;
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir     if( mpCurTheme && mnCurActionPos != 0xffffffff )
1195cdf0e10cSrcweir     {
1196cdf0e10cSrcweir         const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( mnCurActionPos );
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir         if( ( SGA_OBJ_BMP == eObjKind ) || ( SGA_OBJ_ANIM == eObjKind ) )
1199cdf0e10cSrcweir         {
1200cdf0e10cSrcweir             GraphicFilter*      pFilter = GraphicFilter::GetGraphicFilter();
1201cdf0e10cSrcweir             INetURLObject       aURL; mpCurTheme->GetURL( mnCurActionPos, aURL );
1202cdf0e10cSrcweir             sal_uInt16          nFilter = pFilter->GetImportFormatNumberForShortName( aURL.GetExtension() );
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir             if( GRFILTER_FORMAT_DONTKNOW != nFilter )
1205cdf0e10cSrcweir                 aFilterName = pFilter->GetImportFormatName( nFilter );
1206cdf0e10cSrcweir         }
1207cdf0e10cSrcweir     }
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir     return aFilterName;
1210cdf0e10cSrcweir }
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir // -----------------------------------------------------------------------------
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir Graphic GalleryBrowser2::GetGraphic() const
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir     Graphic aGraphic;
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir     if( mpCurTheme && mnCurActionPos != 0xffffffff )
1219cdf0e10cSrcweir         mpCurTheme->GetGraphic( mnCurActionPos, aGraphic );
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir     return aGraphic;
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir // -----------------------------------------------------------------------------
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir sal_Bool GalleryBrowser2::GetVCDrawModel( FmFormModel& rModel ) const
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir     sal_Bool bRet = sal_False;
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir     if( mpCurTheme && mnCurActionPos != 0xffffffff )
1231cdf0e10cSrcweir         bRet = mpCurTheme->GetModel( mnCurActionPos, rModel );
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir     return bRet;
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir // -----------------------------------------------------------------------------
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir sal_Bool GalleryBrowser2::IsLinkage() const
1239cdf0e10cSrcweir {
1240cdf0e10cSrcweir     return mbCurActionIsLinkage;
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir // -----------------------------------------------------------------------------
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, MenuSelectHdl, Menu*, pMenu )
1246cdf0e10cSrcweir {
1247cdf0e10cSrcweir     if( pMenu )
1248cdf0e10cSrcweir         ImplExecute( pMenu->GetCurItemId() );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     return 0;
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir // -----------------------------------------------------------------------------
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, SelectObjectHdl, void*, EMPTYARG )
1256cdf0e10cSrcweir {
1257cdf0e10cSrcweir     ImplUpdateInfoBar();
1258cdf0e10cSrcweir     return 0L;
1259cdf0e10cSrcweir }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir // -----------------------------------------------------------------------------
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, SelectTbxHdl, ToolBox*, pBox )
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir     if( pBox->GetCurItemId() == TBX_ID_ICON )
1266cdf0e10cSrcweir         SetMode( GALLERYBROWSERMODE_ICON );
1267cdf0e10cSrcweir     else if( pBox->GetCurItemId() == TBX_ID_LIST )
1268cdf0e10cSrcweir         SetMode( GALLERYBROWSERMODE_LIST );
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir     return 0L;
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir // -----------------------------------------------------------------------------
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, MiscHdl, void*, EMPTYARG )
1276cdf0e10cSrcweir {
1277cdf0e10cSrcweir     const sal_Bool  bHC = maViewBox.GetSettings().GetStyleSettings().GetHighContrastMode();
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir     maViewBox.SetOutStyle( maMiscOptions.GetToolboxStyle() );
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir     BitmapEx aIconBmpEx = BitmapEx( Image( GAL_RESID( bHC? RID_SVXIMG_GALLERY_VIEW_ICON_HC : RID_SVXIMG_GALLERY_VIEW_ICON ) ).GetBitmapEx() );
1282cdf0e10cSrcweir     BitmapEx aListBmpEx = BitmapEx( Image( GAL_RESID( bHC? RID_SVXIMG_GALLERY_VIEW_LIST_HC : RID_SVXIMG_GALLERY_VIEW_LIST ) ).GetBitmapEx() );
1283cdf0e10cSrcweir 
1284cdf0e10cSrcweir     if( maMiscOptions.AreCurrentSymbolsLarge() )
1285cdf0e10cSrcweir     {
1286cdf0e10cSrcweir         const Size aLargeSize( 24, 24);
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir         aIconBmpEx.Scale( aLargeSize );
1289cdf0e10cSrcweir         aListBmpEx.Scale( aLargeSize );
1290cdf0e10cSrcweir     }
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir     maViewBox.SetItemImage( TBX_ID_ICON, aIconBmpEx );
1293cdf0e10cSrcweir     maViewBox.SetItemImage( TBX_ID_LIST, aListBmpEx );
1294cdf0e10cSrcweir     maViewBox.SetSizePixel( maViewBox.CalcWindowSizePixel() );
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir     Resize();
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir     return 0L;
1299cdf0e10cSrcweir }
1300