2005-07-16 00:30:23 +00:00
|
|
|
/* GtkComponentPeer.java -- Implements ComponentPeer with GTK
|
2006-03-10 21:46:48 +00:00
|
|
|
Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
|
|
|
|
Free Software Foundation, Inc.
|
2005-07-16 00:30:23 +00:00
|
|
|
|
|
|
|
This file is part of GNU Classpath.
|
|
|
|
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301 USA.
|
|
|
|
|
|
|
|
Linking this library statically or dynamically with other modules is
|
|
|
|
making a combined work based on this library. Thus, the terms and
|
|
|
|
conditions of the GNU General Public License cover the whole
|
|
|
|
combination.
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent
|
|
|
|
modules, and to copy and distribute the resulting executable under
|
|
|
|
terms of your choice, provided that you also meet, for each linked
|
|
|
|
independent module, the terms and conditions of the license of that
|
|
|
|
module. An independent module is a module which is not derived from
|
|
|
|
or based on this library. If you modify this library, you may extend
|
|
|
|
this exception to your version of the library, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version. */
|
|
|
|
|
|
|
|
|
|
|
|
package gnu.java.awt.peer.gtk;
|
|
|
|
|
|
|
|
import java.awt.AWTEvent;
|
|
|
|
import java.awt.AWTException;
|
|
|
|
import java.awt.BufferCapabilities;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.Container;
|
|
|
|
import java.awt.Cursor;
|
|
|
|
import java.awt.Dimension;
|
2006-03-10 21:46:48 +00:00
|
|
|
import java.awt.EventQueue;
|
2005-07-16 00:30:23 +00:00
|
|
|
import java.awt.Font;
|
|
|
|
import java.awt.FontMetrics;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.GraphicsConfiguration;
|
|
|
|
import java.awt.Image;
|
|
|
|
import java.awt.Insets;
|
|
|
|
import java.awt.ItemSelectable;
|
|
|
|
import java.awt.Point;
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
import java.awt.Toolkit;
|
|
|
|
import java.awt.Window;
|
|
|
|
import java.awt.event.FocusEvent;
|
|
|
|
import java.awt.event.ItemEvent;
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import java.awt.event.MouseEvent;
|
2006-05-18 17:29:21 +00:00
|
|
|
import java.awt.event.MouseWheelEvent;
|
2005-07-16 00:30:23 +00:00
|
|
|
import java.awt.event.PaintEvent;
|
|
|
|
import java.awt.event.TextEvent;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.awt.image.ColorModel;
|
|
|
|
import java.awt.image.ImageObserver;
|
|
|
|
import java.awt.image.ImageProducer;
|
|
|
|
import java.awt.image.VolatileImage;
|
|
|
|
import java.awt.peer.ComponentPeer;
|
2005-09-23 21:31:04 +00:00
|
|
|
import java.awt.peer.ContainerPeer;
|
2005-11-15 23:20:01 +00:00
|
|
|
import java.awt.peer.WindowPeer;
|
2005-09-23 21:31:04 +00:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
2005-07-16 00:30:23 +00:00
|
|
|
|
|
|
|
public class GtkComponentPeer extends GtkGenericPeer
|
|
|
|
implements ComponentPeer
|
|
|
|
{
|
|
|
|
VolatileImage backBuffer;
|
|
|
|
BufferCapabilities caps;
|
|
|
|
|
|
|
|
Component awtComponent;
|
|
|
|
|
|
|
|
Insets insets;
|
|
|
|
|
|
|
|
/* this isEnabled differs from Component.isEnabled, in that it
|
|
|
|
knows if a parent is disabled. In that case Component.isEnabled
|
|
|
|
may return true, but our isEnabled will always return false */
|
|
|
|
native boolean isEnabled ();
|
|
|
|
static native boolean modalHasGrab();
|
|
|
|
|
|
|
|
native int[] gtkWidgetGetForeground ();
|
|
|
|
native int[] gtkWidgetGetBackground ();
|
|
|
|
native void gtkWidgetGetDimensions (int[] dim);
|
|
|
|
native void gtkWidgetGetPreferredDimensions (int[] dim);
|
2005-11-15 23:20:01 +00:00
|
|
|
native void gtkWindowGetLocationOnScreen (int[] point);
|
2005-07-16 00:30:23 +00:00
|
|
|
native void gtkWidgetGetLocationOnScreen (int[] point);
|
2006-05-18 17:29:21 +00:00
|
|
|
native void gtkWidgetSetCursor (int type, GtkImage image, int x, int y);
|
|
|
|
native void gtkWidgetSetCursorUnlocked (int type, GtkImage image,
|
|
|
|
int x, int y);
|
2005-07-16 00:30:23 +00:00
|
|
|
native void gtkWidgetSetBackground (int red, int green, int blue);
|
|
|
|
native void gtkWidgetSetForeground (int red, int green, int blue);
|
|
|
|
native void gtkWidgetSetSensitive (boolean sensitive);
|
|
|
|
native void gtkWidgetSetParent (ComponentPeer parent);
|
|
|
|
native void gtkWidgetRequestFocus ();
|
|
|
|
native void gtkWidgetDispatchKeyEvent (int id, long when, int mods,
|
|
|
|
int keyCode, int keyLocation);
|
|
|
|
|
|
|
|
native boolean isRealized ();
|
|
|
|
|
|
|
|
void realize ()
|
|
|
|
{
|
|
|
|
// Default implementation does nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
native void setNativeEventMask ();
|
|
|
|
|
|
|
|
void create ()
|
|
|
|
{
|
|
|
|
throw new RuntimeException ();
|
|
|
|
}
|
|
|
|
|
|
|
|
native void connectSignals ();
|
|
|
|
|
|
|
|
protected GtkComponentPeer (Component awtComponent)
|
|
|
|
{
|
|
|
|
super (awtComponent);
|
|
|
|
this.awtComponent = awtComponent;
|
|
|
|
insets = new Insets (0, 0, 0, 0);
|
|
|
|
|
|
|
|
create ();
|
|
|
|
|
|
|
|
connectSignals ();
|
|
|
|
|
|
|
|
if (awtComponent.getForeground () != null)
|
|
|
|
setForeground (awtComponent.getForeground ());
|
|
|
|
if (awtComponent.getBackground () != null)
|
|
|
|
setBackground (awtComponent.getBackground ());
|
|
|
|
if (awtComponent.getFont() != null)
|
|
|
|
setFont(awtComponent.getFont());
|
|
|
|
|
|
|
|
Component parent = awtComponent.getParent ();
|
|
|
|
|
2006-03-10 21:46:48 +00:00
|
|
|
setParentAndBounds ();
|
2005-07-16 00:30:23 +00:00
|
|
|
|
|
|
|
setNativeEventMask ();
|
|
|
|
|
|
|
|
realize ();
|
2006-05-18 17:29:21 +00:00
|
|
|
|
|
|
|
if (awtComponent.isCursorSet())
|
|
|
|
setCursor ();
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setParentAndBounds ()
|
|
|
|
{
|
|
|
|
setParent ();
|
|
|
|
|
|
|
|
setComponentBounds ();
|
|
|
|
|
|
|
|
setVisibleAndEnabled ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setParent ()
|
|
|
|
{
|
|
|
|
ComponentPeer p;
|
|
|
|
Component component = awtComponent;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
component = component.getParent ();
|
|
|
|
p = component.getPeer ();
|
|
|
|
}
|
|
|
|
while (p instanceof java.awt.peer.LightweightPeer);
|
|
|
|
|
|
|
|
if (p != null)
|
|
|
|
gtkWidgetSetParent (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the bounds of this peer's AWT Component based on dimensions
|
|
|
|
* returned by the native windowing system. Most Components impose
|
|
|
|
* their dimensions on the peers which is what the default
|
|
|
|
* implementation does. However some peers, like GtkFileDialogPeer,
|
|
|
|
* need to pass their size back to the AWT Component.
|
|
|
|
*/
|
|
|
|
void setComponentBounds ()
|
|
|
|
{
|
|
|
|
Rectangle bounds = awtComponent.getBounds ();
|
|
|
|
setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setVisibleAndEnabled ()
|
|
|
|
{
|
|
|
|
setVisible (awtComponent.isVisible ());
|
|
|
|
setEnabled (awtComponent.isEnabled ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int checkImage (Image image, int width, int height,
|
|
|
|
ImageObserver observer)
|
|
|
|
{
|
|
|
|
return getToolkit().checkImage(image, width, height, observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Image createImage (ImageProducer producer)
|
|
|
|
{
|
|
|
|
return new GtkImage (producer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Image createImage (int width, int height)
|
|
|
|
{
|
|
|
|
Image image;
|
|
|
|
if (GtkToolkit.useGraphics2D ())
|
|
|
|
image = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);
|
|
|
|
else
|
|
|
|
image = new GtkImage (width, height);
|
|
|
|
|
|
|
|
Graphics g = image.getGraphics();
|
|
|
|
g.setColor(getBackground());
|
|
|
|
g.fillRect(0, 0, width, height);
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void disable ()
|
|
|
|
{
|
|
|
|
setEnabled (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void enable ()
|
|
|
|
{
|
|
|
|
setEnabled (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ColorModel getColorModel ()
|
|
|
|
{
|
|
|
|
return ColorModel.getRGBdefault ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public FontMetrics getFontMetrics (Font font)
|
|
|
|
{
|
|
|
|
return getToolkit().getFontMetrics(font);
|
|
|
|
}
|
|
|
|
|
2006-05-18 17:29:21 +00:00
|
|
|
// getGraphics may be overridden by derived classes but it should
|
|
|
|
// never return null.
|
2005-07-16 00:30:23 +00:00
|
|
|
public Graphics getGraphics ()
|
|
|
|
{
|
|
|
|
if (GtkToolkit.useGraphics2D ())
|
|
|
|
return new GdkGraphics2D (this);
|
|
|
|
else
|
|
|
|
return new GdkGraphics (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point getLocationOnScreen ()
|
|
|
|
{
|
|
|
|
int point[] = new int[2];
|
2005-11-15 23:20:01 +00:00
|
|
|
if( this instanceof WindowPeer )
|
|
|
|
gtkWindowGetLocationOnScreen (point);
|
|
|
|
else
|
|
|
|
gtkWidgetGetLocationOnScreen (point);
|
2005-07-16 00:30:23 +00:00
|
|
|
return new Point (point[0], point[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension getMinimumSize ()
|
|
|
|
{
|
|
|
|
return minimumSize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension getPreferredSize ()
|
|
|
|
{
|
|
|
|
return preferredSize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Toolkit getToolkit ()
|
|
|
|
{
|
|
|
|
return Toolkit.getDefaultToolkit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleEvent (AWTEvent event)
|
|
|
|
{
|
|
|
|
int id = event.getID();
|
|
|
|
KeyEvent ke = null;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PaintEvent.PAINT:
|
2006-05-18 17:29:21 +00:00
|
|
|
paintComponent((PaintEvent) event);
|
|
|
|
break;
|
2005-07-16 00:30:23 +00:00
|
|
|
case PaintEvent.UPDATE:
|
2006-05-18 17:29:21 +00:00
|
|
|
updateComponent((PaintEvent) event);
|
2005-07-16 00:30:23 +00:00
|
|
|
break;
|
|
|
|
case KeyEvent.KEY_PRESSED:
|
|
|
|
ke = (KeyEvent) event;
|
|
|
|
gtkWidgetDispatchKeyEvent (ke.getID (), ke.getWhen (), ke.getModifiersEx (),
|
|
|
|
ke.getKeyCode (), ke.getKeyLocation ());
|
|
|
|
break;
|
|
|
|
case KeyEvent.KEY_RELEASED:
|
|
|
|
ke = (KeyEvent) event;
|
|
|
|
gtkWidgetDispatchKeyEvent (ke.getID (), ke.getWhen (), ke.getModifiersEx (),
|
|
|
|
ke.getKeyCode (), ke.getKeyLocation ());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 17:29:21 +00:00
|
|
|
|
|
|
|
// This method and its overrides are the only methods in the peers
|
|
|
|
// that should call awtComponent.paint.
|
|
|
|
protected void paintComponent (PaintEvent event)
|
|
|
|
{
|
|
|
|
// Do not call Component.paint if the component is not showing or
|
|
|
|
// if its bounds form a degenerate rectangle.
|
|
|
|
if (!awtComponent.isShowing()
|
|
|
|
|| (awtComponent.getWidth() < 1 || awtComponent.getHeight() < 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Creating and disposing a GdkGraphics every time paint is called
|
|
|
|
// seems expensive. However, the graphics state does not carry
|
|
|
|
// over between calls to paint, and resetting the graphics object
|
|
|
|
// may even be more costly than simply creating a new one.
|
|
|
|
Graphics g = getGraphics();
|
|
|
|
|
|
|
|
g.setClip(event.getUpdateRect());
|
|
|
|
|
|
|
|
awtComponent.paint(g);
|
|
|
|
|
|
|
|
g.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method and its overrides are the only methods in the peers
|
|
|
|
// that should call awtComponent.update.
|
|
|
|
protected void updateComponent (PaintEvent event)
|
|
|
|
{
|
|
|
|
// Do not call Component.update if the component is not showing or
|
|
|
|
// if its bounds form a degenerate rectangle.
|
|
|
|
if (!awtComponent.isShowing()
|
|
|
|
|| (awtComponent.getWidth() < 1 || awtComponent.getHeight() < 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Graphics g = getGraphics();
|
|
|
|
|
|
|
|
g.setClip(event.getUpdateRect());
|
|
|
|
|
|
|
|
awtComponent.update(g);
|
|
|
|
|
|
|
|
g.dispose();
|
|
|
|
}
|
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
public boolean isFocusTraversable ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension minimumSize ()
|
|
|
|
{
|
|
|
|
int dim[] = new int[2];
|
|
|
|
|
|
|
|
gtkWidgetGetPreferredDimensions (dim);
|
|
|
|
|
|
|
|
return new Dimension (dim[0], dim[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void paint (Graphics g)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension preferredSize ()
|
|
|
|
{
|
|
|
|
int dim[] = new int[2];
|
|
|
|
|
|
|
|
gtkWidgetGetPreferredDimensions (dim);
|
|
|
|
|
|
|
|
return new Dimension (dim[0], dim[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean prepareImage (Image image, int width, int height,
|
|
|
|
ImageObserver observer)
|
|
|
|
{
|
|
|
|
return getToolkit().prepareImage(image, width, height, observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void print (Graphics g)
|
|
|
|
{
|
|
|
|
throw new RuntimeException ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void repaint (long tm, int x, int y, int width, int height)
|
|
|
|
{
|
2006-05-18 17:29:21 +00:00
|
|
|
if (width < 1 || height < 1)
|
2005-07-16 00:30:23 +00:00
|
|
|
return;
|
|
|
|
|
2006-03-10 21:46:48 +00:00
|
|
|
if (tm <= 0)
|
|
|
|
q().postEvent(new PaintEvent(awtComponent, PaintEvent.UPDATE,
|
|
|
|
new Rectangle(x, y, width, height)));
|
|
|
|
else
|
|
|
|
RepaintTimerTask.schedule(tm, x, y, width, height, awtComponent);
|
2005-09-23 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 21:46:48 +00:00
|
|
|
/**
|
|
|
|
* Used for scheduling delayed paint updates on the event queue.
|
|
|
|
*/
|
|
|
|
private static class RepaintTimerTask extends TimerTask
|
2005-09-23 21:31:04 +00:00
|
|
|
{
|
2006-03-10 21:46:48 +00:00
|
|
|
private static final Timer repaintTimer = new Timer(true);
|
|
|
|
|
2005-09-23 21:31:04 +00:00
|
|
|
private int x, y, width, height;
|
2006-03-10 21:46:48 +00:00
|
|
|
private Component awtComponent;
|
2005-09-23 21:31:04 +00:00
|
|
|
|
2006-03-10 21:46:48 +00:00
|
|
|
RepaintTimerTask(Component c, int x, int y, int width, int height)
|
2005-09-23 21:31:04 +00:00
|
|
|
{
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
2006-03-10 21:46:48 +00:00
|
|
|
this.awtComponent = c;
|
2005-09-23 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE,
|
|
|
|
new Rectangle (x, y, width, height)));
|
|
|
|
}
|
2006-03-10 21:46:48 +00:00
|
|
|
|
|
|
|
static void schedule(long tm, int x, int y, int width, int height,
|
|
|
|
Component c)
|
|
|
|
{
|
|
|
|
repaintTimer.schedule(new RepaintTimerTask(c, x, y, width, height), tm);
|
|
|
|
}
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void requestFocus ()
|
|
|
|
{
|
|
|
|
gtkWidgetRequestFocus();
|
|
|
|
postFocusEvent(FocusEvent.FOCUS_GAINED, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reshape (int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
setBounds (x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBackground (Color c)
|
|
|
|
{
|
|
|
|
gtkWidgetSetBackground (c.getRed(), c.getGreen(), c.getBlue());
|
|
|
|
}
|
|
|
|
|
|
|
|
native void setNativeBounds (int x, int y, int width, int height);
|
|
|
|
|
|
|
|
public void setBounds (int x, int y, int width, int height)
|
|
|
|
{
|
2005-09-23 21:31:04 +00:00
|
|
|
int new_x = x;
|
|
|
|
int new_y = y;
|
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
Component parent = awtComponent.getParent ();
|
2006-03-10 21:46:48 +00:00
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
// Heavyweight components that are children of one or more
|
|
|
|
// lightweight containers have to be handled specially. Because
|
|
|
|
// calls to GLightweightPeer.setBounds do nothing, GTK has no
|
|
|
|
// knowledge of the lightweight containers' positions. So we have
|
|
|
|
// to add the offsets manually when placing a heavyweight
|
|
|
|
// component within a lightweight container. The lightweight
|
|
|
|
// container may itself be in a lightweight container and so on,
|
|
|
|
// so we need to continue adding offsets until we reach a
|
|
|
|
// container whose position GTK knows -- that is, the first
|
|
|
|
// non-lightweight.
|
2006-03-10 21:46:48 +00:00
|
|
|
Insets i;
|
|
|
|
while (parent.isLightweight())
|
2005-07-16 00:30:23 +00:00
|
|
|
{
|
2006-03-10 21:46:48 +00:00
|
|
|
i = ((Container) parent).getInsets();
|
|
|
|
|
|
|
|
new_x += parent.getX() + i.left;
|
|
|
|
new_y += parent.getY() + i.top;
|
|
|
|
|
|
|
|
parent = parent.getParent();
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
// We only need to convert from Java to GTK coordinates if we're
|
|
|
|
// placing a heavyweight component in a Window.
|
2006-03-10 21:46:48 +00:00
|
|
|
if (parent instanceof Window)
|
2005-07-16 00:30:23 +00:00
|
|
|
{
|
|
|
|
GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer ();
|
2005-09-23 21:31:04 +00:00
|
|
|
// important: we want the window peer's insets here, not the
|
|
|
|
// window's, since user sub-classes of Window can override
|
|
|
|
// getInset and we only want to correct for the frame borders,
|
|
|
|
// not for any user-defined inset values
|
|
|
|
Insets insets = peer.getInsets ();
|
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
int menuBarHeight = 0;
|
|
|
|
if (peer instanceof GtkFramePeer)
|
|
|
|
menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight ();
|
2006-03-10 21:46:48 +00:00
|
|
|
|
|
|
|
new_x -= insets.left;
|
|
|
|
new_y -= insets.top;
|
|
|
|
new_y += menuBarHeight;
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
2005-09-23 21:31:04 +00:00
|
|
|
|
|
|
|
setNativeBounds (new_x, new_y, width, height);
|
2006-03-10 21:46:48 +00:00
|
|
|
|
|
|
|
// If the height or width were (or are now) smaller than zero
|
|
|
|
// then we want to adjust the visibility.
|
|
|
|
setVisible(awtComponent.isVisible());
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setCursor ()
|
|
|
|
{
|
|
|
|
setCursor (awtComponent.getCursor ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCursor (Cursor cursor)
|
|
|
|
{
|
2006-05-18 17:29:21 +00:00
|
|
|
int x, y;
|
|
|
|
GtkImage image;
|
|
|
|
int type = cursor.getType();
|
|
|
|
if (cursor instanceof GtkCursor)
|
|
|
|
{
|
|
|
|
GtkCursor gtkCursor = (GtkCursor) cursor;
|
|
|
|
image = gtkCursor.getGtkImage();
|
|
|
|
Point hotspot = gtkCursor.getHotspot();
|
|
|
|
x = hotspot.x;
|
|
|
|
y = hotspot.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = null;
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2005-09-23 21:31:04 +00:00
|
|
|
if (Thread.currentThread() == GtkToolkit.mainThread)
|
2006-05-18 17:29:21 +00:00
|
|
|
gtkWidgetSetCursorUnlocked(cursor.getType(), image, x, y);
|
2005-09-23 21:31:04 +00:00
|
|
|
else
|
2006-05-18 17:29:21 +00:00
|
|
|
gtkWidgetSetCursor(cursor.getType(), image, x, y);
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setEnabled (boolean b)
|
|
|
|
{
|
|
|
|
gtkWidgetSetSensitive (b);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFont (Font f)
|
|
|
|
{
|
|
|
|
// FIXME: This should really affect the widget tree below me.
|
|
|
|
// Currently this is only handled if the call is made directly on
|
|
|
|
// a text widget, which implements setFont() itself.
|
|
|
|
gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setForeground (Color c)
|
|
|
|
{
|
|
|
|
gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Color getForeground ()
|
|
|
|
{
|
|
|
|
int rgb[] = gtkWidgetGetForeground ();
|
|
|
|
return new Color (rgb[0], rgb[1], rgb[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Color getBackground ()
|
|
|
|
{
|
|
|
|
int rgb[] = gtkWidgetGetBackground ();
|
|
|
|
return new Color (rgb[0], rgb[1], rgb[2]);
|
|
|
|
}
|
|
|
|
|
2005-09-23 21:31:04 +00:00
|
|
|
public native void setVisibleNative (boolean b);
|
|
|
|
public native void setVisibleNativeUnlocked (boolean b);
|
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
public void setVisible (boolean b)
|
|
|
|
{
|
2006-03-10 21:46:48 +00:00
|
|
|
// Only really set visible when component is bigger than zero pixels.
|
2006-05-18 17:29:21 +00:00
|
|
|
if (b && ! (awtComponent instanceof Window))
|
2006-03-10 21:46:48 +00:00
|
|
|
{
|
|
|
|
Rectangle bounds = awtComponent.getBounds();
|
|
|
|
b = (bounds.width > 0) && (bounds.height > 0);
|
|
|
|
}
|
|
|
|
|
2005-09-23 21:31:04 +00:00
|
|
|
if (Thread.currentThread() == GtkToolkit.mainThread)
|
|
|
|
setVisibleNativeUnlocked (b);
|
2005-07-16 00:30:23 +00:00
|
|
|
else
|
2005-09-23 21:31:04 +00:00
|
|
|
setVisibleNative (b);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hide ()
|
|
|
|
{
|
|
|
|
setVisible (false);
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
2005-09-23 21:31:04 +00:00
|
|
|
public void show ()
|
|
|
|
{
|
|
|
|
setVisible (true);
|
|
|
|
}
|
2005-07-16 00:30:23 +00:00
|
|
|
|
|
|
|
protected void postMouseEvent(int id, long when, int mods, int x, int y,
|
|
|
|
int clickCount, boolean popupTrigger)
|
|
|
|
{
|
|
|
|
q().postEvent(new MouseEvent(awtComponent, id, when, mods, x, y,
|
|
|
|
clickCount, popupTrigger));
|
|
|
|
}
|
|
|
|
|
2006-05-18 17:29:21 +00:00
|
|
|
/**
|
|
|
|
* Callback for component_scroll_cb.
|
|
|
|
*/
|
|
|
|
protected void postMouseWheelEvent(int id, long when, int mods,
|
|
|
|
int x, int y, int clickCount,
|
|
|
|
boolean popupTrigger,
|
|
|
|
int type, int amount, int rotation)
|
|
|
|
{
|
|
|
|
q().postEvent(new MouseWheelEvent(awtComponent, id, when, mods,
|
|
|
|
x, y, clickCount, popupTrigger,
|
|
|
|
type, amount, rotation));
|
|
|
|
}
|
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
protected void postExposeEvent (int x, int y, int width, int height)
|
|
|
|
{
|
2006-05-18 17:29:21 +00:00
|
|
|
q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
|
2005-07-16 00:30:23 +00:00
|
|
|
new Rectangle (x, y, width, height)));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void postKeyEvent (int id, long when, int mods,
|
|
|
|
int keyCode, char keyChar, int keyLocation)
|
|
|
|
{
|
|
|
|
KeyEvent keyEvent = new KeyEvent (awtComponent, id, when, mods,
|
|
|
|
keyCode, keyChar, keyLocation);
|
|
|
|
|
2006-03-10 21:46:48 +00:00
|
|
|
EventQueue q = q();
|
|
|
|
|
2005-07-16 00:30:23 +00:00
|
|
|
// Also post a KEY_TYPED event if keyEvent is a key press that
|
|
|
|
// doesn't represent an action or modifier key.
|
|
|
|
if (keyEvent.getID () == KeyEvent.KEY_PRESSED
|
|
|
|
&& (!keyEvent.isActionKey ()
|
|
|
|
&& keyCode != KeyEvent.VK_SHIFT
|
|
|
|
&& keyCode != KeyEvent.VK_CONTROL
|
|
|
|
&& keyCode != KeyEvent.VK_ALT))
|
|
|
|
{
|
2006-03-10 21:46:48 +00:00
|
|
|
synchronized(q)
|
|
|
|
{
|
|
|
|
q.postEvent(keyEvent);
|
|
|
|
keyEvent = new KeyEvent(awtComponent, KeyEvent.KEY_TYPED, when,
|
|
|
|
mods, KeyEvent.VK_UNDEFINED, keyChar,
|
|
|
|
keyLocation);
|
|
|
|
q.postEvent(keyEvent);
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-03-10 21:46:48 +00:00
|
|
|
q.postEvent(keyEvent);
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void postFocusEvent (int id, boolean temporary)
|
|
|
|
{
|
|
|
|
q().postEvent (new FocusEvent (awtComponent, id, temporary));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void postItemEvent (Object item, int stateChange)
|
|
|
|
{
|
|
|
|
q().postEvent (new ItemEvent ((ItemSelectable)awtComponent,
|
|
|
|
ItemEvent.ITEM_STATE_CHANGED,
|
|
|
|
item, stateChange));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void postTextEvent ()
|
|
|
|
{
|
|
|
|
q().postEvent (new TextEvent (awtComponent, TextEvent.TEXT_VALUE_CHANGED));
|
|
|
|
}
|
|
|
|
|
|
|
|
public GraphicsConfiguration getGraphicsConfiguration ()
|
|
|
|
{
|
|
|
|
// FIXME: just a stub for now.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEventMask (long mask)
|
|
|
|
{
|
|
|
|
// FIXME: just a stub for now.
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFocusable ()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean requestFocus (Component source, boolean b1,
|
|
|
|
boolean b2, long x)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isObscured ()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDetermineObscurity ()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void coalescePaintEvent (PaintEvent e)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateCursorImmediately ()
|
|
|
|
{
|
2005-09-23 21:31:04 +00:00
|
|
|
if (awtComponent.getCursor() != null)
|
|
|
|
setCursor(awtComponent.getCursor());
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean handlesWheelScrolling ()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience method to create a new volatile image on the screen
|
|
|
|
// on which this component is displayed.
|
|
|
|
public VolatileImage createVolatileImage (int width, int height)
|
|
|
|
{
|
|
|
|
return new GtkVolatileImage (width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates buffers used in a buffering strategy.
|
|
|
|
public void createBuffers (int numBuffers, BufferCapabilities caps)
|
|
|
|
throws AWTException
|
|
|
|
{
|
|
|
|
// numBuffers == 2 implies double-buffering, meaning one back
|
|
|
|
// buffer and one front buffer.
|
|
|
|
if (numBuffers == 2)
|
|
|
|
backBuffer = new GtkVolatileImage(awtComponent.getWidth(),
|
|
|
|
awtComponent.getHeight(),
|
|
|
|
caps.getBackBufferCapabilities());
|
|
|
|
else
|
|
|
|
throw new AWTException("GtkComponentPeer.createBuffers:"
|
|
|
|
+ " multi-buffering not supported");
|
|
|
|
this.caps = caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the back buffer.
|
|
|
|
public Image getBackBuffer ()
|
|
|
|
{
|
|
|
|
return backBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: flip should be implemented as a fast native operation
|
|
|
|
public void flip (BufferCapabilities.FlipContents contents)
|
|
|
|
{
|
|
|
|
getGraphics().drawImage(backBuffer,
|
|
|
|
awtComponent.getWidth(),
|
|
|
|
awtComponent.getHeight(),
|
|
|
|
null);
|
|
|
|
|
|
|
|
// create new back buffer and clear it to the background color.
|
|
|
|
if (contents == BufferCapabilities.FlipContents.BACKGROUND)
|
|
|
|
{
|
|
|
|
backBuffer = createVolatileImage(awtComponent.getWidth(),
|
|
|
|
awtComponent.getHeight());
|
|
|
|
backBuffer.getGraphics().clearRect(0, 0,
|
|
|
|
awtComponent.getWidth(),
|
|
|
|
awtComponent.getHeight());
|
|
|
|
}
|
|
|
|
// FIXME: support BufferCapabilities.FlipContents.PRIOR
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release the resources allocated to back buffers.
|
|
|
|
public void destroyBuffers ()
|
|
|
|
{
|
|
|
|
backBuffer.flush();
|
|
|
|
}
|
2005-09-23 21:31:04 +00:00
|
|
|
|
|
|
|
public String toString ()
|
|
|
|
{
|
|
|
|
return "peer of " + awtComponent.toString();
|
|
|
|
}
|
|
|
|
public Rectangle getBounds()
|
|
|
|
{
|
|
|
|
// FIXME: implement
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
public void reparent(ContainerPeer parent)
|
|
|
|
{
|
|
|
|
// FIXME: implement
|
|
|
|
|
|
|
|
}
|
|
|
|
public void setBounds(int x, int y, int width, int height, int z)
|
|
|
|
{
|
|
|
|
// FIXME: implement
|
|
|
|
setBounds (x, y, width, height);
|
|
|
|
|
|
|
|
}
|
|
|
|
public boolean isReparentSupported()
|
|
|
|
{
|
|
|
|
// FIXME: implement
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public void layout()
|
|
|
|
{
|
|
|
|
// FIXME: implement
|
|
|
|
|
|
|
|
}
|
2005-07-16 00:30:23 +00:00
|
|
|
}
|