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