Mercurial > projects > dwt-mac
comparison dwt/widgets/Scrollable.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | 642f460a0908 |
children | cfa563df4fdd |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | 10 * |
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 12 * Jacob Carlborg <doob@me.com> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwt.widgets.Scrollable; | 14 module dwt.widgets.Scrollable; |
15 | 15 |
16 | 16 |
17 import dwt.DWT; | 17 import dwt.DWT; |
21 import dwt.internal.cocoa.NSScrollView; | 21 import dwt.internal.cocoa.NSScrollView; |
22 import dwt.internal.cocoa.NSScroller; | 22 import dwt.internal.cocoa.NSScroller; |
23 import dwt.internal.cocoa.NSSize; | 23 import dwt.internal.cocoa.NSSize; |
24 import dwt.internal.cocoa.NSView; | 24 import dwt.internal.cocoa.NSView; |
25 import dwt.internal.cocoa.OS; | 25 import dwt.internal.cocoa.OS; |
26 import dwt.internal.cocoa.SWTScrollView; | 26 import dwt.internal.cocoa.SWTScroller; |
27 | 27 |
28 import dwt.dwthelper.utils; | 28 import dwt.dwthelper.utils; |
29 import dwt.widgets.Composite; | 29 import dwt.widgets.Composite; |
30 import dwt.widgets.Control; | 30 import dwt.widgets.Control; |
31 import dwt.widgets.Display; | 31 import dwt.widgets.Display; |
43 * </dl> | 43 * </dl> |
44 * <p> | 44 * <p> |
45 * IMPORTANT: This class is intended to be subclassed <em>only</em> | 45 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
46 * within the DWT implementation. | 46 * within the DWT implementation. |
47 * </p> | 47 * </p> |
48 * | |
49 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
48 */ | 50 */ |
49 public abstract class Scrollable : Control { | 51 public abstract class Scrollable : Control { |
50 SWTScrollView scrollView; | 52 NSScrollView scrollView; |
51 ScrollBar horizontalBar, verticalBar; | 53 ScrollBar horizontalBar, verticalBar; |
52 | 54 |
53 this () { | 55 this () { |
54 /* Do nothing */ | 56 /* Do nothing */ |
55 } | 57 } |
83 * @see Widget#checkSubclass | 85 * @see Widget#checkSubclass |
84 * @see Widget#getStyle | 86 * @see Widget#getStyle |
85 */ | 87 */ |
86 public this (Composite parent, int style) { | 88 public this (Composite parent, int style) { |
87 super (parent, style); | 89 super (parent, style); |
90 } | |
91 | |
92 bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) { | |
93 // Always ignore scrollers. | |
94 if (scrollView !is null && id is scrollView.id) return true; | |
95 return super.accessibilityIsIgnored(id, sel); | |
88 } | 96 } |
89 | 97 |
90 /** | 98 /** |
91 * Given a desired <em>client area</em> for the receiver | 99 * Given a desired <em>client area</em> for the receiver |
92 * (as described by the arguments), returns the bounding | 100 * (as described by the arguments), returns the bounding |
137 bar.parent = this; | 145 bar.parent = this; |
138 bar.style = style; | 146 bar.style = style; |
139 bar.display = display; | 147 bar.display = display; |
140 NSScroller scroller; | 148 NSScroller scroller; |
141 String actionSelector; | 149 String actionSelector; |
150 NSRect rect = new NSRect(); | |
142 if ((style & DWT.H_SCROLL) !is 0) { | 151 if ((style & DWT.H_SCROLL) !is 0) { |
143 scroller = scrollView.horizontalScroller(); | 152 rect.width = 1; |
153 } else { | |
154 rect.height = 1; | |
155 } | |
156 scroller = (NSScroller)new SWTScroller().alloc(); | |
157 scroller.initWithFrame(rect); | |
158 if ((style & DWT.H_SCROLL) !is 0) { | |
159 scrollView.setHorizontalScroller(scroller); | |
144 actionSelector = OS.sel_sendHorizontalSelection; | 160 actionSelector = OS.sel_sendHorizontalSelection; |
145 } else { | 161 } else { |
146 scroller = scrollView.verticalScroller(); | 162 scrollView.setVerticalScroller(scroller); |
147 actionSelector = OS.sel_sendVerticalSelection; | 163 actionSelector = OS.sel_sendVerticalSelection; |
148 } | 164 } |
149 bar.view = scroller; | 165 bar.view = scroller; |
150 //bar.createJNIRef(); | 166 //bar.createJNIRef(); |
151 scroller.setTag(bar.jniRef); | 167 bar.register(); |
152 if ((state & CANVAS) is 0) { | 168 if ((state & CANVAS) is 0) { |
153 bar.target = scroller.target(); | 169 bar.target = scroller.target(); |
154 bar.actionSelector = scroller.action(); | 170 bar.actionSelector = scroller.action(); |
155 } | 171 } |
156 scroller.setTarget(scrollView); | 172 scroller.setTarget(scrollView); |
160 | 176 |
161 void createWidget () { | 177 void createWidget () { |
162 super.createWidget (); | 178 super.createWidget (); |
163 if ((style & DWT.H_SCROLL) !is 0) horizontalBar = createScrollBar (DWT.H_SCROLL); | 179 if ((style & DWT.H_SCROLL) !is 0) horizontalBar = createScrollBar (DWT.H_SCROLL); |
164 if ((style & DWT.V_SCROLL) !is 0) verticalBar = createScrollBar (DWT.V_SCROLL); | 180 if ((style & DWT.V_SCROLL) !is 0) verticalBar = createScrollBar (DWT.V_SCROLL); |
181 } | |
182 | |
183 void deregister () { | |
184 super.deregister (); | |
185 if (scrollView !is null) display.removeWidget (scrollView); | |
165 } | 186 } |
166 | 187 |
167 /** | 188 /** |
168 * Returns a rectangle which describes the area of the | 189 * Returns a rectangle which describes the area of the |
169 * receiver which is capable of displaying data (that is, | 190 * receiver which is capable of displaying data (that is, |
223 | 244 |
224 bool hooksKeys () { | 245 bool hooksKeys () { |
225 return hooks (DWT.KeyDown) || hooks (DWT.KeyUp) || hooks (DWT.Traverse); | 246 return hooks (DWT.KeyDown) || hooks (DWT.KeyUp) || hooks (DWT.Traverse); |
226 } | 247 } |
227 | 248 |
249 bool isTrim (NSView view) { | |
250 if (scrollView !is null) { | |
251 if (scrollView.id is view.id) return true; | |
252 if (horizontalBar !is null && horizontalBar.view.id is view.id) return true; | |
253 if (verticalBar !is null && verticalBar.view.id is view.id) return true; | |
254 } | |
255 return super.isTrim (view); | |
256 } | |
257 | |
258 void register () { | |
259 super.register (); | |
260 if (scrollView !is null) display.addWidget (scrollView, this); | |
261 } | |
228 | 262 |
229 void releaseHandle () { | 263 void releaseHandle () { |
230 super.releaseHandle (); | 264 super.releaseHandle (); |
231 if (scrollView !is null) { | 265 if (scrollView !is null) scrollView.release(); |
232 scrollView.setTag(-1); | |
233 scrollView.release(); | |
234 } | |
235 scrollView = null; | 266 scrollView = null; |
236 } | 267 } |
237 | 268 |
238 void releaseChildren (bool destroy) { | 269 void releaseChildren (bool destroy) { |
239 if (horizontalBar !is null) { | 270 if (horizontalBar !is null) { |
245 verticalBar = null; | 276 verticalBar = null; |
246 } | 277 } |
247 super.releaseChildren (destroy); | 278 super.releaseChildren (destroy); |
248 } | 279 } |
249 | 280 |
250 void resizeClientArea () { | |
251 // if (scrolledHandle is 0) return; | |
252 // if ((state & CANVAS) is 0) return; | |
253 // int vWidth = 0, hHeight = 0; | |
254 // int [] outMetric = new int [1]; | |
255 // OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric); | |
256 // bool isVisibleHBar = horizontalBar !is null && horizontalBar.getVisible (); | |
257 // bool isVisibleVBar = verticalBar !is null && verticalBar.getVisible (); | |
258 // if (isVisibleHBar) hHeight = outMetric [0]; | |
259 // if (isVisibleVBar) vWidth = outMetric [0]; | |
260 // int width, height; | |
261 // CGRect rect = new CGRect (); | |
262 // OS.HIViewGetBounds (scrolledHandle, rect); | |
263 // width = cast(int) rect.width; | |
264 // height = cast(int) rect.height; | |
265 // Rect inset = inset (); | |
266 // width = Math.max (0, width - vWidth - inset.left - inset.right); | |
267 // height = Math.max (0, height - hHeight - inset.top - inset.bottom); | |
268 // setBounds (handle, inset.left, inset.top, width, height, true, true, false); | |
269 // if (isVisibleHBar) { | |
270 // setBounds (horizontalBar.handle, inset.left, inset.top + height, width, hHeight, true, true, false); | |
271 // } | |
272 // if (isVisibleVBar) { | |
273 // setBounds (verticalBar.handle, inset.left + width, inset.top, vWidth, height, true, true, false); | |
274 // } | |
275 } | |
276 | |
277 void sendHorizontalSelection () { | 281 void sendHorizontalSelection () { |
278 horizontalBar.sendSelection (); | 282 horizontalBar.sendSelection (); |
279 } | |
280 | |
281 bool sendMouseWheel (short wheelAxis, int wheelDelta) { | |
282 // if ((state & CANVAS) !is 0) { | |
283 // ScrollBar bar = wheelAxis is OS.kEventMouseWheelAxisX ? horizontalBar : verticalBar; | |
284 // if (bar !is null && bar.getEnabled ()) { | |
285 // bar.setSelection (Math.max (0, bar.getSelection () - bar.getIncrement () * wheelDelta)); | |
286 // Event event = new Event (); | |
287 // event.detail = wheelDelta > 0 ? DWT.PAGE_UP : DWT.PAGE_DOWN; | |
288 // bar.sendEvent (DWT.Selection, event); | |
289 // return true; | |
290 // } | |
291 // } | |
292 return false; | |
293 } | 283 } |
294 | 284 |
295 void sendVerticalSelection () { | 285 void sendVerticalSelection () { |
296 verticalBar.sendSelection (); | 286 verticalBar.sendSelection (); |
297 } | 287 } |
304 bar.state &= ~HIDDEN; | 294 bar.state &= ~HIDDEN; |
305 } else { | 295 } else { |
306 if ((bar.state & HIDDEN) !is 0) return false; | 296 if ((bar.state & HIDDEN) !is 0) return false; |
307 bar.state |= HIDDEN; | 297 bar.state |= HIDDEN; |
308 } | 298 } |
309 resizeClientArea (); | 299 if ((bar.style & DWT.HORIZONTAL) !is 0) { |
310 // setVisible (bar.handle, visible); | 300 scrollView.setHasHorizontalScroller (visible); |
301 } else { | |
302 scrollView.setHasVerticalScroller (visible); | |
303 } | |
311 bar.sendEvent (visible ? DWT.Show : DWT.Hide); | 304 bar.sendEvent (visible ? DWT.Show : DWT.Hide); |
312 sendEvent (DWT.Resize); | 305 sendEvent (DWT.Resize); |
313 return true; | 306 return true; |
314 } | 307 } |
315 | 308 |
309 void setZOrder () { | |
310 super.setZOrder (); | |
311 if (scrollView !is null) scrollView.setDocumentView (view); | |
312 } | |
313 | |
316 NSView topView () { | 314 NSView topView () { |
317 if (scrollView !is null) return scrollView; | 315 if (scrollView !is null) return scrollView; |
318 return super.topView (); | 316 return super.topView (); |
319 } | 317 } |
320 } | 318 } |