3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.air.NativeWindow
11
* @extends Ext.air.NativeObservable
13
* Wraps the AIR NativeWindow class to give an Ext friendly API. <br/><br/>This class also adds
14
* automatic state management (position and size) for the window (by id) and it can be used
15
* for easily creating "minimize to system tray" for the main window in your application.<br/><br/>
17
* Note: Many of the config options for this class can only be applied to NEW windows. Passing
18
* in an existing instance of a window along with those config options will have no effect.
21
* @param {Object} config
23
Ext.air.NativeWindow = function(config){
24
Ext.apply(this, config);
29
this.id = this.id || Ext.uniqueId();
34
* @param {Object} e The air event object
39
* @param {Object} e The air event object
44
* @param {Object} e The air event object
49
* @param {Object} e The air event object
54
* @param {Object} e The air event object
59
* @param {Object} e The air event object
63
* @event displayStateChange
64
* @param {Object} e The air event object
68
* @event displayStateChanging
69
* @param {Object} e The air event object
71
'displayStateChanging'
74
Ext.air.NativeWindow.superclass.constructor.call(this);
77
var options = new air.NativeWindowInitOptions();
78
options.systemChrome = this.chrome;
79
options.type = this.type;
80
options.resizable = this.resizable;
81
options.minimizable = this.minimizable;
82
options.maximizable = this.maximizable;
83
options.transparent = this.transparent;
85
this.loader = window.runtime.flash.html.HTMLLoader.createRootWindow(false, options, false);
86
this.loader.load(new air.URLRequest(this.file));
88
this.instance = this.loader.window.nativeWindow;
90
this.loader = this.instance.stage.getChildAt(0);
93
var provider = Ext.state.Manager;
94
var b = air.Screen.mainScreen.visibleBounds;
96
var state = provider.get(this.id) || {};
97
provider.set(this.id, state);
99
var win = this.instance;
101
var width = Math.max(state.width || this.width, 100);
102
var height = Math.max(state.height || this.height, 100);
104
var centerX = b.x + ((b.width/2)-(width/2));
105
var centerY = b.y + ((b.height/2)-(height/2));
107
var x = !Ext.isEmpty(state.x, false) ? state.x : (!Ext.isEmpty(this.x, false) ? this.x : centerX);
108
var y = !Ext.isEmpty(state.y, false) ? state.y : (!Ext.isEmpty(this.y, false) ? this.y : centerY);
115
win.addEventListener('move', function(){
116
if(win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
121
win.addEventListener('resize', function(){
122
if (win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
123
state.width = win.width;
124
state.height = win.height;
128
Ext.air.NativeWindowManager.register(this);
129
this.on('close', this.unregister, this);
132
* @cfg {Boolean} minimizeToTray
133
* True to enable minimizing to the system tray. Note: this should only be applied
134
* to the primary window in your application. A trayIcon is required.
136
if(this.minimizeToTray){
137
this.initMinimizeToTray(this.trayIcon, this.trayMenu);
142
Ext.extend(Ext.air.NativeWindow, Ext.air.NativeObservable, {
145
* @cfg {air.NativeWindow} instance
146
* The native window instance to wrap. If undefined, a new window will be created.
150
* @cfg {String} trayIcon
151
* The icon to display when minimized in the system tray
154
* @cfg {NativeMenu} trayMenu
155
* Menu to display when the tray icon is right clicked
158
* @cfg {String} trayTip
159
* Tooltip for the tray icon
163
* @cfg {String} chrome
164
* The native window chrome (defaults to 'standard', can also be 'none').
166
chrome: 'standard', // can also be none
169
* The native window type - normal, utility or lightweight. (defaults to normal)
171
type: 'normal', // can be normal, utility or lightweight
173
* @cfg {Number} width
177
* @cfg {Number} height
181
* @cfg {Boolean} resizable
185
* @cfg {Boolean} minimizable
189
* @cfg {Boolean} maximizable
193
* @cfg {Boolean} transparent
198
* Returns the air.NativeWindow instance
199
* @return air.NativeWindow
201
getNative : function(){
202
return this.instance;
206
* Returns the x/y coordinates for centering the windw on the screen
207
* @return {x: Number, y: Number}
209
getCenterXY : function(){
210
var b = air.Screen.mainScreen.visibleBounds;
212
x: b.x + ((b.width/2)-(this.width/2)),
213
y: b.y + ((b.height/2)-(this.height/2))
222
Ext.air.SystemTray.hideIcon();
225
this.instance.visible = true;
229
* Shows and activates the window
231
activate : function(){
233
this.instance.activate();
240
this.instance.visible = false;
247
this.instance.close();
251
* Returns true if this window is minimized
254
isMinimized :function(){
255
return this.instance.displayState == air.NativeWindowDisplayState.MINIMIZED;
259
* Returns true if this window is maximized
262
isMaximized :function(){
263
return this.instance.displayState == air.NativeWindowDisplayState.MAXIMIZED;
267
* Moves the window to the passed xy and y coordinates
271
moveTo : function(x, y){
272
this.x = this.instance.x = x;
273
this.y = this.instance.y = y;
277
* @param {Number} width
278
* @param {Number} height
280
resize : function(width, height){
281
this.width = this.instance.width = width;
282
this.height = this.instance.height = height;
285
unregister : function(){
286
Ext.air.NativeWindowManager.unregister(this);
289
initMinimizeToTray : function(icon, menu){
290
var tray = Ext.air.SystemTray;
292
tray.setIcon(icon, this.trayTip);
293
this.on('displayStateChanging', function(e){
294
if(e.afterDisplayState == 'minimized'){
302
tray.on('click', function(){
313
* Returns the first opened window in your application
314
* @return air.NativeWindow
317
Ext.air.NativeWindow.getRootWindow = function(){
318
return air.NativeApplication.nativeApplication.openedWindows[0];
322
* Returns the javascript "window" object of the first opened window in your application
326
Ext.air.NativeWindow.getRootHtmlWindow = function(){
327
return Ext.air.NativeWindow.getRootWindow().stage.getChildAt(0).window;
331
* @class Ext.air.NativeWindowGroup
333
* A collection of NativeWindows.
335
Ext.air.NativeWindowGroup = function(){
340
* @param {Object} win
342
register : function(win){
347
* @param {Object} win
349
unregister : function(win){
363
closeAll : function(){
365
if(list.hasOwnProperty(id)){
372
* Executes the specified function once for every window in the group, passing each
373
* window as the only parameter. Returning false from the function will stop the iteration.
374
* @param {Function} fn The function to execute for each item
375
* @param {Object} scope (optional) The scope in which to execute the function
377
each : function(fn, scope){
379
if(list.hasOwnProperty(id)){
380
if(fn.call(scope || list[id], list[id]) === false){
390
* @class Ext.air.NativeWindowManager
391
* @extends Ext.air.NativeWindowGroup
393
* Collection of all NativeWindows created.
397
Ext.air.NativeWindowManager = new Ext.air.NativeWindowGroup();
b'\\ No newline at end of file'