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
|
|
28 public class ControlSegment : ObjectSegment, IFocusSelectable {
|
76
|
29
|
|
30
|
75
|
31 private bool fill;
|
|
32 private int width = DWT.DEFAULT;
|
|
33 private int height = DWT.DEFAULT;
|
|
34
|
76
|
35 // reimpl for interface
|
|
36 Rectangle getBounds(){
|
|
37 return super.getBounds();
|
|
38 }
|
|
39
|
75
|
40 public this() {
|
|
41 }
|
|
42
|
|
43 public void setFill(bool fill) {
|
|
44 this.fill = fill;
|
|
45 }
|
|
46
|
|
47 public void setWidth(int width) {
|
|
48 this.width = width;
|
|
49 }
|
|
50
|
|
51 public void setHeight(int height) {
|
|
52 this.height = height;
|
|
53 }
|
|
54
|
|
55 public Control getControl(Hashtable resourceTable) {
|
|
56 Object obj = resourceTable.get(getObjectId());
|
|
57 if ( auto c = cast(Control)obj ) {
|
|
58 if (!c.isDisposed())
|
|
59 return c;
|
|
60 }
|
|
61 return null;
|
|
62 }
|
|
63
|
|
64 protected Point getObjectSize(Hashtable resourceTable, int wHint) {
|
|
65 Control control = getControl(resourceTable);
|
76
|
66 if (control is null)
|
75
|
67 return new Point(0,0);
|
|
68 int realWhint = FormUtil.getWidthHint(wHint, control);
|
|
69 Point size = control.computeSize(realWhint, DWT.DEFAULT);
|
|
70 if (realWhint !is DWT.DEFAULT && fill)
|
|
71 size.x = Math.max(size.x, realWhint);
|
|
72 if (width !is DWT.DEFAULT)
|
|
73 size.x = width;
|
|
74 if (height !is DWT.DEFAULT)
|
|
75 size.y = height;
|
|
76 return size;
|
|
77 }
|
|
78
|
|
79 public void layout(GC gc, int width, Locator loc, Hashtable resourceTable,
|
|
80 bool selected) {
|
|
81 super.layout(gc, width, loc, resourceTable, selected);
|
|
82 Control control = getControl(resourceTable);
|
|
83 if (control !is null)
|
|
84 control.setBounds(getBounds());
|
|
85 }
|
|
86
|
|
87 public bool setFocus(Hashtable resourceTable, bool next) {
|
|
88 Control c = getControl(resourceTable);
|
|
89 if (c !is null) {
|
|
90 return setFocus(c, next);
|
|
91 }
|
|
92 return false;
|
|
93 }
|
|
94
|
|
95 private bool setFocus(Control c, bool direction) {
|
|
96 if (auto comp = cast(Composite)c ) {
|
|
97 Control [] tabList = comp.getTabList();
|
|
98 if (direction) {
|
|
99 for (int i=0; i<tabList.length; i++) {
|
|
100 if (setFocus(tabList[i], direction))
|
|
101 return true;
|
|
102 }
|
|
103 }
|
|
104 else {
|
|
105 for (int i=tabList.length-1; i>=0; i--) {
|
|
106 if (setFocus(tabList[i], direction))
|
|
107 return true;
|
|
108 }
|
|
109 }
|
|
110 if (!(null !is cast(Canvas)c ))
|
|
111 return false;
|
|
112 }
|
|
113 return c.setFocus();
|
|
114 }
|
|
115
|
|
116 public bool isFocusSelectable(Hashtable resourceTable) {
|
|
117 Control c = getControl(resourceTable);
|
|
118 if (c !is null)
|
|
119 return true;
|
|
120 return false;
|
|
121 }
|
|
122 }
|