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 <limits.h>
30 : : #include <tools/shl.hxx>
31 : : #include <vcl/status.hxx>
32 : : #include <vcl/menu.hxx>
33 : : #include <vcl/image.hxx>
34 : : #include <svl/stritem.hxx>
35 : : #include <svl/ptitem.hxx>
36 : : #include <svl/itempool.hxx>
37 : : #include <sfx2/app.hxx>
38 : : #include <sfx2/module.hxx>
39 : : #include <sfx2/dispatch.hxx>
40 : : #include <sfx2/objsh.hxx>
41 : : #include <svl/intitem.hxx>
42 : :
43 : : #include "svx/pszctrl.hxx"
44 : :
45 : : #define PAINT_OFFSET 5
46 : :
47 : : #include <editeng/sizeitem.hxx>
48 : : #include <svx/dialmgr.hxx>
49 : : #include "svx/dlgutil.hxx"
50 : : #include "stbctrls.h"
51 : : #include "sfx2/module.hxx"
52 : :
53 : : #include <svx/dialogs.hrc>
54 : : #include <unotools/localedatawrapper.hxx>
55 : : #include <comphelper/processfactory.hxx>
56 : :
57 : : // -----------------------------------------------------------------------
58 : :
59 : : /* [Description]
60 : :
61 : : Function used to create a text representation of
62 : : a metric value
63 : :
64 : : nVal is the metric value in the unit eUnit.
65 : :
66 : : [cross reference]
67 : :
68 : : <SvxPosSizeStatusBarControl::Paint(const UserDrawEvent&)>
69 : : */
70 : :
71 : 1040 : String SvxPosSizeStatusBarControl::GetMetricStr_Impl( long nVal )
72 : : {
73 : : // deliver and set the Metric of the application
74 [ + - ]: 1040 : FieldUnit eOutUnit = SfxModule::GetModuleFieldUnit( getFrameInterface() );
75 : 1040 : FieldUnit eInUnit = FUNIT_100TH_MM;
76 : :
77 : 1040 : String sMetric;
78 [ + - ][ + - ]: 1040 : const sal_Unicode cSep = Application::GetSettings().GetLocaleDataWrapper().getNumDecimalSep()[0];
[ + - ]
79 [ + - ]: 1040 : sal_Int64 nConvVal = MetricField::ConvertValue( nVal * 100, 0L, 0, eInUnit, eOutUnit );
80 : :
81 [ + + ][ + + ]: 1040 : if ( nConvVal < 0 && ( nConvVal / 100 == 0 ) )
82 [ + - ]: 325 : sMetric += '-';
83 [ + - ]: 1040 : sMetric += rtl::OUString::valueOf(nConvVal / 100);
84 : :
85 [ + - ]: 1040 : if( FUNIT_NONE != eOutUnit )
86 : : {
87 [ + - ]: 1040 : sMetric += cSep;
88 : 1040 : sal_Int64 nFract = nConvVal % 100;
89 : :
90 [ + + ]: 1040 : if ( nFract < 0 )
91 : 478 : nFract *= -1;
92 [ + + ]: 1040 : if ( nFract < 10 )
93 [ + - ]: 559 : sMetric += '0';
94 [ + - ]: 1040 : sMetric += rtl::OUString::valueOf(nFract);
95 : : }
96 : :
97 : 1040 : return sMetric;
98 : : }
99 : :
100 : : // -----------------------------------------------------------------------
101 : :
102 [ + - ]: 1258 : SFX_IMPL_STATUSBAR_CONTROL(SvxPosSizeStatusBarControl, SvxSizeItem);
103 : :
104 : : // class FunctionPopup_Impl ----------------------------------------------
105 : :
106 [ # # ]: 0 : class FunctionPopup_Impl : public PopupMenu
107 : : {
108 : : public:
109 : : FunctionPopup_Impl( sal_uInt16 nCheck );
110 : :
111 : 0 : sal_uInt16 GetSelected() const { return nSelected; }
112 : :
113 : : private:
114 : : sal_uInt16 nSelected;
115 : :
116 : : virtual void Select();
117 : : };
118 : :
119 : : // -----------------------------------------------------------------------
120 : :
121 : 0 : FunctionPopup_Impl::FunctionPopup_Impl( sal_uInt16 nCheck ) :
122 : 0 : PopupMenu( ResId( RID_SVXMNU_PSZ_FUNC, DIALOG_MGR() ) ),
123 [ # # ]: 0 : nSelected( 0 )
124 : : {
125 [ # # ]: 0 : if (nCheck)
126 [ # # ]: 0 : CheckItem( nCheck );
127 : 0 : }
128 : :
129 : : // -----------------------------------------------------------------------
130 : :
131 : 0 : void FunctionPopup_Impl::Select()
132 : : {
133 : 0 : nSelected = GetCurItemId();
134 : 0 : }
135 : :
136 : : // struct SvxPosSizeStatusBarControl_Impl --------------------------------
137 : :
138 [ + - ][ + - ]: 2218 : struct SvxPosSizeStatusBarControl_Impl
[ + - ][ + - ]
139 : :
140 : : /* [Description]
141 : :
142 : : This implementation-structure of the class SvxPosSizeStatusBarControl
143 : : is done for the un-linking of the changes of the exported interface such as
144 : : the toning down of symbols that are visible externaly.
145 : :
146 : : One instance exists for each SvxPosSizeStatusBarControl-instance
147 : : during it's life time
148 : : */
149 : :
150 : : {
151 : : Point aPos; // valid when a position is shown
152 : : Size aSize; // valid when a size is shown
153 : : String aStr; // valid when a text is shown
154 : : sal_Bool bPos; // show position ?
155 : : sal_Bool bSize; // set size ?
156 : : sal_Bool bTable; // set table index ?
157 : : sal_Bool bHasMenu; // set StarCalc popup menu ?
158 : : sal_uInt16 nFunction; // the selected StarCalc function
159 : : Image aPosImage; // Image to show the position
160 : : Image aSizeImage; // Image to show the size
161 : : };
162 : :
163 : : // class SvxPosSizeStatusBarControl ------------------------------------------
164 : :
165 : : /* [Description]
166 : :
167 : : Ctor():
168 : : Create an instance of the implementation class,
169 : : load the images for the position and size
170 : : */
171 : :
172 : : #define STR_POSITION ".uno:Position"
173 : : #define STR_TABLECELL ".uno:StateTableCell"
174 : : #define STR_FUNC ".uno:StatusBarFunc"
175 : :
176 : 1109 : SvxPosSizeStatusBarControl::SvxPosSizeStatusBarControl( sal_uInt16 _nSlotId,
177 : : sal_uInt16 _nId,
178 : : StatusBar& rStb ) :
179 : : SfxStatusBarControl( _nSlotId, _nId, rStb ),
180 [ + - ][ + - ]: 1109 : pImp( new SvxPosSizeStatusBarControl_Impl )
181 : : {
182 : 1109 : pImp->bPos = sal_False;
183 : 1109 : pImp->bSize = sal_False;
184 : 1109 : pImp->bTable = sal_False;
185 : 1109 : pImp->bHasMenu = sal_False;
186 : 1109 : pImp->nFunction = 0;
187 [ + - ][ + - ]: 1109 : pImp->aPosImage = Image( ResId( RID_SVXBMP_POSITION, DIALOG_MGR() ) );
[ + - ][ + - ]
188 [ + - ][ + - ]: 1109 : pImp->aSizeImage = Image( ResId( RID_SVXBMP_SIZE, DIALOG_MGR() ) );
[ + - ][ + - ]
189 : :
190 [ + - ][ + - ]: 1109 : addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STR_POSITION ))); // SID_ATTR_POSITION
191 [ + - ][ + - ]: 1109 : addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STR_TABLECELL ))); // SID_TABLE_CELL
192 [ + - ][ + - ]: 1109 : addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STR_FUNC ))); // SID_PSZ_FUNCTION
193 : 1109 : }
194 : :
195 : : // -----------------------------------------------------------------------
196 : :
197 : : /* [Description]
198 : :
199 : : Dtor():
200 : : remove the pointer to the implementation class, so that the timer is stopped
201 : :
202 : : */
203 : :
204 : 1109 : SvxPosSizeStatusBarControl::~SvxPosSizeStatusBarControl()
205 : : {
206 [ + - ][ + - ]: 1109 : delete pImp;
207 [ - + ]: 2218 : }
208 : :
209 : : // -----------------------------------------------------------------------
210 : :
211 : : /* [Description]
212 : :
213 : : SID_PSZ_FUNCTION activates the popup menu for Calc:
214 : :
215 : : Status overview
216 : : Depending on the type of the item, a special setting is enabled, the others disabled.
217 : :
218 : : NULL/Void SfxPointItem SvxSizeItem SfxStringItem
219 : : ------------------------------------------------------------------------
220 : : Position sal_False FALSE
221 : : Size FALSE TRUE FALSE
222 : : Text sal_False sal_False TRUE
223 : :
224 : : */
225 : :
226 : 5244 : void SvxPosSizeStatusBarControl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
227 : : const SfxPoolItem* pState )
228 : : {
229 : : // Because the combi-controller, always sets the curent Id as HelpId
230 : : // first clean the cached HelpText
231 [ + - ][ + - ]: 5244 : GetStatusBar().SetHelpText( GetId(), String() );
[ + - ]
232 : :
233 [ + + + + ]: 5244 : switch ( nSID )
234 : : {
235 [ + - ]: 1730 : case SID_ATTR_POSITION : GetStatusBar().SetHelpId( GetId(), STR_POSITION ); break;
236 [ + - ]: 1517 : case SID_TABLE_CELL: GetStatusBar().SetHelpId( GetId(), STR_TABLECELL ); break;
237 [ + - ]: 274 : case SID_PSZ_FUNCTION: GetStatusBar().SetHelpId( GetId(), STR_FUNC ); break;
238 : 1723 : default: break;
239 : : }
240 : :
241 [ + + ]: 5244 : if ( nSID == SID_PSZ_FUNCTION )
242 : : {
243 [ + + ]: 274 : if ( eState == SFX_ITEM_AVAILABLE )
244 : : {
245 : 55 : pImp->bHasMenu = sal_True;
246 [ + - ][ + - ]: 55 : if ( pState && pState->ISA(SfxUInt16Item) )
[ + - ][ + - ]
[ + - ]
247 : 55 : pImp->nFunction = ((const SfxUInt16Item*)pState)->GetValue();
248 : : }
249 : : else
250 : 219 : pImp->bHasMenu = sal_False;
251 : : }
252 [ + + ]: 4970 : else if ( SFX_ITEM_AVAILABLE != eState )
253 : : {
254 : : // don't switch to empty display before an empty state was
255 : : // notified for all display types
256 : :
257 [ + + ]: 4325 : if ( nSID == SID_TABLE_CELL )
258 : 1293 : pImp->bTable = sal_False;
259 [ + + ]: 3032 : else if ( nSID == SID_ATTR_POSITION )
260 : 1516 : pImp->bPos = sal_False;
261 [ + - ]: 1516 : else if ( nSID == GetSlotId() ) // controller is registered for SID_ATTR_SIZE
262 : 1516 : pImp->bSize = sal_False;
263 : : else
264 : : {
265 : : SAL_WARN( "svx.stbcrtls","unknown slot id");
266 : : }
267 : : }
268 [ + - ][ + - ]: 645 : else if ( pState->ISA( SfxPointItem ) )
[ + + ]
269 : : {
270 : : // show position
271 : 214 : pImp->aPos = ( (SfxPointItem*)pState )->GetValue();
272 : 214 : pImp->bPos = sal_True;
273 : 214 : pImp->bTable = sal_False;
274 : : }
275 [ + - ][ + - ]: 431 : else if ( pState->ISA( SvxSizeItem ) )
[ + + ]
276 : : {
277 : : // show size
278 : 207 : pImp->aSize = ( (SvxSizeItem*)pState )->GetSize();
279 : 207 : pImp->bSize = sal_True;
280 : 207 : pImp->bTable = sal_False;
281 : : }
282 [ + - ][ + - ]: 224 : else if ( pState->ISA( SfxStringItem ) )
[ + - ]
283 : : {
284 : : // show string (table cel or different)
285 [ + - ]: 224 : pImp->aStr = ( (SfxStringItem*)pState )->GetValue();
286 : 224 : pImp->bTable = sal_True;
287 : 224 : pImp->bPos = sal_False;
288 : 224 : pImp->bSize = sal_False;
289 : : }
290 : : else
291 : : {
292 : : SAL_WARN( "svx.stbcrtls", "invalid item type" );
293 : 0 : pImp->bPos = sal_False;
294 : 0 : pImp->bSize = sal_False;
295 : 0 : pImp->bTable = sal_False;
296 : : }
297 : :
298 [ + - ]: 5244 : if ( GetStatusBar().AreItemsVisible() )
299 [ + - ]: 5244 : GetStatusBar().SetItemData( GetId(), 0 );
300 : :
301 : : // set only strings as text at the statusBar, so that the Help-Tips
302 : : // can work with the text, when it is too long for the statusBar
303 [ + - ]: 5244 : String aText;
304 [ + + ]: 5244 : if ( pImp->bTable )
305 [ + - ]: 537 : aText = pImp->aStr;
306 [ + - ][ + - ]: 5244 : GetStatusBar().SetItemText( GetId(), aText );
307 : 5244 : }
308 : :
309 : : // -----------------------------------------------------------------------
310 : :
311 : : /* [Description]
312 : :
313 : : execute popup menu, when the status enables this
314 : : */
315 : :
316 : 0 : void SvxPosSizeStatusBarControl::Command( const CommandEvent& rCEvt )
317 : : {
318 [ # # ][ # # ]: 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && pImp->bHasMenu )
[ # # ]
319 : : {
320 : 0 : sal_uInt16 nSelect = pImp->nFunction;
321 [ # # ]: 0 : if (!nSelect)
322 : 0 : nSelect = PSZ_FUNC_NONE;
323 [ # # ]: 0 : FunctionPopup_Impl aMenu( nSelect );
324 [ # # ][ # # ]: 0 : if ( aMenu.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel() ) )
325 : : {
326 : 0 : nSelect = aMenu.GetSelected();
327 [ # # ]: 0 : if (nSelect)
328 : : {
329 [ # # ]: 0 : if (nSelect == PSZ_FUNC_NONE)
330 : 0 : nSelect = 0;
331 : :
332 : 0 : ::com::sun::star::uno::Any a;
333 [ # # ]: 0 : SfxUInt16Item aItem( SID_PSZ_FUNCTION, nSelect );
334 : :
335 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
336 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusBarFunc" ));
337 [ # # ]: 0 : aItem.QueryValue( a );
338 [ # # ]: 0 : aArgs[0].Value = a;
339 : :
340 [ # # ][ # # ]: 0 : execute( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StatusBarFunc" )), aArgs );
[ # # ][ # # ]
341 : : // GetBindings().GetDispatcher()->Execute( SID_PSZ_FUNCTION, SFX_CALLMODE_RECORD, &aItem, 0L );
342 : : }
343 [ # # ]: 0 : }
344 : : }
345 : : else
346 : 0 : SfxStatusBarControl::Command( rCEvt );
347 : 0 : }
348 : :
349 : : // -----------------------------------------------------------------------
350 : :
351 : : /* [Description]
352 : :
353 : : Depending on the type to be shown, the value us shown. First the
354 : : rectangle is repainted (removed).
355 : : */
356 : :
357 : 3835 : void SvxPosSizeStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
358 : : {
359 : 3835 : OutputDevice* pDev = rUsrEvt.GetDevice();
360 : : DBG_ASSERT( pDev, "no OutputDevice on UserDrawEvent" );
361 : 3835 : const Rectangle& rRect = rUsrEvt.GetRect();
362 : 3835 : StatusBar& rBar = GetStatusBar();
363 [ + - ]: 3835 : Point aItemPos = rBar.GetItemTextPos( GetId() );
364 : 3835 : Color aOldLineColor = pDev->GetLineColor();
365 : 3835 : Color aOldFillColor = pDev->GetFillColor();
366 [ + - ]: 3835 : pDev->SetLineColor();
367 [ + - ][ + - ]: 3835 : pDev->SetFillColor( pDev->GetBackground().GetColor() );
368 : :
369 [ + + ][ - + ]: 3835 : if ( pImp->bPos || pImp->bSize )
370 : : {
371 : : // count the position for showing the size
372 : : long nSizePosX =
373 [ + - ]: 260 : rRect.Left() + rRect.GetWidth() / 2 + PAINT_OFFSET;
374 : : // draw position
375 : 260 : Point aPnt = rRect.TopLeft();
376 : 260 : aPnt.Y() = aItemPos.Y();
377 : 260 : aPnt.X() += PAINT_OFFSET;
378 [ + - ]: 260 : pDev->DrawImage( aPnt, pImp->aPosImage );
379 [ + - ]: 260 : aPnt.X() += pImp->aPosImage.GetSizePixel().Width();
380 : 260 : aPnt.X() += PAINT_OFFSET;
381 [ + - ]: 260 : String aStr = GetMetricStr_Impl( pImp->aPos.X());
382 [ + - ]: 260 : aStr.AppendAscii(" / ");
383 [ + - ][ + - ]: 260 : aStr += GetMetricStr_Impl( pImp->aPos.Y());
[ + - ]
384 : : pDev->DrawRect(
385 [ + - ][ + - ]: 260 : Rectangle( aPnt, Point( nSizePosX, rRect.Bottom() ) ) );
386 [ + - ]: 260 : pDev->DrawText( aPnt, aStr );
387 : :
388 : : // draw the size, when available
389 : 260 : aPnt.X() = nSizePosX;
390 : :
391 [ + - ]: 260 : if ( pImp->bSize )
392 : : {
393 [ + - ]: 260 : pDev->DrawImage( aPnt, pImp->aSizeImage );
394 [ + - ]: 260 : aPnt.X() += pImp->aSizeImage.GetSizePixel().Width();
395 : 260 : Point aDrwPnt = aPnt;
396 : 260 : aPnt.X() += PAINT_OFFSET;
397 [ + - ][ + - ]: 260 : aStr = GetMetricStr_Impl( pImp->aSize.Width() );
[ + - ]
398 [ + - ]: 260 : aStr.AppendAscii(" x ");
399 [ + - ][ + - ]: 260 : aStr += GetMetricStr_Impl( pImp->aSize.Height() );
[ + - ]
400 [ + - ][ + - ]: 260 : pDev->DrawRect( Rectangle( aDrwPnt, rRect.BottomRight() ) );
[ + - ]
401 [ + - ]: 260 : pDev->DrawText( aPnt, aStr );
402 : : }
403 : : else
404 [ # # ][ # # ]: 260 : pDev->DrawRect( Rectangle( aPnt, rRect.BottomRight() ) );
[ # # ][ + - ]
405 : : }
406 [ + + ]: 3575 : else if ( pImp->bTable )
407 : : {
408 [ + - ]: 413 : pDev->DrawRect( rRect );
409 : : pDev->DrawText( Point(
410 [ + - ][ + - ]: 413 : rRect.Left() + rRect.GetWidth() / 2 - pDev->GetTextWidth( pImp->aStr ) / 2,
411 [ + - ]: 826 : aItemPos.Y() ), pImp->aStr );
412 : : }
413 : : else
414 : : {
415 : : // Empty display if neither size nor table position are available.
416 : : // Date/Time are no longer used (#65302#).
417 [ + - ]: 3162 : pDev->DrawRect( rRect );
418 : : }
419 : :
420 [ + - ]: 3835 : pDev->SetLineColor( aOldLineColor );
421 [ + - ]: 3835 : pDev->SetFillColor( aOldFillColor );
422 : 3835 : }
423 : :
424 : :
425 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|