2019-02-06 09:41:49 +00:00
|
|
|
/* gcc -g -Wall -O2 -o dialog-test dialog-test.c `pkg-config --cflags --libs gtk4` */
|
2013-05-25 15:42:28 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static GtkWidget *window;
|
|
|
|
static GtkWidget *width_chars_spin;
|
2013-11-25 02:49:13 +00:00
|
|
|
static GtkWidget *max_width_chars_spin;
|
2013-05-25 15:42:28 +00:00
|
|
|
static GtkWidget *default_width_spin;
|
|
|
|
static GtkWidget *default_height_spin;
|
|
|
|
static GtkWidget *resizable_check;
|
|
|
|
|
2018-10-12 17:45:30 +00:00
|
|
|
static void
|
|
|
|
size_changed_cb (GdkSurface *surface, int width, int height, GtkLabel *label)
|
2013-05-25 17:12:56 +00:00
|
|
|
{
|
2018-10-12 17:45:30 +00:00
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = g_strdup_printf ("%d x %d", width, height);
|
|
|
|
gtk_label_set_label (label, str);
|
|
|
|
g_free (str);
|
2013-05-25 17:12:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-25 15:42:28 +00:00
|
|
|
static void
|
|
|
|
show_dialog (void)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *label;
|
2013-11-25 02:49:13 +00:00
|
|
|
gint width_chars, max_width_chars, default_width, default_height;
|
2013-05-25 15:42:28 +00:00
|
|
|
gboolean resizable;
|
|
|
|
|
|
|
|
width_chars = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (width_chars_spin));
|
2013-11-25 02:49:13 +00:00
|
|
|
max_width_chars = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (max_width_chars_spin));
|
2013-05-25 15:42:28 +00:00
|
|
|
default_width = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (default_width_spin));
|
|
|
|
default_height = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (default_height_spin));
|
|
|
|
resizable = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (resizable_check));
|
|
|
|
|
|
|
|
dialog = gtk_dialog_new_with_buttons ("Test", GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_MODAL,
|
2013-06-24 21:31:22 +00:00
|
|
|
"_Close", GTK_RESPONSE_CANCEL,
|
2013-05-25 15:42:28 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
label = gtk_label_new ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
|
|
|
"Nulla innn urna ac dui malesuada ornare. Nullam dictum "
|
|
|
|
"tempor mi et tincidunt. Aliquam metus nulla, auctor "
|
|
|
|
"vitae pulvinar nec, egestas at mi. Class aptent taciti "
|
|
|
|
"sociosqu ad litora torquent per conubia nostra, per "
|
|
|
|
"inceptos himenaeos. Aliquam sagittis, tellus congue "
|
|
|
|
"cursus congue, diam massa mollis enim, sit amet gravida "
|
|
|
|
"magna turpis egestas sapien. Aenean vel molestie nunc. "
|
|
|
|
"In hac habitasse platea dictumst. Suspendisse lacinia"
|
|
|
|
"mi eu ipsum vestibulum in venenatis enim commodo. "
|
|
|
|
"Vivamus non malesuada ligula.");
|
|
|
|
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2013-05-25 15:42:28 +00:00
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), width_chars);
|
2013-11-25 02:49:13 +00:00
|
|
|
gtk_label_set_max_width_chars (GTK_LABEL (label), max_width_chars);
|
2013-05-25 15:42:28 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (dialog), default_width, default_height);
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), resizable);
|
|
|
|
|
2017-04-21 16:59:59 +00:00
|
|
|
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
2017-04-21 20:34:36 +00:00
|
|
|
label);
|
2013-05-25 17:12:56 +00:00
|
|
|
gtk_widget_show (label);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
2013-05-25 17:12:56 +00:00
|
|
|
label = gtk_label_new ("? x ?");
|
2013-11-25 02:49:13 +00:00
|
|
|
//gtk_widget_show (label);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
2013-05-25 17:12:56 +00:00
|
|
|
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), label, GTK_RESPONSE_HELP);
|
2018-10-12 17:45:30 +00:00
|
|
|
gtk_widget_realize (dialog);
|
2019-05-20 00:38:08 +00:00
|
|
|
g_signal_connect (gtk_native_get_surface (GTK_NATIVE (dialog)), "size-changed",
|
2018-10-12 17:45:30 +00:00
|
|
|
G_CALLBACK (size_changed_cb), label);
|
2013-05-25 17:12:56 +00:00
|
|
|
|
2013-05-25 15:42:28 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_window (void)
|
|
|
|
{
|
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-05-25 15:42:28 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Window size");
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
|
|
|
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), grid);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Width chars");
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
width_chars_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
|
|
|
|
gtk_widget_set_halign (width_chars_spin, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), width_chars_spin, 1, 0, 1, 1);
|
|
|
|
|
2013-11-25 02:49:13 +00:00
|
|
|
label = gtk_label_new ("Max width chars");
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
max_width_chars_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
|
|
|
|
gtk_widget_set_halign (width_chars_spin, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), max_width_chars_spin, 1, 1, 1, 1);
|
|
|
|
|
2013-05-25 15:42:28 +00:00
|
|
|
label = gtk_label_new ("Default size");
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
default_width_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
|
|
|
|
gtk_widget_set_halign (default_width_spin, GTK_ALIGN_START);
|
|
|
|
default_height_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
|
|
|
|
gtk_widget_set_halign (default_height_spin, GTK_ALIGN_START);
|
|
|
|
|
2013-11-25 02:49:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), default_width_spin, 1, 2, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), default_height_spin, 2, 2, 1, 1);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Resizable");
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
resizable_check = gtk_check_button_new ();
|
|
|
|
gtk_widget_set_halign (resizable_check, GTK_ALIGN_START);
|
|
|
|
|
2013-11-25 02:49:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), resizable_check, 1, 3, 1, 1);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Show");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (show_dialog), NULL);
|
2013-11-25 02:49:13 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 2, 4, 1, 1);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-05-25 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2013-05-25 15:42:28 +00:00
|
|
|
|
|
|
|
create_window ();
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-05-25 15:42:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|