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