diff --git a/gtk/CellRenderer.custom b/gtk/CellRenderer.custom index 6a6b20b63..17e8f1d1b 100644 --- a/gtk/CellRenderer.custom +++ b/gtk/CellRenderer.custom @@ -54,7 +54,9 @@ try { CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer; 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; obj.OnGetSize (widg, ref cell_area, out a, out b, out c, out d); diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 9b787c7e9..e819d8e5c 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -7,6 +7,7 @@ 1 1 1 + false 1 true 1 @@ -531,8 +532,11 @@ out 1 out + out out out + out + out 1 out 1 diff --git a/sample/CustomCellRenderer.cs b/sample/CustomCellRenderer.cs index 53df19249..d9a47ae2e 100644 --- a/sample/CustomCellRenderer.cs +++ b/sample/CustomCellRenderer.cs @@ -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; - StateType state; - OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + int x = (int) (cell_area.X + this.Xpad); + int y = (int) (cell_area.Y + this.Ypad); + int width = (int) (cell_area.Width - this.Xpad * 2); + int height = (int) (cell_area.Height - this.Ypad * 2); - if (widget.HasFocus) - state = StateType.Active; - else - state = StateType.Normal; - - 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); + widget.StyleContext.Save (); + widget.StyleContext.AddClass ("trough"); + widget.StyleContext.RenderBackground (cr, x, y, width, height); + widget.StyleContext.RenderFrame (cr, x, y, width, height); - 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 () { - Application.Init (); + Gtk.Application.Init (); new Driver (); - Application.Run (); + Gtk.Application.Run (); } ListStore liststore; @@ -128,7 +127,7 @@ public class Driver : Gtk.Window void window_delete (object obj, DeleteEventArgs args) { - Application.Quit (); + Gtk.Application.Quit (); args.RetVal = true; } } diff --git a/sample/CustomWidget.cs b/sample/CustomWidget.cs index bd974bb8f..ddd7c3fbb 100644 --- a/sample/CustomWidget.cs +++ b/sample/CustomWidget.cs @@ -5,7 +5,7 @@ using System; class CustomWidgetTest { public static int Main (string[] args) { - Application.Init (); + Gtk.Application.Init (); Window win = new Window ("Custom Widget Test"); win.DeleteEvent += new DeleteEventHandler (OnQuit); @@ -30,18 +30,17 @@ class CustomWidgetTest { win.Add (paned); win.ShowAll (); - Application.Run (); + Gtk.Application.Run (); return 0; } static void OnQuit (object sender, DeleteEventArgs args) { - Application.Quit (); + Gtk.Application.Quit (); } } class CustomWidget : Bin { - internal static GType customWidgetGType; private Gdk.Pixbuf icon; private string label; private Pango.Layout layout; @@ -54,13 +53,13 @@ class CustomWidget : Bin { layout = null; stockid = Stock.Execute; - WidgetFlags |= WidgetFlags.NoWindow; + HasWindow = false; } private Gdk.Pixbuf Icon { get { if (icon == null) - icon = RenderIcon (stockid, IconSize.Menu, ""); + icon = RenderIconPixbuf (stockid, IconSize.Menu); return icon; } } @@ -89,7 +88,7 @@ class CustomWidget : Bin { } set { 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; - if (args.Area.Intersect (titleArea, out exposeArea)) - GdkWindow.DrawPixbuf (Style.BackgroundGC (State), Icon, 0, 0, - titleArea.X, titleArea.Y, Icon.Width, - Icon.Height, Gdk.RgbDither.None, 0, 0); + Gdk.CairoHelper.SetSourcePixbuf (cr, Icon, 0, 0); + cr.Paint (); - titleArea.X += icon.Width + 1; + int layout_x = icon.Width + 1; titleArea.Width -= icon.Width - 1; - if (args.Area.Intersect (titleArea, out exposeArea)) { - int layoutWidth, layoutHeight; - Layout.GetPixelSize (out layoutWidth, out layoutHeight); + int layoutWidth, layoutHeight; + Layout.GetPixelSize (out layoutWidth, out layoutHeight); - titleArea.Y += (titleArea.Height - layoutHeight) / 2; - - Style.PaintLayout (Style, GdkWindow, State, - true, exposeArea, this, null, - titleArea.X, titleArea.Y, Layout); - } + int layout_y = (titleArea.Height - layoutHeight) / 2; + + StyleContext.RenderLayout (cr, layout_x, layout_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) { 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; - requisition.Width += Icon.Width + 1; - + minimum_width = natural_width = (int)BorderWidth * 2 + Icon.Width + 1; int layoutWidth, layoutHeight; Layout.GetPixelSize (out layoutWidth, out layoutHeight); - requisition.Height += layoutHeight; if (Child != null && Child.Visible) { - Requisition childReq = Child.SizeRequest (); - requisition.Height += childReq.Height; - - requisition.Width += Math.Max (layoutWidth, childReq.Width); + int child_min_width, child_nat_width; + Child.GetPreferredWidth (out child_min_width, out child_nat_width); + + minimum_width += Math.Max (layoutWidth, child_min_width); + natural_width += Math.Max (layoutWidth, child_nat_width); } 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); } } } diff --git a/sample/Makefile.am b/sample/Makefile.am index 0e8aa4040..86f12740c 100755 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -8,7 +8,7 @@ DOTNET_TARGETS= DOTNET_ASSEMBLY= 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)) diff --git a/sample/TestDnd.cs b/sample/TestDnd.cs index f571355ca..21a1777d8 100644 --- a/sample/TestDnd.cs +++ b/sample/TestDnd.cs @@ -290,7 +290,7 @@ public class TestDnd { have_drag = false; // 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) @@ -298,13 +298,13 @@ public class TestDnd { if (! have_drag) { have_drag = true; // 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); 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) Console.WriteLine (a.Name); @@ -316,7 +316,7 @@ public class TestDnd { { Console.WriteLine ("drop"); 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 (Context.Targets.Length != 0) { @@ -474,7 +474,7 @@ public class TestDnd { Button button; Pixbuf drag_icon_pixbuf; - Application.Init (); + Gtk.Application.Init (); window = new Gtk.Window (Gtk.WindowType.Toplevel); window.DeleteEvent += new DeleteEventHandler (OnDelete); @@ -522,8 +522,7 @@ public class TestDnd { Gtk.Drag.SourceSet (button, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask, target_table, DragAction.Copy | DragAction.Move); - // FIXME can I pass a pixbuf here instead? - // Gtk.Drag.SourceSetIcon (button, window.Colormap, drag_icon, drag_mask); + Gtk.Drag.SourceSetIconPixbuf (button, drag_icon_pixbuf); table.Attach (button, 0, 1, 1, 2, AttachOptions.Expand | AttachOptions.Fill, @@ -534,11 +533,11 @@ public class TestDnd { window.ShowAll (); - Application.Run (); + Gtk.Application.Run (); } private static void OnDelete (object o, DeleteEventArgs e) { - Application.Quit (); + Gtk.Application.Quit (); } }