summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-11-22 18:30:38 +0100
committerinfirit <[email protected]>2014-11-22 18:43:04 +0100
commit232713d42e79c519cfb060bb286e4cd600678559 (patch)
tree10f856f9c23aef8c83a107f457f6864b548f5e2c
parent1b0b03e09e3910280c1734475f0b0ac4122fcfca (diff)
downloadmate-panel-232713d42e79c519cfb060bb286e4cd600678559.tar.bz2
mate-panel-232713d42e79c519cfb060bb286e4cd600678559.tar.xz
Gtk3: Sync get_preferred_width/height() usage with gnome-panel
Even tough it works it makes taking code (eg StyleContext) from gnome-panel much easier. Also fixes a bug where applets are not drawn when moved/added.
-rw-r--r--applets/clock/clock-face.c123
-rw-r--r--applets/clock/clock-map.c4
-rw-r--r--mate-panel/button-widget.c47
-rw-r--r--mate-panel/panel-frame.c96
-rw-r--r--mate-panel/panel-separator.c58
5 files changed, 217 insertions, 111 deletions
diff --git a/applets/clock/clock-face.c b/applets/clock/clock-face.c
index 558201ab..dfe1e224 100644
--- a/applets/clock/clock-face.c
+++ b/applets/clock/clock-face.c
@@ -25,23 +25,28 @@ static GHashTable *pixbuf_cache = NULL;
G_DEFINE_TYPE (ClockFace, clock_face, GTK_TYPE_WIDGET)
-static void clock_face_finalize (GObject *);
+static void clock_face_finalize (GObject *);
#if GTK_CHECK_VERSION (3, 0, 0)
-static gboolean clock_face_draw (GtkWidget *clock, cairo_t *cr);
-static void clock_face_get_preferred_width (GtkWidget *widget, gint *minimum_width, gint *natural_width);
-static void clock_face_get_preferred_height (GtkWidget *widget, gint *minimum_height, gint *natural_height);
+static gboolean clock_face_draw (GtkWidget *clock,
+ cairo_t *cr);
+static void clock_face_get_preferred_width (GtkWidget *this,
+ gint *minimal_width,
+ gint *natural_width);
+static void clock_face_get_preferred_height (GtkWidget *this,
+ gint *minimal_height,
+ gint *natural_height);
#else
-static gboolean clock_face_expose (GtkWidget *clock, GdkEventExpose *event);
+static gboolean clock_face_expose (GtkWidget *clock, GdkEventExpose *event);
+static void clock_face_size_request (GtkWidget *clock,
+ GtkRequisition *requisition);
#endif
-static void clock_face_size_request (GtkWidget *clock,
- GtkRequisition *requisition);
-static void clock_face_size_allocate (GtkWidget *clock,
- GtkAllocation *allocation);
+static void clock_face_size_allocate (GtkWidget *clock,
+ GtkAllocation *allocation);
-static void update_time_and_face (ClockFace *this,
- gboolean force_face_loading);
-static void clock_face_load_face (ClockFace *this,
- gint width, gint height);
+static void update_time_and_face (ClockFace *this,
+ gboolean force_face_loading);
+static void clock_face_load_face (ClockFace *this,
+ gint width, gint height);
typedef struct _ClockFacePrivate ClockFacePrivate;
@@ -256,6 +261,73 @@ clock_face_redraw_canvas (ClockFace *this)
gtk_widget_queue_draw (GTK_WIDGET (this));
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void
+clock_face_get_preferred_width (GtkWidget *this,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ ClockFacePrivate *priv = CLOCK_FACE_GET_PRIVATE (this);
+
+ if (priv->size_widget != NULL) {
+ int child_minimal_height;
+ int child_natural_height;
+
+ /* Tie our size to the height of the size_widget */
+ gtk_widget_get_preferred_height (GTK_WIDGET (priv->size_widget),
+ &child_minimal_height,
+ &child_natural_height);
+
+ /* Pad out our height by a little bit - this improves
+ the balance */
+ *minimal_width = child_minimal_height + child_minimal_height / 8;
+ *natural_width = child_natural_height + child_natural_height / 8;
+ } else if (priv->face_pixbuf != NULL) {
+ /* Use the size of the current pixbuf */
+ *minimal_width = *natural_width = gdk_pixbuf_get_width (GDK_PIXBUF (priv->face_pixbuf));
+ } else {
+ /* we don't know anything, so use known dimensions for the svg
+ * files */
+ if (priv->size == CLOCK_FACE_LARGE)
+ *minimal_width = *natural_width = 50;
+ else
+ *minimal_width = *natural_width = 36;
+ }
+}
+
+static void
+clock_face_get_preferred_height (GtkWidget *this,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ ClockFacePrivate *priv = CLOCK_FACE_GET_PRIVATE (this);
+
+ if (priv->size_widget != NULL) {
+ int child_minimal_height;
+ int child_natural_height;
+
+ /* Tie our size to the height of the size_widget */
+ gtk_widget_get_preferred_height (GTK_WIDGET (priv->size_widget),
+ &child_minimal_height,
+ &child_natural_height);
+
+ /* Pad out our height by a little bit - this improves
+ the balance */
+ *minimal_height = child_minimal_height + child_minimal_height / 8;
+ *natural_height = child_natural_height + child_natural_height / 8;
+ } else if (priv->face_pixbuf != NULL) {
+ /* Use the size of the current pixbuf */
+ *minimal_height = *natural_height = gdk_pixbuf_get_height (GDK_PIXBUF (priv->face_pixbuf));
+ } else {
+ /* we don't know anything, so use known dimensions for the svg
+ * files */
+ if (priv->size == CLOCK_FACE_LARGE)
+ *minimal_height = *natural_height = 50;
+ else
+ *minimal_height = *natural_height = 36;
+ }
+}
+#else
static void
clock_face_size_request (GtkWidget *this,
GtkRequisition *requisition)
@@ -266,11 +338,7 @@ clock_face_size_request (GtkWidget *this,
GtkRequisition req;
/* Tie our size to the height of the size_widget */
-#if GTK_CHECK_VERSION (3, 0, 0)
- gtk_widget_get_preferred_size (GTK_WIDGET (priv->size_widget), &req, NULL);
-#else
gtk_widget_size_request (GTK_WIDGET (priv->size_widget), &req);
-#endif
/* Pad out our height by a little bit - this improves
the balance */
@@ -297,27 +365,6 @@ clock_face_size_request (GtkWidget *this,
}
}
}
-
-#if GTK_CHECK_VERSION (3, 0, 0)
-static void
-clock_face_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width)
-{
- GtkRequisition req;
- clock_face_size_request (widget, &req);
- *minimum_width = *natural_width = req.width;
-}
-
-static void
-clock_face_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- GtkRequisition req;
- clock_face_size_request (widget, &req);
- *minimum_height = *natural_height = req.height;
-}
#endif
static void
diff --git a/applets/clock/clock-map.c b/applets/clock/clock-map.c
index 13032c54..bb7fee5c 100644
--- a/applets/clock/clock-map.c
+++ b/applets/clock/clock-map.c
@@ -321,7 +321,7 @@ clock_map_expose (GtkWidget *this, GdkEventExpose *event)
#if GTK_CHECK_VERSION (3, 0, 0)
static void
-clock_map_get_preferred_width (GtkWidget *widget,
+clock_map_get_preferred_width (GtkWidget *this,
gint *minimum_width,
gint *natural_width)
{
@@ -329,7 +329,7 @@ clock_map_get_preferred_width (GtkWidget *widget,
}
static void
-clock_map_get_preferred_height (GtkWidget *widget,
+clock_map_get_preferred_height (GtkWidget *this,
gint *minimum_height,
gint *natural_height)
{
diff --git a/mate-panel/button-widget.c b/mate-panel/button-widget.c
index 8f2d4483..faea383f 100644
--- a/mate-panel/button-widget.c
+++ b/mate-panel/button-widget.c
@@ -645,37 +645,37 @@ button_widget_expose (GtkWidget *widget,
}
#endif
-static void
-button_widget_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- ButtonWidget *button_widget = BUTTON_WIDGET (widget);
-
- if (button_widget->priv->pixbuf) {
- requisition->width = gdk_pixbuf_get_width (button_widget->priv->pixbuf);
- requisition->height = gdk_pixbuf_get_height (button_widget->priv->pixbuf);
- }
-}
-
#if GTK_CHECK_VERSION (3, 0, 0)
static void
button_widget_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
+ gint *minimal_width,
gint *natural_width)
{
- GtkRequisition req;
- button_widget_size_request (widget, &req);
- *minimum_width = *natural_width = req.width;
+ ButtonWidget *button_widget = BUTTON_WIDGET (widget);
+
+ *minimal_width = *natural_width = gdk_pixbuf_get_width (button_widget->priv->pixbuf);
}
static void
button_widget_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
+ gint *minimal_height,
gint *natural_height)
{
- GtkRequisition req;
- button_widget_size_request (widget, &req);
- *minimum_height = *natural_height = req.height;
+ ButtonWidget *button_widget = BUTTON_WIDGET (widget);
+
+ *minimal_height = *natural_height = gdk_pixbuf_get_height (button_widget->priv->pixbuf);
+}
+#else
+static void
+button_widget_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ ButtonWidget *button_widget = BUTTON_WIDGET (widget);
+
+ if (button_widget->priv->pixbuf) {
+ requisition->width = gdk_pixbuf_get_width (button_widget->priv->pixbuf);
+ requisition->height = gdk_pixbuf_get_height (button_widget->priv->pixbuf);
+ }
}
#endif
@@ -845,17 +845,14 @@ button_widget_class_init (ButtonWidgetClass *klass)
#if GTK_CHECK_VERSION (3, 0, 0)
widget_class->get_preferred_width = button_widget_get_preferred_width;
widget_class->get_preferred_height = button_widget_get_preferred_height;
+ widget_class->draw = button_widget_draw;
#else
widget_class->size_request = button_widget_size_request;
+ widget_class->expose_event = button_widget_expose;
#endif
widget_class->button_press_event = button_widget_button_press;
widget_class->enter_notify_event = button_widget_enter_notify;
widget_class->leave_notify_event = button_widget_leave_notify;
-#if GTK_CHECK_VERSION (3, 0, 0)
- widget_class->draw = button_widget_draw;
-#else
- widget_class->expose_event = button_widget_expose;
-#endif
button_class->activate = button_widget_activate;
diff --git a/mate-panel/panel-frame.c b/mate-panel/panel-frame.c
index 7602a724..224a00b8 100644
--- a/mate-panel/panel-frame.c
+++ b/mate-panel/panel-frame.c
@@ -35,6 +35,77 @@ enum {
PROP_EDGES
};
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void
+panel_frame_get_preferred_width (GtkWidget *widget,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ PanelFrame *frame = (PanelFrame *) widget;
+ GtkBin *bin = (GtkBin *) widget;
+ GtkStyle *style;
+ GtkWidget *child;
+ int border_width;
+
+ style = gtk_widget_get_style (widget);
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+ *minimal_width = 1;
+ *natural_width = 1;
+
+ child = gtk_bin_get_child (bin);
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_get_preferred_width (child, minimal_width, natural_width);
+
+ *minimal_width += border_width;
+ *natural_width += border_width;
+
+ if (frame->edges & PANEL_EDGE_LEFT) {
+ *minimal_width += style->ythickness;
+ *natural_width += style->ythickness;
+ }
+ if (frame->edges & PANEL_EDGE_RIGHT) {
+ *minimal_width += style->ythickness;
+ *natural_width += style->ythickness;
+ }
+}
+
+static void
+panel_frame_get_preferred_height (GtkWidget *widget,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ PanelFrame *frame = (PanelFrame *) widget;
+ GtkBin *bin = (GtkBin *) widget;
+ GtkStyle *style;
+ GtkWidget *child;
+ int border_width;
+
+ style = gtk_widget_get_style (widget);
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+ *minimal_height = 1;
+ *natural_height = 1;
+
+ child = gtk_bin_get_child (bin);
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_get_preferred_height (child, minimal_height, natural_height);
+
+ *minimal_height += border_width;
+ *natural_height += border_width;
+
+
+ if (frame->edges & PANEL_EDGE_TOP) {
+ *minimal_height += style->xthickness;
+ *natural_height += style->xthickness;
+ }
+ if (frame->edges & PANEL_EDGE_BOTTOM) {
+ *minimal_height += style->xthickness;
+ *natural_height += style->xthickness;
+ }
+}
+
+#else
static void
panel_frame_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@@ -53,11 +124,7 @@ panel_frame_size_request (GtkWidget *widget,
child = gtk_bin_get_child (bin);
if (child && gtk_widget_get_visible (child))
-#if GTK_CHECK_VERSION (3, 0, 0)
- gtk_widget_get_preferred_size (child, requisition, NULL);
-#else
gtk_widget_size_request (child, requisition);
-#endif
requisition->width += border_width;
requisition->height += border_width;
@@ -71,27 +138,6 @@ panel_frame_size_request (GtkWidget *widget,
if (frame->edges & PANEL_EDGE_RIGHT)
requisition->width += style->ythickness;
}
-
-#if GTK_CHECK_VERSION (3, 0, 0)
-static void
-panel_frame_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width)
-{
- GtkRequisition req;
- panel_frame_size_request (widget, &req);
- *minimum_width = *natural_width = req.width;
-}
-
-static void
-panel_frame_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- GtkRequisition req;
- panel_frame_size_request (widget, &req);
- *minimum_height = *natural_height = req.height;
-}
#endif
static void
diff --git a/mate-panel/panel-separator.c b/mate-panel/panel-separator.c
index 022797c6..7233d59a 100644
--- a/mate-panel/panel-separator.c
+++ b/mate-panel/panel-separator.c
@@ -133,6 +133,43 @@ static gboolean panel_separator_expose_event(GtkWidget* widget, GdkEventExpose*
return FALSE;
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void
+panel_separator_get_preferred_width (GtkWidget *widget,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ PanelSeparator *separator;
+ int size;
+
+ separator = PANEL_SEPARATOR (widget);
+
+ size = panel_toplevel_get_size (separator->priv->panel->toplevel);
+
+ if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ *minimal_width = *natural_width = size;
+ else
+ *minimal_width = *natural_width = SEPARATOR_SIZE;
+}
+
+static void
+panel_separator_get_preferred_height (GtkWidget *widget,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ PanelSeparator *separator;
+ int size;
+
+ separator = PANEL_SEPARATOR (widget);
+
+ size = panel_toplevel_get_size (separator->priv->panel->toplevel);
+
+ if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ *minimal_height = *natural_height = SEPARATOR_SIZE;
+ else
+ *minimal_height = *natural_height = size;
+}
+#else
static void
panel_separator_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@@ -152,27 +189,6 @@ panel_separator_size_request (GtkWidget *widget,
requisition->height = size;
}
}
-
-#if GTK_CHECK_VERSION (3, 0, 0)
-static void
-panel_separator_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width)
-{
- GtkRequisition req;
- panel_separator_size_request (widget, &req);
- *minimum_width = *natural_width = req.width;
-}
-
-static void
-panel_separator_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- GtkRequisition req;
- panel_separator_size_request (widget, &req);
- *minimum_height = *natural_height = req.height;
-}
#endif
static void