You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
6.0 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.Desktop = function(app) {
  16. this.taskbar = new Ext.ux.TaskBar(app);
  17. this.xTickSize = this.yTickSize = 1;
  18. var taskbar = this.taskbar;
  19. var desktopEl = Ext.get('x-desktop');
  20. var taskbarEl = Ext.get('ux-taskbar');
  21. var shortcuts = Ext.get('x-shortcuts');
  22. var windows = new Ext.WindowGroup();
  23. var activeWindow;
  24. function minimizeWin(win) {
  25. win.minimized = true;
  26. win.hide();
  27. }
  28. function markActive(win) {
  29. if (activeWindow && activeWindow != win) {
  30. markInactive(activeWindow);
  31. }
  32. taskbar.setActiveButton(win.taskButton);
  33. activeWindow = win;
  34. Ext.fly(win.taskButton.el).addClass('active-win');
  35. win.minimized = false;
  36. }
  37. function markInactive(win) {
  38. if (win == activeWindow) {
  39. activeWindow = null;
  40. Ext.fly(win.taskButton.el).removeClass('active-win');
  41. }
  42. }
  43. function removeWin(win) {
  44. taskbar.removeTaskButton(win.taskButton);
  45. layout();
  46. }
  47. function layout() {
  48. desktopEl.setHeight(Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight());
  49. }
  50. Ext.EventManager.onWindowResize(layout);
  51. this.layout = layout;
  52. this.createWindow = function(config, cls) {
  53. var win = new(cls || Ext.Window)(
  54. Ext.applyIf(config || {},
  55. {
  56. renderTo: desktopEl,
  57. manager: windows,
  58. minimizable: true,
  59. maximizable: true
  60. })
  61. );
  62. win.dd.xTickSize = this.xTickSize;
  63. win.dd.yTickSize = this.yTickSize;
  64. if (win.resizer) {
  65. win.resizer.widthIncrement = this.xTickSize;
  66. win.resizer.heightIncrement = this.yTickSize;
  67. }
  68. win.render(desktopEl);
  69. win.taskButton = taskbar.addTaskButton(win);
  70. win.cmenu = new Ext.menu.Menu({
  71. items: [
  72. ]
  73. });
  74. win.animateTarget = win.taskButton.el;
  75. win.on({
  76. 'activate': {
  77. fn: markActive
  78. },
  79. 'beforeshow': {
  80. fn: markActive
  81. },
  82. 'deactivate': {
  83. fn: markInactive
  84. },
  85. 'minimize': {
  86. fn: minimizeWin
  87. },
  88. 'close': {
  89. fn: removeWin
  90. }
  91. });
  92. layout();
  93. return win;
  94. };
  95. this.getManager = function() {
  96. return windows;
  97. };
  98. this.getWindow = function(id) {
  99. return windows.get(id);
  100. };
  101. this.getWinWidth = function() {
  102. var width = Ext.lib.Dom.getViewWidth();
  103. return width < 200 ? 200: width;
  104. };
  105. this.getWinHeight = function() {
  106. var height = (Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight());
  107. return height < 100 ? 100: height;
  108. };
  109. this.getWinX = function(width) {
  110. return (Ext.lib.Dom.getViewWidth() - width) / 2;
  111. };
  112. this.getWinY = function(height) {
  113. return (Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight() - height) / 2;
  114. };
  115. this.setTickSize = function(xTickSize, yTickSize) {
  116. this.xTickSize = xTickSize;
  117. if (arguments.length == 1) {
  118. this.yTickSize = xTickSize;
  119. } else {
  120. this.yTickSize = yTickSize;
  121. }
  122. windows.each(function(win) {
  123. win.dd.xTickSize = this.xTickSize;
  124. win.dd.yTickSize = this.yTickSize;
  125. win.resizer.widthIncrement = this.xTickSize;
  126. win.resizer.heightIncrement = this.yTickSize;
  127. },
  128. this);
  129. };
  130. this.cascade = function() {
  131. var x = 0,
  132. y = 0;
  133. windows.each(function(win) {
  134. if (win.isVisible() && !win.maximized) {
  135. win.setPosition(x, y);
  136. x += 20;
  137. y += 20;
  138. }
  139. },
  140. this);
  141. };
  142. this.tile = function() {
  143. var availWidth = desktopEl.getWidth(true);
  144. var x = this.xTickSize;
  145. var y = this.yTickSize;
  146. var nextY = y;
  147. windows.each(function(win) {
  148. if (win.isVisible() && !win.maximized) {
  149. var w = win.el.getWidth();
  150. // Wrap to next row if we are not at the line start and this Window will go off the end
  151. if ((x > this.xTickSize) && (x + w > availWidth)) {
  152. x = this.xTickSize;
  153. y = nextY;
  154. }
  155. win.setPosition(x, y);
  156. x += w + this.xTickSize;
  157. nextY = Math.max(nextY, y + win.el.getHeight() + this.yTickSize);
  158. }
  159. },
  160. this);
  161. };
  162. this.contextMenu = new Ext.menu.Menu({
  163. items: [{
  164. text: 'Tile',
  165. handler: this.tile,
  166. scope: this
  167. },
  168. {
  169. text: 'Cascade',
  170. handler: this.cascade,
  171. scope: this
  172. }]
  173. });
  174. desktopEl.on('contextmenu',
  175. function(e) {
  176. e.stopEvent();
  177. this.contextMenu.showAt(e.getXY());
  178. },
  179. this);
  180. layout();
  181. if (shortcuts) {
  182. shortcuts.on('click',
  183. function(e, t) {
  184. t = e.getTarget('dt', shortcuts);
  185. if (t) {
  186. e.stopEvent();
  187. var module = app.getModule(t.id.replace('-shortcut', ''));
  188. if (module) {
  189. module.createWindow();
  190. }
  191. }
  192. });
  193. }
  194. };