Editing Legacy Maemo 5 Documentation/Graphical UI Tutorial/Getting started

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
{{Legacy documentation}}
{{Legacy documentation}}
 +
=Getting started=
Before starting to develop your Hildon applications you need to get, install and properly configure the Maemo SDK. You can download and learn how to use the latest SDK in [http://maemo.org/development/sdks/ Maemo SDK Releases].
Before starting to develop your Hildon applications you need to get, install and properly configure the Maemo SDK. You can download and learn how to use the latest SDK in [http://maemo.org/development/sdks/ Maemo SDK Releases].
-
To begin our introduction to Hildon, we start with the simplest program possible - <code>base.c</code>. This program creates a window and has no way of exiting except to be killed by using the shell.
+
To begin our introduction to Hildon, we start with the simplest program possible - base.c. This program creates a window and has no way of exiting except to be killed by using the shell.
'''Example 1.1. Simple Hildon program'''
'''Example 1.1. Simple Hildon program'''
-
<source lang="c">
+
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;hildon/hildon.h&gt;</font></span>
-
#include <hildon/hildon.h>
+
<span><font color="#009900">int</font></span> <span>'''<span><font color="#000000">main</font></span>'''</span><span><font color="#990000">(</font></span> <span><font color="#009900">int</font></span>   argc<span><font color="#990000">,</font></span>
-
int main( int  argc,
+
          <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>argv<span><font color="#990000">[]</font></span> <span><font color="#990000">)</font></span>
-
          char *argv[] )
+
<span><font color="#FF0000">{</font></span>
-
{
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget *window;
+
  <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span>
-
  hildon_gtk_init (&argc, &argv);
+
  <span>'''<span><font color="#000000">g_set_application_name</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Simplest example"</font></span><span><font color="#990000">);</font></span>
-
  g_set_application_name ("Simplest example");
+
  window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  window = hildon_window_new ();
+
  <span>'''<span><font color="#000000">gtk_widget_show</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">);</font></span>
-
  gtk_widget_show  (window);
+
  <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  gtk_main ();
+
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  return 0;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
To compile the program, use the following command:
To compile the program, use the following command:
-
gcc base.c `pkg-config hildon-1 --cflags --libs` -o base
 
-
All programs include <code>hildon/hildon.h</code> which declares the variables, functions, structures, and so on, that are used in your Hildon application.
+
<div class="graybox">
 +
  gcc base.c `pkg-config hildon-1 --cflags --libs` -o base
 +
</div>
 +
 
 +
 
 +
All programs include hildon/hildon.h which declares the variables, functions, structures, and so on, that are used in your Hildon application.
The next line is necessary in every program:
The next line is necessary in every program:
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span></tt>
-
hildon_gtk_init (&argc, &argv);
+
-
</source>
+
This function replaces a call to <code>gtk_init()</code> and also initializes the Hildon library. This function also performs a call to <code>gtk_init()</code>. For more information on GTK+ initialization and arguments that can be passed to your application on the command line, see [http://library.gnome.org/devel/gtk/unstable/gtk-General.html#gtk-init GTK+ Reference Manual]. The next two lines of code create and display a window.
This function replaces a call to <code>gtk_init()</code> and also initializes the Hildon library. This function also performs a call to <code>gtk_init()</code>. For more information on GTK+ initialization and arguments that can be passed to your application on the command line, see [http://library.gnome.org/devel/gtk/unstable/gtk-General.html#gtk-init GTK+ Reference Manual]. The next two lines of code create and display a window.
-
<source lang="c">
+
<tt> window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
window = hildon_window_new ();
+
  <span>'''<span><font color="#000000">gtk_widget_show</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">);</font></span>
-
gtk_widget_show  (window);
+
</tt>
-
</source>
+
-
The <code>HildonWindow</code> used in this example represents a top-level window in the Hildon framework. It is derived from <code>GtkWindow</code> and provides additional commodities specific to the Hildon framework.
+
The HildonWindow used in this example represents a top-level window in the Hildon framework. It is derived from GtkWindow and provides additional commodities specific to the Hildon framework.
-
In very simple applications, <code>HildonWindow</code> can be enough. However, in most of the applications, use a <code>HildonStackableWindow</code>.
+
In very simple applications, HildonWindow can be enough. However, in most of the applications, use a HildonStackableWindow.  
The <code>gtk_widget_show()</code> shows the widget (makes it visible) that would not be otherwise displayed.
The <code>gtk_widget_show()</code> shows the widget (makes it visible) that would not be otherwise displayed.
Line 50: Line 51:
The last line enters the GTK+ main processing loop.
The last line enters the GTK+ main processing loop.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
-
gtk_main  ();
+
</tt>
-
</source>
+
-
This call exists in every GTK+ application and therefore in every Hildon application. When control reaches this point, GTK+ sleeps waiting for X events (for example, button or key presses), timeouts, or file I/O notifications to occur. In our simple example, however, events are ignored.
+
This call exists in every GTK+ application and therefore in every Hildon application. When control reaches this point, GTK+ sleeps waiting for X events (for example, button or key presses), timeouts, or file i/o notifications to occur. In our simple example, however, events are ignored.
-
==Hello World in Hildon ==
 
 +
==Hello World in Hildon ==
To begin our introduction to Hildon, we introduce the classic Hello World, Hildon style. This program creates a window with a widget (a button).
To begin our introduction to Hildon, we introduce the classic Hello World, Hildon style. This program creates a window with a widget (a button).
 +
'''Example 1.2. Hildon Hello World program'''
'''Example 1.2. Hildon Hello World program'''
-
<source lang="c">
+
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span>                                       <span><font color="#FF0000">&lt;hildon/hildon.h&gt;</font></span>
-
#include                                        <hildon/hildon.h>
+
-
 
+
<span>''<span><font color="#9A1900">/* This is a callback function. The data arguments are ignored</font></span>''</span>
-
/* This is a callback function. The data arguments are ignored
+
  <span>''<span><font color="#9A1900"> * in this example. More on callbacks . */</font></span>''</span>
-
  * in this example. More on callbacks . */
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hello</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span>
-
static void hello (GtkWidget *widget,
+
                    gpointer  data<span><font color="#990000">)</font></span>
-
                  gpointer  data)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span>'''<span><font color="#000000">g_print</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Hello World!</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">);</font></span>
-
  g_print ("Hello World!\n");
+
<span><font color="#FF0000">}</font></span>
-
}
+
-
 
+
<span><font color="#009900">int</font></span>
-
int
+
<span>'''<span><font color="#000000">main</font></span>'''</span>                                           <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span>
-
main                                            (int argc,
+
                                                  <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span>
-
                                                char **argv)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>program<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  HildonProgram *program;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget *window;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget *button;
+
-
 
+
  <span>''<span><font color="#9A1900">/* This is called in all Hildon applications. Arguments are parsed</font></span>''</span>
-
  /* This is called in all Hildon applications. Arguments are parsed
+
<span>''<span><font color="#9A1900">  * from the command line and are returned to the application. */</font></span>''</span>
-
  * from the command line and are returned to the application. */
+
  <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span>
-
  hildon_gtk_init (&argc, &argv);
+
-
 
+
  <span>''<span><font color="#9A1900">/* Get an instance of HildonProgram. It is an object used to represent</font></span>''</span>
-
  /* Get an instance of HildonProgram. It is an object used to represent
+
<span>''<span><font color="#9A1900">  * an application running in the Hildon framework.              */</font></span>''</span>
-
  * an application running in the Hildon framework.              */
+
  program <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_instance</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  program = hildon_program_get_instance ();
+
-
 
+
  <span>''<span><font color="#9A1900">/* create a new hildon window */</font></span>''</span>
-
  /* create a new hildon window */
+
  window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  window = hildon_window_new ();
+
-
 
+
  <span>''<span><font color="#9A1900">/* Registers a window as belonging to the program */</font></span>''</span>
-
  /* Registers a window as belonging to the program */
+
  <span>'''<span><font color="#000000">hildon_program_add_window</font></span>'''</span> <span><font color="#990000">(</font></span>program<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
-
  hildon_program_add_window (program, HILDON_WINDOW (window));
+
-
 
+
  <span>''<span><font color="#9A1900">/* When the window is given the "delete_event" signal (this is given</font></span>''</span>
-
  /* When the window is given the "delete_event" signal (this is given
+
<span>''<span><font color="#9A1900">  * by the window manager, usually by the "close" option, or on the</font></span>''</span>
-
  * by the window manager, usually by the "close" option, or on the
+
<span>''<span><font color="#9A1900">  * titlebar), we ask it to call the delete_event () function</font></span>''</span>
-
  * titlebar), we ask it to call the delete_event () function
+
<span>''<span><font color="#9A1900">  * as defined above. The data passed to the callback</font></span>''</span>
-
  * as defined above. The data passed to the callback
+
<span>''<span><font color="#9A1900">  * function is NULL and is ignored in the callback function. */</font></span>''</span>
-
  * function is NULL and is ignored in the callback function. */
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"delete_event"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (window), "delete_event",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (gtk_main_quit), NULL);
+
-
 
+
  <span>''<span><font color="#9A1900">/* Create a new hildon button with its title label set to "Hello world!",</font></span>''</span>
-
  /* Create a new hildon button with its title label set to "Hello world!",
+
<span>''<span><font color="#9A1900">  * also size and type of arrangement is set */</font></span>''</span>
-
  * also size and type of arrangement is set */
+
  button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_button_new_with_text</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">,</font></span>
-
  button = hildon_button_new_with_text (HILDON_SIZE_AUTO,
+
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL<span><font color="#990000">,</font></span>
-
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+
                                        <span><font color="#FF0000">"Hello world!"</font></span><span><font color="#990000">,</font></span>
-
                                        "Hello world!",
+
                                        NULL<span><font color="#990000">);</font></span>
-
                                        NULL);
+
-
 
+
  <span>''<span><font color="#9A1900">/* When the button is given the "clicked" signal, we ask it to call the</font></span>''</span>
-
  /* When the button is given the "clicked" signal, we ask it to call the
+
<span>''<span><font color="#9A1900">  * hello () function as defined above. The data passed to the callback</font></span>''</span>
-
  * hello () function as defined above. The data passed to the callback
+
<span>''<span><font color="#9A1900">  * function is NULL and is ignored in the callback function. */</font></span>''</span>
-
  * function is NULL and is ignored in the callback function. */
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (button), "clicked",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>hello<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (hello), NULL);
+
-
 
+
  <span>''<span><font color="#9A1900">/* This packs the button into the window (a GTK+ container). */</font></span>''</span>
-
  /* This packs the button into the window (a GTK+ container). */
+
  <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span>
-
  gtk_container_add (GTK_CONTAINER (window),
+
                      button<span><font color="#990000">);</font></span>
-
                    button);
+
-
 
+
  <span>''<span><font color="#9A1900">/* The final step is to display this newly created widget</font></span>''</span>
-
  /* The final step is to display this newly created widget
+
<span>''<span><font color="#9A1900">  * and all widgets it contains. */</font></span>''</span>
-
  * and all widgets it contains. */
+
  <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
-
  gtk_widget_show_all (GTK_WIDGET (window));
+
-
 
+
  <span>''<span><font color="#9A1900">/* All GTK+ applications must have a gtk_main(). Control ends here</font></span>''</span>
-
  /* All GTK+ applications must have a gtk_main(). Control ends here
+
<span>''<span><font color="#9A1900">  * and waits for an event to occur (like a key press or</font></span>''</span>
-
  * and waits for an event to occur (like a key press or
+
<span>''<span><font color="#9A1900">  * mouse event). */</font></span>''</span>
-
  * mouse event). */
