Mar 19, 2006

Answer = Gtk.EventBox

I don't usually send emails to mailing lists that am subscribed to and wait for an answer, when I do is because I couldn't find any solution to my problem or, in the other way, want to announce something (like our Mono Hispano ezine!). However I (think that) finally find the answer ('cause still needs further testing) for bringing-to-front widgets drawn in a Gtk.Layout, using the following code as primary sample:

using Gtk;
using System;

public class Sample
{
public static void Main ()
{
Application.Init ();
Window window = new Window ("");
Layout layout = new Layout (new Adjustment (IntPtr.Zero),
new Adjustment (IntPtr.Zero));
Button b1 = new Button ("1");
Button b2 = new Button ("2");
layout.Put (b1, 10, 20);
layout.Put (b2, 15, 15);
ScrolledWindow scrolled = new ScrolledWindow ();
scrolled.AddWithViewport (layout);
window.Add (scrolled);
window.ShowAll ();
Application.Run ();
}
}

You will notice the overlap of b2 over b1, if you switch lines b1 overlaps b2, however, there isn't a solution for doing this after showing the Gtk.Window.

Solution? Use Gtk.EventBox, after reading gmane's archive I figured it out! However I didn't know Gtk.Button doesn't owns a Gdk.Window, by don't owning a Gdk.Window, Gtk.Button draws over anything (or any other Gdk.Windowless-widget) so, that might the problem am facing recently. Using Gdk.Window.Lower (), sends to back, Next code shows solution:

using Gtk;
using System;

public class Sample
{
public static void Main ()
{
Application.Init ();
EventBox e1 = new EventBox ();
EventBox e2 = new EventBox ();
Window window = new Window ("");
Layout layout = new Layout (new Adjustment (IntPtr.Zero),
new Adjustment (IntPtr.Zero));
layout.Add (e1);
layout.Add (e2);
Button b1 = new Button ("1");
b1.Clicked += new EventHandler (ButtonClick);
e1.Add (b1);
Button b2 = new Button ("2");
b2.Clicked += new EventHandler (ButtonClick);
e2.Add (b2);
layout.Move (e1, 10, 20);
layout.Move (e2, 15, 15);
ScrolledWindow scrolled = new ScrolledWindow ();
scrolled.AddWithViewport (layout);
window.Add (scrolled);
window.ShowAll ();
Application.Run ();
}

public static void ButtonClick (object o, EventArgs a)
{
Button b = o as Button;
b.GdkWindow.Raise ();
}
}

Nice!. By the way, Rodolfo and I improved MonoUML a little bit, now MonoUML gots its history navigator

MonoUML's history navigator