Skip to content

Commit

Permalink
Merge pull request #2662 from cwensley/curtis/gtk-remove-vhbox-usage
Browse files Browse the repository at this point in the history
Gtk: Use Gtk.Box vs deprecated HBox/VBox
  • Loading branch information
cwensley authored Jun 3, 2024
2 parents cba28b5 + fc1c2a7 commit 2b38807
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 74 deletions.
16 changes: 6 additions & 10 deletions src/Eto.Gtk/CustomControls/DateComboBoxDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ void UpdateClock ()

Gtk.Widget CalendarControls ()
{
var vbox = new Gtk.VBox {
Spacing = 5
};
var vbox = new Gtk.Box(Gtk.Orientation.Vertical, 5);

calendar = new Gtk.Calendar
{
Expand All @@ -158,8 +156,8 @@ Gtk.Widget CalendarControls ()
};

vbox.PackStart(calendar, false, false, 0);
var hbox = new Gtk.HBox (true, 6);

var hbox = new Gtk.Box(Gtk.Orientation.Horizontal, 6) { Homogeneous = true };

var todayButton = new Gtk.Button {
CanFocus = true,
Expand Down Expand Up @@ -217,13 +215,12 @@ Gtk.SpinButton CreateSpinner (int max, int increment, Gtk.SpinButton parent)

Gtk.Widget ClockControls ()
{

#if GTK2
var vbox = new Gtk.VBox ();
var spinners = new Gtk.HBox ();
#else
var vbox = new Gtk.HBox ();
var spinners = new Gtk.VBox ();
var vbox = new Gtk.Box(Gtk.Orientation.Vertical, 0);
var spinners = new Gtk.Box(Gtk.Orientation.Vertical, 0);
#endif
vbox.Spacing = 6;
spinners.Spacing = 6;
Expand Down Expand Up @@ -270,8 +267,7 @@ void CreateControls ()
SkipPagerHint = true;
SkipTaskbarHint = true;

var hbox = new Gtk.HBox {
Spacing = 5,
var hbox = new Gtk.Box(Gtk.Orientation.Horizontal, 5) {
BorderWidth = 3
};

Expand Down
27 changes: 13 additions & 14 deletions src/Eto.Gtk/Forms/Controls/ButtonHandler.gtk3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,28 @@ void SetImagePosition()
var showLabel = !string.IsNullOrEmpty(label.Text);
if (showImage && showLabel)
{
Gtk.VBox vbox;
Gtk.HBox hbox;
Gtk.Box box;
switch (ImagePosition)
{
case ButtonImagePosition.Above:
child = vbox = new Gtk.VBox(false, 2);
vbox.PackStart(gtkimage, true, true, 0);
vbox.PackEnd(label, false, true, 0);
child = box = new Gtk.Box(Gtk.Orientation.Vertical, 2);
box.PackStart(gtkimage, true, true, 0);
box.PackEnd(label, false, true, 0);
break;
case ButtonImagePosition.Below:
child = vbox = new Gtk.VBox(false, 2);
vbox.PackStart(label, false, true, 0);
vbox.PackEnd(gtkimage, true, true, 0);
child = box = new Gtk.Box(Gtk.Orientation.Vertical, 2);
box.PackStart(label, false, true, 0);
box.PackEnd(gtkimage, true, true, 0);
break;
case ButtonImagePosition.Left:
child = hbox = new Gtk.HBox(false, 2);
hbox.PackStart(gtkimage, false, true, 0);
hbox.PackStart(label, true, true, 0);
child = box = new Gtk.Box(Gtk.Orientation.Horizontal, 2);
box.PackStart(gtkimage, false, true, 0);
box.PackStart(label, true, true, 0);
break;
case ButtonImagePosition.Right:
child = hbox = new Gtk.HBox(false, 2);
hbox.PackStart(label, true, true, 0);
hbox.PackEnd(gtkimage, false, true, 0);
child = box = new Gtk.Box(Gtk.Orientation.Horizontal, 2);
box.PackStart(label, true, true, 0);
box.PackEnd(gtkimage, false, true, 0);
break;
case ButtonImagePosition.Overlay:
#if GTK2
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Gtk/Forms/Controls/CalendarHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void SetContent()
suppressRangeChanged--;

if (box == null)
box = new Gtk.HBox();
box = new Gtk.Box(Gtk.Orientation.Horizontal, 0);
else
box.Remove(endCalendar);
box.PackStart(Control, true, true, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/Eto.Gtk/Forms/Controls/DocumentPageHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Eto.GtkSharp.Drawing;
namespace Eto.GtkSharp.Forms.Controls
{
public class DocumentPageHandler : GtkPanel<Gtk.VBox, DocumentPage, DocumentPage.ICallback>, DocumentPage.IHandler
public class DocumentPageHandler : GtkPanel<Gtk.Box, DocumentPage, DocumentPage.ICallback>, DocumentPage.IHandler
{
Gtk.Label label;

internal Gtk.Button closeButton;
readonly Gtk.HBox tab;
readonly Gtk.Box tab;
Gtk.Image gtkimage;
Image image;
public static Size MaxImageSize = new Size(16, 16);
Expand All @@ -27,8 +27,8 @@ private static Gdk.Pixbuf LoadCloseImage()

public DocumentPageHandler()
{
Control = new Gtk.VBox();
tab = new Gtk.HBox();
Control = new Gtk.Box(Gtk.Orientation.Vertical, 0);
tab = new Gtk.Box(Gtk.Orientation.Horizontal, 0);
closeButton = new Gtk.Button();
closeButton.Relief = Gtk.ReliefStyle.None;
closeButton.CanFocus = false;
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Gtk/Forms/Controls/DrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Eto.GtkSharp.Forms.Controls
{
public class DrawableHandler : GtkPanel<Gtk.EventBox, Drawable, Drawable.ICallback>, Drawable.IHandler
{
Gtk.VBox content;
Gtk.Box content;

public bool SupportsCreateGraphics { get { return true; } }

Expand All @@ -17,7 +17,7 @@ public void Create()
Control.CanDefault = true;
Control.Events |= Gdk.EventMask.ButtonPressMask;

content = new Gtk.VBox();
content = new Gtk.Box(Gtk.Orientation.Vertical, 0);

Control.Add(content);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Gtk/Forms/Controls/FilePickerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class FilePickerHandler : GtkControl<Gtk.EventBox, FilePicker, FilePicker
{
FileAction action;
Gtk.FileChooserButton filebutton;
Gtk.HBox savebox;
Gtk.Box savebox;
Gtk.Entry saveentry;
Gtk.Button savebutton;

Expand All @@ -17,7 +17,7 @@ public FilePickerHandler()

// Save is not a valid option for FileChooserButton, therefore
// we need to create our own, or use the ThemedFilePickerHandler
savebox = new Gtk.HBox();
savebox = new Gtk.Box(Gtk.Orientation.Horizontal, 0);
saveentry = new Gtk.Entry();
savebox.PackStart(saveentry, true, true, 0);
savebutton = new Gtk.Button();
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Gtk/Forms/Controls/PanelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void SetContainerContent(Gtk.Widget content)
public PanelHandler()
{
Control = new Gtk.EventBox();
box = new Gtk.VBox();
box = new Gtk.Box(Gtk.Orientation.Vertical, 0);
Control.Add(box);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Eto.Gtk/Forms/Controls/ScrollableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Eto.GtkSharp.Forms.Controls
public class ScrollableHandler : GtkPanel<Gtk.ScrolledWindow, Scrollable, Scrollable.ICallback>, Scrollable.IHandler
{
readonly Gtk.Viewport vp;
readonly Gtk.HBox hbox;
readonly Gtk.VBox vbox;
readonly Gtk.Box hbox;
readonly Gtk.Box vbox;
BorderType border;
bool expandWidth = true;
bool expandHeight = true;
Expand Down Expand Up @@ -64,8 +64,11 @@ protected override void OnAdjustSizeRequest(Gtk.Orientation orientation, out int
#endif
}

public class EtoVBox : Gtk.VBox
public class EtoVBox : Gtk.Box
{
public EtoVBox() : base(Gtk.Orientation.Vertical, 0)
{
}
#if GTK3
protected override void OnAdjustSizeRequest(Gtk.Orientation orientation, out int minimum_size, out int natural_size)
{
Expand All @@ -86,7 +89,7 @@ public ScrollableHandler()
Control.SetSizeRequest(10, 10);
#endif
// ensure things are top-left and not centered
hbox = new Gtk.HBox();
hbox = new Gtk.Box(Gtk.Orientation.Horizontal, 0);

vbox = new EtoVBox();
vbox.PackStart(hbox, true, true, 0);
Expand Down
13 changes: 6 additions & 7 deletions src/Eto.Gtk/Forms/Controls/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ public class SliderHandler : GtkControl<Gtk.EventBox, Slider, Slider.ICallback>,
int max = 100;
int tick = 1;
Gtk.Scale scale;
Orientation orientation;

public SliderHandler()
{
this.Control = new Gtk.EventBox();
//Control.VisibleWindow = false;
scale = new Gtk.HScale(min, max, 1);
scale = new Gtk.Scale(Gtk.Orientation.Horizontal, min, max, 1);
this.Control.Child = scale;
}

Expand Down Expand Up @@ -107,24 +108,22 @@ public int TickFrequency

public Orientation Orientation
{
get
{
return (scale is Gtk.HScale) ? Orientation.Horizontal : Orientation.Vertical;
}
get => orientation;
set
{
if (Orientation != value)
{
orientation = value;
scale.ValueChanged -= Connector.HandleScaleValueChanged;
Control.Remove(scale);
#if !GTKCORE
scale.Destroy();
#endif
scale.Dispose();
if (value == Orientation.Horizontal)
scale = new Gtk.HScale(min, max, 1);
scale = new Gtk.Scale(Gtk.Orientation.Horizontal, min, max, 1);
else
scale = new Gtk.VScale(min, max, 1);
scale = new Gtk.Scale(Gtk.Orientation.Vertical, min, max, 1);
scale.ValueChanged += Connector.HandleScaleValueChanged;
Control.Child = scale;
scale.ShowAll();
Expand Down
14 changes: 11 additions & 3 deletions src/Eto.Gtk/Forms/Controls/SplitterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ int GetPreferredPanelSize(int width1, int width2)
return width1 + width2 + SplitterWidth;
}

class EtoHPaned : Gtk.HPaned
class EtoHPaned : Gtk.Paned
{
WeakReference handler;

public EtoHPaned() : base(Gtk.Orientation.Horizontal)
{
}

public SplitterHandler Handler
{
get => handler?.Target as SplitterHandler;
Expand Down Expand Up @@ -98,10 +102,14 @@ protected override void OnSizeAllocated(Gdk.Rectangle allocation)
}
}

class EtoVPaned : Gtk.VPaned
class EtoVPaned : Gtk.Paned
{
WeakReference handler;

public EtoVPaned() : base(Gtk.Orientation.Vertical)
{
}

public SplitterHandler Handler
{
get => handler?.Target as SplitterHandler;
Expand Down Expand Up @@ -551,7 +559,7 @@ void EnsurePosition()

static Gtk.Widget EmptyContainer()
{
var bin = new Gtk.VBox();
var bin = new Gtk.Box(Gtk.Orientation.Horizontal, 0);
bin.Visible = false;
bin.NoShowAll = true;
return bin;
Expand Down
8 changes: 4 additions & 4 deletions src/Eto.Gtk/Forms/Controls/TabPageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Eto.GtkSharp.Forms.Controls
{
public class TabPageHandler : GtkPanel<Gtk.VBox, TabPage, TabPage.ICallback>, TabPage.IHandler
public class TabPageHandler : GtkPanel<Gtk.Box, TabPage, TabPage.ICallback>, TabPage.IHandler
{
Gtk.Label label;
readonly Gtk.HBox tab;
readonly Gtk.Box tab;
Gtk.Image gtkimage;
Image image;
public static Size MaxImageSize = new Size(16, 16);

public TabPageHandler()
{
Control = new Gtk.VBox();
tab = new Gtk.HBox();
Control = new Gtk.Box(Gtk.Orientation.Vertical, 0);
tab = new Gtk.Box(Gtk.Orientation.Horizontal, 0);
label = new Gtk.Label();
tab.PackEnd(label, true, true, 0);
tab.ShowAll();
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Gtk/Forms/CursorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class CursorHandler : WidgetHandler<Gdk.Cursor, Cursor>, Cursor.IHandler

public void Create(CursorType cursor)
{
Control = new Gdk.Cursor(cursor.ToGdk());
Control = new Gdk.Cursor(Gdk.Display.Default, cursor.ToGdk());
}

public void Create(Bitmap image, PointF hotspot)
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Gtk/Forms/DialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override void Initialize()
base.Initialize();
Control.KeyPressEvent += Connector.Control_KeyPressEvent;

var vbox = new EtoVBox { Handler = this };
var vbox = new EtoBox(Gtk.Orientation.Vertical, 0) { Handler = this };
vbox.PackStart(WindowActionControl, false, true, 0);
vbox.PackStart(WindowContentControl, true, true, 0);

Expand Down
7 changes: 6 additions & 1 deletion src/Eto.Gtk/Forms/EtoControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,19 @@ protected override void OnAdjustSizeRequest(Gtk.Orientation orientation, out int

}

public partial class EtoVBox : Gtk.VBox
public partial class EtoBox : Gtk.Box
{
WeakReference _handler;
public IGtkControl Handler
{
get => _handler?.Target as IGtkControl;
set => _handler = new WeakReference(value);
}
public EtoBox(Gtk.Orientation orientation, int spacing)
: base(orientation, spacing)
{

}

#if GTK3
protected override void OnGetPreferredWidth(out int minimum_width, out int natural_width)
Expand Down
14 changes: 13 additions & 1 deletion src/Eto.Gtk/Forms/EtoControls.tt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Eto;
namespace Eto.GtkSharp.Forms
{
<#
var controls = new[] { "Fixed", "EventBox", "VBox", "ScrolledWindow" };
var controls = new[] { "Fixed", "EventBox", "Box", "ScrolledWindow" };

foreach (var control in controls)
{
Expand All @@ -22,6 +22,18 @@ foreach (var control in controls)
get => _handler?.Target as IGtkControl;
set => _handler = new WeakReference(value);
}
<#
if (control == "Box")
{
#>
public EtoBox(Gtk.Orientation orientation, int spacing)
: base(orientation, spacing)
{

}
<#
}
#>

#if GTK3
protected override void OnGetPreferredWidth(out int minimum_width, out int natural_width)
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Gtk/Forms/FormHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public FormHandler()
Resizable = true;
Control.SetPosition(Gtk.WindowPosition.Center);

var vbox = new EtoVBox { Handler = this };
var vbox = new EtoBox(Gtk.Orientation.Vertical, 0) { Handler = this };
vbox.PackStart(WindowActionControl, false, true, 0);
vbox.PackStart(WindowContentControl, true, true, 0);
Control.Child = vbox;
Expand Down
Loading

0 comments on commit 2b38807

Please sign in to comment.