Merge pull request #9 from bl8/more-sample-fixes

More sample fixes
This commit is contained in:
Mike Kestner 2011-07-04 10:15:23 -07:00
commit 43b4522f87
6 changed files with 81 additions and 76 deletions

View file

@ -54,7 +54,9 @@
try { try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer; CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget; Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr); Gdk.Rectangle cell_area = Gdk.Rectangle.Zero;
if (cell_area_ptr != IntPtr.Zero)
cell_area = Gdk.Rectangle.New (cell_area_ptr);
int a, b, c, d; int a, b, c, d;
obj.OnGetSize (widg, ref cell_area, out a, out b, out c, out d); obj.OnGetSize (widg, ref cell_area, out a, out b, out c, out d);

View file

@ -7,6 +7,7 @@
<attr path="/api/namespace/struct[@cname='GtkActionEntry']" name="hidden">1</attr> <attr path="/api/namespace/struct[@cname='GtkActionEntry']" name="hidden">1</attr>
<attr path="/api/namespace/struct[@cname='GtkRadioActionEntry']" name="hidden">1</attr> <attr path="/api/namespace/struct[@cname='GtkRadioActionEntry']" name="hidden">1</attr>
<attr path="/api/namespace/struct[@cname='GtkToggleActionEntry']" name="hidden">1</attr> <attr path="/api/namespace/struct[@cname='GtkToggleActionEntry']" name="hidden">1</attr>
<attr path="/api/namespace/boxed[@cname='GtkBorder']" name="opaque">false</attr>
<attr path="/api/namespace/boxed[@cname='GtkIconInfo']/method[@name='Free']" name="deprecated">1</attr> <attr path="/api/namespace/boxed[@cname='GtkIconInfo']/method[@name='Free']" name="deprecated">1</attr>
<attr path="/api/namespace/boxed[@cname='GtkIconInfo']/method[@name='GetFilename']" name="win32_utf8_variant">true</attr> <attr path="/api/namespace/boxed[@cname='GtkIconInfo']/method[@name='GetFilename']" name="win32_utf8_variant">true</attr>
<attr path="/api/namespace/boxed[@cname='GtkIconSet']/method[@name='GetSizes']" name="hidden">1</attr> <attr path="/api/namespace/boxed[@cname='GtkIconSet']/method[@name='GetSizes']" name="hidden">1</attr>
@ -531,8 +532,11 @@
<attr path="/api/namespace/object[@cname='GtkStyle']/method[@name='LookupColor']/*/*[@name='color']" name="pass_as">out</attr> <attr path="/api/namespace/object[@cname='GtkStyle']/method[@name='LookupColor']/*/*[@name='color']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='Get']" name="hidden">1</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='Get']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetBackgroundColor']/*/parameter[@name='color']" name="pass_as">out</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetBackgroundColor']/*/parameter[@name='color']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetBorder']/*/parameter[@name='border']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetBorderColor']/*/parameter[@name='color']" name="pass_as">out</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetBorderColor']/*/parameter[@name='color']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetColor']/*/parameter[@name='color']" name="pass_as">out</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetColor']/*/parameter[@name='color']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetMargin']/*/parameter[@name='margin']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetPadding']/*/parameter[@name='padding']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetStyle']" name="hidden">1</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetStyle']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetStyleProperty']/*/parameter[@name='value']" name="pass_as">out</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetStyleProperty']/*/parameter[@name='value']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetStyleValist']" name="hidden">1</attr> <attr path="/api/namespace/object[@cname='GtkStyleContext']/method[@name='GetStyleValist']" name="hidden">1</attr>

View file

