fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / adminpages.cxx
blob7282b7fb9f5d80162b02aec8515a11fbad78b035
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include "adminpages.hxx"
21 #include "dbadmin.hxx"
22 #include "dbu_dlg.hrc"
23 #include <svl/stritem.hxx>
24 #include <svl/eitem.hxx>
25 #include <svl/intitem.hxx>
26 #include "dbustrings.hrc"
27 #include "dsitems.hxx"
28 #include "dsselect.hxx"
29 #include "localresaccess.hxx"
30 #include "odbcconfig.hxx"
31 #include "optionalboolitem.hxx"
32 #include "sqlmessage.hxx"
34 #include <osl/file.hxx>
35 #include <vcl/accel.hxx>
36 #include <vcl/button.hxx>
37 #include <vcl/edit.hxx>
38 #include <vcl/field.hxx>
39 #include <vcl/layout.hxx>
40 #include <vcl/lstbox.hxx>
42 #include <algorithm>
43 #include <stdlib.h>
45 namespace dbaui
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::sdbc;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::lang;
52 using namespace ::dbtools;
53 using namespace ::svt;
55 ISaveValueWrapper::~ISaveValueWrapper()
59 OGenericAdministrationPage::OGenericAdministrationPage(vcl::Window* _pParent, const OString& _rId, const OUString& _rUIXMLDescription, const SfxItemSet& _rAttrSet)
60 :SfxTabPage(_pParent, _rId, _rUIXMLDescription, &_rAttrSet)
61 ,m_abEnableRoadmap(false)
62 ,m_pAdminDialog(NULL)
63 ,m_pItemSetHelper(NULL)
66 SetExchangeSupport(true);
69 SfxTabPage::sfxpg OGenericAdministrationPage::DeactivatePage(SfxItemSet* _pSet)
71 if (_pSet)
73 if (!prepareLeave())
74 return KEEP_PAGE;
75 FillItemSet(_pSet);
78 return LEAVE_PAGE;
81 void OGenericAdministrationPage::Reset(const SfxItemSet* _rCoreAttrs)
83 implInitControls(*_rCoreAttrs, false);
85 void OGenericAdministrationPage::ActivatePage()
87 TabPage::ActivatePage();
88 OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
89 if ( m_pItemSetHelper )
90 ActivatePage(*m_pItemSetHelper->getOutputSet());
92 void OGenericAdministrationPage::ActivatePage(const SfxItemSet& _rSet)
94 implInitControls(_rSet, true);
97 void OGenericAdministrationPage::getFlags(const SfxItemSet& _rSet, bool& _rValid, bool& _rReadonly)
99 SFX_ITEMSET_GET(_rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, true);
100 _rValid = !pInvalid || !pInvalid->GetValue();
101 SFX_ITEMSET_GET(_rSet, pReadonly, SfxBoolItem, DSID_READONLY, true);
102 _rReadonly = !_rValid || (pReadonly && pReadonly->GetValue());
105 IMPL_LINK_NOARG(OGenericAdministrationPage, OnControlModified)
107 callModifiedHdl();
108 return 0L;
110 bool OGenericAdministrationPage::getSelectedDataSource(OUString& _sReturn, OUString& _sCurr)
112 // collect all ODBC data source names
113 StringBag aOdbcDatasources;
114 OOdbcEnumeration aEnumeration;
115 if (!aEnumeration.isLoaded())
117 // show an error message
118 OUString sError( ModuleRes( STR_COULD_NOT_LOAD_ODBC_LIB ) );
119 sError = sError.replaceFirst("#lib#", aEnumeration.getLibraryName());
120 ScopedVclPtrInstance< MessageDialog > aDialog(this, sError);
121 aDialog->Execute();
122 return false;
124 else
126 aEnumeration.getDatasourceNames(aOdbcDatasources);
127 // execute the select dialog
128 ScopedVclPtrInstance< ODatasourceSelectDialog > aSelector(GetParent(), aOdbcDatasources);
129 if (!_sCurr.isEmpty())
130 aSelector->Select(_sCurr);
131 if ( RET_OK == aSelector->Execute() )
132 _sReturn = aSelector->GetSelected();
134 return true;
137 void OGenericAdministrationPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
139 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
140 bool bValid, bReadonly;
141 getFlags(_rSet, bValid, bReadonly);
143 ::std::vector< ISaveValueWrapper* > aControlList;
144 if ( _bSaveValue )
146 fillControls(aControlList);
147 ::std::for_each(aControlList.begin(),aControlList.end(),TSaveValueWrapperFunctor());
150 if ( bReadonly )
152 fillWindows(aControlList);
153 ::std::for_each(aControlList.begin(),aControlList.end(),TDisableWrapperFunctor());
156 ::std::for_each(aControlList.begin(),aControlList.end(),TDeleteWrapperFunctor());
157 aControlList.clear();
160 void OGenericAdministrationPage::initializePage()
162 OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
163 if ( m_pItemSetHelper )
164 Reset(m_pItemSetHelper->getOutputSet());
166 bool OGenericAdministrationPage::commitPage( ::svt::WizardTypes::CommitPageReason )
168 return true;
170 bool OGenericAdministrationPage::canAdvance() const
172 return true;
174 void OGenericAdministrationPage::fillBool( SfxItemSet& _rSet, CheckBox* _pCheckBox, sal_uInt16 _nID, bool& _bChangedSomething, bool _bRevertValue )
176 if ( _pCheckBox && _pCheckBox->IsValueChangedFromSaved() )
178 bool bValue = _pCheckBox->IsChecked();
179 if ( _bRevertValue )
180 bValue = !bValue;
182 if ( _pCheckBox->IsTriStateEnabled() )
184 OptionalBoolItem aValue( _nID );
185 if ( _pCheckBox->GetState() != TRISTATE_INDET )
186 aValue.SetValue( bValue );
187 _rSet.Put( aValue );
189 else
190 _rSet.Put( SfxBoolItem( _nID, bValue ) );
192 _bChangedSomething = true;
195 void OGenericAdministrationPage::fillInt32(SfxItemSet& _rSet, NumericField* _pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
197 if( _pEdit && _pEdit->IsValueChangedFromSaved() )
199 _rSet.Put(SfxInt32Item(_nID, static_cast<sal_Int32>(_pEdit->GetValue())));
200 _bChangedSomething = true;
203 void OGenericAdministrationPage::fillString(SfxItemSet& _rSet, Edit* _pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
205 if( _pEdit && _pEdit->IsValueChangedFromSaved() )
207 _rSet.Put(SfxStringItem(_nID, _pEdit->GetText()));
208 _bChangedSomething = true;
212 IMPL_LINK(OGenericAdministrationPage, OnTestConnectionClickHdl, PushButton*, /*_pButton*/)
214 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
215 bool bSuccess = false;
216 if ( m_pAdminDialog )
218 m_pAdminDialog->saveDatasource();
219 OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), true);
220 bool bShowMessage = true;
223 ::std::pair< Reference<XConnection>,sal_Bool> xConnection = m_pAdminDialog->createConnection();
224 bShowMessage = xConnection.second;
225 bSuccess = xConnection.first.is();
226 ::comphelper::disposeComponent(xConnection.first);
228 catch(Exception&)
231 if ( bShowMessage )
233 OSQLMessageBox::MessageType eImage = OSQLMessageBox::Info;
234 OUString aMessage,sTitle;
235 sTitle = ModuleRes(STR_CONNECTION_TEST);
236 if ( bSuccess )
238 aMessage = ModuleRes(STR_CONNECTION_SUCCESS);
240 else
242 eImage = OSQLMessageBox::Error;
243 aMessage = ModuleRes(STR_CONNECTION_NO_SUCCESS);
245 ScopedVclPtrInstance< OSQLMessageBox > aMsg( this, sTitle, aMessage, WB_OK, eImage );
246 aMsg->Execute();
248 if ( !bSuccess )
249 m_pAdminDialog->clearPassword();
251 return 0L;
254 // LayoutHelper
255 void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl, const ControlRelation _eRelation,
256 const long _nIndentAppFont )
258 Point aReference = _rReference.GetPosPixel();
259 aReference.Y() += _rReference.GetSizePixel().Height();
261 const vcl::Window* pConverter = _rControl.GetParent();
262 Size aOffset = pConverter->LogicToPixel( Size( _nIndentAppFont, ( _eRelation == RelatedControls ? 3 : 6 ) ), MAP_APPFONT );
264 Point aControlPos( aReference.X() + aOffset.Width(), aReference.Y() + aOffset.Height() );
265 _rControl.SetPosPixel( aControlPos );
268 void LayoutHelper::fitSizeRightAligned( PushButton& io_button )
270 const Point aOldPos = io_button.GetPosPixel();
271 const Size aOldSize = io_button.GetSizePixel();
272 const Size aMinSize( io_button.CalcMinimumSize() );
273 if ( aMinSize.Width() > aOldSize.Width() )
275 io_button.setPosSizePixel(
276 aOldPos.X() + aOldSize.Width() - aMinSize.Width(),
278 aMinSize.Width(),
280 PosSizeFlags::X | PosSizeFlags::Width
285 } // namespace dbaui
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */