//////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// package mx.managers.systemClasses { import flash.display.DisplayObject; import flash.display.InteractiveObject; import flash.display.Sprite; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IEventDispatcher; import flash.events.FocusEvent; import flash.events.MouseEvent; import mx.core.IChildList; import mx.core.IFlexModuleFactory; import mx.core.IRawChildrenContainer; import mx.core.IUIComponent; import mx.core.mx_internal; import mx.core.Singleton; import mx.events.DynamicEvent; import mx.events.Request; import mx.managers.IActiveWindowManager; import mx.managers.IFocusManagerContainer; import mx.managers.ISystemManager; use namespace mx_internal; [ExcludeClass] [Mixin] public class ActiveWindowManager extends EventDispatcher implements IActiveWindowManager { include "../../core/Version.as"; //-------------------------------------------------------------------------- // // Class Method // //-------------------------------------------------------------------------- public static function init(fbs:IFlexModuleFactory):void { Singleton.registerClass("mx.managers::IActiveWindowManager", ActiveWindowManager); } //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * *
This is the starting point for all Flex applications. * This class is set to be the root class of a Flex SWF file. * Flash Player instantiates an instance of this class, * causing this constructor to be called.
*/ public function ActiveWindowManager(systemManager:ISystemManager = null) { super(); if (!systemManager) return; this.systemManager = systemManager; // capture mouse down so we can switch top level windows and activate // the right focus manager before the components inside start // processing the event if (systemManager.isTopLevelRoot() || systemManager.getSandboxRoot() == systemManager) systemManager.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true); } //-------------------------------------------------------------------------- // // Variables // //-------------------------------------------------------------------------- /** * @private */ private var systemManager:ISystemManager; /** * @private * List of top level windows. */ mx_internal var forms:Array = []; /** * @private * The current top level window. * * Will be of type IFocusManagerContainer if the form * in the top-level system manager's application domain * or a child of that application domain. Otherwise the * form will be of type RemotePopUp. */ mx_internal var form:Object; //---------------------------------- // numModalWindows //---------------------------------- /** * @private * Storage for the numModalWindows property. */ private var _numModalWindows:int = 0; /** * The number of modal windows. Modal windows don't allow * clicking in another windows which would normally * activate the FocusManager in that window. The PopUpManager * modifies this count as it creates and destroys modal windows. */ public function get numModalWindows():int { return _numModalWindows; } /** * @private */ public function set numModalWindows(value:int):void { _numModalWindows = value; systemManager.numModalWindows = value; } //-------------------------------------------------------------------------- // // Methods: Focus // //-------------------------------------------------------------------------- /** * @inheritDoc */ public function activate(f:Object):void { activateForm(f); } /** * @private * * New version of activate that does not require a * IFocusManagerContainer. */ private function activateForm(f:Object):void { var e:DynamicEvent; // trace("SM: activate " + f + " " + forms.length); if (form) { if (form != f && forms.length > 1) { if (hasEventListener("activateForm")) { e = new DynamicEvent("activateForm", false, true); e.form = f; } // Switch the active form. if (!e || dispatchEvent(e)) { var z:IFocusManagerContainer = IFocusManagerContainer(form); // trace("OLW " + f + " deactivating old form " + z); z.focusManager.deactivate(); } } } form = f; var e2:DynamicEvent; if (hasEventListener("activatedForm")) { e2 = new DynamicEvent("activatedForm", false, true); e2.form = f; } if (!e2 || dispatchEvent(e2)) { if (f.focusManager) { // trace("has focus manager"); f.focusManager.activate(); } } // trace("END SM: activate " + f); } /** * @inheritDoc */ public function deactivate(f:Object):void { deactivateForm(Object(f)); } /** * @private * * New version of deactivate that works with remote pop ups. * */ private function deactivateForm(f:Object):void { var e:DynamicEvent; // trace(">>SM: deactivate " + f); if (form) { // If there's more than one form and this is it, find a new form. if (form == f && forms.length > 1) { if (hasEventListener("deactivateForm")) { e = new DynamicEvent("deactivateForm", false, true); e.form = form; } if (!e || dispatchEvent(e)) form.focusManager.deactivate(); form = findLastActiveForm(f); var e2:DynamicEvent; // make sure we have a valid top level window. // This can be null if top level window has been hidden for some reason. if (form) { if (hasEventListener("deactivatedForm")) { e2 = new DynamicEvent("deactivatedForm", false, true); e2.form = form; } if (!e2 || dispatchEvent(e2)) { // make sure we have a valid top level window. // This can be null if top level window has been hidden for some reason. if (form) { form.focusManager.activate(); } } } } } // trace("<