2 Copyright (C) 2005, 2006 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., 51 Franklin Street, Fifth Floor, 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. */
38 package gnu.java.awt.peer.qt;
40 import gnu.java.awt.EmbeddedWindow;
41 import gnu.java.awt.peer.ClasspathFontPeer;
42 import gnu.java.awt.peer.EmbeddedWindowPeer;
44 import java.awt.AWTException;
45 import java.awt.Button;
46 import java.awt.Canvas;
47 import java.awt.Checkbox;
48 import java.awt.CheckboxMenuItem;
49 import java.awt.Choice;
50 import java.awt.Dialog;
51 import java.awt.Dimension;
52 import java.awt.EventQueue;
54 import java.awt.FontMetrics;
55 import java.awt.Frame;
56 import java.awt.Image;
57 import java.awt.Label;
59 import java.awt.MenuBar;
61 import java.awt.MenuItem;
62 import java.awt.Panel;
63 import java.awt.TextArea;
64 import java.awt.TextField;
65 import java.awt.FileDialog;
66 import java.awt.GraphicsDevice;
67 import java.awt.GraphicsEnvironment;
68 import java.awt.PopupMenu;
69 import java.awt.PrintJob;
70 import java.awt.Scrollbar;
71 import java.awt.ScrollPane;
72 import java.awt.Window;
73 import java.awt.datatransfer.Clipboard;
74 import java.awt.dnd.DragGestureEvent;
75 import java.awt.dnd.peer.DragSourceContextPeer;
76 import java.awt.event.AWTEventListener;
77 import java.awt.image.ColorModel;
78 import java.awt.image.DirectColorModel;
79 import java.awt.image.ImageObserver;
80 import java.awt.image.ImageProducer;
81 import java.awt.im.InputMethodHighlight;
82 import java.awt.peer.ButtonPeer;
83 import java.awt.peer.FontPeer;
84 import java.awt.peer.PanelPeer;
85 import java.awt.peer.CanvasPeer;
86 import java.awt.peer.FramePeer;
87 import java.awt.peer.PopupMenuPeer;
88 import java.awt.peer.CheckboxMenuItemPeer;
89 import java.awt.peer.LabelPeer;
90 import java.awt.peer.RobotPeer;
91 import java.awt.peer.CheckboxPeer;
92 import java.awt.peer.ScrollPanePeer;
93 import java.awt.peer.ChoicePeer;
94 import java.awt.peer.ListPeer;
95 import java.awt.peer.ScrollbarPeer;
96 import java.awt.peer.MenuBarPeer;
97 import java.awt.peer.TextAreaPeer;
98 import java.awt.peer.DialogPeer;
99 import java.awt.peer.MenuItemPeer;
100 import java.awt.peer.TextFieldPeer;
101 import java.awt.peer.FileDialogPeer;
102 import java.awt.peer.MenuPeer;
103 import java.awt.peer.WindowPeer;
104 import java.io.InputStream;
106 import java.util.HashMap;
107 import java.util.Map;
108 import java.util.Properties;
110 import gnu.java.awt.ClasspathToolkit;
112 public class QtToolkit extends ClasspathToolkit
114 public static EventQueue eventQueue = null; // the native event queue
115 public static QtRepaintThread repaintThread = null;
116 public static MainQtThread guiThread = null;
117 public static QtGraphicsEnvironment graphicsEnv = null;
119 private static void initToolkit()
121 eventQueue = new EventQueue();
122 repaintThread = new QtRepaintThread();
123 System.loadLibrary("qtpeer");
128 String style = System.getProperty("qtoptions.style");
132 catch(SecurityException e)
135 catch(IllegalArgumentException e)
139 boolean doublebuffer = true;
142 String style = System.getProperty("qtoptions.nodoublebuffer");
144 doublebuffer = false;
146 catch(SecurityException e)
149 catch(IllegalArgumentException e)
153 guiThread = new MainQtThread( theme, doublebuffer );
155 repaintThread.start();
159 * Construct the toolkit!
163 if( guiThread == null )
166 while (!guiThread.isRunning()); // make sure the GUI thread has started.
168 if( graphicsEnv == null )
169 graphicsEnv = new QtGraphicsEnvironment( this );
172 native String[] nativeFontFamilies();
174 native int numScreens();
176 native int defaultScreen();
178 // ************ Public methods *********************
180 public synchronized native void beep();
182 public int checkImage(Image image, int w, int h, ImageObserver observer)
184 if(image instanceof QtImage)
185 return ((QtImage)image).checkImage(observer);
187 return ImageObserver.ERROR; // FIXME
190 protected ButtonPeer createButton( Button target )
192 return new QtButtonPeer( this, target );
195 protected CanvasPeer createCanvas(Canvas target)
197 return new QtCanvasPeer( this, target );
200 protected CheckboxPeer createCheckbox(Checkbox target)
202 return new QtCheckboxPeer( this, target );
205 protected ChoicePeer createChoice(Choice target)
207 return new QtChoicePeer( this, target );
210 protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)
212 return new QtMenuItemPeer( this, target );
215 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
217 throw new RuntimeException("Not implemented");
220 protected FramePeer createFrame(Frame target)
222 return new QtFramePeer( this, target );
225 protected FileDialogPeer createFileDialog(FileDialog target)
227 return new QtFileDialogPeer( this, target );
230 public Image createImage(ImageProducer producer)
232 return new QtImage( producer );
235 public Image createImage(byte[] imageData,
239 byte[] dataCopy = new byte[imageLength];
240 System.arraycopy(imageData, imageOffset, dataCopy, 0, imageLength);
241 return new QtImage( dataCopy );
244 public Image createImage(String filename)
246 return new QtImage( filename );
249 public Image createImage(URL url)
251 return new QtImage( url );
254 protected TextFieldPeer createTextField(TextField target)
256 return new QtTextFieldPeer(this,target);
259 protected LabelPeer createLabel(Label target)
261 return new QtLabelPeer( this, target );
264 protected ListPeer createList(List target)
266 return new QtListPeer( this, target );
269 protected ScrollbarPeer createScrollbar(Scrollbar target)
271 return new QtScrollbarPeer( this, target );
274 protected ScrollPanePeer createScrollPane(ScrollPane target)
276 return new QtScrollPanePeer( this, target );
279 protected TextAreaPeer createTextArea(TextArea target)
281 return new QtTextAreaPeer( this, target );
284 protected PanelPeer createPanel(Panel target)
286 return new QtPanelPeer( this, target);
289 protected WindowPeer createWindow(Window target)
291 return new QtWindowPeer( this, target );
294 protected DialogPeer createDialog(Dialog target)
296 return new QtDialogPeer( this, target );
299 protected MenuBarPeer createMenuBar(MenuBar target)
301 return new QtMenuBarPeer( this, target );
304 protected MenuPeer createMenu(Menu target)
306 return new QtMenuPeer( this, target );
309 protected PopupMenuPeer createPopupMenu(PopupMenu target)
311 return new QtPopupMenuPeer( this, target );
314 protected MenuItemPeer createMenuItem(MenuItem target)
316 return new QtMenuItemPeer( this, target );
322 public AWTEventListener[] getAWTEventListeners()
324 return null; // FIXME
330 public AWTEventListener[] getAWTEventListeners(long mask)
332 return null; // FIXME
335 public ColorModel getColorModel()
337 return new DirectColorModel(32,
345 * Just return the defaults.
347 public String[] getFontList()
349 String[] builtIn = new String[] { "Dialog",
354 String[] nat = nativeFontFamilies();
355 String[] allFonts = new String[ nat.length + 5 ];
356 System.arraycopy(builtIn, 0, allFonts, 0, 5);
357 System.arraycopy(nat, 0, allFonts, 5, nat.length);
361 public FontMetrics getFontMetrics(Font font)
363 return new QtFontMetrics(font);
366 protected FontPeer getFontPeer(String name,
369 Map attrs = new HashMap ();
370 ClasspathFontPeer.copyStyleToAttrs(style, attrs);
371 ClasspathFontPeer.copySizeToAttrs(12, attrs); // Default size is 12.
372 return getClasspathFontPeer (name, attrs);
375 public Image getImage(String filename)
377 return new QtImage(filename);
380 public Image getImage(URL url)
382 return createImage( url );
385 public PrintJob getPrintJob(Frame frame,
390 sm = System.getSecurityManager();
392 sm.checkPrintJobAccess();
394 throw new RuntimeException("Not implemented");
397 public Clipboard getSystemClipboard()
399 throw new RuntimeException("Not implemented");
402 protected EventQueue getSystemEventQueueImpl()
407 public native Dimension getScreenSize();
409 public native int getScreenResolution();
411 public Map mapInputMethodHighlight(InputMethodHighlight highlight)
413 return null; // FIXME
416 public boolean prepareImage(Image image, int w, int h, ImageObserver observer)
418 if(image instanceof QtImage)
420 return false; // FIXME?
423 public native void sync();
425 // ********************** ClasspathToolkit methods
427 public GraphicsEnvironment getLocalGraphicsEnvironment()
432 public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
434 return new QtFontPeer (name, attrs);
438 public Font createFont(int format, InputStream stream)
440 throw new UnsupportedOperationException();
444 public RobotPeer createRobot (GraphicsDevice screen) throws AWTException
446 throw new UnsupportedOperationException();
449 public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w)
451 // return new QtEmbeddedWindowPeer( this, w );