Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / java / awt / peer / gtk / GtkTextFieldPeer.java
blob4afdae82e5e24a6399a788fc21c9106562881d01
1 /* GtkTextFieldPeer.java -- Implements TextFieldPeer with GTK
2 Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.awt.peer.gtk;
41 import java.awt.AWTEvent;
42 import java.awt.Dimension;
43 import java.awt.Font;
44 import java.awt.FontMetrics;
45 import java.awt.Rectangle;
46 import java.awt.TextField;
47 import java.awt.event.KeyEvent;
48 import java.awt.im.InputMethodRequests;
49 import java.awt.peer.TextFieldPeer;
50 import java.awt.peer.TextComponentPeer;
52 public class GtkTextFieldPeer extends GtkComponentPeer
53 implements TextComponentPeer, TextFieldPeer
55 native void create (int width);
56 native void gtkWidgetSetBackground (int red, int green, int blue);
57 native void gtkWidgetSetForeground (int red, int green, int blue);
59 public native void connectSignals ();
61 public native int getCaretPosition ();
62 public native void setCaretPosition (int pos);
63 public native int getSelectionStart ();
64 public native int getSelectionEnd ();
65 public native String getText ();
66 public native void select (int start, int end);
67 public native void setEditable (boolean state);
68 public native void setText (String text);
70 public int getIndexAtPoint(int x, int y)
72 // FIXME
73 return 0;
76 public Rectangle getCharacterBounds (int pos)
78 // FIXME
79 return null;
82 public long filterEvents (long filter)
84 // FIXME
85 return filter;
88 void create ()
90 Font f = awtComponent.getFont ();
92 // By default, Sun sets a TextField's font when its peer is
93 // created. If f != null then the peer's font is set by
94 // GtkComponent.create.
95 if (f == null)
97 f = new Font ("Dialog", Font.PLAIN, 12);
98 awtComponent.setFont (f);
101 FontMetrics fm = getFontMetrics (f);
103 TextField tf = ((TextField) awtComponent);
104 int cols = tf.getColumns ();
106 int text_width = cols * fm.getMaxAdvance ();
108 create (text_width);
110 setEditable (tf.isEditable ());
113 native int gtkEntryGetBorderWidth ();
115 native void gtkWidgetModifyFont (String name, int style, int size);
117 public GtkTextFieldPeer (TextField tf)
119 super (tf);
121 setText (tf.getText ());
122 setCaretPosition (0);
124 if (tf.echoCharIsSet ())
125 setEchoChar (tf.getEchoChar ());
128 public Dimension getMinimumSize (int cols)
130 return minimumSize (cols);
133 public Dimension getPreferredSize (int cols)
135 return preferredSize (cols);
138 public native void setEchoChar (char c);
140 // Deprecated
141 public Dimension minimumSize (int cols)
143 int dim[] = new int[2];
145 gtkWidgetGetPreferredDimensions (dim);
147 Font f = awtComponent.getFont ();
148 if (f == null)
149 return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]);
151 FontMetrics fm = getFontMetrics (f);
153 int text_width = cols * fm.getMaxAdvance ();
155 int width = text_width + 2 * gtkEntryGetBorderWidth ();
157 return new Dimension (width, dim[1]);
160 public Dimension preferredSize (int cols)
162 int dim[] = new int[2];
164 gtkWidgetGetPreferredDimensions (dim);
166 Font f = awtComponent.getFont ();
167 if (f == null)
168 return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]);
170 FontMetrics fm = getFontMetrics (f);
172 int text_width = cols * fm.getMaxAdvance ();
174 int width = text_width + 2 * gtkEntryGetBorderWidth ();
176 return new Dimension (width, dim[1]);
179 public void setEchoCharacter (char c)
181 setEchoChar (c);
184 public void handleEvent (AWTEvent e)
186 if (e.getID () == KeyEvent.KEY_PRESSED)
188 KeyEvent ke = (KeyEvent) e;
190 if (!ke.isConsumed ()
191 && ke.getKeyCode () == KeyEvent.VK_ENTER)
192 postActionEvent (getText (), ke.getModifiersEx ());
195 super.handleEvent (e);
197 public InputMethodRequests getInputMethodRequests()
199 // FIXME: implement
200 return null;