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