1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _DBAUI_ADMINPAGES_HXX_
30 #define _DBAUI_ADMINPAGES_HXX_
32 #include <sfx2/tabdlg.hxx>
33 #include "dsntypes.hxx"
34 #include "commontypes.hxx"
35 #include <svtools/wizardmachine.hxx>
36 #include <vcl/field.hxx>
37 #include <vcl/fixed.hxx>
42 //.........................................................................
45 //.........................................................................
46 /// helper class to wrap the savevalue and disable call
47 class SAL_NO_VTABLE ISaveValueWrapper
50 virtual ~ISaveValueWrapper() = 0;
51 virtual bool SaveValue() = 0;
52 virtual bool Disable() = 0;
55 template < class T
> class OSaveValueWrapper
: public ISaveValueWrapper
59 OSaveValueWrapper(T
* _pSaveValue
) : m_pSaveValue(_pSaveValue
)
60 { OSL_ENSURE(m_pSaveValue
,"Illegal argument!"); }
62 virtual bool SaveValue() { m_pSaveValue
->SaveValue(); return true;} // bool return value only for stl
63 virtual bool Disable() { m_pSaveValue
->Disable(); return true;} // bool return value only for stl
66 template < class T
> class ODisableWrapper
: public ISaveValueWrapper
70 ODisableWrapper(T
* _pSaveValue
) : m_pSaveValue(_pSaveValue
)
71 { OSL_ENSURE(m_pSaveValue
,"Illegal argument!"); }
73 virtual bool SaveValue() { return true;} // bool return value only for stl
74 virtual bool Disable() { m_pSaveValue
->Disable(); return true;} // bool return value only for stl
77 struct TSaveValueWrapperFunctor
: public ::std::unary_function
< ISaveValueWrapper
, bool>
79 bool operator() (ISaveValueWrapper
* lhs
)
81 return lhs
->SaveValue();
84 struct TDisableWrapperFunctor
: public ::std::unary_function
< ISaveValueWrapper
, bool>
86 bool operator() (ISaveValueWrapper
* lhs
)
88 return lhs
->Disable();
92 struct TDeleteWrapperFunctor
: public ::std::unary_function
< ISaveValueWrapper
, bool>
94 bool operator() (ISaveValueWrapper
* lhs
)
101 //=========================================================================
102 //= OGenericAdministrationPage
103 //=========================================================================
104 class IDatabaseSettingsDialog
;
105 class IItemSetHelper
;
106 class OGenericAdministrationPage
:public SfxTabPage
107 ,public ::svt::IWizardPageController
110 Link m_aModifiedHandler
; /// to be called if something on the page has been modified
111 sal_Bool m_abEnableRoadmap
;
113 IDatabaseSettingsDialog
* m_pAdminDialog
;
114 IItemSetHelper
* m_pItemSetHelper
;
115 FixedText
* m_pFT_HeaderText
;
117 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>
120 OGenericAdministrationPage(Window
* _pParent
, const ResId
& _rId
, const SfxItemSet
& _rAttrSet
);
121 ~OGenericAdministrationPage();
123 /// set a handler which gets called every time something on the page has been modified
124 void SetModifiedHandler(const Link
& _rHandler
) { m_aModifiedHandler
= _rHandler
; }
126 /** Sets the ParentDialog
129 @param _pItemSetHelper
132 inline void SetAdminDialog(IDatabaseSettingsDialog
* _pDialog
,IItemSetHelper
* _pItemSetHelper
)
134 OSL_ENSURE(_pDialog
&& _pItemSetHelper
,"Values are NULL!");
135 m_pAdminDialog
= _pDialog
;
136 m_pItemSetHelper
= _pItemSetHelper
;
139 /** Sets the ServiceFactory
143 virtual void SetServiceFactory(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> _rxORB
)
148 /** opens a dialog filled with all data sources available for this type and
149 returns the selected on.
151 The type for which the data source dialog should be opened.
153 <OUT/> contains the selected name.
155 <FALSE/> if an error occurred, otherwise <TRUE/>
157 sal_Bool
getSelectedDataSource(::rtl::OUString
& _sReturn
,::rtl::OUString
& _sCurr
);
159 // svt::IWizardPageController
160 virtual void initializePage();
161 virtual sal_Bool
commitPage( ::svt::WizardTypes::CommitPageReason _eReason
);
162 virtual bool canAdvance() const;
164 void SetRoadmapStateValue( sal_Bool _bDoEnable
) { m_abEnableRoadmap
= _bDoEnable
; }
165 bool GetRoadmapStateValue() const { return m_abEnableRoadmap
; }
168 /// default implementation: call FillItemSet, call prepareLeave,
169 virtual int DeactivatePage(SfxItemSet
* pSet
);
170 using SfxTabPage::DeactivatePage
;
171 /// default implementation: call implInitControls with the given item set and _bSaveValue = sal_False
172 virtual void Reset(const SfxItemSet
& _rCoreAttrs
);
173 /// default implementation: call implInitControls with the given item set and _bSaveValue = sal_True
174 virtual void ActivatePage(const SfxItemSet
& _rSet
);
176 // TabPage overridables
177 virtual void ActivatePage();
180 void callModifiedHdl() const { if (m_aModifiedHandler
.IsSet()) m_aModifiedHandler
.Call((void*)this); }
182 /// called from within DeactivatePage. The page is allowed to be deactivated if this method returns sal_True
183 virtual sal_Bool
prepareLeave() { return sal_True
; }
185 /** called from within Reset and ActivatePage, use to initialize the controls with the items from the given set
186 @param _bSaveValue if set to sal_True, the implementation should call SaveValue on all relevant controls
188 virtual void implInitControls(const SfxItemSet
& _rSet
, sal_Bool _bSaveValue
);
190 /// analyze the invalid and the readonly flag which may be present in the set
191 void getFlags(const SfxItemSet
& _rSet
, sal_Bool
& _rValid
, sal_Bool
& _rReadonly
);
193 /** will be called inside <method>implInitControls</method> to save the value if necessary
195 The list must be filled with the controls.
196 It is not allowed to clear the list before pusching data into it.
198 virtual void fillControls(::std::vector
< ISaveValueWrapper
* >& _rControlList
) = 0;
200 /** will be called inside <method>implInitControls</method> to disable if necessary
202 The list must be filled with the controls.
203 It is not allowed to clear the list before pusching data into it.
205 virtual void fillWindows(::std::vector
< ISaveValueWrapper
* >& _rControlList
) = 0;
208 /** fills the Boolean value into the item set when the value changed.
210 The item set where to put the new value into.
212 The check box which is checked.
214 The id in the itemset to set whith the new value.
215 @param _bChangedSomething
216 <TRUE/> if something changed otherwise <FALSE/>
218 set to <TRUE/> if the display value should be reverted before putting it into the set
220 static void fillBool( SfxItemSet
& _rSet
, CheckBox
* _pCheckBox
, sal_uInt16 _nID
, sal_Bool
& _bChangedSomething
, bool _bRevertValue
= false);
222 /** fills the int value into the item set when the value changed.
224 The item set where to put the new value into.
226 The check box which is checked.
228 The id in the itemset to set whith the new value.
229 @param _bChangedSomething
230 <TRUE/> if something changed otherwise <FALSE/>
232 static void fillInt32(SfxItemSet
& _rSet
,NumericField
* _pEdit
,sal_uInt16 _nID
,sal_Bool
& _bChangedSomething
);
234 /** fills the String value into the item set when the value changed.
236 The item set where to put the new value into.
238 The check box which is checked.
240 The id in the itemset to set whith the new value.
241 @param _bChangedSomething
242 <TRUE/> if something changed otherwise <FALSE/>
244 static void fillString(SfxItemSet
& _rSet
,Edit
* _pEdit
,sal_uInt16 _nID
,sal_Bool
& _bChangedSomething
);
247 // used to set the right Pane header of a wizard to bold
248 void SetControlFontWeight(Window
* _pWindow
, FontWeight _eWeight
= WEIGHT_BOLD
);
249 void SetHeaderText( sal_uInt16 _nFTResId
, sal_uInt16 _StringResId
);
251 /** This link be used for controls where the tabpage does not need to take any special action when the control
252 is modified. The implementation just calls callModifiedHdl.
254 DECL_LINK(OnControlModified
, void*);
255 DECL_LINK(OnTestConnectionClickHdl
,PushButton
*);
257 /// may be used in SetXXXHdl calls to controls, is a link to <method>OnControlModified</method>
258 virtual Link
getControlModifiedLink() { return LINK(this, OGenericAdministrationPage
, OnControlModified
); }
261 //=========================================================================
263 //=========================================================================
266 RelatedControls
, UnrelatedControls
269 //=========================================================================
271 //=========================================================================
275 static void positionBelow(
276 const Control
& _rReference
,
278 const ControlRelation _eRelation
,
279 const long _nIndentAppFont
281 /** fits the button size to be large enough to contain the buttons text
283 static void fitSizeRightAligned( PushButton
& io_button
);
284 // why is CalcMinimumSize not a virtual method of ::Window?
287 //.........................................................................
289 //.........................................................................
291 #endif // _DBAUI_ADMINPAGES_HXX_
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */