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_USERCONTROL_HXX_
29 #define _EXTENSIONS_PROPCTRLR_USERCONTROL_HXX_
30 
31 #include "commoncontrol.hxx"
32 #define _ZFORLIST_DECLARE_TABLE
33 #include <svtools/fmtfield.hxx>
34 #include <svtools/fileurlbox.hxx>
35 #include "standardcontrol.hxx"
36 
37 class SvNumberFormatsSupplierObj;
38 
39 //............................................................................
40 namespace pcr
41 {
42 //............................................................................
43 
44     //========================================================================
45     //= NumberFormatSampleField
46     //========================================================================
47     class NumberFormatSampleField : public ControlWindow< FormattedField >
48     {
49     private:
50         typedef ControlWindow< FormattedField > BaseClass;
51 
52     public:
53         NumberFormatSampleField( Window* _pParent, WinBits _nStyle )
54             :BaseClass( _pParent, _nStyle )
55         {
56         }
57 
58         void SetFormatSupplier( const SvNumberFormatsSupplierObj* pSupplier );
59 
60     protected:
61         virtual long PreNotify( NotifyEvent& rNEvt );
62     };
63 
64     //========================================================================
65     //= OFormatSampleControl
66     //========================================================================
67     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, NumberFormatSampleField > OFormatSampleControl_Base;
68     class OFormatSampleControl : public OFormatSampleControl_Base
69     {
70     public:
71         OFormatSampleControl( Window* pParent, WinBits nWinStyle );
72 
73         // XPropertyControl
74         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
75         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
76         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
77 
78         inline void SetFormatSupplier( const SvNumberFormatsSupplierObj* _pSupplier )
79         {
80             getTypedControlWindow()->SetFormatSupplier( _pSupplier );
81         }
82 
83         /** returns the default preview value for the given format key
84         *
85         * \param _pNF the number formatter
86         * \param _nFormatKey the format key
87         * \return current date or time or the value 1234.56789
88         */
89         static double getPreviewValue(SvNumberFormatter* _pNF,sal_Int32 _nFormatKey);
90 
91     private:
92         static double getPreviewValue( const SvNumberformat& i_rEntry );
93     };
94 
95     //========================================================================
96     //= FormatDescription
97     //========================================================================
98     struct FormatDescription
99     {
100         SvNumberFormatsSupplierObj*     pSupplier;
101         sal_Int32                       nKey;
102     };
103 
104     //========================================================================
105     //= OFormattedNumericControl
106     //========================================================================
107     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< FormattedField > > OFormattedNumericControl_Base;
108     class OFormattedNumericControl : public OFormattedNumericControl_Base
109     {
110     private:
111         sal_Int32   m_nLastDecimalDigits;
112 
113     public:
114         OFormattedNumericControl( Window* pParent, WinBits nWinStyle = WB_TABSTOP);
115 
116         // XPropertyControl
117         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
118         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
119         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
120 
121         void SetFormatDescription( const FormatDescription& rDesc );
122 
123         // make some FormattedField methods available
124         void SetDecimalDigits(sal_uInt16 nPrecision) { getTypedControlWindow()->SetDecimalDigits(nPrecision); m_nLastDecimalDigits = nPrecision; }
125         void SetDefaultValue(double dDef) { getTypedControlWindow()->SetDefaultValue(dDef); }
126         void EnableEmptyField(sal_Bool bEnable) { getTypedControlWindow()->EnableEmptyField(bEnable); }
127         void SetThousandsSep(sal_Bool bEnable) { getTypedControlWindow()->SetThousandsSep(bEnable); }
128 
129     protected:
130         ~OFormattedNumericControl();
131     };
132 
133     //========================================================================
134     //= OFileUrlControl
135     //========================================================================
136     typedef CommonBehaviourControl< ::com::sun::star::inspection::XPropertyControl, ControlWindow< ::svt::FileURLBox > > OFileUrlControl_Base;
137     class OFileUrlControl : public OFileUrlControl_Base
138     {
139     public:
140         OFileUrlControl( Window* pParent, WinBits nWinStyle );
141 
142         // XPropertyControl
143         virtual ::com::sun::star::uno::Any SAL_CALL getValue() throw (::com::sun::star::uno::RuntimeException);
144         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& _value ) throw (::com::sun::star::beans::IllegalTypeException, ::com::sun::star::uno::RuntimeException);
145         virtual ::com::sun::star::uno::Type SAL_CALL getValueType() throw (::com::sun::star::uno::RuntimeException);
146 
147     protected:
148         ~OFileUrlControl();
149     };
150 
151     //========================================================================
152     //= OTimeDurationControl
153     //========================================================================
154     class OTimeDurationControl : public ONumericControl
155     {
156     public:
157         OTimeDurationControl( ::Window* pParent, WinBits nWinStyle );
158         ~OTimeDurationControl();
159 
160         // XPropertyControl
161         ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException);
162 
163     private:
164         DECL_LINK( OnCustomConvert, MetricField* );
165     };
166 
167 //............................................................................
168 } // namespace pcr
169 //............................................................................
170 
171 #endif // _EXTENSIONS_PROPCTRLR_USERCONTROL_HXX_
172 
173