source: trunk/gcc/libjava/gnu/awt/gtk/GtkComponentPeer.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.5 KB
Line 
1/* GtkComponentPeer.java -- Implements ComponentPeer with GTK
2 Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
3
4This file is part of the peer AWT libraries of GNU Classpath.
5
6This library is free software; you can redistribute it and/or modify
7it under the terms of the GNU Library General Public License as published
8by the Free Software Foundation, either version 2 of the License, or
9(at your option) any later verion.
10
11This library is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Library General Public License for more details.
15
16You should have received a copy of the GNU Library General Public License
17along with this library; if not, write to the Free Software Foundation
18Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */
19
20
21package gnu.awt.gtk;
22
23import java.awt.*;
24import java.awt.event.*;
25import java.awt.image.*;
26import java.awt.peer.ComponentPeer;
27
28public abstract class GtkComponentPeer implements ComponentPeer
29{
30 // We need to put a reference to the Event Queue somewhere. This seems like
31 // a convenient place.
32 static EventQueue eventQueue = new EventQueue();
33
34 Component awtComponent;
35 gnu.gcj.RawData ptr; // Actual gtk object.
36
37 static
38 {
39 // This will start the main toolkit thread.
40 GtkToolkit.instance.init();
41 }
42
43 public int checkImage (Image image, int width, int height,
44 ImageObserver observer)
45 {
46 return -1;
47 /*
48 GtkImage i = (GtkImage) image;
49 return i.checkImage ();
50 */
51 }
52
53 public Image createImage (ImageProducer producer)
54 {
55 return null;
56 //return new GtkImage (producer, null);
57 }
58
59 public Image createImage (int width, int height)
60 {
61 return null;
62 /*
63 GdkGraphics g = new GdkGraphics (width, height);
64 return new GtkOffScreenImage (null, g, width, height);
65 */
66 }
67
68 public void disable ()
69 {
70 setEnabled (false);
71 }
72
73 native public void dispose ();
74
75 public void enable ()
76 {
77 setEnabled (true);
78 }
79
80 /**
81 * Get the graphics configuration of the component. The color model
82 * of the component can be derived from the configuration.
83 */
84 public GraphicsConfiguration getGraphicsConfiguration ()
85 {
86 return null;
87 }
88
89 public FontMetrics getFontMetrics (Font font)
90 {
91 return null;
92 //return new GdkFontMetrics (font);
93 }
94
95 public Graphics getGraphics ()
96 {
97 throw new InternalError ();
98 }
99
100 public native Point getLocationOnScreen ();
101 public native Dimension getMinimumSize();
102 public native Dimension getPreferredSize();
103
104 public Toolkit getToolkit ()
105 {
106 return GtkToolkit.instance;
107 }
108
109 public void handleEvent(AWTEvent e)
110 {
111 }
112
113 public void hide ()
114 {
115 setVisible (false);
116 }
117
118 public void show ()
119 {
120 setVisible (true);
121 }
122
123 public boolean isFocusTraversable ()
124 {
125 return true;
126 }
127
128 public Dimension minimumSize ()
129 {
130 return getMinimumSize();
131 }
132
133 public Dimension preferredSize()
134 {
135 return getPreferredSize();
136 }
137
138 public void paint (Graphics g)
139 {
140 awtComponent.paint (g); // ???
141 }
142
143 public boolean prepareImage (Image image, int width, int height,
144 ImageObserver observer)
145 {
146 /*
147 GtkImage i = (GtkImage) image;
148
149 if (i.isLoaded ()) return true;
150
151 class PrepareImage extends Thread
152 {
153 GtkImage image;
154 ImageObserver observer;
155
156 PrepareImage (GtkImage image, ImageObserver observer)
157 {
158 this.image = image;
159 this.observer = observer;
160 }
161
162 public void run ()
163 {
164 // XXX: need to return data to image observer
165 image.source.startProduction (null);
166 }
167 }
168
169 new PrepareImage (i, observer).start ();
170 */
171 return false;
172 }
173
174 public void print (Graphics g)
175 {
176 throw new RuntimeException ();
177 }
178
179 native public void requestFocus ();
180
181 public void repaint (long tm, int x, int y, int width, int height)
182 {
183 // ???
184 eventQueue.postEvent (new PaintEvent (
185 awtComponent, PaintEvent.UPDATE, new Rectangle (x, y, width, height)));
186 }
187
188
189 public void reshape (int x, int y, int width, int height)
190 {
191 setBounds (x, y, width, height);
192 }
193
194 public native void setBounds (int x, int y, int width, int height);
195 public native void setCursor (Cursor cursor);
196
197 public native void setEnabled (boolean b);
198
199 public native void setEventMask(long eventMask);
200 public native void setFont(Font font);
201 public native void setForeground(Color color);
202 public native void setBackground (Color c);
203 public native void setVisible(boolean visible);
204
205 native void realize();
206
207 protected GtkComponentPeer (Component awtComponent)
208 {
209 this.awtComponent = awtComponent;
210 create();
211
212 // TODO: Each of these calls will currently perform a separate native lock.
213 // It may be desirable to use our own, recusive mutex implementation by
214 // passing our threads implementation to g_threads_init().
215 // This would greatly reduce locking calls in the peer code, and allow us
216 // to aquire the lock from java code.
217 Rectangle r = awtComponent.getBounds();
218 setBounds (r.x, r.y, r.width, r.height);
219
220 Color c = awtComponent.getForeground();
221 if (c != null)
222 setForeground (c);
223 c = awtComponent.getBackground();
224 if (c != null)
225 setBackground (c);
226 setEnabled (awtComponent.isEnabled());
227 Font f = awtComponent.getFont();
228 if (f != null)
229 setFont (awtComponent.getFont());
230
231 realize();
232 }
233
234 protected native void create ();
235
236 // FIXME: It may make sense to do the following directly from the native
237 // code.
238 protected void postMouseEvent(int id, long when, int mods, int x, int y,
239 int clickCount, boolean popupTrigger)
240 {
241 eventQueue.postEvent(new MouseEvent(awtComponent, id, when, mods, x, y,
242 clickCount, popupTrigger));
243 }
244
245 protected void postExposeEvent (int x, int y, int width, int height)
246 {
247 eventQueue.postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
248 new Rectangle (x, y, width, height)));
249 }
250
251 protected void postKeyEvent (int id, long when, int mods,
252 int keyCode, char keyChar)
253 {
254 eventQueue.postEvent (new KeyEvent (awtComponent, id, when, mods,
255 keyCode, keyChar));
256 }
257
258 protected void postFocusEvent (int id, boolean temporary)
259 {
260 eventQueue.postEvent (new FocusEvent (awtComponent, id, temporary));
261 }
262
263 protected void postItemEvent (Object item, int stateChange)
264 {
265 eventQueue.postEvent (new ItemEvent ((ItemSelectable)awtComponent,
266 ItemEvent.ITEM_STATE_CHANGED,
267 item, stateChange));
268 }
269}
Note: See TracBrowser for help on using the repository browser.