]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktearoffmenuitem.c
Make the widgets work reasonably when they don't have children -- draw the
[~andy/gtk] / gtk / gtktearoffmenuitem.c
index ac775cd6cb3a43b8624525e4b945c9d9beb3aafd..c087ad0e5abea6352d1617d106c855b7d0e5ffe5 100644 (file)
@@ -2,30 +2,29 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * 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.
  */
 
 /*
- * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
 #include "gtkmenu.h"
-#include "gtksignal.h"
 #include "gtktearoffmenuitem.h"
 
 #define ARROW_SIZE 10
@@ -36,34 +35,35 @@ static void gtk_tearoff_menu_item_class_init (GtkTearoffMenuItemClass *klass);
 static void gtk_tearoff_menu_item_init       (GtkTearoffMenuItem      *tearoff_menu_item);
 static void gtk_tearoff_menu_item_size_request (GtkWidget             *widget,
                                                GtkRequisition        *requisition);
-static void gtk_tearoff_menu_item_draw       (GtkWidget             *widget,
-                                             GdkRectangle          *area);
 static gint gtk_tearoff_menu_item_expose     (GtkWidget             *widget,
                                              GdkEventExpose        *event);
 static void gtk_tearoff_menu_item_activate   (GtkMenuItem           *menu_item);
 static gint gtk_tearoff_menu_item_delete_cb  (GtkMenuItem           *menu_item,
                                              GdkEventAny           *event);
 
-GtkType
+GType
 gtk_tearoff_menu_item_get_type (void)
 {
-  static GtkType tearoff_menu_item_type = 0;
+  static GType tearoff_menu_item_type = 0;
 
   if (!tearoff_menu_item_type)
     {
-      static const GtkTypeInfo tearoff_menu_item_info =
+      static const GTypeInfo tearoff_menu_item_info =
       {
-        "GtkTearoffMenuItem",
-        sizeof (GtkTearoffMenuItem),
         sizeof (GtkTearoffMenuItemClass),
-        (GtkClassInitFunc) gtk_tearoff_menu_item_class_init,
-        (GtkObjectInitFunc) gtk_tearoff_menu_item_init,
-        /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_tearoff_menu_item_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkTearoffMenuItem),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) gtk_tearoff_menu_item_init,
       };
 
-      tearoff_menu_item_type = gtk_type_unique (gtk_menu_item_get_type (), &tearoff_menu_item_info);
+      tearoff_menu_item_type =
+       g_type_register_static (GTK_TYPE_MENU_ITEM, "GtkTearoffMenuItem",
+                               &tearoff_menu_item_info, 0);
     }
 
   return tearoff_menu_item_type;
@@ -72,7 +72,7 @@ gtk_tearoff_menu_item_get_type (void)
 GtkWidget*
 gtk_tearoff_menu_item_new (void)
 {
-  return GTK_WIDGET (gtk_type_new (gtk_tearoff_menu_item_get_type ()));
+  return g_object_new (GTK_TYPE_TEAROFF_MENU_ITEM, NULL);
 }
 
 static void
@@ -86,7 +86,6 @@ gtk_tearoff_menu_item_class_init (GtkTearoffMenuItemClass *klass)
   widget_class = (GtkWidgetClass*) klass;
   menu_item_class = (GtkMenuItemClass*) klass;
 
-  widget_class->draw = gtk_tearoff_menu_item_draw;
   widget_class->expose_event = gtk_tearoff_menu_item_expose;
   widget_class->size_request = gtk_tearoff_menu_item_size_request;
 
@@ -108,10 +107,10 @@ gtk_tearoff_menu_item_size_request (GtkWidget      *widget,
   tearoff = GTK_TEAROFF_MENU_ITEM (widget);
   
   requisition->width = (GTK_CONTAINER (widget)->border_width +
-                       widget->style->klass->xthickness +
+                       widget->style->xthickness +
                        BORDER_SPACING) * 2;
   requisition->height = (GTK_CONTAINER (widget)->border_width +
-                        widget->style->klass->ythickness) * 2;
+                        widget->style->ythickness) * 2;
 
   if (tearoff->torn_off)
     {
@@ -119,7 +118,7 @@ gtk_tearoff_menu_item_size_request (GtkWidget      *widget,
     }
   else
     {
-      requisition->height += widget->style->klass->ythickness;
+      requisition->height += widget->style->ythickness;
     }
 }
 
@@ -134,29 +133,33 @@ gtk_tearoff_menu_item_paint (GtkWidget   *widget,
   gint x, y;
   gint right_max;
 
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TEAROFF_MENU_ITEM (widget));
-
   if (GTK_WIDGET_DRAWABLE (widget))
     {
       menu_item = GTK_MENU_ITEM (widget);
       tearoff_item = GTK_TEAROFF_MENU_ITEM (widget);
 
-      x = GTK_CONTAINER (menu_item)->border_width;
-      y = GTK_CONTAINER (menu_item)->border_width;
+      x = widget->allocation.x + GTK_CONTAINER (menu_item)->border_width;
+      y = widget->allocation.y + GTK_CONTAINER (menu_item)->border_width;
       width = widget->allocation.width - x * 2;
       height = widget->allocation.height - y * 2;
       right_max = x + width;
 
       if (widget->state == GTK_STATE_PRELIGHT)
-       gtk_paint_box (widget->style,
-                      widget->window,
-                      GTK_STATE_PRELIGHT,
-                      GTK_SHADOW_OUT,
-                      area, widget, "menuitem",
-                      x, y, width, height);
-       else
-        gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
+       {
+         gint selected_shadow_type;
+         
+         gtk_widget_style_get (widget,
+                               "selected_shadow_type", &selected_shadow_type,
+                               NULL);
+         gtk_paint_box (widget->style,
+                        widget->window,
+                        GTK_STATE_PRELIGHT,
+                        selected_shadow_type,
+                        area, widget, "menuitem",
+                        x, y, width, height);
+       }
+      else
+       gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
 
       if (tearoff_item->torn_off)
        {
@@ -178,41 +181,29 @@ gtk_tearoff_menu_item_paint (GtkWidget   *widget,
              x += 2 * ARROW_SIZE;
            }
          
-         gtk_draw_arrow (widget->style, widget->window,
-                         widget->state, shadow_type, GTK_ARROW_LEFT, FALSE,
-                         arrow_x, y + height / 2 - 5, 
-                         ARROW_SIZE, ARROW_SIZE);
+         gtk_paint_arrow (widget->style, widget->window,
+                          widget->state, shadow_type,
+                          NULL, widget, "tearoffmenuitem",
+                          GTK_ARROW_LEFT, FALSE,
+                          arrow_x, y + height / 2 - 5, 
+                          ARROW_SIZE, ARROW_SIZE);
        }
 
       while (x < right_max)
        {
-         gtk_draw_hline (widget->style, widget->window, GTK_STATE_NORMAL,
-                         x, MIN (x+TEAR_LENGTH, right_max),
-                         y + (height - widget->style->klass->ythickness)/2);
+         gtk_paint_hline (widget->style, widget->window, GTK_STATE_NORMAL,
+                          NULL, widget, "tearoffmenuitem",
+                          x, MIN (x + TEAR_LENGTH, right_max),
+                          y + (height - widget->style->ythickness) / 2);
          x += 2 * TEAR_LENGTH;
        }
     }
 }
 
-static void
-gtk_tearoff_menu_item_draw (GtkWidget    *widget,
-                         GdkRectangle *area)
-{
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TEAROFF_MENU_ITEM (widget));
-  g_return_if_fail (area != NULL);
-
-  gtk_tearoff_menu_item_paint (widget, area);
-}
-
 static gint
 gtk_tearoff_menu_item_expose (GtkWidget      *widget,
                            GdkEventExpose *event)
 {
-  g_return_val_if_fail (widget != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_TEAROFF_MENU_ITEM (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
-
   gtk_tearoff_menu_item_paint (widget, &event->area);
 
   return FALSE;
@@ -228,13 +219,10 @@ gtk_tearoff_menu_item_delete_cb (GtkMenuItem *menu_item, GdkEventAny *event)
 static void
 gtk_tearoff_menu_item_activate (GtkMenuItem *menu_item)
 {
-  GtkTearoffMenuItem *tearoff_menu_item;
-
-  g_return_if_fail (menu_item != NULL);
-  g_return_if_fail (GTK_IS_TEAROFF_MENU_ITEM (menu_item));
+  GtkTearoffMenuItem *tearoff_menu_item = GTK_TEAROFF_MENU_ITEM (menu_item);
 
-  tearoff_menu_item = GTK_TEAROFF_MENU_ITEM (menu_item);
   tearoff_menu_item->torn_off = !tearoff_menu_item->torn_off;
+  gtk_widget_queue_resize (GTK_WIDGET (menu_item));
 
   if (GTK_IS_MENU (GTK_WIDGET (menu_item)->parent))
     {
@@ -247,12 +235,10 @@ gtk_tearoff_menu_item_activate (GtkMenuItem *menu_item)
                                    tearoff_menu_item->torn_off);
 
        if (need_connect)
-         gtk_signal_connect_object (GTK_OBJECT (menu->tearoff_window),  
-                                    "delete_event",
-                                    GTK_SIGNAL_FUNC (gtk_tearoff_menu_item_delete_cb),
-                                    GTK_OBJECT (menu_item));
+         g_signal_connect_swapped (menu->tearoff_window,
+                                   "delete_event",
+                                   G_CALLBACK (gtk_tearoff_menu_item_delete_cb),
+                                   menu_item);
     }
-  
-  gtk_widget_queue_resize (GTK_WIDGET (menu_item));
 }