@ -46,31 +46,30 @@ public class CustomCellRenderer : CellRenderer
} }
} }
protected override void OnRender (Drawable window, Widget widget, Rectangle background_area, Rectangle cell_area, Rectangle expose_area, CellRendererState flags) protected override void OnRender (Cairo.Context cr, Widget widget, Rectangle background_area, Rectangle cell_area, CellRendererState flags)
{ {
int width = 0, height = 0, x_offset = 0, y_offset = 0; int x = (int) (cell_area.X + this.Xpad);
StateType state; int y = (int) (cell_area.Y + this.Ypad);
OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); int width = (int) (cell_area.Width - this.Xpad * 2);
int height = (int) (cell_area.Height - this.Ypad * 2);
if (widget.HasFocus) widget.StyleContext.Save ();
state = StateType.Active; widget.StyleContext.AddClass ("trough");
else widget.StyleContext.RenderBackground (cr, x, y, width, height);
state = StateType.Normal; widget.StyleContext.RenderFrame (cr, x, y, width, height);
width -= (int) this.Xpad * 2;
height -= (int) this.Ypad * 2;
//FIXME: Style.PaintBox needs some customization so that if you pass it
//a Gdk.Rectangle.Zero it gives a clipping area big enough to draw
//everything
Gdk.Rectangle clipping_area = new Gdk.Rectangle ((int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), width - 1, height - 1);
Style.PaintBox (widget.Style, (Gdk.Window) window, StateType.Normal, ShadowType.In, clipping_area, widget, "trough", (int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), width - 1, height - 1); Border padding = widget.StyleContext.GetPadding (StateFlags.Normal);
x += padding.Left;
y += padding.Top;
width -= padding.Left + padding.Right;
height -= padding.Top + padding.Bottom;
Gdk.Rectangle clipping_area2 = new Gdk.Rectangle ((int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), (int) (width * Percentage), height - 1); widget.StyleContext.Restore ();
Style.PaintBox (widget.Style, (Gdk.Window) window, state, ShadowType.Out, clipping_area2, widget, "bar", (int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), (int) (width * Percentage), height - 1); widget.StyleContext.Save ();
widget.StyleContext.AddClass ("progressbar");
widget.StyleContext.RenderActivity (cr, x, y, (int) (width * Percentage), height);
widget.StyleContext.Restore ();
} }
} }
@ -78,9 +77,9 @@ public class Driver : Gtk.Window
{ {
public static void Main () public static void Main ()
{ {
Application.Init (); Gtk.Application.Init ();
new Driver (); new Driver ();
Application.Run (); Gtk.Application.Run ();
} }
ListStore liststore; ListStore liststore;
@ -128,7 +127,7 @@ public class Driver : Gtk.Window
void window_delete (object obj, DeleteEventArgs args) void window_delete (object obj, DeleteEventArgs args)
{ {
Application.Quit (); Gtk.Application.Quit ();
args.RetVal = true; args.RetVal = true;
} }
} }

View file

