2002-08-03 Rachel Hestilow <hestilow@ximian.com>

* generator/Method.cs: Support libname overrides. Call parms.Finish.
	* generator/Parameters.cs: New method parms.Finish. Generate a temporary
	holder variable for enum out parameters.
	* generator/Property.cs: Pass a boolean to EnumWrapper indicating.
	if these are flags.
	* generator/StructBase.cs: Disable array marshalling (it is
	broken in mono.)
	* generator/SymbolTable.cs: Add methods IsEnumFlags.

	* glib/EnumWrapper.cs: New bool "flags".
	* glib/Value.cs: Call flags variant on GValue for enum props, if needed.

	* glue/Makefile.am, glue/style.c, glue/widget.c: Add widget
	and style field accessor methods.

	* gtk/Style.custom, Widget.custom: Added.

	* parser/README: Update requirements (needed for pixbuf drawable hack)
	* parser/Gdk.metadata: Fix library for pixbuf methods in gdk.
	Add Window.GetPointer "out" parameters.
	* parser/gapi2xml.pl: Remap gdk_draw_* methods to Drawable.

	* sample/Makefile.in: Add size and scribble samples.
	* sample/Scribble.cs: Added.

svn path=/trunk/gtk-sharp/; revision=6387
This commit is contained in:
Rachel Hestilow 2002-08-03 22:24:37 +00:00
parent 7648593a67
commit 54838fec29
21 changed files with 832 additions and 27 deletions

View file

@ -1,3 +1,30 @@
2002-08-03 Rachel Hestilow <hestilow@ximian.com>
* generator/Method.cs: Support libname overrides. Call parms.Finish.
* generator/Parameters.cs: New method parms.Finish. Generate a temporary
holder variable for enum out parameters.
* generator/Property.cs: Pass a boolean to EnumWrapper indicating.
if these are flags.
* generator/StructBase.cs: Disable array marshalling (it is
broken in mono.)
* generator/SymbolTable.cs: Add methods IsEnumFlags.
* glib/EnumWrapper.cs: New bool "flags".
* glib/Value.cs: Call flags variant on GValue for enum props, if needed.
* glue/Makefile.am, glue/style.c, glue/widget.c: Add widget
and style field accessor methods.
* gtk/Style.custom, Widget.custom: Added.
* parser/README: Update requirements (needed for pixbuf drawable hack)
* parser/Gdk.metadata: Fix library for pixbuf methods in gdk.
Add Window.GetPointer "out" parameters.
* parser/gapi2xml.pl: Remap gdk_draw_* methods to Drawable.
* sample/Makefile.in: Add size and scribble samples.
* sample/Scribble.cs: Added.
2002-08-02 Rachel Hestilow <hestilow@ximian.com>
[ Mike, this is everything I wanted in for the release. ]

View file

