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