[gtk+/resolution-independence: 13/24] port GtkArrow, GtkEntry, GtkFrame, GtkStatus and GtkImage to RI
- From: Davyd Madeley <davyd src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+/resolution-independence: 13/24] port GtkArrow, GtkEntry, GtkFrame, GtkStatus and GtkImage to RI
- Date: Sat, 2 May 2009 02:18:07 -0400 (EDT)
commit 6fb824a0b331737e025d6fe17ed996b68ee16898
Author: David Zeuthen <davidz redhat com>
Date: Wed Aug 13 15:13:27 2008 -0400
port GtkArrow, GtkEntry, GtkFrame, GtkStatus and GtkImage to RI
min/max for GtkImage
fixed gtkimage.c
Rebase: fix GtkArrow
---
docs/reference/gtk/gtk-sections.txt | 1 +
gtk/gtk.symbols | 1 +
gtk/gtkarrow.c | 17 ++++++--
gtk/gtkentry.c | 34 ++++++++++++++--
gtk/gtkframe.c | 16 ++++----
gtk/gtkimage.c | 72 ++++++++++++++++++++++++++--------
gtk/gtkimage.h | 3 +-
gtk/gtkstatusbar.c | 4 +-
8 files changed, 111 insertions(+), 37 deletions(-)
diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt
index 11d8806..fbc5085 100644
--- a/docs/reference/gtk/gtk-sections.txt
+++ b/docs/reference/gtk/gtk-sections.txt
@@ -2021,6 +2021,7 @@ gtk_image_set
gtk_image_get
gtk_image_set_pixel_size
gtk_image_get_pixel_size
+gtk_image_get_pixel_size_unit
<SUBSECTION Standard>
GTK_IMAGE
GTK_IS_IMAGE
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 755431a..9407a17 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2030,6 +2030,7 @@ gtk_image_get_icon_set
gtk_image_get_image
gtk_image_get_pixbuf
gtk_image_get_pixel_size
+gtk_image_get_pixel_size_unit
gtk_image_get_pixmap
gtk_image_get_stock
gtk_image_get_gicon
diff --git a/gtk/gtkarrow.c b/gtk/gtkarrow.c
index e6fc3dc..17a49cf 100644
--- a/gtk/gtkarrow.c
+++ b/gtk/gtkarrow.c
@@ -31,7 +31,7 @@
#include "gtkintl.h"
#include "gtkalias.h"
-#define MIN_ARROW_SIZE 15
+#define MIN_ARROW_SIZE GTK_SIZE_ONE_TWELFTH_EM(15)
enum {
PROP_0,
@@ -50,7 +50,8 @@ static void gtk_arrow_get_property (GObject *object,
GParamSpec *pspec);
static gboolean gtk_arrow_expose (GtkWidget *widget,
GdkEventExpose *event);
-
+static void gtk_arrow_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
@@ -68,6 +69,7 @@ gtk_arrow_class_init (GtkArrowClass *class)
gobject_class->get_property = gtk_arrow_get_property;
widget_class->expose_event = gtk_arrow_expose;
+ widget_class->size_request = gtk_arrow_size_request;
g_object_class_install_property (gobject_class,
PROP_ARROW_TYPE,
@@ -148,9 +150,6 @@ gtk_arrow_init (GtkArrow *arrow)
{
GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
- GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
- GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
-
arrow->arrow_type = GTK_ARROW_RIGHT;
arrow->shadow_type = GTK_SHADOW_OUT;
}
@@ -200,6 +199,14 @@ gtk_arrow_set (GtkArrow *arrow,
}
}
+static void
+gtk_arrow_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ GtkArrow *arrow = GTK_ARROW (widget);
+ requisition->width = gtk_widget_size_to_pixel (arrow, MIN_ARROW_SIZE) + GTK_MISC (arrow)->xpad * 2;
+ requisition->height = gtk_widget_size_to_pixel (arrow, MIN_ARROW_SIZE) + GTK_MISC (arrow)->ypad * 2;
+}
static gboolean
gtk_arrow_expose (GtkWidget *widget,
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 607ef87..1d5078d 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -68,7 +68,7 @@
#define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
-#define MIN_ENTRY_WIDTH 150
+#define MIN_ENTRY_WIDTH GTK_SIZE_ONE_TWELFTH_EM(150)
#define DRAW_TIMEOUT 20
#define COMPLETION_TIMEOUT 300
#define PASSWORD_HINT_MAX 8
@@ -85,12 +85,20 @@
((pos) == GTK_ENTRY_ICON_PRIMARY || \
(pos) == GTK_ENTRY_ICON_SECONDARY)
-static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
static GQuark quark_inner_border = 0;
static GQuark quark_password_hint = 0;
static GQuark quark_cursor_hadjustment = 0;
static GQuark quark_capslock_feedback = 0;
+static void
+set_default_inner_border (GtkEntry *entry, GtkBorder *border)
+{
+ border->left = gtk_widget_size_to_pixel (entry, GTK_SIZE_ONE_TWELFTH_EM (2));
+ border->right = gtk_widget_size_to_pixel (entry, GTK_SIZE_ONE_TWELFTH_EM (2));
+ border->top = gtk_widget_size_to_pixel (entry, GTK_SIZE_ONE_TWELFTH_EM (2));
+ border->bottom = gtk_widget_size_to_pixel (entry, GTK_SIZE_ONE_TWELFTH_EM (2));
+}
+
typedef struct _GtkEntryPrivate GtkEntryPrivate;
#define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
@@ -381,6 +389,7 @@ static void gtk_entry_toggle_overwrite (GtkEntry *entry);
static void gtk_entry_select_all (GtkEntry *entry);
static void gtk_entry_real_activate (GtkEntry *entry);
static gboolean gtk_entry_popup_menu (GtkWidget *widget);
+static void gtk_entry_unit_changed (GtkWidget *widget);
static void keymap_direction_changed (GdkKeymap *keymap,
GtkEntry *entry);
@@ -580,6 +589,7 @@ gtk_entry_class_init (GtkEntryClass *class)
widget_class->drag_data_delete = gtk_entry_drag_data_delete;
widget_class->popup_menu = gtk_entry_popup_menu;
+ widget_class->unit_changed = gtk_entry_unit_changed;
gtk_object_class->destroy = gtk_entry_destroy;
@@ -2760,7 +2770,7 @@ gtk_entry_size_request (GtkWidget *widget,
_gtk_entry_effective_inner_border (entry, &inner_border);
if (entry->width_chars < 0)
- requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
+ requisition->width = gtk_widget_size_to_pixel (entry, MIN_ENTRY_WIDTH) + xborder * 2 + inner_border.left + inner_border.right;
else
{
gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
@@ -2927,12 +2937,16 @@ _gtk_entry_effective_inner_border (GtkEntry *entry,
if (tmp_border)
{
+ tmp_border->left = gtk_widget_size_to_pixel (entry, tmp_border->left);
+ tmp_border->right = gtk_widget_size_to_pixel (entry, tmp_border->right);
+ tmp_border->top = gtk_widget_size_to_pixel (entry, tmp_border->top);
+ tmp_border->bottom = gtk_widget_size_to_pixel (entry, tmp_border->bottom);
*border = *tmp_border;
gtk_border_free (tmp_border);
return;
}
- *border = default_inner_border;
+ set_default_inner_border (entry, border);
}
static void
@@ -9803,5 +9817,17 @@ keymap_state_changed (GdkKeymap *keymap,
remove_capslock_feedback (entry);
}
+static void
+gtk_entry_unit_changed (GtkWidget *widget)
+{
+ GtkEntry *entry = GTK_ENTRY (widget);
+
+ /* must chain up */
+ if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->unit_changed != NULL)
+ GTK_WIDGET_CLASS (gtk_entry_parent_class)->unit_changed (widget);
+
+ gtk_entry_reset_layout (entry);
+}
+
#define __GTK_ENTRY_C__
#include "gtkaliasdef.c"
diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c
index c767455..fc131ec 100644
--- a/gtk/gtkframe.c
+++ b/gtk/gtkframe.c
@@ -33,8 +33,8 @@
#include "gtkbuildable.h"
#include "gtkalias.h"
-#define LABEL_PAD 1
-#define LABEL_SIDE_PAD 2
+#define LABEL_PAD GTK_SIZE_ONE_TWELFTH_EM(1)
+#define LABEL_SIDE_PAD GTK_SIZE_ONE_TWELFTH_EM(2)
enum {
PROP_0,
@@ -560,7 +560,7 @@ gtk_frame_paint (GtkWidget *widget,
y -= height_extra;
height += height_extra;
- x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
+ x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * gtk_widget_size_to_pixel (frame, LABEL_PAD) - 2 * gtk_widget_size_to_pixel (frame, LABEL_SIDE_PAD)) * xalign + gtk_widget_size_to_pixel (frame, LABEL_SIDE_PAD);
/* If the label is completely over or under the frame we can omit the gap */
if (frame->label_yalign == 0.0 || frame->label_yalign == 1.0)
@@ -574,7 +574,7 @@ gtk_frame_paint (GtkWidget *widget,
area, widget, "frame",
x, y, width, height,
GTK_POS_TOP,
- x2, child_requisition.width + 2 * LABEL_PAD);
+ x2, child_requisition.width + 2 * gtk_widget_size_to_pixel (frame, LABEL_PAD));
}
else
gtk_paint_shadow (widget->style, widget->window,
@@ -610,7 +610,7 @@ gtk_frame_size_request (GtkWidget *widget,
{
gtk_widget_size_request (frame->label_widget, &child_requisition);
- requisition->width = child_requisition.width + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
+ requisition->width = child_requisition.width + 2 * gtk_widget_size_to_pixel (frame, LABEL_PAD) + 2 * gtk_widget_size_to_pixel (frame, LABEL_SIDE_PAD);
requisition->height =
MAX (0, child_requisition.height - widget->style->ythickness);
}
@@ -674,9 +674,9 @@ gtk_frame_size_allocate (GtkWidget *widget,
else
xalign = 1 - frame->label_xalign;
- child_allocation.x = frame->child_allocation.x + LABEL_SIDE_PAD +
- (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
- child_allocation.width = MIN (child_requisition.width, new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD);
+ child_allocation.x = frame->child_allocation.x + gtk_widget_size_to_pixel (frame, LABEL_SIDE_PAD) +
+ (frame->child_allocation.width - child_requisition.width - 2 * gtk_widget_size_to_pixel (frame, LABEL_PAD) - 2 * gtk_widget_size_to_pixel (frame, LABEL_SIDE_PAD)) * xalign + gtk_widget_size_to_pixel (frame, LABEL_PAD);
+ child_allocation.width = MIN (child_requisition.width, new_allocation.width - 2 * gtk_widget_size_to_pixel (frame, LABEL_PAD) - 2 * gtk_widget_size_to_pixel (frame, LABEL_SIDE_PAD));
child_allocation.y = frame->child_allocation.y - MAX (child_requisition.height, widget->style->ythickness);
child_allocation.height = child_requisition.height;
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 036560f..031f679 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -44,7 +44,7 @@ struct _GtkImagePrivate
/* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
gchar *filename;
- gint pixel_size;
+ GtkSize pixel_size;
};
#define GTK_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_IMAGE, GtkImagePrivate))
@@ -61,6 +61,7 @@ static void gtk_image_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gtk_image_screen_changed (GtkWidget *widget,
GdkScreen *prev_screen);
+static void gtk_image_unit_changed (GtkWidget *widget);
static void gtk_image_destroy (GtkObject *object);
static void gtk_image_reset (GtkImage *image);
static void gtk_image_calc_size (GtkImage *image);
@@ -124,6 +125,7 @@ gtk_image_class_init (GtkImageClass *class)
widget_class->unrealize = gtk_image_unrealize;
widget_class->style_set = gtk_image_style_set;
widget_class->screen_changed = gtk_image_screen_changed;
+ widget_class->unit_changed = gtk_image_unit_changed;
g_object_class_install_property (gobject_class,
PROP_PIXBUF,
@@ -201,12 +203,11 @@ gtk_image_class_init (GtkImageClass *class)
*/
g_object_class_install_property (gobject_class,
PROP_PIXEL_SIZE,
- g_param_spec_int ("pixel-size",
- P_("Pixel size"),
- P_("Pixel size to use for named icon"),
- -1, G_MAXINT,
- -1,
- GTK_PARAM_READWRITE));
+ gtk_param_spec_size ("pixel-size",
+ P_("Pixel size"),
+ P_("Pixel size to use for named icon"),
+ -1, G_MAXINT, -1,
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_PIXBUF_ANIMATION,
@@ -365,7 +366,7 @@ gtk_image_set_property (GObject *object,
image->icon_size = g_value_get_int (value);
break;
case PROP_PIXEL_SIZE:
- gtk_image_set_pixel_size (image, g_value_get_int (value));
+ gtk_image_set_pixel_size (image, gtk_value_get_size (value));
break;
case PROP_PIXBUF_ANIMATION:
gtk_image_set_from_animation (image,
@@ -451,7 +452,7 @@ gtk_image_get_property (GObject *object,
g_value_set_int (value, image->icon_size);
break;
case PROP_PIXEL_SIZE:
- g_value_set_int (value, priv->pixel_size);
+ gtk_value_set_size (value, priv->pixel_size, image);
break;
case PROP_PIXBUF_ANIMATION:
if (image->storage_type != GTK_IMAGE_ANIMATION)
@@ -1540,12 +1541,13 @@ ensure_pixbuf_for_icon_name (GtkImage *image)
{
if (priv->pixel_size != -1)
{
- width = height = priv->pixel_size;
+ width = height = gtk_widget_size_to_pixel (image, priv->pixel_size);
flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
}
- else if (!gtk_icon_size_lookup_for_settings (settings,
- image->icon_size,
- &width, &height))
+ else if (!gtk_icon_size_lookup_for_settings_for_monitor (settings,
+ gtk_widget_get_monitor_num (GTK_WIDGET (image)),
+ image->icon_size,
+ &width, &height))
{
if (image->icon_size == -1)
{
@@ -1623,12 +1625,13 @@ ensure_pixbuf_for_gicon (GtkImage *image)
{
if (priv->pixel_size != -1)
{
- width = height = priv->pixel_size;
+ width = height = gtk_widget_size_to_pixel (image, priv->pixel_size);
flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
}
- else if (!gtk_icon_size_lookup_for_settings (settings,
- image->icon_size,
- &width, &height))
+ else if (!gtk_icon_size_lookup_for_settings_for_monitor (settings,
+ gtk_widget_get_monitor_num (GTK_WIDGET (image)),
+ image->icon_size,
+ &width, &height))
{
if (image->icon_size == -1)
width = height = 48;
@@ -2332,6 +2335,28 @@ gtk_image_get_pixel_size (GtkImage *image)
priv = GTK_IMAGE_GET_PRIVATE (image);
+ return gtk_widget_size_to_pixel (image, priv->pixel_size);
+}
+
+/**
+ * gtk_image_get_pixel_size_unit:
+ * @image: a #GtkImage
+ *
+ * Like gtk_image_get_pixel_size() but preserves the unit.
+ *
+ * Returns: the pixel size used for named icons.
+ *
+ * Since: 2.14
+ */
+GtkSize
+gtk_image_get_pixel_size_unit (GtkImage *image)
+{
+ GtkImagePrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
+
+ priv = GTK_IMAGE_GET_PRIVATE (image);
+
return priv->pixel_size;
}
@@ -2367,5 +2392,18 @@ gtk_image_set_from_file (GtkImage *image,
#endif
+static void
+gtk_image_unit_changed (GtkWidget *widget)
+{
+ GtkImage *image = GTK_IMAGE (widget);
+
+ /* must chain up */
+ if (GTK_WIDGET_CLASS (gtk_image_parent_class)->unit_changed != NULL)
+ GTK_WIDGET_CLASS (gtk_image_parent_class)->unit_changed (widget);
+
+ icon_theme_changed (image);
+}
+
+
#define __GTK_IMAGE_C__
#include "gtkaliasdef.c"
diff --git a/gtk/gtkimage.h b/gtk/gtkimage.h
index 8c5e77b..a15bea6 100644
--- a/gtk/gtkimage.h
+++ b/gtk/gtkimage.h
@@ -204,7 +204,7 @@ void gtk_image_set_from_gicon (GtkImage *image,
GIcon *icon,
GtkIconSize size);
void gtk_image_set_pixel_size (GtkImage *image,
- gint pixel_size);
+ GtkSize pixel_size);
GtkImageType gtk_image_get_storage_type (GtkImage *image);
@@ -229,6 +229,7 @@ void gtk_image_get_gicon (GtkImage *image,
GIcon **gicon,
GtkIconSize *size);
gint gtk_image_get_pixel_size (GtkImage *image);
+GtkSize gtk_image_get_pixel_size_unit (GtkImage *image);
#ifndef GTK_DISABLE_DEPRECATED
/* These three are deprecated */
diff --git a/gtk/gtkstatusbar.c b/gtk/gtkstatusbar.c
index 2bddfa8..a77f3c1 100644
--- a/gtk/gtkstatusbar.c
+++ b/gtk/gtkstatusbar.c
@@ -198,8 +198,8 @@ gtk_statusbar_init (GtkStatusbar *statusbar)
box = GTK_BOX (statusbar);
- box->spacing = 2;
- box->homogeneous = FALSE;
+ gtk_box_set_spacing (box, GTK_SIZE_ONE_TWELFTH_EM (2));
+ gtk_box_set_homogeneous (box, FALSE);
statusbar->has_resize_grip = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]