Revision: 1655
          http://svn.sourceforge.net/vexi/?rev=1655&view=rev
Author:   clrg
Date:     2007-01-19 09:12:28 -0800 (Fri, 19 Jan 2007)

Log Message:
-----------
A surface position now takes into account the alignment of the root box

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

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp  2007-01-11 15:54:52 UTC 
(rev 1654)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp  2007-01-19 17:12:28 UTC 
(rev 1655)
@@ -156,6 +156,9 @@
         }
         //#end
     }
+    //#repeat leftAlign/topAlign/bottomAlign/rightAlign 
ALIGN_LEFT/ALIGN_TOP/ALIGN_BOTTOM/ALIGN_RIGHT
+    protected final boolean leftAlign() { return test(ALIGN_LEFT); }
+    //#end
 
 
     // Flags 
//////////////////////////////////////////////////////////////////////
@@ -1270,7 +1273,7 @@
         case "x":
             if (parent == null && getSurface()!=null) {
                 this.x = JSU.toInt(value);
-                getSurface().setLocation();
+                getSurface().setPocation();
             }
             else if (!test(PACKED)) { dirty(); x = JSU.toInt(value); dirty(); 
setReconstrain(); }
         case "y":

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Surface.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Surface.java     2007-01-11 
15:54:52 UTC (rev 1654)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Surface.java     2007-01-19 
17:12:28 UTC (rev 1655)
@@ -64,6 +64,11 @@
     public boolean maximized = false;                  ///< True iff this 
surface is maximized, in real time
     DirtyList dirtyRegions = new DirtyList();          ///< Dirty regions on 
the surface
 
+    public int topInset = 0;
+    public int leftInset = 0;
+    public int bottomInset = 0;
+    public int rightInset = 0;
+
     // Used For Simulating Clicks and DoubleClicks 
/////////////////////////////////////////////////
 
     int last_press_x = Integer.MAX_VALUE;      ///< the x-position of the 
mouse the last time a Press message was enqueued
@@ -183,6 +188,7 @@
         pendingHeight = height;
         syncRootWithSurface = true;
         abort = true;
+        setPosition();
         Refresh();
     }
 
@@ -207,6 +213,29 @@
             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;
