[gnome-devel-docs] C tutorial samples: CheckButton Example



commit c8cb4718730635793afe7219f4c7aab21c654062
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Thu May 31 17:26:41 2012 -0400

    C tutorial samples: CheckButton Example

 platform-demos/C/checkbutton.c.page    |   30 ++++++++++++++++++++
 platform-demos/C/samples/checkbutton.c |   46 ++++++++++++++++++++++++++++++++
 platform-demos/Makefile.am             |    2 +
 3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/checkbutton.c.page b/platform-demos/C/checkbutton.c.page
new file mode 100644
index 0000000..52e5700
--- /dev/null
+++ b/platform-demos/C/checkbutton.c.page
@@ -0,0 +1,30 @@
+<?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="checkbutton.c">
+  <info>
+    <link type="guide" xref="beginner.c#buttons"/>
+    <revision version="0.1" date="2012-05-31" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Tiffany Antopolski</name>
+      <email>tiffany antpoolski gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>Create widgets with a discrete ToggleButton</desc>
+  </info>
+
+  <title>CheckButton</title>
+  <media type="image" mime="image/png" src="media/checkbutton.png"/>
+  <p>This CheckButton toggles the title.</p>
+
+<code mime="text/x-csrc" style="numbered"><xi:include href="samples/checkbutton.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.2/GtkCheckButton.html";>GtkCheckButton</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/checkbutton.c b/platform-demos/C/samples/checkbutton.c
new file mode 100644
index 0000000..feec092
--- /dev/null
+++ b/platform-demos/C/samples/checkbutton.c
@@ -0,0 +1,46 @@
+#include <gtk/gtk.h>
+
+/* signal handler for "toggled" signal of the CheckButton */
+static void
+toggled_cb (GtkToggleButton *toggle_button,
+            gpointer         user_data)
+{
+  GtkWindow *window = user_data;
+
+  if (gtk_toggle_button_get_active (toggle_button))
+      gtk_window_set_title (window, "CheckButton Example");
+  else
+      gtk_window_set_title (window, "");
+}
+
+static void
+activate (GtkApplication *app,
+          gpointer        user_data)
+{
+  GtkWidget *window;
+  GtkWidget *checkbutton;
+
+  window = gtk_application_window_new (app);
+  gtk_window_set_title (GTK_WINDOW (window), "CheckButton Example");
+  gtk_window_set_default_size (GTK_WINDOW (window), 300, 100);
+
+  checkbutton = gtk_check_button_new_with_label ("Show Title");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), TRUE);
+  g_signal_connect (GTK_TOGGLE_BUTTON (checkbutton), "toggled", G_CALLBACK (toggled_cb), window);
+  gtk_container_add (GTK_CONTAINER (window), checkbutton);
+  gtk_widget_show_all (window);
+}
+
+int
+main (int argc, char **argv)
+{
+  GtkApplication *app;
+  int status;
+
+  app = gtk_application_new ("org.example.checkbutton", 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 f77a378..499bf5a 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -27,6 +27,7 @@ demo_sources = \
 	samples/button.js			\
 	samples/button.py			\
 	samples/button.vala			\
+	samples/checkbutton.c			\
 	samples/checkbutton.py			\
 	samples/checkbutton.vala		\
 	samples/combobox.vala			\
@@ -143,6 +144,7 @@ DOC_PAGES =				\
 	button.py.page			\
 	button.vala.page		\
 	c.page				\
+	checkbutton.c.page		\
 	checkbutton.py.page		\
 	checkbutton.vala.page		\
 	combobox.vala.page		\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]