Mercurial > projects > dwt-addons
annotate dwtx/ui/internal/forms/widgets/ControlSegment.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 0953c252a764 |
children |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2005, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.ui.internal.forms.widgets.ControlSegment; | |
14 | |
15 import dwtx.ui.internal.forms.widgets.ObjectSegment; | |
16 import dwtx.ui.internal.forms.widgets.IFocusSelectable; | |
17 import dwtx.ui.internal.forms.widgets.Locator; | |
76 | 18 import dwtx.ui.internal.forms.widgets.FormUtil; |
75 | 19 |
20 import dwt.DWT; | |
21 import dwt.graphics.GC; | |
22 import dwt.graphics.Point; | |
76 | 23 import dwt.graphics.Rectangle; |
75 | 24 import dwt.widgets.Canvas; |
25 import dwt.widgets.Composite; | |
26 import dwt.widgets.Control; | |
27 | |
79 | 28 import dwt.dwthelper.utils; |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
79
diff
changeset
|
29 import dwtx.dwtxhelper.Collection; |
79 | 30 |
75 | 31 public class ControlSegment : ObjectSegment, IFocusSelectable { |
76 | 32 |
33 | |
75 | 34 private bool fill; |
35 private int width = DWT.DEFAULT; | |
36 private int height = DWT.DEFAULT; | |
37 | |
76 | 38 // reimpl for interface |
39 Rectangle getBounds(){ | |
40 return super.getBounds(); | |
41 } | |
42 | |
75 | 43 public this() { |
44 } | |
45 | |
46 public void setFill(bool fill) { | |
47 this.fill = fill; | |
48 } | |
49 | |
50 public void setWidth(int width) { | |
51 this.width = width; | |
52 } | |
53 | |
54 public void setHeight(int height) { | |
55 this.height = height; | |
56 } | |
57 | |
58 public Control getControl(Hashtable resourceTable) { | |
59 Object obj = resourceTable.get(getObjectId()); | |
60 if ( auto c = cast(Control)obj ) { | |
61 if (!c.isDisposed()) | |
62 return c; | |
63 } | |
64 return null; | |
65 } | |
66 | |
67 protected Point getObjectSize(Hashtable resourceTable, int wHint) { | |
68 Control control = getControl(resourceTable); | |
76 | 69 if (control is null) |
75 | 70 return new Point(0,0); |
71 int realWhint = FormUtil.getWidthHint(wHint, control); | |
72 Point size = control.computeSize(realWhint, DWT.DEFAULT); | |
73 if (realWhint !is DWT.DEFAULT && fill) | |
74 size.x = Math.max(size.x, realWhint); | |
75 if (width !is DWT.DEFAULT) | |
76 size.x = width; | |
77 if (height !is DWT.DEFAULT) | |
78 size.y = height; | |
79 return size; | |
80 } | |
81 | |
82 public void layout(GC gc, int width, Locator loc, Hashtable resourceTable, | |
83 bool selected) { | |
84 super.layout(gc, width, loc, resourceTable, selected); | |
85 Control control = getControl(resourceTable); | |
86 if (control !is null) | |
87 control.setBounds(getBounds()); | |
88 } | |
89 | |
90 public bool setFocus(Hashtable resourceTable, bool next) { | |
91 Control c = getControl(resourceTable); | |
92 if (c !is null) { | |
93 return setFocus(c, next); | |
94 } | |
95 return false; | |
96 } | |
97 | |
98 private bool setFocus(Control c, bool direction) { | |
99 if (auto comp = cast(Composite)c ) { | |
100 Control [] tabList = comp.getTabList(); | |
101 if (direction) { | |
102 for (int i=0; i<tabList.length; i++) { | |
103 if (setFocus(tabList[i], direction)) | |
104 return true; | |
105 } | |
106 } | |
107 else { | |
108 for (int i=tabList.length-1; i>=0; i--) { | |
109 if (setFocus(tabList[i], direction)) | |
110 return true; | |
111 } | |
112 } | |
113 if (!(null !is cast(Canvas)c )) | |
114 return false; | |
115 } | |
116 return c.setFocus(); | |
117 } | |
118 | |
119 public bool isFocusSelectable(Hashtable resourceTable) { | |
120 Control c = getControl(resourceTable); | |
121 if (c !is null) | |
122 return true; | |
123 return false; | |
124 } | |
125 } |