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 Hutchinson <m.j.hutchinson@gmail.com>2013-10-21 17:24:37 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2013-10-21 17:50:12 +0400
commit6800aa6ec6363805e012b8c882c4a2fd6f64d73f (patch)
tree4808dd381294203b48db1988877eb9d55f63b836 /Xwt.Gtk
parentb9f63045c06f54119cc5df34921287d424ff202a (diff)
[Gtk] Fix link locations in labels
#251: GTK label backend finds links incorrectly
Diffstat (limited to 'Xwt.Gtk')
-rw-r--r--Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs42
1 files changed, 30 insertions, 12 deletions
diff --git a/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs b/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs
index f05d8309..ca01723b 100644
--- a/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs
+++ b/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs
@@ -40,6 +40,7 @@ namespace Xwt.GtkBackend
Color? bgColor, textColor;
int wrapHeight, wrapWidth;
List<LabelLink> links;
+ TextIndexer indexer;
public LabelBackend ()
{
@@ -133,19 +134,27 @@ namespace Xwt.GtkBackend
LabelLink FindLink (double px, double py)
{
- var x = px * Pango.Scale.PangoScale;
- var y = py * Pango.Scale.PangoScale;
+ if (links == null)
+ return null;
+
+ var alloc = Label.Allocation;
+
+ int offsetX, offsetY;
+ Label.GetLayoutOffsets (out offsetX, out offsetY);
- int index, trailing;
- if (!Label.Layout.XyToIndex ((int)x, (int)y, out index, out trailing))
+ var x = (px - offsetX + alloc.X) * Pango.Scale.PangoScale;
+ var y = (py - offsetY + alloc.Y) * Pango.Scale.PangoScale;
+
+ int byteIndex, trailing;
+ if (!Label.Layout.XyToIndex ((int)x, (int)y, out byteIndex, out trailing))
return null;
- if (links != null) {
- foreach (var li in links) {
- if (index >= li.StartIndex && index <= li.EndIndex)
- return li;
- }
- }
+ int index = indexer.ByteIndexToIndex (byteIndex);
+
+ foreach (var li in links)
+ if (byteIndex >= li.StartIndex && byteIndex <= li.EndIndex)
+ return li;
+
return null;
}
@@ -189,14 +198,18 @@ namespace Xwt.GtkBackend
public virtual string Text {
get { return Label.Text; }
- set { Label.Text = value; }
+ set {
+ links = null;
+ indexer = null;
+ Label.Text = value;
+ }
}
public void SetFormattedText (FormattedText text)
{
Label.Text = text.Text;
var list = new FastPangoAttrList ();
- TextIndexer indexer = new TextIndexer (text.Text);
+ indexer = new TextIndexer (text.Text);
list.AddAttributes (indexer, text.Attributes);
gtk_label_set_attributes (Label.Handle, list.Handle);
@@ -215,6 +228,11 @@ namespace Xwt.GtkBackend
}
links.Add (ll);
}
+
+ if (links == null || links.Count == 0) {
+ links = null;
+ indexer = null;
+ }
}
[DllImport (GtkInterop.LIBGTK, CallingConvention=CallingConvention.Cdecl)]