xref: /aoo41x/main/svtools/source/uno/unoiface.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svtools.hxx"
30 
31 #define _SVT_UNOIFACE_CXX
32 #include <tools/debug.hxx>
33 #include <vcl/svapp.hxx>
34 #include <svtools/svmedit.hxx>
35 #include <unoiface.hxx>
36 #include <svtools/filedlg.hxx>
37 #include <svtools/filectrl.hxx>
38 #include <svtools/roadmap.hxx>
39 #include <svtools/fixedhyper.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include <com/sun/star/awt/LineEndFormat.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <toolkit/helper/convert.hxx>
45 #include <toolkit/helper/property.hxx>
46 #include <svtools/fmtfield.hxx>
47 #include <svl/numuno.hxx>
48 #include <svtools/calendar.hxx>
49 #include <svtools/prgsbar.hxx>
50 #include <svtools/svtreebx.hxx>
51 #include "treecontrolpeer.hxx"
52 #include "svtxgridcontrol.hxx"
53 #include <svtools/table/tablecontrol.hxx>
54 
55 namespace
56 {
57     static void lcl_setWinBits( Window* _pWindow, WinBits _nBits, sal_Bool _bSet )
58     {
59         WinBits nStyle = _pWindow->GetStyle();
60         if ( _bSet )
61             nStyle |= _nBits;
62         else
63             nStyle &= ~_nBits;
64         _pWindow->SetStyle( nStyle );
65     }
66 }
67 
68 //	----------------------------------------------------
69 //	help function for the toolkit...
70 //	----------------------------------------------------
71 
72 extern "C" {
73 
74 SAL_DLLPUBLIC_EXPORT Window* CreateWindow( VCLXWindow** ppNewComp, const ::com::sun::star::awt::WindowDescriptor* pDescriptor, Window* pParent, WinBits nWinBits )
75 {
76 	Window* pWindow = NULL;
77 	String aServiceName( pDescriptor->WindowServiceName );
78 	if ( aServiceName.EqualsIgnoreCaseAscii( "MultiLineEdit" ) )
79 	{
80 		if ( pParent )
81 		{
82 			pWindow = new MultiLineEdit( pParent, nWinBits|WB_IGNORETAB);
83             static_cast< MultiLineEdit* >( pWindow )->DisableSelectionOnFocus();
84 			*ppNewComp = new VCLXMultiLineEdit;
85 		}
86 		else
87 		{
88 			*ppNewComp = NULL;
89 			return NULL;
90 		}
91 	}
92 	else if ( aServiceName.EqualsIgnoreCaseAscii( "FileControl" ) )
93 	{
94 		if ( pParent )
95 		{
96 			pWindow = new FileControl( pParent, nWinBits );
97 			*ppNewComp = new VCLXFileControl;
98 		}
99 		else
100 		{
101 			*ppNewComp = NULL;
102 			return NULL;
103 		}
104 	}
105 	else if (aServiceName.EqualsIgnoreCaseAscii("FormattedField") )
106 	{
107 		pWindow = new FormattedField( pParent, nWinBits );
108 		*ppNewComp = new SVTXFormattedField;
109 	}
110 	else if (aServiceName.EqualsIgnoreCaseAscii("NumericField") )
111 	{
112 		pWindow = new DoubleNumericField( pParent, nWinBits );
113 		*ppNewComp = new SVTXNumericField;
114 	}
115 	else if (aServiceName.EqualsIgnoreCaseAscii("LongCurrencyField") )
116 	{
117 		pWindow = new DoubleCurrencyField( pParent, nWinBits );
118 		*ppNewComp = new SVTXCurrencyField;
119 	}
120 	else if (aServiceName.EqualsIgnoreCaseAscii("datefield") )
121 	{
122 		pWindow = new CalendarField( pParent, nWinBits);
123 		static_cast<CalendarField*>(pWindow)->EnableToday();
124 		static_cast<CalendarField*>(pWindow)->EnableNone();
125 		static_cast<CalendarField*>(pWindow)->EnableEmptyFieldValue( sal_True );
126 		*ppNewComp = new SVTXDateField;
127 		((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pWindow );
128 	}
129 	else if (aServiceName.EqualsIgnoreCaseAscii("roadmap") )
130 	{
131         pWindow = new ::svt::ORoadmap( pParent, WB_TABSTOP );
132 		*ppNewComp = new SVTXRoadmap;
133 	}
134     else if ( aServiceName.EqualsIgnoreCaseAscii( "ProgressBar" ) )
135 	{
136 		if ( pParent )
137 		{
138 			pWindow = new ProgressBar( pParent, nWinBits );
139 			*ppNewComp = new VCLXProgressBar;
140 		}
141 		else
142 		{
143 			*ppNewComp = NULL;
144 			return NULL;
145 		}
146 	}
147 	else if ( aServiceName.EqualsIgnoreCaseAscii( "Tree" ) )
148 	{
149 		TreeControlPeer* pPeer = new TreeControlPeer;
150 		*ppNewComp = pPeer;
151 		pWindow = pPeer->createVclControl( pParent, nWinBits );
152 	}
153     else if ( aServiceName.EqualsIgnoreCaseAscii( "FixedHyperlink" ) )
154     {
155         if ( pParent )
156         {
157             pWindow = new ::svt::FixedHyperlink( pParent, nWinBits );
158             *ppNewComp = new VCLXFixedHyperlink;
159         }
160         else
161         {
162             *ppNewComp = NULL;
163             return NULL;
164         }
165     }
166 	else if ( aServiceName.EqualsIgnoreCaseAscii( "Grid" ) )
167 	{
168 		if ( pParent )
169 		{
170 			pWindow = new ::svt::table::TableControl(pParent, nWinBits);
171 			*ppNewComp = new SVTXGridControl;
172 		}
173 		else
174 		{
175 			*ppNewComp = NULL;
176 			return NULL;
177 		}
178 	}
179 	return pWindow;
180 }
181 
182 }	// extern "C"
183 
184 //	----------------------------------------------------
185 //	class VCLXMultiLineEdit
186 //	----------------------------------------------------
187 VCLXMultiLineEdit::VCLXMultiLineEdit()
188     :maTextListeners( *this )
189     ,meLineEndType( LINEEND_LF )    // default behavior before introducing this property: LF (unix-like)
190 {
191 }
192 
193 VCLXMultiLineEdit::~VCLXMultiLineEdit()
194 {
195 }
196 
197 ::com::sun::star::uno::Any VCLXMultiLineEdit::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
198 {
199 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
200 										SAL_STATIC_CAST( ::com::sun::star::awt::XTextComponent*, this ),
201 										SAL_STATIC_CAST( ::com::sun::star::awt::XTextArea*, this ),
202 										SAL_STATIC_CAST( ::com::sun::star::awt::XTextLayoutConstrains*, this ),
203 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
204 	return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
205 }
206 
207 // ::com::sun::star::lang::XTypeProvider
208 IMPL_XTYPEPROVIDER_START( VCLXMultiLineEdit )
209 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent>* ) NULL ),
210 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextArea>* ) NULL ),
211 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains>* ) NULL ),
212 	VCLXWindow::getTypes()
213 IMPL_XTYPEPROVIDER_END
214 
215 void VCLXMultiLineEdit::addTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
216 {
217 	maTextListeners.addInterface( l );
218 }
219 
220 void VCLXMultiLineEdit::removeTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
221 {
222 	maTextListeners.removeInterface( l );
223 }
224 
225 void VCLXMultiLineEdit::setText( const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
226 {
227 	::vos::OGuard aGuard( GetMutex() );
228 
229 	MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
230 	if ( pEdit )
231 	{
232 		pEdit->SetText( aText );
233 
234         // #107218# Call same listeners like VCL would do after user interaction
235         SetSynthesizingVCLEvent( sal_True );
236         pEdit->SetModifyFlag();
237         pEdit->Modify();
238         SetSynthesizingVCLEvent( sal_False );
239 	}
240 }
241 
242 void VCLXMultiLineEdit::insertText( const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
243 {
244 	::vos::OGuard aGuard( GetMutex() );
245 
246 	MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
247 	if ( pEdit )
248 	{
249 		setSelection( rSel );
250 		pEdit->ReplaceSelected( aText );
251 	}
252 }
253 
254 ::rtl::OUString VCLXMultiLineEdit::getText() throw(::com::sun::star::uno::RuntimeException)
255 {
256 	::vos::OGuard aGuard( GetMutex() );
257 
258 	::rtl::OUString aText;
259 	MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
260 	if ( pEdit )
261 		aText = pEdit->GetText( meLineEndType );
262 	return aText;
263 }
264 
265 ::rtl::OUString VCLXMultiLineEdit::getSelectedText() throw(::com::sun::star::uno::RuntimeException)
266 {
267 	::vos::OGuard aGuard( GetMutex() );
268 
269 	::rtl::OUString aText;
270 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
271 	if ( pMultiLineEdit)
272 		aText = pMultiLineEdit->GetSelected( meLineEndType );
273 	return aText;
274 
275 }
276 
277 void VCLXMultiLineEdit::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw(::com::sun::star::uno::RuntimeException)
278 {
279 	::vos::OGuard aGuard( GetMutex() );
280 
281 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
282 	if ( pMultiLineEdit )
283 	{
284 		pMultiLineEdit->SetSelection( Selection( aSelection.Min, aSelection.Max ) );
285 	}
286 }
287 
288 ::com::sun::star::awt::Selection VCLXMultiLineEdit::getSelection() throw(::com::sun::star::uno::RuntimeException)
289 {
290 	::vos::OGuard aGuard( GetMutex() );
291 
292 	::com::sun::star::awt::Selection aSel;
293 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
294 	if ( pMultiLineEdit )
295 	{
296 		aSel.Min = pMultiLineEdit->GetSelection().Min();
297 		aSel.Max = pMultiLineEdit->GetSelection().Max();
298 	}
299 	return aSel;
300 }
301 
302 sal_Bool VCLXMultiLineEdit::isEditable() throw(::com::sun::star::uno::RuntimeException)
303 {
304 	::vos::OGuard aGuard( GetMutex() );
305 
306 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
307 	return ( pMultiLineEdit && !pMultiLineEdit->IsReadOnly() && pMultiLineEdit->IsEnabled() ) ? sal_True : sal_False;
308 }
309 
310 void VCLXMultiLineEdit::setEditable( sal_Bool bEditable ) throw(::com::sun::star::uno::RuntimeException)
311 {
312 	::vos::OGuard aGuard( GetMutex() );
313 
314 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
315 	if ( pMultiLineEdit )
316 		pMultiLineEdit->SetReadOnly( !bEditable );
317 }
318 
319 void VCLXMultiLineEdit::setMaxTextLen( sal_Int16 nLen ) throw(::com::sun::star::uno::RuntimeException)
320 {
321 	::vos::OGuard aGuard( GetMutex() );
322 
323 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
324 	if ( pMultiLineEdit )
325 		pMultiLineEdit->SetMaxTextLen( nLen );
326 }
327 
328 sal_Int16 VCLXMultiLineEdit::getMaxTextLen() throw(::com::sun::star::uno::RuntimeException)
329 {
330 	::vos::OGuard aGuard( GetMutex() );
331 
332 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*) GetWindow();
333 	return pMultiLineEdit ? (sal_Int16)pMultiLineEdit->GetMaxTextLen() : (sal_Int16)0;
334 }
335 
336 ::rtl::OUString VCLXMultiLineEdit::getTextLines() throw(::com::sun::star::uno::RuntimeException)
337 {
338 	::vos::OGuard aGuard( GetMutex() );
339 
340 	::rtl::OUString aText;
341 	MultiLineEdit* pEdit = (MultiLineEdit*)GetWindow();
342 	if ( pEdit )
343 		aText = pEdit->GetTextLines( meLineEndType );
344 	return aText;
345 }
346 
347 ::com::sun::star::awt::Size VCLXMultiLineEdit::getMinimumSize() throw(::com::sun::star::uno::RuntimeException)
348 {
349 	::vos::OGuard aGuard( GetMutex() );
350 
351 	::com::sun::star::awt::Size aSz;
352 	MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
353 	if ( pEdit )
354 		aSz = AWTSize(pEdit->CalcMinimumSize());
355 	return aSz;
356 }
357 
358 ::com::sun::star::awt::Size VCLXMultiLineEdit::getPreferredSize() throw(::com::sun::star::uno::RuntimeException)
359 {
360 	return getMinimumSize();
361 }
362 
363 ::com::sun::star::awt::Size VCLXMultiLineEdit::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException)
364 {
365 	::vos::OGuard aGuard( GetMutex() );
366 
367 	::com::sun::star::awt::Size aSz = rNewSize;
368 	MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
369 	if ( pEdit )
370 		aSz = AWTSize(pEdit->CalcAdjustedSize( VCLSize(rNewSize )));
371 	return aSz;
372 }
373 
374 ::com::sun::star::awt::Size VCLXMultiLineEdit::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(::com::sun::star::uno::RuntimeException)
375 {
376 	::vos::OGuard aGuard( GetMutex() );
377 
378 	::com::sun::star::awt::Size aSz;
379 	MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
380 	if ( pEdit )
381 		aSz = AWTSize(pEdit->CalcSize( nCols, nLines ));
382 	return aSz;
383 }
384 
385 void VCLXMultiLineEdit::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException)
386 {
387 	::vos::OGuard aGuard( GetMutex() );
388 
389 	nCols = nLines = 0;
390 	MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
391 	if ( pEdit )
392 	{
393 		sal_uInt16 nC, nL;
394 		pEdit->GetMaxVisColumnsAndLines( nC, nL );
395 		nCols = nC;
396 		nLines = nL;
397 	}
398 }
399 
400 void VCLXMultiLineEdit::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
401 {
402 	switch ( rVclWindowEvent.GetId() )
403 	{
404 		case VCLEVENT_EDIT_MODIFY:
405         {
406 		    if ( maTextListeners.getLength() )
407 		    {
408 	            ::com::sun::star::awt::TextEvent aEvent;
409 	            aEvent.Source = (::cppu::OWeakObject*)this;
410 	            maTextListeners.textChanged( aEvent );
411 		    }
412         }
413         break;
414 		default:
415         {
416 			VCLXWindow::ProcessWindowEvent( rVclWindowEvent );
417         }
418 		break;
419 	}
420 }
421 
422 void VCLXMultiLineEdit::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
423 {
424 	::vos::OGuard aGuard( GetMutex() );
425 
426 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*)GetWindow();
427 	if ( pMultiLineEdit )
428 	{
429 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
430 		switch ( nPropType )
431 		{
432             case BASEPROPERTY_LINE_END_FORMAT:
433             {
434                 sal_Int16 nLineEndType = ::com::sun::star::awt::LineEndFormat::LINE_FEED;
435                 OSL_VERIFY( Value >>= nLineEndType );
436                 switch ( nLineEndType )
437                 {
438                 case ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN:           meLineEndType = LINEEND_CR; break;
439                 case ::com::sun::star::awt::LineEndFormat::LINE_FEED:                 meLineEndType = LINEEND_LF; break;
440                 case ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: meLineEndType = LINEEND_CRLF; break;
441                 default: DBG_ERROR( "VCLXMultiLineEdit::setProperty: invalid line end value!" ); break;
442                 }
443             }
444             break;
445 
446 			case BASEPROPERTY_READONLY:
447 			{
448 				sal_Bool b = sal_Bool();
449 				if ( Value >>= b )
450 					pMultiLineEdit->SetReadOnly( b );
451 			}
452 			break;
453 			case BASEPROPERTY_MAXTEXTLEN:
454 			{
455 				sal_Int16 n = sal_Int16();
456 				if ( Value >>= n )
457 					pMultiLineEdit->SetMaxTextLen( n );
458 			}
459 			break;
460 			case BASEPROPERTY_HIDEINACTIVESELECTION:
461 			{
462 				sal_Bool b = sal_Bool();
463 				if ( Value >>= b )
464                 {
465 					pMultiLineEdit->EnableFocusSelectionHide( b );
466                     lcl_setWinBits( pMultiLineEdit, WB_NOHIDESELECTION, !b );
467                 }
468 			}
469 			break;
470 			default:
471 			{
472 				VCLXWindow::setProperty( PropertyName, Value );
473 			}
474 		}
475 	}
476 }
477 
478 ::com::sun::star::uno::Any VCLXMultiLineEdit::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
479 {
480 	::vos::OGuard aGuard( GetMutex() );
481 
482 	::com::sun::star::uno::Any aProp;
483 	MultiLineEdit* pMultiLineEdit = (MultiLineEdit*)GetWindow();
484 	if ( pMultiLineEdit )
485 	{
486 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
487 		switch ( nPropType )
488 		{
489             case BASEPROPERTY_LINE_END_FORMAT:
490             {
491                 sal_Int16 nLineEndType = ::com::sun::star::awt::LineEndFormat::LINE_FEED;
492                 switch ( meLineEndType )
493                 {
494                 case LINEEND_CR:   nLineEndType = ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN; break;
495                 case LINEEND_LF:   nLineEndType = ::com::sun::star::awt::LineEndFormat::LINE_FEED; break;
496                 case LINEEND_CRLF: nLineEndType = ::com::sun::star::awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED; break;
497                 default: DBG_ERROR( "VCLXMultiLineEdit::getProperty: invalid line end value!" ); break;
498                 }
499                 aProp <<= nLineEndType;
500             }
501             break;
502 
503 			case BASEPROPERTY_READONLY:
504 			{
505 				aProp <<= pMultiLineEdit->IsReadOnly();
506 			}
507 			break;
508 			case BASEPROPERTY_MAXTEXTLEN:
509 			{
510 				aProp <<= (sal_Int16) pMultiLineEdit->GetMaxTextLen();
511 			}
512 			break;
513 			default:
514 			{
515 				aProp <<= VCLXWindow::getProperty( PropertyName );
516 			}
517 		}
518 	}
519 	return aProp;
520 }
521 
522 void SAL_CALL VCLXMultiLineEdit::setFocus(  ) throw(::com::sun::star::uno::RuntimeException)
523 {
524 	::vos::OGuard aGuard( GetMutex() );
525 
526     // don't grab the focus if we already have it. Reason is that the only thing which the edit
527     // does is forwarding the focus to it's text window. This text window then does a "select all".
528     // So if the text window already has the focus, and we give the focus to the multi line
529     // edit, then all which happens is that everything is selected.
530     // #i27072# - 2004-04-25 - fs@openoffice.org
531     if ( GetWindow() && !GetWindow()->HasChildPathFocus() )
532 		GetWindow()->GrabFocus();
533 }
534 
535 void VCLXMultiLineEdit::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
536 {
537     PushPropertyIds( rIds,
538                      // FIXME: elide duplication ?
539                      BASEPROPERTY_LINE_END_FORMAT,
540                      BASEPROPERTY_READONLY,
541                      BASEPROPERTY_MAXTEXTLEN,
542                      BASEPROPERTY_HIDEINACTIVESELECTION,
543                      0);
544     VCLXWindow::ImplGetPropertyIds( rIds, true );
545 
546 }
547 //	----------------------------------------------------
548 //	class VCLXFileControl
549 //	----------------------------------------------------
550 VCLXFileControl::VCLXFileControl() : maTextListeners( *this )
551 {
552 }
553 
554 VCLXFileControl::~VCLXFileControl()
555 {
556 	FileControl* pControl = (FileControl*) GetWindow();
557 	if ( pControl )
558 		pControl->GetEdit().SetModifyHdl( Link() );
559 }
560 
561 ::com::sun::star::uno::Any VCLXFileControl::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
562 {
563 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
564 										SAL_STATIC_CAST( ::com::sun::star::awt::XTextComponent*, this ),
565 										SAL_STATIC_CAST( ::com::sun::star::awt::XTextLayoutConstrains*, this ),
566 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
567 	return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
568 }
569 
570 // ::com::sun::star::lang::XTypeProvider
571 IMPL_XTYPEPROVIDER_START( VCLXFileControl )
572 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent>* ) NULL ),
573 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains>* ) NULL ),
574 	VCLXWindow::getTypes()
575 IMPL_XTYPEPROVIDER_END
576 
577 void SAL_CALL VCLXFileControl::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
578 {
579 	::vos::OGuard aGuard( GetMutex() );
580 
581 	FileControl* pControl = (FileControl*)GetWindow();
582 	if ( pControl )
583 	{
584 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
585 		switch ( nPropType )
586 		{
587         case BASEPROPERTY_HIDEINACTIVESELECTION:
588         {
589             sal_Bool bValue( sal_False );
590             OSL_VERIFY( Value >>= bValue );
591 
592             lcl_setWinBits( pControl, WB_NOHIDESELECTION, !bValue );
593             lcl_setWinBits( &pControl->GetEdit(), WB_NOHIDESELECTION, !bValue );
594         }
595         break;
596 
597         default:
598             VCLXWindow::setProperty( PropertyName, Value );
599             break;
600         }
601     }
602 }
603 
604 void VCLXFileControl::SetWindow( Window* pWindow )
605 {
606 	FileControl* pPrevFileControl = dynamic_cast<FileControl*>( GetWindow() );
607 	if ( pPrevFileControl )
608 		pPrevFileControl->GetEdit().SetModifyHdl( Link() );
609 
610 	FileControl* pNewFileControl = dynamic_cast<FileControl*>( pWindow );
611 	if ( pNewFileControl )
612 		pNewFileControl->GetEdit().SetModifyHdl( LINK( this, VCLXFileControl, ModifyHdl ) );
613 
614 	VCLXWindow::SetWindow( pWindow );
615 }
616 
617 void VCLXFileControl::addTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
618 {
619 	maTextListeners.addInterface( l );
620 }
621 
622 void VCLXFileControl::removeTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException)
623 {
624 	maTextListeners.removeInterface( l );
625 }
626 
627 void VCLXFileControl::setText( const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
628 {
629 	::vos::OGuard aGuard( GetMutex() );
630 
631 	Window* pWindow = GetWindow();
632 	if ( pWindow )
633 	{
634 		pWindow->SetText( aText );
635 
636 		// In JAVA wird auch ein textChanged ausgeloest, in VCL nicht.
637 		// ::com::sun::star::awt::Toolkit soll JAVA-komform sein...
638 		ModifyHdl( NULL );
639 	}
640 }
641 
642 void VCLXFileControl::insertText( const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
643 {
644 	::vos::OGuard aGuard( GetMutex() );
645 
646 	FileControl* pFileControl = (FileControl*) GetWindow();
647 	if ( pFileControl )
648 	{
649 		pFileControl->GetEdit().SetSelection( Selection( rSel.Min, rSel.Max ) );
650 		pFileControl->GetEdit().ReplaceSelected( aText );
651 	}
652 }
653 
654 ::rtl::OUString VCLXFileControl::getText() throw(::com::sun::star::uno::RuntimeException)
655 {
656 	::vos::OGuard aGuard( GetMutex() );
657 
658 	::rtl::OUString aText;
659 	Window* pWindow = GetWindow();
660 	if ( pWindow )
661 		aText = pWindow->GetText();
662 	return aText;
663 }
664 
665 ::rtl::OUString VCLXFileControl::getSelectedText() throw(::com::sun::star::uno::RuntimeException)
666 {
667 	::vos::OGuard aGuard( GetMutex() );
668 
669 	::rtl::OUString aText;
670 	FileControl* pFileControl = (FileControl*) GetWindow();
671 	if ( pFileControl)
672 		aText = pFileControl->GetEdit().GetSelected();
673 	return aText;
674 
675 }
676 
677 void VCLXFileControl::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw(::com::sun::star::uno::RuntimeException)
678 {
679 	::vos::OGuard aGuard( GetMutex() );
680 
681 	FileControl* pFileControl = (FileControl*) GetWindow();
682 	if ( pFileControl )
683 		pFileControl->GetEdit().SetSelection( Selection( aSelection.Min, aSelection.Max ) );
684 }
685 
686 ::com::sun::star::awt::Selection VCLXFileControl::getSelection() throw(::com::sun::star::uno::RuntimeException)
687 {
688 	::vos::OGuard aGuard( GetMutex() );
689 
690 	::com::sun::star::awt::Selection aSel;
691 	FileControl* pFileControl = (FileControl*) GetWindow();
692 	if ( pFileControl )
693 	{
694 		aSel.Min = pFileControl->GetEdit().GetSelection().Min();
695 		aSel.Max = pFileControl->GetEdit().GetSelection().Max();
696 	}
697 	return aSel;
698 }
699 
700 sal_Bool VCLXFileControl::isEditable() throw(::com::sun::star::uno::RuntimeException)
701 {
702 	::vos::OGuard aGuard( GetMutex() );
703 
704 	FileControl* pFileControl = (FileControl*) GetWindow();
705 	return ( pFileControl && !pFileControl->GetEdit().IsReadOnly() && pFileControl->GetEdit().IsEnabled() ) ? sal_True : sal_False;
706 }
707 
708 void VCLXFileControl::setEditable( sal_Bool bEditable ) throw(::com::sun::star::uno::RuntimeException)
709 {
710 	::vos::OGuard aGuard( GetMutex() );
711 
712 	FileControl* pFileControl = (FileControl*) GetWindow();
713 	if ( pFileControl )
714 		pFileControl->GetEdit().SetReadOnly( !bEditable );
715 }
716 
717 void VCLXFileControl::setMaxTextLen( sal_Int16 nLen ) throw(::com::sun::star::uno::RuntimeException)
718 {
719 	::vos::OGuard aGuard( GetMutex() );
720 
721 	FileControl* pFileControl = (FileControl*) GetWindow();
722 	if ( pFileControl )
723 		pFileControl->GetEdit().SetMaxTextLen( nLen );
724 }
725 
726 sal_Int16 VCLXFileControl::getMaxTextLen() throw(::com::sun::star::uno::RuntimeException)
727 {
728 	::vos::OGuard aGuard( GetMutex() );
729 
730 	FileControl* pFileControl = (FileControl*) GetWindow();
731 	return pFileControl ? pFileControl->GetEdit().GetMaxTextLen() : 0;
732 }
733 
734 
735 IMPL_LINK( VCLXFileControl, ModifyHdl, Edit*, EMPTYARG )
736 {
737 	::com::sun::star::awt::TextEvent aEvent;
738 	aEvent.Source = (::cppu::OWeakObject*)this;
739 	maTextListeners.textChanged( aEvent );
740 
741 	return 1;
742 }
743 
744 ::com::sun::star::awt::Size VCLXFileControl::getMinimumSize() throw(::com::sun::star::uno::RuntimeException)
745 {
746 	::vos::OGuard aGuard( GetMutex() );
747 
748 	::com::sun::star::awt::Size aSz;
749 	FileControl* pControl = (FileControl*) GetWindow();
750 	if ( pControl )
751 	{
752 		Size aTmpSize = pControl->GetEdit().CalcMinimumSize();
753 		aTmpSize.Width() += pControl->GetButton().CalcMinimumSize().Width();
754 		aSz = AWTSize(pControl->CalcWindowSize( aTmpSize ));
755 	}
756 	return aSz;
757 }
758 
759 ::com::sun::star::awt::Size VCLXFileControl::getPreferredSize() throw(::com::sun::star::uno::RuntimeException)
760 {
761 	::com::sun::star::awt::Size aSz = getMinimumSize();
762 	aSz.Height += 4;
763 	return aSz;
764 }
765 
766 ::com::sun::star::awt::Size VCLXFileControl::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException)
767 {
768 	::vos::OGuard aGuard( GetMutex() );
769 
770 	::com::sun::star::awt::Size aSz =rNewSize;
771 	FileControl* pControl = (FileControl*) GetWindow();
772 	if ( pControl )
773 	{
774 		::com::sun::star::awt::Size aMinSz = getMinimumSize();
775 		if ( aSz.Height != aMinSz.Height )
776 			aSz.Height = aMinSz.Height;
777 	}
778 	return aSz;
779 }
780 
781 ::com::sun::star::awt::Size VCLXFileControl::getMinimumSize( sal_Int16 nCols, sal_Int16 ) throw(::com::sun::star::uno::RuntimeException)
782 {
783 	::vos::OGuard aGuard( GetMutex() );
784 
785 	::com::sun::star::awt::Size aSz;
786 	FileControl* pControl = (FileControl*) GetWindow();
787 	if ( pControl )
788 	{
789 		aSz = AWTSize(pControl->GetEdit().CalcSize( nCols ));
790 		aSz.Width += pControl->GetButton().CalcMinimumSize().Width();
791 	}
792 	return aSz;
793 }
794 
795 void VCLXFileControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException)
796 {
797 	::vos::OGuard aGuard( GetMutex() );
798 
799 	nCols = 0;
800 	nLines = 1;
801 	FileControl* pControl = (FileControl*) GetWindow();
802 	if ( pControl )
803 		nCols = (sal_Int16) pControl->GetEdit().GetMaxVisChars();
804 }
805 
806 void VCLXFileControl::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
807 {
808     PushPropertyIds( rIds,
809                      // FIXME: elide duplication ?
810                      BASEPROPERTY_HIDEINACTIVESELECTION,
811                      0);
812     VCLXWindow::ImplGetPropertyIds( rIds, true );
813 }
814 
815 
816 //	----------------------------------------------------
817 //	class SVTXFormattedField
818 //	----------------------------------------------------
819 // --------------------------------------------------------------------------------------
820 SVTXFormattedField::SVTXFormattedField()
821 	:m_pCurrentSupplier(NULL)
822 	,bIsStandardSupplier(sal_True)
823 	,nKeyToSetDelayed(-1)
824 {
825 }
826 
827 // --------------------------------------------------------------------------------------
828 SVTXFormattedField::~SVTXFormattedField()
829 {
830 	if (m_pCurrentSupplier)
831 	{
832 		m_pCurrentSupplier->release();
833 		m_pCurrentSupplier = NULL;
834 	}
835 }
836 
837 // --------------------------------------------------------------------------------------
838 void SVTXFormattedField::SetWindow( Window* _pWindow )
839 {
840 	VCLXSpinField::SetWindow(_pWindow);
841 	if (GetFormattedField())
842 		GetFormattedField()->SetAutoColor(sal_True);
843 }
844 
845 // --------------------------------------------------------------------------------------
846 void SVTXFormattedField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
847 {
848 	::vos::OGuard aGuard( GetMutex() );
849 
850 	FormattedField* pField = GetFormattedField();
851 	if ( pField )
852 	{
853 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
854 		switch (nPropType)
855 		{
856             case BASEPROPERTY_ENFORCE_FORMAT:
857             {
858                 sal_Bool bEnable( sal_True );
859                 if ( Value >>= bEnable )
860                     pField->EnableNotANumber( !bEnable );
861             }
862             break;
863 
864 			case BASEPROPERTY_EFFECTIVE_MIN:
865 			case BASEPROPERTY_VALUEMIN_DOUBLE:
866 				SetMinValue(Value);
867 				break;
868 
869 			case BASEPROPERTY_EFFECTIVE_MAX:
870 			case BASEPROPERTY_VALUEMAX_DOUBLE:
871 				SetMaxValue(Value);
872 				break;
873 
874 			case BASEPROPERTY_EFFECTIVE_DEFAULT:
875 				SetDefaultValue(Value);
876 				break;
877 
878             case BASEPROPERTY_TREATASNUMBER:
879             {
880                 sal_Bool b = sal_Bool();
881                 if ( Value >>= b )
882                     SetTreatAsNumber(b);
883             }
884             break;
885 
886 			case BASEPROPERTY_FORMATSSUPPLIER:
887 				if (!Value.hasValue())
888 					setFormatsSupplier(::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > (NULL));
889 				else
890 				{
891 					::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > xNFS;
892 					if ( Value >>= xNFS )
893 						setFormatsSupplier(xNFS);
894 				}
895 				break;
896 			case BASEPROPERTY_FORMATKEY:
897 				if (!Value.hasValue())
898 					setFormatKey(0);
899 				else
900 				{
901 					sal_Int32 n = 0;
902 					if ( Value >>= n )
903 						setFormatKey(n);
904 				}
905 				break;
906 
907 			case BASEPROPERTY_EFFECTIVE_VALUE:
908 			case BASEPROPERTY_VALUE_DOUBLE:
909 			{
910 				const ::com::sun::star::uno::TypeClass rTC = Value.getValueType().getTypeClass();
911 				if (rTC != ::com::sun::star::uno::TypeClass_STRING)
912 					// no string
913 					if (rTC != ::com::sun::star::uno::TypeClass_DOUBLE)
914 						// no double
915 						if (Value.hasValue())
916 						{	// but a value
917 							// try if it is something converitble
918 							sal_Int32 nValue = 0;
919 							if (!(Value >>= nValue))
920 								throw ::com::sun::star::lang::IllegalArgumentException();
921 							SetValue(::com::sun::star::uno::makeAny((double)nValue));
922 							break;
923 						}
924 
925 				SetValue(Value);
926 			}
927 			break;
928 			case BASEPROPERTY_VALUESTEP_DOUBLE:
929 			{
930 				double d = 0.0;
931 				if ( Value >>= d )
932 		 			pField->SetSpinSize( d );
933 				else
934 				{
935 					sal_Int32 n = 0;
936 					if ( Value >>= n )
937 		 				pField->SetSpinSize( n );
938 				}
939 			}
940 			break;
941 			case BASEPROPERTY_DECIMALACCURACY:
942 			{
943 				sal_Int32 n = 0;
944 				if ( Value >>= n )
945 			 		pField->SetDecimalDigits( (sal_uInt16)n );
946 			}
947 			break;
948 			case BASEPROPERTY_NUMSHOWTHOUSANDSEP:
949 			{
950 					sal_Bool b = sal_Bool();
951 					if ( Value >>= b )
952 			 		pField->SetThousandsSep( b );
953 			}
954 			break;
955 
956 			default:
957 				VCLXSpinField::setProperty( PropertyName, Value );
958 		}
959 
960 		if (BASEPROPERTY_TEXTCOLOR == nPropType)
961 		{	// after setting a new text color, think again about the AutoColor flag of the control
962 			// 17.05.2001 - 86859 - frank.schoenheit@germany.sun.com
963 			pField->SetAutoColor(!Value.hasValue());
964 		}
965 	}
966 	else
967 		VCLXSpinField::setProperty( PropertyName, Value );
968 }
969 
970 // --------------------------------------------------------------------------------------
971 ::com::sun::star::uno::Any SVTXFormattedField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
972 {
973 	::vos::OGuard aGuard( GetMutex() );
974 
975 	::com::sun::star::uno::Any aReturn;
976 
977 	FormattedField* pField = GetFormattedField();
978 	if ( pField )
979 	{
980 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
981 		switch (nPropType)
982 		{
983 			case BASEPROPERTY_EFFECTIVE_MIN:
984 			case BASEPROPERTY_VALUEMIN_DOUBLE:
985 				aReturn <<= GetMinValue();
986 				break;
987 
988 			case BASEPROPERTY_EFFECTIVE_MAX:
989 			case BASEPROPERTY_VALUEMAX_DOUBLE:
990 				aReturn <<= GetMaxValue();
991 				break;
992 
993 			case BASEPROPERTY_EFFECTIVE_DEFAULT:
994 				aReturn <<= GetDefaultValue();
995 				break;
996 
997 			case BASEPROPERTY_TREATASNUMBER:
998 				aReturn <<= GetTreatAsNumber();
999 				break;
1000 
1001 			case BASEPROPERTY_EFFECTIVE_VALUE:
1002 			case BASEPROPERTY_VALUE_DOUBLE:
1003 				aReturn <<= GetValue();
1004 				break;
1005 
1006 			case BASEPROPERTY_VALUESTEP_DOUBLE:
1007 				aReturn <<= pField->GetSpinSize();
1008 				break;
1009 
1010 			case BASEPROPERTY_DECIMALACCURACY:
1011 				aReturn <<= pField->GetDecimalDigits();
1012 				break;
1013 
1014 			case BASEPROPERTY_FORMATSSUPPLIER:
1015 			{
1016 				if (!bIsStandardSupplier)
1017 				{	// ansonsten void
1018 					::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = getFormatsSupplier();
1019 					aReturn <<= xSupplier;
1020 				}
1021 			}
1022 			break;
1023 
1024 			case BASEPROPERTY_FORMATKEY:
1025 			{
1026 				if (!bIsStandardSupplier)
1027 					aReturn <<= getFormatKey();
1028 			}
1029 			break;
1030 
1031 			default:
1032 				aReturn <<= VCLXSpinField::getProperty(PropertyName);
1033 		}
1034 	}
1035 	return aReturn;
1036 }
1037 
1038 // --------------------------------------------------------------------------------------
1039 ::com::sun::star::uno::Any SVTXFormattedField::convertEffectiveValue(const ::com::sun::star::uno::Any& rValue)
1040 {
1041 	::com::sun::star::uno::Any aReturn;
1042 
1043 	FormattedField* pField = GetFormattedField();
1044 	if (!pField)
1045 		return aReturn;
1046 
1047 	switch (rValue.getValueType().getTypeClass())
1048 	{
1049 		case ::com::sun::star::uno::TypeClass_DOUBLE:
1050 			if (pField->TreatingAsNumber())
1051 			{
1052 				double d = 0.0;
1053 				rValue >>= d;
1054 				aReturn <<= d;
1055 			}
1056 			else
1057 			{
1058 				SvNumberFormatter* pFormatter = pField->GetFormatter();
1059 				if (!pFormatter)
1060 					pFormatter = pField->StandardFormatter();
1061 					// should never fail
1062 
1063 				Color* pDum;
1064 				double d = 0.0;
1065 				rValue >>= d;
1066 				String sConverted;
1067 				pFormatter->GetOutputString(d, 0, sConverted, &pDum);
1068 				aReturn <<= ::rtl::OUString( sConverted );
1069 			}
1070 			break;
1071 		case ::com::sun::star::uno::TypeClass_STRING:
1072 		{
1073 			::rtl::OUString aStr;
1074 			rValue >>= aStr;
1075 			String sValue = aStr;
1076 			if (pField->TreatingAsNumber())
1077 			{
1078 				SvNumberFormatter* pFormatter = pField->GetFormatter();
1079 				if (!pFormatter)
1080 					pFormatter = pField->StandardFormatter();
1081 
1082 				double dVal;
1083 				sal_uInt32 nTestFormat(0);
1084 				if (!pFormatter->IsNumberFormat(sValue, nTestFormat, dVal))
1085 					aReturn.clear();
1086 				aReturn <<=dVal;
1087 			}
1088 			else
1089 				aReturn <<= aStr;
1090 		}
1091 		break;
1092 		default:
1093 			aReturn.clear();
1094 			break;
1095 	}
1096 	return aReturn;
1097 }
1098 
1099 // --------------------------------------------------------------------------------------
1100 void SVTXFormattedField::SetMinValue(const ::com::sun::star::uno::Any& rValue)
1101 {
1102 	FormattedField* pField = GetFormattedField();
1103 	if (!pField)
1104 		return;
1105 
1106 	switch (rValue.getValueType().getTypeClass())
1107 
1108 	{
1109 		case ::com::sun::star::uno::TypeClass_DOUBLE:
1110         {
1111 			double d = 0.0;
1112 			rValue >>= d;
1113 			pField->SetMinValue(d);
1114         }
1115 			break;
1116 		default:
1117 			DBG_ASSERT(rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID, "SVTXFormattedField::SetMinValue : invalid argument (an exception will be thrown) !");
1118 			if ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID )
1119 
1120 			{
1121 				throw ::com::sun::star::lang::IllegalArgumentException();
1122 			}
1123 			pField->ClearMinValue();
1124 			break;
1125 	}
1126 }
1127 
1128 // --------------------------------------------------------------------------------------
1129 ::com::sun::star::uno::Any SVTXFormattedField::GetMinValue()
1130 {
1131 	FormattedField* pField = GetFormattedField();
1132 	if (!pField || !pField->HasMinValue())
1133 		return ::com::sun::star::uno::Any();
1134 
1135 	::com::sun::star::uno::Any aReturn;
1136 	aReturn <<= pField->GetMinValue();
1137 	return aReturn;
1138 }
1139 
1140 // --------------------------------------------------------------------------------------
1141 void SVTXFormattedField::SetMaxValue(const ::com::sun::star::uno::Any& rValue)
1142 {
1143 	FormattedField* pField = GetFormattedField();
1144 	if (!pField)
1145 		return;
1146 
1147 	switch (rValue.getValueType().getTypeClass())
1148 
1149 	{
1150 		case ::com::sun::star::uno::TypeClass_DOUBLE:
1151         {
1152 			double d = 0.0;
1153 			rValue >>= d;
1154 			pField->SetMaxValue(d);
1155         }
1156 			break;
1157 		default:
1158 			if (rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID)
1159 
1160 			{
1161 				throw ::com::sun::star::lang::IllegalArgumentException();
1162 			}
1163 			pField->ClearMaxValue();
1164 			break;
1165 	}
1166 }
1167 
1168 // --------------------------------------------------------------------------------------
1169 ::com::sun::star::uno::Any SVTXFormattedField::GetMaxValue()
1170 {
1171 	FormattedField* pField = GetFormattedField();
1172 	if (!pField || !pField->HasMaxValue())
1173 		return ::com::sun::star::uno::Any();
1174 
1175 	::com::sun::star::uno::Any aReturn;
1176 	aReturn <<= pField->GetMaxValue();
1177 	return aReturn;
1178 }
1179 
1180 // --------------------------------------------------------------------------------------
1181 void SVTXFormattedField::SetDefaultValue(const ::com::sun::star::uno::Any& rValue)
1182 {
1183 	FormattedField* pField = GetFormattedField();
1184 	if (!pField)
1185 		return;
1186 
1187 	::com::sun::star::uno::Any aConverted = convertEffectiveValue(rValue);
1188 
1189 	switch (aConverted.getValueType().getTypeClass())
1190 
1191 	{
1192 		case ::com::sun::star::uno::TypeClass_DOUBLE:
1193 		{
1194 			double d = 0.0;
1195 			aConverted >>= d;
1196 			pField->SetDefaultValue(d);
1197 		}
1198 		break;
1199 		case ::com::sun::star::uno::TypeClass_STRING:
1200 		{
1201 			::rtl::OUString aStr;
1202 			aConverted >>= aStr;
1203 			pField->SetDefaultText( aStr );
1204 		}
1205 		break;
1206 		default:
1207 			pField->EnableEmptyField(sal_True);
1208 				// nur noch void erlaubt
1209 			break;
1210 	}
1211 }
1212 
1213 // --------------------------------------------------------------------------------------
1214 ::com::sun::star::uno::Any SVTXFormattedField::GetDefaultValue()
1215 {
1216 	FormattedField* pField = GetFormattedField();
1217 	if (!pField || pField->IsEmptyFieldEnabled())
1218 		return ::com::sun::star::uno::Any();
1219 
1220 	::com::sun::star::uno::Any aReturn;
1221 	if (pField->TreatingAsNumber())
1222 		aReturn <<= pField->GetDefaultValue();
1223 	else
1224 		aReturn <<= ::rtl::OUString( pField->GetDefaultText() );
1225 	return aReturn;
1226 }
1227 
1228 // --------------------------------------------------------------------------------------
1229 sal_Bool SVTXFormattedField::GetTreatAsNumber()
1230 {
1231 	FormattedField* pField = GetFormattedField();
1232 	if (pField)
1233 		return pField->TreatingAsNumber();
1234 
1235 	return sal_True;
1236 }
1237 
1238 // --------------------------------------------------------------------------------------
1239 void SVTXFormattedField::SetTreatAsNumber(sal_Bool bSet)
1240 {
1241 	FormattedField* pField = GetFormattedField();
1242 	if (pField)
1243 		pField->TreatAsNumber(bSet);
1244 }
1245 
1246 // --------------------------------------------------------------------------------------
1247 ::com::sun::star::uno::Any SVTXFormattedField::GetValue()
1248 {
1249 	FormattedField* pField = GetFormattedField();
1250 	if (!pField)
1251 		return ::com::sun::star::uno::Any();
1252 
1253 	::com::sun::star::uno::Any aReturn;
1254 	if (!pField->TreatingAsNumber())
1255 	{
1256 		::rtl::OUString sText = pField->GetTextValue();
1257 		aReturn <<= sText;
1258 	}
1259 	else
1260 	{
1261 		if (pField->GetText().Len())	// empty wird erst mal standardmaessig als void nach draussen gereicht
1262 			aReturn <<= pField->GetValue();
1263 	}
1264 
1265 	return aReturn;
1266 }
1267 
1268 // --------------------------------------------------------------------------------------
1269 void SVTXFormattedField::SetValue(const ::com::sun::star::uno::Any& rValue)
1270 {
1271 	FormattedField* pField = GetFormattedField();
1272 	if (!pField)
1273 		return;
1274 
1275 	if (!rValue.hasValue())
1276 	{
1277 		pField->SetText(String());
1278 	}
1279 	else
1280 	{
1281 		if (rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_DOUBLE )
1282 		{
1283 			double d = 0.0;
1284 			rValue >>= d;
1285 			pField->SetValue(d);
1286 		}
1287 		else
1288 		{
1289 			DBG_ASSERT(rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_STRING, "SVTXFormattedField::SetValue : invalid argument !");
1290 
1291 			::rtl::OUString sText;
1292 			rValue >>= sText;
1293 			String aStr( sText );
1294 			if (!pField->TreatingAsNumber())
1295 				pField->SetTextFormatted(aStr);
1296 			else
1297 				pField->SetTextValue(aStr);
1298 		}
1299 	}
1300 //	NotifyTextListeners();
1301 }
1302 
1303 // --------------------------------------------------------------------------------------
1304 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >  SVTXFormattedField::getFormatsSupplier(void) const
1305 {
1306 	return ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > ((::com::sun::star::util::XNumberFormatsSupplier*)m_pCurrentSupplier);
1307 }
1308 
1309 // --------------------------------------------------------------------------------------
1310 void SVTXFormattedField::setFormatsSupplier(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > & xSupplier)
1311 {
1312 	FormattedField* pField = GetFormattedField();
1313 
1314 	SvNumberFormatsSupplierObj* pNew = NULL;
1315 	if (!xSupplier.is())
1316 	{
1317 		if (pField)
1318 		{
1319 			pNew = new SvNumberFormatsSupplierObj(pField->StandardFormatter());
1320 			bIsStandardSupplier = sal_True;
1321 		}
1322 	}
1323 	else
1324 	{
1325 		pNew = SvNumberFormatsSupplierObj::getImplementation(xSupplier);
1326 		bIsStandardSupplier = sal_False;
1327 	}
1328 
1329 	if (!pNew)
1330 		return;		// TODO : wie das behandeln ?
1331 
1332 	if (m_pCurrentSupplier)
1333 		m_pCurrentSupplier->release();
1334 	m_pCurrentSupplier = pNew;
1335 	m_pCurrentSupplier->acquire();
1336 	if (pField)
1337 	{
1338 		// den aktuellen Value mit hinueberretten
1339 		::com::sun::star::uno::Any aCurrent = GetValue();
1340 		pField->SetFormatter(m_pCurrentSupplier->GetNumberFormatter(), sal_False);
1341 		if (nKeyToSetDelayed != -1)
1342 		{
1343 			pField->SetFormatKey(nKeyToSetDelayed);
1344 			nKeyToSetDelayed = -1;
1345 		}
1346 		SetValue(aCurrent);
1347 		NotifyTextListeners();
1348 	}
1349 }
1350 
1351 // --------------------------------------------------------------------------------------
1352 sal_Int32 SVTXFormattedField::getFormatKey(void) const
1353 {
1354 	FormattedField* pField = GetFormattedField();
1355 	return pField ? pField->GetFormatKey() : 0;
1356 }
1357 
1358 // --------------------------------------------------------------------------------------
1359 void SVTXFormattedField::setFormatKey(sal_Int32 nKey)
1360 {
1361 	FormattedField* pField = GetFormattedField();
1362 	if (pField)
1363 	{
1364 		if (pField->GetFormatter())
1365 			pField->SetFormatKey(nKey);
1366 		else
1367 		{	// Wahrscheinlich bin ich gerade in einem Block, in dem erst der Key und dann der Formatter gesetzt
1368 			// wird, das passiert initial mit ziemlicher Sicherheit, da die Properties in alphabetischer Reihenfolge
1369 			// gesetzt werden, und der FormatsSupplier nun mal vor dem FormatKey kommt
1370 			nKeyToSetDelayed = nKey;
1371 		}
1372 		NotifyTextListeners();
1373 	}
1374 }
1375 
1376 // --------------------------------------------------------------------------------------
1377 void SVTXFormattedField::NotifyTextListeners()
1378 {
1379 	if ( GetTextListeners().getLength() )
1380 	{
1381 		::com::sun::star::awt::TextEvent aEvent;
1382 		aEvent.Source = (::cppu::OWeakObject*)this;
1383 		GetTextListeners().textChanged( aEvent );
1384 	}
1385 }
1386 
1387 void SVTXFormattedField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
1388 {
1389     PushPropertyIds( rIds,
1390                      // FIXME: elide duplication ?
1391                      BASEPROPERTY_EFFECTIVE_MIN,
1392                      BASEPROPERTY_VALUEMIN_DOUBLE,
1393                      BASEPROPERTY_EFFECTIVE_MAX,
1394                      BASEPROPERTY_VALUEMAX_DOUBLE,
1395                      BASEPROPERTY_EFFECTIVE_DEFAULT,
1396                      BASEPROPERTY_TREATASNUMBER,
1397                      BASEPROPERTY_EFFECTIVE_VALUE,
1398                      BASEPROPERTY_VALUE_DOUBLE,
1399                      BASEPROPERTY_VALUESTEP_DOUBLE,
1400                      BASEPROPERTY_DECIMALACCURACY,
1401                      BASEPROPERTY_FORMATSSUPPLIER,
1402                      BASEPROPERTY_NUMSHOWTHOUSANDSEP,
1403                      BASEPROPERTY_FORMATKEY,
1404                      BASEPROPERTY_TREATASNUMBER,
1405                      BASEPROPERTY_ENFORCE_FORMAT,
1406                      0);
1407     VCLXWindow::ImplGetPropertyIds( rIds, true );
1408     VCLXSpinField::ImplGetPropertyIds( rIds );
1409 }
1410 
1411 
1412 //	----------------------------------------------------
1413 //	class SVTXRoadmap
1414 //	----------------------------------------------------
1415 
1416 using namespace svt;
1417 
1418 // --------------------------------------------------------------------------------------
1419 SVTXRoadmap::SVTXRoadmap() : maItemListeners( *this )
1420 {
1421 }
1422 
1423 // --------------------------------------------------------------------------------------
1424 SVTXRoadmap::~SVTXRoadmap()
1425 {
1426 }
1427 
1428 void SVTXRoadmap::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
1429 {
1430 	switch ( rVclWindowEvent.GetId() )
1431 	{
1432 		case VCLEVENT_ROADMAP_ITEMSELECTED:
1433         {
1434         	::vos::OGuard aGuard( GetMutex() );
1435             ::svt::ORoadmap* pField = GetRoadmap();
1436 	        if ( pField )
1437 	        {
1438                 sal_Int16 CurItemID = pField->GetCurrentRoadmapItemID();
1439                 ::com::sun::star::awt::ItemEvent aEvent;
1440                 aEvent.Selected = CurItemID;
1441                 aEvent.Highlighted = CurItemID;
1442                 aEvent.ItemId = CurItemID;
1443                 maItemListeners.itemStateChanged( aEvent );
1444             }
1445         }
1446         break;
1447 		default:
1448             SVTXRoadmap_Base::ProcessWindowEvent( rVclWindowEvent );
1449 		    break;
1450 	}
1451 }
1452 
1453 
1454 void SVTXRoadmap::propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException)
1455 {
1456 	::vos::OGuard aGuard( GetMutex() );
1457     ::svt::ORoadmap* pField = GetRoadmap();
1458 	if ( pField )
1459 	{
1460         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xRoadmapItem;
1461         xRoadmapItem = evt.Source;
1462         sal_Int32 nID = 0;
1463         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropertySet( xRoadmapItem, ::com::sun::star::uno::UNO_QUERY );
1464         ::com::sun::star::uno::Any aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "ID" ));
1465         aValue >>= nID;
1466 
1467         ::com::sun::star::uno::Any rVal = evt.NewValue;
1468         evt.NewValue >>= rVal;
1469         ::rtl::OUString sPropertyName = evt.PropertyName;
1470         if ( sPropertyName.equals(::rtl::OUString::createFromAscii( "Enabled" ) ) )
1471         {
1472             sal_Bool bEnable = false;
1473             evt.NewValue >>= bEnable;
1474             pField->EnableRoadmapItem( (RoadmapTypes::ItemId)nID , bEnable );
1475         }
1476         else if ( sPropertyName.equals(::rtl::OUString::createFromAscii( "Label" ) ) )
1477         {
1478             ::rtl::OUString sLabel;
1479             evt.NewValue >>= sLabel;
1480             pField->ChangeRoadmapItemLabel( (RoadmapTypes::ItemId)nID , sLabel );
1481         }
1482         else if  ( sPropertyName.equals(::rtl::OUString::createFromAscii( "ID" ) ) )
1483         {
1484             sal_Int32 nNewID = 0;
1485             evt.NewValue >>= nNewID;
1486             evt.OldValue >>= nID;
1487             pField->ChangeRoadmapItemID( (RoadmapTypes::ItemId)nID, (RoadmapTypes::ItemId)nNewID );
1488         }
1489     //    else
1490             // Todo: handle Interactive appropriately
1491     }
1492 }
1493 
1494 
1495 void SVTXRoadmap::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException)
1496 {
1497     maItemListeners.addInterface( l );
1498 }
1499 
1500 void SVTXRoadmap::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException)
1501 {
1502     maItemListeners.removeInterface( l );
1503 }
1504 
1505 RMItemData SVTXRoadmap::GetRMItemData( const ::com::sun::star::container::ContainerEvent& _rEvent )
1506 {
1507     RMItemData aCurRMItemData;
1508     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xRoadmapItem;
1509 	_rEvent.Element >>= xRoadmapItem;
1510     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropertySet( xRoadmapItem, ::com::sun::star::uno::UNO_QUERY );
1511 	if ( xPropertySet.is() )
1512     {
1513         ::com::sun::star::uno::Any aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "Label" ));
1514         aValue >>= aCurRMItemData.Label;
1515         aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "ID" ));
1516         aValue >>= aCurRMItemData.n_ID;
1517         aValue = xPropertySet->getPropertyValue(::rtl::OUString::createFromAscii( "Enabled" ));
1518         aValue >>= aCurRMItemData.b_Enabled;
1519     }
1520     return aCurRMItemData;;
1521 }
1522 
1523 void SVTXRoadmap::elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent )throw(::com::sun::star::uno::RuntimeException)
1524 {
1525 	::vos::OGuard aGuard( GetMutex() );
1526     ::svt::ORoadmap* pField = GetRoadmap();
1527 	if ( pField )
1528 	{
1529         RMItemData CurItemData = GetRMItemData(  _rEvent );
1530         sal_Int32 InsertIndex = 0;
1531         _rEvent.Accessor >>= InsertIndex;
1532         pField->InsertRoadmapItem( InsertIndex, CurItemData.Label, (RoadmapTypes::ItemId)CurItemData.n_ID, CurItemData.b_Enabled );
1533     }
1534 }
1535 
1536 void SVTXRoadmap::elementRemoved( const ::com::sun::star::container::ContainerEvent& _rEvent )throw(::com::sun::star::uno::RuntimeException)
1537 {
1538 	::vos::OGuard aGuard( GetMutex() );
1539     ::svt::ORoadmap* pField = GetRoadmap();
1540 	if ( pField )
1541 	{
1542         sal_Int32 DelIndex = 0;
1543         _rEvent.Accessor >>= DelIndex;
1544         pField->DeleteRoadmapItem(DelIndex);
1545 //        pField->GetCurrentRoadmapItem()
1546 //        setProperty(::rtl::OUString.createFromAscii( "CurrentItem" )aAny,
1547     }
1548 }
1549 
1550 void SVTXRoadmap::elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent )throw(::com::sun::star::uno::RuntimeException)
1551 {
1552 	::vos::OGuard aGuard( GetMutex() );
1553     ::svt::ORoadmap* pField = GetRoadmap();
1554 	if ( pField )
1555 	{
1556         RMItemData CurItemData = GetRMItemData(  _rEvent );
1557         sal_Int32 ReplaceIndex = 0;
1558         _rEvent.Accessor >>= ReplaceIndex;
1559         pField->ReplaceRoadmapItem( ReplaceIndex, CurItemData.Label, (RoadmapTypes::ItemId)CurItemData.n_ID, CurItemData.b_Enabled );
1560     }
1561 }
1562 
1563 
1564 
1565 // --------------------------------------------------------------------------------------
1566 void SVTXRoadmap::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
1567 {
1568 	::vos::OGuard aGuard( GetMutex() );
1569 
1570     ::svt::ORoadmap* pField = GetRoadmap();
1571 	if ( pField )
1572 	{
1573 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
1574 		switch (nPropType)
1575 		{
1576 			case BASEPROPERTY_COMPLETE:
1577             {
1578                 sal_Bool b = false;
1579 	    		Value >>= b;
1580                 pField->SetRoadmapComplete( b);
1581             }
1582             break;
1583 
1584 			case BASEPROPERTY_ACTIVATED:
1585             {
1586    		    	sal_Bool b = false;
1587 	    		Value >>= b;
1588                 pField->SetRoadmapInteractive( b);
1589             }
1590 			break;
1591 
1592             case BASEPROPERTY_CURRENTITEMID:
1593             {
1594    				sal_Int32 nId = 0;
1595 				Value >>= nId;
1596                 pField->SelectRoadmapItemByID( (RoadmapTypes::ItemId)nId );
1597             }
1598             break;
1599 
1600             case BASEPROPERTY_TEXT:
1601             {
1602    				::rtl::OUString aStr;
1603 				Value >>= aStr;
1604                 pField->SetText( aStr );
1605                 pField->Invalidate();
1606             }
1607             break;
1608 
1609             default:
1610 				SVTXRoadmap_Base::setProperty( PropertyName, Value );
1611                 break;
1612 		}
1613 
1614 	}
1615 	else
1616 		SVTXRoadmap_Base::setProperty( PropertyName, Value );
1617 }
1618 
1619 
1620 // --------------------------------------------------------------------------------------
1621 ::com::sun::star::uno::Any SVTXRoadmap::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
1622 {
1623 	::vos::OGuard aGuard( GetMutex() );
1624 
1625 	::com::sun::star::uno::Any aReturn;
1626 
1627 	::svt::ORoadmap* pField = GetRoadmap();
1628 	if ( pField )
1629 	{
1630 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
1631 		switch (nPropType)
1632 		{
1633 			case BASEPROPERTY_COMPLETE:
1634                 aReturn <<= pField->IsRoadmapComplete();
1635                 break;
1636 			case BASEPROPERTY_ACTIVATED:
1637                 aReturn <<= pField->IsRoadmapInteractive();
1638 				break;
1639 			case BASEPROPERTY_CURRENTITEMID:
1640                 aReturn <<= pField->GetCurrentRoadmapItemID();
1641                 break;
1642             default:
1643 				aReturn = SVTXRoadmap_Base::getProperty(PropertyName);
1644                 break;
1645 		}
1646 	}
1647 	return aReturn;
1648 }
1649 
1650 void SVTXRoadmap::ImplSetNewImage()
1651 {
1652     OSL_PRECOND( GetWindow(), "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!" );
1653 	::svt::ORoadmap* pButton = static_cast< ::svt::ORoadmap* >( GetWindow() );
1654 	pButton->SetRoadmapBitmap( GetImage().GetBitmapEx() );
1655 }
1656 
1657 void SVTXRoadmap::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
1658 {
1659     PushPropertyIds( rIds,
1660                      BASEPROPERTY_COMPLETE,
1661                      BASEPROPERTY_ACTIVATED,
1662                      BASEPROPERTY_CURRENTITEMID,
1663                      BASEPROPERTY_TEXT,
1664                      0);
1665     VCLXWindow::ImplGetPropertyIds( rIds, true );
1666     VCLXGraphicControl::ImplGetPropertyIds( rIds );
1667 }
1668 
1669 //	----------------------------------------------------
1670 //	class SVTXNumericField
1671 //	----------------------------------------------------
1672 SVTXNumericField::SVTXNumericField()
1673 {
1674 }
1675 
1676 SVTXNumericField::~SVTXNumericField()
1677 {
1678 }
1679 
1680 ::com::sun::star::uno::Any SVTXNumericField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
1681 {
1682 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
1683 										SAL_STATIC_CAST( ::com::sun::star::awt::XNumericField*, this ),
1684 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
1685 	return (aRet.hasValue() ? aRet : SVTXFormattedField::queryInterface( rType ));
1686 }
1687 
1688 // ::com::sun::star::lang::XTypeProvider
1689 IMPL_XTYPEPROVIDER_START( SVTXNumericField )
1690 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XNumericField>* ) NULL ),
1691 	SVTXFormattedField::getTypes()
1692 IMPL_XTYPEPROVIDER_END
1693 
1694 
1695 void SVTXNumericField::setValue( double Value ) throw(::com::sun::star::uno::RuntimeException)
1696 {
1697 	::vos::OGuard aGuard( GetMutex() );
1698 
1699 	FormattedField* pField = GetFormattedField();
1700 	if ( pField )
1701 		pField->SetValue( Value );
1702 }
1703 
1704 double SVTXNumericField::getValue() throw(::com::sun::star::uno::RuntimeException)
1705 {
1706 	::vos::OGuard aGuard( GetMutex() );
1707 
1708 	FormattedField* pField = GetFormattedField();
1709 	return pField ? pField->GetValue() : 0;
1710 }
1711 
1712 void SVTXNumericField::setMin( double Value ) throw(::com::sun::star::uno::RuntimeException)
1713 {
1714 	::vos::OGuard aGuard( GetMutex() );
1715 
1716 	FormattedField* pField = GetFormattedField();
1717 	if ( pField )
1718 		pField->SetMinValue( Value );
1719 }
1720 
1721 double SVTXNumericField::getMin() throw(::com::sun::star::uno::RuntimeException)
1722 {
1723 	::vos::OGuard aGuard( GetMutex() );
1724 
1725 	FormattedField* pField = GetFormattedField();
1726 	return pField ? pField->GetMinValue() : 0;
1727 }
1728 
1729 void SVTXNumericField::setMax( double Value ) throw(::com::sun::star::uno::RuntimeException)
1730 {
1731 	::vos::OGuard aGuard( GetMutex() );
1732 
1733 	FormattedField* pField = GetFormattedField();
1734 	if ( pField )
1735 		pField->SetMaxValue( Value );
1736 }
1737 
1738 double SVTXNumericField::getMax() throw(::com::sun::star::uno::RuntimeException)
1739 {
1740 	::vos::OGuard aGuard( GetMutex() );
1741 
1742 	FormattedField* pField = GetFormattedField();
1743 	return pField ? pField->GetMaxValue() : 0;
1744 }
1745 
1746 void SVTXNumericField::setFirst( double Value ) throw(::com::sun::star::uno::RuntimeException)
1747 {
1748 	::vos::OGuard aGuard( GetMutex() );
1749 
1750 	FormattedField* pField = GetFormattedField();
1751 	if ( pField )
1752 		pField->SetSpinFirst( Value );
1753 }
1754 
1755 double SVTXNumericField::getFirst() throw(::com::sun::star::uno::RuntimeException)
1756 {
1757 	::vos::OGuard aGuard( GetMutex() );
1758 
1759 	FormattedField* pField = GetFormattedField();
1760 	return pField ? pField->GetSpinFirst() : 0;
1761 }
1762 
1763 void SVTXNumericField::setLast( double Value ) throw(::com::sun::star::uno::RuntimeException)
1764 {
1765 	::vos::OGuard aGuard( GetMutex() );
1766 
1767 	FormattedField* pField = GetFormattedField();
1768 	if ( pField )
1769 		pField->SetSpinLast( Value );
1770 }
1771 
1772 double SVTXNumericField::getLast() throw(::com::sun::star::uno::RuntimeException)
1773 {
1774 	::vos::OGuard aGuard( GetMutex() );
1775 
1776 	FormattedField* pField = GetFormattedField();
1777 	return pField ? pField->GetSpinLast() : 0;
1778 }
1779 
1780 void SVTXNumericField::setSpinSize( double Value ) throw(::com::sun::star::uno::RuntimeException)
1781 {
1782 	::vos::OGuard aGuard( GetMutex() );
1783 
1784 	FormattedField* pField = GetFormattedField();
1785 	if ( pField )
1786 		pField->SetSpinSize( Value );
1787 }
1788 
1789 double SVTXNumericField::getSpinSize() throw(::com::sun::star::uno::RuntimeException)
1790 {
1791 	::vos::OGuard aGuard( GetMutex() );
1792 
1793 	FormattedField* pField = GetFormattedField();
1794 	return pField ? pField->GetSpinSize() : 0;
1795 }
1796 
1797 void SVTXNumericField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException)
1798 {
1799 	::vos::OGuard aGuard( GetMutex() );
1800 
1801 	FormattedField* pField = GetFormattedField();
1802 	if ( pField )
1803 		pField->SetDecimalDigits( Value );
1804 }
1805 
1806 sal_Int16 SVTXNumericField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException)
1807 {
1808 	::vos::OGuard aGuard( GetMutex() );
1809 
1810 	FormattedField* pField = GetFormattedField();
1811 	return pField ? pField->GetDecimalDigits() : 0;
1812 }
1813 
1814 void SVTXNumericField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException)
1815 {
1816 	::vos::OGuard aGuard( GetMutex() );
1817 
1818 	FormattedField* pField = GetFormattedField();
1819 	if ( pField )
1820 		pField->SetStrictFormat( bStrict );
1821 }
1822 
1823 sal_Bool SVTXNumericField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException)
1824 {
1825 	::vos::OGuard aGuard( GetMutex() );
1826 
1827 	FormattedField* pField = GetFormattedField();
1828 	return pField ? pField->IsStrictFormat() : sal_False;
1829 }
1830 
1831 void SVTXNumericField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
1832 {
1833     SVTXFormattedField::ImplGetPropertyIds( rIds );
1834 }
1835 
1836 //	----------------------------------------------------
1837 //	class SVTXCurrencyField
1838 //	----------------------------------------------------
1839 SVTXCurrencyField::SVTXCurrencyField()
1840 {
1841 }
1842 
1843 SVTXCurrencyField::~SVTXCurrencyField()
1844 {
1845 }
1846 
1847 ::com::sun::star::uno::Any SVTXCurrencyField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
1848 {
1849 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
1850 										SAL_STATIC_CAST( ::com::sun::star::awt::XCurrencyField*, this ),
1851 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
1852 	return (aRet.hasValue() ? aRet : SVTXFormattedField::queryInterface( rType ));
1853 }
1854 
1855 // ::com::sun::star::lang::XTypeProvider
1856 IMPL_XTYPEPROVIDER_START( SVTXCurrencyField )
1857 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XCurrencyField>* ) NULL ),
1858 	SVTXFormattedField::getTypes()
1859 IMPL_XTYPEPROVIDER_END
1860 
1861 void SVTXCurrencyField::setValue( double Value ) throw(::com::sun::star::uno::RuntimeException)
1862 {
1863 	::vos::OGuard aGuard( GetMutex() );
1864 
1865 	FormattedField* pField = GetFormattedField();
1866 	if ( pField )
1867 		pField->SetValue( Value );
1868 }
1869 
1870 double SVTXCurrencyField::getValue() throw(::com::sun::star::uno::RuntimeException)
1871 {
1872 	::vos::OGuard aGuard( GetMutex() );
1873 
1874 	FormattedField* pField = GetFormattedField();
1875 	return pField ? pField->GetValue() : 0;
1876 }
1877 
1878 void SVTXCurrencyField::setMin( double Value ) throw(::com::sun::star::uno::RuntimeException)
1879 {
1880 	::vos::OGuard aGuard( GetMutex() );
1881 
1882 	FormattedField* pField = GetFormattedField();
1883 	if ( pField )
1884 		pField->SetMinValue( Value );
1885 }
1886 
1887 double SVTXCurrencyField::getMin() throw(::com::sun::star::uno::RuntimeException)
1888 {
1889 	::vos::OGuard aGuard( GetMutex() );
1890 
1891 	FormattedField* pField = GetFormattedField();
1892 	return pField ? pField->GetMinValue() : 0;
1893 }
1894 
1895 void SVTXCurrencyField::setMax( double Value ) throw(::com::sun::star::uno::RuntimeException)
1896 {
1897 	::vos::OGuard aGuard( GetMutex() );
1898 
1899 	FormattedField* pField = GetFormattedField();
1900 	if ( pField )
1901 		pField->SetMaxValue( Value );
1902 }
1903 
1904 double SVTXCurrencyField::getMax() throw(::com::sun::star::uno::RuntimeException)
1905 {
1906 	::vos::OGuard aGuard( GetMutex() );
1907 
1908 	FormattedField* pField = GetFormattedField();
1909 	return pField ? pField->GetMaxValue() : 0;
1910 }
1911 
1912 void SVTXCurrencyField::setFirst( double Value ) throw(::com::sun::star::uno::RuntimeException)
1913 {
1914 	::vos::OGuard aGuard( GetMutex() );
1915 
1916 	FormattedField* pField = GetFormattedField();
1917 	if ( pField )
1918 		pField->SetSpinFirst( Value );
1919 }
1920 
1921 double SVTXCurrencyField::getFirst() throw(::com::sun::star::uno::RuntimeException)
1922 {
1923 	::vos::OGuard aGuard( GetMutex() );
1924 
1925 	FormattedField* pField = GetFormattedField();
1926 	return pField ? pField->GetSpinFirst() : 0;
1927 }
1928 
1929 void SVTXCurrencyField::setLast( double Value ) throw(::com::sun::star::uno::RuntimeException)
1930 {
1931 	::vos::OGuard aGuard( GetMutex() );
1932 
1933 	FormattedField* pField = GetFormattedField();
1934 	if ( pField )
1935 		pField->SetSpinLast( Value );
1936 }
1937 
1938 double SVTXCurrencyField::getLast() throw(::com::sun::star::uno::RuntimeException)
1939 {
1940 	::vos::OGuard aGuard( GetMutex() );
1941 
1942 	FormattedField* pField = GetFormattedField();
1943 	return pField ? pField->GetSpinLast() : 0;
1944 }
1945 
1946 void SVTXCurrencyField::setSpinSize( double Value ) throw(::com::sun::star::uno::RuntimeException)
1947 {
1948 	::vos::OGuard aGuard( GetMutex() );
1949 
1950 	FormattedField* pField = GetFormattedField();
1951 	if ( pField )
1952 		pField->SetSpinSize( Value );
1953 }
1954 
1955 double SVTXCurrencyField::getSpinSize() throw(::com::sun::star::uno::RuntimeException)
1956 {
1957 	::vos::OGuard aGuard( GetMutex() );
1958 
1959 	FormattedField* pField = GetFormattedField();
1960 	return pField ? pField->GetSpinSize() : 0;
1961 }
1962 
1963 void SVTXCurrencyField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException)
1964 {
1965 	::vos::OGuard aGuard( GetMutex() );
1966 
1967 	FormattedField* pField = GetFormattedField();
1968 	if ( pField )
1969 		pField->SetDecimalDigits( Value );
1970 }
1971 
1972 sal_Int16 SVTXCurrencyField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException)
1973 {
1974 	::vos::OGuard aGuard( GetMutex() );
1975 
1976 	FormattedField* pField = GetFormattedField();
1977 	return pField ? pField->GetDecimalDigits() : 0;
1978 }
1979 
1980 void SVTXCurrencyField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException)
1981 {
1982 	::vos::OGuard aGuard( GetMutex() );
1983 
1984 	FormattedField* pField = GetFormattedField();
1985 	if ( pField )
1986 		pField->SetStrictFormat( bStrict );
1987 }
1988 
1989 sal_Bool SVTXCurrencyField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException)
1990 {
1991 	::vos::OGuard aGuard( GetMutex() );
1992 
1993 	FormattedField* pField = GetFormattedField();
1994 	return pField ? pField->IsStrictFormat() : sal_False;
1995 }
1996 
1997 void SVTXCurrencyField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
1998 {
1999 	::vos::OGuard aGuard( GetMutex() );
2000 
2001 	::com::sun::star::uno::Any aReturn;
2002 
2003 	DoubleCurrencyField* pField = (DoubleCurrencyField*)GetFormattedField();
2004 	if ( pField )
2005 	{
2006 #ifdef DBG_UTIL
2007 		String sAssertion( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "SVTXCurrencyField::setProperty(" ) ) );
2008 		sAssertion += String( PropertyName );
2009 		sAssertion.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ") : invalid value !" ) );
2010 #endif
2011 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
2012 		switch (nPropType)
2013 		{
2014 			case BASEPROPERTY_CURRENCYSYMBOL:
2015 			{
2016 				::rtl::OUString aStr;
2017 				Value >>= aStr;
2018 				pField->setCurrencySymbol( aStr );
2019 			}
2020 			break;
2021 			case BASEPROPERTY_CURSYM_POSITION:
2022 			{
2023 				sal_Bool b = false;
2024 				Value >>= b;
2025 				pField->setPrependCurrSym(b);
2026 			}
2027 			break;
2028 
2029 			default:
2030 				SVTXFormattedField::setProperty(PropertyName, Value);
2031 		}
2032 	}
2033 	else
2034 		SVTXFormattedField::setProperty(PropertyName, Value);
2035 }
2036 
2037 ::com::sun::star::uno::Any SVTXCurrencyField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
2038 {
2039 	::vos::OGuard aGuard( GetMutex() );
2040 
2041 	::com::sun::star::uno::Any aReturn;
2042 
2043 	DoubleCurrencyField* pField = (DoubleCurrencyField*)GetFormattedField();
2044 	if ( pField )
2045 	{
2046 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
2047 		switch (nPropType)
2048 		{
2049 			case BASEPROPERTY_CURRENCYSYMBOL:
2050 			{
2051 				aReturn <<= ::rtl::OUString( pField->getCurrencySymbol() );
2052 			}
2053 			break;
2054 			case BASEPROPERTY_CURSYM_POSITION:
2055 			{
2056 				aReturn <<= pField->getPrependCurrSym();
2057 			}
2058 			break;
2059 			default:
2060 				return SVTXFormattedField::getProperty(PropertyName);
2061 		}
2062 	}
2063 	return SVTXFormattedField::getProperty(PropertyName);
2064 }
2065 
2066 void SVTXCurrencyField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
2067 {
2068     PushPropertyIds( rIds,
2069                      BASEPROPERTY_CURRENCYSYMBOL,
2070                      BASEPROPERTY_CURSYM_POSITION,
2071                      0);
2072     SVTXFormattedField::ImplGetPropertyIds( rIds );
2073 }
2074 
2075 
2076 //	----------------------------------------------------
2077 //	class VCLXProgressBar
2078 //	----------------------------------------------------
2079 
2080 VCLXProgressBar::VCLXProgressBar()
2081 			:m_nValue(0)
2082 			,m_nValueMin(0)
2083 			,m_nValueMax(100)
2084 {
2085 }
2086 
2087 VCLXProgressBar::~VCLXProgressBar()
2088 {
2089 }
2090 
2091 void VCLXProgressBar::ImplUpdateValue()
2092 {
2093 	ProgressBar* pProgressBar = (ProgressBar*) GetWindow();
2094 	if ( pProgressBar )
2095 	{
2096 		sal_Int32 nVal;
2097 		sal_Int32 nValMin;
2098 		sal_Int32 nValMax;
2099 
2100 		// check min and max
2101 		if (m_nValueMin < m_nValueMax)
2102 		{
2103 			nValMin = m_nValueMin;
2104 			nValMax = m_nValueMax;
2105 		}
2106 		else
2107 		{
2108 			nValMin = m_nValueMax;
2109 			nValMax = m_nValueMin;
2110 		}
2111 
2112 		// check value
2113 		if (m_nValue < nValMin)
2114 		{
2115 			nVal = nValMin;
2116 		}
2117 		else if (m_nValue > nValMax)
2118 		{
2119 			nVal = nValMax;
2120 		}
2121 		else
2122 		{
2123 			nVal = m_nValue;
2124 		}
2125 
2126 		// calculate percent
2127 		sal_Int32 nPercent;
2128 		if (nValMin != nValMax)
2129 		{
2130 			nPercent = 100 * (nVal - nValMin) / (nValMax - nValMin);
2131 		}
2132 		else
2133 		{
2134 			nPercent = 0;
2135 		}
2136 
2137 		// set progressbar value
2138 		pProgressBar->SetValue( (sal_uInt16) nPercent );
2139 	}
2140 }
2141 
2142 // ::com::sun::star::uno::XInterface
2143 ::com::sun::star::uno::Any VCLXProgressBar::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
2144 {
2145 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
2146 										SAL_STATIC_CAST( ::com::sun::star::awt::XProgressBar*, this ),
2147 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
2148 	return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
2149 }
2150 
2151 // ::com::sun::star::lang::XTypeProvider
2152 IMPL_XTYPEPROVIDER_START( VCLXProgressBar )
2153 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XProgressBar>* ) NULL ),
2154 	VCLXWindow::getTypes()
2155 IMPL_XTYPEPROVIDER_END
2156 
2157 // ::com::sun::star::awt::XProgressBar
2158 void VCLXProgressBar::setForegroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException)
2159 {
2160 	::vos::OGuard aGuard( GetMutex() );
2161 
2162 	Window* pWindow = GetWindow();
2163 	if ( pWindow )
2164 	{
2165 		Color aColor( nColor );
2166 		pWindow->SetControlForeground( aColor );
2167 	}
2168 }
2169 
2170 void VCLXProgressBar::setBackgroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException)
2171 {
2172 	::vos::OGuard aGuard( GetMutex() );
2173 
2174 	Window* pWindow = GetWindow();
2175 	if ( pWindow )
2176 	{
2177 		Color aColor( nColor );
2178 		pWindow->SetBackground( aColor );
2179 		pWindow->SetControlBackground( aColor );
2180 		pWindow->Invalidate();
2181 	}
2182 }
2183 
2184 void VCLXProgressBar::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException)
2185 {
2186 	::vos::OGuard aGuard( GetMutex() );
2187 
2188 	m_nValue = nValue;
2189 	ImplUpdateValue();
2190 }
2191 
2192 void VCLXProgressBar::setRange( sal_Int32 nMin, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException )
2193 {
2194 	::vos::OGuard aGuard( GetMutex() );
2195 
2196 	if ( nMin < nMax )
2197 	{
2198 		// take correct min and max
2199 		m_nValueMin = nMin;
2200 		m_nValueMax = nMax;
2201 	}
2202 	else
2203 	{
2204 		// change min and max
2205 		m_nValueMin = nMax;
2206 		m_nValueMax = nMin;
2207 	}
2208 
2209 	ImplUpdateValue();
2210 }
2211 
2212 sal_Int32 VCLXProgressBar::getValue() throw(::com::sun::star::uno::RuntimeException)
2213 {
2214 	::vos::OGuard aGuard( GetMutex() );
2215 
2216 	return m_nValue;
2217 }
2218 
2219 // ::com::sun::star::awt::VclWindowPeer
2220 void VCLXProgressBar::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException)
2221 {
2222 	::vos::OGuard aGuard( GetMutex() );
2223 
2224     ProgressBar* pProgressBar = (ProgressBar*)GetWindow();
2225     if ( pProgressBar )
2226 	{
2227 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
2228 		switch ( nPropType )
2229 		{
2230 			case BASEPROPERTY_PROGRESSVALUE:
2231 			{
2232 				if ( Value >>= m_nValue )
2233 					ImplUpdateValue();
2234 			}
2235 			break;
2236 			case BASEPROPERTY_PROGRESSVALUE_MIN:
2237 			{
2238 				if ( Value >>= m_nValueMin )
2239 					ImplUpdateValue();
2240 			}
2241 			break;
2242 			case BASEPROPERTY_PROGRESSVALUE_MAX:
2243 			{
2244 				if ( Value >>= m_nValueMax )
2245 					ImplUpdateValue();
2246 			}
2247 			break;
2248 			case BASEPROPERTY_FILLCOLOR:
2249 			{
2250 				Window* pWindow = GetWindow();
2251 				if ( pWindow )
2252 				{
2253 					sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
2254 
2255 					if ( bVoid )
2256 					{
2257 						pWindow->SetControlForeground();
2258 					}
2259 					else
2260 					{
2261 						sal_Int32 nColor = 0;
2262 						if ( Value >>= nColor )
2263 						{
2264 							Color aColor( nColor );
2265 							pWindow->SetControlForeground( aColor );
2266 						}
2267 					}
2268 				}
2269 			}
2270 			break;
2271 			default:
2272 				VCLXWindow::setProperty( PropertyName, Value );
2273                 break;
2274 		}
2275 	}
2276 }
2277 
2278 ::com::sun::star::uno::Any VCLXProgressBar::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
2279 {
2280 	::vos::OGuard aGuard( GetMutex() );
2281 
2282 	::com::sun::star::uno::Any aProp;
2283     ProgressBar* pProgressBar = (ProgressBar*)GetWindow();
2284     if ( pProgressBar )
2285 	{
2286 		sal_uInt16 nPropType = GetPropertyId( PropertyName );
2287 		switch ( nPropType )
2288 		{
2289 			case BASEPROPERTY_PROGRESSVALUE:
2290 			{
2291  				aProp <<= m_nValue;
2292 			}
2293 			break;
2294 			case BASEPROPERTY_PROGRESSVALUE_MIN:
2295 			{
2296  				aProp <<= m_nValueMin;
2297 			}
2298 			break;
2299 			case BASEPROPERTY_PROGRESSVALUE_MAX:
2300 			{
2301  				aProp <<= m_nValueMax;
2302 			}
2303 			break;
2304             default:
2305 				aProp <<= VCLXWindow::getProperty( PropertyName );
2306                 break;
2307 		}
2308 	}
2309 	return aProp;
2310 }
2311 
2312 void VCLXProgressBar::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
2313 {
2314     PushPropertyIds( rIds,
2315                      BASEPROPERTY_PROGRESSVALUE,
2316                      BASEPROPERTY_PROGRESSVALUE_MIN,
2317                      BASEPROPERTY_PROGRESSVALUE_MAX,
2318                      BASEPROPERTY_FILLCOLOR,
2319                      0);
2320     VCLXWindow::ImplGetPropertyIds( rIds, true );
2321 }
2322 
2323 
2324 //	----------------------------------------------------
2325 //	class SVTXDateField
2326 //	----------------------------------------------------
2327 SVTXDateField::SVTXDateField()
2328     :VCLXDateField()
2329 {
2330 }
2331 
2332 SVTXDateField::~SVTXDateField()
2333 {
2334 }
2335 
2336 void SAL_CALL SVTXDateField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException)
2337 {
2338     VCLXDateField::setProperty( PropertyName, Value );
2339 
2340     // some properties need to be forwarded to the sub edit, too
2341     Edit* pSubEdit = GetWindow() ? static_cast< Edit* >( GetWindow() )->GetSubEdit() : NULL;
2342     if ( !pSubEdit )
2343         return;
2344 
2345     switch ( GetPropertyId( PropertyName ) )
2346     {
2347     case BASEPROPERTY_TEXTLINECOLOR:
2348         if ( !Value.hasValue() )
2349             pSubEdit->SetTextLineColor();
2350         else
2351         {
2352             sal_Int32 nColor = 0;
2353             if ( Value >>= nColor )
2354                 pSubEdit->SetTextLineColor( Color( nColor ) );
2355         }
2356         break;
2357     }
2358 }
2359 
2360 void SVTXDateField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
2361 {
2362     PushPropertyIds( rIds,
2363                      BASEPROPERTY_TEXTLINECOLOR,
2364                      0);
2365     VCLXDateField::ImplGetPropertyIds( rIds );
2366 }
2367