⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grids.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
/* * Bindows 1.01 * http://www.bindows.net/ * Copyright (c) 2003-2004 MB Technologies * * Bindows(tm) belongs to MB Technologies (Georgia, USA). All rights reserved. * You are not allowed to copy or modify this code. Commercial use requires * license. */function BiGridHeaders(){    BiComponent.call(this);    this._columnWidths = [];    this._columnOrders = [];    this._invertedColumnOrders = [];    this.setCssClassName("bi-tree-headers");    this.setTop(0);    this.setSize(296, 18);    this._resizeHandle = new BiResizeHandle;    this._moveHandle = new BiMoveHandle;    this._moveHandle.setMoveDirection("horizontal");    this._resizeHandle.addEventListener("beforeresize", this._onBeforeResizeHandleResize, this);    this._resizeHandle.addEventListener("resize", this._onResizeHandleResize, this);    this._resizeHandle.addEventListener("resizeend", this._onResizeHandleResizeEnd, this);    this._moveHandle.addEventListener("moveend", this._onMoveHandleMoveEnd, this);    this._moveHandle.addEventListener("move", this._onMoveHandleMove, this);    this._filler = new this._gridHeaderFillerConstructor;    this.add(this._filler);}_p = BiGridHeaders.prototype = new BiComponent;_p._className = "BiGridHeaders";_p._gridHeaderFillerConstructor = BiGridHeaderFiller;_p._gridHeaderConstructor = BiGridHeader;_p._sortColumn = -1;_p._ascending = null;_p._columnCount = 0;_p._fitColumnWidths = false;BiGridHeaders.prototype.getFitColumnWidths = function(){    return this._fitColumnWidths;} ;_p.setFitColumnWidths = function(b){    if (this._fitColumnWidths != b)    {        this._fitColumnWidths = b;        if (this.getCreated())            this.layoutAllChildrenX();    }};_p.layoutAllChildrenX = function(){    if (this._fitColumnWidths)        this._distributeColumns();    var l = Math.min(this._columnCount, this._children.length);    var x = 0;    var j;    for (var i = 0; i < l; i++)    {        j = this._columnOrders[i]        this._children[j].setLeft(x);        this._children[j].setWidth(this._columnWidths[j]);        x += this._columnWidths[j];    }    this._filler.setLeft(x);    if (this.getCreated())    {        this._filler.setWidth(this.getClientWidth() - x);    }};_p._distributeColumns = function(){    var sBefore = this._columnWidths.join("-");    var l = Math.min(this._columnCount, this._children.length);    var cs = this._children;    var j, mw;    var sum = 0;    var minSum = 0;    var availWidth = this.getClientWidth();    for (var i = 0; i < l; i++)    {        j = this._columnOrders[i];        mw = this._children[j].getMinimumWidth();        availWidth -= mw;        sum += this._columnWidths[j] - mw;        minSum += mw;    }    if (availWidth < 0)        availWidth = 0;    if (sum <= 0)        sum = minSum;    var w;    var res = new Array(l);    for (var i = 0; i < l; i++)    {        w = this._columnWidths[i];        mw = this._children[i].getMinimumWidth();        this._columnWidths[i] = mw + Math.round((w - mw) / sum * availWidth);        if (isNaN(this._columnWidths[i]))            alert(sum);    }    var sAfter = this._columnWidths.join("-");    if (sAfter != sBefore)        this.dispatchEvent(new BiEvent("columnwidthschanged"));};_p.layoutAllChildren = function(){    this.layoutAllChildrenX();    this.layoutAllChildrenY();};_p.add = function(oChild, oBefore){    if (oBefore == null && oChild != this._filler)        oBefore = this._filler;    BiComponent.prototype.add.call(this, oChild, oBefore);    if (oChild instanceof BiGridHeader && !(oChild instanceof BiGridHeaderFiller))    {        oChild._columnIndex = this._children.indexOf(oChild);    }};_p.remove = function(oChild){    BiComponent.prototype.remove.call(this, oChild);    if (oChild instanceof BiGridHeader && !oChild instanceof BiGridHeaderFiller)    {        delete oChild._columnIndex;    }};BiGridHeaders.prototype.getColumnCount = function(){    return this._columnCount;} ;BiGridHeaders.prototype.setColumnCount = function(v){    this._columnCount = v;} ;_p.setColumnWidths = function(aWidths){    var sBefore = this._columnWidths.join("-");    this._columnWidths = aWidths;    var sAfter = this._columnWidths.join("-");    if (sAfter != sBefore)        this.dispatchEvent(new BiEvent("columnwidthschanged"));};BiGridHeaders.prototype.getColumnWidths = function(){    return this._columnWidths;} ;_p.setColumnOrders = function(aOrders){    var sBefore = this._columnOrders.join("-");    this._columnOrders = aOrders;    this._invertedColumnOrders = new Array(aOrders.length);    for (var i = 0; i < aOrders.length; i++)    {        this._invertedColumnOrders[aOrders[i]] = i;    }    var sAfter = this._columnOrders.join("-");    if (sAfter != sBefore)        this.dispatchEvent(new BiEvent("columnorderschanged"));};BiGridHeaders.prototype.getColumnOrders = function(){    return this._columnOrders;} ;_p.setSortColumn = function(n){    if (this._sortColumn != n)    {        if (this._sortColumn != -1)            this._children[this._sortColumn].setAscending(null);        this._sortColumn = n;        if (n != -1)            this._children[this._sortColumn].setAscending(this._ascending);        this.dispatchEvent(new BiEvent("sortcolumnchanged"));    }};BiGridHeaders.prototype.getSortColumn = function(){    return this._sortColumn;} ;_p.setAscending = function(b){    if (this._ascending != b)    {        this._ascending = b;        if (this._children[this._sortColumn])            this._children[this._sortColumn].setAscending(this._ascending);        this.dispatchEvent(new BiEvent("ascendingchanged"));    }};BiGridHeaders.prototype.getAscending = function(){    return this._ascending;} ;_p._onBeforeResizeHandleResize = function(e){    this._beforeWidth = e.getTarget().getHandleFor().getWidth();} ;_p._onResizeHandleResize = function(e){    if (this._fitColumnWidths)    {        var current = e.getTarget().getHandleFor();        var visualIndex = this._invertedColumnOrders[current._columnIndex];        var nextIndex = this._columnOrders[visualIndex + 1];        var next = this._children[nextIndex];        if (next)        {            var delta = current.getWidth() - this._beforeWidth;            var mw = next.getMinimumWidth();            var w = Math.max(mw, next.getWidth() - delta);            next.setWidth(w);            if (w == mw)                current.setWidth(this._beforeWidth);        }    }    var l = Math.min(this._columnWidths.length, this._children.length);    for (var i = 0; i < l; i++)    {        this._columnWidths[i] = this._children[i].getWidth();    }    this._columnResized = true;    this.layoutAllChildrenX();    this.dispatchEvent(new BiEvent("columnwidthschanging"));};_p._onResizeHandleResizeEnd = function(e){    var sAfter = this._columnWidths.join("-");    if (this._beforeColumnWidths != sAfter)    {        delete this._beforeColumnWidths;        this.dispatchEvent(new BiEvent("columnwidthschanged"));    }};_p._onMoveHandleMove = function(e){    if (Math.abs(this._moveHeader.getLeft() - this._currentDragHeader.getLeft()) > 5)    {        this._moveHeader.setVisible(true);        this._headerDropMarker.setVisible(true);        this._columnDragged = true;    }    var left = BiMouseEvent.getScreenX() - this.getScreenLeft() - this.getInsetLeft() + this.getScrollLeft();    if (left < 0)        return;    var x = 0;    var l = this._columnWidths.length;    var i = 0;    var j;    for (;i < l; i++)    {        j = this._columnOrders[i];        if (left >= x - (this._columnWidths[this._columnOrders[i - 1]] || 0) / 2            && left <= x + this._columnWidths[j] / 2)            break;        x += this._columnWidths[j];    }    this._headerDropMarker.setLeft(x - 1);    this._headerDropMarker._dropIndex = i;};_p._onMoveHandleMoveEnd = function(e){    var dropIndex = this._headerDropMarker._dropIndex;    this._moveHandle.setHandleFor(null);    this.remove(this._moveHeader);    this._moveHeader.dispose();    this._moveHeader = null;    this.remove(this._headerDropMarker);    this._headerDropMarker.dispose();    this._headerDropMarker = null;    if (typeof dropIndex == "number")    {        var colIndex = this._currentDragHeader._columnIndex;        var visIndex = this._invertedColumnOrders[colIndex];        if (visIndex == dropIndex || visIndex + 1 == dropIndex)        {        }        else        {            if (dropIndex < visIndex)            {                var tmp = this._columnOrders.copy();                tmp.remove(colIndex);                tmp.insertAt(colIndex, dropIndex);                this.setColumnOrders(tmp);            }            else            {                var tmp = this._columnOrders.copy();                tmp.remove(colIndex);                tmp.insertAt(colIndex, dropIndex - 1);                this.setColumnOrders(tmp);            }            this.layoutAllChildrenX();        }    }    if (this._currentDragHeader)    {        this._currentDragHeader._setDownState(false);        this._currentDragHeader = null;    }};_p._startDrag = function(oSrc, e){    this._columnResized = false;    this._columnDragged = false;    this._currentDragHeader = oSrc;    this._moveHeader = new this._gridHeaderConstructor;    this._moveHeader.setVisible(false);    this._moveHeader.setOpacity(0.7);    this._moveHeader.setBorder(oSrc.getBorder());    this._moveHeader.setText(oSrc.getText());    this._moveHeader.setAscending(oSrc.getAscending());    this._moveHeader.setLeft(oSrc.getLeft());    this._moveHeader.setWidth(oSrc.getWidth());    this._moveHeader.setPaddingLeft(oSrc.getPaddingLeft());    this._moveHeader.setPaddingRight(oSrc.getPaddingRight());    this._moveHeader.setPaddingTop(oSrc.getPaddingTop());    this._moveHeader.setPaddingBottom(oSrc.getPaddingBottom());    this._moveHeader.setZIndex(1);    this.add(this._moveHeader);    this._headerDropMarker = new BiComponent;    this._headerDropMarker.setVisible(false);    this._headerDropMarker.setBackColor("blue");    this._headerDropMarker.setWidth(2);    this._headerDropMarker.setTop(0);    this._headerDropMarker.setBottom(0);    this._headerDropMarker.setZIndex(1);    this.add(this._headerDropMarker, this._moveHeader);    this._moveHandle.setHandleFor(this._moveHeader);    this._moveHandle.startMove(e);};_p.dispose = function(){    if (this._disposed)        return;    BiComponent.prototype.dispose.call(this);    this._resizeHandle.dispose();    this._moveHandle.dispose();    this._filler.dispose();    if (this._moveHeader)        this._moveHeader.dispose();    if (this._headerDropMarker)        this._headerDropMarker.dispose();    this._resizeHandle = null;    this._moveHandle = null;    this._filler = null;    this._moveHeader = null;    this._headerDropMarker = null;};function BiGridHeader(sText){    BiLabel.call(this, sText);    this.setCssClassName("bi-grid-header");    this.setIconPosition("right");    this.setBorder(this._normalBorder);    this.setPadding(this._normalPadding.left, this._normalPadding.right, this._normalPadding.top,                    this._normalPadding.bottom);    this.setTop(0);    this.setBottom(0);    this.setBackColor("ThreeDFace");    this.addEventListener("mousedown", this._onMouseDown);    this.addEventListener("mouseup", this._onMouseUp);    this.addEventListener("mousemove", this._onMouseMove);}var _p = BiGridHeader.prototype = new BiLabel;_p._className = "BiGridHeader";_p._normalBorder = new BiBorder(1, "solid", "ThreeDShadow");_p._normalBorder.setTopColor("ThreeDHighlight");_p._normalBorder.setLeftColor("ThreeDHighlight");_p._normalPadding = {    left: 4, right: 4, top: 1, bottom: 1};_p._activeBorder = new BiBorder(1, "solid", "ThreeDShadow");_p._activePadding = {    left: 5, right: 3, top: 2, bottom: 0};_p._ascendingIcon = new BiImage(application.getPath() + "images/sortarrow.ascending.gif", 7, 4);_p._descendingIcon = new BiImage(application.getPath() + "images/sortarrow.descending.gif", 7, 4);_p._minimumWidth = 20;_p._ascending = null;_p._resizable = true;_p._sortable = true;_p._movable = true;BiGridHeader.prototype.getResizable = function(){    return this._resizable;} ;BiGridHeader.prototype.setResizable = function(v){    this._resizable = v;} ;BiGridHeader.prototype.getSortable = function(){    return this._sortable;} ;BiGridHeader.prototype.setSortable = function(v){    this._sortable = v;} ;BiGridHeader.prototype.getMovable = function(){    return this._movable;} ;BiGridHeader.prototype.setMovable = function(v){    this._movable = v;} ;BiGridHeader.prototype.getColumnIndex = function(){    return this._columnIndex;} ;_p.setAscending = function(b){    this._ascending = b;    if (b == null)        this.setIcon(null);    else if (b)        this.setIcon(this._ascendingIcon);    else        this.setIcon(this._descendingIcon);};BiGridHeader.prototype.getAscending = function(){    return this._ascending;} ;_p._onMouseDown = function(e){    if (e.getButton() != BiMouseEvent.LEFT)        return;    if (this._resizeDir != "" && this._resizeDir != null)    {        var p = this._parent;        if (this._resizeDir == "e")        {            p._resizeHandle.setHandleFor(this);        }        else        {            var visualIndex = p._invertedColumnOrders[this._columnIndex];            var previousIndex = p._columnOrders[visualIndex - 1];            p._resizeHandle.setHandleFor(p._children[previousIndex]);        }        p._columnResized = false;        p._columnDragged = false;        p._beforeColumnWidths = p._columnWidths.join("-");        p._resizeHandle.startResize("e", e);    }    else    {        if (this._sortable)            this._setDownState(true);        if (this._movable)        {            this.setCursor("");            this._parent._startDrag(this, e);        }    }};_p._setDownState = function(b){    if (b)    {        this.setBorder(this._activeBorder);        this.setPadding(this._activePadding.left, this._activePadding.right, this._activePadding.top,                        this._activePadding.bottom);    }    else    {        this.setBorder(this._normalBorder);        this.setPadding(this._normalPadding.left, this._normalPadding.right, this._normalPadding.top,                        this._normalPadding.bottom);    }};_p._onMouseUp = function(e){    if (e.getButton() != BiMouseEvent.LEFT)        return;    if (this._parent._currentDragHeader && this != this._parent._currentDragHeader)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -