3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.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||{}, {
62 win.dd.xTickSize = this.xTickSize;
63 win.dd.yTickSize = this.yTickSize;
64 win.resizer.widthIncrement = this.xTickSize;
65 win.resizer.heightIncrement = this.yTickSize;
66 win.render(desktopEl);
67 win.taskButton = taskbar.addTaskButton(win);
69 win.cmenu = new Ext.menu.Menu({
75 win.animateTarget = win.taskButton.el;
99 this.getManager = function(){
103 this.getWindow = function(id){
104 return windows.get(id);
107 this.getWinWidth = function(){
108 var width = Ext.lib.Dom.getViewWidth();
109 return width < 200 ? 200 : width;
112 this.getWinHeight = function(){
113 var height = (Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight());
114 return height < 100 ? 100 : height;
117 this.getWinX = function(width){
118 return (Ext.lib.Dom.getViewWidth() - width) / 2
121 this.getWinY = function(height){
122 return (Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight() - height) / 2;
125 this.setTickSize = function(xTickSize, yTickSize) {
126 this.xTickSize = xTickSize;
127 if (arguments.length == 1) {
128 this.yTickSize = xTickSize;
130 this.yTickSize = yTickSize;
132 windows.each(function(win) {
133 win.dd.xTickSize = this.xTickSize;
134 win.dd.yTickSize = this.yTickSize;
135 win.resizer.widthIncrement = this.xTickSize;
136 win.resizer.heightIncrement = this.yTickSize;
140 this.cascade = function() {
142 windows.each(function(win) {
143 if (win.isVisible() && !win.maximized) {
144 win.setPosition(x, y);
151 this.tile = function() {
152 var availWidth = desktopEl.getWidth(true);
153 var x = this.xTickSize;
154 var y = this.yTickSize;
156 windows.each(function(win) {
157 if (win.isVisible() && !win.maximized) {
158 var w = win.el.getWidth();
160 // Wrap to next row if we are not at the line start and this Window will go off the end
161 if ((x > this.xTickSize) && (x + w > availWidth)) {
166 win.setPosition(x, y);
167 x += w + this.xTickSize;
168 nextY = Math.max(nextY, y + win.el.getHeight() + this.yTickSize);
173 this.contextMenu = new Ext.menu.Menu({
180 handler: this.cascade,
184 desktopEl.on('contextmenu', function(e) {
186 this.contextMenu.showAt(e.getXY());
192 shortcuts.on('click', function(e, t){
193 if(t = e.getTarget('dt', shortcuts)){
195 var module = app.getModule(t.id.replace('-shortcut', ''));
197 module.createWindow();