X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkframe.c;h=9b81631394c455e6d3adefe903861ab7a14d012c;hb=1247a842a228980a06893e6167ae8c73a4bb6eed;hp=5e6e2fc7878da795ec9f1e74ff959503a2f60dbb;hpb=920e8b434367f9aa8aab306721cc024e66892e2e;p=~andy%2Fgtk
diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c
index 5e6e2fc78..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 .
*/
/*
@@ -32,6 +30,45 @@
#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
@@ -184,6 +221,8 @@ gtk_frame_class_init (GtkFrameClass *class)
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
@@ -210,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,
@@ -220,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
@@ -347,7 +390,9 @@ gtk_frame_get_path_for_child (GtkContainer *container,
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, -1, GTK_STYLE_CLASS_FRAME);
+ gtk_widget_path_iter_add_class (path,
+ gtk_widget_path_length (path) - 2,
+ GTK_STYLE_CLASS_FRAME);
return path;
}
@@ -393,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;
@@ -522,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().
@@ -595,6 +642,30 @@ 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)
@@ -602,7 +673,6 @@ gtk_frame_draw (GtkWidget *widget,
GtkFrame *frame;
GtkFramePrivate *priv;
GtkStyleContext *context;
- GtkStateFlags state;
gint x, y, width, height;
GtkAllocation allocation;
GtkBorder padding;
@@ -610,14 +680,9 @@ gtk_frame_draw (GtkWidget *widget,
frame = GTK_FRAME (widget);
priv = frame->priv;
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
gtk_widget_get_allocation (widget, &allocation);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
-
- gtk_style_context_get_padding (context, state, &padding);
+ get_padding_and_border (frame, &padding);
+ context = gtk_widget_get_style_context (widget);
x = priv->child_allocation.x - allocation.x - padding.left;
y = priv->child_allocation.y - allocation.y - padding.top;
@@ -643,6 +708,9 @@ gtk_frame_draw (GtkWidget *widget,
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);
@@ -653,10 +721,15 @@ gtk_frame_draw (GtkWidget *widget,
x2 + priv->label_allocation.width + 2 * LABEL_PAD);
}
else
- gtk_render_frame (context, cr, x, y, width, height);
+ {
+ 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);
}
-
- gtk_style_context_restore (context);
GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
@@ -693,19 +766,11 @@ gtk_frame_size_allocate (GtkWidget *widget,
if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
{
- GtkStyleContext *context;
- GtkStateFlags state;
GtkBorder padding;
gint nat_width, width, height;
gfloat xalign;
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
-
- gtk_style_context_get_padding (context, state, &padding);
+ get_padding_and_border (frame, &padding);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = priv->label_xalign;
@@ -729,8 +794,6 @@ gtk_frame_size_allocate (GtkWidget *widget,
priv->label_allocation.height = height;
gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
-
- gtk_style_context_restore (context);
}
}
@@ -751,21 +814,12 @@ gtk_frame_real_compute_child_allocation (GtkFrame *frame,
GtkFramePrivate *priv = frame->priv;
GtkWidget *widget = GTK_WIDGET (frame);
GtkAllocation allocation;
- GtkStyleContext *context;
- GtkStateFlags state;
GtkBorder padding;
gint top_margin;
guint border_width;
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
-
- gtk_style_context_get_padding (context, state, &padding);
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)
@@ -790,15 +844,13 @@ gtk_frame_real_compute_child_allocation (GtkFrame *frame,
child_allocation->x = border_width + padding.left;
child_allocation->y = border_width + top_margin;
- 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->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;
-
- gtk_style_context_restore (context);
}
static void
@@ -809,8 +861,6 @@ gtk_frame_get_preferred_size (GtkWidget *request,
{
GtkFrame *frame = GTK_FRAME (request);
GtkFramePrivate *priv = frame->priv;
- GtkStyleContext *context;
- GtkStateFlags state;
GtkBorder padding;
GtkWidget *widget = GTK_WIDGET (request);
GtkWidget *child;
@@ -819,12 +869,8 @@ gtk_frame_get_preferred_size (GtkWidget *request,
gint minimum, natural;
guint border_width;
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
- gtk_style_context_get_padding (context, state, &padding);
+ 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))
{
@@ -868,8 +914,6 @@ 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 * 2) + padding.left + padding.right;
@@ -886,8 +930,6 @@ gtk_frame_get_preferred_size (GtkWidget *request,
if (natural_size)
*natural_size = natural;
-
- gtk_style_context_restore (context);
}
static void
@@ -918,23 +960,16 @@ gtk_frame_get_preferred_height_for_width (GtkWidget *request,
GtkFrame *frame = GTK_FRAME (widget);
GtkFramePrivate *priv = frame->priv;
GtkBin *bin = GTK_BIN (widget);
- GtkStyleContext *context;
- GtkStateFlags state;
GtkBorder padding;
gint child_min, child_nat, label_width;
gint minimum, natural;
guint border_width;
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
- gtk_style_context_get_padding (context, state, &padding);
-
+ get_padding_and_border (frame, &padding);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- minimum = (border_width * 2) + padding.top + padding.bottom;
- natural = (border_width * 2) + padding.top + padding.bottom;
+
+ 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;
@@ -961,8 +996,6 @@ gtk_frame_get_preferred_height_for_width (GtkWidget *request,
if (natural_height)
*natural_height = natural;
-
- gtk_style_context_restore (context);
}
static void