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