Update of /cvsroot/dynapi/dynapi2x/src/dynapi/gui
In directory usw-pr-cvs1:/tmp/cvs-serv15575/src/dynapi/gui
Added Files:
dynimage.js graphics.js loadpanel.js
Log Message:
Initial Import == 2.9
--- NEW FILE ---
/*
DynAPI Distribution
DynImage Class
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
DynImage = {};
DynImage.image = [];
DynImage.getImage = function(src,w,h) {
for (var i=0;i<DynImage.image.length;i++) {
if (DynImage.image[i].img.src==src) return DynImage.image[i].img;
}
var index = DynImage.image.length;
DynImage.image[index] = {};
if (w&&h) {
DynImage.image[index].img = new Image(w,h);
DynImage.image[index].img.w = w;
DynImage.image[index].img.h = h;
}
else DynImage.image[index].img = new Image();
DynImage.image[index].img.src = src;
if (!DynImage.timerId)
DynImage.timerId=setTimeout('DynImage.loadercheck()',50);
return DynImage.image[index].img;
}
DynImage.loadercheck=function() {
DynImage.ItemsDone=0;
var max=DynImage.image.length;
for (var i=0; i<max; i++) if (DynImage.image[i].img.complete)
DynImage.ItemsDone+=1;
if (DynImage.ItemsDone<max)
DynImage.timerId=setTimeout('DynImage.loadercheck()',25);
else {
if
(DynAPI.ua.def&&(!DynAPI.ua.ie||(DynAPI.ua.ie&&DynAPI.ua.platform=="mac"))) {
DynImage.image[i].img.width = DynImage.image[i].img.w;
DynImage.image[i].img.height = DynImage.image[i].img.h;
}
DynImage.timerId=null;
}
};
dynapi.onLoad(DynImage.loadercheck);
--- NEW FILE ---
// 2D Graphics Package
// Drawing routines for DynLayer
// Copyright (C) 2000-2001 Dan Steinman, Guoyi Chao, Rob Breeds
// Guoyi Chao: drawing routines for line, circle, ellipse
// Dan Steinman: DynAPI2 support, object wrappers, VML support, improved routines for
line, rect, and fills()
// Rob Breeds: improve performance on ellipse and circle algorithms, and added line
thicknesses support
// Distributed under the terms of the GNU Library General Public License
function Graphics(dlyr) {
this._dlyr = dlyr;
this._s = "yellow";
this._w = 1;
this._f = "white";
}
Graphics.prototype.setStrokeColor = function(v) {this._s = v};
Graphics.prototype.setStrokeWeight = function(v) {this._w = v};
Graphics.prototype.setFillColor = function(v) {this._f = v};
Graphics.prototype.drawPixel = function(x,y) {
drawPixel(x,y,this._s,this._w,this);
};
Graphics.prototype.drawLine = function(x1,y1,x2,y2) {
var shape;
if (Graphics.useVML) {
shape = new VML_Line(x1,y1,x2,y2,this._w,this._s);
this._dlyr.elm.appendChild(shape.elm);
}
else {
shape = new Line(x1,y1,x2,y2,this._w,this._s);
this._dlyr.addChild(shape);
}
return shape;
};
Graphics.prototype.drawCircle = function(x,y,radius) {
var shape;
if (Graphics.useVML) {
// bug in IE, always fills anyway
shape = new VML_Oval(x,y,2*radius,2*radius,this._w,this._s,
dynapi.ua.ie5?this._dlyr.bgColor:false);
this._dlyr.elm.appendChild(shape.elm);
}
else {
shape = new Circle(x,y,radius,this._w,this._s);
this._dlyr.addChild(shape);
}
return shape;
};
Graphics.prototype.fillCircle = function(x,y,r) {
fillCircle(x+r,y+r,r,this.color,this._dlyr);
};
Graphics.prototype.drawOval = function(x,y,w,h) {
drawEllipse(x+w/2,y+h/2,w,h,this.color,false,this.thickness,this._dlyr);
};
Graphics.prototype.fillEllipse = function(x,y,w,h) {
drawEllipse(x+w/2,y+h/2,w,h,this.color,true,this.thickness,this._dlyr);
};
Graphics.prototype.drawRect = function(x,y,w,h) {
drawRect(x,y,w,h,this.color,this.thickness,this._dlyr);
};
Graphics.prototype.fillRect = function(x,y,w,h) {
fillRect(x,y,w,h,this.color,this._dlyr);
};
Graphics.prototype.clear = function() {
this.deleteAllChildren();
this.setHTML('');
};
Graphics.useVML = false;
if (dynapi.ua.ie && dynapi.ua.v>=5) { // include active-x component for IE5+
Graphics.useVML = true;
var str = '<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>'+
'<object id="VMLRender" codebase="vgx.dll"
classid="CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E"></object>'+
'<style>'+
'<!--'+
'v\\:* { behavior: url(#VMLRender); }'+
'-->'+
'</style>';
if (dynapi.loaded) {
dynapi.frame.document.body.appendChild('beforeEnd',str);
}
else {
document.write(str);
}
}
// Drawing Routines
function Pixel(x,y,color,t) { // not really needed
this.DynLayer = DynLayer;
this.DynLayer();
this.setLocation(x,y);
this.setSize(t||1,t||1);
this.setBgColor(color||"black");
}
Pixel.prototype = new DynLayer();
function drawPixel(x,y,color,t,lyr) {
lyr.addChild( new DynLayer('',Math.round(x),Math.round(y),t,t,color) )
}
function Shape() {
this.DynLayer = DynLayer;
this.DynLayer();
this.setStrokeColor("black");
this.setStrokeWeight(1);
}
Shape.prototype = new DynLayer();
Shape.prototype.setStrokeColor = function(v) {this._s = v};
Shape.prototype.setStrokeWeight = function(v) {this._w = v};
function Line(x1,y1,x2,y2,w,s) {
this.Shape = Shape;
this.Shape();
this.setStrokeWeight(w);
this.setStrokeColor(s);
var dx = Math.min(x1,x2);
var dy = Math.min(y1,y2);
var width = Math.abs(x2-x1);
var height = Math.abs(y2-y1);
this.setLocation(dx, dy);
if(x1==x2||y1==y2) { // straight line
this.setBgColor(s);
if(x1==x2) this.setSize(w,height); // vertical
else this.setSize(width,w); //horizontal
}
else { // diagonal
this.setSize(width,height);
var nx1 = x1-dx;
var ny1 = y1-dy;
var nx2 = x2-dx;
var ny2 = y2-dy;
drawLine(nx1,ny1,nx2,ny2,s,w,this);
}
}
Line.prototype = new Shape();
function VMLElement() {
this.elm = null
};
VMLElement.prototype.createShape = function(type) {
this.elm = document.createElement('v:'+type);
}
VMLElement.prototype.setLocation = function() {};
function VML_Line(x1,y1,x2,y2,w,s) {
this.VMLElement = VMLElement;
this.VMLElement();
this.createShape("line");
this.elm.from = x1+'px ,'+y1+'px';
this.elm.to = x2+'px ,'+y2+'px';
this.elm.strokeColor = s;
this.elm.innerHTML = '<v:stroke weight="'+w+'px">';
//this.elm.innerHTML = '<v:stroke weight="'+this.thickness+'px"
color="'+this.color+'">';
//"<v:line id='line" + nnode + "' from=" + x1 + "," + y1 +"' to='" + x2 + ","
+ y2 +"'><v:stroke weight='2px' color='black'/></v:line>";
};
VML_Line.prototype = new VMLElement();
function VML_Oval(x,y,width,height,w,s,fc) {
this.VMLElement = VMLElement;
this.VMLElement();
this.elm = document.createElement('v:oval');
this.elm.style.position = "absolute";
this.elm.style.left = x+"px";
this.elm.style.top = y+"px";
this.elm.style.width = width+"px";
this.elm.style.height = height+"px";
this.elm.strokeColor = s;
if (fc) {
this.elm.fillColor = fc;
this.elm.fill = true;
}
else this.elm.fill = false;
this.elm.innerHTML = '<v:stroke weight="'+w+'px">';
};
VML_Oval.prototype = new VMLElement();
function drawLine(x1,y1,x2,y2,color,t,lyr) {
var flag = (Math.abs(y2-y1) > Math.abs(x2-x1))
var dx,dy,x,y,e,xstep,ystep
if (flag) dx=Math.abs(y2-y1),dy=Math.abs(x2-x1),x=y1,y=x1
else dx=Math.abs(x2-x1),dy=Math.abs(y2-y1),x=x1,y=y1
xstep=x1>x2?-1:1
ystep=y1>y2?-1:1
if(x1==x2||y1==y2) {
if(x1==x2) {
var ny1 = Math.min(y1,y2)
var ny2 = Math.max(y1,y2)
lyr.addChild( new DynLayer('',x1,ny1,t,(ny2-ny1)*t,color) )
return
}
else {
var nx1 = Math.min(x1,x2)
var nx2 = Math.max(x1,x2)
lyr.addChild( new DynLayer('',nx1,y1,(nx2-nx1)*t,t,color) )
return
}
}
// Bresenham Method Begin
var e=-dx
for(var count=0;count<=dx;count++) {
if (flag) drawPixel(y,x,color,t,lyr)
else drawPixel(x,y,color,t,lyr)
if (flag) x+=ystep
else x+=xstep
e+=dy<<1
if(e>=0) {
if(flag) y+=xstep
else y+=ystep
e-=dx<<1
}
}
return
}
function Circle(x,y,radius,w,s) {
this.Shape = Shape;
this.Shape();
this.setStrokeWeight(w);
this.setStrokeColor(s);
this.setLocation(x,y);
this.setSize(2*radius, 2*radius);
drawCircle(0+radius,0+radius,radius-1,this._s,this._w,this);
}
Circle.prototype = new Shape();
function drawCircle(centerX,centerY,radius,color,t,lyr) {
var x = centerX;
var y = centerY;
var cx = 0
var cy = radius
var df = 1 - radius
var d_e = 3
var d_se = -(radius<<1) + 5
do {
drawPixel(x+cx, y+cy, color,t,lyr)
if (cx) drawPixel(x-cx, y+cy, color,t,lyr)
if (cy) drawPixel(x+cx, y-cy, color,t,lyr)
if ((cx) && (cy)) drawPixel(x-cx, y-cy, color,t,lyr)
if (cx != cy) {
drawPixel(x+cy, y+cx, color,t,lyr)
if (cx) drawPixel(x+cy, y-cx, color,t,lyr)
if (cy) drawPixel(x-cy, y+cx, color,t,lyr)
if (cx && cy) drawPixel(x-cy, y-cx, color,t,lyr)
}
if (df < 0) {
df += d_e
d_e += 2
d_se += 2
}
else {
df += d_se
d_e += 2
d_se += 4
cy--
}
cx++
} while (cx <= cy)
}
function fillCircle(x,y,radius,color,lyr) {
var cx = 0
var cy = radius
var df = 1 - radius
var d_e = 3
var d_se = -(radius<<1) + 5
do {
fillRect(x-cy, y-cx, cy<<1, cx<<1, color,lyr)
if (df < 0) {
df += d_e
d_e += 2
d_se += 2
}
else {
if (cx != cy) fillRect(x-cx, y-cy, cx<<1, cy<<1, color,lyr)
df += d_se
d_e += 2
d_se += 4
cy--
}
cx++
} while (cx <= cy)
}
function drawEllipse(cx,cy,rx,ry,color,filled,t,lyr) {
var x,y,a2,b2, S, T
a2 = rx*rx
b2 = ry*ry
x = 0
y = ry
S = a2*(1-2*ry) + 2*b2
T = b2 - 2*a2*(2*ry-1)
symmPaint(cx,cy,x,y,color,filled,t,lyr)
do {
if (S<0) {
S += 2*b2*(2*x+3)
T += 4*b2*(x+1)
x++
} else if (T<0) {
S += 2*b2*(2*x+3) - 4*a2*(y-1)
T += 4*b2*(x+1) - 2*a2*(2*y-3)
x++
y--
} else {
S -= 4*a2*(y-1)
T -= 2*a2*(2*y-3)
y--
}
symmPaint(cx,cy,x,y,color,filled,t,lyr)
} while (y>0)
}
//Bresenham's algorithm for ellipses
function symmPaint(cx,cy, x, y, color, filled, t, lyr){
if (filled) {
fillRect ( cx-x, cy-y, x<<1, y<<1, color, lyr )
} else {
drawPixel ( cx-x, cy-y, color, t,lyr )
drawPixel ( cx+x, cy-y, color, t,lyr )
drawPixel ( cx-x, cy+y, color, t,lyr )
drawPixel ( cx+x, cy+y, color, t,lyr )
}
}
function drawRect(x,y,w,h,color,t,lyr) {
lyr.addChild( new DynLayer('',x,y,w,t,color) )
lyr.addChild( new DynLayer('',x,y,t,h,color) )
lyr.addChild( new DynLayer('',x+w-t,y,t,h,color) )
lyr.addChild( new DynLayer('',x,y+h-t,w,t,color) )
}
function fillRect(x,y,w,h,color,lyr) {
lyr.addChild( new DynLayer('',x,y,w,h,color) )
}
--- NEW FILE ---
/*
DynAPI Distribution
LoadPanel Class
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
Requirements:
dynapi.api [dynlayer, dyndocument, browser, events]
*/
function LoadPanel(url) {
this.DynLayer = DynLayer;
this.DynLayer();
this.autoH=true;
this.autoW=false;
this.isILayer=false;
this.isIFrame=!(dynapi.ua.ie5 && is.platform=='win32');
this._isReloading = false;
this.addEventListener(LoadPanel.events);
this.url = url;
};
LoadPanel.events = {
oncreate : function(e) {
var o = e.getSource();
if (!o._isReloading) {
o.setURL(o.url);
}
}
};
LoadPanel.prototype = new DynLayer();
LoadPanel.prototype._DynLayer_setSize = DynLayer.prototype.setSize;
LoadPanel.prototype.setSize = function(w,h) {
var r = this._DynLayer_setSize(w,h);
if (r && this._created && !this._isReloading && this.autoH && this.url)
this.reload();
};
LoadPanel.prototype.setAutoResizeWidth=function(b) {this.autoW=b};
LoadPanel.prototype.setAutoResizeHeight=function(b) {this.autoH=b};
LoadPanel.prototype.useILayer=function(b) {
if (dynapi.ua.ns4) {
this.isILayer=b;
if (this.created) this.reload();
}
};
LoadPanel.prototype.useIFrame=function(b) {
if (is.def) {
this.isIFrame=b;
if (this.created) this.reload();
}
};
LoadPanel.prototype.insertInlineElements=function() {
if (dynapi.ua.ie) {
if (this.isIFrame) this.setHTML('<IFRAME ID="'+this.id+'loadElement"
STYLE="visibility: hidden; display: none;"></IFRAME>',false);
else this.setHTML('<DIV ID="'+this.id+'loadElement"
STYLE="behavior:url(#default#download)" style="display: none;"></DIV>',false);
}
else if (dynapi.ua.ns4 && this.isILayer)
this.setHTML('<ilayer></ilayer>',false);
else if (dynapi.ua.ns6) this.setHTML('<IFRAME ID="'+this.id+'loadElement"
STYLE="visibility: hidden;"></IFRAME>',false);
};
LoadPanel.prototype.findInlineElements=function() {
if (dynapi.ua.ie) {
if (this.isIFrame)
this.loadElement=document.frames(this.id+'loadElement');
else this.loadElement=document.all(this.id+'loadElement');
alert(this.loadElement);
}
else if (dynapi.ua.ns4) {
if (this.isILayer) this.loadElement=this.doc.layers[0];
else this.loadElement=this.elm;
}
else if (dynapi.ua.ns6)
this.loadElement=document.getElementById(this.id+'loadElement');
};
LoadPanel.prototype.getFileScope=function() {
if (!this.loadElement) return null;
return this.loadElement;
};
LoadPanel.prototype.clearFile=function() {
this.url=null;
if (this.isILayer) {
this.loadElement.document.write('');
this.loadElement.document.close();
}
else this.reload();
};
LoadPanel.prototype.getURL=function() {
return this.url;
};
LoadPanel.prototype.setURL = function(url) {
alert('yo')
if (!url) return;
else if (!this._created) this.url = url;
else LoadPanel.queue.add(url,this);
};
LoadPanel.prototype.reload=function() {
this._isReloading=true;
this.setHTML('');
this.setURL(this.url);
this._isReloading=false;
};
LoadPanel.prototype.loadHandler=function(url) {
this.url=url;
if (dynapi.ua.ie5 && !this.isIFrame && this.elm && this.elm.all) {
var imgs = this.elm.all.tags("img");
for (var i=0;i<imgs.length;i++) {
if (imgs[i].readyState == 'uninitialized') imgs[i].src =
imgs[i].src;
}
}
if (dynapi.ua.ns4 && this.isILayer) {
var w = this.loadElement.document.width;
var h = this.loadElement.document.height;
}
else {
var w = this.getContentWidth()||this.w;
var h = this.getContentHeight()||this.h;
}
this._DynLayer_setSize(this.autoW?w:null,this.autoH?h:null);
this._isReloading=false;
this.invokeEvent('load');
};
function LoadQueue() {
this.queue=new Array();
this.index=0;
};
LoadQueue.prototype.toString=function() {
return "LoadPanel.queue";
};
LoadQueue.prototype.add=function(url,loadpanel) {
var q=this.queue.length;
this.queue[q]=[url,loadpanel];
this.loadNext();
};
LoadQueue.prototype.loadNext=function() {
dprint('loadnext')
if (!this.busy && this.queue[this.index]) {
this.busy=true;
var lpanel=this.currentLoadPanel=this.queue[this.index][1];
var url=this.currentURL=this.queue[this.index][0];
if (dynapi.ua.ns4) {
if (!lpanel.loadElement) {
lpanel.insertInlineElements();
lpanel.findInlineElements();
}
DynAPI.document.releaseMouseEvents();
var lyr=lpanel.elm;
while(lyr.parentLayer) lyr=lyr.parentLayer;
lyr.onload=LoadQueue.loadHandler;
lpanel.loadElement.onload=LoadQueue.loadHandler;
lpanel.loadElement.src=url;
} else {
if (!lpanel.loadElement) {
alert('no')
lpanel.insertInlineElements();
lpanel.findInlineElements();
}
if (dynapi.ua.ie) {
if (lpanel.isIFrame) {
lpanel.loadElement.document.isLoading=true;
lpanel.loadElement.location=url;
lpanel.timerID=setInterval(this.toString() +
'.loadTimer()',250);
}
else
lpanel.loadElement.startDownload(url,LoadQueue.loadHandler);
}
else if (dynapi.ua.ns6) {
lpanel.timerID=setInterval(this.toString() +
'.loadTimer()',250);
lpanel.loadElement.src=url;
}
}
Methods.removeFromArray(this.queue,this.index);
}
};
if (dynapi.ua.ns6) {
LoadQueue.prototype.loadTimer=function() {
var lpanel=this.currentLoadPanel;
if (!document.getElementById(lpanel.id+'loadElement')) {
clearInterval(lpanel.timerID);
LoadQueue.continueLoad();
}
else if (lpanel.loadElement.contentDocument &&
lpanel.loadElement.contentDocument.body.innerHTML != document.body.innerHTML) {
clearInterval(lpanel.timerID);
LoadQueue.loadHandler(lpanel.loadElement.contentDocument);
}
}
} else if (dynapi.ua.ie) {
LoadQueue.prototype.loadTimer=function() {
var lpanel=this.currentLoadPanel;
if (!document.frames(lpanel.id+'loadElement')) {
clearInterval(lpanel.timerID);
LoadQueue.continueLoad();
}
else if (!lpanel.loadElement.document.isLoading &&
(lpanel.loadElement.document.readyState=='interactive' ||
lpanel.loadElement.document.readyState=='complete')) {
clearInterval(lpanel.timerID);
LoadQueue.loadHandler(lpanel.loadElement.document.body.innerHTML);
}
}
}
LoadQueue.loadHandler=function(e) {
var q=LoadPanel.queue;
var lp=q.currentLoadPanel;
if (q.currentLoadPanel) {
if (dynapi.ua.ie) {
lp.elm.innerHTML=e;
if (lp.isIFrame) lp.loadElement=null;
}
else if (dynapi.ua.ns4) {
var lyr = lp.elm;
while(lyr.parentLayer != window) lyr = lyr.parentLayer;
lyr.onload = function(){};
lp.loadElement.onload = function(){};
}
else if (dynapi.ua.ns6) {
var html=e.body.innerHTML;
lp.elm.innerHTML=html;
lp.loadElement=null;
}
setTimeout('LoadQueue.continueLoad()',200);
}
};
LoadQueue.continueLoad=function() {
var q=LoadPanel.queue;
q.currentLoadPanel.loadHandler(q.currentURL);
q.busy=false;
if (q.queue[q.index]) q.loadNext();
else if (dynapi.ua.ns4) DynAPI.document.captureMouseEvents();
};
LoadPanel.queue=new LoadQueue();
_______________________________________________
Dynapi-CVS mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dynapi-cvs