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