@ -27,12 +27,16 @@ namespace GtkSharp.Generation {
public Method (string libname, XmlElement elem, ClassBase container_type)
{
this.libname = libname;
this.elem = elem;
if (elem["parameters"] != null)
parms = new Parameters (elem["parameters"]);
this.container_type = container_type;
this.name = elem.GetAttribute("name");
// override library - used in pixbuf API fixage
if (elem.HasAttribute ("library"))
this.libname = elem.GetAttribute ("library");
else
this.libname = libname;
}
public string Name {
@ -356,8 +360,10 @@ namespace GtkSharp.Generation {
}
}
if (parms != null)
if (parms != null) {
parms.Finish (sw, indent);
parms.HandleException (sw, indent);
}
if (is_get && parms != null)
sw.WriteLine (indent + "\t\t\treturn " + parms.AccessorName + ";");

View file

@ -205,6 +205,9 @@ namespace GtkSharp.Generation {
import_sig += pass_as + " ";
call_string += "out ";
}
if (SymbolTable.IsEnum (type))
call_parm = name + "_as_int";
}
else if (type == "GError**")
{
@ -253,13 +256,17 @@ namespace GtkSharp.Generation {
if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type))) {
sw.WriteLine(indent + "\t\t\t" + name + " = new " + type + "();");
}
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.IsEnum (c_type)) {
sw.WriteLine(indent + "\t\t\tint " + name + "_as_int;");
}
}
if (ThrowsException)
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
}
/*
public void Finish (StreamWriter sw)
public void Finish (StreamWriter sw, string indent)
{
foreach (XmlNode parm in elem.ChildNodes) {
if (parm.Name != "parameter") {
@ -269,16 +276,14 @@ namespace GtkSharp.Generation {
XmlElement p_elem = (XmlElement) parm;
string c_type = p_elem.GetAttribute ("type");
string name = MangleName(p_elem.GetAttribute("name"));
string type = SymbolTable.GetCSType(c_type);
if ((p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) {
string call_parm = SymbolTable.CallByName(c_type, name);
string local_parm = GetPossibleLocal (call_parm);
if (call_parm != local_parm)
sw.WriteLine ("\t\t\t{0} = {1};", call_parm, local_parm);
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.IsEnum (c_type)) {
sw.WriteLine(indent + "\t\t\t" + name + " = (" + type + ") " + name + "_as_int;");
}
}
}
*/
public void HandleException (StreamWriter sw, string indent)
{

View file

@ -117,7 +117,7 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\tset {");
sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value(");
if (SymbolTable.IsEnum(c_type)) {
sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value)));");
sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value, {0})));", SymbolTable.IsEnumFlags (c_type) ? "true" : "false");
} else if (SymbolTable.IsBoxed (c_type)) {
sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));");
} else {

View file

@ -128,8 +128,9 @@ namespace GtkSharp.Generation {
}
}
// FIXME: marshalling not implemented here in mono
if (field.HasAttribute("array_len"))
type += "[]";
type = "IntPtr";
if (IsBit (field))
name = String.Format ("_bitfield{0}", bitfields++);

View file

