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