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