Mercurial > projects > dwt2
comparison org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/ControlSegment.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | dbfb303e8fb0 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
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 org.eclipse.ui.internal.forms.widgets.ControlSegment; | |
14 | |
15 import org.eclipse.ui.internal.forms.widgets.ObjectSegment; | |
16 import org.eclipse.ui.internal.forms.widgets.IFocusSelectable; | |
17 import org.eclipse.ui.internal.forms.widgets.Locator; | |
18 import org.eclipse.ui.internal.forms.widgets.FormUtil; | |
19 | |
20 import org.eclipse.swt.SWT; | |
21 import org.eclipse.swt.graphics.GC; | |
22 import org.eclipse.swt.graphics.Point; | |
23 import org.eclipse.swt.graphics.Rectangle; | |
24 import org.eclipse.swt.widgets.Canvas; | |
25 import org.eclipse.swt.widgets.Composite; | |
26 import org.eclipse.swt.widgets.Control; | |
27 | |
28 import java.lang.all; | |
29 import java.util.Set; | |
30 | |
31 public class ControlSegment : ObjectSegment, IFocusSelectable { | |
32 | |
33 | |
34 private bool fill; | |
35 private int width = SWT.DEFAULT; | |
36 private int height = SWT.DEFAULT; | |
37 | |
38 // reimpl for interface | |
39 Rectangle getBounds(){ | |
40 return super.getBounds(); | |
41 } | |
42 | |
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); | |
69 if (control is null) | |
70 return new Point(0,0); | |
71 int realWhint = FormUtil.getWidthHint(wHint, control); | |
72 Point size = control.computeSize(realWhint, SWT.DEFAULT); | |
73 if (realWhint !is SWT.DEFAULT && fill) | |
74 size.x = Math.max(size.x, realWhint); | |
75 if (width !is SWT.DEFAULT) | |
76 size.x = width; | |
77 if (height !is SWT.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 } |