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

Generated by: LCOV version 1.10