2 * Ext JS Library 0.30
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.air.NativeWindow
\r
11 * @extends Ext.air.NativeObservable
\r
13 * Wraps the AIR NativeWindow class to give an Ext friendly API. <br/><br/>This class also adds
\r
14 * automatic state management (position and size) for the window (by id) and it can be used
\r
15 * for easily creating "minimize to system tray" for the main window in your application.<br/><br/>
\r
17 * Note: Many of the config options for this class can only be applied to NEW windows. Passing
\r
18 * in an existing instance of a window along with those config options will have no effect.
\r
21 * @param {Object} config
\r
23 Ext.air.NativeWindow = function(config){
\r
24 Ext.apply(this, config);
\r
29 this.id = this.id || Ext.uniqueId();
\r
34 * @param {Object} e The air event object
\r
39 * @param {Object} e The air event object
\r
44 * @param {Object} e The air event object
\r
49 * @param {Object} e The air event object
\r
54 * @param {Object} e The air event object
\r
59 * @param {Object} e The air event object
\r
63 * @event displayStateChange
\r
64 * @param {Object} e The air event object
\r
66 'displayStateChange',
\r
68 * @event displayStateChanging
\r
69 * @param {Object} e The air event object
\r
71 'displayStateChanging'
\r
74 Ext.air.NativeWindow.superclass.constructor.call(this);
\r
77 var options = new air.NativeWindowInitOptions();
\r
78 options.systemChrome = this.chrome;
\r
79 options.type = this.type;
\r
80 options.resizable = this.resizable;
\r
81 options.minimizable = this.minimizable;
\r
82 options.maximizable = this.maximizable;
\r
83 options.transparent = this.transparent;
\r
85 this.loader = window.runtime.flash.html.HTMLLoader.createRootWindow(false, options, false);
\r
87 this.loader.load(new air.URLRequest(this.file));
\r
89 this.loader.loadString(this.html || '');
\r
93 this.instance = this.loader.window.nativeWindow;
\r
95 this.loader = this.instance.stage.getChildAt(0);
\r
98 var provider = Ext.state.Manager;
\r
99 var b = air.Screen.mainScreen.visibleBounds;
\r
101 var state = provider.get(this.id) || {};
\r
102 provider.set(this.id, state);
\r
104 var win = this.instance;
\r
106 var width = Math.max(state.width || this.width, 100);
\r
107 var height = Math.max(state.height || this.height, 100);
\r
109 var centerX = b.x + ((b.width/2)-(width/2));
\r
110 var centerY = b.y + ((b.height/2)-(height/2));
\r
112 var x = !Ext.isEmpty(state.x, false) ? state.x : (!Ext.isEmpty(this.x, false) ? this.x : centerX);
\r
113 var y = !Ext.isEmpty(state.y, false) ? state.y : (!Ext.isEmpty(this.y, false) ? this.y : centerY);
\r
116 win.height = height;
\r
120 win.addEventListener('move', function(){
\r
121 if(win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
\r
126 win.addEventListener('resize', function(){
\r
127 if (win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
\r
128 state.width = win.width;
\r
129 state.height = win.height;
\r
133 Ext.air.NativeWindowManager.register(this);
\r
134 this.on('close', this.unregister, this);
\r
137 * @cfg {Boolean} minimizeToTray
\r
138 * True to enable minimizing to the system tray. Note: this should only be applied
\r
139 * to the primary window in your application. A trayIcon is required.
\r
141 if(this.minimizeToTray){
\r
142 this.initMinimizeToTray(this.trayIcon, this.trayMenu);
\r
147 Ext.extend(Ext.air.NativeWindow, Ext.air.NativeObservable, {
\r
150 * @cfg {air.NativeWindow} instance
\r
151 * The native window instance to wrap. If undefined, a new window will be created.
\r
155 * @cfg {String} trayIcon
\r
156 * The icon to display when minimized in the system tray
\r
159 * @cfg {NativeMenu} trayMenu
\r
160 * Menu to display when the tray icon is right clicked
\r
163 * @cfg {String} trayTip
\r
164 * Tooltip for the tray icon
\r
168 * @cfg {String} chrome
\r
169 * The native window chrome (defaults to 'standard', can also be 'none').
\r
171 chrome: 'standard', // can also be none
\r
173 * @cfg {String} type
\r
174 * The native window type - normal, utility or lightweight. (defaults to normal)
\r
176 type: 'normal', // can be normal, utility or lightweight
\r
178 * @cfg {Number} width
\r
182 * @cfg {Number} height
\r
186 * @cfg {Boolean} resizable
\r
190 * @cfg {Boolean} minimizable
\r
194 * @cfg {Boolean} maximizable
\r
198 * @cfg {Boolean} transparent
\r
200 transparent: false,
\r
203 * Returns the air.NativeWindow instance
\r
204 * @return air.NativeWindow
\r
206 getNative : function(){
\r
207 return this.instance;
\r
211 * Returns the x/y coordinates for centering the windw on the screen
\r
212 * @return {x: Number, y: Number}
\r
214 getCenterXY : function(){
\r
215 var b = air.Screen.mainScreen.visibleBounds;
\r
217 x: b.x + ((b.width/2)-(this.width/2)),
\r
218 y: b.y + ((b.height/2)-(this.height/2))
\r
227 Ext.air.SystemTray.hideIcon();
\r
228 this.trayed = false;
\r
230 this.instance.visible = true;
\r
234 * Shows and activates the window
\r
236 activate : function(){
\r
238 this.instance.activate();
\r
245 this.instance.visible = false;
\r
249 * Closes the window
\r
251 close : function(){
\r
252 this.instance.close();
\r
256 * Returns true if this window is minimized
\r
259 isMinimized :function(){
\r
260 return this.instance.displayState == air.NativeWindowDisplayState.MINIMIZED;
\r
264 * Returns true if this window is maximized
\r
267 isMaximized :function(){
\r
268 return this.instance.displayState == air.NativeWindowDisplayState.MAXIMIZED;
\r
272 * Moves the window to the passed xy and y coordinates
\r
273 * @param {Number} x
\r
274 * @param {Number} y
\r
276 moveTo : function(x, y){
\r
277 this.x = this.instance.x = x;
\r
278 this.y = this.instance.y = y;
\r
281 * Enter full-screen mode for the window.
\r
282 * @param {Boolean} nonInteractive (optional) Boolean flag to allow the full screen window to be interactive or not. By default this is false.
\r
284 * var win = new Ext.air.NativeWindow({instance: Ext.air.NativeWindow.getRootWindow()});
\r
285 * win.fullscreen();
\r
287 fullscreen: function(nonInteractive) {
\r
288 var SDS = runtime.flash.display.StageDisplayState;
\r
289 this.instance.stage.displayState = nonInteractive ? SDS.FULL_SCREEN : SDS.FULL_SCREEN_INTERACTIVE;
\r
292 bringToFront: function() {
\r
293 this.instance.orderToFront();
\r
296 bringInFrontOf: function(win) {
\r
297 this.instance.orderInFrontOf(win.instance ? win.instance : win);
\r
300 sendToBack: function() {
\r
301 this.instance.orderToBack();
\r
304 sendBehind: function(win) {
\r
305 this.instance.orderInBackOf(win.instance ? win.instance : win);
\r
310 * @param {Number} width
\r
311 * @param {Number} height
\r
313 resize : function(width, height){
\r
314 this.width = this.instance.width = width;
\r
315 this.height = this.instance.height = height;
\r
318 unregister : function(){
\r
319 Ext.air.NativeWindowManager.unregister(this);
\r
322 initMinimizeToTray : function(icon, menu){
\r
323 var tray = Ext.air.SystemTray;
\r
325 tray.setIcon(icon, this.trayTip);
\r
326 this.on('displayStateChanging', function(e){
\r
327 if(e.afterDisplayState == 'minimized'){
\r
328 e.preventDefault();
\r
331 this.trayed = true;
\r
335 tray.on('click', function(){
\r
340 tray.setMenu(menu);
\r
346 * Returns the first opened window in your application
\r
347 * @return air.NativeWindow
\r
350 Ext.air.NativeWindow.getRootWindow = function(){
\r
351 return air.NativeApplication.nativeApplication.openedWindows[0];
\r
355 * Returns the javascript "window" object of the first opened window in your application
\r
359 Ext.air.NativeWindow.getRootHtmlWindow = function(){
\r
360 return Ext.air.NativeWindow.getRootWindow().stage.getChildAt(0).window;
\r
364 * @class Ext.air.NativeWindowGroup
\r
366 * A collection of NativeWindows.
\r
368 Ext.air.NativeWindowGroup = function(){
\r
373 * @param {Object} win
\r
375 register : function(win){
\r
376 list[win.id] = win;
\r
380 * @param {Object} win
\r
382 unregister : function(win){
\r
383 delete list[win.id];
\r
387 * @param {String} id
\r
389 get : function(id){
\r
394 * Closes all windows
\r
396 closeAll : function(){
\r
397 for(var id in list){
\r
398 if(list.hasOwnProperty(id)){
\r
405 * Executes the specified function once for every window in the group, passing each
\r
406 * window as the only parameter. Returning false from the function will stop the iteration.
\r
407 * @param {Function} fn The function to execute for each item
\r
408 * @param {Object} scope (optional) The scope in which to execute the function
\r
410 each : function(fn, scope){
\r
411 for(var id in list){
\r
412 if(list.hasOwnProperty(id)){
\r
413 if(fn.call(scope || list[id], list[id]) === false){
\r
423 * @class Ext.air.NativeWindowManager
\r
424 * @extends Ext.air.NativeWindowGroup
\r
426 * Collection of all NativeWindows created.
\r
430 Ext.air.NativeWindowManager = new Ext.air.NativeWindowGroup();