--- /dev/null
+<html>\r
+<head>\r
+ <title>The source code</title>\r
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
+</head>\r
+<body onload="prettyPrint();">\r
+ <pre class="prettyprint lang-js"><div id="cls-Ext.air.NativeWindow"></div>/**\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
+ <div id="prop-Ext.air.NativeWindow-id"></div>/**\r
+ * @type String\r
+ */\r
+ this.id = this.id || Ext.uniqueId();\r
+ \r
+ this.addEvents(\r
+ <div id="event-Ext.air.NativeWindow-close"></div>/**\r
+ * @event close\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'close', \r
+ <div id="event-Ext.air.NativeWindow-closing"></div>/**\r
+ * @event closing\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'closing',\r
+ <div id="event-Ext.air.NativeWindow-move"></div>/**\r
+ * @event move\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'move',\r
+ <div id="event-Ext.air.NativeWindow-moving"></div>/**\r
+ * @event moving\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'moving',\r
+ <div id="event-Ext.air.NativeWindow-resize"></div>/**\r
+ * @event resize\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'resize',\r
+ <div id="event-Ext.air.NativeWindow-resizing"></div>/**\r
+ * @event resizing\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'resizing',\r
+ <div id="event-Ext.air.NativeWindow-displayStateChange"></div>/**\r
+ * @event displayStateChange\r
+ * @param {Object} e The air event object\r
+ */\r
+ 'displayStateChange',\r
+ <div id="event-Ext.air.NativeWindow-displayStateChanging"></div>/**\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
+ this.loader.load(new air.URLRequest(this.file));\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
+ <div id="cfg-Ext.air.NativeWindow-minimizeToTray"></div>/**\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
+ <div id="cfg-Ext.air.NativeWindow-instance"></div>/**\r
+ * @cfg {air.NativeWindow} instance \r
+ * The native window instance to wrap. If undefined, a new window will be created.\r
+ */\r
+ \r
+ <div id="cfg-Ext.air.NativeWindow-trayIcon"></div>/**\r
+ * @cfg {String} trayIcon \r
+ * The icon to display when minimized in the system tray\r
+ */\r
+ <div id="cfg-Ext.air.NativeWindow-trayMenu"></div>/**\r
+ * @cfg {NativeMenu} trayMenu \r
+ * Menu to display when the tray icon is right clicked\r
+ */\r
+ <div id="cfg-Ext.air.NativeWindow-trayTip"></div>/**\r
+ * @cfg {String} trayTip \r
+ * Tooltip for the tray icon\r
+ */ \r
+ \r
+ <div id="cfg-Ext.air.NativeWindow-chrome"></div>/**\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
+ <div id="cfg-Ext.air.NativeWindow-type"></div>/**\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
+ <div id="cfg-Ext.air.NativeWindow-width"></div>/**\r
+ * @cfg {Number} width\r
+ */\r
+ width:600,\r
+ <div id="cfg-Ext.air.NativeWindow-height"></div>/**\r
+ * @cfg {Number} height \r
+ */\r
+ height:400,\r
+ <div id="cfg-Ext.air.NativeWindow-resizable"></div>/**\r
+ * @cfg {Boolean} resizable \r
+ */\r
+ resizable: true,\r
+ <div id="cfg-Ext.air.NativeWindow-minimizable"></div>/**\r
+ * @cfg {Boolean} minimizable \r
+ */\r
+ minimizable: true,\r
+ <div id="cfg-Ext.air.NativeWindow-maximizable"></div>/**\r
+ * @cfg {Boolean} maximizable \r
+ */\r
+ maximizable: true,\r
+ <div id="cfg-Ext.air.NativeWindow-transparent"></div>/**\r
+ * @cfg {Boolean} transparent\r
+ */\r
+ transparent: false,\r
+ \r
+ <div id="method-Ext.air.NativeWindow-getNative"></div>/**\r
+ * Returns the air.NativeWindow instance\r
+ * @return air.NativeWindow\r
+ */\r
+ getNative : function(){\r
+ return this.instance;\r
+ },\r
+ \r
+ <div id="method-Ext.air.NativeWindow-getCenterXY"></div>/**\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
+ <div id="method-Ext.air.NativeWindow-show"></div>/**\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
+ <div id="method-Ext.air.NativeWindow-activate"></div>/**\r
+ * Shows and activates the window\r
+ */\r
+ activate : function(){\r
+ this.show();\r
+ this.instance.activate();\r
+ },\r
+ \r
+ <div id="method-Ext.air.NativeWindow-hide"></div>/**\r
+ * Hides the window\r
+ */\r
+ hide :function(){\r
+ this.instance.visible = false;\r
+ },\r
+ \r
+ <div id="method-Ext.air.NativeWindow-close"></div>/**\r
+ * Closes the window\r
+ */\r
+ close : function(){\r
+ this.instance.close(); \r
+ },\r
+ \r
+ <div id="method-Ext.air.NativeWindow-isMinimized"></div>/**\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
+ <div id="method-Ext.air.NativeWindow-isMaximized"></div>/**\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
+ <div id="method-Ext.air.NativeWindow-moveTo"></div>/**\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
+ <div id="method-Ext.air.NativeWindow-resize"></div>/**\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
+<div id="method-Ext.air.NativeWindow-NativeWindow.getRootWindow"></div>/**\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
+<div id="method-Ext.air.NativeWindow-NativeWindow.getRootHtmlWindow"></div>/**\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
+<div id="cls-Ext.air.NativeWindowGroup"></div>/**\r
+ * @class Ext.air.NativeWindowGroup\r
+ * \r
+ * A collection of NativeWindows.\r
+ */\r
+Ext.air.NativeWindowGroup = function(){\r
+ var list = {};\r
+\r
+ return {\r
+ <div id="method-Ext.air.NativeWindowGroup-register"></div>/**\r
+ * @param {Object} win\r
+ */\r
+ register : function(win){\r
+ list[win.id] = win;\r
+ },\r
+\r
+ <div id="method-Ext.air.NativeWindowGroup-unregister"></div>/**\r
+ * @param {Object} win\r
+ */\r
+ unregister : function(win){\r
+ delete list[win.id];\r
+ },\r
+\r
+ <div id="method-Ext.air.NativeWindowGroup-get"></div>/**\r
+ * @param {String} id\r
+ */\r
+ get : function(id){\r
+ return list[id];\r
+ },\r
+\r
+ <div id="method-Ext.air.NativeWindowGroup-closeAll"></div>/**\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
+ <div id="method-Ext.air.NativeWindowGroup-each"></div>/**\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
+<div id="cls-Ext.air.NativeWindowManager"></div>/**\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();</pre> \r
+</body>\r
+</html>
\ No newline at end of file