[gtk+/resolution-independence: 10/24] port GtkAlignment, GtkButton and GtkLabel to RI
- From: Davyd Madeley <davyd src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+/resolution-independence: 10/24] port GtkAlignment, GtkButton and GtkLabel to RI
- Date: Sat, 2 May 2009 02:17:52 -0400 (EDT)
commit 6c6f1b3dcd08957b61d31225f4b5a81f5690a91f
Author: David Zeuthen <davidz redhat com>
Date: Wed Aug 13 14:42:38 2008 -0400
port GtkAlignment, GtkButton and GtkLabel to RI
min/max for GtkAlignment
min/max for GtkButton
fixed gtkbutton.c
fixed gtkalignment.c
---
docs/reference/gtk/gtk-sections.txt | 1 +
gtk/gtk.symbols | 1 +
gtk/gtkalignment.c | 128 +++++++++++++++++++++--------------
gtk/gtkalignment.h | 14 +++-
gtk/gtkbutton.c | 97 +++++++++++++++++---------
gtk/gtklabel.c | 18 +++++-
6 files changed, 168 insertions(+), 91 deletions(-)
diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt
index 92c60f4..11d8806 100644
--- a/docs/reference/gtk/gtk-sections.txt
+++ b/docs/reference/gtk/gtk-sections.txt
@@ -328,6 +328,7 @@ GtkAlignment
gtk_alignment_new
gtk_alignment_set
gtk_alignment_get_padding
+gtk_alignment_get_padding_unit
gtk_alignment_set_padding
<SUBSECTION Standard>
GTK_ALIGNMENT
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 9d13ae3..755431a 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -266,6 +266,7 @@ gtk_adjustment_value_changed
#if IN_HEADER(__GTK_ALIGNMENT_H__)
#if IN_FILE(__GTK_ALIGNMENT_C__)
gtk_alignment_get_padding
+gtk_alignment_get_padding_unit
gtk_alignment_get_type G_GNUC_CONST
gtk_alignment_new
gtk_alignment_set
diff --git a/gtk/gtkalignment.c b/gtk/gtkalignment.c
index bf3523b..2b320ba 100644
--- a/gtk/gtkalignment.c
+++ b/gtk/gtkalignment.c
@@ -48,10 +48,10 @@ enum {
struct _GtkAlignmentPrivate
{
- guint padding_top;
- guint padding_bottom;
- guint padding_left;
- guint padding_right;
+ GtkUSize padding_top;
+ GtkUSize padding_bottom;
+ GtkUSize padding_left;
+ GtkUSize padding_right;
};
static void gtk_alignment_size_request (GtkWidget *widget,
@@ -132,13 +132,11 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
*/
g_object_class_install_property (gobject_class,
PROP_TOP_PADDING,
- g_param_spec_uint("top-padding",
- P_("Top Padding"),
- P_("The padding to insert at the top of the widget."),
- 0,
- G_MAXINT,
- 0,
- GTK_PARAM_READWRITE));
+ gtk_param_spec_usize("top-padding",
+ P_("Top Padding"),
+ P_("The padding to insert at the top of the widget."),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
/**
* GtkAlignment:bottom-padding:
@@ -149,13 +147,11 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
*/
g_object_class_install_property (gobject_class,
PROP_BOTTOM_PADDING,
- g_param_spec_uint("bottom-padding",
- P_("Bottom Padding"),
- P_("The padding to insert at the bottom of the widget."),
- 0,
- G_MAXINT,
- 0,
- GTK_PARAM_READWRITE));
+ gtk_param_spec_usize("bottom-padding",
+ P_("Bottom Padding"),
+ P_("The padding to insert at the bottom of the widget."),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
/**
* GtkAlignment:left-padding:
@@ -166,13 +162,11 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
*/
g_object_class_install_property (gobject_class,
PROP_LEFT_PADDING,
- g_param_spec_uint("left-padding",
- P_("Left Padding"),
- P_("The padding to insert at the left of the widget."),
- 0,
- G_MAXINT,
- 0,
- GTK_PARAM_READWRITE));
+ gtk_param_spec_usize("left-padding",
+ P_("Left Padding"),
+ P_("The padding to insert at the left of the widget."),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
/**
* GtkAlignment:right-padding:
@@ -183,13 +177,11 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
*/
g_object_class_install_property (gobject_class,
PROP_RIGHT_PADDING,
- g_param_spec_uint("right-padding",
- P_("Right Padding"),
- P_("The padding to insert at the right of the widget."),
- 0,
- G_MAXINT,
- 0,
- GTK_PARAM_READWRITE));
+ gtk_param_spec_usize("right-padding",
+ P_("Right Padding"),
+ P_("The padding to insert at the right of the widget."),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
g_type_class_add_private (gobject_class, sizeof (GtkAlignmentPrivate));
}
@@ -279,7 +271,7 @@ gtk_alignment_set_property (GObject *object,
/* Padding: */
case PROP_TOP_PADDING:
gtk_alignment_set_padding (alignment,
- g_value_get_uint (value),
+ gtk_value_get_usize (value),
priv->padding_bottom,
priv->padding_left,
priv->padding_right);
@@ -287,7 +279,7 @@ gtk_alignment_set_property (GObject *object,
case PROP_BOTTOM_PADDING:
gtk_alignment_set_padding (alignment,
priv->padding_top,
- g_value_get_uint (value),
+ gtk_value_get_usize (value),
priv->padding_left,
priv->padding_right);
break;
@@ -295,7 +287,7 @@ gtk_alignment_set_property (GObject *object,
gtk_alignment_set_padding (alignment,
priv->padding_top,
priv->padding_bottom,
- g_value_get_uint (value),
+ gtk_value_get_usize (value),
priv->padding_right);
break;
case PROP_RIGHT_PADDING:
@@ -303,7 +295,7 @@ gtk_alignment_set_property (GObject *object,
priv->padding_top,
priv->padding_bottom,
priv->padding_left,
- g_value_get_uint (value));
+ gtk_value_get_usize (value));
break;
default:
@@ -341,16 +333,16 @@ gtk_alignment_get_property (GObject *object,
/* Padding: */
case PROP_TOP_PADDING:
- g_value_set_uint (value, priv->padding_top);
+ gtk_value_set_usize (value, priv->padding_top, alignment);
break;
case PROP_BOTTOM_PADDING:
- g_value_set_uint (value, priv->padding_bottom);
+ gtk_value_set_usize (value, priv->padding_bottom, alignment);
break;
case PROP_LEFT_PADDING:
- g_value_set_uint (value, priv->padding_left);
+ gtk_value_set_usize (value, priv->padding_left, alignment);
break;
case PROP_RIGHT_PADDING:
- g_value_set_uint (value, priv->padding_right);
+ gtk_value_set_usize (value, priv->padding_right, alignment);
break;
default:
@@ -431,8 +423,8 @@ gtk_alignment_size_request (GtkWidget *widget,
requisition->height += child_requisition.height;
/* Request extra space for the padding: */
- requisition->width += (priv->padding_left + priv->padding_right);
- requisition->height += (priv->padding_top + priv->padding_bottom);
+ requisition->width += (gtk_widget_size_to_pixel (widget, priv->padding_left) + gtk_widget_size_to_pixel (widget, priv->padding_right));
+ requisition->height += (gtk_widget_size_to_pixel (widget, priv->padding_top) + gtk_widget_size_to_pixel (widget, priv->padding_bottom));
}
}
@@ -463,8 +455,8 @@ gtk_alignment_size_allocate (GtkWidget *widget,
border_width = GTK_CONTAINER (alignment)->border_width;
priv = GTK_ALIGNMENT_GET_PRIVATE (widget);
- padding_horizontal = priv->padding_left + priv->padding_right;
- padding_vertical = priv->padding_top + priv->padding_bottom;
+ padding_horizontal = gtk_widget_size_to_pixel (widget, priv->padding_left) + gtk_widget_size_to_pixel (widget, priv->padding_right);
+ padding_vertical = gtk_widget_size_to_pixel (widget, priv->padding_top) + gtk_widget_size_to_pixel (widget, priv->padding_bottom);
width = MAX (1, allocation->width - padding_horizontal - 2 * border_width);
height = MAX (1, allocation->height - padding_vertical - 2 * border_width);
@@ -484,11 +476,11 @@ gtk_alignment_size_allocate (GtkWidget *widget,
child_allocation.height = height;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- child_allocation.x = (1.0 - alignment->xalign) * (width - child_allocation.width) + allocation->x + border_width + priv->padding_right;
+ child_allocation.x = (1.0 - alignment->xalign) * (width - child_allocation.width) + allocation->x + border_width + gtk_widget_size_to_pixel (widget, priv->padding_right);
else
- child_allocation.x = alignment->xalign * (width - child_allocation.width) + allocation->x + border_width + priv->padding_left;
+ child_allocation.x = alignment->xalign * (width - child_allocation.width) + allocation->x + border_width + gtk_widget_size_to_pixel (widget, priv->padding_left);
- child_allocation.y = alignment->yalign * (height - child_allocation.height) + allocation->y + border_width + priv->padding_top;
+ child_allocation.y = alignment->yalign * (height - child_allocation.height) + allocation->y + border_width + gtk_widget_size_to_pixel (widget, priv->padding_top);
gtk_widget_size_allocate (bin->child, &child_allocation);
}
@@ -511,10 +503,10 @@ gtk_alignment_size_allocate (GtkWidget *widget,
*/
void
gtk_alignment_set_padding (GtkAlignment *alignment,
- guint padding_top,
- guint padding_bottom,
- guint padding_left,
- guint padding_right)
+ GtkUSize padding_top,
+ GtkUSize padding_bottom,
+ GtkUSize padding_left,
+ GtkUSize padding_right)
{
GtkAlignmentPrivate *priv;
@@ -580,6 +572,40 @@ gtk_alignment_get_padding (GtkAlignment *alignment,
priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
if(padding_top)
+ *padding_top = gtk_widget_size_to_pixel (alignment, priv->padding_top);
+ if(padding_bottom)
+ *padding_bottom = gtk_widget_size_to_pixel (alignment, priv->padding_bottom);
+ if(padding_left)
+ *padding_left = gtk_widget_size_to_pixel (alignment, priv->padding_left);
+ if(padding_right)
+ *padding_right = gtk_widget_size_to_pixel (alignment, priv->padding_right);
+}
+
+/**
+ * gtk_alignment_get_padding_unit:
+ * @alignment: a #GtkAlignment
+ * @padding_top: location to store the padding for the top of the widget, or %NULL
+ * @padding_bottom: location to store the padding for the bottom of the widget, or %NULL
+ * @padding_left: location to store the padding for the left of the widget, or %NULL
+ * @padding_right: location to store the padding for the right of the widget, or %NULL
+ *
+ * Like gtk_alignment_get_padding() but preserves the unit.
+ *
+ * Since: 2.14
+ */
+void
+gtk_alignment_get_padding_unit (GtkAlignment *alignment,
+ GtkUSize *padding_top,
+ GtkUSize *padding_bottom,
+ GtkUSize *padding_left,
+ GtkUSize *padding_right)
+{
+ GtkAlignmentPrivate *priv;
+
+ g_return_if_fail (GTK_IS_ALIGNMENT (alignment));
+
+ priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
+ if(padding_top)
*padding_top = priv->padding_top;
if(padding_bottom)
*padding_bottom = priv->padding_bottom;
diff --git a/gtk/gtkalignment.h b/gtk/gtkalignment.h
index 4fad302..c30e373 100644
--- a/gtk/gtkalignment.h
+++ b/gtk/gtkalignment.h
@@ -77,10 +77,10 @@ void gtk_alignment_set (GtkAlignment *alignment,
gfloat yscale);
void gtk_alignment_set_padding (GtkAlignment *alignment,
- guint padding_top,
- guint padding_bottom,
- guint padding_left,
- guint padding_right);
+ GtkUSize padding_top,
+ GtkUSize padding_bottom,
+ GtkUSize padding_left,
+ GtkUSize padding_right);
void gtk_alignment_get_padding (GtkAlignment *alignment,
guint *padding_top,
@@ -88,6 +88,12 @@ void gtk_alignment_get_padding (GtkAlignment *alignment,
guint *padding_left,
guint *padding_right);
+void gtk_alignment_get_padding_unit (GtkAlignment *alignment,
+ GtkUSize *padding_top,
+ GtkUSize *padding_bottom,
+ GtkUSize *padding_left,
+ GtkUSize *padding_right);
+
G_END_DECLS
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index d749344..a0d1dc1 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -41,9 +41,32 @@
#include "gtkintl.h"
#include "gtkalias.h"
-static const GtkBorder default_default_border = { 1, 1, 1, 1 };
-static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
-static const GtkBorder default_inner_border = { 1, 1, 1, 1 };
+static void
+set_default_default_border (GtkWidget *widget, GtkBorder *border)
+{
+ border->left = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+ border->right = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+ border->top = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+ border->bottom = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+}
+
+static void
+set_default_default_outside_border (GtkWidget *widget, GtkBorder *border)
+{
+ border->left = 0;
+ border->right = 0;
+ border->top = 0;
+ border->bottom = 0;
+}
+
+static void
+set_default_inner_border (GtkWidget *widget, GtkBorder *border)
+{
+ border->left = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+ border->right = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+ border->top = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+ border->bottom = gtk_widget_size_to_pixel (widget, GTK_SIZE_ONE_TWELFTH_EM (1));
+}
/* Time out before giving up on getting a key release when animating
* the close button.
@@ -442,21 +465,17 @@ gtk_button_class_init (GtkButtonClass *klass)
GTK_TYPE_BORDER,
GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_int ("child-displacement-x",
- P_("Child X Displacement"),
- P_("How far in the x direction to move the child when the button is depressed"),
- G_MININT,
- G_MAXINT,
- 0,
- GTK_PARAM_READABLE));
+ gtk_param_spec_size ("child-displacement-x",
+ P_("Child X Displacement"),
+ P_("How far in the x direction to move the child when the button is depressed"),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_int ("child-displacement-y",
- P_("Child Y Displacement"),
- P_("How far in the y direction to move the child when the button is depressed"),
- G_MININT,
- G_MAXINT,
- 0,
- GTK_PARAM_READABLE));
+ gtk_param_spec_size ("child-displacement-y",
+ P_("Child Y Displacement"),
+ P_("How far in the y direction to move the child when the button is depressed"),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READABLE));
/**
* GtkButton:displace-focus:
@@ -495,13 +514,11 @@ gtk_button_class_init (GtkButtonClass *klass)
* Since: 2.10
*/
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_int ("image-spacing",
- P_("Image spacing"),
- P_("Spacing in pixels between the image and label"),
- 0,
- G_MAXINT,
- 2,
- GTK_PARAM_READABLE));
+ gtk_param_spec_size ("image-spacing",
+ P_("Image spacing"),
+ P_("Spacing in pixels between the image and label"),
+ 0, G_MAXINT, GTK_SIZE_ONE_TWELFTH_EM (2),
+ GTK_PARAM_READABLE));
/**
* GtkSettings::gtk-button-images:
@@ -933,7 +950,7 @@ gtk_button_construct_child (GtkButton *button)
GtkWidget *align;
GtkWidget *image = NULL;
gchar *label_text = NULL;
- gint image_spacing;
+ GtkSize image_spacing;
if (!button->constructed)
return;
@@ -941,9 +958,9 @@ gtk_button_construct_child (GtkButton *button)
if (!button->label_text && !priv->image)
return;
- gtk_widget_style_get (GTK_WIDGET (button),
- "image-spacing", &image_spacing,
- NULL);
+ gtk_widget_style_get_unit (GTK_WIDGET (button),
+ "image-spacing", &image_spacing,
+ NULL);
if (priv->image && !priv->image_is_stock)
{
@@ -1241,9 +1258,9 @@ gtk_button_update_image_spacing (GtkButton *button)
child = GTK_BIN (child)->child;
if (GTK_IS_BOX (child))
{
- gtk_widget_style_get (GTK_WIDGET (button),
- "image-spacing", &spacing,
- NULL);
+ gtk_widget_style_get_unit (GTK_WIDGET (button),
+ "image-spacing", &spacing,
+ NULL);
gtk_box_set_spacing (GTK_BOX (child), spacing);
}
@@ -1273,11 +1290,15 @@ gtk_button_get_props (GtkButton *button,
if (tmp_border)
{
+ tmp_border->left = gtk_widget_size_to_pixel (widget, tmp_border->left);
+ tmp_border->right = gtk_widget_size_to_pixel (widget, tmp_border->right);
+ tmp_border->top = gtk_widget_size_to_pixel (widget, tmp_border->top);
+ tmp_border->bottom = gtk_widget_size_to_pixel (widget, tmp_border->bottom);
*default_border = *tmp_border;
gtk_border_free (tmp_border);
}
else
- *default_border = default_default_border;
+ set_default_default_border (widget, default_border);
}
if (default_outside_border)
@@ -1286,11 +1307,15 @@ gtk_button_get_props (GtkButton *button,
if (tmp_border)
{
+ tmp_border->left = gtk_widget_size_to_pixel (widget, tmp_border->left);
+ tmp_border->right = gtk_widget_size_to_pixel (widget, tmp_border->right);
+ tmp_border->top = gtk_widget_size_to_pixel (widget, tmp_border->top);
+ tmp_border->bottom = gtk_widget_size_to_pixel (widget, tmp_border->bottom);
*default_outside_border = *tmp_border;
gtk_border_free (tmp_border);
}
else
- *default_outside_border = default_default_outside_border;
+ set_default_default_outside_border (widget, default_outside_border);
}
if (inner_border)
@@ -1299,11 +1324,15 @@ gtk_button_get_props (GtkButton *button,
if (tmp_border)
{
+ tmp_border->left = gtk_widget_size_to_pixel (widget, tmp_border->left);
+ tmp_border->right = gtk_widget_size_to_pixel (widget, tmp_border->right);
+ tmp_border->top = gtk_widget_size_to_pixel (widget, tmp_border->top);
+ tmp_border->bottom = gtk_widget_size_to_pixel (widget, tmp_border->bottom);
*inner_border = *tmp_border;
gtk_border_free (tmp_border);
}
else
- *inner_border = default_inner_border;
+ set_default_inner_border (widget, inner_border);
}
if (interior_focus)
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 91ab5cc..ce0c41d 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -162,6 +162,7 @@ static void gtk_label_hierarchy_changed (GtkWidget *widget,
GtkWidget *old_toplevel);
static void gtk_label_screen_changed (GtkWidget *widget,
GdkScreen *old_screen);
+static void gtk_label_unit_changed (GtkWidget *widget);
static void gtk_label_create_window (GtkLabel *label);
static void gtk_label_destroy_window (GtkLabel *label);
@@ -277,6 +278,7 @@ gtk_label_class_init (GtkLabelClass *class)
widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
widget_class->drag_data_get = gtk_label_drag_data_get;
widget_class->grab_focus = gtk_label_grab_focus;
+ widget_class->unit_changed = gtk_label_unit_changed;
class->move_cursor = gtk_label_move_cursor;
class->copy_clipboard = gtk_label_copy_clipboard;
@@ -1406,6 +1408,18 @@ label_shortcut_setting_changed (GtkSettings *settings)
}
static void
+gtk_label_unit_changed (GtkWidget *widget)
+{
+ GtkLabel *label = GTK_LABEL (widget);
+
+ gtk_label_recalculate (label);
+
+ /* must chain up */
+ if (GTK_WIDGET_CLASS (gtk_label_parent_class)->unit_changed != NULL)
+ GTK_WIDGET_CLASS (gtk_label_parent_class)->unit_changed (widget);
+}
+
+static void
gtk_label_screen_changed (GtkWidget *widget,
GdkScreen *old_screen)
{
@@ -2487,7 +2501,7 @@ gtk_label_ensure_layout (GtkLabel *label)
aux_info = _gtk_widget_get_aux_info (widget, FALSE);
if (aux_info && aux_info->width > 0)
- pango_layout_set_width (label->layout, aux_info->width * PANGO_SCALE);
+ pango_layout_set_width (label->layout, gtk_widget_size_to_pixel (widget, aux_info->width) * PANGO_SCALE);
else
{
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (label));
@@ -2607,7 +2621,7 @@ gtk_label_size_request (GtkWidget *widget,
if ((label->wrap || label->ellipsize ||
priv->width_chars > 0 || priv->max_width_chars > 0) &&
aux_info && aux_info->width > 0)
- width += aux_info->width;
+ width += gtk_widget_size_to_pixel (widget, aux_info->width);
else if (label->ellipsize || priv->width_chars > 0 || priv->max_width_chars > 0)
{
width += PANGO_PIXELS (get_label_char_width (label));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]