1 """
2 /*
3 * Copyright 2008 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License") you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http:#www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 """
18 from pyjamas.ui.Panel import Panel
19 from pyjamas.ui import Event
20
21 from pyjamas import DOM
22
24 """ Abstract base class for {@link HorizontalSplitPanel} and
25 {@link VerticalSplitPanel}.
26 """
27
28 - def __init__(self, mainElem, splitElem, headElem, tailElem, **kwargs):
29 """ Initializes the split panel.
30 @param mainElem the root element for the split panel
31 @param splitElem the element that acts as the splitter
32 @param headElem the element to contain the top or left most widget
33 @param tailElem the element to contain the bottom or right most widget
34 """
35
36 self.widgets = [None, None]
37 self.elements = [headElem, tailElem]
38 self.isResizing = False
39
40 self.setElement(mainElem)
41 self.splitElem = splitElem
42
43 Panel.__init__(self, **kwargs)
44
45 self.sinkEvents(Event.MOUSEEVENTS)
46
48 """ Sets an elements positioning to absolute.
49 """
50 DOM.setStyleAttribute(elem, "position", "absolute")
51
56
61
63 """ Sizes and element to consume the full area of its parent
64 using the CSS properties left, right, top, and
65 bottom. This method is used for all browsers except IE6/7.
66 """
67 zeroSize = "0px"
68
69 self.addAbsolutePositoning(elem)
70 self.setLeft(elem, zeroSize)
71 self.setRight(elem, zeroSize)
72 self.setTop(elem, zeroSize)
73 self.setBottom(elem, zeroSize)
74
76 """ Sizes an element to consume the full areas of its parent
77 using 100% width and height. This method is used on IE6/7
78 where CSS offsets don't work reliably.
79 """
80 zeroSize = "0px"
81 fullSize = "100%"
82
83 self.addAbsolutePositoning(elem)
84 self.setTop(elem, zeroSize)
85 self.setLeft(elem, zeroSize)
86 self.setElemWidth(elem, fullSize)
87 self.setElemHeight(elem, fullSize)
88
90 """ Returns the offsetHeight element property.
91 """
92 return DOM.getIntAttribute(elem, "offsetHeight")
93
95 """ Returns the offsetWidth element property.
96 """
97 return DOM.getIntAttribute(elem, "offsetWidth")
98
100 """ Adds zero or none CSS values for padding, margin and
101 border to prevent stylesheet overrides. Returns the
102 element for convenience to support builder pattern.
103 """
104 DOM.setIntStyleAttribute(elem, "padding", 0)
105 DOM.setIntStyleAttribute(elem, "margin", 0)
106 DOM.setStyleAttribute(elem, "border", "none")
107 return elem
108
110 """ Convenience method to set bottom offset of an element.
111 """
112 DOM.setStyleAttribute(elem, "bottom", size)
113
115 """ Convenience method to set the height of an element.
116 """
117 DOM.setStyleAttribute(elem, "height", height)
118
120 """ Convenience method to set the left offset of an element.
121 """
122 DOM.setStyleAttribute(elem, "left", left)
123
125 """ Convenience method to set the right offset of an element.
126 """
127 DOM.setStyleAttribute(elem, "right", right)
128
130 """ Convenience method to set the top offset of an element.
131 """
132 DOM.setStyleAttribute(elem, "top", top)
133
135 """ Convenience method to set the width of an element.
136 """
137 DOM.setStyleAttribute(elem, "width", width)
138
144
145
146
148 """ Indicates whether the split panel is being resized.
149
150 @return <code>True</code> if the user is dragging the splitter,
151 <code>False</code> otherwise
152 """
153 return self.isResizing
154
157
181
183 if widgets[0] == widget:
184 setWidget(0, None)
185 return True
186 elif widgets[1] == widget:
187 setWidget(1, None)
188 return True
189 return False
190
192 """ Moves the position of the splitter.
193 @param size the new size of the left region in CSS units
194 (e.g. "10px", "1em")
195 """
196 pass
197
204
206 """ Gets the element that is acting as the splitter.
207 @return the element
208 """
209 return self.splitElem
210
217
247
249 """ Called on each mouse drag event as the user is dragging
250 the splitter.
251 @param x the x coord of the mouse relative to the panel's extent
252 @param y the y coord of the mosue relative to the panel's extent
253 """
254 pass
255
257 """ Called when the user starts dragging the splitter.
258 @param x the x coord of the mouse relative to the panel's extent
259 @param y the y coord of the mouse relative to the panel's extent
260 """
261
265
268