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