1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
33 #include <tools/shl.hxx>
34 #include <vcl/status.hxx>
35 #include <vcl/menu.hxx>
36 #include <vcl/image.hxx>
37 #include <svl/stritem.hxx>
38 #include <svl/ptitem.hxx>
39 #include <svl/itempool.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/module.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <svl/intitem.hxx>
45 #define _SVX_PSZCTRL_CXX
47 #include "svx/pszctrl.hxx"
49 #define PAINT_OFFSET 5
51 #include <editeng/sizeitem.hxx>
52 #include <svx/dialmgr.hxx>
53 #include "svx/dlgutil.hxx"
55 #include "sfx2/module.hxx"
57 #include <svx/dialogs.hrc>
58 #include <unotools/localedatawrapper.hxx>
59 #include <comphelper/processfactory.hxx>
61 // -----------------------------------------------------------------------
65 Function used to create a text representation of
68 nVal is the metric value in the unit eUnit.
72 <SvxPosSizeStatusBarControl::Paint(const UserDrawEvent&)>
75 String
SvxPosSizeStatusBarControl::GetMetricStr_Impl( long nVal
)
77 // deliver and set the Metric of the application
78 FieldUnit eOutUnit
= SfxModule::GetModuleFieldUnit( getFrameInterface() );
79 FieldUnit eInUnit
= FUNIT_100TH_MM
;
82 const sal_Unicode cSep
= Application::GetSettings().GetLocaleDataWrapper().getNumDecimalSep().GetChar(0);
83 sal_Int64 nConvVal
= MetricField::ConvertValue( nVal
* 100, 0L, 0, eInUnit
, eOutUnit
);
85 if ( nConvVal
< 0 && ( nConvVal
/ 100 == 0 ) )
87 sMetric
+= rtl::OUString::valueOf(nConvVal
/ 100);
89 if( FUNIT_NONE
!= eOutUnit
)
92 sal_Int64 nFract
= nConvVal
% 100;
98 sMetric
+= rtl::OUString::valueOf(nFract
);
104 // -----------------------------------------------------------------------
106 SFX_IMPL_STATUSBAR_CONTROL(SvxPosSizeStatusBarControl
, SvxSizeItem
);
108 // class FunctionPopup_Impl ----------------------------------------------
110 class FunctionPopup_Impl
: public PopupMenu
113 FunctionPopup_Impl( sal_uInt16 nCheck
);
115 sal_uInt16
GetSelected() const { return nSelected
; }
118 sal_uInt16 nSelected
;
120 virtual void Select();
123 // -----------------------------------------------------------------------
125 FunctionPopup_Impl::FunctionPopup_Impl( sal_uInt16 nCheck
) :
126 PopupMenu( ResId( RID_SVXMNU_PSZ_FUNC
, DIALOG_MGR() ) ),
133 // -----------------------------------------------------------------------
135 void FunctionPopup_Impl::Select()
137 nSelected
= GetCurItemId();
140 // struct SvxPosSizeStatusBarControl_Impl --------------------------------
142 struct SvxPosSizeStatusBarControl_Impl
146 This implementation-structure of the class SvxPosSizeStatusBarControl
147 is done for the un-linking of the changes of the exported interface such as
148 the toning down of symbols that are visible externaly.
150 One instance exists for each SvxPosSizeStatusBarControl-instance
151 during it's life time
155 Point aPos
; // valid when a position is shown
156 Size aSize
; // valid when a size is shown
157 String aStr
; // valid when a text is shown
158 sal_Bool bPos
; // show position ?
159 sal_Bool bSize
; // set size ?
160 sal_Bool bTable
; // set table index ?
161 sal_Bool bHasMenu
; // set StarCalc popup menu ?
162 sal_uInt16 nFunction
; // the selected StarCalc function
163 Image aPosImage
; // Image to show the position
164 Image aSizeImage
; // Image to show the size
167 // class SvxPosSizeStatusBarControl ------------------------------------------
172 Create an instance of the implementation class,
173 load the images for the position and size
176 #define STR_POSITION ".uno:Position"
177 #define STR_TABLECELL ".uno:StateTableCell"
178 #define STR_FUNC ".uno:StatusBarFunc"
180 SvxPosSizeStatusBarControl::SvxPosSizeStatusBarControl( sal_uInt16 _nSlotId
,
183 SfxStatusBarControl( _nSlotId
, _nId
, rStb
),
184 pImp( new SvxPosSizeStatusBarControl_Impl
)
186 pImp
->bPos
= sal_False
;
187 pImp
->bSize
= sal_False
;
188 pImp
->bTable
= sal_False
;
189 pImp
->bHasMenu
= sal_False
;
191 pImp
->aPosImage
= Image( ResId( RID_SVXBMP_POSITION
, DIALOG_MGR() ) );
192 pImp
->aSizeImage
= Image( ResId( RID_SVXBMP_SIZE
, DIALOG_MGR() ) );
194 addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STR_POSITION
))); // SID_ATTR_POSITION
195 addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STR_TABLECELL
))); // SID_TABLE_CELL
196 addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STR_FUNC
))); // SID_PSZ_FUNCTION
199 // -----------------------------------------------------------------------
204 remove the pointer to the implementation class, so that the timer is stopped
208 SvxPosSizeStatusBarControl::~SvxPosSizeStatusBarControl()
213 // -----------------------------------------------------------------------
217 SID_PSZ_FUNCTION activates the popup menu for Calc:
220 Depending on the type of the item, a special setting is enabled, the others disabled.
222 NULL/Void SfxPointItem SvxSizeItem SfxStringItem
223 ------------------------------------------------------------------------
224 Position sal_False FALSE
225 Size FALSE TRUE FALSE
226 Text sal_False sal_False TRUE
230 void SvxPosSizeStatusBarControl::StateChanged( sal_uInt16 nSID
, SfxItemState eState
,
231 const SfxPoolItem
* pState
)
233 // Because the combi-controller, always sets the curent Id as HelpId
234 // first clean the cached HelpText
235 GetStatusBar().SetHelpText( GetId(), String() );
239 case SID_ATTR_POSITION
: GetStatusBar().SetHelpId( GetId(), STR_POSITION
); break;
240 case SID_TABLE_CELL
: GetStatusBar().SetHelpId( GetId(), STR_TABLECELL
); break;
241 case SID_PSZ_FUNCTION
: GetStatusBar().SetHelpId( GetId(), STR_FUNC
); break;
245 if ( nSID
== SID_PSZ_FUNCTION
)
247 if ( eState
== SFX_ITEM_AVAILABLE
)
249 pImp
->bHasMenu
= sal_True
;
250 if ( pState
&& pState
->ISA(SfxUInt16Item
) )
251 pImp
->nFunction
= ((const SfxUInt16Item
*)pState
)->GetValue();
254 pImp
->bHasMenu
= sal_False
;
256 else if ( SFX_ITEM_AVAILABLE
!= eState
)
258 // don't switch to empty display before an empty state was
259 // notified for all display types
261 if ( nSID
== SID_TABLE_CELL
)
262 pImp
->bTable
= sal_False
;
263 else if ( nSID
== SID_ATTR_POSITION
)
264 pImp
->bPos
= sal_False
;
265 else if ( nSID
== GetSlotId() ) // controller is registered for SID_ATTR_SIZE
266 pImp
->bSize
= sal_False
;
269 SAL_WARN( "svx.stbcrtls","unknown slot id");
272 else if ( pState
->ISA( SfxPointItem
) )
275 pImp
->aPos
= ( (SfxPointItem
*)pState
)->GetValue();
276 pImp
->bPos
= sal_True
;
277 pImp
->bTable
= sal_False
;
279 else if ( pState
->ISA( SvxSizeItem
) )
282 pImp
->aSize
= ( (SvxSizeItem
*)pState
)->GetSize();
283 pImp
->bSize
= sal_True
;
284 pImp
->bTable
= sal_False
;
286 else if ( pState
->ISA( SfxStringItem
) )
288 // show string (table cel or different)
289 pImp
->aStr
= ( (SfxStringItem
*)pState
)->GetValue();
290 pImp
->bTable
= sal_True
;
291 pImp
->bPos
= sal_False
;
292 pImp
->bSize
= sal_False
;
296 SAL_WARN( "svx.stbcrtls", "invalid item type" );
297 pImp
->bPos
= sal_False
;
298 pImp
->bSize
= sal_False
;
299 pImp
->bTable
= sal_False
;
302 if ( GetStatusBar().AreItemsVisible() )
303 GetStatusBar().SetItemData( GetId(), 0 );
305 // set only strings as text at the statusBar, so that the Help-Tips
306 // can work with the text, when it is too long for the statusBar
310 GetStatusBar().SetItemText( GetId(), aText
);
313 // -----------------------------------------------------------------------
317 execute popup menu, when the status enables this
320 void SvxPosSizeStatusBarControl::Command( const CommandEvent
& rCEvt
)
322 if ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
&& pImp
->bHasMenu
)
324 sal_uInt16 nSelect
= pImp
->nFunction
;
326 nSelect
= PSZ_FUNC_NONE
;
327 FunctionPopup_Impl
aMenu( nSelect
);
328 if ( aMenu
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel() ) )
330 nSelect
= aMenu
.GetSelected();
333 if (nSelect
== PSZ_FUNC_NONE
)
336 ::com::sun::star::uno::Any a
;
337 SfxUInt16Item
aItem( SID_PSZ_FUNCTION
, nSelect
);
339 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs( 1 );
340 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusBarFunc" ));
341 aItem
.QueryValue( a
);
344 execute( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StatusBarFunc" )), aArgs
);
345 // GetBindings().GetDispatcher()->Execute( SID_PSZ_FUNCTION, SFX_CALLMODE_RECORD, &aItem, 0L );
350 SfxStatusBarControl::Command( rCEvt
);
353 // -----------------------------------------------------------------------
357 Depending on the type to be shown, the value us shown. First the
358 rectangle is repainted (removed).
361 void SvxPosSizeStatusBarControl::Paint( const UserDrawEvent
& rUsrEvt
)
363 OutputDevice
* pDev
= rUsrEvt
.GetDevice();
364 DBG_ASSERT( pDev
, "no OutputDevice on UserDrawEvent" );
365 const Rectangle
& rRect
= rUsrEvt
.GetRect();
366 StatusBar
& rBar
= GetStatusBar();
367 Point aItemPos
= rBar
.GetItemTextPos( GetId() );
368 Color aOldLineColor
= pDev
->GetLineColor();
369 Color aOldFillColor
= pDev
->GetFillColor();
370 pDev
->SetLineColor();
371 pDev
->SetFillColor( pDev
->GetBackground().GetColor() );
373 if ( pImp
->bPos
|| pImp
->bSize
)
375 // count the position for showing the size
377 rRect
.Left() + rRect
.GetWidth() / 2 + PAINT_OFFSET
;
379 Point aPnt
= rRect
.TopLeft();
380 aPnt
.Y() = aItemPos
.Y();
381 aPnt
.X() += PAINT_OFFSET
;
382 pDev
->DrawImage( aPnt
, pImp
->aPosImage
);
383 aPnt
.X() += pImp
->aPosImage
.GetSizePixel().Width();
384 aPnt
.X() += PAINT_OFFSET
;
385 String aStr
= GetMetricStr_Impl( pImp
->aPos
.X());
386 aStr
.AppendAscii(" / ");
387 aStr
+= GetMetricStr_Impl( pImp
->aPos
.Y());
389 Rectangle( aPnt
, Point( nSizePosX
, rRect
.Bottom() ) ) );
390 pDev
->DrawText( aPnt
, aStr
);
392 // draw the size, when available
393 aPnt
.X() = nSizePosX
;
397 pDev
->DrawImage( aPnt
, pImp
->aSizeImage
);
398 aPnt
.X() += pImp
->aSizeImage
.GetSizePixel().Width();
399 Point aDrwPnt
= aPnt
;
400 aPnt
.X() += PAINT_OFFSET
;
401 aStr
= GetMetricStr_Impl( pImp
->aSize
.Width() );
402 aStr
.AppendAscii(" x ");
403 aStr
+= GetMetricStr_Impl( pImp
->aSize
.Height() );
404 pDev
->DrawRect( Rectangle( aDrwPnt
, rRect
.BottomRight() ) );
405 pDev
->DrawText( aPnt
, aStr
);
408 pDev
->DrawRect( Rectangle( aPnt
, rRect
.BottomRight() ) );
410 else if ( pImp
->bTable
)
412 pDev
->DrawRect( rRect
);
413 pDev
->DrawText( Point(
414 rRect
.Left() + rRect
.GetWidth() / 2 - pDev
->GetTextWidth( pImp
->aStr
) / 2,
415 aItemPos
.Y() ), pImp
->aStr
);
419 // Empty display if neither size nor table position are available.
420 // Date/Time are no longer used (#65302#).
421 pDev
->DrawRect( rRect
);
424 pDev
->SetLineColor( aOldLineColor
);
425 pDev
->SetFillColor( aOldFillColor
);
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */