]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkstyle.c
removed the "widget &&" part from "widget && GTK_IS_FOO (widget)" checks.
[~andy/gtk] / gtk / gtkstyle.c
index 14a74050e886b46965be4cffda5d28dcfe2525a8..58f4d0ef9aefba05d35ed9c5e1c31ba1fa01930e 100644 (file)
@@ -59,8 +59,6 @@ struct _GtkStylePrivate {
 };
 
 /* --- prototypes --- */
-static void     gtk_style_init                 (GtkStyle       *style);
-static void     gtk_style_class_init           (GtkStyleClass  *klass);
 static void     gtk_style_finalize             (GObject        *object);
 static void     gtk_style_realize              (GtkStyle       *style,
                                                 GdkColormap    *colormap);
@@ -355,39 +353,13 @@ static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
 static const GdkColor gtk_default_selected_base =  { 0, GTK_BLUE };
 static const GdkColor gtk_default_active_base =    { 0, GTK_VERY_DARK_GRAY };
 
-static gpointer parent_class = NULL;
-
 /* --- signals --- */
 static guint realize_signal = 0;
 static guint unrealize_signal = 0;
 
+G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
+
 /* --- functions --- */
-GType
-gtk_style_get_type (void)
-{
-  static GType style_type = 0;
-  
-  if (!style_type)
-    {
-      static const GTypeInfo style_info =
-      {
-        sizeof (GtkStyleClass),
-        (GBaseInitFunc) NULL,
-        (GBaseFinalizeFunc) NULL,
-        (GClassInitFunc) gtk_style_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (GtkStyle),
-        0,              /* n_preallocs */
-        (GInstanceInitFunc) gtk_style_init,
-      };
-      
-      style_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkStyle"),
-                                          &style_info, 0);
-    }
-  
-  return style_type;
-}
 
 /**
  * _gtk_style_init_for_settings:
@@ -505,8 +477,6 @@ gtk_style_class_init (GtkStyleClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   
-  parent_class = g_type_class_peek_parent (klass);
-
   object_class->finalize = gtk_style_finalize;
 
   klass->clone = gtk_style_real_clone;
@@ -649,7 +619,7 @@ gtk_style_finalize (GObject *object)
   if (style->rc_style)
     gtk_rc_style_unref (style->rc_style);
   
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
 }
 
 
@@ -863,9 +833,6 @@ static void
 gtk_style_realize (GtkStyle    *style,
                    GdkColormap *colormap)
 {
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GDK_IS_COLORMAP (colormap));
-  
   style->colormap = g_object_ref (colormap);
   style->depth = gdk_colormap_get_visual (colormap)->depth;
 
@@ -1647,10 +1614,10 @@ gtk_style_real_copy (GtkStyle *style,
   style->ythickness = src->ythickness;
 
   if (style->rc_style)
-    gtk_rc_style_unref (style->rc_style);
+    g_object_unref (style->rc_style);
   style->rc_style = src->rc_style;
   if (src->rc_style)
-    gtk_rc_style_ref (src->rc_style);
+    g_object_ref (src->rc_style);
 
   /* don't copy, just clear cache */
   clear_property_cache (style);
