2013-03-18 05:03:39 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static const gchar css[] =
|
2013-05-13 10:06:10 +00:00
|
|
|
".main.background { "
|
2017-12-24 15:27:54 +00:00
|
|
|
" background-image: linear-gradient(to bottom, red, blue);"
|
2013-03-18 12:26:24 +00:00
|
|
|
" border-width: 0px; "
|
|
|
|
"}"
|
2013-05-26 00:56:14 +00:00
|
|
|
".titlebar.backdrop { "
|
2013-03-18 12:26:24 +00:00
|
|
|
" background-image: none; "
|
|
|
|
" background-color: @bg_color; "
|
|
|
|
" border-radius: 10px 10px 0px 0px; "
|
|
|
|
"}"
|
|
|
|
".titlebar { "
|
2017-12-24 15:27:54 +00:00
|
|
|
" background-image: linear-gradient(to bottom, white, @bg_color);"
|
2013-03-18 12:26:24 +00:00
|
|
|
" border-radius: 10px 10px 0px 0px; "
|
|
|
|
"}";
|
2013-03-18 05:03:39 +00:00
|
|
|
|
2013-05-13 10:06:10 +00:00
|
|
|
static void
|
|
|
|
on_bookmark_clicked (GtkButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWindow *window = GTK_WINDOW (data);
|
|
|
|
GtkWidget *chooser;
|
|
|
|
|
|
|
|
chooser = gtk_file_chooser_dialog_new ("File Chooser Test",
|
|
|
|
window,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
2013-06-24 21:31:22 +00:00
|
|
|
"_Close",
|
2013-05-13 10:06:10 +00:00
|
|
|
GTK_RESPONSE_CLOSE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_connect (chooser, "response",
|
|
|
|
G_CALLBACK (gtk_widget_destroy), NULL);
|
|
|
|
|
|
|
|
gtk_widget_show (chooser);
|
|
|
|
}
|
|
|
|
|
2013-05-26 00:56:14 +00:00
|
|
|
static GtkWidget *header;
|
|
|
|
|
2013-03-20 02:08:13 +00:00
|
|
|
static void
|
|
|
|
change_subtitle (GtkButton *button, gpointer data)
|
|
|
|
{
|
2013-05-26 00:56:14 +00:00
|
|
|
if (!GTK_IS_HEADER_BAR (header))
|
|
|
|
return;
|
2013-03-20 02:08:13 +00:00
|
|
|
|
2013-05-26 00:56:14 +00:00
|
|
|
if (gtk_header_bar_get_subtitle (GTK_HEADER_BAR (header)) == NULL)
|
2013-03-20 02:08:13 +00:00
|
|
|
{
|
2013-05-26 00:56:14 +00:00
|
|
|
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header), "(subtle subtitle)");
|
2013-03-20 02:08:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-26 00:56:14 +00:00
|
|
|
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header), NULL);
|
2013-03-20 02:08:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 01:00:06 +00:00
|
|
|
static void
|
|
|
|
toggle_fullscreen (GtkButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *window = GTK_WIDGET (data);
|
|
|
|
static gboolean fullscreen = FALSE;
|
|
|
|
|
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
gtk_window_unfullscreen (GTK_WINDOW (window));
|
|
|
|
fullscreen = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_fullscreen (GTK_WINDOW (window));
|
|
|
|
fullscreen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static gboolean done = FALSE;
|
|
|
|
|
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2013-05-26 00:56:14 +00:00
|
|
|
static void
|
|
|
|
change_header (GtkButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *window = GTK_WIDGET (data);
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *image;
|
|
|
|
|
|
|
|
if (button && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
|
|
|
{
|
2017-08-01 22:49:42 +00:00
|
|
|
header = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
2013-05-26 00:56:14 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (header), "titlebar");
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (header), "header-bar");
|
2017-08-01 22:49:42 +00:00
|
|
|
g_object_set (header, "margin", 10, NULL);
|
2013-05-26 00:56:14 +00:00
|
|
|
label = gtk_label_new ("Label");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (header), label);
|
2013-05-26 00:56:14 +00:00
|
|
|
widget = gtk_level_bar_new ();
|
|
|
|
gtk_level_bar_set_value (GTK_LEVEL_BAR (widget), 0.4);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (header), widget);
|
2013-05-26 00:56:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header = gtk_header_bar_new ();
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (header), "titlebar");
|
|
|
|
gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Example header");
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
widget = gtk_button_new_with_label ("_Close");
|
2013-06-28 20:08:15 +00:00
|
|
|
gtk_button_set_use_underline (GTK_BUTTON (widget), TRUE);
|
2013-05-26 00:56:14 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (widget), "suggested-action");
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (widget, "clicked", G_CALLBACK (quit_cb), &done);
|
2013-05-26 00:56:14 +00:00
|
|
|
|
|
|
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), widget);
|
|
|
|
|
|
|
|
widget= gtk_button_new ();
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("bookmark-new-symbolic");
|
2013-05-26 00:56:14 +00:00
|
|
|
g_signal_connect (widget, "clicked", G_CALLBACK (on_bookmark_clicked), window);
|
|
|
|
gtk_container_add (GTK_CONTAINER (widget), image);
|
|
|
|
|
|
|
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
|
|
|
}
|
|
|
|
|
2013-03-18 05:03:39 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *footer;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *content;
|
|
|
|
GtkCssProvider *provider;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2013-03-18 05:03:39 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-05-13 10:06:10 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (window), "main");
|
2013-03-18 05:03:39 +00:00
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
2016-10-17 14:09:12 +00:00
|
|
|
gtk_css_provider_load_from_data (provider, css, -1);
|
2017-10-31 01:35:21 +00:00
|
|
|
gtk_style_context_add_provider_for_display (gtk_widget_get_display (window),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
2013-03-18 05:03:39 +00:00
|
|
|
|
|
|
|
|
2013-05-26 00:56:14 +00:00
|
|
|
change_header (NULL, window);
|
2013-03-18 05:03:39 +00:00
|
|
|
|
2013-03-18 12:26:24 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2013-03-18 05:03:39 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), box);
|
|
|
|
|
2018-12-26 07:20:34 +00:00
|
|
|
content = gtk_image_new_from_icon_name ("start-here-symbolic");
|
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (content), 512);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), content);
|
|
|
|
|
2014-01-06 22:14:14 +00:00
|
|
|
footer = gtk_action_bar_new ();
|
|
|
|
gtk_action_bar_set_center_widget (GTK_ACTION_BAR (footer), gtk_check_button_new_with_label ("Middle"));
|
2013-05-26 00:56:14 +00:00
|
|
|
button = gtk_toggle_button_new_with_label ("Custom");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (change_header), window);
|
2014-01-06 22:14:14 +00:00
|
|
|
gtk_action_bar_pack_start (GTK_ACTION_BAR (footer), button);
|
2013-05-26 00:56:14 +00:00
|
|
|
button = gtk_button_new_with_label ("Subtitle");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (change_subtitle), NULL);
|
2014-01-06 22:14:14 +00:00
|
|
|
gtk_action_bar_pack_end (GTK_ACTION_BAR (footer), button);
|
2013-05-26 00:56:14 +00:00
|
|
|
button = gtk_button_new_with_label ("Fullscreen");
|
2014-01-06 22:14:14 +00:00
|
|
|
gtk_action_bar_pack_end (GTK_ACTION_BAR (footer), button);
|
2013-05-13 01:00:06 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (toggle_fullscreen), window);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), footer);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-03-18 05:03:39 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-03-18 05:03:39 +00:00
|
|
|
|
2013-05-13 01:00:06 +00:00
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
2013-03-18 05:03:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|