[Libreoffice-commits] .: sw/source

Joseph Powers jpowers at kemper.freedesktop.org
Wed Dec 15 06:29:43 PST 2010


 sw/source/ui/inc/swuicnttab.hxx |    6 
 sw/source/ui/index/cnttab.cxx   |  273 +++++++++++++++++++---------------------
 2 files changed, 133 insertions(+), 146 deletions(-)

New commits:
commit e6def92fb2a578bbfc162585985c5454576cb921
Author: Joseph Powers <jpowers27 at cox.net>
Date:   Wed Dec 15 06:20:55 2010 -0800

    Revert DECLARE_LIST(TOXControlList, Control*)
    
    This will remove the segfault I caused in:
    Writer -> Insert -> Indexes and Tables -> Indexes and Tables -> Entries

diff --git a/sw/source/ui/inc/swuicnttab.hxx b/sw/source/ui/inc/swuicnttab.hxx
index 7c90534..497a9c2 100644
--- a/sw/source/ui/inc/swuicnttab.hxx
+++ b/sw/source/ui/inc/swuicnttab.hxx
@@ -49,8 +49,6 @@
 #include <vcl/menubtn.hxx>
 #include <svx/langbox.hxx>
 #include <cnttab.hxx>
-#include <list>
-
 class SwWrtShell;
 class SwTOXMgr;
 namespace com{namespace sun{namespace star{
@@ -233,7 +231,7 @@ class SwTOXSelectTabPage : public SfxTabPage
     DECL_LINK(RadioButtonHdl, RadioButton* );
     DECL_LINK(ModifyHdl, void*);
 
-    void	ApplyTOXDescription();
+      void	ApplyTOXDescription();
     void 	FillTOXDescription();
 
     using SfxTabPage::ActivatePage;
@@ -256,7 +254,7 @@ public:
     void				SetWrtShell(SwWrtShell& rSh);
 };
 
-typedef ::std::list< Control* > TOXControlList;
+DECLARE_LIST(TOXControlList, Control*)
 
 class SwTOXEdit;
 class SwTOXButton;
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index fbd65bb..24bd655 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -2833,16 +2833,19 @@ SwTokenWindow::SwTokenWindow(SwTOXEntryTabPage* pParent, const ResId& rResId) :
 
 SwTokenWindow::~SwTokenWindow()
 {
-    for ( TOXControlList::iterator i = aControlList.begin(); i != aControlList.end(); ++i )
+
+    for( sal_uInt32 n = 0; n < aControlList.Count(); ++n )
     {
-        Control* pControl = *i;
+        Control* pControl = aControlList.GetObject( n );
         pControl->SetGetFocusHdl( Link() );
         pControl->SetLoseFocusHdl( Link() );
     }
 
-    for ( TOXControlList::iterator i = aControlList.begin(); i != aControlList.end(); ++i )
-        delete *i;
-    aControlList.clear();
+    for( ULONG i = aControlList.Count(); i; )
+    {
+        Control* pControl = aControlList.Remove( --i );
+        delete pControl;
+    }
 }
 
 void	SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
@@ -2851,9 +2854,12 @@ void	SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
     bValid = sal_True;
     if(pForm)
     {
-        for ( TOXControlList::iterator i = aControlList.begin(); i != aControlList.end(); ++i )
-            delete *i;
-        aControlList.clear();
+        //apply current level settings to the form
+        for( ULONG i = aControlList.Count(); i; )
+        {
+            Control* pControl = aControlList.Remove( --i );
+            delete pControl;
+        }
     }
     nLevel = nL;
     pForm = &rForm;
@@ -2949,7 +2955,7 @@ void SwTokenWindow::SetActiveControl(Control* pSet)
 Control*	SwTokenWindow::InsertItem(const String& rText, const SwFormToken& rToken)
 {
     Control* pRet = 0;
-    Control* pLast = aControlList.back();
+    Control* pLast = aControlList.Last();
     Size aControlSize(GetOutputSizePixel());
      Point aControlPos;
     if( pLast )
@@ -2962,9 +2968,9 @@ Control*	SwTokenWindow::InsertItem(const String& rText, const SwFormToken& rToke
     {
         SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, rToken);
         pEdit->SetPosPixel(aControlPos);
-        aControlList.push_back( pEdit );
+        aControlList.Insert(pEdit, aControlList.Count());
         pEdit->SetText(rText);
-        Size aEditSize(aControlSize);
+         Size aEditSize(aControlSize);
         aEditSize.Width() = pEdit->GetTextWidth(rText) + EDIT_MINWIDTH;
         pEdit->SetSizePixel(aEditSize);
         pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
@@ -2977,8 +2983,8 @@ Control*	SwTokenWindow::InsertItem(const String& rText, const SwFormToken& rToke
     {
         SwTOXButton* pButton = new SwTOXButton(&aCtrlParentWin, this, rToken);
         pButton->SetPosPixel(aControlPos);
-        aControlList.push_back( pButton );
-        Size aEditSize(aControlSize);
+        aControlList.Insert(pButton, aControlList.Count());
+         Size aEditSize(aControlSize);
         aEditSize.Width() = pButton->GetTextWidth(rText) + 5;
         pButton->SetSizePixel(aEditSize);
         pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
@@ -3020,13 +3026,9 @@ void	SwTokenWindow::InsertAtSelection(
         sal_Bool bPreStartLinkFound = sal_False; //
         sal_Bool bPreEndLinkFound = sal_False;
 
-        const Control* pExchange = NULL;
-        const Control* pControl  = NULL;
-
-        TOXControlList::iterator it = aControlList.begin();
-        while (  ( it != aControlList.end() )
-              && ( (pControl = *it) != pActiveCtrl )
-              )
+        const Control* pControl = aControlList.First();
+        const Control* pExchange = 0;
+        while( pControl && pActiveCtrl != pControl )
         {
             if( WINDOW_EDIT != pControl->GetType())
             {
@@ -3048,15 +3050,14 @@ void	SwTokenWindow::InsertAtSelection(
                     }
                 }
             }
-            ++it;
+            pControl = aControlList.Next();
         }
 
         sal_Bool bPostLinkEndFound = sal_False;
         sal_Bool bPostLinkStartFound = sal_False;
         if(!bPreStartLinkFound && !bPreEndLinkFound)
-            while( it != aControlList.end() )
+            while(pControl)
             {
-                pControl = *it;
                 if( pControl != pActiveCtrl &&
                     WINDOW_EDIT != pControl->GetType())
                 {
@@ -3083,7 +3084,7 @@ void	SwTokenWindow::InsertAtSelection(
                         break;
                     }
                 }
-                ++it;
+                pControl = aControlList.Next();
             }
 
         if(bPreStartLinkFound)
@@ -3115,13 +3116,14 @@ void	SwTokenWindow::InsertAtSelection(
 
     //if the active control is text then insert a new button at the selection
     //else replace the button
-    TOXControlList::iterator it = aControlList.begin();
-    for ( ; it != aControlList.end() && *it != pActiveCtrl; ++it );
+    sal_uInt32 nActivePos = aControlList.GetPos(pActiveCtrl);
+    sal_uInt32 nInsertPos = nActivePos;
 
     Size aControlSize(GetOutputSizePixel());
     if( WINDOW_EDIT == pActiveCtrl->GetType())
     {
-        Selection aSel = ((SwTOXEdit*)pActiveCtrl)->GetSelection();
+        nInsertPos++;
+         Selection aSel = ((SwTOXEdit*)pActiveCtrl)->GetSelection();
         aSel.Justify();
         String sEditText = ((SwTOXEdit*)pActiveCtrl)->GetText();
         String sLeft = sEditText.Copy( 0, static_cast< USHORT >(aSel.A()) );
@@ -3133,7 +3135,7 @@ void	SwTokenWindow::InsertAtSelection(
 
         SwFormToken aTmpToken(TOKEN_TEXT);
         SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, aTmpToken);
-        it = aControlList.insert( ++it, pEdit );
+        aControlList.Insert(pEdit, nActivePos + 1);
         pEdit->SetText(sRight);
         pEdit->SetSizePixel(aControlSize);
         pEdit->AdjustSize();
@@ -3144,14 +3146,14 @@ void	SwTokenWindow::InsertAtSelection(
     }
     else
     {
+        aControlList.Remove(pActiveCtrl);
         pActiveCtrl->Hide();
         delete pActiveCtrl;
-        it = aControlList.erase( it );
     }
 
     //now the new button
     SwTOXButton* pButton = new SwTOXButton(&aCtrlParentWin, this, aToInsertToken);
-    it = aControlList.insert( it, pButton );
+    aControlList.Insert(pButton, nInsertPos);
     pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
     pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
     if(TOKEN_AUTHORITY != aToInsertToken.eTokenType)
@@ -3179,37 +3181,28 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall )
     if(bInternalCall && TOX_AUTHORITIES == pForm->GetTOXType())
         m_pParent->PreTokenButtonRemoved(pDel->GetFormToken());
 
-    TOXControlList::iterator itLeft = aControlList.begin();
-    for ( ; itLeft != aControlList.end() && *itLeft != pDel; ++itLeft );
-
-    TOXControlList::iterator itRight = itLeft;
-    if (  itLeft    == aControlList.end()   // not found
-       || itLeft    == aControlList.begin() // the 1st element  (no left )
-       || ++itRight == aControlList.end()   // the last element (no right)
-       )
-        return;
-
+    sal_uInt32 nActivePos = aControlList.GetPos(pDel);
+    OSL_ENSURE(nActivePos != 0xffffffff, "Control does not exist!");
     // the two neighbours of the box must be merged
     // the properties of the right one will be lost
-    --itLeft;
-    Control* pLeftEdit = *itLeft;
-
-    Control* pRightEdit = *itRight;
-
+    OSL_ENSURE(nActivePos && nActivePos < aControlList.Count() - 1,
+        "Button at first or last position?");
+    aControlList.Seek(nActivePos - 1);
+    Control* pLeftEdit = aControlList.GetCurObject();
+    aControlList.Seek(nActivePos + 1);
+    Control* pRightEdit = aControlList.GetCurObject();
     String sTemp(((SwTOXEdit*)pLeftEdit)->GetText());
     sTemp += ((SwTOXEdit*)pRightEdit)->GetText();
     ((SwTOXEdit*)pLeftEdit)->SetText(sTemp);
     ((SwTOXEdit*)pLeftEdit)->AdjustSize();
 
+    aControlList.Remove(pRightEdit);
     delete pRightEdit;
-    itRight = aControlList.erase( itRight );
-
-    ++itLeft;
-    pDel->Hide();
-    delete pDel;
-    itLeft = aControlList.erase( itLeft );
 
-    SetActiveControl( pLeftEdit );
+    aControlList.Remove(pDel);
+    pActiveCtrl->Hide();
+    delete pActiveCtrl;
+    SetActiveControl(pLeftEdit);
     AdjustPositions();
     if(aModifyHdl.IsSet())
         aModifyHdl.Call(0);
@@ -3217,15 +3210,13 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall )
 
 void SwTokenWindow::AdjustPositions()
 {
-    if( aControlList.size() > 1 )
+    if(aControlList.Count() > 1)
     {
-        TOXControlList::iterator it = aControlList.begin();
-        Control* pCtrl = *it;
-        Point aNextPos = pCtrl->GetPosPixel();
+        Control* pCtrl = aControlList.First();
+     Point aNextPos = pCtrl->GetPosPixel();
         aNextPos.X() += pCtrl->GetSizePixel().Width();
-        while ( ++it != aControlList.end() )
+        while(0 != (pCtrl = aControlList.Next()))
         {
-            pCtrl = *it;
             pCtrl->SetPosPixel(aNextPos);
             aNextPos.X() += pCtrl->GetSizePixel().Width();
         }
@@ -3236,22 +3227,22 @@ void SwTokenWindow::AdjustPositions()
 void SwTokenWindow::MoveControls(long nOffset)
 {
     // move the complete list
-    for ( TOXControlList::iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+    Control* pCtrl = aControlList.First();
+    do
     {
-        Control* pCtrl = *it;
         Point aPos = pCtrl->GetPosPixel();
         aPos.X() += nOffset;
         pCtrl->SetPosPixel(aPos);
-    }
+    }while(0 != (pCtrl = aControlList.Next()));
 }
 
 void SwTokenWindow::AdjustScrolling()
 {
-    if( aControlList.size() > 1 )
+    if(aControlList.Count() > 1)
     {
         //validate scroll buttons
-        Control* pLastCtrl  = aControlList.back();
-        Control* pFirstCtrl = aControlList.front();
+        Control* pLastCtrl = aControlList.Last();
+        Control* pFirstCtrl = aControlList.First();
         long nSpace = aCtrlParentWin.GetSizePixel().Width();
         long nWidth = pLastCtrl->GetPosPixel().X() - pFirstCtrl->GetPosPixel().X()
                                                     + pLastCtrl->GetSizePixel().Width();
@@ -3259,7 +3250,7 @@ void SwTokenWindow::AdjustScrolling()
         //the active control must be visible
         if(bEnable && pActiveCtrl)
         {
-            Point aActivePos(pActiveCtrl->GetPosPixel());
+             Point aActivePos(pActiveCtrl->GetPosPixel());
             long nMove = 0;
             if(aActivePos.X() < 0)
                 nMove = -aActivePos.X();
@@ -3267,8 +3258,8 @@ void SwTokenWindow::AdjustScrolling()
                 nMove = -(aActivePos.X() + pActiveCtrl->GetSizePixel().Width() - nSpace);
             if(nMove)
                 MoveControls(nMove);
-            aLeftScrollWin.Enable( aControlList.front()->GetPosPixel().X() < 0 );
-            Control* pCtrl = aControlList.back();
+            aLeftScrollWin.Enable(aControlList.First()->GetPosPixel().X() < 0);
+            Control* pCtrl = aControlList.Last();
             aRightScrollWin.Enable((pCtrl->GetPosPixel().X() + pCtrl->GetSizePixel().Width()) > nSpace);
         }
         else
@@ -3288,46 +3279,44 @@ void SwTokenWindow::AdjustScrolling()
 
 IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
 {
-    if( !aControlList.empty() )
+    if(aControlList.Count())
     {
         const long nSpace = aCtrlParentWin.GetSizePixel().Width();
 #if OSL_DEBUG_LEVEL > 1
-        //find all start/end positions and print it
-        String sMessage(String::CreateFromAscii("Space: "));
-        sMessage += String::CreateFromInt32(nSpace);
+    //find all start/end positions and print it
+    String sMessage(String::CreateFromAscii("Space: "));
+    sMessage += String::CreateFromInt32(nSpace);
+    sMessage += String::CreateFromAscii(" | ");
+    Control* pDebugCtrl = aControlList.First();
+    do
+    {
+        long nDebugXPos = pDebugCtrl->GetPosPixel().X();
+        long nDebugWidth = pDebugCtrl->GetSizePixel().Width();
+        sMessage += String::CreateFromInt32( nDebugXPos );
+        sMessage += String::CreateFromAscii(" ");
+        sMessage += String::CreateFromInt32(nDebugXPos + nDebugWidth);
         sMessage += String::CreateFromAscii(" | ");
-        for ( TOXControlList::iterator it = aControlList.begin(); it != aControlList.end(); ++it )
-        {
-            Control* pDebugCtrl = *it;
-            long nDebugXPos = pDebugCtrl->GetPosPixel().X();
-            long nDebugWidth = pDebugCtrl->GetSizePixel().Width();
-            sMessage += String::CreateFromInt32( nDebugXPos );
-            sMessage += String::CreateFromAscii(" ");
-            sMessage += String::CreateFromInt32(nDebugXPos + nDebugWidth);
-            sMessage += String::CreateFromAscii(" | ");
-        }
+
+    }while(0 != (pDebugCtrl = aControlList.Next()));
+
 #endif
 
         long nMove = 0;
         if(pBtn == &aLeftScrollWin)
         {
             //find the first completely visible control (left edge visible)
-            for ( TOXControlList::iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+            for(sal_uInt16 i = 0; i < aControlList.Count(); i++ )
             {
-                Control* pCtrl = *it;
+                Control* pCtrl = aControlList.GetObject(i);
                 long nXPos = pCtrl->GetPosPixel().X();
                 if(nXPos >= 0)
                 {
-                    if( it != aControlList.begin() )
+                    if(!i)
                         //move the current control to the left edge
                         nMove = -nXPos;
                     else
-                    {
                         //move the left neighbor to the start position
-                        TOXControlList::iterator itLeft = it;
-                        --itLeft;
-                        nMove = -( (*itLeft)->GetPosPixel().X() );
-                    }
+                        nMove = -aControlList.GetObject(i - 1)->GetPosPixel().X();
                     break;
                 }
             }
@@ -3335,19 +3324,17 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
         else
         {
             //find the first completely visible control (left edge visible)
-            for ( TOXControlList::reverse_iterator it = aControlList.rbegin(); it != aControlList.rend(); ++it )
+            for(ULONG i = aControlList.Count(); i; i-- )
             {
-                Control* pCtrl = *it;
+                Control* pCtrl = aControlList.GetObject(i - 1);
                 long nCtrlWidth = pCtrl->GetSizePixel().Width();
                 long nXPos = pCtrl->GetPosPixel().X() + nCtrlWidth;
                 if(nXPos <= nSpace)
                 {
-                    if( it != aControlList.rbegin() )
+                    if( i < aControlList.Count())
                     {
                         //move the right neighbor  to the right edge right aligned
-                        TOXControlList::reverse_iterator itRight = it;
-                        --itRight;
-                        Control* pRight = *itRight;
+                        Control* pRight = aControlList.GetObject(i);
                         nMove = nSpace - pRight->GetPosPixel().X() - pRight->GetSizePixel().Width();
                     }
                     break;
@@ -3359,15 +3346,15 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
         if(nMove)
         {
             // move the complete list
-            for ( TOXControlList::iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+            Control* pCtrl = aControlList.First();
+            do
             {
-                Control* pCtrl = *it;
-                Point aPos = pCtrl->GetPosPixel();
+             Point aPos = pCtrl->GetPosPixel();
                 aPos.X() += nMove;
                 pCtrl->SetPosPixel(aPos);
-            }
-            aLeftScrollWin.Enable(aControlList.front()->GetPosPixel().X() < 0);
-            Control* pCtrl = aControlList.back();
+            }while(0 != (pCtrl = aControlList.Next()));
+            aLeftScrollWin.Enable(aControlList.First()->GetPosPixel().X() < 0);
+            pCtrl = aControlList.Last();
             aRightScrollWin.Enable((pCtrl->GetPosPixel().X() + pCtrl->GetSizePixel().Width()) > nSpace);
 
 #if OSL_DEBUG_LEVEL > 1
@@ -3383,15 +3370,17 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
 String	SwTokenWindow::GetPattern() const
 {
     String sRet;
-    for ( TOXControlList::const_iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+    const Control* pControl = ((SwTokenWindow*)this)->aControlList.First();
+    while(pControl)
     {
-        const Control* pControl = *it;
         const SwFormToken& rNewToken = WINDOW_EDIT == pControl->GetType()
                     ? ((SwTOXEdit*)pControl)->GetFormToken()
                     : ((SwTOXButton*)pControl)->GetFormToken();
 
         //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput
         sRet += rNewToken.GetString();
+
+        pControl = ((SwTokenWindow*)this)->aControlList.Next();
     }
     return sRet;
 }
@@ -3402,9 +3391,9 @@ String	SwTokenWindow::GetPattern() const
 sal_Bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
 {
     sal_Bool bRet = sal_False;
-    for ( TOXControlList::const_iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+    const Control* pControl = ((SwTokenWindow*)this)->aControlList.First();
+    while(pControl)
     {
-        const Control* pControl = *it;
         const SwFormToken& rNewToken = WINDOW_EDIT == pControl->GetType()
                     ? ((SwTOXEdit*)pControl)->GetFormToken()
                     : ((SwTOXButton*)pControl)->GetFormToken();
@@ -3414,6 +3403,7 @@ sal_Bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
             bRet = sal_True;
             break;
         }
+        pControl = ((SwTokenWindow*)this)->aControlList.Next();
     }
     return bRet;
 }
@@ -3492,19 +3482,15 @@ IMPL_LINK(SwTokenWindow, EditResize, Edit*, pEdit)
 
 IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit*,  pEdit)
 {
-    TOXControlList::iterator it = aControlList.begin();
-    for ( ; it != aControlList.end() && *it != pEdit; ++it );
-
-    if (  ( it != aControlList.end()  && !pEdit->IsNextControl() )
-       || (*it != aControlList.back() &&  pEdit->IsNextControl() )
-       )
+    sal_uInt16 nPos = (sal_uInt16)aControlList.GetPos(pEdit);
+    if((nPos && !pEdit->IsNextControl()) ||
+       (nPos < aControlList.Count() - 1 && pEdit->IsNextControl()))
     {
-        if ( pEdit->IsNextControl() )
-            ++it;
-        else
-            --it;
-        (*it)->GrabFocus();
-        ((SwTOXButton*)*it)->Check();
+        aControlList.Seek(nPos);
+        Control* pNextPrev = pEdit->IsNextControl() ? aControlList.Next() : aControlList.Prev();
+        nPos += pEdit->IsNextControl() ? 1 : -1;
+        pNextPrev->GrabFocus();
+        ((SwTOXButton*)pNextPrev)->Check();
         AdjustScrolling();
     }
     return 0;
@@ -3512,11 +3498,15 @@ IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit*,  pEdit)
 
 IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit)
 {
-    for ( TOXControlList::iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+    for(sal_uInt16 i = 0; i < aControlList.Count(); i++)
     {
-        Control* pControl = *it;
-        if(WINDOW_EDIT != pControl->GetType() )
-            ((SwTOXButton*)pControl)->Check(sal_False);
+        Control* pControl = aControlList.First();
+        while(pControl)
+        {
+            if(WINDOW_EDIT != pControl->GetType() )
+                ((SwTOXButton*)pControl)->Check(sal_False);
+            pControl = aControlList.Next();
+        }
     }
     SetActiveControl(pEdit);
     return 0;
@@ -3524,27 +3514,22 @@ IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit)
 
 IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn )
 {
-    TOXControlList::iterator it = aControlList.begin();
-    for ( ; it != aControlList.end() && *it != pBtn; ++it );
-
-    if (  ( it != aControlList.end()  && !pBtn->IsNextControl() )
-       || (*it != aControlList.back() &&  pBtn->IsNextControl() )
-       )
+    sal_uInt16 nPos = (sal_uInt16)aControlList.GetPos(pBtn);
+    if((nPos && !pBtn->IsNextControl()) ||
+       (nPos < aControlList.Count() - 1 && pBtn->IsNextControl()))
     {
+        aControlList.Seek(nPos);
         sal_Bool bNext = pBtn->IsNextControl();
-        if ( bNext )
-            ++it;
-        else
-            --it;
-        (*it)->GrabFocus();
-        Selection aSel( 0, 0 );
-        if ( !bNext )
+        Control* pNextPrev = bNext ? aControlList.Next() : aControlList.Prev();
+        pNextPrev->GrabFocus();
+         Selection aSel(0, 0);
+        if(!bNext)
         {
-            sal_uInt16 nLen = ((SwTOXEdit*)*it)->GetText().Len();
+            sal_uInt16 nLen = ((SwTOXEdit*)pNextPrev)->GetText().Len();
             aSel.A() = nLen;
             aSel.B() = nLen;
         }
-        ((SwTOXEdit*)*it)->SetSelection(aSel);
+        ((SwTOXEdit*)pNextPrev)->SetSelection(aSel);
         pBtn->Check(sal_False);
         AdjustScrolling();
     }
@@ -3553,11 +3538,15 @@ IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn )
 
 IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXButton*, pBtn )
 {
-    for ( TOXControlList::iterator it = aControlList.begin(); it != aControlList.end(); ++it )
+    for(sal_uInt16 i = 0; i < aControlList.Count(); i++)
     {
-        Control* pControl = *it;
-        if(WINDOW_EDIT != pControl->GetType() )
-            ((SwTOXButton*)pControl)->Check(pBtn == pControl);
+        Control* pControl = aControlList.First();
+        while(pControl)
+        {
+            if(WINDOW_EDIT != pControl->GetType() )
+                ((SwTOXButton*)pControl)->Check(pBtn == pControl);
+            pControl = aControlList.Next();
+        }
     }
     SetActiveControl(pBtn);
     return 0;
@@ -3567,9 +3556,9 @@ void SwTokenWindow::GetFocus()
 {
     if(GETFOCUS_TAB & GetGetFocusFlags())
     {
-       if( !aControlList.empty() )
+       Control* pFirst = aControlList.First();
+       if(pFirst)
        {
-            Control* pFirst = aControlList.front();
             pFirst->GrabFocus();
             SetActiveControl(pFirst);
             AdjustScrolling();


More information about the Libreoffice-commits mailing list