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