Mercurial > projects > dwt-addons
annotate dwtx/jface/fieldassist/TextContentAdapter.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.TextContentAdapter; | |
14 | |
15 import dwtx.jface.fieldassist.IControlContentAdapter; | |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
16 import dwtx.jface.fieldassist.IControlContentAdapter2; |
29 | 17 |
18 import dwt.graphics.Point; | |
19 import dwt.graphics.Rectangle; | |
20 import dwt.widgets.Control; | |
21 import dwt.widgets.Text; | |
22 | |
23 import dwt.dwthelper.utils; | |
24 | |
25 /** | |
26 * An {@link IControlContentAdapter} for DWT Text controls. This is a | |
27 * convenience class for easily creating a {@link ContentProposalAdapter} for | |
28 * text fields. | |
29 * | |
30 * @since 3.2 | |
31 */ | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
32 public class TextContentAdapter : IControlContentAdapter, |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
33 IControlContentAdapter2 { |
29 | 34 |
35 /* | |
36 * (non-Javadoc) | |
37 * | |
38 * @see dwtx.jface.dialogs.taskassistance.IControlContentAdapter#getControlContents(dwt.widgets.Control) | |
39 */ | |
40 public String getControlContents(Control control) { | |
41 return (cast(Text) control).getText(); | |
42 } | |
43 | |
44 /* | |
45 * (non-Javadoc) | |
46 * | |
47 * @see dwtx.jface.fieldassist.IControlContentAdapter#setControlContents(dwt.widgets.Control, | |
48 * java.lang.String, int) | |
49 */ | |
50 public void setControlContents(Control control, String text, | |
51 int cursorPosition) { | |
52 (cast(Text) control).setText(text); | |
53 (cast(Text) control).setSelection(cursorPosition, cursorPosition); | |
54 } | |
55 | |
56 /* | |
57 * (non-Javadoc) | |
58 * | |
59 * @see dwtx.jface.fieldassist.IControlContentAdapter#insertControlContents(dwt.widgets.Control, | |
60 * java.lang.String, int) | |
61 */ | |
62 public void insertControlContents(Control control, String text, | |
63 int cursorPosition) { | |
64 Point selection = (cast(Text) control).getSelection(); | |
65 (cast(Text) control).insert(text); | |
66 // Insert will leave the cursor at the end of the inserted text. If this | |
67 // is not what we wanted, reset the selection. | |
68 if (cursorPosition < text.length) { | |
69 (cast(Text) control).setSelection(selection.x + cursorPosition, | |
70 selection.x + cursorPosition); | |
71 } | |
72 } | |
73 | |
74 /* | |
75 * (non-Javadoc) | |
76 * | |
77 * @see dwtx.jface.fieldassist.IControlContentAdapter#getCursorPosition(dwt.widgets.Control) | |
78 */ | |
79 public int getCursorPosition(Control control) { | |
80 return (cast(Text) control).getCaretPosition(); | |
81 } | |
82 | |
83 /* | |
84 * (non-Javadoc) | |
85 * | |
86 * @see dwtx.jface.fieldassist.IControlContentAdapter#getInsertionBounds(dwt.widgets.Control) | |
87 */ | |
88 public Rectangle getInsertionBounds(Control control) { | |
89 Text text = cast(Text) control; | |
90 Point caretOrigin = text.getCaretLocation(); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
91 // We fudge the y pixels due to problems with getCaretLocation |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
92 // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=52520 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
93 return new Rectangle(caretOrigin.x + text.getClientArea().x, |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
94 caretOrigin.y + text.getClientArea().y + 3, 1, text.getLineHeight()); |
29 | 95 } |
96 | |
97 /* | |
98 * (non-Javadoc) | |
99 * | |
100 * @see dwtx.jface.fieldassist.IControlContentAdapter#setCursorPosition(dwt.widgets.Control, | |
101 * int) | |
102 */ | |
103 public void setCursorPosition(Control control, int position) { | |
104 (cast(Text) control).setSelection(new Point(position, position)); | |
105 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
106 |
90 | 107 /** |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
108 * @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
|
109 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
110 * @since 3.4 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
111 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
112 public Point getSelection(Control control) { |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
113 return (cast(Text) control).getSelection(); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
114 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
115 |
90 | 116 /** |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
117 * @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
|
118 * dwt.graphics.Point) |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
119 * |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
120 * @since 3.4 |
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 public void setSelection(Control control, Point range) { |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
123 (cast(Text) control).setSelection(range); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
29
diff
changeset
|
124 } |
29 | 125 } |