@ -297,6 +297,17 @@ namespace GtkSharp.Generation {
return false;
}
public static bool IsEnumFlags(string c_type)
{
c_type = Trim(c_type);
c_type = DeAlias(c_type);
if (complex_types.ContainsKey(c_type)) {
EnumGen gen = complex_types[c_type] as EnumGen;
return (gen != null && gen.Elem.GetAttribute ("type") == "flags");
}
return false;
}
public static bool IsInterface(string c_type)
{
c_type = Trim(c_type);

View file

@ -1119,6 +1119,32 @@
<method name="GetColorspace" cname="gdk_pixbuf_get_colorspace">
<return-type type="GdkColorspace"/>
</method>
<method name="GetFromDrawable" cname="gdk_pixbuf_get_from_drawable" library="gdk-x11-2.0">
<return-type type="GdkPixbuf*"/>
<parameters>
<parameter type="GdkDrawable*" name="src"/>
<parameter type="GdkColormap*" name="cmap"/>
<parameter type="int" name="src_x"/>
<parameter type="int" name="src_y"/>
<parameter type="int" name="dest_x"/>
<parameter type="int" name="dest_y"/>
<parameter type="int" name="width"/>
<parameter type="int" name="height"/>
</parameters>
</method>
<method name="GetFromImage" cname="gdk_pixbuf_get_from_image" library="gdk-x11-2.0">
<return-type type="GdkPixbuf*"/>
<parameters>
<parameter type="GdkImage*" name="src"/>
<parameter type="GdkColormap*" name="cmap"/>
<parameter type="int" name="src_x"/>
<parameter type="int" name="src_y"/>
<parameter type="int" name="dest_x"/>
<parameter type="int" name="dest_y"/>
<parameter type="int" name="width"/>
<parameter type="int" name="height"/>
</parameters>
</method>
<method name="GetHasAlpha" cname="gdk_pixbuf_get_has_alpha">
<return-type type="gboolean"/>
</method>
@ -1196,6 +1222,69 @@
<parameter type="int" name="height"/>
</parameters>
</constructor>
<method name="RenderPixmapAndMask" cname="gdk_pixbuf_render_pixmap_and_mask" library="gdk-x11-2.0">
<return-type type="void"/>
<parameters>
<parameter type="GdkPixmap**" name="pixmap_return"/>
<parameter type="GdkBitmap**" name="mask_return"/>
<parameter type="int" name="alpha_threshold"/>
</parameters>
</method>
<method name="RenderPixmapAndMaskForColormap" cname="gdk_pixbuf_render_pixmap_and_mask_for_colormap" library="gdk-x11-2.0">
<return-type type="void"/>
<parameters>
<parameter type="GdkColormap*" name="colormap"/>
<parameter type="GdkPixmap**" name="pixmap_return"/>
<parameter type="GdkBitmap**" name="mask_return"/>
<parameter type="int" name="alpha_threshold"/>
</parameters>
</method>
<method name="RenderThresholdAlpha" cname="gdk_pixbuf_render_threshold_alpha" library="gdk-x11-2.0">
<return-type type="void"/>
<parameters>
<parameter type="GdkBitmap*" name="bitmap"/>
<parameter type="int" name="src_x"/>
<parameter type="int" name="src_y"/>
<parameter type="int" name="dest_x"/>
<parameter type="int" name="dest_y"/>
<parameter type="int" name="width"/>
<parameter type="int" name="height"/>
<parameter type="int" name="alpha_threshold"/>
</parameters>
</method>
<method name="RenderToDrawable" cname="gdk_pixbuf_render_to_drawable" library="gdk-x11-2.0">
<return-type type="void"/>
<parameters>
<parameter type="GdkDrawable*" name="drawable"/>
<parameter type="GdkGC*" name="gc"/>
<parameter type="int" name="src_x"/>
<parameter type="int" name="src_y"/>
<parameter type="int" name="dest_x"/>
<parameter type="int" name="dest_y"/>
<parameter type="int" name="width"/>
<parameter type="int" name="height"/>
<parameter type="GdkRgbDither" name="dither"/>
<parameter type="int" name="x_dither"/>
<parameter type="int" name="y_dither"/>
</parameters>
</method>
<method name="RenderToDrawableAlpha" cname="gdk_pixbuf_render_to_drawable_alpha" library="gdk-x11-2.0">
<return-type type="void"/>
<parameters>
<parameter type="GdkDrawable*" name="drawable"/>
<parameter type="int" name="src_x"/>
<parameter type="int" name="src_y"/>
<parameter type="int" name="dest_x"/>
<parameter type="int" name="dest_y"/>
<parameter type="int" name="width"/>
<parameter type="int" name="height"/>
<parameter type="GdkPixbufAlphaMode" name="alpha_mode"/>
<parameter type="int" name="alpha_threshold"/>
<parameter type="GdkRgbDither" name="dither"/>
<parameter type="int" name="x_dither"/>
<parameter type="int" name="y_dither"/>
</parameters>
</method>
<method name="SaturateAndPixelate" cname="gdk_pixbuf_saturate_and_pixelate">
<return-type type="void"/>
<parameters>
@ -2313,6 +2402,240 @@
<constructor cname="gdk_drag_context_new"/>
</object>
<object name="Drawable" cname="GdkDrawable" parent="GObject">
<method name="DrawArc" cname="gdk_draw_arc">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="filled"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="gint" name="angle1"/>
<parameter type="gint" name="angle2"/>
</parameters>
</method>
<method name="DrawDrawable" cname="gdk_draw_drawable">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="GdkDrawable*" name="src"/>
<parameter type="gint" name="xsrc"/>
<parameter type="gint" name="ysrc"/>
<parameter type="gint" name="xdest"/>
<parameter type="gint" name="ydest"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
</parameters>
</method>
<method name="DrawGlyphs" cname="gdk_draw_glyphs">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="PangoFont*" name="font"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="PangoGlyphString*" name="glyphs"/>
</parameters>
</method>
<method name="DrawGrayImage" cname="gdk_draw_gray_image">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="GdkRgbDither" name="dith"/>
<parameter type="guchar*" name="buf"/>
<parameter type="gint" name="rowstride"/>
</parameters>
</method>
<method name="DrawImage" cname="gdk_draw_image">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="GdkImage*" name="image"/>
<parameter type="gint" name="xsrc"/>
<parameter type="gint" name="ysrc"/>
<parameter type="gint" name="xdest"/>
<parameter type="gint" name="ydest"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
</parameters>
</method>
<method name="DrawIndexedImage" cname="gdk_draw_indexed_image">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="GdkRgbDither" name="dith"/>
<parameter type="guchar*" name="buf"/>
<parameter type="gint" name="rowstride"/>
<parameter type="GdkRgbCmap*" name="cmap"/>
</parameters>
</method>
<method name="DrawLayout" cname="gdk_draw_layout">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="PangoLayout*" name="layout"/>
</parameters>
</method>
<method name="DrawLayoutLine" cname="gdk_draw_layout_line">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="PangoLayoutLine*" name="line"/>
</parameters>
</method>
<method name="DrawLayoutLineWithColors" cname="gdk_draw_layout_line_with_colors">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="PangoLayoutLine*" name="line"/>
<parameter type="GdkColor*" name="foreground"/>
<parameter type="GdkColor*" name="background"/>
</parameters>
</method>
<method name="DrawLayoutWithColors" cname="gdk_draw_layout_with_colors">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="PangoLayout*" name="layout"/>
<parameter type="GdkColor*" name="foreground"/>
<parameter type="GdkColor*" name="background"/>
</parameters>
</method>
<method name="DrawLine" cname="gdk_draw_line">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x1"/>
<parameter type="gint" name="y1"/>
<parameter type="gint" name="x2"/>
<parameter type="gint" name="y2"/>
</parameters>
</method>
<method name="DrawLines" cname="gdk_draw_lines">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="GdkPoint*" name="points"/>
<parameter type="gint" name="npoints"/>
</parameters>
</method>
<method name="DrawPoint" cname="gdk_draw_point">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
</parameters>
</method>
<method name="DrawPoints" cname="gdk_draw_points">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="GdkPoint*" name="points"/>
<parameter type="gint" name="npoints"/>
</parameters>
</method>
<method name="DrawPolygon" cname="gdk_draw_polygon">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="filled"/>
<parameter type="GdkPoint*" name="points"/>
<parameter type="gint" name="npoints"/>
</parameters>
</method>
<method name="DrawRectangle" cname="gdk_draw_rectangle">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="filled"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
</parameters>
</method>
<method name="DrawRgb32Image" cname="gdk_draw_rgb_32_image">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="GdkRgbDither" name="dith"/>
<parameter type="guchar*" name="buf"/>
<parameter type="gint" name="rowstride"/>
</parameters>
</method>
<method name="DrawRgb32ImageDithalign" cname="gdk_draw_rgb_32_image_dithalign">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="GdkRgbDither" name="dith"/>
<parameter type="guchar*" name="buf"/>
<parameter type="gint" name="rowstride"/>
<parameter type="gint" name="xdith"/>
<parameter type="gint" name="ydith"/>
</parameters>
</method>
<method name="DrawRgbImage" cname="gdk_draw_rgb_image">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="GdkRgbDither" name="dith"/>
<parameter type="guchar*" name="rgb_buf"/>
<parameter type="gint" name="rowstride"/>
</parameters>
</method>
<method name="DrawRgbImageDithalign" cname="gdk_draw_rgb_image_dithalign">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="gint" name="x"/>
<parameter type="gint" name="y"/>
<parameter type="gint" name="width"/>
<parameter type="gint" name="height"/>
<parameter type="GdkRgbDither" name="dith"/>
<parameter type="guchar*" name="rgb_buf"/>
<parameter type="gint" name="rowstride"/>
<parameter type="gint" name="xdith"/>
<parameter type="gint" name="ydith"/>
</parameters>
</method>
<method name="DrawSegments" cname="gdk_draw_segments">
<return-type type="void"/>
<parameters>
<parameter type="GdkGC*" name="gc"/>
<parameter type="GdkSegment*" name="segs"/>
<parameter type="gint" name="nsegs"/>
</parameters>
</method>
<method name="GetClipRegion" cname="gdk_drawable_get_clip_region">
<return-type type="GdkRegion*"/>
</method>
@ -2912,9 +3235,9 @@
<method name="GetPointer" cname="gdk_window_get_pointer">
<return-type type="GdkWindow*"/>
<parameters>
<parameter type="gint*" name="x"/>
<parameter type="gint*" name="y"/>
<parameter type="GdkModifierType*" name="mask"/>
<parameter type="gint*" name="x" pass_as="out"/>
<parameter type="gint*" name="y" pass_as="out"/>
<parameter type="GdkModifierType*" name="mask" pass_as="out"/>
</parameters>
</method>
<method name="GetPosition" cname="gdk_window_get_position">

View file

@ -13,9 +13,11 @@ namespace GLib {
// <remarks> </remarks>
public class EnumWrapper {
int val;
public bool flags;
public EnumWrapper (int val) {
public EnumWrapper (int val, bool flags) {
this.val = val;
this.flags = flags;
}
public static explicit operator int (EnumWrapper wrap) {

View file

@ -233,6 +233,8 @@ namespace GLib {
[DllImport("gobject-2.0")]
static extern void g_value_set_enum (IntPtr val, int data);
[DllImport("gobject-2.0")]
static extern void g_value_set_flags (IntPtr val, uint data);
/// <summary>
/// Value Constructor
@ -245,6 +247,9 @@ namespace GLib {
public Value (IntPtr obj, string prop_name, EnumWrapper wrap)
{
_val = gtksharp_value_create_from_property (obj, prop_name);
if (wrap.flags)
g_value_set_flags (_val, (uint) (int) wrap);
else
g_value_set_enum (_val, (int) wrap);
}
@ -451,6 +456,8 @@ namespace GLib {
[DllImport("gobject-2.0")]
static extern int g_value_get_enum (IntPtr val);
[DllImport("gobject-2.0")]
static extern uint g_value_get_flags (IntPtr val);
/// <summary>
/// Value to Enum Conversion
@ -466,7 +473,8 @@ namespace GLib {
{
// FIXME: Insert an appropriate exception here if
// _val.type indicates an error.
return new EnumWrapper (g_value_get_enum (val._val));
// FIXME: handle flags
return new EnumWrapper (g_value_get_enum (val._val), false);
}
/// <summary>

View file

@ -8,7 +8,9 @@ BASESOURCES = \
error.c \
event.c \
slist.c \
paned.c
paned.c \
style.c \
widget.c
if ENABLE_GNOME
libgtksharpglue_la_SOURCES = \

59
glue/style.c Normal file
View file

@ -0,0 +1,59 @@
/* style.c : Glue to access fields in GtkStyle.
*
* Author: Rachel Hestilow <hestilow@ximian.com>
*
* <c> 2002 Rachel Hestilow, Mike Kestner
*/
#include <gtk/gtkstyle.h>
/* FIXME: include all fields */
GdkGC*
gtksharp_gtk_style_get_white_gc (GtkStyle *style)
{
return style->white_gc;
}
GdkGC*
gtksharp_gtk_style_get_black_gc (GtkStyle *style)
{
return style->black_gc;
}
GdkGC**
gtksharp_gtk_style_get_fg_gc (GtkStyle *style)
{
return style->fg_gc;
}
GdkGC**
gtksharp_gtk_style_get_bg_gc (GtkStyle *style)
{
return style->bg_gc;
}
GdkColor*
gtksharp_gtk_style_get_white (GtkStyle *style)
{
return &style->white;
}
GdkColor*
gtksharp_gtk_style_get_black (GtkStyle *style)
{
return &style->black;
}
GdkColor*
gtksharp_gtk_style_get_fg (GtkStyle *style)
{
return style->fg;
}
GdkColor**
gtksharp_gtk_style_get_bg (GtkStyle *style)
{
return style->bg;
}

16
glue/widget.c Normal file
View file

@ -0,0 +1,16 @@
/* widget.c : Glue to access fields in GtkWidget.
*
* Author: Rachel Hestilow <hestilow@ximian.com>
*
* <c> 2002 Rachel Hestilow, Mike Kestner
*/
#include <gtk/gtkwidget.h>
GdkRectangle*
gtksharp_gtk_widget_get_allocation (GtkWidget *widget)
{
return &widget->allocation;
}

92
gtk/Style.custom Normal file
View file

@ -0,0 +1,92 @@
//
// Gtk.Style.custom - Gtk Style class customizations
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// Copyright (C) 2002 Rachel Hestilow
//
// This code is inserted after the automatically generated code.
//
static Gdk.GC EnsureGC (IntPtr raw) {
if (raw == IntPtr.Zero)
return null;
Gdk.GC ret = (Gdk.GC) GLib.Object.GetObject (raw);
if (ret == null)
ret = new Gdk.GC (raw);
return ret;
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_gtk_style_get_white_gc (IntPtr style);
public Gdk.GC WhiteGC {
get { return EnsureGC (gtksharp_gtk_style_get_white_gc (Handle)); }
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_gtk_style_get_black_gc (IntPtr style);
public Gdk.GC BlackGC {
get { return EnsureGC (gtksharp_gtk_style_get_black_gc (Handle)); }
}
[DllImport("gtksharpglue")]
static extern IntPtr[] gtksharp_gtk_style_get_fg_gc (IntPtr style);
public Gdk.GC[] ForegroundGC {
get {
IntPtr[] raws = gtksharp_gtk_style_get_fg_gc (Handle);
Gdk.GC[] ret = new Gdk.GC[raws.Length];
int i = 0;
foreach (IntPtr raw in raws) {
ret[i++] = EnsureGC (raw);
}
return ret;
}
}
[DllImport("gtksharpglue")]
static extern IntPtr[] gtksharp_gtk_style_get_bg_gc (IntPtr style);
public Gdk.GC[] BackgroundGC {
get {
IntPtr[] raws = gtksharp_gtk_style_get_bg_gc (Handle);
Gdk.GC[] ret = new Gdk.GC[raws.Length];
int i = 0;
foreach (IntPtr raw in raws) {
ret[i++] = EnsureGC (raw);
}
return ret;
}
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_gtk_style_get_white (IntPtr style);
public Gdk.Color White {
get { return Gdk.Color.New (gtksharp_gtk_style_get_white (Handle)); }
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_gtk_style_get_black (IntPtr style);
public Gdk.Color Black {
get { return Gdk.Color.New (gtksharp_gtk_style_get_black (Handle)); }
}
[DllImport("gtksharpglue")]
static extern Gdk.Color[] gtksharp_gtk_style_get_fg (IntPtr style);
public Gdk.Color[] Foreground {
get {
return gtksharp_gtk_style_get_fg (Handle);
}
}
static extern Gdk.Color[] gtksharp_gtk_style_get_bg (IntPtr style);
public Gdk.Color[] Background {
get {
return gtksharp_gtk_style_get_bg (Handle);
}
}

17
gtk/Widget.custom Normal file
View file

@ -0,0 +1,17 @@
//
// Gtk.Widget.custom - Gtk Widget class customizations
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// Copyright (C) 2002 Rachel Hestilow
//
// This code is inserted after the automatically generated code.
//
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_gtk_widget_get_allocation (IntPtr style);
public Gdk.Rectangle Allocation {
get { return Gdk.Rectangle.New (gtksharp_gtk_widget_get_allocation (Handle)); }
}

View file

@ -42,7 +42,7 @@
</data>
</rule>
<!-- drawable hacks-->
<!-- API hacks -->
<rule>
<class name="GdkBitmap"/>
<class name="GdkPixmap"/>
@ -63,5 +63,48 @@
</attribute>
</data>
</rule>
<rule>
<class name="GdkPixbuf">
<method>RenderThresholdAlpha</method>
<method>RenderToDrawable</method>
<method>RenderToDrawableAlpha</method>
<method>RenderPixmapAndMaskForColormap</method>
<method>RenderPixmapAndMask</method>
<method>GetFromDrawable</method>
<method>GetFromImage</method>
</class>
<data>
<attribute target="method">
<name>library</name>
<value>gdk-x11-2.0</value>
</attribute>
</data>
</rule>
<!-- out parameters -->
<rule>
<class name="GdkWindow">
<method>GetPointer</method>
</class>
<data>
<attribute target="param">
<filter level="type">gint*</filter>
<name>pass_as</name>
<value>out</value>
</attribute>
</data>
</rule>
<rule>
<class name="GdkWindow">
<method>GetPointer</method>
</class>
<data>
<attribute target="param">
<filter level="type">GdkModifierType*</filter>
<name>pass_as</name>
<value>out</value>
</attribute>
</data>
</rule>
</metadata>

View file

@ -6,6 +6,7 @@ glib-2.0.3
pango-1.0.3
atk-1.0.2
gtk+-2.0.5
* you need gdkpixbuf*.[ch] from gdk/ symlinked into gdk-pixbuf/
libgnome-2.0.1
libgnomecanvas-2.0.1
libgnomeui-2.0.1

View file

@ -438,9 +438,15 @@ sub addFuncElems
next if ($mname =~ /^_/);
$obj_el = "";
$prefix = $mname;
$prepend = undef;
while ($prefix =~ /(\w+)_/) {
$prefix = $key = $1;
$key =~ s/_//g;
# FIXME: lame Gdk API hack
if ($key eq "gdkdraw") {
$key = "gdkdrawable";
$prepend = "draw_";
}
if (exists ($elem_table{$key})) {
$prefix .= "_";
$obj_el = $elem_table{$key};
@ -456,7 +462,7 @@ sub addFuncElems
$el = addNameElem($obj_el, 'constructor', $mname);
$drop_1st = 0;
} else {
$el = addNameElem($obj_el, 'method', $mname, $prefix);
$el = addNameElem($obj_el, 'method', $mname, $prefix, $prepend);
$mdef =~ /(.*?)\w+\s*\(/;
addReturnElem($el, $1);
$mdef =~ /\(\s*(const)?\s*(\w+)/;
@ -500,13 +506,18 @@ sub addFuncElems
sub addNameElem
{
my ($node, $type, $cname, $prefix) = @_;
my ($node, $type, $cname, $prefix, $prepend) = @_;
my $elem = $doc->createElement($type);
$node->appendChild($elem);
if ($prefix) {
$cname =~ /$prefix(\w+)/;
$elem->setAttribute('name', StudlyCaps($1));
if ($prepend) {
$name = $prepend . $1;
} else {
$name = $1;
}
$elem->setAttribute('name', StudlyCaps($name));
}
if ($cname) {
$elem->setAttribute('cname', $cname);

View file

@ -14,7 +14,7 @@ windows:
$(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll /r:../gdk/gdk-sharp.dll HelloWorld.cs
$(CSC) /unsafe /out:button.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll ButtonApp.cs
linux: gtk-hello-world.exe button.exe menu.exe $(GNOME_TARGETS)
linux: gtk-hello-world.exe button.exe menu.exe size.exe scribble.exe $(GNOME_TARGETS)
gtk-hello-world.exe: HelloWorld.cs
$(MCS) --unsafe -o gtk-hello-world.exe $(local_paths) $(all_assemblies) HelloWorld.cs
@ -28,6 +28,12 @@ button.exe: ButtonApp.cs
menu.exe: Menu.cs
$(MCS) --unsafe -o menu.exe $(local_paths) $(all_assemblies) Menu.cs
size.exe: Size.cs
$(MCS) --unsafe -o size.exe $(local_paths) $(all_assemblies) Size.cs
scribble.exe: Scribble.cs
$(MCS) --unsafe -o scribble.exe $(local_paths) $(all_assemblies) Scribble.cs
clean:
rm -f *.exe

131
sample/Scribble.cs Normal file
View file

@ -0,0 +1,131 @@
// Scribble.cs - port of Gtk+ scribble demo
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2002 Rachel Hestilow
namespace GtkSamples {
using Gtk;
using Gdk;
using GtkSharp;
using System;
public class Scribble {
private static Gtk.DrawingArea darea;
private static Gdk.Pixmap pixmap = null;
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Scribble demo");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
darea = new Gtk.DrawingArea ();
darea.SetSizeRequest (200, 200);
win.Add (darea);
darea.ExposeEvent += new ExposeEventHandler (ExposeEvent);
darea.ConfigureEvent += new ConfigureEventHandler (ConfigureEvent);
darea.MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEvent);
darea.ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEvent);
darea.Events = EventMask.ExposureMask |
EventMask.LeaveNotifyMask |
EventMask.ButtonPressMask |
EventMask.PointerMotionMask |
EventMask.PointerMotionHintMask;
win.ShowAll ();
Application.Run ();
return 0;
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
SignalArgs sa = (SignalArgs) args;
Application.Quit ();
sa.RetVal = true;
}
static void ExposeEvent (object obj, ExposeEventArgs args)
{
Gdk.EventExpose ev = args.Event;
Gdk.Window window = ev.window;
// FIXME: mcs bug
Gdk.Rectangle area = ev.area;
// FIXME: array marshalling not done yet so no FG */
window.DrawDrawable (darea.Style.BlackGC,
pixmap,
area.x, area.y,
area.x, area.y,
area.width, area.height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = false;
}
static void ConfigureEvent (object obj, ConfigureEventArgs args)
{
Gdk.EventConfigure ev = args.Event;
Gdk.Window window = ev.window;
Gdk.Rectangle allocation = darea.Allocation;
pixmap = new Gdk.Pixmap (window,
allocation.width,
allocation.height,
-1);
pixmap.DrawRectangle (darea.Style.WhiteGC, 1, 0, 0,
allocation.width, allocation.height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
static void DrawBrush (double x, double y)
{
Gdk.Rectangle update_rect = new Gdk.Rectangle ();
update_rect.x = (int) x - 5;
update_rect.y = (int) y - 5;
update_rect.width = 10;
update_rect.height = 10;
pixmap.DrawRectangle (darea.Style.BlackGC, 1,
update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
darea.QueueDrawArea (update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
}
static void ButtonPressEvent (object obj, ButtonPressEventArgs args)
{
Gdk.EventButton ev = args.Event;
if (ev.button == 1 && pixmap != null)
DrawBrush (ev.x, ev.y);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
static void MotionNotifyEvent (object obj, MotionNotifyEventArgs args)
{
int x, y;
Gdk.ModifierType state;
Gdk.EventMotion ev = args.Event;
Gdk.Window window = ev.window;
if (ev.is_hint != 0)
window.GetPointer (out x, out y, out state);
else {
x = (int) ev.x;
y = (int) ev.y;
state = (Gdk.ModifierType) ev.state;
}
if ((state & Gdk.ModifierType.Button1Mask) != 0 && pixmap != null)
DrawBrush (x, y);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
}
}

View file

@ -42,7 +42,7 @@
</data>
</rule>
<!-- drawable hacks-->
<!-- API hacks -->
<rule>
<class name="GdkBitmap"/>
<class name="GdkPixmap"/>
@ -63,5 +63,48 @@
</attribute>
</data>
</rule>
<rule>
<class name="GdkPixbuf">
<method>RenderThresholdAlpha</method>
<method>RenderToDrawable</method>
<method>RenderToDrawableAlpha</method>
<method>RenderPixmapAndMaskForColormap</method>
<method>RenderPixmapAndMask</method>
<method>GetFromDrawable</method>
<method>GetFromImage</method>
</class>
<data>
<attribute target="method">
<name>library</name>
<value>gdk-x11-2.0</value>
</attribute>
</data>
</rule>
<!-- out parameters -->
<rule>
<class name="GdkWindow">
<method>GetPointer</method>
</class>
<data>
<attribute target="param">
<filter level="type">gint*</filter>
<name>pass_as</name>
<value>out</value>
</attribute>
</data>
</rule>
<rule>
<class name="GdkWindow">
<method>GetPointer</method>
</class>
<data>
<attribute target="param">
<filter level="type">GdkModifierType*</filter>
<name>pass_as</name>
<value>out</value>
</attribute>
</data>
</rule>
</metadata>

View file

@ -6,6 +6,7 @@ glib-2.0.3
pango-1.0.3
atk-1.0.2
gtk+-2.0.5
* you need gdkpixbuf*.[ch] from gdk/ symlinked into gdk-pixbuf/
libgnome-2.0.1
libgnomecanvas-2.0.1
libgnomeui-2.0.1