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