[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - wizards/com

Lionel Elie Mamane lionel at mamane.lu
Wed Jan 7 09:24:56 PST 2015


 wizards/com/sun/star/wizards/form/FormControlArranger.java |   88 ++++++-------
 1 file changed, 47 insertions(+), 41 deletions(-)

New commits:
commit 9fb950db44260b6a9f3946117a42a3d43be44415
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Fri Dec 19 23:21:52 2014 +0100

    protect against division by zero
    
    Change-Id: Ib91120e626f772bb52531c4a35fc70f04cc5c48f
    Reviewed-on: https://gerrit.libreoffice.org/13558
    Reviewed-by: David Tardon <dtardon at redhat.com>
    Tested-by: David Tardon <dtardon at redhat.com>

diff --git a/wizards/com/sun/star/wizards/form/FormControlArranger.java b/wizards/com/sun/star/wizards/form/FormControlArranger.java
index 9d842d6..105bfde 100644
--- a/wizards/com/sun/star/wizards/form/FormControlArranger.java
+++ b/wizards/com/sun/star/wizards/form/FormControlArranger.java
@@ -227,7 +227,10 @@ public class FormControlArranger
             // shapes are made more narrow
             ShapeCount = iReduceWidth;
         }
-        return (nDist) / ShapeCount;
+        if(ShapeCount == 0)
+            return 0;
+        else
+            return (nDist) / ShapeCount;
     }
 
     /**
@@ -237,51 +240,54 @@ public class FormControlArranger
      * @param nDist
      * @param WidthFactor is either '+1' or '-1' and determines whether the control shapes widths are to be made smaller or larger
      */
-    private void adjustLineWidth(int StartIndex, int EndIndex, int nDist, int WidthFactor)
+    private void adjustLineWidth(final int StartIndex, final int EndIndex, final int nDist, final int WidthFactor)
     {
-        int CorrWidth = getCorrWidth(StartIndex, EndIndex, nDist, WidthFactor);
-        int iLocTCPosX = cXOffset;
-        for (int i = StartIndex; i <= EndIndex; i++)
+        if(StartIndex <= EndIndex)
         {
-            int nControlBaseWidth = 0;
-            DatabaseControl dbControl = DBControlList[i];
-            Control curLabelControl = LabelControlList[i];
-            if (i != StartIndex)
-            {
-                curLabelControl.setPosition(new Point(iLocTCPosX, curLabelControl.getPosition().Y));
-                dbControl.setPosition(new Point(iLocTCPosX, curLabelControl.getPosition().Y + m_LabelHeight));
-            }
-            final Size labelSize = curLabelControl.getSize();
-            Size controlSize = dbControl.getSize();
-            if (((labelSize.Width > controlSize.Width)) && (WidthFactor > 0))
-            {
-                nControlBaseWidth = labelSize.Width;
-            }
-            else
-            {
-                nControlBaseWidth = controlSize.Width;
-            }
-            if (FieldColumns[i].getFieldType() == DataType.TIMESTAMP)
-            {
-                TimeStampControl oDBTimeStampControl = (TimeStampControl) dbControl;
-                nControlBaseWidth = oDBTimeStampControl.getSize().Width;
-            }
-            if (WidthFactor > 0 || isReducable(i, labelSize.Width, controlSize.Width))
+            int CorrWidth = getCorrWidth(StartIndex, EndIndex, nDist, WidthFactor);
+            int iLocTCPosX = cXOffset;
+            for (int i = StartIndex; i <= EndIndex; i++)
             {
-                controlSize.Width = nControlBaseWidth + WidthFactor * CorrWidth;
-                dbControl.setSize(controlSize);
-                controlSize = dbControl.getSize();
-            }
+                int nControlBaseWidth = 0;
+                DatabaseControl dbControl = DBControlList[i];
+                Control curLabelControl = LabelControlList[i];
+                if (i != StartIndex)
+                {
+                    curLabelControl.setPosition(new Point(iLocTCPosX, curLabelControl.getPosition().Y));
+                    dbControl.setPosition(new Point(iLocTCPosX, curLabelControl.getPosition().Y + m_LabelHeight));
+                }
+                final Size labelSize = curLabelControl.getSize();
+                Size controlSize = dbControl.getSize();
+                if (((labelSize.Width > controlSize.Width)) && (WidthFactor > 0))
+                {
+                    nControlBaseWidth = labelSize.Width;
+                }
+                else
+                {
+                    nControlBaseWidth = controlSize.Width;
+                }
+                if (FieldColumns[i].getFieldType() == DataType.TIMESTAMP)
+                {
+                    TimeStampControl oDBTimeStampControl = (TimeStampControl) dbControl;
+                    nControlBaseWidth = oDBTimeStampControl.getSize().Width;
+                }
+                if (WidthFactor > 0 || isReducable(i, labelSize.Width, controlSize.Width))
+                {
+                    controlSize.Width = nControlBaseWidth + WidthFactor * CorrWidth;
+                    dbControl.setSize(controlSize);
+                    controlSize = dbControl.getSize();
+                }
 
-            if (labelSize.Width > controlSize.Width)
-            {
-                iLocTCPosX += labelSize.Width;
-            }
-            else
-            {
-                iLocTCPosX += controlSize.Width;
+                if (labelSize.Width > controlSize.Width)
+                {
+                    iLocTCPosX += labelSize.Width;
+                }
+                else
+                {
+                    iLocTCPosX += controlSize.Width;
+                }
+                iLocTCPosX += cHoriDistance;
             }
-            iLocTCPosX += cHoriDistance;
         }
         if (WidthFactor > 0)
         {


More information about the Libreoffice-commits mailing list