[gnome-devel-docs] tutorials C: Button sample and page, includes added comments and trivial change in coding



commit b302d055bdb9083571dba5e91095f95bb5a65470
Author: Monica Kochofar <monicakochofar gmail com>
Date:   Fri Jun 1 00:40:52 2012 -0400

    tutorials C: Button sample and page, includes added comments and trivial change in coding

 platform-demos/C/button.c.page    |   35 ++++++++++++++++++++++
 platform-demos/C/samples/button.c |   58 +++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/button.c.page b/platform-demos/C/button.c.page
new file mode 100644
index 0000000..eefc5b7
--- /dev/null
+++ b/platform-demos/C/button.c.page
@@ -0,0 +1,35 @@
+<?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="button.c">
+  <info>
+    <link type="guide" xref="beginner.c#buttons"/>
+    <revision version="0.1" date="2012-05-30" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Monica Kochofar</name>
+      <email>monicakochofar gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A button widget which emits a signal when clicked</desc>
+  </info>
+
+  <title>Button Widget</title>
+
+  <media type="image" mime="image/png" src="media/button.png"/>
+  <p>A button widget connected to a callback function</p>
+
+      <code mime="text/x-csrc" style="numbered">
+<xi:include href="samples/button.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/GtkButton.html";>GtkButton</link></p></item>
+  <item><p><link href="http://developer.gnome.org/glib/stable/glib-Unicode-Manipulation.html#g-utf8-strreverse";>Unicode Manipulation</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/button.c b/platform-demos/C/samples/button.c
new file mode 100644
index 0000000..663da54
--- /dev/null
+++ b/platform-demos/C/samples/button.c
@@ -0,0 +1,58 @@
+#include <gtk/gtk.h>
+
+/*This is the callback function. It is a handler function which reacts to the signal. 
+In this case, it will cause the button label's string to reverse.*/
+
+static void 
+button_clicked (GtkButton *button,
+                gpointer   user_data)
+{
+  const char *old_label;
+  char *new_label;
+  
+  old_label = gtk_button_get_label (button);
+  new_label = g_utf8_strreverse (old_label, -1);
+  
+  gtk_button_set_label (button, new_label);
+  g_free (new_label);
+}
+
+
+static void
+activate (GtkApplication *app,
+          gpointer        user_data)
+{
+  GtkWidget *window;
+  GtkWidget *button;
+  
+  /*Create a window with a title and a default size*/
+  window = gtk_application_window_new (app);
+
+  gtk_window_set_title (GTK_WINDOW (window), "GNOME Button");
+  gtk_window_set_default_size (GTK_WINDOW (window), 250, 50);
+  
+  /*create a button with a label, and add it to the window*/
+  button = gtk_button_new_with_label ("Click Me");
+  gtk_container_add (GTK_CONTAINER (window), button);
+
+  /*connecting the clicked signal to the callback*/
+  g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (button_clicked), G_OBJECT (window));
+
+  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;
+}



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