X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkframe.c;h=9b81631394c455e6d3adefe903861ab7a14d012c;hb=5e2c23214564f7dcc687fa8467020eeb6b9407a9;hp=07393dea2d878a2147f236be539743c6ebddce4d;hpb=52711beba57239aadde460d49d492ef6951f9335;p=~andy%2Fgtk diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c index 07393dea2..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,7 @@ #include "gtktypebuiltins.h" #include "gtkintl.h" #include "gtkbuildable.h" +#include "gtkwidgetpath.h" #include "a11y/gtkframeaccessible.h" @@ -250,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, @@ -260,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 @@ -639,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) @@ -646,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; @@ -654,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; @@ -687,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); @@ -697,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); @@ -737,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; @@ -773,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); } } @@ -795,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) @@ -834,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 @@ -853,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; @@ -863,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)) { @@ -912,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; @@ -930,8 +930,6 @@ gtk_frame_get_preferred_size (GtkWidget *request, if (natural_size) *natural_size = natural; - - gtk_style_context_restore (context); } static void @@ -962,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; @@ -1005,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