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 : #include "connpooloptions.hxx"
21 : #include "connpooloptions.hrc"
22 : #include <svtools/editbrowsebox.hxx>
23 : #include <vcl/field.hxx>
24 : #include "connpoolsettings.hxx"
25 : #include <svl/eitem.hxx>
26 : #include <cuires.hrc>
27 : #include "helpid.hrc"
28 : #include <dialmgr.hxx>
29 :
30 : //........................................................................
31 : namespace offapp
32 : {
33 : //........................................................................
34 :
35 : //====================================================================
36 : //= DriverListControl
37 : //====================================================================
38 : typedef ::svt::EditBrowseBox DriverListControl_Base;
39 0 : class DriverListControl : public DriverListControl_Base
40 : {
41 : using Window::Update;
42 : protected:
43 : DriverPoolingSettings m_aSavedSettings;
44 : DriverPoolingSettings m_aSettings;
45 : DriverPoolingSettings::const_iterator m_aSeekRow;
46 :
47 : String m_sYes;
48 : String m_sNo;
49 :
50 : Link m_aRowChangeHandler;
51 :
52 : public:
53 : DriverListControl( Window* _pParent, const ResId& _rId);
54 :
55 : virtual void Init();
56 : void Update(const DriverPoolingSettings& _rSettings);
57 : virtual String GetCellText( long nRow, sal_uInt16 nColId ) const;
58 :
59 : // the handler will be called with a DriverPoolingSettings::const_iterator as parameter,
60 : // or NULL if no valid current row exists
61 0 : void SetRowChangeHandler(const Link& _rHdl) { m_aRowChangeHandler = _rHdl; }
62 : Link GetRowChangeHandler() const { return m_aRowChangeHandler; }
63 :
64 : const DriverPooling* getCurrentRow() const;
65 : DriverPooling* getCurrentRow();
66 : void updateCurrentRow();
67 :
68 0 : const DriverPoolingSettings& getSettings() const { return m_aSettings; }
69 :
70 0 : void saveValue() { m_aSavedSettings = m_aSettings; }
71 : sal_Bool isModified() const;
72 :
73 : protected:
74 : virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol );
75 : virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol );
76 :
77 : virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId ) const;
78 :
79 : virtual sal_Bool SeekRow( long nRow );
80 : virtual sal_Bool SaveModified();
81 :
82 : virtual sal_Bool IsTabAllowed(sal_Bool _bForward) const;
83 :
84 : virtual void StateChanged( StateChangedType nStateChange );
85 :
86 : virtual void CursorMoved();
87 :
88 : protected:
89 : virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId);
90 :
91 :
92 : private:
93 : String implGetCellText(DriverPoolingSettings::const_iterator _rPos, sal_uInt16 _nColId) const;
94 : };
95 :
96 : //--------------------------------------------------------------------
97 0 : DriverListControl::DriverListControl( Window* _pParent, const ResId& _rId)
98 : :DriverListControl_Base(_pParent, _rId, EBBF_NOROWPICTURE, BROWSER_AUTO_VSCROLL | BROWSER_AUTO_HSCROLL | BROWSER_HIDECURSOR | BROWSER_AUTOSIZE_LASTCOL)
99 0 : ,m_aSeekRow(m_aSettings.end())
100 0 : ,m_sYes(ResId(STR_YES,*_rId.GetResMgr()))
101 0 : ,m_sNo(ResId(STR_NO,*_rId.GetResMgr()))
102 : {
103 0 : SetStyle((GetStyle() & ~WB_HSCROLL) | WB_AUTOHSCROLL);
104 :
105 0 : SetUniqueId(UID_OFA_CONNPOOL_DRIVERLIST_BACK);
106 0 : GetDataWindow().SetHelpId(HID_OFA_CONNPOOL_DRIVERLIST);
107 0 : }
108 :
109 : //--------------------------------------------------------------------
110 0 : sal_Bool DriverListControl::IsTabAllowed(sal_Bool /*_bForward*/) const
111 : {
112 : // no travinling within the fields via RETURN and TAB
113 0 : return sal_False;
114 : }
115 :
116 : //--------------------------------------------------------------------
117 0 : sal_Bool DriverListControl::isModified() const
118 : {
119 0 : if (m_aSettings.size() != m_aSavedSettings.size())
120 0 : return sal_True;
121 :
122 0 : DriverPoolingSettings::const_iterator aCurrent = m_aSettings.begin();
123 0 : DriverPoolingSettings::const_iterator aCurrentEnd = m_aSettings.end();
124 0 : DriverPoolingSettings::const_iterator aSaved = m_aSavedSettings.begin();
125 0 : for (;aCurrent != aCurrentEnd; ++aCurrent, ++aSaved)
126 : {
127 0 : if (*aCurrent != *aSaved)
128 0 : return sal_True;
129 : }
130 :
131 0 : return sal_False;
132 : }
133 :
134 : //--------------------------------------------------------------------
135 0 : void DriverListControl::Init()
136 : {
137 0 : DriverListControl_Base::Init();
138 :
139 0 : Size aColWidth = LogicToPixel(Size(160, 0), MAP_APPFONT);
140 0 : InsertDataColumn(1, String(CUI_RES(STR_DRIVER_NAME)), aColWidth.Width());
141 0 : aColWidth = LogicToPixel(Size(30, 0), MAP_APPFONT);
142 0 : InsertDataColumn(2, String(CUI_RES(STR_POOLED_FLAG)), aColWidth.Width());
143 0 : aColWidth = LogicToPixel(Size(60, 0), MAP_APPFONT);
144 0 : InsertDataColumn(3, String(CUI_RES(STR_POOL_TIMEOUT)), aColWidth.Width());
145 : // Attention: the resource of the string is local to the resource of the enclosing dialog!
146 0 : }
147 :
148 : //--------------------------------------------------------------------
149 0 : void DriverListControl::CursorMoved()
150 : {
151 0 : DriverListControl_Base::CursorMoved();
152 :
153 : // call the row change handler
154 0 : if ( m_aRowChangeHandler.IsSet() )
155 : {
156 0 : if ( GetCurRow() >= 0 )
157 : { // == -1 may happen in case the browse box has just been cleared
158 0 : m_aRowChangeHandler.Call( getCurrentRow() );
159 : }
160 : }
161 0 : }
162 :
163 : //--------------------------------------------------------------------
164 0 : const DriverPooling* DriverListControl::getCurrentRow() const
165 : {
166 : OSL_ENSURE( ( GetCurRow() < m_aSettings.size() ) && ( GetCurRow() >= 0 ),
167 : "DriverListControl::getCurrentRow: invalid current row!");
168 :
169 0 : if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings.size() ) )
170 0 : return &(*(m_aSettings.begin() + GetCurRow()));
171 :
172 0 : return NULL;
173 : }
174 :
175 : //--------------------------------------------------------------------
176 0 : DriverPooling* DriverListControl::getCurrentRow()
177 : {
178 : OSL_ENSURE( ( GetCurRow() < m_aSettings.size() ) && ( GetCurRow() >= 0 ),
179 : "DriverListControl::getCurrentRow: invalid current row!");
180 :
181 0 : if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings.size() ) )
182 0 : return &(*(m_aSettings.begin() + GetCurRow()));
183 :
184 0 : return NULL;
185 : }
186 :
187 : //--------------------------------------------------------------------
188 0 : void DriverListControl::updateCurrentRow()
189 : {
190 0 : Window::Invalidate( GetRowRectPixel( GetCurRow() ), INVALIDATE_UPDATE );
191 0 : }
192 :
193 : //--------------------------------------------------------------------
194 0 : void DriverListControl::Update(const DriverPoolingSettings& _rSettings)
195 : {
196 0 : m_aSettings = _rSettings;
197 :
198 0 : SetUpdateMode(sal_False);
199 0 : RowRemoved(0, GetRowCount());
200 0 : RowInserted(0, m_aSettings.size());
201 0 : SetUpdateMode(sal_True);
202 :
203 0 : ActivateCell(1, 0);
204 0 : }
205 :
206 : //--------------------------------------------------------------------
207 0 : sal_uInt32 DriverListControl::GetTotalCellWidth(long nRow, sal_uInt16 nColId)
208 : {
209 0 : return GetDataWindow().GetTextWidth(GetCellText(nRow, nColId));
210 : }
211 :
212 : //--------------------------------------------------------------------
213 0 : String DriverListControl::implGetCellText(DriverPoolingSettings::const_iterator _rPos, sal_uInt16 _nColId) const
214 : {
215 : OSL_ENSURE(_rPos < m_aSettings.end(), "DriverListControl::implGetCellText: invalid position!");
216 :
217 0 : String sReturn;
218 0 : switch (_nColId)
219 : {
220 : case 1:
221 0 : sReturn = _rPos->sName;
222 0 : break;
223 : case 2:
224 0 : sReturn = _rPos->bEnabled ? m_sYes : m_sNo;
225 0 : break;
226 : case 3:
227 0 : if (_rPos->bEnabled)
228 0 : sReturn = String::CreateFromInt32(_rPos->nTimeoutSeconds);
229 0 : break;
230 : default:
231 : OSL_FAIL("DriverListControl::implGetCellText: invalid column id!");
232 : }
233 0 : return sReturn;
234 : }
235 :
236 : //--------------------------------------------------------------------
237 0 : void DriverListControl::StateChanged( StateChangedType nStateChange )
238 : {
239 0 : if (STATE_CHANGE_ENABLE == nStateChange)
240 0 : Window::Invalidate(INVALIDATE_UPDATE);
241 0 : DriverListControl_Base::StateChanged( nStateChange );
242 0 : }
243 :
244 : //--------------------------------------------------------------------
245 0 : String DriverListControl::GetCellText( long nRow, sal_uInt16 nColId ) const
246 : {
247 0 : String sReturn;
248 0 : if (nRow > m_aSettings.size())
249 : {
250 : OSL_FAIL("DriverListControl::GetCellText: don't ask me for such rows!");
251 : }
252 : else
253 : {
254 0 : sReturn = implGetCellText(m_aSettings.begin() + nRow, nColId);
255 : }
256 0 : return sReturn;
257 : }
258 :
259 : //--------------------------------------------------------------------
260 0 : void DriverListControl::InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol )
261 : {
262 0 : rController->GetWindow().SetText(GetCellText(nRow, nCol));
263 0 : }
264 :
265 : //--------------------------------------------------------------------
266 0 : ::svt::CellController* DriverListControl::GetController( long /*nRow*/, sal_uInt16 /*nCol*/ )
267 : {
268 0 : return NULL;
269 : }
270 :
271 : //--------------------------------------------------------------------
272 0 : sal_Bool DriverListControl::SaveModified()
273 : {
274 0 : return sal_True;
275 : }
276 :
277 : //--------------------------------------------------------------------
278 0 : sal_Bool DriverListControl::SeekRow( long _nRow )
279 : {
280 0 : DriverListControl_Base::SeekRow(_nRow);
281 :
282 0 : if (_nRow < m_aSettings.size())
283 0 : m_aSeekRow = m_aSettings.begin() + _nRow;
284 : else
285 0 : m_aSeekRow = m_aSettings.end();
286 :
287 0 : return m_aSeekRow != m_aSettings.end();
288 : }
289 :
290 : //--------------------------------------------------------------------
291 0 : void DriverListControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId ) const
292 : {
293 : OSL_ENSURE(m_aSeekRow != m_aSettings.end(), "DriverListControl::PaintCell: invalid row!");
294 :
295 0 : if (m_aSeekRow != m_aSettings.end())
296 : {
297 0 : rDev.SetClipRegion(rRect);
298 :
299 0 : sal_uInt16 nStyle = TEXT_DRAW_CLIP;
300 0 : if (!IsEnabled())
301 0 : nStyle |= TEXT_DRAW_DISABLE;
302 0 : switch (nColId)
303 : {
304 0 : case 1: nStyle |= TEXT_DRAW_LEFT; break;
305 : case 2:
306 0 : case 3: nStyle |= TEXT_DRAW_CENTER; break;
307 : }
308 :
309 0 : rDev.DrawText(rRect, implGetCellText(m_aSeekRow, nColId), nStyle);
310 :
311 0 : rDev.SetClipRegion();
312 : }
313 0 : }
314 :
315 : //====================================================================
316 : //= ConnectionPoolOptionsPage
317 : //====================================================================
318 : //--------------------------------------------------------------------
319 0 : ConnectionPoolOptionsPage::ConnectionPoolOptionsPage(Window* _pParent, const SfxItemSet& _rAttrSet)
320 0 : :SfxTabPage(_pParent, CUI_RES(RID_OFAPAGE_CONNPOOLOPTIONS ), _rAttrSet)
321 0 : ,m_aFrame (this, CUI_RES(FL_POOLING))
322 0 : ,m_aEnablePooling (this, CUI_RES(CB_POOL_CONNS))
323 0 : ,m_aDriversLabel (this, CUI_RES(FT_DRIVERS))
324 0 : ,m_pDriverList(new DriverListControl(this, CUI_RES(CTRL_DRIVER_LIST)))
325 0 : ,m_aDriverLabel (this, CUI_RES(FT_DRIVERLABEL))
326 0 : ,m_aDriver (this, CUI_RES(FT_DRIVER))
327 0 : ,m_aDriverPoolingEnabled(this, CUI_RES(CB_DRIVERPOOLING))
328 0 : ,m_aTimeoutLabel (this, CUI_RES(FT_TIMEOUT))
329 0 : ,m_aTimeout (this, CUI_RES(NF_TIMEOUT))
330 : {
331 0 : m_pDriverList->Init();
332 0 : m_pDriverList->Show();
333 :
334 0 : FreeResource();
335 :
336 0 : m_aEnablePooling.SetClickHdl( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
337 0 : m_aDriverPoolingEnabled.SetClickHdl( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
338 :
339 0 : m_pDriverList->SetRowChangeHandler( LINK(this, ConnectionPoolOptionsPage, OnDriverRowChanged) );
340 0 : }
341 :
342 : //--------------------------------------------------------------------
343 0 : SfxTabPage* ConnectionPoolOptionsPage::Create(Window* _pParent, const SfxItemSet& _rAttrSet)
344 : {
345 0 : return new ConnectionPoolOptionsPage(_pParent, _rAttrSet);
346 : }
347 :
348 : //--------------------------------------------------------------------
349 0 : ConnectionPoolOptionsPage::~ConnectionPoolOptionsPage()
350 : {
351 0 : delete m_pDriverList;
352 0 : }
353 :
354 : //--------------------------------------------------------------------
355 0 : void ConnectionPoolOptionsPage::implInitControls(const SfxItemSet& _rSet, sal_Bool /*_bFromReset*/)
356 : {
357 : // the enabled flag
358 0 : SFX_ITEMSET_GET( _rSet, pEnabled, SfxBoolItem, SID_SB_POOLING_ENABLED, sal_True );
359 : OSL_ENSURE(pEnabled, "ConnectionPoolOptionsPage::implInitControls: missing the Enabled item!");
360 0 : m_aEnablePooling.Check(pEnabled ? pEnabled->GetValue() : sal_True);
361 :
362 0 : m_aEnablePooling.SaveValue();
363 :
364 : // the settings for the single drivers
365 0 : SFX_ITEMSET_GET( _rSet, pDriverSettings, DriverPoolingSettingsItem, SID_SB_DRIVER_TIMEOUTS, sal_True );
366 0 : if (pDriverSettings)
367 0 : m_pDriverList->Update(pDriverSettings->getSettings());
368 : else
369 : {
370 : OSL_FAIL("ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
371 0 : m_pDriverList->Update(DriverPoolingSettings());
372 : }
373 0 : m_pDriverList->saveValue();
374 :
375 : // reflect the new settings
376 0 : OnEnabledDisabled(&m_aEnablePooling);
377 0 : }
378 :
379 : //--------------------------------------------------------------------
380 0 : long ConnectionPoolOptionsPage::Notify( NotifyEvent& _rNEvt )
381 : {
382 0 : if (EVENT_LOSEFOCUS == _rNEvt.GetType())
383 0 : if (m_aTimeout.IsWindowOrChild(_rNEvt.GetWindow()))
384 0 : commitTimeoutField();
385 :
386 0 : return SfxTabPage::Notify(_rNEvt);
387 : }
388 :
389 : //--------------------------------------------------------------------
390 0 : sal_Bool ConnectionPoolOptionsPage::FillItemSet(SfxItemSet& _rSet)
391 : {
392 0 : commitTimeoutField();
393 :
394 0 : sal_Bool bModified = sal_False;
395 : // the enabled flag
396 0 : if (m_aEnablePooling.GetSavedValue() != m_aEnablePooling.IsChecked())
397 : {
398 0 : _rSet.Put(SfxBoolItem(SID_SB_POOLING_ENABLED, m_aEnablePooling.IsChecked()), SID_SB_POOLING_ENABLED);
399 0 : bModified = sal_True;
400 : }
401 :
402 : // the settings for the single drivers
403 0 : if (m_pDriverList->isModified())
404 : {
405 0 : _rSet.Put(DriverPoolingSettingsItem(SID_SB_DRIVER_TIMEOUTS, m_pDriverList->getSettings()), SID_SB_DRIVER_TIMEOUTS);
406 0 : bModified = sal_True;
407 : }
408 :
409 0 : return bModified;
410 : }
411 :
412 : //--------------------------------------------------------------------
413 0 : void ConnectionPoolOptionsPage::ActivatePage( const SfxItemSet& _rSet)
414 : {
415 0 : SfxTabPage::ActivatePage(_rSet);
416 0 : implInitControls(_rSet, sal_False);
417 0 : }
418 :
419 : //--------------------------------------------------------------------
420 0 : void ConnectionPoolOptionsPage::Reset(const SfxItemSet& _rSet)
421 : {
422 0 : implInitControls(_rSet, sal_True);
423 0 : }
424 :
425 : //--------------------------------------------------------------------
426 0 : IMPL_LINK( ConnectionPoolOptionsPage, OnDriverRowChanged, const void*, _pRowIterator )
427 : {
428 0 : sal_Bool bValidRow = (NULL != _pRowIterator);
429 0 : m_aDriverPoolingEnabled.Enable(bValidRow && m_aEnablePooling.IsChecked());
430 0 : m_aTimeoutLabel.Enable(bValidRow);
431 0 : m_aTimeout.Enable(bValidRow);
432 :
433 0 : if (!bValidRow)
434 : { // positioned on an invalid row
435 0 : m_aDriver.SetText(String());
436 : }
437 : else
438 : {
439 0 : const DriverPooling *pDriverPos = static_cast<const DriverPooling*>(_pRowIterator);
440 :
441 0 : m_aDriver.SetText(pDriverPos->sName);
442 0 : m_aDriverPoolingEnabled.Check(pDriverPos->bEnabled);
443 0 : m_aTimeout.SetText(String::CreateFromInt32(pDriverPos->nTimeoutSeconds));
444 :
445 0 : OnEnabledDisabled(&m_aDriverPoolingEnabled);
446 : }
447 :
448 0 : return 0L;
449 : }
450 :
451 : //--------------------------------------------------------------------
452 0 : void ConnectionPoolOptionsPage::commitTimeoutField()
453 : {
454 0 : if (DriverPooling* pCurrentDriver = m_pDriverList->getCurrentRow())
455 : {
456 0 : pCurrentDriver->nTimeoutSeconds = static_cast<long>(m_aTimeout.GetValue());
457 0 : m_pDriverList->updateCurrentRow();
458 : }
459 0 : }
460 :
461 : //--------------------------------------------------------------------
462 0 : IMPL_LINK( ConnectionPoolOptionsPage, OnEnabledDisabled, const CheckBox*, _pCheckBox )
463 : {
464 0 : sal_Bool bGloballyEnabled = m_aEnablePooling.IsChecked();
465 0 : sal_Bool bLocalDriverChanged = &m_aDriverPoolingEnabled == _pCheckBox;
466 :
467 0 : if (&m_aEnablePooling == _pCheckBox)
468 : {
469 0 : m_aDriversLabel.Enable(bGloballyEnabled);
470 0 : m_pDriverList->Enable(bGloballyEnabled);
471 0 : m_aDriverLabel.Enable(bGloballyEnabled);
472 0 : m_aDriver.Enable(bGloballyEnabled);
473 0 : m_aDriverPoolingEnabled.Enable(bGloballyEnabled);
474 : }
475 : else
476 : OSL_ENSURE(bLocalDriverChanged, "ConnectionPoolOptionsPage::OnEnabledDisabled: where did this come from?");
477 :
478 0 : m_aTimeoutLabel.Enable(bGloballyEnabled && m_aDriverPoolingEnabled.IsChecked());
479 0 : m_aTimeout.Enable(bGloballyEnabled && m_aDriverPoolingEnabled.IsChecked());
480 :
481 0 : if (bLocalDriverChanged)
482 : {
483 : // update the list
484 0 : m_pDriverList->getCurrentRow()->bEnabled = m_aDriverPoolingEnabled.IsChecked();
485 0 : m_pDriverList->updateCurrentRow();
486 : }
487 :
488 0 : return 0L;
489 : }
490 :
491 : //........................................................................
492 3 : } // namespace offapp
493 : //........................................................................
494 :
495 :
496 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|