[Libreoffice-commits] .: vcl/inc vcl/source

Jan Holesovsky kendy at kemper.freedesktop.org
Tue Feb 22 08:23:59 PST 2011


 vcl/inc/vcl/btndlg.hxx       |    7 -
 vcl/source/window/btndlg.cxx |  198 ++++++++++++++-----------------------------
 2 files changed, 71 insertions(+), 134 deletions(-)

New commits:
commit e0b9df123939c6ea273e7fe5fe40a106ce0c7a0f
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Fri Feb 18 15:32:32 2011 -0430

    Update mpItemList from std::vector to boost::ptr_vector.

diff --git a/vcl/inc/vcl/btndlg.hxx b/vcl/inc/vcl/btndlg.hxx
index e06f181..3b66351 100644
--- a/vcl/inc/vcl/btndlg.hxx
+++ b/vcl/inc/vcl/btndlg.hxx
@@ -29,16 +29,15 @@
 #ifndef _SV_BTNDLG_HXX
 #define _SV_BTNDLG_HXX
 
+#include <boost/ptr_container/ptr_vector.hpp>
+
 #include <vcl/sv.h>
 #include <vcl/dllapi.h>
 #include <vcl/dialog.hxx>
-#include <vector>
 
 struct ImplBtnDlgItem;
 class PushButton;
 
-typedef ::std::vector< ImplBtnDlgItem* > ImplBtnDlgItemList;
-
 // ----------------------
 // - ButtonDialog-Types -
 // ----------------------
