1 | /* |
---|
2 | * Ext JS Library 2.2.1 |
---|
3 | * Copyright(c) 2006-2009, Ext JS, LLC. |
---|
4 | * licensing@extjs.com |
---|
5 | * |
---|
6 | * http://extjs.com/license |
---|
7 | */ |
---|
8 | |
---|
9 | Ext.Desktop = function(app){ |
---|
10 | this.taskbar = new Ext.ux.TaskBar(app); |
---|
11 | var taskbar = this.taskbar; |
---|
12 | |
---|
13 | var desktopEl = Ext.get('x-desktop'); |
---|
14 | var taskbarEl = Ext.get('ux-taskbar'); |
---|
15 | var shortcuts = Ext.get('x-shortcuts'); |
---|
16 | |
---|
17 | var windows = new Ext.WindowGroup(); |
---|
18 | var activeWindow; |
---|
19 | |
---|
20 | function minimizeWin(win){ |
---|
21 | win.minimized = true; |
---|
22 | win.hide(); |
---|
23 | } |
---|
24 | |
---|
25 | function markActive(win){ |
---|
26 | if(activeWindow && activeWindow != win){ |
---|
27 | markInactive(activeWindow); |
---|
28 | } |
---|
29 | taskbar.setActiveButton(win.taskButton); |
---|
30 | activeWindow = win; |
---|
31 | Ext.fly(win.taskButton.el).addClass('active-win'); |
---|
32 | win.minimized = false; |
---|
33 | } |
---|
34 | |
---|
35 | function markInactive(win){ |
---|
36 | if(win == activeWindow){ |
---|
37 | activeWindow = null; |
---|
38 | Ext.fly(win.taskButton.el).removeClass('active-win'); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | function removeWin(win){ |
---|
43 | taskbar.removeTaskButton(win.taskButton); |
---|
44 | layout(); |
---|
45 | } |
---|
46 | |
---|
47 | function layout(){ |
---|
48 | desktopEl.setHeight(Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight()); |
---|
49 | } |
---|
50 | Ext.EventManager.onWindowResize(layout); |
---|
51 | |
---|
52 | this.layout = layout; |
---|
53 | |
---|
54 | this.createWindow = function(config, cls){ |
---|
55 | var win = new (cls||Ext.Window)( |
---|
56 | Ext.applyIf(config||{}, { |
---|
57 | manager: windows, |
---|
58 | minimizable: true, |
---|
59 | maximizable: true |
---|
60 | }) |
---|
61 | ); |
---|
62 | win.render(desktopEl); |
---|
63 | win.taskButton = taskbar.addTaskButton(win); |
---|
64 | |
---|
65 | win.cmenu = new Ext.menu.Menu({ |
---|
66 | items: [ |
---|
67 | |
---|
68 | ] |
---|
69 | }); |
---|
70 | |
---|
71 | win.animateTarget = win.taskButton.el; |
---|
72 | |
---|
73 | win.on({ |
---|
74 | 'activate': { |
---|
75 | fn: markActive |
---|
76 | }, |
---|
77 | 'beforeshow': { |
---|
78 | fn: markActive |
---|
79 | }, |
---|
80 | 'deactivate': { |
---|
81 | fn: markInactive |
---|
82 | }, |
---|
83 | 'minimize': { |
---|
84 | fn: minimizeWin |
---|
85 | }, |
---|
86 | 'close': { |
---|
87 | fn: removeWin |
---|
88 | } |
---|
89 | }); |
---|
90 | |
---|
91 | layout(); |
---|
92 | return win; |
---|
93 | }; |
---|
94 | |
---|
95 | this.getManager = function(){ |
---|
96 | return windows; |
---|
97 | }; |
---|
98 | |
---|
99 | this.getWindow = function(id){ |
---|
100 | return windows.get(id); |
---|
101 | } |
---|
102 | |
---|
103 | this.getWinWidth = function(){ |
---|
104 | var width = Ext.lib.Dom.getViewWidth(); |
---|
105 | return width < 200 ? 200 : width; |
---|
106 | } |
---|
107 | |
---|
108 | this.getWinHeight = function(){ |
---|
109 | var height = (Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight()); |
---|
110 | return height < 100 ? 100 : height; |
---|
111 | } |
---|
112 | |
---|
113 | this.getWinX = function(width){ |
---|
114 | return (Ext.lib.Dom.getViewWidth() - width) / 2 |
---|
115 | } |
---|
116 | |
---|
117 | this.getWinY = function(height){ |
---|
118 | return (Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight() - height) / 2; |
---|
119 | } |
---|
120 | |
---|
121 | layout(); |
---|
122 | |
---|
123 | if(shortcuts){ |
---|
124 | shortcuts.on('click', function(e, t){ |
---|
125 | if(t = e.getTarget('dt', shortcuts)){ |
---|
126 | e.stopEvent(); |
---|
127 | var module = app.getModule(t.id.replace('-shortcut', '')); |
---|
128 | if(module){ |
---|
129 | module.createWindow(); |
---|
130 | } |
---|
131 | } |
---|
132 | }); |
---|
133 | } |
---|
134 | }; |
---|