X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkframe.c;h=9b81631394c455e6d3adefe903861ab7a14d012c;hb=e1edc998a2e9c557030d207533932b3120e13fe5;hp=3390e47e8b01508b5482ac40087e6829e2f504de;hpb=d9c92598612714683eab96fecf6e90a9531607e5;p=~andy%2Fgtk
diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c
index 3390e47e8..9b8163139 100644
--- a/gtk/gtkframe.c
+++ b/gtk/gtkframe.c
@@ -12,9 +12,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
/*
@@ -29,8 +27,48 @@
#include "gtkframe.h"
#include "gtklabel.h"
#include "gtkprivate.h"
+#include "gtktypebuiltins.h"
#include "gtkintl.h"
#include "gtkbuildable.h"
+#include "gtkwidgetpath.h"
+
+#include "a11y/gtkframeaccessible.h"
+
+/**
+ * SECTION:gtkframe
+ * @Short_description: A bin with a decorative frame and optional label
+ * @Title: GtkFrame
+ *
+ * The frame widget is a Bin that surrounds its child
+ * with a decorative frame and an optional label.
+ * If present, the label is drawn in a gap in the
+ * top side of the frame. The position of the
+ * label can be controlled with gtk_frame_set_label_align().
+ *
+ *
+ * GtkFrame as GtkBuildable
+ *
+ * The GtkFrame implementation of the GtkBuildable interface
+ * supports placing a child in the label position by specifying
+ * "label" as the "type" attribute of a <child> element.
+ * A normal content child can be specified without specifying
+ * a <child> type attribute.
+ *
+ *
+ * A UI definition fragment with GtkFrame
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * ]]>
+ *
+ *
+ */
#define LABEL_PAD 1
@@ -77,6 +115,8 @@ static void gtk_frame_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
+static GtkWidgetPath * gtk_frame_get_path_for_child (GtkContainer *container,
+ GtkWidget *child);
static void gtk_frame_compute_child_allocation (GtkFrame *frame,
GtkAllocation *child_allocation);
@@ -176,10 +216,13 @@ gtk_frame_class_init (GtkFrameClass *class)
container_class->remove = gtk_frame_remove;
container_class->forall = gtk_frame_forall;
+ container_class->get_path_for_child = gtk_frame_get_path_for_child;
class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
g_type_class_add_private (class, sizeof (GtkFramePrivate));
+
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_FRAME_ACCESSIBLE);
}
static void
@@ -206,6 +249,7 @@ static void
gtk_frame_init (GtkFrame *frame)
{
GtkFramePrivate *priv;
+ GtkStyleContext *context;
frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
GTK_TYPE_FRAME,
@@ -216,6 +260,9 @@ gtk_frame_init (GtkFrame *frame)
priv->shadow_type = GTK_SHADOW_ETCHED_IN;
priv->label_xalign = 0.0;
priv->label_yalign = 0.5;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (frame));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
}
static void
@@ -333,6 +380,23 @@ gtk_frame_forall (GtkContainer *container,
(* callback) (priv->label_widget, callback_data);
}
+static GtkWidgetPath *
+gtk_frame_get_path_for_child (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkFramePrivate *priv = GTK_FRAME (container)->priv;
+ GtkWidgetPath *path;
+
+ path = GTK_CONTAINER_CLASS (gtk_frame_parent_class)->get_path_for_child (container, child);
+
+ if (child == priv->label_widget)
+ gtk_widget_path_iter_add_class (path,
+ gtk_widget_path_length (path) - 2,
+ GTK_STYLE_CLASS_FRAME);
+
+ return path;
+}
+
/**
* gtk_frame_set_label:
* @frame: a #GtkFrame
@@ -374,7 +438,7 @@ gtk_frame_set_label (GtkFrame *frame,
* a #GtkLabel. This string is owned by GTK+ and
* must not be modified or freed.
**/
-G_CONST_RETURN gchar *
+const gchar *
gtk_frame_get_label (GtkFrame *frame)
{
GtkFramePrivate *priv;
@@ -503,8 +567,10 @@ gtk_frame_set_label_align (GtkFrame *frame,
/**
* gtk_frame_get_label_align:
* @frame: a #GtkFrame
- * @xalign: (allow-none): location to store X alignment of frame's label, or %NULL
- * @yalign: (allow-none): location to store X alignment of frame's label, or %NULL
+ * @xalign: (out) (allow-none): location to store X alignment of
+ * frame's label, or %NULL
+ * @yalign: (out) (allow-none): location to store X alignment of
+ * frame's label, or %NULL
*
* Retrieves the X and Y alignment of the frame's label. See
* gtk_frame_set_label_align().
@@ -576,65 +642,94 @@ gtk_frame_get_shadow_type (GtkFrame *frame)
return frame->priv->shadow_type;
}
+static void
+get_padding_and_border (GtkFrame *frame,
+ GtkBorder *border)
+{
+ GtkStyleContext *context;
+ GtkStateFlags state;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (frame));
+ state = gtk_widget_get_state_flags (GTK_WIDGET (frame));
+
+ gtk_style_context_get_padding (context, state, border);
+
+ if (frame->priv->shadow_type != GTK_SHADOW_NONE)
+ {
+ GtkBorder tmp;
+
+ gtk_style_context_get_border (context, state, &tmp);
+ border->top += tmp.top;
+ border->right += tmp.right;
+ border->bottom += tmp.bottom;
+ border->left += tmp.left;
+ }
+}
+
static gboolean
gtk_frame_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkFrame *frame;
GtkFramePrivate *priv;
- GtkStateType state;
- GtkStyle *style;
+ GtkStyleContext *context;
gint x, y, width, height;
GtkAllocation allocation;
+ GtkBorder padding;
frame = GTK_FRAME (widget);
priv = frame->priv;
- style = gtk_widget_get_style (widget);
- state = gtk_widget_get_state (widget);
gtk_widget_get_allocation (widget, &allocation);
+ get_padding_and_border (frame, &padding);
+ context = gtk_widget_get_style_context (widget);
- x = priv->child_allocation.x - allocation.x - style->xthickness;
- y = priv->child_allocation.y - allocation.y - style->ythickness;
- width = priv->child_allocation.width + 2 * style->xthickness;
- height = priv->child_allocation.height + 2 * style->ythickness;
+ x = priv->child_allocation.x - allocation.x - padding.left;
+ y = priv->child_allocation.y - allocation.y - padding.top;
+ width = priv->child_allocation.width + padding.left + padding.right;
+ height = priv->child_allocation.height + padding.top + padding.bottom;
- if (priv->label_widget)
+ if (priv->shadow_type != GTK_SHADOW_NONE)
{
- gfloat xalign;
- gint height_extra;
- gint x2;
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
- xalign = priv->label_xalign;
- else
- xalign = 1 - priv->label_xalign;
-
- height_extra = MAX (0, priv->label_allocation.height - style->ythickness)
- - priv->label_yalign * priv->label_allocation.height;
- y -= height_extra;
- height += height_extra;
-
- x2 = style->xthickness + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
- /* If the label is completely over or under the frame we can omit the gap */
- if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
- gtk_paint_shadow (style, cr,
- state, priv->shadow_type,
- widget, "frame",
- x, y, width, height);
+ if (priv->label_widget)
+ {
+ gfloat xalign;
+ gint height_extra;
+ gint x2;
+
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+ xalign = priv->label_xalign;
+ else
+ xalign = 1 - priv->label_xalign;
+
+ height_extra = MAX (0, priv->label_allocation.height - padding.top)
+ - priv->label_yalign * priv->label_allocation.height;
+ y -= height_extra;
+ height += height_extra;
+
+ x2 = padding.left + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
+
+ gtk_render_background (context, cr, x, y, width, height);
+
+ /* If the label is completely over or under the frame we can omit the gap */
+ if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
+ gtk_render_frame (context, cr, x, y, width, height);
+ else
+ gtk_render_frame_gap (context, cr,
+ x, y, width, height,
+ GTK_POS_TOP, x2,
+ x2 + priv->label_allocation.width + 2 * LABEL_PAD);
+ }
else
- gtk_paint_shadow_gap (style, cr,
- state, priv->shadow_type,
- widget, "frame",
- x, y, width, height,
- GTK_POS_TOP,
- x2, priv->label_allocation.width + 2 * LABEL_PAD);
+ {
+ gtk_render_background (context, cr, x, y, width, height);
+ gtk_render_frame (context, cr, x, y, width, height);
+ }
+ }
+ else
+ {
+ gtk_render_background (context, cr, x, y, width, height);
}
- else
- gtk_paint_shadow (style, cr,
- state, priv->shadow_type,
- widget, "frame",
- x, y, width, height);
GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
@@ -671,11 +766,11 @@ gtk_frame_size_allocate (GtkWidget *widget,
if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
{
- GtkStyle *style;
+ GtkBorder padding;
gint nat_width, width, height;
gfloat xalign;
- style = gtk_widget_get_style (widget);
+ get_padding_and_border (frame, &padding);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = priv->label_xalign;
@@ -695,7 +790,7 @@ gtk_frame_size_allocate (GtkWidget *widget,
priv->label_allocation.width = width;
- priv->label_allocation.y = priv->child_allocation.y - MAX (height, style->ythickness);
+ priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
priv->label_allocation.height = height;
gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
@@ -719,14 +814,12 @@ gtk_frame_real_compute_child_allocation (GtkFrame *frame,
GtkFramePrivate *priv = frame->priv;
GtkWidget *widget = GTK_WIDGET (frame);
GtkAllocation allocation;
- GtkStyle *style;
+ GtkBorder padding;
gint top_margin;
guint border_width;
- style = gtk_widget_get_style (widget);
-
gtk_widget_get_allocation (widget, &allocation);
-
+ get_padding_and_border (frame, &padding);
border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
if (priv->label_widget)
@@ -737,23 +830,24 @@ gtk_frame_real_compute_child_allocation (GtkFrame *frame,
width = allocation.width;
width -= 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
- width -= (border_width + style->xthickness) * 2;
+ width -= (border_width * 2) + padding.left + padding.right;
width = MIN (width, nat_width);
gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
&height, NULL);
- top_margin = MAX (height, style->ythickness);
+ top_margin = MAX (height, padding.top);
}
else
- top_margin = style->ythickness;
+ top_margin = padding.top;
- child_allocation->x = border_width + style->xthickness;
+ child_allocation->x = border_width + padding.left;
child_allocation->y = border_width + top_margin;
- child_allocation->width = MAX (1, (gint) allocation.width - child_allocation->x * 2);
- child_allocation->height = MAX (1, ((gint) allocation.height - child_allocation->y -
- border_width - (gint) style->ythickness));
+ child_allocation->width = MAX (1, (gint) (allocation.width - (border_width * 2) -
+ padding.left - padding.right));
+ child_allocation->height = MAX (1, (gint) (allocation.height - child_allocation->y -
+ border_width - padding.bottom));
child_allocation->x += allocation.x;
child_allocation->y += allocation.y;
@@ -767,7 +861,7 @@ gtk_frame_get_preferred_size (GtkWidget *request,
{
GtkFrame *frame = GTK_FRAME (request);
GtkFramePrivate *priv = frame->priv;
- GtkStyle *style;
+ GtkBorder padding;
GtkWidget *widget = GTK_WIDGET (request);
GtkWidget *child;
GtkBin *bin = GTK_BIN (widget);
@@ -775,7 +869,8 @@ gtk_frame_get_preferred_size (GtkWidget *request,
gint minimum, natural;
guint border_width;
- style = gtk_widget_get_style (widget);
+ get_padding_and_border (frame, &padding);
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
{
@@ -790,8 +885,8 @@ gtk_frame_get_preferred_size (GtkWidget *request,
{
gtk_widget_get_preferred_height (priv->label_widget,
&child_min, &child_nat);
- minimum = MAX (0, child_min - style->ythickness);
- natural = MAX (0, child_nat - style->ythickness);
+ minimum = MAX (0, child_min - padding.top);
+ natural = MAX (0, child_nat - padding.top);
}
}
else
@@ -819,17 +914,15 @@ gtk_frame_get_preferred_size (GtkWidget *request,
}
}
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- minimum += (border_width + style->xthickness) * 2;
- natural += (border_width + style->xthickness) * 2;
+ minimum += (border_width * 2) + padding.left + padding.right;
+ natural += (border_width * 2) + padding.left + padding.right;
}
else
{
- minimum += (border_width + style->ythickness) * 2;
- natural += (border_width + style->ythickness) * 2;
+ minimum += (border_width * 2) + padding.top + padding.bottom;
+ natural += (border_width * 2) + padding.top + padding.bottom;
}
if (minimum_size)
@@ -867,18 +960,18 @@ gtk_frame_get_preferred_height_for_width (GtkWidget *request,
GtkFrame *frame = GTK_FRAME (widget);
GtkFramePrivate *priv = frame->priv;
GtkBin *bin = GTK_BIN (widget);
- GtkStyle *style;
+ GtkBorder padding;
gint child_min, child_nat, label_width;
gint minimum, natural;
guint border_width;
- style = gtk_widget_get_style (widget);
-
+ get_padding_and_border (frame, &padding);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- minimum = (border_width + style->ythickness) * 2;
- natural = (border_width + style->ythickness) * 2;
- width -= (border_width + style->xthickness) * 2;
+ minimum = (border_width * 2) + padding.top + padding.bottom;
+ natural = (border_width * 2) + padding.top + padding.bottom;
+
+ width -= (border_width * 2) + padding.left + padding.right;
label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))