2012-01-14 23:22:33 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2016-02-14 02:46:40 +00:00
|
|
|
typedef GtkApplication DemoApplication;
|
|
|
|
typedef GtkApplicationClass DemoApplicationClass;
|
|
|
|
|
2020-03-07 14:01:21 +00:00
|
|
|
static GType demo_application_get_type (void);
|
2016-02-14 02:46:40 +00:00
|
|
|
G_DEFINE_TYPE (DemoApplication, demo_application, GTK_TYPE_APPLICATION)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GtkApplicationWindow parent_instance;
|
|
|
|
|
|
|
|
GtkWidget *message;
|
|
|
|
GtkWidget *infobar;
|
2016-02-14 03:53:16 +00:00
|
|
|
GtkWidget *status;
|
2020-02-03 03:52:15 +00:00
|
|
|
GtkWidget *menubutton;
|
2016-02-14 03:53:16 +00:00
|
|
|
GMenuModel *toolmenu;
|
2016-02-14 02:46:40 +00:00
|
|
|
GtkTextBuffer *buffer;
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
gboolean maximized;
|
|
|
|
gboolean fullscreen;
|
2016-02-14 02:46:40 +00:00
|
|
|
} DemoApplicationWindow;
|
|
|
|
typedef GtkApplicationWindowClass DemoApplicationWindowClass;
|
|
|
|
|
2020-03-07 14:01:21 +00:00
|
|
|
static GType demo_application_window_get_type (void);
|
2016-02-14 02:46:40 +00:00
|
|
|
G_DEFINE_TYPE (DemoApplicationWindow, demo_application_window, GTK_TYPE_APPLICATION_WINDOW)
|
|
|
|
|
2015-11-05 15:25:59 +00:00
|
|
|
static void create_window (GApplication *app, const char *contents);
|
|
|
|
|
2012-01-14 23:22:33 +00:00
|
|
|
static void
|
|
|
|
show_action_dialog (GSimpleAction *action)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name;
|
2012-01-14 23:22:33 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
name = g_action_get_name (G_ACTION (action));
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (NULL,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"You activated action: \"%s\"",
|
|
|
|
name);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2012-01-14 23:22:33 +00:00
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_action_infobar (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
2016-02-14 02:46:40 +00:00
|
|
|
gpointer data)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
2016-02-14 02:46:40 +00:00
|
|
|
DemoApplicationWindow *window = data;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
|
|
|
const char *name;
|
|
|
|
const char *value;
|
2012-01-14 23:22:33 +00:00
|
|
|
|
|
|
|
name = g_action_get_name (G_ACTION (action));
|
|
|
|
value = g_variant_get_string (parameter, NULL);
|
|
|
|
|
|
|
|
text = g_strdup_printf ("You activated radio action: \"%s\".\n"
|
|
|
|
"Current value: %s", name, value);
|
2016-02-14 02:46:40 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (window->message), text);
|
|
|
|
gtk_widget_show (window->infobar);
|
2012-01-14 23:22:33 +00:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-14 02:46:40 +00:00
|
|
|
activate_action (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
|
|
|
show_action_dialog (action);
|
|
|
|
}
|
|
|
|
|
2015-11-05 15:25:59 +00:00
|
|
|
static void
|
2016-02-14 02:46:40 +00:00
|
|
|
activate_new (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
2015-11-05 15:25:59 +00:00
|
|
|
{
|
|
|
|
GApplication *app = user_data;
|
|
|
|
|
|
|
|
create_window (app, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
open_response_cb (GtkNativeDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2016-02-14 02:46:40 +00:00
|
|
|
gpointer user_data)
|
2015-11-05 15:25:59 +00:00
|
|
|
{
|
|
|
|
GtkFileChooserNative *native = user_data;
|
|
|
|
GApplication *app = g_object_get_data (G_OBJECT (native), "app");
|
|
|
|
GtkWidget *message_dialog;
|
|
|
|
GFile *file;
|
|
|
|
char *contents;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
|
|
|
|
|
|
|
|
if (g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
|
|
|
|
{
|
|
|
|
create_window (app, contents);
|
|
|
|
g_free (contents);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message_dialog = gtk_message_dialog_new (NULL,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"Error loading file: \"%s\"",
|
|
|
|
error->message);
|
|
|
|
g_signal_connect (message_dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2015-11-05 15:25:59 +00:00
|
|
|
gtk_widget_show (message_dialog);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 15:06:44 +00:00
|
|
|
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
|
2015-11-05 15:25:59 +00:00
|
|
|
g_object_unref (native);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-02-14 02:46:40 +00:00
|
|
|
activate_open (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
2015-11-05 15:25:59 +00:00
|
|
|
{
|
|
|
|
GApplication *app = user_data;
|
|
|
|
GtkFileChooserNative *native;
|
|
|
|
|
|
|
|
native = gtk_file_chooser_native_new ("Open File",
|
|
|
|
NULL,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
"_Open",
|
|
|
|
"_Cancel");
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (native), "app", g_object_ref (app), g_object_unref);
|
|
|
|
g_signal_connect (native,
|
|
|
|
"response",
|
|
|
|
G_CALLBACK (open_response_cb),
|
|
|
|
native);
|
|
|
|
|
|
|
|
gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
|
|
|
|
}
|
|
|
|
|
2012-01-14 23:22:33 +00:00
|
|
|
static void
|
|
|
|
activate_toggle (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GVariant *state;
|
|
|
|
|
|
|
|
show_action_dialog (action);
|
|
|
|
|
|
|
|
state = g_action_get_state (G_ACTION (action));
|
|
|
|
g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
|
|
|
|
g_variant_unref (state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_radio (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
show_action_infobar (action, parameter, user_data);
|
|
|
|
|
|
|
|
g_action_change_state (G_ACTION (action), parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_about (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *window = user_data;
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *authors[] = {
|
2012-01-14 23:22:33 +00:00
|
|
|
"Peter Mattis",
|
|
|
|
"Spencer Kimball",
|
|
|
|
"Josh MacDonald",
|
|
|
|
"and many more...",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *documentors[] = {
|
2012-01-14 23:22:33 +00:00
|
|
|
"Owen Taylor",
|
|
|
|
"Tony Gale",
|
|
|
|
"Matthias Clasen <mclasen@redhat.com>",
|
|
|
|
"and many more...",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gtk_show_about_dialog (GTK_WINDOW (window),
|
2019-02-05 09:19:57 +00:00
|
|
|
"program-name", "GTK Code Demos",
|
|
|
|
"version", g_strdup_printf ("%s,\nRunning against GTK %d.%d.%d",
|
2012-01-14 23:22:33 +00:00
|
|
|
PACKAGE_VERSION,
|
|
|
|
gtk_get_major_version (),
|
|
|
|
gtk_get_minor_version (),
|
|
|
|
gtk_get_micro_version ()),
|
2019-02-05 09:19:57 +00:00
|
|
|
"copyright", "(C) 1997-2013 The GTK Team",
|
2012-01-14 23:22:33 +00:00
|
|
|
"license-type", GTK_LICENSE_LGPL_2_1,
|
|
|
|
"website", "http://www.gtk.org",
|
2019-02-05 09:19:57 +00:00
|
|
|
"comments", "Program to demonstrate GTK functions.",
|
2012-01-14 23:22:33 +00:00
|
|
|
"authors", authors,
|
|
|
|
"documenters", documentors,
|
2019-04-01 22:49:09 +00:00
|
|
|
"logo-icon-name", "org.gtk.Demo4",
|
2019-02-05 09:19:57 +00:00
|
|
|
"title", "About GTK Code Demos",
|
2012-01-14 23:22:33 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_quit (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplication *app = user_data;
|
|
|
|
GtkWidget *win;
|
|
|
|
GList *list, *next;
|
|
|
|
|
|
|
|
list = gtk_application_get_windows (app);
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
win = list->data;
|
|
|
|
next = list->next;
|
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (win));
|
2012-01-14 23:22:33 +00:00
|
|
|
|
|
|
|
list = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-14 03:53:16 +00:00
|
|
|
update_statusbar (GtkTextBuffer *buffer,
|
|
|
|
DemoApplicationWindow *window)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *msg;
|
2020-07-24 13:54:49 +00:00
|
|
|
int row, col;
|
|
|
|
int count;
|
2012-01-14 23:22:33 +00:00
|
|
|
GtkTextIter iter;
|
|
|
|
|
|
|
|
/* clear any previous message, underflow is allowed */
|
2016-02-14 03:53:16 +00:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (window->status), 0);
|
2012-01-14 23:22:33 +00:00
|
|
|
|
|
|
|
count = gtk_text_buffer_get_char_count (buffer);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer,
|
|
|
|
&iter,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
|
|
|
|
row = gtk_text_iter_get_line (&iter);
|
|
|
|
col = gtk_text_iter_get_line_offset (&iter);
|
|
|
|
|
|
|
|
msg = g_strdup_printf ("Cursor at row %d column %d - %d chars in document",
|
|
|
|
row, col, count);
|
|
|
|
|
2016-02-14 03:53:16 +00:00
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (window->status), 0, msg);
|
2012-01-14 23:22:33 +00:00
|
|
|
|
|
|
|
g_free (msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-14 03:53:16 +00:00
|
|
|
mark_set_callback (GtkTextBuffer *buffer,
|
|
|
|
const GtkTextIter *new_location,
|
|
|
|
GtkTextMark *mark,
|
|
|
|
DemoApplicationWindow *window)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
2016-02-14 03:53:16 +00:00
|
|
|
update_statusbar (buffer, window);
|
2012-01-14 23:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
change_theme_state (GSimpleAction *action,
|
|
|
|
GVariant *state,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkSettings *settings = gtk_settings_get_default ();
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (settings),
|
|
|
|
"gtk-application-prefer-dark-theme",
|
|
|
|
g_variant_get_boolean (state),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_simple_action_set_state (action, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
change_radio_state (GSimpleAction *action,
|
|
|
|
GVariant *state,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_simple_action_set_state (action, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GActionEntry app_entries[] = {
|
2015-11-05 15:25:59 +00:00
|
|
|
{ "new", activate_new, NULL, NULL, NULL },
|
|
|
|
{ "open", activate_open, NULL, NULL, NULL },
|
2012-01-14 23:22:33 +00:00
|
|
|
{ "save", activate_action, NULL, NULL, NULL },
|
|
|
|
{ "save-as", activate_action, NULL, NULL, NULL },
|
|
|
|
{ "quit", activate_quit, NULL, NULL, NULL },
|
|
|
|
{ "dark", activate_toggle, NULL, "false", change_theme_state }
|
|
|
|
};
|
|
|
|
|
|
|
|
static GActionEntry win_entries[] = {
|
|
|
|
{ "shape", activate_radio, "s", "'oval'", change_radio_state },
|
|
|
|
{ "bold", activate_toggle, NULL, "false", NULL },
|
|
|
|
{ "about", activate_about, NULL, NULL, NULL },
|
2012-01-25 03:27:28 +00:00
|
|
|
{ "file1", activate_action, NULL, NULL, NULL },
|
2012-01-14 23:22:33 +00:00
|
|
|
{ "logo", activate_action, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2016-02-14 03:53:16 +00:00
|
|
|
clicked_cb (GtkWidget *widget, DemoApplicationWindow *window)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
2016-02-14 03:53:16 +00:00
|
|
|
gtk_widget_hide (window->infobar);
|
2012-01-14 23:22:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:07:12 +00:00
|
|
|
static void
|
|
|
|
startup (GApplication *app)
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
|
|
|
|
2016-02-14 02:46:40 +00:00
|
|
|
G_APPLICATION_CLASS (demo_application_parent_class)->startup (app);
|
|
|
|
|
2012-01-16 22:07:12 +00:00
|
|
|
builder = gtk_builder_new ();
|
2016-02-14 14:39:15 +00:00
|
|
|
gtk_builder_add_from_resource (builder, "/application_demo/menus.ui", NULL);
|
2012-01-16 22:07:12 +00:00
|
|
|
|
2020-05-22 20:19:49 +00:00
|
|
|
gtk_application_set_menubar (GTK_APPLICATION (app),
|
|
|
|
G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
|
2012-01-16 22:07:12 +00:00
|
|
|
|
|
|
|
g_object_unref (builder);
|
|
|
|
}
|
|
|
|
|
2012-01-14 23:22:33 +00:00
|
|
|
static void
|
2015-11-05 15:25:59 +00:00
|
|
|
create_window (GApplication *app,
|
2016-02-14 02:46:40 +00:00
|
|
|
const char *content)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
2016-02-14 02:46:40 +00:00
|
|
|
DemoApplicationWindow *window;
|
2012-01-14 23:22:33 +00:00
|
|
|
|
2016-02-14 03:53:16 +00:00
|
|
|
window = (DemoApplicationWindow *)g_object_new (demo_application_window_get_type (),
|
|
|
|
"application", app,
|
2020-05-22 20:19:49 +00:00
|
|
|
"show-menubar", TRUE,
|
2016-02-14 03:53:16 +00:00
|
|
|
NULL);
|
2016-02-14 02:46:40 +00:00
|
|
|
if (content)
|
|
|
|
gtk_text_buffer_set_text (window->buffer, content, -1);
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (window));
|
2012-01-14 23:22:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 15:25:59 +00:00
|
|
|
static void
|
|
|
|
activate (GApplication *app)
|
|
|
|
{
|
|
|
|
create_window (app, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-14 02:46:40 +00:00
|
|
|
static void
|
|
|
|
demo_application_init (DemoApplication *app)
|
2012-01-14 23:22:33 +00:00
|
|
|
{
|
2012-01-24 05:07:03 +00:00
|
|
|
GSettings *settings;
|
|
|
|
GAction *action;
|
2012-01-14 23:22:33 +00:00
|
|
|
|
2019-04-01 22:49:09 +00:00
|
|
|
settings = g_settings_new ("org.gtk.Demo4");
|
2012-01-14 23:22:33 +00:00
|
|
|
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
|
|
|
app_entries, G_N_ELEMENTS (app_entries),
|
|
|
|
app);
|
|
|
|
|
2012-01-24 05:07:03 +00:00
|
|
|
action = g_settings_create_action (settings, "color");
|
|
|
|
|
|
|
|
g_action_map_add_action (G_ACTION_MAP (app), action);
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
g_object_unref (settings);
|
2016-02-14 02:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_application_class_init (DemoApplicationClass *class)
|
|
|
|
{
|
|
|
|
GApplicationClass *app_class = G_APPLICATION_CLASS (class);
|
|
|
|
|
|
|
|
app_class->startup = startup;
|
|
|
|
app_class->activate = activate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-14 03:53:16 +00:00
|
|
|
demo_application_window_store_state (DemoApplicationWindow *win)
|
|
|
|
{
|
|
|
|
GSettings *settings;
|
|
|
|
|
2019-04-01 22:49:09 +00:00
|
|
|
settings = g_settings_new ("org.gtk.Demo4");
|
2016-02-14 03:53:16 +00:00
|
|
|
g_settings_set (settings, "window-size", "(ii)", win->width, win->height);
|
|
|
|
g_settings_set_boolean (settings, "maximized", win->maximized);
|
|
|
|
g_settings_set_boolean (settings, "fullscreen", win->fullscreen);
|
|
|
|
g_object_unref (settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_application_window_load_state (DemoApplicationWindow *win)
|
|
|
|
{
|
|
|
|
GSettings *settings;
|
|
|
|
|
2019-04-01 22:49:09 +00:00
|
|
|
settings = g_settings_new ("org.gtk.Demo4");
|
2016-02-14 03:53:16 +00:00
|
|
|
g_settings_get (settings, "window-size", "(ii)", &win->width, &win->height);
|
|
|
|
win->maximized = g_settings_get_boolean (settings, "maximized");
|
|
|
|
win->fullscreen = g_settings_get_boolean (settings, "fullscreen");
|
|
|
|
g_object_unref (settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_application_window_init (DemoApplicationWindow *window)
|
2016-02-14 02:46:40 +00:00
|
|
|
{
|
2019-12-27 02:06:56 +00:00
|
|
|
GtkWidget *popover;
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
window->width = -1;
|
|
|
|
window->height = -1;
|
|
|
|
window->maximized = FALSE;
|
|
|
|
window->fullscreen = FALSE;
|
|
|
|
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (window));
|
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = gtk_popover_menu_new_from_model (window->toolmenu);
|
2020-02-03 03:52:15 +00:00
|
|
|
gtk_menu_button_set_popover (GTK_MENU_BUTTON (window->menubutton), popover);
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (window),
|
2016-02-14 02:46:40 +00:00
|
|
|
win_entries, G_N_ELEMENTS (win_entries),
|
2016-02-14 03:53:16 +00:00
|
|
|
window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_application_window_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
DemoApplicationWindow *window = (DemoApplicationWindow *)object;
|
|
|
|
|
|
|
|
demo_application_window_load_state (window);
|
|
|
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), window->width, window->height);
|
|
|
|
|
|
|
|
if (window->maximized)
|
|
|
|
gtk_window_maximize (GTK_WINDOW (window));
|
|
|
|
|
|
|
|
if (window->fullscreen)
|
|
|
|
gtk_window_fullscreen (GTK_WINDOW (window));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (demo_application_window_parent_class)->constructed (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-16 04:53:03 +00:00
|
|
|
demo_application_window_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
2016-02-14 03:53:16 +00:00
|
|
|
{
|
|
|
|
DemoApplicationWindow *window = (DemoApplicationWindow *)widget;
|
|
|
|
|
2018-08-16 04:53:03 +00:00
|
|
|
GTK_WIDGET_CLASS (demo_application_window_parent_class)->size_allocate (widget,
|
|
|
|
width,
|
|
|
|
height,
|
2018-03-31 19:02:28 +00:00
|
|
|
baseline);
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
if (!window->maximized && !window->fullscreen)
|
2020-12-05 10:44:51 +00:00
|
|
|
gtk_window_get_default_size (GTK_WINDOW (window), &window->width, &window->height);
|
2016-02-14 03:53:16 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 03:10:44 +00:00
|
|
|
static void
|
2018-03-20 11:05:26 +00:00
|
|
|
surface_state_changed (GtkWidget *widget)
|
2016-02-14 03:53:16 +00:00
|
|
|
{
|
|
|
|
DemoApplicationWindow *window = (DemoApplicationWindow *)widget;
|
2020-09-10 04:39:03 +00:00
|
|
|
GdkToplevelState new_state;
|
2016-02-14 03:53:16 +00:00
|
|
|
|
2020-03-01 01:44:19 +00:00
|
|
|
new_state = gdk_toplevel_get_state (GDK_TOPLEVEL (gtk_native_get_surface (GTK_NATIVE (widget))));
|
2020-09-10 04:39:03 +00:00
|
|
|
window->maximized = (new_state & GDK_TOPLEVEL_STATE_MAXIMIZED) != 0;
|
|
|
|
window->fullscreen = (new_state & GDK_TOPLEVEL_STATE_FULLSCREEN) != 0;
|
2017-12-15 03:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_application_window_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (demo_application_window_parent_class)->realize (widget);
|
|
|
|
|
2019-05-20 00:38:08 +00:00
|
|
|
g_signal_connect_swapped (gtk_native_get_surface (GTK_NATIVE (widget)), "notify::state",
|
2018-03-20 11:05:26 +00:00
|
|
|
G_CALLBACK (surface_state_changed), widget);
|
2017-12-15 03:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_application_window_unrealize (GtkWidget *widget)
|
|
|
|
{
|
2019-05-20 00:38:08 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (gtk_native_get_surface (GTK_NATIVE (widget)),
|
2018-03-20 11:05:26 +00:00
|
|
|
surface_state_changed, widget);
|
2016-02-14 03:53:16 +00:00
|
|
|
|
2017-12-15 03:10:44 +00:00
|
|
|
GTK_WIDGET_CLASS (demo_application_window_parent_class)->unrealize (widget);
|
2016-02-14 03:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-05 20:57:28 +00:00
|
|
|
demo_application_window_dispose (GObject *object)
|
2016-02-14 03:53:16 +00:00
|
|
|
{
|
2020-05-05 20:57:28 +00:00
|
|
|
DemoApplicationWindow *window = (DemoApplicationWindow *)object;
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
demo_application_window_store_state (window);
|
|
|
|
|
2022-07-07 13:09:35 +00:00
|
|
|
gtk_widget_dispose_template (GTK_WIDGET (window), demo_application_window_get_type ());
|
2022-07-06 12:23:54 +00:00
|
|
|
|
2020-05-05 20:57:28 +00:00
|
|
|
G_OBJECT_CLASS (demo_application_window_parent_class)->dispose (object);
|
2016-02-14 02:46:40 +00:00
|
|
|
}
|
2012-01-24 05:07:03 +00:00
|
|
|
|
2016-02-14 02:46:40 +00:00
|
|
|
static void
|
|
|
|
demo_application_window_class_init (DemoApplicationWindowClass *class)
|
|
|
|
{
|
2016-02-14 03:53:16 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
2016-02-14 02:46:40 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
2016-02-14 03:53:16 +00:00
|
|
|
object_class->constructed = demo_application_window_constructed;
|
2020-05-05 20:57:28 +00:00
|
|
|
object_class->dispose = demo_application_window_dispose;
|
2016-02-14 03:53:16 +00:00
|
|
|
|
|
|
|
widget_class->size_allocate = demo_application_window_size_allocate;
|
2017-12-15 03:10:44 +00:00
|
|
|
widget_class->realize = demo_application_window_realize;
|
|
|
|
widget_class->unrealize = demo_application_window_unrealize;
|
2016-02-14 03:53:16 +00:00
|
|
|
|
2016-02-14 14:39:15 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/application_demo/application.ui");
|
2016-02-14 02:46:40 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, message);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, infobar);
|
2016-02-14 03:53:16 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, status);
|
2016-02-14 02:46:40 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, buffer);
|
2020-02-03 03:52:15 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, menubutton);
|
2016-02-14 03:53:16 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, toolmenu);
|
2016-02-14 02:46:40 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, clicked_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, update_statusbar);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, mark_set_callback);
|
|
|
|
}
|
2012-01-14 23:22:33 +00:00
|
|
|
|
2016-02-14 02:46:40 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkApplication *app;
|
|
|
|
|
|
|
|
app = GTK_APPLICATION (g_object_new (demo_application_get_type (),
|
2019-04-01 22:49:09 +00:00
|
|
|
"application-id", "org.gtk.Demo4.App",
|
2016-02-14 03:53:16 +00:00
|
|
|
"flags", G_APPLICATION_HANDLES_OPEN,
|
2016-02-14 02:46:40 +00:00
|
|
|
NULL));
|
2012-01-14 23:22:33 +00:00
|
|
|
|
2016-02-14 02:46:40 +00:00
|
|
|
return g_application_run (G_APPLICATION (app), 0, NULL);
|
2012-01-14 23:22:33 +00:00
|
|
|
}
|