]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkframe.c
spinbutton: don't override initial text in non-numeric-only spin buttons
[~andy/gtk] / gtk / gtkframe.c
index f0a42ed9532639815093a08a2a951f1d3cf9c736..9b81631394c455e6d3adefe903861ab7a14d012c 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 
 /*
@@ -32,7 +30,9 @@
 #include "gtktypebuiltins.h"
 #include "gtkintl.h"
 #include "gtkbuildable.h"
+#include "gtkwidgetpath.h"
 
+#include "a11y/gtkframeaccessible.h"
 
 /**
  * SECTION:gtkframe
@@ -221,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
@@ -247,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,
@@ -257,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 
@@ -432,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;
@@ -636,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)
@@ -643,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;
@@ -651,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;
@@ -684,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);
@@ -694,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);
 
@@ -734,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;
@@ -770,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);
     }
 }
 
@@ -792,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)
@@ -831,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
@@ -850,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;
@@ -860,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))
     {
@@ -909,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;
@@ -927,8 +930,6 @@ gtk_frame_get_preferred_size (GtkWidget      *request,
 
   if (natural_size)
     *natural_size = natural;
-
-  gtk_style_context_restore (context);
 }
 
 static void
@@ -959,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;
@@ -1002,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