@ -5,7 +5,7 @@ using System;
class CustomWidgetTest { class CustomWidgetTest {
public static int Main (string[] args) public static int Main (string[] args)
{ {
Application.Init (); Gtk.Application.Init ();
Window win = new Window ("Custom Widget Test"); Window win = new Window ("Custom Widget Test");
win.DeleteEvent += new DeleteEventHandler (OnQuit); win.DeleteEvent += new DeleteEventHandler (OnQuit);
@ -30,18 +30,17 @@ class CustomWidgetTest {
win.Add (paned); win.Add (paned);
win.ShowAll (); win.ShowAll ();
Application.Run (); Gtk.Application.Run ();
return 0; return 0;
} }
static void OnQuit (object sender, DeleteEventArgs args) static void OnQuit (object sender, DeleteEventArgs args)
{ {
Application.Quit (); Gtk.Application.Quit ();
} }
} }
class CustomWidget : Bin { class CustomWidget : Bin {
internal static GType customWidgetGType;
private Gdk.Pixbuf icon; private Gdk.Pixbuf icon;
private string label; private string label;
private Pango.Layout layout; private Pango.Layout layout;
@ -54,13 +53,13 @@ class CustomWidget : Bin {
layout = null; layout = null;
stockid = Stock.Execute; stockid = Stock.Execute;
WidgetFlags |= WidgetFlags.NoWindow; HasWindow = false;
} }
private Gdk.Pixbuf Icon { private Gdk.Pixbuf Icon {
get { get {
if (icon == null) if (icon == null)
icon = RenderIcon (stockid, IconSize.Menu, ""); icon = RenderIconPixbuf (stockid, IconSize.Menu);
return icon; return icon;
} }
} }
@ -89,7 +88,7 @@ class CustomWidget : Bin {
} }
set { set {
stockid = value; stockid = value;
icon = RenderIcon (stockid, IconSize.Menu, ""); icon = RenderIconPixbuf (stockid, IconSize.Menu);
} }
} }
@ -108,41 +107,26 @@ class CustomWidget : Bin {
} }
} }
protected override bool OnExposeEvent (Gdk.EventExpose args) protected override bool OnDrawn (Cairo.Context cr)
{ {
Gdk.Rectangle exposeArea;
Gdk.Rectangle titleArea = TitleArea; Gdk.Rectangle titleArea = TitleArea;
if (args.Area.Intersect (titleArea, out exposeArea)) Gdk.CairoHelper.SetSourcePixbuf (cr, Icon, 0, 0);
GdkWindow.DrawPixbuf (Style.BackgroundGC (State), Icon, 0, 0, cr.Paint ();
titleArea.X, titleArea.Y, Icon.Width,
Icon.Height, Gdk.RgbDither.None, 0, 0);
titleArea.X += icon.Width + 1; int layout_x = icon.Width + 1;
titleArea.Width -= icon.Width - 1; titleArea.Width -= icon.Width - 1;
if (args.Area.Intersect (titleArea, out exposeArea)) { int layoutWidth, layoutHeight;
int layoutWidth, layoutHeight; Layout.GetPixelSize (out layoutWidth, out layoutHeight);
Layout.GetPixelSize (out layoutWidth, out layoutHeight);
titleArea.Y += (titleArea.Height - layoutHeight) / 2; int layout_y = (titleArea.Height - layoutHeight) / 2;
Style.PaintLayout (Style, GdkWindow, State, StyleContext.RenderLayout (cr, layout_x, layout_y, Layout);
true, exposeArea, this, null,
titleArea.X, titleArea.Y, Layout);
}
return base.OnExposeEvent (args); return base.OnDrawn (cr);
} }
protected override void OnRealized ()
{
WidgetFlags |= WidgetFlags.Realized;
GdkWindow = ParentWindow;
Style = Style.Attach (GdkWindow);
}
protected override void OnSizeAllocated (Gdk.Rectangle allocation) protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{ {
base.OnSizeAllocated (allocation); base.OnSizeAllocated (allocation);
@ -161,22 +145,39 @@ class CustomWidget : Bin {
} }
} }
protected override void OnSizeRequested (ref Requisition requisition) protected override void OnGetPreferredWidth (out int minimum_width, out int natural_width)
{ {
requisition.Width = requisition.Height = (int)BorderWidth * 2; minimum_width = natural_width = (int)BorderWidth * 2 + Icon.Width + 1;
requisition.Width += Icon.Width + 1;
int layoutWidth, layoutHeight; int layoutWidth, layoutHeight;
Layout.GetPixelSize (out layoutWidth, out layoutHeight); Layout.GetPixelSize (out layoutWidth, out layoutHeight);
requisition.Height += layoutHeight;
if (Child != null && Child.Visible) { if (Child != null && Child.Visible) {
Requisition childReq = Child.SizeRequest (); int child_min_width, child_nat_width;
requisition.Height += childReq.Height; Child.GetPreferredWidth (out child_min_width, out child_nat_width);
requisition.Width += Math.Max (layoutWidth, childReq.Width); minimum_width += Math.Max (layoutWidth, child_min_width);
natural_width += Math.Max (layoutWidth, child_nat_width);
} else { } else {
requisition.Width += layoutWidth; minimum_width += layoutWidth;
natural_width += layoutWidth;
}
}
protected override void OnGetPreferredHeight (out int minimum_height, out int natural_height)
{
minimum_height = natural_height = (int)BorderWidth * 2;
int layoutWidth, layoutHeight;
Layout.GetPixelSize (out layoutWidth, out layoutHeight);
minimum_height += layoutHeight;
natural_height += layoutHeight;
if (Child != null && Child.Visible) {
int child_min_height, child_nat_height;
Child.GetPreferredHeight (out child_min_height, out child_nat_height);
minimum_height += Math.Max (layoutHeight, child_min_height);
natural_height += Math.Max (layoutHeight, child_nat_height);
} }
} }
} }

View file

