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.GetPreviewUsesCheckeredBackground()) 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 const Rectangle& rRect = rUDEvt.GetRect(); 382 const Size aSize(rRect.GetWidth(), rRect.GetHeight()); 383 BitmapEx aBitmapEx; 384 Size aPreparedSize; 385 String aItemTextTitle; 386 String aItemTextPath; 387 388 mpTheme->GetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath); 389 390 bool bNeedToCreate(aBitmapEx.IsEmpty()); 391 392 if(!bNeedToCreate && !aItemTextTitle.Len()) 393 { 394 bNeedToCreate = true; 395 } 396 397 if(!bNeedToCreate && aPreparedSize != aSize) 398 { 399 bNeedToCreate = true; 400 } 401 402 if(bNeedToCreate) 403 { 404 SgaObject* pObj = mpTheme->AcquireObject(nId - 1); 405 406 if(pObj) 407 { 408 aBitmapEx = pObj->createPreviewBitmapEx(aSize); 409 aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GALLERY_ITEM_TITLE); 410 411 mpTheme->SetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aSize, aItemTextTitle, aItemTextPath); 412 mpTheme->ReleaseObject(pObj); 413 } 414 } 415 416 if(!aBitmapEx.IsEmpty()) 417 { 418 const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel()); 419 const Point aPos( 420 ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(), 421 ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top()); 422 OutputDevice* pDev = rUDEvt.GetDevice(); 423 424 if(aBitmapEx.IsTransparent()) 425 { 426 // draw checkered background 427 drawTransparenceBackground(*pDev, aPos, aBitmapExSizePixel); 428 } 429 430 pDev->DrawBitmapEx(aPos, aBitmapEx); 431 } 432 433 SetItemText(nId, aItemTextTitle); 434 435 //SgaObject* pObj = mpTheme->AcquireObject( nId - 1 ); 436 // 437 //if( pObj ) 438 //{ 439 // const Rectangle& rRect = rUDEvt.GetRect(); 440 // const Size aSize(rRect.GetWidth(), rRect.GetHeight()); 441 // const BitmapEx aBitmapEx(pObj->createPreviewBitmapEx(aSize)); 442 // const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel()); 443 // 444 // if(!aBitmapEx.IsEmpty()) 445 // { 446 // const Point aPos( 447 // ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(), 448 // ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top()); 449 // OutputDevice* pDev = rUDEvt.GetDevice(); 450 // 451 // if(aBitmapEx.IsTransparent()) 452 // { 453 // // draw checkered background 454 // drawTransparenceBackground(*pDev, aPos, aBitmapExSizePixel); 455 // } 456 // 457 // pDev->DrawBitmapEx(aPos, aBitmapEx); 458 // } 459 // 460 // //const Rectangle& rRect = rUDEvt.GetRect(); 461 // //OutputDevice* pDev = rUDEvt.GetDevice(); 462 // //Graphic aGraphic; 463 // //bool bTransparent(false); 464 // // 465 // //if( pObj->IsThumbBitmap() ) 466 // //{ 467 // // BitmapEx aBitmapEx; 468 // // 469 // // if( pObj->GetObjKind() == SGA_OBJ_SOUND ) 470 // // { 471 // // Bitmap aTemp = pObj->GetThumbBmp().GetBitmap(); 472 // // 473 // // aTemp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); 474 // // aBitmapEx = BitmapEx(aTemp); 475 // // } 476 // // else 477 // // { 478 // // aBitmapEx = pObj->GetThumbBmp(); 479 // // bTransparent = aBitmapEx.IsTransparent(); 480 // // } 481 // // 482 // // if( ( pDev->GetBitCount() <= 8 ) && ( aBitmapEx.GetBitCount() >= 8 ) ) 483 // // { 484 // // aBitmapEx.Dither( BMP_DITHER_FLOYD ); 485 // // } 486 // // 487 // // aGraphic = aBitmapEx; 488 // //} 489 // //else 490 // //{ 491 // // aGraphic = pObj->GetThumbMtf(); 492 // // bTransparent = true; 493 // //} 494 // // 495 // //Size aSize( aGraphic.GetSizePixel( pDev ) ); 496 // // 497 // //if ( aSize.Width() && aSize.Height() ) 498 // //{ 499 // // if( ( aSize.Width() > rRect.GetWidth() ) || ( aSize.Height() > rRect.GetHeight() ) ) 500 // // { 501 // // Point aNewPos; 502 // // const double fBmpWH = (double) aSize.Width() / aSize.Height(); 503 // // const double fThmpWH = (double) rRect.GetWidth() / rRect.GetHeight(); 504 // // 505 // // // Bitmap an Thumbgroesse anpassen 506 // // if ( fBmpWH < fThmpWH ) 507 // // { 508 // // aSize.Width() = (long) ( rRect.GetHeight() * fBmpWH ); 509 // // aSize.Height()= rRect.GetHeight(); 510 // // } 511 // // else 512 // // { 513 // // aSize.Width() = rRect.GetWidth(); 514 // // aSize.Height()= (long) ( rRect.GetWidth() / fBmpWH ); 515 // // } 516 // // } 517 // // 518 // // const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(), 519 // // ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() ); 520 // // 521 // // if(bTransparent) 522 // // { 523 // // // draw checkered background 524 // // drawTransparenceBackground(*pDev, aPos, aSize); 525 // // } 526 // // 527 // // aGraphic.Draw( pDev, aPos, aSize ); 528 // //} 529 // 530 // SetItemText( nId, GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE) ); 531 // mpTheme->ReleaseObject( pObj ); 532 //} 533 } 534 } 535 536 // ------------------------------------------------------------------------ 537 538 void GalleryIconView::MouseButtonDown( const MouseEvent& rMEvt ) 539 { 540 ValueSet::MouseButtonDown( rMEvt ); 541 542 if( rMEvt.GetClicks() == 2 ) 543 ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rMEvt.GetPosPixel() ); 544 } 545 546 // ------------------------------------------------------------------------ 547 548 void GalleryIconView::Command( const CommandEvent& rCEvt ) 549 { 550 ValueSet::Command( rCEvt ); 551 552 if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 553 { 554 ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, 555 ( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) ); 556 } 557 } 558 559 // ------------------------------------------------------------------------ 560 561 void GalleryIconView::KeyInput( const KeyEvent& rKEvt ) 562 { 563 if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) ) 564 ValueSet::KeyInput( rKEvt ); 565 } 566 567 // ------------------------------------------------------------------------ 568 569 sal_Int8 GalleryIconView::AcceptDrop( const AcceptDropEvent& rEvt ) 570 { 571 return( static_cast< GalleryBrowser2* >( GetParent() )->AcceptDrop( *this, rEvt ) ); 572 } 573 574 // ------------------------------------------------------------------------ 575 576 sal_Int8 GalleryIconView::ExecuteDrop( const ExecuteDropEvent& rEvt ) 577 { 578 return( static_cast< GalleryBrowser2* >( GetParent() )->ExecuteDrop( *this, rEvt ) ); 579 } 580 581 // ------------------------------------------------------------------------ 582 583 void GalleryIconView::StartDrag( sal_Int8, const Point& ) 584 { 585 const CommandEvent aEvt( GetPointerPosPixel(), COMMAND_STARTDRAG, sal_True ); 586 Region aRegion; 587 588 // call this to initiate dragging for ValueSet 589 ValueSet::StartDrag( aEvt, aRegion ); 590 static_cast< GalleryBrowser2* >( GetParent() )->StartDrag( this ); 591 } 592 593 // ------------------- 594 // - GalleryListView - 595 // ------------------- 596 DBG_NAME(GalleryListView) 597 598 GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) : 599 BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ), 600 mpTheme( pTheme ), 601 mnCurRow( 0 ), 602 mbInit( sal_False ) 603 { 604 DBG_CTOR(GalleryListView,NULL); 605 606 SetHelpId( HID_GALLERY_WINDOW ); 607 608 InitSettings(); 609 610 SetMode( BROWSER_AUTO_VSCROLL | BROWSER_AUTOSIZE_LASTCOL ); 611 SetDataRowHeight( 28 ); 612 InsertDataColumn( GALLERY_BRWBOX_TITLE, String( GAL_RESID( RID_SVXSTR_GALLERY_TITLE ) ), 256 ); 613 InsertDataColumn( GALLERY_BRWBOX_PATH, String( GAL_RESID( RID_SVXSTR_GALLERY_PATH ) ), 256 ); 614 } 615 616 // ------------------------------------------------------------------------ 617 618 GalleryListView::~GalleryListView() 619 { 620 621 DBG_DTOR(GalleryListView,NULL); 622 } 623 624 // ------------------------------------------------------------------------ 625 626 void GalleryListView::InitSettings() 627 { 628 SetBackground( Wallpaper( GALLERY_BG_COLOR ) ); 629 SetControlBackground( GALLERY_BG_COLOR ); 630 SetControlForeground( GALLERY_FG_COLOR ); 631 } 632 633 // ----------------------------------------------------------------------- 634 635 void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt ) 636 { 637 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) ) 638 InitSettings(); 639 else 640 BrowseBox::DataChanged( rDCEvt ); 641 } 642 643 // ------------------------------------------------------------------------ 644 645 sal_Bool GalleryListView::SeekRow( long nRow ) 646 { 647 mnCurRow = nRow; 648 return sal_True; 649 } 650 651 // ----------------------------------------------------------------------------- 652 653 String GalleryListView::GetCellText(long _nRow, sal_uInt16 nColumnId) const 654 { 655 String sRet; 656 if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) ) 657 { 658 SgaObject* pObj = mpTheme->AcquireObject( _nRow ); 659 660 if( pObj ) 661 { 662 sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj, 663 ( GALLERY_BRWBOX_TITLE == nColumnId ) ? GALLERY_ITEM_TITLE : GALLERY_ITEM_PATH ); 664 665 mpTheme->ReleaseObject( pObj ); 666 } 667 } 668 669 return sRet;; 670 } 671 672 // ----------------------------------------------------------------------------- 673 674 Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex) 675 { 676 DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow"); 677 Rectangle aRect; 678 if ( SeekRow(_nRow) ) 679 { 680 SvxFont aFont( GetFont() ); 681 AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) ); 682 683 // get the bounds inside the string 684 aStringWrap.GetCharacterBounds(nIndex, aRect); 685 686 // offset to 687 } 688 return aRect; 689 } 690 691 // ----------------------------------------------------------------------------- 692 693 sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint) 694 { 695 DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow"); 696 sal_Int32 nRet = -1; 697 if ( SeekRow(_nRow) ) 698 { 699 SvxFont aFont( GetFont() ); 700 AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) ); 701 nRet = aStringWrap.GetIndexAtPoint(_rPoint); 702 } 703 return nRet; 704 } 705 706 // ------------------------------------------------------------------------ 707 708 void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const 709 { 710 rDev.Push( PUSH_CLIPREGION ); 711 rDev.IntersectClipRegion( rRect ); 712 713 if( mpTheme && ( mnCurRow < mpTheme->GetObjectCount() ) ) 714 { 715 const Size aSize(rRect.GetHeight(), rRect.GetHeight()); 716 BitmapEx aBitmapEx; 717 Size aPreparedSize; 718 String aItemTextTitle; 719 String aItemTextPath; 720 721 mpTheme->GetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath); 722 723 bool bNeedToCreate(aBitmapEx.IsEmpty()); 724 725 if(!bNeedToCreate && GALLERY_BRWBOX_TITLE == nColumnId && !aItemTextTitle.Len()) 726 { 727 bNeedToCreate = true; 728 } 729 730 if(!bNeedToCreate && GALLERY_BRWBOX_PATH == nColumnId && !aItemTextPath.Len()) 731 { 732 bNeedToCreate = true; 733 } 734 735 if(!bNeedToCreate && aPreparedSize != aSize) 736 { 737 bNeedToCreate = true; 738 } 739 740 if(bNeedToCreate) 741 { 742 SgaObject* pObj = mpTheme->AcquireObject(mnCurRow); 743 744 if(pObj) 745 { 746 aBitmapEx = pObj->createPreviewBitmapEx(aSize); 747 aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GALLERY_ITEM_TITLE); 748 aItemTextPath = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GALLERY_ITEM_PATH); 749 750 mpTheme->SetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aSize, aItemTextTitle, aItemTextPath); 751 mpTheme->ReleaseObject(pObj); 752 } 753 } 754 755 const long nTextPosY(rRect.Top() + ((rRect.GetHeight() - rDev.GetTextHeight()) >> 1)); 756 757 if(GALLERY_BRWBOX_TITLE == nColumnId) 758 { 759 if(!aBitmapEx.IsEmpty()) 760 { 761 const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel()); 762 const Point aPos( 763 ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(), 764 ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top()); 765 766 if(aBitmapEx.IsTransparent()) 767 { 768 // draw checkered background 769 drawTransparenceBackground(rDev, aPos, aBitmapExSizePixel); 770 } 771 772 rDev.DrawBitmapEx(aPos, aBitmapEx); 773 } 774 775 rDev.DrawText(Point(rRect.Left() + rRect.GetHeight() + 6, nTextPosY), aItemTextTitle); 776 } 777 else if(GALLERY_BRWBOX_PATH == nColumnId) 778 { 779 rDev.DrawText(Point(rRect.Left(), nTextPosY), aItemTextPath); 780 } 781 782 783 //SgaObject* pObj = mpTheme->AcquireObject( mnCurRow ); 784 // 785 //if( pObj ) 786 //{ 787 // const long nTextPosY = rRect.Top() + ( ( rRect.GetHeight() - rDev.GetTextHeight() ) >> 1 ); 788 // 789 // if( GALLERY_BRWBOX_TITLE == nColumnId ) 790 // { 791 // const Size aSize(rRect.GetHeight(), rRect.GetHeight()); 792 // const BitmapEx aBitmapEx(pObj->createPreviewBitmapEx(aSize)); 793 // const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel()); 794 // 795 // if(!aBitmapEx.IsEmpty()) 796 // { 797 // const Point aPos( 798 // ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(), 799 // ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top()); 800 // 801 // if(aBitmapEx.IsTransparent()) 802 // { 803 // // draw checkered background 804 // drawTransparenceBackground(rDev, aPos, aBitmapExSizePixel); 805 // } 806 // 807 // rDev.DrawBitmapEx(aPos, aBitmapEx); 808 // } 809 // 810 // 811 // //Rectangle aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) ); 812 // //GraphicObject aGrfObj; 813 // //bool bTransparent(false); 814 // // 815 // //if( pObj->GetObjKind() == SGA_OBJ_SOUND ) 816 // //{ 817 // // aGrfObj = Graphic( BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) ) ); 818 // //} 819 // //else if( pObj->IsThumbBitmap() ) 820 // //{ 821 // // const BitmapEx aBitmapEx(pObj->GetThumbBmp()); 822 // // 823 // // bTransparent = aBitmapEx.IsTransparent(); 824 // // aGrfObj = Graphic(aBitmapEx); 825 // //} 826 // //else 827 // //{ 828 // // aGrfObj = Graphic( pObj->GetThumbMtf() ); 829 // // bTransparent = true; 830 // //} 831 // // 832 // //Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) ); 833 // // 834 // //if( aSize.Width() && aSize.Height() ) 835 // //{ 836 // // if( ( aSize.Width() > aOutputRect.GetWidth() ) || ( aSize.Height() > aOutputRect.GetHeight() ) ) 837 // // { 838 // // Point aNewPos; 839 // // const double fBmpWH = (double) aSize.Width() / aSize.Height(); 840 // // const double fThmpWH = (double) aOutputRect.GetWidth() / aOutputRect.GetHeight(); 841 // // 842 // // // Bitmap an Thumbgroesse anpassen 843 // // if ( fBmpWH < fThmpWH ) 844 // // { 845 // // aSize.Width() = (long) ( aOutputRect.GetHeight() * fBmpWH ); 846 // // aSize.Height()= aOutputRect.GetHeight(); 847 // // } 848 // // else 849 // // { 850 // // aSize.Width() = aOutputRect.GetWidth(); 851 // // aSize.Height()= (long) ( aOutputRect.GetWidth() / fBmpWH ); 852 // // } 853 // // } 854 // // 855 // // aSize.Width() = Max( aSize.Width(), 4L ); 856 // // aSize.Height() = Max( aSize.Height(), 4L ); 857 // // 858 // // const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(), 859 // // ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() ); 860 // // 861 // // if(bTransparent) 862 // // { 863 // // // draw checkered background 864 // // drawTransparenceBackground(rDev, aPos, aSize); 865 // // } 866 // // 867 // // aGrfObj.Draw( &rDev, aPos, aSize ); 868 // //} 869 // 870 // // aOutputRect.Right() is here rRect.Left() + rRect.GetHeight() 871 // rDev.DrawText( Point( rRect.Left() + rRect.GetHeight() + 6, nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE ) ); 872 // } 873 // else if( GALLERY_BRWBOX_PATH == nColumnId ) 874 // { 875 // rDev.DrawText( Point( rRect.Left(), nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_PATH ) ); 876 // } 877 // 878 // mpTheme->ReleaseObject( pObj ); 879 //} 880 } 881 882 rDev.Pop(); 883 } 884 885 // ------------------------------------------------------------------------ 886 887 void GalleryListView::Command( const CommandEvent& rCEvt ) 888 { 889 BrowseBox::Command( rCEvt ); 890 891 if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 892 { 893 const Point* pPos = NULL; 894 895 if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) ) 896 pPos = &rCEvt.GetMousePosPixel(); 897 898 ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, pPos ); 899 } 900 } 901 902 // ------------------------------------------------------------------------ 903 904 void GalleryListView::KeyInput( const KeyEvent& rKEvt ) 905 { 906 if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) ) 907 BrowseBox::KeyInput( rKEvt ); 908 } 909 910 // ------------------------------------------------------------------------ 911 912 void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt ) 913 { 914 BrowseBox::DoubleClick( rEvt ); 915 916 if( rEvt.GetRow() != BROWSER_ENDOFSELECTION ) 917 ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rEvt.GetPosPixel() ); 918 } 919 920 // ------------------------------------------------------------------------ 921 922 void GalleryListView::Select() 923 { 924 if( maSelectHdl.IsSet() ) 925 maSelectHdl.Call( this ); 926 } 927 928 // ------------------------------------------------------------------------ 929 930 sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& ) 931 { 932 sal_Int8 nRet = DND_ACTION_NONE; 933 934 if( mpTheme && !mpTheme->IsReadOnly() && !mpTheme ->IsImported() ) 935 { 936 if( !mpTheme->IsDragging() ) 937 nRet = DND_ACTION_COPY; 938 else 939 nRet = DND_ACTION_COPY; 940 } 941 942 return nRet; 943 } 944 945 // ------------------------------------------------------------------------ 946 947 sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) 948 { 949 ExecuteDropEvent aEvt( rEvt ); 950 951 aEvt.maPosPixel.Y() += GetTitleHeight(); 952 953 return( ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, aEvt ) ); 954 } 955 956 // ------------------------------------------------------------------------ 957 958 void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel ) 959 { 960 ( (GalleryBrowser2*) GetParent() )->StartDrag( this, &rPosPixel ); 961 } 962