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