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 #include "connpooloptions.hxx"
21 #include <svtools/editbrowsebox.hxx>
22 #include <vcl/field.hxx>
23 #include "connpoolsettings.hxx"
24 #include <svl/eitem.hxx>
27 #include <dialmgr.hxx>
29 using ::svt::EditBrowseBox
;
33 /// Widget for the Connection Pool options page
34 class DriverListControl
: public EditBrowseBox
38 DriverPoolingSettings m_aSavedSettings
;
39 DriverPoolingSettings m_aSettings
;
40 DriverPoolingSettings::const_iterator m_aSeekRow
;
45 Link m_aRowChangeHandler
;
48 DriverListControl(Window
* _pParent
);
50 virtual void Init() SAL_OVERRIDE
;
51 void Update(const DriverPoolingSettings
& _rSettings
);
52 virtual OUString
GetCellText( long nRow
, sal_uInt16 nColId
) const SAL_OVERRIDE
;
54 // the handler will be called with a DriverPoolingSettings::const_iterator as parameter,
55 // or NULL if no valid current row exists
56 void SetRowChangeHandler(const Link
& _rHdl
) { m_aRowChangeHandler
= _rHdl
; }
58 DriverPooling
* getCurrentRow();
59 void updateCurrentRow();
61 const DriverPoolingSettings
& getSettings() const { return m_aSettings
; }
63 void saveValue() { m_aSavedSettings
= m_aSettings
; }
64 bool isModified() const;
67 virtual void InitController( ::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
) SAL_OVERRIDE
;
68 virtual ::svt::CellController
* GetController( long nRow
, sal_uInt16 nCol
) SAL_OVERRIDE
;
70 virtual void PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColId
) const SAL_OVERRIDE
;
72 virtual bool SeekRow( long nRow
) SAL_OVERRIDE
;
73 virtual bool SaveModified() SAL_OVERRIDE
;
75 virtual bool IsTabAllowed(bool _bForward
) const SAL_OVERRIDE
;
77 virtual void StateChanged( StateChangedType nStateChange
) SAL_OVERRIDE
;
79 virtual void CursorMoved() SAL_OVERRIDE
;
82 virtual sal_uInt32
GetTotalCellWidth(long nRow
, sal_uInt16 nColId
) SAL_OVERRIDE
;
86 OUString
implGetCellText(DriverPoolingSettings::const_iterator _rPos
, sal_uInt16 _nColId
) const;
90 DriverListControl::DriverListControl(Window
* _pParent
)
91 :EditBrowseBox(_pParent
, EBBF_NOROWPICTURE
, BROWSER_AUTO_VSCROLL
| BROWSER_AUTO_HSCROLL
| BROWSER_HIDECURSOR
| BROWSER_AUTOSIZE_LASTCOL
| WB_BORDER
)
92 ,m_aSeekRow(m_aSettings
.end())
93 ,m_sYes(CUI_RES(RID_SVXSTR_YES
))
94 ,m_sNo(CUI_RES(RID_SVXSTR_NO
))
96 SetStyle((GetStyle() & ~WB_HSCROLL
) | WB_AUTOHSCROLL
);
98 SetUniqueId(UID_OFA_CONNPOOL_DRIVERLIST_BACK
);
101 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeDriverListControl(Window
*pParent
, VclBuilder::stringmap
&)
103 return new DriverListControl(pParent
);
107 bool DriverListControl::IsTabAllowed(bool /*_bForward*/) const
109 // no travelling within the fields via RETURN and TAB
114 bool DriverListControl::isModified() const
116 if (m_aSettings
.size() != m_aSavedSettings
.size())
119 DriverPoolingSettings::const_iterator aCurrent
= m_aSettings
.begin();
120 DriverPoolingSettings::const_iterator aCurrentEnd
= m_aSettings
.end();
121 DriverPoolingSettings::const_iterator aSaved
= m_aSavedSettings
.begin();
122 for (;aCurrent
!= aCurrentEnd
; ++aCurrent
, ++aSaved
)
124 if (*aCurrent
!= *aSaved
)
132 void DriverListControl::Init()
134 EditBrowseBox::Init();
136 Size aColWidth
= LogicToPixel(Size(160, 0), MAP_APPFONT
);
137 InsertDataColumn(1, OUString(CUI_RES(RID_SVXSTR_DRIVER_NAME
)), aColWidth
.Width());
138 aColWidth
= LogicToPixel(Size(30, 0), MAP_APPFONT
);
139 InsertDataColumn(2, OUString(CUI_RES(RID_SVXSTR_POOLED_FLAG
)), aColWidth
.Width());
140 aColWidth
= LogicToPixel(Size(60, 0), MAP_APPFONT
);
141 InsertDataColumn(3, OUString(CUI_RES(RID_SVXSTR_POOL_TIMEOUT
)), aColWidth
.Width());
142 // Attention: the resource of the string is local to the resource of the enclosing dialog!
146 void DriverListControl::CursorMoved()
148 EditBrowseBox::CursorMoved();
150 // call the row change handler
151 if ( m_aRowChangeHandler
.IsSet() )
153 if ( GetCurRow() >= 0 )
154 { // == -1 may happen in case the browse box has just been cleared
155 m_aRowChangeHandler
.Call( getCurrentRow() );
160 DriverPooling
* DriverListControl::getCurrentRow()
162 OSL_ENSURE( ( GetCurRow() < m_aSettings
.size() ) && ( GetCurRow() >= 0 ),
163 "DriverListControl::getCurrentRow: invalid current row!");
165 if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings
.size() ) )
166 return &(*(m_aSettings
.begin() + GetCurRow()));
172 void DriverListControl::updateCurrentRow()
174 Window::Invalidate( GetRowRectPixel( GetCurRow() ), INVALIDATE_UPDATE
);
178 void DriverListControl::Update(const DriverPoolingSettings
& _rSettings
)
180 m_aSettings
= _rSettings
;
182 SetUpdateMode(false);
183 RowRemoved(0, GetRowCount());
184 RowInserted(0, m_aSettings
.size());
191 sal_uInt32
DriverListControl::GetTotalCellWidth(long nRow
, sal_uInt16 nColId
)
193 return GetDataWindow().GetTextWidth(GetCellText(nRow
, nColId
));
197 OUString
DriverListControl::implGetCellText(DriverPoolingSettings::const_iterator _rPos
, sal_uInt16 _nColId
) const
199 OSL_ENSURE(_rPos
< m_aSettings
.end(), "DriverListControl::implGetCellText: invalid position!");
205 sReturn
= _rPos
->sName
;
208 sReturn
= _rPos
->bEnabled
? m_sYes
: m_sNo
;
212 sReturn
= OUString::number(_rPos
->nTimeoutSeconds
);
215 OSL_FAIL("DriverListControl::implGetCellText: invalid column id!");
221 void DriverListControl::StateChanged( StateChangedType nStateChange
)
223 if (STATE_CHANGE_ENABLE
== nStateChange
)
224 Window::Invalidate(INVALIDATE_UPDATE
);
225 EditBrowseBox::StateChanged( nStateChange
);
229 OUString
DriverListControl::GetCellText( long nRow
, sal_uInt16 nColId
) const
232 if (nRow
> m_aSettings
.size())
234 OSL_FAIL("DriverListControl::GetCellText: don't ask me for such rows!");
238 sReturn
= implGetCellText(m_aSettings
.begin() + nRow
, nColId
);
244 void DriverListControl::InitController( ::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
)
246 rController
->GetWindow().SetText(GetCellText(nRow
, nCol
));
250 ::svt::CellController
* DriverListControl::GetController( long /*nRow*/, sal_uInt16
/*nCol*/ )
256 bool DriverListControl::SaveModified()
262 bool DriverListControl::SeekRow( long _nRow
)
264 EditBrowseBox::SeekRow(_nRow
);
266 if (_nRow
< m_aSettings
.size())
267 m_aSeekRow
= m_aSettings
.begin() + _nRow
;
269 m_aSeekRow
= m_aSettings
.end();
271 return m_aSeekRow
!= m_aSettings
.end();
275 void DriverListControl::PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColId
) const
277 OSL_ENSURE(m_aSeekRow
!= m_aSettings
.end(), "DriverListControl::PaintCell: invalid row!");
279 if (m_aSeekRow
!= m_aSettings
.end())
281 rDev
.SetClipRegion(Region(rRect
));
283 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
;
285 nStyle
|= TEXT_DRAW_DISABLE
;
288 case 1: nStyle
|= TEXT_DRAW_LEFT
; break;
290 case 3: nStyle
|= TEXT_DRAW_CENTER
; break;
293 rDev
.DrawText(rRect
, implGetCellText(m_aSeekRow
, nColId
), nStyle
);
295 rDev
.SetClipRegion();
300 //= ConnectionPoolOptionsPage
303 ConnectionPoolOptionsPage::ConnectionPoolOptionsPage(Window
* _pParent
, const SfxItemSet
& _rAttrSet
)
304 : SfxTabPage(_pParent
, "ConnPoolPage", "cui/ui/connpooloptions.ui", _rAttrSet
)
306 get(m_pEnablePooling
, "connectionpooling");
307 get(m_pDriversLabel
, "driverslabel");
308 get(m_pDriverList
, "driverlist");
309 get(m_pDriverLabel
, "driverlabel");
310 get(m_pDriver
, "driver");
311 get(m_pDriverPoolingEnabled
, "enablepooling");
312 get(m_pTimeoutLabel
, "timeoutlabel");
313 get(m_pTimeout
, "timeout");
315 Size
aControlSize(248, 100);
316 aControlSize
= LogicToPixel(aControlSize
, MAP_APPFONT
);
317 m_pDriverList
->set_width_request(aControlSize
.Width());
318 m_pDriverList
->set_height_request(aControlSize
.Height());
319 m_pDriverList
->Init();
320 m_pDriverList
->Show();
322 m_pEnablePooling
->SetClickHdl( LINK(this, ConnectionPoolOptionsPage
, OnEnabledDisabled
) );
323 m_pDriverPoolingEnabled
->SetClickHdl( LINK(this, ConnectionPoolOptionsPage
, OnEnabledDisabled
) );
325 m_pDriverList
->SetRowChangeHandler( LINK(this, ConnectionPoolOptionsPage
, OnDriverRowChanged
) );
329 SfxTabPage
* ConnectionPoolOptionsPage::Create(Window
* _pParent
, const SfxItemSet
& _rAttrSet
)
331 return new ConnectionPoolOptionsPage(_pParent
, _rAttrSet
);
335 void ConnectionPoolOptionsPage::implInitControls(const SfxItemSet
& _rSet
, bool /*_bFromReset*/)
338 SFX_ITEMSET_GET( _rSet
, pEnabled
, SfxBoolItem
, SID_SB_POOLING_ENABLED
, true );
339 OSL_ENSURE(pEnabled
, "ConnectionPoolOptionsPage::implInitControls: missing the Enabled item!");
340 m_pEnablePooling
->Check(pEnabled
? pEnabled
->GetValue() : sal_True
);
342 m_pEnablePooling
->SaveValue();
344 // the settings for the single drivers
345 SFX_ITEMSET_GET( _rSet
, pDriverSettings
, DriverPoolingSettingsItem
, SID_SB_DRIVER_TIMEOUTS
, true );
347 m_pDriverList
->Update(pDriverSettings
->getSettings());
350 OSL_FAIL("ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
351 m_pDriverList
->Update(DriverPoolingSettings());
353 m_pDriverList
->saveValue();
355 // reflect the new settings
356 OnEnabledDisabled(m_pEnablePooling
);
360 bool ConnectionPoolOptionsPage::Notify( NotifyEvent
& _rNEvt
)
362 if (EVENT_LOSEFOCUS
== _rNEvt
.GetType())
363 if (m_pTimeout
->IsWindowOrChild(_rNEvt
.GetWindow()))
364 commitTimeoutField();
366 return SfxTabPage::Notify(_rNEvt
);
370 bool ConnectionPoolOptionsPage::FillItemSet(SfxItemSet
& _rSet
)
372 commitTimeoutField();
374 bool bModified
= false;
376 if (m_pEnablePooling
->IsValueChangedFromSaved())
378 _rSet
.Put(SfxBoolItem(SID_SB_POOLING_ENABLED
, m_pEnablePooling
->IsChecked()), SID_SB_POOLING_ENABLED
);
382 // the settings for the single drivers
383 if (m_pDriverList
->isModified())
385 _rSet
.Put(DriverPoolingSettingsItem(SID_SB_DRIVER_TIMEOUTS
, m_pDriverList
->getSettings()), SID_SB_DRIVER_TIMEOUTS
);
393 void ConnectionPoolOptionsPage::ActivatePage( const SfxItemSet
& _rSet
)
395 SfxTabPage::ActivatePage(_rSet
);
396 implInitControls(_rSet
, false);
400 void ConnectionPoolOptionsPage::Reset(const SfxItemSet
& _rSet
)
402 implInitControls(_rSet
, true);
406 IMPL_LINK( ConnectionPoolOptionsPage
, OnDriverRowChanged
, const void*, _pRowIterator
)
408 bool bValidRow
= (NULL
!= _pRowIterator
);
409 m_pDriverPoolingEnabled
->Enable(bValidRow
&& m_pEnablePooling
->IsChecked());
410 m_pTimeoutLabel
->Enable(bValidRow
);
411 m_pTimeout
->Enable(bValidRow
);
414 { // positioned on an invalid row
415 m_pDriver
->SetText(OUString());
419 const DriverPooling
*pDriverPos
= static_cast<const DriverPooling
*>(_pRowIterator
);
421 m_pDriver
->SetText(pDriverPos
->sName
);
422 m_pDriverPoolingEnabled
->Check(pDriverPos
->bEnabled
);
423 m_pTimeout
->SetText(OUString::number(pDriverPos
->nTimeoutSeconds
));
425 OnEnabledDisabled(m_pDriverPoolingEnabled
);
432 void ConnectionPoolOptionsPage::commitTimeoutField()
434 if (DriverPooling
* pCurrentDriver
= m_pDriverList
->getCurrentRow())
436 pCurrentDriver
->nTimeoutSeconds
= static_cast<long>(m_pTimeout
->GetValue());
437 m_pDriverList
->updateCurrentRow();
442 IMPL_LINK( ConnectionPoolOptionsPage
, OnEnabledDisabled
, const CheckBox
*, _pCheckBox
)
444 bool bGloballyEnabled
= m_pEnablePooling
->IsChecked();
445 bool bLocalDriverChanged
= m_pDriverPoolingEnabled
== _pCheckBox
;
447 if (m_pEnablePooling
== _pCheckBox
)
449 m_pDriversLabel
->Enable(bGloballyEnabled
);
450 m_pDriverList
->Enable(bGloballyEnabled
);
451 m_pDriverLabel
->Enable(bGloballyEnabled
);
452 m_pDriver
->Enable(bGloballyEnabled
);
453 m_pDriverPoolingEnabled
->Enable(bGloballyEnabled
);
456 OSL_ENSURE(bLocalDriverChanged
, "ConnectionPoolOptionsPage::OnEnabledDisabled: where did this come from?");
458 m_pTimeoutLabel
->Enable(bGloballyEnabled
&& m_pDriverPoolingEnabled
->IsChecked());
459 m_pTimeout
->Enable(bGloballyEnabled
&& m_pDriverPoolingEnabled
->IsChecked());
461 if (bLocalDriverChanged
)
464 m_pDriverList
->getCurrentRow()->bEnabled
= m_pDriverPoolingEnabled
->IsChecked();
465 m_pDriverList
->updateCurrentRow();
471 } // namespace offapp
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */