banshee r3716 - in trunk/banshee: . src/Core/Banshee.ThickClient/Banshee.Collection.Gui src/Libraries/Hyena.Gui/Hyena.Data.Gui src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView src/Libraries/Hyena.Gui/Hyena.Gui



Author: abock
Date: Tue Apr  8 04:58:13 2008
New Revision: 3716
URL: http://svn.gnome.org/viewvc/banshee?rev=3716&view=rev

Log:
2008-04-07  Aaron Bockover  <abock gnome org>

    * src/Libraries/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs:
    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs:
    Let Cairo know what DPI we're using so text is rendered at the right size,
    and recalculate the row height on style set in case the DPI changed;
    fixes BGO #522500, and is completely awesome - I recommend people change
    their DPI settings while Banshee is running a few times to really take in
    the awesomeness of this fix. Really.

    I also added a nicer way for row heights to be queried so renderers can
    provide their desired heights; it's a better solution than the previous
    hack, which was not nice.

    * src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs:
    * src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellTrack.cs:
    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs: Provide
    row height calculating functions; ColumnCellText's version is static and
    is referenced by ListView as the default calculator

    * src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TerseTrackListView.cs:
    * src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs:
    Set the renderer row height computing functions to the view



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellTrack.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TerseTrackListView.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs	Tue Apr  8 04:58:13 2008
@@ -41,12 +41,15 @@
     {
         private ColumnController column_controller;
         
-        public AlbumListView() : base()
+        public AlbumListView () : base ()
         {
-            column_controller = new ColumnController();
-            column_controller.Add(new Column("Album", new ColumnCellAlbum(), 1.0));
+            ColumnCellAlbum renderer = new ColumnCellAlbum ();
+            
+            column_controller = new ColumnController ();
+            column_controller.Add (new Column ("Album", renderer, 1.0));
             ColumnController = column_controller;
-            RowHeight = ColumnCellAlbum.RowHeight;
+            
+            RowHeightProvider = renderer.ComputeRowHeight;
             
             RowActivated += delegate {
                 ServiceManager.PlaybackController.Source = (ServiceManager.SourceManager.ActiveSource as Banshee.Sources.ITrackModelSource);

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs	Tue Apr  8 04:58:13 2008
@@ -42,8 +42,9 @@
         
         private static Gdk.Pixbuf default_cover_pixbuf = IconThemeUtils.LoadIcon (48, "media-optical");
         
-        public static int RowHeight {
-            get { return 54; }
+        public int ComputeRowHeight (Widget widget)
+        {
+            return 54;
         }
     
         private ArtworkManager artwork_manager;

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellTrack.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellTrack.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellTrack.cs	Tue Apr  8 04:58:13 2008
@@ -46,7 +46,8 @@
             Pango.Layout layout = new Pango.Layout (widget.PangoContext);
             layout.SetMarkup ("<b>W</b>\n<small><i>W</i></small>");
             layout.GetPixelSize (out lw, out lh);
-            return lh + 4;
+            layout.Dispose ();
+            return lh + 8;
         }
         
         public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TerseTrackListView.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TerseTrackListView.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TerseTrackListView.cs	Tue Apr  8 04:58:13 2008
@@ -50,7 +50,7 @@
             
             ColumnController = column_controller;
             
-            RowHeight = renderer.ComputeRowHeight (this);
+            RowHeightProvider = renderer.ComputeRowHeight;
             HeaderVisible = false;
             RulesHint = true;
         }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs	Tue Apr  8 04:58:13 2008
@@ -59,7 +59,6 @@
         public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
         {
             context.Layout.Width = (int)((cellWidth - 8) * Pango.Scale.PangoScale);
-            context.Layout.FontDescription = context.Widget.PangoContext.FontDescription.Copy ();
             context.Layout.FontDescription.Weight = font_weight;
             context.Layout.Ellipsize = EllipsizeMode;
             
@@ -79,7 +78,7 @@
         }
         
         protected virtual string Text {
-            get { return BoundObject == null ? String.Empty : BoundObject.ToString(); }
+            get { return BoundObject == null ? String.Empty : BoundObject.ToString (); }
         }
         
         protected int TextWidth {
@@ -90,10 +89,6 @@
             get { return text_height; }
         }
         
-        internal bool UseCairoPango {
-            set { use_cairo_pango = value; }
-        }
-        
         public virtual Pango.Weight FontWeight {
             get { return font_weight; }
             set { font_weight = value; }
@@ -103,5 +98,15 @@
             get { return ellipsize_mode; }
             set { ellipsize_mode = value; }
         }
+        
+        internal static int ComputeRowHeight (Widget widget)
+        {
+            int w_width, row_height;
+            Pango.Layout layout = new Pango.Layout (widget.PangoContext);
+            layout.SetText ("W");
+            layout.GetPixelSize (out w_width, out row_height);
+            layout.Dispose ();
+            return row_height + 8;
+        }
     }
 }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs	Tue Apr  8 04:58:13 2008
