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)
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
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
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
;
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
.*;
51 import java
.util
.Hashtable
;
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
72 Hashtable containers
= new Hashtable();
73 static EventQueue q
= new EventQueue();
74 static Clipboard systemClipboard
;
78 if (Configuration
.INIT_LOAD_LIBRARY
)
79 System
.loadLibrary("gtkpeer");
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
,
116 return new GtkImage (new GdkPixbufDecoder (imagedata
,
122 public ColorModel
getColorModel ()
124 return ColorModel
.getRGBdefault ();
127 public String
[] getFontList ()
129 return (new String
[] { "Dialog",
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
)
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
)
173 throw new NullPointerException ();
175 GtkImage i
= (GtkImage
) image
;
177 if (i
.isLoaded ()) return true;
179 class PrepareImage
extends Thread
182 ImageObserver observer
;
184 PrepareImage (GtkImage image
, ImageObserver observer
)
187 image
.setObserver (observer
);
192 image
.source
.startProduction (image
);
196 new PrepareImage (i
, observer
).start ();
200 native public void sync ();
202 protected void setComponentState (Component c
, GtkComponentPeer cp
)
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 ());
212 /* Make the Peer reflect the state of the Component */
213 if (! (c
instanceof Window
))
215 cp
.setCursor (c
.getCursor ());
217 Rectangle bounds
= c
.getBounds ();
218 cp
.setBounds (bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
219 cp
.setVisible (c
.isVisible ());
223 protected ButtonPeer
createButton (Button b
)
225 return new GtkButtonPeer (b
);
228 protected CanvasPeer
createCanvas (Canvas c
)
230 return new GtkCanvasPeer (c
);
233 protected CheckboxPeer
createCheckbox (Checkbox cb
)
235 return new GtkCheckboxPeer (cb
);
238 protected CheckboxMenuItemPeer
createCheckboxMenuItem (CheckboxMenuItem cmi
)
240 return new GtkCheckboxMenuItemPeer (cmi
);
243 protected ChoicePeer
createChoice (Choice c
)
245 return new GtkChoicePeer (c
);
248 protected DialogPeer
createDialog (Dialog d
)
250 return new GtkDialogPeer (d
);
253 protected FileDialogPeer
createFileDialog (FileDialog fd
)
255 return new GtkFileDialogPeer (fd
);
258 protected FramePeer
createFrame (Frame f
)
260 return new GtkFramePeer (f
);
263 protected LabelPeer
createLabel (Label label
)
265 return new GtkLabelPeer (label
);
268 protected ListPeer
createList (List list
)
270 return new GtkListPeer (list
);
273 protected MenuPeer
createMenu (Menu m
)
275 return new GtkMenuPeer (m
);
278 protected MenuBarPeer
createMenuBar (MenuBar mb
)
280 return new GtkMenuBarPeer (mb
);
283 protected MenuItemPeer
createMenuItem (MenuItem mi
)
285 return new GtkMenuItemPeer (mi
);
288 protected PanelPeer
createPanel (Panel p
)
290 return new GtkPanelPeer (p
);
293 protected PopupMenuPeer
createPopupMenu (PopupMenu target
)
295 return new GtkPopupMenuPeer (target
);
298 protected ScrollPanePeer
createScrollPane (ScrollPane sp
)
300 return new GtkScrollPanePeer (sp
);
303 protected ScrollbarPeer
createScrollbar (Scrollbar sb
)
305 return new GtkScrollbarPeer (sb
);
308 protected TextAreaPeer
createTextArea (TextArea ta
)
310 return new GtkTextAreaPeer (ta
);
313 protected TextFieldPeer
createTextField (TextField tf
)
315 return new GtkTextFieldPeer (tf
);
318 protected WindowPeer
createWindow (Window w
)
320 return new GtkWindowPeer (w
);
323 public EmbeddedWindowPeer
createEmbeddedWindow (EmbeddedWindow w
)
325 return new GtkEmbeddedWindowPeer (w
);
328 protected FontPeer
getFontPeer (String name
, int style
)
331 GtkFontPeer fp
= new GtkFontPeer (name
, style
);
333 } catch (MissingResourceException ex
) {
338 protected EventQueue
getSystemEventQueueImpl()
343 protected void loadSystemColors (int[] systemColors
)
347 public DragSourceContextPeer
createDragSourceContextPeer(DragGestureEvent e
)
349 throw new Error("not implemented");
352 public Map
mapInputMethodHighlight(InputMethodHighlight highlight
)
354 throw new Error("not implemented");
356 } // class GtkToolkit