@@ -58,7 +57,7 @@ typedef ::std::vector< ImplBtnDlgItem* > ImplBtnDlgItemList;
 class VCL_DLLPUBLIC ButtonDialog : public Dialog
 {
 private:
-    ImplBtnDlgItemList* mpItemList;
+    boost::ptr_vector<ImplBtnDlgItem> maItemList;
     Size				maPageSize;
     Size				maCtrlSize;
     long				mnButtonSize;
diff --git a/vcl/source/window/btndlg.cxx b/vcl/source/window/btndlg.cxx
index ee1b34d..845a787 100644
--- a/vcl/source/window/btndlg.cxx
+++ b/vcl/source/window/btndlg.cxx
@@ -29,46 +29,38 @@
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_vcl.hxx"
 
-#include <tools/ref.hxx>
 #include <tools/debug.hxx>
-#include <vcl/svdata.hxx>
+#include <tools/rc.h>
 #include <vcl/button.hxx>
 #include <vcl/btndlg.hxx>
+#include <vcl/svdata.hxx>
 
-#include <tools/rc.h>
-
-// =======================================================================
+typedef boost::ptr_vector<ImplBtnDlgItem>::iterator btn_iterator;
+typedef boost::ptr_vector<ImplBtnDlgItem>::const_iterator btn_const_iterator;
 
 struct ImplBtnDlgItem
 {
     USHORT				mnId;
-    BOOL				mbOwnButton;
-    BOOL				mbDummyAlign;
+    bool				mbOwnButton;
+    bool				mbDummyAlign;
     long				mnSepSize;
     PushButton* 		mpPushButton;
 };
 
-// =======================================================================
-
 void ButtonDialog::ImplInitButtonDialogData()
 {
-    mpItemList				= new ImplBtnDlgItemList();
     mnButtonSize			= 0;
     mnCurButtonId			= 0;
     mnFocusButtonId 		= BUTTONDIALOG_BUTTON_NOTFOUND;
     mbFormat				= TRUE;
 }
 
-// -----------------------------------------------------------------------
-
 ButtonDialog::ButtonDialog( WindowType nType ) :
     Dialog( nType )
 {
     ImplInitButtonDialogData();
 }
 
-// -----------------------------------------------------------------------
-
 ButtonDialog::ButtonDialog( Window* pParent, WinBits nStyle ) :
     Dialog( WINDOW_BUTTONDIALOG )
 {
@@ -76,8 +68,6 @@ ButtonDialog::ButtonDialog( Window* pParent, WinBits nStyle ) :
     ImplInit( pParent, nStyle );
 }
 
-// -----------------------------------------------------------------------
-
 ButtonDialog::ButtonDialog( Window* pParent, const ResId& rResId ) :
     Dialog( WINDOW_BUTTONDIALOG )
 {
@@ -87,22 +77,15 @@ ButtonDialog::ButtonDialog( Window* pParent, const ResId& rResId ) :
     ImplLoadRes( rResId );
 }
 
-// -----------------------------------------------------------------------
-
 ButtonDialog::~ButtonDialog()
 {
-    for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
-        ImplBtnDlgItem* pItem = (*mpItemList)[ i ];
-        if ( pItem->mpPushButton && pItem->mbOwnButton ) {
-            delete pItem->mpPushButton;
-        }
-        delete pItem;
+    for ( btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
+    {
+        if ( it->mpPushButton && it->mbOwnButton )
+            delete it->mpPushButton;
     }
-    delete mpItemList;
 }
 
-// -----------------------------------------------------------------------
-
 PushButton* ButtonDialog::ImplCreatePushButton( USHORT nBtnFlags )
 {
     PushButton* pBtn;
@@ -125,57 +108,53 @@ PushButton* ButtonDialog::ImplCreatePushButton( USHORT nBtnFlags )
     return pBtn;
 }
 
-// -----------------------------------------------------------------------
-
 ImplBtnDlgItem* ButtonDialog::ImplGetItem( USHORT nId ) const
 {
-    for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
-        ImplBtnDlgItem* pItem = (*mpItemList)[ i ];
-        if ( pItem->mnId == nId ) {
-            return pItem;
-        }
+    for ( btn_const_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
+    {
+        if (it->mnId == nId)
+            return const_cast<ImplBtnDlgItem*>(&(*it));
     }
 
     return NULL;
 }
 
-// -----------------------------------------------------------------------
-
 long ButtonDialog::ImplGetButtonSize()
 {
     if ( !mbFormat )
         return mnButtonSize;
 
     // Calculate ButtonSize
-    long	nLastSepSize = 0;
-    long	nSepSize = 0;
-    long	nButtonCount = 0;
+    long nLastSepSize = 0;
+    long nSepSize = 0;
     maCtrlSize = Size( IMPL_MINSIZE_BUTTON_WIDTH, IMPL_MINSIZE_BUTTON_HEIGHT );
 
-    for ( size_t i = 0, n = mpItemList->size(); i < n; ++i )
+    for ( btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
     {
-        ImplBtnDlgItem* pItem = (*mpItemList)[ i ];
         nSepSize += nLastSepSize;
 
-        long nTxtWidth = pItem->mpPushButton->GetCtrlTextWidth( pItem->mpPushButton->GetText() );
+        long nTxtWidth = it->mpPushButton->GetCtrlTextWidth(it->mpPushButton->GetText());
         nTxtWidth += IMPL_EXTRA_BUTTON_WIDTH;
+
         if ( nTxtWidth > maCtrlSize.Width() )
             maCtrlSize.Width() = nTxtWidth;
-        long nTxtHeight = pItem->mpPushButton->GetTextHeight();
+
+        long nTxtHeight = it->mpPushButton->GetTextHeight();
         nTxtHeight += IMPL_EXTRA_BUTTON_HEIGHT;
+
         if ( nTxtHeight > maCtrlSize.Height() )
             maCtrlSize.Height() = nTxtHeight;
 
-        nSepSize += pItem->mnSepSize;
+        nSepSize += it->mnSepSize;
 
         if ( GetStyle() & WB_HORZ )
             nLastSepSize = IMPL_SEP_BUTTON_X;
         else
             nLastSepSize = IMPL_SEP_BUTTON_Y;
-
-        nButtonCount++;
     }
 
+    long nButtonCount = maItemList.size();
+
     if ( GetStyle() & WB_HORZ )
         mnButtonSize  = nSepSize + (nButtonCount*maCtrlSize.Width());
     else
@@ -184,8 +163,6 @@ long ButtonDialog::ImplGetButtonSize()
     return mnButtonSize;
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::ImplPosControls()
 {
     if ( !mbFormat )
@@ -195,7 +172,6 @@ void ButtonDialog::ImplPosControls()
     ImplGetButtonSize();
 
     // determine dialog size
-    ImplBtnDlgItem* pItem;
     Size			aDlgSize = maPageSize;
     long			nX;
     long			nY;
@@ -229,15 +205,16 @@ void ButtonDialog::ImplPosControls()
     }
 
     // Arrange PushButtons
-    for ( size_t i = 0, n = mpItemList->size(); i < n; ++i )
+    for ( btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
     {
-        pItem = (*mpItemList)[ i ];
         if ( GetStyle() & WB_HORZ )
-            nX += pItem->mnSepSize;
+            nX += it->mnSepSize;
         else
-            nY += pItem->mnSepSize;
-        pItem->mpPushButton->SetPosSizePixel( Point( nX, nY ), maCtrlSize );
-        pItem->mpPushButton->Show();
+            nY += it->mnSepSize;
+
+        it->mpPushButton->SetPosSizePixel( Point( nX, nY ), maCtrlSize );
+        it->mpPushButton->Show();
+
         if ( GetStyle() & WB_HORZ )
             nX += maCtrlSize.Width()+IMPL_SEP_BUTTON_X;
         else
@@ -249,16 +226,13 @@ void ButtonDialog::ImplPosControls()
     mbFormat = FALSE;
 }
 
-// -----------------------------------------------------------------------
-
 IMPL_LINK( ButtonDialog, ImplClickHdl, PushButton*, pBtn )
 {
-    for ( size_t i = 0, n = mpItemList->size(); i < n; ++i )
+    for ( btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
     {
-        ImplBtnDlgItem* pItem = (*mpItemList)[ i ];
-        if ( pItem->mpPushButton == pBtn )
+        if ( it->mpPushButton == pBtn )
         {
-            mnCurButtonId = pItem->mnId;
+            mnCurButtonId = it->mnId;
             Click();
             break;
         }
@@ -267,30 +241,26 @@ IMPL_LINK( ButtonDialog, ImplClickHdl, PushButton*, pBtn )
     return 0;
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::Resize()
 {
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::StateChanged( StateChangedType nType )
 {
     if ( nType == STATE_CHANGE_INITSHOW )
     {
         ImplPosControls();
 
-        // Focus evt. auf den entsprechenden Button setzen
+        // Set focus on default button.
         if ( mnFocusButtonId != BUTTONDIALOG_BUTTON_NOTFOUND )
         {
-            for ( size_t i = 0, n = mpItemList->size(); i < n; ++i )
+            for ( btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
             {
-                ImplBtnDlgItem* pItem = (*mpItemList)[ i ];
-                if ( pItem->mnId == mnFocusButtonId )
+                if (it->mnId == mnFocusButtonId )
                 {
-                    if ( pItem->mpPushButton->IsVisible() )
-                        pItem->mpPushButton->GrabFocus();
+                    if (it->mpPushButton->IsVisible())
+                        it->mpPushButton->GrabFocus();
+
                     break;
                 }
             }
@@ -300,8 +270,6 @@ void ButtonDialog::StateChanged( StateChangedType nType )
     Dialog::StateChanged( nType );
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::Click()
 {
     if ( !maClickHdl )
@@ -313,8 +281,6 @@ void ButtonDialog::Click()
         maClickHdl.Call( this );
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::AddButton( const XubString& rText, USHORT nId,
                               USHORT nBtnFlags, long nSepPixel )
 {
@@ -324,11 +290,11 @@ void ButtonDialog::AddButton( const XubString& rText, USHORT nId,
     pItem->mbOwnButton		= TRUE;
     pItem->mnSepSize		= nSepPixel;
     pItem->mpPushButton 	= ImplCreatePushButton( nBtnFlags );
+
     if ( rText.Len() )
         pItem->mpPushButton->SetText( rText );
 
-    // In die Liste eintragen
-    mpItemList->push_back( pItem );
+    maItemList.push_back(pItem);
 
     if ( nBtnFlags & BUTTONDIALOG_FOCUSBUTTON )
         mnFocusButtonId = nId;
@@ -336,8 +302,6 @@ void ButtonDialog::AddButton( const XubString& rText, USHORT nId,
     mbFormat = TRUE;
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::AddButton( StandardButtonType eType, USHORT nId,
                               USHORT nBtnFlags, long nSepPixel )
 {
@@ -367,14 +331,11 @@ void ButtonDialog::AddButton( StandardButtonType eType, USHORT nId,
     if ( nBtnFlags & BUTTONDIALOG_FOCUSBUTTON )
         mnFocusButtonId = nId;
 
-    // In die Liste eintragen
-    mpItemList->push_back( pItem );
+    maItemList.push_back(pItem);
 
     mbFormat = TRUE;
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::AddButton( PushButton* pBtn, USHORT nId,
                               USHORT nBtnFlags, long nSepPixel )
 {
@@ -388,71 +349,60 @@ void ButtonDialog::AddButton( PushButton* pBtn, USHORT nId,
     if ( nBtnFlags & BUTTONDIALOG_FOCUSBUTTON )
         mnFocusButtonId = nId;
 
-    // In die View-Liste eintragen
-    mpItemList->push_back( pItem );
+    maItemList.push_back(pItem);
 
     mbFormat = TRUE;
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::RemoveButton( USHORT nId )
 {
-    for ( ImplBtnDlgItemList::iterator it = mpItemList->begin();
-          it < mpItemList->end();
-          ++it
-    ) {
-        if ( (*it)->mnId == nId ) {
-            (*it)->mpPushButton->Hide();
-            if ( (*it)->mbOwnButton ) {
-                delete (*it)->mpPushButton;
-            }
-            delete *it;
-            mpItemList->erase( it );
+    btn_iterator it;
+    for (it = maItemList.begin(); it != maItemList.end(); ++it)
+    {
+        if (it->mnId == nId)
+        {
+            it->mpPushButton->Hide();
+
+            if (it->mbOwnButton )
+                delete it->mpPushButton;
+
+            maItemList.erase(it);
             mbFormat = TRUE;
             break;
         }
     }
 
-    DBG_ERRORFILE( "ButtonDialog::RemoveButton(): ButtonId invalid" );
+    if (it == maItemList.end())
+        DBG_ERRORFILE( "ButtonDialog::RemoveButton(): ButtonId invalid" );
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::Clear()
 {
-    for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
-        ImplBtnDlgItem* pItem = (*mpItemList)[ i ];
-        pItem->mpPushButton->Hide();
-        if ( pItem->mbOwnButton ) {
-            delete pItem->mpPushButton;
-        }
-        delete pItem;
+    for (btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it)
+    {
+        it->mpPushButton->Hide();
+
+        if (it->mbOwnButton )
+            delete it->mpPushButton;
     }
-    mpItemList->clear();
 
+    maItemList.clear();
     mbFormat = TRUE;
 }
 
-// -----------------------------------------------------------------------
-
 USHORT ButtonDialog::GetButtonCount() const
 {
-    return (USHORT)mpItemList->size();
+    return (USHORT)maItemList.size();
 }
 
-// -----------------------------------------------------------------------
-
 USHORT ButtonDialog::GetButtonId( USHORT nButton ) const
 {
-    if ( nButton < mpItemList->size() )
-        return (USHORT)( (*mpItemList)[ nButton ]->mnId );
+    if ( nButton < maItemList.size() )
+        return maItemList[nButton].mnId;
     else
         return BUTTONDIALOG_BUTTON_NOTFOUND;
 }
 
-// -----------------------------------------------------------------------
-
 PushButton* ButtonDialog::GetPushButton( USHORT nId ) const
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );
@@ -463,8 +413,6 @@ PushButton* ButtonDialog::GetPushButton( USHORT nId ) const
         return NULL;
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::SetButtonText( USHORT nId, const XubString& rText )
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );
@@ -476,8 +424,6 @@ void ButtonDialog::SetButtonText( USHORT nId, const XubString& rText )
     }
 }
 
-// -----------------------------------------------------------------------
-
 XubString ButtonDialog::GetButtonText( USHORT nId ) const
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );
@@ -488,8 +434,6 @@ XubString ButtonDialog::GetButtonText( USHORT nId ) const
         return ImplGetSVEmptyStr();
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::SetButtonHelpText( USHORT nId, const XubString& rText )
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );
@@ -498,8 +442,6 @@ void ButtonDialog::SetButtonHelpText( USHORT nId, const XubString& rText )
         pItem->mpPushButton->SetHelpText( rText );
 }
 
-// -----------------------------------------------------------------------
-
 XubString ButtonDialog::GetButtonHelpText( USHORT nId ) const
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );
@@ -510,8 +452,6 @@ XubString ButtonDialog::GetButtonHelpText( USHORT nId ) const
         return ImplGetSVEmptyStr();
 }
 
-// -----------------------------------------------------------------------
-
 void ButtonDialog::SetButtonHelpId( USHORT nId, ULONG nHelpId )
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );
@@ -520,8 +460,6 @@ void ButtonDialog::SetButtonHelpId( USHORT nId, ULONG nHelpId )
         pItem->mpPushButton->SetHelpId( nHelpId );
 }
 
-// -----------------------------------------------------------------------
-
 ULONG ButtonDialog::GetButtonHelpId( USHORT nId ) const
 {
     ImplBtnDlgItem* pItem = ImplGetItem( nId );


More information about the Libreoffice-commits mailing list