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