]> Pileus Git - ~andy/gtk/blobdiff - docs/faq/gtk-faq.sgml
Rename configure.in to configure.ac
[~andy/gtk] / docs / faq / gtk-faq.sgml
index df91d4477fb1a6eb49cb61a6c518d4cb5a496d43..481f17faec82e06d6c7bfb801d9a47e6ba8d8182 100644 (file)
@@ -2,7 +2,7 @@
 <book>
 
 <bookinfo>
-  <date>January 9th 2004</date>
+  <date>January 14th 2004</date>
   <title>GTK+ FAQ</title>
   <authorgroup>
     <author>
@@ -429,7 +429,7 @@ in which they need to be installed:</para>
 
 <itemizedlist spacing=compact>
 <listitem><simpara> pkg-config
-(<ulink url="http://www.freedesktop.org/software/pkgconfig/">
+(<ulink url="http://pkg-config.freedesktop.org/wiki">
 pkg-config Site</ulink>)</simpara>
 </listitem>
 
@@ -789,8 +789,7 @@ disgrace to the widget set will gladly be included.</para>
 <para>The new widgets that get added to GTK+ are generally either
 replacements for existing widgets that are no longer
 deemed to be adequate, or have been developed externally to GTK+ but
-have been widely tested. One possible avenue for this is via
-<ulink url="http://cvs.gnome.org/lxr/source/libegg/">libegg</ulink>.</para>
+have been widely tested. 
 
 <para>Before you spend months of your valuable time implementing your
 revolutionary widget, it is highly recommended that you get some
@@ -825,8 +824,8 @@ However, bindings for many other languages are available.</para>
 <para>So, after you have installed GTK+ there are a couple of
 things that can ease you into developing applications with
 it. There is the GTK+ Tutorial <ulink
-url="http://www.gtk.org/tutorial/">
-http://www.gtk.org/tutorial/</ulink>, which is undergoing
+url="http://library.gnome.org/devel/gtk-tutorial/stable/">
+http://library.gnome.org/devel/gtk-tutorial/stable/</ulink>, which is undergoing
 development. This will introduce you to writing applications
 using C.</para>
 
@@ -976,7 +975,7 @@ url="ftp://ftp.gnu.org/gnu/make/">ftp://ftp.gnu.org/gnu/make/</ulink>).</para>
 
 <sect1>
 <title>I want to add some configure stuff, how could I do
-this?</title>
+this? <emphasis>[GTK 2.x]</emphasis></title>
 
 <para>To use autoconf/automake, you must first install the
 relevant packages. These are:</para>
@@ -985,10 +984,10 @@ relevant packages. These are:</para>
 <listitem><simpara>the m4 preprocessor v1.4 or better</simpara>
 </listitem>
 
-<listitem><simpara>autoconf v2.13 or better</simpara>
+<listitem><simpara>autoconf v2.54 or better</simpara>
 </listitem>
 
-<listitem><simpara>automake v1.4 or better</simpara>
+<listitem><simpara>automake v1.7 or better suggested</simpara>
 </listitem>
 </itemizedlist>
 
@@ -997,26 +996,26 @@ relevant packages. These are:</para>
 or on any GNU mirror.</para>
 
 <para>In order to use the powerful autoconf/automake scheme,
-you must create a configure.in which may look like:</para>
+you must create a configure.ac which may look like:</para>
 
 <programlisting role="C">
 dnl Process this file with autoconf to produce a configure script.
-dnl configure.in for a GTK+ based program
+dnl configure.ac for a GTK+ based program
 
-AC_INIT(myprg.c)dnl
-AM_INIT_AUTOMAKE(mypkgname,0.0.1)dnl
-AM_CONFIG_HEADER(config.h)dnl
+AC_INIT(myprg.c)
+AM_INIT_AUTOMAKE(mypkgname, 0.0.1)
+AM_CONFIG_HEADER(config.h)
 
 dnl Checks for programs.
 AC_PROG_CC dnl check for the c compiler
 dnl you should add CFLAGS="" here, 'cos it is set to -g by PROG_CC
 
 dnl Checks for libraries.
-AM_PATH_GTK(1.2.0,,AC_MSG_ERROR(mypkgname 0.1 needs GTK))dnl
+AM_PATH_GTK_2_0(2.2.0,,AC_MSG_ERROR(mypkgname 0.1 needs GTK+ 2.2.0))
 
 AC_OUTPUT(
        Makefile
-)dnl
+)
 </programlisting>
 
 <para>You must add a Makefile.am file:</para>
