📄 window.js
字号:
/* * 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 BiMoveHandle(oHandleFor){ BiComponent.call(this); this.setCursor("move"); this._handleFor = oHandleFor; this.addEventListener("mousedown", this._startMove, this);}_p = BiMoveHandle.prototype = new BiComponent;_p._className = "BiMoveHandle";_p._handleFor = null;_p._moveDirection = "both";BiMoveHandle.prototype.getHandleFor = function(){ return this._handleFor;} ;BiMoveHandle.prototype.setHandleFor = function(v){ this._handleFor = v;} ;BiMoveHandle.prototype.getMoveDirection = function(){ return this._moveDirection;} ;BiMoveHandle.prototype.setMoveDirection = function(v){ this._moveDirection = v;} ;_p.startMove = function(e){ this._startMove(e);} ;_p._startMove = function(e){ if (!this._handleFor) return; if (this.dispatchEvent(new BiEvent("movestart"))) { var c = this._handleFor; c.addEventListener("mousemove", this._continueMove, this); c.addEventListener("mouseup", this._endMove, this); c.addEventListener("losecapture", this._endMove, this); c.setCapture(true); this._moveData = { screenX: e.getScreenX(), screenY: e.getScreenY(), startX: c.getLeft(), startY: c.getTop(), dx: e.getScreenX() - c.getScreenLeft(), dy: e.getScreenY() - c.getScreenTop() }; e.preventDefault(); }};_p._continueMove = function(e){ var c = this._handleFor; var p = c.getParent(); var ex = e.getScreenX(); var ey = e.getScreenY(); var r = p ? p._getScreenClientArea() : null; ex = Math.max(ex, p ? r.left : 0); ey = Math.max(ey, p ? r.top : 0); ex = Math.min(ex, p ? r.left + r.width - 1 : screen.availWidth); ey = Math.min(ey, p ? r.top + r.height - 1 : screen.availHeight); var x = ex - this._moveData.screenX + this._moveData.startX; var y = ey - this._moveData.screenY + this._moveData.startY; if (this.dispatchEvent(new BiEvent("beforemove"))) { if (this._moveDirection == "both") c.setLocation(x, y); else if (this._moveDirection == "horizontal") c.setLeft(x); else c.setTop(y); this.dispatchEvent(new BiEvent("move")); } e.preventDefault();};_p._endMove = function(e){ var c = this._handleFor; c.removeEventListener("mousemove", this._continueMove, this); c.removeEventListener("mouseup", this._endMove, this); c.removeEventListener("losecapture", this._endMove, this); c.setCapture(false); this._moveData = null; this.dispatchEvent(new BiEvent("moveend")); e.preventDefault();};_p.dispose = function(){ if (this._disposed) return; BiComponent.prototype.dispose.call(this); this._handleFor = null; this._moveData = null;};function BiResizeHandle(oHandleFor){ BiComponent.call(this); this.setCssClassName("bi-resize-handle"); this._handleChar1 = new BiLabel("o"); this._handleChar1.setCssClassName("bi-handle-char bi-handle-char-o"); this._handleChar1.setRight(0); this._handleChar1.setBottom(0); this.add(this._handleChar1); this._handleChar2 = new BiLabel("p"); this._handleChar2.setCssClassName("bi-handle-char bi-handle-char-p"); this._handleChar2.setRight(0); this._handleChar2.setBottom(0); this.add(this._handleChar2); this.setSize(18, 18); this.setRight(0); this.setBottom(0); this._handleFor = oHandleFor; this.addEventListener("mousedown", this._startResize, this);}var _p = BiResizeHandle.prototype = new BiComponent;_p._className = "BiResizeHandle";_p._handleFor = null;_p._resizeDirection = "se";BiResizeHandle.prototype.getHandleFor = function(){ return this._handleFor;} ;BiResizeHandle.prototype.setHandleFor = function(v){ this._handleFor = v;} ;_p.setResizeDirection = function(sDir){ this._resizeDirection = sDir; this.setCursor(sDir + "-resize");};BiResizeHandle.prototype.getResizeDirection = function(){ return this._resizeDirection;} ;_p.startResize = function(sDir, e){ if (sDir) this.setResizeDirection(sDir); this._startResize(e);};_p._startResize = function(e){ if (!this._handleFor) return; if (this.dispatchEvent(new BiEvent("resizestart"))) { var c = this._handleFor; c.addEventListener("mousemove", this._continueResize, this); c.addEventListener("mouseup", this._endResize, this); c.addEventListener("losecapture", this._endResize, this); c.setCapture(true); this._resizeData = { screenX: e.getScreenX(), screenY: e.getScreenY(), startX: c.getLeft(), startY: c.getTop(), startW: c.getWidth(), startH: c.getHeight(), dx: e.getScreenX() - c.getScreenLeft(), dy: e.getScreenY() - c.getScreenTop() }; e.preventDefault(); }};_p._continueResize = function(e){ var dir = this._resizeDirection; var c = this._handleFor; var p = c.getParent(); var width = this._resizeData.startW; var height = this._resizeData.startH; var left = this._resizeData.startX; var top = this._resizeData.startY; var r = p ? p._getScreenClientArea() : null; var ex = e.getScreenX(); var ey = e.getScreenY(); ex = Math.max(ex, p ? r.left : 0); ey = Math.max(ey, p ? r.top : 0); ex = Math.min(ex, p ? r.left + r.width - 1 : screen.availWidth); ey = Math.min(ey, p ? r.top + r.height - 1 : screen.availHeight); if (/e/i.test(dir)) { width = Math.max(Number(c.getMinimumWidth()), Math.min(Number(c.getMaximumWidth()), ex - (this._resizeData.screenX - this._resizeData.startW))); } else if (/w/i.test(dir)) { width = Math.max(Number(c.getMinimumWidth()), Math.min(Number(c.getMaximumWidth()), this._resizeData.startW + this._resizeData.startX - ex + (this._resizeData.screenX - this._resizeData.startX))); left = this._resizeData.startW + this._resizeData.startX - width; } if (/s/i.test(dir)) { height = Math.max(Number(c.getMinimumHeight()), Math.min(Number(c.getMaximumHeight()), ey - (this._resizeData.screenY - this._resizeData.startH))); } else if (/n/i.test(dir)) { height = Math.max(Number(c.getMinimumHeight()), Math.min(Number(c.getMaximumHeight()), this._resizeData.startH + this._resizeData.startY - ey + (this._resizeData.screenY - this._resizeData.startY))); top = this._resizeData.startH + this._resizeData.startY - height; } if (this.dispatchEvent(new BiEvent("beforeresize"))) { c.setSize(width, height); c.setLocation(left, top); this.dispatchEvent(new BiEvent("resize")); } e.preventDefault();};_p._endResize = function(e){ var c = this._handleFor; c.removeEventListener("mousemove", this._continueResize, this); c.removeEventListener("mouseup", this._endResize, this); c.removeEventListener("losecapture", this._endResize, this); c.setCapture(false); this._resizeData = null; this.dispatchEvent(new BiEvent("resizeend")); e.preventDefault();};_p.dispose = function(){ if (this._disposed) return; BiComponent.prototype.dispose.call(this); this._handleFor = null; this._resizeData = null;};function BiWindow(sCaption){ BiComponent.call(this); this.setCssClassName("bi-window"); this.setSize(400, 200); this.setTabIndex(0); this.setHideFocus(true); this._focusManager = new BiFocusManager; this._commands = { }; this._windowCaption = new BiComponent; this._windowCaption.setCssClassName("bi-window-caption"); this._windowIcon = new BiImage(BiWindow.DEFAULT_ICON, 16, 16); this._captionLabel = new BiLabel(sCaption) this._minimizeButton = new BiButton(); this._minimizeButton.setHtml("<span>0</span>"); this._minimizeButton.setTabIndex(-1); this._minimizeButton._setHtmlAttribute("buttontype", "minimize"); this._maximizeButton = new BiButton(); this._maximizeButton.setHtml("<span>1</span>"); this._maximizeButton.setTabIndex(-1); this._maximizeButton._setHtmlAttribute("buttontype", "maximize"); this._closeButton = new BiButton(); this._closeButton.setHtml("<span>r</span>"); this._closeButton.setTabIndex(-1); this._closeButton._setHtmlAttribute("buttontype", "close"); this._contentPane = new BiComponent; this._contentPane.setCursor("default"); this._windowCaption.add(this._windowIcon); this._windowCaption.add(this._captionLabel); this._windowCaption.add(this._minimizeButton); this._windowCaption.add(this._maximizeButton); this._windowCaption.add(this._closeButton); BiComponent.prototype.add.call(this, this._windowCaption); BiComponent.prototype.add.call(this, this._contentPane); this._fixedLayout(); this._resizeHandler = new BiResizeHandle(this); this._moveHandler = new BiMoveHandle(this); this._captionLabel.addEventListener("mousedown", this._onCaptionDown, this); this._minimizeButton.addEventListener("click", this._onMinimizeButtonClick, this); this._maximizeButton.addEventListener("click", this._onMaximizeButtonClick, this); this._closeButton.addEventListener("click", this._onCloseButtonClick, this); this._captionLabel.addEventListener("dblclick", this._onMaximizeButtonClick, this); this._windowIcon.addEventListener("dblclick", this._onCloseButtonClick, this); this.addEventListener("mousemove", this._checkForResize); this.addEventListener("mousedown", this._onEdgeDown); this.addEventListener("focusin", this._onFocusIn); this.addEventListener("focusout", this._onFocusOut); this.addEventListener("focus", this._onFocus); this.addEventListener("mouseover", this._onMouseEvent); this.addEventListener("mousemove", this._onMouseEvent); this.addEventListener("mouseout", this._onMouseEvent); this.addEventListener("mousedown", this._onMouseEvent); this.addEventListener("mouseup", this._onMouseEvent); this.addEventListener("click", this._onMouseEvent); this.addEventListener("dblclick", this._onMouseEvent); this.addEventListener("contextmenu", this._onMouseEvent); this.addEventListener("mousewheel", this._onMouseEvent); this.addEventListener("keydown", this._onkeydown); this.addEventListener("keydown", this._onDefaultButtonKeyDown); this.addEventListener("keydown", this._onKeyEvent); this.addEventListener("keypress", this._onKeyEvent); this.addEventListener("keyup", this._onKeyEvent);}var _p = BiWindow.prototype = new BiComponent;_p._className = "BiWindow";BiWindow.DEFAULT_ICON = application.getPath() + "images/default.16.gif";_p._showIcon = true;_p._showMinimize = true;_p._showMaximize = true;_p._showClose = true;_p._canMinimize = true;_p._resizable = true;_p._movable = true;_p._state = "normal";_p._icon = null;_p._activeComponent = null;_p._lastActive = null;_p._hideChrome = false;_p._minimumWidth = 120;_p._maximumWidth = Infinity;_p._minimumHeight = 27;_p._maximumHeight = Infinity;_p.layoutAllChildren = function(){ BiComponent.prototype.layoutAllChildren.call(this); this._layoutChrome();};_p.layoutAllChildrenX = function(){ BiComponent.prototype.layoutAllChildrenX.call(this); this._layoutChromeX();};_p.layoutAllChildrenY = function(){ BiComponent.prototype.layoutAllChildrenY.call(this); this._layoutChromeY();};_p._fixedLayout = function(){ this._windowCaption.setLocation(2, 2); this._windowCaption.setRight(2); this._windowCaption.setHeight(19); this._windowIcon.setLocation(2, 1); this._minimizeButton.setSize(16, 14); this._maximizeButton.setSize(16, 14); this._closeButton.setSize(16, 14); this._minimizeButton.setTop(2); this._maximizeButton.setTop(2); this._closeButton.setTop(2); this._closeButton.setRight(2); this._setContentPaneSize(); this._captionLabel.setTop(0); this._captionLabel.setBottom(0); this._windowIcon.setVisible(this._showIcon); this._minimizeButton.setVisible(this._showMinimize); this._maximizeButton.setVisible(this._showMaximize); this._closeButton.setVisible(this._showClose);};_p._layoutChromeX = function(){ if (this._showIcon) this._captionLabel.setLeft(18); else this._captionLabel.setLeft(0); var r = 2; if (this._showClose) r += 18; this._maximizeButton.setRight(r); if (this._showMaximize) r += 16; this._minimizeButton.setRight(r); if (this._showMinimize) r += 16; r += 2; this._captionLabel.setRight(r);};_p._layoutChromeY = function(){} ;_p._layoutChrome = function(){ this._layoutChromeX();} ;BiWindow.prototype.getContentPane = function(){ return this._contentPane;} ;_p.setContentPane = function(oComp){ if (oComp && oComp != this._contentPane) { this.add(oComp, this._contentPane); this.remove(this._contentPane); this._contentPane = oComp; this._setContentPaneSize(); oComp.setCursor("default"); }};BiWindow.prototype.getShowIcon = function(){ return this._showIcon;} ;BiWindow.prototype.getShowMinimize = function(){ return this._showMinimize;} ;BiWindow.prototype.getShowMaximize = function(){ return this._showMaximize;} ;BiWindow.prototype.getShowClose = function(){ return this._showClose;} ;_p.setShowIcon = function(b){ if (this._showIcon != b) { this._showIcon = b; this._windowIcon.setVisible(b); this._layoutChrome(); }};_p.setShowMinimize = function(b){ if (this._showMinimize != b) { this._showMinimize = b; this._minimizeButton.setVisible(b); this._layoutChrome(); }};_p.setShowMaximize = function(b){ if (this._showMaximize != b) { this._showMaximize = b; this._maximizeButton.setVisible(b); this._layoutChrome(); }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -