uicontrol(x) to set focus must pass through the model instead of call directly SwingView 37/20537/3
Antoine ELIAS [Fri, 5 Oct 2018 12:32:21 +0000 (14:32 +0200)]
Change-Id: I557994bd67e20a8e659aaea95de7f94d3f494a95

scilab/modules/graphic_objects/includes/graphicObjectProperties.h
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicObject/GraphicObjectProperties.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/uicontrol/Uicontrol.java
scilab/modules/graphic_objects/src/scripts/propertiesMap.properties
scilab/modules/gui/sci_gateway/c/sci_uicontrol.c
scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java

index 5aea4b6..d1cab15 100755 (executable)
 #define __GO_NUM_MARK_FOREGROUNDS__ 401
 #define __GO_MARK_BACKGROUNDS__ 402
 #define __GO_NUM_MARK_BACKGROUNDS__ 403
+#define __GO_UI_FOCUS__ 404
 
 #endif /* !__GRAPHIC_OBJECT_PROPERTIES_H__ */
index e02d689..b80f66d 100644 (file)
@@ -424,5 +424,6 @@ public class GraphicObjectProperties {
     public static final int __GO_NUM_MARK_FOREGROUNDS__ = 401;
     public static final int __GO_MARK_BACKGROUNDS__ = 402;
     public static final int __GO_NUM_MARK_BACKGROUNDS__ = 403;
+    public static final int __GO_UI_FOCUS__ = 404;
 
 }
index a4aa7b5..c626d92 100644 (file)
@@ -80,6 +80,7 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE_SIZE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VERTICALALIGNMENT__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOCUS__;
 
 import java.awt.Font;
 import java.util.Arrays;
@@ -546,7 +547,8 @@ public class Uicontrol extends GraphicObject {
         SCROLLABLE,
         ICON,
         EVENTHANDLER,
-        EVENTHANDLERENABLE
+        EVENTHANDLERENABLE,
+        FOCUS
     };
 
     /**
@@ -787,6 +789,8 @@ public class Uicontrol extends GraphicObject {
                 return UicontrolProperty.EVENTHANDLER;
             case __GO_EVENTHANDLER_ENABLE__:
                 return UicontrolProperty.EVENTHANDLERENABLE;
+            case __GO_UI_FOCUS__:
+                return UicontrolProperty.FOCUS;
             default :
                 return super.getPropertyFromName(propertyName);
         }
@@ -998,6 +1002,8 @@ public class Uicontrol extends GraphicObject {
                 return setEventHandler((String) value);
             case EVENTHANDLERENABLE:
                 return setEventHandlerEnable((Boolean) value);
+            case FOCUS:
+                return UpdateStatus.Success;
             default:
                 return super.setProperty(property, value);
         }
index 724fea2..2bd2bdd 100755 (executable)
@@ -454,3 +454,5 @@ __GO_MARK_FOREGROUNDS__
 __GO_NUM_MARK_FOREGROUNDS__
 __GO_MARK_BACKGROUNDS__
 __GO_NUM_MARK_BACKGROUNDS__
+
+__GO_UI_FOCUS__
\ No newline at end of file
index 555b46c..2aafac3 100644 (file)
@@ -237,8 +237,10 @@ int sci_uicontrol(char *fname, void* pvApiCtx)
                 getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
                 if (iParentType == __GO_UICONTROL__)  /* Focus management */
                 {
+                    int fake = 0; //no real data
                     GraphicHandle = (unsigned long)hParent;
-                    requestFocus(iParentUID);
+                    setGraphicObjectProperty(iParentUID, __GO_UI_FOCUS__, &fake, jni_int, 1);
+                    //requestFocus(iParentUID);
                 }
                 else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__)  /* PushButton creation */
                 {
index 18593ca..ab1b11c 100644 (file)
@@ -73,6 +73,7 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VALID__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_WAITBAR__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOCUS__;
 import static org.scilab.modules.gui.utils.Debug.DEBUG;
 
 import java.awt.Component;
@@ -793,6 +794,11 @@ public final class SwingView implements GraphicView {
             return;
         }
 
+        if(property == __GO_UI_FOCUS__) {
+            requestFocus(registeredObject);
+            return;
+        }
+
         /* Do not update axes on EDT to avoid dead locks between SwingView & DrawerVisitor */
         /* Test which freezes without this condition: bug_1257.tst in graphics */
         int type = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
@@ -1605,4 +1611,15 @@ public final class SwingView implements GraphicView {
             updatedComponent.validate();
         }
     }
+
+    private void requestFocus(TypedObject updatedObject) {
+        SwingViewObject uicontrol = updatedObject.getValue();
+        if (uicontrol instanceof SwingScilabScrollableFrame) {
+            ((SwingScilabScrollableFrame) uicontrol).requestFocus();
+        } else if (uicontrol instanceof SwingScilabFrame) {
+            ((SwingScilabFrame) uicontrol).requestFocus();
+        } else {
+            ((Widget) uicontrol).requestFocus();
+        }
+    }
 }