@@ -1138,8 +1137,7 @@ myapp --display=:1
      | | | +GtkCombo
      | | | `GtkStatusbar
      | | `GtkVBox
-     | |   +GtkColorSelection
-     | |   `GtkGammaCurve
+     | |   `GtkColorSelection
      | +GtkButton
      | | +GtkOptionMenu
      | | `GtkToggleButton
@@ -1161,7 +1159,6 @@ myapp --display=:1
      | +GtkToolbar
      | `GtkTree
      +GtkDrawingArea
-     | `GtkCurve
      +GtkEditable
      | +GtkEntry
      | | `GtkSpinButton
@@ -1469,7 +1466,7 @@ in a priority of G_PRIORITY_HIGH.</para>
 
 <sect1>
 <title>Why does this strange 'x io error' occur when I
-<literal>fork()</literal> in my GTK+ app?</title>
+<literal>fork()</literal> in my GTK+ app? <emphasis>[GTK 2.x]</emphasis></title>
 
 <para>This is not really a GTK+ problem, and the problem is
 not related to <literal>fork()</literal> either. If the 'x io
@@ -1490,13 +1487,15 @@ illustrate handling fork() and exit().</para>
 <programlisting role="C">
 /*-------------------------------------------------------------------------
  * Filename:      gtk-fork.c
- * Version:       0.99.1
+ * Version:       0.99.2
  * Copyright:     Copyright (C) 1999, Erik Mouw
  * Author:        Erik Mouw &lt;J.A.K.Mouw@its.tudelft.nl&gt;
  * Description:   GTK+ fork example
  * Created at:    Thu Sep 23 21:37:55 1999
  * Modified by:   Erik Mouw &lt;J.A.K.Mouw@its.tudelft.nl&gt;
  * Modified at:   Thu Sep 23 22:39:39 1999
+ * Modified by:   Tony Gale &lt;gale@gtk.org&gt;
+ * Modified at:   Wed Jan 14 12:38:00 2004
  *-----------------------------------------------------------------------*/
 /*
  * Compile with:
@@ -1525,7 +1524,7 @@ void sigchld_handler(int num)
   sigprocmask(SIG_BLOCK, &amp;set, &amp;oldset);
 
   /* wait for child */
