[gnome-devel-docs] platform-demos: C: Combobox sample and page
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] platform-demos: C: Combobox sample and page
- Date: Mon, 1 Jul 2013 06:37:47 +0000 (UTC)
commit dff96e3ccfca131f166de2cfc4c0ff19cf4e533e
Author: Monica Kochofar <monicakochofar gmail com>
Date: Mon Jul 1 02:22:43 2013 -0400
platform-demos: C: Combobox sample and page
bug #68228
platform-demos/C/combobox.c.page | 34 +++++++++++
platform-demos/C/samples/combobox.c | 105 +++++++++++++++++++++++++++++++++++
platform-demos/Makefile.am | 2 +
3 files changed, 141 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/combobox.c.page b/platform-demos/C/combobox.c.page
new file mode 100644
index 0000000..a715c4c
--- /dev/null
+++ b/platform-demos/C/combobox.c.page
@@ -0,0 +1,34 @@
+<?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="combobox.c">
+ <info>
+ <title type="text">ComboBox (C)</title>
+ <link type="guide" xref="beginner.c#menu-combo-toolbar"/>
+ <revision version="0.1" date="2012-08-20" status="draft"/>
+
+ <credit type="author copyright">
+ <name>Monica Kochofar</name>
+ <email>monicakochofar gmail com</email>
+ <years>2012</years>
+ </credit>
+
+ <desc>A widget used to choose from a list of items</desc>
+ </info>
+
+ <title>ComboBox</title>
+ <media type="image" mime="image/png" src="media/combobox.png"/>
+ <p>This ComboBox prints to the terminal when you change your selection.</p>
+
+ <code mime="text/x-csrc" style="numbered">
+<xi:include href="samples/combobox.c" parse="text"><xi:fallback/></xi:include></code>
+<p>
+ In this sample we used the following:
+</p>
+<list>
+ <item><p><link
href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link></p></item>
+ <item><p><link
href="http://developer.gnome.org/gtk3/stable/GtkComboBoxText.html">GtkComboBoxText</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/combobox.c b/platform-demos/C/samples/combobox.c
new file mode 100644
index 0000000..00471c8
--- /dev/null
+++ b/platform-demos/C/samples/combobox.c
@@ -0,0 +1,105 @@
+#include <gtk/gtk.h>
+
+
+
+/* This is the callback function. It is a handler function which reacts to the
+ * signal. In this case, if the row selected is not the first one of the
+ * ComboBox, we write its value in the terminal for the user.
+ */
+static void
+on_changed (GtkComboBox *widget,
+ gpointer user_data)
+{
+ GtkComboBox *combo_box = widget;
+
+ /* This will return the index of the currently active
+ * item within the ComboBox.
+ */
+ gint value = gtk_combo_box_get_active (combo_box);
+
+ /* Equate the index to the list of the choices you put up and
+ * print what happened to the user.
+ */
+ switch (value) {
+ case 1:
+ g_print ("You chose Fedora.\n");
+ break;
+ case 2:
+ g_print ("You chose Mint.\n");
+ break;
+ case 3:
+ g_print ("You chose Suse.\n");
+ break;
+ default:
+ /* Nothing else will happen in the terminal otherwise */
+ break;
+ }
+}
+
+
+
+static void
+activate (GtkApplication *app,
+ gpointer user_data)
+{
+ GtkWidget *window;
+ GtkWidget *combo_box;
+ GtkWidget *view;
+
+ /* Create a window with a title, border width, and a default size. Setting the
+ * size to -1 means to use the "natural" default size.
+ * (the size request of the window)
+ */
+ window = gtk_application_window_new (app);
+ gtk_window_set_title (GTK_WINDOW (window), "Welcome to GNOME");
+ gtk_window_set_default_size (GTK_WINDOW (window), 200, -1);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+ /* Create the combo box and append your string values to it. Note that the
+ * values in our combo box are to be this:
+ * @ Position 0 - "Select distribution"
+ * @ Position 1 - "Fedora"
+ * @ Position 2 - "Mint"
+ * @ Position 3 - "Suse"
+ * (For a more advanced approach, try putting these into a string array)
+ * Furthermore, we give the gtk_combo_box_text_append function a NULL id for
+ * the parameter as it is not needed.
+ */
+ combo_box = gtk_combo_box_text_new ();
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo_box), NULL, "Select distribution");
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo_box), NULL, "Fedora");
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo_box), NULL, "Mint");
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo_box), NULL, "Suse");
+
+ /* Choose to set the first row as the active one by default, from the beginning */
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
+
+ /* Connect the signal emitted when a row is selected to the appropriate
+ * callback function.
+ */
+ g_signal_connect (combo_box,
+ "changed",
+ G_CALLBACK (on_changed),
+ NULL);
+
+ /* Add it to the window */
+ gtk_container_add (GTK_CONTAINER (window), combo_box);
+
+ gtk_widget_show_all (window);
+}
+
+
+
+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);
+ 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 7d186bf..69ab4c4 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -45,6 +45,7 @@ demo_sources = \
samples/colorbutton.py \
samples/colorbutton.vala \
samples/comboboxtext.js \
+ samples/combobox.c
samples/combobox.js \
samples/combobox.py \
samples/combobox.vala \
@@ -322,6 +323,7 @@ HELP_FILES = \
colorbutton.py.page \
colorbutton.vala.page \
comboboxtext.js.page \
+ combobox.c.page \
combobox.js.page \
combobox.py.page \
combobox.vala.page \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]