Project

General

Profile

position_validate.patch

Marian Edu, 05/27/2022 01:50 AM

Download (6.6 KB)

View differences:

new/src/com/goldencode/p2j/ui/BaseEntity.java 2022-05-26 13:11:28 +0000
187 187
**                           and converted to integer. See #5345.
188 188
**     VVT 20211118          Fixed: incorrect coordinate conversion when setting size atributes. See #5034-1422.
189 189
**     ME  20220209          Replace getAttr for "realized" with isRealized method.
190
**     ME  20220526          Extend validation for ROW/COLUMN attributes against parent.
190 191
*/
191 192
/*
192 193
** This program is free software: you can redistribute it and/or modify
......
2796 2797
   protected boolean validColumnOrRow(boolean isUnknown, double value, boolean row)
2797 2798
   {
2798 2799
      boolean isChui = LogicalTerminal.isChui();
2799
      
2800
      if (isChui)
2801
      {
2802
         value = Coordinate.scale(value, 0);
2803
         
2804
         if (isUnknown || value < Coordinate.MIN_CHUI_CH)
2805
         {
2806
            String msg = String.format(
2807
                  "**Attribute %s must be greater than or equal to 1 on %s widget", 
2808
                  row ? "ROW" : "COL",
2809
                  type());
2810
            ErrorManager.displayWarning(4081, msg, false);
2811
            return false;
2812
         }
2813
         
2814
         if (value > Coordinate.MAX_CHUI_CH)
2815
         {
2816
            String msg = String.format("Invalid character unit value %d changed to %d", 
2817
                                       Math.abs((int) value), Coordinate.MAX_CHUI_CH);
2818
            ErrorManager.recordOrShowError(13734, msg, false, true, false);
2819
            return false;
2820
         }
2821
         
2822
         value = Coordinate.adjustMinMaxChuiChar(value);
2823
      }
2824
      else
2825
      {
2826
         value = Coordinate.scale(value);
2827
         
2828
         if (isUnknown || (value > -1 && value < 1))
2829
         {
2830
            String msg = String.format(
2831
                  "**Attribute %s must be greater than or equal to 1 on %s widget", 
2832
                  row ? "ROW" : "COL",
2833
                  type());
2834
            ErrorManager.displayWarning(4081, msg, false);
2835
            return false;
2836
         }
2837
         
2838
         if (value < Coordinate.MIN_GUI_CH || value > Coordinate.MAX_GUI_CH)
2839
         {
2840
            double origValue = value;
2841
            value = Coordinate.adjustMinMaxGuiChar(value); 
2842
            String msg;
2843
            if (origValue == (long) origValue)
2844
            {
2845
               msg = String.format("Invalid character unit value %d changed to %d", 
2846
                     Math.abs((long) origValue), Math.abs((long) value));
2847
            }
2848
            else
2849
            {
2850
               msg = String.format("Invalid character unit value %s changed to %s", 
2851
                     Math.abs(origValue), Math.abs(value));
2852
            }
2853
            ErrorManager.recordOrShowError(13734, msg, false, true, false);
2854
            return false;
2855
         }
2856
      }
2857
      // TODO: widget can not go outside of the frame's size (when realized)!
2800
      value = isChui ? Coordinate.scale(value, 0) : Coordinate.scale(value);
2801
      
2802
      if (isUnknown || value < 1)
2803
      {
2804
         String msg = String.format("**Attribute %s must be greater than or equal to 1 on %s %s",
2805
                  row ? "ROW" : "COL", type(), widgetName());
2806
         ErrorManager.recordOrShowWarning(4081, msg, false, false, true, true);
2807
         return false;
2808
      }
2809

  
2810
      double adjusted = isChui ? Coordinate.adjustMinMaxChuiChar(value) : Coordinate.adjustMinMaxGuiChar(value);
2811
      
2812
      if (value > adjusted)
2813
      {
2814
         String msg = String.format("Invalid character unit value %d changed to %d",
2815
                  Math.abs((long) value), Math.abs((long) adjusted));
2816
         ErrorManager.recordOrShowWarning(13734, msg, false, false, true, true);
2817
         return true;
2818
      }
2819
      
2820
      // check if it fits in parent, only if parent was realized
2821
      PaneEntity parent = getParent(PaneEntity.class);
2822
      if (parent != null && parent._isRealized())
2823
      {
2824
         double parentSize = row ? parent.getVirtHeight().doubleValue()
2825
                  : parent.getVirtWidth().doubleValue();
2826
         double size = row ? getVirtHeight().doubleValue() : getVirtWidth().doubleValue();
2827

  
2828
         if (value - 1 > parentSize - size)
2829
         {
2830
            ErrorManager.recordOrShowWarning(4054,
2831
                     String.format("Unable to set %s. %s %s does not fit in %s widget",
2832
                              row ? "ROW" : "COLUMN", type(), widgetName(), parent.type()),
2833
                     false, false, true, true);
2834
            return false;
2835
         }
2836
      }
2858 2837

  
2859 2838
      return true;
2860 2839
   }
new/src/com/goldencode/p2j/ui/FrameWidget.java 2022-05-26 13:12:22 +0000
198 198
**                           Notes resolution.  Added root frame detection code.  According to testcases the
199 199
**                           root frame should return unknown value as tab-position.
200 200
**     ME  20220512          Frame has fixed size only when size is assigned outside of frame setup.
201
**     ME  20220526          Extend validation for ROW/COLUMN attributes against parent.                        
201 202
*/
202 203
/*
203 204
** This program is free software: you can redistribute it and/or modify
......
3142 3143
   @Override
3143 3144
   protected void setColumnOrRow(boolean isUnknown, double value, boolean row)
3144 3145
   {
3145
      // TO-DO:
3146
      // value > screen-width - frame-width should produce PROGRESS error 4054
3147
      // "**Unable to set COL.  FRAME f does not fit in WINDOW widget. (4054)"
3148
      if (!validColumnOrRow(isUnknown, value, row))
3146
      if (!frame.isInsideSetup() && !validColumnOrRow(isUnknown, value, row))
3149 3147
      {
3150 3148
         // for frames, there are two cases when the value is not a valid coordinate:
3151 3149
         // 1. frame is a child frame (has the FRAME attribute set)
......
3157 3155
         //     by the runtime
3158 3156
         //   - frame is realized: the new value is ignored
3159 3157
         
3160
         if (_isRealized())
3161
         {
3162
            return;
3163
         }
3158
         return;
3164 3159
      }
3165 3160
      
3166 3161
      placeFrame();
3167 3162
      
3168 3163
      boolean isChui = LogicalTerminal.isChui();
3169 3164

  
3170
      value = isChui ? Coordinate.scale(value, 0) : Coordinate.scale(value);
3171
      
3165
      value = isChui ? Coordinate.adjustMinMaxChuiChar(Coordinate.scale(value, 0))
3166
               : Coordinate.adjustMinMaxGuiChar(Coordinate.scale(value));
3167

  
3172 3168
      if ((row && getAttr("row", () -> config.row) == value - 1) || (!row && getAttr("column", () -> config.column) == value - 1))
3173 3169
      {
3174 3170
         return;