123 |
{ |
{ |
124 |
this.owner = owner; |
this.owner = owner; |
125 |
this.toolkit = kit; |
this.toolkit = kit; |
126 |
qtApp = QtToolkit.guiThread.QApplicationPointer; |
qtApp = toolkit.guiThread.QApplicationPointer; |
127 |
nativeObject = 0; |
nativeObject = 0; |
128 |
callInit(); // Calls the init method FROM THE MAIN THREAD. |
callInit(); // Calls the init method FROM THE MAIN THREAD. |
129 |
setup(); |
setup(); |
145 |
settingUp = true; |
settingUp = true; |
146 |
if (owner != null) |
if (owner != null) |
147 |
{ |
{ |
148 |
// if (owner.getBackground() != null) |
if (owner instanceof javax.swing.JComponent) |
149 |
// setBackground(owner.getBackground()); |
setBackground(owner.getBackground()); |
150 |
// else |
else |
151 |
owner.setBackground(getNativeBackground()); |
owner.setBackground(getNativeBackground()); |
152 |
|
|
153 |
if (owner.getForeground() != null) |
if (owner.getForeground() != null) |
163 |
setFont(owner.getFont()); |
setFont(owner.getFont()); |
164 |
|
|
165 |
setEnabled( owner.isEnabled() ); |
setEnabled( owner.isEnabled() ); |
166 |
setVisible( owner.isVisible() ); |
|
167 |
|
backBuffer = null; |
|
Rectangle r = owner.getBounds(); |
|
|
setBounds( r.x, r.y, r.width, r.height ); |
|
|
if( drawableComponent() ) |
|
|
backBuffer = new QtImage( r.width, r.height ); |
|
|
else |
|
|
backBuffer = null; |
|
168 |
dirtyBackBuffer = true; |
dirtyBackBuffer = true; |
169 |
|
updateBounds(); |
170 |
|
|
171 |
|
setVisible( owner.isVisible() ); |
172 |
} |
} |
173 |
settingUp = false; |
settingUp = false; |
174 |
} |
} |
190 |
(this instanceof QtCanvasPeer)); |
(this instanceof QtCanvasPeer)); |
191 |
} |
} |
192 |
|
|
193 |
|
void updateBounds() |
194 |
|
{ |
195 |
|
Rectangle r = owner.getBounds(); |
196 |
|
setBounds( r.x, r.y, r.width, r.height ); |
197 |
|
} |
198 |
|
|
199 |
// ************ Event methods ********************* |
// ************ Event methods ********************* |
200 |
|
|
201 |
/** |
/** |
207 |
{ |
{ |
208 |
WindowEvent e = new WindowEvent((Window)owner, |
WindowEvent e = new WindowEvent((Window)owner, |
209 |
WindowEvent.WINDOW_CLOSING); |
WindowEvent.WINDOW_CLOSING); |
210 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
211 |
} |
} |
212 |
} |
} |
213 |
|
|
217 |
MouseEvent.MOUSE_ENTERED, |
MouseEvent.MOUSE_ENTERED, |
218 |
System.currentTimeMillis(), |
System.currentTimeMillis(), |
219 |
(modifiers & 0x2FF), x, y, 0, false); |
(modifiers & 0x2FF), x, y, 0, false); |
220 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
221 |
} |
} |
222 |
|
|
223 |
protected void focusInEvent() |
protected void focusInEvent() |
224 |
{ |
{ |
225 |
FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_GAINED); |
FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_GAINED); |
226 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
227 |
} |
} |
228 |
|
|
229 |
protected void focusOutEvent() |
protected void focusOutEvent() |
230 |
{ |
{ |
231 |
FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_LOST); |
FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_LOST); |
232 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
233 |
} |
} |
234 |
|
|
235 |
protected void keyPressEvent(int modifiers, int code, int unicode, int dummy) |
protected void keyPressEvent(int modifiers, int code, int unicode, int dummy) |
241 |
modifiers, code, (char)(unicode & 0xFFFF), |
modifiers, code, (char)(unicode & 0xFFFF), |
242 |
KeyEvent.KEY_LOCATION_UNKNOWN); |
KeyEvent.KEY_LOCATION_UNKNOWN); |
243 |
if (!manager.dispatchEvent (e)) |
if (!manager.dispatchEvent (e)) |
244 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
245 |
} |
} |
246 |
|
|
247 |
protected void keyReleaseEvent(int modifiers, int code, int unicode, int dummy) |
protected void keyReleaseEvent(int modifiers, int code, int unicode, int dummy) |
251 |
System.currentTimeMillis(), |
System.currentTimeMillis(), |
252 |
modifiers, code, (char)(unicode & 0xFFFF), |
modifiers, code, (char)(unicode & 0xFFFF), |
253 |
KeyEvent.KEY_LOCATION_UNKNOWN); |
KeyEvent.KEY_LOCATION_UNKNOWN); |
254 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
255 |
} |
} |
256 |
|
|
257 |
protected void leaveEvent(int modifiers, int x, int y, int dummy) |
protected void leaveEvent(int modifiers, int x, int y, int dummy) |
260 |
MouseEvent.MOUSE_EXITED, |
MouseEvent.MOUSE_EXITED, |
261 |
System.currentTimeMillis(), |
System.currentTimeMillis(), |
262 |
(modifiers & 0x2FF), x, y, 0, false); |
(modifiers & 0x2FF), x, y, 0, false); |
263 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
264 |
} |
} |
265 |
|
|
266 |
// FIXME: Coalesce press-release events into clicks. |
// FIXME: Coalesce press-release events into clicks. |
280 |
System.currentTimeMillis(), |
System.currentTimeMillis(), |
281 |
(modifiers & 0x2FF), x, y, clickCount, |
(modifiers & 0x2FF), x, y, clickCount, |
282 |
false, button); |
false, button); |
283 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
284 |
} |
} |
285 |
|
|
286 |
protected void mouseMoveEvent( int modifiers, int x, int y, int clickCount) |
protected void mouseMoveEvent( int modifiers, int x, int y, int clickCount) |
306 |
timeStamp, |
timeStamp, |
307 |
(modifiers & 0x2FF), x, y, clickCount, |
(modifiers & 0x2FF), x, y, clickCount, |
308 |
false, button); |
false, button); |
309 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
310 |
} |
} |
311 |
lastMME = timeStamp; |
lastMME = timeStamp; |
312 |
} |
} |
313 |
|
|
314 |
protected void mousePressEvent( int modifiers, int x, int y, int clickCount) |
protected void mousePressEvent( int modifiers, int x, int y, int clickCount) |
315 |
{ |
{ |
316 |
// if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 ) |
if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 ) |
317 |
// return; |
return; |
318 |
int button = 0; |
int button = 0; |
319 |
if((modifiers & InputEvent.BUTTON1_DOWN_MASK) == |
if((modifiers & InputEvent.BUTTON1_DOWN_MASK) == |
320 |
InputEvent.BUTTON1_DOWN_MASK) button = 1; |
InputEvent.BUTTON1_DOWN_MASK) button = 1; |
328 |
(modifiers & 0x2FF), x, y, clickCount, |
(modifiers & 0x2FF), x, y, clickCount, |
329 |
( button == POPUP_TRIGGER ), |
( button == POPUP_TRIGGER ), |
330 |
button); |
button); |
331 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
332 |
} |
} |
333 |
|
|
334 |
protected void mouseReleaseEvent( int modifiers, int x, int y, int clickCount) |
protected void mouseReleaseEvent( int modifiers, int x, int y, int clickCount) |
348 |
System.currentTimeMillis(), |
System.currentTimeMillis(), |
349 |
(modifiers & 0x2FF), x, y, clickCount, |
(modifiers & 0x2FF), x, y, clickCount, |
350 |
false, button); |
false, button); |
351 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
352 |
} |
} |
353 |
|
|
354 |
protected void moveEvent() |
protected void moveEvent() |
355 |
{ |
{ |
356 |
ComponentEvent e = new ComponentEvent(owner, |
ComponentEvent e = new ComponentEvent(owner, |
357 |
ComponentEvent.COMPONENT_MOVED); |
ComponentEvent.COMPONENT_MOVED); |
358 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
|
} |
|
|
|
|
|
protected void paintEvent(QtGraphics g) |
|
|
{ |
|
|
if (backBuffer != null) |
|
|
{ |
|
|
if (dirtyBackBuffer) |
|
|
{ |
|
|
backBuffer.clear(); |
|
|
Graphics2D bbg = (Graphics2D)backBuffer.getGraphics(); |
|
|
owner.paint(bbg); |
|
|
bbg.dispose(); |
|
|
dirtyBackBuffer = false; |
|
|
} |
|
|
backBuffer.drawPixels(g, 0, 0, 0, 0, 0, false ); |
|
|
} |
|
359 |
} |
} |
360 |
|
|
361 |
protected void resizeEvent(int oldWidth, int oldHeight, |
protected void resizeEvent(int oldWidth, int oldHeight, |
363 |
{ |
{ |
364 |
dirtyBackBuffer = true; |
dirtyBackBuffer = true; |
365 |
if( drawableComponent() ) |
if( drawableComponent() ) |
366 |
backBuffer = new QtImage(width, height); |
{ |
367 |
|
// backBuffer.dispose(); |
368 |
|
backBuffer = new QtImage(width, height); |
369 |
|
} |
370 |
owner.setSize(width, height); |
owner.setSize(width, height); |
371 |
ComponentEvent e = new ComponentEvent(owner, |
ComponentEvent e = new ComponentEvent(owner, |
372 |
ComponentEvent.COMPONENT_RESIZED); |
ComponentEvent.COMPONENT_RESIZED); |
373 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
374 |
} |
} |
375 |
|
|
376 |
protected void showEvent() |
protected void showEvent() |
379 |
{ |
{ |
380 |
WindowEvent e = new WindowEvent((Window)owner, |
WindowEvent e = new WindowEvent((Window)owner, |
381 |
WindowEvent.WINDOW_OPENED); |
WindowEvent.WINDOW_OPENED); |
382 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
383 |
} |
} |
384 |
else |
else |
385 |
{ |
{ |
386 |
ComponentEvent e = new ComponentEvent(owner, |
ComponentEvent e = new ComponentEvent(owner, |
387 |
ComponentEvent.COMPONENT_SHOWN); |
ComponentEvent.COMPONENT_SHOWN); |
388 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
389 |
} |
} |
390 |
} |
} |
391 |
|
|
393 |
{ |
{ |
394 |
ComponentEvent e = new ComponentEvent(owner, |
ComponentEvent e = new ComponentEvent(owner, |
395 |
ComponentEvent.COMPONENT_HIDDEN); |
ComponentEvent.COMPONENT_HIDDEN); |
396 |
QtToolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
397 |
} |
} |
398 |
|
|
399 |
private native Dimension getMinimumSizeNative(); |
private native Dimension getMinimumSizeNative(); |
475 |
|
|
476 |
public void flip(BufferCapabilities.FlipContents contents) |
public void flip(BufferCapabilities.FlipContents contents) |
477 |
{ |
{ |
|
// FIXME |
|
478 |
} |
} |
479 |
|
|
480 |
public Image getBackBuffer() |
public Image getBackBuffer() |
499 |
Rectangle r = owner.getBounds(); |
Rectangle r = owner.getBounds(); |
500 |
backBuffer = new QtImage( r.width, r.height ); |
backBuffer = new QtImage( r.width, r.height ); |
501 |
} |
} |
|
dirtyBackBuffer = true; |
|
502 |
return backBuffer.getGraphics(); |
return backBuffer.getGraphics(); |
503 |
} |
} |
504 |
|
|
505 |
public GraphicsConfiguration getGraphicsConfiguration() |
public GraphicsConfiguration getGraphicsConfiguration() |
506 |
{ |
{ |
507 |
int id = whichScreen(); // get the ID of the screen the widget is on. |
int id = whichScreen(); // get the ID of the screen the widget is on. |
508 |
GraphicsDevice[] devs = QtToolkit.graphicsEnv.getScreenDevices(); |
GraphicsDevice[] devs = toolkit.graphicsEnv.getScreenDevices(); |
509 |
return devs[id].getDefaultConfiguration(); |
return devs[id].getDefaultConfiguration(); |
510 |
} |
} |
511 |
|
|
586 |
|
|
587 |
public void setBounds(int x, int y, int width, int height) |
public void setBounds(int x, int y, int width, int height) |
588 |
{ |
{ |
589 |
if(width > 0 && height > 0) |
if(width > 0 && height > 0 && (drawableComponent() || backBuffer != null)) |
590 |
backBuffer = new QtImage(width, height); |
backBuffer = new QtImage(width, height); |
591 |
setBoundsNative(x, y, width, height); |
setBoundsNative(x, y, width, height); |
592 |
} |
} |
627 |
{ |
{ |
628 |
case ComponentEvent.COMPONENT_SHOWN: |
case ComponentEvent.COMPONENT_SHOWN: |
629 |
case PaintEvent.PAINT: |
case PaintEvent.PAINT: |
630 |
case PaintEvent.UPDATE: |
case PaintEvent.UPDATE: |
631 |
dirtyBackBuffer = true; |
dirtyBackBuffer = true; |
632 |
QtUpdate(); |
QtUpdate(); |
633 |
break; |
break; |
634 |
case KeyEvent.KEY_PRESSED: |
case KeyEvent.KEY_PRESSED: |
|
// FIXME |
|
635 |
break; |
break; |
636 |
case KeyEvent.KEY_RELEASED: |
case KeyEvent.KEY_RELEASED: |
|
// FIXME |
|
637 |
break; |
break; |
638 |
} |
} |
639 |
} |
} |
640 |
|
|
641 |
|
/** |
642 |
|
* Paint() is called back from the native side in response to a native |
643 |
|
* repaint event. |
644 |
|
*/ |
645 |
public void paint(Graphics g) |
public void paint(Graphics g) |
646 |
{ |
{ |
647 |
// We don't need to do anything here. |
if (backBuffer != null) |
648 |
|
{ |
649 |
|
if (dirtyBackBuffer) |
650 |
|
{ |
651 |
|
backBuffer.clear(); |
652 |
|
Graphics2D bbg = (Graphics2D)backBuffer.getGraphics(); |
653 |
|
owner.paint(bbg); |
654 |
|
bbg.dispose(); |
655 |
|
dirtyBackBuffer = false; |
656 |
|
} |
657 |
|
backBuffer.drawPixels((QtGraphics)g, 0, 0, 0, 0, 0, false ); |
658 |
|
} |
659 |
} |
} |
660 |
|
|
661 |
public boolean prepareImage(Image img, |
public boolean prepareImage(Image img, |