]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkoptionmenu.c
Deprecate flag macros for toplevel, state, no window and composite child
[~andy/gtk] / gtk / gtkoptionmenu.c
index b7ee5bcbb993fd51feea6631085f3e15c7433d4d..74d05547fd3db41ad99cdb01b7709f6f7027b9e2 100644 (file)
@@ -1,5 +1,5 @@
 /* GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Jsh MacDonald
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include "gtkintl.h"
+#include "config.h"
+
+#include "gdk/gdkkeysyms.h"
+
+#undef GTK_DISABLE_DEPRECATED
+
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
-#include "gtkoptionmenu.h"
 #include "gtkmarshalers.h"
-#include "gdk/gdkkeysyms.h"
-
+#include "gtkoptionmenu.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 #define CHILD_LEFT_SPACING        4
 #define CHILD_RIGHT_SPACING       1
@@ -56,8 +62,6 @@ static const GtkOptionMenuProps default_props = {
   0
 };
 
-static void gtk_option_menu_class_init      (GtkOptionMenuClass *klass);
-static void gtk_option_menu_init            (GtkOptionMenu      *option_menu);
 static void gtk_option_menu_destroy         (GtkObject          *object);
 static void gtk_option_menu_set_property    (GObject            *object,
                                             guint               prop_id,
@@ -106,41 +110,12 @@ enum
 enum
 {
   PROP_0,
-  PROP_MENU,
-  LAST_PROP
+  PROP_MENU
 };
 
-static GtkButtonClass *parent_class = NULL;
-static guint           signals[LAST_SIGNAL] = { 0 };
+static guint signals[LAST_SIGNAL] = { 0 };
 
-
-GType
-gtk_option_menu_get_type (void)
-{
-  static GType option_menu_type = 0;
-
-  if (!option_menu_type)
-    {
-      static const GTypeInfo option_menu_info =
-      {
-       sizeof (GtkOptionMenuClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_option_menu_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkOptionMenu),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_option_menu_init,
-      };
-
-      option_menu_type =
-       g_type_register_static (GTK_TYPE_BUTTON, "GtkOptionMenu",
-                               &option_menu_info, 0);
-    }
-
-  return option_menu_type;
-}
+G_DEFINE_TYPE (GtkOptionMenu, gtk_option_menu, GTK_TYPE_BUTTON)
 
 static void
 gtk_option_menu_class_init (GtkOptionMenuClass *class)
@@ -148,19 +123,15 @@ gtk_option_menu_class_init (GtkOptionMenuClass *class)
   GObjectClass *gobject_class;
   GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
-  GtkButtonClass *button_class;
   GtkContainerClass *container_class;
 
   gobject_class = (GObjectClass*) class;
   object_class = (GtkObjectClass*) class;
   widget_class = (GtkWidgetClass*) class;
-  button_class = (GtkButtonClass*) class;
   container_class = (GtkContainerClass*) class;
 
-  parent_class = g_type_class_peek_parent (class);
-
   signals[CHANGED] =
-    g_signal_new ("changed",
+    g_signal_new (I_("changed"),
                   G_OBJECT_CLASS_TYPE (class),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkOptionMenuClass, changed),
@@ -187,23 +158,23 @@ gtk_option_menu_class_init (GtkOptionMenuClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_MENU,
                                    g_param_spec_object ("menu",
-                                                        _("Menu"),
-                                                        _("The menu of options"),
+                                                        P_("Menu"),
+                                                        P_("The menu of options"),
                                                         GTK_TYPE_MENU,
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
   
   gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boxed ("indicator_size",
-                                                              _("Indicator Size"),
-                                                              _("Size of dropdown indicator"),
+                                          g_param_spec_boxed ("indicator-size",
+                                                              P_("Indicator Size"),
+                                                              P_("Size of dropdown indicator"),
                                                               GTK_TYPE_REQUISITION,
-                                                              G_PARAM_READABLE));
+                                                              GTK_PARAM_READABLE));
   gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boxed ("indicator_spacing",
-                                                              _("Indicator Spacing"),
-                                                              _("Spacing around indicator"),
+                                          g_param_spec_boxed ("indicator-spacing",
+                                                              P_("Indicator Spacing"),
+                                                              P_("Spacing around indicator"),
                                                               GTK_TYPE_BORDER,
-                                                              G_PARAM_READABLE));
+                                                              GTK_PARAM_READABLE));
 }
 
 static GType
@@ -279,10 +250,10 @@ gtk_option_menu_set_menu (GtkOptionMenu *option_menu,
 
       gtk_option_menu_calc_size (option_menu);
 
-      g_signal_connect_after (option_menu->menu, "selection_done",
+      g_signal_connect_after (option_menu->menu, "selection-done",
                              G_CALLBACK (gtk_option_menu_selection_done),
                              option_menu);
-      g_signal_connect_swapped (option_menu->menu, "size_request",
+      g_signal_connect_swapped (option_menu->menu, "size-request",
                                G_CALLBACK (gtk_option_menu_calc_size),
                                option_menu);
 
@@ -303,7 +274,7 @@ gtk_option_menu_remove_menu (GtkOptionMenu *option_menu)
   if (option_menu->menu)
     {
       if (GTK_MENU_SHELL (option_menu->menu)->active)
-       g_signal_emit_by_name (option_menu->menu, "cancel", 0);
+       gtk_menu_shell_cancel (GTK_MENU_SHELL (option_menu->menu));
       
       gtk_menu_detach (GTK_MENU (option_menu->menu));
     }
@@ -335,6 +306,7 @@ gtk_option_menu_set_history (GtkOptionMenu *option_menu,
  * items are numbered from top to bottom, starting with 0. 
  * 
  * Return value: index of the selected menu item, or -1 if there are no menu items
+ * Deprecated: 2.4: Use #GtkComboBox instead.
  **/
 gint
 gtk_option_menu_get_history (GtkOptionMenu *option_menu)
