4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.BasicLayoutRegion
14 * @extends Roo.util.Observable
15 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
16 * and does not have a titlebar, tabs or any other features. All it does is size and position
17 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
19 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
24 * @scope Roo.BasicLayoutRegion
29 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
30 * @param {Roo.LayoutRegion} this
31 * @param {Roo.ContentPanel} panel The panel
32 * @param {Object} e The cancel event object
34 "beforeremove" : true,
37 * Fires when the layout for this region is changed.
38 * @param {Roo.LayoutRegion} this
42 * @event visibilitychange
43 * Fires when this region is shown or hidden
44 * @param {Roo.LayoutRegion} this
45 * @param {Boolean} visibility true or false
47 "visibilitychange" : true,
50 * Fires when a panel is added.
51 * @param {Roo.LayoutRegion} this
52 * @param {Roo.ContentPanel} panel The panel
57 * Fires when a panel is removed.
58 * @param {Roo.LayoutRegion} this
59 * @param {Roo.ContentPanel} panel The panel
61 "panelremoved" : true,
63 * @event beforecollapse
64 * Fires when this region before collapse.
65 * @param {Roo.LayoutRegion} this
67 "beforecollapse" : true,
70 * Fires when this region is collapsed.
71 * @param {Roo.LayoutRegion} this
76 * Fires when this region is expanded.
77 * @param {Roo.LayoutRegion} this
82 * Fires when this region is slid into view.
83 * @param {Roo.LayoutRegion} this
88 * Fires when this region slides out of view.
89 * @param {Roo.LayoutRegion} this
93 * @event panelactivated
94 * Fires when a panel is activated.
95 * @param {Roo.LayoutRegion} this
96 * @param {Roo.ContentPanel} panel The activated panel
98 "panelactivated" : true,
101 * Fires when the user resizes this region.
102 * @param {Roo.LayoutRegion} this
103 * @param {Number} newSize The new size (width for east/west, height for north/south)
107 /** A collection of panels in this region. @type Roo.util.MixedCollection */
108 this.panels = new Roo.util.MixedCollection();
109 this.panels.getKey = this.getPanelId.createDelegate(this);
111 this.activePanel = null;
112 // ensure listeners are added...
114 if (config.listeners || config.events) {
115 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
116 listeners : config.listeners || {},
117 events : config.events || {}
121 if(skipConfig !== true){
122 this.applyConfig(config);
126 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
127 getPanelId : function(p){
131 applyConfig : function(config){
132 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
133 this.config = config;
138 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
139 * the width, for horizontal (north, south) the height.
140 * @param {Number} newSize The new width or height
142 resizeTo : function(newSize){
143 var el = this.el ? this.el :
144 (this.activePanel ? this.activePanel.getEl() : null);
146 switch(this.position){
149 el.setWidth(newSize);
150 this.fireEvent("resized", this, newSize);
154 el.setHeight(newSize);
155 this.fireEvent("resized", this, newSize);
162 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
165 getMargins : function(){
169 updateBox : function(box){
171 var el = this.activePanel.getEl();
172 el.dom.style.left = box.x + "px";
173 el.dom.style.top = box.y + "px";
174 this.activePanel.setSize(box.width, box.height);
178 * Returns the container element for this region.
179 * @return {Roo.Element}
182 return this.activePanel;
186 * Returns true if this region is currently visible.
189 isVisible : function(){
190 return this.activePanel ? true : false;
193 setActivePanel : function(panel){
194 panel = this.getPanel(panel);
195 if(this.activePanel && this.activePanel != panel){
196 this.activePanel.setActiveState(false);
197 this.activePanel.getEl().setLeftTop(-10000,-10000);
199 this.activePanel = panel;
200 panel.setActiveState(true);
202 panel.setSize(this.box.width, this.box.height);
204 this.fireEvent("panelactivated", this, panel);
205 this.fireEvent("invalidated");
209 * Show the specified panel.
210 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
211 * @return {Roo.ContentPanel} The shown panel or null
213 showPanel : function(panel){
214 if(panel = this.getPanel(panel)){
215 this.setActivePanel(panel);
221 * Get the active panel for this region.
222 * @return {Roo.ContentPanel} The active panel or null
224 getActivePanel : function(){
225 return this.activePanel;
229 * Add the passed ContentPanel(s)
230 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
231 * @return {Roo.ContentPanel} The panel added (if only one was added)
233 add : function(panel){
234 if(arguments.length > 1){
235 for(var i = 0, len = arguments.length; i < len; i++) {
236 this.add(arguments[i]);
240 if(this.hasPanel(panel)){
241 this.showPanel(panel);
244 var el = panel.getEl();
245 if(el.dom.parentNode != this.mgr.el.dom){
246 this.mgr.el.dom.appendChild(el.dom);
249 panel.setRegion(this);
251 this.panels.add(panel);
252 el.setStyle("position", "absolute");
253 if(!panel.background){
254 this.setActivePanel(panel);
255 if(this.config.initialSize && this.panels.getCount()==1){
256 this.resizeTo(this.config.initialSize);
259 this.fireEvent("paneladded", this, panel);
264 * Returns true if the panel is in this region.
265 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
268 hasPanel : function(panel){
269 if(typeof panel == "object"){ // must be panel obj
270 panel = panel.getId();
272 return this.getPanel(panel) ? true : false;
276 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
277 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
278 * @param {Boolean} preservePanel Overrides the config preservePanel option
279 * @return {Roo.ContentPanel} The panel that was removed
281 remove : function(panel, preservePanel){
282 panel = this.getPanel(panel);
287 this.fireEvent("beforeremove", this, panel, e);
288 if(e.cancel === true){
291 var panelId = panel.getId();
292 this.panels.removeKey(panelId);
297 * Returns the panel specified or null if it's not in this region.
298 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
299 * @return {Roo.ContentPanel}
301 getPanel : function(id){
302 if(typeof id == "object"){ // must be panel obj
305 return this.panels.get(id);
309 * Returns this regions position (north/south/east/west/center).
312 getPosition: function(){
313 return this.position;