LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/utlui - viewlayoutctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 71 1.4 %
Date: 2012-12-27 Functions: 1 10 10.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>  // fuer Pathfinder
      28             : 
      29             : // STATIC DATA -----------------------------------------------------------
      30             : 
      31          10 : SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
      32             : 
      33             : const long nImageWidthSingle = 14;
      34             : const long nImageWidthAuto = 24;
      35             : const long nImageWidthBook = 22;
      36             : const long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
      37             : const long nImageHeight = 10;
      38             : 
      39           0 : struct SwViewLayoutControl::SwViewLayoutControl_Impl
      40             : {
      41             :     sal_uInt16      mnState; // 0 = single, 1 = auto, 2 = book, 3 = none
      42             :     Image       maImageSingleColumn;
      43             :     Image       maImageSingleColumn_Active;
      44             :     Image       maImageAutomatic;
      45             :     Image       maImageAutomatic_Active;
      46             :     Image       maImageBookMode;
      47             :     Image       maImageBookMode_Active;
      48             : };
      49             : 
      50             : // class SwViewLayoutControl ------------------------------------------
      51             : 
      52           0 : SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
      53             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      54           0 :     mpImpl( new SwViewLayoutControl_Impl )
      55             : {
      56           0 :     mpImpl->mnState = 0;
      57             : 
      58           0 :     mpImpl->maImageSingleColumn         = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
      59           0 :     mpImpl->maImageSingleColumn_Active  = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
      60           0 :     mpImpl->maImageAutomatic            = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
      61           0 :     mpImpl->maImageAutomatic_Active     = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
      62           0 :     mpImpl->maImageBookMode             = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
      63           0 :     mpImpl->maImageBookMode_Active      = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
      64           0 : }
      65             : 
      66           0 : SwViewLayoutControl::~SwViewLayoutControl()
      67             : {
      68           0 :     delete mpImpl;
      69           0 : }
      70             : 
      71           0 : void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      72             : {
      73           0 :     if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
      74           0 :         GetStatusBar().SetItemText( GetId(), String() );
      75             :     else
      76             :     {
      77             :         OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
      78           0 :         const sal_uInt16 nColumns  = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
      79           0 :         const bool   bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
      80             : 
      81             :         // SingleColumn Mode
      82           0 :         if ( 1 == nColumns )
      83           0 :             mpImpl->mnState = 0;
      84             :         // Automatic Mode
      85           0 :         else if ( 0 == nColumns )
      86           0 :             mpImpl->mnState = 1;
      87             :         // Book Mode
      88           0 :         else if ( bBookMode && 2 == nColumns )
      89           0 :             mpImpl->mnState = 2;
      90             :         else
      91           0 :             mpImpl->mnState = 3;
      92             :     }
      93             : 
      94           0 :     if ( GetStatusBar().AreItemsVisible() )
      95           0 :         GetStatusBar().SetItemData( GetId(), 0 );    // force repaint
      96           0 : }
      97             : 
      98           0 : void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
      99             : {
     100           0 :     OutputDevice*       pDev =  rUsrEvt.GetDevice();
     101           0 :     Rectangle           aRect = rUsrEvt.GetRect();
     102             : 
     103           0 :     const Rectangle aControlRect = getControlRect();
     104             : 
     105           0 :     const bool bSingleColumn    = 0 == mpImpl->mnState;
     106           0 :     const bool bAutomatic       = 1 == mpImpl->mnState;
     107           0 :     const bool bBookMode        = 2 == mpImpl->mnState;
     108             : 
     109           0 :     const long nXOffset = (aRect.GetWidth()  - nImageWidthSum)/2;
     110           0 :     const long nYOffset = (aControlRect.GetHeight() - nImageHeight)/2;
     111             : 
     112           0 :     aRect.Left() = aRect.Left() + nXOffset;
     113           0 :     aRect.Top()  = aRect.Top() + nYOffset;
     114             : 
     115             :     // draw single column image:
     116           0 :     pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
     117             : 
     118             :     // draw automatic image:
     119           0 :     aRect.Left() += nImageWidthSingle;
     120           0 :     pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active       : mpImpl->maImageAutomatic );
     121             : 
     122             :     // draw bookmode image:
     123           0 :     aRect.Left() += nImageWidthAuto;
     124           0 :     pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active         : mpImpl->maImageBookMode );
     125           0 : }
     126             : 
     127           0 : sal_Bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
     128             : {
     129           0 :     const Rectangle aRect = getControlRect();
     130           0 :     const Point aPoint = rEvt.GetPosPixel();
     131           0 :     const long nXDiff = aPoint.X() - aRect.Left();
     132             : 
     133           0 :     sal_uInt16 nColumns = 1;
     134           0 :     bool bBookMode = false;
     135             : 
     136           0 :     const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
     137             : 
     138           0 :     if ( nXDiff < nXOffset + nImageWidthSingle )
     139             :     {
     140           0 :         mpImpl->mnState = 0; // single
     141           0 :         nColumns = 1;
     142             :     }
     143           0 :     else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
     144             :     {
     145           0 :         mpImpl->mnState = 1; // auto
     146           0 :         nColumns = 0;
     147             :     }
     148             :     else
     149             :     {
     150           0 :         mpImpl->mnState = 2; // book
     151           0 :         nColumns = 2;
     152           0 :         bBookMode = true;
     153             :     }
     154             : 
     155             :     // commit state change
     156           0 :     SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
     157             : 
     158           0 :     ::com::sun::star::uno::Any a;
     159           0 :     aViewLayout.QueryValue( a );
     160             : 
     161           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     162           0 :     aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ViewLayout" ));
     163           0 :     aArgs[0].Value = a;
     164             : 
     165           0 :     execute( aArgs );
     166             : 
     167           0 :     return sal_True;
     168             : }
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10