mdiwindow.as
来自「flex的一些小例子」· AS 代码 · 共 1,764 行 · 第 1/4 页
AS
1,764 行
titleBarOverlay.width = this.width; titleBarOverlay.height = this.titleBar.height; // edges resizeHandleTop.x = cornerHandleSize * .5; resizeHandleTop.y = -(edgeHandleSize * .5); resizeHandleTop.width = this.width - cornerHandleSize; resizeHandleTop.height = edgeHandleSize; resizeHandleRight.x = this.width - edgeHandleSize * .5; resizeHandleRight.y = cornerHandleSize * .5; resizeHandleRight.width = edgeHandleSize; resizeHandleRight.height = this.height - cornerHandleSize; resizeHandleBottom.x = cornerHandleSize * .5; resizeHandleBottom.y = this.height - edgeHandleSize * .5; resizeHandleBottom.width = this.width - cornerHandleSize; resizeHandleBottom.height = edgeHandleSize; resizeHandleLeft.x = -(edgeHandleSize * .5); resizeHandleLeft.y = cornerHandleSize * .5; resizeHandleLeft.width = edgeHandleSize; resizeHandleLeft.height = this.height - cornerHandleSize; // corners resizeHandleTL.x = resizeHandleTL.y = -(cornerHandleSize * .5); resizeHandleTL.width = resizeHandleTL.height = cornerHandleSize; resizeHandleTR.x = this.width - cornerHandleSize * .5; resizeHandleTR.y = -(cornerHandleSize * .5); resizeHandleTR.width = resizeHandleTR.height = cornerHandleSize; resizeHandleBR.x = this.width - cornerHandleSize * .5; resizeHandleBR.y = this.height - cornerHandleSize * .5; resizeHandleBR.width = resizeHandleBR.height = cornerHandleSize; resizeHandleBL.x = -(cornerHandleSize * .5); resizeHandleBL.y = this.height - cornerHandleSize * .5; resizeHandleBL.width = resizeHandleBL.height = cornerHandleSize; // cause windowControls container to update UIComponent(windowControls).invalidateDisplayList(); } public function get hasFocus():Boolean { return _hasFocus; } /** * Property is set by MDIManager when a window's focus changes. Triggers an update to the window's styleName. */ public function set hasFocus(value:Boolean):void { // guard against unnecessary processing if(_hasFocus == value) return; // set new value _hasFocus = value; updateStyles(); } /** * Mother of all styling functions. All styles fall back to the defaults if necessary. */ private function updateStyles():void { var selectorList:Array = getSelectorList(); // if the style specifies a class to use for the controls container that is // different from the current one we will update it here if(getStyleByPriority(selectorList, "windowControlsClass")) { var clazz:Class = getStyleByPriority(selectorList, "windowControlsClass") as Class; var classNameExisting:String = getQualifiedClassName(windowControls); var classNameNew:String = getQualifiedClassName(clazz); if(classNameExisting != classNameNew) { windowControls = new clazz(); // sometimes necessary to adjust windowControls subcomponents callLater(windowControls.invalidateDisplayList); } } // set window's styleName based on focus status if(hasFocus) { setStyle("styleName", getStyleByPriority(selectorList, "styleNameFocus")); } else { setStyle("styleName", getStyleByPriority(selectorList, "styleNameNoFocus")); } // style the window's title // this code is probably not as efficient as it could be but i am sick of dealing with styling // if titleStyleName (the style inherited from Panel) has been set we use that, regardless of focus if(!hasFocus && getStyleByPriority(selectorList, "titleStyleNameNoFocus")) { setStyle("titleStyleName", getStyleByPriority(selectorList, "titleStyleNameNoFocus")); } else if(getStyleByPriority(selectorList, "titleStyleNameFocus")) { setStyle("titleStyleName", getStyleByPriority(selectorList, "titleStyleNameFocus")); } else { getStyleByPriority(selectorList, "titleStyleName") } // style minimize button if(minimizeBtn) { // use noFocus style if appropriate and one exists if(!hasFocus && getStyleByPriority(selectorList, "minimizeBtnStyleNameNoFocus")) { minimizeBtn.styleName = getStyleByPriority(selectorList, "minimizeBtnStyleNameNoFocus"); } else { minimizeBtn.styleName = getStyleByPriority(selectorList, "minimizeBtnStyleName"); } } // style maximize/restore button if(maximizeRestoreBtn) { // fork on windowState if(maximized) { // use noFocus style if appropriate and one exists if(!hasFocus && getStyleByPriority(selectorList, "restoreBtnStyleNameNoFocus")) { maximizeRestoreBtn.styleName = getStyleByPriority(selectorList, "restoreBtnStyleNameNoFocus"); } else { maximizeRestoreBtn.styleName = getStyleByPriority(selectorList, "restoreBtnStyleName"); } } else { // use noFocus style if appropriate and one exists if(!hasFocus && getStyleByPriority(selectorList, "maximizeBtnStyleNameNoFocus")) { maximizeRestoreBtn.styleName = getStyleByPriority(selectorList, "maximizeBtnStyleNameNoFocus"); } else { maximizeRestoreBtn.styleName = getStyleByPriority(selectorList, "maximizeBtnStyleName"); } } } // style close button if(closeBtn) { // use noFocus style if appropriate and one exists if(!hasFocus && getStyleByPriority(selectorList, "closeBtnStyleNameNoFocus")) { closeBtn.styleName = getStyleByPriority(selectorList, "closeBtnStyleNameNoFocus"); } else { closeBtn.styleName = getStyleByPriority(selectorList, "closeBtnStyleName"); } } } protected function getSelectorList():Array { // initialize array with ref to ourself since inline styles take highest priority var selectorList:Array = new Array(this); // if windowStyleName was set by developer we associated styles to the list if(windowStyleName) { // make sure a corresponding style actually exists var classSelector:CSSStyleDeclaration = StyleManager.getStyleDeclaration("." + windowStyleName); if(classSelector) { selectorList.push(classSelector); } } // add type selector (created in classConstruct so we know it exists) var typeSelector:CSSStyleDeclaration = StyleManager.getStyleDeclaration("MDIWindow"); selectorList.push(typeSelector); return selectorList; } /** * Function to return appropriate style based on our funky setup. * Precedence of styles is inline, class selector (as specified by windowStyleName) * and then type selector (MDIWindow). * * @private */ protected function getStyleByPriority(selectorList:Array, style:String):Object { var n:int = selectorList.length; for(var i:int = 0; i < n; i++) { // we need to make sure this.getStyle() is not pointing to the style defined // in the type selector because styles defined in the class selector (windowStyleName) // should take precedence over type selector (MDIWindow) styles // this.getStyle() will return styles from the type selector if an inline // style was not specified if(selectorList[i] == this && selectorList[i].getStyle(style) && this.getStyle(style) === selectorList[n - 1].getStyle(style)) { continue; } if(selectorList[i].getStyle(style)) { // if this is a style name make sure the style exists if(typeof(selectorList[i].getStyle(style)) == "string" && !(StyleManager.getStyleDeclaration("." + selectorList[i].getStyle(style)))) { continue; } else { return selectorList[i].getStyle(style); } } } return null; } /** * Detects change to styleName that is executed by MDIManager indicating a change in focus. * Iterates over window controls and adjusts their styles if they're focus-aware. */ override public function styleChanged(styleProp:String):void { super.styleChanged(styleProp); if(!styleProp || styleProp == "styleName") updateStyles(); } /** * Reference to class used to create windowControls property. */ public function get windowControls():MDIWindowControlsContainer { return _windowControls; } /** * When reference is set windowControls will be reinstantiated, meaning runtime switching is supported. */ public function set windowControls(controlsContainer:MDIWindowControlsContainer):void { if(_windowControls) { var cntnr:Container = Container(windowControls); cntnr.removeAllChildren(); rawChildren.removeChild(cntnr); _windowControls = null; } _windowControls = controlsContainer; _windowControls.window = this; rawChildren.addChild(UIComponent(_windowControls)); if(windowState == MDIWindowState.MINIMIZED) { showControls = false; } } /** * Minimize window button. */ public function get minimizeBtn():Button { return windowControls.minimizeBtn; } /** * Maximize/restore window button. */ public function get maximizeRestoreBtn():Button { return windowControls.maximizeRestoreBtn; } /** * Close window button. */ public function get closeBtn():Button { return windowControls.closeBtn; } public function get showCloseButton():Boolean { return _showCloseButton; } public function set showCloseButton(value:Boolean):void { _showCloseButton = value; if(closeBtn && closeBtn.visible != value) { closeBtn.visible = value; invalidateDisplayList(); } } /** * Returns reference to titleTextField which is protected by default. * Provided to allow MDIWindowControlsContainer subclasses as much freedom as possible. */ public function getTitleTextField():UITextField { return titleTextField as UITextField; } /** * Returns reference to titleIconObject which is mx_internal by default. * Provided to allow MDIWindowControlsContainer subclasses as much freedom as possible. */ public function getTitleIconObject():DisplayObject { use namespace mx_internal; return titleIconObject as DisplayObject; } /** * Save style settings for minimizing. */ public function saveStyle():void { //this.backgroundAlphaRestore = this.getStyle("backgroundAlpha"); } /** * Restores style settings for restore and maximize */ public function restoreStyle():void { //this.setStyle("backgroundAlpha", this.backgroundAlphaRestore); } /** * Add listeners for resize handles and window controls. */ private function addListeners():void { // edges resizeHandleTop.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleTop.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleTop.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); resizeHandleRight.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleRight.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleRight.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); resizeHandleBottom.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleBottom.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleBottom.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); resizeHandleLeft.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleLeft.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleLeft.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); // corners resizeHandleTL.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleTL.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleTL.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); resizeHandleTR.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleTR.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleTR.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); resizeHandleBR.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleBR.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleBR.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); resizeHandleBL.addEventListener(MouseEvent.ROLL_OVER, onResizeButtonRollOver, false, 0, true); resizeHandleBL.addEventListener(MouseEvent.ROLL_OUT, onResizeButtonRollOut, false, 0, true); resizeHandleBL.addEventListener(MouseEvent.MOUSE_DOWN, onResizeButtonPress, false, 0, true); // titleBar overlay titleBarOverlay.addEventListener(MouseEvent.MOUSE_DOWN, onTitleBarPress, false, 0, true); titleBarOverlay.addEventListener(MouseEvent.MOUSE_UP, onTitleBarRelease, false, 0, true); titleBarOverlay.addEventListener(MouseEvent.DOUBLE_CLICK, maximizeRestore, false, 0, true); titleBarOverlay.addEventListener(MouseEvent.CLICK, unMinimize, false, 0, true); // window controls addEventListener(MouseEvent.CLICK, windowControlClickHandler, false, 0, true); // clicking anywhere brings window to front addEventListener(MouseEvent.MOUSE_DOWN, bringToFrontProxy); contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, bringToFrontProxy); } /** * Click handler for default window controls (minimize, maximize/restore and close). */ private function windowControlClickHandler(event:MouseEvent):void { if(windowControls) { if(windowControls.minimizeBtn && event.target == windowControls.minimizeBtn) { minimize(); } else if(windowControls.maximizeRestoreBtn && event.target == windowControls.maximizeRestoreBtn) { maximizeRestore(); } else if(windowControls.closeBtn && event.target == windowControls.closeBtn) { close(); } } } /** * Called automatically by clicking on window this now delegates execution to the manager. */ private function bringToFrontProxy(event:Event):void { windowManager.bringToFront(this); } /** * Minimize the window. */ public function minimize(event:MouseEvent = null):void {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?