LCOV - code coverage report
Current view: top level - sw/source/uibase/utlui - viewlayoutctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 47 92 51.1 %
Date: 2014-11-03 Functions: 11 12 91.7 %
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             : #include <viewlayoutctrl.hxx>
      21             : 
      22             : #include <vcl/status.hxx>
      23             : #include <vcl/image.hxx>
      24             : #include <svl/eitem.hxx>
      25             : #include <svx/viewlayoutitem.hxx>
      26             : #include <utlui.hrc>
      27             : #include <swtypes.hxx>
      28             : 
      29         940 : SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
      30             : 
      31        1700 : struct SwViewLayoutControl::SwViewLayoutControl_Impl
      32             : {
      33             :     sal_uInt16      mnState; // 0 = single, 1 = auto, 2 = book, 3 = none
      34             :     Image       maImageSingleColumn;
      35             :     Image       maImageSingleColumn_Active;
      36             :     Image       maImageAutomatic;
      37             :     Image       maImageAutomatic_Active;
      38             :     Image       maImageBookMode;
      39             :     Image       maImageBookMode_Active;
      40             : };
      41             : 
      42         850 : SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
      43             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      44         850 :     mpImpl( new SwViewLayoutControl_Impl )
      45             : {
      46         850 :     mpImpl->mnState = 0;
      47             : 
      48         850 :     mpImpl->maImageSingleColumn         = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
      49         850 :     mpImpl->maImageSingleColumn_Active  = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
      50         850 :     mpImpl->maImageAutomatic            = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
      51         850 :     mpImpl->maImageAutomatic_Active     = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
      52         850 :     mpImpl->maImageBookMode             = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
      53         850 :     mpImpl->maImageBookMode_Active      = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
      54             : 
      55         850 :     if ( rStb.GetDPIScaleFactor() > 1)
      56             :     {
      57             :         Image arr[6] = {mpImpl->maImageSingleColumn, mpImpl->maImageSingleColumn_Active,
      58             :                         mpImpl->maImageAutomatic, mpImpl->maImageAutomatic_Active,
      59           0 :                         mpImpl->maImageBookMode, mpImpl->maImageBookMode_Active};
      60             : 
      61           0 :         for (int i = 0; i < 6; i++)
      62             :         {
      63           0 :             BitmapEx b = arr[i].GetBitmapEx();
      64             :             //Don't scale width, no space.
      65           0 :             b.Scale(1.0, rStb.GetDPIScaleFactor(), BMP_SCALE_FAST);
      66           0 :             arr[i] = Image(b);
      67           0 :         }
      68             : 
      69           0 :         mpImpl->maImageSingleColumn = arr[0];
      70           0 :         mpImpl->maImageSingleColumn_Active = arr[1];
      71             : 
      72           0 :         mpImpl->maImageAutomatic = arr[2];
      73           0 :         mpImpl->maImageAutomatic_Active = arr[3];
      74             : 
      75           0 :         mpImpl->maImageBookMode = arr[4];
      76           0 :         mpImpl->maImageBookMode_Active = arr[5];
      77             :     }
      78             : 
      79         850 : }
      80             : 
      81        2550 : SwViewLayoutControl::~SwViewLayoutControl()
      82             : {
      83         850 :     delete mpImpl;
      84        1700 : }
      85             : 
      86        1035 : void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      87             : {
      88        1035 :     if ( SfxItemState::DEFAULT != eState || pState->ISA( SfxVoidItem ) )
      89           0 :         GetStatusBar().SetItemText( GetId(), OUString() );
      90             :     else
      91             :     {
      92             :         OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
      93        1035 :         const sal_uInt16 nColumns  = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
      94        1035 :         const bool   bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
      95             : 
      96             :         // SingleColumn Mode
      97        1035 :         if ( 1 == nColumns )
      98           0 :             mpImpl->mnState = 0;
      99             :         // Automatic Mode
     100        1035 :         else if ( 0 == nColumns )
     101        1035 :             mpImpl->mnState = 1;
     102             :         // Book Mode
     103           0 :         else if ( bBookMode && 2 == nColumns )
     104           0 :             mpImpl->mnState = 2;
     105             :         else
     106           0 :             mpImpl->mnState = 3;
     107             :     }
     108             : 
     109        1035 :     if ( GetStatusBar().AreItemsVisible() )
     110        1035 :         GetStatusBar().SetItemData( GetId(), 0 );    // force repaint
     111        1035 : }
     112             : 
     113        1589 : void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
     114             : {
     115        1589 :     OutputDevice*       pDev =  rUsrEvt.GetDevice();
     116        1589 :     Rectangle           aRect = rUsrEvt.GetRect();
     117             : 
     118        1589 :     const Rectangle aControlRect = getControlRect();
     119             : 
     120        1589 :     const bool bSingleColumn    = 0 == mpImpl->mnState;
     121        1589 :     const bool bAutomatic       = 1 == mpImpl->mnState;
     122        1589 :     const bool bBookMode        = 2 == mpImpl->mnState;
     123             : 
     124        4767 :     const long nImageWidthSum = mpImpl->maImageSingleColumn.GetSizePixel().Width() +
     125        4767 :                                 mpImpl->maImageAutomatic.GetSizePixel().Width() +
     126        3178 :                                 mpImpl->maImageBookMode.GetSizePixel().Width();
     127             : 
     128        1589 :     const long nXOffset = (aRect.GetWidth()  - nImageWidthSum)/2;
     129        1589 :     const long nYOffset = (aControlRect.GetHeight() - mpImpl->maImageSingleColumn.GetSizePixel().Height())/2;
     130             : 
     131        1589 :     aRect.Left() = aRect.Left() + nXOffset;
     132        1589 :     aRect.Top()  = aRect.Top() + nYOffset;
     133             : 
     134             :     // draw single column image:
     135        1589 :     pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
     136             : 
     137             :     // draw automatic image:
     138        1589 :     aRect.Left() += mpImpl->maImageSingleColumn.GetSizePixel().Width();
     139        1589 :     pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active       : mpImpl->maImageAutomatic );
     140             : 
     141             :     // draw bookmode image:
     142        1589 :     aRect.Left() += mpImpl->maImageAutomatic.GetSizePixel().Width();
     143        1589 :     pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active         : mpImpl->maImageBookMode );
     144        1589 : }
     145             : 
     146           0 : bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
     147             : {
     148           0 :     const Rectangle aRect = getControlRect();
     149           0 :     const Point aPoint = rEvt.GetPosPixel();
     150           0 :     const long nXDiff = aPoint.X() - aRect.Left();
     151             : 
     152           0 :     sal_uInt16 nColumns = 1;
     153           0 :     bool bBookMode = false;
     154             : 
     155           0 :     const long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
     156           0 :     const long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
     157           0 :     const long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
     158           0 :     const long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
     159             : 
     160           0 :     const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
     161             : 
     162           0 :     if ( nXDiff < nXOffset + nImageWidthSingle )
     163             :     {
     164           0 :         mpImpl->mnState = 0; // single
     165           0 :         nColumns = 1;
     166             :     }
     167           0 :     else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
     168             :     {
     169           0 :         mpImpl->mnState = 1; // auto
     170           0 :         nColumns = 0;
     171             :     }
     172             :     else
     173             :     {
     174           0 :         mpImpl->mnState = 2; // book
     175           0 :         nColumns = 2;
     176           0 :         bBookMode = true;
     177             :     }
     178             : 
     179             :     // commit state change
     180           0 :     SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
     181             : 
     182           0 :     ::com::sun::star::uno::Any a;
     183           0 :     aViewLayout.QueryValue( a );
     184             : 
     185           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     186           0 :     aArgs[0].Name = "ViewLayout";
     187           0 :     aArgs[0].Value = a;
     188             : 
     189           0 :     execute( aArgs );
     190             : 
     191           0 :     return true;
     192         270 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10