xref: /aoo41x/main/svx/source/gallery2/galctrl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <vcl/svapp.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <avmedia/mediaplayer.hxx>
35 #include "helpid.hrc"
36 #include "galbrws2.hxx"
37 #include "svx/galtheme.hxx"
38 #include "svx/galmisc.hxx"
39 #include "svx/galctrl.hxx"
40 #include "editeng/AccessibleStringWrap.hxx"
41 #include <editeng/svxfont.hxx>
42 #include "galobj.hxx"
43 #include <avmedia/mediawindow.hxx>
44 #include "gallery.hrc"
45 #include <svtools/filter.hxx>
46 
47 // -----------
48 // - Defines -
49 // -----------
50 
51 #define GALLERY_BRWBOX_TITLE    1
52 #define GALLERY_BRWBOX_PATH     2
53 
54 // ------------------
55 // - GalleryPreview -
56 // ------------------
57 DBG_NAME(GalleryPreview)
58 
59 GalleryPreview::GalleryPreview( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
60 	Window( pParent, WB_TABSTOP | WB_BORDER ),
61 	DropTargetHelper( this ),
62     DragSourceHelper( this ),
63     mpTheme( pTheme )
64 {
65     DBG_CTOR(GalleryPreview,NULL);
66 
67 	SetHelpId( HID_GALLERY_WINDOW );
68     InitSettings();
69 }
70 
71 // ------------------------------------------------------------------------
72 
73 GalleryPreview::GalleryPreview( Window* pParent, const ResId & rResId  ) :
74 	Window( pParent, rResId ),
75 	DropTargetHelper( this ),
76     DragSourceHelper( this ),
77     mpTheme( NULL )
78 {
79     DBG_CTOR(GalleryPreview,NULL);
80 
81 	SetHelpId( HID_GALLERY_PREVIEW );
82     InitSettings();
83 }
84 
85 // ------------------------------------------------------------------------
86 
87 GalleryPreview::~GalleryPreview()
88 {
89 
90     DBG_DTOR(GalleryPreview,NULL);
91 }
92 
93 
94 bool GalleryPreview::SetGraphic( const INetURLObject& _aURL )
95 {
96 	bool bRet = true;
97 	Graphic	aGraphic;
98     if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
99 	{
100 		aGraphic = BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) );
101 	}
102 	else
103 	{
104 		GraphicFilter*  pFilter = GraphicFilter::GetGraphicFilter();
105 		GalleryProgress aProgress( pFilter );
106         if( pFilter->ImportGraphic( aGraphic, _aURL, GRFILTER_FORMAT_DONTKNOW ) )
107 			bRet = false;
108 	}
109 
110 	SetGraphic( aGraphic );
111 	Invalidate();
112 	return bRet;
113 }
114 
115 // ------------------------------------------------------------------------
116 
117 void GalleryPreview::InitSettings()
118 {
119 	SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
120 	SetControlBackground( GALLERY_BG_COLOR );
121 	SetControlForeground( GALLERY_FG_COLOR );
122 }
123 
124 // -----------------------------------------------------------------------
125 
126 void GalleryPreview::DataChanged( const DataChangedEvent& rDCEvt )
127 {
128 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
129 		InitSettings();
130 	else
131 		Window::DataChanged( rDCEvt );
132 }
133 
134 // ------------------------------------------------------------------------
135 
136 sal_Bool GalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
137 {
138 	const Size	aWinSize( GetOutputSizePixel() );
139 	Size		aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
140 	sal_Bool		bRet = sal_False;
141 
142 	if( aNewSize.Width() && aNewSize.Height() )
143 	{
144 		// scale to fit window
145 		const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
146 		const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
147 
148 		if ( fGrfWH < fWinWH )
149 		{
150 			aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
151 			aNewSize.Height()= aWinSize.Height();
152 		}
153 		else
154 		{
155 			aNewSize.Width() = aWinSize.Width();
156 			aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
157 		}
158 
159 		const Point aNewPos( ( aWinSize.Width()  - aNewSize.Width() ) >> 1,
160 							 ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
161 
162 		rResultRect = Rectangle( aNewPos, aNewSize );
163 		bRet = sal_True;
164 	}
165 
166 	return bRet;
167 }
168 
169 // ------------------------------------------------------------------------
170 
171 void GalleryPreview::Paint( const Rectangle& rRect )
172 {
173 	Window::Paint( rRect );
174 
175 	if( ImplGetGraphicCenterRect( aGraphicObj.GetGraphic(), aPreviewRect ) )
176 	{
177 		const Point aPos( aPreviewRect.TopLeft() );
178 		const Size	aSize( aPreviewRect.GetSize() );
179 
180 		if( aGraphicObj.IsAnimated() )
181 			aGraphicObj.StartAnimation( this, aPos, aSize );
182 		else
183 			aGraphicObj.Draw( this, aPos, aSize );
184 	}
185 }
186 
187 // ------------------------------------------------------------------------
188 
189 void GalleryPreview::MouseButtonDown( const MouseEvent& rMEvt )
190 {
191     if( mpTheme && ( rMEvt.GetClicks() == 2 ) )
192         ( (GalleryBrowser2*) GetParent() )->TogglePreview( this );
193 }
194 
195 // ------------------------------------------------------------------------
196 
197 void GalleryPreview::Command(const CommandEvent& rCEvt )
198 {
199 	Window::Command( rCEvt );
200 
201     if( mpTheme && ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) )
202         ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this,
203 			( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) );
204 }
205 
206 // ------------------------------------------------------------------------
207 
208 void GalleryPreview::KeyInput( const KeyEvent& rKEvt )
209 {
210     if( mpTheme )
211     {
212         GalleryBrowser2* pBrowser = static_cast< GalleryBrowser2* >( GetParent() );
213 
214         switch( rKEvt.GetKeyCode().GetCode() )
215         {
216             case( KEY_BACKSPACE ):
217                 pBrowser->TogglePreview( this );
218             break;
219 
220             case( KEY_HOME ):
221                 pBrowser->Travel( GALLERYBROWSERTRAVEL_FIRST );
222             break;
223 
224             case( KEY_END ):
225                 pBrowser->Travel( GALLERYBROWSERTRAVEL_LAST );
226             break;
227 
228             case( KEY_LEFT ):
229             case( KEY_UP ):
230                 pBrowser->Travel( GALLERYBROWSERTRAVEL_PREVIOUS );
231             break;
232 
233             case( KEY_RIGHT ):
234             case( KEY_DOWN ):
235                 pBrowser->Travel( GALLERYBROWSERTRAVEL_NEXT );
236             break;
237 
238             default:
239             {
240                 if( !pBrowser->KeyInput( rKEvt, this ) )
241                     Window::KeyInput( rKEvt );
242             }
243             break;
244         }
245     }
246     else
247         Window::KeyInput( rKEvt );
248 }
249 
250 // ------------------------------------------------------------------------
251 
252 sal_Int8 GalleryPreview::AcceptDrop( const AcceptDropEvent& rEvt )
253 {
254     sal_Int8 nRet;
255 
256     if( mpTheme )
257         nRet = ( (GalleryBrowser2*) GetParent() )->AcceptDrop( *this, rEvt );
258     else
259         nRet = DND_ACTION_NONE;
260 
261     return nRet;
262 }
263 
264 // ------------------------------------------------------------------------
265 
266 sal_Int8 GalleryPreview::ExecuteDrop( const ExecuteDropEvent& rEvt )
267 {
268     sal_Int8 nRet;
269 
270     if( mpTheme )
271         nRet = ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, rEvt );
272     else
273         nRet = DND_ACTION_NONE;
274 
275     return nRet;
276 }
277 
278 // ------------------------------------------------------------------------
279 
280 void GalleryPreview::StartDrag( sal_Int8, const Point& )
281 {
282     if( mpTheme )
283         ( (GalleryBrowser2*) GetParent() )->StartDrag( this );
284 }
285 
286 // ------------------------------------------------------------------------
287 
288 void GalleryPreview::PreviewMedia( const INetURLObject& rURL )
289 {
290 	if( rURL.GetProtocol() != INET_PROT_NOT_VALID )
291 	{
292 		::avmedia::MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
293 
294 		if( !pFloater )
295 		{
296 			SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_AVMEDIA_PLAYER, SFX_CALLMODE_SYNCHRON );
297 			pFloater = AVMEDIA_MEDIAWINDOW();
298 		}
299 
300 		if( pFloater )
301 			pFloater->setURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ), true );
302 	}
303 }
304 
305 // ------------------------------------------------------------------------
306 
307 // -------------------
308 // - GalleryIconView -
309 // -------------------
310 DBG_NAME(GalleryIconView)
311 
312 GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
313 		ValueSet( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET ),
314 		DropTargetHelper( this ),
315         DragSourceHelper( this ),
316 		mpTheme	( pTheme )
317 {
318     DBG_CTOR(GalleryIconView,NULL);
319 	EnableFullItemMode( sal_False );
320 
321 	SetHelpId( HID_GALLERY_WINDOW );
322     InitSettings();
323 	SetExtraSpacing( 2 );
324 	SetItemWidth( S_THUMB + 6 );
325 	SetItemHeight( S_THUMB + 6 );
326 }
327 
328 // ------------------------------------------------------------------------
329 
330 GalleryIconView::~GalleryIconView()
331 {
332 
333     DBG_DTOR(GalleryIconView,NULL);
334 }
335 
336 // ------------------------------------------------------------------------
337 
338 void GalleryIconView::InitSettings()
339 {
340 	SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
341 	SetControlBackground( GALLERY_BG_COLOR );
342 	SetControlForeground( GALLERY_FG_COLOR );
343 	SetColor( GALLERY_BG_COLOR );
344 }
345 
346 // -----------------------------------------------------------------------
347 
348 void GalleryIconView::DataChanged( const DataChangedEvent& rDCEvt )
349 {
350 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
351 		InitSettings();
352 	else
353 		ValueSet::DataChanged( rDCEvt );
354 }
355 
356 // ------------------------------------------------------------------------
357 
358 void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt )
359 {
360 	const sal_uInt16 nId = rUDEvt.GetItemId();
361 
362 	if( nId && mpTheme )
363 	{
364 		SgaObject* pObj = mpTheme->AcquireObject( nId - 1 );
365 
366 		if( pObj )
367 		{
368 			const Rectangle&	rRect = rUDEvt.GetRect();
369 			OutputDevice*		pDev = rUDEvt.GetDevice();
370 			Graphic 			aGraphic;
371 
372 			if( pObj->IsThumbBitmap() )
373 			{
374 				Bitmap aBmp( pObj->GetThumbBmp() );
375 
376 				if( pObj->GetObjKind() == SGA_OBJ_SOUND )
377 					aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
378 
379 				if( ( pDev->GetBitCount() <= 8 ) && ( aBmp.GetBitCount() >= 8 ) )
380 					aBmp.Dither( BMP_DITHER_FLOYD );
381 
382 				aGraphic = aBmp;
383 			}
384 			else
385 				aGraphic = pObj->GetThumbMtf();
386 
387 			Size aSize( aGraphic.GetSizePixel( pDev ) );
388 
389 			if ( aSize.Width() && aSize.Height() )
390 			{
391 				if( ( aSize.Width() > rRect.GetWidth() ) || ( aSize.Height() > rRect.GetHeight() ) )
392 				{
393 					Point			aNewPos;
394 					const double	fBmpWH	= (double) aSize.Width() / aSize.Height();
395 					const double	fThmpWH = (double) rRect.GetWidth() / rRect.GetHeight();
396 
397 					// Bitmap an Thumbgroesse anpassen
398 					if ( fBmpWH < fThmpWH )
399 					{
400 						aSize.Width() = (long) ( rRect.GetHeight() * fBmpWH );
401 						aSize.Height()= rRect.GetHeight();
402 					}
403 					else
404 					{
405 						aSize.Width() = rRect.GetWidth();
406 						aSize.Height()= (long) ( rRect.GetWidth() / fBmpWH );
407 					}
408 				}
409 
410 				const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(),
411 								  ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() );
412 
413 				aGraphic.Draw( pDev, aPos, aSize );
414 			}
415 
416 			SetItemText( nId, GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE) );
417 			mpTheme->ReleaseObject( pObj );
418 		}
419 	}
420 }
421 
422 // ------------------------------------------------------------------------
423 
424 void GalleryIconView::MouseButtonDown( const MouseEvent& rMEvt )
425 {
426     ValueSet::MouseButtonDown( rMEvt );
427 
428     if( rMEvt.GetClicks() == 2 )
429         ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rMEvt.GetPosPixel() );
430 }
431 
432 // ------------------------------------------------------------------------
433 
434 void GalleryIconView::Command( const CommandEvent& rCEvt )
435 {
436 	ValueSet::Command( rCEvt );
437 
438     if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
439 	{
440         ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this,
441 			( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) );
442 	}
443 }
444 
445 // ------------------------------------------------------------------------
446 
447 void GalleryIconView::KeyInput( const KeyEvent& rKEvt )
448 {
449     if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
450         ValueSet::KeyInput( rKEvt );
451 }
452 
453 // ------------------------------------------------------------------------
454 
455 sal_Int8 GalleryIconView::AcceptDrop( const AcceptDropEvent& rEvt )
456 {
457 	return( static_cast< GalleryBrowser2* >( GetParent() )->AcceptDrop( *this, rEvt ) );
458 }
459 
460 // ------------------------------------------------------------------------
461 
462 sal_Int8 GalleryIconView::ExecuteDrop( const ExecuteDropEvent& rEvt )
463 {
464 	return(	static_cast< GalleryBrowser2* >( GetParent() )->ExecuteDrop( *this, rEvt ) );
465 }
466 
467 // ------------------------------------------------------------------------
468 
469 void GalleryIconView::StartDrag( sal_Int8, const Point& )
470 {
471 	const CommandEvent	aEvt( GetPointerPosPixel(), COMMAND_STARTDRAG, sal_True );
472 	Region				aRegion;
473 
474 	// call this to initiate dragging for ValueSet
475     ValueSet::StartDrag( aEvt, aRegion );
476     static_cast< GalleryBrowser2* >( GetParent() )->StartDrag( this );
477 }
478 
479 // -------------------
480 // - GalleryListView -
481 // -------------------
482 DBG_NAME(GalleryListView)
483 
484 GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
485     BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ),
486     mpTheme( pTheme ),
487     mnCurRow( 0 ),
488     mbInit( sal_False )
489 {
490     DBG_CTOR(GalleryListView,NULL);
491 
492 	SetHelpId( HID_GALLERY_WINDOW );
493 
494     InitSettings();
495 
496     SetMode( BROWSER_AUTO_VSCROLL | BROWSER_AUTOSIZE_LASTCOL );
497     SetDataRowHeight( 28 );
498 	InsertDataColumn( GALLERY_BRWBOX_TITLE, String( GAL_RESID( RID_SVXSTR_GALLERY_TITLE ) ), 256  );
499 	InsertDataColumn( GALLERY_BRWBOX_PATH, String( GAL_RESID( RID_SVXSTR_GALLERY_PATH ) ), 256 );
500 }
501 
502 // ------------------------------------------------------------------------
503 
504 GalleryListView::~GalleryListView()
505 {
506 
507     DBG_DTOR(GalleryListView,NULL);
508 }
509 
510 // ------------------------------------------------------------------------
511 
512 void GalleryListView::InitSettings()
513 {
514 	SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
515 	SetControlBackground( GALLERY_BG_COLOR );
516 	SetControlForeground( GALLERY_FG_COLOR );
517 }
518 
519 // -----------------------------------------------------------------------
520 
521 void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt )
522 {
523 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
524 		InitSettings();
525 	else
526 		BrowseBox::DataChanged( rDCEvt );
527 }
528 
529 // ------------------------------------------------------------------------
530 
531 sal_Bool GalleryListView::SeekRow( long nRow )
532 {
533     mnCurRow = nRow;
534     return sal_True;
535 }
536 
537 // -----------------------------------------------------------------------------
538 
539 String GalleryListView::GetCellText(long _nRow, sal_uInt16 nColumnId) const
540 {
541 	String sRet;
542 	if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) )
543 	{
544     	SgaObject* pObj = mpTheme->AcquireObject( _nRow );
545 
546 		if( pObj )
547 		{
548 			sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj,
549 				( GALLERY_BRWBOX_TITLE == nColumnId ) ? GALLERY_ITEM_TITLE : GALLERY_ITEM_PATH );
550 
551 		    mpTheme->ReleaseObject( pObj );
552 		}
553 	}
554 
555 	return sRet;;
556 }
557 
558 // -----------------------------------------------------------------------------
559 
560 Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex)
561 {
562     DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow");
563 	Rectangle aRect;
564 	if ( SeekRow(_nRow) )
565 	{
566         SvxFont aFont( GetFont() );
567         AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) );
568 
569         // get the bounds inside the string
570         aStringWrap.GetCharacterBounds(nIndex, aRect);
571 
572         // offset to
573 	}
574 	return aRect;
575 }
576 
577 // -----------------------------------------------------------------------------
578 
579 sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
580 {
581     DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow");
582 	sal_Int32 nRet = -1;
583 	if ( SeekRow(_nRow) )
584 	{
585         SvxFont aFont( GetFont() );
586         AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) );
587         nRet = aStringWrap.GetIndexAtPoint(_rPoint);
588 	}
589 	return nRet;
590 }
591 
592 // ------------------------------------------------------------------------
593 
594 void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
595 {
596     rDev.Push( PUSH_CLIPREGION );
597     rDev.IntersectClipRegion( rRect );
598 
599 	if( mpTheme && ( mnCurRow < mpTheme->GetObjectCount() ) )
600 	{
601     	SgaObject* pObj = mpTheme->AcquireObject( mnCurRow );
602 
603 		if( pObj )
604 		{
605             const long nTextPosY = rRect.Top() + ( ( rRect.GetHeight() - rDev.GetTextHeight() ) >> 1 );
606 
607             if( GALLERY_BRWBOX_TITLE == nColumnId )
608             {
609                 Rectangle       aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) );
610     			GraphicObject   aGrfObj;
611 
612                 if( pObj->GetObjKind() == SGA_OBJ_SOUND )
613                     aGrfObj = Graphic( BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) ) );
614                 else if( pObj->IsThumbBitmap() )
615 				    aGrfObj = Graphic( pObj->GetThumbBmp() );
616 			    else
617 				    aGrfObj = Graphic( pObj->GetThumbMtf() );
618 
619 			    Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) );
620 
621 			    if( aSize.Width() && aSize.Height() )
622 			    {
623 				    if( ( aSize.Width() > aOutputRect.GetWidth() ) || ( aSize.Height() > aOutputRect.GetHeight() ) )
624 				    {
625 					    Point			aNewPos;
626 					    const double	fBmpWH	= (double) aSize.Width() / aSize.Height();
627 					    const double	fThmpWH = (double) aOutputRect.GetWidth() / aOutputRect.GetHeight();
628 
629 					    // Bitmap an Thumbgroesse anpassen
630 					    if ( fBmpWH < fThmpWH )
631 					    {
632 						    aSize.Width() = (long) ( aOutputRect.GetHeight() * fBmpWH );
633 						    aSize.Height()= aOutputRect.GetHeight();
634 					    }
635 					    else
636 					    {
637 						    aSize.Width() = aOutputRect.GetWidth();
638 						    aSize.Height()= (long) ( aOutputRect.GetWidth() / fBmpWH );
639 					    }
640 				    }
641 
642                     aSize.Width() = Max( aSize.Width(), 4L );
643                     aSize.Height() = Max( aSize.Height(), 4L );
644 
645 				    const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(),
646 								      ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() );
647 
648 				    aGrfObj.Draw( &rDev, aPos, aSize );
649 			    }
650 
651 			    rDev.DrawText( Point( aOutputRect.Right() + 6, nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE ) );
652             }
653             else if( GALLERY_BRWBOX_PATH == nColumnId )
654                 rDev.DrawText( Point( rRect.Left(), nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_PATH ) );
655 
656 		    mpTheme->ReleaseObject( pObj );
657 		}
658 	}
659 
660     rDev.Pop();
661 }
662 
663 // ------------------------------------------------------------------------
664 
665 void GalleryListView::Command( const CommandEvent& rCEvt )
666 {
667 	BrowseBox::Command( rCEvt );
668 
669     if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
670 	{
671 		const Point* pPos = NULL;
672 
673 		if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) )
674 			pPos = &rCEvt.GetMousePosPixel();
675 
676 		( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, pPos );
677 	}
678 }
679 
680 // ------------------------------------------------------------------------
681 
682 void GalleryListView::KeyInput( const KeyEvent& rKEvt )
683 {
684     if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
685         BrowseBox::KeyInput( rKEvt );
686 }
687 
688 // ------------------------------------------------------------------------
689 
690 void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt )
691 {
692     BrowseBox::DoubleClick( rEvt );
693 
694     if( rEvt.GetRow() != BROWSER_ENDOFSELECTION )
695         ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rEvt.GetPosPixel() );
696 }
697 
698 // ------------------------------------------------------------------------
699 
700 void GalleryListView::Select()
701 {
702     if( maSelectHdl.IsSet() )
703         maSelectHdl.Call( this );
704 }
705 
706 // ------------------------------------------------------------------------
707 
708 sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& )
709 {
710     sal_Int8 nRet = DND_ACTION_NONE;
711 
712    	if( mpTheme && !mpTheme->IsReadOnly() && !mpTheme ->IsImported() )
713 	{
714 		if( !mpTheme->IsDragging() )
715 			nRet = DND_ACTION_COPY;
716 		else
717 			nRet = DND_ACTION_COPY;
718 	}
719 
720 	return nRet;
721 }
722 
723 // ------------------------------------------------------------------------
724 
725 sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
726 {
727     ExecuteDropEvent aEvt( rEvt );
728 
729     aEvt.maPosPixel.Y() += GetTitleHeight();
730 
731     return(	( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, aEvt ) );
732 }
733 
734 // ------------------------------------------------------------------------
735 
736 void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel )
737 {
738     ( (GalleryBrowser2*) GetParent() )->StartDrag( this, &rPosPixel );
739 }
740