bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / utlui / viewlayoutctrl.cxx
blob6e4fbd3de59f50ccecf3bc1d3aca2cf9b65e9151
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <viewlayoutctrl.hxx>
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> // for pathfinder
29 SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
31 const long nImageWidthSingle = 14;
32 const long nImageWidthAuto = 24;
33 const long nImageWidthBook = 22;
34 const long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
35 const long nImageHeight = 10;
37 struct SwViewLayoutControl::SwViewLayoutControl_Impl
39 sal_uInt16 mnState; // 0 = single, 1 = auto, 2 = book, 3 = none
40 Image maImageSingleColumn;
41 Image maImageSingleColumn_Active;
42 Image maImageAutomatic;
43 Image maImageAutomatic_Active;
44 Image maImageBookMode;
45 Image maImageBookMode_Active;
48 SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
49 SfxStatusBarControl( _nSlotId, _nId, rStb ),
50 mpImpl( new SwViewLayoutControl_Impl )
52 mpImpl->mnState = 0;
54 mpImpl->maImageSingleColumn = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
55 mpImpl->maImageSingleColumn_Active = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
56 mpImpl->maImageAutomatic = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
57 mpImpl->maImageAutomatic_Active = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
58 mpImpl->maImageBookMode = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
59 mpImpl->maImageBookMode_Active = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
62 SwViewLayoutControl::~SwViewLayoutControl()
64 delete mpImpl;
67 void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
69 if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
70 GetStatusBar().SetItemText( GetId(), String() );
71 else
73 OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
74 const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
75 const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
77 // SingleColumn Mode
78 if ( 1 == nColumns )
79 mpImpl->mnState = 0;
80 // Automatic Mode
81 else if ( 0 == nColumns )
82 mpImpl->mnState = 1;
83 // Book Mode
84 else if ( bBookMode && 2 == nColumns )
85 mpImpl->mnState = 2;
86 else
87 mpImpl->mnState = 3;
90 if ( GetStatusBar().AreItemsVisible() )
91 GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
94 void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
96 OutputDevice* pDev = rUsrEvt.GetDevice();
97 Rectangle aRect = rUsrEvt.GetRect();
99 const Rectangle aControlRect = getControlRect();
101 const bool bSingleColumn = 0 == mpImpl->mnState;
102 const bool bAutomatic = 1 == mpImpl->mnState;
103 const bool bBookMode = 2 == mpImpl->mnState;
105 const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
106 const long nYOffset = (aControlRect.GetHeight() - nImageHeight)/2;
108 aRect.Left() = aRect.Left() + nXOffset;
109 aRect.Top() = aRect.Top() + nYOffset;
111 // draw single column image:
112 pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
114 // draw automatic image:
115 aRect.Left() += nImageWidthSingle;
116 pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
118 // draw bookmode image:
119 aRect.Left() += nImageWidthAuto;
120 pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
123 sal_Bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
125 const Rectangle aRect = getControlRect();
126 const Point aPoint = rEvt.GetPosPixel();
127 const long nXDiff = aPoint.X() - aRect.Left();
129 sal_uInt16 nColumns = 1;
130 bool bBookMode = false;
132 const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
134 if ( nXDiff < nXOffset + nImageWidthSingle )
136 mpImpl->mnState = 0; // single
137 nColumns = 1;
139 else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
141 mpImpl->mnState = 1; // auto
142 nColumns = 0;
144 else
146 mpImpl->mnState = 2; // book
147 nColumns = 2;
148 bBookMode = true;
151 // commit state change
152 SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
154 ::com::sun::star::uno::Any a;
155 aViewLayout.QueryValue( a );
157 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
158 aArgs[0].Name = OUString( "ViewLayout" );
159 aArgs[0].Value = a;
161 execute( aArgs );
163 return sal_True;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */