[banshee/gtk3] Banshee.Widgets: More theming and size calculation updates



commit dac065d1644335924fefd66054cb3a39c0f1aba9
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Thu Jul 21 21:54:25 2011 +0200

    Banshee.Widgets: More theming and size calculation updates

 .../Banshee.Widgets/HoverImageButton.cs            |    8 ++-
 .../Banshee.Widgets/Banshee.Widgets/LinkLabel.cs   |   40 ++++++++++--------
 .../Banshee.Widgets/Banshee.Widgets/MessagePane.cs |    4 +-
 .../Banshee.Widgets/Banshee.Widgets/SearchEntry.cs |   43 ++++++++++----------
 .../Banshee.Widgets/StreamPositionLabel.cs         |   13 +++---
 src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs   |    4 +-
 .../Banshee.Widgets/Banshee.Widgets/TileView.cs    |    4 +-
 7 files changed, 62 insertions(+), 54 deletions(-)
---
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/HoverImageButton.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/HoverImageButton.cs
index 454c45b..98dcf3a 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/HoverImageButton.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/HoverImageButton.cs
@@ -94,7 +94,7 @@ namespace Banshee.Widgets
 
         protected override bool OnEnterNotifyEvent(Gdk.EventCrossing evnt)
         {
-            image.GdkWindow.Cursor = hand_cursor;
+            image.Window.Cursor = hand_cursor;
             is_hovering = true;
             UpdateImage();
             return base.OnEnterNotifyEvent(evnt);
@@ -154,8 +154,10 @@ namespace Banshee.Widgets
             PropagateDraw(Child, cr);
 
             if(HasFocus && draw_focus) {
-                Style.PaintFocus(Style, cr, StateType.Normal, this, "button",
-                    0, 0, Allocation.Width, Allocation.Height);
+                StyleContext.Save ();
+                StyleContext.AddClass ("button");
+                StyleContext.RenderFocus (cr, 0, 0, Allocation.Width, Allocation.Height);
+                StyleContext.Restore ();
             }
 
             return true;
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs
index 017e79a..725084b 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs
@@ -47,7 +47,7 @@ namespace Banshee.Widgets
         private bool is_hovering;
         private bool selectable;
         private UriOpenHandler open_handler;
-        private Gdk.Color link_color;
+        private Gdk.RGBA link_color;
 
         private bool interior_focus;
         private int focus_width;
@@ -71,18 +71,17 @@ namespace Banshee.Widgets
             label = new Label(text);
             label.Show();
 
-            link_color = label.Style.Background(StateType.Selected);
+            link_color = label.StyleContext.GetBackgroundColor (StateFlags.Selected);
             ActAsLink = true;
 
             Add(label);
         }
 
-        protected override void OnStyleSet (Style previous_style)
+        protected override void OnStyleUpdated ()
         {
-            base.OnStyleSet (previous_style);
+            base.OnStyleUpdated ();
 
             CheckButton check = new CheckButton ();
-            check.EnsureStyle ();
 
             interior_focus = GtkUtilities.StyleGetProperty<bool> (check, "interior-focus", false);
             focus_width = GtkUtilities.StyleGetProperty<int> (check, "focus-line-width", -1);
@@ -111,8 +110,10 @@ namespace Banshee.Widgets
             if(CairoHelper.ShouldDrawWindow (cr, Window) && HasFocus) {
                 int layout_width = 0, layout_height = 0;
                 label.Layout.GetPixelSize(out layout_width, out layout_height);
-                Style.PaintFocus (Style, cr, State, this, "checkbutton",
-                    0, 0, layout_width + 2 * padding, layout_height + 2 * padding);
+                StyleContext.Save ();
+                StyleContext.AddClass ("check");
+                StyleContext.RenderFocus (cr, 0, 0, layout_width + 2 * padding, layout_height + 2 * padding);
+                StyleContext.Restore ();
             }
 
             if(Child != null) {
@@ -131,11 +132,13 @@ namespace Banshee.Widgets
 
             minimum_height = natural_height = 0;
 
-            Requisition child_requisition = label.SizeRequest ();
-            natural_height += child_requisition.Height;
+            int label_min_height, label_natural_height;
+            label.GetPreferredHeight (out label_min_height, out label_natural_height);
+            minimum_height += label_min_height;
+            natural_height += label_natural_height;
 
             natural_height += ((int)BorderWidth + padding) * 2;
-            minimum_height = natural_height;
+            minimum_height += ((int)BorderWidth + padding) * 2;
         }
 
         protected override void OnGetPreferredWidth (out int minimum_width, out int natural_width)
@@ -147,12 +150,13 @@ namespace Banshee.Widgets
 
             minimum_width = natural_width = 0;
 
-            Requisition child_requisition = label.SizeRequest ();
-            natural_width = Math.Max (natural_width, child_requisition.Width);
+            int label_min_width, label_natural_width;
+            label.GetPreferredWidth (out label_min_width, out label_natural_width);
+            minimum_width = Math.Max (minimum_width, label_min_width);
+            natural_width = Math.Max (natural_width, label_natural_width);
 
+            minimum_width += ((int)BorderWidth + padding) * 2;
             natural_width += ((int)BorderWidth + padding) * 2;
-
-            minimum_width = natural_width;
         }
 
         protected override void OnSizeAllocated (Gdk.Rectangle allocation)
