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