[rhythmbox/gobject-introspection: 18/41] port rating and segmented bar widgets to new size request stuff
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/gobject-introspection: 18/41] port rating and segmented bar widgets to new size request stuff
- Date: Sun, 12 Dec 2010 10:00:45 +0000 (UTC)
commit 660c508ffd7ebf1e7ac98013b854e2a42e69d1dd
Author: Jonathan Matthew <jonathan d14n org>
Date: Mon Nov 29 11:55:10 2010 +1000
port rating and segmented bar widgets to new size request stuff
widgets/rb-rating.c | 42 +++++++++++++++++++++--------------
widgets/rb-segmented-bar.c | 51 +++++++++++++++++++++++++++++++-------------
2 files changed, 61 insertions(+), 32 deletions(-)
---
diff --git a/widgets/rb-rating.c b/widgets/rb-rating.c
index 215f2f2..6752715 100644
--- a/widgets/rb-rating.c
+++ b/widgets/rb-rating.c
@@ -57,16 +57,14 @@ static void rb_rating_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec);
static void rb_rating_realize (GtkWidget *widget);
-static void rb_rating_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
static gboolean rb_rating_draw (GtkWidget *widget, cairo_t *cr);
-/*static gboolean rb_rating_expose (GtkWidget *widget,
- GdkEventExpose *event); */
static gboolean rb_rating_focus (GtkWidget *widget, GtkDirectionType direction);
static gboolean rb_rating_set_rating_cb (RBRating *rating, gdouble score);
static gboolean rb_rating_adjust_rating_cb (RBRating *rating, gdouble adjust);
static gboolean rb_rating_button_press_cb (GtkWidget *widget,
GdkEventButton *event);
+static void rb_rating_get_preferred_width (GtkWidget *widget, int *minimum_width, int *natural_width);
+static void rb_rating_get_preferred_height (GtkWidget *widget, int *minimum_height, int *natural_height);
struct _RBRatingPrivate
{
@@ -115,9 +113,9 @@ rb_rating_class_init (RBRatingClass *klass)
object_class->set_property = rb_rating_set_property;
widget_class->realize = rb_rating_realize;
- /*widget_class->expose_event = rb_rating_expose;*/
- widget_class->draw = rb_rating_draw; /* ? */
- widget_class->size_request = rb_rating_size_request;
+ widget_class->draw = rb_rating_draw;
+ widget_class->get_preferred_width = rb_rating_get_preferred_width;
+ widget_class->get_preferred_height = rb_rating_get_preferred_height;
widget_class->button_press_event = rb_rating_button_press_cb;
widget_class->focus = rb_rating_focus;
@@ -339,17 +337,32 @@ rb_rating_realize (GtkWidget *widget)
}
static void
-rb_rating_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+rb_rating_get_preferred_width (GtkWidget *widget, int *minimum_width, int *natural_width)
{
int icon_size;
+ int width;
- g_return_if_fail (requisition != NULL);
+ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, NULL);
+ width = RB_RATING_MAX_SCORE * icon_size + X_OFFSET;
+ if (minimum_width != NULL)
+ *minimum_width = width;
+ if (natural_width != NULL)
+ *natural_width = width;
+}
+
+static void
+rb_rating_get_preferred_height (GtkWidget *widget, int *minimum_height, int *natural_height)
+{
+ int icon_size;
+ int height;
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, NULL);
- requisition->width = RB_RATING_MAX_SCORE * icon_size + X_OFFSET;
- requisition->height = icon_size + Y_OFFSET * 2;
+ height = icon_size + Y_OFFSET * 2;
+ if (minimum_height != NULL)
+ *minimum_height = height;
+ if (natural_height != NULL)
+ *natural_height = height;
}
static gboolean
@@ -365,11 +378,6 @@ rb_rating_draw (GtkWidget *widget, cairo_t *cr)
int focus_width;
g_return_val_if_fail (RB_IS_RATING (widget), FALSE);
- /* what
- if (!gtk_widget_is_drawable (widget)) {
- return FALSE;
- }
- */
ret = FALSE;
rating = RB_RATING (widget);
diff --git a/widgets/rb-segmented-bar.c b/widgets/rb-segmented-bar.c
index 4aaa3de..3baf8ca 100644
--- a/widgets/rb-segmented-bar.c
+++ b/widgets/rb-segmented-bar.c
@@ -39,8 +39,6 @@
#define MINIMUM_HEIGHT 26
static void rb_segmented_bar_finalize (GObject *object);
-static void rb_segmented_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
static void rb_segmented_bar_size_allocate(GtkWidget *widget,
GtkAllocation *allocation);
static gboolean rb_segmented_bar_draw (GtkWidget *widget, cairo_t *context);
@@ -51,6 +49,12 @@ static void rb_segmented_bar_set_property (GObject *object, guint param_id,
static gchar *rb_segmented_bar_default_value_formatter (gdouble percent,
gpointer data);
+static void rb_segmented_bar_get_preferred_height (GtkWidget *widget,
+ int *minimum_height,
+ int *natural_height);
+static void rb_segmented_bar_get_preferred_width (GtkWidget *widget,
+ int *minimum_width,
+ int *natural_width);
static void compute_layout_size (RBSegmentedBar *bar);
@@ -153,7 +157,8 @@ rb_segmented_bar_class_init (RBSegmentedBarClass *klass)
object_class->set_property = rb_segmented_bar_set_property;
widget_class->draw = rb_segmented_bar_draw;
- widget_class->size_request = rb_segmented_bar_size_request;
+ widget_class->get_preferred_height = rb_segmented_bar_get_preferred_height;
+ widget_class->get_preferred_width = rb_segmented_bar_get_preferred_width;
widget_class->size_allocate = rb_segmented_bar_size_allocate;
widget_class->get_accessible = rb_segmented_bar_get_accessible;
@@ -270,29 +275,45 @@ rb_segmented_bar_default_value_formatter (gdouble percent,
}
static void
-rb_segmented_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+rb_segmented_bar_get_preferred_height (GtkWidget *widget, int *minimum_height, int *natural_height)
{
RBSegmentedBarPrivate *priv;
- int real_height;
+ int height;
- g_return_if_fail (requisition != NULL);
priv = RB_SEGMENTED_BAR_GET_PRIVATE (RB_SEGMENTED_BAR (widget));
-
if (priv->reflect) {
- real_height = MINIMUM_HEIGHT*1.75;
+ height = MINIMUM_HEIGHT * 1.75;
} else {
- real_height = MINIMUM_HEIGHT;
+ height = MINIMUM_HEIGHT;
}
+
if (priv->show_labels) {
compute_layout_size (RB_SEGMENTED_BAR (widget));
- requisition->height = MAX (MINIMUM_HEIGHT + priv->bar_label_spacing + priv->layout_height,
- real_height);
- } else {
- requisition->height = real_height;
+ height = MAX (MINIMUM_HEIGHT + priv->bar_label_spacing + priv->layout_height, height);
}
- requisition->width = MAX (priv->layout_width, 200);
+
+ if (minimum_height)
+ *minimum_height = height;
+ if (natural_height)
+ *natural_height = height;
+}
+
+static void
+rb_segmented_bar_get_preferred_width (GtkWidget *widget, int *minimum_width, int *natural_width)
+{
+ RBSegmentedBarPrivate *priv;
+ int width;
+
+ priv = RB_SEGMENTED_BAR_GET_PRIVATE (RB_SEGMENTED_BAR (widget));
+
+ compute_layout_size (RB_SEGMENTED_BAR (widget));
+ width = MAX (priv->layout_width, 200);
+
+ if (minimum_width)
+ *minimum_width = width;
+ if (natural_width)
+ *natural_width = width;
}
static PangoLayout *create_adapt_layout (GtkWidget *widget, PangoLayout *layout,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]