@ -8,7 +8,7 @@ DOTNET_TARGETS=
DOTNET_ASSEMBLY= DOTNET_ASSEMBLY=
endif endif
TARGETS = gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe treemodeldemo.exe actions.exe spawn.exe assistant.exe registerprop.exe gexceptiontest.exe native-instantiation.exe polarfixed.exe cairo-sample.exe scribble.exe # custom-widget.exe custom-cellrenderer.exe scribble-xinput.exe testdnd.exe $(DOTNET_TARGETS) TARGETS = gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe treemodeldemo.exe actions.exe spawn.exe assistant.exe registerprop.exe gexceptiontest.exe native-instantiation.exe polarfixed.exe cairo-sample.exe scribble.exe testdnd.exe custom-cellrenderer.exe custom-widget.exe #scribble-xinput.exe $(DOTNET_TARGETS)
DEBUGS = $(addsuffix .mdb, $(TARGETS)) DEBUGS = $(addsuffix .mdb, $(TARGETS))

View file

@ -290,7 +290,7 @@ public class TestDnd {
have_drag = false; have_drag = false;
// FIXME? Kinda wonky binding. // FIXME? Kinda wonky binding.
(sender as Gtk.Image).FromPixbuf = trashcan_closed_pixbuf; (sender as Gtk.Image).Pixbuf = trashcan_closed_pixbuf;
} }
private static void HandleTargetDragMotion (object sender, DragMotionArgs args) private static void HandleTargetDragMotion (object sender, DragMotionArgs args)
@ -298,13 +298,13 @@ public class TestDnd {
if (! have_drag) { if (! have_drag) {
have_drag = true; have_drag = true;
// FIXME? Kinda wonky binding. // FIXME? Kinda wonky binding.
(sender as Gtk.Image).FromPixbuf = trashcan_open_pixbuf; (sender as Gtk.Image).Pixbuf = trashcan_open_pixbuf;
} }
Widget source_widget = Gtk.Drag.GetSourceWidget (args.Context); Widget source_widget = Gtk.Drag.GetSourceWidget (args.Context);
Console.WriteLine ("motion, source {0}", source_widget == null ? "null" : source_widget.ToString ()); Console.WriteLine ("motion, source {0}", source_widget == null ? "null" : source_widget.ToString ());
Atom [] targets = args.Context.Targets; Atom [] targets = args.Context.ListTargets ();
foreach (Atom a in targets) foreach (Atom a in targets)
Console.WriteLine (a.Name); Console.WriteLine (a.Name);
@ -316,7 +316,7 @@ public class TestDnd {
{ {
Console.WriteLine ("drop"); Console.WriteLine ("drop");
have_drag = false; have_drag = false;
(sender as Gtk.Image).FromPixbuf = trashcan_closed_pixbuf; (sender as Gtk.Image).Pixbuf = trashcan_closed_pixbuf;
#if BROKEN // Context.Targets is not defined in the bindings #if BROKEN // Context.Targets is not defined in the bindings
if (Context.Targets.Length != 0) { if (Context.Targets.Length != 0) {
@ -474,7 +474,7 @@ public class TestDnd {
Button button; Button button;
Pixbuf drag_icon_pixbuf; Pixbuf drag_icon_pixbuf;
Application.Init (); Gtk.Application.Init ();
window = new Gtk.Window (Gtk.WindowType.Toplevel); window = new Gtk.Window (Gtk.WindowType.Toplevel);
window.DeleteEvent += new DeleteEventHandler (OnDelete); window.DeleteEvent += new DeleteEventHandler (OnDelete);
@ -522,8 +522,7 @@ public class TestDnd {
Gtk.Drag.SourceSet (button, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask, Gtk.Drag.SourceSet (button, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask,
target_table, DragAction.Copy | DragAction.Move); target_table, DragAction.Copy | DragAction.Move);
// FIXME can I pass a pixbuf here instead? Gtk.Drag.SourceSetIconPixbuf (button, drag_icon_pixbuf);
// Gtk.Drag.SourceSetIcon (button, window.Colormap, drag_icon, drag_mask);
table.Attach (button, 0, 1, 1, 2, table.Attach (button, 0, 1, 1, 2,
AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill,
@ -534,11 +533,11 @@ public class TestDnd {
window.ShowAll (); window.ShowAll ();
Application.Run (); Gtk.Application.Run ();
} }
private static void OnDelete (object o, DeleteEventArgs e) private static void OnDelete (object o, DeleteEventArgs e)
{ {
Application.Quit (); Gtk.Application.Quit ();
} }
} }