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