+        }
+        // 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;
+        }
+        // propogate to frame/window
+        setLocation();
+    }
 
     private final String[] doubleClick = new String[] { null, "_DoubleClick1", 
"_DoubleClick2", "_DoubleClick3" };
     protected final void DoubleClick(int button) { new 
Message(doubleClick[button], T, root); }
@@ -258,11 +287,11 @@
     public Surface(Box root) {
         this.root = root;
         // TODO: document this in the reference
-        // FIXME: these should trigger read traps
         if (root.maxwidth == Integer.MAX_VALUE)
             root.setMinMaxWidth(root.minwidth, Platform.getScreenWidth() / 2);
         if (root.maxheight == Integer.MAX_VALUE)
             root.setMinMaxHeight(root.minheight, Platform.getScreenHeight() / 
2);
+        setPosition();
         Surface old = fromBox(root);
         if (old != null) old.dispose(false);
         else try {

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp 2007-01-11 15:54:52 UTC 
(rev 1654)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp 2007-01-19 17:12:28 UTC 
(rev 1655)
@@ -196,6 +196,20 @@
                     break;
                 case 1:
                     //#switch(JSU.toString(method))
+                    case "ui.insets":
+                        if(args[0] == null) throw new JSExn("can't discern 
insets for a null frame");
+                        Box b = null;
+                        try{ b = (Box)args[0]; }
+                        catch(ClassCastException cce) { throw new JSExn("can't 
discern insets for non-box '"+args[0]+"'"); }
+                        Surface s = null;
+                        try{ s = b.getSurface(); }
+                        catch(ClassCastException cce) { throw new JSExn("can't 
discern insets for box not attached to a surface"); }
+                        JS ret = new JS.Obj();
+                        ret.put(JSU.S("top"), JSU.N(s.topInset));
+                        ret.put(JSU.S("left"), JSU.N(s.leftInset));
+                        ret.put(JSU.S("bottom"), JSU.N(s.bottomInset));
+                        ret.put(JSU.S("right"), JSU.N(s.rightInset));
+                        return ret;
                     case "clone":
                         if(args[0] == null) throw new JSExn("can't clone the 
null value");
                         return new JS.Clone(args[0]);

Modified: core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java 2007-01-11 15:54:52 UTC 
(rev 1654)
+++ core/trunk/org.vexi.core/src/org/vexi/plat/AWT.java 2007-01-19 17:12:28 UTC 
(rev 1655)
@@ -320,12 +320,12 @@
         implements MouseListener, MouseMotionListener, KeyListener, 
ComponentListener, WindowListener {
 
         public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int 
dx2, int dy2) {
-            insets = (frame == null ? window : frame).getInsets();
+            discoverInsets();
             window.getGraphics().drawImage(((AWTPixelBuffer)s).i,
-                                  dx + insets.left,
-                                  dy + insets.top,
-                                  dx2 + insets.left,
-                                  dy2 + insets.top,
+                                  dx + leftInset,
+                                  dy + topInset,
+                                  dx2 + leftInset,
+                                  dy2 + topInset,
                                   sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), 
null);
         }
         
@@ -334,17 +334,17 @@
         Window window = null;
         
         /** our component's insets */
-        protected Insets insets = new Insets(0, 0, 0, 0);
+        //protected Insets insets = new Insets(0, 0, 0, 0);
         
         /** some JDKs let us recycle a single Dimension object when calling 
getSize() */
         Dimension singleSize = new Dimension();
         
         public void toBack() { if (window != null) window.toBack(); }
         public void toFront() { if (window != null) window.toFront(); }
-        public void setLocation() { window.setLocation(root.x, root.y); }
+        public void setLocation() { if (window != null) window.setLocation(x, 
y); }
         public void setTitleBarText(String s) { if (frame != null) 
frame.setTitle(s); }
         public void setIcon(Picture i) { if (frame != null) 
frame.setIconImage(((AWTPicture)i).i); }
-        public void _setSize(int width, int height) { insets = 
window.getInsets(); window.setSize(width + (insets.left + insets.right), height 
+ (insets.top + insets.bottom)); }
+        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) { if (Log.on) Log.info(this, 
"JDK 1.1 platforms cannot minimize or unminimize windows"); }
         protected void _setMaximized(boolean b) {
@@ -365,13 +365,13 @@
                 Rectangle r = gr.getClipBounds();
 
                 // ugly hack for Java1.4 dynamicLayout on Win32 -- this 
catches expansions during smooth resize
-                int newwidth = Math.max(r.x - insets.left + r.width, 
root.width);
-                int newheight = Math.max(r.y - insets.top + r.height, 
root.height);
+                int newwidth = Math.max(r.x - leftInset + r.width, root.width);
+                int newheight = Math.max(r.y - topInset + r.height, 
root.height);
                 if (newwidth > root.width || newheight > root.height)
-                    componentResized(window.getWidth() - insets.left - 
insets.right,
-                                     window.getHeight() - insets.top - 
insets.bottom);
+                    componentResized(window.getWidth() - leftInset - 
rightInset,
+                                     window.getHeight() - topInset - 
bottomInset);
 
-                refreshFromBackbuffer(r.x - insets.left, r.y - insets.top, 
r.width, r.height);
+                refreshFromBackbuffer(r.x - leftInset, r.y - topInset, 
r.width, r.height);
             }
         }
 
@@ -382,10 +382,21 @@
             public void update(Graphics gr) { paint(gr); }
             public void paint(Graphics gr) {
                 Rectangle r = gr.getClipBounds();
-                refreshFromBackbuffer(r.x - insets.left, r.y - insets.top, 
r.width, r.height);
+                refreshFromBackbuffer(r.x - leftInset, r.y - topInset, 
r.width, r.height);
             }
         }
 
+        private void discoverInsets() {
+            Insets i = (frame == null ? window : frame).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();
+        }
+
         public void setMinimumSize(int minx, int miny, boolean resizable) { if 
(frame != null) frame.setResizable(resizable); }
 
         private int oldfill = 0x0;
@@ -407,6 +418,7 @@
             try {
                 if (framed) window = frame = new InnerFrame();
                 else window = new InnerWindow();
+                setLocation();
 
             // this is here to catch HeadlessException on jdk1.4
             } catch (java.lang.UnsupportedOperationException e) {
@@ -426,8 +438,6 @@
             // Not setting size before showing the frame
             //setSize(root.maxwidth, root.maxheight);
 
-            setLocation();
-            
             window.addMouseListener(this);
             window.addKeyListener(this);
             window.addComponentListener(this);
@@ -495,8 +505,8 @@
                        // Before being set visible (AWT on top of XWindows at 
least) 
                        // after pack it seems AWT guesses what the insets will 
be
                // Take every time in case they change(?!)
-            insets = window.getInsets();
-            componentResized(window.getWidth() - insets.left - insets.right, 
window.getHeight() - insets.top - insets.bottom);
+            discoverInsets();
+            componentResized(window.getWidth() - leftInset - rightInset, 
window.getHeight() - topInset - bottomInset);
         }
 
         public void componentResized(int newwidth, int newheight) { 
SizeChange(newwidth, newheight); }
@@ -510,11 +520,11 @@
         public void mouseMoved(MouseEvent m) {
 
             // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches 
contractions during smooth resize
-            int newwidth = window.getWidth() - insets.left - insets.right;
-            int newheight = window.getHeight() - insets.top - insets.bottom;
+            int newwidth = window.getWidth() - leftInset - rightInset;
+            int newheight = window.getHeight() - topInset - bottomInset;
             if (newwidth != root.width || newheight != root.height) 
componentResized(newwidth, newheight);
             
-            Move(m.getX() - insets.left, m.getY() - insets.top);
+            Move(m.getX() - leftInset, m.getY() - topInset);
         }
         public void mousePressed(MouseEvent m) { 
Press(modifiersToButtonNumber(m.getModifiers())); }
         public void mouseReleased(MouseEvent m) { 
Release(modifiersToButtonNumber(m.getModifiers())); }


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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to