@@ -209,14 +213,14 @@ namespace Banshee.Widgets
         protected override bool OnEnterNotifyEvent(Gdk.EventCrossing evnt)
         {
             is_hovering = true;
-            GdkWindow.Cursor = hand_cursor;
+            Window.Cursor = hand_cursor;
             return false;
         }
 
         protected override bool OnLeaveNotifyEvent(Gdk.EventCrossing evnt)
         {
             is_hovering = false;
-            GdkWindow.Cursor = null;
+            Window.Cursor = null;
             return false;
         }
 
@@ -285,10 +289,10 @@ namespace Banshee.Widgets
 
                 if(act_as_link) {
                     label.Selectable = false;
-                    label.ModifyFg(Gtk.StateType.Normal, link_color);
+                    label.OverrideColor (StateFlags.Normal, link_color);
                 } else {
                     label.Selectable = selectable;
-                    label.ModifyFg(Gtk.StateType.Normal, label.Style.Foreground(Gtk.StateType.Normal));
+                    label.OverrideColor (StateFlags.Normal, label.StyleContext.GetColor (StateFlags.Normal));
                 }
 
                 label.QueueDraw();
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/MessagePane.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/MessagePane.cs
index c06ba18..c18f9ce 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/MessagePane.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/MessagePane.cs
@@ -105,7 +105,7 @@ namespace Banshee.Widgets
             label.Markup = tip;
             label.SetAlignment (0.0f, 0.5f);
             label.LineWrap = true;
-            label.ModifyFg (StateType.Normal, label.Style.Foreground (StateType.Insensitive));
+            label.OverrideColor (StateFlags.Normal, label.StyleContext.GetColor (StateFlags.Insensitive));
             label.Show ();
             Attach (label, 1, 2, row, row + 1, AttachOptions.Expand | AttachOptions.Fill, 0, 0, 0);
         }
@@ -130,7 +130,7 @@ namespace Banshee.Widgets
             }
 
             Attach (widget, 1, 2, row, row + 1, xoptions, yoptions, 0, 0);
-            widget.ModifyBg (StateType.Normal, Style.Base (StateType.Normal));
+            widget.OverrideBackgroundColor (StateFlags.Normal, StyleContext.GetBackgroundColor (StateFlags.Normal));
         }
 
         public void Clear ()
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs
index 557ed67..651d74c 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs
@@ -144,11 +144,13 @@ namespace Banshee.Widgets
         {
             int origin_x, origin_y, tmp;
 
-            filter_button.GdkWindow.GetOrigin(out origin_x, out tmp);
-            GdkWindow.GetOrigin(out tmp, out origin_y);
+            filter_button.Window.GetOrigin(out origin_x, out tmp);
+            Window.GetOrigin(out tmp, out origin_y);
 
             x = origin_x + filter_button.Allocation.X;
-            y = origin_y + SizeRequest().Height;
+            int minimum_height, natural_height;
+            GetPreferredHeight (out minimum_height, out natural_height);
+            y = origin_y + natural_height;
             push_in = true;
         }
 
@@ -204,11 +206,11 @@ namespace Banshee.Widgets
 
         private void UpdateStyle ()
         {
-            Gdk.Color color = entry.Style.Base (entry.State);
-            filter_button.ModifyBg (entry.State, color);
-            clear_button.ModifyBg (entry.State, color);
+            var color = entry.StyleContext.GetBackgroundColor (entry.StateFlags);
+            filter_button.OverrideBackgroundColor (entry.StateFlags, color);
+            clear_button.OverrideBackgroundColor (entry.StateFlags, color);
 
-            box.BorderWidth = (uint)entry.Style.XThickness;
+            box.BorderWidth = (uint)entry.StyleContext.GetBorder (StateFlags).Left;
         }
 
         private void OnInnerEntryStyleSet (object o, StyleSetArgs args)
@@ -257,12 +259,13 @@ namespace Banshee.Widgets
 
         protected override bool OnDrawn (Cairo.Context cr)
         {
-            Style.PaintFlatBox (entry.Style, cr, State, ShadowType.None, this,
-                "entry_bg", 0, 0, Allocation.Width, Allocation.Height);
-            PropagateDraw(Child, cr);
-            Style.PaintShadow(entry.Style, cr, StateType.Normal,
-                ShadowType.In, entry, "entry",
-                0, 0, Allocation.Width, Allocation.Height);
+            StyleContext.Save ();
+            StyleContext.AddClass ("entry");
+            StyleContext.RenderFrame (cr, 0, 0, Allocation.Width, Allocation.Height);
+            StyleContext.RenderBackground (cr, 0, 0, Allocation.Width, Allocation.Height);
+            PropagateDraw (Child, cr);
+            StyleContext.Restore ();
+
             return true;
         }
 
