/* ************************************************************************ 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) ************************************************************************ */ /* ************************************************************************ #module(ui_listview) ************************************************************************ */ qx.OO.defineClass("qx.ui.listview.ListViewPane", qx.ui.layout.GridLayout, function(vData, vColumns) { qx.ui.layout.GridLayout.call(this); // ************************************************************************ // DATA // ************************************************************************ // Add aliases for data tables this._data = vData; this._columns = vColumns; // ************************************************************************ // INITIALIZE MANAGER // ************************************************************************ this._manager = new qx.manager.selection.VirtualSelectionManager(this); // ************************************************************************ // MOUSE EVENT LISTENER // ************************************************************************ // Add handling for mouse wheel events // Needed because the virtual scroll area does not fire browser // understandable events above this pane. this.addEventListener("mousewheel", this._onmousewheel); this.addEventListener("mouseover", this._onmouseover); this.addEventListener("mousedown", this._onmousedown); this.addEventListener("mouseup", this._onmouseup); this.addEventListener("click", this._onclick); this.addEventListener("dblclick", this._ondblclick); // ************************************************************************ // KEY EVENT LISTENER // ************************************************************************ this.addEventListener("keypress", this._onkeypress); }); qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "list-view-pane" }); qx.Proto._rowHeight = 16; /* --------------------------------------------------------------------------- UTILITIES --------------------------------------------------------------------------- */ qx.Proto.getView = function() { return this.getParent().getParent(); } /* --------------------------------------------------------------------------- UPDATER --------------------------------------------------------------------------- */ qx.Proto._lastRowCount = 0; qx.Proto._updateLayout = function(vUpdate) { // this.debug("InnerHeight: " + this._computeInnerHeight()); // this.debug("BoxHeight: " + this._computeBoxHeight()); // return var vColumns = this._columns; var vRowCount = Math.ceil(this.getInnerHeight() / this._rowHeight); var vData = this._data; var vCell; // this.debug("Row-Count: " + this._lastRowCount + " => " + vRowCount); // Sync cells: Add new ones and configure them if (vRowCount > this._lastRowCount) { for (var i=this._lastRowCount, j=0; i vRowCount) { var vChildren = this.getChildren(); var vChildrenLength = vChildren.length - 1; for (var i=this._lastRowCount; i>vRowCount; i--) { for (var vCol in vColumns) { vCell = vChildren[vChildrenLength--]; this.remove(vCell); vCell.dispose(); } } } // Update row and column count this.setRowCount(vRowCount); if (!vUpdate) { this.setColumnCount(qx.lang.Object.getLength(vColumns)); } // Apply height to all rows for (var i=0; i vParentHeight || vOffset < vParentScrollTop) { vNewScrollTop = vOffset; } else if ((vOffset + vHeight) > (vParentScrollTop + vParentHeight)) { vNewScrollTop = vOffset + vHeight - vParentHeight; } if (vNewScrollTop != null) { this.getView().getScroll().setScrollTop(vNewScrollTop); } } qx.Proto.setScrollTop = function(vScrollTop) { this.getView().getScroll().setScrollTop(vScrollTop); this._updateRendering(); } qx.Proto.getScrollTop = function() { return this._currentScrollTop; } qx.Proto.setScrollLeft = function() { this.error("Not implemented in qx.ui.listview.ListViewPane!"); } qx.Proto.getScrollLeft = function() { return 0; } qx.Proto.isItemVisible = function(vItem) { var vIndex = this._data.indexOf(vItem); var vRowStart = Math.floor(this._currentScrollTop / this._rowHeight); var vRowLength = Math.ceil(this.getClientHeight() / this._rowHeight); return vIndex >= vRowStart && vIndex <= (vRowStart + vRowLength); } qx.Proto.getRelativeItemPosition = function(vItem) { var vIndex = this._data.indexOf(vItem); var vRowStart = Math.floor(this._currentScrollTop / this._rowHeight); return vIndex - vRowStart; } qx.Proto._updateItem = function(vItem) { var vIndex = this._data.indexOf(vItem); var vRowStart = Math.floor(this._currentScrollTop / this._rowHeight); var vRowLength = Math.ceil(this.getClientHeight() / this._rowHeight); if (vIndex < vRowStart || vIndex > (vRowStart + vRowLength)) { return; } this._updateRow(vIndex - vRowStart); } /* --------------------------------------------------------------------------- DISPOSER --------------------------------------------------------------------------- */ qx.Proto.dispose = function() { if (this.getDisposed()) { return; } // ************************************************************************ // MOUSE EVENT LISTENER // ************************************************************************ this.removeEventListener("mousewheel", this._onmousewheel); this.removeEventListener("mouseover", this._onmouseover); this.removeEventListener("mousedown", this._onmousedown); this.removeEventListener("mouseup", this._onmouseup); this.removeEventListener("click", this._onclick); this.removeEventListener("dblclick", this._ondblclick); // ************************************************************************ // KEY EVENT LISTENER // ************************************************************************ this.removeEventListener("keypress", this._onkeypress); // ************************************************************************ // DATA // ************************************************************************ delete this._data; delete this._columns; // ************************************************************************ // MANAGER // ************************************************************************ if (this._manager) { this._manager.dispose(); this._manager = null; } return qx.ui.layout.GridLayout.prototype.dispose.call(this); }