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