Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / standardcontrol.hxx
blobf78c225e11751f2b68afbd9669997dd20daaf4f5
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 <svtools/ctrlbox.hxx>
32 #include <vcl/lstbox.hxx>
33 #include <vcl/combobox.hxx>
34 #include <svtools/calendar.hxx>
35 #include <vcl/fmtfield.hxx>
36 #include <svx/colorbox.hxx>
38 #include <set>
40 class PushButton;
41 class MultiLineEdit;
43 namespace pcr
47 //= ListLikeControlWithModifyHandler
49 /** Very small helper class which adds a SetModifyHdl to a ListBox-derived class,
50 thus giving this class the same API (as far as the CommonBehaviourControl is concerned)
51 as all other windows.
53 template< class TListboxWindow >
54 class ListLikeControlWithModifyHandler : public TListboxWindow
56 public:
57 ListLikeControlWithModifyHandler( vcl::Window* _pParent, WinBits _nStyle )
58 : TListboxWindow( _pParent, _nStyle )
60 TListboxWindow::SetSelectHdl( LINK(this, ListLikeControlWithModifyHandler, OnSelect) );
63 void SetModifyHdl( const Link<TListboxWindow&,void>& _rLink ) { aModifyHdl = _rLink; }
64 private:
65 DECL_LINK(OnSelect, TListboxWindow&, void);
66 Link<TListboxWindow&,void> aModifyHdl;
69 template< class LISTBOX_WINDOW >
70 void ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::LinkStubOnSelect(void * instance, LISTBOX_WINDOW& data) {
71 return static_cast<ListLikeControlWithModifyHandler< LISTBOX_WINDOW > *>(instance)->OnSelect(data);
73 template< class LISTBOX_WINDOW >
74 void ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::OnSelect(LISTBOX_WINDOW& rListBox)
76 aModifyHdl.Call(rListBox);
79 //= OTimeControl
81 typedef CommonBehaviourControl< css::inspection::XPropertyControl, TimeField > OTimeControl_Base;
82 class OTimeControl : public OTimeControl_Base
84 public:
85 OTimeControl( vcl::Window* pParent, WinBits nWinStyle );
87 // XPropertyControl
88 virtual css::uno::Any SAL_CALL getValue() override;
89 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
90 virtual css::uno::Type SAL_CALL getValueType() override;
94 //= ODateControl
96 typedef CommonBehaviourControl< css::inspection::XPropertyControl, CalendarField > ODateControl_Base;
97 class ODateControl : public ODateControl_Base
99 public:
100 ODateControl( vcl::Window* pParent, WinBits nWinStyle );
102 // XPropertyControl
103 virtual css::uno::Any SAL_CALL getValue() override;
104 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
105 virtual css::uno::Type SAL_CALL getValueType() override;
109 //= OEditControl
111 typedef CommonBehaviourControl< css::inspection::XPropertyControl, Edit > OEditControl_Base;
112 class OEditControl final : public OEditControl_Base
114 bool m_bIsPassword : 1;
116 public:
117 OEditControl( vcl::Window* _pParent, bool _bPassWord, WinBits nWinStyle );
119 // XPropertyControl
120 virtual css::uno::Any SAL_CALL getValue() override;
121 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
122 virtual css::uno::Type SAL_CALL getValueType() override;
124 private:
125 // CommonBehaviourControlHelper::modified
126 virtual void setModified() override;
130 //= ODateTimeControl
132 typedef CommonBehaviourControl< css::inspection::XPropertyControl, FormattedField > ODateTimeControl_Base;
133 class ODateTimeControl : public ODateTimeControl_Base
135 public:
136 ODateTimeControl( vcl::Window* pParent,WinBits nWinStyle );
138 // XPropertyControl
139 virtual css::uno::Any SAL_CALL getValue() override;
140 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
141 virtual css::uno::Type SAL_CALL getValueType() override;
145 //= HyperlinkInput
147 class HyperlinkInput : public Edit
149 private:
150 Point m_aMouseButtonDownPos;
151 Link<void*,void> m_aClickHandler;
153 public:
154 HyperlinkInput( vcl::Window* _pParent, WinBits _nWinStyle );
156 /** sets the handler which will (asynchronously, with locked SolarMutex) be called
157 when the hyperlink has been clicked by the user
159 void SetClickHdl( const Link<void*,void>& _rHdl ) { m_aClickHandler = _rHdl; }
161 protected:
162 virtual void MouseMove( const MouseEvent& rMEvt ) override;
163 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
164 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
165 virtual void Tracking( const TrackingEvent& rTEvt ) override;
167 private:
168 void impl_checkEndClick( const MouseEvent& rMEvt );
169 bool impl_textHitTest( const Point& rWindowPos );
173 //= OHyperlinkControl
175 typedef CommonBehaviourControl< css::inspection::XHyperlinkControl, HyperlinkInput > OHyperlinkControl_Base;
176 class OHyperlinkControl final : public OHyperlinkControl_Base
178 ::comphelper::OInterfaceContainerHelper2 m_aActionListeners;
180 public:
181 OHyperlinkControl( vcl::Window* _pParent, WinBits _nWinStyle );
183 // XPropertyControl
184 virtual css::uno::Any SAL_CALL getValue() override;
185 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
186 virtual css::uno::Type SAL_CALL getValueType() override;
188 // XHyperlinkControl
189 virtual void SAL_CALL addActionListener( const css::uno::Reference< css::awt::XActionListener >& listener ) override;
190 virtual void SAL_CALL removeActionListener( const css::uno::Reference< css::awt::XActionListener >& listener ) override;
192 private:
193 // XComponent
194 virtual void SAL_CALL disposing() override;
196 DECL_LINK( OnHyperlinkClicked, void*, void );
200 //= CustomConvertibleNumericField
202 class CustomConvertibleNumericField : public MetricField
204 public:
205 CustomConvertibleNumericField( vcl::Window* _pParent, WinBits _nStyle )
206 :MetricField( _pParent, _nStyle )
210 sal_Int64 GetLastValue() const { return mnLastValue; }
214 //= ONumericControl
216 typedef CommonBehaviourControl< css::inspection::XNumericControl, CustomConvertibleNumericField > ONumericControl_Base;
217 class ONumericControl : public ONumericControl_Base
219 private:
220 FieldUnit m_eValueUnit;
221 sal_Int16 m_nFieldToUNOValueFactor;
223 public:
224 ONumericControl( vcl::Window* pParent, WinBits nWinStyle );
226 // XPropertyControl
227 virtual css::uno::Any SAL_CALL getValue() override;
228 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
229 virtual css::uno::Type SAL_CALL getValueType() override;
231 // XNumericControl
232 virtual ::sal_Int16 SAL_CALL getDecimalDigits() override;
233 virtual void SAL_CALL setDecimalDigits( ::sal_Int16 _decimaldigits ) override;
234 virtual css::beans::Optional< double > SAL_CALL getMinValue() override;
235 virtual void SAL_CALL setMinValue( const css::beans::Optional< double >& _minvalue ) override;
236 virtual css::beans::Optional< double > SAL_CALL getMaxValue() override;
237 virtual void SAL_CALL setMaxValue( const css::beans::Optional< double >& _maxvalue ) override;
238 virtual ::sal_Int16 SAL_CALL getDisplayUnit() override;
239 virtual void SAL_CALL setDisplayUnit( ::sal_Int16 _displayunit ) override;
240 virtual ::sal_Int16 SAL_CALL getValueUnit() override;
241 virtual void SAL_CALL setValueUnit( ::sal_Int16 _valueunit ) override;
243 private:
244 /** converts an API value (<code>double</code>, as passed into <code>set[Max|Min|]Value) into
245 a <code>long</code> value which can be passed to our NumericField.
247 The conversion respects our decimal digits as well as our value factor (<member>m_nFieldToUNOValueFactor</member>).
249 long impl_apiValueToFieldValue_nothrow( double _nApiValue ) const;
251 /** converts a control value, as obtained from our Numeric field, into a value which can passed
252 to outer callers via our UNO API.
254 double impl_fieldValueToApiValue_nothrow( sal_Int64 _nFieldValue ) const;
258 //= OColorControl
260 typedef CommonBehaviourControl < css::inspection::XPropertyControl
261 , ListLikeControlWithModifyHandler<SvxColorListBox>
262 > OColorControl_Base;
263 class OColorControl : public OColorControl_Base
265 public:
266 OColorControl( vcl::Window* pParent, WinBits nWinStyle );
268 // XPropertyControl
269 virtual css::uno::Any SAL_CALL getValue() override;
270 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
271 virtual css::uno::Type SAL_CALL getValueType() override;
273 protected:
274 // CommonBehaviourControlHelper::setModified
275 virtual void setModified() override;
279 //= OListboxControl
281 typedef CommonBehaviourControl < css::inspection::XStringListControl
282 , ListLikeControlWithModifyHandler< ListBox >
283 > OListboxControl_Base;
284 class OListboxControl : public OListboxControl_Base
286 public:
287 OListboxControl( vcl::Window* pParent, WinBits nWinStyle );
289 // XPropertyControl
290 virtual css::uno::Any SAL_CALL getValue() override;
291 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
292 virtual css::uno::Type SAL_CALL getValueType() override;
294 // XStringListControl
295 virtual void SAL_CALL clearList( ) override;
296 virtual void SAL_CALL prependListEntry( const OUString& NewEntry ) override;
297 virtual void SAL_CALL appendListEntry( const OUString& NewEntry ) override;
298 virtual css::uno::Sequence< OUString > SAL_CALL getListEntries( ) override;
300 protected:
301 // CommonBehaviourControlHelper::setModified
302 virtual void setModified() override;
306 //= OComboboxControl
308 typedef CommonBehaviourControl< css::inspection::XStringListControl, ComboBox > OComboboxControl_Base;
309 class OComboboxControl final : public OComboboxControl_Base
311 public:
312 OComboboxControl( vcl::Window* pParent, WinBits nWinStyle );
314 // XPropertyControl
315 virtual css::uno::Any SAL_CALL getValue() override;
316 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
317 virtual css::uno::Type SAL_CALL getValueType() override;
319 // XStringListControl
320 virtual void SAL_CALL clearList( ) override;
321 virtual void SAL_CALL prependListEntry( const OUString& NewEntry ) override;
322 virtual void SAL_CALL appendListEntry( const OUString& NewEntry ) override;
323 virtual css::uno::Sequence< OUString > SAL_CALL getListEntries( ) override;
325 private:
326 DECL_LINK( OnEntrySelected, ComboBox&, void );
330 //= DropDownEditControl
332 enum MultiLineOperationMode
334 eStringList,
335 eMultiLineText
338 //= DropDownEditControl
340 class OMultilineFloatingEdit;
341 /** an Edit field which can be used as ControlWindow, and has a drop-down button
343 class DropDownEditControl final : public Edit
345 VclPtr<OMultilineFloatingEdit> m_pFloatingEdit;
346 VclPtr<MultiLineEdit> m_pImplEdit;
347 VclPtr<PushButton> m_pDropdownButton;
348 MultiLineOperationMode m_nOperationMode;
349 bool m_bDropdown : 1;
350 CommonBehaviourControlHelper* m_pHelper;
352 public:
353 DropDownEditControl( vcl::Window* _pParent, WinBits _nStyle );
354 virtual ~DropDownEditControl() override;
355 virtual void dispose() override;
357 void setControlHelper( CommonBehaviourControlHelper& _rControlHelper );
358 void setOperationMode( MultiLineOperationMode _eMode ) { m_nOperationMode = _eMode; }
359 MultiLineOperationMode getOperationMode() const { return m_nOperationMode; }
361 void SetTextValue( const OUString& _rText );
362 OUString GetTextValue() const;
364 void SetStringListValue( const StlSyntaxSequence< OUString >& _rStrings );
365 StlSyntaxSequence< OUString >
366 GetStringListValue() const;
368 private:
369 // Window overridables
370 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
371 virtual void Resize() override;
373 long FindPos(long nSinglePos);
375 DECL_LINK( ReturnHdl, FloatingWindow*, void );
376 DECL_LINK( DropDownHdl, Button*, void );
378 void ShowDropDown( bool bShow );
382 //= OMultilineEditControl
384 typedef CommonBehaviourControl< css::inspection::XPropertyControl, DropDownEditControl > OMultilineEditControl_Base;
385 class OMultilineEditControl : public OMultilineEditControl_Base
387 public:
388 OMultilineEditControl( vcl::Window* pParent, MultiLineOperationMode _eMode, WinBits nWinStyle );
390 // XPropertyControl
391 virtual css::uno::Any SAL_CALL getValue() override;
392 virtual void SAL_CALL setValue( const css::uno::Any& _value ) override;
393 virtual css::uno::Type SAL_CALL getValueType() override;
397 } // namespace pcr
400 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_STANDARDCONTROL_HXX
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */