[gnome-devel-docs] tutorials C: Entry sample and page



commit 30082a0eae42b85e43e459c6a6f6c44b973a4e31
Author: Monica Kochofar <monicakochofar gmail com>
Date:   Thu Jun 14 17:04:05 2012 -0400

    tutorials C: Entry sample and page

 platform-demos/C/entry.c.page    |   34 ++++++++++++++++++++++++
 platform-demos/C/samples/entry.c |   52 ++++++++++++++++++++++++++++++++++++++
 platform-demos/Makefile.am       |    2 +
 3 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/entry.c.page b/platform-demos/C/entry.c.page
new file mode 100644
index 0000000..fec9286
--- /dev/null
+++ b/platform-demos/C/entry.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="entry.c">
+  <info>
+    <link type="guide" xref="beginner.c#entry"/>
+    <revision version="0.1" date="2012-06-14" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Monica Kochofar</name>
+      <email>monicakochofar gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A single line text entry field</desc>
+  </info>
+
+  <title>Entry</title>
+
+  <media type="image" mime="image/png" src="media/entry.png"/>
+  <p>This application greets you in the terminal.</p>
+
+      <code mime="text/x-csrc" style="numbered">
+<xi:include href="samples/entry.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/GtkEntry.html";>GtkEntry</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/entry.c b/platform-demos/C/samples/entry.c
new file mode 100644
index 0000000..a400b56
--- /dev/null
+++ b/platform-demos/C/samples/entry.c
@@ -0,0 +1,52 @@
+#include <gtk/gtk.h>
+
+/*This is the callback function. It is a handler function 
+which reacts to the signal. In this case, it will grab the 
+text input from the entry box and print out a line to the user.*/
+static void
+on_activate (GtkEntry *entry,
+             gpointer  user_data)
+{
+  const char *name;
+  name = gtk_entry_get_text (entry);
+
+  g_print ("\nHello %s!\n\n", name);
+}
+
+static void
+activate (GtkApplication *app,
+          gpointer        user_data)
+{
+  GtkWidget *window;
+  GtkWidget *entry_box;
+
+  /*Create a window with a title, a default size, 
+  and a set border width*/
+  window = gtk_application_window_new (app);
+  gtk_window_set_title (GTK_WINDOW (window), "What is your name?");
+  gtk_window_set_default_size (GTK_WINDOW (window), 300, 100);
+  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
+
+  /*create a new entry box, and add it to the window*/
+  entry_box = gtk_entry_new ();
+  gtk_container_add (GTK_CONTAINER (window), entry_box);
+
+  /*connecting the clicked signal to the callback*/
+  g_signal_connect(GTK_ENTRY (entry_box), "activate", G_CALLBACK (on_activate), NULL);
+
+  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 68be4c4..ba02d4b 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -40,6 +40,7 @@ demo_sources = \
 	samples/dialog.js			\
 	samples/dialog.py			\
 	samples/dialog.vala			\
+	samples/entry.c				\
 	samples/entry.js			\
 	samples/entry.py			\
 	samples/entry.vala			\
@@ -197,6 +198,7 @@ DOC_PAGES =				\
 	dialog.py.page			\
 	dialog.vala.page		\
 	documentation.page		\
+	entry.c.page			\
 	entry.js.page			\
 	entry.py.page			\
 	entry.vala.page			\



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