1 /* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
2 Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4 This file is part of the peer AWT libraries of GNU Classpath.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Library General Public License as published
8 by the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later verion.
11 This library 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
14 GNU Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; if not, write to the Free Software Foundation
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */
25 import java
.util
.Hashtable
;
26 import java
.util
.Properties
;
27 import java
.util
.MissingResourceException
;
28 import java
.awt
.datatransfer
.*;
29 import java
.awt
.image
.*;
30 import java
.awt
.peer
.*;
32 public class GtkToolkit
extends java
.awt
.Toolkit
34 static GtkMainThread gtkthread
;
35 static EventQueue evtqueue
;
36 static Hashtable containers
= new Hashtable();
37 static Clipboard systemClipboard
;
38 static GtkToolkit instance
= null;
44 //systemClipboard = new GtkClipboard ();
47 // Start the thread to run the GTK event loop. This is called from
48 // a GtkComponentPeer static initializer.
51 gtkthread
= new GtkMainThread ();
55 static native void gtkInit();
57 native public void beep ();
59 public int checkImage (Image image
, int width
, int height
,
60 ImageObserver observer
)
62 return ImageObserver
.ALLBITS
;
64 // GtkImage i = (GtkImage) image;
65 // return i.checkImage ();
68 public Image
createImage(String filename
)
73 public Image
createImage(URL url
)
78 public Image
createImage (ImageProducer producer
)
80 // return new GtkImage (producer, null);
84 public Image
createImage (byte[] imagedata
, int imageoffset
,
87 System
.out
.println ("createImage byte[] NOT SUPPORTED");
91 public ColorModel
getColorModel ()
93 return ColorModel
.getRGBdefault ();
96 public String
[] getFontList ()
98 return (new String
[] { "Dialog",
105 public FontMetrics
getFontMetrics (Font font
)
107 // return new GdkFontMetrics (font);
111 public Image
getImage (String filename
)
113 // return new GtkImage (new GdkPixbufDecoder (filename), null);
117 public Image
getImage (URL url
)
119 // return new GtkImage (new GdkPixbufDecoder (url), null);
124 public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)
129 native public int getScreenResolution();
131 native public Dimension
getScreenSize ();
133 public Clipboard
getSystemClipboard()
135 return systemClipboard
;
138 public boolean prepareImage (Image image
, int width
, int height
,
139 ImageObserver observer
)
144 native public void sync ();
146 protected void setComponentState (Component c
, GtkComponentPeer cp
)
148 /* Make the Peer reflect the state of the Component */
149 if (! (c
instanceof Window
))
151 cp
.setCursor (c
.getCursor ());
153 Rectangle bounds
= c
.getBounds ();
154 cp
.setBounds (bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
155 if (c
instanceof Canvas
)
156 System
.out
.println ("width " + bounds
.width
+ " height " + bounds
.height
);
158 cp
.setVisible (c
.isVisible ());
162 protected ButtonPeer
createButton (Button b
)
166 GtkButtonPeer bp = new GtkButtonPeer (b);
167 Rectangle bounds = b.getBounds ();
168 bp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
173 protected CanvasPeer
createCanvas (Canvas c
)
175 // return new GtkCanvasPeer (c);
179 protected CheckboxPeer
createCheckbox (Checkbox cb
)
183 if (cb.getCheckboxGroup () != null)
184 return new GtkRadioButtonPeer (cb);
186 return new GtkCheckButtonPeer (cb);
190 protected CheckboxMenuItemPeer
createCheckboxMenuItem (CheckboxMenuItem cmi
)
193 //return new GtkCheckboxMenuItemPeer (cmi);
196 protected ChoicePeer
createChoice (Choice c
)
199 //return new GtkChoicePeer (c);
202 protected DialogPeer
createDialog (Dialog d
)
205 //return new GtkDialogPeer (d);
208 protected FileDialogPeer
createFileDialog (FileDialog fd
)
211 //return new GtkFileDialogPeer (fd);
214 protected FramePeer
createFrame (Frame f
)
216 return new GtkFramePeer (f
);
219 protected LabelPeer
createLabel (Label label
)
222 //return new GtkLabelPeer (label);
225 protected ListPeer
createList (List list
)
228 //return new GtkListPeer (list);
231 protected MenuPeer
createMenu (Menu m
)
234 //return new GtkMenuPeer (m);
237 protected MenuBarPeer
createMenuBar (MenuBar mb
)
240 //return new GtkMenuBarPeer (mb);
243 protected MenuItemPeer
createMenuItem (MenuItem mi
)
246 //return new GtkMenuItemPeer (mi);
249 protected PanelPeer
createPanel (Panel p
)
252 //return new GtkPanelPeer (p);
255 protected PopupMenuPeer
createPopupMenu (PopupMenu target
)
258 //return new GtkPopupMenuPeer (target);
261 protected ScrollPanePeer
createScrollPane (ScrollPane sp
)
264 //return new GtkScrollPanePeer (sp);
267 protected ScrollbarPeer
createScrollbar (Scrollbar sb
)
270 //return new GtkScrollbarPeer (sb);
273 protected TextAreaPeer
createTextArea (TextArea ta
)
276 //return new GtkTextAreaPeer (ta);
279 protected TextFieldPeer
createTextField (TextField tf
)
282 //return new GtkTextFieldPeer (tf);
285 protected WindowPeer
createWindow (Window w
)
287 return new GtkWindowPeer (w
);
290 protected FontPeer
getFontPeer (String name
, int style
)
296 GtkFontPeer fp = new GtkFontPeer (name, style);
299 catch (MissingResourceException ex)
306 protected EventQueue
getSystemEventQueueImpl()
308 return GtkComponentPeer
.eventQueue
;
311 protected void loadSystemColors (int[] systemColors
)