Update ooo320-m1
[ooovba.git] / svtools / source / uno / unoiface.cxx
blobee62412b3243a5d6f1625424a8b60c670af9ed1c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoiface.cxx,v $
10 * $Revision: 1.32 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _SVT_UNOIFACE_CXX
35 #include <tools/debug.hxx>
36 #include <vcl/svapp.hxx>
38 #include <svtools/svmedit.hxx>
39 #include <unoiface.hxx>
40 #include "filedlg.hxx"
41 #include "filectrl.hxx"
42 #include "roadmap.hxx"
43 #include <svtools/fixedhyper.hxx>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
46 #include <com/sun/star/awt/LineEndFormat.hpp>
47 #include <comphelper/processfactory.hxx>
48 #include <toolkit/helper/convert.hxx>
49 #include <toolkit/helper/property.hxx>
50 #include <svtools/fmtfield.hxx>
51 #include <numuno.hxx>
52 #include <calendar.hxx>
53 #include <prgsbar.hxx>
55 #include <svtools/svtreebx.hxx>
56 #include "treecontrolpeer.hxx"
57 //#include "vclxgridcontrol.hxx"
58 #include "unocontroltablemodel.hxx"
59 #include <svtools/table/tablecontrol.hxx>
61 namespace
63 static void lcl_setWinBits( Window* _pWindow, WinBits _nBits, sal_Bool _bSet )
65 WinBits nStyle = _pWindow->GetStyle();
66 if ( _bSet )
67 nStyle |= _nBits;
68 else
69 nStyle &= ~_nBits;
70 _pWindow->SetStyle( nStyle );
74 // ----------------------------------------------------
75 // help function for the toolkit...
76 // ----------------------------------------------------
78 extern "C" {
80 SAL_DLLPUBLIC_EXPORT Window* CreateWindow( VCLXWindow** ppNewComp, const ::com::sun::star::awt::WindowDescriptor* pDescriptor, Window* pParent, WinBits nWinBits )
82 Window* pWindow = NULL;
83 String aServiceName( pDescriptor->WindowServiceName );
84 if ( aServiceName.EqualsIgnoreCaseAscii( "MultiLineEdit" ) )
86 if ( pParent )
88 pWindow = new MultiLineEdit( pParent, nWinBits|WB_IGNORETAB);
89 *ppNewComp = new VCLXMultiLineEdit;
91 else
93 *ppNewComp = NULL;
94 return NULL;
97 else if ( aServiceName.EqualsIgnoreCaseAscii( "FileControl" ) )
99 if ( pParent )
101 pWindow = new FileControl( pParent, nWinBits );
102 *ppNewComp = new VCLXFileControl;
104 else
106 *ppNewComp = NULL;
107 return NULL;
110 else if (aServiceName.EqualsIgnoreCaseAscii("FormattedField") )
112 pWindow = new FormattedField( pParent, nWinBits );
113 *ppNewComp = new SVTXFormattedField;
115 else if (aServiceName.EqualsIgnoreCaseAscii("NumericField") )
117 pWindow = new DoubleNumericField( pParent, nWinBits );
118 *ppNewComp = new SVTXNumericField;
120 else if (aServiceName.EqualsIgnoreCaseAscii("LongCurrencyField") )
122 pWindow = new DoubleCurrencyField( pParent, nWinBits );
123 *ppNewComp = new SVTXCurrencyField;
125 else if (aServiceName.EqualsIgnoreCaseAscii("datefield") )
127 pWindow = new CalendarField( pParent, nWinBits);
128 static_cast<CalendarField*>(pWindow)->EnableToday();
129 static_cast<CalendarField*>(pWindow)->EnableNone();
130 static_cast<CalendarField*>(pWindow)->EnableEmptyFieldValue( TRUE );
131 *ppNewComp = new SVTXDateField;
132 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pWindow );
134 else if (aServiceName.EqualsIgnoreCaseAscii("roadmap") )
136 pWindow = new ::svt::ORoadmap( pParent, WB_TABSTOP );
137 *ppNewComp = new SVTXRoadmap;
139 else if ( aServiceName.EqualsIgnoreCaseAscii( "ProgressBar" ) )
141 if ( pParent )
143 pWindow = new ProgressBar( pParent, nWinBits );
144 *ppNewComp = new VCLXProgressBar;
146 else
148 *ppNewComp = NULL;
149 return NULL;
152 else if ( aServiceName.EqualsIgnoreCaseAscii( "Tree" ) )
154 TreeControlPeer* pPeer = new TreeControlPeer;
155 *ppNewComp = pPeer;
156 pWindow = pPeer->createVclControl( pParent, nWinBits );
158 else if ( aServiceName.EqualsIgnoreCaseAscii( "FixedHyperlink" ) )
160 if ( pParent )
162 pWindow = new ::svt::FixedHyperlink( pParent, nWinBits );
163 *ppNewComp = new VCLXFixedHyperlink;
165 else
167 *ppNewComp = NULL;
168 return NULL;
171 else if ( aServiceName.EqualsIgnoreCaseAscii( "Grid" ) )
173 if ( pParent )
175 ::svt::table::TableControl* m_pTable = new ::svt::table::TableControl(pParent, nWinBits);
176 UnoControlTableModel* pModel = new UnoControlTableModel();
177 *ppNewComp = pModel;
178 pWindow = m_pTable;
180 else
182 *ppNewComp = NULL;
183 return NULL;
186 return pWindow;
189 } // extern "C"
191 // ----------------------------------------------------
192 // class VCLXMultiLineEdit
193 // ----------------------------------------------------
194 VCLXMultiLineEdit::VCLXMultiLineEdit()
195 :maTextListeners( *this )
196 ,meLineEndType( LINEEND_LF ) // default behavior before introducing this property: LF (unix-like)
200 VCLXMultiLineEdit::~VCLXMultiLineEdit()
204 ::com::sun::star::uno::Any VCLXMultiLineEdit::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
206 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
207 SAL_STATIC_CAST( ::com::sun::star::awt::XTextComponent*, this ),
208 SAL_STATIC_CAST( ::com::sun::star::awt::XTextArea*, this ),
209 SAL_STATIC_CAST( ::com::sun::star::awt::XTextLayoutConstrains*, this ),
210 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
211 return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
214 // ::com::sun::star::lang::XTypeProvider
215 IMPL_XTYPEPROVIDER_START( VCLXMultiLineEdit )
216 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent>* ) NULL ),
217 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextArea>* ) NULL ),
218 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains>* ) NULL ),
219 VCLXWindow::getTypes()
220 IMPL_XTYPEPROVIDER_END
222 void VCLXMultiLineEdit::addTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
224 maTextListeners.addInterface( l );
227 void VCLXMultiLineEdit::removeTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
229 maTextListeners.removeInterface( l );
232 void VCLXMultiLineEdit::setText( const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
234 ::vos::OGuard aGuard( GetMutex() );
236 MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
237 if ( pEdit )
239 pEdit->SetText( aText );
241 // #107218# Call same listeners like VCL would do after user interaction
242 SetSynthesizingVCLEvent( sal_True );
243 pEdit->SetModifyFlag();
244 pEdit->Modify();
245 SetSynthesizingVCLEvent( sal_False );
249 void VCLXMultiLineEdit::insertText( const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
251 ::vos::OGuard aGuard( GetMutex() );
253 MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
254 if ( pEdit )
256 setSelection( rSel );
257 pEdit->ReplaceSelected( aText );
261 ::rtl::OUString VCLXMultiLineEdit::getText() throw(::com::sun::star::uno::RuntimeException)
263 ::vos::OGuard aGuard( GetMutex() );
265 ::rtl::OUString aText;
266 MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
267 if ( pEdit )
268 aText = pEdit->GetText( meLineEndType );
269 return aText;
272 ::rtl::OUString VCLXMultiLineEdit::getSelectedText() throw(::com::sun::star::uno::RuntimeException)
274 ::vos::OGuard aGuard( GetMutex() );
276 ::rtl::OUString aText;
277 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
278 if ( pMultiLineEdit)
279 aText = pMultiLineEdit->GetSelected( meLineEndType );
280 return aText;
284 void VCLXMultiLineEdit::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw(::com::sun::star::uno::RuntimeException)
286 ::vos::OGuard aGuard( GetMutex() );
288 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
289 if ( pMultiLineEdit )
291 pMultiLineEdit->SetSelection( Selection( aSelection.Min, aSelection.Max ) );
295 ::com::sun::star::awt::Selection VCLXMultiLineEdit::getSelection() throw(::com::sun::star::uno::RuntimeException)
297 ::vos::OGuard aGuard( GetMutex() );
299 ::com::sun::star::awt::Selection aSel;
300 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
301 if ( pMultiLineEdit )
303 aSel.Min = pMultiLineEdit->GetSelection().Min();
304 aSel.Max = pMultiLineEdit->GetSelection().Max();
306 return aSel;
309 sal_Bool VCLXMultiLineEdit::isEditable() throw(::com::sun::star::uno::RuntimeException)
311 ::vos::OGuard aGuard( GetMutex() );
313 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
314 return ( pMultiLineEdit && !pMultiLineEdit->IsReadOnly() && pMultiLineEdit->IsEnabled() ) ? sal_True : sal_False;
317 void VCLXMultiLineEdit::setEditable( sal_Bool bEditable ) throw(::com::sun::star::uno::RuntimeException)
319 ::vos::OGuard aGuard( GetMutex() );
321 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
322 if ( pMultiLineEdit )
323 pMultiLineEdit->SetReadOnly( !bEditable );
326 void VCLXMultiLineEdit::setMaxTextLen( sal_Int16 nLen ) throw(::com::sun::star::uno::RuntimeException)
328 ::vos::OGuard aGuard( GetMutex() );
330 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
331 if ( pMultiLineEdit )
332 pMultiLineEdit->SetMaxTextLen( nLen );
335 sal_Int16 VCLXMultiLineEdit::getMaxTextLen() throw(::com::sun::star::uno::RuntimeException)
337 ::vos::OGuard aGuard( GetMutex() );
339 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
340 return pMultiLineEdit ? (sal_Int16)pMultiLineEdit->GetMaxTextLen() : (sal_Int16)0;
343 ::rtl::OUString VCLXMultiLineEdit::getTextLines() throw(::com::sun::star::uno::RuntimeException)
345 ::vos::OGuard aGuard( GetMutex() );
347 ::rtl::OUString aText;
348 MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
349 if ( pEdit )
350 aText = pEdit->GetTextLines( meLineEndType );
351 return aText;
354 ::com::sun::star::awt::Size VCLXMultiLineEdit::getMinimumSize() throw(::com::sun::star::uno::RuntimeException)
356 ::vos::OGuard aGuard( GetMutex() );
358 ::com::sun::star::awt::Size aSz;
359 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
360 if ( pEdit )
361 aSz = AWTSize(pEdit->CalcMinimumSize());
362 return aSz;
365 ::com::sun::star::awt::Size VCLXMultiLineEdit::getPreferredSize() throw(::com::sun::star::uno::RuntimeException)
367 return getMinimumSize();
370 ::com::sun::star::awt::Size VCLXMultiLineEdit::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException)
372 ::vos::OGuard aGuard( GetMutex() );
374 ::com::sun::star::awt::Size aSz = rNewSize;
375 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
376 if ( pEdit )
377 aSz = AWTSize(pEdit->CalcAdjustedSize( VCLSize(rNewSize )));
378 return aSz;
381 ::com::sun::star::awt::Size VCLXMultiLineEdit::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(::com::sun::star::uno::RuntimeException)
383 ::vos::OGuard aGuard( GetMutex() );
385 ::com::sun::star::awt::Size aSz;
386 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
387 if ( pEdit )
388 aSz = AWTSize(pEdit->CalcSize( nCols, nLines ));
389 return aSz;
392 void VCLXMultiLineEdit::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException)
394 ::vos::OGuard aGuard( GetMutex() );
396 nCols = nLines = 0;
397 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
398 if ( pEdit )
400 sal_uInt16 nC, nL;
401 pEdit->GetMaxVisColumnsAndLines( nC, nL );
402 nCols = nC;
403 nLines = nL;
407 void VCLXMultiLineEdit::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
409 switch ( rVclWindowEvent.GetId() )
411 case VCLEVENT_EDIT_MODIFY:
413 if ( maTextListeners.getLength() )
415 ::com::sun::star::awt::TextEvent aEvent;
416 aEvent.Source = (::cppu::OWeakObject*)this;
417 maTextListeners.textChanged( aEvent );
420 break;
421 default:
423 VCLXWindow::ProcessWindowEvent( rVclWindowEvent );
425 break;
429 void VCLXMultiLineEdit::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
431 ::vos::OGuard aGuard( GetMutex() );
433 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*)GetWindow();
434 if ( pMultiLineEdit )
436 sal_uInt16 nPropType = GetPropertyId( PropertyName );
437 switch ( nPropType )
439 case BASEPROPERTY_LINE_END_FORMAT:
441 sal_Int16 nLineEndType = ::com::sun::star::awt::LineEndFormat::LINE_FEED;
442 OSL_VERIFY( Value >>= nLineEndType );
443 switch ( nLineEndType )
445 case ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN: meLineEndType = LINEEND_CR; break;
446 case ::com::sun::star::awt::LineEndFormat::LINE_FEED: meLineEndType = LINEEND_LF; break;
447 case ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: meLineEndType = LINEEND_CRLF; break;
448 default: DBG_ERROR( "VCLXMultiLineEdit::setProperty: invalid line end value!" ); break;
451 break;
453 case BASEPROPERTY_READONLY:
455 sal_Bool b = sal_Bool();
456 if ( Value >>= b )
457 pMultiLineEdit->SetReadOnly( b );
459 break;
460 case BASEPROPERTY_MAXTEXTLEN:
462 sal_Int16 n = sal_Int16();
463 if ( Value >>= n )
464 pMultiLineEdit->SetMaxTextLen( n );
466 break;
467 case BASEPROPERTY_HIDEINACTIVESELECTION:
469 sal_Bool b = sal_Bool();
470 if ( Value >>= b )
472 pMultiLineEdit->EnableFocusSelectionHide( b );
473 lcl_setWinBits( pMultiLineEdit, WB_NOHIDESELECTION, !b );
476 break;
477 default:
479 VCLXWindow::setProperty( PropertyName, Value );
485 ::com::sun::star::uno::Any VCLXMultiLineEdit::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
487 ::vos::OGuard aGuard( GetMutex() );
489 ::com::sun::star::uno::Any aProp;
490 MultiLineEdit* pMultiLineEdit = (MultiLineEdit*)GetWindow();
491 if ( pMultiLineEdit )
493 sal_uInt16 nPropType = GetPropertyId( PropertyName );
494 switch ( nPropType )
496 case BASEPROPERTY_LINE_END_FORMAT:
498 sal_Int16 nLineEndType = ::com::sun::star::awt::LineEndFormat::LINE_FEED;
499 switch ( meLineEndType )
501 case LINEEND_CR: nLineEndType = ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN; break;
502 case LINEEND_LF: nLineEndType = ::com::sun::star::awt::LineEndFormat::LINE_FEED; break;
503 case LINEEND_CRLF: nLineEndType = ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED; break;
504 default: DBG_ERROR( "VCLXMultiLineEdit::getProperty: invalid line end value!" ); break;
506 aProp <<= nLineEndType;
508 break;
510 case BASEPROPERTY_READONLY:
512 aProp <<= pMultiLineEdit->IsReadOnly();
514 break;
515 case BASEPROPERTY_MAXTEXTLEN:
517 aProp <<= (sal_Int16) pMultiLineEdit->GetMaxTextLen();
519 break;
520 default:
522 aProp <<= VCLXWindow::getProperty( PropertyName );
526 return aProp;
529 void SAL_CALL VCLXMultiLineEdit::setFocus( ) throw(::com::sun::star::uno::RuntimeException)
531 ::vos::OGuard aGuard( GetMutex() );
533 // don't grab the focus if we already have it. Reason is that the only thing which the edit
534 // does is forwarding the focus to it's text window. This text window then does a "select all".
535 // So if the text window already has the focus, and we give the focus to the multi line
536 // edit, then all which happens is that everything is selected.
537 // #i27072# - 2004-04-25 - fs@openoffice.org
538 if ( GetWindow() && !GetWindow()->HasChildPathFocus() )
539 GetWindow()->GrabFocus();
542 void VCLXMultiLineEdit::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
544 PushPropertyIds( rIds,
545 // FIXME: elide duplication ?
546 BASEPROPERTY_LINE_END_FORMAT,
547 BASEPROPERTY_READONLY,
548 BASEPROPERTY_MAXTEXTLEN,
549 BASEPROPERTY_HIDEINACTIVESELECTION,
551 VCLXWindow::ImplGetPropertyIds( rIds, true );
554 // ----------------------------------------------------
555 // class VCLXFileDialog
556 // ----------------------------------------------------
558 VCLXFileDialog::VCLXFileDialog()
562 VCLXFileDialog::~VCLXFileDialog()
566 ::com::sun::star::uno::Any VCLXFileDialog::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
568 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
569 SAL_STATIC_CAST( ::com::sun::star::awt::XXX*, this ) );
570 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
573 // ::com::sun::star::lang::XTypeProvider
574 IMPL_XTYPEPROVIDER_START( VCLXFileDialog )
575 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XXX>* ) NULL )
576 IMPL_XTYPEPROVIDER_END
578 void VCLXFileDialog::setPath( const ::rtl::OUString& rPath )
580 ::vos::OGuard aGuard( GetMutex() );
582 FileDialog* pDlg = (FileDialog*)GetWindow();
583 if ( pDlg )
584 pDlg->SetPath( ::rtl::OUStringToOString( rPath, CHARSET_SYSTEM ) );
587 ::rtl::OUString VCLXFileDialog::getPath()
589 ::vos::OGuard aGuard( GetMutex() );
591 ::rtl::OUString aPath;
592 FileDialog* pDlg = (FileDialog*)GetWindow();
593 if ( pDlg )
594 aPath = StringToOUString( pDlg->GetPath(), CHARSET_SYSTEM );
595 return aPath;
598 void VCLXFileDialog::setFilters( const ::com::sun::star::uno::Sequence< ::rtl::OUString>& rFilterNames, const ::com::sun::star::uno::Sequence< ::rtl::OUString>& rMasks )
600 ::vos::OGuard aGuard( GetMutex() );
602 FileDialog* pDlg = (FileDialog*)GetWindow();
603 if ( pDlg )
605 sal_uInt32 nFlts = rFilterNames.getLength();
606 for ( sal_uInt32 n = 0; n < nFlts; n++ )
607 pDlg->AddFilter(
608 ::rtl::OUStringToOString( rFilterNames.getConstArray()[n], CHARSET_SYSTEM ),
609 ::rtl::OUStringToOString( rMasks.getConstArray()[n], CHARSET_SYSTEM ) );
613 void VCLXFileDialog::setCurrentFilter( const ::rtl::OUString& rFilterName )
615 ::vos::OGuard aGuard( GetMutex() );
617 FileDialog* pDlg = (FileDialog*)GetWindow();
618 if ( pDlg )
619 pDlg->SetCurFilter( ::rtl::OUStringToOString( rFilterName, CHARSET_SYSTEM ) );
622 ::rtl::OUString VCLXFileDialog::getCurrentFilter()
624 ::vos::OGuard aGuard( GetMutex() );
626 ::rtl::OUString aFilter;
627 FileDialog* pDlg = (FileDialog*)GetWindow();
628 if ( pDlg )
629 aFilter = StringToOUString( pDlg->GetCurFilter(), CHARSET_SYSTEM );
630 return aFilter;
634 // ----------------------------------------------------
635 // class VCLXFileControl
636 // ----------------------------------------------------
637 VCLXFileControl::VCLXFileControl() : maTextListeners( *this )
641 VCLXFileControl::~VCLXFileControl()
643 FileControl* pControl = (FileControl*) GetWindow();
644 if ( pControl )
645 pControl->GetEdit().SetModifyHdl( Link() );
648 ::com::sun::star::uno::Any VCLXFileControl::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
650 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
651 SAL_STATIC_CAST( ::com::sun::star::awt::XTextComponent*, this ),
652 SAL_STATIC_CAST( ::com::sun::star::awt::XTextLayoutConstrains*, this ),
653 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
654 return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
657 // ::com::sun::star::lang::XTypeProvider
658 IMPL_XTYPEPROVIDER_START( VCLXFileControl )
659 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent>* ) NULL ),
660 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains>* ) NULL ),
661 VCLXWindow::getTypes()
662 IMPL_XTYPEPROVIDER_END
664 void SAL_CALL VCLXFileControl::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
666 ::vos::OGuard aGuard( GetMutex() );
668 FileControl* pControl = (FileControl*)GetWindow();
669 if ( pControl )
671 sal_uInt16 nPropType = GetPropertyId( PropertyName );
672 switch ( nPropType )
674 case BASEPROPERTY_HIDEINACTIVESELECTION:
676 sal_Bool bValue( sal_False );
677 OSL_VERIFY( Value >>= bValue );
679 lcl_setWinBits( pControl, WB_NOHIDESELECTION, !bValue );
680 lcl_setWinBits( &pControl->GetEdit(), WB_NOHIDESELECTION, !bValue );
682 break;
684 default:
685 VCLXWindow::setProperty( PropertyName, Value );
686 break;
691 void VCLXFileControl::SetWindow( Window* pWindow )
693 FileControl* pPrevFileControl = dynamic_cast<FileControl*>( GetWindow() );
694 if ( pPrevFileControl )
695 pPrevFileControl->GetEdit().SetModifyHdl( Link() );
697 FileControl* pNewFileControl = dynamic_cast<FileControl*>( pWindow );
698 if ( pNewFileControl )
699 pNewFileControl->GetEdit().SetModifyHdl( LINK( this, VCLXFileControl, ModifyHdl ) );
701 VCLXWindow::SetWindow( pWindow );
704 void VCLXFileControl::addTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
706 maTextListeners.addInterface( l );
709 void VCLXFileControl::removeTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
711 maTextListeners.removeInterface( l );
714 void VCLXFileControl::setText( const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
716 ::vos::OGuard aGuard( GetMutex() );
718 Window* pWindow = GetWindow();
719 if ( pWindow )
721 pWindow->SetText( aText );
723 // In JAVA wird auch ein textChanged ausgeloest, in VCL nicht.
724 // ::com::sun::star::awt::Toolkit soll JAVA-komform sein...
725 ModifyHdl( NULL );
729 void VCLXFileControl::insertText( const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
731 ::vos::OGuard aGuard( GetMutex() );
733 FileControl* pFileControl = (FileControl*) GetWindow();
734 if ( pFileControl )
736 pFileControl->GetEdit().SetSelection( Selection( rSel.Min, rSel.Max ) );
737 pFileControl->GetEdit().ReplaceSelected( aText );
741 ::rtl::OUString VCLXFileControl::getText() throw(::com::sun::star::uno::RuntimeException)
743 ::vos::OGuard aGuard( GetMutex() );
745 ::rtl::OUString aText;
746 Window* pWindow = GetWindow();
747 if ( pWindow )
748 aText = pWindow->GetText();
749 return aText;
752 ::rtl::OUString VCLXFileControl::getSelectedText() throw(::com::sun::star::uno::RuntimeException)
754 ::vos::OGuard aGuard( GetMutex() );
756 ::rtl::OUString aText;
757 FileControl* pFileControl = (FileControl*) GetWindow();
758 if ( pFileControl)
759 aText = pFileControl->GetEdit().GetSelected();
760 return aText;
764 void VCLXFileControl::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw(::com::sun::star::uno::RuntimeException)
766 ::vos::OGuard aGuard( GetMutex() );
768 FileControl* pFileControl = (FileControl*) GetWindow();
769 if ( pFileControl )
770 pFileControl->GetEdit().SetSelection( Selection( aSelection.Min, aSelection.Max ) );
773 ::com::sun::star::awt::Selection VCLXFileControl::getSelection() throw(::com::sun::star::uno::RuntimeException)
775 ::vos::OGuard aGuard( GetMutex() );
777 ::com::sun::star::awt::Selection aSel;
778 FileControl* pFileControl = (FileControl*) GetWindow();
779 if ( pFileControl )
781 aSel.Min = pFileControl->GetEdit().GetSelection().Min();
782 aSel.Max = pFileControl->GetEdit().GetSelection().Max();
784 return aSel;
787 sal_Bool VCLXFileControl::isEditable() throw(::com::sun::star::uno::RuntimeException)
789 ::vos::OGuard aGuard( GetMutex() );
791 FileControl* pFileControl = (FileControl*) GetWindow();
792 return ( pFileControl && !pFileControl->GetEdit().IsReadOnly() && pFileControl->GetEdit().IsEnabled() ) ? sal_True : sal_False;
795 void VCLXFileControl::setEditable( sal_Bool bEditable ) throw(::com::sun::star::uno::RuntimeException)
797 ::vos::OGuard aGuard( GetMutex() );
799 FileControl* pFileControl = (FileControl*) GetWindow();
800 if ( pFileControl )
801 pFileControl->GetEdit().SetReadOnly( !bEditable );
804 void VCLXFileControl::setMaxTextLen( sal_Int16 nLen ) throw(::com::sun::star::uno::RuntimeException)
806 ::vos::OGuard aGuard( GetMutex() );
808 FileControl* pFileControl = (FileControl*) GetWindow();
809 if ( pFileControl )
810 pFileControl->GetEdit().SetMaxTextLen( nLen );
813 sal_Int16 VCLXFileControl::getMaxTextLen() throw(::com::sun::star::uno::RuntimeException)
815 ::vos::OGuard aGuard( GetMutex() );
817 FileControl* pFileControl = (FileControl*) GetWindow();
818 return pFileControl ? pFileControl->GetEdit().GetMaxTextLen() : 0;
822 IMPL_LINK( VCLXFileControl, ModifyHdl, Edit*, EMPTYARG )
824 ::com::sun::star::awt::TextEvent aEvent;
825 aEvent.Source = (::cppu::OWeakObject*)this;
826 maTextListeners.textChanged( aEvent );
828 return 1;
831 ::com::sun::star::awt::Size VCLXFileControl::getMinimumSize() throw(::com::sun::star::uno::RuntimeException)
833 ::vos::OGuard aGuard( GetMutex() );
835 ::com::sun::star::awt::Size aSz;
836 FileControl* pControl = (FileControl*) GetWindow();
837 if ( pControl )
839 Size aTmpSize = pControl->GetEdit().CalcMinimumSize();
840 aTmpSize.Width() += pControl->GetButton().CalcMinimumSize().Width();
841 aSz = AWTSize(pControl->CalcWindowSize( aTmpSize ));
843 return aSz;
846 ::com::sun::star::awt::Size VCLXFileControl::getPreferredSize() throw(::com::sun::star::uno::RuntimeException)
848 ::com::sun::star::awt::Size aSz = getMinimumSize();
849 aSz.Height += 4;
850 return aSz;
853 ::com::sun::star::awt::Size VCLXFileControl::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException)
855 ::vos::OGuard aGuard( GetMutex() );
857 ::com::sun::star::awt::Size aSz =rNewSize;
858 FileControl* pControl = (FileControl*) GetWindow();
859 if ( pControl )
861 ::com::sun::star::awt::Size aMinSz = getMinimumSize();
862 if ( aSz.Height != aMinSz.Height )
863 aSz.Height = aMinSz.Height;
865 return aSz;
868 ::com::sun::star::awt::Size VCLXFileControl::getMinimumSize( sal_Int16 nCols, sal_Int16 ) throw(::com::sun::star::uno::RuntimeException)
870 ::vos::OGuard aGuard( GetMutex() );
872 ::com::sun::star::awt::Size aSz;
873 FileControl* pControl = (FileControl*) GetWindow();
874 if ( pControl )
876 aSz = AWTSize(pControl->GetEdit().CalcSize( nCols ));
877 aSz.Width += pControl->GetButton().CalcMinimumSize().Width();
879 return aSz;
882 void VCLXFileControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException)
884 ::vos::OGuard aGuard( GetMutex() );
886 nCols = 0;
887 nLines = 1;
888 FileControl* pControl = (FileControl*) GetWindow();
889 if ( pControl )
890 nCols = (sal_Int16) pControl->GetEdit().GetMaxVisChars();
893 void VCLXFileControl::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
895 PushPropertyIds( rIds,
896 // FIXME: elide duplication ?
897 BASEPROPERTY_HIDEINACTIVESELECTION,
899 VCLXWindow::ImplGetPropertyIds( rIds, true );
903 // ----------------------------------------------------
904 // class SVTXFormattedField
905 // ----------------------------------------------------
906 // --------------------------------------------------------------------------------------
907 SVTXFormattedField::SVTXFormattedField()
908 :m_pCurrentSupplier(NULL)
909 ,bIsStandardSupplier(sal_True)
910 ,nKeyToSetDelayed(-1)
914 // --------------------------------------------------------------------------------------
915 SVTXFormattedField::~SVTXFormattedField()
917 if (m_pCurrentSupplier)
919 m_pCurrentSupplier->release();
920 m_pCurrentSupplier = NULL;
924 // --------------------------------------------------------------------------------------
925 void SVTXFormattedField::SetWindow( Window* _pWindow )
927 VCLXSpinField::SetWindow(_pWindow);
928 if (GetFormattedField())
929 GetFormattedField()->SetAutoColor(TRUE);
932 // --------------------------------------------------------------------------------------
933 void SVTXFormattedField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
935 ::vos::OGuard aGuard( GetMutex() );
937 FormattedField* pField = GetFormattedField();
938 if ( pField )
940 sal_uInt16 nPropType = GetPropertyId( PropertyName );
941 switch (nPropType)
943 case BASEPROPERTY_ENFORCE_FORMAT:
945 sal_Bool bEnable( sal_True );
946 if ( Value >>= bEnable )
947 pField->EnableNotANumber( !bEnable );
949 break;
951 case BASEPROPERTY_EFFECTIVE_MIN:
952 case BASEPROPERTY_VALUEMIN_DOUBLE:
953 SetMinValue(Value);
954 break;
956 case BASEPROPERTY_EFFECTIVE_MAX:
957 case BASEPROPERTY_VALUEMAX_DOUBLE:
958 SetMaxValue(Value);
959 break;
961 case BASEPROPERTY_EFFECTIVE_DEFAULT:
962 SetDefaultValue(Value);
963 break;
965 case BASEPROPERTY_TREATASNUMBER:
967 sal_Bool b = sal_Bool();
968 if ( Value >>= b )
969 SetTreatAsNumber(b);
971 break;
973 case BASEPROPERTY_FORMATSSUPPLIER:
974 if (!Value.hasValue())
975 setFormatsSupplier(::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > (NULL));
976 else
978 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > xNFS;
979 if ( Value >>= xNFS )
980 setFormatsSupplier(xNFS);
982 break;
983 case BASEPROPERTY_FORMATKEY:
984 if (!Value.hasValue())
985 setFormatKey(0);
986 else
988 sal_Int32 n = 0;
989 if ( Value >>= n )
990 setFormatKey(n);
992 break;
994 case BASEPROPERTY_EFFECTIVE_VALUE:
995 case BASEPROPERTY_VALUE_DOUBLE:
997 const ::com::sun::star::uno::TypeClass rTC = Value.getValueType().getTypeClass();
998 if (rTC != ::com::sun::star::uno::TypeClass_STRING)
999 // no string
1000 if (rTC != ::com::sun::star::uno::TypeClass_DOUBLE)
1001 // no double
1002 if (Value.hasValue())
1003 { // but a value
1004 // try if it is something converitble
1005 sal_Int32 nValue = 0;
1006 if (!(Value >>= nValue))
1007 throw ::com::sun::star::lang::IllegalArgumentException();
1008 SetValue(::com::sun::star::uno::makeAny((double)nValue));
1009 break;
1012 SetValue(Value);
1014 break;
1015 case BASEPROPERTY_VALUESTEP_DOUBLE:
1017 double d = 0.0;
1018 if ( Value >>= d )
1019 pField->SetSpinSize( d );
1020 else
1022 sal_Int32 n = 0;
1023 if ( Value >>= n )
1024 pField->SetSpinSize( n );
1027 break;
1028 case BASEPROPERTY_DECIMALACCURACY:
1030 sal_Int32 n = 0;
1031 if ( Value >>= n )
1032 pField->SetDecimalDigits( (sal_uInt16)n );
1034 break;
1035 case BASEPROPERTY_NUMSHOWTHOUSANDSEP:
1037 sal_Bool b = sal_Bool();
1038 if ( Value >>= b )
1039 pField->SetThousandsSep( b );
1041 break;
1043 default:
1044 VCLXSpinField::setProperty( PropertyName, Value );
1047 if (BASEPROPERTY_TEXTCOLOR == nPropType)
1048 { // after setting a new text color, think again about the AutoColor flag of the control
1049 // 17.05.2001 - 86859 - frank.schoenheit@germany.sun.com
1050 pField->SetAutoColor(!Value.hasValue());
1053 else
1054 VCLXSpinField::setProperty( PropertyName, Value );
1057 // --------------------------------------------------------------------------------------
1058 ::com::sun::star::uno::Any SVTXFormattedField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
1060 ::vos::OGuard aGuard( GetMutex() );
1062 ::com::sun::star::uno::Any aReturn;
1064 FormattedField* pField = GetFormattedField();
1065 if ( pField )
1067 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1068 switch (nPropType)
1070 case BASEPROPERTY_EFFECTIVE_MIN:
1071 case BASEPROPERTY_VALUEMIN_DOUBLE:
1072 aReturn <<= GetMinValue();
1073 break;
1075 case BASEPROPERTY_EFFECTIVE_MAX:
1076 case BASEPROPERTY_VALUEMAX_DOUBLE:
1077 aReturn <<= GetMaxValue();
1078 break;
1080 case BASEPROPERTY_EFFECTIVE_DEFAULT:
1081 aReturn <<= GetDefaultValue();
1082 break;
1084 case BASEPROPERTY_TREATASNUMBER:
1085 aReturn <<= GetTreatAsNumber();
1086 break;
1088 case BASEPROPERTY_EFFECTIVE_VALUE:
1089 case BASEPROPERTY_VALUE_DOUBLE:
1090 aReturn <<= GetValue();
1091 break;
1093 case BASEPROPERTY_VALUESTEP_DOUBLE:
1094 aReturn <<= pField->GetSpinSize();
1095 break;
1097 case BASEPROPERTY_DECIMALACCURACY:
1098 aReturn <<= pField->GetDecimalDigits();
1099 break;
1101 case BASEPROPERTY_FORMATSSUPPLIER:
1103 if (!bIsStandardSupplier)
1104 { // ansonsten void
1105 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = getFormatsSupplier();
1106 aReturn <<= xSupplier;
1109 break;
1111 case BASEPROPERTY_FORMATKEY:
1113 if (!bIsStandardSupplier)
1114 aReturn <<= getFormatKey();
1116 break;
1118 default:
1119 aReturn <<= VCLXSpinField::getProperty(PropertyName);
1122 return aReturn;
1125 // --------------------------------------------------------------------------------------
1126 ::com::sun::star::uno::Any SVTXFormattedField::convertEffectiveValue(const ::com::sun::star::uno::Any& rValue)
1128 ::com::sun::star::uno::Any aReturn;
1130 FormattedField* pField = GetFormattedField();
1131 if (!pField)
1132 return aReturn;
1134 switch (rValue.getValueType().getTypeClass())
1136 case ::com::sun::star::uno::TypeClass_DOUBLE:
1137 if (pField->TreatingAsNumber())
1139 double d;
1140 rValue >>= d;
1141 aReturn <<= d;
1143 else
1145 SvNumberFormatter* pFormatter = pField->GetFormatter();
1146 if (!pFormatter)
1147 pFormatter = pField->StandardFormatter();
1148 // should never fail
1150 Color* pDum;
1151 double d;
1152 rValue >>= d;
1153 String sConverted;
1154 pFormatter->GetOutputString(d, 0, sConverted, &pDum);
1155 aReturn <<= ::rtl::OUString( sConverted );
1157 break;
1158 case ::com::sun::star::uno::TypeClass_STRING:
1160 ::rtl::OUString aStr;
1161 rValue >>= aStr;
1162 String sValue = aStr;
1163 if (pField->TreatingAsNumber())
1165 SvNumberFormatter* pFormatter = pField->GetFormatter();
1166 if (!pFormatter)
1167 pFormatter = pField->StandardFormatter();
1169 double dVal;
1170 sal_uInt32 nTestFormat(0);
1171 if (!pFormatter->IsNumberFormat(sValue, nTestFormat, dVal))
1172 aReturn.clear();
1173 aReturn <<=dVal;
1175 else
1176 aReturn <<= aStr;
1178 break;
1179 default:
1180 aReturn.clear();
1181 break;
1183 return aReturn;
1186 // --------------------------------------------------------------------------------------
1187 void SVTXFormattedField::SetMinValue(const ::com::sun::star::uno::Any& rValue)
1189 FormattedField* pField = GetFormattedField();
1190 if (!pField)
1191 return;
1193 switch (rValue.getValueType().getTypeClass())
1196 case ::com::sun::star::uno::TypeClass_DOUBLE:
1198 double d = 0.0;
1199 rValue >>= d;
1200 pField->SetMinValue(d);
1202 break;
1203 default:
1204 DBG_ASSERT(rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID, "SVTXFormattedField::SetMinValue : invalid argument (an exception will be thrown) !");
1205 if ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID )
1208 throw ::com::sun::star::lang::IllegalArgumentException();
1210 pField->ClearMinValue();
1211 break;
1215 // --------------------------------------------------------------------------------------
1216 ::com::sun::star::uno::Any SVTXFormattedField::GetMinValue()
1218 FormattedField* pField = GetFormattedField();
1219 if (!pField || !pField->HasMinValue())
1220 return ::com::sun::star::uno::Any();
1222 ::com::sun::star::uno::Any aReturn;
1223 aReturn <<= pField->GetMinValue();
1224 return aReturn;
1227 // --------------------------------------------------------------------------------------
1228 void SVTXFormattedField::SetMaxValue(const ::com::sun::star::uno::Any& rValue)
1230 FormattedField* pField = GetFormattedField();
1231 if (!pField)
1232 return;
1234 switch (rValue.getValueType().getTypeClass())
1237 case ::com::sun::star::uno::TypeClass_DOUBLE:
1239 double d = 0.0;
1240 rValue >>= d;
1241 pField->SetMaxValue(d);
1243 break;
1244 default:
1245 if (rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID)
1248 throw ::com::sun::star::lang::IllegalArgumentException();
1250 pField->ClearMaxValue();
1251 break;
1255 // --------------------------------------------------------------------------------------
1256 ::com::sun::star::uno::Any SVTXFormattedField::GetMaxValue()
1258 FormattedField* pField = GetFormattedField();
1259 if (!pField || !pField->HasMaxValue())
1260 return ::com::sun::star::uno::Any();
1262 ::com::sun::star::uno::Any aReturn;
1263 aReturn <<= pField->GetMaxValue();
1264 return aReturn;
1267 // --------------------------------------------------------------------------------------
1268 void SVTXFormattedField::SetDefaultValue(const ::com::sun::star::uno::Any& rValue)
1270 FormattedField* pField = GetFormattedField();
1271 if (!pField)
1272 return;
1274 ::com::sun::star::uno::Any aConverted = convertEffectiveValue(rValue);
1276 switch (aConverted.getValueType().getTypeClass())
1279 case ::com::sun::star::uno::TypeClass_DOUBLE:
1281 double d = 0.0;
1282 aConverted >>= d;
1283 pField->SetDefaultValue(d);
1285 break;
1286 case ::com::sun::star::uno::TypeClass_STRING:
1288 ::rtl::OUString aStr;
1289 aConverted >>= aStr;
1290 pField->SetDefaultText( aStr );
1292 break;
1293 default:
1294 pField->EnableEmptyField(sal_True);
1295 // nur noch void erlaubt
1296 break;
1300 // --------------------------------------------------------------------------------------
1301 ::com::sun::star::uno::Any SVTXFormattedField::GetDefaultValue()
1303 FormattedField* pField = GetFormattedField();
1304 if (!pField || pField->IsEmptyFieldEnabled())
1305 return ::com::sun::star::uno::Any();
1307 ::com::sun::star::uno::Any aReturn;
1308 if (pField->TreatingAsNumber())
1309 aReturn <<= pField->GetDefaultValue();
1310 else
1311 aReturn <<= ::rtl::OUString( pField->GetDefaultText() );
1312 return aReturn;
1315 // --------------------------------------------------------------------------------------
1316 sal_Bool SVTXFormattedField::GetTreatAsNumber()
1318 FormattedField* pField = GetFormattedField();
1319 if (pField)
1320 return pField->TreatingAsNumber();
1322 return sal_True;
1325 // --------------------------------------------------------------------------------------
1326 void SVTXFormattedField::SetTreatAsNumber(sal_Bool bSet)
1328 FormattedField* pField = GetFormattedField();
1329 if (pField)
1330 pField->TreatAsNumber(bSet);
1333 // --------------------------------------------------------------------------------------
1334 ::com::sun::star::uno::Any SVTXFormattedField::GetValue()
1336 FormattedField* pField = GetFormattedField();
1337 if (!pField)
1338 return ::com::sun::star::uno::Any();
1340 ::com::sun::star::uno::Any aReturn;
1341 if (!pField->TreatingAsNumber())
1343 ::rtl::OUString sText = pField->GetTextValue();
1344 aReturn <<= sText;
1346 else
1348 if (pField->GetText().Len()) // empty wird erst mal standardmaessig als void nach draussen gereicht
1349 aReturn <<= pField->GetValue();
1352 return aReturn;
1355 // --------------------------------------------------------------------------------------
1356 void SVTXFormattedField::SetValue(const ::com::sun::star::uno::Any& rValue)
1358 FormattedField* pField = GetFormattedField();
1359 if (!pField)
1360 return;
1362 if (!rValue.hasValue())
1364 pField->SetText(String());
1366 else
1368 if (rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_DOUBLE )
1370 double d = 0.0;
1371 rValue >>= d;
1372 pField->SetValue(d);
1374 else
1376 DBG_ASSERT(rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_STRING, "SVTXFormattedField::SetValue : invalid argument !");
1378 ::rtl::OUString sText;
1379 rValue >>= sText;
1380 String aStr( sText );
1381 if (!pField->TreatingAsNumber())
1382 pField->SetTextFormatted(aStr);
1383 else
1384 pField->SetTextValue(aStr);
1387 // NotifyTextListeners();
1390 // --------------------------------------------------------------------------------------
1391 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > SVTXFormattedField::getFormatsSupplier(void) const
1393 return ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > ((::com::sun::star::util::XNumberFormatsSupplier*)m_pCurrentSupplier);
1396 // --------------------------------------------------------------------------------------
1397 void SVTXFormattedField::setFormatsSupplier(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > & xSupplier)
1399 FormattedField* pField = GetFormattedField();
1401 SvNumberFormatsSupplierObj* pNew = NULL;
1402 if (!xSupplier.is())
1404 if (pField)
1406 pNew = new SvNumberFormatsSupplierObj(pField->StandardFormatter());
1407 bIsStandardSupplier = sal_True;
1410 else
1412 pNew = SvNumberFormatsSupplierObj::getImplementation(xSupplier);
1413 bIsStandardSupplier = sal_False;
1416 if (!pNew)
1417 return; // TODO : wie das behandeln ?
1419 if (m_pCurrentSupplier)
1420 m_pCurrentSupplier->release();
1421 m_pCurrentSupplier = pNew;
1422 m_pCurrentSupplier->acquire();
1423 if (pField)
1425 // den aktuellen Value mit hinueberretten
1426 ::com::sun::star::uno::Any aCurrent = GetValue();
1427 pField->SetFormatter(m_pCurrentSupplier->GetNumberFormatter(), sal_False);
1428 if (nKeyToSetDelayed != -1)
1430 pField->SetFormatKey(nKeyToSetDelayed);
1431 nKeyToSetDelayed = -1;
1433 SetValue(aCurrent);
1434 NotifyTextListeners();
1438 // --------------------------------------------------------------------------------------
1439 sal_Int32 SVTXFormattedField::getFormatKey(void) const
1441 FormattedField* pField = GetFormattedField();
1442 return pField ? pField->GetFormatKey() : 0;
1445 // --------------------------------------------------------------------------------------
1446 void SVTXFormattedField::setFormatKey(sal_Int32 nKey)
1448 FormattedField* pField = GetFormattedField();
1449 if (pField)
1451 if (pField->GetFormatter())
1452 pField->SetFormatKey(nKey);
1453 else
1454 { // Wahrscheinlich bin ich gerade in einem Block, in dem erst der Key und dann der Formatter gesetzt
1455 // wird, das passiert initial mit ziemlicher Sicherheit, da die Properties in alphabetischer Reihenfolge
1456 // gesetzt werden, und der FormatsSupplier nun mal vor dem FormatKey kommt
1457 nKeyToSetDelayed = nKey;
1459 NotifyTextListeners();
1463 // --------------------------------------------------------------------------------------
1464 void SVTXFormattedField::NotifyTextListeners()
1466 if ( GetTextListeners().getLength() )
1468 ::com::sun::star::awt::TextEvent aEvent;
1469 aEvent.Source = (::cppu::OWeakObject*)this;
1470 GetTextListeners().textChanged( aEvent );
1474 void SVTXFormattedField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
1476 PushPropertyIds( rIds,
1477 // FIXME: elide duplication ?
1478 BASEPROPERTY_EFFECTIVE_MIN,
1479 BASEPROPERTY_VALUEMIN_DOUBLE,
1480 BASEPROPERTY_EFFECTIVE_MAX,
1481 BASEPROPERTY_VALUEMAX_DOUBLE,
1482 BASEPROPERTY_EFFECTIVE_DEFAULT,
1483 BASEPROPERTY_TREATASNUMBER,
1484 BASEPROPERTY_EFFECTIVE_VALUE,
1485 BASEPROPERTY_VALUE_DOUBLE,
1486 BASEPROPERTY_VALUESTEP_DOUBLE,
1487 BASEPROPERTY_DECIMALACCURACY,
1488 BASEPROPERTY_FORMATSSUPPLIER,
1489 BASEPROPERTY_NUMSHOWTHOUSANDSEP,
1490 BASEPROPERTY_FORMATKEY,
1491 BASEPROPERTY_TREATASNUMBER,
1492 BASEPROPERTY_ENFORCE_FORMAT,
1494 VCLXWindow::ImplGetPropertyIds( rIds, true );
1495 VCLXSpinField::ImplGetPropertyIds( rIds );
1499 // ----------------------------------------------------
1500 // class SVTXRoadmap
1501 // ----------------------------------------------------
1503 using namespace svt;
1505 // --------------------------------------------------------------------------------------
1506 SVTXRoadmap::SVTXRoadmap() : maItemListeners( *this )
1510 // --------------------------------------------------------------------------------------
1511 SVTXRoadmap::~SVTXRoadmap()
1515 void SVTXRoadmap::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
1517 switch ( rVclWindowEvent.GetId() )
1519 case VCLEVENT_ROADMAP_ITEMSELECTED:
1521 ::vos::OGuard aGuard( GetMutex() );
1522 ::svt::ORoadmap* pField = GetRoadmap();
1523 if ( pField )
1525 sal_Int16 CurItemID = pField->GetCurrentRoadmapItemID();
1526 ::com::sun::star::awt::ItemEvent aEvent;
1527 aEvent.Selected = CurItemID;
1528 aEvent.Highlighted = CurItemID;
1529 aEvent.ItemId = CurItemID;
1530 maItemListeners.itemStateChanged( aEvent );
1533 break;
1534 default:
1535 SVTXRoadmap_Base::ProcessWindowEvent( rVclWindowEvent );
1536 break;
1541 void SVTXRoadmap::propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException)
1543 ::vos::OGuard aGuard( GetMutex() );
1544 ::svt::ORoadmap* pField = GetRoadmap();
1545 if ( pField )
1547 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xRoadmapItem;
1548 xRoadmapItem = evt.Source;
1549 sal_Int32 nID = 0;
1550 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropertySet( xRoadmapItem, ::com::sun::star::uno::UNO_QUERY );
1551 ::com::sun::star::uno::Any aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "ID" ));
1552 aValue >>= nID;
1554 ::com::sun::star::uno::Any rVal = evt.NewValue;
1555 evt.NewValue >>= rVal;
1556 ::rtl::OUString sPropertyName = evt.PropertyName;
1557 if ( sPropertyName.equals(::rtl::OUString::createFromAscii( "Enabled" ) ) )
1559 sal_Bool bEnable = false;
1560 evt.NewValue >>= bEnable;
1561 pField->EnableRoadmapItem( (RoadmapTypes::ItemId)nID , bEnable );
1563 else if ( sPropertyName.equals(::rtl::OUString::createFromAscii( "Label" ) ) )
1565 ::rtl::OUString sLabel;
1566 evt.NewValue >>= sLabel;
1567 pField->ChangeRoadmapItemLabel( (RoadmapTypes::ItemId)nID , sLabel );
1569 else if ( sPropertyName.equals(::rtl::OUString::createFromAscii( "ID" ) ) )
1571 sal_Int32 nNewID = 0;
1572 evt.NewValue >>= nNewID;
1573 evt.OldValue >>= nID;
1574 pField->ChangeRoadmapItemID( (RoadmapTypes::ItemId)nID, (RoadmapTypes::ItemId)nNewID );
1576 // else
1577 // Todo: handle Interactive appropriately
1582 void SVTXRoadmap::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException)
1584 maItemListeners.addInterface( l );
1587 void SVTXRoadmap::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException)
1589 maItemListeners.removeInterface( l );
1592 RMItemData SVTXRoadmap::GetRMItemData( const ::com::sun::star::container::ContainerEvent& _rEvent )
1594 RMItemData aCurRMItemData;
1595 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xRoadmapItem;
1596 _rEvent.Element >>= xRoadmapItem;
1597 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropertySet( xRoadmapItem, ::com::sun::star::uno::UNO_QUERY );
1598 if ( xPropertySet.is() )
1600 ::com::sun::star::uno::Any aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "Label" ));
1601 aValue >>= aCurRMItemData.Label;
1602 aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "ID" ));
1603 aValue >>= aCurRMItemData.n_ID;
1604 aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "Enabled" ));
1605 aValue >>= aCurRMItemData.b_Enabled;
1607 return aCurRMItemData;;
1610 void SVTXRoadmap::elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent )throw(::com::sun::star::uno::RuntimeException)
1612 ::vos::OGuard aGuard( GetMutex() );
1613 ::svt::ORoadmap* pField = GetRoadmap();
1614 if ( pField )
1616 RMItemData CurItemData = GetRMItemData( _rEvent );
1617 sal_Int32 InsertIndex = 0;
1618 _rEvent.Accessor >>= InsertIndex;
1619 pField->InsertRoadmapItem( InsertIndex, CurItemData.Label, (RoadmapTypes::ItemId)CurItemData.n_ID, CurItemData.b_Enabled );
1623 void SVTXRoadmap::elementRemoved( const ::com::sun::star::container::ContainerEvent& _rEvent )throw(::com::sun::star::uno::RuntimeException)
1625 ::vos::OGuard aGuard( GetMutex() );
1626 ::svt::ORoadmap* pField = GetRoadmap();
1627 if ( pField )
1629 sal_Int32 DelIndex = 0;
1630 _rEvent.Accessor >>= DelIndex;
1631 pField->DeleteRoadmapItem(DelIndex);
1632 // pField->GetCurrentRoadmapItem()
1633 // setProperty(::rtl::OUString.createFromAscii( "CurrentItem" )aAny,
1637 void SVTXRoadmap::elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent )throw(::com::sun::star::uno::RuntimeException)
1639 ::vos::OGuard aGuard( GetMutex() );
1640 ::svt::ORoadmap* pField = GetRoadmap();
1641 if ( pField )
1643 RMItemData CurItemData = GetRMItemData( _rEvent );
1644 sal_Int32 ReplaceIndex = 0;
1645 _rEvent.Accessor >>= ReplaceIndex;
1646 pField->ReplaceRoadmapItem( ReplaceIndex, CurItemData.Label, (RoadmapTypes::ItemId)CurItemData.n_ID, CurItemData.b_Enabled );
1652 // --------------------------------------------------------------------------------------
1653 void SVTXRoadmap::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
1655 ::vos::OGuard aGuard( GetMutex() );
1657 ::svt::ORoadmap* pField = GetRoadmap();
1658 if ( pField )
1660 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1661 switch (nPropType)
1663 case BASEPROPERTY_COMPLETE:
1665 sal_Bool b = false;
1666 Value >>= b;
1667 pField->SetRoadmapComplete( b);
1669 break;
1671 case BASEPROPERTY_ACTIVATED:
1673 sal_Bool b = false;
1674 Value >>= b;
1675 pField->SetRoadmapInteractive( b);
1677 break;
1679 case BASEPROPERTY_CURRENTITEMID:
1681 sal_Int32 nId = 0;
1682 Value >>= nId;
1683 pField->SelectRoadmapItemByID( (RoadmapTypes::ItemId)nId );
1685 break;
1687 case BASEPROPERTY_TEXT:
1689 ::rtl::OUString aStr;
1690 Value >>= aStr;
1691 pField->SetText( aStr );
1692 pField->Invalidate();
1694 break;
1696 default:
1697 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1698 break;
1702 else
1703 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1707 // --------------------------------------------------------------------------------------
1708 ::com::sun::star::uno::Any SVTXRoadmap::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
1710 ::vos::OGuard aGuard( GetMutex() );
1712 ::com::sun::star::uno::Any aReturn;
1714 ::svt::ORoadmap* pField = GetRoadmap();
1715 if ( pField )
1717 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1718 switch (nPropType)
1720 case BASEPROPERTY_COMPLETE:
1721 aReturn <<= pField->IsRoadmapComplete();
1722 break;
1723 case BASEPROPERTY_ACTIVATED:
1724 aReturn <<= pField->IsRoadmapInteractive();
1725 break;
1726 case BASEPROPERTY_CURRENTITEMID:
1727 aReturn <<= pField->GetCurrentRoadmapItemID();
1728 break;
1729 default:
1730 aReturn = SVTXRoadmap_Base::getProperty(PropertyName);
1731 break;
1734 return aReturn;
1737 void SVTXRoadmap::ImplSetNewImage()
1739 OSL_PRECOND( GetWindow(), "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!" );
1740 ::svt::ORoadmap* pButton = static_cast< ::svt::ORoadmap* >( GetWindow() );
1741 pButton->SetRoadmapBitmap( GetBitmap() );
1744 void SVTXRoadmap::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
1746 PushPropertyIds( rIds,
1747 BASEPROPERTY_COMPLETE,
1748 BASEPROPERTY_ACTIVATED,
1749 BASEPROPERTY_CURRENTITEMID,
1750 BASEPROPERTY_TEXT,
1752 VCLXWindow::ImplGetPropertyIds( rIds, true );
1753 VCLXImageConsumer::ImplGetPropertyIds( rIds );
1756 // ----------------------------------------------------
1757 // class SVTXNumericField
1758 // ----------------------------------------------------
1759 SVTXNumericField::SVTXNumericField()
1763 SVTXNumericField::~SVTXNumericField()
1767 ::com::sun::star::uno::Any SVTXNumericField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
1769 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
1770 SAL_STATIC_CAST( ::com::sun::star::awt::XNumericField*, this ),
1771 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
1772 return (aRet.hasValue() ? aRet : SVTXFormattedField::queryInterface( rType ));
1775 // ::com::sun::star::lang::XTypeProvider
1776 IMPL_XTYPEPROVIDER_START( SVTXNumericField )
1777 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XNumericField>* ) NULL ),
1778 SVTXFormattedField::getTypes()
1779 IMPL_XTYPEPROVIDER_END
1782 void SVTXNumericField::setValue( double Value ) throw(::com::sun::star::uno::RuntimeException)
1784 ::vos::OGuard aGuard( GetMutex() );
1786 FormattedField* pField = GetFormattedField();
1787 if ( pField )
1788 pField->SetValue( Value );
1791 double SVTXNumericField::getValue() throw(::com::sun::star::uno::RuntimeException)
1793 ::vos::OGuard aGuard( GetMutex() );
1795 FormattedField* pField = GetFormattedField();
1796 return pField ? pField->GetValue() : 0;
1799 void SVTXNumericField::setMin( double Value ) throw(::com::sun::star::uno::RuntimeException)
1801 ::vos::OGuard aGuard( GetMutex() );
1803 FormattedField* pField = GetFormattedField();
1804 if ( pField )
1805 pField->SetMinValue( Value );
1808 double SVTXNumericField::getMin() throw(::com::sun::star::uno::RuntimeException)
1810 ::vos::OGuard aGuard( GetMutex() );
1812 FormattedField* pField = GetFormattedField();
1813 return pField ? pField->GetMinValue() : 0;
1816 void SVTXNumericField::setMax( double Value ) throw(::com::sun::star::uno::RuntimeException)
1818 ::vos::OGuard aGuard( GetMutex() );
1820 FormattedField* pField = GetFormattedField();
1821 if ( pField )
1822 pField->SetMaxValue( Value );
1825 double SVTXNumericField::getMax() throw(::com::sun::star::uno::RuntimeException)
1827 ::vos::OGuard aGuard( GetMutex() );
1829 FormattedField* pField = GetFormattedField();
1830 return pField ? pField->GetMaxValue() : 0;
1833 void SVTXNumericField::setFirst( double Value ) throw(::com::sun::star::uno::RuntimeException)
1835 ::vos::OGuard aGuard( GetMutex() );
1837 FormattedField* pField = GetFormattedField();
1838 if ( pField )
1839 pField->SetSpinFirst( Value );
1842 double SVTXNumericField::getFirst() throw(::com::sun::star::uno::RuntimeException)
1844 ::vos::OGuard aGuard( GetMutex() );
1846 FormattedField* pField = GetFormattedField();
1847 return pField ? pField->GetSpinFirst() : 0;
1850 void SVTXNumericField::setLast( double Value ) throw(::com::sun::star::uno::RuntimeException)
1852 ::vos::OGuard aGuard( GetMutex() );
1854 FormattedField* pField = GetFormattedField();
1855 if ( pField )
1856 pField->SetSpinLast( Value );
1859 double SVTXNumericField::getLast() throw(::com::sun::star::uno::RuntimeException)
1861 ::vos::OGuard aGuard( GetMutex() );
1863 FormattedField* pField = GetFormattedField();
1864 return pField ? pField->GetSpinLast() : 0;
1867 void SVTXNumericField::setSpinSize( double Value ) throw(::com::sun::star::uno::RuntimeException)
1869 ::vos::OGuard aGuard( GetMutex() );
1871 FormattedField* pField = GetFormattedField();
1872 if ( pField )
1873 pField->SetSpinSize( Value );
1876 double SVTXNumericField::getSpinSize() throw(::com::sun::star::uno::RuntimeException)
1878 ::vos::OGuard aGuard( GetMutex() );
1880 FormattedField* pField = GetFormattedField();
1881 return pField ? pField->GetSpinSize() : 0;
1884 void SVTXNumericField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException)
1886 ::vos::OGuard aGuard( GetMutex() );
1888 FormattedField* pField = GetFormattedField();
1889 if ( pField )
1890 pField->SetDecimalDigits( Value );
1893 sal_Int16 SVTXNumericField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException)
1895 ::vos::OGuard aGuard( GetMutex() );
1897 FormattedField* pField = GetFormattedField();
1898 return pField ? pField->GetDecimalDigits() : 0;
1901 void SVTXNumericField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException)
1903 ::vos::OGuard aGuard( GetMutex() );
1905 FormattedField* pField = GetFormattedField();
1906 if ( pField )
1907 pField->SetStrictFormat( bStrict );
1910 sal_Bool SVTXNumericField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException)
1912 ::vos::OGuard aGuard( GetMutex() );
1914 FormattedField* pField = GetFormattedField();
1915 return pField ? pField->IsStrictFormat() : sal_False;
1918 void SVTXNumericField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
1920 SVTXFormattedField::ImplGetPropertyIds( rIds );
1923 // ----------------------------------------------------
1924 // class SVTXCurrencyField
1925 // ----------------------------------------------------
1926 SVTXCurrencyField::SVTXCurrencyField()
1930 SVTXCurrencyField::~SVTXCurrencyField()
1934 ::com::sun::star::uno::Any SVTXCurrencyField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
1936 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
1937 SAL_STATIC_CAST( ::com::sun::star::awt::XCurrencyField*, this ),
1938 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
1939 return (aRet.hasValue() ? aRet : SVTXFormattedField::queryInterface( rType ));
1942 // ::com::sun::star::lang::XTypeProvider
1943 IMPL_XTYPEPROVIDER_START( SVTXCurrencyField )
1944 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XCurrencyField>* ) NULL ),
1945 SVTXFormattedField::getTypes()
1946 IMPL_XTYPEPROVIDER_END
1948 void SVTXCurrencyField::setValue( double Value ) throw(::com::sun::star::uno::RuntimeException)
1950 ::vos::OGuard aGuard( GetMutex() );
1952 FormattedField* pField = GetFormattedField();
1953 if ( pField )
1954 pField->SetValue( Value );
1957 double SVTXCurrencyField::getValue() throw(::com::sun::star::uno::RuntimeException)
1959 ::vos::OGuard aGuard( GetMutex() );
1961 FormattedField* pField = GetFormattedField();
1962 return pField ? pField->GetValue() : 0;
1965 void SVTXCurrencyField::setMin( double Value ) throw(::com::sun::star::uno::RuntimeException)
1967 ::vos::OGuard aGuard( GetMutex() );
1969 FormattedField* pField = GetFormattedField();
1970 if ( pField )
1971 pField->SetMinValue( Value );
1974 double SVTXCurrencyField::getMin() throw(::com::sun::star::uno::RuntimeException)
1976 ::vos::OGuard aGuard( GetMutex() );
1978 FormattedField* pField = GetFormattedField();
1979 return pField ? pField->GetMinValue() : 0;
1982 void SVTXCurrencyField::setMax( double Value ) throw(::com::sun::star::uno::RuntimeException)
1984 ::vos::OGuard aGuard( GetMutex() );
1986 FormattedField* pField = GetFormattedField();
1987 if ( pField )
1988 pField->SetMaxValue( Value );
1991 double SVTXCurrencyField::getMax() throw(::com::sun::star::uno::RuntimeException)
1993 ::vos::OGuard aGuard( GetMutex() );
1995 FormattedField* pField = GetFormattedField();
1996 return pField ? pField->GetMaxValue() : 0;
1999 void SVTXCurrencyField::setFirst( double Value ) throw(::com::sun::star::uno::RuntimeException)
2001 ::vos::OGuard aGuard( GetMutex() );
2003 FormattedField* pField = GetFormattedField();
2004 if ( pField )
2005 pField->SetSpinFirst( Value );
2008 double SVTXCurrencyField::getFirst() throw(::com::sun::star::uno::RuntimeException)
2010 ::vos::OGuard aGuard( GetMutex() );
2012 FormattedField* pField = GetFormattedField();
2013 return pField ? pField->GetSpinFirst() : 0;
2016 void SVTXCurrencyField::setLast( double Value ) throw(::com::sun::star::uno::RuntimeException)
2018 ::vos::OGuard aGuard( GetMutex() );
2020 FormattedField* pField = GetFormattedField();
2021 if ( pField )
2022 pField->SetSpinLast( Value );
2025 double SVTXCurrencyField::getLast() throw(::com::sun::star::uno::RuntimeException)
2027 ::vos::OGuard aGuard( GetMutex() );
2029 FormattedField* pField = GetFormattedField();
2030 return pField ? pField->GetSpinLast() : 0;
2033 void SVTXCurrencyField::setSpinSize( double Value ) throw(::com::sun::star::uno::RuntimeException)
2035 ::vos::OGuard aGuard( GetMutex() );
2037 FormattedField* pField = GetFormattedField();
2038 if ( pField )
2039 pField->SetSpinSize( Value );
2042 double SVTXCurrencyField::getSpinSize() throw(::com::sun::star::uno::RuntimeException)
2044 ::vos::OGuard aGuard( GetMutex() );
2046 FormattedField* pField = GetFormattedField();
2047 return pField ? pField->GetSpinSize() : 0;
2050 void SVTXCurrencyField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException)
2052 ::vos::OGuard aGuard( GetMutex() );
2054 FormattedField* pField = GetFormattedField();
2055 if ( pField )
2056 pField->SetDecimalDigits( Value );
2059 sal_Int16 SVTXCurrencyField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException)
2061 ::vos::OGuard aGuard( GetMutex() );
2063 FormattedField* pField = GetFormattedField();
2064 return pField ? pField->GetDecimalDigits() : 0;
2067 void SVTXCurrencyField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException)
2069 ::vos::OGuard aGuard( GetMutex() );
2071 FormattedField* pField = GetFormattedField();
2072 if ( pField )
2073 pField->SetStrictFormat( bStrict );
2076 sal_Bool SVTXCurrencyField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException)
2078 ::vos::OGuard aGuard( GetMutex() );
2080 FormattedField* pField = GetFormattedField();
2081 return pField ? pField->IsStrictFormat() : sal_False;
2084 void SVTXCurrencyField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
2086 ::vos::OGuard aGuard( GetMutex() );
2088 ::com::sun::star::uno::Any aReturn;
2090 DoubleCurrencyField* pField = (DoubleCurrencyField*)GetFormattedField();
2091 if ( pField )
2093 #ifdef DBG_UTIL
2094 String sAssertion( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "SVTXCurrencyField::setProperty(" ) ) );
2095 sAssertion += String( PropertyName );
2096 sAssertion.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ") : invalid value !" ) );
2097 #endif
2098 sal_uInt16 nPropType = GetPropertyId( PropertyName );
2099 switch (nPropType)
2101 case BASEPROPERTY_CURRENCYSYMBOL:
2103 ::rtl::OUString aStr;
2104 Value >>= aStr;
2105 pField->setCurrencySymbol( aStr );
2107 break;
2108 case BASEPROPERTY_CURSYM_POSITION:
2110 sal_Bool b = false;
2111 Value >>= b;
2112 pField->setPrependCurrSym(b);
2114 break;
2116 default:
2117 SVTXFormattedField::setProperty(PropertyName, Value);
2120 else
2121 SVTXFormattedField::setProperty(PropertyName, Value);
2124 ::com::sun::star::uno::Any SVTXCurrencyField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
2126 ::vos::OGuard aGuard( GetMutex() );
2128 ::com::sun::star::uno::Any aReturn;
2130 DoubleCurrencyField* pField = (DoubleCurrencyField*)GetFormattedField();
2131 if ( pField )
2133 sal_uInt16 nPropType = GetPropertyId( PropertyName );
2134 switch (nPropType)
2136 case BASEPROPERTY_CURRENCYSYMBOL:
2138 aReturn <<= ::rtl::OUString( pField->getCurrencySymbol() );
2140 break;
2141 case BASEPROPERTY_CURSYM_POSITION:
2143 aReturn <<= pField->getPrependCurrSym();
2145 break;
2146 default:
2147 return SVTXFormattedField::getProperty(PropertyName);
2150 return SVTXFormattedField::getProperty(PropertyName);
2153 void SVTXCurrencyField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
2155 PushPropertyIds( rIds,
2156 BASEPROPERTY_CURRENCYSYMBOL,
2157 BASEPROPERTY_CURSYM_POSITION,
2159 SVTXFormattedField::ImplGetPropertyIds( rIds );
2163 // ----------------------------------------------------
2164 // class VCLXProgressBar
2165 // ----------------------------------------------------
2167 VCLXProgressBar::VCLXProgressBar()
2168 :m_nValue(0)
2169 ,m_nValueMin(0)
2170 ,m_nValueMax(100)
2174 VCLXProgressBar::~VCLXProgressBar()
2178 void VCLXProgressBar::ImplUpdateValue()
2180 ProgressBar* pProgressBar = (ProgressBar*) GetWindow();
2181 if ( pProgressBar )
2183 sal_Int32 nVal;
2184 sal_Int32 nValMin;
2185 sal_Int32 nValMax;
2187 // check min and max
2188 if (m_nValueMin < m_nValueMax)
2190 nValMin = m_nValueMin;
2191 nValMax = m_nValueMax;
2193 else
2195 nValMin = m_nValueMax;
2196 nValMax = m_nValueMin;
2199 // check value
2200 if (m_nValue < nValMin)
2202 nVal = nValMin;
2204 else if (m_nValue > nValMax)
2206 nVal = nValMax;
2208 else
2210 nVal = m_nValue;
2213 // calculate percent
2214 sal_Int32 nPercent;
2215 if (nValMin != nValMax)
2217 nPercent = 100 * (nVal - nValMin) / (nValMax - nValMin);
2219 else
2221 nPercent = 0;
2224 // set progressbar value
2225 pProgressBar->SetValue( (USHORT) nPercent );
2229 // ::com::sun::star::uno::XInterface
2230 ::com::sun::star::uno::Any VCLXProgressBar::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
2232 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
2233 SAL_STATIC_CAST( ::com::sun::star::awt::XProgressBar*, this ),
2234 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
2235 return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
2238 // ::com::sun::star::lang::XTypeProvider
2239 IMPL_XTYPEPROVIDER_START( VCLXProgressBar )
2240 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XProgressBar>* ) NULL ),
2241 VCLXWindow::getTypes()
2242 IMPL_XTYPEPROVIDER_END
2244 // ::com::sun::star::awt::XProgressBar
2245 void VCLXProgressBar::setForegroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException)
2247 ::vos::OGuard aGuard( GetMutex() );
2249 Window* pWindow = GetWindow();
2250 if ( pWindow )
2252 Color aColor( nColor );
2253 pWindow->SetControlForeground( aColor );
2257 void VCLXProgressBar::setBackgroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException)
2259 ::vos::OGuard aGuard( GetMutex() );
2261 Window* pWindow = GetWindow();
2262 if ( pWindow )
2264 Color aColor( nColor );
2265 pWindow->SetBackground( aColor );
2266 pWindow->SetControlBackground( aColor );
2267 pWindow->Invalidate();
2271 void VCLXProgressBar::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException)
2273 ::vos::OGuard aGuard( GetMutex() );
2275 m_nValue = nValue;
2276 ImplUpdateValue();
2279 void VCLXProgressBar::setRange( sal_Int32 nMin, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException )
2281 ::vos::OGuard aGuard( GetMutex() );
2283 if ( nMin < nMax )
2285 // take correct min and max
2286 m_nValueMin = nMin;
2287 m_nValueMax = nMax;
2289 else
2291 // change min and max
2292 m_nValueMin = nMax;
2293 m_nValueMax = nMin;
2296 ImplUpdateValue();
2299 sal_Int32 VCLXProgressBar::getValue() throw(::com::sun::star::uno::RuntimeException)
2301 ::vos::OGuard aGuard( GetMutex() );
2303 return m_nValue;
2306 // ::com::sun::star::awt::VclWindowPeer
2307 void VCLXProgressBar::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
2309 ::vos::OGuard aGuard( GetMutex() );
2311 ProgressBar* pProgressBar = (ProgressBar*)GetWindow();
2312 if ( pProgressBar )
2314 sal_uInt16 nPropType = GetPropertyId( PropertyName );
2315 switch ( nPropType )
2317 case BASEPROPERTY_PROGRESSVALUE:
2319 if ( Value >>= m_nValue )
2320 ImplUpdateValue();
2322 break;
2323 case BASEPROPERTY_PROGRESSVALUE_MIN:
2325 if ( Value >>= m_nValueMin )
2326 ImplUpdateValue();
2328 break;
2329 case BASEPROPERTY_PROGRESSVALUE_MAX:
2331 if ( Value >>= m_nValueMax )
2332 ImplUpdateValue();
2334 break;
2335 case BASEPROPERTY_FILLCOLOR:
2337 Window* pWindow = GetWindow();
2338 if ( pWindow )
2340 sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
2342 if ( bVoid )
2344 pWindow->SetControlForeground();
2346 else
2348 sal_Int32 nColor = 0;
2349 if ( Value >>= nColor )
2351 Color aColor( nColor );
2352 pWindow->SetControlForeground( aColor );
2357 break;
2358 default:
2359 VCLXWindow::setProperty( PropertyName, Value );
2360 break;
2365 ::com::sun::star::uno::Any VCLXProgressBar::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
2367 ::vos::OGuard aGuard( GetMutex() );
2369 ::com::sun::star::uno::Any aProp;
2370 ProgressBar* pProgressBar = (ProgressBar*)GetWindow();
2371 if ( pProgressBar )
2373 sal_uInt16 nPropType = GetPropertyId( PropertyName );
2374 switch ( nPropType )
2376 case BASEPROPERTY_PROGRESSVALUE:
2378 aProp <<= m_nValue;
2380 break;
2381 case BASEPROPERTY_PROGRESSVALUE_MIN:
2383 aProp <<= m_nValueMin;
2385 break;
2386 case BASEPROPERTY_PROGRESSVALUE_MAX:
2388 aProp <<= m_nValueMax;
2390 break;
2391 default:
2392 aProp <<= VCLXWindow::getProperty( PropertyName );
2393 break;
2396 return aProp;
2399 void VCLXProgressBar::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
2401 PushPropertyIds( rIds,
2402 BASEPROPERTY_PROGRESSVALUE,
2403 BASEPROPERTY_PROGRESSVALUE_MIN,
2404 BASEPROPERTY_PROGRESSVALUE_MAX,
2405 BASEPROPERTY_FILLCOLOR,
2407 VCLXWindow::ImplGetPropertyIds( rIds, true );
2411 // ----------------------------------------------------
2412 // class SVTXDateField
2413 // ----------------------------------------------------
2414 SVTXDateField::SVTXDateField()
2415 :VCLXDateField()
2419 SVTXDateField::~SVTXDateField()
2423 void SAL_CALL SVTXDateField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException)
2425 VCLXDateField::setProperty( PropertyName, Value );
2427 // some properties need to be forwarded to the sub edit, too
2428 Edit* pSubEdit = GetWindow() ? static_cast< Edit* >( GetWindow() )->GetSubEdit() : NULL;
2429 if ( !pSubEdit )
2430 return;
2432 switch ( GetPropertyId( PropertyName ) )
2434 case BASEPROPERTY_TEXTLINECOLOR:
2435 if ( !Value.hasValue() )
2436 pSubEdit->SetTextLineColor();
2437 else
2439 sal_Int32 nColor = 0;
2440 if ( Value >>= nColor )
2441 pSubEdit->SetTextLineColor( Color( nColor ) );
2443 break;
2447 void SVTXDateField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
2449 PushPropertyIds( rIds,
2450 BASEPROPERTY_TEXTLINECOLOR,
2452 VCLXDateField::ImplGetPropertyIds( rIds );