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