]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkframe.c
Set name "gtk-tooltips" on tip window so that a style can be set for
[~andy/gtk] / gtk / gtkframe.c
index 5fc6aaea6d474ad47b5c8c78303e664ffa422955..5831382da630e6111a86725cc6edcec7b341847e 100644 (file)
@@ -12,8 +12,9 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
  */
 #include <string.h>
 #include "gtkframe.h"
@@ -29,10 +30,10 @@ enum {
 
 static void gtk_frame_class_init    (GtkFrameClass  *klass);
 static void gtk_frame_init          (GtkFrame       *frame);
-static void gtk_frame_set_arg       (GtkFrame       *frame,
+static void gtk_frame_set_arg       (GtkObject      *object,
                                     GtkArg         *arg,
                                     guint           arg_id);
-static void gtk_frame_get_arg       (GtkFrame       *frame,
+static void gtk_frame_get_arg       (GtkObject      *object,
                                     GtkArg         *arg,
                                     guint           arg_id);
 static void gtk_frame_finalize      (GtkObject      *object);
@@ -46,27 +47,30 @@ static void gtk_frame_size_request  (GtkWidget      *widget,
                                     GtkRequisition *requisition);
 static void gtk_frame_size_allocate (GtkWidget      *widget,
                                     GtkAllocation  *allocation);
+static void gtk_frame_style_set     (GtkWidget      *widget,
+                                    GtkStyle       *previous_style);
 
 
 static GtkBinClass *parent_class = NULL;
 
 
-guint
-gtk_frame_get_type ()
+GtkType
+gtk_frame_get_type (void)
 {
-  static guint frame_type = 0;
+  static GtkType frame_type = 0;
 
   if (!frame_type)
     {
-      GtkTypeInfo frame_info =
+      static const GtkTypeInfo frame_info =
       {
        "GtkFrame",
        sizeof (GtkFrame),
        sizeof (GtkFrameClass),
        (GtkClassInitFunc) gtk_frame_class_init,
        (GtkObjectInitFunc) gtk_frame_init,
-       (GtkArgSetFunc) gtk_frame_set_arg,
-        (GtkArgGetFunc) gtk_frame_get_arg,
+        /* reserved_1 */ NULL,
+       /* reserved_2 */ NULL,
+       (GtkClassInitFunc) NULL,
       };
 
       frame_type = gtk_type_unique (gtk_bin_get_type (), &frame_info);
@@ -86,24 +90,25 @@ gtk_frame_class_init (GtkFrameClass *class)
 
   parent_class = gtk_type_class (gtk_bin_get_type ());
 
-  gtk_object_add_arg_type ("GtkFrame::label", GTK_TYPE_STRING, ARG_LABEL);
-  gtk_object_add_arg_type ("GtkFrame::label_xalign", GTK_TYPE_DOUBLE, ARG_LABEL_XALIGN);
-  gtk_object_add_arg_type ("GtkFrame::label_yalign", GTK_TYPE_DOUBLE, ARG_LABEL_YALIGN);
-  gtk_object_add_arg_type ("GtkFrame::shadow", GTK_TYPE_ENUM, ARG_SHADOW);
+  gtk_object_add_arg_type ("GtkFrame::label", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_LABEL);
+  gtk_object_add_arg_type ("GtkFrame::label_xalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_LABEL_XALIGN);
+  gtk_object_add_arg_type ("GtkFrame::label_yalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_LABEL_YALIGN);
+  gtk_object_add_arg_type ("GtkFrame::shadow", GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, ARG_SHADOW);
 
+  object_class->set_arg = gtk_frame_set_arg;
+  object_class->get_arg = gtk_frame_get_arg;
   object_class->finalize = gtk_frame_finalize;
 
   widget_class->draw = gtk_frame_draw;
   widget_class->expose_event = gtk_frame_expose;
   widget_class->size_request = gtk_frame_size_request;
   widget_class->size_allocate = gtk_frame_size_allocate;
+  widget_class->style_set = gtk_frame_style_set;
 }
 
 static void
 gtk_frame_init (GtkFrame *frame)
 {
-  GTK_WIDGET_SET_FLAGS (frame, GTK_BASIC);
-
   frame->label = NULL;
   frame->shadow_type = GTK_SHADOW_ETCHED_IN;
   frame->label_width = 0;
@@ -113,45 +118,52 @@ gtk_frame_init (GtkFrame *frame)
 }
 
 static void
-gtk_frame_set_arg (GtkFrame       *frame,
+gtk_frame_set_arg (GtkObject      *object,
                   GtkArg         *arg,
                   guint           arg_id)
 {
+  GtkFrame *frame;
+
+  frame = GTK_FRAME (object);
+
   switch (arg_id)
     {
     case ARG_LABEL:
       gtk_frame_set_label (frame, GTK_VALUE_STRING (*arg));
       break;
     case ARG_LABEL_XALIGN:
-      gtk_frame_set_label_align (frame, GTK_VALUE_DOUBLE (*arg), frame->label_yalign);
+      gtk_frame_set_label_align (frame, GTK_VALUE_FLOAT (*arg), frame->label_yalign);
       break;
     case ARG_LABEL_YALIGN:
-      gtk_frame_set_label_align (frame, frame->label_xalign, GTK_VALUE_DOUBLE (*arg));
+      gtk_frame_set_label_align (frame, frame->label_xalign, GTK_VALUE_FLOAT (*arg));
       break;
     case ARG_SHADOW:
       gtk_frame_set_shadow_type (frame, GTK_VALUE_ENUM (*arg));
       break;
     default:
-      arg->type = GTK_TYPE_INVALID;
       break;
     }
 }
 
 static void
-gtk_frame_get_arg (GtkFrame       *frame,
+gtk_frame_get_arg (GtkObject      *object,
                   GtkArg         *arg,
                   guint           arg_id)
 {
+  GtkFrame *frame;
+
+  frame = GTK_FRAME (object);
+
   switch (arg_id)
     {
     case ARG_LABEL:
       GTK_VALUE_STRING (*arg) = g_strdup (frame->label);
       break;
     case ARG_LABEL_XALIGN:
-      GTK_VALUE_DOUBLE (*arg) = frame->label_xalign;
+      GTK_VALUE_FLOAT (*arg) = frame->label_xalign;
       break;
     case ARG_LABEL_YALIGN:
-      GTK_VALUE_DOUBLE (*arg) = frame->label_yalign;
+      GTK_VALUE_FLOAT (*arg) = frame->label_yalign;
       break;
     case ARG_SHADOW:
       GTK_VALUE_ENUM (*arg) = frame->shadow_type;
@@ -174,6 +186,25 @@ gtk_frame_new (const gchar *label)
   return GTK_WIDGET (frame);
 }
 
+static void
+gtk_frame_style_set (GtkWidget      *widget,
+                    GtkStyle       *previous_style)
+{
+  GtkFrame *frame;
+
+  frame = GTK_FRAME (widget);
+
+  if (frame->label)
+    {
+      frame->label_width = gdk_string_measure (GTK_WIDGET (frame)->style->font, frame->label) + 7;
+      frame->label_height = (GTK_WIDGET (frame)->style->font->ascent +
+                            GTK_WIDGET (frame)->style->font->descent + 1);
+    }
+
+  if (GTK_WIDGET_CLASS (parent_class)->style_set)
+    GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+}
+
 void
 gtk_frame_set_label (GtkFrame *frame,
                     const gchar *label)
@@ -209,11 +240,11 @@ gtk_frame_set_label (GtkFrame *frame,
       /* clear the old label area
       */
       widget = GTK_WIDGET (frame);
-      gdk_window_clear_area (widget->window,
-                             widget->allocation.x + GTK_CONTAINER (frame)->border_width,
-                             widget->allocation.y + GTK_CONTAINER (frame)->border_width,
-                             widget->allocation.width - GTK_CONTAINER (frame)->border_width,
-                             widget->allocation.y + frame->label_height);
+      gtk_widget_queue_clear_area (widget,
+                                  widget->allocation.x + GTK_CONTAINER (frame)->border_width,
+                                  widget->allocation.y + GTK_CONTAINER (frame)->border_width,
+                                  widget->allocation.width - GTK_CONTAINER (frame)->border_width,
+                                  widget->allocation.y + frame->label_height);
 
     }
   
@@ -243,11 +274,11 @@ gtk_frame_set_label_align (GtkFrame *frame,
           /* clear the old label area
           */
           widget = GTK_WIDGET (frame);
-          gdk_window_clear_area (widget->window,
-                                 widget->allocation.x + GTK_CONTAINER (frame)->border_width,
-                                 widget->allocation.y + GTK_CONTAINER (frame)->border_width,
-                                 widget->allocation.width - GTK_CONTAINER (frame)->border_width,
-                                 widget->allocation.y + frame->label_height);
+          gtk_widget_queue_clear_area (widget,
+                                      widget->allocation.x + GTK_CONTAINER (frame)->border_width,
+                                      widget->allocation.y + GTK_CONTAINER (frame)->border_width,
+                                      widget->allocation.width - GTK_CONTAINER (frame)->border_width,
+                                      widget->allocation.y + frame->label_height);
 
        }
       gtk_widget_queue_resize (GTK_WIDGET (frame));
@@ -267,11 +298,7 @@ gtk_frame_set_shadow_type (GtkFrame      *frame,
 
       if (GTK_WIDGET_DRAWABLE (frame))
        {
-         gdk_window_clear_area (GTK_WIDGET (frame)->window,
-                                GTK_WIDGET (frame)->allocation.x,
-                                GTK_WIDGET (frame)->allocation.y,
-                                GTK_WIDGET (frame)->allocation.width,
-                                GTK_WIDGET (frame)->allocation.height);
+         gtk_widget_queue_clear (GTK_WIDGET (frame));
        }
       gtk_widget_queue_resize (GTK_WIDGET (frame));
     }
@@ -301,7 +328,7 @@ gtk_frame_paint (GtkWidget    *widget,
   GtkFrame *frame;
   gint height_extra;
   gint label_area_width;
-  gint x, y;
+  gint x, y, x2, y2;
 
   g_return_if_fail (widget != NULL);
   g_return_if_fail (GTK_IS_FRAME (widget));
@@ -317,33 +344,40 @@ gtk_frame_paint (GtkWidget    *widget,
       x = GTK_CONTAINER (frame)->border_width;
       y = GTK_CONTAINER (frame)->border_width;
 
-      gtk_draw_shadow (widget->style, widget->window,
-                      GTK_STATE_NORMAL, frame->shadow_type,
-                      widget->allocation.x + x,
-                      widget->allocation.y + y + height_extra / 2,
-                      widget->allocation.width - x * 2,
-                      widget->allocation.height - y * 2 - height_extra / 2);
-
       if (frame->label)
        {
-         label_area_width = (widget->allocation.width -
-                             GTK_CONTAINER (frame)->border_width * 2 -
-                             widget->style->klass->xthickness * 2);
-
-         x = ((label_area_width - frame->label_width) * frame->label_xalign +
-              GTK_CONTAINER (frame)->border_width + widget->style->klass->xthickness);
-         y = (GTK_CONTAINER (frame)->border_width + widget->style->font->ascent);
-
-         gdk_window_clear_area (widget->window,
-                                widget->allocation.x + x + 2,
-                                widget->allocation.y + GTK_CONTAINER (frame)->border_width,
-                                frame->label_width - 4,
-                                frame->label_height);
-         gtk_draw_string (widget->style, widget->window, GTK_WIDGET_STATE (widget),
-                          widget->allocation.x + x + 3,
-                          widget->allocation.y + y,
-                          frame->label);
+          label_area_width = (widget->allocation.width -
+                              GTK_CONTAINER (frame)->border_width * 2 -
+                              widget->style->klass->xthickness * 2);
+          
+          x2 = ((label_area_width - frame->label_width) * frame->label_xalign +
+               GTK_CONTAINER (frame)->border_width + widget->style->klass->xthickness);
+          y2 = (GTK_CONTAINER (frame)->border_width + widget->style->font->ascent);
+
+          gtk_paint_shadow_gap (widget->style, widget->window,
+                                GTK_STATE_NORMAL, frame->shadow_type,
+                                area, widget, "frame",
+                                widget->allocation.x + x,
+                                widget->allocation.y + y + height_extra / 2,
+                                widget->allocation.width - x * 2,
+                                widget->allocation.height - y * 2 - height_extra / 2,
+                                GTK_POS_TOP, 
+                                x2 + 2 - x, frame->label_width - 4);
+          
+          gtk_paint_string (widget->style, widget->window, GTK_WIDGET_STATE (widget),
+                            area, widget, "frame",
+                            widget->allocation.x + x2 + 3,
+                            widget->allocation.y + y2,
+                            frame->label);
        }
+       else
+        gtk_paint_shadow (widget->style, widget->window,
+                          GTK_STATE_NORMAL, frame->shadow_type,
+                          area, widget, "frame",
+                          widget->allocation.x + x,
+                          widget->allocation.y + y + height_extra / 2,
+                          widget->allocation.width - x * 2,
+                          widget->allocation.height - y * 2 - height_extra / 2);
     }
 }
 
@@ -455,11 +489,7 @@ gtk_frame_size_allocate (GtkWidget     *widget,
        (widget->allocation.height != allocation->height)) &&
       (widget->allocation.width != 0) &&
       (widget->allocation.height != 0))
-    gdk_window_clear_area (widget->window,
-                          widget->allocation.x,
-                          widget->allocation.y,
-                          widget->allocation.width,
-                          widget->allocation.height);
+     gtk_widget_queue_clear (widget);
 
   widget->allocation = *allocation;
 
@@ -471,7 +501,7 @@ gtk_frame_size_allocate (GtkWidget     *widget,
 
       child_allocation.y = (GTK_CONTAINER (frame)->border_width +
                            MAX (frame->label_height, GTK_WIDGET (frame)->style->klass->ythickness));
-      child_allocation.height = MAX (0, (allocation->height - child_allocation.y -
+      child_allocation.height = MAX (1, (allocation->height - child_allocation.y -
                                         GTK_CONTAINER (frame)->border_width -
                                         GTK_WIDGET (frame)->style->klass->ythickness));