1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 #include "connpooloptions.hxx"
32 #include "connpooloptions.hrc"
33 #include <svtools/editbrowsebox.hxx>
34 #include <vcl/field.hxx>
35 #include "connpoolsettings.hxx"
36 #include <svl/eitem.hxx>
39 #include <dialmgr.hxx>
41 //........................................................................
44 //........................................................................
46 //====================================================================
48 //====================================================================
49 typedef ::svt::EditBrowseBox DriverListControl_Base
;
50 class DriverListControl
: public DriverListControl_Base
54 DriverPoolingSettings m_aSavedSettings
;
55 DriverPoolingSettings m_aSettings
;
56 DriverPoolingSettings::const_iterator m_aSeekRow
;
61 Link m_aRowChangeHandler
;
64 DriverListControl( Window
* _pParent
, const ResId
& _rId
);
67 void Update(const DriverPoolingSettings
& _rSettings
);
68 virtual String
GetCellText( long nRow
, sal_uInt16 nColId
) const;
70 // the handler will be called with a DriverPoolingSettings::const_iterator as parameter,
71 // or NULL if no valid current row exists
72 void SetRowChangeHandler(const Link
& _rHdl
) { m_aRowChangeHandler
= _rHdl
; }
73 Link
GetRowChangeHandler() const { return m_aRowChangeHandler
; }
75 const DriverPooling
* getCurrentRow() const;
76 DriverPooling
* getCurrentRow();
77 void updateCurrentRow();
79 const DriverPoolingSettings
& getSettings() const { return m_aSettings
; }
81 void saveValue() { m_aSavedSettings
= m_aSettings
; }
82 sal_Bool
isModified() const;
85 virtual void InitController( ::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
);
86 virtual ::svt::CellController
* GetController( long nRow
, sal_uInt16 nCol
);
88 virtual void PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColId
) const;
90 virtual sal_Bool
SeekRow( long nRow
);
91 virtual sal_Bool
SaveModified();
93 virtual sal_Bool
IsTabAllowed(sal_Bool _bForward
) const;
95 virtual void StateChanged( StateChangedType nStateChange
);
97 virtual void CursorMoved();
100 virtual sal_uInt32
GetTotalCellWidth(long nRow
, sal_uInt16 nColId
);
104 String
implGetCellText(DriverPoolingSettings::const_iterator _rPos
, sal_uInt16 _nColId
) const;
107 //--------------------------------------------------------------------
108 DriverListControl::DriverListControl( Window
* _pParent
, const ResId
& _rId
)
109 // :DriverListControl_Base(_pParent, _rId, DBBF_NOROWPICTURE, BROWSER_AUTO_VSCROLL | BROWSER_AUTO_HSCROLL | BROWSER_COLUMNSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_HIDESELECT | BROWSER_CURSOR_WO_FOCUS)
110 :DriverListControl_Base(_pParent
, _rId
, EBBF_NOROWPICTURE
, BROWSER_AUTO_VSCROLL
| BROWSER_AUTO_HSCROLL
| BROWSER_HIDECURSOR
| BROWSER_AUTOSIZE_LASTCOL
)
111 ,m_aSeekRow(m_aSettings
.end())
112 ,m_sYes(ResId(STR_YES
,*_rId
.GetResMgr()))
113 ,m_sNo(ResId(STR_NO
,*_rId
.GetResMgr()))
115 SetStyle((GetStyle() & ~WB_HSCROLL
) | WB_AUTOHSCROLL
);
117 SetUniqueId(UID_OFA_CONNPOOL_DRIVERLIST_BACK
);
118 GetDataWindow().SetHelpId(HID_OFA_CONNPOOL_DRIVERLIST
);
121 //--------------------------------------------------------------------
122 sal_Bool
DriverListControl::IsTabAllowed(sal_Bool
/*_bForward*/) const
124 // no travinling within the fields via RETURN and TAB
128 //--------------------------------------------------------------------
129 sal_Bool
DriverListControl::isModified() const
131 if (m_aSettings
.size() != m_aSavedSettings
.size())
134 DriverPoolingSettings::const_iterator aCurrent
= m_aSettings
.begin();
135 DriverPoolingSettings::const_iterator aCurrentEnd
= m_aSettings
.end();
136 DriverPoolingSettings::const_iterator aSaved
= m_aSavedSettings
.begin();
137 for (;aCurrent
!= aCurrentEnd
; ++aCurrent
, ++aSaved
)
139 if (*aCurrent
!= *aSaved
)
146 //--------------------------------------------------------------------
147 void DriverListControl::Init()
149 DriverListControl_Base::Init();
151 Size aColWidth
= LogicToPixel(Size(160, 0), MAP_APPFONT
);
152 InsertDataColumn(1, String(CUI_RES(STR_DRIVER_NAME
)), aColWidth
.Width());
153 aColWidth
= LogicToPixel(Size(30, 0), MAP_APPFONT
);
154 InsertDataColumn(2, String(CUI_RES(STR_POOLED_FLAG
)), aColWidth
.Width());
155 aColWidth
= LogicToPixel(Size(60, 0), MAP_APPFONT
);
156 InsertDataColumn(3, String(CUI_RES(STR_POOL_TIMEOUT
)), aColWidth
.Width());
157 // Attention: the resource of the string is local to the resource of the enclosing dialog!
160 //--------------------------------------------------------------------
161 void DriverListControl::CursorMoved()
163 DriverListControl_Base::CursorMoved();
165 // call the row change handler
166 if ( m_aRowChangeHandler
.IsSet() )
168 if ( GetCurRow() >= 0 )
169 { // == -1 may happen in case the browse box has just been cleared
170 m_aRowChangeHandler
.Call( getCurrentRow() );
175 //--------------------------------------------------------------------
176 const DriverPooling
* DriverListControl::getCurrentRow() const
178 OSL_ENSURE( ( GetCurRow() < m_aSettings
.size() ) && ( GetCurRow() >= 0 ),
179 "DriverListControl::getCurrentRow: invalid current row!");
181 if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings
.size() ) )
182 return &(*(m_aSettings
.begin() + GetCurRow()));
187 //--------------------------------------------------------------------
188 DriverPooling
* DriverListControl::getCurrentRow()
190 OSL_ENSURE( ( GetCurRow() < m_aSettings
.size() ) && ( GetCurRow() >= 0 ),
191 "DriverListControl::getCurrentRow: invalid current row!");
193 if ( ( GetCurRow() >= 0 ) && ( GetCurRow() < m_aSettings
.size() ) )
194 return &(*(m_aSettings
.begin() + GetCurRow()));
199 //--------------------------------------------------------------------
200 void DriverListControl::updateCurrentRow()
202 Window::Invalidate( GetRowRectPixel( GetCurRow() ), INVALIDATE_UPDATE
);
205 //--------------------------------------------------------------------
206 void DriverListControl::Update(const DriverPoolingSettings
& _rSettings
)
208 m_aSettings
= _rSettings
;
210 SetUpdateMode(sal_False
);
211 RowRemoved(0, GetRowCount());
212 RowInserted(0, m_aSettings
.size());
213 SetUpdateMode(sal_True
);
218 //--------------------------------------------------------------------
219 sal_uInt32
DriverListControl::GetTotalCellWidth(long nRow
, sal_uInt16 nColId
)
221 return GetDataWindow().GetTextWidth(GetCellText(nRow
, nColId
));
224 //--------------------------------------------------------------------
225 String
DriverListControl::implGetCellText(DriverPoolingSettings::const_iterator _rPos
, sal_uInt16 _nColId
) const
227 OSL_ENSURE(_rPos
< m_aSettings
.end(), "DriverListControl::implGetCellText: invalid position!");
233 sReturn
= _rPos
->sName
;
236 sReturn
= _rPos
->bEnabled
? m_sYes
: m_sNo
;
240 sReturn
= String::CreateFromInt32(_rPos
->nTimeoutSeconds
);
243 OSL_ENSURE(sal_False
, "DriverListControl::implGetCellText: invalid column id!");
248 //--------------------------------------------------------------------
249 void DriverListControl::StateChanged( StateChangedType nStateChange
)
251 if (STATE_CHANGE_ENABLE
== nStateChange
)
252 Window::Invalidate(INVALIDATE_UPDATE
);
253 DriverListControl_Base::StateChanged( nStateChange
);
256 //--------------------------------------------------------------------
257 String
DriverListControl::GetCellText( long nRow
, sal_uInt16 nColId
) const
260 if (nRow
> m_aSettings
.size())
262 OSL_ENSURE(sal_False
, "DriverListControl::GetCellText: don't ask me for such rows!");
266 sReturn
= implGetCellText(m_aSettings
.begin() + nRow
, nColId
);
271 //--------------------------------------------------------------------
272 void DriverListControl::InitController( ::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
)
274 rController
->GetWindow().SetText(GetCellText(nRow
, nCol
));
277 //--------------------------------------------------------------------
278 ::svt::CellController
* DriverListControl::GetController( long /*nRow*/, sal_uInt16
/*nCol*/ )
283 //--------------------------------------------------------------------
284 sal_Bool
DriverListControl::SaveModified()
289 //--------------------------------------------------------------------
290 sal_Bool
DriverListControl::SeekRow( long _nRow
)
292 DriverListControl_Base::SeekRow(_nRow
);
294 if (_nRow
< m_aSettings
.size())
295 m_aSeekRow
= m_aSettings
.begin() + _nRow
;
297 m_aSeekRow
= m_aSettings
.end();
299 return m_aSeekRow
!= m_aSettings
.end();
302 //--------------------------------------------------------------------
303 void DriverListControl::PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColId
) const
305 OSL_ENSURE(m_aSeekRow
!= m_aSettings
.end(), "DriverListControl::PaintCell: invalid row!");
307 if (m_aSeekRow
!= m_aSettings
.end())
309 rDev
.SetClipRegion(rRect
);
311 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
;
313 nStyle
|= TEXT_DRAW_DISABLE
;
316 case 1: nStyle
|= TEXT_DRAW_LEFT
; break;
318 case 3: nStyle
|= TEXT_DRAW_CENTER
; break;
321 rDev
.DrawText(rRect
, implGetCellText(m_aSeekRow
, nColId
), nStyle
);
323 rDev
.SetClipRegion();
327 //====================================================================
328 //= ConnectionPoolOptionsPage
329 //====================================================================
330 //--------------------------------------------------------------------
331 ConnectionPoolOptionsPage::ConnectionPoolOptionsPage(Window
* _pParent
, const SfxItemSet
& _rAttrSet
)
332 :SfxTabPage(_pParent
, CUI_RES(RID_OFAPAGE_CONNPOOLOPTIONS
), _rAttrSet
)
333 ,m_aFrame (this, CUI_RES(FL_POOLING
))
334 ,m_aEnablePooling (this, CUI_RES(CB_POOL_CONNS
))
335 ,m_aDriversLabel (this, CUI_RES(FT_DRIVERS
))
336 ,m_pDriverList(new DriverListControl(this, CUI_RES(CTRL_DRIVER_LIST
)))
337 ,m_aDriverLabel (this, CUI_RES(FT_DRIVERLABEL
))
338 ,m_aDriver (this, CUI_RES(FT_DRIVER
))
339 ,m_aDriverPoolingEnabled(this, CUI_RES(CB_DRIVERPOOLING
))
340 ,m_aTimeoutLabel (this, CUI_RES(FT_TIMEOUT
))
341 ,m_aTimeout (this, CUI_RES(NF_TIMEOUT
))
343 m_pDriverList
->Init();
344 m_pDriverList
->Show();
348 m_aEnablePooling
.SetClickHdl( LINK(this, ConnectionPoolOptionsPage
, OnEnabledDisabled
) );
349 m_aDriverPoolingEnabled
.SetClickHdl( LINK(this, ConnectionPoolOptionsPage
, OnEnabledDisabled
) );
351 m_pDriverList
->SetRowChangeHandler( LINK(this, ConnectionPoolOptionsPage
, OnDriverRowChanged
) );
354 //--------------------------------------------------------------------
355 SfxTabPage
* ConnectionPoolOptionsPage::Create(Window
* _pParent
, const SfxItemSet
& _rAttrSet
)
357 return new ConnectionPoolOptionsPage(_pParent
, _rAttrSet
);
360 //--------------------------------------------------------------------
361 ConnectionPoolOptionsPage::~ConnectionPoolOptionsPage()
363 delete m_pDriverList
;
366 //--------------------------------------------------------------------
367 void ConnectionPoolOptionsPage::implInitControls(const SfxItemSet
& _rSet
, sal_Bool
/*_bFromReset*/)
370 SFX_ITEMSET_GET( _rSet
, pEnabled
, SfxBoolItem
, SID_SB_POOLING_ENABLED
, sal_True
);
371 OSL_ENSURE(pEnabled
, "ConnectionPoolOptionsPage::implInitControls: missing the Enabled item!");
372 m_aEnablePooling
.Check(pEnabled
? pEnabled
->GetValue() : sal_True
);
374 m_aEnablePooling
.SaveValue();
376 // the settings for the single drivers
377 SFX_ITEMSET_GET( _rSet
, pDriverSettings
, DriverPoolingSettingsItem
, SID_SB_DRIVER_TIMEOUTS
, sal_True
);
379 m_pDriverList
->Update(pDriverSettings
->getSettings());
382 OSL_ENSURE(sal_False
, "ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
383 m_pDriverList
->Update(DriverPoolingSettings());
385 m_pDriverList
->saveValue();
387 // reflect the new settings
388 OnEnabledDisabled(&m_aEnablePooling
);
391 //--------------------------------------------------------------------
392 long ConnectionPoolOptionsPage::Notify( NotifyEvent
& _rNEvt
)
394 if (EVENT_LOSEFOCUS
== _rNEvt
.GetType())
395 if (m_aTimeout
.IsWindowOrChild(_rNEvt
.GetWindow()))
396 commitTimeoutField();
398 return SfxTabPage::Notify(_rNEvt
);
401 //--------------------------------------------------------------------
402 sal_Bool
ConnectionPoolOptionsPage::FillItemSet(SfxItemSet
& _rSet
)
404 commitTimeoutField();
406 sal_Bool bModified
= sal_False
;
408 if (m_aEnablePooling
.GetSavedValue() != m_aEnablePooling
.IsChecked())
410 _rSet
.Put(SfxBoolItem(SID_SB_POOLING_ENABLED
, m_aEnablePooling
.IsChecked()), SID_SB_POOLING_ENABLED
);
411 bModified
= sal_True
;
414 // the settings for the single drivers
415 if (m_pDriverList
->isModified())
417 _rSet
.Put(DriverPoolingSettingsItem(SID_SB_DRIVER_TIMEOUTS
, m_pDriverList
->getSettings()), SID_SB_DRIVER_TIMEOUTS
);
418 bModified
= sal_True
;
424 //--------------------------------------------------------------------
425 void ConnectionPoolOptionsPage::ActivatePage( const SfxItemSet
& _rSet
)
427 SfxTabPage::ActivatePage(_rSet
);
428 implInitControls(_rSet
, sal_False
);
431 //--------------------------------------------------------------------
432 void ConnectionPoolOptionsPage::Reset(const SfxItemSet
& _rSet
)
434 implInitControls(_rSet
, sal_True
);
437 //--------------------------------------------------------------------
438 IMPL_LINK( ConnectionPoolOptionsPage
, OnDriverRowChanged
, const void*, _pRowIterator
)
440 sal_Bool bValidRow
= (NULL
!= _pRowIterator
);
441 m_aDriverPoolingEnabled
.Enable(bValidRow
&& m_aEnablePooling
.IsChecked());
442 m_aTimeoutLabel
.Enable(bValidRow
);
443 m_aTimeout
.Enable(bValidRow
);
446 { // positioned on an invalid row
447 m_aDriver
.SetText(String());
451 const DriverPooling
*pDriverPos
= static_cast<const DriverPooling
*>(_pRowIterator
);
453 m_aDriver
.SetText(pDriverPos
->sName
);
454 m_aDriverPoolingEnabled
.Check(pDriverPos
->bEnabled
);
455 m_aTimeout
.SetText(String::CreateFromInt32(pDriverPos
->nTimeoutSeconds
));
457 OnEnabledDisabled(&m_aDriverPoolingEnabled
);
463 //--------------------------------------------------------------------
464 void ConnectionPoolOptionsPage::commitTimeoutField()
466 if (DriverPooling
* pCurrentDriver
= m_pDriverList
->getCurrentRow())
468 pCurrentDriver
->nTimeoutSeconds
= static_cast<long>(m_aTimeout
.GetValue());
469 m_pDriverList
->updateCurrentRow();
473 //--------------------------------------------------------------------
474 IMPL_LINK( ConnectionPoolOptionsPage
, OnEnabledDisabled
, const CheckBox
*, _pCheckBox
)
476 sal_Bool bGloballyEnabled
= m_aEnablePooling
.IsChecked();
477 sal_Bool bLocalDriverChanged
= &m_aDriverPoolingEnabled
== _pCheckBox
;
479 if (&m_aEnablePooling
== _pCheckBox
)
481 m_aDriversLabel
.Enable(bGloballyEnabled
);
482 m_pDriverList
->Enable(bGloballyEnabled
);
483 m_aDriverLabel
.Enable(bGloballyEnabled
);
484 m_aDriver
.Enable(bGloballyEnabled
);
485 m_aDriverPoolingEnabled
.Enable(bGloballyEnabled
);
488 OSL_ENSURE(bLocalDriverChanged
, "ConnectionPoolOptionsPage::OnEnabledDisabled: where did this come from?");
490 m_aTimeoutLabel
.Enable(bGloballyEnabled
&& m_aDriverPoolingEnabled
.IsChecked());
491 m_aTimeout
.Enable(bGloballyEnabled
&& m_aDriverPoolingEnabled
.IsChecked());
493 if (bLocalDriverChanged
)
496 m_pDriverList
->getCurrentRow()->bEnabled
= m_aDriverPoolingEnabled
.IsChecked();
497 m_pDriverList
->updateCurrentRow();
503 //........................................................................
504 } // namespace offapp
505 //........................................................................