3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * Ext JS Library 3.3.1
17 * Copyright(c) 2006-2010 Sencha Inc.
18 * licensing@sencha.com
19 * http://www.sencha.com/license
21 Ext.Desktop = function(app) {
22 this.taskbar = new Ext.ux.TaskBar(app);
23 this.xTickSize = this.yTickSize = 1;
24 var taskbar = this.taskbar;
26 var desktopEl = Ext.get('x-desktop');
27 var taskbarEl = Ext.get('ux-taskbar');
28 var shortcuts = Ext.get('x-shortcuts');
30 var windows = new Ext.WindowGroup();
33 function minimizeWin(win) {
38 function markActive(win) {
39 if (activeWindow && activeWindow != win) {
40 markInactive(activeWindow);
42 taskbar.setActiveButton(win.taskButton);
44 Ext.fly(win.taskButton.el).addClass('active-win');
45 win.minimized = false;
48 function markInactive(win) {
49 if (win == activeWindow) {
51 Ext.fly(win.taskButton.el).removeClass('active-win');
55 function removeWin(win) {
56 taskbar.removeTaskButton(win.taskButton);
61 desktopEl.setHeight(Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight());
63 Ext.EventManager.onWindowResize(layout);
67 this.createWindow = function(config, cls) {
68 var win = new(cls || Ext.Window)(
69 Ext.applyIf(config || {},
77 win.dd.xTickSize = this.xTickSize;
78 win.dd.yTickSize = this.yTickSize;
80 win.resizer.widthIncrement = this.xTickSize;
81 win.resizer.heightIncrement = this.yTickSize;
83 win.render(desktopEl);
84 win.taskButton = taskbar.addTaskButton(win);
86 win.cmenu = new Ext.menu.Menu({
92 win.animateTarget = win.taskButton.el;
116 this.getManager = function() {
120 this.getWindow = function(id) {
121 return windows.get(id);
124 this.getWinWidth = function() {
125 var width = Ext.lib.Dom.getViewWidth();
126 return width < 200 ? 200: width;
129 this.getWinHeight = function() {
130 var height = (Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight());
131 return height < 100 ? 100: height;
134 this.getWinX = function(width) {
135 return (Ext.lib.Dom.getViewWidth() - width) / 2;
138 this.getWinY = function(height) {
139 return (Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight() - height) / 2;
142 this.setTickSize = function(xTickSize, yTickSize) {
143 this.xTickSize = xTickSize;
144 if (arguments.length == 1) {
145 this.yTickSize = xTickSize;
147 this.yTickSize = yTickSize;
149 windows.each(function(win) {
150 win.dd.xTickSize = this.xTickSize;
151 win.dd.yTickSize = this.yTickSize;
152 win.resizer.widthIncrement = this.xTickSize;
153 win.resizer.heightIncrement = this.yTickSize;
158 this.cascade = function() {
161 windows.each(function(win) {
162 if (win.isVisible() && !win.maximized) {
163 win.setPosition(x, y);
171 this.tile = function() {
172 var availWidth = desktopEl.getWidth(true);
173 var x = this.xTickSize;
174 var y = this.yTickSize;
176 windows.each(function(win) {
177 if (win.isVisible() && !win.maximized) {
178 var w = win.el.getWidth();
180 // Wrap to next row if we are not at the line start and this Window will go off the end
181 if ((x > this.xTickSize) && (x + w > availWidth)) {
186 win.setPosition(x, y);
187 x += w + this.xTickSize;
188 nextY = Math.max(nextY, y + win.el.getHeight() + this.yTickSize);
194 this.contextMenu = new Ext.menu.Menu({
202 handler: this.cascade,
206 desktopEl.on('contextmenu',
209 this.contextMenu.showAt(e.getXY());
216 shortcuts.on('click',
218 t = e.getTarget('dt', shortcuts);
221 var module = app.getModule(t.id.replace('-shortcut', ''));
223 module.createWindow();