Update of /cvsroot/dynapi/dynapi/src/lib/dynapi/gui
In directory usw-pr-cvs1:/tmp/cvs-serv22640/src/lib/dynapi/gui

Modified Files:
        button.js dynimage.js label.js 
Log Message:
Label works in all browsers now. So does dynImage. Now NS4 button (in fact, the label 
) generates all clicks, even the missed ones ( remeber growable button in the button 
example, did not grow when clicked over the text. This was because as label cancels 
browser events when set to non-selectable, NS4 was not firing its click event. Made 
label generate one by itself.

Index: button.js
===================================================================
RCS file: /cvsroot/dynapi/dynapi/src/lib/dynapi/gui/button.js,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** button.js   2001/03/25 06:46:04     1.8
--- button.js   2001/03/26 16:57:00     1.9
***************
*** 39,44 ****
                var o = e.getTarget();
                //alert(o.w+' '+o.h);
                if (o.w==null && o.h==null) {
!                       if (o.label) o.setSize(o.label.w+4,o.label.h+4);
                        else if (o.imglyr) o.setSize(o.imglyr.w+4,o.imglyr.h+4);
                }
--- 39,48 ----
                var o = e.getTarget();
                //alert(o.w+' '+o.h);
+               if (o.label) o.setText(o.text)
                if (o.w==null && o.h==null) {
!                       if (o.label) {
!                               o.setSize(o.label.w+4,o.label.h+4);
!                               //alert(o.label.w)
!                       }
                        else if (o.imglyr) o.setSize(o.imglyr.w+4,o.imglyr.h+4);
                }
***************
*** 74,78 ****
  };
  Button.prototype = new DynLayer;
- 
  Button.prototype.setImage = function(imgObj) {
        this.img = imgObj;
--- 78,81 ----
***************
*** 82,87 ****
--- 85,92 ----
        }
        else this.imglyr.setImage(imgObj);
+       this.imglyr.addEventListener(Button.imglyrlistener); //added
  };
  Button.prototype.setText = function(text) {
+       this.text = text
        if (!this.label) {
                this.label = this.addChild(new Label(arguments[0]));
***************
*** 93,97 ****
        else {
                this.label.setText(text);
!               this.label.packWidth();
        }
        this.recenter();
--- 98,102 ----
        else {
                this.label.setText(text);
!               this.label.pack();
        }
        this.recenter();
***************
*** 127,128 ****
--- 132,138 ----
        this.setBgColor("#CECECE");
  };
+ Button.imglyrlistener=new EventListener();
+ Button.imglyrlistener.onresize=function(e){
+       var o = e.getSource();
+       o.w=o.img.width; o.h=o.img.height; o.parent.recenter();
+ }
\ No newline at end of file

Index: dynimage.js
===================================================================
RCS file: /cvsroot/dynapi/dynapi/src/lib/dynapi/gui/dynimage.js,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** dynimage.js 2001/03/26 02:42:14     1.18
--- dynimage.js 2001/03/26 16:57:00     1.19
***************
*** 11,22 ****
  function DynImage() {
        this.DynLayer = DynLayer;
!       this.DynLayer();        
!       if (typeof(arguments[0])=="string") this.setImageSrc(arguments[0]); 
!       else if (typeof(arguments[0])=="object") this.setImage(arguments[0]); 
        else this.img = null;
        this.addEventListener(DynImage.listener);
  };
  DynImage.prototype = new DynLayer;
  DynImage.listener = new EventListener();
  DynImage.listener.onprecreate = function(e) {
        var o = e.getSource();
--- 11,29 ----
  function DynImage() {
        this.DynLayer = DynLayer;
!       this.DynLayer();
!       
!       if (typeof(arguments[0])=="string") this.setImageSrc(arguments[0]); // 
DynImage("source")
!       else if (typeof(arguments[0])=="object") this.setImage(arguments[0]); // 
DynImage(imgObj)
        else this.img = null;
+       if (typeof(this.img.dynimages.slice)=="function") {
+         this.img.dynimages[this.img.dynimages.length]=this;
+       this.imgresize=true;
+       }
        this.addEventListener(DynImage.listener);
  };
  DynImage.prototype = new DynLayer;
+ 
  DynImage.listener = new EventListener();
+ 
  DynImage.listener.onprecreate = function(e) {
        var o = e.getSource();
***************
*** 25,28 ****
--- 32,36 ----
        }
  };
+ 
  DynImage.listener.onresize = function (e) {
        var o = e.getSource();
***************
*** 33,40 ****
--- 41,54 ----
        }
  };
