Revision: 2342
          http://vexi.svn.sourceforge.net/vexi/?rev=2342&view=rev
Author:   clrg
Date:     2007-09-27 08:28:50 -0700 (Thu, 27 Sep 2007)

Log Message:
-----------
More cleanup of Surface size handling
- restore framewidth/frameheight (old XWT properties!!!)
- fix initial refresh bug caused by properties not current in componentResized
- add a few pieces of commented code that could be minor improvements

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
    trunk/core/org.vexi.core/src/org/vexi/core/Constants.java
    trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
    trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2007-09-27 15:25:20 UTC 
(rev 2341)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2007-09-27 15:28:50 UTC 
(rev 2342)
@@ -1279,6 +1279,24 @@
         case "minwidth":    setMinMaxWidth(JSU.toInt(value), maxwidth);
         case "maxheight":   setMinMaxHeight(minheight, JSU.toInt(value));
         case "minheight":   setMinMaxHeight(JSU.toInt(value), maxheight);
+        case "framewidth":
+               int fw, fh;
+               try { fw = JSU.toInt(value); }
+               catch (Exception e) { throw new JSExn("framewidth must be an 
integer"); }
+               try { fh = JSU.toInt(getAndTriggerTraps(SC_frameheight)); }
+               catch (Exception e) { throw new JSExn("frameheight read traps 
must return an integer"); }
+               super.put(name, value);
+               if (parent == null && getSurface() != null)
+                       getSurface().setSize(fw, fh);
+        case "frameheight":
+               int fw, fh;
+               try { fh = JSU.toInt(value); }
+               catch (Exception e) { throw new JSExn("frameheight must be an 
integer"); }
+               try { fw = JSU.toInt(getAndTriggerTraps(SC_framewidth)); }
+               catch (Exception e) { throw new JSExn("framewidth read traps 
must return an integer"); }
+               super.put(name, value);
+               if (parent == null && getSurface() != null)
+                       getSurface().setSize(fw, fh);
         case "display":
             boolean display = JSU.toBoolean(value);
             if (test(DISPLAY) != display) {

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Constants.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Constants.java   2007-09-27 
15:25:20 UTC (rev 2341)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Constants.java   2007-09-27 
15:28:50 UTC (rev 2342)
@@ -13,6 +13,8 @@
        static final JS SC_cursor = JSU.S("cursor",true);
        static final JS SC_endElement = JSU.S("endElement",true);
        static final JS SC_Enter = JSU.S("Enter",true);
+       static final JS SC_frameheight = JSU.S("frameheight",true);
+       static final JS SC_framewidth = JSU.S("framewidth");
        static final JS SC_height = JSU.S("height",true);
     static final JS SC_horizontal = JSU.S("horizontal",true);
        static final JS SC_hshrink = JSU.S("hshrink",true);

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2007-09-27 
15:25:20 UTC (rev 2341)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2007-09-27 
15:28:50 UTC (rev 2342)
@@ -38,8 +38,6 @@
     public volatile boolean abort = false;
 
     // these three variables are used to ensure that user resizes trump 
programmatic resizes
-    public volatile boolean syncRootWithSurface = false;
-    public volatile boolean syncSurfaceWithRoot = true;
     public volatile int pendingWidth = 0;
     public volatile int pendingHeight = 0;
 
@@ -198,8 +196,28 @@
     protected final void HScroll(float lines) { new Message("HScroll", 
JSU.N(lines), root); }
     protected final void VScroll(float lines) { new Message("VScroll", 
JSU.N(lines), root); }
 
+    protected boolean firstrender = false;
     /** subclasses should invoke this method when the user resizes the window 
*/
-    protected final void SizeChange(final int width, final int height) {
+    protected final void SizeChange(int width, int height) {
+        if (firstrender) return;
+        // constrain our size as determined by the root box
+        width = root.maxwidth < width ? root.maxwidth : width;
+        width = root.minwidth > width ? root.minwidth : width;
+        height = root.maxheight < height ? root.maxheight : height;
+        height = root.minheight > height ? root.minheight : height;
+        /*
+        // the following causes the expanded region to flicker
+        // as it 1. resizes (AWT), 2. fills, 3. collapses (setSizes), back to 
1.
+        int capwidth = width, capheight = height;
+        capwidth = root.maxwidth < capwidth ? root.maxwidth : capwidth;
+        capwidth = root.minwidth > capwidth ? root.minwidth : capwidth;
+        capheight = root.maxheight < capheight ? root.maxheight : capheight;
+        capheight = root.minheight > capheight ? root.minheight : capheight;
+        if (capwidth != width || capheight != height) {
+               //setSize(capwidth, capheight);
+               return;
+        }
+        */
         if (pendingWidth == width && pendingHeight == height) return;
         pendingWidth = width;
         pendingHeight = height;
@@ -247,26 +265,20 @@
         poschangeScheduled = true;
         Scheduler.add(poschanger);
     }
-    
+
     protected final void setPosition() {
         int sw = Platform.getScreenWidth();
         int sh = Platform.getScreenHeight();
         // horizontal
-        if (root.leftAlign()) {
-            this.x = root.x;
-        } else if (root.rightAlign()) {
-            this.x = root.x + sw - leftInset - rightInset - root.maxwidth;
-        } else {
-            this.x = root.x + (sw - leftInset - rightInset - root.maxwidth) / 
2;
-        }
+        if (root.leftAlign()) this.x = root.x;
+        else if (root.rightAlign())
+               this.x = root.x+sw-leftInset-rightInset-root.width;
+        else this.x = root.x+(sw-leftInset-rightInset-root.width)/2;
         // vertical
-        if (root.topAlign()) {
-            this.y = root.y;
-        } else if (root.bottomAlign()) {
-            this.y = root.y + sh - leftInset - rightInset - root.maxheight;
-        } else {
-            this.y = root.y + (sh - topInset - bottomInset - root.maxheight) / 
2;
-        }
+        if (root.topAlign()) this.y = root.y;
+        else if (root.bottomAlign())
+               this.y = root.y+sh-leftInset-rightInset-root.height;
+        else this.y = root.y+(sh-topInset-bottomInset-root.height)/2;
         // propogate to frame/window
         setLocation();
     }
@@ -355,18 +367,16 @@
             Log.info(this, "Caught JSExn from setParent() in Surface 
constructor - this should not happen");
             Log.warn(this, jse);
         }
-        // TODO: document this in the reference
-        pendingWidth = root.maxwidth;
-        pendingHeight = root.maxheight;
-        if (pendingWidth == Integer.MAX_VALUE)
-               pendingWidth = Platform.getScreenWidth() / 2;
-        if (pendingHeight == Integer.MAX_VALUE)
-               pendingHeight = Platform.getScreenHeight() / 2;
         // set frame specific box properties
         try {
-            JS icon = root.get(SC_icon);
+            // TODO: document this in the reference
+               JS fw = root.getAndTriggerTraps(SC_framewidth);
+            pendingWidth = fw != null ? JSU.toInt(fw) : 
Platform.getScreenWidth() / 2;
+            JS fh = root.getAndTriggerTraps(SC_frameheight);
+            pendingHeight = fh != null ? JSU.toInt(fh) : 
Platform.getScreenHeight() / 2;
+            JS icon = root.getAndTriggerTraps(SC_icon);
             if (icon != null) queueSetIcon(icon);
-            JS titlebar = root.get(SC_titlebar);
+            JS titlebar = root.getAndTriggerTraps(SC_titlebar);
             if (titlebar != null) setTitleBarText(JSU.toString(titlebar));
         } catch (JSExn jse) {
             // FIXME: handle exceptions properly
@@ -380,6 +390,7 @@
     /** runs the prerender() and render() pipelines in the root Box to 
regenerate the backbuffer, then blits it to the screen */
     public synchronized void render() {
        scheduled = false;
+       firstrender = false;
         // do nothing if we are minimized
         if (minimized) return;
         // make sure the root is properly sized
@@ -395,12 +406,7 @@
                 }
                 // reflow to new size as set by the frame
                 root.reflow(pendingWidth, pendingHeight);
-                // root rejects new sizes
-                /*if (root.width != pendingWidth || root.height != 
pendingHeight) {
-                       pendingWidth = root.width;
-                       pendingHeight = root.height;
-                       setSize(pendingWidth, pendingHeight);
-                }*/
+            // size the same but maybe box-tree needs reflow
             } else root.reflow();
         } while(abort);
 
@@ -423,7 +429,6 @@
                 if(scarImage.width > x && yscarstart < y+h)
                        buff.drawPicture(scarImage, 0, yscarstart, x, y, x+w, 
y+h);
             }
-            /*
             if (abort) {
                 // x,y,w,h is only partially reconstructed, so we must be 
careful not to re-blit it
                 dirtyRegions.dirty(x, y, w, h);
@@ -433,7 +438,6 @@
                         dirtyRegions.dirty(dirt[j][0], dirt[j][1], dirt[j][2], 
dirt[j][3]);
                 return;
             }
-            */
         }
     }
 
@@ -528,7 +532,6 @@
 
         public void render() {
             super.render();
-            //if (abort) { System.err.println("early abort"); return; }
             int numregions = screenDirtyRegions.num();
             int[][] dirt = screenDirtyRegions.flush();
             for(int i = 0; dirt != null && i < numregions; i++) {
@@ -542,7 +545,6 @@
                 if (x+w > root.width) w = root.width - x;
                 if (y+h > root.height) h = root.height - y;
                 if (w <= 0 || h <= 0) continue;
-                //if (abort) { System.err.println("aborting render ("+i+")"); 
return; }
                 blit(backbuffer, x, y, x, y, w + x, h + y);
             }
         }

Modified: trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java 2007-09-27 15:25:20 UTC 
(rev 2341)
+++ trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java 2007-09-27 15:28:50 UTC 
(rev 2342)
@@ -351,6 +351,7 @@
         public void toFront() { if (window != null) window.toFront(); }
         public void setLocation() { if (window != null) window.setLocation(x, 
y); }
         public void setTitleBarText(String s) { if (frame != null) 
frame.setTitle(s); }
+        public void setInvisible(boolean b) { window.setVisible(!b); }
         public void setIcon(Picture i) 
         { 
                if (frame == null) return;
@@ -360,9 +361,13 @@
             // ImageIcon(..).getImage() seems to work however.
             // frame.setIconImage(((AWTPicture)i).i);
         }
-        public void _setSize(int width, int height) { discoverInsets(); 
window.setSize(width + (leftInset + rightInset), height + (topInset + 
bottomInset)); }
-        public void setInvisible(boolean b) { window.setVisible(!b); }
-        protected void _setMinimized(boolean b) { Log.warn(this, "JDK 1.1 
platforms cannot minimize or unminimize windows"); }
+        public void _setSize(int width, int height) {
+               discoverInsets();
+               window.setSize(width + (leftInset + rightInset), height + 
(topInset + bottomInset));
+        }
+        protected void _setMinimized(boolean b) {
+               Log.warn(this, "JDK 1.1 platforms cannot minimize or unminimize 
windows");
+        }
         protected void _setMaximized(boolean b) {
             if (!b) {
                Log.warn(this, "JDK 1.1 platforms cannot unmaximize windows");
@@ -374,8 +379,11 @@
 
         class InnerFrame extends Frame {
             public InnerFrame() throws java.lang.UnsupportedOperationException 
{ }
+            /** overrides the native Frame method to supposedly enforce a 
minimum size */
             public Dimension getMinimumSize() {
-                return new Dimension(root == null ? 0 : root.minwidth, root == 
null ? 0 : root.minheight); }
+                // FEATURE: cache dimension
+                return new Dimension(root == null ? 0 : root.minwidth, root == 
null ? 0 : root.minheight);
+            }
             public void update(Graphics gr) { paint(gr); }
             public void paint(Graphics gr) {
                 Rectangle r = gr.getClipBounds();
@@ -389,7 +397,6 @@
 
                 refreshFromBackbuffer(r.x - leftInset, r.y - topInset, 
r.width, r.height);
             }
-            
             public InputMethodRequests getInputMethodRequests() {
                 // REMARK - makes us a passive client FOOTNOTE1
                return null;
@@ -398,8 +405,11 @@
 
         class InnerWindow extends Window {
             public InnerWindow() throws 
java.lang.UnsupportedOperationException { super(new Frame()); }
+            /** overrides the native Window method to supposedly enforce a 
minimum size */
             public Dimension getMinimumSize() {
-                return new Dimension(root == null ? 0 : root.minwidth, root == 
null ? 0 : root.minheight); }
+                // FEATURE: cache dimension
+                return new Dimension(root == null ? 0 : root.minwidth, root == 
null ? 0 : root.minheight);
+            }
             public void update(Graphics gr) { paint(gr); }
             public void paint(Graphics gr) {
                 Rectangle r = gr.getClipBounds();
@@ -410,25 +420,35 @@
                return null;
             }
         }
-        
 
-        
+        /** establish the size of the frame decorations */
         private void discoverInsets() {
-            Insets i = (frame == null ? window : frame).getInsets();
+            Insets i = window.getInsets();
             if (leftInset == i.left && topInset == i.top && bottomInset == 
i.bottom && rightInset == i.right)
                 return;
             leftInset = i.left;
             topInset = i.top;
             bottomInset = i.bottom;
             rightInset = i.right;
-            setPosition();
+            // respect the size of the root box
+               window.setSize(pendingWidth + (leftInset + rightInset), 
pendingHeight + (topInset + bottomInset));
         }
+        
+        /** sets the maximum size of the frame */
+        public void setMaximumSize(int maxw, int maxh) {
+               
+        }
 
-        public void setMinimumSize(int minx, int miny, boolean resizable) { if 
(frame != null) frame.setResizable(resizable); }
+        /** note that the minimum size is handled by getMinimumSize in 
InnerFrame/InnerWindow */
+        public void setMinimumSize(int minx, int miny, boolean resizable) {
+               if (frame != null) frame.setResizable(resizable);
+               // FEATURE: Java 1.5
+               //window.setMinimumSize(new 
Dimension(root.minwidth+leftInset+rightInset, 
root.minheight+topInset+bottomInset));
+        }
 
         private int oldfill = 0x0;
         public void render() {
-            // useful optimizatin;
+            // useful optimisation;
             if (oldfill != root.fillcolor) {
                 oldfill = root.fillcolor;
                 window.setBackground((root.fillcolor & 0xFF000000) == 0 ?
@@ -442,6 +462,15 @@
 
         AWTSurface(Box root, boolean framed) {
             super(root);
+            /*
+            // fill the backbuffer with the root colour to prevent early 
flicker
+            // NOTE: is this really necessary?
+               AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
+               buf.g.setColor(new java.awt.Color((root.fillcolor >> 16) & 0xff,
+                    (root.fillcolor >> 8) & 0xff,
+                    (root.fillcolor) & 0xff));
+               buf.g.fillRect(0, 0, pendingWidth, pendingHeight);
+               */
             try {
                 if (framed) window = frame = new InnerFrame();
                 else window = new InnerWindow();
@@ -520,7 +549,7 @@
         // MessageQueue thread. As a result, they must be *extremely*
         // careful about invoking methods on instances of Box. Currently,
         // they should only enqueue messages, use Box.whoIs()
-        // (unsynchronized but thought to be safe), and modify members of
+        // (unsynchronised but thought to be safe), and modify members of
         // Surface.
         
         public void componentHidden(ComponentEvent e) { }
@@ -543,35 +572,29 @@
             componentResized(window.getWidth() - leftInset - rightInset, 
window.getHeight() - topInset - bottomInset);
         }
 
-        private int oldwidth = 0, oldheight = 0;
         public void componentResized(int newwidth, int newheight) {
                // First we fill the expanded part of the buffer before
                // an old (dirty) copy of that buffer part gets painted
-               // FIXME: whilst this improves things significantly that
-               // without it, there is still a black artifact in the
-               // corner that appears on occasion - but why !?
                AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
                buf.g.setColor(new java.awt.Color((root.fillcolor >> 16) & 0xff,
                     (root.fillcolor >> 8) & 0xff,
                     (root.fillcolor) & 0xff));
-               if (oldwidth < newwidth) {
-                       buf.g.fillRect(oldwidth, 0, newwidth, newheight);
-                       dirty(oldwidth, 0, newwidth-oldwidth, newheight);
+               if (pendingWidth < newwidth) {
+                       buf.g.fillRect(pendingWidth, 0, newwidth, newheight);
+                       dirty(pendingWidth, 0, newwidth-pendingWidth, 
newheight);
                }
-               if (oldheight < newheight) {
-                       buf.g.fillRect(0, oldheight, newwidth, newheight);
-                       dirty(0, oldheight, newwidth, newheight-oldheight);
+               if (pendingHeight < newheight) {
+                       buf.g.fillRect(0, pendingHeight, newwidth, newheight);
+                       dirty(0, pendingHeight, newwidth, 
newheight-pendingHeight);
                }
-               oldwidth = newwidth;
-               oldheight = newheight;
                SizeChange(newwidth, newheight);
         }
 
         public void keyTyped(KeyEvent k) { 
                // REMARK - we are a so called 'passive Input Method' client.
-               // We receive composed text (e.g. asian characters) as keytyped
-               // events where we want to convert them into a 
keypressed/keyreleased
-               // vexi event. Unfortunately we need a way to distinguish 
between 
+               // We receive composed text (e.g. asian characters) as key 
events
+               // where we want to convert them into a keypressed/keyreleased
+               // Vexi event. Unfortunately we need a way to distinguish 
between 
                // events due to inputMethods (which we want) and those from the
                // keyboard which are already handled via 
keyPressed/keyReleased.
             // HACK Simplest is to just except non-ascii chars.
@@ -680,7 +703,7 @@
     }
 }
 /* FOOTNOTES
- * 1. Passive InputMethod Client - means: we only handle commited text. 
+ * 1. Passive InputMethod Client - means: we only handle committed text. 
  * 
  * The alternative to be an 'Active InputMethod Client' would mean we have 
  * in place composition, this presents quite a lot of complexity. We would 
need to 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to