LCOV - code coverage report
Current view: top level - sw/source/uibase/utlui - viewlayoutctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 48 107 44.9 %
Date: 2015-06-13 12:38:46 Functions: 9 11 81.8 %
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         403 : SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
      30             : 
      31         688 : struct SwViewLayoutControl::SwViewLayoutControl_Impl
      32             : {
      33             :     sal_uInt16      mnState; // 0 = auto, 1= single, 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         344 : SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStatusBar ) :
      43             :     SfxStatusBarControl( _nSlotId, _nId, rStatusBar ),
      44         344 :     mpImpl( new SwViewLayoutControl_Impl )
      45             : {
      46         344 :     mpImpl->mnState = 1;
      47             : 
      48         344 :     mpImpl->maImageSingleColumn         = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
      49         344 :     mpImpl->maImageSingleColumn_Active  = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
      50         344 :     mpImpl->maImageAutomatic            = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
      51         344 :     mpImpl->maImageAutomatic_Active     = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
      52         344 :     mpImpl->maImageBookMode             = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
      53         344 :     mpImpl->maImageBookMode_Active      = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
      54             : 
      55         344 :     sal_Int32 nScaleFactor = rStatusBar.GetDPIScaleFactor();
      56         344 :     if (nScaleFactor != 1)
      57             :     {
      58             :         Image arr[6] = {mpImpl->maImageSingleColumn, mpImpl->maImageSingleColumn_Active,
      59             :                         mpImpl->maImageAutomatic, mpImpl->maImageAutomatic_Active,
      60           0 :                         mpImpl->maImageBookMode, mpImpl->maImageBookMode_Active};
      61             : 
      62           0 :         for (int i = 0; i < 6; i++)
      63             :         {
      64           0 :             BitmapEx aBitmap = arr[i].GetBitmapEx();
      65           0 :             aBitmap.Scale(nScaleFactor, nScaleFactor, BmpScaleFlag::Fast);
      66           0 :             arr[i] = Image(aBitmap);
      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         344 : }
      79             : 
      80        1032 : SwViewLayoutControl::~SwViewLayoutControl()
      81             : {
      82         344 :     delete mpImpl;
      83         688 : }
      84             : 
      85         608 : void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      86             : {
      87         608 :     if ( SfxItemState::DEFAULT != eState || pState->ISA( SfxVoidItem ) )
      88           0 :         GetStatusBar().SetItemText( GetId(), OUString() );
      89             :     else
      90             :     {
      91             :         OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
      92         608 :         const sal_uInt16 nColumns  = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
      93         608 :         const bool   bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
      94             : 
      95             :         // SingleColumn Mode
      96         608 :         if ( 1 == nColumns )
      97         603 :             mpImpl->mnState = 0;
      98             :         // Automatic Mode
      99           5 :         else if ( 0 == nColumns )
     100           5 :             mpImpl->mnState = 1;
     101             :         // Book Mode
     102           0 :         else if ( bBookMode && 2 == nColumns )
     103           0 :             mpImpl->mnState = 2;
     104             :         else
     105           0 :             mpImpl->mnState = 3;
     106             :     }
     107             : 
     108         608 :     if ( GetStatusBar().AreItemsVisible() )
     109         608 :         GetStatusBar().SetItemData( GetId(), 0 );    // force repaint
     110         608 : }
     111             : 
     112        3197 : void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
     113             : {
     114        3197 :     OutputDevice*       pDev =  rUsrEvt.GetDevice();
     115        3197 :     Rectangle           aRect = rUsrEvt.GetRect();
     116             : 
     117        3197 :     const Rectangle aControlRect = getControlRect();
     118             : 
     119        3197 :     const bool bSingleColumn    = 0 == mpImpl->mnState;
     120        3197 :     const bool bAutomatic       = 1 == mpImpl->mnState;
     121        3197 :     const bool bBookMode        = 2 == mpImpl->mnState;
     122             : 
     123        9591 :     const long nImageWidthSum = mpImpl->maImageSingleColumn.GetSizePixel().Width() +
     124        9591 :                                 mpImpl->maImageAutomatic.GetSizePixel().Width() +
     125        6394 :                                 mpImpl->maImageBookMode.GetSizePixel().Width();
     126             : 
     127        3197 :     const long nXOffset = (aRect.GetWidth() - nImageWidthSum) / 2;
     128        3197 :     const long nYOffset = (aControlRect.GetHeight() - mpImpl->maImageSingleColumn.GetSizePixel().Height()) / 2;
     129             : 
     130        3197 :     aRect.Left() = aRect.Left() + nXOffset;
     131        3197 :     aRect.Top()  = aRect.Top() + nYOffset;
     132             : 
     133             :     // draw single column image:
     134        3197 :     pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
     135             : 
     136             :     // draw automatic image:
     137        3197 :     aRect.Left() += mpImpl->maImageSingleColumn.GetSizePixel().Width();
     138        3197 :     pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active       : mpImpl->maImageAutomatic );
     139             : 
     140             :     // draw bookmode image:
     141        3197 :     aRect.Left() += mpImpl->maImageAutomatic.GetSizePixel().Width();
     142        3197 :     pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active         : mpImpl->maImageBookMode );
     143        3197 : }
     144             : 
     145           0 : bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
     146             : {
     147           0 :     const Rectangle aRect = getControlRect();
     148           0 :     const Point aPoint = rEvt.GetPosPixel();
     149           0 :     const long nXDiff = aPoint.X() - aRect.Left();
     150             : 
     151           0 :     sal_uInt16 nColumns = 1;
     152           0 :     bool bBookMode = false;
     153             : 
     154           0 :     const long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
     155           0 :     const long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
     156           0 :     const long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
     157           0 :     const long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
     158             : 
     159           0 :     const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
     160             : 
     161           0 :     if ( nXDiff < nXOffset + nImageWidthSingle )
     162             :     {
     163           0 :         mpImpl->mnState = 0; // single
     164           0 :         nColumns = 1;
     165             :     }
     166           0 :     else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
     167             :     {
     168           0 :         mpImpl->mnState = 1; // auto
     169           0 :         nColumns = 0;
     170             :     }
     171             :     else
     172             :     {
     173           0 :         mpImpl->mnState = 2; // book
     174           0 :         nColumns = 2;
     175           0 :         bBookMode = true;
     176             :     }
     177             : 
     178             :     // commit state change
     179           0 :     SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
     180             : 
     181           0 :     ::com::sun::star::uno::Any a;
     182           0 :     aViewLayout.QueryValue( a );
     183             : 
     184           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     185           0 :     aArgs[0].Name = "ViewLayout";
     186           0 :     aArgs[0].Value = a;
     187             : 
     188           0 :     execute( aArgs );
     189             : 
     190           0 :     return true;
     191             : }
     192             : 
     193           0 : bool SwViewLayoutControl::MouseMove( const MouseEvent & rEvt )
     194             : {
     195           0 :     const Rectangle aRect = getControlRect();
     196           0 :     const Point aPoint = rEvt.GetPosPixel();
     197           0 :     const long nXDiff = aPoint.X() - aRect.Left();
     198             : 
     199           0 :     const long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
     200           0 :     const long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
     201           0 :     const long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
     202           0 :     const long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
     203             : 
     204           0 :     const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
     205             : 
     206           0 :     if ( nXDiff < nXOffset + nImageWidthSingle )
     207             :     {
     208           0 :         GetStatusBar().SetQuickHelpText(GetId(), SW_RESSTR(STR_VIEWLAYOUT_ONE));
     209             :     }
     210           0 :     else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
     211             :     {
     212           0 :         GetStatusBar().SetQuickHelpText(GetId(), SW_RESSTR(STR_VIEWLAYOUT_MULTI));
     213             :     }
     214             :     else
     215             :     {
     216           0 :         GetStatusBar().SetQuickHelpText(GetId(), SW_RESSTR(STR_VIEWLAYOUT_BOOK));
     217             :     }
     218           0 :     return true;
     219             : }
     220             : 
     221             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11