Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[GTK] fix PopoverBackend focus and placement #362

Merged
merged 3 commits into from

2 participants

@sevoku
Collaborator

Fix Gtk PopoverBackend placement and initial focus. If position was set to Popover.Position.Bottom the window was drawn with wrong coordinates. Additionally Present () should be called to focus the popover window correctly.

sevoku added some commits
@sevoku sevoku [GTK] fix PopoverBackend focus and placement 0e9ef51
@sevoku sevoku [GTK] let parent window hide Popover.
Popover should be only hidden, if the parent window gets
the focus. Gtk.Window doesn't know which window receives
the focus and hides when child windows (e.g. ComboBox)
steal the focus, too.
3c0786a
@sevoku sevoku Merge remote-tracking branch 'mono/master' into fix-gtk-popover-backend
Conflicts:
	Xwt.Gtk/Xwt.GtkBackend/PopoverBackend.cs
273dee9
@slluis slluis merged commit 273dee9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 16, 2014
  1. @sevoku
Commits on Jul 21, 2014
  1. @sevoku

    [GTK] let parent window hide Popover.

    sevoku authored
    Popover should be only hidden, if the parent window gets
    the focus. Gtk.Window doesn't know which window receives
    the focus and hides when child windows (e.g. ComboBox)
    steal the focus, too.
Commits on Aug 4, 2014
  1. @sevoku

    Merge remote-tracking branch 'mono/master' into fix-gtk-popover-backend

    sevoku authored
    Conflicts:
    	Xwt.Gtk/Xwt.GtkBackend/PopoverBackend.cs
