LCOV - code coverage report
Current view: top level - sw/source/core/uibase/utlui - viewlayoutctrl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 91 0.0 %
Date: 2014-04-14 Functions: 0 10 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             : #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           0 : SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
      30             : 
      31           0 : 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           0 : SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
      43             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      44           0 :     mpImpl( new SwViewLayoutControl_Impl )
      45             : {
      46           0 :     mpImpl->mnState = 0;
      47             : 
      48           0 :     mpImpl->maImageSingleColumn         = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
      49           0 :     mpImpl->maImageSingleColumn_Active  = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
      50           0 :     mpImpl->maImageAutomatic            = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
      51           0 :     mpImpl->maImageAutomatic_Active     = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
      52           0 :     mpImpl->maImageBookMode             = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
      53           0 :     mpImpl->maImageBookMode_Active      = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
      54             : 
      55           0 :     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           0 : }
      80             : 
      81           0 : SwViewLayoutControl::~SwViewLayoutControl()
      82             : {
      83           0 :     delete mpImpl;
      84           0 : }
      85             : 
      86           0 : void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      87             : {
      88           0 :     if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
      89           0 :         GetStatusBar().SetItemText( GetId(), OUString() );
      90             :     else
      91             :     {
      92             :         OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
      93           0 :         const sal_uInt16 nColumns  = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
      94           0 :         const bool   bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
      95             : 
      96             :         // SingleColumn Mode
      97           0 :         if ( 1 == nColumns )
      98           0 :             mpImpl->mnState = 0;
      99             :         // Automatic Mode
     100           0 :         else if ( 0 == nColumns )
     101           0 :             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           0 :     if ( GetStatusBar().AreItemsVisible() )
     110           0 :         GetStatusBar().SetItemData( GetId(), 0 );    // force repaint
     111           0 : }
     112             : 
     113           0 : void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
     114             : {
     115           0 :     OutputDevice*       pDev =  rUsrEvt.GetDevice();
     116           0 :     Rectangle           aRect = rUsrEvt.GetRect();
     117             : 
     118           0 :     const Rectangle aControlRect = getControlRect();
     119             : 
     120           0 :     const bool bSingleColumn    = 0 == mpImpl->mnState;
     121           0 :     const bool bAutomatic       = 1 == mpImpl->mnState;
     122           0 :     const bool bBookMode        = 2 == mpImpl->mnState;
     123             : 
     124           0 :     const long nImageWidthSum = mpImpl->maImageSingleColumn.GetSizePixel().Width() +
     125           0 :                                 mpImpl->maImageAutomatic.GetSizePixel().Width() +
     126           0 :                                 mpImpl->maImageBookMode.GetSizePixel().Width();
     127             : 
     128           0 :     const long nXOffset = (aRect.GetWidth()  - nImageWidthSum)/2;
     129           0 :     const long nYOffset = (aControlRect.GetHeight() - mpImpl->maImageSingleColumn.GetSizePixel().Height())/2;
     130             : 
     131           0 :     aRect.Left() = aRect.Left() + nXOffset;
     132           0 :     aRect.Top()  = aRect.Top() + nYOffset;
     133             : 
     134             :     // draw single column image:
     135           0 :     pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
     136             : 
     137             :     // draw automatic image:
     138           0 :     aRect.Left() += mpImpl->maImageSingleColumn.GetSizePixel().Width();
     139           0 :     pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active       : mpImpl->maImageAutomatic );
     140             : 
     141             :     // draw bookmode image:
     142           0 :     aRect.Left() += mpImpl->maImageAutomatic.GetSizePixel().Width();
     143           0 :     pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active         : mpImpl->maImageBookMode );
     144           0 : }
     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             : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10