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 drawCheckered(OutputDevice& rOut, const Point& rPos, const Size& rSize) 304 { 305 // draw checkered background 306 static const sal_uInt32 nLen(8); 307 static const Color aW(COL_WHITE); 308 static const Color aG(0xef, 0xef, 0xef); 309 310 rOut.DrawCheckered(rPos, rSize, nLen, aW, aG); 311 } 312 313 // ------------------- 314 // - GalleryIconView - 315 // ------------------- 316 DBG_NAME(GalleryIconView) 317 318 GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) : 319 ValueSet( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET ), 320 DropTargetHelper( this ), 321 DragSourceHelper( this ), 322 mpTheme ( pTheme ) 323 { 324 DBG_CTOR(GalleryIconView,NULL); 325 EnableFullItemMode( sal_False ); 326 327 SetHelpId( HID_GALLERY_WINDOW ); 328 InitSettings(); 329 SetExtraSpacing( 2 ); 330 SetItemWidth( S_THUMB + 6 ); 331 SetItemHeight( S_THUMB + 6 ); 332 } 333 334 // ------------------------------------------------------------------------ 335 336 GalleryIconView::~GalleryIconView() 337 { 338 339 DBG_DTOR(GalleryIconView,NULL); 340 } 341 342 // ------------------------------------------------------------------------ 343 344 void GalleryIconView::InitSettings() 345 { 346 SetBackground( Wallpaper( GALLERY_BG_COLOR ) ); 347 SetControlBackground( GALLERY_BG_COLOR ); 348 SetControlForeground( GALLERY_FG_COLOR ); 349 SetColor( GALLERY_BG_COLOR ); 350 } 351 352 // ----------------------------------------------------------------------- 353 354 void GalleryIconView::DataChanged( const DataChangedEvent& rDCEvt ) 355 { 356 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) ) 357 InitSettings(); 358 else 359 ValueSet::DataChanged( rDCEvt ); 360 } 361 362 // ------------------------------------------------------------------------ 363 364 void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt ) 365 { 366 const sal_uInt16 nId = rUDEvt.GetItemId(); 367 368 if( nId && mpTheme ) 369 { 370 SgaObject* pObj = mpTheme->AcquireObject( nId - 1 ); 371 372 if( pObj ) 373 { 374 const Rectangle& rRect = rUDEvt.GetRect(); 375 OutputDevice* pDev = rUDEvt.GetDevice(); 376 Graphic aGraphic; 377 bool bTransparent(false); 378 379 if( pObj->IsThumbBitmap() ) 380 { 381 BitmapEx aBitmapEx; 382 383 if( pObj->GetObjKind() == SGA_OBJ_SOUND ) 384 { 385 Bitmap aTemp = pObj->GetThumbBmp().GetBitmap(); 386 387 aTemp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); 388 aBitmapEx = BitmapEx(aTemp); 389 } 390 else 391 { 392 aBitmapEx = pObj->GetThumbBmp(); 393 bTransparent = aBitmapEx.IsTransparent(); 394 } 395 396 if( ( pDev->GetBitCount() <= 8 ) && ( aBitmapEx.GetBitCount() >= 8 ) ) 397 { 398 aBitmapEx.Dither( BMP_DITHER_FLOYD ); 399 } 400 401 aGraphic = aBitmapEx; 402 } 403 else 404 { 405 aGraphic = pObj->GetThumbMtf(); 406 bTransparent = true; 407 } 408 409 Size aSize( aGraphic.GetSizePixel( pDev ) ); 410 411 if ( aSize.Width() && aSize.Height() ) 412 { 413 if( ( aSize.Width() > rRect.GetWidth() ) || ( aSize.Height() > rRect.GetHeight() ) ) 414 { 415 Point aNewPos; 416 const double fBmpWH = (double) aSize.Width() / aSize.Height(); 417 const double fThmpWH = (double) rRect.GetWidth() / rRect.GetHeight(); 418 419 // Bitmap an Thumbgroesse anpassen 420 if ( fBmpWH < fThmpWH ) 421 { 422 aSize.Width() = (long) ( rRect.GetHeight() * fBmpWH ); 423 aSize.Height()= rRect.GetHeight(); 424 } 425 else 426 { 427 aSize.Width() = rRect.GetWidth(); 428 aSize.Height()= (long) ( rRect.GetWidth() / fBmpWH ); 429 } 430 } 431 432 const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(), 433 ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() ); 434 435 if(bTransparent) 436 { 437 // draw checkered background 438 drawCheckered(*pDev, aPos, aSize); 439 } 440 441 aGraphic.Draw( pDev, aPos, aSize ); 442 } 443 444 SetItemText( nId, GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE) ); 445 mpTheme->ReleaseObject( pObj ); 446 } 447 } 448 } 449 450 // ------------------------------------------------------------------------ 451 452 void GalleryIconView::MouseButtonDown( const MouseEvent& rMEvt ) 453 { 454 ValueSet::MouseButtonDown( rMEvt ); 455 456 if( rMEvt.GetClicks() == 2 ) 457 ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rMEvt.GetPosPixel() ); 458 } 459 460 // ------------------------------------------------------------------------ 461 462 void GalleryIconView::Command( const CommandEvent& rCEvt ) 463 { 464 ValueSet::Command( rCEvt ); 465 466 if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 467 { 468 ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, 469 ( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) ); 470 } 471 } 472 473 // ------------------------------------------------------------------------ 474 475 void GalleryIconView::KeyInput( const KeyEvent& rKEvt ) 476 { 477 if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) ) 478 ValueSet::KeyInput( rKEvt ); 479 } 480 481 // ------------------------------------------------------------------------ 482 483 sal_Int8 GalleryIconView::AcceptDrop( const AcceptDropEvent& rEvt ) 484 { 485 return( static_cast< GalleryBrowser2* >( GetParent() )->AcceptDrop( *this, rEvt ) ); 486 } 487 488 // ------------------------------------------------------------------------ 489 490 sal_Int8 GalleryIconView::ExecuteDrop( const ExecuteDropEvent& rEvt ) 491 { 492 return( static_cast< GalleryBrowser2* >( GetParent() )->ExecuteDrop( *this, rEvt ) ); 493 } 494 495 // ------------------------------------------------------------------------ 496 497 void GalleryIconView::StartDrag( sal_Int8, const Point& ) 498 { 499 const CommandEvent aEvt( GetPointerPosPixel(), COMMAND_STARTDRAG, sal_True ); 500 Region aRegion; 501 502 // call this to initiate dragging for ValueSet 503 ValueSet::StartDrag( aEvt, aRegion ); 504 static_cast< GalleryBrowser2* >( GetParent() )->StartDrag( this ); 505 } 506 507 // ------------------- 508 // - GalleryListView - 509 // ------------------- 510 DBG_NAME(GalleryListView) 511 512 GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) : 513 BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ), 514 mpTheme( pTheme ), 515 mnCurRow( 0 ), 516 mbInit( sal_False ) 517 { 518 DBG_CTOR(GalleryListView,NULL); 519 520 SetHelpId( HID_GALLERY_WINDOW ); 521 522 InitSettings(); 523 524 SetMode( BROWSER_AUTO_VSCROLL | BROWSER_AUTOSIZE_LASTCOL ); 525 SetDataRowHeight( 28 ); 526 InsertDataColumn( GALLERY_BRWBOX_TITLE, String( GAL_RESID( RID_SVXSTR_GALLERY_TITLE ) ), 256 ); 527 InsertDataColumn( GALLERY_BRWBOX_PATH, String( GAL_RESID( RID_SVXSTR_GALLERY_PATH ) ), 256 ); 528 } 529 530 // ------------------------------------------------------------------------ 531 532 GalleryListView::~GalleryListView() 533 { 534 535 DBG_DTOR(GalleryListView,NULL); 536 } 537 538 // ------------------------------------------------------------------------ 539 540 void GalleryListView::InitSettings() 541 { 542 SetBackground( Wallpaper( GALLERY_BG_COLOR ) ); 543 SetControlBackground( GALLERY_BG_COLOR ); 544 SetControlForeground( GALLERY_FG_COLOR ); 545 } 546 547 // ----------------------------------------------------------------------- 548 549 void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt ) 550 { 551 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) ) 552 InitSettings(); 553 else 554 BrowseBox::DataChanged( rDCEvt ); 555 } 556 557 // ------------------------------------------------------------------------ 558 559 sal_Bool GalleryListView::SeekRow( long nRow ) 560 { 561 mnCurRow = nRow; 562 return sal_True; 563 } 564 565 // ----------------------------------------------------------------------------- 566 567 String GalleryListView::GetCellText(long _nRow, sal_uInt16 nColumnId) const 568 { 569 String sRet; 570 if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) ) 571 { 572 SgaObject* pObj = mpTheme->AcquireObject( _nRow ); 573 574 if( pObj ) 575 { 576 sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj, 577 ( GALLERY_BRWBOX_TITLE == nColumnId ) ? GALLERY_ITEM_TITLE : GALLERY_ITEM_PATH ); 578 579 mpTheme->ReleaseObject( pObj ); 580 } 581 } 582 583 return sRet;; 584 } 585 586 // ----------------------------------------------------------------------------- 587 588 Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex) 589 { 590 DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow"); 591 Rectangle aRect; 592 if ( SeekRow(_nRow) ) 593 { 594 SvxFont aFont( GetFont() ); 595 AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) ); 596 597 // get the bounds inside the string 598 aStringWrap.GetCharacterBounds(nIndex, aRect); 599 600 // offset to 601 } 602 return aRect; 603 } 604 605 // ----------------------------------------------------------------------------- 606 607 sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint) 608 { 609 DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow"); 610 sal_Int32 nRet = -1; 611 if ( SeekRow(_nRow) ) 612 { 613 SvxFont aFont( GetFont() ); 614 AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) ); 615 nRet = aStringWrap.GetIndexAtPoint(_rPoint); 616 } 617 return nRet; 618 } 619 620 // ------------------------------------------------------------------------ 621 622 void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const 623 { 624 rDev.Push( PUSH_CLIPREGION ); 625 rDev.IntersectClipRegion( rRect ); 626 627 if( mpTheme && ( mnCurRow < mpTheme->GetObjectCount() ) ) 628 { 629 SgaObject* pObj = mpTheme->AcquireObject( mnCurRow ); 630 631 if( pObj ) 632 { 633 const long nTextPosY = rRect.Top() + ( ( rRect.GetHeight() - rDev.GetTextHeight() ) >> 1 ); 634 635 if( GALLERY_BRWBOX_TITLE == nColumnId ) 636 { 637 Rectangle aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) ); 638 GraphicObject aGrfObj; 639 bool bTransparent(false); 640 641 if( pObj->GetObjKind() == SGA_OBJ_SOUND ) 642 { 643 aGrfObj = Graphic( BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) ) ); 644 } 645 else if( pObj->IsThumbBitmap() ) 646 { 647 const BitmapEx aBitmapEx(pObj->GetThumbBmp()); 648 649 bTransparent = aBitmapEx.IsTransparent(); 650 aGrfObj = Graphic(aBitmapEx); 651 } 652 else 653 { 654 aGrfObj = Graphic( pObj->GetThumbMtf() ); 655 bTransparent = true; 656 } 657 658 Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) ); 659 660 if( aSize.Width() && aSize.Height() ) 661 { 662 if( ( aSize.Width() > aOutputRect.GetWidth() ) || ( aSize.Height() > aOutputRect.GetHeight() ) ) 663 { 664 Point aNewPos; 665 const double fBmpWH = (double) aSize.Width() / aSize.Height(); 666 const double fThmpWH = (double) aOutputRect.GetWidth() / aOutputRect.GetHeight(); 667 668 // Bitmap an Thumbgroesse anpassen 669 if ( fBmpWH < fThmpWH ) 670 { 671 aSize.Width() = (long) ( aOutputRect.GetHeight() * fBmpWH ); 672 aSize.Height()= aOutputRect.GetHeight(); 673 } 674 else 675 { 676 aSize.Width() = aOutputRect.GetWidth(); 677 aSize.Height()= (long) ( aOutputRect.GetWidth() / fBmpWH ); 678 } 679 } 680 681 aSize.Width() = Max( aSize.Width(), 4L ); 682 aSize.Height() = Max( aSize.Height(), 4L ); 683 684 const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(), 685 ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() ); 686 687 if(bTransparent) 688 { 689 // draw checkered background 690 drawCheckered(rDev, aPos, aSize); 691 } 692 693 aGrfObj.Draw( &rDev, aPos, aSize ); 694 } 695 696 rDev.DrawText( Point( aOutputRect.Right() + 6, nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE ) ); 697 } 698 else if( GALLERY_BRWBOX_PATH == nColumnId ) 699 rDev.DrawText( Point( rRect.Left(), nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_PATH ) ); 700 701 mpTheme->ReleaseObject( pObj ); 702 } 703 } 704 705 rDev.Pop(); 706 } 707 708 // ------------------------------------------------------------------------ 709 710 void GalleryListView::Command( const CommandEvent& rCEvt ) 711 { 712 BrowseBox::Command( rCEvt ); 713 714 if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 715 { 716 const Point* pPos = NULL; 717 718 if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) ) 719 pPos = &rCEvt.GetMousePosPixel(); 720 721 ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, pPos ); 722 } 723 } 724 725 // ------------------------------------------------------------------------ 726 727 void GalleryListView::KeyInput( const KeyEvent& rKEvt ) 728 { 729 if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) ) 730 BrowseBox::KeyInput( rKEvt ); 731 } 732 733 // ------------------------------------------------------------------------ 734 735 void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt ) 736 { 737 BrowseBox::DoubleClick( rEvt ); 738 739 if( rEvt.GetRow() != BROWSER_ENDOFSELECTION ) 740 ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rEvt.GetPosPixel() ); 741 } 742 743 // ------------------------------------------------------------------------ 744 745 void GalleryListView::Select() 746 { 747 if( maSelectHdl.IsSet() ) 748 maSelectHdl.Call( this ); 749 } 750 751 // ------------------------------------------------------------------------ 752 753 sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& ) 754 { 755 sal_Int8 nRet = DND_ACTION_NONE; 756 757 if( mpTheme && !mpTheme->IsReadOnly() && !mpTheme ->IsImported() ) 758 { 759 if( !mpTheme->IsDragging() ) 760 nRet = DND_ACTION_COPY; 761 else 762 nRet = DND_ACTION_COPY; 763 } 764 765 return nRet; 766 } 767 768 // ------------------------------------------------------------------------ 769 770 sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) 771 { 772 ExecuteDropEvent aEvt( rEvt ); 773 774 aEvt.maPosPixel.Y() += GetTitleHeight(); 775 776 return( ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, aEvt ) ); 777 } 778 779 // ------------------------------------------------------------------------ 780 781 void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel ) 782 { 783 ( (GalleryBrowser2*) GetParent() )->StartDrag( this, &rPosPixel ); 784 } 785