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,
64 * Fires when this region is collapsed.
65 * @param {Roo.LayoutRegion} this
70 * Fires when this region is expanded.
71 * @param {Roo.LayoutRegion} this
76 * Fires when this region is slid into view.
77 * @param {Roo.LayoutRegion} this
82 * Fires when this region slides out of view.
83 * @param {Roo.LayoutRegion} this
87 * @event panelactivated
88 * Fires when a panel is activated.
89 * @param {Roo.LayoutRegion} this
90 * @param {Roo.ContentPanel} panel The activated panel
92 "panelactivated" : true,
95 * Fires when the user resizes this region.
96 * @param {Roo.LayoutRegion} this
97 * @param {Number} newSize The new size (width for east/west, height for north/south)
101 /** A collection of panels in this region. @type Roo.util.MixedCollection */
102 this.panels = new Roo.util.MixedCollection();
103 this.panels.getKey = this.getPanelId.createDelegate(this);
105 this.activePanel = null;
106 // ensure listeners are added...
108 if (config.listeners || config.events) {
109 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
110 listeners : config.listeners || {},
111 events : config.events || {}
115 if(skipConfig !== true){
116 this.applyConfig(config);
120 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
121 getPanelId : function(p){
125 applyConfig : function(config){
126 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
127 this.config = config;
132 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
133 * the width, for horizontal (north, south) the height.
134 * @param {Number} newSize The new width or height
136 resizeTo : function(newSize){
137 var el = this.el ? this.el :
138 (this.activePanel ? this.activePanel.getEl() : null);
140 switch(this.position){
143 el.setWidth(newSize);
144 this.fireEvent("resized", this, newSize);
148 el.setHeight(newSize);
149 this.fireEvent("resized", this, newSize);
156 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
159 getMargins : function(){
163 updateBox : function(box){
165 var el = this.activePanel.getEl();
166 el.dom.style.left = box.x + "px";
167 el.dom.style.top = box.y + "px";
168 this.activePanel.setSize(box.width, box.height);
172 * Returns the container element for this region.
173 * @return {Roo.Element}
176 return this.activePanel;
180 * Returns true if this region is currently visible.
183 isVisible : function(){
184 return this.activePanel ? true : false;
187 setActivePanel : function(panel){
188 panel = this.getPanel(panel);
189 if(this.activePanel && this.activePanel != panel){
190 this.activePanel.setActiveState(false);
191 this.activePanel.getEl().setLeftTop(-10000,-10000);
193 this.activePanel = panel;
194 panel.setActiveState(true);
196 panel.setSize(this.box.width, this.box.height);
198 this.fireEvent("panelactivated", this, panel);
199 this.fireEvent("invalidated");
203 * Show the specified panel.
204 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
205 * @return {Roo.ContentPanel} The shown panel or null
207 showPanel : function(panel){
208 if(panel = this.getPanel(panel)){
209 this.setActivePanel(panel);
215 * Get the active panel for this region.
216 * @return {Roo.ContentPanel} The active panel or null
218 getActivePanel : function(){
219 return this.activePanel;
223 * Add the passed ContentPanel(s)
224 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
225 * @return {Roo.ContentPanel} The panel added (if only one was added)
227 add : function(panel){
228 if(arguments.length > 1){
229 for(var i = 0, len = arguments.length; i < len; i++) {
230 this.add(arguments[i]);
234 if(this.hasPanel(panel)){
235 this.showPanel(panel);
238 var el = panel.getEl();
239 if(el.dom.parentNode != this.mgr.el.dom){
240 this.mgr.el.dom.appendChild(el.dom);
243 panel.setRegion(this);
245 this.panels.add(panel);
246 el.setStyle("position", "absolute");
247 if(!panel.background){
248 this.setActivePanel(panel);
249 if(this.config.initialSize && this.panels.getCount()==1){
250 this.resizeTo(this.config.initialSize);
253 this.fireEvent("paneladded", this, panel);
258 * Returns true if the panel is in this region.
259 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
262 hasPanel : function(panel){
263 if(typeof panel == "object"){ // must be panel obj
264 panel = panel.getId();
266 return this.getPanel(panel) ? true : false;
270 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
271 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
272 * @param {Boolean} preservePanel Overrides the config preservePanel option
273 * @return {Roo.ContentPanel} The panel that was removed
275 remove : function(panel, preservePanel){
276 panel = this.getPanel(panel);
281 this.fireEvent("beforeremove", this, panel, e);
282 if(e.cancel === true){
285 var panelId = panel.getId();
286 this.panels.removeKey(panelId);
291 * Returns the panel specified or null if it's not in this region.
292 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
293 * @return {Roo.ContentPanel}
295 getPanel : function(id){
296 if(typeof id == "object"){ // must be panel obj
299 return this.panels.get(id);
303 * Returns this regions position (north/south/east/west/center).
306 getPosition: function(){
307 return this.position;