1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: connpooloptions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include "connpooloptions.hxx"
38 #ifndef _OFFAPP_CONNPOOLOPTIONS_HRC_
39 #include "connpooloptions.hrc"
41 #include <svtools/editbrowsebox.hxx>
42 #include <vcl/field.hxx>
43 #include "connpoolsettings.hxx"
44 #include <svtools/eitem.hxx>
46 #include <svx/dialogs.hrc>
48 #include <svx/dialmgr.hxx>
50 //........................................................................
53 //........................................................................
55 //====================================================================
57 //====================================================================
58 typedef ::svt::EditBrowseBox DriverListControl_Base
;
59 class DriverListControl
: public DriverListControl_Base
63 DriverPoolingSettings m_aSavedSettings
;
64 DriverPoolingSettings m_aSettings
;
65 DriverPoolingSettings::const_iterator m_aSeekRow
;
70 Link m_aRowChangeHandler
;
73 DriverListControl( Window
* _pParent
, const ResId
& _rId
);
76 void Update(const DriverPoolingSettings
& _rSettings
);
77 virtual String
GetCellText( long nRow
, USHORT nColId
) const;
79 // the handler will be called with a DriverPoolingSettings::const_iterator as parameter,
80 // or NULL if no valid current row exists
81 void SetRowChangeHandler(const Link
& _rHdl
) { m_aRowChangeHandler
= _rHdl
; }
82 Link
GetRowChangeHandler() const { return m_aRowChangeHandler
; }
84 const DriverPooling
* getCurrentRow() const;
85 DriverPooling
* getCurrentRow();
86 void updateCurrentRow();
88 const DriverPoolingSettings
& getSettings() const { return m_aSettings
; }
90 void saveValue() { m_aSavedSettings
= m_aSettings
; }
91 sal_Bool
isModified() const;
94 virtual void InitController( ::svt::CellControllerRef
& rController
, long nRow
, USHORT nCol
);
95 virtual ::svt::CellController
* GetController( long nRow
, USHORT nCol
);
97 virtual void PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, USHORT nColId
) const;
99 virtual BOOL
SeekRow( long nRow
);
100 virtual BOOL
SaveModified();
102 virtual sal_Bool
IsTabAllowed(sal_Bool _bForward
) const;
104 virtual void StateChanged( StateChangedType nStateChange
);
106 virtual void CursorMoved();
109 virtual sal_uInt32
GetTotalCellWidth(long nRow
, USHORT nColId
);
113 String
implGetCellText(DriverPoolingSettings::const_iterator _rPos
, sal_uInt16 _nColId
) const;
116 //--------------------------------------------------------------------
117 DriverListControl::DriverListControl( Window
* _pParent
, const ResId
& _rId
)
118 // :DriverListControl_Base(_pParent, _rId, DBBF_NOROWPICTURE, BROWSER_AUTO_VSCROLL | BROWSER_AUTO_HSCROLL | BROWSER_COLUMNSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_HIDESELECT | BROWSER_CURSOR_WO_FOCUS)
119 :DriverListControl_Base(_pParent
, _rId
, EBBF_NOROWPICTURE
, BROWSER_AUTO_VSCROLL
| BROWSER_AUTO_HSCROLL
| BROWSER_HIDECURSOR
| BROWSER_AUTOSIZE_LASTCOL
)
120 ,m_aSeekRow(m_aSettings
.end())
121 ,m_sYes(ResId(STR_YES
,*_rId
.GetResMgr()))
122 ,m_sNo(ResId(STR_NO
,*_rId
.GetResMgr()))
124 SetStyle((GetStyle() & ~WB_HSCROLL
) | WB_AUTOHSCROLL
);
126 SetUniqueId(UID_OFA_CONNPOOL_DRIVERLIST_BACK
);
127 GetDataWindow().SetHelpId(HID_OFA_CONNPOOL_DRIVERLIST
);
130 //--------------------------------------------------------------------
131 sal_Bool
DriverListControl::IsTabAllowed(sal_Bool
/*_bForward*/) const
133 // no travinling within the fields via RETURN and TAB
137 //--------------------------------------------------------------------
138 sal_Bool
DriverListControl::isModified() const
140 if (m_aSettings
.size() != m_aSavedSettings
.size())
143 DriverPoolingSettings::const_iterator aCurrent
= m_aSettings
.begin();
144 DriverPoolingSettings::const_iterator aCurrentEnd
= m_aSettings
.end();
145 DriverPoolingSettings::const_iterator aSaved
= m_aSavedSettings
.begin();
146 for (;aCurrent
!= aCurrentEnd
; ++aCurrent
, ++aSaved
)
148 if (*aCurrent
!= *aSaved
)
155 //--------------------------------------------------------------------
156 void DriverListControl::Init()
158 DriverListControl_Base::Init();
160 Size aColWidth
= LogicToPixel(Size(160, 0), MAP_APPFONT
);
161 InsertDataColumn(1, String(SVX_RES(STR_DRIVER_NAME
)), aColWidth
.Width());
162 aColWidth
= LogicToPixel(Size(30, 0), MAP_APPFONT
);
163 InsertDataColumn(2, String(SVX_RES(STR_POOLED_FLAG
)), aColWidth
.Width());
164 aColWidth
= LogicToPixel(Size(60, 0), MAP_APPFONT
);
165 InsertDataColumn(3, String(SVX_RES(STR_POOL_TIMEOUT
)), aColWidth
.Width());
166 // Attention: the resource of the string is local to the resource of the enclosing dialog!
169 //--------------------------------------------------------------------
170 void DriverListControl::CursorMoved()
172 DriverListControl_Base::CursorMoved();
174 // call the row change handler
175 if ( m_aRowChangeHandler
.IsSet() )
177 if ( GetCurRow() >= 0 )
178 { // == -1 may happen in case the browse box has just been cleared
179 m_aRowChangeHandler
.Call( getCurrentRow() );
184 //--------------------------------------------------------------------
185 const DriverPooling
* DriverListControl::getCurrentRow() const
187 OSL_ENSURE( ( GetCurRow() < m_aSettings
.size() ) && ( GetCurRow() >= 0 ),
188 "DriverListControl::getCurrentRow: invalid current row!");
190 if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings
.size() ) )
191 return &(*(m_aSettings
.begin() + GetCurRow()));
196 //--------------------------------------------------------------------
197 DriverPooling
* DriverListControl::getCurrentRow()
199 OSL_ENSURE( ( GetCurRow() < m_aSettings
.size() ) && ( GetCurRow() >= 0 ),
200 "DriverListControl::getCurrentRow: invalid current row!");
202 if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings
.size() ) )
203 return &(*(m_aSettings
.begin() + GetCurRow()));
208 //--------------------------------------------------------------------
209 void DriverListControl::updateCurrentRow()
211 Window::Invalidate( GetRowRectPixel( GetCurRow() ), INVALIDATE_UPDATE
);
214 //--------------------------------------------------------------------
215 void DriverListControl::Update(const DriverPoolingSettings
& _rSettings
)
217 m_aSettings
= _rSettings
;
219 SetUpdateMode(sal_False
);
220 RowRemoved(0, GetRowCount());
221 RowInserted(0, m_aSettings
.size());
222 SetUpdateMode(sal_True
);
227 //--------------------------------------------------------------------
228 sal_uInt32
DriverListControl::GetTotalCellWidth(long nRow
, USHORT nColId
)
230 return GetDataWindow().GetTextWidth(GetCellText(nRow
, nColId
));
233 //--------------------------------------------------------------------
234 String
DriverListControl::implGetCellText(DriverPoolingSettings::const_iterator _rPos
, sal_uInt16 _nColId
) const
236 OSL_ENSURE(_rPos
< m_aSettings
.end(), "DriverListControl::implGetCellText: invalid position!");
242 sReturn
= _rPos
->sName
;
245 sReturn
= _rPos
->bEnabled
? m_sYes
: m_sNo
;
249 sReturn
= String::CreateFromInt32(_rPos
->nTimeoutSeconds
);
252 OSL_ENSURE(sal_False
, "DriverListControl::implGetCellText: invalid column id!");
257 //--------------------------------------------------------------------
258 void DriverListControl::StateChanged( StateChangedType nStateChange
)
260 if (STATE_CHANGE_ENABLE
== nStateChange
)
261 Window::Invalidate(INVALIDATE_UPDATE
);
262 DriverListControl_Base::StateChanged( nStateChange
);
265 //--------------------------------------------------------------------
266 String
DriverListControl::GetCellText( long nRow
, USHORT nColId
) const
269 if (nRow
> m_aSettings
.size())
271 OSL_ENSURE(sal_False
, "DriverListControl::GetCellText: don't ask me for such rows!");
275 sReturn
= implGetCellText(m_aSettings
.begin() + nRow
, nColId
);
280 //--------------------------------------------------------------------
281 void DriverListControl::InitController( ::svt::CellControllerRef
& rController
, long nRow
, USHORT nCol
)
283 rController
->GetWindow().SetText(GetCellText(nRow
, nCol
));
286 //--------------------------------------------------------------------
287 ::svt::CellController
* DriverListControl::GetController( long /*nRow*/, USHORT
/*nCol*/ )
292 //--------------------------------------------------------------------
293 BOOL
DriverListControl::SaveModified()
298 //--------------------------------------------------------------------
299 BOOL
DriverListControl::SeekRow( long _nRow
)
301 DriverListControl_Base::SeekRow(_nRow
);
303 if (_nRow
< m_aSettings
.size())
304 m_aSeekRow
= m_aSettings
.begin() + _nRow
;
306 m_aSeekRow
= m_aSettings
.end();
308 return m_aSeekRow
!= m_aSettings
.end();
311 //--------------------------------------------------------------------
312 void DriverListControl::PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, USHORT nColId
) const
314 OSL_ENSURE(m_aSeekRow
!= m_aSettings
.end(), "DriverListControl::PaintCell: invalid row!");
316 if (m_aSeekRow
!= m_aSettings
.end())
318 rDev
.SetClipRegion(rRect
);
320 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
;
322 nStyle
|= TEXT_DRAW_DISABLE
;
325 case 1: nStyle
|= TEXT_DRAW_LEFT
; break;
327 case 3: nStyle
|= TEXT_DRAW_CENTER
; break;
330 rDev
.DrawText(rRect
, implGetCellText(m_aSeekRow
, nColId
), nStyle
);
332 rDev
.SetClipRegion();
336 //====================================================================
337 //= ConnectionPoolOptionsPage
338 //====================================================================
339 //--------------------------------------------------------------------
340 ConnectionPoolOptionsPage::ConnectionPoolOptionsPage(Window
* _pParent
, const SfxItemSet
& _rAttrSet
)
341 :SfxTabPage(_pParent
, SVX_RES(RID_OFAPAGE_CONNPOOLOPTIONS
), _rAttrSet
)
342 ,m_aFrame (this, SVX_RES(FL_POOLING
))
343 ,m_aEnablePooling (this, SVX_RES(CB_POOL_CONNS
))
344 ,m_aDriversLabel (this, SVX_RES(FT_DRIVERS
))
345 ,m_pDriverList(new DriverListControl(this, SVX_RES(CTRL_DRIVER_LIST
)))
346 ,m_aDriverLabel (this, SVX_RES(FT_DRIVERLABEL
))
347 ,m_aDriver (this, SVX_RES(FT_DRIVER
))
348 ,m_aDriverPoolingEnabled(this, SVX_RES(CB_DRIVERPOOLING
))
349 ,m_aTimeoutLabel (this, SVX_RES(FT_TIMEOUT
))
350 ,m_aTimeout (this, SVX_RES(NF_TIMEOUT
))
352 m_pDriverList
->Init();
353 m_pDriverList
->Show();
357 m_aEnablePooling
.SetClickHdl( LINK(this, ConnectionPoolOptionsPage
, OnEnabledDisabled
) );
358 m_aDriverPoolingEnabled
.SetClickHdl( LINK(this, ConnectionPoolOptionsPage
, OnEnabledDisabled
) );
360 m_pDriverList
->SetRowChangeHandler( LINK(this, ConnectionPoolOptionsPage
, OnDriverRowChanged
) );
363 //--------------------------------------------------------------------
364 SfxTabPage
* ConnectionPoolOptionsPage::Create(Window
* _pParent
, const SfxItemSet
& _rAttrSet
)
366 return new ConnectionPoolOptionsPage(_pParent
, _rAttrSet
);
369 //--------------------------------------------------------------------
370 ConnectionPoolOptionsPage::~ConnectionPoolOptionsPage()
372 delete m_pDriverList
;
375 //--------------------------------------------------------------------
376 void ConnectionPoolOptionsPage::implInitControls(const SfxItemSet
& _rSet
, sal_Bool
/*_bFromReset*/)
379 SFX_ITEMSET_GET( _rSet
, pEnabled
, SfxBoolItem
, SID_SB_POOLING_ENABLED
, sal_True
);
380 OSL_ENSURE(pEnabled
, "ConnectionPoolOptionsPage::implInitControls: missing the Enabled item!");
381 m_aEnablePooling
.Check(pEnabled
? pEnabled
->GetValue() : sal_True
);
383 m_aEnablePooling
.SaveValue();
385 // the settings for the single drivers
386 SFX_ITEMSET_GET( _rSet
, pDriverSettings
, DriverPoolingSettingsItem
, SID_SB_DRIVER_TIMEOUTS
, sal_True
);
388 m_pDriverList
->Update(pDriverSettings
->getSettings());
391 OSL_ENSURE(sal_False
, "ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
392 m_pDriverList
->Update(DriverPoolingSettings());
394 m_pDriverList
->saveValue();
396 // reflect the new settings
397 OnEnabledDisabled(&m_aEnablePooling
);
400 //--------------------------------------------------------------------
401 long ConnectionPoolOptionsPage::Notify( NotifyEvent
& _rNEvt
)
403 if (EVENT_LOSEFOCUS
== _rNEvt
.GetType())
404 if (m_aTimeout
.IsWindowOrChild(_rNEvt
.GetWindow()))
405 commitTimeoutField();
407 return SfxTabPage::Notify(_rNEvt
);
410 //--------------------------------------------------------------------
411 BOOL
ConnectionPoolOptionsPage::FillItemSet(SfxItemSet
& _rSet
)
413 commitTimeoutField();
415 sal_Bool bModified
= sal_False
;
417 if (m_aEnablePooling
.GetSavedValue() != m_aEnablePooling
.IsChecked())
419 _rSet
.Put(SfxBoolItem(SID_SB_POOLING_ENABLED
, m_aEnablePooling
.IsChecked()), SID_SB_POOLING_ENABLED
);
420 bModified
= sal_True
;
423 // the settings for the single drivers
424 if (m_pDriverList
->isModified())
426 _rSet
.Put(DriverPoolingSettingsItem(SID_SB_DRIVER_TIMEOUTS
, m_pDriverList
->getSettings()), SID_SB_DRIVER_TIMEOUTS
);
427 bModified
= sal_True
;
433 //--------------------------------------------------------------------
434 void ConnectionPoolOptionsPage::ActivatePage( const SfxItemSet
& _rSet
)
436 SfxTabPage::ActivatePage(_rSet
);
437 implInitControls(_rSet
, sal_False
);
440 //--------------------------------------------------------------------
441 void ConnectionPoolOptionsPage::Reset(const SfxItemSet
& _rSet
)
443 implInitControls(_rSet
, sal_True
);
446 //--------------------------------------------------------------------
447 IMPL_LINK( ConnectionPoolOptionsPage
, OnDriverRowChanged
, const void*, _pRowIterator
)
449 sal_Bool bValidRow
= (NULL
!= _pRowIterator
);
450 m_aDriverPoolingEnabled
.Enable(bValidRow
&& m_aEnablePooling
.IsChecked());
451 m_aTimeoutLabel
.Enable(bValidRow
);
452 m_aTimeout
.Enable(bValidRow
);
455 { // positioned on an invalid row
456 m_aDriver
.SetText(String());
460 const DriverPooling
*pDriverPos
= static_cast<const DriverPooling
*>(_pRowIterator
);
462 m_aDriver
.SetText(pDriverPos
->sName
);
463 m_aDriverPoolingEnabled
.Check(pDriverPos
->bEnabled
);
464 m_aTimeout
.SetText(String::CreateFromInt32(pDriverPos
->nTimeoutSeconds
));
466 OnEnabledDisabled(&m_aDriverPoolingEnabled
);
472 //--------------------------------------------------------------------
473 void ConnectionPoolOptionsPage::commitTimeoutField()
475 if (DriverPooling
* pCurrentDriver
= m_pDriverList
->getCurrentRow())
477 pCurrentDriver
->nTimeoutSeconds
= static_cast<long>(m_aTimeout
.GetValue());
478 m_pDriverList
->updateCurrentRow();
482 //--------------------------------------------------------------------
483 IMPL_LINK( ConnectionPoolOptionsPage
, OnEnabledDisabled
, const CheckBox
*, _pCheckBox
)
485 sal_Bool bGloballyEnabled
= m_aEnablePooling
.IsChecked();
486 sal_Bool bLocalDriverChanged
= &m_aDriverPoolingEnabled
== _pCheckBox
;
488 if (&m_aEnablePooling
== _pCheckBox
)
490 m_aDriversLabel
.Enable(bGloballyEnabled
);
491 m_pDriverList
->Enable(bGloballyEnabled
);
492 m_aDriverLabel
.Enable(bGloballyEnabled
);
493 m_aDriver
.Enable(bGloballyEnabled
);
494 m_aDriverPoolingEnabled
.Enable(bGloballyEnabled
);
497 OSL_ENSURE(bLocalDriverChanged
, "ConnectionPoolOptionsPage::OnEnabledDisabled: where did this come from?");
499 m_aTimeoutLabel
.Enable(bGloballyEnabled
&& m_aDriverPoolingEnabled
.IsChecked());
500 m_aTimeout
.Enable(bGloballyEnabled
&& m_aDriverPoolingEnabled
.IsChecked());
502 if (bLocalDriverChanged
)
505 m_pDriverList
->getCurrentRow()->bEnabled
= m_aDriverPoolingEnabled
.IsChecked();
506 m_pDriverList
->updateCurrentRow();
512 //........................................................................
513 } // namespace offapp
514 //........................................................................