natGtkComponentPeer.cc (getLocationOnScreen): Wrote.
* gnu/awt/gtk/natGtkComponentPeer.cc (getLocationOnScreen): Wrote. (setCursor): Wrote. Include Cursor.h. * gnu/awt/gtk/natGtkLabelPeer.cc: New file. * gnu/awt/gtk/natGtkButtonPeer.cc: New file. * gnu/awt/gtk/gtkcommon.h (class _Jv_GdkThreadLock): New class. * gnu/awt/gtk/GtkLabelPeer.java: New file. * gnu/awt/gtk/GtkButtonPeer.java: New file. From-SVN: r38967
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/* GtkButtonPeer.java -- Implements ButtonPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the peer AWT libraries of GNU Classpath.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later verion.
|
||||
|
||||
This library 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 Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; if not, write to the Free Software Foundation
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */
|
||||
|
||||
|
||||
package gnu.awt.gtk;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.peer.*;
|
||||
|
||||
public class GtkButtonPeer extends GtkComponentPeer
|
||||
implements ButtonPeer
|
||||
{
|
||||
protected native void create ();
|
||||
public native void setLabel (String label);
|
||||
|
||||
public GtkButtonPeer (Button b)
|
||||
{
|
||||
super (b);
|
||||
}
|
||||
|
||||
public void handleEvent (AWTEvent e)
|
||||
{
|
||||
// if (e.getID () == MouseEvent.MOUSE_CLICKED && isEnabled ()
|
||||
// && !modalHasGrab ())
|
||||
// {
|
||||
// MouseEvent me = (MouseEvent) e;
|
||||
// if (!me.isConsumed ()
|
||||
// && (me.getModifiers () & MouseEvent.BUTTON1_MASK) != 0)
|
||||
// postActionEvent (((Button)awtComponent).getActionCommand (),
|
||||
// me.getModifiers ());
|
||||
// }
|
||||
|
||||
// if (e.getID () == KeyEvent.KEY_PRESSED)
|
||||
// {
|
||||
// KeyEvent ke = (KeyEvent) e;
|
||||
// if (!ke.isConsumed () && ke.getKeyCode () == KeyEvent.VK_SPACE)
|
||||
// postActionEvent (((Button)awtComponent).getActionCommand (),
|
||||
// ke.getModifiers ());
|
||||
// }
|
||||
|
||||
super.handleEvent (e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/* GtkLabelPeer.java -- Implements LabelPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the peer AWT libraries of GNU Classpath.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later verion.
|
||||
|
||||
This library 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 Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; if not, write to the Free Software Foundation
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */
|
||||
|
||||
|
||||
package gnu.awt.gtk;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.peer.*;
|
||||
|
||||
public class GtkLabelPeer extends GtkComponentPeer
|
||||
implements LabelPeer
|
||||
{
|
||||
public GtkLabelPeer (Label l)
|
||||
{
|
||||
super (l);
|
||||
}
|
||||
|
||||
public native void setText (String text);
|
||||
public native void setAlignment (int alignment);
|
||||
protected native void create ();
|
||||
}
|
||||
@@ -17,6 +17,20 @@ details. */
|
||||
|
||||
#include <java/awt/Color.h>
|
||||
|
||||
class _Jv_GdkThreadLock
|
||||
{
|
||||
public:
|
||||
_Jv_GdkThreadLock ()
|
||||
{
|
||||
GDK_THREADS_ENTER ();
|
||||
}
|
||||
|
||||
~_Jv_GdkThreadLock ()
|
||||
{
|
||||
GDK_THREADS_LEAVE ();
|
||||
}
|
||||
};
|
||||
|
||||
// Convert AWT Color to gdk color value.
|
||||
static inline void
|
||||
_Jv_ConvertAwtColor(java::awt::Color* awtcolor, GdkColor* gdkcolor)
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Native Gtk AWT button code
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <gcj/cni.h>
|
||||
|
||||
#include "gtkcommon.h"
|
||||
#include <gnu/awt/gtk/GtkButtonPeer.h>
|
||||
#include <java/awt/Button.h>
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkButtonPeer::setLabel (java::lang::String *label)
|
||||
{
|
||||
_Jv_GdkThreadLock sync;
|
||||
jsize len = 0;
|
||||
if (label)
|
||||
len = JvGetStringUTFLength (label);
|
||||
char buf[len + 1];
|
||||
// FIXME: this can allocate an unbounded amount. Should use heap
|
||||
// even though it is slower.
|
||||
if (label)
|
||||
JvGetStringUTFRegion (label, 0, len, buf);
|
||||
buf[len] = '\0';
|
||||
// The button child is a label.
|
||||
GtkBin *bin = GTK_BIN (ptr);
|
||||
gtk_label_set_text (GTK_LABEL (bin->child), buf);
|
||||
}
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkButtonPeer::create ()
|
||||
{
|
||||
if (! ptr)
|
||||
{
|
||||
_Jv_GdkThreadLock sync;
|
||||
// This is a little inefficient.
|
||||
ptr = (gnu::gcj::RawData *) gtk_button_new_with_label ("");
|
||||
|
||||
using namespace ::java::awt;
|
||||
Button *button = reinterpret_cast<Button *> (awtComponent);
|
||||
setLabel (button->getLabel ());
|
||||
}
|
||||
|
||||
gnu::awt::gtk::GtkComponentPeer::create ();
|
||||
}
|
||||
|
||||
// void
|
||||
// gnu::awt::gtk::GtkButtonPeer::clicked (::gnu::gcj::RawData *button_wrap,
|
||||
// ::gnu::gcj::RawData *peer_wrap)
|
||||
// {
|
||||
// GtkButtonPeer *button = reinterpret_cast<GtkButtonPeer *> (peer_wrap);
|
||||
|
||||
// }
|
||||
@@ -5,15 +5,19 @@
|
||||
// Be aware: running `gcjh -stubs ' once more for this class may
|
||||
// overwrite any edits you have made to this file.
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <gcj/cni.h>
|
||||
|
||||
#include <java/awt/Point.h>
|
||||
#include <java/awt/Dimension.h>
|
||||
|
||||
#include <gnu/awt/gtk/GtkComponentPeer.h>
|
||||
#include <gcj/cni.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <java/awt/Cursor.h>
|
||||
|
||||
#include "gtkcommon.h"
|
||||
|
||||
#include <gnu/awt/gtk/GtkComponentPeer.h>
|
||||
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkComponentPeer::dispose ()
|
||||
{
|
||||
@@ -26,12 +30,10 @@ gnu::awt::gtk::GtkComponentPeer::dispose ()
|
||||
::java::awt::Point *
|
||||
gnu::awt::gtk::GtkComponentPeer::getLocationOnScreen ()
|
||||
{
|
||||
GDK_THREADS_ENTER ();
|
||||
GDK_THREADS_LEAVE ();
|
||||
|
||||
// FIXME
|
||||
|
||||
return NULL;
|
||||
gint x, y;
|
||||
_Jv_GdkThreadLock sync;
|
||||
gdk_window_get_root_origin (GTK_WIDGET (ptr)->window, &x, &y);
|
||||
return new ::java::awt::Point (x, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,9 +88,67 @@ gnu::awt::gtk::GtkComponentPeer::setBounds (jint x, jint y,
|
||||
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkComponentPeer::setCursor (::java::awt::Cursor *)
|
||||
gnu::awt::gtk::GtkComponentPeer::setCursor (::java::awt::Cursor *cursor)
|
||||
{
|
||||
// JvFail ("gnu::awt::gtk::GtkComponentPeer::setCursor (::java::awt::Cursor *) not implemented");
|
||||
GdkCursorType type;
|
||||
|
||||
switch (cursor->type)
|
||||
{
|
||||
case ::java::awt::Cursor::CROSSHAIR_CURSOR:
|
||||
type = GDK_CROSSHAIR;
|
||||
break;
|
||||
case ::java::awt::Cursor::TEXT_CURSOR:
|
||||
type = GDK_XTERM;
|
||||
break;
|
||||
case ::java::awt::Cursor::WAIT_CURSOR:
|
||||
type = GDK_WATCH;
|
||||
break;
|
||||
case ::java::awt::Cursor::SW_RESIZE_CURSOR:
|
||||
type = GDK_BOTTOM_LEFT_CORNER;
|
||||
break;
|
||||
case ::java::awt::Cursor::SE_RESIZE_CURSOR:
|
||||
type = GDK_BOTTOM_RIGHT_CORNER;
|
||||
break;
|
||||
case ::java::awt::Cursor::NW_RESIZE_CURSOR:
|
||||
type = GDK_TOP_LEFT_CORNER;
|
||||
break;
|
||||
case ::java::awt::Cursor::NE_RESIZE_CURSOR:
|
||||
type = GDK_TOP_RIGHT_CORNER;
|
||||
break;
|
||||
case ::java::awt::Cursor::N_RESIZE_CURSOR:
|
||||
type = GDK_TOP_SIDE;
|
||||
break;
|
||||
case ::java::awt::Cursor::S_RESIZE_CURSOR:
|
||||
type = GDK_RIGHT_SIDE;
|
||||
break;
|
||||
case ::java::awt::Cursor::W_RESIZE_CURSOR:
|
||||
type = GDK_LEFT_SIDE;
|
||||
break;
|
||||
case ::java::awt::Cursor::E_RESIZE_CURSOR:
|
||||
type = GDK_BOTTOM_SIDE;
|
||||
break;
|
||||
case ::java::awt::Cursor::HAND_CURSOR:
|
||||
type = GDK_HAND1;
|
||||
break;
|
||||
case ::java::awt::Cursor::MOVE_CURSOR:
|
||||
type = GDK_FLEUR;
|
||||
break;
|
||||
case ::java::awt::Cursor::CUSTOM_CURSOR:
|
||||
// FIXME: not implemented yet. We want a gtk-specific subclass
|
||||
// of Cursor which holds a new gdk cursor. For now, fall
|
||||
// through.
|
||||
|
||||
case ::java::awt::Cursor::DEFAULT_CURSOR:
|
||||
default:
|
||||
type = GDK_LEFT_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
_Jv_GdkThreadLock sync;
|
||||
GtkWidget *widget = GTK_WIDGET (ptr);
|
||||
GdkCursor *cursor = gdk_cursor_new (type);
|
||||
gdk_window_set_cursor (widget->window, cursor);
|
||||
gdk_cursor_destroy (cursor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Native Gtk AWT label code.
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <gcj/cni.h>
|
||||
|
||||
#include "gtkcommon.h"
|
||||
|
||||
#include <gnu/awt/gtk/GtkLabelPeer.h>
|
||||
#include <java/awt/Label.h>
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkLabelPeer::setText (java::lang::String *text)
|
||||
{
|
||||
_Jv_GdkThreadLock sync;
|
||||
jsize len = 0;
|
||||
if (text)
|
||||
len = JvGetStringUTFLength (text);
|
||||
// FIXME: this can allocate an unbounded amount. Should use heap
|
||||
// even though it is slower.
|
||||
char buf[len + 1];
|
||||
if (text)
|
||||
JvGetStringUTFRegion (text, 0, len, buf);
|
||||
buf[len] = '\0';
|
||||
gtk_label_set_text (GTK_LABEL (ptr), buf);
|
||||
}
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkLabelPeer::setAlignment (jint alignment)
|
||||
{
|
||||
using namespace java::awt;
|
||||
|
||||
gfloat value = 0.5;
|
||||
if (alignment == Label::LEFT)
|
||||
value = 0.0;
|
||||
else if (alignment == Label::RIGHT)
|
||||
value = 1.0;
|
||||
|
||||
_Jv_GdkThreadLock sync;
|
||||
gtk_misc_set_alignment (GTK_MISC (ptr), 0.5f, value);
|
||||
}
|
||||
|
||||
void
|
||||
gnu::awt::gtk::GtkLabelPeer::create ()
|
||||
{
|
||||
if (! ptr)
|
||||
{
|
||||
_Jv_GdkThreadLock sync;
|
||||
// This is a little inefficient.
|
||||
ptr = (gnu::gcj::RawData *) gtk_label_new ("");
|
||||
|
||||
using namespace ::java::awt;
|
||||
Label *label = reinterpret_cast<Label *> (awtComponent);
|
||||
setText (label->getText ());
|
||||
setAlignment (label->getAlignment ());
|
||||
}
|
||||
|
||||
gnu::awt::gtk::GtkComponentPeer::create ();
|
||||
}
|
||||
Reference in New Issue
Block a user