Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / air / src / NativeWindow.js
diff --git a/air/src/NativeWindow.js b/air/src/NativeWindow.js
deleted file mode 100644 (file)
index abdb3a2..0000000
+++ /dev/null
@@ -1,430 +0,0 @@
-/*\r
- * Ext JS Library 0.30\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.air.NativeWindow\r
- * @extends Ext.air.NativeObservable\r
- * \r
- * Wraps the AIR NativeWindow class to give an Ext friendly API. <br/><br/>This class also adds \r
- * automatic state management (position and size) for the window (by id) and it can be used \r
- * for easily creating "minimize to system tray" for the main window in your application.<br/><br/>\r
- * \r
- * Note: Many of the config options for this class can only be applied to NEW windows. Passing \r
- * in an existing instance of a window along with those config options will have no effect.\r
- * \r
- * @constructor\r
- * @param {Object} config\r
- */\r
-Ext.air.NativeWindow = function(config){\r
-       Ext.apply(this, config);\r
-       \r
-       /**\r
-        * @type String\r
-        */\r
-       this.id = this.id || Ext.uniqueId();\r
-       \r
-       this.addEvents(\r
-               /**\r
-                * @event close\r
-                * @param {Object} e The air event object\r
-                */\r
-               'close', \r
-               /**\r
-                * @event closing\r
-                * @param {Object} e The air event object\r
-                */\r
-               'closing',\r
-               /**\r
-                * @event move\r
-                * @param {Object} e The air event object\r
-                */\r
-               'move',\r
-               /**\r
-                * @event moving\r
-                * @param {Object} e The air event object\r
-                */\r
-               'moving',\r
-               /**\r
-                * @event resize\r
-                * @param {Object} e The air event object\r
-                */\r
-               'resize',\r
-               /**\r
-                * @event resizing\r
-                * @param {Object} e The air event object\r
-                */\r
-               'resizing',\r
-               /**\r
-                * @event displayStateChange\r
-                * @param {Object} e The air event object\r
-                */\r
-               'displayStateChange',\r
-               /**\r
-                * @event displayStateChanging\r
-                * @param {Object} e The air event object\r
-                */\r
-               'displayStateChanging'\r
-       );\r
-       \r
-       Ext.air.NativeWindow.superclass.constructor.call(this);\r
-       \r
-       if(!this.instance){\r
-               var options = new air.NativeWindowInitOptions();\r
-               options.systemChrome = this.chrome;\r
-               options.type = this.type;\r
-               options.resizable = this.resizable;\r
-               options.minimizable = this.minimizable;\r
-               options.maximizable = this.maximizable;\r
-               options.transparent = this.transparent;\r
-               \r
-               this.loader = window.runtime.flash.html.HTMLLoader.createRootWindow(false, options, false);\r
-               if (this.file) {\r
-                       this.loader.load(new air.URLRequest(this.file));        \r
-               } else {\r
-                       this.loader.loadString(this.html || '');\r
-               }\r
-               \r
-       \r
-               this.instance = this.loader.window.nativeWindow;\r
-       }else{\r
-               this.loader = this.instance.stage.getChildAt(0);\r
-       }\r
-       \r
-       var provider = Ext.state.Manager;\r
-       var b = air.Screen.mainScreen.visibleBounds;\r
-       \r
-       var state = provider.get(this.id) || {};\r
-       provider.set(this.id, state);\r
-               \r
-       var win = this.instance;\r
-       \r
-       var width = Math.max(state.width || this.width, 100);\r
-       var height = Math.max(state.height || this.height, 100);\r
-       \r
-       var centerX = b.x + ((b.width/2)-(width/2));\r
-       var centerY = b.y + ((b.height/2)-(height/2));\r
-       \r
-       var x = !Ext.isEmpty(state.x, false) ? state.x : (!Ext.isEmpty(this.x, false) ? this.x : centerX);\r
-       var y = !Ext.isEmpty(state.y, false) ? state.y : (!Ext.isEmpty(this.y, false) ? this.y : centerY);\r
-       \r
-       win.width = width;\r
-       win.height = height;\r
-       win.x = x;\r
-       win.y = y;\r
-       \r
-       win.addEventListener('move', function(){\r
-               if(win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {\r
-                       state.x = win.x;\r
-                       state.y = win.y;\r
-               }\r
-       });     \r
-       win.addEventListener('resize', function(){\r
-               if (win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {\r
-                       state.width = win.width;\r
-                       state.height = win.height;\r
-               }\r
-       });\r
-       \r
-       Ext.air.NativeWindowManager.register(this);\r
-       this.on('close', this.unregister, this);\r
-       \r
-       /**\r
-        * @cfg {Boolean} minimizeToTray \r
-        * True to enable minimizing to the system tray. Note: this should only be applied\r
-        * to the primary window in your application. A trayIcon is required.\r
-        */\r
-       if(this.minimizeToTray){\r
-               this.initMinimizeToTray(this.trayIcon, this.trayMenu);\r
-       }\r
-       \r
-};\r
-\r
-Ext.extend(Ext.air.NativeWindow, Ext.air.NativeObservable, {\r
-       \r
-       /**\r
-        * @cfg {air.NativeWindow} instance \r
-        * The native window instance to wrap. If undefined, a new window will be created.\r
-        */\r
-       \r
-       /**\r
-        * @cfg {String} trayIcon \r
-        * The icon to display when minimized in the system tray\r
-        */\r
-       /**\r
-        * @cfg {NativeMenu} trayMenu \r
-        * Menu to display when the tray icon is right clicked\r
-        */\r
-       /**\r
-        * @cfg {String} trayTip \r
-        * Tooltip for the tray icon\r
-        */     \r
-       \r
-       /**\r
-        * @cfg {String} chrome \r
-        * The native window chrome (defaults to 'standard', can also be 'none').\r
-        */\r
-       chrome: 'standard', // can also be none\r
-       /**\r
-        * @cfg {String} type \r
-        * The native window type - normal, utility or lightweight. (defaults to normal)\r
-        */\r
-       type: 'normal', // can be normal, utility or lightweight\r
-       /**\r
-        * @cfg {Number} width\r
-        */\r
-       width:600,\r
-       /**\r
-        * @cfg {Number} height \r
-        */\r
-       height:400,\r
-       /**\r
-        * @cfg {Boolean} resizable \r
-        */\r
-       resizable: true,\r
-       /**\r
-        * @cfg {Boolean} minimizable \r
-        */\r
-       minimizable: true,\r
-       /**\r
-        * @cfg {Boolean} maximizable \r
-        */\r
-       maximizable: true,\r
-       /**\r
-        * @cfg {Boolean} transparent\r
-        */\r
-       transparent: false,\r
-       \r
-       /**\r
-        * Returns the air.NativeWindow instance\r
-        * @return air.NativeWindow\r
-        */\r
-       getNative : function(){\r
-               return this.instance;\r
-       },\r
-       \r
-       /**\r
-        * Returns the x/y coordinates for centering the windw on the screen\r
-        * @return {x: Number, y: Number}\r
-        */\r
-       getCenterXY : function(){\r
-               var b = air.Screen.mainScreen.visibleBounds;\r
-               return {\r
-                       x: b.x + ((b.width/2)-(this.width/2)),\r
-                       y: b.y + ((b.height/2)-(this.height/2))\r
-               };\r
-       },\r
-       \r
-       /**\r
-        * Shows the window\r
-        */\r
-       show :function(){\r
-               if(this.trayed){\r
-                       Ext.air.SystemTray.hideIcon();\r
-                       this.trayed = false;\r
-               }\r
-               this.instance.visible = true;\r
-       },\r
-       \r
-       /**\r
-        * Shows and activates the window\r
-        */\r
-       activate : function(){\r
-               this.show();\r
-               this.instance.activate();\r
-       },\r
-       \r
-       /**\r
-        * Hides the window\r
-        */\r
-       hide :function(){\r
-               this.instance.visible = false;\r
-       },\r
-       \r
-       /**\r
-        * Closes the window\r
-        */\r
-       close : function(){\r
-               this.instance.close();  \r
-       },\r
-       \r
-       /**\r
-        * Returns true if this window is minimized\r
-        * @return Boolean\r
-        */\r
-       isMinimized :function(){\r
-               return this.instance.displayState == air.NativeWindowDisplayState.MINIMIZED;\r
-       },\r
-       \r
-       /**\r
-        * Returns true if this window is maximized\r
-        * @return Boolean\r
-        */\r
-       isMaximized :function(){\r
-               return this.instance.displayState == air.NativeWindowDisplayState.MAXIMIZED;\r
-       },\r
-       \r
-       /**\r
-        * Moves the window to the passed xy and y coordinates\r
-        * @param {Number} x\r
-        * @param {Number} y\r
-        */\r
-       moveTo : function(x, y){\r
-               this.x = this.instance.x = x;\r
-               this.y = this.instance.y = y;   \r
-       },\r
-       /**\r
-        * Enter full-screen mode for the window.\r
-        * @param {Boolean} nonInteractive (optional) Boolean flag to allow the full screen window to be interactive or not. By default this is false.\r
-        * Example Code:\r
-        * var win = new Ext.air.NativeWindow({instance: Ext.air.NativeWindow.getRootWindow()});\r
-        * win.fullscreen();\r
-        */\r
-       fullscreen: function(nonInteractive) {\r
-               var SDS = runtime.flash.display.StageDisplayState;\r
-               this.instance.stage.displayState = nonInteractive ? SDS.FULL_SCREEN : SDS.FULL_SCREEN_INTERACTIVE; \r
-       },\r
-       \r
-       bringToFront: function() {\r
-               this.instance.orderToFront();\r
-       },\r
-       \r
-       bringInFrontOf: function(win) {\r
-               this.instance.orderInFrontOf(win.instance ? win.instance : win);\r
-       },\r
-       \r
-       sendToBack: function() {\r
-               this.instance.orderToBack();\r
-       },\r
-       \r
-       sendBehind: function(win) {\r
-               this.instance.orderInBackOf(win.instance ? win.instance : win);\r
-       },\r
-       \r
-       \r
-       /**\r
-        * @param {Number} width\r
-        * @param {Number} height\r
-        */\r
-       resize : function(width, height){\r
-               this.width = this.instance.width = width;\r
-               this.height = this.instance.height = height;    \r
-       },\r
-       \r
-       unregister : function(){\r
-               Ext.air.NativeWindowManager.unregister(this);\r
-       },\r
-       \r
-       initMinimizeToTray : function(icon, menu){\r
-               var tray = Ext.air.SystemTray;\r
-               \r
-               tray.setIcon(icon, this.trayTip);\r
-               this.on('displayStateChanging', function(e){\r
-                       if(e.afterDisplayState == 'minimized'){\r
-                               e.preventDefault();\r
-                               this.hide();\r
-                               tray.showIcon();\r
-                               this.trayed = true;\r
-                       }\r
-               }, this);\r
-               \r
-               tray.on('click', function(){\r
-                       this.activate();\r
-               }, this);\r
-               \r
-               if(menu){\r
-                       tray.setMenu(menu);\r
-               }\r
-       }\r
-});\r
-\r
-/**\r
- * Returns the first opened window in your application\r
- * @return air.NativeWindow\r
- * @static\r
- */\r
-Ext.air.NativeWindow.getRootWindow = function(){\r
-       return air.NativeApplication.nativeApplication.openedWindows[0];\r
-};\r
-\r
-/**\r
- * Returns the javascript "window" object of the first opened window in your application\r
- * @return Window\r
- * @static\r
- */\r
-Ext.air.NativeWindow.getRootHtmlWindow = function(){\r
-       return Ext.air.NativeWindow.getRootWindow().stage.getChildAt(0).window;\r
-};\r
-\r
-/**\r
- * @class Ext.air.NativeWindowGroup\r
- * \r
- * A collection of NativeWindows.\r
- */\r
-Ext.air.NativeWindowGroup = function(){\r
-    var list = {};\r
-\r
-    return {\r
-               /**\r
-                * @param {Object} win\r
-                */\r
-        register : function(win){\r
-            list[win.id] = win;\r
-        },\r
-\r
-        /**\r
-                * @param {Object} win\r
-                */\r
-        unregister : function(win){\r
-            delete list[win.id];\r
-        },\r
-\r
-        /**\r
-                * @param {String} id\r
-                */\r
-        get : function(id){\r
-            return list[id];\r
-        },\r
-\r
-        /**\r
-                * Closes all windows\r
-                */\r
-        closeAll : function(){\r
-            for(var id in list){\r
-                if(list.hasOwnProperty(id)){\r
-                    list[id].close();\r
-                }\r
-            }\r
-        },\r
-\r
-        /**\r
-         * Executes the specified function once for every window in the group, passing each\r
-         * window as the only parameter. Returning false from the function will stop the iteration.\r
-         * @param {Function} fn The function to execute for each item\r
-         * @param {Object} scope (optional) The scope in which to execute the function\r
-         */\r
-        each : function(fn, scope){\r
-            for(var id in list){\r
-                if(list.hasOwnProperty(id)){\r
-                    if(fn.call(scope || list[id], list[id]) === false){\r
-                        return;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-    };\r
-};\r
-\r
-/**\r
- * @class Ext.air.NativeWindowManager\r
- * @extends Ext.air.NativeWindowGroup\r
- * \r
- * Collection of all NativeWindows created.\r
- * \r
- * @singleton\r
- */\r
-Ext.air.NativeWindowManager = new Ext.air.NativeWindowGroup();
\ No newline at end of file