@@ -400,17 +372,12 @@ gtk_option_menu_get_property (GObject            *object,
 static void
 gtk_option_menu_destroy (GtkObject *object)
 {
-  GtkOptionMenu *option_menu;
-
-  g_return_if_fail (GTK_IS_OPTION_MENU (object));
-
-  option_menu = GTK_OPTION_MENU (object);
+  GtkOptionMenu *option_menu = GTK_OPTION_MENU (object);
 
   if (option_menu->menu)
     gtk_widget_destroy (option_menu->menu);
 
-  if (GTK_OBJECT_CLASS (parent_class)->destroy)
-    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+  GTK_OBJECT_CLASS (gtk_option_menu_parent_class)->destroy (object);
 }
 
 static void
@@ -421,11 +388,11 @@ gtk_option_menu_get_props (GtkOptionMenu       *option_menu,
   GtkBorder *indicator_spacing;
   
   gtk_widget_style_get (GTK_WIDGET (option_menu),
-                       "indicator_size", &indicator_size,
-                       "indicator_spacing", &indicator_spacing,
-                       "interior_focus", &props->interior_focus,
-                       "focus_line_width", &props->focus_width,
-                       "focus_padding", &props->focus_pad,
+                       "indicator-size", &indicator_size,
+                       "indicator-spacing", &indicator_spacing,
+                       "interior-focus", &props->interior_focus,
+                       "focus-line-width", &props->focus_width,
+                       "focus-padding", &props->focus_pad,
                        NULL);
 
   if (indicator_size)
@@ -438,8 +405,8 @@ gtk_option_menu_get_props (GtkOptionMenu       *option_menu,
   else
     props->indicator_spacing = default_props.indicator_spacing;
 
-  g_free (indicator_size);
-  g_free (indicator_spacing);
+  gtk_requisition_free (indicator_size);
+  gtk_border_free (indicator_spacing);
 }
 
 static void
@@ -641,7 +608,7 @@ gtk_option_menu_expose (GtkWidget      *widget,
 
       child_event = *event;
 
-      if (GTK_WIDGET_NO_WINDOW (child) &&
+      if (!gtk_widget_get_has_window (child) &&
          gtk_widget_intersect (child, &event->area, &child_event.area))
        gtk_widget_event (child, (GdkEvent*) &child_event);
 
@@ -809,7 +776,7 @@ gtk_option_menu_update_contents (GtkOptionMenu *option_menu)
              gtk_widget_reparent (child, GTK_WIDGET (option_menu));
            }
 
-         g_signal_connect (option_menu->menu_item, "state_changed",
+         g_signal_connect (option_menu->menu_item, "state-changed",
                            G_CALLBACK (gtk_option_menu_item_state_changed_cb), option_menu);
          g_signal_connect (option_menu->menu_item, "destroy",
                            G_CALLBACK (gtk_option_menu_item_destroy_cb), option_menu);
@@ -841,6 +808,7 @@ gtk_option_menu_remove_contents (GtkOptionMenu *option_menu)
       if (child)
        {
          gtk_widget_set_sensitive (child, TRUE);
+         gtk_widget_set_state (child, GTK_STATE_NORMAL);
          gtk_widget_reparent (child, option_menu->menu_item);
        }
 
@@ -926,6 +894,10 @@ gtk_option_menu_position (GtkMenu  *menu,
   active = gtk_menu_get_active (GTK_MENU (option_menu->menu));
   gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
 
+  /* set combo box type hint for menu popup */
+  gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (option_menu->menu)->toplevel),
+                           GDK_WINDOW_TYPE_HINT_COMBO);
+
   menu_xpos += widget->allocation.x;
   menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
 
@@ -952,6 +924,10 @@ gtk_option_menu_position (GtkMenu  *menu,
       children = children->next;
     }
 
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+    menu_xpos = menu_xpos + widget->allocation.width - menu_width;
+
+  /* Clamp the position on screen */
   screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
   
   if (menu_xpos < 0)
@@ -1051,3 +1027,6 @@ gtk_option_menu_scroll_event (GtkWidget          *widget,
   return TRUE;
 }
 
+#define __GTK_OPTION_MENU_C__
+#include "gtkaliasdef.c"
+