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 : :
30 : : #include <stdio.h>
31 : : #include <wchar.h>
32 : :
33 : : #include "uielement/spinfieldtoolbarcontroller.hxx"
34 : :
35 : : #include "uielement/toolbar.hxx"
36 : :
37 : : #include <com/sun/star/util/XURLTransformer.hpp>
38 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
39 : : #include <com/sun/star/beans/PropertyValue.hpp>
40 : : #include <com/sun/star/frame/status/ItemStatus.hpp>
41 : : #include <com/sun/star/frame/status/ItemState.hpp>
42 : : #include <com/sun/star/frame/status/Visibility.hpp>
43 : : #include <com/sun/star/frame/XControlNotificationListener.hpp>
44 : :
45 : : #include <svtools/toolboxcontroller.hxx>
46 : : #include <osl/mutex.hxx>
47 : : #include <vcl/svapp.hxx>
48 : : #include <vcl/mnemonic.hxx>
49 : : #ifdef WINNT
50 : : #include <systools/win32/snprintf.h>
51 : : #endif
52 : :
53 : : using namespace ::com::sun::star;
54 : : using namespace ::com::sun::star::uno;
55 : : using namespace ::com::sun::star::beans;
56 : : using namespace ::com::sun::star::lang;
57 : : using namespace ::com::sun::star::frame;
58 : : using namespace ::com::sun::star::frame::status;
59 : : using namespace ::com::sun::star::util;
60 : :
61 : : namespace framework
62 : : {
63 : :
64 : : // ------------------------------------------------------------------
65 : :
66 : : // Wrapper class to notify controller about events from combobox.
67 : : // Unfortunaltly the events are notifed through virtual methods instead
68 : : // of Listeners.
69 : :
70 : : class SpinfieldControl : public SpinField
71 : : {
72 : : public:
73 : : SpinfieldControl( Window* pParent, WinBits nStyle, ISpinfieldListener* pSpinFieldListener );
74 : : virtual ~SpinfieldControl();
75 : :
76 : : virtual void Up();
77 : : virtual void Down();
78 : : virtual void First();
79 : : virtual void Last();
80 : : virtual void KeyInput( const ::KeyEvent& rKEvt );
81 : : virtual void Modify();
82 : : virtual void GetFocus();
83 : : virtual void LoseFocus();
84 : : virtual void StateChanged( StateChangedType nType );
85 : : virtual void DataChanged( const DataChangedEvent& rDCEvt );
86 : : virtual long PreNotify( NotifyEvent& rNEvt );
87 : :
88 : : private:
89 : : ISpinfieldListener* m_pSpinFieldListener;
90 : : };
91 : :
92 : 0 : SpinfieldControl::SpinfieldControl( Window* pParent, WinBits nStyle, ISpinfieldListener* pSpinFieldListener ) :
93 : : SpinField( pParent, nStyle )
94 : 0 : , m_pSpinFieldListener( pSpinFieldListener )
95 : : {
96 : 0 : }
97 : :
98 : 0 : SpinfieldControl::~SpinfieldControl()
99 : : {
100 : 0 : m_pSpinFieldListener = 0;
101 [ # # ]: 0 : }
102 : :
103 : 0 : void SpinfieldControl::Up()
104 : : {
105 : 0 : SpinField::Up();
106 [ # # ]: 0 : if ( m_pSpinFieldListener )
107 : 0 : m_pSpinFieldListener->Up();
108 : 0 : }
109 : :
110 : 0 : void SpinfieldControl::Down()
111 : : {
112 : 0 : SpinField::Down();
113 [ # # ]: 0 : if ( m_pSpinFieldListener )
114 : 0 : m_pSpinFieldListener->Down();
115 : 0 : }
116 : :
117 : 0 : void SpinfieldControl::First()
118 : : {
119 : 0 : SpinField::First();
120 [ # # ]: 0 : if ( m_pSpinFieldListener )
121 : 0 : m_pSpinFieldListener->First();
122 : 0 : }
123 : :
124 : 0 : void SpinfieldControl::Last()
125 : : {
126 : 0 : SpinField::First();
127 [ # # ]: 0 : if ( m_pSpinFieldListener )
128 : 0 : m_pSpinFieldListener->Last();
129 : 0 : }
130 : :
131 : 0 : void SpinfieldControl::KeyInput( const ::KeyEvent& rKEvt )
132 : : {
133 : 0 : SpinField::KeyInput( rKEvt );
134 [ # # ]: 0 : if ( m_pSpinFieldListener )
135 : 0 : m_pSpinFieldListener->KeyInput( rKEvt );
136 : 0 : }
137 : :
138 : 0 : void SpinfieldControl::Modify()
139 : : {
140 : 0 : SpinField::Modify();
141 [ # # ]: 0 : if ( m_pSpinFieldListener )
142 : 0 : m_pSpinFieldListener->Modify();
143 : 0 : }
144 : :
145 : 0 : void SpinfieldControl::GetFocus()
146 : : {
147 : 0 : SpinField::GetFocus();
148 [ # # ]: 0 : if ( m_pSpinFieldListener )
149 : 0 : m_pSpinFieldListener->GetFocus();
150 : 0 : }
151 : :
152 : 0 : void SpinfieldControl::LoseFocus()
153 : : {
154 : 0 : SpinField::GetFocus();
155 [ # # ]: 0 : if ( m_pSpinFieldListener )
156 : 0 : m_pSpinFieldListener->GetFocus();
157 : 0 : }
158 : :
159 : 0 : void SpinfieldControl::StateChanged( StateChangedType nType )
160 : : {
161 : 0 : SpinField::StateChanged( nType );
162 [ # # ]: 0 : if ( m_pSpinFieldListener )
163 : 0 : m_pSpinFieldListener->StateChanged( nType );
164 : 0 : }
165 : :
166 : 0 : void SpinfieldControl::DataChanged( const DataChangedEvent& rDCEvt )
167 : : {
168 : 0 : SpinField::DataChanged( rDCEvt );
169 [ # # ]: 0 : if ( m_pSpinFieldListener )
170 : 0 : m_pSpinFieldListener->DataChanged( rDCEvt );
171 : 0 : }
172 : :
173 : 0 : long SpinfieldControl::PreNotify( NotifyEvent& rNEvt )
174 : : {
175 : 0 : long nRet( 0 );
176 [ # # ]: 0 : if ( m_pSpinFieldListener )
177 : 0 : nRet = m_pSpinFieldListener->PreNotify( rNEvt );
178 [ # # ]: 0 : if ( nRet == 0 )
179 : 0 : nRet = SpinField::PreNotify( rNEvt );
180 : :
181 : 0 : return nRet;
182 : : }
183 : :
184 : : // ------------------------------------------------------------------
185 : :
186 : 0 : SpinfieldToolbarController::SpinfieldToolbarController(
187 : : const Reference< XMultiServiceFactory >& rServiceManager,
188 : : const Reference< XFrame >& rFrame,
189 : : ToolBox* pToolbar,
190 : : sal_uInt16 nID,
191 : : sal_Int32 nWidth,
192 : : const ::rtl::OUString& aCommand ) :
193 : : ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
194 : : , m_bFloat( false )
195 : : , m_bMaxSet( false )
196 : : , m_bMinSet( false )
197 : : , m_nMax( 0.0 )
198 : : , m_nMin( 0.0 )
199 : : , m_nValue( 0.0 )
200 : : , m_nStep( 0.0 )
201 [ # # ]: 0 : , m_pSpinfieldControl( 0 )
202 : : {
203 [ # # ][ # # ]: 0 : m_pSpinfieldControl = new SpinfieldControl( m_pToolbar, WB_SPIN|WB_BORDER, this );
204 [ # # ]: 0 : if ( nWidth == 0 )
205 : 0 : nWidth = 100;
206 : :
207 : : // Calculate height of the spin field according to the application font height
208 [ # # ]: 0 : sal_Int32 nHeight = getFontSizePixel( m_pSpinfieldControl ) + 5 + 1;
209 : :
210 [ # # ]: 0 : m_pSpinfieldControl->SetSizePixel( ::Size( nWidth, nHeight ));
211 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, m_pSpinfieldControl );
212 : 0 : }
213 : :
214 : : // ------------------------------------------------------------------
215 : :
216 [ # # ]: 0 : SpinfieldToolbarController::~SpinfieldToolbarController()
217 : : {
218 [ # # ]: 0 : }
219 : :
220 : : // ------------------------------------------------------------------
221 : :
222 : 0 : void SAL_CALL SpinfieldToolbarController::dispose()
223 : : throw ( RuntimeException )
224 : : {
225 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
226 : :
227 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, 0 );
228 [ # # ][ # # ]: 0 : delete m_pSpinfieldControl;
229 : :
230 [ # # ]: 0 : ComplexToolbarController::dispose();
231 : :
232 [ # # ]: 0 : m_pSpinfieldControl = 0;
233 : 0 : }
234 : :
235 : : // ------------------------------------------------------------------
236 : 0 : Sequence<PropertyValue> SpinfieldToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
237 : : {
238 [ # # ]: 0 : Sequence<PropertyValue> aArgs( 2 );
239 [ # # ][ # # ]: 0 : ::rtl::OUString aSpinfieldText = m_pSpinfieldControl->GetText();
[ # # ]
240 : :
241 : : // Add key modifier to argument list
242 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
243 [ # # ][ # # ]: 0 : aArgs[0].Value <<= KeyModifier;
244 [ # # ][ # # ]: 0 : aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Value" ));
245 [ # # ]: 0 : if ( m_bFloat )
246 [ # # ][ # # ]: 0 : aArgs[1].Value <<= aSpinfieldText.toDouble();
247 : : else
248 [ # # ][ # # ]: 0 : aArgs[1].Value <<= aSpinfieldText.toInt32();
249 : 0 : return aArgs;
250 : : }
251 : :
252 : : // ------------------------------------------------------------------
253 : :
254 : 0 : void SpinfieldToolbarController::Up()
255 : : {
256 : 0 : double nValue = m_nValue + m_nStep;
257 [ # # ][ # # ]: 0 : if ( m_bMaxSet && nValue > m_nMax )
258 : 0 : return;
259 : :
260 : 0 : m_nValue = nValue;
261 : :
262 [ # # ]: 0 : rtl::OUString aText = impl_formatOutputString( m_nValue );
263 [ # # ][ # # ]: 0 : m_pSpinfieldControl->SetText( aText );
[ # # ]
264 [ # # ]: 0 : execute( 0 );
265 : : }
266 : :
267 : 0 : void SpinfieldToolbarController::Down()
268 : : {
269 : 0 : double nValue = m_nValue - m_nStep;
270 [ # # ][ # # ]: 0 : if ( m_bMinSet && nValue < m_nMin )
271 : 0 : return;
272 : :
273 : 0 : m_nValue = nValue;
274 : :
275 [ # # ]: 0 : rtl::OUString aText = impl_formatOutputString( m_nValue );
276 [ # # ][ # # ]: 0 : m_pSpinfieldControl->SetText( aText );
[ # # ]
277 [ # # ]: 0 : execute( 0 );
278 : : }
279 : :
280 : 0 : void SpinfieldToolbarController::First()
281 : : {
282 [ # # ]: 0 : if ( m_bMinSet )
283 : : {
284 : 0 : m_nValue = m_nMin;
285 : :
286 [ # # ]: 0 : rtl::OUString aText = impl_formatOutputString( m_nValue );
287 [ # # ][ # # ]: 0 : m_pSpinfieldControl->SetText( aText );
[ # # ]
288 [ # # ]: 0 : execute( 0 );
289 : : }
290 : 0 : }
291 : :
292 : 0 : void SpinfieldToolbarController::Last()
293 : : {
294 [ # # ]: 0 : if ( m_bMaxSet )
295 : : {
296 : 0 : m_nValue = m_nMax;
297 : :
298 [ # # ]: 0 : rtl::OUString aText = impl_formatOutputString( m_nValue );
299 [ # # ][ # # ]: 0 : m_pSpinfieldControl->SetText( aText );
[ # # ]
300 [ # # ]: 0 : execute( 0 );
301 : : }
302 : 0 : }
303 : :
304 : 0 : void SpinfieldToolbarController::Modify()
305 : : {
306 [ # # ][ # # ]: 0 : notifyTextChanged( m_pSpinfieldControl->GetText() );
307 : 0 : }
308 : :
309 : 0 : void SpinfieldToolbarController::KeyInput( const ::KeyEvent& /*rKEvt*/ )
310 : : {
311 : 0 : }
312 : :
313 : 0 : void SpinfieldToolbarController::GetFocus()
314 : : {
315 : 0 : notifyFocusGet();
316 : 0 : }
317 : :
318 : 0 : void SpinfieldToolbarController::LoseFocus()
319 : : {
320 : 0 : notifyFocusLost();
321 : 0 : }
322 : :
323 : 0 : void SpinfieldToolbarController::StateChanged( StateChangedType /*nType*/ )
324 : : {
325 : 0 : }
326 : :
327 : 0 : void SpinfieldToolbarController::DataChanged( const DataChangedEvent& /*rDCEvt*/ )
328 : : {
329 : 0 : }
330 : :
331 : 0 : long SpinfieldToolbarController::PreNotify( NotifyEvent& rNEvt )
332 : : {
333 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
334 : : {
335 : 0 : const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
336 : 0 : const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
337 [ # # ]: 0 : if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
338 : : {
339 : : // Call execute only with non-empty text
340 [ # # ]: 0 : if ( m_pSpinfieldControl->GetText().Len() > 0 )
341 : 0 : execute( rKeyCode.GetModifier() );
342 : 0 : return 1;
343 : : }
344 : : }
345 : :
346 : 0 : return 0;
347 : : }
348 : :
349 : : // --------------------------------------------------------
350 : :
351 : 0 : void SpinfieldToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
352 : : {
353 : 0 : rtl::OUString aValue;
354 : 0 : rtl::OUString aMax;
355 : 0 : rtl::OUString aMin;
356 : 0 : rtl::OUString aStep;
357 : 0 : bool bFloatValue( false );
358 : :
359 [ # # ]: 0 : if ( rControlCommand.Command.equalsAsciiL( "SetStep", 7 ))
360 : : {
361 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
362 : : {
363 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Step", 4 ))
364 : : {
365 : : sal_Int32 nValue;
366 : : double fValue;
367 : 0 : bool bFloat( false );
368 [ # # ]: 0 : if ( impl_getValue( rControlCommand.Arguments[i].Value, nValue, fValue, bFloat ))
369 : : aStep = bFloat ? ::rtl::OUString::valueOf( fValue ) :
370 [ # # ]: 0 : ::rtl::OUString::valueOf( nValue );
371 : : break;
372 : : }
373 : : }
374 : : }
375 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetValue", 8 ))
376 : : {
377 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
378 : : {
379 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Value", 5 ))
380 : : {
381 : : sal_Int32 nValue;
382 : : double fValue;
383 : 0 : bool bFloat( false );
384 : :
385 [ # # ]: 0 : if ( impl_getValue( rControlCommand.Arguments[i].Value, nValue, fValue, bFloat ))
386 : : {
387 [ # # ]: 0 : aValue = bFloat ? ::rtl::OUString::valueOf( fValue ) : ::rtl::OUString::valueOf( nValue );
388 : 0 : bFloatValue = bFloat;
389 : : }
390 : : break;
391 : : }
392 : : }
393 : : }
394 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetValues", 9 ))
395 : : {
396 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
397 : : {
398 : : sal_Int32 nValue;
399 : : double fValue;
400 : 0 : bool bFloat( false );
401 : :
402 : 0 : rtl::OUString aName = rControlCommand.Arguments[i].Name;
403 [ # # ]: 0 : if ( impl_getValue( rControlCommand.Arguments[i].Value, nValue, fValue, bFloat ))
404 : : {
405 [ # # ]: 0 : if ( aName.equalsAsciiL( "Value", 5 ))
406 : : {
407 [ # # ]: 0 : aValue = bFloat ? ::rtl::OUString::valueOf( fValue ) : ::rtl::OUString::valueOf( nValue );
408 : 0 : bFloatValue = bFloat;
409 : : }
410 [ # # ]: 0 : else if ( aName.equalsAsciiL( "Step", 4 ))
411 : : aStep = bFloat ? ::rtl::OUString::valueOf( fValue ) :
412 [ # # ]: 0 : ::rtl::OUString::valueOf( nValue );
413 [ # # ]: 0 : else if ( aName.equalsAsciiL( "LowerLimit", 10 ))
414 : : aMin = bFloat ? ::rtl::OUString::valueOf( fValue ) :
415 [ # # ]: 0 : ::rtl::OUString::valueOf( nValue );
416 [ # # ]: 0 : else if ( aName.equalsAsciiL( "UpperLimit", 10 ))
417 : : aMax = bFloat ? ::rtl::OUString::valueOf( fValue ) :
418 [ # # ]: 0 : ::rtl::OUString::valueOf( nValue );
419 : : }
420 [ # # ]: 0 : else if ( aName.equalsAsciiL( "OutputFormat", 12 ))
421 : 0 : rControlCommand.Arguments[i].Value >>= m_aOutFormat;
422 : 0 : }
423 : : }
424 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetLowerLimit", 13 ))
425 : : {
426 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
427 : : {
428 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "LowerLimit", 10 ))
429 : : {
430 : : sal_Int32 nValue;
431 : : double fValue;
432 : 0 : bool bFloat( false );
433 [ # # ]: 0 : if ( impl_getValue( rControlCommand.Arguments[i].Value, nValue, fValue, bFloat ))
434 : : aMin = bFloat ? ::rtl::OUString::valueOf( fValue ) :
435 [ # # ]: 0 : ::rtl::OUString::valueOf( nValue );
436 : : break;
437 : : }
438 : : }
439 : : }
440 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetUpperLimit", 13 ))
441 : : {
442 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
443 : : {
444 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "UpperLimit", 10 ))
445 : : {
446 : : sal_Int32 nValue;
447 : : double fValue;
448 : 0 : bool bFloat( false );
449 [ # # ]: 0 : if ( impl_getValue( rControlCommand.Arguments[i].Value, nValue, fValue, bFloat ))
450 : : aMax = bFloat ? ::rtl::OUString::valueOf( fValue ) :
451 [ # # ]: 0 : ::rtl::OUString::valueOf( nValue );
452 : : break;
453 : : }
454 : : }
455 : : }
456 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetOutputFormat", 15 ))
457 : : {
458 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
459 : : {
460 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "OutputFormat", 10 ))
461 : : {
462 : 0 : rControlCommand.Arguments[i].Value >>= m_aOutFormat;
463 : 0 : break;
464 : : }
465 : : }
466 : : }
467 : :
468 : : // Check values and set members
469 [ # # ]: 0 : if ( !aValue.isEmpty() )
470 : : {
471 : 0 : m_bFloat = bFloatValue;
472 : 0 : m_nValue = aValue.toDouble();
473 : :
474 [ # # ]: 0 : rtl::OUString aOutString = impl_formatOutputString( m_nValue );
475 [ # # ][ # # ]: 0 : m_pSpinfieldControl->SetText( aOutString );
[ # # ]
476 [ # # ]: 0 : notifyTextChanged( aOutString );
477 : : }
478 [ # # ]: 0 : if ( !aMax.isEmpty() )
479 : : {
480 : 0 : m_nMax = aMax.toDouble();
481 : 0 : m_bMaxSet = true;
482 : : }
483 [ # # ]: 0 : if ( !aMin.isEmpty() )
484 : : {
485 : 0 : m_nMin = aMin.toDouble();
486 : 0 : m_bMinSet = true;
487 : : }
488 [ # # ]: 0 : if ( !aStep.isEmpty() )
489 : 0 : m_nStep = aStep.toDouble();
490 : 0 : }
491 : :
492 : 0 : bool SpinfieldToolbarController::impl_getValue(
493 : : const Any& rAny, sal_Int32& nValue, double& fValue, bool& bFloat )
494 : : {
495 : : using ::com::sun::star::uno::TypeClass;
496 : :
497 : 0 : bool bValueValid( false );
498 : :
499 : 0 : bFloat = false;
500 : 0 : TypeClass aTypeClass = rAny.getValueTypeClass();
501 [ # # ][ # # ]: 0 : if (( aTypeClass == TypeClass( typelib_TypeClass_LONG )) ||
[ # # ]
502 : : ( aTypeClass == TypeClass( typelib_TypeClass_SHORT )) ||
503 : : ( aTypeClass == TypeClass( typelib_TypeClass_BYTE )))
504 : 0 : bValueValid = rAny >>= nValue;
505 [ # # ][ # # ]: 0 : else if (( aTypeClass == TypeClass( typelib_TypeClass_FLOAT )) ||
506 : : ( aTypeClass == TypeClass( typelib_TypeClass_DOUBLE )))
507 : : {
508 : 0 : bValueValid = rAny >>= fValue;
509 : 0 : bFloat = true;
510 : : }
511 : :
512 : 0 : return bValueValid;
513 : : }
514 : :
515 : 0 : rtl::OUString SpinfieldToolbarController::impl_formatOutputString( double fValue )
516 : : {
517 [ # # ]: 0 : if ( m_aOutFormat.isEmpty() )
518 : : {
519 [ # # ]: 0 : if ( m_bFloat )
520 : 0 : return rtl::OUString::valueOf( fValue );
521 : : else
522 : 0 : return rtl::OUString::valueOf( sal_Int32( fValue ));
523 : : }
524 : : else
525 : : {
526 : : #ifdef WNT
527 : : sal_Unicode aBuffer[128];
528 : :
529 : : aBuffer[0] = 0;
530 : : if ( m_bFloat )
531 : : snwprintf( reinterpret_cast<wchar_t *>(aBuffer), 128, reinterpret_cast<const wchar_t *>(m_aOutFormat.getStr()), fValue );
532 : : else
533 : : snwprintf( reinterpret_cast<wchar_t *>(aBuffer), 128, reinterpret_cast<const wchar_t *>(m_aOutFormat.getStr()), sal_Int32( fValue ));
534 : :
535 : : sal_Int32 nSize = rtl_ustr_getLength( aBuffer );
536 : : return rtl::OUString( aBuffer, nSize );
537 : : #else
538 : : // Currently we have no support for a format string using sal_Unicode. wchar_t
539 : : // is 32 bit on Unix platform!
540 : : char aBuffer[128];
541 : :
542 [ # # ][ # # ]: 0 : ::rtl::OString aFormat = OUStringToOString( m_aOutFormat, osl_getThreadTextEncoding() );
543 [ # # ]: 0 : if ( m_bFloat )
544 : 0 : snprintf( aBuffer, 128, aFormat.getStr(), fValue );
545 : : else
546 : 0 : snprintf( aBuffer, 128, aFormat.getStr(), static_cast<long>( fValue ));
547 : :
548 : 0 : sal_Int32 nSize = strlen( aBuffer );
549 : 0 : rtl::OString aTmp( aBuffer, nSize );
550 [ # # ][ # # ]: 0 : return rtl::OStringToOUString( aTmp, osl_getThreadTextEncoding() );
551 : : #endif
552 : : }
553 : : }
554 : :
555 : : } // namespace
556 : :
557 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|