2011-06-02 01:44:22 +00:00
|
|
|
/* Pickers
|
2022-10-28 15:38:57 +00:00
|
|
|
* #Keywords: GtkColorDialog, GtkFontDialog, GtkFileDialog
|
2005-05-25 04:09:20 +00:00
|
|
|
*
|
|
|
|
* These widgets are mainly intended for use in preference dialogs.
|
2022-06-22 21:07:11 +00:00
|
|
|
* They allow to select colors, fonts and applications.
|
2020-09-20 14:57:19 +00:00
|
|
|
*
|
|
|
|
* This demo shows both the default appearance for these dialogs,
|
|
|
|
* as well as some of the customizations that are possible.
|
2005-05-25 04:09:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2022-10-26 17:38:22 +00:00
|
|
|
static void
|
|
|
|
file_opened (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
void *data)
|
2020-09-20 14:57:19 +00:00
|
|
|
{
|
2022-10-26 17:38:22 +00:00
|
|
|
GFile *file;
|
|
|
|
GError *error = NULL;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
file = gtk_file_dialog_open_finish (GTK_FILE_DIALOG (source), result, &error);
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = g_file_get_basename (file);
|
|
|
|
gtk_button_set_label (GTK_BUTTON (data), name);
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
open_file (GtkButton *picker)
|
|
|
|
{
|
|
|
|
GtkWindow *parent = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (picker)));
|
|
|
|
GtkFileDialog *dialog;
|
|
|
|
|
|
|
|
dialog = gtk_file_dialog_new ();
|
|
|
|
|
|
|
|
gtk_file_dialog_open (dialog, parent, NULL, NULL, file_opened, picker);
|
|
|
|
|
|
|
|
g_object_unref (dialog);
|
2020-09-20 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 21:19:36 +00:00
|
|
|
#define COLOR(r,g,b) { r/255., g/255., b/255., 1.0 }
|
|
|
|
|
2005-05-25 04:09:20 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_pickers (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
GtkWidget *table, *label, *picker;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2005-05-25 04:09:20 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Pickers");
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2011-06-02 01:44:22 +00:00
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
table = gtk_grid_new ();
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (table, 20);
|
|
|
|
gtk_widget_set_margin_end (table, 20);
|
|
|
|
gtk_widget_set_margin_top (table, 20);
|
|
|
|
gtk_widget_set_margin_bottom (table, 20);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (table), 3);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (table), 10);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), table);
|
2005-05-25 04:09:20 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Color:");
|
2011-06-12 23:39:48 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
2020-09-20 14:57:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
|
|
|
|
|
2022-10-26 17:38:22 +00:00
|
|
|
picker = gtk_color_dialog_button_new (gtk_color_dialog_new ());
|
2020-09-20 14:57:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 0, 1, 1);
|
|
|
|
|
2005-05-25 04:09:20 +00:00
|
|
|
label = gtk_label_new ("Font:");
|
2011-06-12 23:39:48 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
|
2020-09-20 14:57:19 +00:00
|
|
|
|
2022-10-26 17:38:22 +00:00
|
|
|
picker = gtk_font_dialog_button_new (gtk_font_dialog_new ());
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 1, 1, 1);
|
2005-05-25 04:09:20 +00:00
|
|
|
|
2022-10-26 17:38:22 +00:00
|
|
|
label = gtk_label_new ("File:");
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
|
2020-09-20 14:57:19 +00:00
|
|
|
|
2022-10-26 17:38:22 +00:00
|
|
|
picker = gtk_button_new_with_label ("[...]");
|
|
|
|
g_signal_connect (picker, "clicked", G_CALLBACK (open_file), NULL);
|
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 2, 1, 1);
|
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2020-09-20 14:57:19 +00:00
|
|
|
|
2011-06-02 01:44:22 +00:00
|
|
|
label = gtk_label_new ("Mail:");
|
2011-06-12 23:39:48 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
2022-10-04 01:54:57 +00:00
|
|
|
|
2011-06-02 01:44:22 +00:00
|
|
|
picker = gtk_app_chooser_button_new ("x-scheme-handler/mailto");
|
|
|
|
gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (picker), TRUE);
|
2022-10-04 01:54:57 +00:00
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
2020-12-04 00:24:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 3, 1, 1);
|
2005-05-25 04:09:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2005-05-25 04:09:20 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2005-05-25 04:09:20 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|