2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GtkToolkit.java
blob0a09f1f1970a69a3b898eaa6d7dbb75bf10bbf98
1 /* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
2 Copyright (C) 1998, 1999, 2002, 2003 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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.*;
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;
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. */
68 public class GtkToolkit extends Toolkit
69 implements EmbeddedWindowSupport
71 GtkMainThread main;
72 Hashtable containers = new Hashtable();
73 static EventQueue q = new EventQueue();
74 static Clipboard systemClipboard;
76 static
78 if (Configuration.INIT_LOAD_LIBRARY)
79 System.loadLibrary("gtkpeer");
82 public GtkToolkit ()
84 main = new GtkMainThread ();
85 systemClipboard = new GtkClipboard ();
86 GtkGenericPeer.enableQueue (q);
89 native public void beep ();
90 native private void getScreenSizeDimensions (int[] xy);
92 public int checkImage (Image image, int width, int height,
93 ImageObserver observer)
95 return ((GtkImage) image).checkImage ();
98 public Image createImage (String filename)
100 return new GtkImage (new GdkPixbufDecoder (filename), null);
103 public Image createImage (URL url)
105 return new GtkImage (new GdkPixbufDecoder (url), null);
108 public Image createImage (ImageProducer producer)
110 return new GtkImage (producer, null);
113 public Image createImage (byte[] imagedata, int imageoffset,
114 int imagelength)
116 return new GtkImage (new GdkPixbufDecoder (imagedata,
117 imageoffset,
118 imagelength),
119 null);
122 public ColorModel getColorModel ()
124 return ColorModel.getRGBdefault ();
127 public String[] getFontList ()
129 return (new String[] { "Dialog",
130 "DialogInput",
131 "Monospaced",
132 "Serif",
133 "SansSerif" });
136 public FontMetrics getFontMetrics (Font font)
138 return new GdkFontMetrics (font);
141 public Image getImage (String filename)
143 return new GtkImage (new GdkPixbufDecoder (filename), null);
146 public Image getImage (URL url)
148 return new GtkImage (new GdkPixbufDecoder (url), null);
151 public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)
153 return null;
156 native public int getScreenResolution();
158 public Dimension getScreenSize () {
159 int dim[] = new int[2];
160 getScreenSizeDimensions(dim);
161 return new Dimension(dim[0], dim[1]);
164 public Clipboard getSystemClipboard()
166 return systemClipboard;
169 public boolean prepareImage (Image image, int width, int height,
170 ImageObserver observer)
172 GtkImage i = (GtkImage) image;
174 if (i.isLoaded ()) return true;
176 class PrepareImage extends Thread
178 GtkImage image;
179 ImageObserver observer;
181 PrepareImage (GtkImage image, ImageObserver observer)
183 this.image = image;
184 image.setObserver (observer);
187 public void run ()
189 image.source.startProduction (image);
193 new PrepareImage (i, observer).start ();
194 return false;
197 native public void sync ();
199 protected void setComponentState (Component c, GtkComponentPeer cp)
201 /* Make the Component reflect Peer defaults */
202 if (c.getForeground () == null)
203 c.setForeground (cp.getForeground ());
204 if (c.getBackground () == null)
205 c.setBackground (cp.getBackground ());
206 // if (c.getFont () == null)
207 // c.setFont (cp.getFont ());
209 /* Make the Peer reflect the state of the Component */
210 if (! (c instanceof Window))
212 cp.setCursor (c.getCursor ());
214 Rectangle bounds = c.getBounds ();
215 cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
216 cp.setVisible (c.isVisible ());
220 protected ButtonPeer createButton (Button b)
222 return new GtkButtonPeer (b);
225 protected CanvasPeer createCanvas (Canvas c)
227 return new GtkCanvasPeer (c);
230 protected CheckboxPeer createCheckbox (Checkbox cb)
232 return new GtkCheckboxPeer (cb);
235 protected CheckboxMenuItemPeer createCheckboxMenuItem (CheckboxMenuItem cmi)
237 return new GtkCheckboxMenuItemPeer (cmi);
240 protected ChoicePeer createChoice (Choice c)
242 return new GtkChoicePeer (c);
245 protected DialogPeer createDialog (Dialog d)
247 return new GtkDialogPeer (d);
250 protected FileDialogPeer createFileDialog (FileDialog fd)
252 return new GtkFileDialogPeer (fd);
255 protected FramePeer createFrame (Frame f)
257 return new GtkFramePeer (f);
260 protected LabelPeer createLabel (Label label)
262 return new GtkLabelPeer (label);
265 protected ListPeer createList (List list)
267 return new GtkListPeer (list);
270 protected MenuPeer createMenu (Menu m)
272 return new GtkMenuPeer (m);
275 protected MenuBarPeer createMenuBar (MenuBar mb)
277 return new GtkMenuBarPeer (mb);
280 protected MenuItemPeer createMenuItem (MenuItem mi)
282 return new GtkMenuItemPeer (mi);
285 protected PanelPeer createPanel (Panel p)
287 return new GtkPanelPeer (p);
290 protected PopupMenuPeer createPopupMenu (PopupMenu target)
292 return new GtkPopupMenuPeer (target);
295 protected ScrollPanePeer createScrollPane (ScrollPane sp)
297 return new GtkScrollPanePeer (sp);
300 protected ScrollbarPeer createScrollbar (Scrollbar sb)
302 return new GtkScrollbarPeer (sb);
305 protected TextAreaPeer createTextArea (TextArea ta)
307 return new GtkTextAreaPeer (ta);
310 protected TextFieldPeer createTextField (TextField tf)
312 return new GtkTextFieldPeer (tf);
315 protected WindowPeer createWindow (Window w)
317 return new GtkWindowPeer (w);
320 public EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w)
322 return new GtkEmbeddedWindowPeer (w);
325 protected FontPeer getFontPeer (String name, int style)
327 try {
328 GtkFontPeer fp = new GtkFontPeer (name, style);
329 return fp;
330 } catch (MissingResourceException ex) {
331 return null;
335 protected EventQueue getSystemEventQueueImpl()
337 return q;
340 protected void loadSystemColors (int[] systemColors)
344 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e)
346 throw new Error("not implemented");
349 public Map mapInputMethodHighlight(InputMethodHighlight highlight)
351 throw new Error("not implemented");
353 } // class GtkToolkit