3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.air.NativeWindow"></div>/**
\r
9 * @class Ext.air.NativeWindow
\r
10 * @extends Ext.air.NativeObservable
\r
12 * Wraps the AIR NativeWindow class to give an Ext friendly API. <br/><br/>This class also adds
\r
13 * automatic state management (position and size) for the window (by id) and it can be used
\r
14 * for easily creating "minimize to system tray" for the main window in your application.<br/><br/>
\r
16 * Note: Many of the config options for this class can only be applied to NEW windows. Passing
\r
17 * in an existing instance of a window along with those config options will have no effect.
\r
20 * @param {Object} config
\r
22 Ext.air.NativeWindow = function(config){
\r
23 Ext.apply(this, config);
\r
25 <div id="prop-Ext.air.NativeWindow-id"></div>/**
\r
28 this.id = this.id || Ext.uniqueId();
\r
31 <div id="event-Ext.air.NativeWindow-close"></div>/**
\r
33 * @param {Object} e The air event object
\r
36 <div id="event-Ext.air.NativeWindow-closing"></div>/**
\r
38 * @param {Object} e The air event object
\r
41 <div id="event-Ext.air.NativeWindow-move"></div>/**
\r
43 * @param {Object} e The air event object
\r
46 <div id="event-Ext.air.NativeWindow-moving"></div>/**
\r
48 * @param {Object} e The air event object
\r
51 <div id="event-Ext.air.NativeWindow-resize"></div>/**
\r
53 * @param {Object} e The air event object
\r
56 <div id="event-Ext.air.NativeWindow-resizing"></div>/**
\r
58 * @param {Object} e The air event object
\r
61 <div id="event-Ext.air.NativeWindow-displayStateChange"></div>/**
\r
62 * @event displayStateChange
\r
63 * @param {Object} e The air event object
\r
65 'displayStateChange',
\r
66 <div id="event-Ext.air.NativeWindow-displayStateChanging"></div>/**
\r
67 * @event displayStateChanging
\r
68 * @param {Object} e The air event object
\r
70 'displayStateChanging'
\r
73 Ext.air.NativeWindow.superclass.constructor.call(this);
\r
76 var options = new air.NativeWindowInitOptions();
\r
77 options.systemChrome = this.chrome;
\r
78 options.type = this.type;
\r
79 options.resizable = this.resizable;
\r
80 options.minimizable = this.minimizable;
\r
81 options.maximizable = this.maximizable;
\r
82 options.transparent = this.transparent;
\r
84 this.loader = window.runtime.flash.html.HTMLLoader.createRootWindow(false, options, false);
\r
85 this.loader.load(new air.URLRequest(this.file));
\r
87 this.instance = this.loader.window.nativeWindow;
\r
89 this.loader = this.instance.stage.getChildAt(0);
\r
92 var provider = Ext.state.Manager;
\r
93 var b = air.Screen.mainScreen.visibleBounds;
\r
95 var state = provider.get(this.id) || {};
\r
96 provider.set(this.id, state);
\r
98 var win = this.instance;
\r
100 var width = Math.max(state.width || this.width, 100);
\r
101 var height = Math.max(state.height || this.height, 100);
\r
103 var centerX = b.x + ((b.width/2)-(width/2));
\r
104 var centerY = b.y + ((b.height/2)-(height/2));
\r
106 var x = !Ext.isEmpty(state.x, false) ? state.x : (!Ext.isEmpty(this.x, false) ? this.x : centerX);
\r
107 var y = !Ext.isEmpty(state.y, false) ? state.y : (!Ext.isEmpty(this.y, false) ? this.y : centerY);
\r
110 win.height = height;
\r
114 win.addEventListener('move', function(){
\r
115 if(win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
\r
120 win.addEventListener('resize', function(){
\r
121 if (win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
\r
122 state.width = win.width;
\r
123 state.height = win.height;
\r
127 Ext.air.NativeWindowManager.register(this);
\r
128 this.on('close', this.unregister, this);
\r
130 <div id="cfg-Ext.air.NativeWindow-minimizeToTray"></div>/**
\r
131 * @cfg {Boolean} minimizeToTray
\r
132 * True to enable minimizing to the system tray. Note: this should only be applied
\r
133 * to the primary window in your application. A trayIcon is required.
\r
135 if(this.minimizeToTray){
\r
136 this.initMinimizeToTray(this.trayIcon, this.trayMenu);
\r
141 Ext.extend(Ext.air.NativeWindow, Ext.air.NativeObservable, {
\r
143 <div id="cfg-Ext.air.NativeWindow-instance"></div>/**
\r
144 * @cfg {air.NativeWindow} instance
\r
145 * The native window instance to wrap. If undefined, a new window will be created.
\r
148 <div id="cfg-Ext.air.NativeWindow-trayIcon"></div>/**
\r
149 * @cfg {String} trayIcon
\r
150 * The icon to display when minimized in the system tray
\r
152 <div id="cfg-Ext.air.NativeWindow-trayMenu"></div>/**
\r
153 * @cfg {NativeMenu} trayMenu
\r
154 * Menu to display when the tray icon is right clicked
\r
156 <div id="cfg-Ext.air.NativeWindow-trayTip"></div>/**
\r
157 * @cfg {String} trayTip
\r
158 * Tooltip for the tray icon
\r
161 <div id="cfg-Ext.air.NativeWindow-chrome"></div>/**
\r
162 * @cfg {String} chrome
\r
163 * The native window chrome (defaults to 'standard', can also be 'none').
\r
165 chrome: 'standard', // can also be none
\r
166 <div id="cfg-Ext.air.NativeWindow-type"></div>/**
\r
167 * @cfg {String} type
\r
168 * The native window type - normal, utility or lightweight. (defaults to normal)
\r
170 type: 'normal', // can be normal, utility or lightweight
\r
171 <div id="cfg-Ext.air.NativeWindow-width"></div>/**
\r
172 * @cfg {Number} width
\r
175 <div id="cfg-Ext.air.NativeWindow-height"></div>/**
\r
176 * @cfg {Number} height
\r
179 <div id="cfg-Ext.air.NativeWindow-resizable"></div>/**
\r
180 * @cfg {Boolean} resizable
\r
183 <div id="cfg-Ext.air.NativeWindow-minimizable"></div>/**
\r
184 * @cfg {Boolean} minimizable
\r
187 <div id="cfg-Ext.air.NativeWindow-maximizable"></div>/**
\r
188 * @cfg {Boolean} maximizable
\r
191 <div id="cfg-Ext.air.NativeWindow-transparent"></div>/**
\r
192 * @cfg {Boolean} transparent
\r
194 transparent: false,
\r
196 <div id="method-Ext.air.NativeWindow-getNative"></div>/**
\r
197 * Returns the air.NativeWindow instance
\r
198 * @return air.NativeWindow
\r
200 getNative : function(){
\r
201 return this.instance;
\r
204 <div id="method-Ext.air.NativeWindow-getCenterXY"></div>/**
\r
205 * Returns the x/y coordinates for centering the windw on the screen
\r
206 * @return {x: Number, y: Number}
\r
208 getCenterXY : function(){
\r
209 var b = air.Screen.mainScreen.visibleBounds;
\r
211 x: b.x + ((b.width/2)-(this.width/2)),
\r
212 y: b.y + ((b.height/2)-(this.height/2))
\r
216 <div id="method-Ext.air.NativeWindow-show"></div>/**
\r
221 Ext.air.SystemTray.hideIcon();
\r
222 this.trayed = false;
\r
224 this.instance.visible = true;
\r
227 <div id="method-Ext.air.NativeWindow-activate"></div>/**
\r
228 * Shows and activates the window
\r
230 activate : function(){
\r
232 this.instance.activate();
\r
235 <div id="method-Ext.air.NativeWindow-hide"></div>/**
\r
239 this.instance.visible = false;
\r
242 <div id="method-Ext.air.NativeWindow-close"></div>/**
\r
243 * Closes the window
\r
245 close : function(){
\r
246 this.instance.close();
\r
249 <div id="method-Ext.air.NativeWindow-isMinimized"></div>/**
\r
250 * Returns true if this window is minimized
\r
253 isMinimized :function(){
\r
254 return this.instance.displayState == air.NativeWindowDisplayState.MINIMIZED;
\r
257 <div id="method-Ext.air.NativeWindow-isMaximized"></div>/**
\r
258 * Returns true if this window is maximized
\r
261 isMaximized :function(){
\r
262 return this.instance.displayState == air.NativeWindowDisplayState.MAXIMIZED;
\r
265 <div id="method-Ext.air.NativeWindow-moveTo"></div>/**
\r
266 * Moves the window to the passed xy and y coordinates
\r
267 * @param {Number} x
\r
268 * @param {Number} y
\r
270 moveTo : function(x, y){
\r
271 this.x = this.instance.x = x;
\r
272 this.y = this.instance.y = y;
\r
275 <div id="method-Ext.air.NativeWindow-resize"></div>/**
\r
276 * @param {Number} width
\r
277 * @param {Number} height
\r
279 resize : function(width, height){
\r
280 this.width = this.instance.width = width;
\r
281 this.height = this.instance.height = height;
\r
284 unregister : function(){
\r
285 Ext.air.NativeWindowManager.unregister(this);
\r
288 initMinimizeToTray : function(icon, menu){
\r
289 var tray = Ext.air.SystemTray;
\r
291 tray.setIcon(icon, this.trayTip);
\r
292 this.on('displayStateChanging', function(e){
\r
293 if(e.afterDisplayState == 'minimized'){
\r
294 e.preventDefault();
\r
297 this.trayed = true;
\r
301 tray.on('click', function(){
\r
306 tray.setMenu(menu);
\r
311 <div id="method-Ext.air.NativeWindow-NativeWindow.getRootWindow"></div>/**
\r
312 * Returns the first opened window in your application
\r
313 * @return air.NativeWindow
\r
316 Ext.air.NativeWindow.getRootWindow = function(){
\r
317 return air.NativeApplication.nativeApplication.openedWindows[0];
\r
320 <div id="method-Ext.air.NativeWindow-NativeWindow.getRootHtmlWindow"></div>/**
\r
321 * Returns the javascript "window" object of the first opened window in your application
\r
325 Ext.air.NativeWindow.getRootHtmlWindow = function(){
\r
326 return Ext.air.NativeWindow.getRootWindow().stage.getChildAt(0).window;
\r
329 <div id="cls-Ext.air.NativeWindowGroup"></div>/**
\r
330 * @class Ext.air.NativeWindowGroup
\r
332 * A collection of NativeWindows.
\r
334 Ext.air.NativeWindowGroup = function(){
\r
338 <div id="method-Ext.air.NativeWindowGroup-register"></div>/**
\r
339 * @param {Object} win
\r
341 register : function(win){
\r
342 list[win.id] = win;
\r
345 <div id="method-Ext.air.NativeWindowGroup-unregister"></div>/**
\r
346 * @param {Object} win
\r
348 unregister : function(win){
\r
349 delete list[win.id];
\r
352 <div id="method-Ext.air.NativeWindowGroup-get"></div>/**
\r
353 * @param {String} id
\r
355 get : function(id){
\r
359 <div id="method-Ext.air.NativeWindowGroup-closeAll"></div>/**
\r
360 * Closes all windows
\r
362 closeAll : function(){
\r
363 for(var id in list){
\r
364 if(list.hasOwnProperty(id)){
\r
370 <div id="method-Ext.air.NativeWindowGroup-each"></div>/**
\r
371 * Executes the specified function once for every window in the group, passing each
\r
372 * window as the only parameter. Returning false from the function will stop the iteration.
\r
373 * @param {Function} fn The function to execute for each item
\r
374 * @param {Object} scope (optional) The scope in which to execute the function
\r
376 each : function(fn, scope){
\r
377 for(var id in list){
\r
378 if(list.hasOwnProperty(id)){
\r
379 if(fn.call(scope || list[id], list[id]) === false){
\r
388 <div id="cls-Ext.air.NativeWindowManager"></div>/**
\r
389 * @class Ext.air.NativeWindowManager
\r
390 * @extends Ext.air.NativeWindowGroup
\r
392 * Collection of all NativeWindows created.
\r
396 Ext.air.NativeWindowManager = new Ext.air.NativeWindowGroup();</pre>
\r