+ 
+ // this is an optional method that only effects the behaviour on subsequent image 
+changes.
+ // During the first creation of DynImage if no w/h is set it will automatically 
+resize
+ // during creation regardless of whether this value is set or not (that is a 
+function of the DynLayer).
+ // If you setAutoResize(true) when you change images after creation it will resize 
+itself again.
  DynImage.prototype.setAutoResize = function (b) {
        this.autoResize = b;
        if (this.created) this.setImage(this.img);
  };
+ 
  DynImage.prototype.setImage = function (imgObject,bRedraw) {
        if (!imgObject) {
***************
*** 42,46 ****
        }
        this.img = imgObject;
!       this.img.dynimage = this;
        if (this.created && this.autoResize && !bRedraw) {
                if (this.img.width!=this.w && this.img.height!=this.h) {
--- 56,60 ----
        }
        this.img = imgObject;
! 
        if (this.created && this.autoResize && !bRedraw) {
                if (this.img.width!=this.w && this.img.height!=this.h) {
***************
*** 49,52 ****
--- 63,67 ----
                }
        }
+ 
        if (!this.created || bRedraw) {
                var wh = ((this.w!=null && this.h!=null)) ? ' width='+this.w+' 
height='+this.h : '';
***************
*** 68,72 ****
        return this.img? this.img.src : null;
  };
! // Static Methods
  DynImage.loadimages=[];
  DynImage.getImage=function(src,w,h) {
--- 83,89 ----
        return this.img? this.img.src : null;
  };
! 
! // Functions
! 
  DynImage.loadimages=[];
  DynImage.getImage=function(src,w,h) {
***************
*** 80,85 ****
        DynImage.loadimages[i].complete = false;
        DynImage.loadimages[i].img.src=DynImage.loadimages[i].origsrc=src;
!       DynImage.loadimages[i].img.w=DynImage.loadimages[i].img.width;
!       DynImage.loadimages[i].img.h=DynImage.loadimages[i].img.height;
        return DynImage.loadimages[i].img;
  };
--- 97,102 ----
        DynImage.loadimages[i].complete = false;
        DynImage.loadimages[i].img.src=DynImage.loadimages[i].origsrc=src;
!       DynImage.loadimages[i].img.dynimages=[];
!       if (DynAPI.loaded && !DynImage.timerId) DynImage.loaderStart();
        return DynImage.loadimages[i].img;
  };
***************
*** 96,106 ****
                DynImage.timerId=setTimeout('DynImage.loadercheck()',25);
        }
!       else {
!               for (var i=0; i<DynImage.loadimages.length; i++) {
!                       if (DynImage.loadimages[i].img.dynimage) {
!                               
DynImage.loadimages[i].img.dynimage.setSize(DynImage.loadimages[i].img.w,DynImage.loadimages[i].img.h,true)
                        }
                }
!               if (DynImage.onLoaderDone) DynImage.onLoaderDone();
        }
  };
--- 113,133 ----
                DynImage.timerId=setTimeout('DynImage.loadercheck()',25);
        }
!       else {  
!       for (var i=0; i<DynImage.loadimages.length; i++) {
!               if (DynImage.loadimages[i].img.dynimages) {
!                       var dlen=DynImage.loadimages[i].img.dynimages.length;
!                       var j;
!                       for (j=dlen-1;j>=0;j--){
!                               if (DynImage.loadimages[i].img.dynimages[j] && 
DynImage.loadimages[i].img.dynimages[j].imgresize) {
!                                       
DynImage.loadimages[i].img.dynimages[j].setSize(DynImage.loadimages[i].img.width,DynImage.loadimages[i].img.height,false);
!                                       
DynImage.loadimages[i].img.dynimages[j].imgresize=false;
!                                       DynImage.loadimages[i].img.dynimages[j]=null;
!                                       }
!                               }
!                       DynImage.loadimages[i].img.dynimages=null;
                        }
                }
!       if (DynImage.onLoaderDone) DynImage.onLoaderDone();
!       DynImage.timerId=null;
        }
  };

