[Libreoffice-commits] .: sw/source

Michael Meeks michael at kemper.freedesktop.org
Tue May 10 06:05:41 PDT 2011


 sw/source/ui/inc/swuicnttab.hxx |   37 ++---
 sw/source/ui/index/cnttab.cxx   |  293 +++++++++++++++++++++-------------------
 2 files changed, 179 insertions(+), 151 deletions(-)

New commits:
commit 0553f4b6b2d5871524b0826512b5217f95e0a67d
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Tue May 10 14:02:26 2011 +0100

    revert commit 5d8a59f64d9d3931e2c9c1ba98f57cd10e0b01c1, fix fdo#36340
    
    old commit: 'Convert std::vector to boost::ptr_vector.'
    this conflated the destruction and removal from list stages which
    have to be separate, so we do not re-enterancy from control
    destructors.

diff --git a/sw/source/ui/inc/swuicnttab.hxx b/sw/source/ui/inc/swuicnttab.hxx
index 9108936..3526989 100644
--- a/sw/source/ui/inc/swuicnttab.hxx
+++ b/sw/source/ui/inc/swuicnttab.hxx
@@ -28,25 +28,27 @@
 #ifndef _SWUI_CNTTAB_HXX
 #define _SWUI_CNTTAB_HXX
 
-#include <boost/ptr_container/ptr_vector.hpp>
-
-#include <tools/resary.hxx>
-#include <sfx2/tabdlg.hxx>
-#include <svtools/svtreebx.hxx>
-#include <svx/checklbx.hxx>
-#include <svx/langbox.hxx>
 #include <svx/stddlg.hxx>
+
 #include <vcl/button.hxx>
+
 #include <vcl/edit.hxx>
-#include <vcl/field.hxx>
+
 #include <vcl/fixed.hxx>
-#include <vcl/lstbox.hxx>
-#include <vcl/menubtn.hxx>
 
-#include <cnttab.hxx>
-#include <toxmgr.hxx>
+#include <vcl/field.hxx>
+#include <vcl/lstbox.hxx>
+#include <sfx2/tabdlg.hxx>
 
 #include "tox.hxx"
+#include <toxmgr.hxx>
+#include <svx/checklbx.hxx>
+#include <tools/resary.hxx>
+#include <svtools/svtreebx.hxx>
+#include <vcl/menubtn.hxx>
+#include <svx/langbox.hxx>
+#include <cnttab.hxx>
+#include <vector>
 
 class SwWrtShell;
 class SwTOXMgr;
@@ -259,16 +261,15 @@ class SwTOXEntryTabPage;
 
 class SwTokenWindow : public Window
 {
-    typedef boost::ptr_vector<Control> TOXControlList;
-    typedef TOXControlList::iterator ctrl_iterator;
-    typedef TOXControlList::const_iterator ctrl_const_iterator;
-    typedef TOXControlList::reverse_iterator ctrl_reverse_iterator;
-    typedef TOXControlList::const_reverse_iterator ctrl_const_reverse_iterator;
+    typedef std::vector<Control*>::iterator ctrl_iterator;
+    typedef std::vector<Control*>::const_iterator ctrl_const_iterator;
+    typedef std::vector<Control*>::reverse_iterator ctrl_reverse_iterator;
+    typedef std::vector<Control*>::const_reverse_iterator ctrl_const_reverse_iterator;
 
     ImageButton 	aLeftScrollWin;
     Window			aCtrlParentWin;
     ImageButton 	aRightScrollWin;
-    TOXControlList	aControlList;
+    std::vector<Control*> 	aControlList;
     SwForm* 		pForm;
     sal_uInt16 			nLevel;
     sal_Bool			bValid;
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index 5d2af67..29dc30e 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -111,17 +111,6 @@ static const sal_Unicode aDeliEnd	 = ']'; //fuer die form
 #define IDX_FILE_EXTENSION String::CreateFromAscii( \
                             RTL_CONSTASCII_STRINGPARAM( "*.sdi" ))
 
