]> Pileus Git - ~andy/gtk/blobdiff - tests/testsocket_common.c
Use gtk_box_new() instead gtk_[v|h]box_new()
[~andy/gtk] / tests / testsocket_common.c
index 6e96d35cd9ee14121d11ae72f1ab766367fcfbfd..7d147f32a6e5c9cb324c040b127c526d292564b2 100644 (file)
@@ -1,25 +1,63 @@
-#undef GTK_DISABLE_DEPRECATED
-
-#include "x11/gdkx.h"
+/* testsocket_common.c
+ * Copyright (C) 2001 Red Hat, Inc
+ * Author: Owen Taylor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
 #include <gtk/gtk.h>
+#if defined (GDK_WINDOWING_X11)
+#include "x11/gdkx.h"
+#elif defined (GDK_WINDOWING_WIN32)
+#include "win32/gdkwin32.h"
+#endif
+
+enum
+{
+  ACTION_FILE_NEW,
+  ACTION_FILE_OPEN,
+  ACTION_OK,
+  ACTION_HELP_ABOUT
+};
 
 static void
-print_hello (GtkWidget *w, gpointer data)
+print_hello (GtkWidget *w,
+            guint      action)
 {
-  g_message (data);
+  switch (action)
+    {
+    case ACTION_FILE_NEW:
+      g_message ("File New activated");
+      break;
+    case ACTION_FILE_OPEN:
+      g_message ("File Open activated");
+      break;
+    case ACTION_OK:
+      g_message ("OK activated");
+      break;
+    case ACTION_HELP_ABOUT:
+      g_message ("Help About activated ");
+      break;
+    default:
+      g_assert_not_reached ();
+      break;
+    }
 }
 
-static GtkItemFactoryEntry menu_items[] = {
-  { "/_File",         NULL,         NULL,           0, "<Branch>" },
-  { "/File/_New",     "<control>N", print_hello,    GPOINTER_TO_INT("File New activated"), "<Item>" },
-  { "/File/_Open",    "<control>O", print_hello,    GPOINTER_TO_INT("File Open activated"), "<Item>" },
-  { "/File/sep1",     NULL,         NULL,           0, "<Separator>" },
-  { "/File/Quit",     "<control>Q", gtk_main_quit,  0, "<Item>" },
-  { "/O_K",            "<control>K",print_hello,    GPOINTER_TO_INT("OK activated"), "<Item>" },
-  { "/_Help",         NULL,         NULL,           0, "<LastBranch>" },
-  { "/_Help/About",   NULL,         print_hello,    GPOINTER_TO_INT("Help About activated "), "<Item>" },
-};
-
 static void
 remove_buttons (GtkWidget *widget, GtkWidget *other_button)
 {
@@ -33,7 +71,7 @@ blink_cb (gpointer data)
   GtkWidget *widget = data;
 
   gtk_widget_show (widget);
-  g_object_set_data (G_OBJECT (widget), "blink", GPOINTER_TO_UINT (0));
+  g_object_set_data (G_OBJECT (widget), "blink", NULL);
 
   return FALSE;
 }
@@ -46,7 +84,7 @@ blink (GtkWidget *widget,
   
   if (!blink_timeout)
     {
-      blink_timeout = g_timeout_add (1000, blink_cb, window);
+      blink_timeout = gdk_threads_add_timeout (1000, blink_cb, window);
       gtk_widget_hide (window);
 
       g_object_set_data (G_OBJECT (window), "blink", GUINT_TO_POINTER (blink_timeout));
@@ -94,25 +132,25 @@ add_buttons (GtkWidget *widget, GtkWidget *box)
 static GtkWidget *
 create_combo (void)
 {
-  GList *cbitems;
-  GtkCombo *combo;
-
-  cbitems = NULL;
-  cbitems = g_list_append (cbitems, "item0");
-  cbitems = g_list_append (cbitems, "item1 item1");
-  cbitems = g_list_append (cbitems, "item2 item2 item2");
-  cbitems = g_list_append (cbitems, "item3 item3 item3 item3");
-  cbitems = g_list_append (cbitems, "item4 item4 item4 item4 item4");
-  cbitems = g_list_append (cbitems, "item5 item5 item5 item5 item5 item5");
-  cbitems = g_list_append (cbitems, "item6 item6 item6 item6 item6");
-  cbitems = g_list_append (cbitems, "item7 item7 item7 item7");
-  cbitems = g_list_append (cbitems, "item8 item8 item8");
-  cbitems = g_list_append (cbitems, "item9 item9");
-
-  combo = GTK_COMBO (gtk_combo_new ());
-  gtk_combo_set_popdown_strings (combo, cbitems);
-  gtk_entry_set_text (GTK_ENTRY (combo->entry), "hello world");
-  gtk_editable_select_region (GTK_EDITABLE (combo->entry), 0, -1);
+  GtkComboBoxText *combo;
+  GtkWidget *entry;
+
+  combo = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
+
+  gtk_combo_box_text_append_text (combo, "item0");
+  gtk_combo_box_text_append_text (combo, "item1 item1");
+  gtk_combo_box_text_append_text (combo, "item2 item2 item2");
+  gtk_combo_box_text_append_text (combo, "item3 item3 item3 item3");
+  gtk_combo_box_text_append_text (combo, "item4 item4 item4 item4 item4");
+  gtk_combo_box_text_append_text (combo, "item5 item5 item5 item5 item5 item5");
+  gtk_combo_box_text_append_text (combo, "item6 item6 item6 item6 item6");
+  gtk_combo_box_text_append_text (combo, "item7 item7 item7 item7");
+  gtk_combo_box_text_append_text (combo, "item8 item8 item8");
+  gtk_combo_box_text_append_text (combo, "item9 item9");
+
+  entry = gtk_bin_get_child (GTK_BIN (combo));
+  gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
+  gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
 
   return GTK_WIDGET (combo);
 }
@@ -120,19 +158,39 @@ create_combo (void)
 static GtkWidget *
 create_menubar (GtkWindow *window)
 {
-  GtkItemFactory *item_factory;
   GtkAccelGroup *accel_group=NULL;
   GtkWidget *menubar;
-  
+  GtkWidget *menuitem;
+  GtkWidget *menu;
+
   accel_group = gtk_accel_group_new ();
-  item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
-                                       accel_group);
-  gtk_item_factory_create_items (item_factory,
-                                G_N_ELEMENTS (menu_items),
-                                menu_items, NULL);
-  
   gtk_window_add_accel_group (window, accel_group);
-  menubar = gtk_item_factory_get_widget (item_factory, "<main>");
+
+  menubar = gtk_menu_bar_new ();
+
+  menuitem = gtk_menu_item_new_with_mnemonic ("_File");
+  gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
+  menu = gtk_menu_new ();
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
+  menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL);
+  g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+  menuitem = gtk_separator_menu_item_new ();
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+  menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, NULL);
+  g_signal_connect (menuitem, "activate", G_CALLBACK (gtk_main_quit), window);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+
+  menuitem = gtk_menu_item_new_with_mnemonic ("O_K");
+  gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
+
+  menuitem = gtk_menu_item_new_with_mnemonic ("_Help");
+  gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
+  menu = gtk_menu_new ();
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
+  menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
+  g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
 
   return menubar;
 }
@@ -140,12 +198,12 @@ create_menubar (GtkWindow *window)
 static GtkWidget *
 create_combo_box (void)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (gtk_combo_box_new_text ());
+  GtkComboBoxText *combo_box = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new ());
 
-  gtk_combo_box_append_text (combo_box, "This");
-  gtk_combo_box_append_text (combo_box, "Is");
-  gtk_combo_box_append_text (combo_box, "A");
-  gtk_combo_box_append_text (combo_box, "ComboBox");
+  gtk_combo_box_text_append_text (combo_box, "This");
+  gtk_combo_box_text_append_text (combo_box, "Is");
+  gtk_combo_box_text_append_text (combo_box, "A");
+  gtk_combo_box_text_append_text (combo_box, "ComboBox");
   
   return GTK_WIDGET (combo_box);
 }
@@ -159,7 +217,7 @@ create_content (GtkWindow *window, gboolean local)
 
   frame = gtk_frame_new (local? "Local" : "Remote");
   gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
-  vbox = gtk_vbox_new (TRUE, 0);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, TRUE, 0);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
 
   gtk_container_add (GTK_CONTAINER (frame), vbox);
@@ -216,8 +274,12 @@ create_child_plug (guint32  xid,
 
   gtk_widget_show_all (window);
 
-  if (GTK_WIDGET_REALIZED (window))
-    return GDK_WINDOW_XID (window->window);
+  if (gtk_widget_get_realized (window))
+#if defined (GDK_WINDOWING_X11)
+    return GDK_WINDOW_XID (gtk_widget_get_window (window));
+#elif defined (GDK_WINDOWING_WIN32)
+    return (guint32) GDK_WINDOW_HWND (gtk_widget_get_window (window));
+#endif
   else
     return 0;
 }