Index: label.js
===================================================================
RCS file: /cvsroot/dynapi/dynapi/src/lib/dynapi/gui/label.js,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** label.js    2001/02/15 19:10:04     1.12
--- label.js    2001/03/26 16:57:00     1.13
***************
*** 21,29 ****
        this.pHeight = false;
        this.selectable = true;
-       // NS6 dirty patch. Store old content's size in order to detect changes
-       this.oldCW = this.oldCH = 0;
-       this.contentChecker = null;
-       this.timeOut = 0;
-       this.packPending = null;
        this.setText(text);
  
--- 21,24 ----
***************
*** 36,43 ****
                        }
                }
-               if(is.ns6) {
-                       o.setText(o.text)
-                       //o.setSize(o.getContentWidth(),o.getContentHeight())
-                       }
        };
        listener.onresize = function(e) {
--- 31,34 ----
***************
*** 45,49 ****
                if (o.created) {
                        if(is.ns&&o.wrap) o.setText(o.text)
!                       
if(!is.ns6&&o.getWidth()!=null)o.pack(o.wrap&&o.pWidth,o.pHeight)
                }
        };
--- 36,40 ----
                if (o.created) {
                        if(is.ns&&o.wrap) o.setText(o.text)
!                       if(o.getWidth()!=null)o.pack(o.wrap&&o.pWidth,o.pHeight)
                }
        };
***************
*** 58,61 ****
--- 49,58 ----
        this.selectListener.onmouseup = function(e) {
                e.cancelBrowserEvent();
+               // This is needed because since mousedown are cancelled, NS does not 
+generate its own 'click' event
+               if(is.ns4) {
+                       var ne = new DynMouseEvent(e)
+                       ne.type = 'click'
+                       e.getSource().invokeEvent('click',ne)
+               }
        };
  };
***************
*** 72,97 ****
  
        this.setHTML(this.textFull);
-       if(is.ns6) {
-               // Start interval contentsize update process. Will have to synchonize 
with any pack() calls
-               this.oldCW = this.getContentWidth()
-               this.oldCH = this.getContentHeight()
-               this.timeOut = 3
-               if(!this.contentChecker) {
-                       //debug(text)
-                       this.contentChecker = setInterval(this+".MozChkCnt()",50)
-                       }
-               }
  };
- Label.prototype.MozChkCnt = function() {
-       if(this.getContentWidth()!=this.oldCW || this.getContentWidth()!=this.oldCH) {
-               this.timeOut = 0
-               //debug('canvi')
-               if(this.packPending!=null) { eval(this.packPending); 
this.packPending=null; }
-       } else {
-               //debug('nya')
-               this.timeOut--;
-               }
-       if(this.timeOut==0) { clearInterval(this.contentChecker); 
this.contentChecker=null; }
- };
  Label.prototype.setFontFamily = function(f,noevt) {
        this.font.family = f;
--- 69,73 ----
***************
*** 155,166 ****
        this.pWidth = bWidth;
        this.pHeight = bHeight;
!       if(is.ns6&&this.timeOut!=0&&(bWidth||bHeight)) {
!               this.packPending = "this.pack("+bWidth+","+bHeight+")"
!               //debug(this.packPending)
!       } else {
!               var w = bWidth? this.getContentWidth() : this.w;
!               var h = bHeight? this.getContentHeight() : this.h;
!               //debug(h)
!               if (this.created) this.setSize(w,h,false);
!       }
  };
--- 131,136 ----
        this.pWidth = bWidth;
        this.pHeight = bHeight;
!       var w = bWidth? this.getContentWidth() : this.w;
!       var h = bHeight? this.getContentHeight() : this.h;
!       if (this.created) this.setSize(w,h,false);
  };


_______________________________________________
Dynapi-CVS mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-cvs

Reply via email to