Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "standardcontrol.hxx"
30 : : #include "pcrcommon.hxx"
31 : :
32 : : #include <com/sun/star/util/DateTime.hpp>
33 : : #include <com/sun/star/util/Date.hpp>
34 : : #include <com/sun/star/util/Time.hpp>
35 : : #include <com/sun/star/util/Color.hpp>
36 : : #include <com/sun/star/util/MeasureUnit.hpp>
37 : : #include <com/sun/star/inspection/PropertyControlType.hpp>
38 : : #include <comphelper/string.hxx>
39 : : #include <rtl/math.hxx>
40 : : #include <sfx2/objsh.hxx>
41 : :
42 : : //==================================================================
43 : : // ugly dependencies for the OColorControl
44 : : #include <svx/svxids.hrc>
45 : : #include <svx/drawitem.hxx>
46 : : #include <svx/xtable.hxx>
47 : : //==================================================================
48 : : #include <vcl/floatwin.hxx>
49 : : #include <svtools/svmedit.hxx>
50 : : #include <svtools/colorcfg.hxx>
51 : : #include <unotools/syslocale.hxx>
52 : : #include <unotools/datetime.hxx>
53 : : #include <i18npool/mslangid.hxx>
54 : : #include <vcl/button.hxx>
55 : : #include <vcl/svapp.hxx>
56 : : //==================================================================
57 : :
58 : : #include <memory>
59 : : #include <limits>
60 : : #include <boost/bind.hpp>
61 : : #include <boost/scoped_ptr.hpp>
62 : :
63 : : //............................................................................
64 : : namespace pcr
65 : : {
66 : : //............................................................................
67 : :
68 : : using namespace ::com::sun::star;
69 : : using namespace ::com::sun::star::uno;
70 : : using namespace ::com::sun::star::awt;
71 : : using namespace ::com::sun::star::lang;
72 : : using namespace ::com::sun::star::util;
73 : : using namespace ::com::sun::star::beans;
74 : : using namespace ::com::sun::star::inspection;
75 : :
76 : : //==================================================================
77 : : //= OTimeControl
78 : : //==================================================================
79 : : //------------------------------------------------------------------
80 : 0 : OTimeControl::OTimeControl( Window* pParent, WinBits nWinStyle )
81 : 0 : :OTimeControl_Base( PropertyControlType::TimeField, pParent, nWinStyle )
82 : : {
83 : 0 : getTypedControlWindow()->SetStrictFormat( sal_True );
84 : 0 : getTypedControlWindow()->SetFormat( TIMEF_SEC );
85 : 0 : getTypedControlWindow()->EnableEmptyFieldValue( sal_True );
86 : 0 : }
87 : :
88 : : //------------------------------------------------------------------
89 : 0 : void SAL_CALL OTimeControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
90 : : {
91 : 0 : util::Time aUNOTime;
92 : 0 : if ( !( _rValue >>= aUNOTime ) )
93 : : {
94 : 0 : getTypedControlWindow()->SetText( String() );
95 : 0 : getTypedControlWindow()->SetEmptyTime();
96 : : }
97 : : else
98 : : {
99 : 0 : ::Time aTime( aUNOTime.Hours, aUNOTime.Minutes, aUNOTime.Seconds, aUNOTime.HundredthSeconds );
100 : 0 : getTypedControlWindow()->SetTime( aTime );
101 : : }
102 : 0 : }
103 : :
104 : : //------------------------------------------------------------------
105 : 0 : Any SAL_CALL OTimeControl::getValue() throw (RuntimeException)
106 : : {
107 : 0 : Any aPropValue;
108 : 0 : if ( getTypedControlWindow()->GetText().Len()>0 )
109 : : {
110 : 0 : ::Time aTime( getTypedControlWindow()->GetTime() );
111 : 0 : util::Time aUNOTime( aTime.Get100Sec(), aTime.GetSec(), aTime.GetMin(), aTime.GetHour() );
112 : 0 : aPropValue <<= aUNOTime;
113 : : }
114 : 0 : return aPropValue;
115 : : }
116 : :
117 : : //------------------------------------------------------------------
118 : 0 : Type SAL_CALL OTimeControl::getValueType() throw (RuntimeException)
119 : : {
120 : 0 : return ::getCppuType( static_cast< util::Time* >( NULL ) );
121 : : }
122 : :
123 : : //==================================================================
124 : : //= ODateControl
125 : : //==================================================================
126 : : //------------------------------------------------------------------
127 : 0 : ODateControl::ODateControl( Window* pParent, WinBits nWinStyle )
128 : 0 : :ODateControl_Base( PropertyControlType::DateField, pParent, nWinStyle | WB_DROPDOWN )
129 : : {
130 : 0 : WindowType* pControlWindow = getTypedControlWindow();
131 : 0 : pControlWindow->SetStrictFormat(sal_True);
132 : :
133 : 0 : pControlWindow->SetMin( ::Date( 1,1,1600 ) );
134 : 0 : pControlWindow->SetFirst( ::Date( 1,1,1600 ) );
135 : 0 : pControlWindow->SetLast( ::Date( 1, 1, 9999 ) );
136 : 0 : pControlWindow->SetMax( ::Date( 1, 1, 9999 ) );
137 : :
138 : 0 : pControlWindow->SetExtDateFormat( XTDATEF_SYSTEM_SHORT_YYYY );
139 : 0 : pControlWindow->EnableEmptyFieldValue( sal_True );
140 : 0 : }
141 : :
142 : : //------------------------------------------------------------------
143 : 0 : void SAL_CALL ODateControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
144 : : {
145 : 0 : util::Date aUNODate;
146 : 0 : if ( !( _rValue >>= aUNODate ) )
147 : : {
148 : 0 : getTypedControlWindow()->SetText( String() );
149 : 0 : getTypedControlWindow()->SetEmptyDate();
150 : : }
151 : : else
152 : : {
153 : 0 : ::Date aDate( aUNODate.Day, aUNODate.Month, aUNODate.Year );
154 : 0 : getTypedControlWindow()->SetDate( aDate );
155 : : }
156 : 0 : }
157 : :
158 : : //------------------------------------------------------------------
159 : 0 : Any SAL_CALL ODateControl::getValue() throw (RuntimeException)
160 : : {
161 : 0 : Any aPropValue;
162 : 0 : if ( getTypedControlWindow()->GetText().Len() > 0 )
163 : : {
164 : 0 : ::Date aDate( getTypedControlWindow()->GetDate() );
165 : 0 : util::Date aUNODate( aDate.GetDay(), aDate.GetMonth(), aDate.GetYear() );
166 : 0 : aPropValue <<= aUNODate;
167 : : }
168 : 0 : return aPropValue;
169 : : }
170 : :
171 : : //------------------------------------------------------------------
172 : 0 : Type SAL_CALL ODateControl::getValueType() throw (RuntimeException)
173 : : {
174 : 0 : return ::getCppuType( static_cast< util::Date* >( NULL ) );
175 : : }
176 : :
177 : : //==================================================================
178 : : //= OEditControl
179 : : //==================================================================
180 : : //------------------------------------------------------------------
181 : 0 : OEditControl::OEditControl(Window* _pParent, sal_Bool _bPW, WinBits _nWinStyle)
182 : 0 : :OEditControl_Base( _bPW ? PropertyControlType::CharacterField : PropertyControlType::TextField, _pParent, _nWinStyle )
183 : : {
184 : 0 : m_bIsPassword = _bPW;
185 : :
186 : 0 : if ( m_bIsPassword )
187 : 0 : getTypedControlWindow()->SetMaxTextLen( 1 );
188 : 0 : }
189 : :
190 : : //------------------------------------------------------------------
191 : 0 : void SAL_CALL OEditControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
192 : : {
193 : 0 : ::rtl::OUString sText;
194 : 0 : if ( m_bIsPassword )
195 : : {
196 : 0 : sal_Int16 nValue = 0;
197 : 0 : _rValue >>= nValue;
198 : 0 : if ( nValue )
199 : : {
200 : 0 : sText = rtl::OUString(static_cast<sal_Unicode>(nValue));
201 : : }
202 : : }
203 : : else
204 : 0 : _rValue >>= sText;
205 : :
206 : 0 : getTypedControlWindow()->SetText( sText );
207 : 0 : }
208 : :
209 : : //------------------------------------------------------------------
210 : 0 : Any SAL_CALL OEditControl::getValue() throw (RuntimeException)
211 : : {
212 : 0 : Any aPropValue;
213 : :
214 : 0 : ::rtl::OUString sText( getTypedControlWindow()->GetText() );
215 : 0 : if ( m_bIsPassword )
216 : : {
217 : 0 : if ( !sText.isEmpty() )
218 : 0 : aPropValue <<= (sal_Int16)sText.getStr()[0];
219 : : }
220 : : else
221 : 0 : aPropValue <<= sText;
222 : :
223 : 0 : return aPropValue;
224 : : }
225 : :
226 : : //------------------------------------------------------------------
227 : 0 : Type SAL_CALL OEditControl::getValueType() throw (RuntimeException)
228 : : {
229 : 0 : return m_bIsPassword ? ::getCppuType( static_cast< sal_Int16* >( NULL ) ) : ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
230 : : }
231 : :
232 : : //------------------------------------------------------------------
233 : 0 : void OEditControl::modified()
234 : : {
235 : 0 : OEditControl_Base::modified();
236 : :
237 : : // for pasword controls, we fire a commit for every single change
238 : 0 : if ( m_bIsPassword )
239 : 0 : m_aImplControl.notifyModifiedValue();
240 : 0 : }
241 : :
242 : : //------------------------------------------------------------------
243 : 0 : static long ImplCalcLongValue( double nValue, sal_uInt16 nDigits )
244 : : {
245 : 0 : double n = nValue;
246 : 0 : for ( sal_uInt16 d = 0; d < nDigits; ++d )
247 : 0 : n *= 10;
248 : :
249 : 0 : if ( n > ::std::numeric_limits< long >::max() )
250 : 0 : return ::std::numeric_limits< long >::max();
251 : 0 : return (long)n;
252 : : }
253 : :
254 : : //------------------------------------------------------------------
255 : 0 : static double ImplCalcDoubleValue( long nValue, sal_uInt16 nDigits )
256 : : {
257 : 0 : double n = nValue;
258 : 0 : for ( sal_uInt16 d = 0; d < nDigits; ++d )
259 : 0 : n /= 10;
260 : 0 : return n;
261 : : }
262 : :
263 : : //==================================================================
264 : : // class ODateTimeControl
265 : : //==================================================================
266 : : //------------------------------------------------------------------
267 : 0 : ODateTimeControl::ODateTimeControl( Window* _pParent, WinBits _nWinStyle)
268 : 0 : :ODateTimeControl_Base( PropertyControlType::DateTimeField, _pParent, _nWinStyle )
269 : : {
270 : 0 : getTypedControlWindow()->EnableEmptyField( sal_True );
271 : :
272 : : // determine a default format
273 : 0 : Locale aSysLocale = SvtSysLocale().GetLocaleData().getLocale();
274 : 0 : LanguageType eSysLanguage = MsLangId::convertLocaleToLanguage( aSysLocale );
275 : :
276 : 0 : getTypedControlWindow()->SetFormatter( getTypedControlWindow()->StandardFormatter() );
277 : 0 : SvNumberFormatter* pFormatter = getTypedControlWindow()->GetFormatter();
278 : 0 : sal_uLong nStandardDateTimeFormat = pFormatter->GetStandardFormat( NUMBERFORMAT_DATETIME, eSysLanguage );
279 : :
280 : 0 : getTypedControlWindow()->SetFormatKey( nStandardDateTimeFormat );
281 : 0 : }
282 : :
283 : : //------------------------------------------------------------------
284 : 0 : void SAL_CALL ODateTimeControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
285 : : {
286 : 0 : if ( !_rValue.hasValue() )
287 : : {
288 : 0 : getTypedControlWindow()->SetText( String() );
289 : : }
290 : : else
291 : : {
292 : 0 : util::DateTime aUNODateTime;
293 : 0 : OSL_VERIFY( _rValue >>= aUNODateTime );
294 : :
295 : 0 : ::DateTime aDateTime( ::DateTime::EMPTY );
296 : 0 : ::utl::typeConvert( aUNODateTime, aDateTime );
297 : :
298 : 0 : double nValue = aDateTime - ::DateTime( *getTypedControlWindow()->GetFormatter()->GetNullDate() );
299 : 0 : getTypedControlWindow()->SetValue( nValue );
300 : : }
301 : 0 : }
302 : :
303 : : //------------------------------------------------------------------
304 : 0 : Any SAL_CALL ODateTimeControl::getValue() throw (RuntimeException)
305 : : {
306 : 0 : Any aPropValue;
307 : 0 : if ( getTypedControlWindow()->GetText().Len() )
308 : : {
309 : 0 : double nValue = getTypedControlWindow()->GetValue();
310 : :
311 : 0 : ::DateTime aDateTime( *getTypedControlWindow()->GetFormatter()->GetNullDate() );
312 : :
313 : : // add the "days" part
314 : 0 : double nDays = floor( nValue );
315 : 0 : aDateTime += nDays;
316 : :
317 : : // add the "time" part
318 : 0 : double nTime = nValue - nDays;
319 : 0 : nTime = ::rtl::math::round( nTime * 86400.0 ) / 86400.0;
320 : : // we're not interested in 100th seconds, and this here prevents rounding errors
321 : 0 : aDateTime += nTime;
322 : :
323 : 0 : util::DateTime aUNODateTime;
324 : 0 : ::utl::typeConvert( aDateTime, aUNODateTime );
325 : :
326 : 0 : aPropValue <<= aUNODateTime;
327 : : }
328 : 0 : return aPropValue;
329 : : }
330 : :
331 : : //------------------------------------------------------------------
332 : 0 : Type SAL_CALL ODateTimeControl::getValueType() throw (RuntimeException)
333 : : {
334 : 0 : return ::getCppuType( static_cast< util::DateTime* >( NULL ) );
335 : : }
336 : :
337 : : //========================================================================
338 : : //= HyperlinkInput
339 : : //========================================================================
340 : : //--------------------------------------------------------------------
341 : 0 : HyperlinkInput::HyperlinkInput( Window* _pParent, WinBits _nWinStyle )
342 : 0 : :Edit( _pParent, _nWinStyle )
343 : : {
344 : 0 : ::svtools::ColorConfig aColorConfig;
345 : 0 : ::svtools::ColorConfigValue aLinkColor( aColorConfig.GetColorValue( ::svtools::LINKS ) );
346 : :
347 : 0 : AllSettings aAllSettings( GetSettings() );
348 : 0 : StyleSettings aStyleSettings( aAllSettings.GetStyleSettings() );
349 : :
350 : 0 : Font aFieldFont( aStyleSettings.GetFieldFont() );
351 : 0 : aFieldFont.SetUnderline( UNDERLINE_SINGLE );
352 : 0 : aFieldFont.SetColor( aLinkColor.nColor );
353 : 0 : aStyleSettings.SetFieldFont( aFieldFont );
354 : :
355 : 0 : aStyleSettings.SetFieldTextColor( aLinkColor.nColor );
356 : :
357 : 0 : aAllSettings.SetStyleSettings( aStyleSettings );
358 : 0 : SetSettings( aAllSettings );
359 : 0 : }
360 : :
361 : : //--------------------------------------------------------------------
362 : 0 : void HyperlinkInput::MouseMove( const ::MouseEvent& rMEvt )
363 : : {
364 : 0 : Edit::MouseMove( rMEvt );
365 : :
366 : 0 : PointerStyle ePointerStyle( POINTER_TEXT );
367 : :
368 : 0 : if ( !rMEvt.IsLeaveWindow() )
369 : : {
370 : 0 : if ( impl_textHitTest( rMEvt.GetPosPixel() ) )
371 : 0 : ePointerStyle = POINTER_REFHAND;
372 : : }
373 : :
374 : 0 : SetPointer( Pointer( ePointerStyle ) );
375 : 0 : }
376 : :
377 : : //--------------------------------------------------------------------
378 : 0 : void HyperlinkInput::MouseButtonDown( const ::MouseEvent& rMEvt )
379 : : {
380 : 0 : Edit::MouseButtonDown( rMEvt );
381 : :
382 : 0 : if ( impl_textHitTest( rMEvt.GetPosPixel() ) )
383 : 0 : m_aMouseButtonDownPos = rMEvt.GetPosPixel();
384 : : else
385 : 0 : m_aMouseButtonDownPos.X() = m_aMouseButtonDownPos.Y() = -1;
386 : 0 : }
387 : :
388 : : //--------------------------------------------------------------------
389 : 0 : void HyperlinkInput::MouseButtonUp( const ::MouseEvent& rMEvt )
390 : : {
391 : 0 : Edit::MouseButtonUp( rMEvt );
392 : :
393 : 0 : impl_checkEndClick( rMEvt );
394 : 0 : }
395 : :
396 : : //--------------------------------------------------------------------
397 : 0 : bool HyperlinkInput::impl_textHitTest( const ::Point& _rWindowPos )
398 : : {
399 : 0 : xub_StrLen nPos = GetCharPos( _rWindowPos );
400 : 0 : return ( ( nPos != STRING_LEN ) && ( nPos < GetText().Len() ) );
401 : : }
402 : :
403 : : //--------------------------------------------------------------------
404 : 0 : void HyperlinkInput::impl_checkEndClick( const ::MouseEvent rMEvt )
405 : : {
406 : 0 : const MouseSettings& rMouseSettings( GetSettings().GetMouseSettings() );
407 : 0 : if ( ( abs( rMEvt.GetPosPixel().X() - m_aMouseButtonDownPos.X() ) < rMouseSettings.GetStartDragWidth() )
408 : 0 : && ( abs( rMEvt.GetPosPixel().Y() - m_aMouseButtonDownPos.Y() ) < rMouseSettings.GetStartDragHeight() )
409 : : )
410 : 0 : Application::PostUserEvent( m_aClickHandler );
411 : 0 : }
412 : :
413 : : //--------------------------------------------------------------------
414 : 0 : void HyperlinkInput::Tracking( const TrackingEvent& rTEvt )
415 : : {
416 : 0 : Edit::Tracking( rTEvt );
417 : :
418 : 0 : if ( rTEvt.IsTrackingEnded() )
419 : 0 : impl_checkEndClick( rTEvt.GetMouseEvent() );
420 : 0 : }
421 : :
422 : : //========================================================================
423 : : //= OHyperlinkControl
424 : : //========================================================================
425 : : //--------------------------------------------------------------------
426 : 0 : OHyperlinkControl::OHyperlinkControl( Window* _pParent, WinBits _nWinStyle )
427 : : :OHyperlinkControl_Base( PropertyControlType::HyperlinkField, _pParent, _nWinStyle )
428 : 0 : ,m_aActionListeners( m_aMutex )
429 : : {
430 : 0 : getTypedControlWindow()->SetClickHdl( LINK( this, OHyperlinkControl, OnHyperlinkClicked ) );
431 : 0 : }
432 : :
433 : : //--------------------------------------------------------------------
434 : 0 : Any SAL_CALL OHyperlinkControl::getValue() throw (RuntimeException)
435 : : {
436 : 0 : ::rtl::OUString sText = getTypedControlWindow()->GetText();
437 : 0 : return makeAny( sText );
438 : : }
439 : :
440 : : //--------------------------------------------------------------------
441 : 0 : void SAL_CALL OHyperlinkControl::setValue( const Any& _value ) throw (IllegalTypeException, RuntimeException)
442 : : {
443 : 0 : ::rtl::OUString sText;
444 : 0 : _value >>= sText;
445 : 0 : getTypedControlWindow()->SetText( sText );
446 : 0 : }
447 : :
448 : : //--------------------------------------------------------------------
449 : 0 : Type SAL_CALL OHyperlinkControl::getValueType() throw (RuntimeException)
450 : : {
451 : 0 : return ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
452 : : }
453 : :
454 : : //--------------------------------------------------------------------
455 : 0 : void SAL_CALL OHyperlinkControl::addActionListener( const Reference< XActionListener >& listener ) throw (RuntimeException)
456 : : {
457 : 0 : if ( listener.is() )
458 : 0 : m_aActionListeners.addInterface( listener );
459 : 0 : }
460 : :
461 : : //--------------------------------------------------------------------
462 : 0 : void SAL_CALL OHyperlinkControl::removeActionListener( const Reference< XActionListener >& listener ) throw (RuntimeException)
463 : : {
464 : 0 : m_aActionListeners.removeInterface( listener );
465 : 0 : }
466 : :
467 : : //------------------------------------------------------------------
468 : 0 : void SAL_CALL OHyperlinkControl::disposing()
469 : : {
470 : 0 : OHyperlinkControl_Base::disposing();
471 : :
472 : 0 : EventObject aEvent( *this );
473 : 0 : m_aActionListeners.disposeAndClear( aEvent );
474 : 0 : }
475 : :
476 : : //------------------------------------------------------------------
477 : 0 : IMPL_LINK( OHyperlinkControl, OnHyperlinkClicked, void*, /*_NotInterestedIn*/ )
478 : : {
479 : 0 : ActionEvent aEvent( *this, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "clicked" ) ) );
480 : : m_aActionListeners.forEach< XActionListener >(
481 : : boost::bind(
482 : : &XActionListener::actionPerformed,
483 : 0 : _1, boost::cref(aEvent) ) );
484 : :
485 : 0 : return 0;
486 : : }
487 : :
488 : : //==================================================================
489 : : //= ONumericControl
490 : : //==================================================================
491 : : //------------------------------------------------------------------
492 : 0 : ONumericControl::ONumericControl( Window* _pParent, WinBits _nWinStyle )
493 : : :ONumericControl_Base( PropertyControlType::NumericField, _pParent, _nWinStyle )
494 : : ,m_eValueUnit( FUNIT_NONE )
495 : 0 : ,m_nFieldToUNOValueFactor( 1 )
496 : : {
497 : 0 : getTypedControlWindow()->SetDefaultUnit( FUNIT_NONE );
498 : :
499 : 0 : getTypedControlWindow()->EnableEmptyFieldValue( sal_True );
500 : 0 : getTypedControlWindow()->SetStrictFormat( sal_True );
501 : 0 : Optional< double > value( getMaxValue() );
502 : 0 : value.Value = -value.Value;
503 : 0 : setMinValue( value );
504 : 0 : }
505 : :
506 : : //--------------------------------------------------------------------
507 : 0 : ::sal_Int16 SAL_CALL ONumericControl::getDecimalDigits() throw (RuntimeException)
508 : : {
509 : 0 : return getTypedControlWindow()->GetDecimalDigits();
510 : : }
511 : :
512 : : //--------------------------------------------------------------------
513 : 0 : void SAL_CALL ONumericControl::setDecimalDigits( ::sal_Int16 _decimaldigits ) throw (RuntimeException)
514 : : {
515 : 0 : getTypedControlWindow()->SetDecimalDigits( _decimaldigits );
516 : 0 : }
517 : :
518 : : //--------------------------------------------------------------------
519 : 0 : Optional< double > SAL_CALL ONumericControl::getMinValue() throw (RuntimeException)
520 : : {
521 : 0 : Optional< double > aReturn( sal_True, 0 );
522 : :
523 : 0 : sal_Int64 minValue = getTypedControlWindow()->GetMin();
524 : 0 : if ( minValue == ::std::numeric_limits< sal_Int64 >::min() )
525 : 0 : aReturn.IsPresent = sal_False;
526 : : else
527 : 0 : aReturn.Value = (double)minValue;
528 : :
529 : 0 : return aReturn;
530 : : }
531 : :
532 : : //--------------------------------------------------------------------
533 : 0 : void SAL_CALL ONumericControl::setMinValue( const Optional< double >& _minvalue ) throw (RuntimeException)
534 : : {
535 : 0 : if ( !_minvalue.IsPresent )
536 : 0 : getTypedControlWindow()->SetMin( ::std::numeric_limits< sal_Int64 >::min() );
537 : : else
538 : 0 : getTypedControlWindow()->SetMin( impl_apiValueToFieldValue_nothrow( _minvalue.Value ) , m_eValueUnit);
539 : 0 : }
540 : :
541 : : //--------------------------------------------------------------------
542 : 0 : Optional< double > SAL_CALL ONumericControl::getMaxValue() throw (RuntimeException)
543 : : {
544 : 0 : Optional< double > aReturn( sal_True, 0 );
545 : :
546 : 0 : sal_Int64 maxValue = getTypedControlWindow()->GetMax();
547 : 0 : if ( maxValue == ::std::numeric_limits< sal_Int64 >::max() )
548 : 0 : aReturn.IsPresent = sal_False;
549 : : else
550 : 0 : aReturn.Value = (double)maxValue;
551 : :
552 : 0 : return aReturn;
553 : : }
554 : :
555 : : //--------------------------------------------------------------------
556 : 0 : void SAL_CALL ONumericControl::setMaxValue( const Optional< double >& _maxvalue ) throw (RuntimeException)
557 : : {
558 : 0 : if ( !_maxvalue.IsPresent )
559 : 0 : getTypedControlWindow()->SetMax( ::std::numeric_limits< sal_Int64 >::max() );
560 : : else
561 : 0 : getTypedControlWindow()->SetMax( impl_apiValueToFieldValue_nothrow( _maxvalue.Value ), m_eValueUnit );
562 : 0 : }
563 : :
564 : : //--------------------------------------------------------------------
565 : 0 : ::sal_Int16 SAL_CALL ONumericControl::getDisplayUnit() throw (RuntimeException)
566 : : {
567 : 0 : return VCLUnoHelper::ConvertToMeasurementUnit( getTypedControlWindow()->GetUnit(), 1 );
568 : : }
569 : :
570 : : //--------------------------------------------------------------------
571 : 0 : void SAL_CALL ONumericControl::setDisplayUnit( ::sal_Int16 _displayunit ) throw (IllegalArgumentException, RuntimeException)
572 : : {
573 : 0 : if ( ( _displayunit < MeasureUnit::MM_100TH ) || ( _displayunit > MeasureUnit::PERCENT ) )
574 : 0 : throw IllegalArgumentException();
575 : 0 : if ( ( _displayunit == MeasureUnit::MM_100TH )
576 : : || ( _displayunit == MeasureUnit::MM_10TH )
577 : : || ( _displayunit == MeasureUnit::INCH_1000TH )
578 : : || ( _displayunit == MeasureUnit::INCH_100TH )
579 : : || ( _displayunit == MeasureUnit::INCH_10TH )
580 : : || ( _displayunit == MeasureUnit::PERCENT )
581 : : )
582 : 0 : throw IllegalArgumentException();
583 : :
584 : 0 : sal_Int16 nDummyFactor = 1;
585 : 0 : FieldUnit eFieldUnit = VCLUnoHelper::ConvertToFieldUnit( _displayunit, nDummyFactor );
586 : 0 : if ( nDummyFactor != 1 )
587 : : // everything which survived the checks above should result in a factor of 1, i.e.,
588 : : // it should have a direct counterpart as FieldUnit
589 : 0 : throw RuntimeException();
590 : 0 : getTypedControlWindow()->MetricFormatter::SetUnit( eFieldUnit );
591 : 0 : }
592 : :
593 : : //--------------------------------------------------------------------
594 : 0 : ::sal_Int16 SAL_CALL ONumericControl::getValueUnit() throw (RuntimeException)
595 : : {
596 : 0 : return VCLUnoHelper::ConvertToMeasurementUnit( m_eValueUnit, m_nFieldToUNOValueFactor );
597 : : }
598 : :
599 : : //--------------------------------------------------------------------
600 : 0 : void SAL_CALL ONumericControl::setValueUnit( ::sal_Int16 _valueunit ) throw (RuntimeException)
601 : : {
602 : 0 : if ( ( _valueunit < MeasureUnit::MM_100TH ) || ( _valueunit > MeasureUnit::PERCENT ) )
603 : 0 : throw IllegalArgumentException();
604 : 0 : m_eValueUnit = VCLUnoHelper::ConvertToFieldUnit( _valueunit, m_nFieldToUNOValueFactor );
605 : 0 : }
606 : :
607 : : //--------------------------------------------------------------------
608 : 0 : void SAL_CALL ONumericControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
609 : : {
610 : 0 : if ( !_rValue.hasValue() )
611 : : {
612 : 0 : getTypedControlWindow()->SetText( String() );
613 : 0 : getTypedControlWindow()->SetEmptyFieldValue();
614 : : }
615 : : else
616 : : {
617 : 0 : double nValue( 0 );
618 : 0 : OSL_VERIFY( _rValue >>= nValue );
619 : 0 : long nControlValue = impl_apiValueToFieldValue_nothrow( nValue );
620 : 0 : getTypedControlWindow()->SetValue( nControlValue, m_eValueUnit );
621 : : }
622 : 0 : }
623 : :
624 : : //------------------------------------------------------------------
625 : 0 : long ONumericControl::impl_apiValueToFieldValue_nothrow( double _nApiValue ) const
626 : : {
627 : 0 : long nControlValue = ImplCalcLongValue( _nApiValue, getTypedControlWindow()->GetDecimalDigits() );
628 : 0 : nControlValue /= m_nFieldToUNOValueFactor;
629 : 0 : return nControlValue;
630 : : }
631 : :
632 : : //------------------------------------------------------------------
633 : 0 : double ONumericControl::impl_fieldValueToApiValue_nothrow( sal_Int64 _nFieldValue ) const
634 : : {
635 : 0 : double nApiValue = ImplCalcDoubleValue( (long)_nFieldValue, getTypedControlWindow()->GetDecimalDigits() );
636 : 0 : nApiValue *= m_nFieldToUNOValueFactor;
637 : 0 : return nApiValue;
638 : : }
639 : :
640 : : //------------------------------------------------------------------
641 : 0 : Any SAL_CALL ONumericControl::getValue() throw (RuntimeException)
642 : : {
643 : 0 : Any aPropValue;
644 : 0 : if ( getTypedControlWindow()->GetText().Len() )
645 : : {
646 : 0 : double nValue = impl_fieldValueToApiValue_nothrow( getTypedControlWindow()->GetValue( m_eValueUnit ) );
647 : 0 : aPropValue <<= nValue;
648 : : }
649 : 0 : return aPropValue;
650 : : }
651 : :
652 : : //------------------------------------------------------------------
653 : 0 : Type SAL_CALL ONumericControl::getValueType() throw (RuntimeException)
654 : : {
655 : 0 : return ::getCppuType( static_cast< double* >( NULL ) );
656 : : }
657 : :
658 : : //==================================================================
659 : : //= OColorControl
660 : : //==================================================================
661 : : #define LB_DEFAULT_COUNT 20
662 : : //------------------------------------------------------------------
663 : 0 : String MakeHexStr(sal_uInt32 nVal, sal_uInt32 nLength)
664 : : {
665 : 0 : String aStr;
666 : 0 : while (nVal>0)
667 : : {
668 : 0 : char c=char(nVal & 0x000F);
669 : 0 : nVal>>=4;
670 : 0 : if (c<=9) c+='0';
671 : 0 : else c+='A'-10;
672 : 0 : aStr.Insert(c,0);
673 : : }
674 : 0 : while (aStr.Len() < nLength) aStr.Insert('0',0);
675 : 0 : return aStr;
676 : : }
677 : :
678 : : //------------------------------------------------------------------
679 : 0 : OColorControl::OColorControl(Window* pParent, WinBits nWinStyle)
680 : 0 : :OColorControl_Base( PropertyControlType::ColorListBox, pParent, nWinStyle )
681 : : {
682 : : // initialize the color listbox
683 : 0 : XColorListRef pColorList;
684 : 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
685 : 0 : const SfxPoolItem* pItem = pDocSh ? pDocSh->GetItem( SID_COLOR_TABLE ) : NULL;
686 : 0 : if ( pItem )
687 : : {
688 : : DBG_ASSERT(pItem->ISA(SvxColorListItem), "OColorControl::OColorControl: invalid color item!");
689 : 0 : pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
690 : : }
691 : :
692 : 0 : if ( !pColorList.is() )
693 : 0 : pColorList = XColorList::GetStdColorList();
694 : :
695 : :
696 : : DBG_ASSERT(pColorList.is(), "OColorControl::OColorControl: no color table!");
697 : :
698 : 0 : if ( pColorList.is() )
699 : : {
700 : 0 : for (sal_uInt16 i = 0; i < pColorList->Count(); ++i)
701 : : {
702 : 0 : XColorEntry* pEntry = pColorList->GetColor( i );
703 : 0 : getTypedControlWindow()->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
704 : : }
705 : : }
706 : :
707 : 0 : getTypedControlWindow()->SetDropDownLineCount( LB_DEFAULT_COUNT );
708 : 0 : if ( ( nWinStyle & WB_READONLY ) != 0 )
709 : : {
710 : 0 : getTypedControlWindow()->SetReadOnly( sal_True );
711 : 0 : getTypedControlWindow()->Enable( sal_True );
712 : 0 : }
713 : 0 : }
714 : :
715 : : //------------------------------------------------------------------
716 : 0 : void SAL_CALL OColorControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
717 : : {
718 : 0 : if ( _rValue.hasValue() )
719 : : {
720 : 0 : ::com::sun::star::util::Color nColor = COL_TRANSPARENT;
721 : 0 : if ( _rValue >>= nColor )
722 : : {
723 : 0 : ::Color aRgbCol((ColorData)nColor);
724 : :
725 : 0 : getTypedControlWindow()->SelectEntry( aRgbCol );
726 : 0 : if ( !getTypedControlWindow()->IsEntrySelected( aRgbCol ) )
727 : : { // the given color is not part of the list -> insert a new entry with the hex code of the color
728 : 0 : String aStr = rtl::OUString("0x");
729 : 0 : aStr += MakeHexStr(nColor,8);
730 : 0 : getTypedControlWindow()->InsertEntry( aRgbCol, aStr );
731 : 0 : getTypedControlWindow()->SelectEntry( aRgbCol );
732 : : }
733 : : }
734 : : else
735 : : {
736 : 0 : ::rtl::OUString sNonColorValue;
737 : 0 : if ( !( _rValue >>= sNonColorValue ) )
738 : 0 : throw IllegalTypeException();
739 : 0 : getTypedControlWindow()->SelectEntry( sNonColorValue );
740 : 0 : if ( !getTypedControlWindow()->IsEntrySelected( sNonColorValue ) )
741 : 0 : getTypedControlWindow()->SetNoSelection();
742 : : }
743 : : }
744 : : else
745 : 0 : getTypedControlWindow()->SetNoSelection();
746 : 0 : }
747 : :
748 : : //------------------------------------------------------------------
749 : 0 : Any SAL_CALL OColorControl::getValue() throw (RuntimeException)
750 : : {
751 : 0 : Any aPropValue;
752 : 0 : if ( getTypedControlWindow()->GetSelectEntryCount() > 0 )
753 : : {
754 : 0 : ::rtl::OUString sSelectedEntry = getTypedControlWindow()->GetSelectEntry();
755 : 0 : if ( m_aNonColorEntries.find( sSelectedEntry ) != m_aNonColorEntries.end() )
756 : 0 : aPropValue <<= sSelectedEntry;
757 : : else
758 : : {
759 : 0 : ::Color aRgbCol = getTypedControlWindow()->GetSelectEntryColor();
760 : 0 : aPropValue <<= (::com::sun::star::util::Color)aRgbCol.GetColor();
761 : 0 : }
762 : : }
763 : 0 : return aPropValue;
764 : : }
765 : :
766 : : //------------------------------------------------------------------
767 : 0 : Type SAL_CALL OColorControl::getValueType() throw (RuntimeException)
768 : : {
769 : 0 : return ::getCppuType( static_cast< sal_Int32* >( NULL ) );
770 : : }
771 : :
772 : : //------------------------------------------------------------------
773 : 0 : void SAL_CALL OColorControl::clearList() throw (RuntimeException)
774 : : {
775 : 0 : getTypedControlWindow()->Clear();
776 : 0 : }
777 : :
778 : : //------------------------------------------------------------------
779 : 0 : void SAL_CALL OColorControl::prependListEntry( const ::rtl::OUString& NewEntry ) throw (RuntimeException)
780 : : {
781 : 0 : getTypedControlWindow()->InsertEntry( NewEntry, 0 );
782 : 0 : m_aNonColorEntries.insert( NewEntry );
783 : 0 : }
784 : :
785 : : //------------------------------------------------------------------
786 : 0 : void SAL_CALL OColorControl::appendListEntry( const ::rtl::OUString& NewEntry ) throw (RuntimeException)
787 : : {
788 : 0 : getTypedControlWindow()->InsertEntry( NewEntry );
789 : 0 : m_aNonColorEntries.insert( NewEntry );
790 : 0 : }
791 : : //------------------------------------------------------------------
792 : 0 : Sequence< ::rtl::OUString > SAL_CALL OColorControl::getListEntries( ) throw (RuntimeException)
793 : : {
794 : 0 : if ( !m_aNonColorEntries.empty() )
795 : 0 : return Sequence< ::rtl::OUString >(&(*m_aNonColorEntries.begin()),m_aNonColorEntries.size());
796 : 0 : return Sequence< ::rtl::OUString >();
797 : : }
798 : :
799 : : //------------------------------------------------------------------
800 : 0 : void OColorControl::modified()
801 : : {
802 : 0 : OColorControl_Base::modified();
803 : :
804 : 0 : if ( !getTypedControlWindow()->IsTravelSelect() )
805 : : // fire a commit
806 : 0 : m_aImplControl.notifyModifiedValue();
807 : 0 : }
808 : :
809 : : //==================================================================
810 : : //= OListboxControl
811 : : //==================================================================
812 : : //------------------------------------------------------------------
813 : 0 : OListboxControl::OListboxControl( Window* pParent, WinBits nWinStyle)
814 : 0 : :OListboxControl_Base( PropertyControlType::ListBox, pParent, nWinStyle )
815 : : {
816 : 0 : getTypedControlWindow()->SetDropDownLineCount( LB_DEFAULT_COUNT );
817 : 0 : if ( ( nWinStyle & WB_READONLY ) != 0 )
818 : : {
819 : 0 : getTypedControlWindow()->SetReadOnly( sal_True );
820 : 0 : getTypedControlWindow()->Enable( sal_True );
821 : : }
822 : 0 : }
823 : :
824 : : //------------------------------------------------------------------
825 : 0 : Any SAL_CALL OListboxControl::getValue() throw (RuntimeException)
826 : : {
827 : 0 : ::rtl::OUString sControlValue( getTypedControlWindow()->GetSelectEntry() );
828 : :
829 : 0 : Any aPropValue;
830 : 0 : if ( !sControlValue.isEmpty() )
831 : 0 : aPropValue <<= sControlValue;
832 : 0 : return aPropValue;
833 : : }
834 : :
835 : : //------------------------------------------------------------------
836 : 0 : Type SAL_CALL OListboxControl::getValueType() throw (RuntimeException)
837 : : {
838 : 0 : return ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
839 : : }
840 : :
841 : : //------------------------------------------------------------------
842 : 0 : void SAL_CALL OListboxControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
843 : : {
844 : 0 : if ( !_rValue.hasValue() )
845 : 0 : getTypedControlWindow()->SetNoSelection();
846 : : else
847 : : {
848 : 0 : ::rtl::OUString sSelection;
849 : 0 : _rValue >>= sSelection;
850 : :
851 : 0 : if ( !sSelection.equals( getTypedControlWindow()->GetSelectEntry() ) )
852 : 0 : getTypedControlWindow()->SelectEntry( sSelection );
853 : :
854 : 0 : if ( !getTypedControlWindow()->IsEntrySelected( sSelection ) )
855 : : {
856 : 0 : getTypedControlWindow()->InsertEntry( sSelection, 0 );
857 : 0 : getTypedControlWindow()->SelectEntry( sSelection );
858 : 0 : }
859 : : }
860 : 0 : }
861 : :
862 : : //------------------------------------------------------------------
863 : 0 : void SAL_CALL OListboxControl::clearList() throw (RuntimeException)
864 : : {
865 : 0 : getTypedControlWindow()->Clear();
866 : 0 : }
867 : :
868 : : //------------------------------------------------------------------
869 : 0 : void SAL_CALL OListboxControl::prependListEntry( const ::rtl::OUString& NewEntry ) throw (RuntimeException)
870 : : {
871 : 0 : getTypedControlWindow()->InsertEntry( NewEntry, 0 );
872 : 0 : }
873 : :
874 : : //------------------------------------------------------------------
875 : 0 : void SAL_CALL OListboxControl::appendListEntry( const ::rtl::OUString& NewEntry ) throw (RuntimeException)
876 : : {
877 : 0 : getTypedControlWindow()->InsertEntry( NewEntry );
878 : 0 : }
879 : : //------------------------------------------------------------------
880 : 0 : Sequence< ::rtl::OUString > SAL_CALL OListboxControl::getListEntries( ) throw (RuntimeException)
881 : : {
882 : 0 : const sal_uInt16 nCount = getTypedControlWindow()->GetEntryCount();
883 : 0 : Sequence< ::rtl::OUString > aRet(nCount);
884 : 0 : ::rtl::OUString* pIter = aRet.getArray();
885 : 0 : for (sal_uInt16 i = 0; i < nCount ; ++i,++pIter)
886 : 0 : *pIter = getTypedControlWindow()->GetEntry(i);
887 : :
888 : 0 : return aRet;
889 : : }
890 : :
891 : : //------------------------------------------------------------------
892 : 0 : void OListboxControl::modified()
893 : : {
894 : 0 : OListboxControl_Base::modified();
895 : :
896 : 0 : if ( !getTypedControlWindow()->IsTravelSelect() )
897 : : // fire a commit
898 : 0 : m_aImplControl.notifyModifiedValue();
899 : 0 : }
900 : :
901 : : //==================================================================
902 : : //= OComboboxControl
903 : : //==================================================================
904 : : //------------------------------------------------------------------
905 : 0 : OComboboxControl::OComboboxControl( Window* pParent, WinBits nWinStyle)
906 : 0 : :OComboboxControl_Base( PropertyControlType::ComboBox, pParent, nWinStyle )
907 : : {
908 : 0 : getTypedControlWindow()->SetDropDownLineCount( LB_DEFAULT_COUNT );
909 : 0 : getTypedControlWindow()->SetSelectHdl( LINK( this, OComboboxControl, OnEntrySelected ) );
910 : 0 : }
911 : :
912 : : //------------------------------------------------------------------
913 : 0 : void SAL_CALL OComboboxControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
914 : : {
915 : 0 : ::rtl::OUString sText;
916 : 0 : _rValue >>= sText;
917 : 0 : getTypedControlWindow()->SetText( sText );
918 : 0 : }
919 : :
920 : : //------------------------------------------------------------------
921 : 0 : Any SAL_CALL OComboboxControl::getValue() throw (RuntimeException)
922 : : {
923 : 0 : return makeAny( ::rtl::OUString( getTypedControlWindow()->GetText() ) );
924 : : }
925 : :
926 : : //------------------------------------------------------------------
927 : 0 : Type SAL_CALL OComboboxControl::getValueType() throw (RuntimeException)
928 : : {
929 : 0 : return ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
930 : : }
931 : :
932 : : //------------------------------------------------------------------
933 : 0 : void SAL_CALL OComboboxControl::clearList() throw (RuntimeException)
934 : : {
935 : 0 : getTypedControlWindow()->Clear();
936 : 0 : }
937 : :
938 : : //------------------------------------------------------------------
939 : 0 : void SAL_CALL OComboboxControl::prependListEntry( const ::rtl::OUString& NewEntry ) throw (RuntimeException)
940 : : {
941 : 0 : getTypedControlWindow()->InsertEntry( NewEntry, 0 );
942 : 0 : }
943 : :
944 : : //------------------------------------------------------------------
945 : 0 : void SAL_CALL OComboboxControl::appendListEntry( const ::rtl::OUString& NewEntry ) throw (RuntimeException)
946 : : {
947 : 0 : getTypedControlWindow()->InsertEntry( NewEntry );
948 : 0 : }
949 : : //------------------------------------------------------------------
950 : 0 : Sequence< ::rtl::OUString > SAL_CALL OComboboxControl::getListEntries( ) throw (RuntimeException)
951 : : {
952 : 0 : const sal_uInt16 nCount = getTypedControlWindow()->GetEntryCount();
953 : 0 : Sequence< ::rtl::OUString > aRet(nCount);
954 : 0 : ::rtl::OUString* pIter = aRet.getArray();
955 : 0 : for (sal_uInt16 i = 0; i < nCount ; ++i,++pIter)
956 : 0 : *pIter = getTypedControlWindow()->GetEntry(i);
957 : :
958 : 0 : return aRet;
959 : : }
960 : :
961 : : //------------------------------------------------------------------
962 : 0 : IMPL_LINK( OComboboxControl, OnEntrySelected, void*, /*_pNothing*/ )
963 : : {
964 : 0 : if ( !getTypedControlWindow()->IsTravelSelect() )
965 : : // fire a commit
966 : 0 : m_aImplControl.notifyModifiedValue();
967 : 0 : return 0L;
968 : : }
969 : :
970 : : //==================================================================
971 : : //= OMultilineFloatingEdit
972 : : //==================================================================
973 : 0 : class OMultilineFloatingEdit : public FloatingWindow
974 : : {
975 : : private:
976 : : MultiLineEdit m_aImplEdit;
977 : :
978 : : protected:
979 : : virtual void Resize();
980 : :
981 : : public:
982 : : OMultilineFloatingEdit(Window* _pParen);
983 : 0 : MultiLineEdit* getEdit() { return &m_aImplEdit; }
984 : :
985 : : protected:
986 : : virtual long PreNotify(NotifyEvent& _rNEvt);
987 : : };
988 : :
989 : : //------------------------------------------------------------------
990 : 0 : OMultilineFloatingEdit::OMultilineFloatingEdit(Window* _pParent)
991 : : :FloatingWindow(_pParent, WB_BORDER)
992 : 0 : ,m_aImplEdit(this, WB_VSCROLL|WB_IGNORETAB|WB_NOBORDER)
993 : : {
994 : 0 : m_aImplEdit.Show();
995 : 0 : }
996 : :
997 : : //------------------------------------------------------------------
998 : 0 : void OMultilineFloatingEdit::Resize()
999 : : {
1000 : 0 : m_aImplEdit.SetSizePixel(GetOutputSizePixel());
1001 : 0 : }
1002 : :
1003 : : //------------------------------------------------------------------
1004 : 0 : long OMultilineFloatingEdit::PreNotify(NotifyEvent& _rNEvt)
1005 : : {
1006 : 0 : long nResult = sal_True;
1007 : :
1008 : 0 : sal_uInt16 nSwitch = _rNEvt.GetType();
1009 : 0 : if (EVENT_KEYINPUT == nSwitch)
1010 : : {
1011 : 0 : const KeyCode& aKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode();
1012 : 0 : sal_uInt16 nKey = aKeyCode.GetCode();
1013 : :
1014 : 0 : if ( ( (KEY_RETURN == nKey)
1015 : 0 : && !aKeyCode.IsShift()
1016 : : )
1017 : : || ( (KEY_UP == nKey)
1018 : 0 : && aKeyCode.IsMod2()
1019 : : )
1020 : : )
1021 : : {
1022 : 0 : EndPopupMode();
1023 : : }
1024 : : else
1025 : 0 : nResult=FloatingWindow::PreNotify(_rNEvt);
1026 : : }
1027 : : else
1028 : 0 : nResult=FloatingWindow::PreNotify(_rNEvt);
1029 : :
1030 : 0 : return nResult;
1031 : : }
1032 : :
1033 : : //==================================================================
1034 : : //= DropDownEditControl_Base
1035 : : //==================================================================
1036 : : //------------------------------------------------------------------
1037 : 0 : DropDownEditControl::DropDownEditControl( Window* _pParent, WinBits _nStyle )
1038 : : :DropDownEditControl_Base( _pParent, _nStyle )
1039 : : ,m_pFloatingEdit( NULL )
1040 : : ,m_pImplEdit( NULL )
1041 : : ,m_pDropdownButton( NULL )
1042 : : ,m_nOperationMode( eStringList )
1043 : 0 : ,m_bDropdown( sal_False )
1044 : : {
1045 : 0 : SetCompoundControl( sal_True );
1046 : :
1047 : 0 : m_pImplEdit = new MultiLineEdit( this, WB_TABSTOP | WB_IGNORETAB | WB_NOBORDER | (_nStyle & WB_READONLY) );
1048 : 0 : SetSubEdit( m_pImplEdit );
1049 : 0 : m_pImplEdit->Show();
1050 : :
1051 : 0 : if ( _nStyle & WB_DROPDOWN )
1052 : : {
1053 : 0 : m_pDropdownButton = new PushButton( this, WB_NOLIGHTBORDER | WB_RECTSTYLE | WB_NOTABSTOP);
1054 : 0 : m_pDropdownButton->SetSymbol(SYMBOL_SPIN_DOWN);
1055 : 0 : m_pDropdownButton->SetClickHdl( LINK( this, DropDownEditControl, DropDownHdl ) );
1056 : 0 : m_pDropdownButton->Show();
1057 : : }
1058 : :
1059 : 0 : m_pFloatingEdit = new OMultilineFloatingEdit(this); //FloatingWindow
1060 : :
1061 : 0 : m_pFloatingEdit->SetPopupModeEndHdl( LINK( this, DropDownEditControl, ReturnHdl ) );
1062 : 0 : m_pFloatingEdit->getEdit()->SetReadOnly( ( _nStyle & WB_READONLY ) != 0 );
1063 : 0 : }
1064 : :
1065 : : //------------------------------------------------------------------
1066 : 0 : void DropDownEditControl::setControlHelper( ControlHelper& _rControlHelper )
1067 : : {
1068 : 0 : DropDownEditControl_Base::setControlHelper( _rControlHelper );
1069 : 0 : m_pFloatingEdit->getEdit()->SetModifyHdl( LINK( &_rControlHelper, ControlHelper, ModifiedHdl ) );
1070 : 0 : m_pImplEdit->SetGetFocusHdl( LINK( &_rControlHelper, ControlHelper, GetFocusHdl ) );
1071 : 0 : m_pImplEdit->SetModifyHdl( LINK( &_rControlHelper, ControlHelper, ModifiedHdl ) );
1072 : 0 : m_pImplEdit->SetLoseFocusHdl( LINK( &_rControlHelper, ControlHelper, LoseFocusHdl ) );
1073 : 0 : }
1074 : :
1075 : : //------------------------------------------------------------------
1076 : 0 : DropDownEditControl::~DropDownEditControl()
1077 : : {
1078 : : {
1079 : 0 : boost::scoped_ptr<Window> aTemp(m_pFloatingEdit);
1080 : 0 : m_pFloatingEdit = NULL;
1081 : : }
1082 : : {
1083 : 0 : boost::scoped_ptr<Window> aTemp(m_pImplEdit);
1084 : 0 : SetSubEdit( NULL );
1085 : 0 : m_pImplEdit = NULL;
1086 : : }
1087 : : {
1088 : 0 : boost::scoped_ptr<Window> aTemp(m_pDropdownButton);
1089 : 0 : m_pDropdownButton = NULL;
1090 : : }
1091 : 0 : }
1092 : :
1093 : : //------------------------------------------------------------------
1094 : 0 : void DropDownEditControl::Resize()
1095 : : {
1096 : 0 : ::Size aOutSz = GetOutputSizePixel();
1097 : :
1098 : 0 : if (m_pDropdownButton!=NULL)
1099 : : {
1100 : 0 : long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
1101 : 0 : nSBWidth = CalcZoom( nSBWidth );
1102 : 0 : m_pImplEdit->SetPosSizePixel( 0, 1, aOutSz.Width() - nSBWidth, aOutSz.Height()-2 );
1103 : 0 : m_pDropdownButton->SetPosSizePixel( aOutSz.Width() - nSBWidth, 0, nSBWidth, aOutSz.Height() );
1104 : : }
1105 : : else
1106 : 0 : m_pImplEdit->SetPosSizePixel( 0, 1, aOutSz.Width(), aOutSz.Height()-2 );
1107 : 0 : }
1108 : :
1109 : : //------------------------------------------------------------------
1110 : 0 : long DropDownEditControl::PreNotify( NotifyEvent& rNEvt )
1111 : : {
1112 : 0 : long nResult = 1;
1113 : :
1114 : 0 : if (rNEvt.GetType() == EVENT_KEYINPUT)
1115 : : {
1116 : 0 : const KeyCode& aKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1117 : 0 : sal_uInt16 nKey = aKeyCode.GetCode();
1118 : :
1119 : 0 : if ( nKey == KEY_RETURN && !aKeyCode.IsShift() )
1120 : : {
1121 : 0 : if ( m_pHelper )
1122 : : {
1123 : 0 : m_pHelper->LoseFocusHdl( m_pImplEdit );
1124 : 0 : m_pHelper->activateNextControl();
1125 : : }
1126 : : }
1127 : 0 : else if ( nKey == KEY_DOWN && aKeyCode.IsMod2() )
1128 : : {
1129 : 0 : Invalidate();
1130 : 0 : ShowDropDown( sal_True );
1131 : : }
1132 : 0 : else if ( KEYGROUP_CURSOR == aKeyCode.GetGroup()
1133 : : || nKey == KEY_HELP
1134 : 0 : || KEYGROUP_FKEYS == aKeyCode.GetGroup()
1135 : : || m_nOperationMode == eMultiLineText
1136 : : )
1137 : : {
1138 : 0 : nResult = DropDownEditControl_Base::PreNotify( rNEvt );
1139 : : }
1140 : 0 : else if ( m_nOperationMode == eStringList )
1141 : : {
1142 : 0 : Selection aSel = m_pImplEdit->GetSelection();
1143 : 0 : if ( aSel.Min() != aSel.Max() )
1144 : : {
1145 : 0 : aSel.Min() = FindPos( aSel.Min() );
1146 : 0 : aSel.Max() = FindPos( aSel.Max() );
1147 : : }
1148 : : else
1149 : : {
1150 : 0 : aSel.Min() = FindPos( aSel.Min() );
1151 : 0 : aSel.Max() = aSel.Min();
1152 : : }
1153 : 0 : Invalidate();
1154 : 0 : ShowDropDown( sal_True );
1155 : 0 : m_pFloatingEdit->getEdit()->GrabFocus();
1156 : 0 : m_pFloatingEdit->getEdit()->SetSelection( aSel );
1157 : 0 : Window* pFocusWin = Application::GetFocusWindow();
1158 : 0 : pFocusWin->KeyInput( *rNEvt.GetKeyEvent() );
1159 : : }
1160 : : }
1161 : : else
1162 : 0 : nResult = DropDownEditControl_Base::PreNotify(rNEvt);
1163 : :
1164 : 0 : return nResult;
1165 : : }
1166 : :
1167 : : //------------------------------------------------------------------
1168 : : namespace
1169 : : {
1170 : : //..............................................................
1171 : 0 : StlSyntaxSequence< ::rtl::OUString > lcl_convertMultiLineToList( const String& _rCompsedTextWithLineBreaks )
1172 : : {
1173 : 0 : xub_StrLen nLines( comphelper::string::getTokenCount(_rCompsedTextWithLineBreaks, '\n') );
1174 : 0 : StlSyntaxSequence< ::rtl::OUString > aStrings( nLines );
1175 : 0 : StlSyntaxSequence< ::rtl::OUString >::iterator stringItem = aStrings.begin();
1176 : 0 : for ( xub_StrLen token = 0; token < nLines; ++token, ++stringItem )
1177 : 0 : *stringItem = _rCompsedTextWithLineBreaks.GetToken( token, '\n' );
1178 : 0 : return aStrings;
1179 : : }
1180 : :
1181 : 0 : String lcl_convertListToMultiLine( const StlSyntaxSequence< ::rtl::OUString >& _rStrings )
1182 : : {
1183 : 0 : String sMultiLineText;
1184 : 0 : for ( StlSyntaxSequence< ::rtl::OUString >::const_iterator item = _rStrings.begin();
1185 : 0 : item != _rStrings.end();
1186 : : )
1187 : : {
1188 : 0 : sMultiLineText += String( *item );
1189 : 0 : if ( ++item != _rStrings.end() )
1190 : 0 : sMultiLineText += '\n';
1191 : : }
1192 : 0 : return sMultiLineText;
1193 : : }
1194 : :
1195 : : //..............................................................
1196 : 0 : String lcl_convertListToDisplayText( const StlSyntaxSequence< ::rtl::OUString >& _rStrings )
1197 : : {
1198 : 0 : ::rtl::OUStringBuffer aComposed;
1199 : 0 : for ( StlSyntaxSequence< ::rtl::OUString >::const_iterator strings = _rStrings.begin();
1200 : 0 : strings != _rStrings.end();
1201 : : ++strings
1202 : : )
1203 : : {
1204 : 0 : if ( strings != _rStrings.begin() )
1205 : 0 : aComposed.append( (sal_Unicode)';' );
1206 : 0 : aComposed.append( (sal_Unicode)'\"' );
1207 : 0 : aComposed.append( *strings );
1208 : 0 : aComposed.append( (sal_Unicode)'\"' );
1209 : : }
1210 : 0 : return aComposed.makeStringAndClear();
1211 : : }
1212 : : }
1213 : :
1214 : : //------------------------------------------------------------------
1215 : : #define STD_HEIGHT 100
1216 : 0 : sal_Bool DropDownEditControl::ShowDropDown( sal_Bool bShow )
1217 : : {
1218 : 0 : if (bShow)
1219 : : {
1220 : 0 : ::Point aMePos= GetPosPixel();
1221 : 0 : aMePos = GetParent()->OutputToScreenPixel( aMePos );
1222 : 0 : ::Size aSize=GetSizePixel();
1223 : 0 : ::Rectangle aRect(aMePos,aSize);
1224 : 0 : aSize.Height() = STD_HEIGHT;
1225 : 0 : m_pFloatingEdit->SetOutputSizePixel(aSize);
1226 : 0 : m_pFloatingEdit->StartPopupMode( aRect, FLOATWIN_POPUPMODE_DOWN );
1227 : :
1228 : 0 : m_pFloatingEdit->Show();
1229 : 0 : m_pFloatingEdit->getEdit()->GrabFocus();
1230 : 0 : m_pFloatingEdit->getEdit()->SetSelection(Selection(m_pFloatingEdit->getEdit()->GetText().Len()));
1231 : 0 : m_bDropdown=sal_True;
1232 : 0 : if ( m_nOperationMode == eMultiLineText )
1233 : 0 : m_pFloatingEdit->getEdit()->SetText( m_pImplEdit->GetText() );
1234 : 0 : m_pImplEdit->SetText(String());
1235 : : }
1236 : : else
1237 : : {
1238 : 0 : m_pFloatingEdit->Hide();
1239 : 0 : m_pFloatingEdit->Invalidate();
1240 : 0 : m_pFloatingEdit->Update();
1241 : :
1242 : : // transfer the text from the floating edit to our own edit
1243 : 0 : String sDisplayText( m_pFloatingEdit->getEdit()->GetText() );
1244 : 0 : if ( m_nOperationMode == eStringList )
1245 : 0 : sDisplayText = lcl_convertListToDisplayText( lcl_convertMultiLineToList( sDisplayText ) );
1246 : :
1247 : 0 : m_pImplEdit->SetText( sDisplayText );
1248 : 0 : GetParent()->Invalidate( INVALIDATE_CHILDREN );
1249 : 0 : m_bDropdown = sal_False;
1250 : 0 : m_pImplEdit->GrabFocus();
1251 : : }
1252 : 0 : return m_bDropdown;
1253 : :
1254 : : }
1255 : :
1256 : : //------------------------------------------------------------------
1257 : 0 : long DropDownEditControl::FindPos(long nSinglePos)
1258 : : {
1259 : 0 : long nPos=0;
1260 : 0 : String aOutput;
1261 : 0 : String aStr=m_pFloatingEdit->getEdit()->GetText();
1262 : 0 : String aStr1 = GetText();
1263 : :
1264 : 0 : if ((nSinglePos == 0) || (nSinglePos == aStr1.Len()))
1265 : : {
1266 : 0 : return nSinglePos;
1267 : : }
1268 : :
1269 : 0 : if (aStr.Len()>0)
1270 : : {
1271 : 0 : long nDiff=0;
1272 : 0 : sal_Int32 nCount = comphelper::string::getTokenCount(aStr, '\n');
1273 : :
1274 : 0 : String aInput = aStr.GetToken(0,'\n' );
1275 : :
1276 : 0 : if (aInput.Len()>0)
1277 : : {
1278 : 0 : aOutput+='\"';
1279 : 0 : nDiff++;
1280 : 0 : aOutput+=aInput;
1281 : 0 : aOutput+='\"';
1282 : : }
1283 : :
1284 : 0 : if (nSinglePos <= aOutput.Len())
1285 : : {
1286 : 0 : nPos=nSinglePos-nDiff;
1287 : : }
1288 : : else
1289 : : {
1290 : 0 : for (sal_Int32 i=1; i<nCount; ++i)
1291 : : {
1292 : 0 : aInput=aStr.GetToken((sal_uInt16)i, '\n');
1293 : 0 : if (aInput.Len()>0)
1294 : : {
1295 : 0 : aOutput += ';';
1296 : 0 : aOutput += '\"';
1297 : 0 : nDiff += 2;
1298 : 0 : aOutput += aInput;
1299 : 0 : aOutput += '\"';
1300 : :
1301 : 0 : if (nSinglePos <= aOutput.Len())
1302 : : {
1303 : 0 : nPos=nSinglePos-nDiff;
1304 : 0 : break;
1305 : : }
1306 : : }
1307 : : }
1308 : 0 : }
1309 : : }
1310 : 0 : return nPos;
1311 : : }
1312 : :
1313 : : //------------------------------------------------------------------
1314 : 0 : IMPL_LINK( DropDownEditControl, ReturnHdl, OMultilineFloatingEdit*, /*pMEd*/)
1315 : : {
1316 : :
1317 : 0 : String aStr = m_pFloatingEdit->getEdit()->GetText();
1318 : 0 : String aStr2 = GetText();
1319 : 0 : ShowDropDown(sal_False);
1320 : :
1321 : 0 : if (aStr!=aStr2 || ( m_nOperationMode == eStringList ) )
1322 : : {
1323 : 0 : if ( m_pHelper )
1324 : 0 : m_pHelper->notifyModifiedValue();
1325 : : }
1326 : :
1327 : 0 : return 0;
1328 : : }
1329 : :
1330 : : //------------------------------------------------------------------
1331 : 0 : IMPL_LINK( DropDownEditControl, DropDownHdl, PushButton*, /*pPb*/ )
1332 : : {
1333 : 0 : ShowDropDown(!m_bDropdown);
1334 : 0 : return 0;
1335 : : }
1336 : :
1337 : : //------------------------------------------------------------------
1338 : 0 : void DropDownEditControl::SetStringListValue( const StlSyntaxSequence< ::rtl::OUString >& _rStrings )
1339 : : {
1340 : 0 : SetText( lcl_convertListToDisplayText( _rStrings ) );
1341 : 0 : m_pFloatingEdit->getEdit()->SetText( lcl_convertListToMultiLine( _rStrings ) );
1342 : 0 : }
1343 : :
1344 : : //------------------------------------------------------------------
1345 : 0 : StlSyntaxSequence< ::rtl::OUString > DropDownEditControl::GetStringListValue() const
1346 : : {
1347 : 0 : return lcl_convertMultiLineToList( m_pFloatingEdit->getEdit()->GetText() );
1348 : : }
1349 : :
1350 : : //------------------------------------------------------------------
1351 : 0 : void DropDownEditControl::SetTextValue( const ::rtl::OUString& _rText )
1352 : : {
1353 : : OSL_PRECOND( m_nOperationMode == eMultiLineText, "DropDownEditControl::SetTextValue: illegal call!" );
1354 : :
1355 : 0 : m_pFloatingEdit->getEdit()->SetText( _rText );
1356 : 0 : SetText( _rText );
1357 : 0 : }
1358 : :
1359 : : //------------------------------------------------------------------
1360 : 0 : ::rtl::OUString DropDownEditControl::GetTextValue() const
1361 : : {
1362 : : OSL_PRECOND( m_nOperationMode == eMultiLineText, "DropDownEditControl::GetTextValue: illegal call!" );
1363 : 0 : return GetText();
1364 : : }
1365 : :
1366 : : //==================================================================
1367 : : //= OMultilineEditControl
1368 : : //==================================================================
1369 : : //------------------------------------------------------------------
1370 : 0 : OMultilineEditControl::OMultilineEditControl( Window* pParent, MultiLineOperationMode _eMode, WinBits nWinStyle )
1371 : : :OMultilineEditControl_Base( _eMode == eMultiLineText ? PropertyControlType::MultiLineTextField : PropertyControlType::StringListField
1372 : : , pParent
1373 : : , ( nWinStyle | WB_DIALOGCONTROL ) & ( ~WB_READONLY | ~WB_DROPDOWN )
1374 : 0 : , false )
1375 : : {
1376 : 0 : getTypedControlWindow()->setOperationMode( _eMode );
1377 : 0 : }
1378 : :
1379 : : //------------------------------------------------------------------
1380 : 0 : void SAL_CALL OMultilineEditControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
1381 : : {
1382 : 0 : impl_checkDisposed_throw();
1383 : :
1384 : 0 : switch ( getTypedControlWindow()->getOperationMode() )
1385 : : {
1386 : : case eMultiLineText:
1387 : : {
1388 : 0 : ::rtl::OUString sText;
1389 : 0 : if ( !( _rValue >>= sText ) && _rValue.hasValue() )
1390 : 0 : throw IllegalTypeException();
1391 : 0 : getTypedControlWindow()->SetTextValue( sText );
1392 : : }
1393 : 0 : break;
1394 : : case eStringList:
1395 : : {
1396 : 0 : Sequence< ::rtl::OUString > aStringLines;
1397 : 0 : if ( !( _rValue >>= aStringLines ) && _rValue.hasValue() )
1398 : 0 : throw IllegalTypeException();
1399 : 0 : getTypedControlWindow()->SetStringListValue( aStringLines );
1400 : : }
1401 : 0 : break;
1402 : : }
1403 : 0 : }
1404 : :
1405 : : //------------------------------------------------------------------
1406 : 0 : Any SAL_CALL OMultilineEditControl::getValue() throw (RuntimeException)
1407 : : {
1408 : 0 : impl_checkDisposed_throw();
1409 : :
1410 : 0 : Any aValue;
1411 : 0 : switch ( getTypedControlWindow()->getOperationMode() )
1412 : : {
1413 : : case eMultiLineText:
1414 : 0 : aValue <<= getTypedControlWindow()->GetTextValue();
1415 : 0 : break;
1416 : : case eStringList:
1417 : 0 : aValue <<= getTypedControlWindow()->GetStringListValue();
1418 : 0 : break;
1419 : : }
1420 : 0 : return aValue;
1421 : : }
1422 : :
1423 : : //------------------------------------------------------------------
1424 : 0 : Type SAL_CALL OMultilineEditControl::getValueType() throw (RuntimeException)
1425 : : {
1426 : 0 : if ( getTypedControlWindow()->getOperationMode() == eMultiLineText )
1427 : 0 : return ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
1428 : 0 : return ::getCppuType( static_cast< Sequence< ::rtl::OUString >* >( NULL ) );
1429 : : }
1430 : :
1431 : : //............................................................................
1432 : 0 : } // namespace pcr
1433 : : //............................................................................
1434 : :
1435 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|