]> gcc.gnu.org Git - gcc.git/blob - libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
Makefile.am: Add GdkPixbufDecoder.java and gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
[gcc.git] / libjava / gnu / java / awt / peer / gtk / GtkToolkit.java
1 /* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
2 Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
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.
25
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. */
37
38
39 package gnu.java.awt.peer.gtk;
40
41 import java.awt.*;
42 import java.awt.datatransfer.Clipboard;
43 import java.awt.dnd.DragGestureEvent;
44 import java.awt.dnd.peer.DragSourceContextPeer;
45 import java.awt.im.InputMethodHighlight;
46 import java.awt.image.ColorModel;
47 import java.awt.image.ImageObserver;
48 import java.awt.image.ImageProducer;
49 import java.awt.peer.*;
50 import java.net.URL;
51 import java.util.Hashtable;
52 import java.util.Map;
53 import java.util.MissingResourceException;
54 import java.util.Properties;
55 import gnu.java.awt.EmbeddedWindow;
56 import gnu.java.awt.EmbeddedWindowSupport;
57 import gnu.java.awt.peer.EmbeddedWindowPeer;
58 import gnu.classpath.Configuration;
59 import gnu.java.awt.peer.gtk.GdkPixbufDecoder;
60
61 /* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer().
62 This merits comment. We are basically calling Sun's bluff on this one.
63 We think Sun has deprecated it simply to discourage its use as it is
64 bad programming style. However, we need to get at a component's peer in
65 this class. If getPeer() ever goes away, we can implement a hash table
66 that will keep up with every window's peer, but for now this is faster. */
67
68 public class GtkToolkit extends Toolkit
69 implements EmbeddedWindowSupport
70 {
71 GtkMainThread main;
72 Hashtable containers = new Hashtable();
73 static EventQueue q = new EventQueue();
74 static Clipboard systemClipboard;
75
76 static
77 {
78 if (Configuration.INIT_LOAD_LIBRARY)
79 System.loadLibrary("gtkpeer");
80 }
81
82 public GtkToolkit ()
83 {
84 main = new GtkMainThread ();
85 systemClipboard = new GtkClipboard ();
86 GtkGenericPeer.enableQueue (q);
87 }
88
89 native public void beep ();
90 native private void getScreenSizeDimensions (int[] xy);
91
92 public int checkImage (Image image, int width, int height,
93 ImageObserver observer)
94 {
95 return ((GtkImage) image).checkImage ();
96 }
97
98 public Image createImage (String filename)
99 {
100 return new GtkImage (new GdkPixbufDecoder (filename), null);
101 }
102
103 public Image createImage (URL url)
104 {
105 return new GtkImage (new GdkPixbufDecoder (url), null);
106 }
107
108 public Image createImage (ImageProducer producer)
109 {
110 return new GtkImage (producer, null);
111 }
112
113 public Image createImage (byte[] imagedata, int imageoffset,
114 int imagelength)
115 {
116 return new GtkImage (new GdkPixbufDecoder (imagedata,
117 imageoffset,
118 imagelength),
119 null);
120 }
121
122 public ColorModel getColorModel ()
123 {
124 return ColorModel.getRGBdefault ();
125 }
126
127 public String[] getFontList ()
128 {
129 return (new String[] { "Dialog",
130 "DialogInput",
131 "Monospaced",
132 "Serif",
133 "SansSerif" });
134 }
135
136 public FontMetrics getFontMetrics (Font font)
137 {
138 return new GdkFontMetrics (font);
139 }
140
141 public Image getImage (String filename)
142 {
143 return new GtkImage (new GdkPixbufDecoder (filename), null);
144 }
145
146 public Image getImage (URL url)
147 {
148 return new GtkImage (new GdkPixbufDecoder (url), null);
149 }
150
151 public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)
152 {
153 return null;
154 }
155
156 native public int getScreenResolution();
157
158 public Dimension getScreenSize () {
159 int dim[] = new int[2];
160 getScreenSizeDimensions(dim);
161 return new Dimension(dim[0], dim[1]);
162 }
163
164 public Clipboard getSystemClipboard()
165 {
166 return systemClipboard;
167 }
168
169 public boolean prepareImage (Image image, int width, int height,
170 ImageObserver observer)
171 {
172 if (image == null)
173 throw new NullPointerException ();
174
175 GtkImage i = (GtkImage) image;
176
177 if (i.isLoaded ()) return true;
178
179 class PrepareImage extends Thread
180 {
181 GtkImage image;
182 ImageObserver observer;
183
184 PrepareImage (GtkImage image, ImageObserver observer)
185 {
186 this.image = image;
187 image.setObserver (observer);
188 }
189
190 public void run ()
191 {
192 image.source.startProduction (image);
193 }
194 }
195
196 new PrepareImage (i, observer).start ();
197 return false;
198 }
199
200 native public void sync ();
201
202 protected void setComponentState (Component c, GtkComponentPeer cp)
203 {
204 /* Make the Component reflect Peer defaults */
205 if (c.getForeground () == null)
206 c.setForeground (cp.getForeground ());
207 if (c.getBackground () == null)
208 c.setBackground (cp.getBackground ());
209 // if (c.getFont () == null)
210 // c.setFont (cp.getFont ());
211
212 /* Make the Peer reflect the state of the Component */
213 if (! (c instanceof Window))
214 {
215 cp.setCursor (c.getCursor ());
216
217 Rectangle bounds = c.getBounds ();
218 cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
219 cp.setVisible (c.isVisible ());
220 }
221 }
222
223 protected ButtonPeer createButton (Button b)
224 {
225 return new GtkButtonPeer (b);
226 }
227
228 protected CanvasPeer createCanvas (Canvas c)
229 {
230 return new GtkCanvasPeer (c);
231 }
232
233 protected CheckboxPeer createCheckbox (Checkbox cb)
234 {
235 return new GtkCheckboxPeer (cb);
236 }
237
238 protected CheckboxMenuItemPeer createCheckboxMenuItem (CheckboxMenuItem cmi)
239 {
240 return new GtkCheckboxMenuItemPeer (cmi);
241 }
242
243 protected ChoicePeer createChoice (Choice c)
244 {
245 return new GtkChoicePeer (c);
246 }
247
248 protected DialogPeer createDialog (Dialog d)
249 {
250 return new GtkDialogPeer (d);
251 }
252
253 protected FileDialogPeer createFileDialog (FileDialog fd)
254 {
255 return new GtkFileDialogPeer (fd);
256 }
257
258 protected FramePeer createFrame (Frame f)
259 {
260 return new GtkFramePeer (f);
261 }
262
263 protected LabelPeer createLabel (Label label)
264 {
265 return new GtkLabelPeer (label);
266 }
267
268 protected ListPeer createList (List list)
269 {
270 return new GtkListPeer (list);
271 }
272
273 protected MenuPeer createMenu (Menu m)
274 {
275 return new GtkMenuPeer (m);
276 }
277
278 protected MenuBarPeer createMenuBar (MenuBar mb)
279 {
280 return new GtkMenuBarPeer (mb);
281 }
282
283 protected MenuItemPeer createMenuItem (MenuItem mi)
284 {
285 return new GtkMenuItemPeer (mi);
286 }
287
288 protected PanelPeer createPanel (Panel p)
289 {
290 return new GtkPanelPeer (p);
291 }
292
293 protected PopupMenuPeer createPopupMenu (PopupMenu target)
294 {
295 return new GtkPopupMenuPeer (target);
296 }
297
298 protected ScrollPanePeer createScrollPane (ScrollPane sp)
299 {
300 return new GtkScrollPanePeer (sp);
301 }
302
303 protected ScrollbarPeer createScrollbar (Scrollbar sb)
304 {
305 return new GtkScrollbarPeer (sb);
306 }
307
308 protected TextAreaPeer createTextArea (TextArea ta)
309 {
310 return new GtkTextAreaPeer (ta);
311 }
312
313 protected TextFieldPeer createTextField (TextField tf)
314 {
315 return new GtkTextFieldPeer (tf);
316 }
317
318 protected WindowPeer createWindow (Window w)
319 {
320 return new GtkWindowPeer (w);
321 }
322
323 public EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w)
324 {
325 return new GtkEmbeddedWindowPeer (w);
326 }
327
328 protected FontPeer getFontPeer (String name, int style)
329 {
330 try {
331 GtkFontPeer fp = new GtkFontPeer (name, style);
332 return fp;
333 } catch (MissingResourceException ex) {
334 return null;
335 }
336 }
337
338 protected EventQueue getSystemEventQueueImpl()
339 {
340 return q;
341 }
342
343 protected void loadSystemColors (int[] systemColors)
344 {
345 }
346
347 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e)
348 {
349 throw new Error("not implemented");
350 }
351
352 public Map mapInputMethodHighlight(InputMethodHighlight highlight)
353 {
354 throw new Error("not implemented");
355 }
356 } // class GtkToolkit
This page took 0.055119 seconds and 6 git commands to generate.