/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org License: LGPL 2.1: http://www.gnu.org/licenses/lgpl.html Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) ************************************************************************ */ /* ************************************************************************ ************************************************************************ */ /** * @event beforeToolTipAppear {qx.event.type.Event} * @event loadComplete {qx.event.type.Event} */ qx.OO.defineClass("qx.ui.embed.Gallery", qx.ui.basic.Terminator, function(vGalleryList) { qx.ui.basic.Terminator.call(this); this._blank = qx.manager.object.AliasManager.getInstance().resolvePath("static/image/blank.gif"); this._list = vGalleryList; this._listSize = vGalleryList.length; this._processedImages = 0; this.setOverflow("auto"); this.setHtmlProperty("className", "qx_ui_embed_Gallery"); this._manager = new qx.manager.selection.DomSelectionManager(this); this._manager.setMultiColumnSupport(true); this.addEventListener("mousedown", this._onmousedown); this.addEventListener("mouseup", this._onmouseup); this.addEventListener("mousemove", this._onmousemove); this.addEventListener("click", this._onclick); this.addEventListener("dblclick", this._ondblclick); this.addEventListener("keypress", this._onkeypress); }); /* --------------------------------------------------------------------------- PROPERTIES --------------------------------------------------------------------------- */ qx.OO.addProperty({ name : "thumbMaxWidth", type : "number", defaultValue : 100 }); qx.OO.addProperty({ name : "thumbMaxHeight", type : "number", defaultValue : 100 }); qx.OO.addProperty({ name : "decorHeight", type : "number", defaultValue : 40 }); qx.OO.addProperty({ name : "showTitle", type : "boolean", defaultValue : true }); qx.OO.addProperty({ name : "showComment", type : "boolean", defaultValue : true }); /* --------------------------------------------------------------------------- ELEMENT HANDLING --------------------------------------------------------------------------- */ qx.Proto._applyElementData = function() { this.getElement().appendChild(this.createView()); } /* --------------------------------------------------------------------------- UTILITIES --------------------------------------------------------------------------- */ qx.Proto.getManager = function() { return this._manager; } qx.Proto.getList = function() { return this._list; } qx.Proto.update = function(vGalleryList) { this._manager.deselectAll(); this._list = vGalleryList; var el = this.getElement(); el.replaceChild(this.createView(), el.firstChild); } qx.Proto.removeAll = function() { this._manager.deselectAll(); this.getElement().innerHTML = ""; } qx.Proto.updateImageById = function(vId, vSrc, vWidth, vHeight) { this.updateImageSrcById(vId, vSrc); this.updateImageDimensionsById(vId, vWidth, vHeight); } qx.Proto.updateImageDimensionsById = function(vId, vWidth, vHeight) { this.updateImageDimensionsByPosition(this.getPositionById(vId), vWidth, vHeight); } qx.Proto.updateImageDimensionsByPosition = function(vPos, vWidth, vHeight) { // TBD: compare dimensions with max. thumb size and scale proportionally if necessary if (vPos == -1) { throw new Error("No valid Position: " + vPos); } var cnode = this.getNodeByPosition(vPos).getElementsByTagName("img")[0]; cnode.width = vWidth; cnode.height = vHeight; cnode.style.marginLeft = cnode.style.marginRight = Math.floor((this.getThumbMaxWidth()-vWidth)/2) + "px"; cnode.style.marginTop = cnode.style.marginBottom = Math.floor((this.getThumbMaxHeight()-vHeight)/2) + "px"; this._list[vPos].thumbWidth = vWidth; this._list[vPos].thumbHeight = vHeight; } qx.Proto.updateImageSrcById = function(vId, vSrc) { this.updateImageSrcByPosition(this.getPositionById(vId), vSrc); } qx.Proto.updateImageSrcByPosition = function(vPos, vSrc) { if (vPos == -1) { throw new Error("No valid Position: " + vPos); } var vNode = this.getNodeByPosition(vPos); vNode.getElementsByTagName("img")[0].src = vSrc; this._list[vPos].src = vSrc; } qx.Proto.deleteById = function(vId) { this.deleteByPosition(this.getPositionById(vId)); } qx.Proto.deleteByPosition = function(vPos) { this._manager.deselectAll(); if (vPos == -1) { throw new Error("No valid Position: " + vPos); } var vNode = this.getNodeByPosition(vPos); if (vNode) { vNode.parentNode.removeChild(vNode); } this._list.splice(vPos, 1); } qx.Proto.getPositionById = function(vId) { for (var i=0, a=this._list, l=a.length; i