From 0acff4bc96a94ae54d1ab69991102dfcc76607e6 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Mon, 2 Oct 2000 06:14:25 +0100 Subject: prims.cc (_Jv_argv, _Jv_argc): New fields. 2000-10-02 Bryce McKinlay * prims.cc (_Jv_argv, _Jv_argc): New fields. (JvRunMain): Set _Jv_argv and _Jv_argc. * java/awt/Component.java: Minor fixes. * java/awt/Image.java (UndefinedProperty): Initialize final field. * java/awt/Toolkit.java (systemEventQueue): Removed. (getDefaultToolkit): Default to "gnu.awt.gtk.GtkToolkit". * java/awt/Window.java (getToolkit): Don't call super. * java/awt/image/BufferedImage.java: Fix definate assignment errors. * java/awt/peer/ContainerPeer.java (insets): Remove unused method. * gnu/awt/gtk/GtkComponentPeer.java: New file. * gnu/awt/gtk/GtkContainerPeer.java: New file. * gnu/awt/gtk/GtkFramePeer.java: New file. * gnu/awt/gtk/GtkMainThread.java: New file. * gnu/awt/gtk/GtkToolkit.java: New file. * gnu/awt/gtk/GtkWindowPeer.java: New file. * gnu/awt/gtk/gtkcommon.cc: New file. * gnu/awt/gtk/gtkcommon.h: New file. * gnu/awt/gtk/natGtkComponentPeer.cc: New file. * gnu/awt/gtk/natGtkContainerPeer.cc: New file. * gnu/awt/gtk/natGtkFramePeer.cc: New file. * gnu/awt/gtk/natGtkMainThread.cc: New file. * gnu/awt/gtk/natGtkToolkit.cc: New file. * gnu/awt/gtk/natGtkWindowPeer.cc: New file. From-SVN: r36688 --- libjava/gnu/awt/gtk/GtkComponentPeer.java | 269 ++++++++++++++++++++++++ libjava/gnu/awt/gtk/GtkContainerPeer.java | 55 +++++ libjava/gnu/awt/gtk/GtkFramePeer.java | 42 ++++ libjava/gnu/awt/gtk/GtkMainThread.java | 36 ++++ libjava/gnu/awt/gtk/GtkToolkit.java | 314 +++++++++++++++++++++++++++++ libjava/gnu/awt/gtk/GtkWindowPeer.java | 39 ++++ libjava/gnu/awt/gtk/gtkcommon.cc | 14 ++ libjava/gnu/awt/gtk/gtkcommon.h | 71 +++++++ libjava/gnu/awt/gtk/natGtkComponentPeer.cc | 205 +++++++++++++++++++ libjava/gnu/awt/gtk/natGtkContainerPeer.cc | 15 ++ libjava/gnu/awt/gtk/natGtkFramePeer.cc | 51 +++++ libjava/gnu/awt/gtk/natGtkMainThread.cc | 22 ++ libjava/gnu/awt/gtk/natGtkToolkit.cc | 75 +++++++ libjava/gnu/awt/gtk/natGtkWindowPeer.cc | 40 ++++ 14 files changed, 1248 insertions(+) create mode 100644 libjava/gnu/awt/gtk/GtkComponentPeer.java create mode 100644 libjava/gnu/awt/gtk/GtkContainerPeer.java create mode 100644 libjava/gnu/awt/gtk/GtkFramePeer.java create mode 100644 libjava/gnu/awt/gtk/GtkMainThread.java create mode 100644 libjava/gnu/awt/gtk/GtkToolkit.java create mode 100644 libjava/gnu/awt/gtk/GtkWindowPeer.java create mode 100644 libjava/gnu/awt/gtk/gtkcommon.cc create mode 100644 libjava/gnu/awt/gtk/gtkcommon.h create mode 100644 libjava/gnu/awt/gtk/natGtkComponentPeer.cc create mode 100644 libjava/gnu/awt/gtk/natGtkContainerPeer.cc create mode 100644 libjava/gnu/awt/gtk/natGtkFramePeer.cc create mode 100644 libjava/gnu/awt/gtk/natGtkMainThread.cc create mode 100644 libjava/gnu/awt/gtk/natGtkToolkit.cc create mode 100644 libjava/gnu/awt/gtk/natGtkWindowPeer.cc (limited to 'libjava/gnu/awt') diff --git a/libjava/gnu/awt/gtk/GtkComponentPeer.java b/libjava/gnu/awt/gtk/GtkComponentPeer.java new file mode 100644 index 0000000..c2e1c53 --- /dev/null +++ b/libjava/gnu/awt/gtk/GtkComponentPeer.java @@ -0,0 +1,269 @@ +/* GtkComponentPeer.java -- Implements ComponentPeer 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.*; +import java.awt.image.*; +import java.awt.peer.ComponentPeer; + +public abstract class GtkComponentPeer implements ComponentPeer +{ + // We need to put a reference to the Event Queue somewhere. This seems like + // a convenient place. + static EventQueue eventQueue = new EventQueue(); + + Component awtComponent; + gnu.gcj.RawData ptr; // Actual gtk object. + + static + { + // This will start the main toolkit thread. + GtkToolkit.instance.init(); + } + + public int checkImage (Image image, int width, int height, + ImageObserver observer) + { + return -1; + /* + GtkImage i = (GtkImage) image; + return i.checkImage (); + */ + } + + public Image createImage (ImageProducer producer) + { + return null; + //return new GtkImage (producer, null); + } + + public Image createImage (int width, int height) + { + return null; + /* + GdkGraphics g = new GdkGraphics (width, height); + return new GtkOffScreenImage (null, g, width, height); + */ + } + + public void disable () + { + setEnabled (false); + } + + native public void dispose (); + + public void enable () + { + setEnabled (true); + } + + /** + * Get the graphics configuration of the component. The color model + * of the component can be derived from the configuration. + */ + public GraphicsConfiguration getGraphicsConfiguration () + { + return null; + } + + public FontMetrics getFontMetrics (Font font) + { + return null; + //return new GdkFontMetrics (font); + } + + public Graphics getGraphics () + { + throw new InternalError (); + } + + public native Point getLocationOnScreen (); + public native Dimension getMinimumSize(); + public native Dimension getPreferredSize(); + + public Toolkit getToolkit () + { + return GtkToolkit.instance; + } + + public void handleEvent(AWTEvent e) + { + } + + public void hide () + { + setVisible (false); + } + + public void show () + { + setVisible (true); + } + + public boolean isFocusTraversable () + { + return true; + } + + public Dimension minimumSize () + { + return getMinimumSize(); + } + + public Dimension preferredSize() + { + return getPreferredSize(); + } + + public void paint (Graphics g) + { + awtComponent.paint (g); // ??? + } + + public boolean prepareImage (Image image, int width, int height, + ImageObserver observer) + { + /* + GtkImage i = (GtkImage) image; + + if (i.isLoaded ()) return true; + + class PrepareImage extends Thread + { + GtkImage image; + ImageObserver observer; + + PrepareImage (GtkImage image, ImageObserver observer) + { + this.image = image; + this.observer = observer; + } + + public void run () + { + // XXX: need to return data to image observer + image.source.startProduction (null); + } + } + + new PrepareImage (i, observer).start (); + */ + return false; + } + + public void print (Graphics g) + { + throw new RuntimeException (); + } + + native public void requestFocus (); + + public void repaint (long tm, int x, int y, int width, int height) + { + // ??? + eventQueue.postEvent (new PaintEvent ( + awtComponent, PaintEvent.UPDATE, new Rectangle (x, y, width, height))); + } + + + public void reshape (int x, int y, int width, int height) + { + setBounds (x, y, width, height); + } + + public native void setBounds (int x, int y, int width, int height); + public native void setCursor (Cursor cursor); + + public native void setEnabled (boolean b); + + public native void setEventMask(long eventMask); + public native void setFont(Font font); + public native void setForeground(Color color); + public native void setBackground (Color c); + public native void setVisible(boolean visible); + + native void realize(); + + protected GtkComponentPeer (Component awtComponent) + { + this.awtComponent = awtComponent; + create(); + + // TODO: Each of these calls will currently perform a separate native lock. + // It may be desirable to use our own, recusive mutex implementation by + // passing our threads implementation to g_threads_init(). + // This would greatly reduce locking calls in the peer code, and allow us + // to aquire the lock from java code. + Rectangle r = awtComponent.getBounds(); + setBounds (r.x, r.y, r.width, r.height); + + Color c = awtComponent.getForeground(); + if (c != null) + setForeground (c); + c = awtComponent.getBackground(); + if (c != null) + setBackground (c); + setEnabled (awtComponent.isEnabled()); + Font f = awtComponent.getFont(); + if (f != null) + setFont (awtComponent.getFont()); + + realize(); + } + + protected native void create (); + + // FIXME: It may make sense to do the following directly from the native + // code. + protected void postMouseEvent(int id, long when, int mods, int x, int y, + int clickCount, boolean popupTrigger) + { + eventQueue.postEvent(new MouseEvent(awtComponent, id, when, mods, x, y, + clickCount, popupTrigger)); + } + + protected void postExposeEvent (int x, int y, int width, int height) + { + eventQueue.postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, + new Rectangle (x, y, width, height))); + } + + protected void postKeyEvent (int id, long when, int mods, + int keyCode, char keyChar) + { + eventQueue.postEvent (new KeyEvent (awtComponent, id, when, mods, + keyCode, keyChar)); + } + + protected void postFocusEvent (int id, boolean temporary) + { + eventQueue.postEvent (new FocusEvent (awtComponent, id, temporary)); + } + + protected void postItemEvent (Object item, int stateChange) + { + eventQueue.postEvent (new ItemEvent ((ItemSelectable)awtComponent, + ItemEvent.ITEM_STATE_CHANGED, + item, stateChange)); + } +} diff --git a/libjava/gnu/awt/gtk/GtkContainerPeer.java b/libjava/gnu/awt/gtk/GtkContainerPeer.java new file mode 100644 index 0000000..2a654da --- /dev/null +++ b/libjava/gnu/awt/gtk/GtkContainerPeer.java @@ -0,0 +1,55 @@ +/* GtkContainerPeer.java -- Implements ContainerPeer 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.*; +import java.awt.peer.ContainerPeer; + +public abstract class GtkContainerPeer extends GtkComponentPeer + implements ContainerPeer +{ + // FIXME? + static Insets insets = new Insets(0,0,0,0); + + protected GtkContainerPeer (Container awtContainer) + { + super (awtContainer); + } + + public Insets getInsets() + { + // FIXME? + return insets; + } + + public void beginValidate() + { + // FIXME + } + + public void endValidate() + { + // FIXME + } + + protected native void create(); +} diff --git a/libjava/gnu/awt/gtk/GtkFramePeer.java b/libjava/gnu/awt/gtk/GtkFramePeer.java new file mode 100644 index 0000000..83ff613 --- /dev/null +++ b/libjava/gnu/awt/gtk/GtkFramePeer.java @@ -0,0 +1,42 @@ +/* GtkFramePeer.java -- Implements FramePeer 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.*; +import java.awt.peer.FramePeer; + +public class GtkFramePeer extends GtkWindowPeer + implements FramePeer +{ + protected GtkFramePeer (Frame awtFrame) + { + super (awtFrame); + //init (); + } + + public native void setIconImage(Image image); + public native void setMenuBar(MenuBar mb); + public native void setResizable(boolean resizable); + public native void setTitle(String title); + + protected native void create(); +} diff --git a/libjava/gnu/awt/gtk/GtkMainThread.java b/libjava/gnu/awt/gtk/GtkMainThread.java new file mode 100644 index 0000000..1822457 --- /dev/null +++ b/libjava/gnu/awt/gtk/GtkMainThread.java @@ -0,0 +1,36 @@ +/* GtkMainThread.java -- Runs gtk_main() + 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; + +public class GtkMainThread extends Thread +{ + native void gtkMain(); + + public GtkMainThread() + { + super ("GtkMain"); + } + + public void run() + { + gtkMain(); + } +} diff --git a/libjava/gnu/awt/gtk/GtkToolkit.java b/libjava/gnu/awt/gtk/GtkToolkit.java new file mode 100644 index 0000000..18833b8 --- /dev/null +++ b/libjava/gnu/awt/gtk/GtkToolkit.java @@ -0,0 +1,314 @@ +/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers + 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.net.*; +import java.util.Hashtable; +import java.util.Properties; +import java.util.MissingResourceException; +import java.awt.datatransfer.*; +import java.awt.image.*; +import java.awt.peer.*; + +public class GtkToolkit extends java.awt.Toolkit +{ + static GtkMainThread gtkthread; + static EventQueue evtqueue; + static Hashtable containers = new Hashtable(); + static Clipboard systemClipboard; + static GtkToolkit instance = null; + + public GtkToolkit () + { + gtkInit(); + instance = this; + //systemClipboard = new GtkClipboard (); + } + + // Start the thread to run the GTK event loop. This is called from + // a GtkComponentPeer static initializer. + void init () + { + gtkthread = new GtkMainThread (); + gtkthread.start(); + } + + static native void gtkInit(); + + native public void beep (); + + public int checkImage (Image image, int width, int height, + ImageObserver observer) + { + return ImageObserver.ALLBITS; + +// GtkImage i = (GtkImage) image; +// return i.checkImage (); + } + + public Image createImage(String filename) + { + return null; + } + + public Image createImage(URL url) + { + return null; + } + + public Image createImage (ImageProducer producer) + { +// return new GtkImage (producer, null); + return null; + } + + public Image createImage (byte[] imagedata, int imageoffset, + int imagelength) + { + System.out.println ("createImage byte[] NOT SUPPORTED"); + return null; + } + + public ColorModel getColorModel () + { + return ColorModel.getRGBdefault (); + } + + public String[] getFontList () + { + return (new String[] { "Dialog", + "DialogInput", + "Monospaced", + "Serif", + "SansSerif" }); + } + + public FontMetrics getFontMetrics (Font font) + { +// return new GdkFontMetrics (font); + return null; + } + + public Image getImage (String filename) + { +// return new GtkImage (new GdkPixbufDecoder (filename), null); + return null; + } + + public Image getImage (URL url) + { +// return new GtkImage (new GdkPixbufDecoder (url), null); + return null; + } + + /* + public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props) + { + return null; + } + */ + native public int getScreenResolution(); + + native public Dimension getScreenSize (); + + public Clipboard getSystemClipboard() + { + return systemClipboard; + } + + public boolean prepareImage (Image image, int width, int height, + ImageObserver observer) + { + return false; + } + + native public void sync (); + + protected void setComponentState (Component c, GtkComponentPeer cp) + { + /* Make the Peer reflect the state of the Component */ + if (! (c instanceof Window)) + { + cp.setCursor (c.getCursor ()); + + Rectangle bounds = c.getBounds (); + cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height); + if (c instanceof Canvas) + System.out.println ("width " + bounds.width + " height " + bounds.height); + + cp.setVisible (c.isVisible ()); + } + } + + protected ButtonPeer createButton (Button b) + { + return null; + /* + GtkButtonPeer bp = new GtkButtonPeer (b); + Rectangle bounds = b.getBounds (); + bp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height); + return bp; + */ + } + + protected CanvasPeer createCanvas (Canvas c) + { +// return new GtkCanvasPeer (c); + return null; + } + + protected CheckboxPeer createCheckbox (Checkbox cb) + { + return null; + /* + if (cb.getCheckboxGroup () != null) + return new GtkRadioButtonPeer (cb); + else + return new GtkCheckButtonPeer (cb); + */ + } + + protected CheckboxMenuItemPeer createCheckboxMenuItem (CheckboxMenuItem cmi) + { + return null; + //return new GtkCheckboxMenuItemPeer (cmi); + } + + protected ChoicePeer createChoice (Choice c) + { + return null; + //return new GtkChoicePeer (c); + } + + protected DialogPeer createDialog (Dialog d) + { + return null; + //return new GtkDialogPeer (d); + } + + protected FileDialogPeer createFileDialog (FileDialog fd) + { + return null; + //return new GtkFileDialogPeer (fd); + } + + protected FramePeer createFrame (Frame f) + { + return new GtkFramePeer (f); + } + + protected LabelPeer createLabel (Label label) + { + return null; + //return new GtkLabelPeer (label); + } + + protected ListPeer createList (List list) + { + return null; + //return new GtkListPeer (list); + } + + protected MenuPeer createMenu (Menu m) + { + return null; + //return new GtkMenuPeer (m); + } + + protected MenuBarPeer createMenuBar (MenuBar mb) + { + return null; + //return new GtkMenuBarPeer (mb); + } + + protected MenuItemPeer createMenuItem (MenuItem mi) + { + return null; + //return new GtkMenuItemPeer (mi); + } + + protected PanelPeer createPanel (Panel p) + { + return null; + //return new GtkPanelPeer (p); + } + + protected PopupMenuPeer createPopupMenu (PopupMenu target) + { + return null; + //return new GtkPopupMenuPeer (target); + } + + protected ScrollPanePeer createScrollPane (ScrollPane sp) + { + return null; + //return new GtkScrollPanePeer (sp); + } + + protected ScrollbarPeer createScrollbar (Scrollbar sb) + { + return null; + //return new GtkScrollbarPeer (sb); + } + + protected TextAreaPeer createTextArea (TextArea ta) + { + return null; + //return new GtkTextAreaPeer (ta); + } + + protected TextFieldPeer createTextField (TextField tf) + { + return null; + //return new GtkTextFieldPeer (tf); + } + + protected WindowPeer createWindow (Window w) + { + return new GtkWindowPeer (w); + } + + protected FontPeer getFontPeer (String name, int style) + { + return null; + /* + try + { + GtkFontPeer fp = new GtkFontPeer (name, style); + return fp; + } + catch (MissingResourceException ex) + { + return null; + } + */ + } + + protected EventQueue getSystemEventQueueImpl() + { + return GtkComponentPeer.eventQueue; + } + + protected void loadSystemColors (int[] systemColors) + { + } +} diff --git a/libjava/gnu/awt/gtk/GtkWindowPeer.java b/libjava/gnu/awt/gtk/GtkWindowPeer.java new file mode 100644 index 0000000..022fecc --- /dev/null +++ b/libjava/gnu/awt/gtk/GtkWindowPeer.java @@ -0,0 +1,39 @@ +/* GtkWindowPeer.java -- Implements WindowPeer 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.*; +import java.awt.peer.WindowPeer; + +public class GtkWindowPeer extends GtkContainerPeer + implements WindowPeer +{ + protected GtkWindowPeer (Window awtWindow) + { + super (awtWindow); + } + + public native void toBack(); + public native void toFront(); + + protected native void create(); +} diff --git a/libjava/gnu/awt/gtk/gtkcommon.cc b/libjava/gnu/awt/gtk/gtkcommon.cc new file mode 100644 index 0000000..6a12130 --- /dev/null +++ b/libjava/gnu/awt/gtk/gtkcommon.cc @@ -0,0 +1,14 @@ +// -*- c++ -*- +// gtkutils.cc - Common functions for the gtk AWT peers. + +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include + +#include "gtkcommon.h" diff --git a/libjava/gnu/awt/gtk/gtkcommon.h b/libjava/gnu/awt/gtk/gtkcommon.h new file mode 100644 index 0000000..4e9c430 --- /dev/null +++ b/libjava/gnu/awt/gtk/gtkcommon.h @@ -0,0 +1,71 @@ +// -*- c++ -*- +// gtkutils.h - Common defines and inline functions for the gtk AWT peers. + +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#ifndef __GTKCOMMON_H__ +#define __GTKCOMMON_H__ + +#include +#include + +#include + +// Convert AWT Color to gdk color value. +static inline void +_Jv_ConvertAwtColor(java::awt::Color* awtcolor, GdkColor* gdkcolor) +{ + jint rgb = awtcolor->getRGB(); + gushort r = (rgb >> 16) & 0xFF; + gushort g = (rgb >> 8) & 0xFF; + gushort b = rgb & 0xFF; + + gdkcolor->red = (r << 8) + r; + gdkcolor->green = (g << 8) + g; + gdkcolor->blue = (b << 8) + b; + + // FIXME: Deal with colormap? gdk_color_alloc()? +} + +// Convert gdk color value to AWT Color. +static inline java::awt::Color* +_Jv_ConvertGtkColor (GdkColor* gdkcolor) +{ + jint r = gdkcolor->red >> 8; + jint g = gdkcolor->green >> 8; + jint b = gdkcolor->blue >> 8; + + java::awt::Color *c = new java::awt::Color(r,g,b); + + return c; +} + +static inline void +_Jv_GdkScaleColor (GdkColor* oldc, GdkColor* newc, gfloat scale) +{ + // FIXME: Need to deal with overflows or find a better way + *newc = *oldc; + newc->red += (gushort) (newc->red * scale); + newc->green += (gushort) (newc->green * scale); + newc->blue += (gushort) (newc->blue * scale); +} + +// Normally the X queue gets flushed automatically when gtk's event loop goes +// idle. However, some calls do not cause any activitity on the event loop, +// so we need to occasionally flush pending requests manually because we arn't +// running from the gtk_main thread. Note that gdk_flush calls XSync(), which +// is more than what is needed here. +static inline void +_Jv_FlushRequests () +{ + // FIXME: What about platforms that arn't X? + XFlush (GDK_DISPLAY ()); +} + +#endif /* __GTKUTILS_H__ */ diff --git a/libjava/gnu/awt/gtk/natGtkComponentPeer.cc b/libjava/gnu/awt/gtk/natGtkComponentPeer.cc new file mode 100644 index 0000000..fea3ca0 --- /dev/null +++ b/libjava/gnu/awt/gtk/natGtkComponentPeer.cc @@ -0,0 +1,205 @@ +// This file was created by `gcjh -stubs'. -*- c++ -*- +// +// This file is intended to give you a head start on implementing native +// methods using CNI. +// Be aware: running `gcjh -stubs ' once more for this class may +// overwrite any edits you have made to this file. + +#include +#include + +#include +#include +#include + +#include "gtkcommon.h" + +void +gnu::awt::gtk::GtkComponentPeer::dispose () +{ + GDK_THREADS_ENTER (); + gtk_widget_destroy (GTK_WIDGET (ptr)); + GDK_THREADS_LEAVE (); +} + + +::java::awt::Point * +gnu::awt::gtk::GtkComponentPeer::getLocationOnScreen () +{ + GDK_THREADS_ENTER (); + GDK_THREADS_LEAVE (); + + // FIXME + + return NULL; +} + + +::java::awt::Dimension * +gnu::awt::gtk::GtkComponentPeer::getMinimumSize () +{ + GtkRequisition req; + ::java::awt::Dimension *dim = new ::java::awt::Dimension (); + + GDK_THREADS_ENTER (); + + gtk_widget_size_request (GTK_WIDGET (ptr), &req); + + GDK_THREADS_LEAVE (); + + dim->width = (jint) req.width; + dim->height = (jint) req.height; + return dim; +} + + +::java::awt::Dimension * +gnu::awt::gtk::GtkComponentPeer::getPreferredSize () +{ + return getMinimumSize (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::requestFocus () +{ + GDK_THREADS_ENTER (); + + gtk_widget_grab_focus (GTK_WIDGET (ptr)); + + GDK_THREADS_LEAVE (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::setBounds (jint x, jint y, + jint width, jint height) +{ + GDK_THREADS_ENTER (); + + GtkWidget *widget = GTK_WIDGET (ptr); + gtk_widget_set_usize (widget, width, height); + //gtk_layout_move (GTK_LAYOUT (widget->parent), widget, x, y); + + GDK_THREADS_LEAVE (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::setCursor (::java::awt::Cursor *) +{ +// JvFail ("gnu::awt::gtk::GtkComponentPeer::setCursor (::java::awt::Cursor *) not implemented"); +} + + +void +gnu::awt::gtk::GtkComponentPeer::setEnabled (jboolean enabled) +{ + GDK_THREADS_ENTER (); + + gtk_widget_set_sensitive (GTK_WIDGET (ptr), enabled); + + GDK_THREADS_LEAVE (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::setEventMask (jlong) +{ + // TODO +} + + +void +gnu::awt::gtk::GtkComponentPeer::setFont (::java::awt::Font *) +{ + // TODO +} + + +void +gnu::awt::gtk::GtkComponentPeer::setForeground (::java::awt::Color *color) +{ + // FIXME: This doesn't work if component is already realized/visible + + GdkColor gcolor; + _Jv_ConvertAwtColor(color, &gcolor); + + GDK_THREADS_ENTER (); + + GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (ptr)); + + style->bg[GTK_STATE_NORMAL] = gcolor; + style->bg[GTK_STATE_ACTIVE] = gcolor; + style->bg[GTK_STATE_PRELIGHT] = gcolor; + style->bg[GTK_STATE_SELECTED] = gcolor; + style->bg[GTK_STATE_INSENSITIVE] = gcolor; + + gtk_widget_set_style (GTK_WIDGET (ptr), style); + + GDK_THREADS_LEAVE (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::setBackground (::java::awt::Color *color) +{ + // FIXME: This doesn't work if component is already realized/visible + + GdkColor gcolor; + _Jv_ConvertAwtColor(color, &gcolor); + + GDK_THREADS_ENTER (); + + GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (ptr)); + + style->bg[GTK_STATE_NORMAL] = gcolor; + style->bg[GTK_STATE_ACTIVE] = gcolor; + style->bg[GTK_STATE_PRELIGHT] = gcolor; + style->bg[GTK_STATE_SELECTED] = gcolor; + style->bg[GTK_STATE_INSENSITIVE] = gcolor; + // gtk allows us to set color values for different states of the + // widget. AWT only provides a single background color, so scale it + // to get some reasonable values. +// _Jv_GdkScaleColor (&gcolor, &style->bg[GTK_STATE_ACTIVE], -0.1); +// _Jv_GdkScaleColor (&gcolor, &style->bg[GTK_STATE_PRELIGHT], 0.2); +// _Jv_GdkScaleColor (&gcolor, &style->bg[GTK_STATE_SELECTED], -0.2); +// _Jv_GdkScaleColor (&gcolor, &style->bg[GTK_STATE_INSENSITIVE], -0.2); + + gtk_widget_set_style (GTK_WIDGET (ptr), style); + + GDK_THREADS_LEAVE (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::setVisible (jboolean visible) +{ + GDK_THREADS_ENTER (); + + GtkWidget *widget = GTK_WIDGET (ptr); + + if (visible) + gtk_widget_show (widget); + else + gtk_widget_hide (widget); + + _Jv_FlushRequests (); + + GDK_THREADS_LEAVE (); +} + + +void +gnu::awt::gtk::GtkComponentPeer::create () +{ +} + + +void +gnu::awt::gtk::GtkComponentPeer::realize () +{ + GDK_THREADS_ENTER (); + gtk_widget_realize (GTK_WIDGET (ptr)); + GDK_THREADS_LEAVE (); +} diff --git a/libjava/gnu/awt/gtk/natGtkContainerPeer.cc b/libjava/gnu/awt/gtk/natGtkContainerPeer.cc new file mode 100644 index 0000000..0d5656d --- /dev/null +++ b/libjava/gnu/awt/gtk/natGtkContainerPeer.cc @@ -0,0 +1,15 @@ +// This file was created by `gcjh -stubs'. -*- c++ -*- +// +// This file is intended to give you a head start on implementing native +// methods using CNI. +// Be aware: running `gcjh -stubs ' once more for this class may +// overwrite any edits you have made to this file. + +#include +#include + +void +gnu::awt::gtk::GtkContainerPeer::create () +{ + gnu::awt::gtk::GtkComponentPeer::create(); +} diff --git a/libjava/gnu/awt/gtk/natGtkFramePeer.cc b/libjava/gnu/awt/gtk/natGtkFramePeer.cc new file mode 100644 index 0000000..b9b4d95 --- /dev/null +++ b/libjava/gnu/awt/gtk/natGtkFramePeer.cc @@ -0,0 +1,51 @@ +// This file was created by `gcjh -stubs'. -*- c++ -*- +// +// This file is intended to give you a head start on implementing native +// methods using CNI. +// Be aware: running `gcjh -stubs ' once more for this class may +// overwrite any edits you have made to this file. + +#include +#include + +#include + +void +gnu::awt::gtk::GtkFramePeer::setIconImage (::java::awt::Image *) +{ + // TODO +} + + +void +gnu::awt::gtk::GtkFramePeer::setMenuBar (::java::awt::MenuBar *) +{ + // TODO +} + + +void +gnu::awt::gtk::GtkFramePeer::setResizable (jboolean) +{ + // TODO +} + + +void +gnu::awt::gtk::GtkFramePeer::setTitle (::java::lang::String *) +{ + // TODO +} + +void +gnu::awt::gtk::GtkFramePeer::create () +{ + if (ptr == NULL) + { + GDK_THREADS_ENTER (); + ptr = (gnu::gcj::RawData *) gtk_window_new(GTK_WINDOW_TOPLEVEL); + GDK_THREADS_LEAVE (); + } + + gnu::awt::gtk::GtkContainerPeer::create(); +} diff --git a/libjava/gnu/awt/gtk/natGtkMainThread.cc b/libjava/gnu/awt/gtk/natGtkMainThread.cc new file mode 100644 index 0000000..9cc492c --- /dev/null +++ b/libjava/gnu/awt/gtk/natGtkMainThread.cc @@ -0,0 +1,22 @@ +// This file was created by `gcjh -stubs'. -*- c++ -*- +// +// This file is intended to give you a head start on implementing native +// methods using CNI. +// Be aware: running `gcjh -stubs ' once more for this class may +// overwrite any edits you have made to this file. + +#include +#include + +#include + + +void +gnu::awt::gtk::GtkMainThread::gtkMain () +{ + GDK_THREADS_ENTER (); + gtk_main (); + GDK_THREADS_LEAVE (); +} + + diff --git a/libjava/gnu/awt/gtk/natGtkToolkit.cc b/libjava/gnu/awt/gtk/natGtkToolkit.cc new file mode 100644 index 0000000..e794939 --- /dev/null +++ b/libjava/gnu/awt/gtk/natGtkToolkit.cc @@ -0,0 +1,75 @@ +// This file was created by `gcjh -stubs'. -*- c++ -*- +// +// This file is intended to give you a head start on implementing native +// methods using CNI. +// Be aware: running `gcjh -stubs ' once more for this class may +// overwrite any edits you have made to this file. + +#include + +#include +#include + +#include + + +// GTK requires the program's argc and argv variables. +extern char **_Jv_argv; +extern int _Jv_argc; + +// Call gtk_init. It is very important that this happen before any other +// gtk calls. +void +gnu::awt::gtk::GtkToolkit::gtkInit () +{ + // Initialize GLib in thread-safe mode. We assume that GLib is using the + // same native threads library as libgcj. Refer to comments in + // GtkComponentPeer constructor. + g_thread_init (NULL); + gtk_init (&_Jv_argc, &_Jv_argv); +} + +void +gnu::awt::gtk::GtkToolkit::beep () +{ + GDK_THREADS_ENTER (); + gdk_beep (); + GDK_THREADS_LEAVE (); +} + +jint +gnu::awt::gtk::GtkToolkit::getScreenResolution () +{ + jint res; + + GDK_THREADS_ENTER (); + + res = (int) (gdk_screen_width () / (gdk_screen_width_mm () / 25.4)); + + GDK_THREADS_LEAVE (); + return res; +} + +::java::awt::Dimension * +gnu::awt::gtk::GtkToolkit::getScreenSize () +{ + ::java::awt::Dimension *dim = new ::java::awt::Dimension (); + + GDK_THREADS_ENTER (); + + dim->width = gdk_screen_width (); + dim->height = gdk_screen_height (); + + GDK_THREADS_LEAVE (); + return dim; +} + +void +gnu::awt::gtk::GtkToolkit::sync () +{ + GDK_THREADS_ENTER (); + gdk_flush (); + GDK_THREADS_LEAVE (); +} + + diff --git a/libjava/gnu/awt/gtk/natGtkWindowPeer.cc b/libjava/gnu/awt/gtk/natGtkWindowPeer.cc new file mode 100644 index 0000000..d3f05c9 --- /dev/null +++ b/libjava/gnu/awt/gtk/natGtkWindowPeer.cc @@ -0,0 +1,40 @@ +// This file was created by `gcjh -stubs'. -*- c++ -*- +// +// This file is intended to give you a head start on implementing native +// methods using CNI. +// Be aware: running `gcjh -stubs ' once more for this class may +// overwrite any edits you have made to this file. + +#include +#include + +#include + +void +gnu::awt::gtk::GtkWindowPeer::toBack () +{ + GDK_THREADS_ENTER (); + gdk_window_lower (GTK_WIDGET (ptr)->window); + GDK_THREADS_LEAVE (); +} + +void +gnu::awt::gtk::GtkWindowPeer::toFront () +{ + GDK_THREADS_ENTER (); + gdk_window_raise (GTK_WIDGET (ptr)->window); + GDK_THREADS_LEAVE (); +} + +void +gnu::awt::gtk::GtkWindowPeer::create () +{ + if (ptr == NULL) + { + GDK_THREADS_ENTER (); + ptr = (gnu::gcj::RawData *) gtk_window_new(GTK_WINDOW_POPUP); + GDK_THREADS_LEAVE (); + } + + gnu::awt::gtk::GtkContainerPeer::create(); +} -- cgit v1.1