summaryrefslogtreecommitdiff
path: root/examples/application6
diff options
context:
space:
mode:
Diffstat (limited to 'examples/application6')
-rw-r--r--examples/application6/Makefile.am47
-rw-r--r--examples/application6/app-menu.ui19
-rw-r--r--examples/application6/exampleapp.c112
-rw-r--r--examples/application6/exampleapp.gresource.xml8
-rw-r--r--examples/application6/exampleapp.h19
-rw-r--r--examples/application6/exampleappprefs.c71
-rw-r--r--examples/application6/exampleappprefs.h20
-rw-r--r--examples/application6/exampleappwin.c108
-rw-r--r--examples/application6/exampleappwin.h22
-rw-r--r--examples/application6/main.c15
-rw-r--r--examples/application6/org.gtk.exampleapp.gschema.xml20
-rw-r--r--examples/application6/prefs.ui82
-rw-r--r--examples/application6/window.ui31
13 files changed, 574 insertions, 0 deletions
diff --git a/examples/application6/Makefile.am b/examples/application6/Makefile.am
new file mode 100644
index 0000000000..b4583fe2d2
--- /dev/null
+++ b/examples/application6/Makefile.am
@@ -0,0 +1,47 @@
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/gdk \
+ -I$(top_builddir)/gdk \
+ $(GTK_DEBUG_FLAGS) \
+ $(GTK_DEP_CFLAGS)
+
+LDADD = \
+ $(top_builddir)/gtk/libgtk-3.la \
+ $(top_builddir)/gdk/libgdk-3.la \
+ $(GTK_DEP_LIBS)
+
+
+noinst_PROGRAMS = exampleapp
+
+exampleapp_SOURCES = \
+ main.c \
+ exampleapp.c exampleapp.h \
+ exampleappwin.c exampleappwin.h \
+ exampleappprefs.c exampleappprefs.h \
+ resources.c
+
+BUILT_SOURCES = \
+ resources.c \
+ gschemas.compiled
+
+resources.c: exampleapp.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/exampleapp.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/exampleapp.gresource.xml \
+ --target=$@ --sourcedir=$(srcdir) --generate-source
+
+gsettings_SCHEMAS = \
+ org.gtk.exampleapp.gschema.xml
+
+@GSETTINGS_RULES@
+
+gschemas.compiled: org.gtk.exampleapp.gschema.xml
+ $(GLIB_COMPILE_SCHEMAS) .
+
+EXTRA_DIST = \
+ window.ui \
+ app-menu.ui \
+ prefs.ui \
+ exampleapp.gresource.xml \
+ org.gtk.exampleapp.gschema.xml
+
+CLEANFILES = \
+ gschemas.compiled
diff --git a/examples/application6/app-menu.ui b/examples/application6/app-menu.ui
new file mode 100644
index 0000000000..b0eddb65e5
--- /dev/null
+++ b/examples/application6/app-menu.ui
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">app.preferences</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/examples/application6/exampleapp.c b/examples/application6/exampleapp.c
new file mode 100644
index 0000000000..633216c692
--- /dev/null
+++ b/examples/application6/exampleapp.c
@@ -0,0 +1,112 @@
+#include <gtk/gtk.h>
+
+#include "exampleapp.h"
+#include "exampleappwin.h"
+#include "exampleappprefs.h"
+
+struct ExampleApp {
+ GtkApplication parent;
+};
+
+struct ExampleAppClass {
+ GtkApplicationClass parent_class;
+};
+
+G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
+
+static void
+example_app_init (ExampleApp *app)
+{
+}
+
+static void
+preferences_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ ExampleAppPrefs *prefs;
+ GtkWindow *win;
+
+ win = gtk_application_get_active_window (GTK_APPLICATION (app));
+ prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
+ gtk_window_present (GTK_WINDOW (prefs));
+}
+
+static void
+quit_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ g_application_quit (G_APPLICATION (app));
+}
+
+static GActionEntry app_entries[] = {
+ { "preferences", preferences_activated, NULL, NULL, NULL },
+ { "quit", quit_activated, NULL, NULL, NULL }
+};
+
+static void
+example_app_startup (GApplication *app)
+{
+ GtkBuilder *builder;
+ GMenuModel *app_menu;
+
+ G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ app_entries, G_N_ELEMENTS (app_entries),
+ app);
+
+ builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
+ app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
+ gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
+ g_object_unref (builder);
+}
+
+static void
+example_app_activate (GApplication *app)
+{
+ ExampleAppWindow *win;
+
+ win = example_app_window_new (EXAMPLE_APP (app));
+ gtk_window_present (GTK_WINDOW (win));
+}
+
+static void
+example_app_open (GApplication *app,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
+{
+ GList *windows;
+ ExampleAppWindow *win;
+ int i;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+ if (windows)
+ win = EXAMPLE_APP_WINDOW (windows->data);
+ else
+ win = example_app_window_new (EXAMPLE_APP (app));
+
+ for (i = 0; i < n_files; i++)
+ example_app_window_open (win, files[i]);
+
+ gtk_window_present (GTK_WINDOW (win));
+}
+
+static void
+example_app_class_init (ExampleAppClass *class)
+{
+ G_APPLICATION_CLASS (class)->startup = example_app_startup;
+ G_APPLICATION_CLASS (class)->activate = example_app_activate;
+ G_APPLICATION_CLASS (class)->open = example_app_open;
+}
+
+ExampleApp *
+example_app_new (void)
+{
+ return g_object_new (EXAMPLE_APP_TYPE,
+ "application-id", "org.gtk.exampleapp",
+ "flags", G_APPLICATION_HANDLES_OPEN,
+ NULL);
+}
diff --git a/examples/application6/exampleapp.gresource.xml b/examples/application6/exampleapp.gresource.xml
new file mode 100644
index 0000000000..797688586b
--- /dev/null
+++ b/examples/application6/exampleapp.gresource.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gtk/exampleapp">
+ <file preprocess="xml-stripblanks">window.ui</file>
+ <file preprocess="xml-stripblanks">app-menu.ui</file>
+ <file preprocess="xml-stripblanks">prefs.ui</file>
+ </gresource>
+</gresources>
diff --git a/examples/application6/exampleapp.h b/examples/application6/exampleapp.h
new file mode 100644
index 0000000000..8b51c598ea
--- /dev/null
+++ b/examples/application6/exampleapp.h
@@ -0,0 +1,19 @@
+#ifndef __EXAMPLEAPP_H
+#define __EXAMPLEAPP_H
+
+#include <gtk/gtk.h>
+
+
+#define EXAMPLE_APP_TYPE (example_app_get_type ())
+#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
+
+
+typedef struct ExampleApp ExampleApp;
+typedef struct ExampleAppClass ExampleAppClass;
+
+
+GType example_app_get_type (void);
+ExampleApp *example_app_new (void);
+
+
+#endif /* __EXAMPLEAPP_H */
diff --git a/examples/application6/exampleappprefs.c b/examples/application6/exampleappprefs.c
new file mode 100644
index 0000000000..75f2ccb164
--- /dev/null
+++ b/examples/application6/exampleappprefs.c
@@ -0,0 +1,71 @@
+#include <gtk/gtk.h>
+
+#include "exampleapp.h"
+#include "exampleappwin.h"
+#include "exampleappprefs.h"
+
+struct ExampleAppPrefs {
+ GtkDialog parent;
+};
+
+struct ExampleAppPrefsClass {
+ GtkDialogClass parent_class;
+};
+
+typedef struct ExampleAppPrefsPrivate ExampleAppPrefsPrivate;
+struct ExampleAppPrefsPrivate {
+ GSettings *settings;
+ GtkWidget *font;
+ GtkWidget *transition;
+ GtkWidget *close;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
+
+static void
+example_app_prefs_init (ExampleAppPrefs *prefs)
+{
+ ExampleAppPrefsPrivate *priv;
+
+ priv = example_app_prefs_get_instance_private (prefs);
+ gtk_widget_init_template (GTK_WIDGET (prefs));
+ priv->settings = g_settings_new ("org.gtk.exampleapp");
+
+ g_settings_bind (priv->settings, "font",
+ priv->font, "font",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "transition",
+ priv->transition, "active-id",
+ G_SETTINGS_BIND_DEFAULT);
+ g_signal_connect_swapped (priv->close, "clicked",
+ G_CALLBACK (gtk_widget_destroy), prefs);
+}
+
+static void
+example_app_prefs_dispose (GObject *object)
+{
+ ExampleAppPrefsPrivate *priv;
+
+ priv = example_app_prefs_get_instance_private (EXAMPLE_APP_PREFS (object));
+ g_clear_object (&priv->settings);
+
+ G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
+}
+
+static void
+example_app_prefs_class_init (ExampleAppPrefsClass *class)
+{
+ G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
+
+ gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
+ "/org/gtk/exampleapp/prefs.ui");
+ gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, font);
+ gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, transition);
+ gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, close);
+}
+
+ExampleAppPrefs *
+example_app_prefs_new (ExampleAppWindow *win)
+{
+ return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, NULL);
+}
diff --git a/examples/application6/exampleappprefs.h b/examples/application6/exampleappprefs.h
new file mode 100644
index 0000000000..fe32a67c1a
--- /dev/null
+++ b/examples/application6/exampleappprefs.h
@@ -0,0 +1,20 @@
+#ifndef __EXAMPLEAPPPREFS_H
+#define __EXAMPLEAPPPREFS_H
+
+#include <gtk/gtk.h>
+#include "exampleappwin.h"
+
+
+#define EXAMPLE_APP_PREFS_TYPE (example_app_prefs_get_type ())
+#define EXAMPLE_APP_PREFS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_PREFS_TYPE, ExampleAppPrefs))
+
+
+typedef struct ExampleAppPrefs ExampleAppPrefs;
+typedef struct ExampleAppPrefsClass ExampleAppPrefsClass;
+
+
+GType example_app_prefs_get_type (void);
+ExampleAppPrefs *example_app_prefs_new (ExampleAppWindow *win);
+
+
+#endif /* __EXAMPLEAPPPREFS_H */
diff --git a/examples/application6/exampleappwin.c b/examples/application6/exampleappwin.c
new file mode 100644
index 0000000000..26790f0524
--- /dev/null
+++ b/examples/application6/exampleappwin.c
@@ -0,0 +1,108 @@
+#include "exampleapp.h"
+#include "exampleappwin.h"
+#include <gtk/gtk.h>
+
+struct ExampleAppWindow {
+ GtkApplicationWindow parent;
+};
+
+struct ExampleAppWindowClass {
+ GtkApplicationWindowClass parent_class;
+};
+
+typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate;
+
+struct ExampleAppWindowPrivate {
+ GSettings *settings;
+ GtkWidget *stack;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
+
+static void
+example_app_window_init (ExampleAppWindow *win)
+{
+ ExampleAppWindowPrivate *priv;
+
+ priv = example_app_window_get_instance_private (win);
+ gtk_widget_init_template (GTK_WIDGET (win));
+ priv->settings = g_settings_new ("org.gtk.exampleapp");
+
+ g_settings_bind (priv->settings, "transition",
+ priv->stack, "transition-type",
+ G_SETTINGS_BIND_DEFAULT);
+}
+
+static void
+example_app_window_dispose (GObject *object)
+{
+ ExampleAppWindow *win;
+ ExampleAppWindowPrivate *priv;
+
+ win = EXAMPLE_APP_WINDOW (object);
+ priv = example_app_window_get_instance_private (win);
+
+ g_clear_object (&priv->settings);
+
+ G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
+}
+
+static void
+example_app_window_class_init (ExampleAppWindowClass *class)
+{
+ G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
+
+ gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
+ "/org/gtk/exampleapp/window.ui");
+ gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
+}
+
+ExampleAppWindow *
+example_app_window_new (ExampleApp *app)
+{
+ return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
+}
+
+void
+example_app_window_open (ExampleAppWindow *win,
+ GFile *file)
+{
+ ExampleAppWindowPrivate *priv;
+ gchar *basename;
+ GtkWidget *scrolled, *view;
+ gchar *contents;
+ gsize length;
+ GtkTextBuffer *buffer;
+ GtkTextTag *tag;
+ GtkTextIter start_iter, end_iter;
+
+ priv = example_app_window_get_instance_private (win);
+ basename = g_file_get_basename (file);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (scrolled);
+ gtk_widget_set_hexpand (scrolled, TRUE);
+ gtk_widget_set_vexpand (scrolled, TRUE);
+ view = gtk_text_view_new ();
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
+ gtk_widget_show (view);
+ gtk_container_add (GTK_CONTAINER (scrolled), view);
+ gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+
+ if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
+ gtk_text_buffer_set_text (buffer, contents, length);
+ g_free (contents);
+ }
+
+ tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
+ g_settings_bind (priv->settings, "font", tag, "font", G_SETTINGS_BIND_DEFAULT);
+
+ gtk_text_buffer_get_start_iter (buffer, &start_iter);
+ gtk_text_buffer_get_end_iter (buffer, &end_iter);
+ gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
+
+ g_free (basename);
+}
diff --git a/examples/application6/exampleappwin.h b/examples/application6/exampleappwin.h
new file mode 100644
index 0000000000..11ff3c27a7
--- /dev/null
+++ b/examples/application6/exampleappwin.h
@@ -0,0 +1,22 @@
+#ifndef __EXAMPLEAPPWIN_H
+#define __EXAMPLEAPPWIN_H
+
+#include <gtk/gtk.h>
+#include "exampleapp.h"
+
+
+#define EXAMPLE_APP_WINDOW_TYPE (example_app_window_get_type ())
+#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
+
+
+typedef struct ExampleAppWindow ExampleAppWindow;
+typedef struct ExampleAppWindowClass ExampleAppWindowClass;
+
+
+GType example_app_window_get_type (void);
+ExampleAppWindow *example_app_window_new (ExampleApp *app);
+void example_app_window_open (ExampleAppWindow *win,
+ GFile *file);
+
+
+#endif /* __EXAMPLEAPPWIN_H */
diff --git a/examples/application6/main.c b/examples/application6/main.c
new file mode 100644
index 0000000000..7ce327aa0b
--- /dev/null
+++ b/examples/application6/main.c
@@ -0,0 +1,15 @@
+#include <gtk/gtk.h>
+#include <exampleapp.h>
+
+int
+main (int argc, char *argv[])
+{
+ /* Since this example is running uninstalled,
+ * we have to help it find its schema. This
+ * is *not* necessary in properly installed
+ * application.
+ */
+ g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
+
+ return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
+}
diff --git a/examples/application6/org.gtk.exampleapp.gschema.xml b/examples/application6/org.gtk.exampleapp.gschema.xml
new file mode 100644
index 0000000000..89718c480c
--- /dev/null
+++ b/examples/application6/org.gtk.exampleapp.gschema.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <enum id="org.gtk.exampleapp.Transition">
+ <value value="0" nick="none"/>
+ <value value="1" nick="crossfade"/>
+ <value value="6" nick="slide-left-right"/>
+ </enum>
+ <schema path="/org/gtk/exampleapp/" id="org.gtk.exampleapp">
+ <key name="font" type="s">
+ <default>'Monospace 12'</default>
+ <summary>Font</summary>
+ <description>The font to be used for content.</description>
+ </key>
+ <key name="transition" enum="org.gtk.exampleapp.Transition">
+ <default>'none'</default>
+ <summary>Transition</summary>
+ <description>The transition to use when switching tabs.</description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/examples/application6/prefs.ui b/examples/application6/prefs.ui
new file mode 100644
index 0000000000..4e846b8e15
--- /dev/null
+++ b/examples/application6/prefs.ui
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <template class="ExampleAppPrefs" parent="GtkDialog">
+ <property name="title" translatable="yes">Preferences</property>
+ <property name="resizable">False</property>
+ <property name="modal">True</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="vbox">
+ <child>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="margin">6</property>
+ <property name="row-spacing">12</property>
+ <property name="column-spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="fontlabel">
+ <property name="visible">True</property>
+ <property name="label">_Font:</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">font</property>
+ <property name="xalign">1</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFontButton" id="font">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="transitionlabel">
+ <property name="visible">True</property>
+ <property name="label">_Transition:</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">transition</property>
+ <property name="xalign">1</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="transition">
+ <property name="visible">True</property>
+ <items>
+ <item translatable="yes" id="none">None</item>
+ <item translatable="yes" id="crossfade">Fade</item>
+ <item translatable="yes" id="slide-left-right">Slide</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="action_area">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="close">
+ <property name="visible">True</property>
+ <property name="label">_Close</property>
+ <property name="use-underline">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/examples/application6/window.ui b/examples/application6/window.ui
new file mode 100644
index 0000000000..d90c3f618c
--- /dev/null
+++ b/examples/application6/window.ui
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <template class="ExampleAppWindow" parent="GtkApplicationWindow">
+ <property name="title" translatable="yes">Example Application</property>
+ <property name="default-width">600</property>
+ <property name="default-height">400</property>
+ <child>
+ <object class="GtkBox" id="content_box">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkHeaderBar" id="header">
+ <property name="visible">True</property>
+ <child type="title">
+ <object class="GtkStackSwitcher" id="tabs">
+ <property name="visible">True</property>
+ <property name="stack">stack</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkStack" id="stack">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>