Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <viewlayoutctrl.hxx>
21 :
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
28 :
29 409 : SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem );
30 :
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;
36 :
37 752 : struct SwViewLayoutControl::SwViewLayoutControl_Impl
38 : {
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;
46 : };
47 :
48 376 : SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
49 : SfxStatusBarControl( _nSlotId, _nId, rStb ),
50 376 : mpImpl( new SwViewLayoutControl_Impl )
51 : {
52 376 : mpImpl->mnState = 0;
53 :
54 376 : mpImpl->maImageSingleColumn = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) );
55 376 : mpImpl->maImageSingleColumn_Active = Image( SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) );
56 376 : mpImpl->maImageAutomatic = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) );
57 376 : mpImpl->maImageAutomatic_Active = Image( SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) );
58 376 : mpImpl->maImageBookMode = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE) );
59 376 : mpImpl->maImageBookMode_Active = Image( SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) );
60 376 : }
61 :
62 1128 : SwViewLayoutControl::~SwViewLayoutControl()
63 : {
64 376 : delete mpImpl;
65 752 : }
66 :
67 604 : void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
68 : {
69 604 : if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) )
70 0 : GetStatusBar().SetItemText( GetId(), String() );
71 : else
72 : {
73 : OSL_ENSURE( pState->ISA( SvxViewLayoutItem ), "invalid item type" );
74 604 : const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
75 604 : const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
76 :
77 : // SingleColumn Mode
78 604 : if ( 1 == nColumns )
79 0 : mpImpl->mnState = 0;
80 : // Automatic Mode
81 604 : else if ( 0 == nColumns )
82 604 : mpImpl->mnState = 1;
83 : // Book Mode
84 0 : else if ( bBookMode && 2 == nColumns )
85 0 : mpImpl->mnState = 2;
86 : else
87 0 : mpImpl->mnState = 3;
88 : }
89 :
90 604 : if ( GetStatusBar().AreItemsVisible() )
91 604 : GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
92 604 : }
93 :
94 1160 : void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt )
95 : {
96 1160 : OutputDevice* pDev = rUsrEvt.GetDevice();
97 1160 : Rectangle aRect = rUsrEvt.GetRect();
98 :
99 1160 : const Rectangle aControlRect = getControlRect();
100 :
101 1160 : const bool bSingleColumn = 0 == mpImpl->mnState;
102 1160 : const bool bAutomatic = 1 == mpImpl->mnState;
103 1160 : const bool bBookMode = 2 == mpImpl->mnState;
104 :
105 1160 : const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
106 1160 : const long nYOffset = (aControlRect.GetHeight() - nImageHeight)/2;
107 :
108 1160 : aRect.Left() = aRect.Left() + nXOffset;
109 1160 : aRect.Top() = aRect.Top() + nYOffset;
110 :
111 : // draw single column image:
112 1160 : pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
113 :
114 : // draw automatic image:
115 1160 : aRect.Left() += nImageWidthSingle;
116 1160 : pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
117 :
118 : // draw bookmode image:
119 1160 : aRect.Left() += nImageWidthAuto;
120 1160 : pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
121 1160 : }
122 :
123 0 : sal_Bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt )
124 : {
125 0 : const Rectangle aRect = getControlRect();
126 0 : const Point aPoint = rEvt.GetPosPixel();
127 0 : const long nXDiff = aPoint.X() - aRect.Left();
128 :
129 0 : sal_uInt16 nColumns = 1;
130 0 : bool bBookMode = false;
131 :
132 0 : const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
133 :
134 0 : if ( nXDiff < nXOffset + nImageWidthSingle )
135 : {
136 0 : mpImpl->mnState = 0; // single
137 0 : nColumns = 1;
138 : }
139 0 : else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
140 : {
141 0 : mpImpl->mnState = 1; // auto
142 0 : nColumns = 0;
143 : }
144 : else
145 : {
146 0 : mpImpl->mnState = 2; // book
147 0 : nColumns = 2;
148 0 : bBookMode = true;
149 : }
150 :
151 : // commit state change
152 0 : SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
153 :
154 0 : ::com::sun::star::uno::Any a;
155 0 : aViewLayout.QueryValue( a );
156 :
157 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
158 0 : aArgs[0].Name = OUString( "ViewLayout" );
159 0 : aArgs[0].Value = a;
160 :
161 0 : execute( aArgs );
162 :
163 0 : return sal_True;
164 99 : }
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|