Update ooo320-m1
[ooovba.git] / extensions / source / propctrlr / standardcontrol.hxx
blob848762daa0597ce21e0b17cf183cea2f31270678
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: standardcontrol.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _EXTENSIONS_PROPCTRLR_STANDARDCONTROL_HXX_
32 #define _EXTENSIONS_PROPCTRLR_STANDARDCONTROL_HXX_
34 #include "commoncontrol.hxx"
35 #include "pcrcommon.hxx"
37 /** === begin UNO includes === **/
38 #include <com/sun/star/inspection/XNumericControl.hpp>
39 #include <com/sun/star/inspection/XStringListControl.hpp>
40 #include <com/sun/star/inspection/XHyperlinkControl.hpp>
41 #include <com/sun/star/uno/Sequence.hxx>
42 /** === end UNO includes === **/
43 #include <vcl/field.hxx>
44 #include <vcl/longcurr.hxx>
45 #include <svtools/ctrlbox.hxx>
46 #include <vcl/lstbox.hxx>
47 #include <vcl/combobox.hxx>
48 #include <svtools/calendar.hxx>
49 #include <svtools/fmtfield.hxx>
51 #include <set>
53 class PushButton;
54 class MultiLineEdit;
55 //............................................................................
56 namespace pcr
58 //............................................................................
60 //========================================================================
61 //= ListLikeControlWithModifyHandler
62 //========================================================================
63 /** Very small helper class which adds a SetModifyHdl to a ListBox-derived class,
64 thus giving this class the same API (as far as the CommonBehaviourControl is concerned)
65 as all other windows.
67 template< class LISTBOX_WINDOW >
68 class ListLikeControlWithModifyHandler : public ControlWindow< LISTBOX_WINDOW >
70 protected:
71 typedef ControlWindow< LISTBOX_WINDOW > ListBoxType;
73 public:
74 ListLikeControlWithModifyHandler( Window* _pParent, WinBits _nStyle )
75 :ListBoxType( _pParent, _nStyle )
79 void SetModifyHdl( const Link& _rLink ) { ListBoxType::SetSelectHdl( _rLink ); }
81 protected:
82 long PreNotify( NotifyEvent& _rNEvt );
85 //------------------------------------------------------------------------
86 template< class LISTBOX_WINDOW >
87 long ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::PreNotify( NotifyEvent& _rNEvt )
89 if ( _rNEvt.GetType() == EVENT_KEYINPUT )
91 const ::KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
92 if ( ( pKeyEvent->GetKeyCode().GetModifier() == 0 )
93 && ( ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEUP )
94 || ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEDOWN )
98 if ( !ListBoxType::IsInDropDown() )
100 // don't give the base class a chance to consume the event, in the property browser, it is
101 // intended to scroll the complete property page
102 return ListBoxType::GetParent()->PreNotify( _rNEvt );
106 return ListBoxType::PreNotify( _rNEvt );
109 //========================================================================
110 //= OTimeControl
111 //========================================================================
112 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< TimeField > > OTimeControl_Base;
113 class OTimeControl : public OTimeControl_Base
115 public:
116 OTimeControl( Window* pParent, WinBits nWinStyle );
118 // XPropertyControl
119 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
120 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
121 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
124 //========================================================================
125 //= ODateControl
126 //========================================================================
127 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< CalendarField > > ODateControl_Base;
128 class ODateControl : public ODateControl_Base
130 public:
131 ODateControl( Window* pParent, WinBits nWinStyle );
133 // XPropertyControl
134 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
135 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
136 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
139 //========================================================================
140 //= OEditControl
141 //========================================================================
142 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< Edit > > OEditControl_Base;
143 class OEditControl : public OEditControl_Base
145 protected:
146 sal_Bool m_bIsPassword : 1;
148 public:
149 OEditControl( Window* _pParent, sal_Bool _bPassWord, WinBits nWinStyle );
151 // XPropertyControl
152 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
153 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
154 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
156 protected:
157 virtual void modified();
160 //========================================================================
161 //= ODateTimeControl
162 //========================================================================
163 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< FormattedField > > ODateTimeControl_Base;
164 class ODateTimeControl : public ODateTimeControl_Base
166 public:
167 ODateTimeControl( Window* pParent,WinBits nWinStyle );
169 // XPropertyControl
170 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
171 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
172 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
175 //========================================================================
176 //= HyperlinkInput
177 //========================================================================
178 class HyperlinkInput : public Edit
180 private:
181 Point m_aMouseButtonDownPos;
182 Link m_aClickHandler;
184 public:
185 HyperlinkInput( Window* _pParent, WinBits _nWinStyle );
187 /** sets the handler which will (asynchronously, with locked SolarMutex) be called
188 when the hyperlink has been clicked by the user
190 void SetClickHdl( const Link& _rHdl ) { m_aClickHandler = _rHdl; }
191 const Link& GetClickHdl( ) const { return m_aClickHandler; }
193 protected:
194 virtual void MouseMove( const MouseEvent& rMEvt );
195 virtual void MouseButtonDown( const MouseEvent& rMEvt );
196 virtual void MouseButtonUp( const MouseEvent& rMEvt );
197 virtual void Tracking( const TrackingEvent& rTEvt );
199 private:
200 void impl_checkEndClick( const MouseEvent rMEvt );
201 bool impl_textHitTest( const Point& _rWindowPos );
204 //========================================================================
205 //= OHyperlinkControl
206 //========================================================================
207 typedef CommonBehaviourControl< ::com::sun::star::inspection::XHyperlinkControl, ControlWindow< HyperlinkInput > > OHyperlinkControl_Base;
208 class OHyperlinkControl : public OHyperlinkControl_Base
210 private:
211 ::cppu::OInterfaceContainerHelper m_aActionListeners;
213 public:
214 OHyperlinkControl( Window* _pParent, WinBits _nWinStyle );
216 // XPropertyControl
217 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
218 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
219 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
221 // XHyperlinkControl
222 virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
223 virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
225 protected:
226 // XComponent
227 virtual void SAL_CALL disposing();
229 protected:
230 DECL_LINK( OnHyperlinkClicked, void* );
233 //========================================================================
234 //= CustomConvertibleNumericField
235 //========================================================================
236 class CustomConvertibleNumericField : public ControlWindow< MetricField >
238 typedef ControlWindow< MetricField > BaseClass;
240 public:
241 CustomConvertibleNumericField( Window* _pParent, WinBits _nStyle )
242 :BaseClass( _pParent, _nStyle )
246 sal_Int64 GetLastValue() const { return mnLastValue; }
249 //========================================================================
250 //= ONumericControl
251 //========================================================================
252 typedef CommonBehaviourControl< ::com::sun::star::inspection::XNumericControl, CustomConvertibleNumericField > ONumericControl_Base;
253 class ONumericControl : public ONumericControl_Base
255 private:
256 FieldUnit m_eValueUnit;
257 sal_Int16 m_nFieldToUNOValueFactor;
259 public:
260 ONumericControl( Window* pParent, WinBits nWinStyle );
262 // XPropertyControl
263 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
264 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
265 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
267 // XNumericControl
268 virtual ::sal_Int16 SAL_CALL getDecimalDigits() throw (::com::sun::star::uno::RuntimeException);
269 virtual void SAL_CALL setDecimalDigits( ::sal_Int16 _decimaldigits ) throw (::com::sun::star::uno::RuntimeException);
270 virtual ::com::sun::star::beans::Optional< double > SAL_CALL getMinValue() throw (::com::sun::star::uno::RuntimeException);
271 virtual void SAL_CALL setMinValue( const ::com::sun::star::beans::Optional< double >& _minvalue ) throw (::com::sun::star::uno::RuntimeException);
272 virtual ::com::sun::star::beans::Optional< double > SAL_CALL getMaxValue() throw (::com::sun::star::uno::RuntimeException);
273 virtual void SAL_CALL setMaxValue( const ::com::sun::star::beans::Optional< double >& _maxvalue ) throw (::com::sun::star::uno::RuntimeException);
274 virtual ::sal_Int16 SAL_CALL getDisplayUnit() throw (::com::sun::star::uno::RuntimeException);
275 virtual void SAL_CALL setDisplayUnit( ::sal_Int16 _displayunit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
276 virtual ::sal_Int16 SAL_CALL getValueUnit() throw (::com::sun::star::uno::RuntimeException);
277 virtual void SAL_CALL setValueUnit( ::sal_Int16 _valueunit ) throw (::com::sun::star::uno::RuntimeException);
279 private:
280 /** converts an API value (<code>double</code>, as passed into <code>set[Max|Min|]Value) into
281 a <code>long</code> value which can be passed to our NumericField.
283 The conversion respects our decimal digits as well as our value factor (<member>m_nFieldToUNOValueFactor</member>).
285 long impl_apiValueToFieldValue_nothrow( double _nApiValue ) const;
287 /** converts a control value, as obtained from our Numeric field, into a value which can passed
288 to outer callers via our UNO API.
290 double impl_fieldValueToApiValue_nothrow( sal_Int64 _nFieldValue ) const;
293 //========================================================================
294 //= OColorControl
295 //========================================================================
296 typedef CommonBehaviourControl < ::com::sun::star::inspection::XStringListControl
297 , ListLikeControlWithModifyHandler< ColorListBox >
298 > OColorControl_Base;
299 class OColorControl : public OColorControl_Base
301 private:
302 ::std::set< ::rtl::OUString > m_aNonColorEntries;
304 public:
305 OColorControl( Window* pParent, WinBits nWinStyle );
307 // XPropertyControl
308 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
309 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
310 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
312 // XStringListControl
313 virtual void SAL_CALL clearList( ) throw (::com::sun::star::uno::RuntimeException);
314 virtual void SAL_CALL prependListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
315 virtual void SAL_CALL appendListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
316 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getListEntries( ) throw (::com::sun::star::uno::RuntimeException);
318 protected:
319 virtual void modified();
322 //========================================================================
323 //= OListboxControl
324 //========================================================================
325 typedef CommonBehaviourControl < ::com::sun::star::inspection::XStringListControl
326 , ListLikeControlWithModifyHandler< ListBox >
327 > OListboxControl_Base;
328 class OListboxControl : public OListboxControl_Base
330 public:
331 OListboxControl( Window* pParent, WinBits nWinStyle );
333 // XPropertyControl
334 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
335 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
336 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
338 // XStringListControl
339 virtual void SAL_CALL clearList( ) throw (::com::sun::star::uno::RuntimeException);
340 virtual void SAL_CALL prependListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
341 virtual void SAL_CALL appendListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
342 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getListEntries( ) throw (::com::sun::star::uno::RuntimeException);
344 protected:
345 virtual void modified();
348 //========================================================================
349 //= OComboboxControl
350 //========================================================================
351 typedef CommonBehaviourControl< ::com::sun::star::inspection::XStringListControl, ControlWindow< ComboBox > > OComboboxControl_Base;
352 class OComboboxControl : public OComboboxControl_Base
354 public:
355 OComboboxControl( Window* pParent, WinBits nWinStyle );
357 // XPropertyControl
358 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
359 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
360 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
362 // XStringListControl
363 virtual void SAL_CALL clearList( ) throw (::com::sun::star::uno::RuntimeException);
364 virtual void SAL_CALL prependListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
365 virtual void SAL_CALL appendListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
366 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getListEntries( ) throw (::com::sun::star::uno::RuntimeException);
368 protected:
369 DECL_LINK( OnEntrySelected, void* );
372 //========================================================================
373 //= DropDownEditControl
374 //========================================================================
375 enum MultiLineOperationMode
377 eStringList,
378 eMultiLineText
380 //========================================================================
381 //= DropDownEditControl
382 //========================================================================
383 class OMultilineFloatingEdit;
384 typedef ControlWindow< Edit > DropDownEditControl_Base;
385 /** an Edit field which can be used as ControlWindow, and has a drop-down button
387 class DropDownEditControl : public DropDownEditControl_Base
389 private:
390 OMultilineFloatingEdit* m_pFloatingEdit;
391 MultiLineEdit* m_pImplEdit;
392 PushButton* m_pDropdownButton;
393 MultiLineOperationMode m_nOperationMode;
394 sal_Bool m_bDropdown : 1;
396 public:
397 DropDownEditControl( Window* _pParent, WinBits _nStyle );
398 ~DropDownEditControl();
400 void setOperationMode( MultiLineOperationMode _eMode ) { m_nOperationMode = _eMode; }
401 MultiLineOperationMode getOperationMode() const { return m_nOperationMode; }
403 void SetTextValue( const ::rtl::OUString& _rText );
404 ::rtl::OUString GetTextValue() const;
406 void SetStringListValue( const StlSyntaxSequence< ::rtl::OUString >& _rStrings );
407 StlSyntaxSequence< ::rtl::OUString >
408 GetStringListValue() const;
410 // ControlWindow overridables
411 virtual void setControlHelper( ControlHelper& _rControlHelper );
413 protected:
414 // Window overridables
415 virtual long PreNotify( NotifyEvent& rNEvt );
416 virtual void Resize();
418 protected:
419 long FindPos(long nSinglePos);
421 private:
422 DECL_LINK( ReturnHdl, OMultilineFloatingEdit* );
423 DECL_LINK( DropDownHdl, PushButton* );
425 sal_Bool ShowDropDown( sal_Bool bShow );
428 //========================================================================
429 //= OMultilineEditControl
430 //========================================================================
431 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, DropDownEditControl > OMultilineEditControl_Base;
432 class OMultilineEditControl : public OMultilineEditControl_Base
434 public:
435 OMultilineEditControl( Window* pParent, MultiLineOperationMode _eMode, WinBits nWinStyle );
437 // XPropertyControl
438 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
439 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
440 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
443 //............................................................................
444 } // namespace pcr
445 //............................................................................
447 #endif // _EXTENSIONS_PROPCTRLR_STANDARDCONTROL_HXX_