2003/12/16 22:35:20
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:42:57 +0000 (07:42 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:42:57 +0000 (07:42 +0000)
darcs-hash:20040130074257-2ba56-4e81a32c031e45f3452e31ae18b10adcfb920c2a.gz

src/org/xwt/Box.java
src/org/xwt/Scheduler.java
src/org/xwt/Surface.java
src/org/xwt/plat/Darwin.java

index a98e052..07c0066 100644 (file)
@@ -227,17 +227,6 @@ public final class Box extends JSScope implements Scheduler.Task {
     Box nextPackedSibling() { Box b = nextSibling(); return b == null || (b.test(PACKED | VISIBLE)) ? b : b.nextPackedSibling(); }
     Box firstPackedChild() { Box b = getChild(0); return b == null || (b.test(PACKED | VISIBLE)) ? b : b.nextPackedSibling(); }
 
-    /** only for use on the root box */
-    void reflow(int new_width, int new_height) {
-        repack();
-        /*
-        new_width = bound(max(contentwidth, minwidth), new_width, test(HSHRINK) ? max(contentwidth, minwidth) : maxwidth);
-        new_height = bound(max(contentheight, minheight), new_height, test(VSHRINK) ? max(contentheight, minheight) : maxheight);
-        */
-        resize(x, y, new_width, new_height);
-        resize_children();
-    }
-
     /** pack the boxes into rows and columns; also computes contentwidth */
     void repack() {
         for(Box child = getChild(0); child != null; child = child.nextSibling()) child.repack();
@@ -271,7 +260,7 @@ public final class Box extends JSScope implements Scheduler.Task {
         //#end               
     }
     
-    private void resize(LENGTH x, LENGTH y, LENGTH width, LENGTH height) {
+    void resize(LENGTH x, LENGTH y, LENGTH width, LENGTH height) {
         // FEATURE reimplement, but we're destroying this
         // FIXME: uncommenting this breaks; see http://bugs.xwt.org/show_bug.cgi?id=345
         //if (x != this.x || y != this.y || width != this.width || height != this.height) {
@@ -287,7 +276,7 @@ public final class Box extends JSScope implements Scheduler.Task {
             //}
     }
 
-    private void resize_children() {
+    void resize_children() {
 
         //#repeat col/row colspan/rowspan contentwidth/contentheight x/y width/height colMaxWidth/rowMaxHeight colWidth/rowHeight \
         //        HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight colWidth/rowHeight x_slack/y_slack
@@ -465,6 +454,9 @@ public final class Box extends JSScope implements Scheduler.Task {
         throw new Error("unreachable"); // unreachable
     }
 
+    void setMaxWidth(Object value) { do { CHECKSET_INT(maxwidth); MARK_RESIZE; } while(false); }
+    void setMaxHeight(Object value) { do { CHECKSET_INT(maxheight); MARK_RESIZE; } while(false); }
+
     public void put(Object name, Object value) throws JSExn {
         if (name instanceof Number) { put(toInt(name), value); return; }
         //#switch(name)
@@ -476,11 +468,11 @@ public final class Box extends JSScope implements Scheduler.Task {
         case "shrink": put("hshrink", value); put("vshrink", value);
         case "hshrink": CHECKSET_FLAG(HSHRINK); MARK_RESIZE;
         case "vshrink": CHECKSET_FLAG(VSHRINK); MARK_RESIZE;
-        case "width": if (parent==null&&Surface.fromBox(this)!=null) { Surface.fromBox(this).setWidth(toInt(value)); } else { put("maxwidth", value); put("minwidth", value); MARK_RESIZE; }
-        case "height": if (parent == null&&Surface.fromBox(this)!=null) { Surface.fromBox(this).setHeight(toInt(value)); } else { put("maxheight", value); put("minheight", value); MARK_RESIZE; }
-        case "maxwidth": CHECKSET_INT(maxwidth); MARK_RESIZE;
+        case "width": put("maxwidth", value); put("minwidth", value); MARK_RESIZE;
+        case "height": put("maxheight", value); put("minheight", value); MARK_RESIZE;
+        case "maxwidth": setMaxWidth(value);
         case "minwidth": CHECKSET_INT(minwidth); MARK_RESIZE;
-        case "maxheight": CHECKSET_INT(maxheight); MARK_RESIZE;
+        case "maxheight": setMaxHeight(value);
         case "minheight": CHECKSET_INT(minheight); MARK_RESIZE;
         case "colspan": CHECKSET_SHORT(colspan); MARK_REPACK_parent;
         case "rowspan": CHECKSET_SHORT(rowspan); MARK_REPACK_parent;
index 8a5cd32..3dcc7f5 100644 (file)
@@ -12,7 +12,13 @@ public class Scheduler {
 
     private static Scheduler singleton;
     public static interface Task { public abstract void perform() throws Exception; }
+
+    /** adds a task to the back of the queue */
     public static void add(Task t) { singleton.runnable.append(t); }
+
+    /** adds a task to the front of the queue (guaranteed to run next) */
+    public static void addAtFront(Task t) { singleton.runnable.prepend(t); }
+
     public static void init() { if (singleton == null) (singleton = Platform.getScheduler()).run(); }
 
     // API which must be supported by subclasses /////////////////////////////////////
index ae85745..be36370 100644 (file)
@@ -36,7 +36,7 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
     public static boolean shift = false;        ///< true iff the shift button is pressed down, in real time
     public static boolean button1 = false;      ///< true iff button 1 is depressed, in Scheduler-time
     public static boolean button2 = false;      ///< true iff button 2 is depressed, in Scheduler-time
-    public static boolean button3 = false;      ///< true iff button 3 is depressed, in Scheduler-time
+    public static boolean button3 = false;      ///< true iff button 3 is depressed, in Scheduler-tiem
 
      
 
@@ -53,11 +53,6 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
     public boolean minimized = false;                  ///< True iff this surface is minimized, in real time
     public boolean maximized = false;                  ///< True iff this surface is maximized, in real time
     private DirtyList dirtyRegions = new DirtyList();  ///< Dirty regions on the *screen*
-    private int width = 0;                             ///< The actual width of the surface
-    private int height = 0;                            ///< The actual height of the surface
-    public int getWidth() { return width; }
-    public int getHeight() { return height; }
-
 
     // Used For Simulating Clicks and DoubleClicks /////////////////////////////////////////////////
 
@@ -80,20 +75,7 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
     public abstract void setTitleBarText(String s);    ///< Sets the surface's title bar text, if applicable
     public abstract void setIcon(Picture i);           ///< Sets the surface's title bar text, if applicable
     public abstract void _dispose();                   ///< Destroy the surface
-
-
-    // Sizing /////////////////////////////////////////////////////////////////////////////////
-
-    public void setLimits(int min_width, int min_height, int max_width, int max_height) { }
-
-    public final void setWidth(int width) { setSize(width, this.height); }
-    public final void setHeight(int height) { setSize(this.width, height); }
-    public final void setSize(int width, int height) {
-        if (this.width == width && this.height == height) return;
-        this.width = Math.max(Main.scarImage.width, width);
-        this.height = Math.max(Main.scarImage.height, height);
-        _setSize(width, height);
-    }
+    public void setLimits(int min_width, int min_height, int max_width, int max_height) { /* FIXME */ }
 
 
     // Helper methods for subclasses ////////////////////////////////////////////////////////////
@@ -218,10 +200,12 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
 
     // FEATURE: can we avoid creating objects here?
     protected final void SizeChange(final int width, final int height) {
-        Scheduler.add(new Scheduler.Task() { public void perform() {
+        Scheduler.addAtFront(new Scheduler.Task() { public void perform() {
+            // dirty the place where the scar used to be
+            root.dirty(0, root.maxheight - Main.scarImage.height, Main.scarImage.width, Main.scarImage.height);
+            root.setMaxWidth(JS.N(width));
+            root.setMaxHeight(JS.N(height));
             root.set(root.REFLOW);
-            Surface.this.width = width;
-            Surface.this.height = height;
         }});
         abort = true;
     }
@@ -278,6 +262,8 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
 
     public Surface(Box root) {
         this.root = root;
+        root.setMaxWidth(JS.N(Math.min(Platform.getScreenWidth(), root.maxwidth)));
+        root.setMaxHeight(JS.N(Math.min(Platform.getScreenHeight(), root.maxheight)));
         Surface old = fromBox(root);
         if (old != null) old.dispose(false);
         else root.removeSelf();
@@ -289,15 +275,17 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
     /** runs the prerender() and render() pipelines in the root Box to regenerate the backbuffer, then blits it to the screen */
     public synchronized void render() {
 
-        // dirty the place where the scar used to be
-        if (root.width != width || root.height != height)
+        // dirty the place where the scar used to be in case the root window size was programmatically changed
+        if (root.maxwidth != root.width || root.maxheight != root.height)
             root.dirty(0, root.height - Main.scarImage.height, Main.scarImage.width, Main.scarImage.height);
 
         // make sure the root is properly sized
         do {
             abort = false;
-            root.reflow(width, height);
-            setSize(width, height);
+            root.repack();
+            root.resize(root.x, root.y, root.maxwidth, root.maxheight);
+            root.resize_children();
+            _setSize(root.width, root.height);
             String oldcursor = cursor;
             cursor = "default";
             root.Move(mousex, mousey, mousex, mousey);
index 84bec1c..14bdecb 100644 (file)
@@ -267,7 +267,8 @@ public class Darwin extends POSIX {
                 
                 reshape(winWidth,winHeight);
                 clear();
-                Dirty(0,0,getWidth(),getHeight());
+                Dirty(0,0,winWidth,winHeight);
+                //Dirty(0,0,getWidth(),getHeight());
             }
             super.render_();
             flush();