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