Mercurial > projects > dwt-addons
annotate dwtx/jface/fieldassist/ComboContentAdapter.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | 5df4896124c7 |
children |
rev | line source |
---|---|
29 | 1 /******************************************************************************* |
90 | 2 * Copyright (c) 2005, 2008 IBM Corporation and others. |
29 | 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.jface.fieldassist.ComboContentAdapter; | |
14 | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
15 import dwt.DWT; |
29 | 16 import dwtx.jface.fieldassist.IControlContentAdapter; |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
17 import dwtx.jface.fieldassist.IControlContentAdapter2; |
29 | 18 |
19 import dwt.graphics.GC; | |
20 import dwt.graphics.Point; | |
21 import dwt.graphics.Rectangle; | |
22 import dwt.widgets.Combo; | |
23 import dwt.widgets.Control; | |
24 | |
25 import dwt.dwthelper.utils; | |
26 import tango.text.Text; | |
27 alias tango.text.Text.Text!(char) StringBuffer; | |
28 /** | |
29 * An {@link IControlContentAdapter} for DWT Combo controls. This is a | |
30 * convenience class for easily creating a {@link ContentProposalAdapter} for | |
31 * combo fields. | |
32 * | |
33 * @since 3.2 | |
34 */ | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
35 public class ComboContentAdapter : IControlContentAdapter, |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
36 IControlContentAdapter2 { |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
37 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
38 /* |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
39 * Set to <code>true</code> if we should compute the text |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
40 * vertical bounds rather than just use the field size. |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
41 * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=164748 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
42 * The corresponding DWT bug is |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
43 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=44072 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
44 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
45 private static final bool COMPUTE_TEXT_USING_CLIENTAREA = !"carbon".equals(DWT.getPlatform()); //$NON-NLS-1$ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
46 |
29 | 47 |
48 /* | |
49 * (non-Javadoc) | |
50 * | |
51 * @see dwtx.jface.dialogs.taskassistance.IControlContentAdapter#getControlContents(dwt.widgets.Control) | |
52 */ | |
53 public String getControlContents(Control control) { | |
54 return (cast(Combo) control).getText(); | |
55 } | |
56 | |
57 /* | |
58 * (non-Javadoc) | |
59 * | |
60 * @see dwtx.jface.fieldassist.IControlContentAdapter#setControlContents(dwt.widgets.Control, | |
61 * java.lang.String, int) | |
62 */ | |
63 public void setControlContents(Control control, String text, | |
64 int cursorPosition) { | |
65 (cast(Combo) control).setText(text); | |
66 (cast(Combo) control) | |
67 .setSelection(new Point(cursorPosition, cursorPosition)); | |
68 } | |
69 | |
70 /* | |
71 * (non-Javadoc) | |
72 * | |
73 * @see dwtx.jface.fieldassist.IControlContentAdapter#insertControlContents(dwt.widgets.Control, | |
74 * java.lang.String, int) | |
75 */ | |
76 public void insertControlContents(Control control, String text, | |
77 int cursorPosition) { | |
78 Combo combo = cast(Combo) control; | |
79 String contents = combo.getText(); | |
80 Point selection = combo.getSelection(); | |
81 StringBuffer sb = new StringBuffer(); | |
82 sb.append(contents.substring(0, selection.x)); | |
83 sb.append(text); | |
84 if (selection.y < contents.length) { | |
85 sb.append(contents.substring(selection.y, contents.length)); | |
86 } | |
87 combo.setText(sb.toString()); | |
88 selection.x = selection.x + cursorPosition; | |
89 selection.y = selection.x; | |
90 combo.setSelection(selection); | |
91 } | |
92 | |
93 /* | |
94 * (non-Javadoc) | |
95 * | |
96 * @see dwtx.jface.fieldassist.IControlContentAdapter#getCursorPosition(dwt.widgets.Control) | |
97 */ | |
98 public int getCursorPosition(Control control) { | |
99 return (cast(Combo) control).getSelection().x; | |
100 } | |
101 | |
102 /* | |
103 * (non-Javadoc) | |
104 * | |
105 * @see dwtx.jface.fieldassist.IControlContentAdapter#getInsertionBounds(dwt.widgets.Control) | |
106 */ | |
107 public Rectangle getInsertionBounds(Control control) { | |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
108 // This doesn't take horizontal scrolling into affect. |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
109 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=204599 |
29 | 110 Combo combo = cast(Combo) control; |
111 int position = combo.getSelection().y; | |
112 String contents = combo.getText(); | |
113 GC gc = new GC(combo); | |
114 gc.setFont(combo.getFont()); | |
115 Point extent = gc.textExtent(contents.substring(0, Math.min(position, | |
116 contents.length))); | |
117 gc.dispose(); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
118 if (COMPUTE_TEXT_USING_CLIENTAREA) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
119 return new Rectangle(combo.getClientArea().x + extent.x, combo |
29 | 120 .getClientArea().y, 1, combo.getClientArea().height); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
121 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
122 return new Rectangle(extent.x, 0, 1, combo.getSize().y); |
29 | 123 } |
124 | |
125 /* | |
126 * (non-Javadoc) | |
127 * | |
128 * @see dwtx.jface.fieldassist.IControlContentAdapter#setCursorPosition(dwt.widgets.Control, | |
129 * int) | |
130 */ | |
131 public void setCursorPosition(Control control, int index) { | |
132 (cast(Combo) control).setSelection(new Point(index, index)); | |
133 } | |
134 | |
90 | 135 /** |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
136 * @see dwtx.jface.fieldassist.IControlContentAdapter2#getSelection(dwt.widgets.Control) |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
137 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
138 * @since 3.4 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
139 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
140 public Point getSelection(Control control) { |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
141 return (cast(Combo) control).getSelection(); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
142 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
143 |
90 | 144 /** |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
145 * @see dwtx.jface.fieldassist.IControlContentAdapter2#setSelection(dwt.widgets.Control, |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
146 * dwt.graphics.Point) |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
147 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
148 * @since 3.4 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
149 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
150 public void setSelection(Control control, Point range) { |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
151 (cast(Combo) control).setSelection(range); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
152 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
153 |
29 | 154 } |