xref: /trunk/main/dbaccess/source/ui/dlg/adminpages.hxx (revision e8df90a080f9dc7518c4b937d7dcd461d7b4d178)
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 _DBAUI_ADMINPAGES_HXX_
25 #define _DBAUI_ADMINPAGES_HXX_
26 
27 #ifndef _SFXTABDLG_HXX
28 #include <sfx2/tabdlg.hxx>
29 #endif
30 #ifndef _DBAUI_DSNTYPES_HXX_
31 #include "dsntypes.hxx"
32 #endif
33 #ifndef _DBAUI_COMMON_TYPES_HXX_
34 #include "commontypes.hxx"
35 #endif
36 #ifndef _SVTOOLS_WIZARDMACHINE_HXX_
37 #include <svtools/wizardmachine.hxx>
38 #endif
39 #ifndef _SV_FIELD_HXX
40 #include <vcl/field.hxx>
41 #endif
42 #ifndef _SV_FIXED_HXX
43 #include <vcl/fixed.hxx>
44 #endif
45 
46 
47 class NumericField;
48 class Edit;
49 //.........................................................................
50 namespace dbaui
51 {
52 //.........................................................................
53     /// helper class to wrap the savevalue and disable call
54     class SAL_NO_VTABLE ISaveValueWrapper
55     {
56     public:
~ISaveValueWrapper()57         virtual ~ISaveValueWrapper() {}
58         virtual bool SaveValue() = 0;
59         virtual bool Disable() = 0;
60     };
61 
62     template < class T > class OSaveValueWrapper : public ISaveValueWrapper
63     {
64         T*  m_pSaveValue;
65     public:
OSaveValueWrapper(T * _pSaveValue)66         OSaveValueWrapper(T* _pSaveValue) : m_pSaveValue(_pSaveValue)
67         { OSL_ENSURE(m_pSaveValue,"Illegal argument!"); }
68 
SaveValue()69         virtual bool SaveValue() { m_pSaveValue->SaveValue(); return true;} // bool return value only for stl
Disable()70         virtual bool Disable() { m_pSaveValue->Disable(); return true;} // bool return value only for stl
71     };
72 
73     template < class T > class ODisableWrapper : public ISaveValueWrapper
74     {
75         T*  m_pSaveValue;
76     public:
ODisableWrapper(T * _pSaveValue)77         ODisableWrapper(T* _pSaveValue) : m_pSaveValue(_pSaveValue)
78         { OSL_ENSURE(m_pSaveValue,"Illegal argument!"); }
79 
SaveValue()80         virtual bool SaveValue() { return true;} // bool return value only for stl
Disable()81         virtual bool Disable() { m_pSaveValue->Disable(); return true;} // bool return value only for stl
82     };
83 
84     struct TSaveValueWrapperFunctor
85     {
86         typedef ISaveValueWrapper argument_type;
87         typedef bool result_type;
operator ()dbaui::TSaveValueWrapperFunctor88         bool operator() (ISaveValueWrapper* lhs)
89         {
90             return lhs->SaveValue();
91         }
92     };
93     struct TDisableWrapperFunctor
94     {
95         typedef ISaveValueWrapper argument_type;
96         typedef bool result_type;
operator ()dbaui::TDisableWrapperFunctor97         bool operator() (ISaveValueWrapper* lhs)
98         {
99             return lhs->Disable();
100         }
101     };
102 
103     struct TDeleteWrapperFunctor
104     {
105         typedef ISaveValueWrapper argument_type;
106         typedef bool result_type;
operator ()dbaui::TDeleteWrapperFunctor107         bool operator() (ISaveValueWrapper* lhs)
108         {
109             delete lhs;
110             return true;
111         }
112     };
113 
114     //=========================================================================
115     //= OGenericAdministrationPage
116     //=========================================================================
117     class IDatabaseSettingsDialog;
118     class IItemSetHelper;
119     class OGenericAdministrationPage    :public SfxTabPage
120                                         ,public ::svt::IWizardPageController
121     {
122     private:
123         Link            m_aModifiedHandler;     /// to be called if something on the page has been modified
124         sal_Bool        m_abEnableRoadmap;
125     protected:
126         IDatabaseSettingsDialog*   m_pAdminDialog;
127         IItemSetHelper* m_pItemSetHelper;
128         FixedText*      m_pFT_HeaderText;
129 
130         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
131                             m_xORB;
132     public:
133         OGenericAdministrationPage(Window* _pParent, const ResId& _rId, const SfxItemSet& _rAttrSet);
134         ~OGenericAdministrationPage();
135 
136         /// set a handler which gets called every time something on the page has been modified
SetModifiedHandler(const Link & _rHandler)137         void SetModifiedHandler(const Link& _rHandler) { m_aModifiedHandler = _rHandler; }
138 
139         /** Sets the ParentDialog
140             @param  _pAdminDialog
141                 the ParentDialog
142             @param  _pItemSetHelper
143                 the itemset helper
144         */
SetAdminDialog(IDatabaseSettingsDialog * _pDialog,IItemSetHelper * _pItemSetHelper)145         inline void SetAdminDialog(IDatabaseSettingsDialog* _pDialog,IItemSetHelper* _pItemSetHelper)
146         {
147             OSL_ENSURE(_pDialog && _pItemSetHelper,"Values are NULL!");
148             m_pAdminDialog = _pDialog;
149             m_pItemSetHelper = _pItemSetHelper;
150         }
151 
152         /** Sets the ServiceFactory
153             @param  _rxORB
154                 The service factory.
155         */
SetServiceFactory(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> _rxORB)156         virtual void SetServiceFactory(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB)
157         {
158             m_xORB = _rxORB;
159         }
160 
161         /** opens a dialog filled with all data sources available for this type and
162             returns the selected on.
163             @param  _eType
164                 The type for which the data source dialog should be opened.
165             @param  _sReturn
166                 <OUT/> contains the selected name.
167             @return
168                 <FALSE/> if an error occurred, otherwise <TRUE/>
169         */
170         sal_Bool getSelectedDataSource(::rtl::OUString& _sReturn,::rtl::OUString& _sCurr);
171 
172         // svt::IWizardPageController
173         virtual void initializePage();
174         virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason );
175         virtual bool canAdvance() const;
176 
SetRoadmapStateValue(sal_Bool _bDoEnable)177         void                SetRoadmapStateValue( sal_Bool _bDoEnable ) { m_abEnableRoadmap = _bDoEnable; }
GetRoadmapStateValue() const178         bool                GetRoadmapStateValue() const { return m_abEnableRoadmap; }
179 
180     protected:
181         /// default implementation: call FillItemSet, call prepareLeave,
182         virtual int DeactivatePage(SfxItemSet* pSet);
183         using SfxTabPage::DeactivatePage;
184         /// default implementation: call implInitControls with the given item set and _bSaveValue = sal_False
185         virtual void Reset(const SfxItemSet& _rCoreAttrs);
186         /// default implementation: call implInitControls with the given item set and _bSaveValue = sal_True
187         virtual void ActivatePage(const SfxItemSet& _rSet);
188 
189         // TabPage overridables
190         virtual void    ActivatePage();
191 
192     protected:
callModifiedHdl() const193         void callModifiedHdl() const { if (m_aModifiedHandler.IsSet()) m_aModifiedHandler.Call((void*)this); }
194 
195         /// called from within DeactivatePage. The page is allowed to be deactivated if this method returns sal_True
prepareLeave()196         virtual sal_Bool prepareLeave() { return sal_True; }
197 
198         /** called from within Reset and ActivatePage, use to initialize the controls with the items from the given set
199             @param      _bSaveValue     if set to sal_True, the implementation should call SaveValue on all relevant controls
200         */
201         virtual void implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue);
202 
203         /// analyze the invalid and the readonly flag which may be present in the set
204         void getFlags(const SfxItemSet& _rSet, sal_Bool& _rValid, sal_Bool& _rReadonly);
205 
206         /** will be called inside <method>implInitControls</method> to save the value if necessary
207             @param  _rControlList
208                 The list must be filled with the controls.
209                 It is not allowed to clear the list before pusching data into it.
210         */
211         virtual void fillControls(::std::vector< ISaveValueWrapper* >& _rControlList) = 0;
212 
213         /** will be called inside <method>implInitControls</method> to disable if necessary
214             @param  _rControlList
215                 The list must be filled with the controls.
216                 It is not allowed to clear the list before pusching data into it.
217         */
218         virtual void fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) = 0;
219 
220     public:
221         /** fills the Boolean value into the item set when the value changed.
222             @param  _rSet
223                 The item set where to put the new value into.
224             @param  _pCheckBox
225                 The check box which is checked.
226             @param  _nID
227                 The id in the itemset to set with the new value.
228             @param  _bChangedSomething
229                 <TRUE/> if something changed otherwise <FALSE/>
230             @param _bRevertValue
231                 set to <TRUE/> if the display value should be reverted before putting it into the set
232         */
233         static void fillBool( SfxItemSet& _rSet, CheckBox* _pCheckBox, sal_uInt16 _nID, sal_Bool& _bChangedSomething, bool _bRevertValue = false);
234 
235         /** fills the int value into the item set when the value changed.
236             @param  _rSet
237                 The item set where to put the new value into.
238             @param  _pEdit
239                 The check box which is checked.
240             @param  _nID
241                 The id in the itemset to set with the new value.
242             @param  _bChangedSomething
243                 <TRUE/> if something changed otherwise <FALSE/>
244         */
245         static void fillInt32(SfxItemSet& _rSet,NumericField* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething);
246 
247         /** fills the String value into the item set when the value changed.
248             @param  _rSet
249                 The item set where to put the new value into.
250             @param  _pEdit
251                 The check box which is checked.
252             @param  _nID
253                 The id in the itemset to set with the new value.
254             @param  _bChangedSomething
255                 <TRUE/> if something changed otherwise <FALSE/>
256         */
257         static void fillString(SfxItemSet& _rSet,Edit* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething);
258 
259     protected:
260         // used to set the right Pane header of a wizard to bold
261         void SetControlFontWeight(Window* _pWindow, FontWeight _eWeight = WEIGHT_BOLD);
262         void SetHeaderText( sal_uInt16 _nFTResId, sal_uInt16 _StringResId);
263 
264         /** This link be used for controls where the tabpage does not need to take any special action when the control
265             is modified. The implementation just calls callModifiedHdl.
266         */
267         DECL_LINK(OnControlModified, Control*);
268         DECL_LINK(OnTestConnectionClickHdl,PushButton*);
269 
270         /// may be used in SetXXXHdl calls to controls, is a link to <method>OnControlModified</method>
getControlModifiedLink()271         virtual Link getControlModifiedLink() { return LINK(this, OGenericAdministrationPage, OnControlModified); }
272     };
273 
274     //=========================================================================
275     //= ControlRelation
276     //=========================================================================
277     enum ControlRelation
278     {
279         RelatedControls, UnrelatedControls
280     };
281 
282     //=========================================================================
283     //= LayoutHelper
284     //=========================================================================
285     class LayoutHelper
286     {
287     public:
288         static void     positionBelow(
289                             const Control& _rReference,
290                             Control& _rControl,
291                             const ControlRelation _eRelation,
292                             const long _nIndentAppFont
293                         );
294         /** fits the button size to be large enough to contain the buttons text
295         */
296         static void fitSizeRightAligned( PushButton& io_button );
297             // why is CalcMinimumSize not a virtual method of ::Window?
298     };
299 
300 //.........................................................................
301 }   // namespace dbaui
302 //.........................................................................
303 
304 #endif // _DBAUI_ADMINPAGES_HXX_
305