xref: /trunk/main/svx/source/gallery2/galctrl.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
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 #include <vcl/svapp.hxx>
28cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
29cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
30cdf0e10cSrcweir #include <avmedia/mediaplayer.hxx>
31cdf0e10cSrcweir #include "helpid.hrc"
32cdf0e10cSrcweir #include "galbrws2.hxx"
33cdf0e10cSrcweir #include "svx/galtheme.hxx"
34cdf0e10cSrcweir #include "svx/galmisc.hxx"
35cdf0e10cSrcweir #include "svx/galctrl.hxx"
36cdf0e10cSrcweir #include "editeng/AccessibleStringWrap.hxx"
37cdf0e10cSrcweir #include <editeng/svxfont.hxx>
38cdf0e10cSrcweir #include "galobj.hxx"
39cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
40cdf0e10cSrcweir #include "gallery.hrc"
41cdf0e10cSrcweir #include <svtools/filter.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // -----------
44cdf0e10cSrcweir // - Defines -
45cdf0e10cSrcweir // -----------
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define GALLERY_BRWBOX_TITLE    1
48cdf0e10cSrcweir #define GALLERY_BRWBOX_PATH     2
49cdf0e10cSrcweir 
50cdf0e10cSrcweir // ------------------
51cdf0e10cSrcweir // - GalleryPreview -
52cdf0e10cSrcweir // ------------------
DBG_NAME(GalleryPreview)53cdf0e10cSrcweir DBG_NAME(GalleryPreview)
54cdf0e10cSrcweir 
55cdf0e10cSrcweir GalleryPreview::GalleryPreview( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
56cdf0e10cSrcweir     Window( pParent, WB_TABSTOP | WB_BORDER ),
57cdf0e10cSrcweir     DropTargetHelper( this ),
58cdf0e10cSrcweir     DragSourceHelper( this ),
59cdf0e10cSrcweir     mpTheme( pTheme )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     DBG_CTOR(GalleryPreview,NULL);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     SetHelpId( HID_GALLERY_WINDOW );
64cdf0e10cSrcweir     InitSettings();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // ------------------------------------------------------------------------
68cdf0e10cSrcweir 
GalleryPreview(Window * pParent,const ResId & rResId)69cdf0e10cSrcweir GalleryPreview::GalleryPreview( Window* pParent, const ResId & rResId  ) :
70cdf0e10cSrcweir     Window( pParent, rResId ),
71cdf0e10cSrcweir     DropTargetHelper( this ),
72cdf0e10cSrcweir     DragSourceHelper( this ),
73cdf0e10cSrcweir     mpTheme( NULL )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     DBG_CTOR(GalleryPreview,NULL);
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     SetHelpId( HID_GALLERY_PREVIEW );
78cdf0e10cSrcweir     InitSettings();
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // ------------------------------------------------------------------------
82cdf0e10cSrcweir 
~GalleryPreview()83cdf0e10cSrcweir GalleryPreview::~GalleryPreview()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     DBG_DTOR(GalleryPreview,NULL);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
SetGraphic(const INetURLObject & _aURL)90cdf0e10cSrcweir bool GalleryPreview::SetGraphic( const INetURLObject& _aURL )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     bool bRet = true;
93cdf0e10cSrcweir     Graphic aGraphic;
94cdf0e10cSrcweir     if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         aGraphic = BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) );
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir     else
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         GraphicFilter*  pFilter = GraphicFilter::GetGraphicFilter();
101cdf0e10cSrcweir         GalleryProgress aProgress( pFilter );
102cdf0e10cSrcweir         if( pFilter->ImportGraphic( aGraphic, _aURL, GRFILTER_FORMAT_DONTKNOW ) )
103cdf0e10cSrcweir             bRet = false;
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     SetGraphic( aGraphic );
107cdf0e10cSrcweir     Invalidate();
108cdf0e10cSrcweir     return bRet;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // ------------------------------------------------------------------------
112cdf0e10cSrcweir 
InitSettings()113cdf0e10cSrcweir void GalleryPreview::InitSettings()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
116cdf0e10cSrcweir     SetControlBackground( GALLERY_BG_COLOR );
117cdf0e10cSrcweir     SetControlForeground( GALLERY_FG_COLOR );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -----------------------------------------------------------------------
121cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)122cdf0e10cSrcweir void GalleryPreview::DataChanged( const DataChangedEvent& rDCEvt )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
125cdf0e10cSrcweir         InitSettings();
126cdf0e10cSrcweir     else
127cdf0e10cSrcweir         Window::DataChanged( rDCEvt );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // ------------------------------------------------------------------------
131cdf0e10cSrcweir 
ImplGetGraphicCenterRect(const Graphic & rGraphic,Rectangle & rResultRect) const132cdf0e10cSrcweir sal_Bool GalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     const Size  aWinSize( GetOutputSizePixel() );
135cdf0e10cSrcweir     Size        aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
136cdf0e10cSrcweir     sal_Bool        bRet = sal_False;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     if( aNewSize.Width() && aNewSize.Height() )
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         // scale to fit window
141cdf0e10cSrcweir         const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
142cdf0e10cSrcweir         const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         if ( fGrfWH < fWinWH )
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
147cdf0e10cSrcweir             aNewSize.Height()= aWinSize.Height();
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir         else
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir             aNewSize.Width() = aWinSize.Width();
152cdf0e10cSrcweir             aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         const Point aNewPos( ( aWinSize.Width()  - aNewSize.Width() ) >> 1,
156cdf0e10cSrcweir                              ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         rResultRect = Rectangle( aNewPos, aNewSize );
159cdf0e10cSrcweir         bRet = sal_True;
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     return bRet;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // ------------------------------------------------------------------------
166cdf0e10cSrcweir 
Paint(const Rectangle & rRect)167cdf0e10cSrcweir void GalleryPreview::Paint( const Rectangle& rRect )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     Window::Paint( rRect );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     if( ImplGetGraphicCenterRect( aGraphicObj.GetGraphic(), aPreviewRect ) )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         const Point aPos( aPreviewRect.TopLeft() );
174cdf0e10cSrcweir         const Size  aSize( aPreviewRect.GetSize() );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         if( aGraphicObj.IsAnimated() )
177cdf0e10cSrcweir             aGraphicObj.StartAnimation( this, aPos, aSize );
178cdf0e10cSrcweir         else
179cdf0e10cSrcweir             aGraphicObj.Draw( this, aPos, aSize );
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir // ------------------------------------------------------------------------
184cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)185cdf0e10cSrcweir void GalleryPreview::MouseButtonDown( const MouseEvent& rMEvt )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     if( mpTheme && ( rMEvt.GetClicks() == 2 ) )
188cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->TogglePreview( this );
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir // ------------------------------------------------------------------------
192cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)193cdf0e10cSrcweir void GalleryPreview::Command(const CommandEvent& rCEvt )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     Window::Command( rCEvt );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     if( mpTheme && ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) )
198cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this,
199cdf0e10cSrcweir             ( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // ------------------------------------------------------------------------
203cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)204cdf0e10cSrcweir void GalleryPreview::KeyInput( const KeyEvent& rKEvt )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     if( mpTheme )
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         GalleryBrowser2* pBrowser = static_cast< GalleryBrowser2* >( GetParent() );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         switch( rKEvt.GetKeyCode().GetCode() )
211cdf0e10cSrcweir         {
212cdf0e10cSrcweir             case( KEY_BACKSPACE ):
213cdf0e10cSrcweir                 pBrowser->TogglePreview( this );
214cdf0e10cSrcweir             break;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir             case( KEY_HOME ):
217cdf0e10cSrcweir                 pBrowser->Travel( GALLERYBROWSERTRAVEL_FIRST );
218cdf0e10cSrcweir             break;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir             case( KEY_END ):
221cdf0e10cSrcweir                 pBrowser->Travel( GALLERYBROWSERTRAVEL_LAST );
222cdf0e10cSrcweir             break;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             case( KEY_LEFT ):
225cdf0e10cSrcweir             case( KEY_UP ):
226cdf0e10cSrcweir                 pBrowser->Travel( GALLERYBROWSERTRAVEL_PREVIOUS );
227cdf0e10cSrcweir             break;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir             case( KEY_RIGHT ):
230cdf0e10cSrcweir             case( KEY_DOWN ):
231cdf0e10cSrcweir                 pBrowser->Travel( GALLERYBROWSERTRAVEL_NEXT );
232cdf0e10cSrcweir             break;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir             default:
235cdf0e10cSrcweir             {
236cdf0e10cSrcweir                 if( !pBrowser->KeyInput( rKEvt, this ) )
237cdf0e10cSrcweir                     Window::KeyInput( rKEvt );
238cdf0e10cSrcweir             }
239cdf0e10cSrcweir             break;
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir     else
243cdf0e10cSrcweir         Window::KeyInput( rKEvt );
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir // ------------------------------------------------------------------------
247cdf0e10cSrcweir 
AcceptDrop(const AcceptDropEvent & rEvt)248cdf0e10cSrcweir sal_Int8 GalleryPreview::AcceptDrop( const AcceptDropEvent& rEvt )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     sal_Int8 nRet;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     if( mpTheme )
253cdf0e10cSrcweir         nRet = ( (GalleryBrowser2*) GetParent() )->AcceptDrop( *this, rEvt );
254cdf0e10cSrcweir     else
255cdf0e10cSrcweir         nRet = DND_ACTION_NONE;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     return nRet;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir // ------------------------------------------------------------------------
261cdf0e10cSrcweir 
ExecuteDrop(const ExecuteDropEvent & rEvt)262cdf0e10cSrcweir sal_Int8 GalleryPreview::ExecuteDrop( const ExecuteDropEvent& rEvt )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     sal_Int8 nRet;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     if( mpTheme )
267cdf0e10cSrcweir         nRet = ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, rEvt );
268cdf0e10cSrcweir     else
269cdf0e10cSrcweir         nRet = DND_ACTION_NONE;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     return nRet;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir // ------------------------------------------------------------------------
275cdf0e10cSrcweir 
StartDrag(sal_Int8,const Point &)276cdf0e10cSrcweir void GalleryPreview::StartDrag( sal_Int8, const Point& )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     if( mpTheme )
279cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->StartDrag( this );
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir // ------------------------------------------------------------------------
283cdf0e10cSrcweir 
PreviewMedia(const INetURLObject & rURL)284cdf0e10cSrcweir void GalleryPreview::PreviewMedia( const INetURLObject& rURL )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     if( rURL.GetProtocol() != INET_PROT_NOT_VALID )
287cdf0e10cSrcweir     {
288cdf0e10cSrcweir         ::avmedia::MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         if( !pFloater )
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_AVMEDIA_PLAYER, SFX_CALLMODE_SYNCHRON );
293cdf0e10cSrcweir             pFloater = AVMEDIA_MEDIAWINDOW();
294cdf0e10cSrcweir         }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         if( pFloater )
297cdf0e10cSrcweir             pFloater->setURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ), true );
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir // ------------------------------------------------------------------------
302cdf0e10cSrcweir 
drawTransparenceBackground(OutputDevice & rOut,const Point & rPos,const Size & rSize)30335726d9dSArmin Le Grand void drawTransparenceBackground(OutputDevice& rOut, const Point& rPos, const Size& rSize)
30435726d9dSArmin Le Grand {
30535726d9dSArmin Le Grand     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
30635726d9dSArmin Le Grand 
30733b19716SArmin Le Grand     if(rStyleSettings.GetPreviewUsesCheckeredBackground())
3086dd94783SArmin Le Grand     {
3096dd94783SArmin Le Grand         // draw checkered background
3106dd94783SArmin Le Grand         static const sal_uInt32 nLen(8);
3116dd94783SArmin Le Grand         static const Color aW(COL_WHITE);
3126dd94783SArmin Le Grand         static const Color aG(0xef, 0xef, 0xef);
3136dd94783SArmin Le Grand 
3146dd94783SArmin Le Grand         rOut.DrawCheckered(rPos, rSize, nLen, aW, aG);
3156dd94783SArmin Le Grand     }
31635726d9dSArmin Le Grand     else
31735726d9dSArmin Le Grand     {
31835726d9dSArmin Le Grand         rOut.SetLineColor();
31935726d9dSArmin Le Grand         rOut.SetFillColor(rStyleSettings.GetFieldColor());
32035726d9dSArmin Le Grand         rOut.DrawRect(Rectangle(rPos, rSize));
32135726d9dSArmin Le Grand     }
32235726d9dSArmin Le Grand }
3236dd94783SArmin Le Grand 
324cdf0e10cSrcweir // -------------------
325cdf0e10cSrcweir // - GalleryIconView -
326cdf0e10cSrcweir // -------------------
DBG_NAME(GalleryIconView)327cdf0e10cSrcweir DBG_NAME(GalleryIconView)
328cdf0e10cSrcweir 
329cdf0e10cSrcweir GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
330cdf0e10cSrcweir         ValueSet( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET ),
331cdf0e10cSrcweir         DropTargetHelper( this ),
332cdf0e10cSrcweir         DragSourceHelper( this ),
333cdf0e10cSrcweir         mpTheme ( pTheme )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir     DBG_CTOR(GalleryIconView,NULL);
336cdf0e10cSrcweir     EnableFullItemMode( sal_False );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     SetHelpId( HID_GALLERY_WINDOW );
339cdf0e10cSrcweir     InitSettings();
340cdf0e10cSrcweir     SetExtraSpacing( 2 );
341cdf0e10cSrcweir     SetItemWidth( S_THUMB + 6 );
342cdf0e10cSrcweir     SetItemHeight( S_THUMB + 6 );
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir // ------------------------------------------------------------------------
346cdf0e10cSrcweir 
~GalleryIconView()347cdf0e10cSrcweir GalleryIconView::~GalleryIconView()
348cdf0e10cSrcweir {
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     DBG_DTOR(GalleryIconView,NULL);
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir // ------------------------------------------------------------------------
354cdf0e10cSrcweir 
InitSettings()355cdf0e10cSrcweir void GalleryIconView::InitSettings()
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
358cdf0e10cSrcweir     SetControlBackground( GALLERY_BG_COLOR );
359cdf0e10cSrcweir     SetControlForeground( GALLERY_FG_COLOR );
360cdf0e10cSrcweir     SetColor( GALLERY_BG_COLOR );
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir // -----------------------------------------------------------------------
364cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)365cdf0e10cSrcweir void GalleryIconView::DataChanged( const DataChangedEvent& rDCEvt )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
368cdf0e10cSrcweir         InitSettings();
369cdf0e10cSrcweir     else
370cdf0e10cSrcweir         ValueSet::DataChanged( rDCEvt );
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir // ------------------------------------------------------------------------
374cdf0e10cSrcweir 
UserDraw(const UserDrawEvent & rUDEvt)375cdf0e10cSrcweir void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir     const sal_uInt16 nId = rUDEvt.GetItemId();
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     if( nId && mpTheme )
380cdf0e10cSrcweir     {
38121b36550SArmin Le Grand         const Rectangle& rRect = rUDEvt.GetRect();
38221b36550SArmin Le Grand         const Size aSize(rRect.GetWidth(), rRect.GetHeight());
38321b36550SArmin Le Grand         BitmapEx aBitmapEx;
38421b36550SArmin Le Grand         Size aPreparedSize;
38521b36550SArmin Le Grand         String aItemTextTitle;
38621b36550SArmin Le Grand         String aItemTextPath;
38721b36550SArmin Le Grand 
38821b36550SArmin Le Grand         mpTheme->GetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);
38921b36550SArmin Le Grand 
39021b36550SArmin Le Grand         bool bNeedToCreate(aBitmapEx.IsEmpty());
39121b36550SArmin Le Grand 
39221b36550SArmin Le Grand         if(!bNeedToCreate && !aItemTextTitle.Len())
39321b36550SArmin Le Grand         {
39421b36550SArmin Le Grand             bNeedToCreate = true;
39521b36550SArmin Le Grand         }
39621b36550SArmin Le Grand 
39721b36550SArmin Le Grand         if(!bNeedToCreate && aPreparedSize != aSize)
39821b36550SArmin Le Grand         {
39921b36550SArmin Le Grand             bNeedToCreate = true;
40021b36550SArmin Le Grand         }
40121b36550SArmin Le Grand 
40221b36550SArmin Le Grand         if(bNeedToCreate)
40321b36550SArmin Le Grand         {
404cdf0e10cSrcweir             SgaObject* pObj = mpTheme->AcquireObject(nId - 1);
405cdf0e10cSrcweir 
406cdf0e10cSrcweir             if(pObj)
407cdf0e10cSrcweir             {
40821b36550SArmin Le Grand                 aBitmapEx = pObj->createPreviewBitmapEx(aSize);
40921b36550SArmin Le Grand                 aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GALLERY_ITEM_TITLE);
410cdf0e10cSrcweir 
41121b36550SArmin Le Grand                 mpTheme->SetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
412cdf0e10cSrcweir                 mpTheme->ReleaseObject(pObj);
413cdf0e10cSrcweir             }
414cdf0e10cSrcweir         }
41521b36550SArmin Le Grand 
41621b36550SArmin Le Grand         if(!aBitmapEx.IsEmpty())
41721b36550SArmin Le Grand         {
41821b36550SArmin Le Grand             const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
41921b36550SArmin Le Grand             const Point aPos(
42021b36550SArmin Le Grand                 ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
42121b36550SArmin Le Grand                 ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
42221b36550SArmin Le Grand             OutputDevice* pDev = rUDEvt.GetDevice();
42321b36550SArmin Le Grand 
42421b36550SArmin Le Grand             if(aBitmapEx.IsTransparent())
42521b36550SArmin Le Grand             {
42621b36550SArmin Le Grand                 // draw checkered background
42721b36550SArmin Le Grand                 drawTransparenceBackground(*pDev, aPos, aBitmapExSizePixel);
42821b36550SArmin Le Grand             }
42921b36550SArmin Le Grand 
43021b36550SArmin Le Grand             pDev->DrawBitmapEx(aPos, aBitmapEx);
43121b36550SArmin Le Grand         }
43221b36550SArmin Le Grand 
43321b36550SArmin Le Grand         SetItemText(nId, aItemTextTitle);
43421b36550SArmin Le Grand 
43521b36550SArmin Le Grand         //SgaObject* pObj = mpTheme->AcquireObject( nId - 1 );
43621b36550SArmin Le Grand         //
43721b36550SArmin Le Grand         //if( pObj )
43821b36550SArmin Le Grand         //{
43921b36550SArmin Le Grand         //    const Rectangle& rRect = rUDEvt.GetRect();
44021b36550SArmin Le Grand         //    const Size aSize(rRect.GetWidth(), rRect.GetHeight());
44121b36550SArmin Le Grand         //    const BitmapEx aBitmapEx(pObj->createPreviewBitmapEx(aSize));
44221b36550SArmin Le Grand         //    const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
44321b36550SArmin Le Grand         //
44421b36550SArmin Le Grand         //    if(!aBitmapEx.IsEmpty())
44521b36550SArmin Le Grand         //    {
44621b36550SArmin Le Grand         //        const Point aPos(
44721b36550SArmin Le Grand         //            ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
44821b36550SArmin Le Grand         //            ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
44921b36550SArmin Le Grand         //        OutputDevice* pDev = rUDEvt.GetDevice();
45021b36550SArmin Le Grand         //
45121b36550SArmin Le Grand         //        if(aBitmapEx.IsTransparent())
45221b36550SArmin Le Grand         //        {
45321b36550SArmin Le Grand         //            // draw checkered background
45421b36550SArmin Le Grand         //            drawTransparenceBackground(*pDev, aPos, aBitmapExSizePixel);
45521b36550SArmin Le Grand         //        }
45621b36550SArmin Le Grand         //
45721b36550SArmin Le Grand         //        pDev->DrawBitmapEx(aPos, aBitmapEx);
45821b36550SArmin Le Grand         //    }
45921b36550SArmin Le Grand         //
46021b36550SArmin Le Grand         //  //const Rectangle&  rRect = rUDEvt.GetRect();
46121b36550SArmin Le Grand         //  //OutputDevice*     pDev = rUDEvt.GetDevice();
46221b36550SArmin Le Grand         //  //Graphic           aGraphic;
46321b36550SArmin Le Grand         //    //bool bTransparent(false);
46421b36550SArmin Le Grand         //    //
46521b36550SArmin Le Grand         //  //if( pObj->IsThumbBitmap() )
46621b36550SArmin Le Grand         //  //{
46721b36550SArmin Le Grand         //  //  BitmapEx aBitmapEx;
46821b36550SArmin Le Grand         //    //
46921b36550SArmin Le Grand         //  //  if( pObj->GetObjKind() == SGA_OBJ_SOUND )
47021b36550SArmin Le Grand         //    //    {
47121b36550SArmin Le Grand         //    //        Bitmap aTemp = pObj->GetThumbBmp().GetBitmap();
47221b36550SArmin Le Grand         //    //
47321b36550SArmin Le Grand         //    //        aTemp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
47421b36550SArmin Le Grand         //    //        aBitmapEx = BitmapEx(aTemp);
47521b36550SArmin Le Grand         //    //    }
47621b36550SArmin Le Grand         //    //    else
47721b36550SArmin Le Grand         //    //    {
47821b36550SArmin Le Grand         //    //        aBitmapEx = pObj->GetThumbBmp();
47921b36550SArmin Le Grand         //    //        bTransparent = aBitmapEx.IsTransparent();
48021b36550SArmin Le Grand         //    //    }
48121b36550SArmin Le Grand         //    //
48221b36550SArmin Le Grand         //  //  if( ( pDev->GetBitCount() <= 8 ) && ( aBitmapEx.GetBitCount() >= 8 ) )
48321b36550SArmin Le Grand         //    //    {
48421b36550SArmin Le Grand         //  //      aBitmapEx.Dither( BMP_DITHER_FLOYD );
48521b36550SArmin Le Grand         //    //    }
48621b36550SArmin Le Grand         //    //
48721b36550SArmin Le Grand         //  //  aGraphic = aBitmapEx;
48821b36550SArmin Le Grand         //  //}
48921b36550SArmin Le Grand         //  //else
49021b36550SArmin Le Grand         //    //{
49121b36550SArmin Le Grand         //  //  aGraphic = pObj->GetThumbMtf();
49221b36550SArmin Le Grand         //    //    bTransparent = true;
49321b36550SArmin Le Grand         //    //}
49421b36550SArmin Le Grand         //    //
49521b36550SArmin Le Grand         //  //Size aSize( aGraphic.GetSizePixel( pDev ) );
49621b36550SArmin Le Grand         //    //
49721b36550SArmin Le Grand         //  //if ( aSize.Width() && aSize.Height() )
49821b36550SArmin Le Grand         //  //{
49921b36550SArmin Le Grand         //  //  if( ( aSize.Width() > rRect.GetWidth() ) || ( aSize.Height() > rRect.GetHeight() ) )
50021b36550SArmin Le Grand         //  //  {
50121b36550SArmin Le Grand         //  //      Point           aNewPos;
50221b36550SArmin Le Grand         //  //      const double    fBmpWH  = (double) aSize.Width() / aSize.Height();
50321b36550SArmin Le Grand         //  //      const double    fThmpWH = (double) rRect.GetWidth() / rRect.GetHeight();
50421b36550SArmin Le Grand         //    //
50521b36550SArmin Le Grand         //  //      // Bitmap an Thumbgroesse anpassen
50621b36550SArmin Le Grand         //  //      if ( fBmpWH < fThmpWH )
50721b36550SArmin Le Grand         //  //      {
50821b36550SArmin Le Grand         //  //          aSize.Width() = (long) ( rRect.GetHeight() * fBmpWH );
50921b36550SArmin Le Grand         //  //          aSize.Height()= rRect.GetHeight();
51021b36550SArmin Le Grand         //  //      }
51121b36550SArmin Le Grand         //  //      else
51221b36550SArmin Le Grand         //  //      {
51321b36550SArmin Le Grand         //  //          aSize.Width() = rRect.GetWidth();
51421b36550SArmin Le Grand         //  //          aSize.Height()= (long) ( rRect.GetWidth() / fBmpWH );
51521b36550SArmin Le Grand         //  //      }
51621b36550SArmin Le Grand         //  //  }
51721b36550SArmin Le Grand         //    //
51821b36550SArmin Le Grand         //  //  const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(),
51921b36550SArmin Le Grand         //  //                    ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() );
52021b36550SArmin Le Grand         //    //
52121b36550SArmin Le Grand         //    //    if(bTransparent)
52221b36550SArmin Le Grand         //    //    {
52321b36550SArmin Le Grand         //    //        // draw checkered background
52421b36550SArmin Le Grand         //    //        drawTransparenceBackground(*pDev, aPos, aSize);
52521b36550SArmin Le Grand         //    //    }
52621b36550SArmin Le Grand         //    //
52721b36550SArmin Le Grand         //  //  aGraphic.Draw( pDev, aPos, aSize );
52821b36550SArmin Le Grand         //  //}
52921b36550SArmin Le Grand         //
53021b36550SArmin Le Grand         //  SetItemText( nId, GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE) );
53121b36550SArmin Le Grand         //  mpTheme->ReleaseObject( pObj );
53221b36550SArmin Le Grand         //}
53321b36550SArmin Le Grand     }
534cdf0e10cSrcweir }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir // ------------------------------------------------------------------------
537cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)538cdf0e10cSrcweir void GalleryIconView::MouseButtonDown( const MouseEvent& rMEvt )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir     ValueSet::MouseButtonDown( rMEvt );
541cdf0e10cSrcweir 
542cdf0e10cSrcweir     if( rMEvt.GetClicks() == 2 )
543cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rMEvt.GetPosPixel() );
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir // ------------------------------------------------------------------------
547cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)548cdf0e10cSrcweir void GalleryIconView::Command( const CommandEvent& rCEvt )
549cdf0e10cSrcweir {
550cdf0e10cSrcweir     ValueSet::Command( rCEvt );
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
553cdf0e10cSrcweir     {
554cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this,
555cdf0e10cSrcweir             ( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) );
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir // ------------------------------------------------------------------------
560cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)561cdf0e10cSrcweir void GalleryIconView::KeyInput( const KeyEvent& rKEvt )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
564cdf0e10cSrcweir         ValueSet::KeyInput( rKEvt );
565cdf0e10cSrcweir }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir // ------------------------------------------------------------------------
568cdf0e10cSrcweir 
AcceptDrop(const AcceptDropEvent & rEvt)569cdf0e10cSrcweir sal_Int8 GalleryIconView::AcceptDrop( const AcceptDropEvent& rEvt )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir     return( static_cast< GalleryBrowser2* >( GetParent() )->AcceptDrop( *this, rEvt ) );
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
574cdf0e10cSrcweir // ------------------------------------------------------------------------
575cdf0e10cSrcweir 
ExecuteDrop(const ExecuteDropEvent & rEvt)576cdf0e10cSrcweir sal_Int8 GalleryIconView::ExecuteDrop( const ExecuteDropEvent& rEvt )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir     return( static_cast< GalleryBrowser2* >( GetParent() )->ExecuteDrop( *this, rEvt ) );
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir // ------------------------------------------------------------------------
582cdf0e10cSrcweir 
StartDrag(sal_Int8,const Point &)583cdf0e10cSrcweir void GalleryIconView::StartDrag( sal_Int8, const Point& )
584cdf0e10cSrcweir {
585cdf0e10cSrcweir     const CommandEvent  aEvt( GetPointerPosPixel(), COMMAND_STARTDRAG, sal_True );
586cdf0e10cSrcweir     Region              aRegion;
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     // call this to initiate dragging for ValueSet
589cdf0e10cSrcweir     ValueSet::StartDrag( aEvt, aRegion );
590cdf0e10cSrcweir     static_cast< GalleryBrowser2* >( GetParent() )->StartDrag( this );
591cdf0e10cSrcweir }
592cdf0e10cSrcweir 
593cdf0e10cSrcweir // -------------------
594cdf0e10cSrcweir // - GalleryListView -
595cdf0e10cSrcweir // -------------------
DBG_NAME(GalleryListView)596cdf0e10cSrcweir DBG_NAME(GalleryListView)
597cdf0e10cSrcweir 
598cdf0e10cSrcweir GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
599cdf0e10cSrcweir     BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ),
600cdf0e10cSrcweir     mpTheme( pTheme ),
601cdf0e10cSrcweir     mnCurRow( 0 ),
602cdf0e10cSrcweir     mbInit( sal_False )
603cdf0e10cSrcweir {
604cdf0e10cSrcweir     DBG_CTOR(GalleryListView,NULL);
605cdf0e10cSrcweir 
606cdf0e10cSrcweir     SetHelpId( HID_GALLERY_WINDOW );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir     InitSettings();
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     SetMode( BROWSER_AUTO_VSCROLL | BROWSER_AUTOSIZE_LASTCOL );
611cdf0e10cSrcweir     SetDataRowHeight( 28 );
612cdf0e10cSrcweir     InsertDataColumn( GALLERY_BRWBOX_TITLE, String( GAL_RESID( RID_SVXSTR_GALLERY_TITLE ) ), 256  );
613cdf0e10cSrcweir     InsertDataColumn( GALLERY_BRWBOX_PATH, String( GAL_RESID( RID_SVXSTR_GALLERY_PATH ) ), 256 );
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
616cdf0e10cSrcweir // ------------------------------------------------------------------------
617cdf0e10cSrcweir 
~GalleryListView()618cdf0e10cSrcweir GalleryListView::~GalleryListView()
619cdf0e10cSrcweir {
620cdf0e10cSrcweir 
621cdf0e10cSrcweir     DBG_DTOR(GalleryListView,NULL);
622cdf0e10cSrcweir }
623cdf0e10cSrcweir 
624cdf0e10cSrcweir // ------------------------------------------------------------------------
625cdf0e10cSrcweir 
InitSettings()626cdf0e10cSrcweir void GalleryListView::InitSettings()
627cdf0e10cSrcweir {
628cdf0e10cSrcweir     SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
629cdf0e10cSrcweir     SetControlBackground( GALLERY_BG_COLOR );
630cdf0e10cSrcweir     SetControlForeground( GALLERY_FG_COLOR );
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir // -----------------------------------------------------------------------
634cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)635cdf0e10cSrcweir void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
638cdf0e10cSrcweir         InitSettings();
639cdf0e10cSrcweir     else
640cdf0e10cSrcweir         BrowseBox::DataChanged( rDCEvt );
641cdf0e10cSrcweir }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir // ------------------------------------------------------------------------
644cdf0e10cSrcweir 
SeekRow(long nRow)645cdf0e10cSrcweir sal_Bool GalleryListView::SeekRow( long nRow )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir     mnCurRow = nRow;
648cdf0e10cSrcweir     return sal_True;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // -----------------------------------------------------------------------------
652cdf0e10cSrcweir 
GetCellText(long _nRow,sal_uInt16 nColumnId) const653cdf0e10cSrcweir String GalleryListView::GetCellText(long _nRow, sal_uInt16 nColumnId) const
654cdf0e10cSrcweir {
655cdf0e10cSrcweir     String sRet;
656cdf0e10cSrcweir     if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) )
657cdf0e10cSrcweir     {
658cdf0e10cSrcweir         SgaObject* pObj = mpTheme->AcquireObject( _nRow );
659cdf0e10cSrcweir 
660cdf0e10cSrcweir         if( pObj )
661cdf0e10cSrcweir         {
662cdf0e10cSrcweir             sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj,
663cdf0e10cSrcweir                 ( GALLERY_BRWBOX_TITLE == nColumnId ) ? GALLERY_ITEM_TITLE : GALLERY_ITEM_PATH );
664cdf0e10cSrcweir 
665cdf0e10cSrcweir             mpTheme->ReleaseObject( pObj );
666cdf0e10cSrcweir         }
667cdf0e10cSrcweir     }
668cdf0e10cSrcweir 
669*a22fd41bSmseidel     return sRet;
670cdf0e10cSrcweir }
671cdf0e10cSrcweir 
672cdf0e10cSrcweir // -----------------------------------------------------------------------------
673cdf0e10cSrcweir 
GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex)674cdf0e10cSrcweir Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex)
675cdf0e10cSrcweir {
676cdf0e10cSrcweir     DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow");
677cdf0e10cSrcweir     Rectangle aRect;
678cdf0e10cSrcweir     if ( SeekRow(_nRow) )
679cdf0e10cSrcweir     {
680cdf0e10cSrcweir         SvxFont aFont( GetFont() );
681cdf0e10cSrcweir         AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir         // get the bounds inside the string
684cdf0e10cSrcweir         aStringWrap.GetCharacterBounds(nIndex, aRect);
685cdf0e10cSrcweir 
686cdf0e10cSrcweir         // offset to
687cdf0e10cSrcweir     }
688cdf0e10cSrcweir     return aRect;
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir // -----------------------------------------------------------------------------
692cdf0e10cSrcweir 
GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point & _rPoint)693cdf0e10cSrcweir sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
694cdf0e10cSrcweir {
695cdf0e10cSrcweir     DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow");
696cdf0e10cSrcweir     sal_Int32 nRet = -1;
697cdf0e10cSrcweir     if ( SeekRow(_nRow) )
698cdf0e10cSrcweir     {
699cdf0e10cSrcweir         SvxFont aFont( GetFont() );
700cdf0e10cSrcweir         AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) );
701cdf0e10cSrcweir         nRet = aStringWrap.GetIndexAtPoint(_rPoint);
702cdf0e10cSrcweir     }
703cdf0e10cSrcweir     return nRet;
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir // ------------------------------------------------------------------------
707cdf0e10cSrcweir 
PaintField(OutputDevice & rDev,const Rectangle & rRect,sal_uInt16 nColumnId) const708cdf0e10cSrcweir void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
709cdf0e10cSrcweir {
710cdf0e10cSrcweir     rDev.Push( PUSH_CLIPREGION );
711cdf0e10cSrcweir     rDev.IntersectClipRegion( rRect );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     if( mpTheme && ( mnCurRow < mpTheme->GetObjectCount() ) )
714cdf0e10cSrcweir     {
71521b36550SArmin Le Grand         const Size aSize(rRect.GetHeight(), rRect.GetHeight());
71621b36550SArmin Le Grand         BitmapEx aBitmapEx;
71721b36550SArmin Le Grand         Size aPreparedSize;
71821b36550SArmin Le Grand         String aItemTextTitle;
71921b36550SArmin Le Grand         String aItemTextPath;
72021b36550SArmin Le Grand 
72121b36550SArmin Le Grand         mpTheme->GetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);
72221b36550SArmin Le Grand 
72321b36550SArmin Le Grand         bool bNeedToCreate(aBitmapEx.IsEmpty());
72421b36550SArmin Le Grand 
72521b36550SArmin Le Grand         if(!bNeedToCreate && GALLERY_BRWBOX_TITLE == nColumnId && !aItemTextTitle.Len())
72621b36550SArmin Le Grand         {
72721b36550SArmin Le Grand             bNeedToCreate = true;
72821b36550SArmin Le Grand         }
72921b36550SArmin Le Grand 
73021b36550SArmin Le Grand         if(!bNeedToCreate && GALLERY_BRWBOX_PATH == nColumnId && !aItemTextPath.Len())
73121b36550SArmin Le Grand         {
73221b36550SArmin Le Grand             bNeedToCreate = true;
73321b36550SArmin Le Grand         }
73421b36550SArmin Le Grand 
73521b36550SArmin Le Grand         if(!bNeedToCreate && aPreparedSize != aSize)
73621b36550SArmin Le Grand         {
73721b36550SArmin Le Grand             bNeedToCreate = true;
73821b36550SArmin Le Grand         }
73921b36550SArmin Le Grand 
74021b36550SArmin Le Grand         if(bNeedToCreate)
74121b36550SArmin Le Grand         {
742cdf0e10cSrcweir             SgaObject* pObj = mpTheme->AcquireObject(mnCurRow);
743cdf0e10cSrcweir 
744cdf0e10cSrcweir             if(pObj)
745cdf0e10cSrcweir             {
74621b36550SArmin Le Grand                 aBitmapEx = pObj->createPreviewBitmapEx(aSize);
74721b36550SArmin Le Grand                 aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GALLERY_ITEM_TITLE);
74821b36550SArmin Le Grand                 aItemTextPath = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GALLERY_ITEM_PATH);
74921b36550SArmin Le Grand 
75021b36550SArmin Le Grand                 mpTheme->SetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
75121b36550SArmin Le Grand                 mpTheme->ReleaseObject(pObj);
75221b36550SArmin Le Grand             }
75321b36550SArmin Le Grand         }
75421b36550SArmin Le Grand 
75521b36550SArmin Le Grand         const long nTextPosY(rRect.Top() + ((rRect.GetHeight() - rDev.GetTextHeight()) >> 1));
756cdf0e10cSrcweir 
757cdf0e10cSrcweir         if(GALLERY_BRWBOX_TITLE == nColumnId)
758cdf0e10cSrcweir         {
75921b36550SArmin Le Grand             if(!aBitmapEx.IsEmpty())
7606dd94783SArmin Le Grand             {
76121b36550SArmin Le Grand                 const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
76221b36550SArmin Le Grand                 const Point aPos(
76321b36550SArmin Le Grand                     ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
76421b36550SArmin Le Grand                     ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
7656dd94783SArmin Le Grand 
76621b36550SArmin Le Grand                 if(aBitmapEx.IsTransparent())
7676dd94783SArmin Le Grand                 {
7686dd94783SArmin Le Grand                     // draw checkered background
76921b36550SArmin Le Grand                     drawTransparenceBackground(rDev, aPos, aBitmapExSizePixel);
7706dd94783SArmin Le Grand                 }
7716dd94783SArmin Le Grand 
77221b36550SArmin Le Grand                 rDev.DrawBitmapEx(aPos, aBitmapEx);
773cdf0e10cSrcweir             }
774cdf0e10cSrcweir 
77521b36550SArmin Le Grand             rDev.DrawText(Point(rRect.Left() + rRect.GetHeight() + 6, nTextPosY), aItemTextTitle);
776cdf0e10cSrcweir         }
777cdf0e10cSrcweir         else if(GALLERY_BRWBOX_PATH == nColumnId)
77821b36550SArmin Le Grand         {
77921b36550SArmin Le Grand             rDev.DrawText(Point(rRect.Left(), nTextPosY), aItemTextPath);
780cdf0e10cSrcweir         }
78121b36550SArmin Le Grand 
78221b36550SArmin Le Grand 
78321b36550SArmin Le Grand         //SgaObject* pObj = mpTheme->AcquireObject( mnCurRow );
78421b36550SArmin Le Grand         //
78521b36550SArmin Le Grand         //if( pObj )
78621b36550SArmin Le Grand         //{
78721b36550SArmin Le Grand         //    const long nTextPosY = rRect.Top() + ( ( rRect.GetHeight() - rDev.GetTextHeight() ) >> 1 );
78821b36550SArmin Le Grand         //
78921b36550SArmin Le Grand         //    if( GALLERY_BRWBOX_TITLE == nColumnId )
79021b36550SArmin Le Grand         //    {
79121b36550SArmin Le Grand         //        const Size aSize(rRect.GetHeight(), rRect.GetHeight());
79221b36550SArmin Le Grand         //        const BitmapEx aBitmapEx(pObj->createPreviewBitmapEx(aSize));
79321b36550SArmin Le Grand         //        const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
79421b36550SArmin Le Grand         //
79521b36550SArmin Le Grand         //        if(!aBitmapEx.IsEmpty())
79621b36550SArmin Le Grand         //        {
79721b36550SArmin Le Grand         //            const Point aPos(
79821b36550SArmin Le Grand         //                ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
79921b36550SArmin Le Grand         //                ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
80021b36550SArmin Le Grand         //
80121b36550SArmin Le Grand         //            if(aBitmapEx.IsTransparent())
80221b36550SArmin Le Grand         //            {
80321b36550SArmin Le Grand         //                // draw checkered background
80421b36550SArmin Le Grand         //                drawTransparenceBackground(rDev, aPos, aBitmapExSizePixel);
80521b36550SArmin Le Grand         //            }
80621b36550SArmin Le Grand         //
80721b36550SArmin Le Grand         //            rDev.DrawBitmapEx(aPos, aBitmapEx);
80821b36550SArmin Le Grand         //        }
80921b36550SArmin Le Grand         //
81021b36550SArmin Le Grand         //
81121b36550SArmin Le Grand         //        //Rectangle       aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) );
81221b36550SArmin Le Grand         //      //GraphicObject   aGrfObj;
81321b36550SArmin Le Grand         //        //bool bTransparent(false);
81421b36550SArmin Le Grand         //        //
81521b36550SArmin Le Grand         //        //if( pObj->GetObjKind() == SGA_OBJ_SOUND )
81621b36550SArmin Le Grand         //        //{
81721b36550SArmin Le Grand         //        //    aGrfObj = Graphic( BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) ) );
81821b36550SArmin Le Grand         //        //}
81921b36550SArmin Le Grand         //        //else if( pObj->IsThumbBitmap() )
82021b36550SArmin Le Grand         //        //{
82121b36550SArmin Le Grand         //        //    const BitmapEx aBitmapEx(pObj->GetThumbBmp());
82221b36550SArmin Le Grand         //        //
82321b36550SArmin Le Grand         //        //    bTransparent = aBitmapEx.IsTransparent();
82421b36550SArmin Le Grand         //      //    aGrfObj = Graphic(aBitmapEx);
82521b36550SArmin Le Grand         //        //}
82621b36550SArmin Le Grand         //      //else
82721b36550SArmin Le Grand         //        //{
82821b36550SArmin Le Grand         //      //    aGrfObj = Graphic( pObj->GetThumbMtf() );
82921b36550SArmin Le Grand         //        //    bTransparent = true;
83021b36550SArmin Le Grand         //        //}
83121b36550SArmin Le Grand         //        //
83221b36550SArmin Le Grand         //      //Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) );
83321b36550SArmin Le Grand         //        //
83421b36550SArmin Le Grand         //      //if( aSize.Width() && aSize.Height() )
83521b36550SArmin Le Grand         //      //{
83621b36550SArmin Le Grand         //      //    if( ( aSize.Width() > aOutputRect.GetWidth() ) || ( aSize.Height() > aOutputRect.GetHeight() ) )
83721b36550SArmin Le Grand         //      //    {
83821b36550SArmin Le Grand         //      //      Point           aNewPos;
83921b36550SArmin Le Grand         //      //      const double    fBmpWH  = (double) aSize.Width() / aSize.Height();
84021b36550SArmin Le Grand         //      //      const double    fThmpWH = (double) aOutputRect.GetWidth() / aOutputRect.GetHeight();
84121b36550SArmin Le Grand         //        //
84221b36550SArmin Le Grand         //      //      // Bitmap an Thumbgroesse anpassen
84321b36550SArmin Le Grand         //      //      if ( fBmpWH < fThmpWH )
84421b36550SArmin Le Grand         //      //      {
84521b36550SArmin Le Grand         //      //          aSize.Width() = (long) ( aOutputRect.GetHeight() * fBmpWH );
84621b36550SArmin Le Grand         //      //          aSize.Height()= aOutputRect.GetHeight();
84721b36550SArmin Le Grand         //      //      }
84821b36550SArmin Le Grand         //      //      else
84921b36550SArmin Le Grand         //      //      {
85021b36550SArmin Le Grand         //      //          aSize.Width() = aOutputRect.GetWidth();
85121b36550SArmin Le Grand         //      //          aSize.Height()= (long) ( aOutputRect.GetWidth() / fBmpWH );
85221b36550SArmin Le Grand         //      //      }
85321b36550SArmin Le Grand         //      //    }
85421b36550SArmin Le Grand         //        //
85521b36550SArmin Le Grand         //        //    aSize.Width() = Max( aSize.Width(), 4L );
85621b36550SArmin Le Grand         //        //    aSize.Height() = Max( aSize.Height(), 4L );
85721b36550SArmin Le Grand         //        //
85821b36550SArmin Le Grand         //      //    const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(),
85921b36550SArmin Le Grand         //      //                    ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() );
86021b36550SArmin Le Grand         //        //
86121b36550SArmin Le Grand         //        //    if(bTransparent)
86221b36550SArmin Le Grand         //        //    {
86321b36550SArmin Le Grand         //        //        // draw checkered background
86421b36550SArmin Le Grand         //        //        drawTransparenceBackground(rDev, aPos, aSize);
86521b36550SArmin Le Grand         //        //    }
86621b36550SArmin Le Grand         //        //
86721b36550SArmin Le Grand         //        //    aGrfObj.Draw( &rDev, aPos, aSize );
86821b36550SArmin Le Grand         //      //}
86921b36550SArmin Le Grand         //
87021b36550SArmin Le Grand         //        // aOutputRect.Right() is here rRect.Left() + rRect.GetHeight()
87121b36550SArmin Le Grand         //      rDev.DrawText( Point( rRect.Left() + rRect.GetHeight() + 6, nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE ) );
87221b36550SArmin Le Grand         //    }
87321b36550SArmin Le Grand         //    else if( GALLERY_BRWBOX_PATH == nColumnId )
87421b36550SArmin Le Grand         //    {
87521b36550SArmin Le Grand         //        rDev.DrawText( Point( rRect.Left(), nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_PATH ) );
87621b36550SArmin Le Grand         //    }
87721b36550SArmin Le Grand         //
87821b36550SArmin Le Grand         //    mpTheme->ReleaseObject( pObj );
87921b36550SArmin Le Grand         //}
880cdf0e10cSrcweir     }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir     rDev.Pop();
883cdf0e10cSrcweir }
884cdf0e10cSrcweir 
885cdf0e10cSrcweir // ------------------------------------------------------------------------
886cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)887cdf0e10cSrcweir void GalleryListView::Command( const CommandEvent& rCEvt )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir     BrowseBox::Command( rCEvt );
890cdf0e10cSrcweir 
891cdf0e10cSrcweir     if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
892cdf0e10cSrcweir     {
893cdf0e10cSrcweir         const Point* pPos = NULL;
894cdf0e10cSrcweir 
895cdf0e10cSrcweir         if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) )
896cdf0e10cSrcweir             pPos = &rCEvt.GetMousePosPixel();
897cdf0e10cSrcweir 
898cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, pPos );
899cdf0e10cSrcweir     }
900cdf0e10cSrcweir }
901cdf0e10cSrcweir 
902cdf0e10cSrcweir // ------------------------------------------------------------------------
903cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)904cdf0e10cSrcweir void GalleryListView::KeyInput( const KeyEvent& rKEvt )
905cdf0e10cSrcweir {
906cdf0e10cSrcweir     if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
907cdf0e10cSrcweir         BrowseBox::KeyInput( rKEvt );
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
910cdf0e10cSrcweir // ------------------------------------------------------------------------
911cdf0e10cSrcweir 
DoubleClick(const BrowserMouseEvent & rEvt)912cdf0e10cSrcweir void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt )
913cdf0e10cSrcweir {
914cdf0e10cSrcweir     BrowseBox::DoubleClick( rEvt );
915cdf0e10cSrcweir 
916cdf0e10cSrcweir     if( rEvt.GetRow() != BROWSER_ENDOFSELECTION )
917cdf0e10cSrcweir         ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rEvt.GetPosPixel() );
918cdf0e10cSrcweir }
919cdf0e10cSrcweir 
920cdf0e10cSrcweir // ------------------------------------------------------------------------
921cdf0e10cSrcweir 
Select()922cdf0e10cSrcweir void GalleryListView::Select()
923cdf0e10cSrcweir {
924cdf0e10cSrcweir     if( maSelectHdl.IsSet() )
925cdf0e10cSrcweir         maSelectHdl.Call( this );
926cdf0e10cSrcweir }
927cdf0e10cSrcweir 
928cdf0e10cSrcweir // ------------------------------------------------------------------------
929cdf0e10cSrcweir 
AcceptDrop(const BrowserAcceptDropEvent &)930cdf0e10cSrcweir sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& )
931cdf0e10cSrcweir {
932cdf0e10cSrcweir     sal_Int8 nRet = DND_ACTION_NONE;
933cdf0e10cSrcweir 
934cdf0e10cSrcweir     if( mpTheme && !mpTheme->IsReadOnly() && !mpTheme ->IsImported() )
935cdf0e10cSrcweir     {
936cdf0e10cSrcweir         if( !mpTheme->IsDragging() )
937cdf0e10cSrcweir             nRet = DND_ACTION_COPY;
938cdf0e10cSrcweir         else
939cdf0e10cSrcweir             nRet = DND_ACTION_COPY;
940cdf0e10cSrcweir     }
941cdf0e10cSrcweir 
942cdf0e10cSrcweir     return nRet;
943cdf0e10cSrcweir }
944cdf0e10cSrcweir 
945cdf0e10cSrcweir // ------------------------------------------------------------------------
946cdf0e10cSrcweir 
ExecuteDrop(const BrowserExecuteDropEvent & rEvt)947cdf0e10cSrcweir sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
948cdf0e10cSrcweir {
949cdf0e10cSrcweir     ExecuteDropEvent aEvt( rEvt );
950cdf0e10cSrcweir 
951cdf0e10cSrcweir     aEvt.maPosPixel.Y() += GetTitleHeight();
952cdf0e10cSrcweir 
953cdf0e10cSrcweir     return( ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, aEvt ) );
954cdf0e10cSrcweir }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir // ------------------------------------------------------------------------
957cdf0e10cSrcweir 
StartDrag(sal_Int8,const Point & rPosPixel)958cdf0e10cSrcweir void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel )
959cdf0e10cSrcweir {
960cdf0e10cSrcweir     ( (GalleryBrowser2*) GetParent() )->StartDrag( this, &rPosPixel );
961cdf0e10cSrcweir }
962