+
  <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  gtk_main ();
+
-
 
+
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  return 0;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
As you can see in this simple example, writing Hildon applications is slightly different from writing standard GTK+ applications. We are going to review these differences through the next chapters.
As you can see in this simple example, writing Hildon applications is slightly different from writing standard GTK+ applications. We are going to review these differences through the next chapters.
==Compiling Hello World ==
==Compiling Hello World ==
-
 
To compile, use the following command:
To compile, use the following command:
-
gcc hello-world.c `pkg-config hildon-1 --cflags --libs` -o hello
+
<div class="graybox">
 +
  gcc hello-world.c `pkg-config hildon-1 --cflags --libs` -o hello
 +
</div>
This uses the program pkg-config, which can be obtained from [http://www.freedesktop.org/wiki/Home Freedesktop]. The program reads the .pc files which come with Hildon to determine what compiler switches are needed to compile programs that use it. pkg-config hildon-1 -cflags outputs a list of include directories for the compiler to look in, and pkg-config hildon-1 -libs outputs the list of libraries for the compiler to link with and the directories to find them in. Although they could be used separately as `pkg-config hildon-1 -cflags` and `pkg-config hildon-1 -libs`, in the above example they were joined as a single instance because it is easier to understand.
This uses the program pkg-config, which can be obtained from [http://www.freedesktop.org/wiki/Home Freedesktop]. The program reads the .pc files which come with Hildon to determine what compiler switches are needed to compile programs that use it. pkg-config hildon-1 -cflags outputs a list of include directories for the compiler to look in, and pkg-config hildon-1 -libs outputs the list of libraries for the compiler to link with and the directories to find them in. Although they could be used separately as `pkg-config hildon-1 -cflags` and `pkg-config hildon-1 -libs`, in the above example they were joined as a single instance because it is easier to understand.
-
N.B. Note that the type of single quote (back-tick) used in the compile command above is significant.
+
 
 +
N.B. Note that the type of single quote used in the compile command above is significant.
==Stepping through Hello World ==
==Stepping through Hello World ==
Line 151: Line 153:
The following lines define the callback function that is called when the button is clicked. We ignore both the widget and the data in this example, but usually developers would need to handle events from them.
The following lines define the callback function that is called when the button is clicked. We ignore both the widget and the data in this example, but usually developers would need to handle events from them.
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hello</font></span>'''</span><span><font color="#990000">(</font></span> GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span>
-
static void hello( GtkWidget *widget,
+
                      gpointer  data <span><font color="#990000">)</font></span>
-
                    gpointer  data )
+
  <span><font color="#FF0000">{</font></span>
-
{
+
    <span>'''<span><font color="#000000">g_print</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Hello World!</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">);</font></span>
-
  g_print ("Hello World!\n");
+
  <span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
The following is the definition of the main function, similar to the standard main function you would find in any C program.
The following is the definition of the main function, similar to the standard main function you would find in any C program.
-
<source lang="c">
+
<tt>  <span><font color="#009900">int</font></span>
-
int
+
    <span>'''<span><font color="#000000">main</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span> <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span><span><font color="#FF0000">{</font></span>
-
main  (int argc, char **argv){
+
</tt>
-
</source>
+
-
The next lines of code declare pointers to an object of type <code>HildonProgram</code> which represents an application running in the Hildon framework. Pointers to the widgets which show the application are also declared.
+
The next lines of code declare pointers to an object of type HildonProgram which represents an application running in the Hildon framework. Pointers to the widgets which show the application are also declared.
-
<source lang="c">
+
<tt>  HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>program<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
HildonProgram *program;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
GtkWidget *window;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
GtkWidget *button;
+
</tt>
-
</source>
+
To use Hildon, initialize it first. Initialization connects to the window system display, and parses some standard command line arguments.
To use Hildon, initialize it first. Initialization connects to the window system display, and parses some standard command line arguments.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span>
-
hildon_gtk_init (&argc, &argv);
+
</tt>
-
</source>
+
-
Only one <code>HildonProgram</code> can be created per process. Use <code>hildon_program_get_instance()</code> to access it.
+
Only one HildonProgram can be created per process. Use <code>hildon_program_get_instance()</code> to access it.
-
<source lang="c">
+
<tt>program <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_instance</font></span>'''</span> <span><font color="#990000">();</font></span>
-
program = hildon_program_get_instance ();
+
</tt>
-
</source>
+
-
In this simple example, a new <code>HildonWindow</code> is created. In cases with nested views, use a <code>HildonStackableWindow</code>.
+
In this simple example, a new HildonWindow is created. In cases with nested views, use a HildonStackableWindow.  
-
<source lang="c">
+
<tt>window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
window = hildon_window_new ();
+
</tt>
-
</source>
+
This call registers a window as belonging to the program. This allows applying program-wide settings to all the registered windows, such as assigning a common menu to all the registered windows by setting it to the program.
This call registers a window as belonging to the program. This allows applying program-wide settings to all the registered windows, such as assigning a common menu to all the registered windows by setting it to the program.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">hildon_program_add_window</font></span>'''</span> <span><font color="#990000">(</font></span>program<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">))</font></span>
-
hildon_program_add_window (program, HILDON_WINDOW (window));
+
</tt>
-
</source>
+
-
The following code is an example of connecting a signal handler to an object, in this case, the window. The function <code>gtk_main_quit()</code> is set as a handler to the "<code>delete_event</code>" signal. The function tells GTK+ that it must exit from <code>gtk_main</code> when control is returned to it, making the program terminate.
+
The following code is an example of connecting a signal handler to an object, in this case, the window. The function <code>gtk_main_quit()</code> is set as a handler to the "delete_event" signal. The function tells GTK+ that it must exit from gtk_main when control is returned to it, making the program terminate.
-
<source lang="c">
+
<tt>  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"delete_event"</font></span><span><font color="#990000">,</font></span>
-
g_signal_connect (G_OBJECT (window), "delete_event",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
-
                G_CALLBACK (gtk_main_quit), NULL);
+
</tt>
-
</source>
+
-
This call creates a new <code>HildonButton</code>. This button allows to set two labels, one main label and another secondary one. You can also set the size of the button and the order of the labels. Notice that you can use <code>GtkButton</code>'s in Hildon applications in case you do not need the additional features that Hildon provides.
+
This call creates a new HildonButton. This button allows to set two labels, one main label and another secondary one. You can also set the size of the button and the order of the labels. Notice that you can use GtkButton's in Hildon applications in case you do not need the additional features that Hildon provides.
-
<source lang="c">
+
<tt> button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_button_new_with_text</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">,</font></span>
-
button = hildon_button_new_with_text (HILDON_SIZE_AUTO,
+
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL<span><font color="#990000">,</font></span>
-
                                    HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+
                                        <span><font color="#FF0000">"Hello world!"</font></span><span><font color="#990000">,</font></span>
-
                                    "Hello world!",
+
                                        NULL<span><font color="#990000">);</font></span>
-
                                    NULL);
+
</tt>
-
</source>
+
-
Here, a signal handler is attached to the newly created button so that when it emits the "<code>clicked</code>" signal, our <code>hello()</code> function is called. The data is ignored, so we simply pass in <code>NULL</code> to the <code>hello()</code> callback function. Obviously, the "<code>clicked</code>" signal is emitted when the button is pressed.
+
Here, a signal handler is attached to the newly created button so that when it emits the "clicked" signal, our <code>hello()</code> function is called. The data is ignored, so we simply pass in NULL to the <code>hello()</code> callback function. Obviously, the "clicked" signal is emitted when the button is pressed.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
-
g_signal_connect (G_OBJECT (button), "clicked",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>hello<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (hello), NULL);
+
</tt>
-
</source>
+
This packing call tells GTK+ to place the button in the window. For more information, see the Packing Widgets section of the [http://library.gnome.org/devel/gtk-tutorial/stable/ GTK+ 2.0] Tutorial.
This packing call tells GTK+ to place the button in the window. For more information, see the Packing Widgets section of the [http://library.gnome.org/devel/gtk-tutorial/stable/ GTK+ 2.0] Tutorial.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span>
-
gtk_container_add (GTK_CONTAINER (window),
+
                      button<span><font color="#990000">);</font></span>
-
                    button);
+
</tt>
-
</source>
+
When everything is set up with all signal handlers in place and the button placed in the window, we ask GTK to "show" the widgets on the screen.
When everything is set up with all signal handlers in place and the button placed in the window, we ask GTK to "show" the widgets on the screen.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
-
gtk_widget_show_all (GTK_WIDGET (window));
+
</tt>
-
</source>
+
And of course, we call <code>gtk_main()</code> which waits for events to come from the X server and calls on the widgets to emit signals when these events come.
And of course, we call <code>gtk_main()</code> which waits for events to come from the X server and calls on the widgets to emit signals when these events come.
-
<source lang="c">
+
<tt><span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
-
gtk_main ();
+
</tt>
-
</source>
+
And the final return. Control returns here after <code>gtk_main_quit()</code> is called.
And the final return. Control returns here after <code>gtk_main_quit()</code> is called.
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
return 0;
+
</tt>
-
</source>
+
<hr/>
<hr/>

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)

Templates used on this page: