Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cummings <mcumming@microsoft.com>2019-08-23 20:18:02 +0300
committerMichael Cummings <mcumming@microsoft.com>2019-08-23 20:20:26 +0300
commit6d6df7fcbbef74800652bd50e9706b2394fb68c1 (patch)
tree611cb995dea763899245521fb74492a849396c99 /Xwt.Gtk
parent449535d13449542e41d4d8da9770e4c161b840fe (diff)
Adding NRE checks and preventing double event subscribing
Diffstat (limited to 'Xwt.Gtk')
-rw-r--r--Xwt.Gtk/Xwt.GtkBackend/ButtonBackend.cs9
-rw-r--r--Xwt.Gtk/Xwt.GtkBackend/MenuItemBackend.cs8
-rw-r--r--Xwt.Gtk/Xwt.GtkBackend/Util.cs20
3 files changed, 24 insertions, 13 deletions
diff --git a/Xwt.Gtk/Xwt.GtkBackend/ButtonBackend.cs b/Xwt.Gtk/Xwt.GtkBackend/ButtonBackend.cs
index e0ab8e77..71c80ff4 100644
--- a/Xwt.Gtk/Xwt.GtkBackend/ButtonBackend.cs
+++ b/Xwt.Gtk/Xwt.GtkBackend/ButtonBackend.cs
@@ -130,6 +130,8 @@ namespace Xwt.GtkBackend
if (image.Backend != null)
imageWidget = new ImageBox (ApplicationContext, image.WithDefaultSize (Gtk.IconSize.Button));
+ labelWidget.Realized -= HandleStyleUpdate;
+ labelWidget.StyleSet -= HandleStyleUpdate;
labelWidget = null;
if (label != null && imageWidget == null) {
@@ -209,6 +211,8 @@ namespace Xwt.GtkBackend
Widget.Label = null;
Widget.Image = labelWidget;
}
+ labelWidget.Realized -= HandleStyleUpdate;
+ labelWidget.StyleSet -= HandleStyleUpdate;
formattedText = label;
labelWidget.ApplyFormattedText (formattedText);
@@ -252,7 +256,7 @@ namespace Xwt.GtkBackend
public void SetFormattedText (FormattedText text)
{
- SetContent (text.Text, Widget.UseUnderline, this.image, ContentPosition.Center);
+ SetContent (text?.Text, Widget.UseUnderline, this.image, ContentPosition.Center);
SetFormattedContent (text, ContentPosition.Center);
}
@@ -310,9 +314,10 @@ namespace Xwt.GtkBackend
protected override void Dispose (bool disposing)
{
- if (labelWidget != null) {
+ if (disposing && labelWidget != null) {
labelWidget.Realized -= HandleStyleUpdate;
labelWidget.StyleSet -= HandleStyleUpdate;
+ labelWidget = null;
}
base.Dispose (disposing);
}
diff --git a/Xwt.Gtk/Xwt.GtkBackend/MenuItemBackend.cs b/Xwt.Gtk/Xwt.GtkBackend/MenuItemBackend.cs
index 5633b937..2f8af07c 100644
--- a/Xwt.Gtk/Xwt.GtkBackend/MenuItemBackend.cs
+++ b/Xwt.Gtk/Xwt.GtkBackend/MenuItemBackend.cs
@@ -172,11 +172,14 @@ namespace Xwt.GtkBackend
FormattedText formattedText = null;
public void SetFormattedText (FormattedText text)
{
- label.Text = text.Text;
+ label.Text = text?.Text;
formattedText = text;
+ label.Realized -= HandleStyleUpdate;
+ label.StyleSet -= HandleStyleUpdate;
+ label.ApplyFormattedText(text);
label.Realized += HandleStyleUpdate;
label.StyleSet += HandleStyleUpdate;
- label.ApplyFormattedText(text);
+
}
void HandleStyleUpdate (object sender, EventArgs e)
@@ -273,6 +276,7 @@ namespace Xwt.GtkBackend
if (label != null) {
label.Realized -= HandleStyleUpdate;
label.StyleSet -= HandleStyleUpdate;
+ label = null;
}
}
}
diff --git a/Xwt.Gtk/Xwt.GtkBackend/Util.cs b/Xwt.Gtk/Xwt.GtkBackend/Util.cs
index 3b12e967..e4bb7010 100644
--- a/Xwt.Gtk/Xwt.GtkBackend/Util.cs
+++ b/Xwt.Gtk/Xwt.GtkBackend/Util.cs
@@ -284,16 +284,18 @@ namespace Xwt.GtkBackend
internal static void ApplyFormattedText(this Gtk.Label label, FormattedText text)
{
var list = new FastPangoAttrList ();
- if (label.IsRealized) {
- var color = Gdk.Color.Zero;
- var colorVal = label.StyleGetProperty ("link-color");
- if (colorVal is Gdk.Color)
- color = (Gdk.Color)colorVal;
- if (!color.Equals (Gdk.Color.Zero))
- list.DefaultLinkColor = color;
+ if (text != null) {
+ if (label.IsRealized) {
+ var color = Gdk.Color.Zero;
+ var colorVal = label.StyleGetProperty ("link-color");
+ if (colorVal is Gdk.Color)
+ color = (Gdk.Color)colorVal;
+ if (!color.Equals (Gdk.Color.Zero))
+ list.DefaultLinkColor = color;
+ }
+ var indexer = new TextIndexer (text.Text);
+ list.AddAttributes (indexer, text.Attributes);
}
- var indexer = new TextIndexer (text.Text);
- list.AddAttributes (indexer, text.Attributes);
gtk_label_set_attributes (label.Handle, list.Handle);
}
}