merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / utlui / viewlayoutctrl.cxx
blob5825200ebf21552bdc88d5dfdc3ff7ba63c88264
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewlayoutctrl.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 // include ---------------------------------------------------------------
35 #include <viewlayoutctrl.hxx>
37 #ifndef _STATUS_HXX //autogen
38 #include <vcl/status.hxx>
39 #endif
40 #include <vcl/image.hxx>
41 #include <svtools/eitem.hxx>
42 #include <svx/viewlayoutitem.hxx>
43 #ifndef _UTLUI_HRC
44 #include <utlui.hrc>
45 #endif
46 #include <swtypes.hxx> // fuer Pathfinder
48 // STATIC DATA -----------------------------------------------------------
50 SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
52 // -----------------------------------------------------------------------
54 const long nImageWidthSingle = 15;
55 const long nImageWidthAuto = 25;
56 const long nImageWidthBook = 23;
57 const long nImageWidthSum = 63;
58 const long nImageHeight = 11;
60 // -----------------------------------------------------------------------
62 struct SwViewLayoutControl::SwViewLayoutControl_Impl
64 USHORT mnState; // 0 = single, 1 = auto, 2 = book, 3 = none
65 Image maImageSingleColumn;
66 Image maImageSingleColumn_Active;
67 Image maImageAutomatic;
68 Image maImageAutomatic_Active;
69 Image maImageBookMode;
70 Image maImageBookMode_Active;
73 // class SwViewLayoutControl ------------------------------------------
75 SwViewLayoutControl::SwViewLayoutControl( USHORT _nSlotId, USHORT _nId, StatusBar& rStb ) :
76 SfxStatusBarControl( _nSlotId, _nId, rStb ),
77 mpImpl( new SwViewLayoutControl_Impl )
79 mpImpl->mnState = 0;
81 const sal_Bool bIsDark = GetStatusBar().GetBackground().GetColor().IsDark();
82 mpImpl->maImageSingleColumn = Image( bIsDark ? SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_HC) : SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
83 mpImpl->maImageSingleColumn_Active = Image( bIsDark ? SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
84 mpImpl->maImageAutomatic = Image( bIsDark ? SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_HC) : SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
85 mpImpl->maImageAutomatic_Active = Image( bIsDark ? SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
86 mpImpl->maImageBookMode = Image( bIsDark ? SW_RES(IMG_VIEWLAYOUT_BOOKMODE_HC) : SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
87 mpImpl->maImageBookMode_Active = Image( bIsDark ? SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
90 // -----------------------------------------------------------------------
92 SwViewLayoutControl::~SwViewLayoutControl()
94 delete mpImpl;
97 // -----------------------------------------------------------------------
99 void SwViewLayoutControl::StateChanged( USHORT /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
101 if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
102 GetStatusBar().SetItemText( GetId(), String() );
103 else
105 DBG_ASSERT( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
106 const USHORT nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
107 const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
109 // SingleColumn Mode
110 if ( 1 == nColumns )
111 mpImpl->mnState = 0;
112 // Automatic Mode
113 else if ( 0 == nColumns )
114 mpImpl->mnState = 1;
115 // Book Mode
116 else if ( bBookMode && 2 == nColumns )
117 mpImpl->mnState = 2;
118 else
119 mpImpl->mnState = 3;
122 if ( GetStatusBar().AreItemsVisible() )
123 GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
126 // -----------------------------------------------------------------------
128 void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
130 OutputDevice* pDev = rUsrEvt.GetDevice();
131 Rectangle aRect = rUsrEvt.GetRect();
132 Color aOldLineColor = pDev->GetLineColor();
133 Color aOldFillColor = pDev->GetFillColor();
135 //pDev->SetLineColor();
136 //pDev->SetFillColor( pDev->GetBackground().GetColor() );
138 const bool bSingleColumn = 0 == mpImpl->mnState;
139 const bool bAutomatic = 1 == mpImpl->mnState;
140 const bool bBookMode = 2 == mpImpl->mnState;
142 const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
143 const long nYOffset = (aRect.GetHeight() - nImageHeight)/2;
145 aRect.Left() = aRect.Left() + nXOffset;
146 aRect.Top() = aRect.Top() + nYOffset;
148 // draw single column image:
149 pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
151 // draw automatic image:
152 aRect.Left() += nImageWidthSingle;
153 pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
155 // draw bookmode image:
156 aRect.Left() += nImageWidthAuto;
157 pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
159 // draw separators
160 //aRect = rUsrEvt.GetRect();
161 //aRect.Left() += nImageWidth;
162 //aRect.setWidth( 1 );
163 //pDev->DrawRect( aRect );
164 //aRect.Left() += nImageWidth;
165 //pDev->DrawRect( aRect );
167 //pDev->SetLineColor( aOldLineColor );
168 //pDev->SetFillColor( aOldFillColor );
171 BOOL SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
173 const Rectangle aRect = getControlRect();
174 const Point aPoint = rEvt.GetPosPixel();
175 const long nXDiff = aPoint.X() - aRect.Left();
177 USHORT nColumns = 1;
178 bool bBookMode = false;
180 const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
182 if ( nXDiff < nXOffset + nImageWidthSingle )
184 mpImpl->mnState = 0; // single
185 nColumns = 1;
187 else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
189 mpImpl->mnState = 1; // auto
190 nColumns = 0;
192 else
194 mpImpl->mnState = 2; // book
195 nColumns = 2;
196 bBookMode = true;
199 // commit state change
200 SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
202 ::com::sun::star::uno::Any a;
203 aViewLayout.QueryValue( a );
205 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
206 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ViewLayout" ));
207 aArgs[0].Value = a;
209 execute( aArgs );
211 return TRUE;