Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / java / awt / peer / qt / QtToolkit.java
blob591b528035dad08d9c9ab3ad9076596778801c58
1 /* QtToolkit.java --
2 Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 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. */
38 package gnu.java.awt.peer.qt;
40 import gnu.classpath.Configuration;
41 import gnu.java.awt.EmbeddedWindow;
42 import gnu.java.awt.peer.ClasspathFontPeer;
43 import gnu.java.awt.peer.EmbeddedWindowPeer;
44 import gnu.java.awt.peer.ClasspathTextLayoutPeer;
45 import java.awt.AWTEvent;
46 import java.awt.AWTException;
47 import java.awt.Button;
48 import java.awt.Canvas;
49 import java.awt.Checkbox;
50 import java.awt.CheckboxMenuItem;
51 import java.awt.Choice;
52 import java.awt.Component;
53 import java.awt.Dialog;
54 import java.awt.Dimension;
55 import java.awt.EventQueue;
56 import java.awt.Font;
57 import java.awt.FontMetrics;
58 import java.awt.Frame;
59 import java.awt.Image;
60 import java.awt.Label;
61 import java.awt.List;
62 import java.awt.MenuBar;
63 import java.awt.Menu;
64 import java.awt.MenuItem;
65 import java.awt.Panel;
66 import java.awt.TextArea;
67 import java.awt.TextField;
68 import java.awt.FileDialog;
69 import java.awt.GraphicsDevice;
70 import java.awt.GraphicsEnvironment;
71 import java.awt.HeadlessException;
72 import java.awt.PopupMenu;
73 import java.awt.PrintJob;
74 import java.awt.Scrollbar;
75 import java.awt.ScrollPane;
76 import java.awt.Toolkit;
77 import java.awt.Window;
78 import java.awt.datatransfer.Clipboard;
79 import java.awt.dnd.DragGestureEvent;
80 import java.awt.dnd.DragGestureListener;
81 import java.awt.dnd.DragGestureRecognizer;
82 import java.awt.dnd.DragSource;
83 import java.awt.dnd.peer.DragSourceContextPeer;
84 import java.awt.event.AWTEventListener;
85 import java.awt.image.ColorModel;
86 import java.awt.image.DirectColorModel;
87 import java.awt.image.ImageObserver;
88 import java.awt.image.ImageProducer;
89 import java.awt.im.InputMethodHighlight;
90 import java.awt.peer.ButtonPeer;
91 import java.awt.peer.FontPeer;
92 import java.awt.peer.PanelPeer;
93 import java.awt.peer.CanvasPeer;
94 import java.awt.peer.FramePeer;
95 import java.awt.peer.PopupMenuPeer;
96 import java.awt.peer.CheckboxMenuItemPeer;
97 import java.awt.peer.LabelPeer;
98 import java.awt.peer.RobotPeer;
99 import java.awt.peer.CheckboxPeer;
100 import java.awt.peer.LightweightPeer;
101 import java.awt.peer.ScrollPanePeer;
102 import java.awt.peer.ChoicePeer;
103 import java.awt.peer.ListPeer;
104 import java.awt.peer.ScrollbarPeer;
105 import java.awt.peer.ComponentPeer;
106 import java.awt.peer.MenuBarPeer;
107 import java.awt.peer.TextAreaPeer;
108 import java.awt.peer.ContainerPeer;
109 import java.awt.peer.MenuComponentPeer;
110 import java.awt.peer.TextComponentPeer;
111 import java.awt.peer.DialogPeer;
112 import java.awt.peer.MenuItemPeer;
113 import java.awt.peer.TextFieldPeer;
114 import java.awt.peer.FileDialogPeer;
115 import java.awt.peer.MenuPeer;
116 import java.awt.peer.WindowPeer;
117 import java.awt.font.FontRenderContext;
118 import java.io.InputStream;
119 import java.net.URL;
120 import java.text.AttributedString;
121 import java.util.HashMap;
122 import java.util.Map;
123 import java.util.Properties;
124 import javax.imageio.spi.IIORegistry;
126 import gnu.java.awt.ClasspathToolkit;
128 public class QtToolkit extends ClasspathToolkit
130 public static EventQueue eventQueue = null; // the native event queue
131 public static QtRepaintThread repaintThread = null;
132 public static MainQtThread guiThread = null;
133 public static QtGraphicsEnvironment graphicsEnv = null;
135 private static void initToolkit()
137 eventQueue = new EventQueue();
138 repaintThread = new QtRepaintThread();
139 if (Configuration.INIT_LOAD_LIBRARY)
140 System.loadLibrary("qtpeer");
142 String theme = null;
143 try
145 String style = System.getProperty("qtoptions.style");
146 if(style != null)
147 theme = style;
149 catch(SecurityException e)
152 catch(IllegalArgumentException e)
156 boolean doublebuffer = true;
157 try
159 String style = System.getProperty("qtoptions.nodoublebuffer");
160 if(style != null)
161 doublebuffer = false;
163 catch(SecurityException e)
166 catch(IllegalArgumentException e)
170 guiThread = new MainQtThread( theme, doublebuffer );
171 guiThread.start();
172 repaintThread.start();
176 * Construct the toolkit!
178 public QtToolkit()
180 if( guiThread == null )
181 initToolkit();
183 while (!guiThread.isRunning()); // make sure the GUI thread has started.
185 if( graphicsEnv == null )
186 graphicsEnv = new QtGraphicsEnvironment( this );
189 native String[] nativeFontFamilies();
191 native int numScreens();
193 native int defaultScreen();
195 // ************ Public methods *********************
197 public synchronized native void beep();
199 public int checkImage(Image image, int w, int h, ImageObserver observer)
201 if(image instanceof QtImage)
202 return ((QtImage)image).checkImage(observer);
204 return ImageObserver.ERROR; // FIXME
207 protected ButtonPeer createButton( Button target )
209 return new QtButtonPeer( this, target );
212 protected CanvasPeer createCanvas(Canvas target)
214 return new QtCanvasPeer( this, target );
217 protected CheckboxPeer createCheckbox(Checkbox target)
219 return new QtCheckboxPeer( this, target );
222 protected ChoicePeer createChoice(Choice target)
224 return new QtChoicePeer( this, target );
227 protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)
229 return new QtMenuItemPeer( this, target );
232 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
234 throw new RuntimeException("Not implemented");
237 protected FramePeer createFrame(Frame target)
239 return new QtFramePeer( this, target );
242 protected FileDialogPeer createFileDialog(FileDialog target)
244 return new QtFileDialogPeer( this, target );
247 public Image createImage(ImageProducer producer)
249 return new QtImage( producer );
252 public Image createImage(byte[] imageData,
253 int imageOffset,
254 int imageLength)
256 byte[] dataCopy = new byte[imageLength];
257 System.arraycopy(imageData, imageOffset, dataCopy, 0, imageLength);
258 return new QtImage( dataCopy );
261 public Image createImage(String filename)
263 return new QtImage( filename );
266 public Image createImage(URL url)
268 return new QtImage( url );
271 protected TextFieldPeer createTextField(TextField target)
273 return new QtTextFieldPeer(this,target);
276 protected LabelPeer createLabel(Label target)
278 return new QtLabelPeer( this, target );
281 protected ListPeer createList(List target)
283 return new QtListPeer( this, target );
286 protected ScrollbarPeer createScrollbar(Scrollbar target)
288 return new QtScrollbarPeer( this, target );
291 protected ScrollPanePeer createScrollPane(ScrollPane target)
293 return new QtScrollPanePeer( this, target );
296 protected TextAreaPeer createTextArea(TextArea target)
298 return new QtTextAreaPeer( this, target );
301 protected PanelPeer createPanel(Panel target)
303 return new QtPanelPeer( this, target);
306 protected WindowPeer createWindow(Window target)
308 return new QtWindowPeer( this, target );
311 protected DialogPeer createDialog(Dialog target)
313 return new QtDialogPeer( this, target );
316 protected MenuBarPeer createMenuBar(MenuBar target)
318 return new QtMenuBarPeer( this, target );
321 protected MenuPeer createMenu(Menu target)
323 return new QtMenuPeer( this, target );
326 protected PopupMenuPeer createPopupMenu(PopupMenu target)
328 return new QtPopupMenuPeer( this, target );
331 protected MenuItemPeer createMenuItem(MenuItem target)
333 return new QtMenuItemPeer( this, target );
337 * @since 1.4
339 public AWTEventListener[] getAWTEventListeners()
341 return null; // FIXME
345 * @since 1.4
347 public AWTEventListener[] getAWTEventListeners(long mask)
349 return null; // FIXME
352 public ColorModel getColorModel()
354 return new DirectColorModel(32,
355 0x00FF0000,
356 0x0000FF00,
357 0x000000FF,
358 0xFF000000);
362 * Just return the defaults.
364 public String[] getFontList()
366 String[] builtIn = new String[] { "Dialog",
367 "DialogInput",
368 "Monospaced",
369 "Serif",
370 "SansSerif" };
371 String[] nat = nativeFontFamilies();
372 String[] allFonts = new String[ nat.length + 5 ];
373 System.arraycopy(builtIn, 0, allFonts, 0, 5);
374 System.arraycopy(nat, 0, allFonts, 5, nat.length);
375 return allFonts;
378 public FontMetrics getFontMetrics(Font font)
380 return new QtFontMetrics(font);
383 protected FontPeer getFontPeer(String name,
384 int style)
386 Map attrs = new HashMap ();
387 ClasspathFontPeer.copyStyleToAttrs(style, attrs);
388 ClasspathFontPeer.copySizeToAttrs(12, attrs); // Default size is 12.
389 return getClasspathFontPeer (name, attrs);
392 public Image getImage(String filename)
394 return new QtImage(filename);
397 public Image getImage(URL url)
399 return createImage( url );
402 public PrintJob getPrintJob(Frame frame,
403 String jobtitle,
404 Properties props)
406 throw new RuntimeException("Not implemented");
409 public Clipboard getSystemClipboard()
411 throw new RuntimeException("Not implemented");
414 protected EventQueue getSystemEventQueueImpl()
416 return eventQueue;
419 public native Dimension getScreenSize();
421 public native int getScreenResolution();
423 public Map mapInputMethodHighlight(InputMethodHighlight highlight)
425 return null; // FIXME
428 public boolean prepareImage(Image image, int w, int h, ImageObserver observer)
430 if(image instanceof QtImage)
431 return true;
432 return false; // FIXME?
435 public native void sync();
437 // ********************** ClasspathToolkit methods
439 public GraphicsEnvironment getLocalGraphicsEnvironment()
441 return graphicsEnv;
444 public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
446 return new QtFontPeer (name, attrs);
449 public ClasspathTextLayoutPeer getClasspathTextLayoutPeer(AttributedString str,
450 FontRenderContext frc)
452 return null;
455 // FIXME
456 public Font createFont(int format, InputStream stream)
458 throw new UnsupportedOperationException();
461 // FIXME
462 public RobotPeer createRobot (GraphicsDevice screen) throws AWTException
464 throw new UnsupportedOperationException();
467 public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w)
469 // return new QtEmbeddedWindowPeer( this, w );
470 return null;