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