1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "commoncontrol.hxx"
23 #include "pcrcommon.hxx"
25 #include <com/sun/star/inspection/XNumericControl.hpp>
26 #include <com/sun/star/inspection/XStringListControl.hpp>
27 #include <com/sun/star/inspection/XHyperlinkControl.hpp>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <comphelper/interfacecontainer2.hxx>
30 #include <svtools/ctrlbox.hxx>
31 #include <svx/colorbox.hxx>
36 typedef CommonBehaviourControl
<css::inspection::XPropertyControl
, weld::FormattedSpinButton
> OTimeControl_Base
;
37 class OTimeControl
: public OTimeControl_Base
39 std::unique_ptr
<weld::TimeFormatter
> m_xFormatter
;
41 OTimeControl(std::unique_ptr
<weld::FormattedSpinButton
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
43 virtual void SAL_CALL
disposing() override
46 OTimeControl_Base::disposing();
50 virtual css::uno::Any SAL_CALL
getValue() override
;
51 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
52 virtual css::uno::Type SAL_CALL
getValueType() override
;
54 virtual void SetModifyHandler() override
56 OTimeControl_Base::SetModifyHandler();
57 getTypedControlWindow()->connect_value_changed( LINK( this, CommonBehaviourControlHelper
, TimeModifiedHdl
) );
60 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
64 typedef CommonBehaviourControl
<css::inspection::XPropertyControl
, weld::Container
> ODateControl_Base
;
65 class ODateControl
: public ODateControl_Base
67 std::unique_ptr
<weld::Entry
> m_xEntry
;
68 std::unique_ptr
<SvtCalendarBox
> m_xCalendarBox
;
69 std::unique_ptr
<weld::DateFormatter
> m_xEntryFormatter
;
71 DECL_LINK(ActivateHdl
, SvtCalendarBox
&, void);
72 DECL_LINK(ToggleHdl
, weld::Toggleable
&, void);
75 ODateControl(std::unique_ptr
<weld::Container
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
78 virtual css::uno::Any SAL_CALL
getValue() override
;
79 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
80 virtual css::uno::Type SAL_CALL
getValueType() override
;
82 virtual void SetModifyHandler() override
84 ODateControl_Base::SetModifyHandler();
86 m_xEntry
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
87 m_xEntryFormatter
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
88 m_xCalendarBox
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
89 m_xCalendarBox
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
91 m_xEntryFormatter
->connect_changed(LINK(this, CommonBehaviourControlHelper
, EditModifiedHdl
));
94 virtual void SAL_CALL
disposing() override
;
96 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
100 typedef CommonBehaviourControl
<css::inspection::XPropertyControl
, weld::Entry
> OEditControl_Base
;
101 class OEditControl final
: public OEditControl_Base
103 bool m_bIsPassword
: 1;
106 OEditControl(std::unique_ptr
<weld::Entry
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bPassWord
, bool bReadOnly
);
109 virtual css::uno::Any SAL_CALL
getValue() override
;
110 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
111 virtual css::uno::Type SAL_CALL
getValueType() override
;
113 virtual void SetModifyHandler() override
115 OEditControl_Base::SetModifyHandler();
116 getTypedControlWindow()->connect_changed( LINK( this, CommonBehaviourControlHelper
, EditModifiedHdl
) );
120 // CommonBehaviourControlHelper::modified
121 virtual void setModified() override
;
122 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
126 typedef CommonBehaviourControl
<css::inspection::XPropertyControl
, weld::Container
> ODateTimeControl_Base
;
127 class ODateTimeControl
: public ODateTimeControl_Base
130 std::unique_ptr
<SvtCalendarBox
> m_xDate
;
131 std::unique_ptr
<weld::FormattedSpinButton
> m_xTime
;
132 std::unique_ptr
<weld::TimeFormatter
> m_xFormatter
;
135 ODateTimeControl(std::unique_ptr
<weld::Container
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
137 virtual void SetModifyHandler() override
139 m_xDate
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
140 m_xDate
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
141 m_xTime
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
142 m_xTime
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
144 m_xDate
->connect_selected( LINK( this, CommonBehaviourControlHelper
, DateModifiedHdl
) );
145 m_xTime
->connect_value_changed( LINK( this, CommonBehaviourControlHelper
, TimeModifiedHdl
) );
148 virtual void SAL_CALL
disposing() override
150 m_xFormatter
.reset();
153 ODateTimeControl_Base::disposing();
157 virtual css::uno::Any SAL_CALL
getValue() override
;
158 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
159 virtual css::uno::Type SAL_CALL
getValueType() override
;
161 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
164 //= OHyperlinkControl
165 typedef CommonBehaviourControl
<css::inspection::XHyperlinkControl
, weld::Container
> OHyperlinkControl_Base
;
166 class OHyperlinkControl final
: public OHyperlinkControl_Base
169 std::unique_ptr
<weld::Entry
> m_xEntry
;
170 std::unique_ptr
<weld::Button
> m_xButton
;
172 ::comphelper::OInterfaceContainerHelper2 m_aActionListeners
;
175 OHyperlinkControl(std::unique_ptr
<weld::Container
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
178 virtual css::uno::Any SAL_CALL
getValue() override
;
179 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
180 virtual css::uno::Type SAL_CALL
getValueType() override
;
182 virtual void SetModifyHandler() override
184 m_xEntry
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
185 m_xEntry
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
186 m_xButton
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
187 m_xButton
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
189 m_xEntry
->connect_changed( LINK( this, CommonBehaviourControlHelper
, EditModifiedHdl
) );
192 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
195 virtual void SAL_CALL
addActionListener( const css::uno::Reference
< css::awt::XActionListener
>& listener
) override
;
196 virtual void SAL_CALL
removeActionListener( const css::uno::Reference
< css::awt::XActionListener
>& listener
) override
;
200 virtual void SAL_CALL
disposing() override
;
202 DECL_LINK(OnHyperlinkClicked
, weld::Button
&, void);
206 typedef CommonBehaviourControl
<css::inspection::XNumericControl
, weld::MetricSpinButton
> ONumericControl_Base
;
207 class ONumericControl
: public ONumericControl_Base
210 FieldUnit m_eValueUnit
;
211 sal_Int16 m_nFieldToUNOValueFactor
;
214 ONumericControl(std::unique_ptr
<weld::MetricSpinButton
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
217 virtual css::uno::Any SAL_CALL
getValue() override
;
218 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
219 virtual css::uno::Type SAL_CALL
getValueType() override
;
222 virtual ::sal_Int16 SAL_CALL
getDecimalDigits() override
;
223 virtual void SAL_CALL
setDecimalDigits( ::sal_Int16 _decimaldigits
) override
;
224 virtual css::beans::Optional
< double > SAL_CALL
getMinValue() override
;
225 virtual void SAL_CALL
setMinValue( const css::beans::Optional
< double >& _minvalue
) override
;
226 virtual css::beans::Optional
< double > SAL_CALL
getMaxValue() override
;
227 virtual void SAL_CALL
setMaxValue( const css::beans::Optional
< double >& _maxvalue
) override
;
228 virtual ::sal_Int16 SAL_CALL
getDisplayUnit() override
;
229 virtual void SAL_CALL
setDisplayUnit( ::sal_Int16 _displayunit
) override
;
230 virtual ::sal_Int16 SAL_CALL
getValueUnit() override
;
231 virtual void SAL_CALL
setValueUnit( ::sal_Int16 _valueunit
) override
;
233 virtual void SetModifyHandler() override
235 ONumericControl_Base::SetModifyHandler();
236 weld::MetricSpinButton
* pSpinButton
= getTypedControlWindow();
237 pSpinButton
->connect_value_changed( LINK( this, CommonBehaviourControlHelper
, MetricModifiedHdl
) );
238 pSpinButton
->get_widget().connect_changed( LINK( this, CommonBehaviourControlHelper
, EditModifiedHdl
) );
242 virtual weld::Widget
* getWidget() override
{ return &getTypedControlWindow()->get_widget(); }
244 /** converts an API value (<code>double</code>, as passed into <code>set[Max|Min|]Value) into
245 a <code>int</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 sal_Int64
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 typedef CommonBehaviourControl
<css::inspection::XPropertyControl
, ColorListBox
> OColorControl_Base
;
259 class OColorControl
: public OColorControl_Base
262 OColorControl(std::unique_ptr
<ColorListBox
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
265 virtual css::uno::Any SAL_CALL
getValue() override
;
266 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
267 virtual css::uno::Type SAL_CALL
getValueType() override
;
269 virtual void SetModifyHandler() override
271 OColorControl_Base::SetModifyHandler();
272 getTypedControlWindow()->SetSelectHdl(LINK(this, CommonBehaviourControlHelper
, ColorModifiedHdl
));
276 // CommonBehaviourControlHelper::setModified
277 virtual void setModified() override
;
280 virtual weld::Widget
* getWidget() override
{ return &getTypedControlWindow()->get_widget(); }
284 typedef CommonBehaviourControl
<css::inspection::XStringListControl
, weld::ComboBox
> OListboxControl_Base
;
285 class OListboxControl
: public OListboxControl_Base
288 OListboxControl(std::unique_ptr
<weld::ComboBox
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
291 virtual css::uno::Any SAL_CALL
getValue() override
;
292 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
293 virtual css::uno::Type SAL_CALL
getValueType() override
;
295 // XStringListControl
296 virtual void SAL_CALL
clearList( ) override
;
297 virtual void SAL_CALL
prependListEntry( const OUString
& NewEntry
) override
;
298 virtual void SAL_CALL
appendListEntry( const OUString
& NewEntry
) override
;
299 virtual css::uno::Sequence
< OUString
> SAL_CALL
getListEntries( ) override
;
301 virtual void SetModifyHandler() override
303 OListboxControl_Base::SetModifyHandler();
304 getTypedControlWindow()->connect_changed(LINK(this, CommonBehaviourControlHelper
, ModifiedHdl
));
308 // CommonBehaviourControlHelper::setModified
309 virtual void setModified() override
;
310 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
314 typedef CommonBehaviourControl
< css::inspection::XStringListControl
, weld::ComboBox
> OComboboxControl_Base
;
315 class OComboboxControl final
: public OComboboxControl_Base
318 OComboboxControl(std::unique_ptr
<weld::ComboBox
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, bool bReadOnly
);
321 virtual css::uno::Any SAL_CALL
getValue() override
;
322 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
323 virtual css::uno::Type SAL_CALL
getValueType() override
;
325 // XStringListControl
326 virtual void SAL_CALL
clearList( ) override
;
327 virtual void SAL_CALL
prependListEntry( const OUString
& NewEntry
) override
;
328 virtual void SAL_CALL
appendListEntry( const OUString
& NewEntry
) override
;
329 virtual css::uno::Sequence
< OUString
> SAL_CALL
getListEntries( ) override
;
331 virtual void SetModifyHandler() override
333 OComboboxControl_Base::SetModifyHandler();
334 getTypedControlWindow()->connect_changed(LINK(this, CommonBehaviourControlHelper
, ModifiedHdl
));
337 // CommonBehaviourControlHelper::setModified
338 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
341 DECL_LINK( OnEntrySelected
, weld::ComboBox
&, void );
345 //= DropDownEditControl
347 enum MultiLineOperationMode
353 //= OMultilineEditControl
354 typedef CommonBehaviourControl
<css::inspection::XPropertyControl
, weld::Container
> OMultilineEditControl_Base
;
355 class OMultilineEditControl
: public OMultilineEditControl_Base
358 MultiLineOperationMode m_nOperationMode
;
359 std::unique_ptr
<weld::Entry
> m_xEntry
;
360 std::unique_ptr
<weld::MenuButton
> m_xButton
;
361 std::unique_ptr
<weld::Widget
> m_xPopover
;
362 std::unique_ptr
<weld::TextView
> m_xTextView
;
363 std::unique_ptr
<weld::Button
> m_xOk
;
365 void SetTextValue(const OUString
& rText
);
366 OUString
GetTextValue() const;
368 void SetStringListValue( const StlSyntaxSequence
< OUString
>& _rStrings
);
369 StlSyntaxSequence
< OUString
>
370 GetStringListValue() const;
372 DECL_LINK(ButtonHandler
, weld::Button
&, void);
373 DECL_LINK(TextViewModifiedHdl
, weld::TextView
&, void);
375 void CheckEntryTextViewMisMatch();
378 OMultilineEditControl(std::unique_ptr
<weld::Container
> xWidget
, std::unique_ptr
<weld::Builder
> xBuilder
, MultiLineOperationMode eMode
, bool bReadOnly
);
381 virtual css::uno::Any SAL_CALL
getValue() override
;
382 virtual void SAL_CALL
setValue( const css::uno::Any
& _value
) override
;
383 virtual css::uno::Type SAL_CALL
getValueType() override
;
384 virtual weld::Widget
* getWidget() override
{ return getTypedControlWindow(); }
386 virtual void editChanged() override
;
388 virtual void SetModifyHandler() override
390 m_xEntry
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
391 m_xEntry
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
392 m_xButton
->connect_focus_in( LINK( this, CommonBehaviourControlHelper
, GetFocusHdl
) );
393 m_xButton
->connect_focus_out( LINK( this, CommonBehaviourControlHelper
, LoseFocusHdl
) );
395 m_xEntry
->connect_changed( LINK( this, CommonBehaviourControlHelper
, EditModifiedHdl
) );
396 m_xTextView
->connect_changed( LINK( this, OMultilineEditControl
, TextViewModifiedHdl
) );
399 virtual void SAL_CALL
disposing() override
405 OMultilineEditControl_Base::disposing();
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */