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