[Libreoffice-commits] core.git: vcl/source

Michael Meeks michael.meeks at suse.com
Wed Mar 27 09:47:54 PDT 2013


 vcl/source/window/dlgctrl.cxx |   47 +++++++++---------------------------------
 1 file changed, 11 insertions(+), 36 deletions(-)

New commits:
commit 23c22d3da5349ba1242edaeecfa0cba97a92ac71
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Wed Mar 27 16:45:05 2013 +0000

    fdo#62094 - fix infinite loop in radio button group iteration.
    
    Simplify the code too - we copy the vector anyway, so reversing it
    should be cheap.
    
    Change-Id: Ie655ba3044c7e0dd5a15b0e839a3712a32a1e298

diff --git a/vcl/source/window/dlgctrl.cxx b/vcl/source/window/dlgctrl.cxx
index 19d68a0..fe7b080 100644
--- a/vcl/source/window/dlgctrl.cxx
+++ b/vcl/source/window/dlgctrl.cxx
@@ -544,39 +544,14 @@ namespace
         return (pWindow && isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled());
     }
 
-    bool backInGroup(std::vector<RadioButton*>::reverse_iterator aRevStart, std::vector<RadioButton*> &rGroup)
+    bool focusNextInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
     {
-        std::vector<RadioButton*>::reverse_iterator aI(aRevStart);
-        while (aI != rGroup.rend())
-        {
-            Window *pWindow = *aI;
-
-            if (isSuitableDestination(pWindow))
-            {
-                pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
-                return true;
-            }
-        }
-
-        aI = rGroup.rbegin();
-        while (aI != aRevStart)
-        {
-            Window *pWindow = *aI;
-
-            if (isSuitableDestination(pWindow))
-            {
-                pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
-                return true;
-            }
-        }
+        std::vector<RadioButton*>::iterator aI(aStart);
 
-        return false;
-    }
+        if (aStart != rGroup.end())
+            ++aI;
 
-    bool forwardInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
-    {
-        std::vector<RadioButton*>::iterator aI(aStart);
-        while (++aI != rGroup.end())
+        for (; aI != rGroup.end(); ++aI)
         {
             Window *pWindow = *aI;
 
@@ -587,8 +562,7 @@ namespace
             }
         }
 
-        aI = rGroup.begin();
-        while (aI != aStart)
+        for (aI = rGroup.begin(); aI != aStart; ++aI)
         {
             Window *pWindow = *aI;
 
@@ -597,6 +571,7 @@ namespace
                 pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_FORWARD );
                 return true;
             }
+            aI++;
         }
 
         return false;
@@ -609,14 +584,14 @@ namespace
         if (aGroup.size() == 1) //only one button in group
             return false;
 
+        if (bBackward)
+            std::reverse(aGroup.begin(), aGroup.end());
+
         std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow));
 
         assert(aStart != aGroup.end());
 
-        if (bBackward)
-            return backInGroup(std::vector<RadioButton*>::reverse_iterator(aStart), aGroup);
-        else
-            return forwardInGroup(aStart, aGroup);
+        return focusNextInGroup(aStart, aGroup);
     }
 }
 


More information about the Libreoffice-commits mailing list