@@ -1772,7 +1739,7 @@ _gtk_style_peek_property_value (GtkStyle           *style,
       gchar *contents = g_strdup_value_contents (&rcprop->value);
       
       g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
-                rcprop->origin,
+                rcprop->origin ? rcprop->origin : "(for origin information, set GTK_DEBUG)",
                 g_type_name (pspec->owner_type), pspec->name,
                 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
                 contents,
@@ -2210,9 +2177,6 @@ gtk_default_draw_hline (GtkStyle     *style,
   gint thickness_dark;
   gint i;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   thickness_light = style->ythickness / 2;
   thickness_dark = style->ythickness - thickness_light;
   
@@ -2267,9 +2231,6 @@ gtk_default_draw_vline (GtkStyle     *style,
   gint thickness_dark;
   gint i;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   thickness_light = style->xthickness / 2;
   thickness_dark = style->xthickness - thickness_light;
   
@@ -2495,12 +2456,9 @@ gtk_default_draw_shadow (GtkStyle      *style,
   gint thickness_dark;
   gint i;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-
   if (shadow_type == GTK_SHADOW_IN)
     {
-      if (detail && (strcmp (detail, "buttondefault") == 0))
+      if (detail && strcmp (detail, "buttondefault") == 0)
        {
          sanitize_size (window, &width, &height);
 
@@ -2515,7 +2473,7 @@ gtk_default_draw_shadow (GtkStyle      *style,
                            x, y, width, height);
          return;
        }
-      if (widget && GTK_IS_SPIN_BUTTON (widget) &&
+      if (GTK_IS_SPIN_BUTTON (widget) &&
          detail && strcmp (detail, "spinbutton") == 0)
        {
          draw_spinbutton_shadow (style, window, state_type, 
@@ -2753,7 +2711,7 @@ gtk_default_draw_shadow (GtkStyle      *style,
     }
 
   if (shadow_type == GTK_SHADOW_IN &&
-      widget && GTK_IS_SPIN_BUTTON (widget) &&
+      GTK_IS_SPIN_BUTTON (widget) &&
       detail && strcmp (detail, "entry") == 0)
     {
       if (get_direction (widget) == GTK_TEXT_DIR_LTR)
@@ -2833,10 +2791,6 @@ gtk_default_draw_polygon (GtkStyle      *style,
   gint yadjust;
   gint i;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  g_return_if_fail (points != NULL);
-  
   switch (shadow_type)
     {
     case GTK_SHADOW_IN:
@@ -3120,9 +3074,6 @@ gtk_default_draw_diamond (GtkStyle      *style,
   GdkGC *inner_sw = NULL;
   GdkGC *inner_se = NULL;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   sanitize_size (window, &width, &height);
   
   half_width = width / 2;
@@ -3240,9 +3191,6 @@ gtk_default_draw_string (GtkStyle      *style,
                          gint           y,
                          const gchar   *string)
 {
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   if (area)
     {
       gdk_gc_set_clip_rectangle (style->white_gc, area);
@@ -3311,12 +3259,9 @@ gtk_default_draw_box (GtkStyle      *style,
 {
   gboolean is_spinbutton_box = FALSE;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   sanitize_size (window, &width, &height);
 
-  if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
+  if (GTK_IS_SPIN_BUTTON (widget) && detail)
     {
       if (strcmp (detail, "spinbutton_up") == 0)
        {
@@ -3462,9 +3407,6 @@ gtk_default_draw_flat_box (GtkStyle      *style,
   GdkGC *gc1;
   GdkGC *freeme = NULL;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   sanitize_size (window, &width, &height);
   
   if (detail)
@@ -3473,15 +3415,26 @@ gtk_default_draw_flat_box (GtkStyle      *style,
         {
           if (!strcmp ("text", detail))
             gc1 = style->bg_gc[GTK_STATE_SELECTED];
-          else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
-                  !strncmp ("cell_odd", detail, strlen ("cell_odd")))
+          else if (!strcmp ("cell_even", detail) ||
+                   !strcmp ("cell_odd", detail) ||
+                   !strcmp ("cell_even_ruled", detail) ||
+                  !strcmp ("cell_even_ruled_sorted", detail))
             {
              /* This has to be really broken; alex made me do it. -jrb */
              if (GTK_WIDGET_HAS_FOCUS (widget))
                gc1 = style->base_gc[state_type];
-             else 
-               gc1 = style->base_gc[GTK_STATE_ACTIVE];
+             else
+               gc1 = style->base_gc[GTK_STATE_ACTIVE];
             }
+         else if (!strcmp ("cell_odd_ruled", detail) ||
+                  !strcmp ("cell_odd_ruled_sorted", detail))
+           {
+             if (GTK_WIDGET_HAS_FOCUS (widget))
+               freeme = get_darkened_gc (window, &style->base[state_type], 1);
+             else
+               freeme = get_darkened_gc (window, &style->base[GTK_STATE_ACTIVE], 1);
+             gc1 = freeme;
+           }
           else
             {
               gc1 = style->bg_gc[state_type];
@@ -3956,9 +3909,6 @@ gtk_default_draw_shadow_gap (GtkStyle       *style,
   GdkGC *gc3 = NULL;
   GdkGC *gc4 = NULL;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   sanitize_size (window, &width, &height);
   
   switch (shadow_type)
@@ -4172,9 +4122,6 @@ gtk_default_draw_box_gap (GtkStyle       *style,
   GdkGC *gc3 = NULL;
   GdkGC *gc4 = NULL;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   gtk_style_apply_default_background (style, window,
                                       widget && !GTK_WIDGET_NO_WINDOW (widget),
                                       state_type, area, x, y, width, height);
@@ -4317,7 +4264,7 @@ gtk_default_draw_box_gap (GtkStyle       *style,
               gdk_draw_line (window, gc2,
                              x, y + gap_x, x, y + gap_x);
             }
-          if ((width - (gap_x + gap_width)) > 0)
+          if ((height - (gap_x + gap_width)) > 0)
             {
               gdk_draw_line (window, gc1,
                              x, y + gap_x + gap_width, x, y + height - 2);
@@ -4350,7 +4297,7 @@ gtk_default_draw_box_gap (GtkStyle       *style,
               gdk_draw_line (window, gc3,
                              x + width - 1, y + gap_x, x + width - 1, y + gap_x);
             }
-          if ((width - (gap_x + gap_width)) > 0)
+          if ((height - (gap_x + gap_width)) > 0)
             {
               gdk_draw_line (window, gc4,
                              x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
@@ -4391,9 +4338,6 @@ gtk_default_draw_extension (GtkStyle       *style,
   GdkGC *gc3 = NULL;
   GdkGC *gc4 = NULL;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   gtk_style_apply_default_background (style, window,
                                       widget && !GTK_WIDGET_NO_WINDOW (widget),
                                       GTK_STATE_NORMAL, area, x, y, width, height);
@@ -4655,9 +4599,6 @@ gtk_default_draw_slider (GtkStyle      *style,
                          gint           height,
                          GtkOrientation orientation)
 {
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   sanitize_size (window, &width, &height);
   
   gtk_paint_box (style, window, state_type, shadow_type,
@@ -4686,7 +4627,6 @@ draw_dot (GdkWindow    *window,
          gint          y,
          gushort       size)
 {
-  
   size = CLAMP (size, 2, 3);
 
   if (size == 2)
@@ -4727,9 +4667,6 @@ gtk_default_draw_handle (GtkStyle      *style,
   GdkRectangle dest;
   gint intersect;
   
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   sanitize_size (window, &width, &height);
   
   gtk_paint_box (style, window, state_type, shadow_type, area, widget, 
@@ -5109,9 +5046,6 @@ gtk_default_draw_layout (GtkStyle        *style,
                          PangoLayout     *layout)
 {
   GdkGC *gc;
-  
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
 
   gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
   
@@ -5153,9 +5087,6 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
   GdkPoint points[4];
   gint i, j, skip;
 
-  g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (window != NULL);
-  
   if (area)
     {
       gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
@@ -6251,6 +6182,25 @@ gtk_paint_focus (GtkStyle      *style,
   GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_slider:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: a shadow
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: the x origin of the rectangle in which to draw a slider
+ * @y: the y origin of the rectangle in which to draw a slider
+ * @width: the width of the rectangle in which to draw a slider
+ * @height: the height of the rectangle in which to draw a slider
+ * @orientation: the orientation to be used
+ *
+ * Draws a slider in the given rectangle on @window using the
+ * given style and orientation.
+ **/
 void
 gtk_paint_slider (GtkStyle      *style,
                   GdkWindow     *window,
@@ -6355,11 +6305,28 @@ gtk_paint_expander (GtkStyle        *style,
                                               widget, detail, x, y, expander_style);
 }
 
+/**
+ * gtk_paint_layout:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @use_text: whether to use the text or foreground
+ *            graphics context of @style
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin
+ * @y: y origin
+ * @layout: the layout to draw
+ * 
+ * Draws a layout on @window using the given parameters.
+ **/
 void
 gtk_paint_layout (GtkStyle        *style,
                   GdkWindow       *window,
                   GtkStateType     state_type,
-                 gboolean         use_text,
+                  gboolean         use_text,
                   GdkRectangle    *area,
                   GtkWidget       *widget,
                   const gchar     *detail,
@@ -6688,8 +6655,6 @@ draw_insertion_cursor (GtkWidget        *widget,
   gfloat cursor_aspect_ratio;
   gint offset;
   
-  g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
-
   /* When changing the shape or size of the cursor here,
    * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
    */