1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <viewlayoutctrl.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen
31cdf0e10cSrcweir #include <vcl/status.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <vcl/image.hxx>
34cdf0e10cSrcweir #include <svl/eitem.hxx>
35cdf0e10cSrcweir #include <svx/viewlayoutitem.hxx>
36cdf0e10cSrcweir #ifndef _UTLUI_HRC
37cdf0e10cSrcweir #include <utlui.hrc>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <swtypes.hxx> // fuer Pathfinder
40cdf0e10cSrcweir
41cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
42cdf0e10cSrcweir
43cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
44cdf0e10cSrcweir
45cdf0e10cSrcweir // -----------------------------------------------------------------------
46cdf0e10cSrcweir
47cdf0e10cSrcweir const long nImageWidthSingle = 15;
48cdf0e10cSrcweir const long nImageWidthAuto = 25;
49cdf0e10cSrcweir const long nImageWidthBook = 23;
50cdf0e10cSrcweir const long nImageWidthSum = 63;
51cdf0e10cSrcweir const long nImageHeight = 11;
52cdf0e10cSrcweir
53cdf0e10cSrcweir // -----------------------------------------------------------------------
54cdf0e10cSrcweir
55cdf0e10cSrcweir struct SwViewLayoutControl::SwViewLayoutControl_Impl
56cdf0e10cSrcweir {
57cdf0e10cSrcweir sal_uInt16 mnState; // 0 = single, 1 = auto, 2 = book, 3 = none
58cdf0e10cSrcweir Image maImageSingleColumn;
59cdf0e10cSrcweir Image maImageSingleColumn_Active;
60cdf0e10cSrcweir Image maImageAutomatic;
61cdf0e10cSrcweir Image maImageAutomatic_Active;
62cdf0e10cSrcweir Image maImageBookMode;
63cdf0e10cSrcweir Image maImageBookMode_Active;
64cdf0e10cSrcweir };
65cdf0e10cSrcweir
66cdf0e10cSrcweir // class SwViewLayoutControl ------------------------------------------
67cdf0e10cSrcweir
SwViewLayoutControl(sal_uInt16 _nSlotId,sal_uInt16 _nId,StatusBar & rStb)68cdf0e10cSrcweir SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
69cdf0e10cSrcweir SfxStatusBarControl( _nSlotId, _nId, rStb ),
70cdf0e10cSrcweir mpImpl( new SwViewLayoutControl_Impl )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir mpImpl->mnState = 0;
73cdf0e10cSrcweir
74cdf0e10cSrcweir const sal_Bool bHC = GetStatusBar().GetSettings().GetStyleSettings().GetHighContrastMode();
75cdf0e10cSrcweir mpImpl->maImageSingleColumn = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_HC) : SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
76cdf0e10cSrcweir mpImpl->maImageSingleColumn_Active = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
77cdf0e10cSrcweir mpImpl->maImageAutomatic = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_HC) : SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
78cdf0e10cSrcweir mpImpl->maImageAutomatic_Active = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
79cdf0e10cSrcweir mpImpl->maImageBookMode = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_BOOKMODE_HC) : SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
80cdf0e10cSrcweir mpImpl->maImageBookMode_Active = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir // -----------------------------------------------------------------------
84cdf0e10cSrcweir
~SwViewLayoutControl()85cdf0e10cSrcweir SwViewLayoutControl::~SwViewLayoutControl()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir delete mpImpl;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir // -----------------------------------------------------------------------
91cdf0e10cSrcweir
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)92cdf0e10cSrcweir void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
95cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() );
96cdf0e10cSrcweir else
97cdf0e10cSrcweir {
98cdf0e10cSrcweir DBG_ASSERT( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
99cdf0e10cSrcweir const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
100cdf0e10cSrcweir const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
101cdf0e10cSrcweir
102cdf0e10cSrcweir // SingleColumn Mode
103cdf0e10cSrcweir if ( 1 == nColumns )
104cdf0e10cSrcweir mpImpl->mnState = 0;
105cdf0e10cSrcweir // Automatic Mode
106cdf0e10cSrcweir else if ( 0 == nColumns )
107cdf0e10cSrcweir mpImpl->mnState = 1;
108cdf0e10cSrcweir // Book Mode
109cdf0e10cSrcweir else if ( bBookMode && 2 == nColumns )
110cdf0e10cSrcweir mpImpl->mnState = 2;
111cdf0e10cSrcweir else
112cdf0e10cSrcweir mpImpl->mnState = 3;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
115cdf0e10cSrcweir if ( GetStatusBar().AreItemsVisible() )
116cdf0e10cSrcweir GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir // -----------------------------------------------------------------------
120cdf0e10cSrcweir
Paint(const UserDrawEvent & rUsrEvt)121cdf0e10cSrcweir void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir OutputDevice* pDev = rUsrEvt.GetDevice();
124cdf0e10cSrcweir Rectangle aRect = rUsrEvt.GetRect();
125cdf0e10cSrcweir Color aOldLineColor = pDev->GetLineColor();
126cdf0e10cSrcweir Color aOldFillColor = pDev->GetFillColor();
127cdf0e10cSrcweir
128cdf0e10cSrcweir //pDev->SetLineColor();
129cdf0e10cSrcweir //pDev->SetFillColor( pDev->GetBackground().GetColor() );
130cdf0e10cSrcweir
131cdf0e10cSrcweir const bool bSingleColumn = 0 == mpImpl->mnState;
132cdf0e10cSrcweir const bool bAutomatic = 1 == mpImpl->mnState;
133cdf0e10cSrcweir const bool bBookMode = 2 == mpImpl->mnState;
134cdf0e10cSrcweir
135cdf0e10cSrcweir const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
136cdf0e10cSrcweir const long nYOffset = (aRect.GetHeight() - nImageHeight)/2;
137cdf0e10cSrcweir
138cdf0e10cSrcweir aRect.Left() = aRect.Left() + nXOffset;
139cdf0e10cSrcweir aRect.Top() = aRect.Top() + nYOffset;
140cdf0e10cSrcweir
141cdf0e10cSrcweir // draw single column image:
142cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
143cdf0e10cSrcweir
144cdf0e10cSrcweir // draw automatic image:
145cdf0e10cSrcweir aRect.Left() += nImageWidthSingle;
146cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
147cdf0e10cSrcweir
148cdf0e10cSrcweir // draw bookmode image:
149cdf0e10cSrcweir aRect.Left() += nImageWidthAuto;
150cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
151cdf0e10cSrcweir
152cdf0e10cSrcweir // draw separators
153cdf0e10cSrcweir //aRect = rUsrEvt.GetRect();
154cdf0e10cSrcweir //aRect.Left() += nImageWidth;
155cdf0e10cSrcweir //aRect.setWidth( 1 );
156cdf0e10cSrcweir //pDev->DrawRect( aRect );
157cdf0e10cSrcweir //aRect.Left() += nImageWidth;
158cdf0e10cSrcweir //pDev->DrawRect( aRect );
159cdf0e10cSrcweir
160cdf0e10cSrcweir //pDev->SetLineColor( aOldLineColor );
161cdf0e10cSrcweir //pDev->SetFillColor( aOldFillColor );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rEvt)164cdf0e10cSrcweir sal_Bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir const Rectangle aRect = getControlRect();
167cdf0e10cSrcweir const Point aPoint = rEvt.GetPosPixel();
168cdf0e10cSrcweir const long nXDiff = aPoint.X() - aRect.Left();
169cdf0e10cSrcweir
170cdf0e10cSrcweir sal_uInt16 nColumns = 1;
171cdf0e10cSrcweir bool bBookMode = false;
172cdf0e10cSrcweir
173cdf0e10cSrcweir const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
174cdf0e10cSrcweir
175cdf0e10cSrcweir if ( nXDiff < nXOffset + nImageWidthSingle )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir mpImpl->mnState = 0; // single
178cdf0e10cSrcweir nColumns = 1;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir mpImpl->mnState = 1; // auto
183cdf0e10cSrcweir nColumns = 0;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir else
186cdf0e10cSrcweir {
187cdf0e10cSrcweir mpImpl->mnState = 2; // book
188cdf0e10cSrcweir nColumns = 2;
189cdf0e10cSrcweir bBookMode = true;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir // commit state change
193cdf0e10cSrcweir SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
194cdf0e10cSrcweir
195cdf0e10cSrcweir ::com::sun::star::uno::Any a;
196cdf0e10cSrcweir aViewLayout.QueryValue( a );
197cdf0e10cSrcweir
198cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
199cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ViewLayout" ));
200cdf0e10cSrcweir aArgs[0].Value = a;
201cdf0e10cSrcweir
202cdf0e10cSrcweir execute( aArgs );
203cdf0e10cSrcweir
204cdf0e10cSrcweir return sal_True;
205cdf0e10cSrcweir }
206