-  while((pid = waitpid((pid_t)-1, &amp;status, WNOHANG)) > 0)
+  while((pid = waitpid((pid_t)-1, &amp;status, WNOHANG)) &gt; 0)
     {
       if(WIFEXITED(status))
        {
@@ -1622,23 +1621,19 @@ int main(int argc, char *argv[])
    */
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
-  gtk_signal_connect(GTK_OBJECT (window), "delete_event",
-                    GTK_SIGNAL_FUNC(delete_event), NULL);
+  g_signal_connect(G_OBJECT (window), "delete_event",
+                    G_CALLBACK(delete_event), NULL);
           
-  gtk_signal_connect(GTK_OBJECT (window), "destroy",
-                    GTK_SIGNAL_FUNC(destroy), NULL);
+  g_signal_connect(G_OBJECT (window), "destroy",
+                    G_CALLBACK(destroy), NULL);
 
-#if (GTK_MAJOR_VERSION == 1) && (GTK_MINOR_VERSION == 0)
-  gtk_container_border_width(GTK_CONTAINER (window), 10);
-#else  
   gtk_container_set_border_width(GTK_CONTAINER (window), 10);
-#endif
 
-  /* add a button to do something usefull */
+  /* add a button to do something useful */
   button = gtk_button_new_with_label("Fork me!");
           
-  gtk_signal_connect(GTK_OBJECT (button), "clicked",
-                    GTK_SIGNAL_FUNC(fork_me), NULL);
+  g_signal_connect(G_OBJECT (button), "clicked",
+                    G_CALLBACK(fork_me), NULL);
 
   gtk_container_add(GTK_CONTAINER(window), button);
           
@@ -1663,7 +1658,7 @@ int main(int argc, char *argv[])
 
 <sect1>
 <title>Why don't the contents of a button move when the button
-is pressed? Here's a patch to make it work that way...</title>
+is pressed? Here's a patch to make it work that way... <emphasis>[GTK 2.x]</emphasis></title>
 
 <para>From: Peter Mattis</para>
 
@@ -1689,12 +1684,12 @@ and determined it didn't look good and removed it.</quote></para>
 
 <sect1>
 <title>How do I identifiy a widgets top level window or other
-ancestor?</title>
+ancestor? <emphasis>[GTK 2.x]</emphasis></title>
 
 <para>There are a couple of ways to find the top level parent
-of a widget. The easier way is to call the
+of a widget. The easiest way is to call the
 <literal>gtk_widget_get_toplevel()</literal> function that
-returns pointer to a GtkWidget that is the top level
+returns pointer to a GtkWidget that is the top level
 window.</para>
 
 <para>A more complicated way to do this (but less limited, as
@@ -1718,12 +1713,16 @@ widget (entry, label, etc. To find the master hbox using the
       hbox = gtk_widget_get_ancestor(w, GTK_TYPE_HBOX);
 </programlisting>
 
+<para>You can also follow the a widgets ancestry by using the function
+<literal>gtk_widget_get_parent()</literal> that returns a pointer
+to a widgets parent widget.</para>
+
 </sect1>
 
 <!-- ----------------------------------------------------------------- -->
 
 <sect1>
-<title>How do I get the Window ID of a GtkWindow?</title>
+<title>How do I get the Window ID of a GtkWindow? <emphasis>[GTK 2.x]</emphasis></title>
 
 <para>The actual Gdk/X window will be created when the widget
 gets realized. You can get the Window ID with:</para>
@@ -1738,8 +1737,7 @@ Window xwin = GDK_WINDOW_XWINDOW (GTK_WIDGET (my_window)->window);
 <!-- ----------------------------------------------------------------- -->
 
 <sect1>
-<title>How do I catch a double click event (in a list widget,
-for example)?</title>
+<title>How do I catch a double click event? <emphasis>[GTK 2.x]</emphasis></title>
 
 <para>Tim Janik wrote to gtk-list (slightly modified):</para>
 
@@ -1749,10 +1747,10 @@ for example)?</title>
 gint
 signal_handler_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data)
 {
-  if (GTK_IS_LIST_ITEM(widget) &&
+  if (GTK_IS_BUTTON(widget) &&
        (event->type==GDK_2BUTTON_PRESS ||
         event->type==GDK_3BUTTON_PRESS) ) {
-    printf("I feel %s clicked on button %d\n",
+    printf("I feel %s clicked with button %d\n",
            event->type==GDK_2BUTTON_PRESS ? "double" : "triple",
            event->button);
   }
@@ -1764,18 +1762,18 @@ signal_handler_event(GtkWidget *widget, GdkEventButton *event, gpointer func_dat
 
 <programlisting role="C">
 {
-  /* list, list item init stuff */     
+  /* button init stuff */     
 
-  gtk_signal_connect(GTK_OBJECT(list_item),
+  g_signal_connect(G_OBJECT(button),
                      "button_press_event",
-                     GTK_SIGNAL_FUNC(signal_handler_event),
+                     G_CALLBACK(signal_handler_event),
                      NULL);
 
   /* and/or */
 
-  gtk_signal_connect(GTK_OBJECT(list_item),
+  g_signal_connect(G_OBJECT(button),
                      "button_release_event",
-                     GTK_SIGNAL_FUNC(signal_handler_event),
+                     G_CALLBACK(signal_handler_event),
                      NULL);
 
   /* something else */
@@ -1894,7 +1892,7 @@ not applied you'll have to use the
 function. <literal>gtk_object_class_user_signal_new</literal> allows you
 to add a new signal to a predefined GTK+ widget without any
 modification of the GTK+ source code. The new signal can be
-emited with <literal>gtk_signal_emit</literal> and can be
+emited with <literal>g_signal_emit</literal> and can be
 handled in the same way as other signals.</para>
 
 <para>Tim Janik posted this code snippet:</para>
@@ -1916,7 +1914,7 @@ gtk_widget_user_action (GtkWidget *widget,
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  gtk_signal_emit (GTK_OBJECT (widget), signal_user_action, act_data);
+  g_signal_emit (widget, signal_user_action, act_data);
 }
 </programlisting>
 
@@ -2104,10 +2102,10 @@ not.</para>
 snippet:</para>
 
 <programlisting role="C">
-     gtk_widget_ref(widget);
+     g_object_ref(widget);
      gtk_container_remove(GTK_CONTAINER(old_parent), widget);
      gtk_container_add(GTK_CONTAINER(new_parent), widget);
-     gtk_widget_unref(widget);
+     g_object_unref(widget);
 </programlisting>
 
 </sect1>
@@ -2303,8 +2301,8 @@ used, as in:</para>
                NULL, gtk_widget_get_colormap(top),
                &amp;pixmap_mask, NULL, pixfile);
   pixw = gtk_pixmap_new (pixmap, pixmap_mask);
-  gdk_pixmap_unref (pixmap);
-  gdk_pixmap_unref (pixmap_mask);
+  g_object_unref (pixmap);
+  g_object_unref (pixmap_mask);
 </programlisting>
 
 </sect1>
@@ -2523,15 +2521,15 @@ using the following expression:</para>
 
 <para>If you don't want the user to be able to modify the
 content of this entry, you can use the
-gtk_entry_set_editable() function:</para>
+gtk_editable_set_editable() function:</para>
 
 
 <programlisting role="C">
-      void gtk_entry_set_editable(GtkEntry *entry, 
-                                  gboolean editable);
+void gtk_editable_set_editable (GtkEditable *editable,
+                                gboolean     is_editable);
 </programlisting>
 
-<para>Set the editable parameter to FALSE to disable typing
+<para>Set the is_editable parameter to FALSE to disable typing
 into the entry.</para>
 </sect1>
 
@@ -2555,10 +2553,10 @@ into the entry.</para>
 signal handler with</para>
 
 <programlisting role="C">
-      gtk_signal_connect(GTK_COMBO(cb)->entry,
-                         "changed",
-                         GTK_SIGNAL_FUNC(my_cb_change_handler),
-                         NULL);
+      g_signal_connect(GTK_COMBO(cb)->entry,
+                       "changed",
+                       G_CALLBACK(my_cb_change_handler),
+                       NULL);
 </programlisting>
 
 </sect1>
@@ -2625,8 +2623,8 @@ underlined, and the relevant accelerators are created.</para>
   gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0);
 
   file1 = gtk_menu_item_new_with_label ("");
-  tmp_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (file1)->child),
-                                   _("_File"));
+  gtk_label_set_use_underline (GTK_LABEL (gtk_bin_get_child (GTK_BIN (file1))),
+                               TRUE);
   gtk_widget_add_accelerator (file1, "activate_item", accel_group,
                               tmp_key, GDK_MOD1_MASK, 0);
   gtk_object_set_data (GTK_OBJECT (window1), "file1", file1);
@@ -2639,8 +2637,8 @@ underlined, and the relevant accelerators are created.</para>
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (file1), file1_menu);
 
   new1 = gtk_menu_item_new_with_label ("");
-  tmp_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (new1)->child),
-                                   _("_New"));
+  gtk_label_set_use_underline (GTK_LABEL (gtk_bin_get_child (GTK_BIN (new1))),
+                               TRUE);
   gtk_widget_add_accelerator (new1, "activate_item", file1_menu_accels,
                               tmp_key, 0, 0);
   gtk_object_set_data (GTK_OBJECT (window1), "new1", new1);
@@ -2666,9 +2664,9 @@ GtkMenuItem with:</para>
       /* do stuff with child */
       if (GTK_IS_LABEL (child))
       {
-        gchar *text;
+        const gchar *text;
     
-        gtk_label_get (GTK_LABEL (child), &amp;text);
+        text = gtk_label_get_text (GTK_LABEL (child));
         g_print ("menu item text: %s\n", text);
       }
     }
@@ -2810,7 +2808,7 @@ the Label widget, which can be done using:</para>
 GtkTooltips in itself is not a GtkWidget (though a GtkObject)
 and as such is not attempted to match any widget styles.</para>
 
-<para>So, you resource file should look something like:</para>
+<para>So, your resource file should look something like:</para>
 
 <programlisting role="C">
 style "postie"
@@ -2860,9 +2858,9 @@ be:</para>
 
 <programlisting role="C">
   entry = gtk_entry_new();
-  gtk_signal_connect (GTK_OBJECT(entry), "activate",
-                      GTK_SIGNAL_FUNC(entry_callback),
-                      NULL);
+  g_signal_connect (entry, "activate",
+                    G_CALLBACK(entry_callback),
+                    NULL);
 </programlisting>
 
 </sect1>
@@ -3040,8 +3038,8 @@ main (int argc, char *argv[])
   gtk_container_add (GTK_CONTAINER (window), text);
 
   /* connect after everything else */
-  gtk_signal_connect_after (GTK_OBJECT(text), "button_press_event",
-    GTK_SIGNAL_FUNC (insert_bar), NULL);
+  g_signal_connect_after (text, "button_press_event",
+                          G_CALLBACK (insert_bar), NULL);
 
   gtk_widget_show_all(window);
   gtk_main();