📄 guicomponents.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 BiCommand(){ BiEventTarget.call(this); if (application && application.getWindow && application.getWindow()) application.getWindow().addCommand(this);}_p = BiCommand.prototype = new BiEventTarget;_p._className = "BiCommand";_p._enabled = true;_p._checked = false;_p._userValue = null;_p._shortcut = null;_p._keyCode = null;_p._ownerWindow = null;BiCommand.prototype.getEnabled = function(){ return this._enabled;} ;BiCommand.prototype.getChecked = function(){ return this._checked;} ;BiCommand.prototype.getUserValue = function(){ return this._userValue;} ;BiCommand.prototype.getShortcut = function(){ return this._shortcut;} ;BiCommand.prototype.getKeyCode = function(){ return this._keyCode;} ;BiCommand.prototype.setKeyCode = function(v){ this._keyCode = v;} ;BiCommand.prototype.getOwnerWindow = function(){ return this._ownerWindow;} ;_p.execute = function(){ this.dispatchEvent(new BiEvent("execute"));} ;_p.setEnabled = function(b){ if (this._enabled != b) { this._enabled = b; this.dispatchEvent(new BiEvent("enabledchanged")); }};_p.setChecked = function(b){ if (this._checked != b) { this._checked = b; this.dispatchEvent(new BiEvent("checkedchanged")); }};_p.setUserValue = function(v){ if (this._userValue != v) { this._userValue = v; this.dispatchEvent(new BiEvent("uservaluechanged")); }};_p.setShortcut = function(s){ if (this._shortcut != s) { this._shortcut = s; if (s != null) { var a = String(s).toLowerCase().split(/[-+\s]+/); this._shortcutParts = { }; for (var i = 0; i < a.length; i++) this._shortcutParts[a[i]] = true; } else this._shortcutParts = null; this.dispatchEvent(new BiEvent("shortcutchanged")); }};_p.matchesKeyboardEvent = function(e){ if (!this._shortcut || this._shortcutParts.shift && !e.getShiftKey() || this._shortcutParts.ctrl && !e.getCtrlKey() || this._shortcutParts.alt && !e.getAltKey()) { return false; } var kc = e.getKeyCode(); if (this._keyCode != null && kc == this._keyCode) return true; var c = String.fromCharCode(kc).toLowerCase(); if (this._shortcutParts[c]) return true; if (this._keyCode == null) { for (var n in this._shortcutParts) { if (n != "ctrl" && n != "shift" && n != "alt" && n != "control" && kc == BiKeyboardEvent[n.toUpperCase()]) { return true; } } } return false;};_p.dispose = function(){ if (this.getDisposed()) return; this._ownerWindow = null; BiEventTarget.prototype.dispose.call(this);};function BiButton(sText){ BiLabel.call(this, sText); this.setCssClassName("bi-button"); this.setTabIndex(1); this.addEventListener("click", this._onclick); this.setCanSelect(true);}var _p = BiButton.prototype = new BiLabel;_p._className = "BiButton";_p._tagName = "BUTTON";_p._acceptsEnter = true;_p._onclick = function(){ if (this.getIsEnabled()) { this.dispatchEvent(new BiEvent("action")); if (this._command) this._command.execute(); }};function BiCheckBox(sText, bChecked){ BiLabel.call(this, sText); this._checkBoxId = this.getHtmlProperty("id") + "-check-box"; this._checked = Boolean(bChecked); this.setHtmlProperty("htmlFor", this._checkBoxId); this.setTabIndex(1); this.addEventListener("click", this._onclick); this.addEventListener("keydown", this._onkeydown); this.addEventListener("keyup", this._onkeyup);}var _p = BiCheckBox.prototype = new BiLabel;_p._className = "BiCheckBox";_p._drawIcon = true;_p._iconTextGap = 5;_p._acceptsEnter = true;_p._userValue = null;BiCheckBox.prototype.getUserValue = function(){ return this._userValue;} ;_p.setUserValue = function(v){ if (this._userValue != v) { this._userValue = v; if (this._command) this._command.setUserValue(v); }};_p._getIconHtml = function(){ var marginSide, blockStyle = ""; switch (this._iconPosition) { case "right": marginSide = "left"; break; case "top": marginSide = "bottom"; blockStyle = "display:block;" break; case "bottom": marginSide = "top"; blockStyle = "display:block;" break; default: marginSide = "right"; break; } var bHasText = !(this._html == "" || this._text == "") var iconTextGap = bHasText ? this._iconTextGap : 0; return "<input type=\"checkbox\" class=\"bi-check-box-input\" tabIndex=\"-1\""+(this._checked?" checked=\"true\"":"")+(!this._enabled?" disabled=\"true\"":"")+" id=\""+this._checkBoxId+"\""+" style=\""+blockStyle+"margin-"+marginSide+":"+iconTextGap+"px;"+"\">";};_p.setLabelFor = _p.getLabelFor = _p.setIcon = _p.getIcon = function(){ throw new Error("Not supported by BiCheckBox");} ;_p.setChecked = function(bChecked){ if (this._checked != bChecked) { this._checked = bChecked; if (this._input) { this._input.checked = bChecked; this._input.defaultChecked = bChecked; } this.dispatchEvent(new BiEvent("change")); if (this._command) this._command.setChecked(this.getChecked()); }};_p.getChecked = function(bChecked){ return this._checked;} ;_p.setValue = _p.setChecked;_p.getValue = _p.getChecked;_p._setHtml = function(){ BiLabel.prototype._setHtml.call(this); if (this._created) { this._input = this._element.getElementsByTagName("INPUT")[0]; if (BiBrowserCheck.ie) { this._element.onclick = BiComponent.__oninlineevent; } }};_p.dispose = function(){ if (this._disposed) return; BiLabel.prototype.dispose.call(this); if (this._input) { this._input._biComponent = null; this._input.onclick = null; } this._input = null;};_p._onclick = function(e){ if (this.getIsEnabled()) { var be = e._event; var el = be.target || be.srcElement; if (el == this._input) { this.setChecked(this._input.checked); this._dispatchAction(); } else if (BiBrowserCheck.moz) { this.setChecked(!this._input.checked); this._dispatchAction(); } }};_p._onkeydown = function(e){ if (e.getKeyCode() == BiKeyboardEvent.ENTER && !e.getAltKey()) { this.setChecked(!this._input.checked); this._dispatchAction(); }};_p._onkeyup = function(e){ if (e.getKeyCode() == BiKeyboardEvent.SPACE) { var be = e._event; var el = be.target || be.srcElement; if (el == this._input) return; this.setChecked(!this._input.checked); this._dispatchAction(); }};_p._oninlineevent = function(e){ if (BiBrowserCheck.ie) { var e = this._document.parentWindow.event; if (e.type == "click") e.cancelBubble = e.srcElement != this._input; else BiComponent.prototype._oninlineevent.call(this, e); } else BiComponent.prototype._oninlineevent.call(this, e);};_p._dispatchAction = function(){ this.dispatchEvent(new BiEvent("action")); if (this._command) this._command.execute();};_p._syncWithCommmand = function(){ if (this._command) { this.setEnabled(this._command.getEnabled()); this.setChecked(this._command.getChecked()); this.setUserValue(this._command.getUserValue()); }};function BiRadioButton(sText, bChecked){ BiLabel.call(this, sText); this._checked = Boolean(bChecked); this._radioButtonId = this.getHtmlProperty("id") + "-radio-button"; this.setTabIndex(1); this.addEventListener("click", this._onclick); this.addEventListener("keydown", this._onkeydown); this.addEventListener("keyup", this._onkeyup); this.setHtmlProperty("htmlFor", this._radioButtonId);}var _p = BiRadioButton.prototype = new BiLabel;_p._className = "BiRadioButton";_p._drawIcon = true;_p._iconTextGap = 5;_p._radioGroup = null;_p._acceptsEnter = true;_p._acceptsEsc = true;_p._userValue = null;BiRadioButton.prototype.getUserValue = function(){ return this._userValue;} ;_p.setUserValue = function(v){ if (this._userValue != v) { this._userValue = v; if (this._command) this._command.setUserValue(v); }};_p.setLabelFor = _p.getLabelFor = _p.setIcon = _p.getIcon = function(){ throw new Error("Not supported by BiRadioButton");} ;_p.setChecked = function(bChecked){ if (this._checked != bChecked) { this._checked = bChecked; if (this._created) { this._input.checked = bChecked; this._input.defaultChecked = bChecked; } this.dispatchEvent(new BiEvent("change")); if (this._group && bChecked) this._group.setSelected(this); }};_p.getChecked = function(bChecked){ return this._checked;} ;_p.setGroup = function(oRadioGroup){ if (this._group != oRadioGroup) { if (this._group) this._group.remove(this); this._group = oRadioGroup; if (this._group) { this._group.add(this); } this._setHtml(); }};BiRadioButton.prototype.getGroup = function(){ return this._group;} ;_p._setHtml = function(){ BiLabel.prototype._setHtml.call(this); if (this._created) { this._input = this._element.getElementsByTagName("INPUT")[0]; if (BiBrowserCheck.ie) { this._element.onclick = BiComponent.__oninlineevent; } }};_p.dispose = function(){ if (this._disposed) return; BiLabel.prototype.dispose.call(this); if (this._input) { this._input._biComponent = null; this._input.onclick = null; } this._input = null;};_p._getIconHtml = function(){ var marginSide, blockStyle = ""; switch (this._iconPosition) { case "right": marginSide = "left"; break; case "top": marginSide = "bottom"; blockStyle = "display:block;" break; case "bottom": marginSide = "top"; blockStyle = "display:block;" break; default: marginSide = "right"; break; } var bHasText = !(this._html == "" || this._text == "") var iconTextGap = bHasText ? this._iconTextGap : 0; return "<input type=\"radio\" class=\"bi-radio-button-input\""+(this._checked?" checked=\"true\"":"")+(!this._enabled?" disabled=\"true\"":"")+" id=\""+this._radioButtonId+"\""+" name=\""+this._radioButtonId+"\" style=\""+blockStyle+"margin-"+marginSide+":"+iconTextGap+"px;"+"\">";};_p._onclick = function(e){ if (this.getIsEnabled()) { var be = e._event; var el = be.target || be.srcElement; if (el == this._input) { this.setChecked(true); this.dispatchEvent(new BiEvent("action")) } else if (BiBrowserCheck.moz) { this.setChecked(true); this.dispatchEvent(new BiEvent("action")); } }};_p._onkeydown = function(e){ var kc = e.getKeyCode(); if (kc == BiKeyboardEvent.ENTER && !e.getAltKey()) { this.setChecked(true); var e = new BiEvent("action"); this.dispatchEvent(e); e.dispose(); } else if (this._group && (kc == BiKeyboardEvent.LEFT || kc == BiKeyboardEvent.UP)) this._group.selectPrevious(this); else if (this._group && (kc == BiKeyboardEvent.RIGHT || kc == BiKeyboardEvent.DOWN)) this._group.selectNext(this);};_p._onkeyup = function(e){ if (e.getKeyCode() == BiKeyboardEvent.SPACE) { var be = e._event; var el = be.target || be.srcElement;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -