]> Pileus Git - ~andy/gtk/blobdiff - tests/testwindows.c
Fixed POTFILES.in (error in D-L)
[~andy/gtk] / tests / testwindows.c
index 8382d5b8d23e2d46ec643439d990efd5f43d1dd0..82aa57ed1bccc8d6b5ea2a397dea65364c9d91be 100644 (file)
@@ -1,5 +1,7 @@
 #include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
 #include <X11/Xlib.h>
+#endif
 
 static GtkWidget *darea;
 static GtkTreeStore *window_store = NULL;
@@ -7,13 +9,8 @@ static GtkWidget *treeview;
 
 static void update_store (void);
 
-static gboolean
-window_has_impl (GdkWindow *window)
-{
-  GdkWindowObject *w;
-  w = (GdkWindowObject *)window;
-  return w->parent == NULL || w->parent->impl != w->impl;
-}
+static GtkWidget *main_window;
+
 
 GdkWindow *
 create_window (GdkWindow *parent,
@@ -54,7 +51,6 @@ create_window (GdkWindow *parent,
       bg->green = g_random_int_range (0, 0xffff);;
     }
   
-  gdk_rgb_find_color (gtk_widget_get_colormap (darea), bg);
   gdk_window_set_background (window, bg);
   g_object_set_data_full (G_OBJECT (window), "color", bg, g_free);
   
@@ -211,7 +207,7 @@ add_window_clicked (GtkWidget *button,
   if (l != NULL)
     parent = l->data;
   else
-    parent = darea->window;
+    parent = gtk_widget_get_window (darea);
 
   g_list_free (l);
   
@@ -241,17 +237,18 @@ static void
 save_window (GString *s,
             GdkWindow *window)
 {
-  gint x, y, w, h;
+  gint x, y;
   GdkColor *color;
 
   gdk_window_get_position (window, &x, &y);
-  gdk_drawable_get_size (GDK_DRAWABLE (window), &w, &h);
   color = g_object_get_data (G_OBJECT (window), "color");
   
   g_string_append_printf (s, "%d,%d %dx%d (%d,%d,%d) %d %d\n",
-                         x, y, w, h,
+                         x, y,
+                          gdk_window_get_width (window),
+                          gdk_window_get_height (window),
                          color->red, color->green, color->blue,
-                         window_has_impl (window),
+                         gdk_window_has_native (window),
                          g_list_length (gdk_window_peek_children (window)));
 
   save_children (s, window);
@@ -286,7 +283,7 @@ save_clicked (GtkWidget *button,
 
   s = g_string_new ("");
 
-  save_children (s, darea->window);
+  save_children (s, gtk_widget_get_window (darea));
 
   dialog = gtk_file_chooser_dialog_new ("Filename for window data",
                                        NULL,
@@ -350,7 +347,7 @@ parse_window (GdkWindow *parent, char **lines)
       color.blue = b;
       window = create_window (parent, x, y, w, h, &color);
       if (native)
-       gdk_window_set_has_native (window, TRUE);
+       gdk_window_ensure_native (window);
       
       for (i = 0; i < n_children; i++)
        lines = parse_window (window, lines);
@@ -364,18 +361,21 @@ parse_window (GdkWindow *parent, char **lines)
 static void
 load_file (GFile *file)
 {
+  GdkWindow *window;
   char *data;
   char **lines, **l;
   
   if (g_file_load_contents (file, NULL, &data, NULL, NULL, NULL))
     {
-      destroy_children (darea->window);
+      window = gtk_widget_get_window (darea);
+
+      destroy_children (window);
 
       lines = g_strsplit (data, "\n", -1);
 
       l = lines;
       while (*l != NULL)
-       l = parse_window (darea->window, l);
+       l = parse_window (window, l);
     }
 
   update_store ();
@@ -423,6 +423,128 @@ move_window_clicked (GtkWidget *button,
   g_list_free (selected);
 }
 
+static void
+manual_clicked (GtkWidget *button, 
+               gpointer data)
+{
+  GdkWindow *window;
+  GList *selected, *l;
+  int x, y, w, h;
+  GtkWidget *dialog, *table, *label, *xspin, *yspin, *wspin, *hspin;
+  
+
+  selected = get_selected_windows ();
+
+  if (selected == NULL)
+    return;
+
+  gdk_window_get_position (selected->data, &x, &y);
+  w = gdk_window_get_width (selected->data);
+  h = gdk_window_get_height (selected->data);
+
+  dialog = gtk_dialog_new_with_buttons ("Select new position and size",
+                                       GTK_WINDOW (main_window),
+                                       GTK_DIALOG_MODAL,
+                                       GTK_STOCK_OK, GTK_RESPONSE_OK,
+                                       NULL);
+  
+
+  table = gtk_table_new (2, 4, TRUE);
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+                     table,
+                     FALSE, FALSE,
+                     2);
+
+  
+  label = gtk_label_new ("x:");
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            label,
+                            0, 1,
+                            0, 1);
+  label = gtk_label_new ("y:");
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            label,
+                            0, 1,
+                            1, 2);
+  label = gtk_label_new ("width:");
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            label,
+                            0, 1,
+                            2, 3);
+  label = gtk_label_new ("height:");
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            label,
+                            0, 1,
+                            3, 4);
+
+  xspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (xspin), x);
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            xspin,
+                            1, 2,
+                            0, 1);
+  yspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (yspin), y);
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            yspin,
+                            1, 2,
+                            1, 2);
+  wspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (wspin), w);
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            wspin,
+                            1, 2,
+                            2, 3);
+  hspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (hspin), h);
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            hspin,
+                            1, 2,
+                            3, 4);
+  
+  gtk_widget_show_all (dialog);
+  
+  gtk_dialog_run (GTK_DIALOG (dialog));
+
+  x = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (xspin));
+  y = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (yspin));
+  w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (wspin));
+  h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (hspin));
+
+  gtk_widget_destroy (dialog);
+  
+  for (l = selected; l != NULL; l = l->next)
+    {
+      window = l->data;
+      
+      gdk_window_move_resize (window, x, y, w, h);
+    }
+
+  g_list_free (selected);
+}
+
+static void
+restack_clicked (GtkWidget *button,
+                gpointer data)
+{
+  GList *selected;
+
+  selected = get_selected_windows ();
+
+  if (g_list_length (selected) != 2)
+    {
+      g_warning ("select two windows");
+    }
+
+  gdk_window_restack (selected->data,
+                     selected->next->data,
+                     GPOINTER_TO_INT (data));
+
+  g_list_free (selected);
+
+  update_store ();
+}
+
 static void
 scroll_window_clicked (GtkWidget *button, 
                       gpointer data)
@@ -522,10 +644,8 @@ smaller_window_clicked (GtkWidget *button,
     {
       window = l->data;
       
-      gdk_drawable_get_size (GDK_DRAWABLE (window), &w, &h);
-      
-      w -= 10;
-      h -= 10;
+      w = gdk_window_get_width (window) - 10;
+      h = gdk_window_get_height (window) - 10;
       if (w < 1)
        w = 1;
       if (h < 1)
@@ -551,10 +671,8 @@ larger_window_clicked (GtkWidget *button,
     {
       window = l->data;
       
-      gdk_drawable_get_size (GDK_DRAWABLE (window), &w, &h);
-      
-      w += 10;
-      h += 10;
+      w = gdk_window_get_width (window) + 10;
+      h = gdk_window_get_height (window) + 10;
       
       gdk_window_resize (window, w, h);
     }
@@ -575,7 +693,7 @@ native_window_clicked (GtkWidget *button,
     {
       window = l->data;
       
-      gdk_window_set_has_native (window, TRUE);
+      gdk_window_ensure_native (window);
     }
   
   g_list_free (selected);
@@ -615,14 +733,14 @@ render_window_cell (GtkTreeViewColumn *tree_column,
                      0, &window,
                      -1);
 
-  if (window_has_impl (window))
+  if (gdk_window_has_native (window))
       name = g_strdup_printf ("%p (native)", window);
   else
       name = g_strdup_printf ("%p", window);
+
   g_object_set (cell,
                "text", name,
-               "background-gdk", &((GdkWindowObject *)window)->bg_color,
-               NULL);  
+               NULL);
 }
 
 static void
@@ -655,7 +773,7 @@ update_store (void)
 
   gtk_tree_store_clear (window_store);
 
-  add_children (window_store, darea->window, NULL);
+  add_children (window_store, gtk_widget_get_window (darea), NULL);
   gtk_tree_view_expand_all (GTK_TREE_VIEW (treeview));
 
   select_windows (selected);
@@ -670,17 +788,17 @@ main (int argc, char **argv)
   GtkWidget *button, *scrolled, *table;
   GtkTreeViewColumn *column;
   GtkCellRenderer *renderer;
-  GdkColor black = {0};
+  GdkRGBA black = {0,0,0,1};
   GFile *file;
   
   gtk_init (&argc, &argv);
 
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  main_window = window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_container_set_border_width (GTK_CONTAINER (window), 0);
 
   g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);
 
-  hbox = gtk_hbox_new (FALSE, 5);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
   gtk_container_add (GTK_CONTAINER (window), hbox);
   gtk_widget_show (hbox);
 
@@ -703,11 +821,10 @@ main (int argc, char **argv)
   gtk_container_add (GTK_CONTAINER (frame), darea);
   gtk_widget_realize (darea);
   gtk_widget_show (darea);
-  gtk_widget_modify_bg (darea, GTK_STATE_NORMAL,
-                       &black);
-                       
-  
-  vbox = gtk_vbox_new (FALSE, 5);
+  gtk_widget_override_background_color (darea, 0, &black);
+
+
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
   gtk_box_pack_start (GTK_BOX (hbox),
                      vbox,
                      FALSE, FALSE,
@@ -741,7 +858,7 @@ main (int argc, char **argv)
   gtk_widget_show (scrolled);
   gtk_widget_show (treeview);
   
-  table = gtk_table_new (4, 4, TRUE);
+  table = gtk_table_new (5, 4, TRUE);
   gtk_box_pack_start (GTK_BOX (vbox),
                      table,
                      FALSE, FALSE,
@@ -879,7 +996,35 @@ main (int argc, char **argv)
                             1, 2);
   gtk_widget_show (button);
 
-  
+  button = gtk_button_new_with_label ("Manual");
+  g_signal_connect (button, "clicked", 
+                   G_CALLBACK (manual_clicked),
+                   NULL);
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            button,
+                            3, 4,
+                            2, 3);
+  gtk_widget_show (button);
+
+  button = gtk_button_new_with_label ("Restack above");
+  g_signal_connect (button, "clicked",
+                   G_CALLBACK (restack_clicked),
+                   GINT_TO_POINTER (1));
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            button,
+                            2, 3,
+                            3, 4);
+  gtk_widget_show (button);
+
+  button = gtk_button_new_with_label ("Restack below");
+  g_signal_connect (button, "clicked",
+                   G_CALLBACK (restack_clicked),
+                   0);
+  gtk_table_attach_defaults (GTK_TABLE (table),
+                            button,
+                            3, 4,
+                            3, 4);
+  gtk_widget_show (button);
 
   button = gtk_button_new_with_label ("Add window");
   gtk_box_pack_start (GTK_BOX (vbox),