-/*
- * Gridded geometry
- */
-#define GRID_SIZE 20
-#define DEFAULT_GEOMETRY "10x10"
-
-static gboolean
-gridded_geometry_expose (GtkWidget *widget,
- GdkEventExpose *event)
-{
- GtkAllocation allocation;
- GtkStateType state;
- GtkStyle *style;
- cairo_t *cr;
- int i, j;
-
- gtk_widget_get_allocation (widget, &allocation);
- style = gtk_widget_get_style (widget);
- state = gtk_widget_get_state (widget);
-
- cr = gdk_cairo_create (gtk_widget_get_window (widget));
-
- cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
- gdk_cairo_set_source_color (cr, &style->base[state]);
- cairo_fill (cr);
-
- for (i = 0 ; i * GRID_SIZE < allocation.width; i++)
- for (j = 0 ; j * GRID_SIZE < allocation.height; j++)
- {
- if ((i + j) % 2 == 0)
- cairo_rectangle (cr, i * GRID_SIZE, j * GRID_SIZE, GRID_SIZE, GRID_SIZE);
- }
-
- gdk_cairo_set_source_color (cr, &style->text[state]);
- cairo_fill (cr);
-
- cairo_destroy (cr);
-
- 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 *content_area;
- 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);
-
- gtk_window_set_screen (GTK_WINDOW (window),
- gtk_widget_get_screen (GTK_WIDGET (dialog)));
- g_free (title);
- g_signal_connect (window, "response",
- G_CALLBACK (gridded_geometry_subresponse), geometry_string);
-
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
-
- box = gtk_vbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (content_area), 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 (GtkWidget *widget)
-{
- static GtkWidget *window = NULL;
- gpointer window_ptr;
- GtkWidget *content_area;
- 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);
-
- gtk_window_set_screen (GTK_WINDOW (window),
- gtk_widget_get_screen (widget));
-
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
-
- label = gtk_label_new ("Geometry string:");
- gtk_box_pack_start (GTK_BOX (content_area), label, FALSE, FALSE, 0);
-
- entry = gtk_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (entry), DEFAULT_GEOMETRY);
- gtk_box_pack_start (GTK_BOX (content_area), entry, FALSE, FALSE, 0);
-
- g_signal_connect (window, "response",
- G_CALLBACK (gridded_geometry_response), entry);
- window_ptr = &window;
- g_object_add_weak_pointer (G_OBJECT (window), window_ptr);
-
- gtk_widget_show_all (window);
- }
- else
- gtk_widget_destroy (window);
-}
-