LCOV - code coverage report
Current view: top level - sfx2/source/dialog - infobar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 26 190 13.7 %
Date: 2014-04-11 Functions: 11 26 42.3 %
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             : 
      10             : #include <basegfx/polygon/b2dpolygon.hxx>
      11             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      12             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      13             : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      14             : #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
      15             : #include <sfx2/bindings.hxx>
      16             : #include <sfx2/dispatch.hxx>
      17             : #include <sfx2/infobar.hxx>
      18             : #include <sfx2/objsh.hxx>
      19             : #include <sfx2/sfx.hrc>
      20             : #include <sfx2/viewsh.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <vcl/settings.hxx>
      23             : 
      24             : using namespace std;
      25             : 
      26             : namespace
      27             : {
      28             :     class SfxCloseButton : public PushButton
      29             :     {
      30             :         public:
      31           0 :             SfxCloseButton( Window* pParent ) : PushButton( pParent, 0 )
      32             :             {
      33           0 :             }
      34             : 
      35           0 :             virtual ~SfxCloseButton( ) { }
      36             : 
      37             :             virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
      38             :     };
      39             : 
      40           0 :     void SfxCloseButton::Paint( const Rectangle& )
      41             :     {
      42           0 :         const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
      43             :         drawinglayer::processor2d::BaseProcessor2D * pProcessor =
      44             :             drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
      45           0 :                         *this, aNewViewInfos );
      46             : 
      47           0 :         const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
      48             : 
      49           0 :         drawinglayer::primitive2d::Primitive2DSequence aSeq( 2 );
      50             : 
      51           0 :         basegfx::BColor aLightColor( 1.0, 1.0, 191.0 / 255.0 );
      52           0 :         basegfx::BColor aDarkColor( 217.0 / 255.0, 217.0 / 255.0, 78.0 / 255.0 );
      53             : 
      54           0 :         const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
      55           0 :         if ( rSettings.GetHighContrastMode() )
      56             :         {
      57           0 :             aLightColor = rSettings.GetLightColor( ).getBColor( );
      58           0 :             aDarkColor = rSettings.GetDialogTextColor( ).getBColor( );
      59             : 
      60             :         }
      61             : 
      62             :         // Light background
      63           0 :         basegfx::B2DPolygon aPolygon;
      64           0 :         aPolygon.append( basegfx::B2DPoint( aRect.Left( ), aRect.Top( ) ) );
      65           0 :         aPolygon.append( basegfx::B2DPoint( aRect.Right( ), aRect.Top( ) ) );
      66           0 :         aPolygon.append( basegfx::B2DPoint( aRect.Right( ), aRect.Bottom( ) ) );
      67           0 :         aPolygon.append( basegfx::B2DPoint( aRect.Left( ), aRect.Bottom( ) ) );
      68           0 :         aPolygon.setClosed( true );
      69             :         drawinglayer::primitive2d::PolyPolygonColorPrimitive2D* pBack =
      70             :             new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
      71           0 :                     basegfx::B2DPolyPolygon( aPolygon ), aLightColor );
      72           0 :         aSeq[0] = pBack;
      73             : 
      74           0 :         drawinglayer::attribute::LineAttribute aLineAttribute( aDarkColor, 2.0 );
      75             : 
      76             :         // Cross
      77           0 :         basegfx::B2DPolyPolygon aCross;
      78           0 :         basegfx::B2DPolygon aLine1;
      79           0 :         aLine1.append( basegfx::B2DPoint( aRect.Left(), aRect.Top( ) ) );
      80           0 :         aLine1.append( basegfx::B2DPoint( aRect.Right(), aRect.Bottom( ) ) );
      81           0 :         aCross.append( aLine1 );
      82           0 :         basegfx::B2DPolygon aLine2;
      83           0 :         aLine2.append( basegfx::B2DPoint( aRect.Right(), aRect.Top( ) ) );
      84           0 :         aLine2.append( basegfx::B2DPoint( aRect.Left(), aRect.Bottom( ) ) );
      85           0 :         aCross.append( aLine2 );
      86             : 
      87             :         drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D * pCross =
      88             :                 new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D (
      89           0 :                     aCross, aLineAttribute, drawinglayer::attribute::StrokeAttribute( ) );
      90             : 
      91           0 :         aSeq[1] = pCross;
      92             : 
      93           0 :         pProcessor->process( aSeq );
      94           0 :         delete pProcessor;
      95           0 :     }
      96             : }
      97             : 
      98           0 : SfxInfoBarWindow::SfxInfoBarWindow( Window* pParent, const OUString& sId,
      99             :        const OUString& sMessage, vector< PushButton* > aButtons ) :
     100             :     Window( pParent, 0 ),
     101             :     m_sId( sId ),
     102             :     m_pMessage( NULL ),
     103             :     m_pCloseBtn( NULL ),
     104           0 :     m_aActionBtns( aButtons )
     105             : {
     106           0 :     long nWidth = pParent->GetSizePixel().getWidth();
     107           0 :     SetPosSizePixel( Point( 0, 0 ), Size( nWidth, 40 ) );
     108           0 :     m_pMessage = new FixedText( this, 0 );
     109           0 :     m_pMessage->SetText( sMessage );
     110           0 :     m_pMessage->SetBackground( Wallpaper( Color(  255, 255, 191 ) ) );
     111           0 :     m_pMessage->Show( );
     112             : 
     113           0 :     m_pCloseBtn = new SfxCloseButton( this );
     114           0 :     m_pCloseBtn->SetPosSizePixel( Point( nWidth - 25, 15 ), Size( 10, 10 ) );
     115           0 :     m_pCloseBtn->SetClickHdl( LINK( this, SfxInfoBarWindow, CloseHandler ) );
     116           0 :     m_pCloseBtn->Show( );
     117             : 
     118             :     // Reparent the buttons and place them on the right of the bar
     119           0 :     long nX = m_pCloseBtn->GetPosPixel( ).getX( ) - 15;
     120           0 :     long nBtnGap = 5;
     121           0 :     for ( vector< PushButton* >::iterator it = m_aActionBtns.begin( );
     122           0 :             it != m_aActionBtns.end( ); ++it )
     123             :     {
     124           0 :         PushButton* pBtn = *it;
     125           0 :         pBtn->SetParent( this );
     126           0 :         long nBtnWidth = pBtn->GetSizePixel( ).getWidth();
     127           0 :         nX -= nBtnWidth;
     128           0 :         pBtn->SetPosSizePixel( Point( nX, 5 ), Size( nBtnWidth, 30 ) );
     129           0 :         nX -= nBtnGap;
     130           0 :         pBtn->Show( );
     131             :     }
     132             : 
     133           0 :     m_pMessage->SetPosSizePixel( Point( 10, 10 ), Size( nX - 20, 20 ) );
     134           0 : }
     135             : 
     136           0 : SfxInfoBarWindow::~SfxInfoBarWindow( )
     137             : {
     138           0 :     delete m_pMessage;
     139           0 :     delete m_pCloseBtn;
     140             : 
     141           0 :     for ( vector< PushButton* >::iterator it = m_aActionBtns.begin( );
     142           0 :             it != m_aActionBtns.end( ); ++it )
     143             :     {
     144           0 :         delete *it;
     145             :     }
     146           0 :     m_aActionBtns.clear( );
     147           0 : }
     148             : 
     149           0 : void SfxInfoBarWindow::Paint( const Rectangle& rPaintRect )
     150             : {
     151           0 :     const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
     152             :     drawinglayer::processor2d::BaseProcessor2D * pProcessor =
     153             :         drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
     154           0 :                     *this, aNewViewInfos );
     155             : 
     156           0 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
     157             : 
     158           0 :     drawinglayer::primitive2d::Primitive2DSequence aSeq( 2 );
     159             : 
     160           0 :     basegfx::BColor aLightColor( 1.0, 1.0, 191.0 / 255.0 );
     161           0 :     basegfx::BColor aDarkColor( 217.0 / 255.0, 217.0 / 255.0, 78.0 / 255.0 );
     162             : 
     163           0 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     164           0 :     if ( rSettings.GetHighContrastMode() )
     165             :     {
     166           0 :         aLightColor = rSettings.GetLightColor( ).getBColor( );
     167           0 :         aDarkColor = rSettings.GetDialogTextColor( ).getBColor( );
     168             :     }
     169             : 
     170             :     // Update the label background color
     171           0 :     m_pMessage->SetBackground( Wallpaper( Color( aLightColor ) ) );
     172             : 
     173             :     // Light background
     174           0 :     basegfx::B2DPolygon aPolygon;
     175           0 :     aPolygon.append( basegfx::B2DPoint( aRect.Left( ), aRect.Top( ) ) );
     176           0 :     aPolygon.append( basegfx::B2DPoint( aRect.Right( ), aRect.Top( ) ) );
     177           0 :     aPolygon.append( basegfx::B2DPoint( aRect.Right( ), aRect.Bottom( ) ) );
     178           0 :     aPolygon.append( basegfx::B2DPoint( aRect.Left( ), aRect.Bottom( ) ) );
     179           0 :     aPolygon.setClosed( true );
     180             :     drawinglayer::primitive2d::PolyPolygonColorPrimitive2D* pBack =
     181             :         new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
     182           0 :                 basegfx::B2DPolyPolygon( aPolygon ), aLightColor );
     183           0 :     aSeq[0] = pBack;
     184             : 
     185           0 :     drawinglayer::attribute::LineAttribute aLineAttribute( aDarkColor, 1.0 );
     186             : 
     187             :     // Bottom dark line
     188           0 :     basegfx::B2DPolygon aPolygonBottom;
     189           0 :     aPolygonBottom.append( basegfx::B2DPoint( aRect.Left(), aRect.Bottom( ) ) );
     190           0 :     aPolygonBottom.append( basegfx::B2DPoint( aRect.Right(), aRect.Bottom( ) ) );
     191             : 
     192             :     drawinglayer::primitive2d::PolygonStrokePrimitive2D * pLineBottom =
     193             :             new drawinglayer::primitive2d::PolygonStrokePrimitive2D (
     194           0 :                 aPolygonBottom, aLineAttribute );
     195             : 
     196           0 :     aSeq[1] = pLineBottom;
     197             : 
     198           0 :     pProcessor->process( aSeq );
     199           0 :     delete pProcessor;
     200             : 
     201           0 :     Window::Paint( rPaintRect );
     202           0 : }
     203             : 
     204           0 : void SfxInfoBarWindow::Resize( )
     205             : {
     206           0 :     long nWidth = GetSizePixel().getWidth();
     207           0 :     m_pCloseBtn->SetPosSizePixel( Point( nWidth - 25, 15 ), Size( 10, 10 ) );
     208             : 
     209             :     // Reparent the buttons and place them on the right of the bar
     210           0 :     long nX = m_pCloseBtn->GetPosPixel( ).getX( ) - 15;
     211           0 :     long nBtnGap = 5;
     212           0 :     for ( vector< PushButton* >::iterator it = m_aActionBtns.begin( );
     213           0 :             it != m_aActionBtns.end( ); ++it )
     214             :     {
     215           0 :         PushButton* pBtn = *it;
     216           0 :         long nBtnWidth = pBtn->GetSizePixel( ).getWidth();
     217           0 :         nX -= nBtnWidth;
     218           0 :         pBtn->SetPosSizePixel( Point( nX, 5 ), Size( nBtnWidth, 30 ) );
     219           0 :         nX -= nBtnGap;
     220             :     }
     221             : 
     222           0 :     m_pMessage->SetPosSizePixel( Point( 10, 10 ), Size( nX - 20, 20 ) );
     223           0 : }
     224             : 
     225           0 : IMPL_LINK_NOARG( SfxInfoBarWindow, CloseHandler )
     226             : {
     227           0 :     ((SfxInfoBarContainerWindow*)GetParent())->removeInfoBar( this );
     228           0 :     return 0;
     229             : }
     230             : 
     231        1953 : SfxInfoBarContainerWindow::SfxInfoBarContainerWindow( SfxInfoBarContainerChild* pChildWin ) :
     232             :     Window( pChildWin->GetParent( ), 0 ),
     233             :     m_pChildWin( pChildWin ),
     234        1953 :     m_pInfoBars( )
     235             : {
     236        1953 : }
     237             : 
     238        5847 : SfxInfoBarContainerWindow::~SfxInfoBarContainerWindow( )
     239             : {
     240        5847 :     for ( vector< SfxInfoBarWindow* >::iterator it = m_pInfoBars.begin( );
     241        3898 :             it != m_pInfoBars.end( ); ++it )
     242             :     {
     243           0 :         delete *it;
     244             :     }
     245        1949 :     m_pInfoBars.clear( );
     246        3898 : }
     247             : 
     248           0 : void SfxInfoBarContainerWindow::appendInfoBar( const OUString& sId, const OUString& sMessage, vector< PushButton* > aButtons )
     249             : {
     250           0 :     Size aSize = GetSizePixel( );
     251             : 
     252           0 :     SfxInfoBarWindow* pInfoBar = new SfxInfoBarWindow( this, sId, sMessage, aButtons );
     253           0 :     pInfoBar->SetPosPixel( Point( 0, aSize.getHeight( ) ) );
     254           0 :     pInfoBar->Show( );
     255           0 :     m_pInfoBars.push_back( pInfoBar );
     256             : 
     257           0 :     long nHeight = pInfoBar->GetSizePixel( ).getHeight( );
     258           0 :     aSize.setHeight( aSize.getHeight() + nHeight );
     259           0 :     SetSizePixel( aSize );
     260           0 : }
     261             : 
     262           0 : SfxInfoBarWindow* SfxInfoBarContainerWindow::getInfoBar( const OUString& sId )
     263             : {
     264           0 :     SfxInfoBarWindow* pRet = NULL;
     265           0 :     for ( vector< SfxInfoBarWindow* >::iterator it = m_pInfoBars.begin( );
     266           0 :             it != m_pInfoBars.end( ) && pRet == NULL; ++it )
     267             :     {
     268           0 :         SfxInfoBarWindow* pBar = *it;
     269           0 :         if ( pBar->getId( ) == sId )
     270           0 :             pRet = pBar;
     271             :     }
     272           0 :     return pRet;
     273             : }
     274             : 
     275           0 : void SfxInfoBarContainerWindow::removeInfoBar( SfxInfoBarWindow* pInfoBar )
     276             : {
     277           0 :     for ( vector< SfxInfoBarWindow* >::iterator it = m_pInfoBars.begin( );
     278           0 :             it != m_pInfoBars.end( ); ++it )
     279             :     {
     280           0 :         if ( pInfoBar == *it )
     281             :         {
     282           0 :             m_pInfoBars.erase( it );
     283           0 :             break;
     284             :         }
     285             :     }
     286           0 :     delete pInfoBar;
     287             : 
     288           0 :     long nY = 0;
     289           0 :     for ( vector< SfxInfoBarWindow* >::iterator it = m_pInfoBars.begin( ); it != m_pInfoBars.end( ); ++it )
     290             :     {
     291           0 :         SfxInfoBarWindow* pBar = *it;
     292           0 :         pBar->SetPosPixel( Point( 0, nY ) );
     293           0 :         nY += pBar->GetSizePixel( ).getHeight( );
     294             :     }
     295             : 
     296           0 :     Size aSize = GetSizePixel( );
     297           0 :     aSize.setHeight( nY );
     298           0 :     SetSizePixel( aSize );
     299             : 
     300           0 :     m_pChildWin->Update( );
     301           0 : }
     302             : 
     303        2656 : void SfxInfoBarContainerWindow::Resize( )
     304             : {
     305             :     // Only need to change the width of the infobars
     306        2656 :     long nWidth = GetSizePixel( ).getWidth( );
     307        7968 :     for ( vector< SfxInfoBarWindow * >::iterator it = m_pInfoBars.begin( );
     308        5312 :             it != m_pInfoBars.end( ); ++it )
     309             :     {
     310           0 :         SfxInfoBarWindow* pInfoBar = *it;
     311           0 :         Size aSize = pInfoBar->GetSizePixel( );
     312           0 :         aSize.setWidth( nWidth );
     313           0 :         pInfoBar->SetSizePixel( aSize );
     314           0 :         pInfoBar->Resize( );
     315             :     }
     316        2656 : }
     317             : 
     318        2236 : SFX_IMPL_POS_CHILDWINDOW_WITHID( SfxInfoBarContainerChild, SID_INFOBARCONTAINER, SFX_OBJECTBAR_OBJECT );
     319             : 
     320        1953 : SfxInfoBarContainerChild::SfxInfoBarContainerChild( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* ) :
     321             :     SfxChildWindow( _pParent, nId ),
     322        1953 :     m_pBindings( pBindings )
     323             : {
     324        1953 :     pWindow = new SfxInfoBarContainerWindow( this );
     325        1953 :     pWindow->SetPosSizePixel( Point( 0, 0 ), Size( _pParent->GetSizePixel( ).getWidth(), 0 ) );
     326        1953 :     pWindow->Show( );
     327             : 
     328        1953 :     eChildAlignment = SFX_ALIGN_LOWESTTOP;
     329        1953 : }
     330             : 
     331        3898 : SfxInfoBarContainerChild::~SfxInfoBarContainerChild( )
     332             : {
     333        3898 : }
     334             : 
     335        1961 : SfxChildWinInfo SfxInfoBarContainerChild::GetInfo( ) const
     336             : {
     337        1961 :     SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
     338        1961 :     return aInfo;
     339             : }
     340             : 
     341           0 : void SfxInfoBarContainerChild::Update( )
     342             : {
     343             :     // Refresh the frame to take the infobars container height change into account
     344           0 :     const sal_uInt16 nId = GetChildWindowId();
     345           0 :     SfxViewFrame* pVFrame = m_pBindings->GetDispatcher( )->GetFrame( );
     346           0 :     pVFrame->ShowChildWindow( nId );
     347             : 
     348             :     // Give the focus to the document view
     349           0 :     pVFrame->GetWindow().GrabFocusToDocument();
     350           0 : }
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10