xref: /aoo41x/main/svx/source/gallery2/galbrws2.cxx (revision 9afceb33)
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
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
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.
19f6e50924SAndrew Rist  *
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>
5665908a7eSAndre Fischer #include "GalleryControl.hxx"
57cdf0e10cSrcweir 
58*9afceb33SAriel Constenla-Haile #include <svx/svxcommands.h>
59*9afceb33SAriel Constenla-Haile #include <svx/galleryitem.hxx>
60*9afceb33SAriel Constenla-Haile #include <comphelper/processfactory.hxx>
61*9afceb33SAriel Constenla-Haile #include <com/sun/star/frame/FrameSearchFlag.hpp>
62*9afceb33SAriel Constenla-Haile #include <com/sun/star/gallery/GalleryItemType.hpp>
63*9afceb33SAriel Constenla-Haile #include <com/sun/star/graphic/XGraphic.hpp>
64*9afceb33SAriel Constenla-Haile #include <com/sun/star/style/GraphicLocation.hpp>
65*9afceb33SAriel Constenla-Haile #include <map>
66*9afceb33SAriel Constenla-Haile 
67cdf0e10cSrcweir // -----------
68cdf0e10cSrcweir // - Defines -
69cdf0e10cSrcweir // -----------
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #undef GALLERY_USE_CLIPBOARD
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #define TBX_ID_ICON 1
74cdf0e10cSrcweir #define TBX_ID_LIST 2
75cdf0e10cSrcweir 
76*9afceb33SAriel Constenla-Haile #define C2U( cstr ) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(cstr)))
77*9afceb33SAriel Constenla-Haile 
78*9afceb33SAriel Constenla-Haile namespace css = ::com::sun::star;
79*9afceb33SAriel Constenla-Haile using rtl::OUString;
80*9afceb33SAriel Constenla-Haile 
81cdf0e10cSrcweir // -----------
82cdf0e10cSrcweir // - statics -
83cdf0e10cSrcweir // -----------
84cdf0e10cSrcweir 
85cdf0e10cSrcweir GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON;
86cdf0e10cSrcweir 
87*9afceb33SAriel Constenla-Haile struct DispatchInfo
88cdf0e10cSrcweir {
89*9afceb33SAriel Constenla-Haile     css::util::URL                                  TargetURL;
90*9afceb33SAriel Constenla-Haile     css::uno::Sequence< css::beans::PropertyValue > Arguments;
91*9afceb33SAriel Constenla-Haile     css::uno::Reference< css::frame::XDispatch >    Dispatch;
92cdf0e10cSrcweir };
93cdf0e10cSrcweir 
IMPL_STATIC_LINK_NOINSTANCE(GalleryBrowser2,AsyncDispatch_Impl,DispatchInfo *,pDispatchInfo)94*9afceb33SAriel Constenla-Haile IMPL_STATIC_LINK_NOINSTANCE( GalleryBrowser2, AsyncDispatch_Impl, DispatchInfo*, pDispatchInfo )
95cdf0e10cSrcweir {
96*9afceb33SAriel Constenla-Haile     if ( pDispatchInfo && pDispatchInfo->Dispatch.is() )
97*9afceb33SAriel Constenla-Haile     {
98*9afceb33SAriel Constenla-Haile         try
99*9afceb33SAriel Constenla-Haile         {
100*9afceb33SAriel Constenla-Haile             pDispatchInfo->Dispatch->dispatch( pDispatchInfo->TargetURL,
101*9afceb33SAriel Constenla-Haile                                                pDispatchInfo->Arguments );
102*9afceb33SAriel Constenla-Haile         }
103*9afceb33SAriel Constenla-Haile         catch ( const css::uno::Exception& )
104*9afceb33SAriel Constenla-Haile         {
105*9afceb33SAriel Constenla-Haile         }
106*9afceb33SAriel Constenla-Haile     }
107cdf0e10cSrcweir 
108*9afceb33SAriel Constenla-Haile     delete pDispatchInfo;
109*9afceb33SAriel Constenla-Haile     return 0;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112*9afceb33SAriel Constenla-Haile namespace
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 
115*9afceb33SAriel Constenla-Haile struct CommandInfo
116*9afceb33SAriel Constenla-Haile {
117*9afceb33SAriel Constenla-Haile     css::util::URL                               URL;
118*9afceb33SAriel Constenla-Haile     css::uno::Reference< css::frame::XDispatch > Dispatch;
119cdf0e10cSrcweir 
CommandInfo__anonaf11f73c0111::CommandInfo120*9afceb33SAriel Constenla-Haile     CommandInfo( const OUString &rURL )
121*9afceb33SAriel Constenla-Haile     {
122*9afceb33SAriel Constenla-Haile         URL.Complete = rURL;
123*9afceb33SAriel Constenla-Haile     }
124*9afceb33SAriel Constenla-Haile };
125cdf0e10cSrcweir 
126*9afceb33SAriel Constenla-Haile class GalleryThemePopup : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
127cdf0e10cSrcweir {
128*9afceb33SAriel Constenla-Haile private:
129*9afceb33SAriel Constenla-Haile     const GalleryTheme* mpTheme;
130*9afceb33SAriel Constenla-Haile     sal_uIntPtr         mnObjectPos;
131*9afceb33SAriel Constenla-Haile     sal_Bool            mbPreview;
132*9afceb33SAriel Constenla-Haile     PopupMenu           maPopupMenu;
133*9afceb33SAriel Constenla-Haile     PopupMenu           maBackgroundPopup;
134*9afceb33SAriel Constenla-Haile     GalleryBrowser2*    mpBrowser;
135*9afceb33SAriel Constenla-Haile 
136*9afceb33SAriel Constenla-Haile     typedef std::map< int, CommandInfo > CommandInfoMap;
137*9afceb33SAriel Constenla-Haile     CommandInfoMap   m_aCommandInfo;
138*9afceb33SAriel Constenla-Haile 
139*9afceb33SAriel Constenla-Haile     void Execute( const CommandInfo &rCmdInfo,
140*9afceb33SAriel Constenla-Haile                   const css::uno::Sequence< css::beans::PropertyValue > &rArguments );
141*9afceb33SAriel Constenla-Haile 
142*9afceb33SAriel Constenla-Haile     DECL_LINK( MenuSelectHdl, Menu* pMenu );
143*9afceb33SAriel Constenla-Haile     DECL_LINK( BackgroundMenuSelectHdl, Menu* pMenu );
144*9afceb33SAriel Constenla-Haile public:
145*9afceb33SAriel Constenla-Haile     GalleryThemePopup( const GalleryTheme* pTheme,
146*9afceb33SAriel Constenla-Haile                        sal_uIntPtr nObjectPos,
147*9afceb33SAriel Constenla-Haile                        sal_Bool bPreview,
148*9afceb33SAriel Constenla-Haile                        GalleryBrowser2* pBrowser );
149*9afceb33SAriel Constenla-Haile     ~GalleryThemePopup();
150cdf0e10cSrcweir 
151*9afceb33SAriel Constenla-Haile     void ExecutePopup( Window *pParent, const ::Point &aPos );
152cdf0e10cSrcweir 
153*9afceb33SAriel Constenla-Haile     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent &rEvent) throw ( css::uno::RuntimeException );
154*9afceb33SAriel Constenla-Haile     virtual void SAL_CALL disposing( const css::lang::EventObject &rSource) throw ( css::uno::RuntimeException );
155*9afceb33SAriel Constenla-Haile };
156cdf0e10cSrcweir 
DBG_NAME(GalleryThemePopup)157*9afceb33SAriel Constenla-Haile DBG_NAME(GalleryThemePopup)
158cdf0e10cSrcweir 
159*9afceb33SAriel Constenla-Haile GalleryThemePopup::GalleryThemePopup(
160*9afceb33SAriel Constenla-Haile     const GalleryTheme* pTheme,
161*9afceb33SAriel Constenla-Haile     sal_uIntPtr nObjectPos,
162*9afceb33SAriel Constenla-Haile     sal_Bool bPreview,
163*9afceb33SAriel Constenla-Haile     GalleryBrowser2* pBrowser )
164*9afceb33SAriel Constenla-Haile     : mpTheme( pTheme )
165*9afceb33SAriel Constenla-Haile     , mnObjectPos( nObjectPos )
166*9afceb33SAriel Constenla-Haile     , mbPreview( bPreview )
167*9afceb33SAriel Constenla-Haile     , maPopupMenu( GAL_RESID( RID_SVXMN_GALLERY2 ) )
168*9afceb33SAriel Constenla-Haile     , maBackgroundPopup()
169*9afceb33SAriel Constenla-Haile     , mpBrowser( pBrowser )
170cdf0e10cSrcweir {
171*9afceb33SAriel Constenla-Haile     DBG_CTOR(GalleryThemePopup,NULL);
172cdf0e10cSrcweir 
173*9afceb33SAriel Constenla-Haile     // SID_GALLERY_ENABLE_ADDCOPY
174*9afceb33SAriel Constenla-Haile     m_aCommandInfo.insert(
175*9afceb33SAriel Constenla-Haile         CommandInfoMap::value_type(
176*9afceb33SAriel Constenla-Haile             SID_GALLERY_ENABLE_ADDCOPY,
177*9afceb33SAriel Constenla-Haile             CommandInfo( C2U(CMD_SID_GALLERY_ENABLE_ADDCOPY ))));
178*9afceb33SAriel Constenla-Haile     // SID_GALLERY_BG_BRUSH
179*9afceb33SAriel Constenla-Haile     m_aCommandInfo.insert(
180*9afceb33SAriel Constenla-Haile         CommandInfoMap::value_type(
181*9afceb33SAriel Constenla-Haile             SID_GALLERY_BG_BRUSH,
182*9afceb33SAriel Constenla-Haile             CommandInfo(C2U(CMD_SID_GALLERY_BG_BRUSH ))));
183*9afceb33SAriel Constenla-Haile     // SID_GALLERY_FORMATS
184*9afceb33SAriel Constenla-Haile     m_aCommandInfo.insert(
185*9afceb33SAriel Constenla-Haile         CommandInfoMap::value_type(
186*9afceb33SAriel Constenla-Haile             SID_GALLERY_FORMATS,
187*9afceb33SAriel Constenla-Haile             CommandInfo(C2U(CMD_SID_GALLERY_FORMATS ))));
188cdf0e10cSrcweir 
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
~GalleryThemePopup()191*9afceb33SAriel Constenla-Haile GalleryThemePopup::~GalleryThemePopup()
192cdf0e10cSrcweir {
193*9afceb33SAriel Constenla-Haile     DBG_DTOR(GalleryThemePopup,NULL);
194*9afceb33SAriel Constenla-Haile }
195cdf0e10cSrcweir 
statusChanged(const css::frame::FeatureStateEvent & rEvent)196*9afceb33SAriel Constenla-Haile void SAL_CALL GalleryThemePopup::statusChanged(
197*9afceb33SAriel Constenla-Haile     const css::frame::FeatureStateEvent &rEvent )
198*9afceb33SAriel Constenla-Haile throw ( css::uno::RuntimeException )
199*9afceb33SAriel Constenla-Haile {
200*9afceb33SAriel Constenla-Haile     const OUString &rURL = rEvent.FeatureURL.Complete;
201*9afceb33SAriel Constenla-Haile     if ( rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_SID_GALLERY_ENABLE_ADDCOPY ) ) )
202*9afceb33SAriel Constenla-Haile     {
203*9afceb33SAriel Constenla-Haile         if ( !rEvent.IsEnabled )
204*9afceb33SAriel Constenla-Haile         {
205*9afceb33SAriel Constenla-Haile             PopupMenu *pAddMenu = maPopupMenu.GetPopupMenu( MN_ADDMENU );
206*9afceb33SAriel Constenla-Haile             pAddMenu->EnableItem( MN_ADD, sal_False );
207*9afceb33SAriel Constenla-Haile             pAddMenu->EnableItem( MN_ADD_LINK, sal_False );
208*9afceb33SAriel Constenla-Haile         }
209*9afceb33SAriel Constenla-Haile     }
210*9afceb33SAriel Constenla-Haile     else if ( rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_SID_GALLERY_BG_BRUSH ) ) )
211*9afceb33SAriel Constenla-Haile     {
212*9afceb33SAriel Constenla-Haile         maBackgroundPopup.Clear();
213*9afceb33SAriel Constenla-Haile         if ( rEvent.IsEnabled )
214*9afceb33SAriel Constenla-Haile         {
215*9afceb33SAriel Constenla-Haile             OUString sItem;
216*9afceb33SAriel Constenla-Haile             css::uno::Sequence< OUString > sItems;
217*9afceb33SAriel Constenla-Haile             if ( ( rEvent.State >>= sItem ) && sItem.getLength() )
218*9afceb33SAriel Constenla-Haile             {
219*9afceb33SAriel Constenla-Haile                 maBackgroundPopup.InsertItem( 1, sItem );
220*9afceb33SAriel Constenla-Haile             }
221*9afceb33SAriel Constenla-Haile             else if ( ( rEvent.State >>= sItems ) && sItems.getLength() )
222*9afceb33SAriel Constenla-Haile             {
223*9afceb33SAriel Constenla-Haile                 const OUString *pStr = sItems.getConstArray();
224*9afceb33SAriel Constenla-Haile                 const OUString *pEnd = pStr + sItems.getLength();
225*9afceb33SAriel Constenla-Haile                 for ( sal_uInt16 nId = 1; pStr != pEnd; pStr++, nId++ )
226*9afceb33SAriel Constenla-Haile                 {
227*9afceb33SAriel Constenla-Haile                     maBackgroundPopup.InsertItem( nId, *pStr );
228*9afceb33SAriel Constenla-Haile                 }
229*9afceb33SAriel Constenla-Haile             }
230*9afceb33SAriel Constenla-Haile         }
231*9afceb33SAriel Constenla-Haile     }
232*9afceb33SAriel Constenla-Haile }
233cdf0e10cSrcweir 
disposing(const css::lang::EventObject &)234*9afceb33SAriel Constenla-Haile void SAL_CALL GalleryThemePopup::disposing(
235*9afceb33SAriel Constenla-Haile     const css::lang::EventObject &/*rSource*/)
236*9afceb33SAriel Constenla-Haile throw ( css::uno::RuntimeException )
237*9afceb33SAriel Constenla-Haile {
238*9afceb33SAriel Constenla-Haile }
239cdf0e10cSrcweir 
Execute(const CommandInfo & rCmdInfo,const css::uno::Sequence<css::beans::PropertyValue> & rArguments)240*9afceb33SAriel Constenla-Haile void GalleryThemePopup::Execute(
241*9afceb33SAriel Constenla-Haile     const CommandInfo &rCmdInfo,
242*9afceb33SAriel Constenla-Haile     const css::uno::Sequence< css::beans::PropertyValue > &rArguments )
243*9afceb33SAriel Constenla-Haile {
244*9afceb33SAriel Constenla-Haile     if ( rCmdInfo.Dispatch.is() )
245*9afceb33SAriel Constenla-Haile     {
246*9afceb33SAriel Constenla-Haile         DispatchInfo *pInfo = new DispatchInfo;
247*9afceb33SAriel Constenla-Haile         pInfo->TargetURL = rCmdInfo.URL;
248*9afceb33SAriel Constenla-Haile         pInfo->Arguments = rArguments;
249*9afceb33SAriel Constenla-Haile         pInfo->Dispatch = rCmdInfo.Dispatch;
250*9afceb33SAriel Constenla-Haile 
251*9afceb33SAriel Constenla-Haile         if ( !Application::PostUserEvent(
252*9afceb33SAriel Constenla-Haile                 STATIC_LINK( 0, GalleryBrowser2, AsyncDispatch_Impl), pInfo ) )
253*9afceb33SAriel Constenla-Haile             delete pInfo;
254*9afceb33SAriel Constenla-Haile     }
255*9afceb33SAriel Constenla-Haile }
256cdf0e10cSrcweir 
ExecutePopup(Window * pWindow,const::Point & aPos)257*9afceb33SAriel Constenla-Haile void GalleryThemePopup::ExecutePopup( Window *pWindow, const ::Point &aPos )
258cdf0e10cSrcweir {
259*9afceb33SAriel Constenla-Haile     css::uno::Reference< css::frame::XStatusListener > xThis( this );
260cdf0e10cSrcweir 
261*9afceb33SAriel Constenla-Haile     const SgaObjKind eObjKind = mpTheme->GetObjectKind( mnObjectPos );
262*9afceb33SAriel Constenla-Haile     PopupMenu*       pAddMenu = maPopupMenu.GetPopupMenu( MN_ADDMENU );
263*9afceb33SAriel Constenla-Haile     INetURLObject    aURL;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     const_cast< GalleryTheme* >( mpTheme )->GetURL( mnObjectPos, aURL );
266cdf0e10cSrcweir     const sal_Bool bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID );
267cdf0e10cSrcweir 
268*9afceb33SAriel Constenla-Haile     pAddMenu->EnableItem( MN_ADD, bValidURL && SGA_OBJ_SOUND != eObjKind );
269*9afceb33SAriel Constenla-Haile     pAddMenu->EnableItem( MN_ADD_LINK, bValidURL && SGA_OBJ_SVDRAW != eObjKind );
270cdf0e10cSrcweir 
271*9afceb33SAriel Constenla-Haile     maPopupMenu.EnableItem( MN_ADDMENU, pAddMenu->IsItemEnabled( MN_ADD ) || pAddMenu->IsItemEnabled( MN_ADD_LINK ) );
272*9afceb33SAriel Constenla-Haile     maPopupMenu.EnableItem( MN_PREVIEW, bValidURL );
273cdf0e10cSrcweir 
274*9afceb33SAriel Constenla-Haile     maPopupMenu.CheckItem( MN_PREVIEW, mbPreview );
275*9afceb33SAriel Constenla-Haile 
276*9afceb33SAriel Constenla-Haile     if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() )
277*9afceb33SAriel Constenla-Haile     {
278*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_DELETE, sal_False );
279*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_TITLE, sal_False );
280*9afceb33SAriel Constenla-Haile 
281*9afceb33SAriel Constenla-Haile         if( mpTheme->IsReadOnly() )
282*9afceb33SAriel Constenla-Haile             maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_False );
283*9afceb33SAriel Constenla-Haile 
284*9afceb33SAriel Constenla-Haile         if( !mpTheme->GetObjectCount() )
285*9afceb33SAriel Constenla-Haile             maPopupMenu.EnableItem( MN_COPYCLIPBOARD, sal_False );
286*9afceb33SAriel Constenla-Haile     }
287*9afceb33SAriel Constenla-Haile     else
288*9afceb33SAriel Constenla-Haile     {
289*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_DELETE, !mbPreview );
290*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_TITLE, sal_True );
291*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_COPYCLIPBOARD, sal_True );
292*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_True );
293*9afceb33SAriel Constenla-Haile     }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir #ifdef GALLERY_USE_CLIPBOARD
296*9afceb33SAriel Constenla-Haile     if( maPopupMenu.IsItemEnabled( MN_PASTECLIPBOARD ) )
297cdf0e10cSrcweir     {
298*9afceb33SAriel Constenla-Haile         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
299*9afceb33SAriel Constenla-Haile         sal_Bool               bEnable = sal_False;
300cdf0e10cSrcweir 
301*9afceb33SAriel Constenla-Haile         if( aDataHelper.GetFormatCount() )
302*9afceb33SAriel Constenla-Haile         {
303*9afceb33SAriel Constenla-Haile             if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) ||
304*9afceb33SAriel Constenla-Haile                 aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
305*9afceb33SAriel Constenla-Haile                 aDataHelper.HasFormat( FORMAT_FILE ) ||
306*9afceb33SAriel Constenla-Haile                 aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) ||
307*9afceb33SAriel Constenla-Haile                 aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) ||
308*9afceb33SAriel Constenla-Haile                 aDataHelper.HasFormat( FORMAT_BITMAP ) )
309*9afceb33SAriel Constenla-Haile             {
310*9afceb33SAriel Constenla-Haile                 bEnable = sal_True;
311*9afceb33SAriel Constenla-Haile             }
312*9afceb33SAriel Constenla-Haile         }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         if( !bEnable )
315*9afceb33SAriel Constenla-Haile             maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_False );
316cdf0e10cSrcweir     }
317cdf0e10cSrcweir #else
318*9afceb33SAriel Constenla-Haile     maPopupMenu.EnableItem( MN_COPYCLIPBOARD, sal_False );
319*9afceb33SAriel Constenla-Haile     maPopupMenu.EnableItem( MN_PASTECLIPBOARD, sal_False );
320cdf0e10cSrcweir #endif
321cdf0e10cSrcweir 
322*9afceb33SAriel Constenla-Haile     // update status
323*9afceb33SAriel Constenla-Haile     css::uno::Reference< css::frame::XDispatchProvider> xDispatchProvider(
324*9afceb33SAriel Constenla-Haile         mpBrowser->GetFrame(), css::uno::UNO_QUERY );
325*9afceb33SAriel Constenla-Haile     css::uno::Reference< css::util::XURLTransformer > xTransformer(
326*9afceb33SAriel Constenla-Haile         mpBrowser->GetURLTransformer() );
327*9afceb33SAriel Constenla-Haile     for ( CommandInfoMap::iterator it = m_aCommandInfo.begin();
328*9afceb33SAriel Constenla-Haile          it != m_aCommandInfo.end(); it++ )
329*9afceb33SAriel Constenla-Haile     {
330*9afceb33SAriel Constenla-Haile         try
331*9afceb33SAriel Constenla-Haile         {
332*9afceb33SAriel Constenla-Haile             CommandInfo &rCmdInfo = it->second;
333*9afceb33SAriel Constenla-Haile             if ( xTransformer.is() )
334*9afceb33SAriel Constenla-Haile                 xTransformer->parseStrict( rCmdInfo.URL );
335cdf0e10cSrcweir 
336*9afceb33SAriel Constenla-Haile             if ( xDispatchProvider.is() )
337*9afceb33SAriel Constenla-Haile             {
338*9afceb33SAriel Constenla-Haile                 rCmdInfo.Dispatch = xDispatchProvider->queryDispatch(
339*9afceb33SAriel Constenla-Haile                     rCmdInfo.URL,
340*9afceb33SAriel Constenla-Haile                     C2U( "_self" ),
341*9afceb33SAriel Constenla-Haile                     css::frame::FrameSearchFlag::SELF );
342*9afceb33SAriel Constenla-Haile             }
343cdf0e10cSrcweir 
344*9afceb33SAriel Constenla-Haile             if ( rCmdInfo.Dispatch.is() )
345*9afceb33SAriel Constenla-Haile             {
346*9afceb33SAriel Constenla-Haile                 rCmdInfo.Dispatch->addStatusListener( this, rCmdInfo.URL );
347*9afceb33SAriel Constenla-Haile                 rCmdInfo.Dispatch->removeStatusListener( this, rCmdInfo.URL );
348*9afceb33SAriel Constenla-Haile             }
349*9afceb33SAriel Constenla-Haile         }
350*9afceb33SAriel Constenla-Haile         catch ( ... )
351*9afceb33SAriel Constenla-Haile         {}
352*9afceb33SAriel Constenla-Haile     }
353cdf0e10cSrcweir 
354*9afceb33SAriel Constenla-Haile     if( !maBackgroundPopup.GetItemCount() || ( eObjKind == SGA_OBJ_SVDRAW ) || ( eObjKind == SGA_OBJ_SOUND ) )
355*9afceb33SAriel Constenla-Haile         pAddMenu->EnableItem( MN_BACKGROUND, sal_False );
356*9afceb33SAriel Constenla-Haile     else
357*9afceb33SAriel Constenla-Haile     {
358*9afceb33SAriel Constenla-Haile         pAddMenu->EnableItem( MN_BACKGROUND, sal_True );
359*9afceb33SAriel Constenla-Haile         pAddMenu->SetPopupMenu( MN_BACKGROUND, &maBackgroundPopup );
360*9afceb33SAriel Constenla-Haile         maBackgroundPopup.SetSelectHdl( LINK( this, GalleryThemePopup, BackgroundMenuSelectHdl ) );
361*9afceb33SAriel Constenla-Haile     }
362cdf0e10cSrcweir 
363*9afceb33SAriel Constenla-Haile     pAddMenu->RemoveDisabledEntries();
364*9afceb33SAriel Constenla-Haile     if ( !pAddMenu->GetItemCount() )
365*9afceb33SAriel Constenla-Haile         maPopupMenu.EnableItem( MN_ADDMENU, sal_False );
366*9afceb33SAriel Constenla-Haile     maPopupMenu.RemoveDisabledEntries();
367*9afceb33SAriel Constenla-Haile 
368*9afceb33SAriel Constenla-Haile     maPopupMenu.SetSelectHdl( LINK( this, GalleryThemePopup, MenuSelectHdl ) );
369*9afceb33SAriel Constenla-Haile     maPopupMenu.Execute( pWindow, aPos );
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
IMPL_LINK(GalleryThemePopup,MenuSelectHdl,Menu *,pMenu)372*9afceb33SAriel Constenla-Haile IMPL_LINK( GalleryThemePopup, MenuSelectHdl, Menu*, pMenu )
373*9afceb33SAriel Constenla-Haile {
374*9afceb33SAriel Constenla-Haile     if( !pMenu )
375*9afceb33SAriel Constenla-Haile         return 0;
376*9afceb33SAriel Constenla-Haile 
377*9afceb33SAriel Constenla-Haile     sal_uInt16 nId( pMenu->GetCurItemId() );
378*9afceb33SAriel Constenla-Haile     switch ( nId )
379*9afceb33SAriel Constenla-Haile     {
380*9afceb33SAriel Constenla-Haile         case( MN_ADD ):
381*9afceb33SAriel Constenla-Haile         case( MN_ADD_LINK ):
382*9afceb33SAriel Constenla-Haile         {
383*9afceb33SAriel Constenla-Haile             const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_FORMATS );
384*9afceb33SAriel Constenla-Haile             if ( it != m_aCommandInfo.end() )
385*9afceb33SAriel Constenla-Haile                 mpBrowser->Dispatch( nId,
386*9afceb33SAriel Constenla-Haile                                      it->second.Dispatch,
387*9afceb33SAriel Constenla-Haile                                      it->second.URL );
388*9afceb33SAriel Constenla-Haile         }
389*9afceb33SAriel Constenla-Haile         break;
390*9afceb33SAriel Constenla-Haile 
391*9afceb33SAriel Constenla-Haile         default:
392*9afceb33SAriel Constenla-Haile             mpBrowser->Execute( nId );
393*9afceb33SAriel Constenla-Haile     }
394cdf0e10cSrcweir 
395*9afceb33SAriel Constenla-Haile     return 0;
396*9afceb33SAriel Constenla-Haile }
397*9afceb33SAriel Constenla-Haile 
IMPL_LINK(GalleryThemePopup,BackgroundMenuSelectHdl,Menu *,pMenu)398*9afceb33SAriel Constenla-Haile IMPL_LINK( GalleryThemePopup, BackgroundMenuSelectHdl, Menu*, pMenu )
399cdf0e10cSrcweir {
400*9afceb33SAriel Constenla-Haile     if( !pMenu )
401*9afceb33SAriel Constenla-Haile         return 0;
402*9afceb33SAriel Constenla-Haile 
403*9afceb33SAriel Constenla-Haile     sal_uInt16 nPos( pMenu->GetCurItemId() - 1 );
404*9afceb33SAriel Constenla-Haile     OUString aURL( mpBrowser->GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
405*9afceb33SAriel Constenla-Haile     OUString aFilterName( mpBrowser->GetFilterName() );
406*9afceb33SAriel Constenla-Haile 
407*9afceb33SAriel Constenla-Haile     css::uno::Sequence< css::beans::PropertyValue > aArgs( 6 );
408*9afceb33SAriel Constenla-Haile     aArgs[0].Name = C2U( "Background.Transparent" );
409*9afceb33SAriel Constenla-Haile     aArgs[0].Value <<= sal_Int32( 0 ); // 0 - 100
410*9afceb33SAriel Constenla-Haile     aArgs[1].Name = C2U( "Background.BackColor" );
411*9afceb33SAriel Constenla-Haile     aArgs[1].Value <<= sal_Int32( - 1 );
412*9afceb33SAriel Constenla-Haile     aArgs[2].Name = C2U( "Background.URL" );
413*9afceb33SAriel Constenla-Haile     aArgs[2].Value <<= aURL;
414*9afceb33SAriel Constenla-Haile     aArgs[3].Name = C2U( "Background.Filtername" ); // FIXME should be FilterName
415*9afceb33SAriel Constenla-Haile     aArgs[3].Value <<= aFilterName;
416*9afceb33SAriel Constenla-Haile     aArgs[4].Name = C2U( "Background.Position" );
417*9afceb33SAriel Constenla-Haile     aArgs[4].Value <<= css::style::GraphicLocation_TILED;
418*9afceb33SAriel Constenla-Haile     aArgs[5].Name = C2U( "Position" );
419*9afceb33SAriel Constenla-Haile     aArgs[5].Value <<= nPos;
420*9afceb33SAriel Constenla-Haile 
421*9afceb33SAriel Constenla-Haile     const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_BG_BRUSH );
422*9afceb33SAriel Constenla-Haile     if ( it != m_aCommandInfo.end() )
423*9afceb33SAriel Constenla-Haile         Execute( it->second, aArgs );
424*9afceb33SAriel Constenla-Haile 
425*9afceb33SAriel Constenla-Haile     return 0;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428*9afceb33SAriel Constenla-Haile } // end anonymous namespace
429*9afceb33SAriel Constenla-Haile 
430cdf0e10cSrcweir // ------------------
431cdf0e10cSrcweir // - GalleryToolBox -
432cdf0e10cSrcweir // ------------------
DBG_NAME(GalleryToolBox)433cdf0e10cSrcweir DBG_NAME(GalleryToolBox)
434cdf0e10cSrcweir 
435cdf0e10cSrcweir GalleryToolBox::GalleryToolBox( GalleryBrowser2* pParent ) :
436cdf0e10cSrcweir     ToolBox( pParent, WB_TABSTOP )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     DBG_CTOR(GalleryToolBox,NULL);
439cdf0e10cSrcweir 
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir // ------------------------------------------------------------------------
443cdf0e10cSrcweir 
~GalleryToolBox()444cdf0e10cSrcweir GalleryToolBox::~GalleryToolBox()
445cdf0e10cSrcweir {
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     DBG_DTOR(GalleryToolBox,NULL);
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir // ------------------------------------------------------------------------
451cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)452cdf0e10cSrcweir void GalleryToolBox::KeyInput( const KeyEvent& rKEvt )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir     if( !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
455cdf0e10cSrcweir         ToolBox::KeyInput( rKEvt );
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir // -------------------
459cdf0e10cSrcweir // - GalleryBrowser2 -
460cdf0e10cSrcweir // -------------------
DBG_NAME(GalleryBrowser2)461cdf0e10cSrcweir DBG_NAME(GalleryBrowser2)
462cdf0e10cSrcweir 
46302c50d82SAndre Fischer GalleryBrowser2::GalleryBrowser2( Window* pParent, const ResId& rResId, Gallery* pGallery ) :
464cdf0e10cSrcweir 	Control				( pParent, rResId ),
465cdf0e10cSrcweir 	mpGallery			( pGallery ),
466cdf0e10cSrcweir 	mpCurTheme			( NULL ),
467cdf0e10cSrcweir 	mpIconView          ( new GalleryIconView( this, NULL ) ),
468cdf0e10cSrcweir     mpListView          ( new GalleryListView( this, NULL ) ),
469cdf0e10cSrcweir 	mpPreview           ( new GalleryPreview( this, NULL ) ),
470cdf0e10cSrcweir     maViewBox           ( this ),
471cdf0e10cSrcweir     maSeparator         ( this, WB_VERT ),
472cdf0e10cSrcweir 	maInfoBar			( this, WB_LEFT | WB_VCENTER ),
473cdf0e10cSrcweir 	mnCurActionPos		( 0xffffffff ),
474cdf0e10cSrcweir     meMode              ( GALLERYBROWSERMODE_NONE ),
475*9afceb33SAriel Constenla-Haile     meLastMode          ( GALLERYBROWSERMODE_NONE )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     DBG_CTOR(GalleryBrowser2,NULL);
478*9afceb33SAriel Constenla-Haile 
479*9afceb33SAriel Constenla-Haile     m_xContext.set( ::comphelper::getProcessComponentContext() );
480*9afceb33SAriel Constenla-Haile 
481*9afceb33SAriel Constenla-Haile     m_xTransformer.set(
482*9afceb33SAriel Constenla-Haile         m_xContext->getServiceManager()->createInstanceWithContext(
483*9afceb33SAriel Constenla-Haile             C2U( "com.sun.star.util.URLTransformer" ), m_xContext ),
484*9afceb33SAriel Constenla-Haile                     css::uno::UNO_QUERY );
485*9afceb33SAriel Constenla-Haile 
486cdf0e10cSrcweir     Image       aDummyImage;
487cdf0e10cSrcweir     const Link  aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
488cdf0e10cSrcweir     Font        aInfoFont( maInfoBar.GetControlFont() );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	maMiscOptions.AddListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     maViewBox.InsertItem( TBX_ID_ICON, aDummyImage );
493cdf0e10cSrcweir     maViewBox.SetItemBits( TBX_ID_ICON, TIB_RADIOCHECK | TIB_AUTOCHECK );
494cdf0e10cSrcweir     maViewBox.SetHelpId( TBX_ID_ICON, HID_GALLERY_ICONVIEW );
495cdf0e10cSrcweir     maViewBox.SetQuickHelpText( TBX_ID_ICON, String( GAL_RESID( RID_SVXSTR_GALLERY_ICONVIEW ) ) );
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     maViewBox.InsertItem( TBX_ID_LIST, aDummyImage );
498cdf0e10cSrcweir     maViewBox.SetItemBits( TBX_ID_LIST, TIB_RADIOCHECK | TIB_AUTOCHECK );
499cdf0e10cSrcweir     maViewBox.SetHelpId( TBX_ID_LIST, HID_GALLERY_LISTVIEW );
500cdf0e10cSrcweir     maViewBox.SetQuickHelpText( TBX_ID_LIST, String( GAL_RESID( RID_SVXSTR_GALLERY_LISTVIEW ) ) );
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     maViewBox.SetBorder( 0, 1 );
503cdf0e10cSrcweir     MiscHdl( NULL );
504cdf0e10cSrcweir     maViewBox.SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
505cdf0e10cSrcweir     maViewBox.Show();
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 	mpIconView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
508cdf0e10cSrcweir 	mpListView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 	maInfoBar.Show();
511cdf0e10cSrcweir     maSeparator.Show();
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 	mpIconView->SetSelectHdl( aSelectHdl );
514cdf0e10cSrcweir 	mpListView->SetSelectHdl( aSelectHdl );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     InitSettings();
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON );
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 	if(maInfoBar.GetText().Len() == 0)
521cdf0e10cSrcweir 		mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
522cdf0e10cSrcweir 	else
523cdf0e10cSrcweir 		mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
524cdf0e10cSrcweir 	mpIconView->SetAccessibleRelationMemberOf(mpIconView);
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir // -----------------------------------------------------------------------------
528cdf0e10cSrcweir 
~GalleryBrowser2()529cdf0e10cSrcweir GalleryBrowser2::~GalleryBrowser2()
530cdf0e10cSrcweir {
531cdf0e10cSrcweir     maMiscOptions.RemoveListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 	delete mpPreview;
534cdf0e10cSrcweir     delete mpListView;
535cdf0e10cSrcweir 	delete mpIconView;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 	if( mpCurTheme )
538cdf0e10cSrcweir 		mpGallery->ReleaseTheme( mpCurTheme, *this );
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     DBG_DTOR(GalleryBrowser2,NULL);
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir // -----------------------------------------------------------------------------
544cdf0e10cSrcweir 
InitSettings()545cdf0e10cSrcweir void GalleryBrowser2::InitSettings()
546cdf0e10cSrcweir {
547cdf0e10cSrcweir     Font  aInfoFont( maInfoBar.GetControlFont() );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     aInfoFont.SetWeight( WEIGHT_BOLD );
550cdf0e10cSrcweir     aInfoFont.SetColor( GALLERY_FG_COLOR );
551cdf0e10cSrcweir     maInfoBar.SetControlFont( aInfoFont );
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     maInfoBar.SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
554cdf0e10cSrcweir 	maInfoBar.SetControlBackground( GALLERY_DLG_COLOR );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 	maSeparator.SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
557cdf0e10cSrcweir 	maSeparator.SetControlBackground( GALLERY_BG_COLOR );
558cdf0e10cSrcweir 	maSeparator.SetControlForeground( GALLERY_FG_COLOR );
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // -----------------------------------------------------------------------------
562cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)563cdf0e10cSrcweir void GalleryBrowser2::DataChanged( const DataChangedEvent& rDCEvt )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
566cdf0e10cSrcweir         InitSettings();
567cdf0e10cSrcweir     else
568cdf0e10cSrcweir         Control::DataChanged( rDCEvt );
569cdf0e10cSrcweir }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir // -----------------------------------------------------------------------------
572cdf0e10cSrcweir 
Resize()573cdf0e10cSrcweir void GalleryBrowser2::Resize()
574cdf0e10cSrcweir {
575cdf0e10cSrcweir 	Control::Resize();
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 	mpIconView->Hide();
578cdf0e10cSrcweir     mpListView->Hide();
579cdf0e10cSrcweir     mpPreview->Hide();
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 	const Size	aOutSize( GetOutputSizePixel() );
582cdf0e10cSrcweir     const Size  aBoxSize( maViewBox.GetOutputSizePixel() );
583cdf0e10cSrcweir     const long  nOffset = 2, nSepWidth = 2;
584cdf0e10cSrcweir     const long  nInfoBarX = aBoxSize.Width() + ( nOffset * 3 ) + nSepWidth;
585cdf0e10cSrcweir 	const Point	aPt( 0, aBoxSize.Height() + 3 );
586cdf0e10cSrcweir 	const Size	aSz( aOutSize.Width(), aOutSize.Height() - aPt.Y() );
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     maSeparator.SetPosSizePixel( Point( aBoxSize.Width() + nOffset, 0 ), Size( nSepWidth, aBoxSize.Height() ) );
589cdf0e10cSrcweir     maInfoBar.SetPosSizePixel( Point( nInfoBarX, 0 ), Size( aOutSize.Width() - nInfoBarX, aBoxSize.Height() ) );
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     mpIconView->SetPosSizePixel( aPt, aSz );
592cdf0e10cSrcweir     mpListView->SetPosSizePixel( aPt, aSz );
593cdf0e10cSrcweir 	mpPreview->SetPosSizePixel( aPt, aSz );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir     switch( GetMode() )
596cdf0e10cSrcweir     {
597cdf0e10cSrcweir         case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
598cdf0e10cSrcweir         case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
599cdf0e10cSrcweir         case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir         default:
602cdf0e10cSrcweir         break;
603cdf0e10cSrcweir     }
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir // -----------------------------------------------------------------------------
607cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)608cdf0e10cSrcweir void GalleryBrowser2::Notify( SfxBroadcaster&, const SfxHint& rHint )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir 	const GalleryHint& rGalleryHint = (const GalleryHint&) rHint;
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 	switch( rGalleryHint.GetType() )
613cdf0e10cSrcweir 	{
614cdf0e10cSrcweir 		case( GALLERY_HINT_THEME_UPDATEVIEW ):
615cdf0e10cSrcweir 		{
616cdf0e10cSrcweir             if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
617cdf0e10cSrcweir                 SetMode( meLastMode );
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 			ImplUpdateViews( (sal_uInt16) rGalleryHint.GetData1() + 1 );
620cdf0e10cSrcweir 		}
621cdf0e10cSrcweir 		break;
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 		default:
624cdf0e10cSrcweir 		break;
625cdf0e10cSrcweir 	}
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir // -----------------------------------------------------------------------------
629cdf0e10cSrcweir 
AcceptDrop(DropTargetHelper & rTarget,const AcceptDropEvent &)630cdf0e10cSrcweir sal_Int8 GalleryBrowser2::AcceptDrop( DropTargetHelper& rTarget, const AcceptDropEvent& )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	sal_Int8 nRet = DND_ACTION_NONE;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 	if( mpCurTheme && !mpCurTheme->IsReadOnly() && !mpCurTheme ->IsImported() )
635cdf0e10cSrcweir 	{
636cdf0e10cSrcweir 		if( !mpCurTheme->IsDragging() )
637cdf0e10cSrcweir 		{
638cdf0e10cSrcweir 			if( rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING ) ||
639cdf0e10cSrcweir 				rTarget.IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) ||
640cdf0e10cSrcweir 				rTarget.IsDropFormatSupported( FORMAT_FILE ) ||
641cdf0e10cSrcweir 				rTarget.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB ) ||
642cdf0e10cSrcweir 				rTarget.IsDropFormatSupported( FORMAT_GDIMETAFILE ) ||
643cdf0e10cSrcweir 				rTarget.IsDropFormatSupported( FORMAT_BITMAP ) )
644cdf0e10cSrcweir 			{
645cdf0e10cSrcweir 				nRet = DND_ACTION_COPY;
646cdf0e10cSrcweir 			}
647cdf0e10cSrcweir 		}
648cdf0e10cSrcweir 		else
649cdf0e10cSrcweir 			nRet = DND_ACTION_COPY;
650cdf0e10cSrcweir 	}
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 	return nRet;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir // -----------------------------------------------------------------------------
656cdf0e10cSrcweir 
ExecuteDrop(DropTargetHelper &,const ExecuteDropEvent & rEvt)657cdf0e10cSrcweir sal_Int8 GalleryBrowser2::ExecuteDrop( DropTargetHelper&, const ExecuteDropEvent& rEvt )
658cdf0e10cSrcweir {
659cdf0e10cSrcweir 	sal_Int8 nRet = DND_ACTION_NONE;
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 	if( mpCurTheme )
662cdf0e10cSrcweir 	{
663cdf0e10cSrcweir 		Point		aSelPos;
664cdf0e10cSrcweir 		const sal_uIntPtr nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos );
665cdf0e10cSrcweir 		const sal_uIntPtr	nInsertPos = ( nItemId ? ( nItemId - 1 ) : LIST_APPEND );
666cdf0e10cSrcweir 
667cdf0e10cSrcweir 		if( mpCurTheme->IsDragging() )
668cdf0e10cSrcweir 			mpCurTheme->ChangeObjectPos( mpCurTheme->GetDragPos(), nInsertPos );
669cdf0e10cSrcweir 		else
670cdf0e10cSrcweir 			nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos );
671cdf0e10cSrcweir 	}
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	return nRet;
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir // -----------------------------------------------------------------------------
677cdf0e10cSrcweir 
StartDrag(Window *,const Point * pDragPoint)678cdf0e10cSrcweir void GalleryBrowser2::StartDrag( Window*, const Point* pDragPoint )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir 	if( mpCurTheme )
681cdf0e10cSrcweir 	{
682cdf0e10cSrcweir 	    Point		aSelPos;
683cdf0e10cSrcweir 		const sal_uIntPtr nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir         if( nItemId )
686cdf0e10cSrcweir 			mpCurTheme->StartDrag( this, nItemId - 1 );
687cdf0e10cSrcweir 	}
688cdf0e10cSrcweir }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir // -----------------------------------------------------------------------------
691cdf0e10cSrcweir 
TogglePreview(Window *,const Point *)692cdf0e10cSrcweir void GalleryBrowser2::TogglePreview( Window*, const Point* )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir     SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
695cdf0e10cSrcweir 	GetViewWindow()->GrabFocus();
696cdf0e10cSrcweir }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir // -----------------------------------------------------------------------------
699cdf0e10cSrcweir 
ShowContextMenu(Window *,const Point * pContextPoint)700cdf0e10cSrcweir void GalleryBrowser2::ShowContextMenu( Window*, const Point* pContextPoint )
701cdf0e10cSrcweir {
702*9afceb33SAriel Constenla-Haile     Point aSelPos;
703*9afceb33SAriel Constenla-Haile     const sal_uIntPtr nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos );
704cdf0e10cSrcweir 
705*9afceb33SAriel Constenla-Haile     if( mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() ) )
706*9afceb33SAriel Constenla-Haile     {
707cdf0e10cSrcweir         ImplSelectItemId( nItemId );
708cdf0e10cSrcweir 
709*9afceb33SAriel Constenla-Haile         css::uno::Reference< css::frame::XFrame > xFrame( GetFrame() );
710*9afceb33SAriel Constenla-Haile         if ( xFrame.is() )
711*9afceb33SAriel Constenla-Haile         {
712*9afceb33SAriel Constenla-Haile             mnCurActionPos = nItemId - 1;
713*9afceb33SAriel Constenla-Haile             rtl::Reference< GalleryThemePopup > rPopup(
714*9afceb33SAriel Constenla-Haile                 new GalleryThemePopup(
715*9afceb33SAriel Constenla-Haile                     mpCurTheme,
716*9afceb33SAriel Constenla-Haile                     mnCurActionPos,
717*9afceb33SAriel Constenla-Haile                     GALLERYBROWSERMODE_PREVIEW == GetMode(),
718*9afceb33SAriel Constenla-Haile                     this ) );
719*9afceb33SAriel Constenla-Haile             rPopup->ExecutePopup( this, aSelPos  );
720*9afceb33SAriel Constenla-Haile         }
721cdf0e10cSrcweir 	}
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir // -----------------------------------------------------------------------------
725cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt,Window * pWindow)726cdf0e10cSrcweir sal_Bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, Window* pWindow )
727cdf0e10cSrcweir {
728cdf0e10cSrcweir     Point		aSelPos;
729cdf0e10cSrcweir 	const sal_uIntPtr	nItemId = ImplGetSelectedItemId( NULL, aSelPos );
73065908a7eSAndre Fischer     GalleryBrowser* pParentBrowser = dynamic_cast<GalleryBrowser*>(GetParent());
73165908a7eSAndre Fischer     sal_Bool bRet = sal_False;
73265908a7eSAndre Fischer     if (pParentBrowser != NULL)
73365908a7eSAndre Fischer         bRet = pParentBrowser->KeyInput( rKEvt, pWindow );
73465908a7eSAndre Fischer     else
73565908a7eSAndre Fischer     {
73665908a7eSAndre Fischer         svx::sidebar::GalleryControl* pParentControl = dynamic_cast<svx::sidebar::GalleryControl*>(GetParent());
73765908a7eSAndre Fischer         if (pParentControl != NULL)
73865908a7eSAndre Fischer             bRet = pParentControl->KeyInput(rKEvt, pWindow);
73965908a7eSAndre Fischer     }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir     if( !bRet && !maViewBox.HasFocus() && nItemId && mpCurTheme )
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         sal_uInt16              nExecuteId = 0;
744cdf0e10cSrcweir 	    const SgaObjKind	eObjKind = mpCurTheme->GetObjectKind( nItemId - 1 );
745cdf0e10cSrcweir         INetURLObject       aURL;
746cdf0e10cSrcweir 
747cdf0e10cSrcweir         const_cast< GalleryTheme* >( mpCurTheme )->GetURL( nItemId - 1, aURL );
748cdf0e10cSrcweir 
749cdf0e10cSrcweir         const sal_Bool  bValidURL = ( aURL.GetProtocol() != INET_PROT_NOT_VALID );
750cdf0e10cSrcweir         sal_Bool        bPreview = bValidURL;
751cdf0e10cSrcweir         sal_Bool        bAdd = bValidURL;
752cdf0e10cSrcweir         sal_Bool        bAddLink = ( bValidURL && SGA_OBJ_SVDRAW != eObjKind );
753cdf0e10cSrcweir         sal_Bool        bDelete = sal_False;
754cdf0e10cSrcweir         sal_Bool        bTitle = sal_False;
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 	    if( !mpCurTheme->IsReadOnly() && mpCurTheme->GetObjectCount() )
757cdf0e10cSrcweir 	    {
758cdf0e10cSrcweir             bDelete = ( GALLERYBROWSERMODE_PREVIEW != GetMode() );
759cdf0e10cSrcweir             bTitle = sal_True;
760cdf0e10cSrcweir 	    }
761cdf0e10cSrcweir 
762cdf0e10cSrcweir         switch( rKEvt.GetKeyCode().GetCode() )
763cdf0e10cSrcweir         {
764cdf0e10cSrcweir             case( KEY_SPACE ):
765cdf0e10cSrcweir             case( KEY_RETURN ):
766cdf0e10cSrcweir             case( KEY_P ):
767cdf0e10cSrcweir             {
768cdf0e10cSrcweir                 if( bPreview )
769cdf0e10cSrcweir                 {
770cdf0e10cSrcweir                     TogglePreview( pWindow );
771cdf0e10cSrcweir                     bRet = sal_True;
772cdf0e10cSrcweir                 }
773cdf0e10cSrcweir             }
774cdf0e10cSrcweir             break;
775cdf0e10cSrcweir 
776cdf0e10cSrcweir             case( KEY_INSERT ):
777cdf0e10cSrcweir             case( KEY_I ):
778cdf0e10cSrcweir             {
779*9afceb33SAriel Constenla-Haile                 // Inserting a gallery item in the document must be dispatched
780cdf0e10cSrcweir                 if( bAddLink && rKEvt.GetKeyCode().IsShift() && rKEvt.GetKeyCode().IsMod1() )
781cdf0e10cSrcweir                     nExecuteId = MN_ADD_LINK;
782cdf0e10cSrcweir                 else if( bAdd )
783cdf0e10cSrcweir                     nExecuteId = MN_ADD;
784*9afceb33SAriel Constenla-Haile                 if( nExecuteId )
785*9afceb33SAriel Constenla-Haile                 {
786*9afceb33SAriel Constenla-Haile                     Dispatch( nExecuteId );
787*9afceb33SAriel Constenla-Haile                     return sal_True;
788*9afceb33SAriel Constenla-Haile                 }
789cdf0e10cSrcweir             }
790cdf0e10cSrcweir             break;
791*9afceb33SAriel Constenla-Haile 
792cdf0e10cSrcweir             case( KEY_DELETE ):
793cdf0e10cSrcweir             case( KEY_D ):
794cdf0e10cSrcweir             {
795cdf0e10cSrcweir                 if( bDelete )
796cdf0e10cSrcweir                     nExecuteId = MN_DELETE;
797cdf0e10cSrcweir             }
798cdf0e10cSrcweir             break;
799cdf0e10cSrcweir 
800cdf0e10cSrcweir             case( KEY_T ):
801cdf0e10cSrcweir             {
802cdf0e10cSrcweir                 if( bTitle )
803cdf0e10cSrcweir                     nExecuteId = MN_TITLE;
804cdf0e10cSrcweir             }
805cdf0e10cSrcweir             break;
806cdf0e10cSrcweir 
807cdf0e10cSrcweir             default:
808cdf0e10cSrcweir             break;
809cdf0e10cSrcweir         }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         if( nExecuteId )
812cdf0e10cSrcweir         {
813*9afceb33SAriel Constenla-Haile             Execute( nExecuteId );
814cdf0e10cSrcweir             bRet = sal_True;
815cdf0e10cSrcweir         }
816cdf0e10cSrcweir     }
817cdf0e10cSrcweir 
818cdf0e10cSrcweir     return bRet;
819cdf0e10cSrcweir }
820cdf0e10cSrcweir 
821cdf0e10cSrcweir // -----------------------------------------------------------------------------
822cdf0e10cSrcweir 
SelectTheme(const String & rThemeName)823cdf0e10cSrcweir void GalleryBrowser2::SelectTheme( const String& rThemeName )
824cdf0e10cSrcweir {
825cdf0e10cSrcweir 	delete mpIconView, mpIconView = NULL;
826cdf0e10cSrcweir     delete mpListView, mpListView = NULL;
827cdf0e10cSrcweir 	delete mpPreview, mpPreview = NULL;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 	if( mpCurTheme )
830cdf0e10cSrcweir 		mpGallery->ReleaseTheme( mpCurTheme, *this );
831cdf0e10cSrcweir 
832cdf0e10cSrcweir 	mpCurTheme = mpGallery->AcquireTheme( rThemeName, *this );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 	mpIconView = new GalleryIconView( this, mpCurTheme );
835cdf0e10cSrcweir     mpListView = new GalleryListView( this, mpCurTheme );
836cdf0e10cSrcweir 	mpPreview = new GalleryPreview( this, mpCurTheme );
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 	mpIconView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
839cdf0e10cSrcweir 	mpListView->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_THEMEITEMS ) ));
840cdf0e10cSrcweir 	mpPreview->SetAccessibleName(String( SVX_RES( RID_SVXSTR_GALLERY_PREVIEW ) ));
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     const Link aSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 	mpIconView->SetSelectHdl( aSelectHdl );
845cdf0e10cSrcweir 	mpListView->SetSelectHdl( aSelectHdl );
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
848cdf0e10cSrcweir         meMode = meLastMode;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 	Resize();
851cdf0e10cSrcweir     ImplUpdateViews( 1 );
852cdf0e10cSrcweir 
853cdf0e10cSrcweir     maViewBox.EnableItem( TBX_ID_ICON, sal_True );
854cdf0e10cSrcweir     maViewBox.EnableItem( TBX_ID_LIST, sal_True );
855cdf0e10cSrcweir     maViewBox.CheckItem( ( GALLERYBROWSERMODE_ICON == GetMode() ) ? TBX_ID_ICON : TBX_ID_LIST, sal_True );
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 	if(maInfoBar.GetText().Len() == 0)
858cdf0e10cSrcweir 		mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
859cdf0e10cSrcweir 	else
860cdf0e10cSrcweir 		mpIconView->SetAccessibleRelationLabeledBy(&maInfoBar);
861cdf0e10cSrcweir 	mpIconView->SetAccessibleRelationMemberOf(mpIconView);
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir // -----------------------------------------------------------------------------
865cdf0e10cSrcweir 
SetMode(GalleryBrowserMode eMode)866cdf0e10cSrcweir void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
867cdf0e10cSrcweir {
868cdf0e10cSrcweir     if( GetMode() != eMode )
869cdf0e10cSrcweir     {
870cdf0e10cSrcweir         meLastMode = GetMode();
871cdf0e10cSrcweir 
872cdf0e10cSrcweir         switch( eMode )
873cdf0e10cSrcweir         {
874cdf0e10cSrcweir             case( GALLERYBROWSERMODE_ICON ):
875cdf0e10cSrcweir             {
876cdf0e10cSrcweir 			    mpListView->Hide();
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 			    mpPreview->Hide();
879cdf0e10cSrcweir     			mpPreview->SetGraphic( Graphic() );
880cdf0e10cSrcweir 	    		mpPreview->PreviewMedia( INetURLObject() );
881cdf0e10cSrcweir 
882cdf0e10cSrcweir                 mpIconView->Show();
883cdf0e10cSrcweir 
884cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
885cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
886cdf0e10cSrcweir 
887cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_ICON, sal_True );
888cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_LIST, sal_False );
889cdf0e10cSrcweir             }
890cdf0e10cSrcweir             break;
891cdf0e10cSrcweir 
892cdf0e10cSrcweir             case( GALLERYBROWSERMODE_LIST ):
893cdf0e10cSrcweir             {
894cdf0e10cSrcweir 			    mpIconView->Hide();
895cdf0e10cSrcweir 
896cdf0e10cSrcweir 			    mpPreview->Hide();
897cdf0e10cSrcweir     			mpPreview->SetGraphic( Graphic() );
898cdf0e10cSrcweir 	    		mpPreview->PreviewMedia( INetURLObject() );
899cdf0e10cSrcweir 
900cdf0e10cSrcweir                 mpListView->Show();
901cdf0e10cSrcweir 
902cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_ICON, sal_True );
903cdf0e10cSrcweir                 maViewBox.EnableItem( TBX_ID_LIST, sal_True );
904cdf0e10cSrcweir 
905cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_ICON, sal_False );
906cdf0e10cSrcweir                 maViewBox.CheckItem( TBX_ID_LIST, sal_True );
907cdf0e10cSrcweir             }
908cdf0e10cSrcweir             break;
909cdf0e10cSrcweir 
910cdf0e10cSrcweir             case( GALLERYBROWSERMODE_PREVIEW ):
911cdf0e10cSrcweir             {
912cdf0e10cSrcweir     			Graphic		aGraphic;
913cdf0e10cSrcweir 			    Point		aSelPos;
914cdf0e10cSrcweir 	    		const sal_uIntPtr	nItemId = ImplGetSelectedItemId( NULL, aSelPos );
915cdf0e10cSrcweir 
916cdf0e10cSrcweir                 if( nItemId )
917cdf0e10cSrcweir                 {
918cdf0e10cSrcweir                     const sal_uIntPtr nPos = nItemId - 1;
919cdf0e10cSrcweir 
920cdf0e10cSrcweir    			        mpIconView->Hide();
921cdf0e10cSrcweir                     mpListView->Hide();
922cdf0e10cSrcweir 
923cdf0e10cSrcweir                     if( mpCurTheme )
924cdf0e10cSrcweir     			        mpCurTheme->GetGraphic( nPos, aGraphic );
925cdf0e10cSrcweir 
926cdf0e10cSrcweir                     mpPreview->SetGraphic( aGraphic );
927cdf0e10cSrcweir  					mpPreview->Show();
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 			        if( mpCurTheme && mpCurTheme->GetObjectKind( nPos ) == SGA_OBJ_SOUND )
930cdf0e10cSrcweir 				        mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );
931cdf0e10cSrcweir 
932cdf0e10cSrcweir                     maViewBox.EnableItem( TBX_ID_ICON, sal_False );
933cdf0e10cSrcweir                     maViewBox.EnableItem( TBX_ID_LIST, sal_False );
934cdf0e10cSrcweir                 }
935cdf0e10cSrcweir             }
936cdf0e10cSrcweir             break;
937cdf0e10cSrcweir 
938cdf0e10cSrcweir 			default:
939cdf0e10cSrcweir 				break;
940cdf0e10cSrcweir         }
941cdf0e10cSrcweir 
942cdf0e10cSrcweir         GalleryBrowser2::meInitMode = meMode = eMode;
943cdf0e10cSrcweir     }
944cdf0e10cSrcweir }
945cdf0e10cSrcweir 
946cdf0e10cSrcweir // -----------------------------------------------------------------------------
947cdf0e10cSrcweir 
GetViewWindow() const948cdf0e10cSrcweir Window* GalleryBrowser2::GetViewWindow() const
949cdf0e10cSrcweir {
950cdf0e10cSrcweir     Window* pRet;
951cdf0e10cSrcweir 
952cdf0e10cSrcweir     switch( GetMode() )
953cdf0e10cSrcweir     {
954cdf0e10cSrcweir         case( GALLERYBROWSERMODE_LIST ): pRet = mpListView; break;
955cdf0e10cSrcweir         case( GALLERYBROWSERMODE_PREVIEW ): pRet = mpPreview; break;
956cdf0e10cSrcweir 
957cdf0e10cSrcweir         default:
958cdf0e10cSrcweir             pRet = mpIconView;
959cdf0e10cSrcweir         break;
960cdf0e10cSrcweir     }
961cdf0e10cSrcweir 
962cdf0e10cSrcweir     return pRet;
963cdf0e10cSrcweir }
964cdf0e10cSrcweir 
965cdf0e10cSrcweir // -----------------------------------------------------------------------------
966cdf0e10cSrcweir 
Travel(GalleryBrowserTravel eTravel)967cdf0e10cSrcweir void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )
968cdf0e10cSrcweir {
969cdf0e10cSrcweir     if( mpCurTheme )
970cdf0e10cSrcweir     {
971cdf0e10cSrcweir 		Point		aSelPos;
972cdf0e10cSrcweir         const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
973cdf0e10cSrcweir 
974cdf0e10cSrcweir         if( nItemId )
975cdf0e10cSrcweir         {
976cdf0e10cSrcweir             sal_uIntPtr nNewItemId = nItemId;
977cdf0e10cSrcweir 
978cdf0e10cSrcweir             switch( eTravel )
979cdf0e10cSrcweir             {
980cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_FIRST ):     nNewItemId = 1; break;
981cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_LAST ):      nNewItemId = mpCurTheme->GetObjectCount(); break;
982cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_PREVIOUS ):  nNewItemId--; break;
983cdf0e10cSrcweir                 case( GALLERYBROWSERTRAVEL_NEXT ):      nNewItemId++; break;
984cdf0e10cSrcweir 				default:
985cdf0e10cSrcweir 					break;
986cdf0e10cSrcweir             }
987cdf0e10cSrcweir 
988cdf0e10cSrcweir             if( nNewItemId < 1 )
989cdf0e10cSrcweir                 nNewItemId = 1;
990cdf0e10cSrcweir             else if( nNewItemId > mpCurTheme->GetObjectCount() )
991cdf0e10cSrcweir                 nNewItemId = mpCurTheme->GetObjectCount();
992cdf0e10cSrcweir 
993cdf0e10cSrcweir             if( nNewItemId != nItemId )
994cdf0e10cSrcweir             {
995cdf0e10cSrcweir                 ImplSelectItemId( nNewItemId );
996cdf0e10cSrcweir             	ImplUpdateInfoBar();
997cdf0e10cSrcweir 
998cdf0e10cSrcweir                 if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
999cdf0e10cSrcweir                 {
1000cdf0e10cSrcweir     			    Graphic		aGraphic;
1001cdf0e10cSrcweir                     const sal_uIntPtr nPos = nNewItemId - 1;
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir                     mpCurTheme->GetGraphic( nPos, aGraphic );
1004cdf0e10cSrcweir                     mpPreview->SetGraphic( aGraphic );
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir 			        if( SGA_OBJ_SOUND == mpCurTheme->GetObjectKind( nPos ) )
1007cdf0e10cSrcweir 				        mpPreview->PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir                     mpPreview->Invalidate();
1010cdf0e10cSrcweir                 }
1011cdf0e10cSrcweir             }
1012cdf0e10cSrcweir         }
1013cdf0e10cSrcweir     }
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir // -----------------------------------------------------------------------------
1017cdf0e10cSrcweir 
ImplUpdateViews(sal_uInt16 nSelectionId)1018cdf0e10cSrcweir void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId )
1019cdf0e10cSrcweir {
1020cdf0e10cSrcweir 	mpIconView->Hide();
1021cdf0e10cSrcweir     mpListView->Hide();
1022cdf0e10cSrcweir     mpPreview->Hide();
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 	mpIconView->Clear();
1025cdf0e10cSrcweir     mpListView->Clear();
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 	if( mpCurTheme )
1028cdf0e10cSrcweir 	{
1029cdf0e10cSrcweir 		for( sal_uIntPtr i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; )
1030cdf0e10cSrcweir         {
1031cdf0e10cSrcweir             mpListView->RowInserted( i++ );
1032cdf0e10cSrcweir 			mpIconView->InsertItem( (sal_uInt16) i );
1033cdf0e10cSrcweir         }
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir         ImplSelectItemId( ( ( nSelectionId > mpCurTheme->GetObjectCount() ) ? mpCurTheme->GetObjectCount() : nSelectionId ) );
1036cdf0e10cSrcweir 	}
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir     switch( GetMode() )
1039cdf0e10cSrcweir     {
1040cdf0e10cSrcweir         case( GALLERYBROWSERMODE_ICON ): mpIconView->Show(); break;
1041cdf0e10cSrcweir         case( GALLERYBROWSERMODE_LIST ): mpListView->Show(); break;
1042cdf0e10cSrcweir         case( GALLERYBROWSERMODE_PREVIEW ): mpPreview->Show(); break;
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir         default:
1045cdf0e10cSrcweir         break;
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 	ImplUpdateInfoBar();
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir // -----------------------------------------------------------------------------
1052cdf0e10cSrcweir 
ImplUpdateInfoBar()1053cdf0e10cSrcweir void GalleryBrowser2::ImplUpdateInfoBar()
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir 	String aInfoText;
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir 	if( mpCurTheme )
1058cdf0e10cSrcweir 	{
1059cdf0e10cSrcweir 	    Point		aSelPos;
1060cdf0e10cSrcweir 		const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir         if( nItemId )
1063cdf0e10cSrcweir         {
1064cdf0e10cSrcweir             const sal_uIntPtr nPos = nItemId - 1;
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 		    aInfoText = mpCurTheme->GetName();
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir 		    if( nPos < mpCurTheme->GetObjectCount() )
1069cdf0e10cSrcweir 		    {
1070cdf0e10cSrcweir 			    SgaObject* pObj = mpCurTheme->AcquireObject( nPos );
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir 			    if( pObj )
1073cdf0e10cSrcweir 			    {
1074cdf0e10cSrcweir 				    aInfoText = GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_THEMENAME | GALLERY_ITEM_TITLE | GALLERY_ITEM_PATH );
1075cdf0e10cSrcweir 				    mpCurTheme->ReleaseObject( pObj );
1076cdf0e10cSrcweir 			    }
1077cdf0e10cSrcweir 		    }
1078cdf0e10cSrcweir         }
1079cdf0e10cSrcweir 	}
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 	maInfoBar.SetText( aInfoText );
1082cdf0e10cSrcweir }
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir // -----------------------------------------------------------------------------
1085cdf0e10cSrcweir 
ImplGetSelectedItemId(const Point * pSelPos,Point & rSelPos)1086cdf0e10cSrcweir sal_uIntPtr GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos )
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir 	const Size  aOutputSizePixel( GetOutputSizePixel() );
1089cdf0e10cSrcweir     sal_uIntPtr       nRet = 0;
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir     if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
1092cdf0e10cSrcweir     {
1093cdf0e10cSrcweir         nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mpIconView->GetSelectItemId() : ( mpListView->FirstSelectedRow() + 1 ) );
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir 	    if( pSelPos )
1096cdf0e10cSrcweir 	        rSelPos = GetPointerPosPixel();
1097cdf0e10cSrcweir 	    else
1098cdf0e10cSrcweir     	    rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
1099cdf0e10cSrcweir     }
1100cdf0e10cSrcweir     else if( GALLERYBROWSERMODE_ICON == GetMode() )
1101cdf0e10cSrcweir 	{
1102cdf0e10cSrcweir 	    if( pSelPos )
1103cdf0e10cSrcweir 	    {
1104cdf0e10cSrcweir             nRet = mpIconView->GetItemId( *pSelPos );
1105cdf0e10cSrcweir 		    rSelPos = GetPointerPosPixel();
1106cdf0e10cSrcweir 	    }
1107cdf0e10cSrcweir 	    else
1108cdf0e10cSrcweir 	    {
1109cdf0e10cSrcweir             nRet = mpIconView->GetSelectItemId();
1110cdf0e10cSrcweir 	    	rSelPos = mpIconView->GetItemRect( (sal_uInt16) nRet ).Center();
1111cdf0e10cSrcweir 	    }
1112cdf0e10cSrcweir 	}
1113cdf0e10cSrcweir     else
1114cdf0e10cSrcweir 	{
1115cdf0e10cSrcweir 	    if( pSelPos )
1116cdf0e10cSrcweir 	    {
1117cdf0e10cSrcweir             nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1;
1118cdf0e10cSrcweir 	    	rSelPos = GetPointerPosPixel();
1119cdf0e10cSrcweir 	    }
1120cdf0e10cSrcweir 	    else
1121cdf0e10cSrcweir 	    {
1122cdf0e10cSrcweir             nRet = mpListView->FirstSelectedRow() + 1;
1123cdf0e10cSrcweir 	    	rSelPos = mpListView->GetFieldRectPixel( (sal_uInt16) nRet, 1 ).Center();
1124cdf0e10cSrcweir 	    }
1125cdf0e10cSrcweir 	}
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 	rSelPos.X() = Max( Min( rSelPos.X(), aOutputSizePixel.Width() - 1L ), 0L );
1128cdf0e10cSrcweir 	rSelPos.Y() = Max( Min( rSelPos.Y(), aOutputSizePixel.Height() - 1L ), 0L );
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir     if( nRet && ( !mpCurTheme || ( nRet > mpCurTheme->GetObjectCount() ) ) )
1131cdf0e10cSrcweir     {
1132cdf0e10cSrcweir         nRet = 0;
1133cdf0e10cSrcweir     }
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir     return nRet;
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir // -----------------------------------------------------------------------------
1139cdf0e10cSrcweir 
ImplSelectItemId(sal_uIntPtr nItemId)1140cdf0e10cSrcweir void GalleryBrowser2::ImplSelectItemId( sal_uIntPtr nItemId )
1141cdf0e10cSrcweir {
1142cdf0e10cSrcweir     if( nItemId )
1143cdf0e10cSrcweir     {
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir         mpIconView->SelectItem( (sal_uInt16) nItemId );
1146cdf0e10cSrcweir         mpListView->SelectRow( nItemId - 1 );
1147cdf0e10cSrcweir     }
1148cdf0e10cSrcweir }
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir // -----------------------------------------------------------------------------
1151cdf0e10cSrcweir 
1152*9afceb33SAriel Constenla-Haile css::uno::Reference< css::frame::XFrame >
GetFrame() const1153*9afceb33SAriel Constenla-Haile GalleryBrowser2::GetFrame() const
1154cdf0e10cSrcweir {
1155*9afceb33SAriel Constenla-Haile     css::uno::Reference< css::frame::XFrame > xFrame;
1156*9afceb33SAriel Constenla-Haile     SfxViewFrame* pCurrentViewFrame = SfxViewFrame::Current();
1157*9afceb33SAriel Constenla-Haile     if ( pCurrentViewFrame )
1158*9afceb33SAriel Constenla-Haile     {
1159*9afceb33SAriel Constenla-Haile         SfxBindings& rBindings = pCurrentViewFrame->GetBindings();
1160*9afceb33SAriel Constenla-Haile         xFrame.set( rBindings.GetActiveFrame() );
1161*9afceb33SAriel Constenla-Haile     }
1162cdf0e10cSrcweir 
1163*9afceb33SAriel Constenla-Haile     return xFrame;
1164*9afceb33SAriel Constenla-Haile }
1165*9afceb33SAriel Constenla-Haile 
Dispatch(sal_uInt16 nId,const css::uno::Reference<css::frame::XDispatch> & rxDispatch,const css::util::URL & rURL)1166*9afceb33SAriel Constenla-Haile void GalleryBrowser2::Dispatch(
1167*9afceb33SAriel Constenla-Haile      sal_uInt16 nId,
1168*9afceb33SAriel Constenla-Haile     const css::uno::Reference< css::frame::XDispatch > &rxDispatch,
1169*9afceb33SAriel Constenla-Haile     const css::util::URL &rURL )
1170*9afceb33SAriel Constenla-Haile {
1171*9afceb33SAriel Constenla-Haile     Point aSelPos;
1172*9afceb33SAriel Constenla-Haile     const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
1173*9afceb33SAriel Constenla-Haile 
1174*9afceb33SAriel Constenla-Haile     if( !mpCurTheme || !nItemId )
1175*9afceb33SAriel Constenla-Haile         return;
1176*9afceb33SAriel Constenla-Haile 
1177*9afceb33SAriel Constenla-Haile     mnCurActionPos = nItemId - 1;
1178*9afceb33SAriel Constenla-Haile 
1179*9afceb33SAriel Constenla-Haile     switch( nId )
1180cdf0e10cSrcweir     {
1181*9afceb33SAriel Constenla-Haile         case( MN_ADD ):
1182*9afceb33SAriel Constenla-Haile         case( MN_ADD_LINK ):
1183*9afceb33SAriel Constenla-Haile         {
1184*9afceb33SAriel Constenla-Haile             css::uno::Reference< css::frame::XDispatch > xDispatch( rxDispatch );
1185*9afceb33SAriel Constenla-Haile             css::util::URL aURL = rURL;
1186cdf0e10cSrcweir 
1187*9afceb33SAriel Constenla-Haile             if ( !xDispatch.is() )
1188*9afceb33SAriel Constenla-Haile             {
1189*9afceb33SAriel Constenla-Haile                 css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(
1190*9afceb33SAriel Constenla-Haile                     GetFrame(), css::uno::UNO_QUERY );
1191*9afceb33SAriel Constenla-Haile                 if ( !xDispatchProvider.is() || !m_xTransformer.is() )
1192*9afceb33SAriel Constenla-Haile                     return;
1193*9afceb33SAriel Constenla-Haile 
1194*9afceb33SAriel Constenla-Haile                 aURL.Complete = C2U( CMD_SID_GALLERY_FORMATS );
1195*9afceb33SAriel Constenla-Haile                 m_xTransformer->parseStrict( aURL );
1196*9afceb33SAriel Constenla-Haile                 xDispatch = xDispatchProvider->queryDispatch(
1197*9afceb33SAriel Constenla-Haile                     aURL,
1198*9afceb33SAriel Constenla-Haile                     C2U( "_self" ),
1199*9afceb33SAriel Constenla-Haile                     css::frame::FrameSearchFlag::SELF );
1200*9afceb33SAriel Constenla-Haile             }
1201cdf0e10cSrcweir 
1202*9afceb33SAriel Constenla-Haile             if ( !xDispatch.is() )
1203*9afceb33SAriel Constenla-Haile                 return;
1204cdf0e10cSrcweir 
1205*9afceb33SAriel Constenla-Haile             sal_Int8 nType = 0;
1206*9afceb33SAriel Constenla-Haile             sal_Bool bIsLink( MN_ADD_LINK == nId );
1207*9afceb33SAriel Constenla-Haile             OUString aFileURL, aFilterName;
1208*9afceb33SAriel Constenla-Haile             css::uno::Reference< css::lang::XComponent > xDrawing;
1209*9afceb33SAriel Constenla-Haile             css::uno::Reference< css::graphic::XGraphic > xGraphic;
1210cdf0e10cSrcweir 
1211*9afceb33SAriel Constenla-Haile             aFilterName = GetFilterName();
1212cdf0e10cSrcweir 
1213*9afceb33SAriel Constenla-Haile             switch( mpCurTheme->GetObjectKind( mnCurActionPos ) )
1214*9afceb33SAriel Constenla-Haile             {
1215*9afceb33SAriel Constenla-Haile                 case( SGA_OBJ_BMP ):
1216*9afceb33SAriel Constenla-Haile                 case( SGA_OBJ_ANIM ):
1217*9afceb33SAriel Constenla-Haile                 case( SGA_OBJ_INET ):
1218*9afceb33SAriel Constenla-Haile                 // TODO drawing objects are inserted as drawings only via drag&drop
1219*9afceb33SAriel Constenla-Haile                 case( SGA_OBJ_SVDRAW ):
1220*9afceb33SAriel Constenla-Haile                     nType = css::gallery::GalleryItemType::GRAPHIC;
1221*9afceb33SAriel Constenla-Haile                 break;
1222*9afceb33SAriel Constenla-Haile 
1223*9afceb33SAriel Constenla-Haile                 case ( SGA_OBJ_SOUND ) :
1224*9afceb33SAriel Constenla-Haile                     nType = css::gallery::GalleryItemType::MEDIA;
1225*9afceb33SAriel Constenla-Haile                 break;
1226*9afceb33SAriel Constenla-Haile 
1227*9afceb33SAriel Constenla-Haile                 default:
1228*9afceb33SAriel Constenla-Haile                     nType = css::gallery::GalleryItemType::EMPTY;
1229*9afceb33SAriel Constenla-Haile                 break;
1230*9afceb33SAriel Constenla-Haile             }
1231cdf0e10cSrcweir 
1232*9afceb33SAriel Constenla-Haile             if ( bIsLink )
1233*9afceb33SAriel Constenla-Haile             {
1234*9afceb33SAriel Constenla-Haile                 aFileURL = mpCurTheme->GetObjectURL( mnCurActionPos ).GetMainURL( INetURLObject::NO_DECODE );
1235*9afceb33SAriel Constenla-Haile                 OSL_ENSURE( aFileURL.getLength(), "gallery item is link but no URL!" );
1236*9afceb33SAriel Constenla-Haile             }
1237*9afceb33SAriel Constenla-Haile 
1238*9afceb33SAriel Constenla-Haile             Graphic aGraphic;
1239*9afceb33SAriel Constenla-Haile             sal_Bool bGraphic = mpCurTheme->GetGraphic( mnCurActionPos, aGraphic );
1240*9afceb33SAriel Constenla-Haile             if ( bGraphic && !!aGraphic )
1241*9afceb33SAriel Constenla-Haile                 xGraphic.set( aGraphic.GetXGraphic() );
1242*9afceb33SAriel Constenla-Haile             OSL_ENSURE( xGraphic.is(), "gallery item is graphic, but the reference is invalid!" );
1243*9afceb33SAriel Constenla-Haile 
1244*9afceb33SAriel Constenla-Haile             css::uno::Sequence< css::beans::PropertyValue > aSeq( SVXGALLERYITEM_PARAMS );
1245*9afceb33SAriel Constenla-Haile 
1246*9afceb33SAriel Constenla-Haile             aSeq[0].Name = C2U( SVXGALLERYITEM_TYPE );
1247*9afceb33SAriel Constenla-Haile             aSeq[0].Value <<= nType;
1248*9afceb33SAriel Constenla-Haile             aSeq[1].Name = C2U( SVXGALLERYITEM_LINK );
1249*9afceb33SAriel Constenla-Haile             aSeq[1].Value <<= bIsLink;
1250*9afceb33SAriel Constenla-Haile             aSeq[2].Name = C2U( SVXGALLERYITEM_URL );
1251*9afceb33SAriel Constenla-Haile             aSeq[2].Value <<= aFileURL;
1252*9afceb33SAriel Constenla-Haile             aSeq[3].Name = C2U( SVXGALLERYITEM_FILTER );
1253*9afceb33SAriel Constenla-Haile             aSeq[3].Value <<= aFilterName;
1254*9afceb33SAriel Constenla-Haile             aSeq[4].Name = C2U( SVXGALLERYITEM_DRAWING );
1255*9afceb33SAriel Constenla-Haile             aSeq[4].Value <<= xDrawing;
1256*9afceb33SAriel Constenla-Haile             aSeq[5].Name = C2U( SVXGALLERYITEM_GRAPHIC );
1257*9afceb33SAriel Constenla-Haile             aSeq[5].Value <<= xGraphic;
1258*9afceb33SAriel Constenla-Haile 
1259*9afceb33SAriel Constenla-Haile             css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
1260*9afceb33SAriel Constenla-Haile             aArgs[0].Name = C2U( SVXGALLERYITEM_ARGNAME );
1261*9afceb33SAriel Constenla-Haile             aArgs[0].Value <<= aSeq;
1262*9afceb33SAriel Constenla-Haile 
1263*9afceb33SAriel Constenla-Haile             DispatchInfo *pInfo = new DispatchInfo;
1264*9afceb33SAriel Constenla-Haile             pInfo->TargetURL = aURL;
1265*9afceb33SAriel Constenla-Haile             pInfo->Arguments = aArgs;
1266*9afceb33SAriel Constenla-Haile             pInfo->Dispatch = xDispatch;
1267*9afceb33SAriel Constenla-Haile 
1268*9afceb33SAriel Constenla-Haile             if ( !Application::PostUserEvent(
1269*9afceb33SAriel Constenla-Haile                     STATIC_LINK( 0, GalleryBrowser2, AsyncDispatch_Impl), pInfo ) )
1270*9afceb33SAriel Constenla-Haile                 delete pInfo;
1271*9afceb33SAriel Constenla-Haile         }
1272*9afceb33SAriel Constenla-Haile         break;
1273*9afceb33SAriel Constenla-Haile 
1274*9afceb33SAriel Constenla-Haile         default:
1275*9afceb33SAriel Constenla-Haile         break;
1276*9afceb33SAriel Constenla-Haile     }
1277*9afceb33SAriel Constenla-Haile }
1278cdf0e10cSrcweir 
Execute(sal_uInt16 nId)1279*9afceb33SAriel Constenla-Haile void GalleryBrowser2::Execute( sal_uInt16 nId )
1280*9afceb33SAriel Constenla-Haile {
1281*9afceb33SAriel Constenla-Haile     Point		aSelPos;
1282*9afceb33SAriel Constenla-Haile 	const sal_uIntPtr nItemId = ImplGetSelectedItemId( NULL, aSelPos );
1283*9afceb33SAriel Constenla-Haile 
1284*9afceb33SAriel Constenla-Haile     if( mpCurTheme && nItemId )
1285*9afceb33SAriel Constenla-Haile     {
1286*9afceb33SAriel Constenla-Haile         mnCurActionPos = nItemId - 1;
1287*9afceb33SAriel Constenla-Haile 
1288*9afceb33SAriel Constenla-Haile 		switch( nId )
1289*9afceb33SAriel Constenla-Haile 		{
1290cdf0e10cSrcweir 			case( MN_PREVIEW ):
1291cdf0e10cSrcweir                 SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
1292cdf0e10cSrcweir 			break;
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir 			case( MN_DELETE ):
1295cdf0e10cSrcweir 			{
1296cdf0e10cSrcweir 				if( !mpCurTheme->IsReadOnly() &&
1297cdf0e10cSrcweir 					QueryBox( NULL, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETEOBJ ) ) ).Execute() == RET_YES )
1298cdf0e10cSrcweir 				{
1299cdf0e10cSrcweir 					mpCurTheme->RemoveObject( mnCurActionPos );
1300cdf0e10cSrcweir 				}
1301cdf0e10cSrcweir 			}
1302cdf0e10cSrcweir 			break;
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir 			case( MN_TITLE ):
1305cdf0e10cSrcweir 			{
1306cdf0e10cSrcweir 				SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos );
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir 				if( pObj )
1309cdf0e10cSrcweir 				{
1310cdf0e10cSrcweir                     const String    aOldTitle( GetItemText( *mpCurTheme, *pObj, GALLERY_ITEM_TITLE ) );
1311cdf0e10cSrcweir 					//CHINA001 TitleDialog	    aDlg( this, aOldTitle );
1312cdf0e10cSrcweir 					SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1313cdf0e10cSrcweir 					if(pFact)
1314cdf0e10cSrcweir 					{
1315cdf0e10cSrcweir 						AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldTitle );
1316cdf0e10cSrcweir 						DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
1317cdf0e10cSrcweir 						if( aDlg->Execute() == RET_OK )//CHINA001 if( aDlg.Execute() == RET_OK )
1318cdf0e10cSrcweir 						{
1319cdf0e10cSrcweir 							String aNewTitle( aDlg->GetTitle() );//CHINA001 String aNewTitle( aDlg.GetTitle() );
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir 							if( ( !aNewTitle.Len() && pObj->GetTitle().Len() ) || ( aNewTitle != aOldTitle ) )
1322cdf0e10cSrcweir 							{
1323cdf0e10cSrcweir 								if( !aNewTitle.Len() )
1324cdf0e10cSrcweir 									aNewTitle = String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) );
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir 								pObj->SetTitle( aNewTitle );
1327cdf0e10cSrcweir 								mpCurTheme->InsertObject( *pObj );
1328cdf0e10cSrcweir 							}
1329cdf0e10cSrcweir 						}
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir 						mpCurTheme->ReleaseObject( pObj );
1332cdf0e10cSrcweir 						delete aDlg; //add CHINA001
1333cdf0e10cSrcweir 					}
1334cdf0e10cSrcweir 				}
1335cdf0e10cSrcweir 			}
1336cdf0e10cSrcweir 			break;
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir 			case( MN_COPYCLIPBOARD ):
1339cdf0e10cSrcweir 			{
1340cdf0e10cSrcweir                 Window* pWindow;
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir                 switch( GetMode() )
1343cdf0e10cSrcweir                 {
1344cdf0e10cSrcweir                     case( GALLERYBROWSERMODE_ICON ): pWindow = (Window*) mpIconView; break;
1345cdf0e10cSrcweir                     case( GALLERYBROWSERMODE_LIST ): pWindow = (Window*) mpListView; break;
1346cdf0e10cSrcweir                     case( GALLERYBROWSERMODE_PREVIEW ): pWindow = (Window*) mpPreview; break;
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir                     default:
1349cdf0e10cSrcweir                         pWindow = NULL;
1350cdf0e10cSrcweir                     break;
1351cdf0e10cSrcweir                 }
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir 				mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos );
1354cdf0e10cSrcweir 			}
1355cdf0e10cSrcweir 			break;
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir 			case( MN_PASTECLIPBOARD ):
1358cdf0e10cSrcweir 			{
1359cdf0e10cSrcweir 				if( !mpCurTheme->IsReadOnly() )
1360cdf0e10cSrcweir 				{
1361cdf0e10cSrcweir 					TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
1362cdf0e10cSrcweir 					mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos );
1363cdf0e10cSrcweir 				}
1364cdf0e10cSrcweir 			}
1365cdf0e10cSrcweir 			break;
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir 			default:
1368cdf0e10cSrcweir 			break;
1369cdf0e10cSrcweir 		}
1370cdf0e10cSrcweir     }
1371cdf0e10cSrcweir }
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir // -----------------------------------------------------------------------------
1374cdf0e10cSrcweir 
GetItemText(const GalleryTheme & rTheme,const SgaObject & rObj,sal_uIntPtr nItemTextFlags)1375cdf0e10cSrcweir String GalleryBrowser2::GetItemText( const GalleryTheme& rTheme, const SgaObject& rObj, sal_uIntPtr nItemTextFlags )
1376cdf0e10cSrcweir {
1377cdf0e10cSrcweir 	INetURLObject   aURL;
1378cdf0e10cSrcweir     String          aRet;
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir     if( rTheme.IsImported() )
1381cdf0e10cSrcweir 	{
1382cdf0e10cSrcweir 		aURL = rTheme.GetParent()->GetImportURL( rTheme.GetName() );
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir 		aURL.removeSegment();
1385cdf0e10cSrcweir 		aURL.Append( rObj.GetURL().GetName() );
1386cdf0e10cSrcweir 	}
1387cdf0e10cSrcweir     else
1388cdf0e10cSrcweir         aURL = rObj.GetURL();
1389cdf0e10cSrcweir 
1390cdf0e10cSrcweir     if( nItemTextFlags & GALLERY_ITEM_THEMENAME )
1391cdf0e10cSrcweir     {
1392cdf0e10cSrcweir         aRet += rTheme.GetName();
1393cdf0e10cSrcweir         aRet += String( RTL_CONSTASCII_USTRINGPARAM( " - " ) );
1394cdf0e10cSrcweir     }
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir     if( nItemTextFlags & GALLERY_ITEM_TITLE )
1397cdf0e10cSrcweir     {
1398cdf0e10cSrcweir 		String aTitle( rObj.GetTitle() );
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir         if( !aTitle.Len() )
1401cdf0e10cSrcweir             aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir         if( !aTitle.Len() )
1404cdf0e10cSrcweir         {
1405cdf0e10cSrcweir             aTitle = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1406cdf0e10cSrcweir             aTitle = aTitle.GetToken( aTitle.GetTokenCount( '/' ) - 1, '/' );
1407cdf0e10cSrcweir         }
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir         aRet += aTitle;
1410cdf0e10cSrcweir     }
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir     if( nItemTextFlags & GALLERY_ITEM_PATH )
1413cdf0e10cSrcweir     {
1414cdf0e10cSrcweir         const String aPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir         if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) )
1417cdf0e10cSrcweir             aRet += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir         aRet += String(aURL.getFSysPath( INetURLObject::FSYS_DETECT ));
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir         if( aPath.Len() && ( nItemTextFlags & GALLERY_ITEM_TITLE ) )
1422cdf0e10cSrcweir             aRet += ')';
1423cdf0e10cSrcweir     }
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir 	return aRet;
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir // -----------------------------------------------------------------------------
1429cdf0e10cSrcweir 
GetURL() const1430cdf0e10cSrcweir INetURLObject GalleryBrowser2::GetURL() const
1431cdf0e10cSrcweir {
1432cdf0e10cSrcweir 	INetURLObject aURL;
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	if( mpCurTheme && mnCurActionPos != 0xffffffff )
1435cdf0e10cSrcweir 		aURL = mpCurTheme->GetObjectURL( mnCurActionPos );
1436cdf0e10cSrcweir 
1437cdf0e10cSrcweir 	return aURL;
1438cdf0e10cSrcweir }
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir // -----------------------------------------------------------------------------
1441cdf0e10cSrcweir 
GetFilterName() const1442cdf0e10cSrcweir String GalleryBrowser2::GetFilterName() const
1443cdf0e10cSrcweir {
1444cdf0e10cSrcweir 	String aFilterName;
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	if( mpCurTheme && mnCurActionPos != 0xffffffff )
1447cdf0e10cSrcweir 	{
1448cdf0e10cSrcweir 		const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( mnCurActionPos );
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir 		if( ( SGA_OBJ_BMP == eObjKind ) || ( SGA_OBJ_ANIM == eObjKind ) )
1451cdf0e10cSrcweir 		{
1452cdf0e10cSrcweir 			GraphicFilter*		pFilter = GraphicFilter::GetGraphicFilter();
1453cdf0e10cSrcweir 			INetURLObject		aURL; mpCurTheme->GetURL( mnCurActionPos, aURL );
1454cdf0e10cSrcweir 			sal_uInt16			nFilter = pFilter->GetImportFormatNumberForShortName( aURL.GetExtension() );
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir 			if( GRFILTER_FORMAT_DONTKNOW != nFilter )
1457cdf0e10cSrcweir 				aFilterName = pFilter->GetImportFormatName( nFilter );
1458cdf0e10cSrcweir 		}
1459cdf0e10cSrcweir 	}
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir 	return aFilterName;
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir // -----------------------------------------------------------------------------
1465cdf0e10cSrcweir 
GetGraphic() const1466cdf0e10cSrcweir Graphic GalleryBrowser2::GetGraphic() const
1467cdf0e10cSrcweir {
1468cdf0e10cSrcweir 	Graphic aGraphic;
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir 	if( mpCurTheme && mnCurActionPos != 0xffffffff )
1471cdf0e10cSrcweir 		mpCurTheme->GetGraphic(	mnCurActionPos, aGraphic );
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir 	return aGraphic;
1474cdf0e10cSrcweir }
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir // -----------------------------------------------------------------------------
1477cdf0e10cSrcweir 
GetVCDrawModel(FmFormModel & rModel) const1478cdf0e10cSrcweir sal_Bool GalleryBrowser2::GetVCDrawModel( FmFormModel& rModel ) const
1479cdf0e10cSrcweir {
1480cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir 	if( mpCurTheme && mnCurActionPos != 0xffffffff )
1483cdf0e10cSrcweir 		bRet = mpCurTheme->GetModel( mnCurActionPos, rModel );
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir 	return bRet;
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir // -----------------------------------------------------------------------------
1489cdf0e10cSrcweir 
IMPL_LINK(GalleryBrowser2,SelectObjectHdl,void *,EMPTYARG)1490cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, SelectObjectHdl, void*, EMPTYARG )
1491cdf0e10cSrcweir {
1492cdf0e10cSrcweir 	ImplUpdateInfoBar();
1493cdf0e10cSrcweir 	return 0L;
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir // -----------------------------------------------------------------------------
1497cdf0e10cSrcweir 
IMPL_LINK(GalleryBrowser2,SelectTbxHdl,ToolBox *,pBox)1498cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, SelectTbxHdl, ToolBox*, pBox )
1499cdf0e10cSrcweir {
1500cdf0e10cSrcweir     if( pBox->GetCurItemId() == TBX_ID_ICON )
1501cdf0e10cSrcweir         SetMode( GALLERYBROWSERMODE_ICON );
1502cdf0e10cSrcweir     else if( pBox->GetCurItemId() == TBX_ID_LIST )
1503cdf0e10cSrcweir         SetMode( GALLERYBROWSERMODE_LIST );
1504*9afceb33SAriel Constenla-Haile 
1505cdf0e10cSrcweir 	return 0L;
1506cdf0e10cSrcweir }
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir // -----------------------------------------------------------------------------
1509cdf0e10cSrcweir 
IMPL_LINK(GalleryBrowser2,MiscHdl,void *,EMPTYARG)1510cdf0e10cSrcweir IMPL_LINK( GalleryBrowser2, MiscHdl, void*, EMPTYARG )
1511cdf0e10cSrcweir {
1512cdf0e10cSrcweir 	const sal_Bool  bHC = maViewBox.GetSettings().GetStyleSettings().GetHighContrastMode();
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir     maViewBox.SetOutStyle( maMiscOptions.GetToolboxStyle() );
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	BitmapEx aIconBmpEx = BitmapEx( Image( GAL_RESID( bHC? RID_SVXIMG_GALLERY_VIEW_ICON_HC : RID_SVXIMG_GALLERY_VIEW_ICON ) ).GetBitmapEx() );
1517cdf0e10cSrcweir 	BitmapEx aListBmpEx = BitmapEx( Image( GAL_RESID( bHC? RID_SVXIMG_GALLERY_VIEW_LIST_HC : RID_SVXIMG_GALLERY_VIEW_LIST ) ).GetBitmapEx() );
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir 	if( maMiscOptions.AreCurrentSymbolsLarge() )
1520cdf0e10cSrcweir 	{
1521cdf0e10cSrcweir 		const Size aLargeSize( 24, 24);
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir 		aIconBmpEx.Scale( aLargeSize );
1524cdf0e10cSrcweir 		aListBmpEx.Scale( aLargeSize );
1525cdf0e10cSrcweir 	}
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir     maViewBox.SetItemImage( TBX_ID_ICON, aIconBmpEx );
1528cdf0e10cSrcweir     maViewBox.SetItemImage( TBX_ID_LIST, aListBmpEx );
1529cdf0e10cSrcweir     maViewBox.SetSizePixel( maViewBox.CalcWindowSizePixel() );
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir 	Resize();
1532cdf0e10cSrcweir 
1533cdf0e10cSrcweir     return 0L;
1534cdf0e10cSrcweir }
1535