diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-03-04 00:11:25 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-03-04 00:11:25 +0000 |
commit | d3a43f73b3a5303186fdcf8b82550877862a2925 (patch) | |
tree | 7eb46e7e0eddac98340c9aca15d7a21de962d903 /tests/testgtk.c | |
parent | 86dec809ba538245f8d1650524beec7bb74d6e8b (diff) | |
download | gtk+-d3a43f73b3a5303186fdcf8b82550877862a2925.tar.gz |
Fix to properly take the default window into account by setting a flag and
Sun Mar 3 18:47:13 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_parse_geometry): Fix
to properly take the default window into account by
setting a flag and in gtk_window_compute_configure_request_size ()
multiplying by the increments and adding in the base
size. (#72393)
* tests/testgtk.c (create_gridded_geometry): Add a
test for gridded geometry and for gtk_window_parse_geometry().
Diffstat (limited to 'tests/testgtk.c')
-rw-r--r-- | tests/testgtk.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/tests/testgtk.c b/tests/testgtk.c index aa032bb00e..997ba0c633 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -1763,6 +1763,150 @@ create_tree_mode_window(void) } /* + * Gridded geometry + */ +#define GRID_SIZE 20 +#define DEFAULT_GEOMETRY "10x10" + +static gboolean +gridded_geometry_expose (GtkWidget *widget, + GdkEventExpose *event) +{ + int i, j; + + gdk_draw_rectangle (widget->window, widget->style->base_gc[widget->state], TRUE, + 0, 0, widget->allocation.width, widget->allocation.height); + + for (i = 0 ; i * GRID_SIZE < widget->allocation.width; i++) + for (j = 0 ; j * GRID_SIZE < widget->allocation.height; j++) + { + if ((i + j) % 2 == 0) + gdk_draw_rectangle (widget->window, widget->style->text_gc[widget->state], TRUE, + i * GRID_SIZE, j * GRID_SIZE, GRID_SIZE, GRID_SIZE); + } + + return FALSE; +} + +static void +gridded_geometry_subresponse (GtkDialog *dialog, + gint response_id, + gchar *geometry_string) +{ + if (response_id == GTK_RESPONSE_NONE) + { + gtk_widget_destroy (GTK_WIDGET (dialog)); + } + else + { + if (!gtk_window_parse_geometry (GTK_WINDOW (dialog), geometry_string)) + { + g_print ("Can't parse geometry string %s\n", geometry_string); + gtk_window_parse_geometry (GTK_WINDOW (dialog), DEFAULT_GEOMETRY); + } + } +} + +static void +gridded_geometry_response (GtkDialog *dialog, + gint response_id, + GtkEntry *entry) +{ + if (response_id == GTK_RESPONSE_NONE) + { + gtk_widget_destroy (GTK_WIDGET (dialog)); + } + else + { + gchar *geometry_string = g_strdup (gtk_entry_get_text (entry)); + gchar *title = g_strdup_printf ("Gridded window at: %s", geometry_string); + GtkWidget *window; + GtkWidget *drawing_area; + GtkWidget *box; + GdkGeometry geometry; + + window = gtk_dialog_new_with_buttons (title, + NULL, 0, + "Reset", 1, + GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, + NULL); + g_free (title); + g_signal_connect (window, "response", + G_CALLBACK (gridded_geometry_subresponse), geometry_string); + + box = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), box, TRUE, TRUE, 0); + + gtk_container_set_border_width (GTK_CONTAINER (box), 7); + + drawing_area = gtk_drawing_area_new (); + g_signal_connect (drawing_area, "expose_event", + G_CALLBACK (gridded_geometry_expose), NULL); + gtk_box_pack_start (GTK_BOX (box), drawing_area, TRUE, TRUE, 0); + + /* Gross hack to work around bug 68668... if we set the size request + * large enough, then the current + * + * request_of_window - request_of_geometry_widget + * + * method of getting the base size works more or less works. + */ + gtk_widget_set_size_request (drawing_area, 2000, 2000); + + geometry.base_width = 0; + geometry.base_height = 0; + geometry.min_width = 2 * GRID_SIZE; + geometry.min_height = 2 * GRID_SIZE; + geometry.width_inc = GRID_SIZE; + geometry.height_inc = GRID_SIZE; + + gtk_window_set_geometry_hints (GTK_WINDOW (window), drawing_area, + &geometry, + GDK_HINT_BASE_SIZE | GDK_HINT_MIN_SIZE | GDK_HINT_RESIZE_INC); + + if (!gtk_window_parse_geometry (GTK_WINDOW (window), geometry_string)) + { + g_print ("Can't parse geometry string %s\n", geometry_string); + gtk_window_parse_geometry (GTK_WINDOW (window), DEFAULT_GEOMETRY); + } + + gtk_widget_show_all (window); + } +} + +static void +create_gridded_geometry (void) +{ + static GtkWidget *window = NULL; + GtkWidget *entry; + GtkWidget *label; + + if (!window) + { + window = gtk_dialog_new_with_buttons ("Gridded Geometry", + NULL, 0, + "Create", 1, + GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, + NULL); + + label = gtk_label_new ("Geometry string:"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), label, FALSE, FALSE, 0); + + entry = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (entry), DEFAULT_GEOMETRY); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), entry, FALSE, FALSE, 0); + + g_signal_connect (window, "response", + G_CALLBACK (gridded_geometry_response), entry); + g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window); + + gtk_widget_show_all (window); + } + else + gtk_widget_destroy (window); +} + +/* * GtkHandleBox */ @@ -11444,6 +11588,7 @@ struct { { "focus", create_focus }, { "font selection", create_font_selection }, { "gamma curve", create_gamma_curve, TRUE }, + { "gridded geometry", create_gridded_geometry, TRUE }, { "handle box", create_handle_box }, { "image from drawable", create_get_image }, { "image", create_image }, |