* 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 <http://www.gnu.org/licenses/>.
*/
/*
#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().
+ *
+ * <refsect2 id="GtkFrame-BUILDER-UI">
+ * <title>GtkFrame as GtkBuildable</title>
+ * <para>
+ * 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.
+ * </para>
+ * <example>
+ * <title>A UI definition fragment with GtkFrame</title>
+ * <programlisting><![CDATA[
+ * <object class="GtkFrame">
+ * <child type="label">
+ * <object class="GtkLabel" id="frame-label"/>
+ * </child>
+ * <child>
+ * <object class="GtkEntry" id="frame-content"/>
+ * </child>
+ * </object>
+ * ]]></programlisting>
+ * </example>
+ * </refsect2>
+ */
#define LABEL_PAD 1
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
gtk_frame_init (GtkFrame *frame)
{
GtkFramePrivate *priv;
+ GtkStyleContext *context;
frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
GTK_TYPE_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
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;
}
* 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;
/**
* 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().
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;
GtkStyleContext *context;
- GtkStateFlags state;
gint x, y, width, height;
GtkAllocation allocation;
GtkBorder padding;
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;
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);
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);
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;
priv->label_allocation.height = height;
gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
-
- gtk_style_context_restore (context);
}
}
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)
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
{
GtkFrame *frame = GTK_FRAME (request);
GtkFramePrivate *priv = frame->priv;
- GtkStyleContext *context;
- GtkStateFlags state;
GtkBorder padding;
GtkWidget *widget = GTK_WIDGET (request);
GtkWidget *child;
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))
{
}
}
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
minimum += (border_width * 2) + padding.left + padding.right;
if (natural_size)
*natural_size = natural;
-
- gtk_style_context_restore (context);
}
static void
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;
if (natural_height)
*natural_height = natural;
-
- gtk_style_context_restore (context);
}
static void