@@ -38,6 +38,8 @@
 
 namespace Hyena.Data.Gui
 {
+    public delegate int ListViewRowHeightHandler (Widget widget);
+
     public partial class ListView<T> : Container
     {
         // The list is rendered to an off-screen Drawable; the "canvas". The canvas is large enough to hold
@@ -57,14 +59,34 @@
         
         private Cairo.Context cairo_context;
         private CellContext cell_context;
-        
-        private Pango.Layout header_pango_layout;
-        private Pango.Layout list_pango_layout;
+        private Pango.Layout pango_layout;
         
         private Theme theme;
         protected Theme Theme {
             get { return theme; }
         }
+        
+        private void CreateLayout (Cairo.Context cairo_context)
+        {
+            if (pango_layout != null) {
+                pango_layout.Dispose ();
+            }
+            
+            pango_layout = PangoCairoHelper.CreateLayout (cairo_context);
+            pango_layout.FontDescription = PangoContext.FontDescription.Copy ();
+            
+            double resolution = Screen.Resolution;
+            if (resolution != -1) {
+                Pango.Context context = PangoCairoHelper.LayoutGetContext (pango_layout);
+                PangoCairoHelper.ContextSetResolution (context, resolution);
+            }
+        }
+        
+        protected override void OnStyleSet (Gtk.Style old_style)
+        {
+            base.OnStyleSet (old_style);
+            RecomputeRowHeight = true;
+        }
          
         protected override bool OnExposeEvent (EventExpose evnt)
         {
@@ -82,6 +104,7 @@
             if (header_visible && column_controller != null) {
                 PaintHeader (damage);
             }
+            
             Theme.DrawFrameBorder (cairo_context, Allocation);
             
             // Then we render the list to the offscreen canvas.
@@ -89,6 +112,7 @@
                 canvas1 = new Pixmap (GdkWindow, canvas_alloc.Width, canvas_alloc.Height);
                 render_everything = true;
             }
+            
             PaintList ();
             
             // Now we blit the offscreen canvas onto the GdkWindow.
@@ -115,7 +139,7 @@
             cairo_context.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
             cairo_context.Clip ();
             
-            header_pango_layout = PangoCairoHelper.CreateLayout (cairo_context);
+            CreateLayout (cairo_context);
             Theme.DrawHeaderBackground (cairo_context, header_rendering_alloc);
             
             Rectangle cell_area = new Rectangle ();
@@ -124,7 +148,7 @@
             
             cell_context.Context = cairo_context;
             cell_context.Drawable = GdkWindow;
-            cell_context.Layout = header_pango_layout;
+            cell_context.Layout = pango_layout;
             cell_context.TextAsForeground = true;
 
             for (int ci = 0; ci < column_cache.Length; ci++) {
@@ -217,7 +241,7 @@
             // Build a cairo context for the primary canvas.
             Cairo.Context tmp_cr = cairo_context;
             cairo_context = CairoHelper.Create (canvas1);
-            list_pango_layout = PangoCairoHelper.CreateLayout (cairo_context);
+            CreateLayout (cairo_context);
             
             // Render the background to the primary canvas.
             Theme.DrawListBackground (cairo_context, canvas_alloc, true);
@@ -285,7 +309,7 @@
         {
             cell_context.Context = cairo_context;
             cell_context.Drawable = canvas1;
-            cell_context.Layout = list_pango_layout;
+            cell_context.Layout = pango_layout;
             cell_context.Clip = canvas_alloc;
             cell_context.TextAsForeground = false;
             
@@ -333,11 +357,11 @@
                         CairoCorners corners = CairoCorners.All;
                         
                         if (Selection.Contains (ri - 1)) {
-                            corners ^= CairoCorners.TopLeft | CairoCorners.TopRight;
+                            corners &= ~(CairoCorners.TopLeft | CairoCorners.TopRight);
                         }
                         
                         if (Selection.Contains (ri + 1)) {
-                            corners ^= CairoCorners.BottomLeft | CairoCorners.BottomRight;
+                            corners &= ~(CairoCorners.BottomLeft | CairoCorners.BottomRight);
                         }
                         
                         Theme.DrawRowSelection (cairo_context, single_list_alloc.X, single_list_alloc.Y, 
@@ -346,8 +370,7 @@
                     }
                     
                     if (selection_height > 0) {
-                        Theme.DrawRowSelection (
-                            cairo_context, 0, selection_y, canvas_alloc.Width, selection_height);
+                        Theme.DrawRowSelection (cairo_context, 0, selection_y, canvas_alloc.Width, selection_height);
                         selection_height = 0;
                     }
                     
@@ -494,21 +517,40 @@
             }
         }
         
-        private int row_height = 0;
-        protected int RowHeight {
+        private ListViewRowHeightHandler row_height_handler;
+        public virtual ListViewRowHeightHandler RowHeightProvider {
+            get { return row_height_handler; }
+            set {
+                if (value != row_height_handler) {
+                    row_height_handler = value;
+                    RecomputeRowHeight = true;
+                }
+            }
+        }
+        
+        private bool recompute_row_height = true;
+        protected bool RecomputeRowHeight {
+            get { return recompute_row_height; }
+            set { 
+                recompute_row_height = value;
+                if (value && IsMapped && IsRealized) {
+                    QueueDraw ();
+                }
+            }
+        }
+        
+        private int row_height = 32;
+        private int RowHeight {
             get {
-                if (row_height == 0) {
-                    int w_width;
-                    Pango.Layout layout = new Pango.Layout (PangoContext);
-                    layout.SetText ("W");
-                    layout.GetPixelSize (out w_width, out row_height);
-                    row_height += 8;
+                if (RecomputeRowHeight) {
+                    row_height = RowHeightProvider != null 
+                        ? RowHeightProvider (this) 
+                        : ColumnCellText.ComputeRowHeight (this);
+                    RecomputeRowHeight = false;
                 }
                 
                 return row_height;
             }
-            
-            set { row_height = value; }
         }
     }
 }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs	Tue Apr  8 04:58:13 2008
@@ -60,5 +60,22 @@
             pango_cairo_layout_path (cr == null ? IntPtr.Zero : cr.Handle, 
                 layout == null ? IntPtr.Zero : layout.Handle);
         }
+        
+        [DllImport ("libpangocairo-1.0.so.0")]
+        private static extern void pango_cairo_context_set_resolution (IntPtr pango_context, double dpi);
+        
+        public static void ContextSetResolution (Pango.Context context, double dpi)
+        {
+            pango_cairo_context_set_resolution (context == null ? IntPtr.Zero : context.Handle, dpi);
+        }
+        
+        [DllImport ("libpangocairo-1.0.so.0")]
+        private static extern IntPtr pango_layout_get_context (IntPtr layout);
+        
+        public static Pango.Context LayoutGetContext (Pango.Layout layout)
+        {
+            IntPtr handle = pango_layout_get_context (layout.Handle);
+            return handle.Equals (IntPtr.Zero) ? null : GLib.Object.GetObject (handle) as Pango.Context;
+        }
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]