Author: hqm
Date: 2008-02-06 14:44:55 -0800 (Wed, 06 Feb 2008)
New Revision: 7968

Modified:
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/Library.lzs
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/LzState.js
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/services/LzModeManager.js
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js
   openlaszlo/branches/devildog/test/swf9/hello.lzx
Log:
Change 20080206-hqm-d by [EMAIL PROTECTED] on 2008-02-06 17:37:56 EST
    in /Users/hqm/openlaszlo/devildog
    for http://svn.openlaszlo.org/openlaszlo/branches/devildog

Summary: improve mouse event handling

New Features:

Bugs Fixed:

Technical Reviewer: max 
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    
for clickable views, capture mouse events in the capture phase, and use 
event.stopPropagation() to keep them from triggering ancestor views. 

Use the Textfield object itself to catch mouse clicks for LzTextSprite

Also, partially ported LzState for swf9, not done yet

Tests:

hello.lzx updated with some clickable text



Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/Library.lzs
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/Library.lzs    
2008-02-06 21:43:25 UTC (rev 7967)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/Library.lzs    
2008-02-06 22:44:55 UTC (rev 7968)
@@ -28,7 +28,7 @@
 }
 
 if ($swf9) {
-    //    #include "helpers/LzState.js"
+    #include "helpers/LzState.js"
 } else {
     #include "helpers/LzState.lzs"
 }

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/LzState.js
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/LzState.js     
2008-02-06 21:43:25 UTC (rev 7967)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/helpers/LzState.js     
2008-02-06 22:44:55 UTC (rev 7968)
@@ -153,7 +153,7 @@
   * @access private
   */
 override function construct ( parent , args ){
-    super.construct.apply(this, arguments);
+    super.construct(parent, args);
     this.heldArgs = {};
     this.appliedChildren = [];
     this.isapplied = false;
@@ -204,6 +204,8 @@
   * has no effect
   */
 function apply ( ){
+    trace ('calling apply', this);
+    return;
     //@field Boolean isapplied: true if the state is currently applied
     if ( this.isapplied ){
         return;
@@ -215,6 +217,7 @@
     var od = this.parent.__LZdelegates;
     this.parent.__LZdelegates = null;
 
+    trace ('...parent.__LZapplyArgs', lzutils.objAsString(this.heldArgs));
     this.parent.__LZapplyArgs( this.heldArgs );
 
     if (this.subh) var shl = this.subh.length;
@@ -245,6 +248,7 @@
   * were changed by the state
   */
 function remove () {
+    trace('calling remove', this);
     if ( !this.isapplied ){
         return;
     }
@@ -252,6 +256,7 @@
     if (this.onremove.ready) this.onremove.sendEvent( this );
     this.isapplied = false;
 
+    trace('....calling remove unregistering delegates', 
lzutils.objAsString(this.__LZstatedelegates));
     if (this.__LZstatedelegates) {
         for ( var i = 0; i < this.__LZstatedelegates.length; i++ ){
             this.__LZstatedelegates[ i ].unregisterAll();

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as        
2008-02-06 21:43:25 UTC (rev 7967)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as        
2008-02-06 22:44:55 UTC (rev 7968)
@@ -244,48 +244,52 @@
       
       //// Mouse event trampoline
       public function attachMouseEvents(dobj:DisplayObject) {
-          dobj.addEventListener(MouseEvent.CLICK, handleMouse_CLICK);
-          dobj.addEventListener(MouseEvent.DOUBLE_CLICK, 
handleMouse_DOUBLE_CLICK);
-          dobj.addEventListener(MouseEvent.MOUSE_DOWN, handleMouse_MOUSE_DOWN);
-          dobj.addEventListener(MouseEvent.MOUSE_UP, handleMouse_MOUSE_UP);
-          dobj.addEventListener(MouseEvent.MOUSE_OVER, handleMouse_MOUSE_OVER);
-          dobj.addEventListener(MouseEvent.MOUSE_OUT, handleMouse_MOUSE_OUT);
+          dobj.addEventListener(MouseEvent.CLICK, handleMouse_CLICK, false);
+          dobj.addEventListener(MouseEvent.DOUBLE_CLICK, 
handleMouse_DOUBLE_CLICK, false);
+          dobj.addEventListener(MouseEvent.MOUSE_DOWN, handleMouse_MOUSE_DOWN, 
false);
+          dobj.addEventListener(MouseEvent.MOUSE_UP, handleMouse_MOUSE_UP, 
false);
+          dobj.addEventListener(MouseEvent.MOUSE_OVER, handleMouse_MOUSE_OVER, 
false);
+          dobj.addEventListener(MouseEvent.MOUSE_OUT, handleMouse_MOUSE_OUT, 
false);
       }
 
+      public function removeMouseEvents(dobj:DisplayObject) {
+          dobj.removeEventListener(MouseEvent.CLICK, handleMouse_CLICK, false);
+          dobj.removeEventListener(MouseEvent.DOUBLE_CLICK, 
handleMouse_DOUBLE_CLICK, false);
+          dobj.removeEventListener(MouseEvent.MOUSE_DOWN, 
handleMouse_MOUSE_DOWN, false);
+          dobj.removeEventListener(MouseEvent.MOUSE_UP, handleMouse_MOUSE_UP, 
false);
+          dobj.removeEventListener(MouseEvent.MOUSE_OVER, 
handleMouse_MOUSE_OVER, false);
+          dobj.removeEventListener(MouseEvent.MOUSE_OUT, 
handleMouse_MOUSE_OUT, false);
+      }
+
+
       public function handleMouse_CLICK (event:MouseEvent) {
-          if (event.eventPhase == EventPhase.AT_TARGET) {
-              LzModeManager.handleMouseEvent( owner, 'onclick');
-          }
+          LzModeManager.handleMouseEvent( owner, 'onclick');
+          event.stopPropagation();
       }
 
       public function handleMouse_DOUBLE_CLICK (event:MouseEvent) {
-          if (event.eventPhase == EventPhase.AT_TARGET) {
-              LzModeManager.handleMouseEvent( owner, 'ondblclick');
-          }
+          LzModeManager.handleMouseEvent( owner, 'ondblclick');
+          event.stopPropagation();
       }
 
       public function handleMouse_MOUSE_DOWN (event:MouseEvent) {
-          if (event.eventPhase == EventPhase.AT_TARGET) {
-              LzModeManager.handleMouseEvent( owner, 'onmousedown');
-          }
+          LzModeManager.handleMouseEvent( owner, 'onmousedown');
+          event.stopPropagation();
       }
 
       public function handleMouse_MOUSE_UP (event:MouseEvent) {
-          if (event.eventPhase == EventPhase.AT_TARGET) {
-              LzModeManager.handleMouseEvent( owner, 'onmouseup');
-          }
+          LzModeManager.handleMouseEvent( owner, 'onmouseup');
+          event.stopPropagation();
       }
 
       public function handleMouse_MOUSE_OVER (event:MouseEvent) {
-          if (event.eventPhase == EventPhase.AT_TARGET) {
-              LzModeManager.handleMouseEvent( owner, 'onmouseover');
-          }
+          LzModeManager.handleMouseEvent( owner, 'onmouseover');
+          event.stopPropagation();
       }
 
       public function handleMouse_MOUSE_OUT (event:MouseEvent) {
-          if (event.eventPhase == EventPhase.AT_TARGET) {
-              LzModeManager.handleMouseEvent( owner, 'onmouseout');
-          }
+          LzModeManager.handleMouseEvent( owner, 'onmouseout');
+          event.stopPropagation();
       }
 
 
@@ -324,7 +328,9 @@
               attachMouseEvents(cb);
           } else {
               this.buttonMode = false;
+              removeMouseEvents(this);
               if (cb) {
+                  removeMouseEvents(cb);
                   removeChild(cb);
               }
 
@@ -486,13 +492,13 @@
               addChild(ms);
               this.mask = ms;
               this.masksprite = ms;
-              trace('applyMask [1] ', this.lzwidth, this.lzheight, owner);
+              //trace('applyMask [1] ', this.lzwidth, this.lzheight, owner);
           } else {
               if (this.mask == null) {
                   addChild(ms);
                   this.mask = ms;
               }
-              trace('applyMask [2] ', this.lzwidth, this.lzheight, owner);
+              //trace('applyMask [2] ', this.lzwidth, this.lzheight, owner);
               ms.scaleX = this.lzwidth;
               ms.scaleY = this.lzheight;
           }
@@ -509,7 +515,7 @@
           o If axes is not 'width', 'height' or 'both', the resource is sized 
to its natural/default size, rather than the sprite's size 
       */
       public function stretchResource( xory:String ):void {
-          trace("stretchResource imgLoader="+imgLoader);
+          //trace("stretchResource imgLoader="+imgLoader);
           if ( xory == null || xory == "x" || xory=="width" || xory=="both" ){
               this._setrescwidth = true;
           }

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as    
2008-02-06 21:43:25 UTC (rev 7967)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as    
2008-02-06 22:44:55 UTC (rev 7968)
@@ -54,7 +54,20 @@
             this.textfield = createTextField(0,0,400,20);
         }
 
+        
+        override public function setClickable( c:Boolean ):void {
+          if (this.clickable == c) return;
 
+          this.textfield.mouseEnabled = c;
+
+          this.clickable = c;
+          if (c) {
+              attachMouseEvents(this.textfield);
+          } else {
+              removeMouseEvents(this.textfield);
+          }
+      }
+
         override public function setWidth( w:* ):void {
             super.setWidth(w);
             if (w) {

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/services/LzModeManager.js
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/services/LzModeManager.js      
2008-02-06 21:43:25 UTC (rev 7967)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/services/LzModeManager.js      
2008-02-06 22:44:55 UTC (rev 7968)
@@ -122,10 +122,8 @@
   */
 static function handleMouseEvent ( view, eventStr ) {
     //Debug.warn("%w, %w", view , eventStr);
-
     if (eventStr == "onmouseup") LzTrack.__LZmouseup();
 
-
     var dosend = true;
     var isinputtext = false;
 

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js    
2008-02-06 21:43:25 UTC (rev 7967)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js    
2008-02-06 22:44:55 UTC (rev 7968)
@@ -1074,8 +1074,35 @@
     return this.height;
 }
 
-    function __LZcheckSize ( sview, axis , xory ){}
+/** @access private */
+function __LZcheckSize ( sview, axis , xory ){
 
+        if ( sview.addedToParent ) {
+            if ( sview.__LZhasoffset || sview.rotation != 0 ){
+                var bobj = sview.getBounds();
+            } else {
+                var bobj = sview;
+            }
+            var ss = bobj[ xory ] + bobj[ axis ];
+
+            //calculating unstretchedsize (for stretches) or just size?
+            var ts = this[ "_setresc" + axis ] ?
+                     this[ "unstretched" + axis ] : this[axis];
+
+            if ( ss > ts && sview.visible ){
+                this[ "__LZoutlie" + axis ] = sview;
+                if (axis == "width")
+                    this.updateWidth(ss);
+                else
+                    this.updateHeight(ss);
+            } else if ( this[ "__LZoutlie" + axis ] == sview
+                        && ( ss < ts || ! sview.visible ) ){
+                //uhoh -- we need to recheck everything
+                this.reevaluateSize( axis );
+            }
+        }
+}
+
 function __LZcheckwidthFunction ( sview )
 {
     this.__LZcheckSize (sview, "width", "x");

Modified: openlaszlo/branches/devildog/test/swf9/hello.lzx
===================================================================
--- openlaszlo/branches/devildog/test/swf9/hello.lzx    2008-02-06 21:43:25 UTC 
(rev 7967)
+++ openlaszlo/branches/devildog/test/swf9/hello.lzx    2008-02-06 22:44:55 UTC 
(rev 7968)
@@ -23,12 +23,15 @@
 
   <attribute name="somey" value="500"/>
 
+  <method name="showText" args="msg">
+    new LzText(canvas, {x: 200, y: canvas.somey, text: msg});
+    canvas.somey += 20;
+  </method>
 
   <view x="200" y="150" resource="http://www.beartronics.com/swf9/logo.swf"; 
         onclick="this.animate('rotation', 45, 1000, true)">
     <handler name="onclick">
-      new LzText(canvas, {x: 200, y: canvas.somey, text: "You clicked me"});
-      canvas.somey += 20;
+      canvas.showText("You clicked me!");
     </handler>
   </view>
 
@@ -73,10 +76,14 @@
 
   <text fontsize="11" x="500" y="200" bgcolor="#cccccc">aaa bbb ccc ddd eee 
fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq</text>
 
-  <text fontsize="11" x="500" y="240"
-        width="100" bgcolor="#ffcccc" clip="true">aaa bbb ccc ddd eee fff ggg 
hhh iii jjj kkk lll mmm nnn ooo ppp qqq</text>
+  <text fontsize="11" x="500" y="240" selectable="true"
+        width="100" bgcolor="#ffcccc" clip="true">I am selectable bbb ccc ddd 
eee fff ggg hhh iii jjj kkk lll</text>
 
 
+  <text fontsize="11" x="650" y="240" onclick="canvas.showText('clicked on 
clickable text')"
+        width="100" bgcolor="#ffccaa">I am clickable text</text>
+
+
   <inputtext fontsize="11" x="500" y="270"
         width="250" bgcolor="#cccccc" >this is input text aaa bbb ccc ddd eee 
fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq</inputtext>
 


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to