1 /* QtComponentPeer.java --
2    Copyright (C)  2005, 2006  Free Software Foundation, Inc.
3 
4 This file is part of GNU Classpath.
5 
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.
10 
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.
15 
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.
20 
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.
25 
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. */
37 
38 package gnu.java.awt.peer.qt;
39 
40 import java.awt.AWTEvent;
41 import java.awt.AWTException;
42 import java.awt.BufferCapabilities;
43 import java.awt.Component;
44 import java.awt.Color;
45 import java.awt.Cursor;
46 import java.awt.Dimension;
47 import java.awt.Font;
48 import java.awt.FontMetrics;
49 import java.awt.Image;
50 import java.awt.Graphics;
51 import java.awt.Graphics2D;
52 import java.awt.GraphicsConfiguration;
53 import java.awt.GraphicsDevice;
54 import java.awt.KeyboardFocusManager;
55 import java.awt.Point;
56 import java.awt.Rectangle;
57 import java.awt.Toolkit;
58 import java.awt.Window;
59 import java.awt.peer.ComponentPeer;
60 import java.awt.peer.ContainerPeer;
61 import java.awt.image.ColorModel;
62 import java.awt.image.VolatileImage;
63 import java.awt.image.ImageObserver;
64 import java.awt.image.ImageProducer;
65 import java.awt.event.ComponentEvent; // 100%
66 import java.awt.event.FocusEvent; // 100%
67 import java.awt.event.InputEvent; // (abstract)
68 import java.awt.event.KeyEvent; // 2/3
69 import java.awt.event.MouseEvent; // 70%?
70 import java.awt.event.PaintEvent; // Yup.
71 import java.awt.event.WindowEvent; // 2/ 12
72 import java.util.Timer;
73 import java.util.TimerTask;
74 
75 public class QtComponentPeer extends NativeWrapper implements ComponentPeer
76 {
77 
78   /**
79    * Popup trigger button, may differ between platforms
80    */
81   protected static final int POPUP_TRIGGER = 3;
82 
83   /**
84    * The toolkit which manufactured this peer.
85    */
86   protected QtToolkit toolkit;
87 
88   /**
89    * The component which owns this peer.
90    */
91   Component owner;
92 
93   /**
94    * Classpath updates our eventMask.
95    */
96   private long eventMask;
97 
98   /**
99    * if the thing has mouse motion listeners or not.
100    */
101   private boolean hasMotionListeners;
102 
103   /**
104    * The component's double buffer for off-screen drawing.
105    */
106   protected QtImage backBuffer;
107 
108   protected long qtApp;
109 
110   private boolean settingUp;
111 
112   private boolean ignoreResize = false;
113 
QtComponentPeer( QtToolkit kit, Component owner )114   QtComponentPeer( QtToolkit kit, Component owner )
115   {
116     this.owner = owner;
117     this.toolkit = kit;
118     qtApp = QtToolkit.guiThread.QApplicationPointer;
119     nativeObject = 0;
120     synchronized(this)
121       {
122         callInit(); // Calls the init method FROM THE MAIN THREAD.
123         try
124           {
125             wait(); // Wait for the thing to be created.
126           }
127         catch(InterruptedException e)
128           {
129           }
130       }
131     setup();
132     hasMotionListeners = false;
133   }
134 
callInit()135   protected native void callInit();
136 
137   /**
138    * Init does the creation of native widgets, it is therefore
139    * called from the main thread. (the constructor waits for this to happen.)
140    */
init()141   protected void init()
142   {
143   }
144 
setup()145   protected void setup()
146   {
147     settingUp = true;
148     if (owner != null)
149       {
150         if (owner instanceof javax.swing.JComponent)
151           setBackground(owner.getBackground());
152         else
153           owner.setBackground(getNativeBackground());
154 
155         if (owner.getForeground() != null)
156           setForeground(owner.getForeground());
157         else
158           setForeground( Color.black );
159 
160         if (owner.getCursor() != null)
161           if (owner.getCursor().getType() != Cursor.DEFAULT_CURSOR)
162             setCursor(owner.getCursor());
163 
164         if (owner.getFont() != null)
165           setFont(owner.getFont());
166 
167         setEnabled( owner.isEnabled() );
168 
169         backBuffer = null;
170         updateBounds();
171 
172         setVisible( owner.isVisible() );
173         QtToolkit.repaintThread.queueComponent(this);
174       }
175     settingUp = false;
176   }
177 
QtUpdate()178   native void QtUpdate();
QtUpdateArea( int x, int y, int w, int h )179   native void QtUpdateArea( int x, int y, int w, int h );
disposeNative()180   private synchronized native void disposeNative();
setGround( int r, int g, int b, boolean isForeground )181   private native void setGround( int r, int g, int b, boolean isForeground );
setBoundsNative( int x, int y, int width, int height )182   private native void setBoundsNative( int x, int y, int width, int height );
setCursor( int ctype )183   private native void setCursor( int ctype );
getNativeBackground()184   private native Color getNativeBackground();
setFontNative( QtFontPeer fp )185   private native void setFontNative( QtFontPeer fp );
whichScreen()186   private native int whichScreen();
reparentNative( QtContainerPeer parent )187   private native void reparentNative( QtContainerPeer parent );
getLocationOnScreenNative( Point p )188   private native void getLocationOnScreenNative( Point p );
189 
drawableComponent()190   private boolean drawableComponent()
191   {
192     return ((this instanceof QtContainerPeer &&
193              !(this instanceof QtScrollPanePeer)) ||
194             (this instanceof QtCanvasPeer));
195   }
196 
updateBounds()197   void updateBounds()
198   {
199     Rectangle r = owner.getBounds();
200     setBounds( r.x, r.y, r.width, r.height );
201   }
202 
updateBackBuffer(int width, int height)203   synchronized void updateBackBuffer(int width, int height)
204   {
205     if(width <= 0 || height <= 0)
206       return;
207 
208     if( !drawableComponent() && backBuffer == null)
209       return;
210 
211     if( backBuffer != null )
212       {
213         if( width < backBuffer.width && height < backBuffer.height )
214           return;
215         backBuffer.dispose();
216       }
217     backBuffer = new QtImage(width, height);
218   }
219 
220 
221   // ************ Event methods *********************
222 
223   /**
224    * Window closing event
225    */
closeEvent()226   protected void closeEvent()
227   {
228     if (owner instanceof Window)
229       {
230         WindowEvent e = new WindowEvent((Window)owner,
231                                         WindowEvent.WINDOW_CLOSING);
232         QtToolkit.eventQueue.postEvent(e);
233       }
234   }
235 
enterEvent(int modifiers, int x, int y, int dummy)236   protected void enterEvent(int modifiers, int x, int y, int dummy)
237   {
238     MouseEvent e = new MouseEvent(owner,
239                                   MouseEvent.MOUSE_ENTERED,
240                                   System.currentTimeMillis(),
241                                   (modifiers & 0x2FF), x, y, 0, false);
242     QtToolkit.eventQueue.postEvent(e);
243   }
244 
focusInEvent()245   protected void focusInEvent()
246   {
247     FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_GAINED);
248     QtToolkit.eventQueue.postEvent(e);
249    }
250 
focusOutEvent()251   protected void focusOutEvent()
252   {
253     FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_LOST);
254     QtToolkit.eventQueue.postEvent(e);
255   }
256 
keyPressEvent(int modifiers, int code, int unicode, int dummy)257   protected void keyPressEvent(int modifiers, int code, int unicode, int dummy)
258   {
259     KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
260     KeyEvent e = new KeyEvent(owner,
261                               KeyEvent.KEY_PRESSED,
262                               System.currentTimeMillis(),
263                               modifiers, code, (char)(unicode & 0xFFFF),
264                               KeyEvent.KEY_LOCATION_UNKNOWN);
265     if (!manager.dispatchEvent (e))
266       QtToolkit.eventQueue.postEvent(e);
267   }
268 
keyReleaseEvent(int modifiers, int code, int unicode, int dummy)269   protected void keyReleaseEvent(int modifiers, int code, int unicode, int dummy)
270   {
271     KeyEvent e = new KeyEvent(owner,
272                               KeyEvent.KEY_RELEASED,
273                               System.currentTimeMillis(),
274                               modifiers, code, (char)(unicode & 0xFFFF),
275                               KeyEvent.KEY_LOCATION_UNKNOWN);
276     QtToolkit.eventQueue.postEvent(e);
277   }
278 
leaveEvent(int modifiers, int x, int y, int dummy)279   protected void leaveEvent(int modifiers, int x, int y, int dummy)
280   {
281     MouseEvent e = new MouseEvent(owner,
282                                   MouseEvent.MOUSE_EXITED,
283                                   System.currentTimeMillis(),
284                                   (modifiers & 0x2FF), x, y, 0, false);
285     QtToolkit.eventQueue.postEvent(e);
286   }
287 
288   // FIXME: Coalesce press-release events into clicks.
mouseDoubleClickEvent( int modifiers, int x, int y, int clickCount)289   protected void mouseDoubleClickEvent( int modifiers, int x, int y, int clickCount)
290   {
291     if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 )
292       return;
293     int button = 0;
294     if((modifiers & InputEvent.BUTTON1_DOWN_MASK) ==
295        InputEvent.BUTTON1_DOWN_MASK) button = 1;
296     if((modifiers & InputEvent.BUTTON2_DOWN_MASK) ==
297        InputEvent.BUTTON2_DOWN_MASK) button = 2;
298     if((modifiers & InputEvent.BUTTON3_DOWN_MASK) ==
299        InputEvent.BUTTON3_DOWN_MASK) button = 3;
300     MouseEvent e = new MouseEvent(owner,
301                                   MouseEvent.MOUSE_CLICKED,
302                                   System.currentTimeMillis(),
303                                   (modifiers & 0x2FF), x, y, clickCount,
304                                   false, button);
305     QtToolkit.eventQueue.postEvent(e);
306   }
307 
mouseMoveEvent( int modifiers, int x, int y, int clickCount)308   protected void mouseMoveEvent( int modifiers, int x, int y, int clickCount)
309   {
310     if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 )
311       return;
312 
313     int button = 0;
314     if((modifiers & InputEvent.BUTTON1_DOWN_MASK) ==
315        InputEvent.BUTTON1_DOWN_MASK) button = 1;
316     if((modifiers & InputEvent.BUTTON2_DOWN_MASK) ==
317        InputEvent.BUTTON2_DOWN_MASK) button = 2;
318     if((modifiers & InputEvent.BUTTON3_DOWN_MASK) ==
319            InputEvent.BUTTON3_DOWN_MASK) button = 3;
320 
321     int type = (button != 0) ?
322       MouseEvent.MOUSE_DRAGGED :MouseEvent.MOUSE_MOVED;
323 
324     MouseEvent e = new MouseEvent(owner,
325                                   type,
326                                   System.currentTimeMillis(),
327                                   (modifiers & 0x2FF), x, y, clickCount,
328                                   false, button);
329     QtToolkit.eventQueue.postEvent(e);
330   }
331 
mousePressEvent( int modifiers, int x, int y, int clickCount)332   protected void mousePressEvent( int modifiers, int x, int y, int clickCount)
333   {
334     if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 )
335       return;
336     int button = 0;
337     if((modifiers & InputEvent.BUTTON1_DOWN_MASK) ==
338        InputEvent.BUTTON1_DOWN_MASK) button = 1;
339     if((modifiers & InputEvent.BUTTON2_DOWN_MASK) ==
340        InputEvent.BUTTON2_DOWN_MASK) button = 2;
341     if((modifiers & InputEvent.BUTTON3_DOWN_MASK) ==
342        InputEvent.BUTTON3_DOWN_MASK) button = 3;
343     MouseEvent e = new MouseEvent(owner,
344                                   MouseEvent.MOUSE_PRESSED,
345                                   System.currentTimeMillis(),
346                                   (modifiers & 0x2FF), x, y, clickCount,
347                                   ( button == POPUP_TRIGGER ),
348                                    button);
349     QtToolkit.eventQueue.postEvent(e);
350   }
351 
mouseReleaseEvent( int modifiers, int x, int y, int clickCount)352   protected void mouseReleaseEvent( int modifiers, int x, int y, int clickCount)
353   {
354     if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 )
355       return;
356     int button = 0;
357     if((modifiers & InputEvent.BUTTON1_DOWN_MASK) ==
358        InputEvent.BUTTON1_DOWN_MASK) button = 1;
359     if((modifiers & InputEvent.BUTTON2_DOWN_MASK) ==
360        InputEvent.BUTTON2_DOWN_MASK) button = 2;
361     if((modifiers & InputEvent.BUTTON3_DOWN_MASK) ==
362        InputEvent.BUTTON3_DOWN_MASK) button = 3;
363 
364     MouseEvent e = new MouseEvent(owner,
365                                   MouseEvent.MOUSE_RELEASED,
366                                   System.currentTimeMillis(),
367                                   (modifiers & 0x2FF), x, y, clickCount,
368                                   false, button);
369     QtToolkit.eventQueue.postEvent(e);
370   }
371 
moveEvent(int x, int y, int oldx, int oldy)372   protected void moveEvent(int x, int y, int oldx, int oldy)
373   {
374     if( !ignoreResize )
375       {
376         // Since Component.setLocation calls back to setBounds,
377         // we need to ignore that.
378         ignoreResize = true;
379         owner.setLocation( x, y );
380         ignoreResize = false;
381       }
382   }
383 
resizeEvent(int oldWidth, int oldHeight, int width, int height)384   protected void resizeEvent(int oldWidth, int oldHeight,
385                              int width, int height)
386   {
387     if(!(owner instanceof Window))
388       return;
389     updateBackBuffer(width, height);
390     ignoreResize = true;
391     owner.setSize(width, height);
392     ignoreResize = false;
393     ComponentEvent e = new ComponentEvent(owner,
394                                           ComponentEvent.COMPONENT_RESIZED);
395     QtToolkit.eventQueue.postEvent(e);
396     QtToolkit.repaintThread.queueComponent(this);
397   }
398 
showEvent()399   protected void showEvent()
400   {
401     if (owner instanceof Window)
402       {
403         WindowEvent e = new WindowEvent((Window)owner,
404                                         WindowEvent.WINDOW_OPENED);
405         QtToolkit.eventQueue.postEvent(e);
406       }
407     else
408       {
409         ComponentEvent e = new ComponentEvent(owner,
410                                               ComponentEvent.COMPONENT_SHOWN);
411         QtToolkit.eventQueue.postEvent(e);
412       }
413   }
414 
hideEvent()415   protected void hideEvent()
416   {
417     ComponentEvent e = new ComponentEvent(owner,
418                                           ComponentEvent.COMPONENT_HIDDEN);
419     QtToolkit.eventQueue.postEvent(e);
420   }
421 
422   // ************ Public methods *********************
423 
424   /** Classpath-specific method */
setEventMask(long x)425   public void setEventMask(long x)
426   {
427     eventMask = x;
428   }
429 
430 
canDetermineObscurity()431   public boolean canDetermineObscurity()
432   {
433     return true;
434   }
435 
checkImage(Image img, int w, int h, ImageObserver o)436   public int checkImage(Image img,
437                         int w,
438                         int h,
439                         ImageObserver o)
440   {
441     return toolkit.checkImage(img, w, h, o);
442   }
443 
createBuffers(int numBuffers, BufferCapabilities caps)444   public void createBuffers(int numBuffers, BufferCapabilities caps)
445     throws AWTException
446   {
447     // FIXME
448   }
449 
createImage(ImageProducer producer)450   public Image createImage(ImageProducer producer)
451   {
452     return toolkit.createImage(producer);
453   }
454 
createImage(int width, int height)455   public Image createImage(int width, int height)
456   {
457     return new QtImage(width, height);
458   }
459 
coalescePaintEvent(PaintEvent e)460   public void coalescePaintEvent(PaintEvent e)
461   {
462     // FIXME
463   }
464 
createVolatileImage(int w, int h)465   public VolatileImage createVolatileImage(int w, int h)
466   {
467     return new QtVolatileImage( w, h );
468   }
469 
destroyBuffers()470   public void destroyBuffers()
471   {
472     // FIXME
473   }
474 
disable()475   public void disable()
476   {
477     setEnabled(false);
478   }
479 
dispose()480   public void dispose()
481   {
482     disposeNative();
483     if( backBuffer != null )
484       backBuffer.dispose();
485   }
486 
enable()487   public void enable()
488   {
489     setEnabled(true);
490   }
491 
finalize()492   public void finalize()
493   {
494     dispose();
495   }
496 
flip(BufferCapabilities.FlipContents contents)497   public void flip(BufferCapabilities.FlipContents contents)
498   {
499   }
500 
getBackBuffer()501   public Image getBackBuffer()
502   {
503     return backBuffer;
504   }
505 
getColorModel()506   public ColorModel getColorModel()
507   {
508     return toolkit.getColorModel();
509   }
510 
getFontMetrics(Font font)511   public FontMetrics getFontMetrics(Font font)
512   {
513     return new QtFontMetrics( font, getGraphics() );
514   }
515 
getGraphics()516   public Graphics getGraphics()
517   {
518     if( backBuffer == null )
519       {
520         Rectangle r = owner.getBounds();
521         backBuffer = new QtImage( r.width, r.height );
522       }
523     return backBuffer.getDirectGraphics( this );
524   }
525 
getGraphicsConfiguration()526   public GraphicsConfiguration getGraphicsConfiguration()
527   {
528     int id = whichScreen(); // get the ID of the screen the widget is on.
529     GraphicsDevice[] devs = QtToolkit.graphicsEnv.getScreenDevices();
530     return devs[id].getDefaultConfiguration();
531   }
532 
getLocationOnScreen()533   public Point getLocationOnScreen()
534   {
535     Point p = new Point();
536     synchronized( p )
537       {
538         getLocationOnScreenNative( p );
539         try
540           {
541             p.wait(); // Wait for the thing to be created.
542           }
543         catch(InterruptedException e)
544           {
545           }
546       }
547     return p;
548   }
549 
getSizeNative(Dimension d, boolean preferred)550   private native void getSizeNative(Dimension d, boolean preferred);
551 
getSize(boolean preferred)552   private Dimension getSize(boolean preferred)
553   {
554     Dimension d = new Dimension();
555     synchronized( d )
556       {
557         getSizeNative(d, preferred);
558         try
559           {
560             d.wait(); // Wait for the thing to be created.
561           }
562         catch(InterruptedException e)
563           {
564           }
565       }
566     return d;
567   }
568 
getMinimumSize()569   public Dimension getMinimumSize()
570   {
571     return getSize( false );
572   }
573 
getPreferredSize()574   public Dimension getPreferredSize()
575   {
576     return getSize( true );
577   }
578 
getToolkit()579   public Toolkit getToolkit()
580   {
581     return toolkit;
582   }
583 
handlesWheelScrolling()584   public native boolean handlesWheelScrolling();
585 
hide()586   public void hide()
587   {
588     setVisible(false);
589   }
590 
isFocusable()591   public native boolean isFocusable();
592 
isFocusTraversable()593   public boolean isFocusTraversable()
594   {
595     // FIXME
596     return false;
597   }
598 
isObscured()599   public native boolean isObscured();
600 
minimumSize()601   public Dimension minimumSize()
602   {
603     return getMinimumSize();
604   }
605 
preferredSize()606   public Dimension preferredSize()
607   {
608     return getPreferredSize();
609   }
610 
requestFocus()611   public native void requestFocus();
612 
requestFocus(Component source, boolean bool1, boolean bool2, long x)613   public boolean requestFocus (Component source, boolean bool1,
614                                boolean bool2, long x)
615   {
616     // FIXME
617     return true;
618   }
619 
reshape(int x, int y, int width, int height)620   public void reshape(int x,
621                       int y,
622                       int width,
623                       int height)
624   {
625     setBounds( x, y, width, height );
626   }
627 
setBackground(Color c)628   public void setBackground(Color c)
629   {
630     if(c == null && !settingUp)
631       return;
632     setGround(c.getRed(), c.getGreen(), c.getBlue(), false);
633   }
634 
setBounds(int x, int y, int width, int height)635   public void setBounds(int x, int y, int width, int height)
636   {
637     if( ignoreResize )
638       return;
639     updateBackBuffer(width, height);
640     QtToolkit.repaintThread.queueComponent(this);
641     setBoundsNative(x, y, width, height);
642   }
643 
setCursor(Cursor cursor)644   public void setCursor(Cursor cursor)
645   {
646     if (cursor != null)
647       setCursor(cursor.getType());
648   }
649 
setEnabled(boolean b)650   public native void setEnabled(boolean b);
651 
setFont(Font f)652   public void setFont(Font f)
653   {
654     if( f == null || f.getPeer() == null)
655       throw new IllegalArgumentException("Null font.");
656     setFontNative( (QtFontPeer)f.getPeer() );
657   }
658 
setForeground(Color c)659   public void setForeground(Color c)
660   {
661     if(c == null && !settingUp)
662       return;
663     setGround(c.getRed(), c.getGreen(), c.getBlue(), true);
664   }
665 
setVisible(boolean b)666   public native void setVisible(boolean b);
667 
show()668   public void show()
669   {
670     setVisible(true);
671   }
672 
handleEvent(AWTEvent e)673   public void handleEvent (AWTEvent e)
674   {
675     int eventID = e.getID();
676     Rectangle r;
677 
678     switch (eventID)
679       {
680       case ComponentEvent.COMPONENT_SHOWN:
681         QtToolkit.repaintThread.queueComponent(this);
682         break;
683       case PaintEvent.PAINT:
684       case PaintEvent.UPDATE:
685         r = ((PaintEvent)e).getUpdateRect();
686         QtToolkit.repaintThread.queueComponent(this, r.x, r.y,
687                                                r.width, r.height);
688         break;
689       case KeyEvent.KEY_PRESSED:
690         break;
691       case KeyEvent.KEY_RELEASED:
692         break;
693       }
694   }
695 
696   /**
697    * paint() is called back from the native side in response to a native
698    * repaint event.
699    */
paint(Graphics g)700   public void paint(Graphics g)
701   {
702     Rectangle r = g.getClipBounds();
703 
704     if (backBuffer != null)
705       backBuffer.drawPixelsScaledFlipped ((QtGraphics) g,
706                                           0, 0, 0, /* bg colors */
707                                           false, false, /* no flipping */
708                                           r.x, r.y, r.width, r.height,
709                                           r.x, r.y, r.width, r.height,
710                                           false ); /* no compositing */
711   }
712 
paintBackBuffer()713   public void paintBackBuffer() throws InterruptedException
714   {
715     if( backBuffer != null )
716       {
717         backBuffer.clear();
718         Graphics2D bbg = (Graphics2D)backBuffer.getGraphics();
719         owner.paint(bbg);
720         bbg.dispose();
721       }
722   }
723 
paintBackBuffer(int x, int y, int w, int h)724   public void paintBackBuffer(int x, int y, int w, int h)
725     throws InterruptedException
726   {
727     if( backBuffer != null )
728       {
729         Graphics2D bbg = (Graphics2D)backBuffer.getGraphics();
730         bbg.setBackground( getNativeBackground() );
731         bbg.clearRect(x, y, w, h);
732         bbg.setClip(x, y, w, h);
733         owner.paint(bbg);
734         bbg.dispose();
735       }
736   }
737 
prepareImage(Image img, int w, int h, ImageObserver o)738   public boolean prepareImage(Image img,
739                               int w,
740                               int h,
741                               ImageObserver o)
742   {
743     return toolkit.prepareImage(img, w, h, o);
744   }
745 
print(Graphics g)746   public void print(Graphics g)
747   {
748     // FIXME
749   }
750 
751   /**
752    * Schedules a timed repaint.
753    */
repaint(long tm, int x, int y, int w, int h)754   public void repaint(long tm,
755                       int x,
756                       int y,
757                       int w,
758                       int h)
759   {
760     if( tm <= 0 )
761       {
762         QtToolkit.repaintThread.queueComponent(this, x, y, w, h);
763         return;
764       }
765     Timer t = new Timer();
766     t.schedule(new RepaintTimerTask(this, x, y, w, h), tm);
767   }
768 
769   /**
770    * Update the cursor (note that setCursor is usually not called)
771    */
updateCursorImmediately()772   public void updateCursorImmediately()
773   {
774     if (owner.getCursor() != null)
775       setCursor(owner.getCursor().getType());
776   }
777 
778   /**
779    * Timed repainter
780    */
781   private class RepaintTimerTask extends TimerTask
782   {
783     private int x, y, w, h;
784     private QtComponentPeer peer;
RepaintTimerTask(QtComponentPeer peer, int x, int y, int w, int h)785     RepaintTimerTask(QtComponentPeer peer, int x, int y, int w, int h)
786     {
787       this.x=x;
788       this.y=y;
789       this.w=w;
790       this.h=h;
791       this.peer=peer;
792     }
run()793     public void run()
794     {
795       QtToolkit.repaintThread.queueComponent(peer, x, y, w, h);
796     }
797   }
798 
getBounds()799   public native Rectangle getBounds();
800 
reparent(ContainerPeer parent)801   public void reparent(ContainerPeer parent)
802   {
803     if(!(parent instanceof QtContainerPeer))
804       throw new IllegalArgumentException("Illegal peer.");
805     reparentNative((QtContainerPeer)parent);
806   }
807 
setBounds(int x, int y, int width, int height, int z)808   public void setBounds(int x, int y, int width, int height, int z)
809   {
810     // TODO Auto-generated method stub
811 
812   }
813 
isReparentSupported()814   public boolean isReparentSupported()
815   {
816     return true;
817   }
818 
819   // What does this do, anyway?
layout()820   public void layout()
821   {
822     // TODO Auto-generated method stub
823   }
824 
requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time, sun.awt.CausedFocusEvent.Cause cause)825   public boolean requestFocus(Component lightweightChild, boolean temporary,
826                               boolean focusedWindowChangeAllowed,
827                               long time, sun.awt.CausedFocusEvent.Cause cause)
828   {
829     // TODO: Implement this properly and remove the other requestFocus()
830     // methods.
831     return true;
832   }
833 
834 }
835