[gnome-devel-docs] demos: GtkMenubutton example (in C)
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] demos: GtkMenubutton example (in C)
- Date: Tue, 2 Jul 2013 05:49:22 +0000 (UTC)
commit 88c8ef8fbbf13a40bc09cfc85cc01acf041b8321
Author: Tiffany Ann Antopolski <tiffany antopolski gmail com>
Date: Tue Jul 2 01:13:49 2013 -0400
demos: GtkMenubutton example (in C)
platform-demos/C/menubutton.c.page | 43 ++++++++++++++
platform-demos/C/samples/menubutton.c | 100 +++++++++++++++++++++++++++++++++
platform-demos/Makefile.am | 2 +
3 files changed, 145 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/menubutton.c.page b/platform-demos/C/menubutton.c.page
new file mode 100644
index 0000000..77c7d7a
--- /dev/null
+++ b/platform-demos/C/menubutton.c.page
@@ -0,0 +1,43 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ type="guide" style="task"
+ id="menubutton.c">
+ <info>
+ <title type="text">MenuButton</title>
+ <link type="guide" xref="beginner.c#buttons"/>
+ <revision version="0.1" date="2013-07-01" status="review"/>
+
+ <credit type="author copyright">
+ <name>Tiffany Antopolski</name>
+ <email>tiffany antopolski gmail com</email>
+ <years>2013</years>
+ </credit>
+
+ <desc>A widget that shows a menu when clicked on</desc>
+ </info>
+
+ <title>MenuButton</title>
+ <media type="image" mime="image/png" src="media/menubutton.png"/>
+ <p>The GtkMenuButton widget is used to display a menu when clicked on. This menu can be provided either as
a GtkMenu, or an abstract GMenuModel. The GtkMenuButton widget can hold any valid child widget. That is, it
can hold almost any other standard GtkWidget. The most commonly used child is the provided GtkArrow.</p>
+
+ <note><p>You need to be running GNOME 3.6 or later for the MenuButton to work.</p></note>
+
+ <links type="section" />
+
+ <section id="code">
+ <title>Code used to generate this example</title>
+ <code mime="text/x-csrc" style="numbered"><xi:include href="samples/menubutton.c"
parse="text"><xi:fallback/></xi:include></code>
+ </section>
+
+ <section id="references">
+ <title>API References</title>
+ <p>In this sample we used the following:</p>
+ <list>
+ <item><p><link
href="http://developer.gnome.org/gtk3/unstable/GtkMenuButton.html">GtkMenuButton</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkMenu.html">GtkMenu</link></p></item>
+ <item><p><link
href="https://developer.gnome.org/gio/unstable/GMenuModel.html">GMenuModel</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkArrow.html">GtkArrow</link></p></item>
+ </list>
+ </section>
+</page>
diff --git a/platform-demos/C/samples/menubutton.c b/platform-demos/C/samples/menubutton.c
new file mode 100644
index 0000000..efa94b7
--- /dev/null
+++ b/platform-demos/C/samples/menubutton.c
@@ -0,0 +1,100 @@
+#include <gtk/gtk.h>
+
+/* Callback function for the undo action */
+static void
+about_callback (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ g_print ("You clicked \"About\"\n");
+}
+
+static void
+activate (GtkApplication *app,
+ gpointer user_data)
+{
+ GMenu *submenu;
+ GtkWidget *grid;
+ GMenu *menumodel;
+ GtkWidget *window;
+ GtkWidget *menubutton;
+ GSimpleAction *about_action;
+
+ window = gtk_application_window_new (app);
+ grid = gtk_grid_new ();
+
+ gtk_window_set_title (GTK_WINDOW (window), "MenuButton Example");
+ gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
+
+ menubutton = gtk_menu_button_new ();
+ gtk_widget_set_size_request (menubutton, 80, 35);
+
+ gtk_grid_attach (GTK_GRID (grid), menubutton, 0, 0, 1, 1);
+ gtk_container_add (GTK_CONTAINER (window), grid);
+
+ menumodel = g_menu_new ();
+ g_menu_append (menumodel, "New", "app.new");
+ g_menu_append (menumodel, "About", "win.about");
+
+ submenu = g_menu_new ();
+ g_menu_append_submenu (menumodel, "Other", G_MENU_MODEL (submenu));
+ g_menu_append (submenu, "Quit", "app.quit");
+ gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menubutton), G_MENU_MODEL (menumodel));
+
+ about_action = g_simple_action_new ("about", NULL);
+ g_signal_connect (about_action, "activate", G_CALLBACK (about_callback),
+ GTK_WINDOW (window));
+ g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (about_action));
+
+ gtk_widget_show_all (window);
+}
+
+
+static void
+new_callback (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ g_print ("You clicked \"New\"\n");
+}
+
+static void
+quit_callback (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GApplication *application = user_data;
+
+ g_application_quit (application);
+}
+
+static void
+startup (GApplication *app,
+ gpointer user_data)
+{
+ GSimpleAction *new_action;
+ GSimpleAction *quit_action;
+
+ new_action = g_simple_action_new ("new", NULL);
+ g_signal_connect (new_action, "activate", G_CALLBACK (new_callback), app);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (new_action));
+
+ quit_action = g_simple_action_new ("quit", NULL);
+ g_signal_connect (quit_action, "activate", G_CALLBACK (quit_callback), app);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (quit_action));
+}
+
+
+int
+main (int argc, char **argv)
+{
+ GtkApplication *app;
+ int status;
+
+ app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
+ g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+ g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
+ status = g_application_run (G_APPLICATION (app), argc, argv);
+ g_object_unref (app);
+ return status;
+}
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 69ab4c4..594cb71 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -118,6 +118,7 @@ demo_sources = \
samples/linkbutton.js \
samples/linkbutton.py \
samples/linkbutton.vala \
+ samples/menubutton.c \
samples/menubutton.js \
samples/menubutton.py \
samples/menubutton.vala \
@@ -391,6 +392,7 @@ HELP_FILES = \
menubar.c.page \
menubar.py.page \
menubar.vala.page \
+ menubutton.c.page \
menubutton.js.page \
menubutton.py.page \
menubutton.vala.page \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]