[banshee] Uncomment the support for ListView tooltips
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Subject: [banshee] Uncomment the support for ListView tooltips
- Date: Thu, 18 Jun 2009 14:12:33 -0400 (EDT)
commit 40bdd4f8271618330674d8d70f70faa9b1009be4
Author: Gabriel Burt <gabriel burt gmail com>
Date: Thu Jun 18 12:39:08 2009 -0500
Uncomment the support for ListView tooltips
Also add ITooltipCell interface to allow any ColumnCell implementation
to have tooltips, not just ColumnCellText ones.
.../Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs | 15 +++++--
.../Hyena.Gui/Hyena.Data.Gui/ITooltipCell.cs | 38 +++++++++++++++++++
.../Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs | 40 ++++++++++---------
src/Libraries/Hyena.Gui/Makefile.am | 1 +
4 files changed, 70 insertions(+), 24 deletions(-)
---
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
index 2e07217..8b43f17 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
@@ -35,7 +35,7 @@ using Hyena.Gui.Theming;
namespace Hyena.Data.Gui
{
- public class ColumnCellText : ColumnCell, ISizeRequestCell, ITextCell
+ public class ColumnCellText : ColumnCell, ISizeRequestCell, ITextCell, ITooltipCell
{
internal const int Spacing = 4;
@@ -102,8 +102,13 @@ namespace Hyena.Data.Gui
context.Layout.Alignment = alignment;
context.Layout.SetText (GetFormattedText (text));
context.Layout.GetPixelSize (out text_width, out text_height);
- // Requires Gtk# 2.12
- //is_ellipsized = context.Layout.IsEllipsized;
+ is_ellipsized = context.Layout.IsEllipsized;
+ }
+
+ public string GetTooltipMarkup (CellContext cellContext, double columnWidth)
+ {
+ UpdateText (cellContext, columnWidth);
+ return IsEllipsized ? Text : null;
}
protected virtual string GetText (object obj)
@@ -119,10 +124,10 @@ namespace Hyena.Data.Gui
return String.Format (text_format, text);
}
- /*private bool is_ellipsized = false;
+ private bool is_ellipsized = false;
public bool IsEllipsized {
get { return is_ellipsized; }
- }*/
+ }
public string Text {
get { return last_text; }
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ITooltipCell.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ITooltipCell.cs
new file mode 100644
index 0000000..14aab77
--- /dev/null
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ITooltipCell.cs
@@ -0,0 +1,38 @@
+//
+// ITooltipCell.cs
+//
+// Author:
+// Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2009 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Gdk;
+
+namespace Hyena.Data.Gui
+{
+ public interface ITooltipCell
+ {
+ string GetTooltipMarkup (CellContext cellContext, double columnWidth);
+ }
+}
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs
index 29d3a37..c0b6cbb 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs
@@ -38,27 +38,22 @@ namespace Hyena.Data.Gui
CanFocus = true;
selection_proxy.Changed += delegate { InvalidateList (); };
- // TODO this is working well except a crasher bug in Gtk+ or Gtk#
- // See http://bugzilla.gnome.org/show_bug.cgi?id=524772
- //HasTooltip = true;
- //QueryTooltip += OnQueryTooltip;
+ HasTooltip = true;
+ QueryTooltip += OnQueryTooltip;
}
- /*private void OnQueryTooltip (object o, Gtk.QueryTooltipArgs args)
+ private void OnQueryTooltip (object o, Gtk.QueryTooltipArgs args)
{
- if (cell_context == null || cell_context.Layout == null) {
- return;
- }
-
- if (!args.KeyboardTooltip) {
- ColumnCellText cell;
+ if (cell_context != null && cell_context.Layout != null && !args.KeyboardTooltip) {
+ ITooltipCell cell;
Column column;
int row_index;
- if (GetEventCell<ColumnCellText> (args.X, args.Y, out cell, out column, out row_index)) {
+ if (GetEventCell<ITooltipCell> (args.X, args.Y, out cell, out column, out row_index)) {
CachedColumn cached_column = GetCachedColumnForColumn (column);
- cell.UpdateText (cell_context, cached_column.Width);
- if (cell.IsEllipsized) {
+
+ string markup = cell.GetTooltipMarkup (cell_context, cached_column.Width);
+ if (!String.IsNullOrEmpty (markup)) {
Gdk.Rectangle rect = new Gdk.Rectangle ();
rect.X = list_interaction_alloc.X + cached_column.X1;
@@ -72,16 +67,23 @@ namespace Hyena.Data.Gui
// convert back to widget coords
rect.Y += list_interaction_alloc.Y;
- rect.Width = cached_column.Width; // TODO is this right even if the list is wide enough to scroll horizontally?
- rect.Height = RowHeight; // TODO not right - could be smaller if at the top/bottom and only partially showing
+ // TODO is this right even if the list is wide enough to scroll horizontally?
+ rect.Width = cached_column.Width;
+
+ // TODO not right - could be smaller if at the top/bottom and only partially showing
+ rect.Height = RowHeight;
- //System.Console.WriteLine ("Got ellipsized column text: {0} at {1}; event was at {3}, {4}", cell.Text, rect, rect.Y, args.X, args.Y);
- args.Tooltip.Markup = GLib.Markup.EscapeText (cell.Text);
+ args.Tooltip.Markup = markup; //GLib.Markup.EscapeText (cell.Text);
args.Tooltip.TipArea = rect;
args.RetVal = true;
}
}
}
- }*/
+
+ // Work around ref counting SIGSEGV, see http://bugzilla.gnome.org/show_bug.cgi?id=478519#c9
+ if (args.Tooltip != null) {
+ args.Tooltip.Dispose ();
+ }
+ }
}
}
diff --git a/src/Libraries/Hyena.Gui/Makefile.am b/src/Libraries/Hyena.Gui/Makefile.am
index 86a5731..b17a50d 100644
--- a/src/Libraries/Hyena.Gui/Makefile.am
+++ b/src/Libraries/Hyena.Gui/Makefile.am
@@ -16,6 +16,7 @@ SOURCES = \
Hyena.Data.Gui/IListView.cs \
Hyena.Data.Gui/ISizeRequestCell.cs \
Hyena.Data.Gui/ITextCell.cs \
+ Hyena.Data.Gui/ITooltipCell.cs \
Hyena.Data.Gui/ListView/ListView.cs \
Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs \
Hyena.Data.Gui/ListView/ListView_Header.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]