-static boost::ptr_vector<Control>::iterator FindControl (boost::ptr_vector<Control> &list, Control *ctrl)
-{
-    for (boost::ptr_vector<Control>::iterator it = list.begin(); it != list.end(); ++it)
-    {
-        if ((&(*it)) == ctrl)
-            return it;
-    }
-
-    return list.end();
-}
-
 String lcl_CreateAutoMarkFileDlg( const String& rURL,
                                 const String& rFileString, sal_Bool bOpen )
 {
@@ -2877,6 +2866,13 @@ SwTokenWindow::SwTokenWindow(SwTOXEntryTabPage* pParent, const ResId& rResId) :
 
 SwTokenWindow::~SwTokenWindow()
 {
+    for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
+    {
+        Control* pControl = (*it);
+        pControl->SetGetFocusHdl( Link() );
+        pControl->SetLoseFocusHdl( Link() );
+        delete pControl;
+    }
 }
 
 void	SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
@@ -2884,9 +2880,14 @@ void	SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
     SetActiveControl(0);
     bValid = sal_True;
 
-    //apply current level settings to the form
     if(pForm)
+    {
+        //apply current level settings to the form
+        for (ctrl_iterator iter = aControlList.begin(); iter != aControlList.end(); ++iter)
+            delete (*iter);
+
         aControlList.clear();
+    }
 
     nLevel = nL;
     pForm = &rForm;
@@ -2984,17 +2985,17 @@ Control*	SwTokenWindow::InsertItem(const String& rText, const SwFormToken& rToke
     Point aControlPos;
 
     if(!aControlList.empty())
-     {
-        ctrl_const_reverse_iterator iterLast = aControlList.rbegin();
+    {
+        Control* pLast = *(aControlList.rbegin());
 
-        aControlSize = iterLast->GetSizePixel();
-        aControlPos = iterLast->GetPosPixel();
+        aControlSize = pLast->GetSizePixel();
+        aControlPos = pLast->GetPosPixel();
         aControlPos.X() += aControlSize.Width();
     }
 
     if(TOKEN_TEXT == rToken.eTokenType)
     {
-        SwTOXEdit *pEdit = new SwTOXEdit(&aCtrlParentWin, this, rToken);
+        SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, rToken);
         pEdit->SetPosPixel(aControlPos);
 
         aControlList.push_back(pEdit);
@@ -3061,73 +3062,71 @@ void	SwTokenWindow::InsertAtSelection(
         //<insert> LS
         //<insert> LE
         //<insert>
-        bool bPreStartLinkFound = false;
-        bool bPreEndLinkFound = false;
+        sal_Bool bPreStartLinkFound = sal_False;
+        sal_Bool bPreEndLinkFound = sal_False;
 
-        const Control *pExchange = 0;
-        ctrl_const_iterator it = aControlList.begin();
+        const Control* pControl = 0;
+        const Control* pExchange = 0;
 
-        while ( it != aControlList.end())
+        ctrl_const_iterator it = aControlList.begin();
+        for( ; it != aControlList.end() && pActiveCtrl != (*it); ++it )
         {
-            if ((&(*it)) == pActiveCtrl)
-                break;
+            pControl = *it;
 
-            if( WINDOW_EDIT != it->GetType())
+            if( WINDOW_EDIT != pControl->GetType())
             {
                 const SwFormToken& rNewToken =
-                                (reinterpret_cast<const SwTOXButton&>(*it)).GetFormToken();
+                                ((SwTOXButton*)pControl)->GetFormToken();
 
                 if( TOKEN_LINK_START == rNewToken.eTokenType )
                 {
-                    bPreStartLinkFound = true;
+                    bPreStartLinkFound = sal_True;
                     pExchange = 0;
                 }
                 else if(TOKEN_LINK_END == rNewToken.eTokenType)
                 {
                     if( bPreStartLinkFound )
-                        bPreStartLinkFound = false;
+                        bPreStartLinkFound = sal_False;
                     else
                     {
-                        bPreEndLinkFound = false;
-                        pExchange = const_cast<Control*>(&(*it));
+                        bPreEndLinkFound = sal_False;
+                        pExchange = pControl;
                     }
                 }
             }
-
-            ++it;
         }
 
         bool bPostLinkStartFound = false;
 
         if(!bPreStartLinkFound && !bPreEndLinkFound)
         {
-            while(it != aControlList.end())
+            for( ; it != aControlList.end(); ++it )
             {
-                if( (&(*it)) != pActiveCtrl &&
-                    WINDOW_EDIT != it->GetType())
+                pControl = *it;
+
+                if( pControl != pActiveCtrl &&
+                    WINDOW_EDIT != pControl->GetType())
                 {
                     const SwFormToken& rNewToken =
-                                    reinterpret_cast<const SwTOXButton&>(*it).GetFormToken();
+                                    ((SwTOXButton*)pControl)->GetFormToken();
 
                     if( TOKEN_LINK_START == rNewToken.eTokenType )
                     {
                         if(bPostLinkStartFound)
                             break;
-                        bPostLinkStartFound = true;
-                        pExchange = const_cast<Control*>(&(*it));
+                        bPostLinkStartFound = sal_True;
+                        pExchange = pControl;
                     }
                     else if(TOKEN_LINK_END == rNewToken.eTokenType )
                     {
                         if(bPostLinkStartFound)
                         {
-                            bPostLinkStartFound = false;
+                            bPostLinkStartFound = sal_False;
                             pExchange = 0;
                         }
                         break;
                     }
                 }
-
-                ++it;
             }
         }
 
@@ -3140,7 +3139,6 @@ void	SwTokenWindow::InsertAtSelection(
         if(bPostLinkStartFound)
         {
             OSL_ENSURE(pExchange, "no control to exchange?");
-
             if(pExchange)
             {
                 ((SwTOXButton*)pExchange)->SetLinkEnd();
@@ -3162,7 +3160,9 @@ void	SwTokenWindow::InsertAtSelection(
 
     //if the active control is text then insert a new button at the selection
     //else replace the button
-    ctrl_iterator iterActive = FindControl(aControlList,pActiveCtrl);
+    ctrl_iterator iterActive = std::find(aControlList.begin(),
+                                         aControlList.end(), pActiveCtrl);
+
     ctrl_iterator iterInsert = iterActive;
 
     Size aControlSize(GetOutputSizePixel());
@@ -3185,7 +3185,7 @@ void	SwTokenWindow::InsertAtSelection(
         SwFormToken aTmpToken(TOKEN_TEXT);
         SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, aTmpToken);
 
-        aControlList.insert(iterInsert,pEdit);
+        aControlList.insert(iterInsert, pEdit);
 
         pEdit->SetText(sRight);
         pEdit->SetSizePixel(aControlSize);
@@ -3197,13 +3197,15 @@ void	SwTokenWindow::InsertAtSelection(
     }
     else
     {
-        pActiveCtrl->Hide();
         aControlList.erase(iterActive);
+        pActiveCtrl->Hide();
+        delete pActiveCtrl;
     }
 
     //now the new button
     SwTOXButton* pButton = new SwTOXButton(&aCtrlParentWin, this, aToInsertToken);
-    aControlList.insert(iterInsert,pButton);
+
+    aControlList.insert(iterInsert, pButton);
 
     pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
     pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
@@ -3235,7 +3237,7 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall )
     if(bInternalCall && TOX_AUTHORITIES == pForm->GetTOXType())
         m_pParent->PreTokenButtonRemoved(pDel->GetFormToken());
 
-    ctrl_iterator it = FindControl(aControlList,pDel);
+    ctrl_iterator it = std::find(aControlList.begin(), aControlList.end(), pDel);
 
     OSL_ENSURE(it != aControlList.end(), "Control does not exist!");
 
@@ -3244,22 +3246,26 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall )
     OSL_ENSURE(it != aControlList.begin() && it != aControlList.end() - 1,
         "Button at first or last position?");
 
-    Control *pLeftCtrl = const_cast<Control*>(&(*(it-1)));
-    Control *pRightCtrl = const_cast<Control*>(&(*(it+1)));
+    ctrl_iterator itLeft = it, itRight = it;
+    --itLeft;
+    ++itRight;
+    Control *pLeftEdit = *itLeft;
+    Control *pRightEdit = *itRight;
 
-    String sTemp(((SwTOXEdit*)pLeftCtrl)->GetText());
-    sTemp += ((SwTOXEdit*)pRightCtrl)->GetText();
-    ((SwTOXEdit*)pLeftCtrl)->SetText(sTemp);
-    ((SwTOXEdit*)pLeftCtrl)->AdjustSize();
+    String sTemp(((SwTOXEdit*)pLeftEdit)->GetText());
+    sTemp += ((SwTOXEdit*)pRightEdit)->GetText();
+    ((SwTOXEdit*)pLeftEdit)->SetText(sTemp);
+    ((SwTOXEdit*)pLeftEdit)->AdjustSize();
 
-    aControlList.erase(it+1);
-    aControlList.erase(it);
+    aControlList.erase(itRight);
+    delete pRightEdit;
 
+    aControlList.erase(it);
     pActiveCtrl->Hide();
+    delete pActiveCtrl;
 
-    SetActiveControl(pLeftCtrl);
+    SetActiveControl(pLeftEdit);
     AdjustPositions();
-
     if(aModifyHdl.IsSet())
         aModifyHdl.Call(0);
 }
@@ -3269,14 +3275,17 @@ void SwTokenWindow::AdjustPositions()
     if(aControlList.size() > 1)
     {
         ctrl_iterator it = aControlList.begin();
+        Control* pCtrl = *it;
+        ++it;
 
-        Point aNextPos = it->GetPosPixel();
-        aNextPos.X() += it->GetSizePixel().Width();
+        Point aNextPos = pCtrl->GetPosPixel();
+        aNextPos.X() += pCtrl->GetSizePixel().Width();
 
-        for (++it; it != aControlList.end(); ++it)
-         {
-            it->SetPosPixel(aNextPos);
-            aNextPos.X() += it->GetSizePixel().Width();
+        for(; it != aControlList.end(); ++it)
+        {
+            pCtrl = *it;
+            pCtrl->SetPosPixel(aNextPos);
+            aNextPos.X() += pCtrl->GetSizePixel().Width();
         }
 
         AdjustScrolling();
@@ -3288,10 +3297,12 @@ void SwTokenWindow::MoveControls(long nOffset)
     // move the complete list
     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
     {
-        Point aPos = it->GetPosPixel();
+        Control *pCtrl = *it;
+
+        Point aPos = pCtrl->GetPosPixel();
         aPos.X() += nOffset;
 
-        it->SetPosPixel(aPos);
+        pCtrl->SetPosPixel(aPos);
     }
 }
 
@@ -3300,19 +3311,21 @@ void SwTokenWindow::AdjustScrolling()
     if(aControlList.size() > 1)
     {
         //validate scroll buttons
-        ctrl_const_reverse_iterator iterLast = aControlList.rbegin();
-        ctrl_const_iterator iterFirst = aControlList.begin();
+        Control* pFirstCtrl = *(aControlList.begin());
+        Control* pLastCtrl = *(aControlList.rbegin());
 
         long nSpace = aCtrlParentWin.GetSizePixel().Width();
-        long nWidth = iterLast->GetPosPixel().X() - iterFirst->GetPosPixel().X()
-                                                    + iterLast->GetSizePixel().Width();
+        long nWidth = pLastCtrl->GetPosPixel().X() - pFirstCtrl->GetPosPixel().X()
+                                                    + pLastCtrl->GetSizePixel().Width();
         bool bEnable = nWidth > nSpace;
+
         //the active control must be visible
         if(bEnable && pActiveCtrl)
         {
-            long nMove = 0;
             Point aActivePos(pActiveCtrl->GetPosPixel());
 
+            long nMove = 0;
+
             if(aActivePos.X() < 0)
                 nMove = -aActivePos.X();
             else if((aActivePos.X() + pActiveCtrl->GetSizePixel().Width())  > nSpace)
@@ -3321,16 +3334,20 @@ void SwTokenWindow::AdjustScrolling()
             if(nMove)
                 MoveControls(nMove);
 
-            aLeftScrollWin.Enable(iterFirst->GetPosPixel().X() < 0);
-            aRightScrollWin.Enable((iterLast->GetPosPixel().X() + iterLast->GetSizePixel().Width()) > nSpace);
+            aLeftScrollWin.Enable(pFirstCtrl->GetPosPixel().X() < 0);
+
+            aRightScrollWin.Enable((pLastCtrl->GetPosPixel().X() + pLastCtrl->GetSizePixel().Width()) > nSpace);
         }
         else
         {
-            //if the control fits into the space then the first control must be at postion 0
-            long nFirstPos = iterFirst->GetPosPixel().X();
+            if(pFirstCtrl)
+            {
+                //if the control fits into the space then the first control must be at postion 0
+                long nFirstPos = pFirstCtrl->GetPosPixel().X();
 
-            if(nFirstPos != 0)
-                MoveControls(-nFirstPos);
+                if(nFirstPos != 0)
+                    MoveControls(-nFirstPos);
+            }
 
             aRightScrollWin.Enable(false);
             aLeftScrollWin.Enable(false);
@@ -3344,7 +3361,6 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
         return 0;
 
     const long nSpace = aCtrlParentWin.GetSizePixel().Width();
-
 #if OSL_DEBUG_LEVEL > 1
     //find all start/end positions and print it
     String sMessage(String::CreateFromAscii("Space: "));
@@ -3353,8 +3369,10 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
 
     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
     {
-        long nDebugXPos = it->GetPosPixel().X();
-        long nDebugWidth = it->GetSizePixel().Width();
+        Control *pDebugCtrl = *it;
+
+        long nDebugXPos = pDebugCtrl->GetPosPixel().X();
+        long nDebugWidth = pDebugCtrl->GetSizePixel().Width();
 
         sMessage += String::CreateFromInt32( nDebugXPos );
         sMessage += String::CreateFromAscii(" ");
@@ -3370,11 +3388,13 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
         //find the first completely visible control (left edge visible)
         for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
         {
-            long nXPos = it->GetPosPixel().X();
+            Control *pCtrl = *it;
+
+            long nXPos = pCtrl->GetPosPixel().X();
 
             if (nXPos >= 0)
             {
-                if(it == aControlList.begin())
+                if (it == aControlList.begin())
                 {
                     //move the current control to the left edge
                     nMove = -nXPos;
@@ -3382,8 +3402,11 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
                 else
                 {
                     //move the left neighbor to the start position
-                    ctrl_iterator iterLeft = it-1;
-                    nMove = -iterLeft->GetPosPixel().X();
+                    ctrl_iterator itLeft = it;
+                    --itLeft;
+                    Control *pLeft = *itLeft;
+
+                    nMove = -pLeft->GetPosPixel().X();
                 }
 
                 break;
@@ -3395,16 +3418,20 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
         //find the first completely visible control (right edge visible)
         for (ctrl_reverse_iterator it = aControlList.rbegin(); it != aControlList.rend(); ++it)
         {
-            long nCtrlWidth = it->GetSizePixel().Width();
-            long nXPos = it->GetPosPixel().X() + nCtrlWidth;
+            Control *pCtrl = *it;
+
+            long nCtrlWidth = pCtrl->GetSizePixel().Width();
+            long nXPos = pCtrl->GetPosPixel().X() + nCtrlWidth;
 
             if (nXPos <= nSpace)
             {
                 if (it != aControlList.rbegin())
                 {
                     //move the right neighbor  to the right edge right aligned
-                    ctrl_reverse_iterator iterRight = it-1;
-                    nMove = nSpace - iterRight->GetPosPixel().X() - iterRight->GetSizePixel().Width();
+                    ctrl_reverse_iterator itRight = it;
+                    --it;
+                    Control *pRight = *itRight;
+                    nMove = nSpace - pRight->GetPosPixel().X() - pRight->GetSizePixel().Width();
                 }
 
                 break;
@@ -3417,20 +3444,23 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
     if(nMove)
     {
         // move the complete list
+
+        Control *pCtrl = 0;
+
         for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
         {
-            Point aPos = it->GetPosPixel();
+            pCtrl = *it;
 
+            Point aPos = pCtrl->GetPosPixel();
             aPos.X() += nMove;
-
-            it->SetPosPixel(aPos);
+            pCtrl->SetPosPixel(aPos);
         }
 
-        ctrl_iterator iterCtrl = aControlList.begin();
-        aLeftScrollWin.Enable(iterCtrl->GetPosPixel().X() < 0);
+        pCtrl = *(aControlList.begin());
+        aLeftScrollWin.Enable(pCtrl->GetPosPixel().X() < 0);
 
-        iterCtrl = aControlList.end()-1;
-        aRightScrollWin.Enable((iterCtrl->GetPosPixel().X() + iterCtrl->GetSizePixel().Width()) > nSpace);
+        pCtrl = *(aControlList.rbegin());
+        aRightScrollWin.Enable((pCtrl->GetPosPixel().X() + pCtrl->GetSizePixel().Width()) > nSpace);
 
 #if OSL_DEBUG_LEVEL > 1
         sMessage.AppendAscii("Move: ");
@@ -3445,14 +3475,14 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
 String	SwTokenWindow::GetPattern() const
 {
     String sRet;
-    const Control *ctrl = 0;
+
     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
     {
-        ctrl = &(*it);
+        const Control *pCtrl = *it;
 
-        const SwFormToken& rNewToken = WINDOW_EDIT == ctrl->GetType()
-                    ? ((SwTOXEdit*)ctrl)->GetFormToken()
-                    : ((SwTOXButton*)ctrl)->GetFormToken();
+        const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT
+                ? ((SwTOXEdit*)pCtrl)->GetFormToken()
+                : ((SwTOXButton*)pCtrl)->GetFormToken();
 
         //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput
         sRet += rNewToken.GetString();
@@ -3467,15 +3497,14 @@ String	SwTokenWindow::GetPattern() const
 sal_Bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
 {
     bool bRet = false;
-    const Control* pControl = 0;
 
     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
     {
-        pControl = &(*it);
+        const Control *pCtrl = *it;
 
-        const SwFormToken& rNewToken = WINDOW_EDIT == pControl->GetType()
-                    ? ((SwTOXEdit*)pControl)->GetFormToken()
-                    : ((SwTOXButton*)pControl)->GetFormToken();
+        const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT
+                ? ((SwTOXEdit*)pCtrl)->GetFormToken()
+                : ((SwTOXButton*)pCtrl)->GetFormToken();
 
         if (eSearchFor == rNewToken.eTokenType)
         {
@@ -3561,24 +3590,22 @@ IMPL_LINK(SwTokenWindow, EditResize, Edit*, pEdit)
 
 IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit*,  pEdit)
 {
-    ctrl_iterator it = FindControl(aControlList,pEdit);
+    ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pEdit);
 
     if (it == aControlList.end())
         return 0;
 
-    ctrl_iterator lastIter = aControlList.end()-1;
+    ctrl_iterator itTest = it;
+    ++itTest;
 
     if ((it != aControlList.begin() && !pEdit->IsNextControl()) ||
-        (it != lastIter && pEdit->IsNextControl()))
+        (itTest != aControlList.end() && pEdit->IsNextControl()))
     {
         ctrl_iterator iterFocus = it;
-
         pEdit->IsNextControl() ? ++iterFocus : --iterFocus;
 
-        Control *pCtrlFocus = &(*iterFocus);
-
+        Control *pCtrlFocus = *iterFocus;
         pCtrlFocus->GrabFocus();
-
         reinterpret_cast<SwTOXButton*>(pCtrlFocus)->Check();
 
         AdjustScrolling();
@@ -3591,7 +3618,7 @@ IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit)
 {
     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
     {
-        Control *pCtrl = &(*it);
+        Control *pCtrl = *it;
 
         if (pCtrl && pCtrl->GetType() != WINDOW_EDIT)
             reinterpret_cast<SwTOXButton*>(pCtrl)->Check(false);
@@ -3604,31 +3631,29 @@ IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit)
 
 IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn )
 {
-    ctrl_iterator iter = FindControl(aControlList,pBtn);
+    ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pBtn);
 
-    if (iter == aControlList.end())
+    if (it == aControlList.end())
         return 0;
 
-    ctrl_iterator lastIter = aControlList.end()-1;
+    ctrl_iterator itTest = it;
+    ++itTest;
 
-    if((iter != aControlList.begin() && !pBtn->IsNextControl()) ||
-       (iter != lastIter && pBtn->IsNextControl()))
+    if (!pBtn->IsNextControl() || (itTest != aControlList.end() && pBtn->IsNextControl()))
     {
-        bool bNext = pBtn->IsNextControl();
-
-        ctrl_iterator iterFocus = iter;
+        bool isNext = pBtn->IsNextControl();
 
-        bNext ? ++iterFocus : --iterFocus;
-
-        Control *pCtrlFocus = &(*iterFocus);
+        ctrl_iterator iterFocus = it;
+        isNext ? ++iterFocus : --iterFocus;
 
+        Control *pCtrlFocus = *iterFocus;
         pCtrlFocus->GrabFocus();
-
         Selection aSel(0,0);
 
-        if(!bNext)
+        if (!isNext)
         {
-            sal_uInt16 nLen = ((SwTOXEdit*)pCtrlFocus)->GetText().Len();
+            sal_uInt16 nLen = reinterpret_cast<SwTOXEdit*>(pCtrlFocus)->GetText().Len();
+
             aSel.A() = nLen;
             aSel.B() = nLen;
         }
@@ -3645,10 +3670,9 @@ IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn )
 
 IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXButton*, pBtn )
 {
-    Control *pControl = 0;
-    for (ctrl_iterator sit = aControlList.begin(); sit != aControlList.end(); ++sit)
+    for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
     {
-        pControl = &(*sit);
+        Control *pControl = *it;
 
         if (pControl && WINDOW_EDIT != pControl->GetType())
             reinterpret_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl);
@@ -3665,11 +3689,14 @@ void SwTokenWindow::GetFocus()
     {
         if (!aControlList.empty())
         {
-            Control *pFirst = &(*aControlList.begin());
+            Control *pFirst = *aControlList.begin();
 
-            pFirst->GrabFocus();
-            SetActiveControl(pFirst);
-            AdjustScrolling();
+            if (pFirst)
+            {
+                pFirst->GrabFocus();
+                SetActiveControl(pFirst);
+                AdjustScrolling();
+            }
         }
     }
 }


More information about the Libreoffice-commits mailing list