2011-06-02 01:44:22 +00:00
|
|
|
/* Pickers
|
2020-09-13 18:59:33 +00:00
|
|
|
* #Keywords: GtkColorChooser, GtkFontChooser, GtkFileChooser,
|
|
|
|
* #Keywords: GtkApplicationChooser
|
2005-05-25 04:09:20 +00:00
|
|
|
*
|
|
|
|
* These widgets are mainly intended for use in preference dialogs.
|
2011-06-02 01:44:22 +00:00
|
|
|
* They allow to select colors, fonts, files, directories 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>
|
|
|
|
|
2020-09-20 14:57:19 +00:00
|
|
|
static gboolean
|
|
|
|
filter_font_cb (const PangoFontFamily *family,
|
|
|
|
const PangoFontFace *face,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
const char *alias_families[] = {
|
|
|
|
"Cursive",
|
|
|
|
"Fantasy",
|
|
|
|
"Monospace",
|
|
|
|
"Sans",
|
|
|
|
"Serif",
|
|
|
|
"System-ui",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
const char *family_name;
|
|
|
|
|
|
|
|
family_name = pango_font_family_get_name (PANGO_FONT_FAMILY (family));
|
|
|
|
|
|
|
|
return g_strv_contains (alias_families, family_name);
|
|
|
|
}
|
|
|
|
|
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;
|
2020-08-24 21:19:36 +00:00
|
|
|
GdkRGBA solarized[] = {
|
|
|
|
COLOR (0xff, 0xff, 0xff),
|
|
|
|
COLOR (0x07, 0x36, 0x42),
|
|
|
|
COLOR (0xdc, 0x32, 0x2f),
|
|
|
|
COLOR (0x85, 0x99, 0x00),
|
|
|
|
COLOR (0xb5, 0x89, 0x00),
|
|
|
|
COLOR (0x26, 0x8b, 0xd2),
|
|
|
|
COLOR (0xd3, 0x36, 0x82),
|
|
|
|
COLOR (0x2a, 0xa1, 0x98),
|
|
|
|
COLOR (0xee, 0xe8, 0xd5),
|
|
|
|
|
|
|
|
COLOR (0x00, 0x00, 0x00),
|
|
|
|
COLOR (0x00, 0x2b, 0x36),
|
|
|
|
COLOR (0xcb, 0x4b, 0x16),
|
|
|
|
COLOR (0x58, 0x6e, 0x75),
|
|
|
|
COLOR (0x65, 0x7b, 0x83),
|
|
|
|
COLOR (0x83, 0x94, 0x96),
|
|
|
|
COLOR (0x6c, 0x71, 0xc4),
|
|
|
|
COLOR (0x93, 0xa1, 0xa1),
|
|
|
|
COLOR (0xfd, 0xf6, 0xe3),
|
|
|
|
};
|
2005-05-25 04:09:20 +00:00
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2020-09-20 14:57:19 +00:00
|
|
|
char *dir;
|
|
|
|
GFile *file;
|
|
|
|
|
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
|
|
|
|
2020-09-20 14:57:19 +00:00
|
|
|
label = gtk_label_new ("Standard");
|
|
|
|
gtk_widget_add_css_class (label, "title-4");
|
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 1, -1, 1, 1);
|
|
|
|
label = gtk_label_new ("Custom");
|
|
|
|
gtk_widget_add_css_class (label, "title-4");
|
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 2, -1, 1, 1);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
picker = gtk_color_button_new ();
|
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 0, 1, 1);
|
|
|
|
|
2005-05-25 04:09:20 +00:00
|
|
|
picker = gtk_color_button_new ();
|
2020-08-24 21:19:36 +00:00
|
|
|
gtk_color_button_set_title (GTK_COLOR_BUTTON (picker), "Solarized colors");
|
|
|
|
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (picker),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
9,
|
|
|
|
18,
|
|
|
|
solarized);
|
2020-09-20 14:57:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 2, 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
|
|
|
|
|
|
|
picker = gtk_font_button_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
|
|
|
|
2020-09-20 14:57:19 +00:00
|
|
|
picker = gtk_font_button_new ();
|
|
|
|
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (picker),
|
|
|
|
GTK_FONT_CHOOSER_LEVEL_FAMILY |
|
|
|
|
GTK_FONT_CHOOSER_LEVEL_SIZE);
|
|
|
|
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (picker), filter_font_cb, NULL, NULL);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 2, 1, 1, 1);
|
|
|
|
|
2005-05-25 04:09:20 +00:00
|
|
|
label = gtk_label_new ("File:");
|
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, 2, 1, 1);
|
|
|
|
|
2011-06-02 01:44:22 +00:00
|
|
|
picker = gtk_file_chooser_button_new ("Pick a File",
|
2005-05-25 04:09:20 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 2, 1, 1);
|
2020-09-20 14:57:19 +00:00
|
|
|
|
|
|
|
picker = gtk_file_chooser_button_new ("Pick a File",
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN);
|
|
|
|
|
|
|
|
dir = g_get_current_dir ();
|
|
|
|
file = g_file_new_for_path (dir);
|
|
|
|
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (picker), file, NULL);
|
|
|
|
g_object_unref (file);
|
|
|
|
g_free (dir);
|
|
|
|
|
|
|
|
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (picker),
|
|
|
|
"choice",
|
|
|
|
"Encoding",
|
|
|
|
(const char *[]) { "option1", "option2", NULL },
|
|
|
|
(const char *[]) { "UTF-8", "Other Encoding", NULL });
|
|
|
|
gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (picker), "choice", "option1");
|
|
|
|
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (picker),
|
|
|
|
"check",
|
|
|
|
"Read backwards",
|
|
|
|
NULL, NULL);
|
|
|
|
gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (picker), "check", "false");
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 2, 2, 1, 1);
|
2005-05-25 04:09:20 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Folder:");
|
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-06-02 01:44:22 +00:00
|
|
|
picker = gtk_file_chooser_button_new ("Pick a Folder",
|
2005-05-25 04:09:20 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
2011-08-31 15:10: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);
|
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);
|
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);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 4, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (table), picker, 1, 4, 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;
|
|
|
|
}
|