mdiwindow.as

来自「flex的一些小例子」· AS 代码 · 共 1,764 行 · 第 1/4 页

AS
1,764
字号
/*Copyright (c) 2007 FlexLib Contributors.  See:    http://code.google.com/p/flexlib/wiki/ProjectContributorsPermission is hereby granted, free of charge, to any person obtaining a copy ofthis software and associated documentation files (the "Software"), to deal inthe Software without restriction, including without limitation the rights touse, copy, modify, merge, publish, distribute, sublicense, and/or sell copiesof the Software, and to permit persons to whom the Software is furnished to doso, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.*/package flexlib.mdi.containers{	import flash.display.DisplayObject;	import flash.events.ContextMenuEvent;	import flash.events.Event;	import flash.events.MouseEvent;	import flash.geom.Rectangle;	import flash.ui.ContextMenu;	import flash.ui.ContextMenuItem;	import flash.utils.getQualifiedClassName;		import flexlib.mdi.events.MDIWindowEvent;	import flexlib.mdi.managers.MDIManager;		import mx.containers.Canvas;	import mx.containers.Panel;	import mx.controls.Button;	import mx.core.Container;	import mx.core.UIComponent;	import mx.core.UITextField;	import mx.core.mx_internal;	import mx.managers.CursorManager;	import mx.styles.CSSStyleDeclaration;	import mx.styles.StyleManager;			//--------------------------------------	//  Events	//--------------------------------------		/**	 *  Dispatched when the minimize button is clicked.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.MINIMIZE	 */	[Event(name="minimize", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  If the window is minimized, this event is dispatched when the titleBar is clicked. 	 * 	If the window is maxmimized, this event is dispatched upon clicking the restore button	 *  or double clicking the titleBar.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.RESTORE	 */	[Event(name="restore", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the maximize button is clicked or when the window is in a	 *  normal state (not minimized or maximized) and the titleBar is double clicked.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.MAXIMIZE	 */	[Event(name="maximize", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the close button is clicked.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.CLOSE	 */	[Event(name="close", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the window gains focus and is given topmost z-index of MDIManager's children.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.FOCUS_START	 */	[Event(name="focusStart", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the window loses focus and no longer has topmost z-index of MDIManager's children.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.FOCUS_END	 */	[Event(name="focusEnd", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the window starts being dragged.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.DRAG_START	 */	[Event(name="dragStart", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched while the window is being dragged.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.DRAG	 */	[Event(name="drag", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the window stops being dragged.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.DRAG_END	 */	[Event(name="dragEnd", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when a resize handle is pressed.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.RESIZE_START	 */	[Event(name="resizeStart", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched while the mouse is down on a resize handle.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.RESIZE	 */	[Event(name="resize", type="flexlib.mdi.events.MDIWindowEvent")]		/**	 *  Dispatched when the mouse is released from a resize handle.	 *	 *  @eventType flexlib.mdi.events.MDIWindowEvent.RESIZE_END	 */	[Event(name="resizeEnd", type="flexlib.mdi.events.MDIWindowEvent")]			//--------------------------------------	//  Skins + Styles	//--------------------------------------		/**	 *  Style declaration name for the window when it has focus.	 *	 *  @default "mdiWindowFocus"	 */	[Style(name="styleNameFocus", type="String", inherit="no")]		/**	 *  Style declaration name for the window when it does not have focus.	 *	 *  @default "mdiWindowNoFocus"	 */	[Style(name="styleNameNoFocus", type="String", inherit="no")]		/**	 *  Style declaration name for the text in the title bar	 * 	when the window is in focus. If <code>titleStyleName</code> (inherited from Panel)	 *  is set, titleStyleNameFocus will be overridden by it.	 *	 *  @default "mdiWindowTitleStyle"	 */	[Style(name="titleStyleNameFocus", type="String", inherit="no")]		/**	 *  Style declaration name for the text in the title bar	 * 	when the window is not in focus. If <code>titleStyleName</code> (inherited from Panel)	 *  is set, <code>titleStyleNameNoFocus</code> will be overridden by it.	 *  If <code>titleStyleNameNoFocus</code> is not set but <code>titleStyleNameFocus</code>	 *  is, <code>titleStyleNameFocus</code> will be used, regardless of the window's focus state.	 */	[Style(name="titleStyleNameNoFocus", type="String", inherit="no")]		/**	 *  Reference to class that will contain window control buttons like	 *  minimize, close, etc. Changes to this style will be detected and will	 *  initiate the instantiation and addition of a new class instance.	 *	 *  @default flexlib.mdi.containers.MDIWindowControlsContainer	 */	[Style(name="windowControlsClass", type="Class", inherit="no")]		/**	 *  Style declaration name for the window's minimize button.	 *  If <code>minimizeBtnStyleNameNoFocus</code> is not provided this style	 *  will be used regardless of the window's focus. If <code>minimizeBtnStyleNameNoFocus</code>	 *  is provided this style will be applied only when the window has focus.	 *	 *  @default "mdiWindowMinimizeBtn"	 */	[Style(name="minimizeBtnStyleName", type="String", inherit="no")]		/**	 *  Style declaration name for the window's minimize button when window does not have focus.	 *  See <code>minimizeBtnStyleName</code> documentation for details.	 */	[Style(name="minimizeBtnStyleNameNoFocus", type="String", inherit="no")]		/**	 *  Style declaration name for the window's maximize button.	 *  If <code>maximizeBtnStyleNameNoFocus</code> is not provided this style	 *  will be used regardless of the window's focus. If <code>maximizeBtnStyleNameNoFocus</code>	 *  is provided this style will be applied only when the window has focus.	 *	 *  @default "mdiWindowMaximizeBtn"	 */	[Style(name="maximizeBtnStyleName", type="String", inherit="no")]		/**	 *  Style declaration name for the window's maximize button when window does not have focus.	 *  See <code>maximizeBtnStyleName</code> documentation for details.	 */	[Style(name="maximizeBtnStyleNameNoFocus", type="String", inherit="no")]		/**	 *  Style declaration name for the window's restore button.	 *  If <code>restoreBtnStyleNameNoFocus</code> is not provided this style	 *  will be used regardless of the window's focus. If <code>restoreBtnStyleNameNoFocus</code>	 *  is provided this style will be applied only when the window has focus.	 *	 *  @default "mdiWindowRestoreBtn"	 */	[Style(name="restoreBtnStyleName", type="String", inherit="no")]		/**	 *  Style declaration name for the window's restore button when window does not have focus.	 *  See <code>restoreBtnStyleName</code> documentation for details.	 */	[Style(name="restoreBtnStyleNameNoFocus", type="String", inherit="no")]		/**	 *  Style declaration name for the window's close button.	 *  If <code>closeBtnStyleNameNoFocus</code> is not provided this style	 *  will be used regardless of the window's focus. If <code>closeBtnStyleNameNoFocus</code>	 *  is provided this style will be applied only when the window has focus.	 *	 *  @default "mdiWindowCloseBtn"	 */	[Style(name="closeBtnStyleName", type="String", inherit="no")]		/**	 *  Style declaration name for the window's close button when window does not have focus.	 *  See <code>closeBtnStyleName</code> documentation for details.	 */	[Style(name="closeBtnStyleNameNoFocus", type="String", inherit="no")]			/**	 *  Name of the class used as cursor when resizing the window horizontally.	 */	[Style(name="resizeCursorHorizontalSkin", type="Class", inherit="no")]		/**	 *  Distance to horizontally offset resizeCursorHorizontalSkin.	 */	[Style(name="resizeCursorHorizontalXOffset", type="Number", inherit="no")]		/**	 *  Distance to vertically offset resizeCursorHorizontalSkin.	 */	[Style(name="resizeCursorHorizontalYOffset", type="Number", inherit="no")]			/**	 *  Name of the class used as cursor when resizing the window vertically.	 */	[Style(name="resizeCursorVerticalSkin", type="Class", inherit="no")]		/**	 *  Distance to horizontally offset resizeCursorVerticalSkin.	 */	[Style(name="resizeCursorVerticalXOffset", type="Number", inherit="no")]		/**	 *  Distance to vertically offset resizeCursorVerticalSkin.	 */	[Style(name="resizeCursorVerticalYOffset", type="Number", inherit="no")]			/**	 *  Name of the class used as cursor when resizing from top left or bottom right corner.	 */	[Style(name="resizeCursorTopLeftBottomRightSkin", type="Class", inherit="no")]		/**	 *  Distance to horizontally offset resizeCursorTopLeftBottomRightSkin.	 */	[Style(name="resizeCursorTopLeftBottomRightXOffset", type="Number", inherit="no")]		/**	 *  Distance to vertically offset resizeCursorTopLeftBottomRightSkin.	 */	[Style(name="resizeCursorTopLeftBottomRightYOffset", type="Number", inherit="no")]			/**	 *  Name of the class used as cursor when resizing from top right or bottom left corner.	 */	[Style(name="resizeCursorTopRightBottomLeftSkin", type="Class", inherit="no")]		/**	 *  Distance to horizontally offset resizeCursorTopRightBottomLeftSkin.	 */	[Style(name="resizeCursorTopRightBottomLeftXOffset", type="Number", inherit="no")]		/**	 *  Distance to vertically offset resizeCursorTopRightBottomLeftSkin.	 */	[Style(name="resizeCursorTopRightBottomLeftYOffset", type="Number", inherit="no")]			/**	 * Central window class used in flexlib.mdi. Includes min/max/close buttons by default.	 */	public class MDIWindow extends Panel	{				/**	     * Size of edge handles. Can be adjusted to affect "sensitivity" of resize area.	     */	    public var edgeHandleSize:Number = 4;	    	    /**	     * Size of corner handles. Can be adjusted to affect "sensitivity" of resize area.	     */		public var cornerHandleSize:Number = 10;	    	    /**	     * @private	     * Internal storage for windowState property.	     */		private var _windowState:int;				/**	     * @private	     * Internal storage of previous state, used in min/max/restore logic.	     */		private var _prevWindowState:int;				/**		 * @private		 * Internal storage of style name to be applied when window is in focus.		 */		private var _styleNameFocus:String;				/**		 * @private		 * Internal storage of style name to be applied when window is out of focus.		 */		private var _styleNameNoFocus:String;				/**	     * Parent of window controls (min, restore/max and close buttons).	     */		private var _windowControls:MDIWindowControlsContainer;				/**		 * @private		 * Flag to determine whether or not close button is visible.		 */		private var _showCloseButton:Boolean = true;				/**		 * Height of window when minimized.		 */		private var _minimizeHeight:Number;				/**		 * Flag determining whether or not this window is resizable.		 */		public var resizable:Boolean = true;				/**		 * Flag determining whether or not this window is draggable.		 */		public var draggable:Boolean = true;				/**	     * @private	     * Resize handle for top edge of window.	     */		private var resizeHandleTop:Button;				/**	     * @private	     * Resize handle for right edge of window.	     */		private var resizeHandleRight:Button;				/**	     * @private	     * Resize handle for bottom edge of window.	     */		private var resizeHandleBottom:Button;				/**	     * @private	     * Resize handle for left edge of window.	     */		private var resizeHandleLeft:Button;				/**	     * @private	     * Resize handle for top left corner of window.	     */		private var resizeHandleTL:Button;				/**	     * @private	     * Resize handle for top right corner of window.	     */		private var resizeHandleTR:Button;				/**	     * @private	     * Resize handle for bottom right corner of window.	     */		private var resizeHandleBR:Button;				/**	     * @private	     * Resize handle for bottom left corner of window.	     */		private var resizeHandleBL:Button;						/**		 * Resize handle currently in use.		 */		private var currentResizeHandle:Button;				/**	     * Rectangle to represent window's size and position when resize begins	     * or window's size/position is saved.	     */		public var savedWindowRect:Rectangle;				/**		 * @private

⌨️ 快捷键说明

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