Roo/LayoutManager.js
[roojs1] / Roo / LayoutManager.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12 /**
13  * @class Roo.LayoutManager
14  * @extends Roo.util.Observable
15  * Base class for layout managers.
16  */
17 Roo.LayoutManager = function(container, config){
18     Roo.LayoutManager.superclass.constructor.call(this);
19     this.el = Roo.get(container);
20     // ie scrollbar fix
21     if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
22         document.body.scroll = "no";
23     }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
24         this.el.position('relative');
25     }
26     this.id = this.el.id;
27     this.el.addClass("x-layout-container");
28     this.el.setStyle('height', '500px');
29     /** false to disable window resize monitoring @type Boolean */
30     this.monitorWindowResize = true;
31     this.regions = {};
32     this.addEvents({
33         /**
34          * @event layout
35          * Fires when a layout is performed. 
36          * @param {Roo.LayoutManager} this
37          */
38         "layout" : true,
39         /**
40          * @event regionresized
41          * Fires when the user resizes a region. 
42          * @param {Roo.LayoutRegion} region The resized region
43          * @param {Number} newSize The new size (width for east/west, height for north/south)
44          */
45         "regionresized" : true,
46         /**
47          * @event regioncollapsed
48          * Fires when a region is collapsed. 
49          * @param {Roo.LayoutRegion} region The collapsed region
50          */
51         "regioncollapsed" : true,
52         /**
53          * @event regionexpanded
54          * Fires when a region is expanded.  
55          * @param {Roo.LayoutRegion} region The expanded region
56          */
57         "regionexpanded" : true
58     });
59     this.updating = false;
60     Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
61 };
62
63 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
64     /**
65      * Returns true if this layout is currently being updated
66      * @return {Boolean}
67      */
68     isUpdating : function(){
69         return this.updating; 
70     },
71     
72     /**
73      * Suspend the LayoutManager from doing auto-layouts while
74      * making multiple add or remove calls
75      */
76     beginUpdate : function(){
77         this.updating = true;    
78     },
79     
80     /**
81      * Restore auto-layouts and optionally disable the manager from performing a layout
82      * @param {Boolean} noLayout true to disable a layout update 
83      */
84     endUpdate : function(noLayout){
85         this.updating = false;
86         if(!noLayout){
87             this.layout();
88         }    
89     },
90     
91     layout: function(){
92         
93     },
94     
95     onRegionResized : function(region, newSize){
96         this.fireEvent("regionresized", region, newSize);
97         this.layout();
98     },
99     
100     onRegionCollapsed : function(region){
101         this.fireEvent("regioncollapsed", region);
102     },
103     
104     onRegionExpanded : function(region){
105         this.fireEvent("regionexpanded", region);
106     },
107         
108     /**
109      * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
110      * performs box-model adjustments.
111      * @return {Object} The size as an object {width: (the width), height: (the height)}
112      */
113     getViewSize : function(){
114         var size;
115         if(this.el.dom != document.body){
116             size = this.el.getSize();
117         }else{
118             size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
119         }
120         size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
121         size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
122         return size;
123     },
124     
125     /**
126      * Returns the Element this layout is bound to.
127      * @return {Roo.Element}
128      */
129     getEl : function(){
130         return this.el;
131     },
132     
133     /**
134      * Returns the specified region.
135      * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
136      * @return {Roo.LayoutRegion}
137      */
138     getRegion : function(target){
139         return this.regions[target.toLowerCase()];
140     },
141     
142     onWindowResize : function(){
143         if(this.monitorWindowResize){
144             this.layout();
145         }
146     }
147 });