Merged with mainline at revision 128810.
[official-gcc.git] / libjava / classpath / gnu / java / awt / peer / qt / QtToolkit.java
blob4cea976ac22512c3fea6e7360c98395766cde11e
1 /* QtToolkit.java --
2 Copyright (C) 2005, 2006, 2007 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.java.awt.ClasspathToolkit;
41 import gnu.java.awt.EmbeddedWindow;
42 import gnu.java.awt.peer.ClasspathFontPeer;
43 import gnu.java.awt.peer.EmbeddedWindowPeer;
45 import java.awt.AWTException;
46 import java.awt.Button;
47 import java.awt.Canvas;
48 import java.awt.Checkbox;
49 import java.awt.CheckboxMenuItem;
50 import java.awt.Choice;
51 import java.awt.Dialog;
52 import java.awt.Dimension;
53 import java.awt.EventQueue;
54 import java.awt.FileDialog;
55 import java.awt.Font;
56 import java.awt.FontMetrics;
57 import java.awt.Frame;
58 import java.awt.GraphicsDevice;
59 import java.awt.GraphicsEnvironment;
60 import java.awt.Image;
61 import java.awt.Label;
62 import java.awt.List;
63 import java.awt.Menu;
64 import java.awt.MenuBar;
65 import java.awt.MenuItem;
66 import java.awt.Panel;
67 import java.awt.PopupMenu;
68 import java.awt.PrintJob;
69 import java.awt.ScrollPane;
70 import java.awt.Scrollbar;
71 import java.awt.TextArea;
72 import java.awt.TextField;
73 import java.awt.Window;
74 import java.awt.datatransfer.Clipboard;
75 import java.awt.dnd.DragGestureEvent;
76 import java.awt.dnd.peer.DragSourceContextPeer;
77 import java.awt.event.AWTEventListener;
78 import java.awt.im.InputMethodHighlight;
79 import java.awt.image.ColorModel;
80 import java.awt.image.DirectColorModel;
81 import java.awt.image.ImageObserver;
82 import java.awt.image.ImageProducer;
83 import java.awt.peer.ButtonPeer;
84 import java.awt.peer.CanvasPeer;
85 import java.awt.peer.CheckboxMenuItemPeer;
86 import java.awt.peer.CheckboxPeer;
87 import java.awt.peer.ChoicePeer;
88 import java.awt.peer.DialogPeer;
89 import java.awt.peer.FileDialogPeer;
90 import java.awt.peer.FontPeer;
91 import java.awt.peer.FramePeer;
92 import java.awt.peer.LabelPeer;
93 import java.awt.peer.ListPeer;
94 import java.awt.peer.MenuBarPeer;
95 import java.awt.peer.MenuItemPeer;
96 import java.awt.peer.MenuPeer;
97 import java.awt.peer.PanelPeer;
98 import java.awt.peer.PopupMenuPeer;
99 import java.awt.peer.RobotPeer;
100 import java.awt.peer.ScrollPanePeer;
101 import java.awt.peer.ScrollbarPeer;
102 import java.awt.peer.TextAreaPeer;
103 import java.awt.peer.TextFieldPeer;
104 import java.awt.peer.WindowPeer;
105 import java.io.InputStream;
106 import java.net.URL;
107 import java.util.HashMap;
108 import java.util.Map;
109 import java.util.Properties;
111 public class QtToolkit extends ClasspathToolkit
113 public static EventQueue eventQueue = null; // the native event queue
114 public static QtRepaintThread repaintThread = null;
115 public static MainQtThread guiThread = null;
116 public static QtGraphicsEnvironment graphicsEnv = null;
118 private static void initToolkit()
120 eventQueue = new EventQueue();
121 repaintThread = new QtRepaintThread();
122 System.loadLibrary("qtpeer");
124 String theme = null;
125 try
127 String style = System.getProperty("qtoptions.style");
128 if(style != null)
129 theme = style;
131 catch(SecurityException e)
134 catch(IllegalArgumentException e)
138 boolean doublebuffer = true;
139 try
141 String style = System.getProperty("qtoptions.nodoublebuffer");
142 if(style != null)
143 doublebuffer = false;
145 catch(SecurityException e)
148 catch(IllegalArgumentException e)
152 guiThread = new MainQtThread( theme, doublebuffer );
153 guiThread.start();
154 repaintThread.start();
158 * Construct the toolkit!
160 public QtToolkit()
162 if( guiThread == null )
163 initToolkit();
165 // make sure the GUI thread has started.
166 while (!guiThread.isRunning())
169 if( graphicsEnv == null )
170 graphicsEnv = new QtGraphicsEnvironment( this );
173 native String[] nativeFontFamilies();
175 native int numScreens();
177 native int defaultScreen();
179 // ************ Public methods *********************
181 public synchronized native void beep();
183 public int checkImage(Image image, int w, int h, ImageObserver observer)
185 if(image instanceof QtImage)
186 return ((QtImage)image).checkImage(observer);
188 return ImageObserver.ERROR; // FIXME
191 protected ButtonPeer createButton( Button target )
193 return new QtButtonPeer( this, target );
196 protected CanvasPeer createCanvas(Canvas target)
198 return new QtCanvasPeer( this, target );
201 protected CheckboxPeer createCheckbox(Checkbox target)
203 return new QtCheckboxPeer( this, target );
206 protected ChoicePeer createChoice(Choice target)
208 return new QtChoicePeer( this, target );
211 protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)
213 return new QtMenuItemPeer( this, target );
216 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
218 throw new RuntimeException("Not implemented");
221 protected FramePeer createFrame(Frame target)
223 return new QtFramePeer( this, target );
226 protected FileDialogPeer createFileDialog(FileDialog target)
228 return new QtFileDialogPeer( this, target );
231 public Image createImage(ImageProducer producer)
233 return new QtImage( producer );
236 public Image createImage(byte[] imageData,
237 int imageOffset,
238 int imageLength)
240 byte[] dataCopy = new byte[imageLength];
241 System.arraycopy(imageData, imageOffset, dataCopy, 0, imageLength);
242 return new QtImage( dataCopy );
245 public Image createImage(String filename)
247 return new QtImage( filename );
250 public Image createImage(URL url)
252 return new QtImage( url );
255 protected TextFieldPeer createTextField(TextField target)
257 return new QtTextFieldPeer(this,target);
260 protected LabelPeer createLabel(Label target)
262 return new QtLabelPeer( this, target );
265 protected ListPeer createList(List target)
267 return new QtListPeer( this, target );
270 protected ScrollbarPeer createScrollbar(Scrollbar target)
272 return new QtScrollbarPeer( this, target );
275 protected ScrollPanePeer createScrollPane(ScrollPane target)
277 return new QtScrollPanePeer( this, target );
280 protected TextAreaPeer createTextArea(TextArea target)
282 return new QtTextAreaPeer( this, target );
285 protected PanelPeer createPanel(Panel target)
287 return new QtPanelPeer( this, target);
290 protected WindowPeer createWindow(Window target)
292 return new QtWindowPeer( this, target );
295 protected DialogPeer createDialog(Dialog target)
297 return new QtDialogPeer( this, target );
300 protected MenuBarPeer createMenuBar(MenuBar target)
302 return new QtMenuBarPeer( this, target );
305 protected MenuPeer createMenu(Menu target)
307 return new QtMenuPeer( this, target );
310 protected PopupMenuPeer createPopupMenu(PopupMenu target)
312 return new QtPopupMenuPeer( this, target );
315 protected MenuItemPeer createMenuItem(MenuItem target)
317 return new QtMenuItemPeer( this, target );
321 * @since 1.4
323 public AWTEventListener[] getAWTEventListeners()
325 return null; // FIXME
329 * @since 1.4
331 public AWTEventListener[] getAWTEventListeners(long mask)
333 return null; // FIXME
336 public ColorModel getColorModel()
338 return new DirectColorModel(32,
339 0x00FF0000,
340 0x0000FF00,
341 0x000000FF,
342 0xFF000000);
346 * Just return the defaults.
348 public String[] getFontList()
350 String[] builtIn = new String[] { "Dialog",
351 "DialogInput",
352 "Monospaced",
353 "Serif",
354 "SansSerif" };
355 String[] nat = nativeFontFamilies();
356 String[] allFonts = new String[ nat.length + 5 ];
357 System.arraycopy(builtIn, 0, allFonts, 0, 5);
358 System.arraycopy(nat, 0, allFonts, 5, nat.length);
359 return allFonts;
362 public FontMetrics getFontMetrics(Font font)
364 return new QtFontMetrics(font);
367 protected FontPeer getFontPeer(String name,
368 int style)
370 Map attrs = new HashMap ();
371 ClasspathFontPeer.copyStyleToAttrs(style, attrs);
372 ClasspathFontPeer.copySizeToAttrs(12, attrs); // Default size is 12.
373 return getClasspathFontPeer (name, attrs);
376 public Image getImage(String filename)
378 return new QtImage(filename);
381 public Image getImage(URL url)
383 return createImage( url );
386 public PrintJob getPrintJob(Frame frame,
387 String jobtitle,
388 Properties props)
390 SecurityManager sm;
391 sm = System.getSecurityManager();
392 if (sm != null)
393 sm.checkPrintJobAccess();
395 throw new RuntimeException("Not implemented");
398 public Clipboard getSystemClipboard()
400 throw new RuntimeException("Not implemented");
403 protected EventQueue getSystemEventQueueImpl()
405 return eventQueue;
408 public native Dimension getScreenSize();
410 public native int getScreenResolution();
412 public Map mapInputMethodHighlight(InputMethodHighlight highlight)
414 return null; // FIXME
417 public boolean prepareImage(Image image, int w, int h, ImageObserver observer)
419 if(image instanceof QtImage)
420 return true;
421 return false; // FIXME?
424 public native void sync();
426 // ********************** ClasspathToolkit methods
428 public GraphicsEnvironment getLocalGraphicsEnvironment()
430 return graphicsEnv;
433 public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
435 return new QtFontPeer (name, attrs);
438 // FIXME
439 public Font createFont(int format, InputStream stream)
441 throw new UnsupportedOperationException();
444 // FIXME
445 public RobotPeer createRobot (GraphicsDevice screen) throws AWTException
447 throw new UnsupportedOperationException();
450 public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w)
452 // return new QtEmbeddedWindowPeer( this, w );
453 return null;
456 @Override
457 public boolean isModalExclusionTypeSupported
458 (Dialog.ModalExclusionType modalExclusionType)
460 return false;
463 @Override
464 public boolean isModalityTypeSupported(Dialog.ModalityType modalityType)
466 return false;