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