1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _EXTENSIONS_PROPCTRLR_STANDARDCONTROL_HXX_
25 #define _EXTENSIONS_PROPCTRLR_STANDARDCONTROL_HXX_
26 
27 #include "commoncontrol.hxx"
28 #include "pcrcommon.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/inspection/XNumericControl.hpp>
32 #include <com/sun/star/inspection/XStringListControl.hpp>
33 #include <com/sun/star/inspection/XHyperlinkControl.hpp>
34 #include <com/sun/star/uno/Sequence.hxx>
35 /** === end UNO includes === **/
36 #include <vcl/field.hxx>
37 #include <vcl/longcurr.hxx>
38 #include <svtools/ctrlbox.hxx>
39 #include <vcl/lstbox.hxx>
40 #include <vcl/combobox.hxx>
41 #include <svtools/calendar.hxx>
42 #include <svtools/fmtfield.hxx>
43 
44 #include <set>
45 
46 class PushButton;
47 class MultiLineEdit;
48 //............................................................................
49 namespace pcr
50 {
51 //............................................................................
52 
53     //========================================================================
54     //= ListLikeControlWithModifyHandler
55     //========================================================================
56     /** Very small helper class which adds a SetModifyHdl to a ListBox-derived class,
57         thus giving this class the same API (as far as the CommonBehaviourControl is concerned)
58         as all other windows.
59     */
60     template< class LISTBOX_WINDOW >
61     class ListLikeControlWithModifyHandler : public ControlWindow< LISTBOX_WINDOW >
62     {
63     protected:
64         typedef ControlWindow< LISTBOX_WINDOW >  ListBoxType;
65 
66     public:
ListLikeControlWithModifyHandler(Window * _pParent,WinBits _nStyle)67         ListLikeControlWithModifyHandler( Window* _pParent, WinBits _nStyle )
68             :ListBoxType( _pParent, _nStyle )
69         {
70         }
71 
SetModifyHdl(const Link & _rLink)72         void SetModifyHdl( const Link& _rLink ) { ListBoxType::SetSelectHdl( _rLink ); }
73 
74     protected:
75         long    PreNotify( NotifyEvent& _rNEvt );
76     };
77 
78     //------------------------------------------------------------------------
79     template< class LISTBOX_WINDOW >
PreNotify(NotifyEvent & _rNEvt)80     long ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::PreNotify( NotifyEvent& _rNEvt )
81     {
82         if ( _rNEvt.GetType() == EVENT_KEYINPUT )
83         {
84             const ::KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
85             if  (   ( pKeyEvent->GetKeyCode().GetModifier() == 0 )
86                 &&  (   ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEUP )
87                     ||  ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEDOWN )
88                     )
89                 )
90             {
91                 if ( !ListBoxType::IsInDropDown() )
92                 {
93                     // don't give the base class a chance to consume the event, in the property browser, it is
94                     // intended to scroll the complete property page
95                     return ListBoxType::GetParent()->PreNotify( _rNEvt );
96                 }
97             }
98         }
99         return ListBoxType::PreNotify( _rNEvt );
100     }
101 
102     //========================================================================
103     //= OTimeControl
104     //========================================================================
105     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< TimeField > > OTimeControl_Base;
106     class OTimeControl : public OTimeControl_Base
107     {
108     public:
109         OTimeControl( Window* pParent, WinBits nWinStyle );
110 
111         // XPropertyControl
112         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
113         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
114         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
115     };
116 
117     //========================================================================
118     //= ODateControl
119     //========================================================================
120     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< CalendarField > > ODateControl_Base;
121     class ODateControl : public ODateControl_Base
122     {
123     public:
124         ODateControl( Window* pParent, WinBits nWinStyle );
125 
126         // XPropertyControl
127         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
128         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
129         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
130     };
131 
132     //========================================================================
133     //= OEditControl
134     //========================================================================
135     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< Edit > > OEditControl_Base;
136     class OEditControl : public OEditControl_Base
137     {
138     protected:
139         sal_Bool m_bIsPassword : 1;
140 
141     public:
142         OEditControl( Window* _pParent, sal_Bool _bPassWord, WinBits nWinStyle );
143 
144         // XPropertyControl
145         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
146         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
147         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
148 
149     protected:
150         virtual void modified();
151     };
152 
153     //========================================================================
154     //= ODateTimeControl
155     //========================================================================
156     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< FormattedField > > ODateTimeControl_Base;
157     class ODateTimeControl : public ODateTimeControl_Base
158     {
159     public:
160         ODateTimeControl( Window* pParent,WinBits nWinStyle );
161 
162         // XPropertyControl
163         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
164         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
165         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
166     };
167 
168     //========================================================================
169     //= HyperlinkInput
170     //========================================================================
171     class HyperlinkInput : public Edit
172     {
173     private:
174         Point   m_aMouseButtonDownPos;
175         Link    m_aClickHandler;
176 
177     public:
178         HyperlinkInput( Window* _pParent, WinBits _nWinStyle );
179 
180         /** sets the handler which will (asynchronously, with locked SolarMutex) be called
181             when the hyperlink has been clicked by the user
182         */
SetClickHdl(const Link & _rHdl)183         void        SetClickHdl( const Link& _rHdl ) { m_aClickHandler = _rHdl; }
GetClickHdl() const184         const Link& GetClickHdl( ) const { return m_aClickHandler; }
185 
186     protected:
187         virtual void        MouseMove( const MouseEvent& rMEvt );
188         virtual void        MouseButtonDown( const MouseEvent& rMEvt );
189         virtual void        MouseButtonUp( const MouseEvent& rMEvt );
190         virtual void        Tracking( const TrackingEvent& rTEvt );
191 
192     private:
193         void    impl_checkEndClick( const MouseEvent rMEvt );
194         bool    impl_textHitTest( const Point& _rWindowPos );
195     };
196 
197     //========================================================================
198     //= OHyperlinkControl
199     //========================================================================
200     typedef CommonBehaviourControl< ::com::sun::star::inspection::XHyperlinkControl, ControlWindow< HyperlinkInput > > OHyperlinkControl_Base;
201     class OHyperlinkControl : public OHyperlinkControl_Base
202     {
203     private:
204         ::cppu::OInterfaceContainerHelper   m_aActionListeners;
205 
206     public:
207         OHyperlinkControl( Window* _pParent, WinBits _nWinStyle );
208 
209         // XPropertyControl
210         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
211         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
212         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
213 
214         // XHyperlinkControl
215         virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
216         virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
217 
218     protected:
219         // XComponent
220         virtual void SAL_CALL disposing();
221 
222     protected:
223         DECL_LINK( OnHyperlinkClicked, void* );
224     };
225 
226     //========================================================================
227     //= CustomConvertibleNumericField
228     //========================================================================
229     class CustomConvertibleNumericField : public ControlWindow< MetricField >
230     {
231         typedef ControlWindow< MetricField > BaseClass;
232 
233     public:
CustomConvertibleNumericField(Window * _pParent,WinBits _nStyle)234         CustomConvertibleNumericField( Window* _pParent, WinBits _nStyle )
235             :BaseClass( _pParent, _nStyle )
236         {
237         }
238 
GetLastValue() const239         sal_Int64 GetLastValue() const { return mnLastValue; }
240     };
241 
242     //========================================================================
243     //= ONumericControl
244     //========================================================================
245     typedef CommonBehaviourControl< ::com::sun::star::inspection::XNumericControl, CustomConvertibleNumericField > ONumericControl_Base;
246     class ONumericControl : public ONumericControl_Base
247     {
248     private:
249         FieldUnit   m_eValueUnit;
250         sal_Int16   m_nFieldToUNOValueFactor;
251 
252     public:
253         ONumericControl( Window* pParent, WinBits nWinStyle );
254 
255         // XPropertyControl
256         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
257         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
258         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
259 
260         // XNumericControl
261         virtual ::sal_Int16 SAL_CALL getDecimalDigits() throw (::com::sun::star::uno::RuntimeException);
262         virtual void SAL_CALL setDecimalDigits( ::sal_Int16 _decimaldigits ) throw (::com::sun::star::uno::RuntimeException);
263         virtual ::com::sun::star::beans::Optional< double > SAL_CALL getMinValue() throw (::com::sun::star::uno::RuntimeException);
264         virtual void SAL_CALL setMinValue( const ::com::sun::star::beans::Optional< double >& _minvalue ) throw (::com::sun::star::uno::RuntimeException);
265         virtual ::com::sun::star::beans::Optional< double > SAL_CALL getMaxValue() throw (::com::sun::star::uno::RuntimeException);
266         virtual void SAL_CALL setMaxValue( const ::com::sun::star::beans::Optional< double >& _maxvalue ) throw (::com::sun::star::uno::RuntimeException);
267         virtual ::sal_Int16 SAL_CALL getDisplayUnit() throw (::com::sun::star::uno::RuntimeException);
268         virtual void SAL_CALL setDisplayUnit( ::sal_Int16 _displayunit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
269         virtual ::sal_Int16 SAL_CALL getValueUnit() throw (::com::sun::star::uno::RuntimeException);
270         virtual void SAL_CALL setValueUnit( ::sal_Int16 _valueunit ) throw (::com::sun::star::uno::RuntimeException);
271 
272     private:
273         /** converts an API value (<code>double</code>, as passed into <code>set[Max|Min|]Value) into
274             a <code>long</code> value which can be passed to our NumericField.
275 
276             The conversion respects our decimal digits as well as our value factor (<member>m_nFieldToUNOValueFactor</member>).
277         */
278         long    impl_apiValueToFieldValue_nothrow( double _nApiValue ) const;
279 
280         /** converts a control value, as obtained from our Numeric field, into a value which can passed
281             to outer callers via our UNO API.
282         */
283         double  impl_fieldValueToApiValue_nothrow( sal_Int64 _nFieldValue ) const;
284     };
285 
286     //========================================================================
287     //= OColorControl
288     //========================================================================
289     typedef CommonBehaviourControl  <   ::com::sun::star::inspection::XStringListControl
290                                     ,   ListLikeControlWithModifyHandler< ColorListBox >
291                                     >   OColorControl_Base;
292     class OColorControl : public OColorControl_Base
293     {
294     private:
295         ::std::set< ::rtl::OUString >   m_aNonColorEntries;
296 
297     public:
298         OColorControl( Window* pParent, WinBits nWinStyle );
299 
300         // XPropertyControl
301         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
302         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
303         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
304 
305         // XStringListControl
306         virtual void SAL_CALL clearList(  ) throw (::com::sun::star::uno::RuntimeException);
307         virtual void SAL_CALL prependListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
308         virtual void SAL_CALL appendListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
309         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getListEntries(  ) throw (::com::sun::star::uno::RuntimeException);
310 
311     protected:
312         virtual void modified();
313     };
314 
315     //========================================================================
316     //= OListboxControl
317     //========================================================================
318     typedef CommonBehaviourControl  <   ::com::sun::star::inspection::XStringListControl
319                                     ,   ListLikeControlWithModifyHandler< ListBox >
320                                     >   OListboxControl_Base;
321     class OListboxControl : public OListboxControl_Base
322     {
323     public:
324         OListboxControl( Window* pParent, WinBits nWinStyle );
325 
326         // XPropertyControl
327         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
328         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
329         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
330 
331         // XStringListControl
332         virtual void SAL_CALL clearList(  ) throw (::com::sun::star::uno::RuntimeException);
333         virtual void SAL_CALL prependListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
334         virtual void SAL_CALL appendListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
335         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getListEntries(  ) throw (::com::sun::star::uno::RuntimeException);
336 
337     protected:
338         virtual void modified();
339     };
340 
341     //========================================================================
342     //= OComboboxControl
343     //========================================================================
344     typedef CommonBehaviourControl< ::com::sun::star::inspection::XStringListControl, ControlWindow< ComboBox > > OComboboxControl_Base;
345     class OComboboxControl : public OComboboxControl_Base
346     {
347     public:
348         OComboboxControl( Window* pParent, WinBits nWinStyle );
349 
350         // XPropertyControl
351         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
352         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
353         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
354 
355         // XStringListControl
356         virtual void SAL_CALL clearList(  ) throw (::com::sun::star::uno::RuntimeException);
357         virtual void SAL_CALL prependListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
358         virtual void SAL_CALL appendListEntry( const ::rtl::OUString& NewEntry ) throw (::com::sun::star::uno::RuntimeException);
359         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getListEntries(  ) throw (::com::sun::star::uno::RuntimeException);
360 
361     protected:
362         DECL_LINK( OnEntrySelected, void* );
363     };
364 
365     //========================================================================
366     //= DropDownEditControl
367     //========================================================================
368     enum MultiLineOperationMode
369     {
370         eStringList,
371         eMultiLineText
372     };
373     //========================================================================
374     //= DropDownEditControl
375     //========================================================================
376     class OMultilineFloatingEdit;
377     typedef ControlWindow< Edit > DropDownEditControl_Base;
378     /** an Edit field which can be used as ControlWindow, and has a drop-down button
379     */
380     class DropDownEditControl : public DropDownEditControl_Base
381     {
382     private:
383         OMultilineFloatingEdit*             m_pFloatingEdit;
384         MultiLineEdit*                      m_pImplEdit;
385         PushButton*                         m_pDropdownButton;
386         MultiLineOperationMode              m_nOperationMode;
387         sal_Bool                            m_bDropdown : 1;
388 
389     public:
390         DropDownEditControl( Window* _pParent, WinBits _nStyle );
391         ~DropDownEditControl();
392 
setOperationMode(MultiLineOperationMode _eMode)393         void setOperationMode( MultiLineOperationMode _eMode ) { m_nOperationMode = _eMode; }
getOperationMode() const394         MultiLineOperationMode getOperationMode() const { return m_nOperationMode; }
395 
396         void            SetTextValue( const ::rtl::OUString& _rText );
397         ::rtl::OUString GetTextValue() const;
398 
399         void            SetStringListValue( const StlSyntaxSequence< ::rtl::OUString >& _rStrings );
400         StlSyntaxSequence< ::rtl::OUString >
401                         GetStringListValue() const;
402 
403         // ControlWindow overridables
404         virtual void setControlHelper( ControlHelper& _rControlHelper );
405 
406     protected:
407         // Window overridables
408         virtual long    PreNotify( NotifyEvent& rNEvt );
409         virtual void    Resize();
410 
411     protected:
412         long            FindPos(long nSinglePos);
413 
414     private:
415         DECL_LINK( ReturnHdl, OMultilineFloatingEdit* );
416         DECL_LINK( DropDownHdl, PushButton* );
417 
418         sal_Bool ShowDropDown( sal_Bool bShow );
419     };
420 
421     //========================================================================
422     //= OMultilineEditControl
423     //========================================================================
424     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, DropDownEditControl > OMultilineEditControl_Base;
425     class OMultilineEditControl : public OMultilineEditControl_Base
426     {
427     public:
428         OMultilineEditControl( Window* pParent, MultiLineOperationMode _eMode, WinBits nWinStyle  );
429 
430         // XPropertyControl
431         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
432         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
433         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
434     };
435 
436 //............................................................................
437 } // namespace pcr
438 //............................................................................
439 
440 #endif // _EXTENSIONS_PROPCTRLR_STANDARDCONTROL_HXX_
441 
442