1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_UI_DLG_ADMINPAGES_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_DLG_ADMINPAGES_HXX
23 #include <sfx2/tabdlg.hxx>
24 #include "dsntypes.hxx"
25 #include "commontypes.hxx"
26 #include <svtools/wizardmachine.hxx>
27 #include <vcl/field.hxx>
28 #include <vcl/fixed.hxx>
34 /// helper class to wrap the savevalue and disable call
35 class SAL_NO_VTABLE ISaveValueWrapper
38 virtual ~ISaveValueWrapper() = 0;
39 virtual bool SaveValue() = 0;
40 virtual bool Disable() = 0;
43 template < class T
> class OSaveValueWrapper
: public ISaveValueWrapper
47 OSaveValueWrapper(T
* _pSaveValue
) : m_pSaveValue(_pSaveValue
)
48 { OSL_ENSURE(m_pSaveValue
,"Illegal argument!"); }
50 virtual bool SaveValue() SAL_OVERRIDE
{ m_pSaveValue
->SaveValue(); return true;} // bool return value only for stl
51 virtual bool Disable() SAL_OVERRIDE
{ m_pSaveValue
->Disable(); return true;} // bool return value only for stl
54 template < class T
> class ODisableWrapper
: public ISaveValueWrapper
58 ODisableWrapper(T
* _pSaveValue
) : m_pSaveValue(_pSaveValue
)
59 { OSL_ENSURE(m_pSaveValue
,"Illegal argument!"); }
61 virtual bool SaveValue() SAL_OVERRIDE
{ return true;} // bool return value only for stl
62 virtual bool Disable() SAL_OVERRIDE
{ m_pSaveValue
->Disable(); return true;} // bool return value only for stl
65 struct TSaveValueWrapperFunctor
: public ::std::unary_function
< ISaveValueWrapper
, bool>
67 bool operator() (ISaveValueWrapper
* lhs
)
69 return lhs
->SaveValue();
72 struct TDisableWrapperFunctor
: public ::std::unary_function
< ISaveValueWrapper
, bool>
74 bool operator() (ISaveValueWrapper
* lhs
)
76 return lhs
->Disable();
80 struct TDeleteWrapperFunctor
: public ::std::unary_function
< ISaveValueWrapper
, bool>
82 bool operator() (ISaveValueWrapper
* lhs
)
89 // OGenericAdministrationPage
90 class IDatabaseSettingsDialog
;
92 class OGenericAdministrationPage
:public SfxTabPage
93 ,public ::svt::IWizardPageController
96 Link
<OGenericAdministrationPage
const *, void> m_aModifiedHandler
; /// to be called if something on the page has been modified
97 bool m_abEnableRoadmap
;
99 IDatabaseSettingsDialog
* m_pAdminDialog
;
100 IItemSetHelper
* m_pItemSetHelper
;
102 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
105 OGenericAdministrationPage(vcl::Window
* _pParent
, const OString
& _rId
, const OUString
& _rUIXMLDescription
, const SfxItemSet
& _rAttrSet
);
106 /// set a handler which gets called every time something on the page has been modified
107 void SetModifiedHandler(const Link
<OGenericAdministrationPage
const *, void>& _rHandler
) { m_aModifiedHandler
= _rHandler
; }
109 /** Sets the ParentDialog
112 @param _pItemSetHelper
115 inline void SetAdminDialog(IDatabaseSettingsDialog
* _pDialog
,IItemSetHelper
* _pItemSetHelper
)
117 OSL_ENSURE(_pDialog
&& _pItemSetHelper
,"Values are NULL!");
118 m_pAdminDialog
= _pDialog
;
119 m_pItemSetHelper
= _pItemSetHelper
;
122 /** Sets the ServiceFactory
126 void SetServiceFactory(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxORB
)
131 /** opens a dialog filled with all data sources available for this type and
132 returns the selected on.
134 The type for which the data source dialog should be opened.
136 <OUT/> contains the selected name.
138 <FALSE/> if an error occurred, otherwise <TRUE/>
140 bool getSelectedDataSource(OUString
& _sReturn
, OUString
& _sCurr
);
142 // svt::IWizardPageController
143 virtual void initializePage() SAL_OVERRIDE
;
144 virtual bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason
) SAL_OVERRIDE
;
145 virtual bool canAdvance() const SAL_OVERRIDE
;
147 void SetRoadmapStateValue( bool _bDoEnable
) { m_abEnableRoadmap
= _bDoEnable
; }
148 bool GetRoadmapStateValue() const { return m_abEnableRoadmap
; }
151 /// default implementation: call FillItemSet, call prepareLeave,
152 virtual sfxpg
DeactivatePage(SfxItemSet
* pSet
) SAL_OVERRIDE
;
153 using SfxTabPage::DeactivatePage
;
154 /// default implementation: call implInitControls with the given item set and _bSaveValue = sal_False
155 virtual void Reset(const SfxItemSet
* _rCoreAttrs
) SAL_OVERRIDE
;
156 /// default implementation: call implInitControls with the given item set and _bSaveValue = sal_True
157 virtual void ActivatePage(const SfxItemSet
& _rSet
) SAL_OVERRIDE
;
159 // TabPage overridables
160 virtual void ActivatePage() SAL_OVERRIDE
;
163 void callModifiedHdl() const { if (m_aModifiedHandler
.IsSet()) m_aModifiedHandler
.Call(this); }
165 /// called from within DeactivatePage. The page is allowed to be deactivated if this method returns sal_True
166 virtual bool prepareLeave() { return true; }
168 /** called from within Reset and ActivatePage, use to initialize the controls with the items from the given set
169 @param _bSaveValue if set to sal_True, the implementation should call SaveValue on all relevant controls
171 virtual void implInitControls(const SfxItemSet
& _rSet
, bool _bSaveValue
);
173 /// analyze the invalid and the readonly flag which may be present in the set
174 static void getFlags(const SfxItemSet
& _rSet
, bool& _rValid
, bool& _rReadonly
);
176 /** will be called inside <method>implInitControls</method> to save the value if necessary
178 The list must be filled with the controls.
179 It is not allowed to clear the list before pusching data into it.
181 virtual void fillControls(::std::vector
< ISaveValueWrapper
* >& _rControlList
) = 0;
183 /** will be called inside <method>implInitControls</method> to disable if necessary
185 The list must be filled with the controls.
186 It is not allowed to clear the list before pusching data into it.
188 virtual void fillWindows(::std::vector
< ISaveValueWrapper
* >& _rControlList
) = 0;
191 /** fills the Boolean value into the item set when the value changed.
193 The item set where to put the new value into.
195 The check box which is checked.
197 The id in the itemset to set with the new value.
198 @param _bChangedSomething
199 <TRUE/> if something changed otherwise <FALSE/>
201 set to <TRUE/> if the display value should be reverted before putting it into the set
203 static void fillBool( SfxItemSet
& _rSet
, CheckBox
* _pCheckBox
, sal_uInt16 _nID
, bool& _bChangedSomething
, bool _bRevertValue
= false);
205 /** fills the int value into the item set when the value changed.
207 The item set where to put the new value into.
209 The check box which is checked.
211 The id in the itemset to set with the new value.
212 @param _bChangedSomething
213 <TRUE/> if something changed otherwise <FALSE/>
215 static void fillInt32(SfxItemSet
& _rSet
,NumericField
* _pEdit
,sal_uInt16 _nID
, bool& _bChangedSomething
);
217 /** fills the String value into the item set when the value changed.
219 The item set where to put the new value into.
221 The check box which is checked.
223 The id in the itemset to set with the new value.
224 @param _bChangedSomething
225 <TRUE/> if something changed otherwise <FALSE/>
227 static void fillString(SfxItemSet
& _rSet
,Edit
* _pEdit
,sal_uInt16 _nID
, bool& _bChangedSomething
);
230 /** This link be used for controls where the tabpage does not need to take any special action when the control
231 is modified. The implementation just calls callModifiedHdl.
233 DECL_LINK(OnControlModified
, void*);
234 DECL_LINK(OnTestConnectionClickHdl
, PushButton
*);
236 /// may be used in SetXXXHdl calls to controls, is a link to <method>OnControlModified</method>
237 virtual Link
<> getControlModifiedLink() { return LINK(this, OGenericAdministrationPage
, OnControlModified
); }
243 RelatedControls
, UnrelatedControls
250 static void positionBelow(
251 const Control
& _rReference
,
253 const ControlRelation _eRelation
,
254 const long _nIndentAppFont
256 /** fits the button size to be large enough to contain the buttons text
258 static void fitSizeRightAligned( PushButton
& io_button
);
259 // why is CalcMinimumSize not a virtual method of vcl::Window?
264 #endif // INCLUDED_DBACCESS_SOURCE_UI_DLG_ADMINPAGES_HXX
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */