LCOV - code coverage report
Current view: top level - cui/source/options - connpooloptions.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 196 0.0 %
Date: 2014-04-11 Functions: 0 38 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10