This page is out of date. Refresh to see the latest.
View
47 TestApps/Samples/Samples/PopoverSample.cs
@@ -31,18 +31,23 @@ namespace Samples
public class PopoverSample : VBox
{
Popover popover;
+ Popover popover2;
public PopoverSample ()
{
var btn = new Button ("Click me");
btn.Clicked += HandleClicked;
PackStart (btn);
+ var btn2 = new Button ("Click me");
+ btn2.Clicked += HandleClicked2;
+ PackEnd (btn2);
}
void HandleClicked (object sender, EventArgs e)
{
if (popover == null) {
popover = new Popover ();
+ popover.Padding = 20;
var table = new Table () { DefaultColumnSpacing = 20, DefaultRowSpacing = 10 };
// table.Margin.SetAll (60);
@@ -52,8 +57,13 @@ void HandleClicked (object sender, EventArgs e)
table.Add (new Label ("Family") { TextAlignment = Alignment.End }, 0, 1);
table.Add (new ComboBox (), 1, 1, vexpand:true);
+ var cmbStyle = new ComboBox ();
+ cmbStyle.Items.Add ("Normal");
+ cmbStyle.Items.Add ("Bold");
+ cmbStyle.Items.Add ("Italic");
+
table.Add (new Label ("Style") { TextAlignment = Alignment.End }, 0, 2);
- table.Add (new ComboBox (), 1, 2, vexpand:true);
+ table.Add (cmbStyle, 1, 2, vexpand:true);
table.Add (new Label ("Size") { TextAlignment = Alignment.End }, 0, 3);
table.Add (new SpinButton (), 1, 3, vexpand:true);
@@ -69,7 +79,40 @@ void HandleClicked (object sender, EventArgs e)
popover.Content = table;
}
// popover.Padding.SetAll (20);
- popover.Show (Popover.Position.Top, (Button)sender);
+ popover.Show (Popover.Position.Top, (Button)sender, new Rectangle (50, 10, 5, 5));
+ }
+
+ void HandleClicked2 (object sender, EventArgs e)
+ {
+ if (popover2 == null) {
+ popover2 = new Popover ();
+
+ var table = new Table () { DefaultColumnSpacing = 20, DefaultRowSpacing = 10 };
+ table.Add (new Label ("Font") { TextAlignment = Alignment.End }, 0, 0);
+ table.Add (new ComboBox (), 1, 0, vexpand:true);
+
+ table.Add (new Label ("Family") { TextAlignment = Alignment.End }, 0, 1);
+ table.Add (new ComboBox (), 1, 1, vexpand:true);
+
+ table.Add (new Label ("Style") { TextAlignment = Alignment.End }, 0, 2);
+ table.Add (new ComboBox (), 1, 2, vexpand:true);
+
+ table.Add (new Label ("Size") { TextAlignment = Alignment.End }, 0, 3);
+ table.Add (new SpinButton (), 1, 3, vexpand:true);
+
+ var b = new Button ("Add more");
+ table.Add (b, 0, 4);
+ int next = 5;
+ b.Clicked += delegate {
+ table.Add (new Label ("Row " + next), 0, next++);
+ };
+
+ table.Margin = 6;
+ popover2.Content = table;
+ }
+
+ var newRect = new Rectangle (((Button)sender).Size.Width * 0.66d, 0, 0, 0);
+ popover2.Show (Popover.Position.Bottom, (Button)sender, newRect);
}
}
}
View
28 Xwt.Gtk/Xwt.GtkBackend/PopoverBackend.cs
@@ -58,7 +58,6 @@ public PopoverWindow (Gtk.Widget child, Xwt.Popover.Position orientation) : base
this.alignment = new Gtk.Alignment (0, 0, 1, 1);
this.Add (alignment);
this.alignment.Add (child);
- this.FocusOutEvent += HandleFocusOutEvent;
OnScreenChanged (null);
}
@@ -73,11 +72,6 @@ public void ReleaseInnerWidget ()
alignment.Remove (alignment.Child);
}
- void HandleFocusOutEvent (object o, FocusOutEventArgs args)
- {
- this.Hide ();
- }
-
public void SetPadding (WidgetSpacing spacing)
{
alignment.LeftPadding = radius + (uint) spacing.Left;
@@ -98,7 +92,7 @@ protected override bool OnDrawn (Context ctx)
var bounds = new Xwt.Rectangle (0.5, 0.5, w - 1, h - 1);
var backgroundColor = Xwt.Drawing.Color.FromBytes (230, 230, 230, 230);
var black = Xwt.Drawing.Color.FromBytes (60, 60, 60);
-
+
// We clear the surface with a transparent color if possible
if (supportAlpha)
ctx.SetSourceRGBA (1.0, 1.0, 1.0, 0.0);
@@ -201,6 +195,7 @@ public void Show (Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Re
popover = new PopoverWindow ((Gtk.Widget)((WidgetBackend)Toolkit.GetBackend (child)).NativeWidget, orientation);
popover.SetPadding (frontend.Padding);
popover.TransientFor = ((WindowFrameBackend)Toolkit.GetBackend (parent)).Window;
+ popover.TransientFor.FocusInEvent += HandleParentFocusInEvent;
popover.DestroyWithParent = true;
popover.Hidden += (o, args) => {
popover.ReleaseInnerWidget ();
@@ -214,11 +209,26 @@ public void Show (Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Re
positionRect = positionRect.Offset (screenBounds.Location);
var position = new Point (positionRect.Center.X, popover.ArrowPosition == Popover.Position.Top ? positionRect.Bottom : positionRect.Top);
popover.ShowAll ();
+ popover.Present ();
popover.GrabFocus ();
int w, h;
popover.GetSize (out w, out h);
- popover.Move ((int)position.X - w / 2, (int)position.Y);
- popover.SizeAllocated += (o, args) => { popover.Move ((int)position.X - args.Allocation.Width / 2, (int)position.Y); popover.GrabFocus (); };
+ if (popover.ArrowPosition == Popover.Position.Top)
+ popover.Move ((int)position.X - w / 2, (int)position.Y);
+ else
+ popover.Move ((int)position.X - w / 2, (int)position.Y - h);
+ popover.SizeAllocated += (o, args) => {
+ if (popover.ArrowPosition == Popover.Position.Top)
+ popover.Move ((int)position.X - args.Allocation.Width / 2, (int)position.Y);
+ else
+ popover.Move ((int)position.X - args.Allocation.Width / 2, (int)position.Y - args.Allocation.Height);
+ popover.GrabFocus ();
+ };
+ }
+
+ void HandleParentFocusInEvent (object o, FocusInEventArgs args)
+ {
+ Hide ();
}
public void Hide ()
Something went wrong with that request. Please try again.