9fef3537a00cd5f1031ddfaf391badf0e48ef58f.svn-base 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.BasicLayoutRegion
  8. * @extends Ext.util.Observable This class represents a lightweight region in a
  9. * layout manager. This region does not move dom nodes and does not
  10. * have a titlebar, tabs or any other features. All it does is size and
  11. * position panels. To create a BasicLayoutRegion, add lightweight:true
  12. * or basic:true to your regions config.
  13. */
  14. Ext.BasicLayoutRegion = function(mgr, config, pos, skipConfig) {
  15. this.mgr = mgr;
  16. this.position = pos;
  17. this.events = {
  18. /**
  19. * @event beforeremove Fires before a panel is removed (or closed). To
  20. * cancel the removal set "e.cancel = true" on the event
  21. * argument.
  22. * @param {Ext.LayoutRegion}
  23. * this
  24. * @param {Ext.ContentPanel}
  25. * panel The panel
  26. * @param {Object}
  27. * e The cancel event object
  28. */
  29. "beforeremove" : true,
  30. /**
  31. * @event invalidated Fires when the layout for this region is changed.
  32. * @param {Ext.LayoutRegion}
  33. * this
  34. */
  35. "invalidated" : true,
  36. /**
  37. * @event visibilitychange Fires when this region is shown or hidden
  38. * @param {Ext.LayoutRegion}
  39. * this
  40. * @param {Boolean}
  41. * visibility true or false
  42. */
  43. "visibilitychange" : true,
  44. /**
  45. * @event paneladded Fires when a panel is added.
  46. * @param {Ext.LayoutRegion}
  47. * this
  48. * @param {Ext.ContentPanel}
  49. * panel The panel
  50. */
  51. "paneladded" : true,
  52. /**
  53. * @event panelremoved Fires when a panel is removed.
  54. * @param {Ext.LayoutRegion}
  55. * this
  56. * @param {Ext.ContentPanel}
  57. * panel The panel
  58. */
  59. "panelremoved" : true,
  60. /**
  61. * @event collapsed Fires when this region is collapsed.
  62. * @param {Ext.LayoutRegion}
  63. * this
  64. */
  65. "collapsed" : true,
  66. /**
  67. * @event expanded Fires when this region is expanded.
  68. * @param {Ext.LayoutRegion}
  69. * this
  70. */
  71. "expanded" : true,
  72. /**
  73. * @event slideshow Fires when this region is slid into view.
  74. * @param {Ext.LayoutRegion}
  75. * this
  76. */
  77. "slideshow" : true,
  78. /**
  79. * @event slidehide Fires when this region slides out of view.
  80. * @param {Ext.LayoutRegion}
  81. * this
  82. */
  83. "slidehide" : true,
  84. /**
  85. * @event panelactivated Fires when a panel is activated.
  86. * @param {Ext.LayoutRegion}
  87. * this
  88. * @param {Ext.ContentPanel}
  89. * panel The activated panel
  90. */
  91. "panelactivated" : true,
  92. /**
  93. * @event resized Fires when the user resizes this region.
  94. * @param {Ext.LayoutRegion}
  95. * this
  96. * @param {Number}
  97. * newSize The new size (width for east/west, height for
  98. * north/south)
  99. */
  100. "resized" : true
  101. };
  102. /**
  103. * A collection of panels in this region.
  104. *
  105. * @type Ext.util.MixedCollection
  106. */
  107. this.panels = new Ext.util.MixedCollection();
  108. this.panels.getKey = this.getPanelId.createDelegate(this);
  109. this.box = null;
  110. this.activePanel = null;
  111. if (skipConfig !== true) {
  112. this.applyConfig(config);
  113. }
  114. };
  115. Ext.extend(Ext.BasicLayoutRegion, Ext.util.Observable, {
  116. getPanelId : function(p) {
  117. return p.getId();
  118. },
  119. applyConfig : function(config) {
  120. this.margins = config.margins || this.margins || {
  121. top : 0,
  122. left : 0,
  123. right : 0,
  124. bottom : 0
  125. };
  126. this.config = config;
  127. },
  128. /**
  129. * Resizes the region to the specified size. For vertical regions
  130. * (west, east) this adjusts the width, for horizontal (north,
  131. * south) the height.
  132. *
  133. * @param {Number}
  134. * newSize The new width or height
  135. */
  136. resizeTo : function(newSize) {
  137. var el = this.el ? this.el : (this.activePanel
  138. ? this.activePanel.getEl()
  139. : null);
  140. if (el) {
  141. switch (this.position) {
  142. case "east" :
  143. case "west" :
  144. el.setWidth(newSize);
  145. this.fireEvent("resized", this, newSize);
  146. break;
  147. case "north" :
  148. case "south" :
  149. el.setHeight(newSize);
  150. this.fireEvent("resized", this, newSize);
  151. break;
  152. }
  153. }
  154. },
  155. getBox : function() {
  156. return this.activePanel ? this.activePanel.getEl().getBox(
  157. false, true) : null;
  158. },
  159. getMargins : function() {
  160. return this.margins;
  161. },
  162. updateBox : function(box) {
  163. this.box = box;
  164. var el = this.activePanel.getEl();
  165. el.dom.style.left = box.x + "px";
  166. el.dom.style.top = box.y + "px";
  167. this.activePanel.setSize(box.width, box.height);
  168. },
  169. /**
  170. * Returns the container element for this region.
  171. *
  172. * @return {Ext.Element}
  173. */
  174. getEl : function() {
  175. return this.activePanel;
  176. },
  177. /**
  178. * Returns true if this region is currently visible.
  179. *
  180. * @return {Boolean}
  181. */
  182. isVisible : function() {
  183. return this.activePanel ? true : false;
  184. },
  185. setActivePanel : function(panel) {
  186. panel = this.getPanel(panel);
  187. if (this.activePanel && this.activePanel != panel) {
  188. this.activePanel.setActiveState(false);
  189. this.activePanel.getEl().setLeftTop(-10000, -10000);
  190. }
  191. this.activePanel = panel;
  192. panel.setActiveState(true);
  193. if (this.box) {
  194. panel.setSize(this.box.width, this.box.height);
  195. }
  196. this.fireEvent("panelactivated", this, panel);
  197. this.fireEvent("invalidated");
  198. },
  199. /**
  200. * Show the specified panel.
  201. *
  202. * @param {Number/String/ContentPanel}
  203. * panelId The panels index, id or the panel itself
  204. * @return {Ext.ContentPanel} The shown panel or null
  205. */
  206. showPanel : function(panel) {
  207. if (panel = this.getPanel(panel)) {
  208. this.setActivePanel(panel);
  209. }
  210. return panel;
  211. },
  212. /**
  213. * Get the active panel for this region.
  214. *
  215. * @return {Ext.ContentPanel} The active panel or null
  216. */
  217. getActivePanel : function() {
  218. return this.activePanel;
  219. },
  220. /**
  221. * Add the passed ContentPanel(s)
  222. *
  223. * @param {ContentPanel...}
  224. * panel The ContentPanel(s) to add (you can pass more
  225. * than one)
  226. * @return {Ext.ContentPanel} The panel added (if only one was
  227. * added)
  228. */
  229. add : function(panel) {
  230. if (arguments.length > 1) {
  231. for (var i = 0, len = arguments.length; i < len; i++) {
  232. this.add(arguments[i]);
  233. }
  234. return null;
  235. }
  236. if (this.hasPanel(panel)) {
  237. this.showPanel(panel);
  238. return panel;
  239. }
  240. var el = panel.getEl();
  241. if (el.dom.parentNode != this.mgr.el.dom) {
  242. this.mgr.el.dom.appendChild(el.dom);
  243. }
  244. if (panel.setRegion) {
  245. panel.setRegion(this);
  246. }
  247. this.panels.add(panel);
  248. el.setStyle("position", "absolute");
  249. if (!panel.background) {
  250. this.setActivePanel(panel);
  251. if (this.config.initialSize && this.panels.getCount() == 1) {
  252. this.resizeTo(this.config.initialSize);
  253. }
  254. }
  255. this.fireEvent("paneladded", this, panel);
  256. return panel;
  257. },
  258. /**
  259. * Returns true if the panel is in this region.
  260. *
  261. * @param {Number/String/ContentPanel}
  262. * panel The panels index, id or the panel itself
  263. * @return {Boolean}
  264. */
  265. hasPanel : function(panel) {
  266. if (typeof panel == "object") { // must be panel obj
  267. panel = panel.getId();
  268. }
  269. return this.getPanel(panel) ? true : false;
  270. },
  271. /**
  272. * Removes the specified panel. If preservePanel is not true (either
  273. * here or in the config), the panel is destroyed.
  274. *
  275. * @param {Number/String/ContentPanel}
  276. * panel The panels index, id or the panel itself
  277. * @param {Boolean}
  278. * preservePanel Overrides the config preservePanel
  279. * option
  280. * @return {Ext.ContentPanel} The panel that was removed
  281. */
  282. remove : function(panel, preservePanel) {
  283. panel = this.getPanel(panel);
  284. if (!panel) {
  285. return null;
  286. }
  287. var e = {};
  288. this.fireEvent("beforeremove", this, panel, e);
  289. if (e.cancel === true) {
  290. return null;
  291. }
  292. var panelId = panel.getId();
  293. this.panels.removeKey(panelId);
  294. return panel;
  295. },
  296. /**
  297. * Returns the panel specified or null if it's not in this region.
  298. *
  299. * @param {Number/String/ContentPanel}
  300. * panel The panels index, id or the panel itself
  301. * @return {Ext.ContentPanel}
  302. */
  303. getPanel : function(id) {
  304. if (typeof id == "object") { // must be panel obj
  305. return id;
  306. }
  307. return this.panels.get(id);
  308. },
  309. /**
  310. * Returns this regions position (north/south/east/west/center).
  311. *
  312. * @return {String}
  313. */
  314. getPosition : function() {
  315. return this.position;
  316. }
  317. });