3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
7 Ext.Desktop = function(app) {
8 this.taskbar = new Ext.ux.TaskBar(app);
9 this.xTickSize = this.yTickSize = 1;
10 var taskbar = this.taskbar;
12 var desktopEl = Ext.get('x-desktop');
13 var taskbarEl = Ext.get('ux-taskbar');
14 var shortcuts = Ext.get('x-shortcuts');
16 var windows = new Ext.WindowGroup();
19 function minimizeWin(win) {
24 function markActive(win) {
25 if (activeWindow && activeWindow != win) {
26 markInactive(activeWindow);
28 taskbar.setActiveButton(win.taskButton);
30 Ext.fly(win.taskButton.el).addClass('active-win');
31 win.minimized = false;
34 function markInactive(win) {
35 if (win == activeWindow) {
37 Ext.fly(win.taskButton.el).removeClass('active-win');
41 function removeWin(win) {
42 taskbar.removeTaskButton(win.taskButton);
47 desktopEl.setHeight(Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight());
49 Ext.EventManager.onWindowResize(layout);
53 this.createWindow = function(config, cls) {
54 var win = new(cls || Ext.Window)(
55 Ext.applyIf(config || {},
63 win.dd.xTickSize = this.xTickSize;
64 win.dd.yTickSize = this.yTickSize;
66 win.resizer.widthIncrement = this.xTickSize;
67 win.resizer.heightIncrement = this.yTickSize;
69 win.render(desktopEl);
70 win.taskButton = taskbar.addTaskButton(win);
72 win.cmenu = new Ext.menu.Menu({
78 win.animateTarget = win.taskButton.el;
102 this.getManager = function() {
106 this.getWindow = function(id) {
107 return windows.get(id);
110 this.getWinWidth = function() {
111 var width = Ext.lib.Dom.getViewWidth();
112 return width < 200 ? 200: width;
115 this.getWinHeight = function() {
116 var height = (Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight());
117 return height < 100 ? 100: height;
120 this.getWinX = function(width) {
121 return (Ext.lib.Dom.getViewWidth() - width) / 2;
124 this.getWinY = function(height) {
125 return (Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight() - height) / 2;
128 this.setTickSize = function(xTickSize, yTickSize) {
129 this.xTickSize = xTickSize;
130 if (arguments.length == 1) {
131 this.yTickSize = xTickSize;
133 this.yTickSize = yTickSize;
135 windows.each(function(win) {
136 win.dd.xTickSize = this.xTickSize;
137 win.dd.yTickSize = this.yTickSize;
138 win.resizer.widthIncrement = this.xTickSize;
139 win.resizer.heightIncrement = this.yTickSize;
144 this.cascade = function() {
147 windows.each(function(win) {
148 if (win.isVisible() && !win.maximized) {
149 win.setPosition(x, y);
157 this.tile = function() {
158 var availWidth = desktopEl.getWidth(true);
159 var x = this.xTickSize;
160 var y = this.yTickSize;
162 windows.each(function(win) {
163 if (win.isVisible() && !win.maximized) {
164 var w = win.el.getWidth();
166 // Wrap to next row if we are not at the line start and this Window will go off the end
167 if ((x > this.xTickSize) && (x + w > availWidth)) {
172 win.setPosition(x, y);
173 x += w + this.xTickSize;
174 nextY = Math.max(nextY, y + win.el.getHeight() + this.yTickSize);
180 this.contextMenu = new Ext.menu.Menu({
188 handler: this.cascade,
192 desktopEl.on('contextmenu',
195 this.contextMenu.showAt(e.getXY());
202 shortcuts.on('click',
204 t = e.getTarget('dt', shortcuts);
207 var module = app.getModule(t.id.replace('-shortcut', ''));
209 module.createWindow();