bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / propctrlr / standardcontrol.hxx
blobaa8e6aff5fd93c651d52148a17a0649a13a26569
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_STANDARDCONTROL_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_STANDARDCONTROL_HXX
23 #include "commoncontrol.hxx"
24 #include "pcrcommon.hxx"
26 #include <com/sun/star/inspection/XNumericControl.hpp>
27 #include <com/sun/star/inspection/XStringListControl.hpp>
28 #include <com/sun/star/inspection/XHyperlinkControl.hpp>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <vcl/field.hxx>
31 #include <vcl/longcurr.hxx>
32 #include <svtools/ctrlbox.hxx>
33 #include <vcl/lstbox.hxx>
34 #include <vcl/combobox.hxx>
35 #include <svtools/calendar.hxx>
36 #include <svtools/fmtfield.hxx>
38 #include <set>
40 class PushButton;
41 class MultiLineEdit;
43 namespace pcr
48 //= ListLikeControlWithModifyHandler
50 /** Very small helper class which adds a SetModifyHdl to a ListBox-derived class,
51 thus giving this class the same API (as far as the CommonBehaviourControl is concerned)
52 as all other windows.
54 template< class LISTBOX_WINDOW >
55 class ListLikeControlWithModifyHandler : public ControlWindow< LISTBOX_WINDOW >
57 protected:
58 typedef ControlWindow< LISTBOX_WINDOW > ListBoxType;
60 public:
61 ListLikeControlWithModifyHandler( vcl::Window* _pParent, WinBits _nStyle )
62 :ListBoxType( _pParent, _nStyle )
66 void SetModifyHdl( const Link<>& _rLink ) { ListBoxType::SetSelectHdl( _rLink ); }
68 protected:
69 bool PreNotify( NotifyEvent& _rNEvt );
73 template< class LISTBOX_WINDOW >
74 bool ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::PreNotify( NotifyEvent& _rNEvt )
76 if ( _rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
78 const ::KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
79 if ( ( pKeyEvent->GetKeyCode().GetModifier() == 0 )
80 && ( ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEUP )
81 || ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEDOWN )
85 if ( !ListBoxType::IsInDropDown() )
87 // don't give the base class a chance to consume the event, in the property browser, it is
88 // intended to scroll the complete property page
89 return ListBoxType::GetParent()->PreNotify( _rNEvt );
93 return ListBoxType::PreNotify( _rNEvt );
97 //= OTimeControl
99 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< TimeField > > OTimeControl_Base;
100 class OTimeControl : public OTimeControl_Base
102 public:
103 OTimeControl( vcl::Window* pParent, WinBits nWinStyle );
105 // XPropertyControl
106 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
108 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 //= ODateControl
114 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< CalendarField > > ODateControl_Base;
115 class ODateControl : public ODateControl_Base
117 public:
118 ODateControl( vcl::Window* pParent, WinBits nWinStyle );
120 // XPropertyControl
121 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
123 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
127 //= OEditControl
129 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< Edit > > OEditControl_Base;
130 class OEditControl : public OEditControl_Base
132 protected:
133 bool m_bIsPassword : 1;
135 public:
136 OEditControl( vcl::Window* _pParent, bool _bPassWord, WinBits nWinStyle );
138 // XPropertyControl
139 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 protected:
144 virtual void modified() SAL_OVERRIDE;
148 //= ODateTimeControl
150 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< FormattedField > > ODateTimeControl_Base;
151 class ODateTimeControl : public ODateTimeControl_Base
153 public:
154 ODateTimeControl( vcl::Window* pParent,WinBits nWinStyle );
156 // XPropertyControl
157 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
163 //= HyperlinkInput
165 class HyperlinkInput : public Edit
167 private:
168 Point m_aMouseButtonDownPos;
169 Link<> m_aClickHandler;
171 public:
172 HyperlinkInput( vcl::Window* _pParent, WinBits _nWinStyle );
174 /** sets the handler which will (asynchronously, with locked SolarMutex) be called
175 when the hyperlink has been clicked by the user
177 void SetClickHdl( const Link<>& _rHdl ) { m_aClickHandler = _rHdl; }
178 const Link<>& GetClickHdl( ) const { return m_aClickHandler; }
180 protected:
181 virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
182 virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
183 virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
184 virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
186 private:
187 void impl_checkEndClick( const MouseEvent& rMEvt );
188 bool impl_textHitTest( const Point& rWindowPos );
192 //= OHyperlinkControl
194 typedef CommonBehaviourControl< ::com::sun::star::inspection::XHyperlinkControl, ControlWindow< HyperlinkInput > > OHyperlinkControl_Base;
195 class OHyperlinkControl : public OHyperlinkControl_Base
197 private:
198 ::cppu::OInterfaceContainerHelper m_aActionListeners;
200 public:
201 OHyperlinkControl( vcl::Window* _pParent, WinBits _nWinStyle );
203 // XPropertyControl
204 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
205 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
206 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
208 // XHyperlinkControl
209 virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
210 virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
212 protected:
213 // XComponent
214 virtual void SAL_CALL disposing() SAL_OVERRIDE;
216 protected:
217 DECL_LINK( OnHyperlinkClicked, void* );
221 //= CustomConvertibleNumericField
223 class CustomConvertibleNumericField : public ControlWindow< MetricField >
225 typedef ControlWindow< MetricField > BaseClass;
227 public:
228 CustomConvertibleNumericField( vcl::Window* _pParent, WinBits _nStyle )
229 :BaseClass( _pParent, _nStyle )
233 sal_Int64 GetLastValue() const { return mnLastValue; }
237 //= ONumericControl
239 typedef CommonBehaviourControl< ::com::sun::star::inspection::XNumericControl, CustomConvertibleNumericField > ONumericControl_Base;
240 class ONumericControl : public ONumericControl_Base
242 private:
243 FieldUnit m_eValueUnit;
244 sal_Int16 m_nFieldToUNOValueFactor;
246 public:
247 ONumericControl( vcl::Window* pParent, WinBits nWinStyle );
249 // XPropertyControl
250 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
251 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
252 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
254 // XNumericControl
255 virtual ::sal_Int16 SAL_CALL getDecimalDigits() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
256 virtual void SAL_CALL setDecimalDigits( ::sal_Int16 _decimaldigits ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
257 virtual ::com::sun::star::beans::Optional< double > SAL_CALL getMinValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
258 virtual void SAL_CALL setMinValue( const ::com::sun::star::beans::Optional< double >& _minvalue ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
259 virtual ::com::sun::star::beans::Optional< double > SAL_CALL getMaxValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
260 virtual void SAL_CALL setMaxValue( const ::com::sun::star::beans::Optional< double >& _maxvalue ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
261 virtual ::sal_Int16 SAL_CALL getDisplayUnit() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
262 virtual void SAL_CALL setDisplayUnit( ::sal_Int16 _displayunit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 virtual ::sal_Int16 SAL_CALL getValueUnit() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 virtual void SAL_CALL setValueUnit( ::sal_Int16 _valueunit ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
266 private:
267 /** converts an API value (<code>double</code>, as passed into <code>set[Max|Min|]Value) into
268 a <code>long</code> value which can be passed to our NumericField.
270 The conversion respects our decimal digits as well as our value factor (<member>m_nFieldToUNOValueFactor</member>).
272 long impl_apiValueToFieldValue_nothrow( double _nApiValue ) const;
274 /** converts a control value, as obtained from our Numeric field, into a value which can passed
275 to outer callers via our UNO API.
277 double impl_fieldValueToApiValue_nothrow( sal_Int64 _nFieldValue ) const;
281 //= OColorControl
283 typedef CommonBehaviourControl < ::com::sun::star::inspection::XStringListControl
284 , ListLikeControlWithModifyHandler< ColorListBox >
285 > OColorControl_Base;
286 class OColorControl : public OColorControl_Base
288 private:
289 ::std::set< OUString > m_aNonColorEntries;
291 public:
292 OColorControl( vcl::Window* pParent, WinBits nWinStyle );
294 // XPropertyControl
295 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
296 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
297 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
299 // XStringListControl
300 virtual void SAL_CALL clearList( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
301 virtual void SAL_CALL prependListEntry( const OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
302 virtual void SAL_CALL appendListEntry( const OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
303 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getListEntries( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
305 protected:
306 virtual void modified() SAL_OVERRIDE;
310 //= OListboxControl
312 typedef CommonBehaviourControl < ::com::sun::star::inspection::XStringListControl
313 , ListLikeControlWithModifyHandler< ListBox >
314 > OListboxControl_Base;
315 class OListboxControl : public OListboxControl_Base
317 public:
318 OListboxControl( vcl::Window* pParent, WinBits nWinStyle );
320 // XPropertyControl
321 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
322 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
323 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
325 // XStringListControl
326 virtual void SAL_CALL clearList( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
327 virtual void SAL_CALL prependListEntry( const OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
328 virtual void SAL_CALL appendListEntry( const OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
329 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getListEntries( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
331 protected:
332 virtual void modified() SAL_OVERRIDE;
336 //= OComboboxControl
338 typedef CommonBehaviourControl< ::com::sun::star::inspection::XStringListControl, ControlWindow< ComboBox > > OComboboxControl_Base;
339 class OComboboxControl : public OComboboxControl_Base
341 public:
342 OComboboxControl( vcl::Window* pParent, WinBits nWinStyle );
344 // XPropertyControl
345 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
346 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
347 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
349 // XStringListControl
350 virtual void SAL_CALL clearList( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
351 virtual void SAL_CALL prependListEntry( const OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
352 virtual void SAL_CALL appendListEntry( const OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
353 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getListEntries( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
355 protected:
356 DECL_LINK( OnEntrySelected, void* );
360 //= DropDownEditControl
362 enum MultiLineOperationMode
364 eStringList,
365 eMultiLineText
368 //= DropDownEditControl
370 class OMultilineFloatingEdit;
371 typedef ControlWindow< Edit > DropDownEditControl_Base;
372 /** an Edit field which can be used as ControlWindow, and has a drop-down button
374 class DropDownEditControl : public DropDownEditControl_Base
376 private:
377 VclPtr<OMultilineFloatingEdit> m_pFloatingEdit;
378 VclPtr<MultiLineEdit> m_pImplEdit;
379 VclPtr<PushButton> m_pDropdownButton;
380 MultiLineOperationMode m_nOperationMode;
381 bool m_bDropdown : 1;
383 public:
384 DropDownEditControl( vcl::Window* _pParent, WinBits _nStyle );
385 virtual ~DropDownEditControl();
386 virtual void dispose() SAL_OVERRIDE;
388 void setOperationMode( MultiLineOperationMode _eMode ) { m_nOperationMode = _eMode; }
389 MultiLineOperationMode getOperationMode() const { return m_nOperationMode; }
391 void SetTextValue( const OUString& _rText );
392 OUString GetTextValue() const;
394 void SetStringListValue( const StlSyntaxSequence< OUString >& _rStrings );
395 StlSyntaxSequence< OUString >
396 GetStringListValue() const;
398 // ControlWindow overridables
399 virtual void setControlHelper( ControlHelper& _rControlHelper ) SAL_OVERRIDE;
401 protected:
402 // Window overridables
403 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
404 virtual void Resize() SAL_OVERRIDE;
406 protected:
407 long FindPos(long nSinglePos);
409 private:
410 DECL_LINK( ReturnHdl, OMultilineFloatingEdit* );
411 DECL_LINK( DropDownHdl, PushButton* );
413 bool ShowDropDown( bool bShow );
417 //= OMultilineEditControl
419 typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, DropDownEditControl > OMultilineEditControl_Base;
420 class OMultilineEditControl : public OMultilineEditControl_Base
422 public:
423 OMultilineEditControl( vcl::Window* pParent, MultiLineOperationMode _eMode, WinBits nWinStyle );
425 // XPropertyControl
426 virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
427 virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
428 virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
432 } // namespace pcr
435 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_STANDARDCONTROL_HXX
437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */