//=============================================================================== // Copyright 2005, Tassos Koutsovassilis // // This file is part of Porcupine. // Porcupine is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation; either version 2.1 of the License, or // (at your option) any later version. // Porcupine is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public License // along with Porcupine; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //=============================================================================== //QuiX generic functions function __init__(){ var root = document.body.removeChild(document.getElementById("xul")); var oDom = XmlDocument.create(root.innerHTML); var parser = new XULParser(); parser.parse(oDom); } function Clipboard() { this.contains = ''; this.action = ''; this.items = []; } var QuiX = function() {} QuiX.version = '0.3 build 20051202'; QuiX.namespace = 'http://www.innoscript.org/quix'; QuiX.browser = 'moz'; QuiX.startX = 0; QuiX.startY = 0; QuiX.clipboard = new Clipboard(); QuiX.tmpWidget = null; QuiX.images = []; QuiX.root = (new RegExp("https?://[^/]+/[^/]+/%7B[0-9a-f]{32}%7D", "i")).exec(document.location.href) + '/'; QuiX.progress = '
Please wait...

' + '
' + '
'; QuiX.modules = [ new Module('Windows and Dialogs', '__xul/windows.js', [3]), new Module('Menus', '__xul/menus.js', [3]), new Module('Splitter', '__xul/splitter.js', [3]), new Module('Labels & Buttons', '__xul/buttons.js', [1]), new Module('Tab Pane', '__xul/tabpane.js', []), new Module('List View', '__xul/listview.js', []), new Module('Tree', '__xul/tree.js', []), new Module('Toolbars', '__xul/toolbars.js', [3]), new Module('Forms & Fields', '__xul/formfields.js', [3]), new Module('Common Widgets', '__xul/common.js', [3]), new Module('Datagrid', '__xul/datagrid.js', [5,8]), new Module('File Control', '__xul/file.js', [3,8]), new Module('Date Picker', '__xul/datepicker.js', [9]), new Module('Timers', '__xul/timers.js', []), ]; QuiX.tags = { 'desktop':-1,'xhtml':-1,'script':-1,'prop':-1,'rect':-1,'progressbar':-1, 'window':0,'dialog':0, 'menubar':1,'menu':1,'menuoption':1,'contextmenu':1, 'splitter':2, 'dlgbutton':3,'button':3,'flatbutton':3,'label':3,'icon':3, 'tabpane':4,'tab':4, 'listview':5, 'tree':6,'treenode':6,'foldertree':6, 'toolbar':7,'tbbutton':7,'outlookbar':7,'tool':7, 'field':8,'selectlist':8,'form':8, 'hr':9,'combo':9,'spinbutton':9, 'datagrid':10, 'file':11,'multifile':11, 'datepicker':12, 'timer':13 }; QuiX.Exception = function(name, msg) { this.name = name; this.message = msg; } QuiX.getWidgetsById = function(w, sid) { var ws = []; if (w._id_widgets[sid]) ws = ws.concat(w._id_widgets[sid]); for (var i=0; i0) QuiX.removeWidget(w.widgets[0]); if (w.parent) { w.parent.widgets.removeItem(w); if (w.id) delete(w.parent._id_widgets[w.id]); } w._detachEvents(); parentElement = w.div.parentNode; parentElement.removeChild(w.div); w._registry = null; w.div = null; w = null; } QuiX.createOutline = function(w) { var oW = new Widget( { left:w._calcLeft(), top:w._calcTop(), width:w.getWidth(true), height:w.getHeight(true), border:2, overflow:'hidden' }); w.parent.appendChild(oW, true); oW.minw = w.minw; oW.minh = w.minh; oW.div.className = 'outline'; return(oW); } QuiX.cleanupOverlays = function() { var ovr = document.desktop.overlays; while (ovr.length>0) ovr[0].close(); } QuiX.stopPropag = function(evt) { evt.stopPropagation(); } QuiX.cancelDefault = function(evt) { evt.preventDefault(); } QuiX.getTarget = function(evt) { return evt.target; } QuiX.removeNode = function(node) { node.parentNode.removeChild(node); } QuiX.getEventWrapper = function(f1, f2) { var wrapper; f1 = getEventListener(f1); f2 = getEventListener(f2); wrapper = function(evt, w) { var r1, r2 = null; r1 = f1(evt, w); if (f2) r2 = f2(evt, w); return((typeof(r1)!='undefined')?r1:r1||r2); } return(wrapper); } QuiX.getImage = function(url) { var img = new Image(); img.src = url; return img; } // xml document function XmlDocument() {} XmlDocument.create = function (s) { var dom = new DOMParser(); if (s) dom = dom.parseFromString(s, 'text/xml'); else dom = dom.parseFromString('', 'text/xml'); return(dom); } function getNodeXml(oNode) { var sXml = ''; var oSerializer = new XMLSerializer(); for (var i=0; i-1 && !QuiX.modules[iMod].isLoaded) { var oMod = QuiX.modules[iMod]; if(!this.__modulesToLoad.hasItem(oMod)) { for (var i=0; i 0) { oModule = this.__modulesToLoad.pop(); if (this.progressWidget) { this.progressWidget.getWidgetById('pb').increase(1); this.progressWidget.div.getElementsByTagName('SPAN')[0].innerHTML = oModule.name; } oModule.load(this); } else if (this.__imagesToLoad.length > 0) { imgurl = this.__imagesToLoad.pop(); img = new QImage(imgurl); if (this.progressWidget) { this.progressWidget.getWidgetById('pb').increase(1); this.progressWidget.div.getElementsByTagName('SPAN')[0].innerHTML = 'image "' + imgurl + '"'; } img.load(this); } else { if (this.progressWidget) this.progressWidget.destroy(); widget = this.beginRender(); } } XULParser.prototype.parse = function(oDom, parentW) { var widget, parser; this.dom = oDom; this.parentWidget = parentW; this.detectModules(oDom.documentElement); if (this.__modulesToLoad.length + this.__imagesToLoad.length > 0) { this.__modulesToLoad.reverse(); parser = this; if (parentW) { parentW.parseFromString(QuiX.progress, function(w){parser.loadModules(w);}); } else { this.loadModules(); } } else { this.beginRender(); } } XULParser.prototype.beginRender = function() { var widget = this.render(); if (this.oncomplete) this.oncomplete(widget); } XULParser.prototype.render = function() { window.status = ''; var parentW = this.parentWidget; var frag = document.createDocumentFragment(); if (parentW) { var root = parentW.div; frag.appendChild(root.cloneNode(true)); parentW.div = frag.firstChild; widget = this.parseXul(this.dom.documentElement, parentW); root.appendChild(widget.div); parentW.div = root; } else { widget = this.parseXul(this.dom.documentElement, frag); document.body.appendChild(frag); widget.redraw(); } return(widget); } XULParser.prototype.getNodeParams = function(oNode) { var params = {}; for (var i=0; i0?w:0) } else if (this.height.slice(this.height.length-1)=='%') { var perc = parseInt(this.height)/100; var nh = (parseInt(this.parent.getHeight()*perc)-offset) || 0; return(nh>0?nh:0); } else { var w = (eval(this.height) - offset) || 0; return(w>0?w:0); } } Widget.prototype._calcWidth = function(b) { var offset = 0; if (!b) offset = this.padding[0]+this.padding[1]+2*this.borderWidth; if (!isNaN(this.width)) { return (parseInt(this.width)-offset); } else if (typeof(this.width)=='function') { var w = (this.width(this)-offset) || 0; return(w>0?w:0) } else if (this.width.slice(this.width.length-1)=='%') { var perc = parseInt(this.width)/100; var nw = (parseInt(this.parent.getWidth()*perc) - offset) || 0; return(nw>0?nw:0); } else { var w = (eval(this.width)-offset) || 0; return(w>0?w:0); } } Widget.prototype._calcLeft = function() { if (!isNaN(this.left)) { var l = parseInt(this.left); if (this.parent) l+= this.parent.padding[0]; return(l); } else if (typeof(this.left)=='function') { var w = this.left(this) || 0; return(w>0?w:0) } else if (this.left.slice(this.left.length-1)=='%') { var perc = parseInt(this.left)/100; return (this.parent.getWidth() * perc) || 0; } else { if (this.left!='center') return(eval(this.left) || 0); else return parseInt((this.parent.getWidth()/2) - (this.getWidth(true)/2)) || 0; } } Widget.prototype._calcTop = function() { if (!isNaN(this.top)) { var t = parseInt(this.top); if (this.parent) t+= this.parent.padding[2]; return(t); } else if (typeof(this.top)=='function') { var w = this.top(this) || 0; return(w>0?w:0) } else if (this.top.slice(this.top.length-1)=='%') { var perc = parseInt(this.top)/100; return (this.parent.getHeight() * perc) || 0; } else { if (this.top!='center') return(eval(this.top) || 0); else return parseInt((this.parent.getHeight()/2) - (this.getHeight(true)/2)) || 0; } } Widget.prototype.getScreenLeft = function() { var oElement = this.div; iX = 0 while(oElement.tagName!='HTML') { if (oElement.tagName!='TR') iX += oElement.offsetLeft - oElement.scrollLeft; oElement = oElement.parentNode; } return(iX); } Widget.prototype.getScreenTop = function() { var oElement = this.div; iY = 0 while(oElement.tagName!='HTML') { if (oElement.tagName!='TR') iY += oElement.offsetTop - oElement.scrollTop; oElement = oElement.parentNode; } return(iY); } Widget.prototype.bringToFront = function(w) { w = w || this; if (w.div.style.zIndex==0 || w.div.style.zIndex < w.parent.maxz) { w.div.style.zIndex = ++w.parent.maxz; } } Widget.prototype.click = function(w) { var e = document.createEvent('MouseEvents'); e.initEvent('click', true, false); this.div.dispatchEvent(e); } Widget.prototype.moveTo = function(x,y) { this.left = x>0?x:0; this.top = y>0?y:0; this.redraw(); } Widget.prototype.resize = function(x,y) { this.width = (x>this.minw)?x:this.minw; this.height = (y>this.minh)?y:this.minh; this.redraw(); } Widget.prototype.destroy = function(w) { w = w || this; QuiX.removeWidget(w); } Widget.prototype.clear = function() { while (this.widgets.length > 0) this.widgets[0].destroy(); } Widget.prototype.hide = function() { this.div.style.visibility = 'hidden'; this.isHidden = true; } Widget.prototype.show = function() { this.div.style.visibility = ''; this.isHidden = false; this.redraw(); } Widget.prototype._startResize = function (evt) { var oWidget = this; QuiX.startX = evt.clientX; QuiX.startY = evt.clientY; QuiX.tmpWidget = QuiX.createOutline(this); QuiX.tmpWidget.bringToFront(); document.desktop.attachEvent('onmouseup', function(evt){oWidget._endResize(evt)}); document.desktop.attachEvent('onmousemove', function(evt){oWidget._resizing(evt)}); this.parent.div.style.cursor = 'se-resize'; } Widget.prototype._resizing = function(evt) { offsetX = evt.clientX - QuiX.startX; offsetY = evt.clientY - QuiX.startY; QuiX.tmpWidget.resize(this.getWidth(true) + offsetX, this.getHeight(true) + offsetY); } Widget.prototype._endResize = function(evt) { offsetX = evt.clientX - QuiX.startX; offsetY = evt.clientY - QuiX.startY; this.resize(this.getWidth(true) + offsetX, this.getHeight(true) + offsetY); this.bringToFront(); QuiX.tmpWidget.destroy(); document.desktop.detachEvent('onmouseup'); document.desktop.detachEvent('onmousemove'); this.parent.div.style.cursor = ''; } Widget.prototype._startMove = function(evt) { var oWidget = this; QuiX.startX = evt.clientX; QuiX.startY = evt.clientY; QuiX.tmpWidget = QuiX.createOutline(this); QuiX.tmpWidget.bringToFront(); document.desktop.attachEvent('onmouseup', function(evt){oWidget._endMove(evt)}); document.desktop.attachEvent('onmousemove', function(evt){oWidget._moving(evt)}); this.parent.div.style.cursor = 'move'; } Widget.prototype._moving = function(evt) { offsetX = evt.clientX - QuiX.startX; offsetY = evt.clientY - QuiX.startY; QuiX.tmpWidget.moveTo(this._calcLeft() + offsetX, this._calcTop() + offsetY); } Widget.prototype._endMove = function(evt) { document.desktop.detachEvent('onmousemove'); document.desktop.detachEvent('onmouseup'); QuiX.tmpWidget.destroy(); offsetX = evt.clientX - QuiX.startX; offsetY = evt.clientY - QuiX.startY; this.moveTo(this.div.offsetLeft + offsetX, this.div.offsetTop + offsetY); this.bringToFront(); this.parent.div.style.cursor = ''; } Widget.prototype._detach = function() { var i; var childWidgets = []; for (i=0; i'; root.appendChild(this.div); this.div.className = 'desktop'; document.desktop = this; window.onresize = function() {document.desktop.redraw()}; this.overlays = []; } Desktop.prototype = new Widget; Desktop.prototype.msgbox = function(mtitle, message, buttons, image, mleft, mtop, mwidth, mheight) { var sButtons = ''; var handler; var oButton; var dlg; mwidth = mwidth || 240; mheight = mheight || 120; if (image) innHTML = '' + message + ''; else innHTML = '' + message + ''; if (typeof buttons=='object') { for (var i=0; i'; } } else sButtons = ''; this.parseFromString('' + '' + innHTML + '
' + sButtons + '
', function(w) { //attach buttons click events if (typeof buttons=='object') { for (var i=0; i2) handler = oButton[2]; w.buttons[i].attachEvent('onclick', handler); } } } ); } function Desktop__onmousedown(evt, w) { QuiX.cleanupOverlays(); QuiX.cancelDefault(evt); } // progress bar function ProgressBar(params) { params = params || {}; this.base = Widget; params.border = 1; params.overflow = 'hidden'; this.base(params); this.div.className = 'progressbar'; this.bar = new Widget({height:"100%",overflow:'hidden'}); this.appendChild(this.bar); this.bar.div.className = 'bar'; this.maxvalue = parseInt(params.maxvalue) || 100; this.value = parseInt(params.value) || 0; } ProgressBar.prototype = new Widget; ProgressBar.prototype._update = function() { this.bar.width = parseInt((this.value/this.maxvalue)*100) + '%'; this.bar.redraw(); } ProgressBar.prototype.setValue = function(v) { this.value = parseInt(v); if (this.value>this.maxvalue) this.value=this.maxvalue; this._update(); } ProgressBar.prototype.increase = function(amount) { this.value += parseInt(amount); if (this.value>this.maxvalue) this.value=this.maxvalue; this._update(); }