Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <viewlayoutctrl.hxx>
30 : :
31 : : #include <vcl/status.hxx>
32 : : #include <vcl/image.hxx>
33 : : #include <svl/eitem.hxx>
34 : : #include <svx/viewlayoutitem.hxx>
35 : : #include <utlui.hrc>
36 : : #include <swtypes.hxx> // fuer Pathfinder
37 : :
38 : : // STATIC DATA -----------------------------------------------------------
39 : :
40 [ + - ]: 833 : SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
41 : :
42 : : const long nImageWidthSingle = 14;
43 : : const long nImageWidthAuto = 24;
44 : : const long nImageWidthBook = 22;
45 : : const long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
46 : : const long nImageHeight = 10;
47 : :
48 [ + - ][ + - ]: 1520 : struct SwViewLayoutControl::SwViewLayoutControl_Impl
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
49 : : {
50 : : sal_uInt16 mnState; // 0 = single, 1 = auto, 2 = book, 3 = none
51 : : Image maImageSingleColumn;
52 : : Image maImageSingleColumn_Active;
53 : : Image maImageAutomatic;
54 : : Image maImageAutomatic_Active;
55 : : Image maImageBookMode;
56 : : Image maImageBookMode_Active;
57 : : };
58 : :
59 : : // class SwViewLayoutControl ------------------------------------------
60 : :
61 : 760 : SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
62 : : SfxStatusBarControl( _nSlotId, _nId, rStb ),
63 [ + - ][ + - ]: 760 : mpImpl( new SwViewLayoutControl_Impl )
64 : : {
65 : 760 : mpImpl->mnState = 0;
66 : :
67 [ + - ][ + - ]: 760 : mpImpl->maImageSingleColumn = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
[ + - ]
68 [ + - ][ + - ]: 760 : mpImpl->maImageSingleColumn_Active = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
[ + - ]
69 [ + - ][ + - ]: 760 : mpImpl->maImageAutomatic = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
[ + - ]
70 [ + - ][ + - ]: 760 : mpImpl->maImageAutomatic_Active = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
[ + - ]
71 [ + - ][ + - ]: 760 : mpImpl->maImageBookMode = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
[ + - ]
72 [ + - ][ + - ]: 760 : mpImpl->maImageBookMode_Active = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
[ + - ]
73 : 760 : }
74 : :
75 : 760 : SwViewLayoutControl::~SwViewLayoutControl()
76 : : {
77 [ + - ][ + - ]: 760 : delete mpImpl;
78 [ - + ]: 1520 : }
79 : :
80 : 1236 : void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
81 : : {
82 [ + - ][ - + ]: 1236 : if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
[ - + ]
83 [ # # ]: 0 : GetStatusBar().SetItemText( GetId(), String() );
84 : : else
85 : : {
86 : : OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
87 : 1236 : const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
88 : 1236 : const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
89 : :
90 : : // SingleColumn Mode
91 [ - + ]: 1236 : if ( 1 == nColumns )
92 : 0 : mpImpl->mnState = 0;
93 : : // Automatic Mode
94 [ + - ]: 1236 : else if ( 0 == nColumns )
95 : 1236 : mpImpl->mnState = 1;
96 : : // Book Mode
97 [ # # ][ # # ]: 0 : else if ( bBookMode && 2 == nColumns )
98 : 0 : mpImpl->mnState = 2;
99 : : else
100 : 0 : mpImpl->mnState = 3;
101 : : }
102 : :
103 [ + - ]: 1236 : if ( GetStatusBar().AreItemsVisible() )
104 : 1236 : GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
105 : 1236 : }
106 : :
107 : 2099 : void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
108 : : {
109 : 2099 : OutputDevice* pDev = rUsrEvt.GetDevice();
110 : 2099 : Rectangle aRect = rUsrEvt.GetRect();
111 : :
112 [ + - ]: 2099 : const Rectangle aControlRect = getControlRect();
113 : :
114 : 2099 : const bool bSingleColumn = 0 == mpImpl->mnState;
115 : 2099 : const bool bAutomatic = 1 == mpImpl->mnState;
116 : 2099 : const bool bBookMode = 2 == mpImpl->mnState;
117 : :
118 [ + - ]: 2099 : const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
119 [ + - ]: 2099 : const long nYOffset = (aControlRect.GetHeight() - nImageHeight)/2;
120 : :
121 : 2099 : aRect.Left() = aRect.Left() + nXOffset;
122 : 2099 : aRect.Top() = aRect.Top() + nYOffset;
123 : :
124 : : // draw single column image:
125 [ + - ][ - + ]: 2099 : pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
126 : :
127 : : // draw automatic image:
128 : 2099 : aRect.Left() += nImageWidthSingle;
129 [ + - ][ + - ]: 2099 : pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
130 : :
131 : : // draw bookmode image:
132 : 2099 : aRect.Left() += nImageWidthAuto;
133 [ + - ][ - + ]: 2099 : pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
134 : 2099 : }
135 : :
136 : 0 : sal_Bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
137 : : {
138 [ # # ]: 0 : const Rectangle aRect = getControlRect();
139 : 0 : const Point aPoint = rEvt.GetPosPixel();
140 : 0 : const long nXDiff = aPoint.X() - aRect.Left();
141 : :
142 : 0 : sal_uInt16 nColumns = 1;
143 : 0 : bool bBookMode = false;
144 : :
145 [ # # ]: 0 : const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
146 : :
147 [ # # ]: 0 : if ( nXDiff < nXOffset + nImageWidthSingle )
148 : : {
149 : 0 : mpImpl->mnState = 0; // single
150 : 0 : nColumns = 1;
151 : : }
152 [ # # ]: 0 : else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
153 : : {
154 : 0 : mpImpl->mnState = 1; // auto
155 : 0 : nColumns = 0;
156 : : }
157 : : else
158 : : {
159 : 0 : mpImpl->mnState = 2; // book
160 : 0 : nColumns = 2;
161 : 0 : bBookMode = true;
162 : : }
163 : :
164 : : // commit state change
165 [ # # ]: 0 : SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
166 : :
167 : 0 : ::com::sun::star::uno::Any a;
168 [ # # ]: 0 : aViewLayout.QueryValue( a );
169 : :
170 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
171 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ViewLayout" ));
172 [ # # ]: 0 : aArgs[0].Value = a;
173 : :
174 [ # # ]: 0 : execute( aArgs );
175 : :
176 [ # # ][ # # ]: 0 : return sal_True;
177 : : }
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|