@@ -419,12 +422,10 @@ namespace Banshee.Widgets
         private class FilterMenuItem : MenuItem /*CheckMenuItem*/
         {
             private int id;
-            private string label;
 
             public FilterMenuItem(int id, string label) : base(label)
             {
                 this.id = id;
-                this.label = label;
                 //DrawAsRadio = true;
             }
 
@@ -432,10 +433,6 @@ namespace Banshee.Widgets
                 get { return id; }
             }
 
-            public string Label {
-                get { return label; }
-            }
-
             // FIXME: Remove when restored to CheckMenuItem
             private bool active;
             public bool Active {
@@ -443,7 +440,7 @@ namespace Banshee.Widgets
                 set { active = value; }
             }
 
-            public new event EventHandler Toggled;
+            public event EventHandler Toggled;
             protected override void OnActivated ()
             {
                 base.OnActivated ();
@@ -475,7 +472,7 @@ namespace Banshee.Widgets
 
             protected override bool OnDrawn (Cairo.Context cr)
             {
-                // The Entry's GdkWindow is the top level window onto which
+                // The Entry's Window is the top level window onto which
                 // the frame is drawn; the actual text entry is drawn into a
                 // separate window, so we can ensure that for themes that don't
                 // respect HasFrame, we never ever allow the base frame drawing
@@ -503,7 +500,9 @@ namespace Banshee.Widgets
                 int width, height;
                 layout.SetMarkup(parent.EmptyMessage);
                 layout.GetPixelSize(out width, out height);
-                StyleContext.RenderLayout (cr, 2, (SizeRequest().Height - height) / 2, layout);
+                int minimum_height, natural_height;
+                OnGetPreferredHeight (out minimum_height, out natural_height);
+                StyleContext.RenderLayout (cr, 2, (natural_height - height) / 2, layout);
                 StyleContext.Restore ();
                 return ret;
             }
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs
index 7ad70c4..4ac9d16 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs
@@ -118,8 +118,9 @@ namespace Banshee.Widgets
             int bar_width = (int)((double)Allocation.Width * buffering_progress);
             bool render_bar = false;
 
+            var border = StyleContext.GetBorder (StateFlags);
             if (bar_width > 0 && IsBuffering) {
-                bar_width -= 2 * Style.XThickness;
+                bar_width -= border.Left + border.Right;
                 render_bar = true;
 
                 StyleContext.RenderBackground (cr,
@@ -129,11 +130,11 @@ namespace Banshee.Widgets
 
                 if (bar_width > 0) {
                     StyleContext.RenderBackground (cr,
-                        Allocation.X + Style.XThickness, Allocation.Y + Style.YThickness,
-                        bar_width, Allocation.Height - 2 * Style.YThickness);
+                        Allocation.X + border.Left, Allocation.Y + border.Top,
+                        bar_width, Allocation.Height - (border.Top + border.Bottom));
                     StyleContext.RenderFrame (cr,
-                        Allocation.X + Style.XThickness, Allocation.Y + Style.YThickness,
-                        bar_width, Allocation.Height - 2 * Style.YThickness);
+                        Allocation.X + border.Left, Allocation.Y + border.Top,
+                        bar_width, Allocation.Height - (border.Top + border.Bottom));
                 }
             }
 
@@ -145,7 +146,7 @@ namespace Banshee.Widgets
             Gdk.Rectangle rect = Allocation;
 
             if (render_bar) {
-                width = bar_width + Style.XThickness;
+                width = bar_width + border.Left;
                 rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, width, Allocation.Height);
                 StyleContext.RenderLayout (cr, x, y, layout);
 
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs
index 3bbf6b5..cf23163 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs
@@ -74,8 +74,8 @@ namespace Banshee.Widgets
             SecondaryLabel.Xalign = 0.0f;
             SecondaryLabel.Yalign = 0.0f;
 
-            StyleSet += delegate {
-                PrimaryLabel.ModifyFg (StateType.Normal, Style.Text (StateType.Normal));
+            StyleUpdated += delegate {
+                PrimaryLabel.OverrideColor (StateFlags.Normal, StyleContext.GetColor (StateFlags.Normal));
                 Gdk.RGBA rgba = StyleContext.GetColor (StateFlags.Normal);
                 SecondaryLabel.OverrideColor (StateFlags.Normal, Hyena.Gui.GtkUtilities.ColorBlend (
                     rgba, StyleContext.GetBackgroundColor (StateFlags.Normal)));
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/TileView.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/TileView.cs
index 6c922db..3f04dcc 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/TileView.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/TileView.cs
@@ -106,7 +106,9 @@ namespace Banshee.Widgets
             int new_column_count = RelayoutTablesIfNeeded(usable_area, current_column_count);
 
             if(current_column_count != new_column_count) {
-                child.SizeRequest();
+                // FIXME: Is that really needed ?
+                Requisition minimum_size, natural_size;
+                child.GetPreferredSize (out minimum_size, out natural_size);
                 current_column_count = new_column_count;
             }
 



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