LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/gallery2 - galctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 321 0.3 %
Date: 2013-07-09 Functions: 2 48 4.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10