]> Pileus Git - ~andy/gtk/blob - docs/faq/gtkfaq.sgml
add question on multi-threading, minor URL cleanups.
[~andy/gtk] / docs / faq / gtkfaq.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
5 <!-- Title information -->
6
7 <title>GTK+ FAQ
8
9 <!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG --> 
10 <author>Nathan Froyd, Tony Gale, Shawn T. Amundson.
11 <date>May 11th 1998
12 <abstract>
13 This document is intended to answer questions that are likely to be 
14 frequently asked by programmers using GTK+ or people who are just
15 looking at using GTK+.  
16 </abstract>
17
18 <!-- Table of contents -->
19 <toc>
20
21 <!-- Begin the document -->
22
23 <!-- ***************************************************************** -->
24 <sect>General Information
25
26 <!-- ----------------------------------------------------------------- -->
27 <sect1>Authors
28 <p>
29 The authors of GTK+ are:
30
31 <itemize>
32 <item>Peter Mattis    (petm@xcf.berkeley.edu)
33 <item>Spencer Kimball (spencer@xcf.berkeley.edu)
34 <item>Josh MacDonald  (jmacd@xcf.berkeley.edu)
35 </itemize>
36 GTK+ is distributed under the GNU Library General Public License
37
38 <!-- ----------------------------------------------------------------- -->
39 <sect1>What is GTK+?
40 <p>
41 GTK+ is a small and efficient widget set designed with the general look 
42 and feel of Motif.  In reality, it looks much better than Motif.  It
43 contains common widgets and some more complex widgets such as a file
44 selection, and color selection widgets.
45
46 GTK+ provides some unique features. (At least, I know of no other widget 
47 library which provides them). For
48 example, a button does not contain a label, it contains a child widget, 
49 which in most instances will be a label.
50 However, the child widget can also be a pixmap, image or any combination 
51 possible the programmer desires.
52 This flexibility is adhered to throughout the library. 
53
54 <!-- ----------------------------------------------------------------- -->
55 <sect1>What is the + in GTK+?
56 <P>
57 Peter Mattis informed the gtk mailing list that:
58 <quote>
59 "I originally wrote gtk which included the three libraries, libglib,
60 libgdk and libgtk. It featured a flat widget hierarchy. That is, you
61 couldn't derive a new widget from an existing one. And it contained
62 a more standard callback mechanism instead of the signal mechanism now
63 present in gtk+. The + was added to distinguish between the original
64 version of gtk and the new version. You can think of it as being an
65 enhancement to the original gtk that adds object oriented features."
66 </quote>
67
68 <!-- ----------------------------------------------------------------- -->
69 <sect1>Does the G in GTK+ stand for General, Gimp, or GNU?
70 <p>
71 Peter Mattis informed the gtk mailing list that:
72 <quote>
73 "I think the last time Spencer and I talked about it we decided on 
74 GTK = Gimp ToolKit. But I don't know for sure. Its definately not
75 GNU, though."
76 </quote>
77
78 <!-- ----------------------------------------------------------------- -->
79 <sect1>Where is the documentation for GTK+?
80 <p>
81 In the GTK+ distribution's doc/ directory you will find the
82 reference material for both GTK and GDK, this FAQ and the
83 GTK Tutorial.
84
85 In addition, you can find links to HTML versions of these documents 
86 by going to 
87 <htmlurl url="http://www.gtk.org/" 
88 name="http://www.gtk.org/">.
89
90 The Tutorial and FAQ can also be found at
91 <htmlurl url="http://www.geocities.com/ResearchTriangle/Lab/4299/"
92 name="http://www.geocities.com/ResearchTriangle/Lab/4299/">.
93
94 <!-- ----------------------------------------------------------------- -->
95 <sect1>Is there a mailing list (or mailing list archive) for GTK+?
96 <p>
97 There are two mailing lists:
98 <itemize>
99 <item>A mailing list for discussion of development of GTK based applications
100 is hosted at gtk-app-devel-list@redhat.com. To subscribe send an
101 email message to <htmlurl url="mailto:gtk-app-devel-list-request@redhat.com"
102 name="gtk-app-devel-list-request@redhat.com">
103 with <em>subscribe</em> in the <bf>subject</bf>.
104 <p>
105 <item>A mailing list for discussion of development of GTK is hosted 
106 at gtk-list@redhat.com. To subscribe send an
107 email message to <htmlurl url="mailto:gtk-list-request@redhat.com" 
108 name="gtk-list-request@redhat.com">
109 with <em>subscribe</em> in the <bf>subject</bf>.
110 <p>
111 A searchable archive of the mailing list can be found at <htmlurl url="http://archive.redhat.com/gtk-list" name="http://archive.redhat.com/gtk-list">
112 </itemize>
113 <!-- ----------------------------------------------------------------- -->
114 <sect1>The gtk-list hasn't had any traffic for days, is it dead?
115 <p>
116 No, everyone's just busy coding.
117
118 <!-- ----------------------------------------------------------------- -->
119 <sect1>How to get help with GTK+
120 <p>
121 First, make sure your question isn't answered in the documentation, this
122 FAQ or the tutorial. Done that? You're sure you've done that, right? In
123 that case, the best place to post questions is to the GTK+ mailing list.
124
125 <!-- ----------------------------------------------------------------- -->
126 <sect1>How to report bugs in GTK+
127 <p>
128 Bug reports should be sent to the GTK+ mailing list.
129
130 <!-- ----------------------------------------------------------------- -->
131 <sect1>What applications have been written with GTK+?
132 <p>
133 Some applications which use GTK+ are:
134 <itemize>
135 <item>GIMP (<htmlurl url="http://www.XCF.Berkeley.EDU/~gimp/" 
136                   name="http://www.XCF.Berkeley.EDU/~gimp/"> ), 
137       an image manipulation program
138 <item>Gsumi (<htmlurl url="http://www.msc.cornell.edu/~otaylor/gsumi/gsumi.html" 
139                   name="http://www.msc.cornell.edu/~otaylor/gsumi/gsumi.html">),
140       a fun B+W doodling program with XInput support.
141 <item>GUBI (<htmlurl url="http://www.SoftHome.net/pub/users/timj/gubi/index.htm"
142             name="http://www.SoftHome.net/pub/users/timj/gubi/index.htm">),
143       a user interface builder
144 <item>Gzilla (<htmlurl url="http://www.levien.com/gzilla/" name="http://www.levien.com/gzilla/">),
145       a web browser
146 <item>SANE (<htmlurl url="http://www.azstarnet.com/~axplinux/sane/" name="http://www.azstarnet.com/~axplinux/sane/"> ),
147       a universal scanner interface
148 <item>XQF (<htmlurl url="http://www.botik.ru/~roma/quake/" name="http://www.botik.ru/~roma/quake/">),
149       a QuakeWorld/Quake2 server browser and launcher
150 <item>ElectricEyes (<htmlurl url="http://www.labs.redhat.com/ee.shtml" name="http://www.labs.redhat.com/ee.shtml">),
151       an image viewer that aims to be a free replacement for xv
152 <item>GPK - the General Proxy Kit (<htmlurl url="http://www.humanfactor.com/gpk/" name="http://www.humanfactor.com/gpk/">),
153       an add-on library to permit thread-safe access to GTK+
154 <item>GCK - the General Convenience Kit (<htmlurl url="http://www.ii.uib.no/~tomb/gck.html" name="http://www.ii.uib.no/~tomb/gck.html">),
155       miscellaneous functions intended to ease color handling, UI construction,
156       vector operations, and math functions
157 <item>GDK Imlib (<htmlurl url="http://www.labs.redhat.com/imlib/" name="http://www.labs.redhat.com/imlib/">),
158       a fast image loading and manipulation library for GDK      
159 </itemize>
160 <p>
161 In addition to the above, the GNOME project (<htmlurl url="http://www.gnome.org"
162 name="http://www.gnome.org">)
163 is using GTK+ to build a free desktop for Linux. Many more programs can be found
164 there.
165
166 <!-- ----------------------------------------------------------------- -->
167 <sect1>I'm looking for an application to write in GTK+. How about an IRC client?
168 <p> 
169
170 Ask on gtk-list for suggestions. There are at least four IRC
171 clients already under development.
172
173 <itemize>
174 <item>girc. (Included with GNOME)
175 <item>Bezerk (<htmlurl url="http://www.gtk.org/~trog/"
176                        name="http://www.gtk.org/~trog/">)
177 <item>gsirc. (Location?)
178 <item>Gnirc. (<htmlurl url="http://www.imaginet.fr/~dramboz/gnirc"
179                        name="http://www.imaginet.fr/~dramboz/gnirc">)
180 </itemize>
181
182
183 <!-- ***************************************************************** -->
184 <sect>How to find, configure, install, and troubleshoot GTK+
185
186 <!-- ***************************************************************** -->
187
188 <!-- ----------------------------------------------------------------- -->
189 <sect1>What do I need to run GTK+?
190 <p>
191 To compile GTK+, all you need is a C compiler (gcc) and the X Window System
192 and associated libraries on your system.
193
194 <!-- ----------------------------------------------------------------- -->
195 <sect1>Where can I get GTK+?
196 <p>
197 The canonical site is:
198 <verb>
199 ftp://ftp.gtk.org/pub/gtk
200 </verb>
201 Of course, any mirrors of ftp.gtk.org should have the latest version, too.
202
203 <sect1>How do I configure/compile GTK+?
204 <p>
205 Generally, all you will need to do is issue the commands:
206 <verb>
207 ./configure
208 make
209 </verb>
210 in the gtk+-version/ directory.
211
212 <!-- ----------------------------------------------------------------- -->
213 <sect1>When compiling GTK+ I get an error like: 
214 <tt/make: file `Makefile' line 456: Syntax error/
215 <p>
216 Make sure that you are using GNU make (use <tt/make -v/ to check). There are
217 many weird and wonderful versions of make out there, and not all of them
218 handle the automatically generated Makefiles.
219
220 <!-- ----------------------------------------------------------------- -->
221  
222 <sect1>I've compiled and installed GTK+, but I can't get any programs to link with it!
223 <p>
224 This problem is most often encountered when the GTK+ libraries can't be 
225 found or are the wrong version. Generally, the compiler will complain about an
226 'unresolved symbol'.  There are two things you need to check:
227 <itemize>
228 <item>Make sure that the libraries can be found. You want to edit 
229 /etc/ld.so.conf to include the directories which contain the GTK libraries,
230  so it looks something like:
231 <verb>
232 /usr/X11R6/lib
233 /usr/local/lib
234 </verb>
235 Then you need to run /sbin/ldconfig as root. You can find what directory
236 GTK is in using
237 <verb>
238 gtk-config --libs
239 </verb>
240
241 If your system doesn't use ld.so to find libraries (such as Solaris), then
242 you will have to use the LD_LIBRARY_PATH environment variable (or compile
243 the path into your program, which I'm not going to cover here). So, with a
244 Bourne type shell you can do (if your GTK libraries are in /usr/local/lib):
245 <verb>
246 export LD_LIBRARY_PATH=/usr/local/lib
247 </verb>
248 and in a csh, you can do:
249 <verb>
250 setenv LD_LIBRARY_PATH /usr/local/lib
251 </verb>
252
253 <item>Make sure the linker is finding the correct set of libraries. If you
254 have a Linux distribution that installs GTK+ (e.g. RedHat 5.0) then this 
255 older version may be used. Now (assuming you have a RedHat
256 system), issue the command
257 <verb>
258 rpm -e gtk gtk-devel
259 </verb>
260 You may also want to remove the packages that depend on gtk (rpm will tell you
261 which ones they are).  If you don't have a RedHat Linux system, check to make sure
262 that neither <verb>/usr/lib</verb> or <verb>/usr/local/lib</verb> contain any of
263 the libraries libgtk, libgdk, libglib, or libgck.  If they do exist, remove them
264 (and any gtk include files, such as /usr/include/gtk and /usr/include/gdk) 
265 and reinstall gtk+.
266 </itemize>
267
268 <!-- ----------------------------------------------------------------- -->
269 <sect1>When compiling programs with GTK+, I get compiler error messages about not being able to find <tt/"glibconfig.h"/.
270
271 <p> The header file "glibconfig.h" was moved to the directory
272 $exec_prefix/lib/glib/include/. $exec_prefix is the
273 directory that was specified by giving the --exec-prefix
274 flags to ./configure when compiling GTK+. It defaults to 
275 $prefix, (specified with --prefix), which in turn defaults
276 to /usr/local/.
277
278 This was done because "glibconfig.h" includes architecture
279 dependent information, and the rest of the include files
280 are put in $prefix/include, which can be shared between different
281 architectures. 
282
283 GTK+ includes a shell script, <tt/gtk-config/, that
284 makes it easy to find out the correct include paths.
285 The GTK+ tutorial includes an example of using <tt/gtk-config/
286 for simple compilation from the command line. For information
287 about more complicated configuration, see the file
288 docs/gtk-config.txt in the GTK+ distribution.
289
290 If you are trying to compile an old program, you may
291 be able to work around the problem by configuring it
292 with a command line like: 
293
294 <tscreen><verb>
295 CPPFLAGS="-I/usr/local/include/glib/include" ./configure
296 </verb></tscreen>
297
298 for Bourne-compatible shells like bash, or for csh variants:
299
300 <tscreen><verb>
301 setenv CPPFLAGS "-I/usr/local/include/glib/include" 
302 ./configure
303 </verb></tscreen>
304
305 (Substitute the appropriate value of $exec_prefix for /usr/local.)
306
307 <!-- ----------------------------------------------------------------- -->
308 <sect1>When installing The GIMP, configure reports that it can't find GTK.
309 <p>
310 There are several common reasons for this:
311 <itemize>
312 <item>You have an old version of GTK installed somewhere. RedHat 5.0, for 
313 example, installs an older copy of GTK that will not work with the latest 
314 versions of GIMP. You should remove this old copy, but note that in the case
315 of RedHat 5.0 this will break the <tt/control-panel/ applications.
316 <P>
317 <item><tt/gtk-config/ (or another component of GTK) isn't in your path, or
318 there is an old version on your system. Type:
319 <verb>
320 gtk-config --version
321 </verb>
322 to check for both of these. This should return a value of at least 0.99.8
323 for things to work properly with GIMP 0.99.23. If it returns a value
324 different from what you expect, then you have an old version of GTK on
325 your system.
326 <P>
327 <item>The ./configure script can't find the GTK libraries. As ./configure
328 compiles various test programs, it needs to be able to find the GTK
329 libraries. See the question above for help on this.
330 </itemize>
331 <p>
332 If none of the above help, then have a look in config.log, which is
333 generated by ./configure as it runs. At the bottom will be the last
334 action it took before failing. If it is a section of source code, copy
335 the source code to a file and compile it with the line just above it in
336 config.log. If the compilation is successful, try executing it.
337
338 <!-- ***************************************************************** -->
339 <sect>Development of GTK+
340 <!-- ***************************************************************** -->
341
342 <!-- ----------------------------------------------------------------- -->
343 <sect1>Whats this CVS thing that everyone keeps talking about, and how do I access it?
344 <p>
345 CVS is the Concurent Version System and is a very popular mean of 
346 version control for software projects. It is designed to allow multiple 
347 authors to be able to simultanously operate on the same source tree. 
348 This source tree is centrally maintained, but each developer has a
349 local mirror of this repository that they make there changes to.
350
351 The GTK+ developers use a CVS repository to store the master copy of
352 the current development version of GTK+. As such, people wishing to
353 contribute patches to GTK+ should generate them against the CVS version.
354 Normal people should use the packaged releases.
355
356 The CVS toolset is available as RPM packages from the usual RedHat sites.
357 The latest version is available at 
358 <htmlurl url="http://download.cyclic.com/pub/" 
359 name="&lt;http://download.cyclic.com/pub/&gt;">
360
361 Anyone can download the latest CVS version of GTK+ by using anonymous access
362 using the following steps:
363 <itemize>
364 <item> In a bourne shell descendant (e.g. bash) type:
365 <verb>
366 export CVSROOT=':pserver:anonymous@cvs.gimp.org:/debian/home/gnomecvs'
367 </verb>
368 <item>Next, the first time the source tree is checked out, a cvs login 
369 is needed. 
370 <verb>
371 cvs login
372 </verb>
373 This will ask you for a password. There is no password for cvs.gimp.org, 
374 so just enter a carriage return. 
375 <item>To get the tree and place it in a subdir of your current working directory, issue the command: 
376 <verb>
377 cvs -z9 get gtk+
378 </verb>
379 </itemize>
380 <!-- ----------------------------------------------------------------- -->
381 <sect1>How can I contribute to GTK+?
382 <p>
383 It's simple.  If something doesn't work like you think it should in a program,
384 check the documentation to make sure you're not missing something.  If it is a
385 true bug or missing feature, track it down in the GTK+ source, change it, 
386 and then generate a patch in the form of a 'context diff'. This can be done
387 using a command such as <tt/diff -ru &lt;oldfile&gt; &lt;newfile&gt;/. 
388 Then upload the patchfile to:
389 <verb>
390 ftp://ftp.gtk.org/incoming
391 </verb>
392 along with a README file.  Make sure you follow the naming conventions or your
393 patch will just be deleted! The filenames should be of this form:
394 <verb>
395 gtk-<username>-<date yymmdd-n>.patch.gz
396 gtk-<username>-<date yymmdd-n>.patch.README
397 </verb>
398 The "n" in the date indicates a unique number (starting from 0)
399 of patches you uploaded that day.  It should be 0, unless you
400 upload more than one patch in the same day.
401
402 Example:
403 <verb>
404 gtk-gale-982701-0.patch.gz
405 gtk-gale-982701-0.patch.README
406 </verb>
407 Once you upload <em>anything</em>, send the README to ftp-admin@gtk.org
408
409 <!-- ----------------------------------------------------------------- -->
410 <sect1>How do I know if my patch got applied, and if not, why not?
411 <p>
412 Uploaded patches will be moved to <tt>ftp://ftp.gtk.org/pub/gtk/patches</tt>
413 where one of the GTK+ development team will pick them up. If applied, they
414 will be moved to <tt>/pub/gtk/patches/old</tt>.
415
416 Patches that aren't applied, for whatever reason, are moved to 
417 <tt>/pub/gtk/patches/unapplied</tt> or <tt>/pub/gtk/patches/outdated</tt>.
418 At this point you can ask on the <tt/gtk-list/ mailing list why your patch
419 wasn't applied. There are many possible reasons why patches may not be
420 applied, ranging from it doesn't apply cleanly, to it isn't right. Don't
421 be put off if your patch didn't make it first time round.
422
423 <!-- ----------------------------------------------------------------- -->
424 <sect1>What is the policy on incorporating new widgets into the library?
425 <p>
426 This is up to the authors, so you will have to ask them once you
427 are done with your widget.  As a general guideline, widgets that are 
428 generally useful, work, and are not a disgrace to the widget set will 
429 gladly be included.
430
431 <!-- ----------------------------------------------------------------- -->
432 <sect1>Is anyone working on bindings for languages other than C?
433 <p>
434 Yes. There is 
435 <itemize>
436 <item>a C++ wrapper for GTK+ called gtk--. You can find the home page at:
437 <htmlurl url="http://www.cs.tut.fi/~p150650/gtk/gtk--.html"
438 name="http://www.cs.tut.fi/~p150650/gtk/gtk--.html">. 
439 The FTP site is 
440 <htmlurl url="ftp://ftp.gtk.org/pub/gtk/gtk--"
441 name="ftp://ftp.gtk.org/pub/gtk/gtk--">.
442 <p>
443
444 <item>There are two Objective-c bindings currently in development:
445
446  <itemize>
447
448  <item>The <htmlurl url="http://www.gnome.org/" name="GNOME project's"> package
449  of choice is obgtk. Objgtk is based on the Object class and is maintained by
450  <htmlurl url="mailto:sopwith@cuc.edu" name="Elliot Lee">. Apparently, objgtk
451  is being accepted as the `standard' Objective-C binding for GTK+.
452
453  <item>If you are more inclined towards the 
454  <htmlurl url="http://www.gnustep.org/" name="GNUstep project">,
455  you may want to check out GTKKit by 
456  <htmlurl url="mailto:helge@mdlink.de" name="Helge He&szlig;">.
457  The intention is to setup a GTK+ binding using the FoundationKit. 
458  GTKKit includes nicities like writing a XML-type template file to 
459  construct a GTK+ interface.
460
461  </itemize> 
462 <p>               
463 <item>Perl bindings
464 <htmlurl url="ftp://ftp.gtk.org/pub/gtk/perl"
465 name="ftp://ftp.gtk.org/pub/gtk/perl">
466 <P>
467 <item>Guile bindings. The home page is at
468 <htmlurl url="http://www.ping.de/sites/zagadka/guile-gtk"
469 name="http://www.ping.de/sites/zagadka/guile-gtk">.
470 By the way, Guile is the GNU Project's implemention of R4RS Scheme (the
471 standard). If you like Scheme, you may want to take a look at this.
472 <p>
473
474 <item>David Monniaux reports:
475 <quote>I've started a gtk-O'Caml binding system.
476 The basics of the system, including callbacks, work fine.
477
478 The current development is in
479 <htmlurl url="http://www.ens-lyon.fr/~dmonniau/arcs"
480 name="http://www.ens-lyon.fr/~dmonniau/arcs">
481 </quote>
482
483 <item>
484 Several python bindings have been done:
485 <p>
486 <itemize>
487 <item>pygtk is at 
488 <htmlurl url="http://www.daa.com.au/~james/pygtk" 
489 name="http://www.daa.com.au/~james/pygtk"> and 
490 <htmlurl url="ftp://ftp.gtk.org/pub/gtk/python"
491 name="ftp://ftp.gtk.org/pub/gtk/python">
492 <item>python-gtk is at
493 <htmlurl url="http://www.ucalgary.ca/~nascheme/python-gtk" 
494 name="http://www.ucalgary.ca/~nascheme/python-gtk">
495 </itemize>
496 <p>
497 <item>
498 There's a OpenGL/Mesa widget available for GTK+. Grab it at
499 <htmlurl url="http://www.sakuranet.or.jp/~aozasa/shige/doc/comp/gtk/gtkGL/files-en.html" 
500 name="http://www.sakuranet.or.jp/~aozasa/shige/doc/comp/gtk/gtkGL/files-en.html">
501
502 </itemize>
503
504 <!-- ***************************************************************** -->
505 <sect>Development with GTK+
506 <!-- ***************************************************************** -->
507 <!-- ----------------------------------------------------------------- -->
508 <sect1>How do I get started?
509 <p>
510 So, after you have installed GTK+ there are a couple of things that can
511 ease you into developing applications with it. There is the
512 GTK+ Tutorial <htmlurl url="http://www.gtk.org/tutorial/" 
513 name="&lt;http://www.gtk.org/tutorial/&gt;">, which is undergoing 
514 development. This will introduce you to writing applications using C.
515
516 The Tutorial doesn't (yet) contain information on all of the widgets
517 that are in GTK+. For example code on how to use the basics of all the
518 GTK+ widgets you should look at the file gtk/testgtk.c (and associated
519 source files) within the GTK+ distribution. Looking at these exmaples will
520 give you a good grounding on what the widgets can do.
521
522 <sect1>What widgets are in GTK?
523 <p>
524 The GTK+ Tutorial lists the following widgets:
525 <verb>
526   GtkObject
527    +GtkData
528    | +GtkAdjustment
529    | `GtkTooltips
530    `GtkWidget
531      +GtkContainer
532      | +GtkBin
533      | | +GtkAlignment
534      | | +GtkEventBox
535      | | +GtkFrame
536      | | | `GtkAspectFrame
537      | | +GtkHandleBox
538      | | +GtkItem
539      | | | +GtkListItem
540      | | | +GtkMenuItem
541      | | | | `GtkCheckMenuItem
542      | | | |   `GtkRadioMenuItem
543      | | | `GtkTreeItem
544      | | +GtkViewport
545      | | `GtkWindow
546      | |   +GtkColorSelectionDialog
547      | |   +GtkDialog
548      | |   | `GtkInputDialog
549      | |   `GtkFileSelection
550      | +GtkBox
551      | | +GtkButtonBox
552      | | | +GtkHButtonBox
553      | | | `GtkVButtonBox
554      | | +GtkHBox
555      | | | +GtkCombo
556      | | | `GtkStatusbar
557      | | `GtkVBox
558      | |   +GtkColorSelection
559      | |   `GtkGammaCurve
560      | +GtkButton
561      | | +GtkOptionMenu
562      | | `GtkToggleButton
563      | |   `GtkCheckButton
564      | |     `GtkRadioButton
565      | +GtkCList
566      |   `GtkCTree
567      | +GtkFixed
568      | +GtkList
569      | +GtkMenuShell
570      | | +GtkMenuBar
571      | | `GtkMenu
572      | +GtkNotebook
573      | +GtkPaned
574      | | +GtkHPaned
575      | | `GtkVPaned
576      | +GtkScrolledWindow
577      | +GtkTable
578      | +GtkToolbar
579      | `GtkTree
580      +GtkDrawingArea
581      | `GtkCurve
582      +GtkEditable
583      | +GtkEntry
584      | | `GtkSpinButton
585      | `GtkText
586      +GtkMisc
587      | +GtkArrow
588      | +GtkImage
589      | +GtkLabel
590      | | `GtkTipsQuery
591      | `GtkPixmap
592      +GtkPreview
593      +GtkProgressBar
594      +GtkRange
595      | +GtkScale
596      | | +GtkHScale
597      | | `GtkVScale
598      | `GtkScrollbar
599      |   +GtkHScrollbar
600      |   `GtkVScrollbar
601      +GtkRuler
602      | +GtkHRuler
603      | `GtkVRuler
604      `GtkSeparator
605        +GtkHSeparator
606        `GtkVSeparator
607 </verb>
608
609 <!-- ----------------------------------------------------------------- -->
610 <sect1>Is GTK+ thread safe? How do I write multi-threaded GTK+ applications?
611 <p>
612 Although GTK+, like many X toolkits, isn't thread safe, this does
613 not prohibit the development of multi-threaded applications with
614 GTK+. 
615
616 Rob Browning (rlb@cs.utexas.edu) describes threading techniques for
617 use with GTK+ (slightly edited): 
618
619 There are basically two main approaches, the first is simple, and the
620 second complicated. In the first, you just make sure that all GTK+ (or
621 X) interactions are handled by one, and
622 only one, thread. Any other thread that wants to draw something has
623 to somehow notify the "GTK+" thread, and let it handle the
624 actual work. 
625
626 The second approach allows you to call GTK+ (or X) functions from any
627 thread, but it requires some careful synchronization. The
628 basic idea is that you create an X protection mutex, and no one may
629 make any X calls without first acquiring this mutex. 
630
631 Note that this is a little effort, but it allows you to be
632 potentially more efficient than a completely thread safe GTK+. You
633 get to decide the granularity of the thread locking. You also have to
634 make sure that the thread that calls gtk_main is holding the lock when
635 it calls gtk_main.
636
637 The next thing to worry about is that since you were holding the
638 global mutex when you entered gtk_main, all callbacks will also be
639 holding it. This means that the callback must release it if it's
640 going to call any other code that might reacquire it. Otherwise
641 you'll get deadlock. Also, you must be holding the mutex when you
642 finally return from the callback. 
643
644 In order to allow threads other than the one calling gtk_main to
645 get access to the mutex, we also need to register a work function
646 with GTK that allows us to release the mutex periodically.
647
648 Why can't GTK+ be thread safe by default?                           
649
650 Complexity, overhead, and manpower.  The proportion of threaded
651 programs is still reasonably small, and getting thread safety right is
652 both quite difficult and takes valuable time away from the main work
653 of getting a good graphics library finished.  It would be nice to have
654 GTK+ thread safe "out of the box", but that's not practical right now,
655 and it also might make GTK+ substantially less efficient if not handled
656 carefully.
657
658 Regardless, it's especially not a priority since relatively good
659 workarounds exist.
660
661 <!-- ----------------------------------------------------------------- -->
662 <sect1>How can I prevent redrawing and resizing while I change multiple widgets?
663 <p> 
664 Use gtk_container_disable_resize and gtk_container_enable_resize around the 
665 code where you are changing a lot of stuff. This will result in much faster 
666 speed since it will prevent resizing of the entire widget hierarchy. 
667
668 <!-- ----------------------------------------------------------------- -->
669 <sect1>How do I catch a double click event (in a list widget, for example)?
670 <p>
671 Tim Janik wrote to gtk-list (slightly modified):
672
673 Define a signal handler:
674
675 <tscreen><verb>
676 gint
677 signal_handler_event(GtkWiget *widget, GdkEvenButton *event, gpointer func_data)
678 {
679   if (GTK_IS_LIST_ITEM(widget) &&
680        (event->type==GDK_2BUTTON_PRESS ||
681         event->type==GDK_3BUTTON_PRESS) ) {
682     printf("I feel %s clicked on button %d\",
683            event->type==GDK_2BUTTON_PRESS ? "double" : "triple",
684            event->button);
685   }
686
687   return FALSE;
688 }
689 </verb></tscreen>
690
691 And connect the handler to your object:
692
693 <tscreen><verb>
694 {
695   /* list, list item init stuff */     
696
697   gtk_signal_connect(GTK_OBJECT(list_item),
698                      "button_press_event",
699                      GTK_SIGNAL_FUNC(signal_handler_event),
700                      NULL);
701
702   /* and/or */
703
704   gtk_signal_connect(GTK_OBJECT(list_item),
705                      "button_release_event",
706                      GTK_SIGNAL_FUNC(signal_handler_event),
707                      NULL);
708
709   /* something else */
710 }
711 </verb></tscreen>
712
713 and, Owen Taylor wrote:
714
715 Note that a single button press will be received beforehand, and
716 if you are doing this for a button, you will therefore also get a
717 "clicked" signal for the button. (This is going to be true for
718 any toolkit, since computers aren't good at reading one's
719 mind.)
720                                        
721 <!-- ----------------------------------------------------------------- -->
722 <sect1>How do I find out about the selection of a GtkList?
723 <p>
724
725 Get the selection something like this:
726 <tscreen><verb>
727 GList *sel;
728 sel = GTK_LIST(list)->selection;
729 </verb></tscreen>
730
731 This is how GList is defined (quoting glist.h):
732 <tscreen><verb>
733 typedef struct _GList GList;
734
735 struct _GList
736 {
737   gpointer data;
738   GList *next;
739   GList *prev;
740 };
741 </verb></tscreen>
742
743 A GList structure is just a simple structure for doubly linked lists.
744 there exist several g_list_*() functions to modify a linked list in
745 glib.h.  However the GTK_LIST(MyGtkList)->selection is maintained
746 by the gtk_list_*() functions and should not be modified.
747
748 The selection_mode of the GtkList determines the selection
749 facilities of a GtkList and therefore the contents
750 of GTK_LIST(AnyGtkList)->selection:
751
752 <verb>
753 selection_mode          GTK_LIST()->selection contents
754 ------------------------------------------------------
755
756 GTK_SELECTION_SINGLE)   selection is either NULL
757                         or contains a GList* pointer
758                         for a single selected item.
759
760 GTK_SELECTION_BROWSE)   selection is NULL if the list
761                         contains no widgets, otherwise
762                         it contains a GList* pointer
763                         for one GList structure.
764 GTK_SELECTION_MULTIPLE) selection is NULL if no listitems
765                         are selected or a a GList* pointer
766                         for the first selected item. that
767                         in turn points to a GList structure
768                         for the second selected item and so
769                         on
770
771 GTK_SELECTION_EXTENDED) selection is NULL.
772 </verb>
773
774 The data field of the GList structure GTK_LIST(MyGtkList)->selection points
775 to the first GtkListItem that is selected.  So if you would like to determine 
776 which listitems are selected you should go like this:
777
778 Upon Initialization:
779 <tscreen><verb>
780 {
781         gchar           *list_items[]={
782                                 "Item0",
783                                 "Item1",
784                                 "foo",
785                                 "last Item",
786                         };
787         guint           nlist_items=sizeof(list_items)/sizeof(list_items[0]);
788         GtkWidget       *list_item;
789         guint           i;
790
791         list=gtk_list_new();
792         gtk_list_set_selection_mode(GTK_LIST(list), GTK_SELECTION_MULTIPLE);
793         gtk_container_add(GTK_CONTAINER(AnyGtkContainer), list);
794         gtk_widget_show (list);
795
796         for (i = 0; i < nlist_items; i++)
797         {
798                 list_item=gtk_list_item_new_with_label(list_items[i]);
799                 gtk_object_set_user_data(GTK_OBJECT(list_item), (gpointer)i);
800                 gtk_container_add(GTK_CONTAINER(list), list_item);
801                 gtk_widget_show(list_item);
802         }
803 }
804 </verb></tscreen>
805
806 To get known about the selection:
807 <tscreen><verb>
808 {
809         GList   *items;
810
811         items=GTK_LIST(list)->selection;
812
813         printf("Selected Items: ");
814         while (items) {
815                 if (GTK_IS_LIST_ITEM(items->data))
816                         printf("%d ", (guint) 
817                 gtk_object_get_user_data(items->data));
818                 items=items->next;
819         }
820         printf("\n");
821 }
822 </verb></tscreen>
823 <!-- ----------------------------------------------------------------- -->
824 <sect1>Is it possible to get some text displayed which is truncated to fit inside its allocation? 
825 <p>
826 GTK's behavior (no clipping) is a consequence of its attempts to
827 conserve X resources. Label widgets (among others) don't get their own
828 X window - they just draw their contents on their parent's window.
829 While it might be possible to have clipping occur by setting the clip
830 mask before drawing the text, this would probably cause a substantial
831 performance penalty.
832
833 Its possible that, in the long term, the best solution to such
834 problems might be just to change gtk to give labels X windows.
835 A short term workaround is to put the label widget inside another
836 widget that does get it's own window - one possible candidate would
837 be the viewport widget.
838
839 <tscreen><verb>
840 viewport = gtk_viewport (NULL, NULL);
841 gtk_widget_set_usize (viewport, 50, 25);
842 gtk_viewport_set_shadow_type (GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
843 gtk_widget_show(viewport);
844
845 label = gtk_label ("a really long label that won't fit");
846 gtk_container_add (GTK_CONTAINER(viewport), label);
847 gtk_widget_show (label);
848 </verb></tscreen>
849
850 If you were doing this for a bunch of widgets, you might want to
851 copy gtkviewport.c and strip out the adjustment and shadow
852 functionality (perhaps you could call it GtkClipper).
853
854 <!-- ----------------------------------------------------------------- -->
855 <sect1>Why don't the contents of a button move when the button is pressed? Here's a patch to make it work that way...
856 <p>
857 From: Peter Mattis
858
859 The reason buttons don't move their child down and to the right when
860 they are depressed is because I don't think that's what is happening
861 visually. My view of buttons is that you are looking at them straight
862 on. That is, the user interface lies in a plane and you're above it
863 looking straight at it. When a button gets pressed it moves directly
864 away from you. To be absolutely correct I guess the child should
865 actually shrink a tiny amount. But I don't see why the child should
866 shift down and to the left. Remember, the child is supposed to be
867 attached to the buttons surface. Its not good for it to appear like
868 the child is slipping on the surface of the button.
869
870 On a more practical note, I did implement this at one point and
871 determined it didn't look good and removed it.
872      
873 <!-- ----------------------------------------------------------------- -->
874 <sect1>How can I define a separation line in a menu? 
875 <p>
876 See the <htmlurl url="http://www.gtk.org/tutorial/"
877 name="Tutorial"> for information on how to create menus.
878 However, to create a separation line in a menu, just insert an
879 empty menu item:
880
881 <tscreen><verb>
882 menuitem = gtk_menu_item_new();
883 gtk_menu_append(GTK_MENU(menu), menuitem);
884 gtk_widget_show(menuitem);
885 </verb></tscreen>
886
887 <!-- ----------------------------------------------------------------- -->
888 <sect1>How can I right justify a menu, such as Help, when using the MenuFactory? 
889 <p>
890 Use something like the following:
891
892 <tscreen><verb>
893 menu_path = gtk_menu_factory_find (factory,  "<MyApp>/Help");
894 gtk_menu_item_right_justify(menu_path->widget);
895 </verb></tscreen>
896 <!-- ----------------------------------------------------------------- -->
897 <sect1>How do I make my window modal? / How do I make a single window active?
898 <p>
899 After you create your window, do gtk_grab_add(my_window). And after 
900 closing the window do gtk_grab_remove(my_window).
901
902 <!-- ----------------------------------------------------------------- -->
903 <sect1>Why doesn't my widget (e.g. progressbar) update?
904 <p>
905
906 You are probably doing all the changes within a function 
907 without returning control to gtk_main. Most drawing updates are only 
908 placed on a queue, which is processed within gtk_main. You can
909 force the drawing queue to be processed using something like:
910
911 <tscreen><verb>
912 while (gtk_events_pending())
913         gtk_main_iteration();
914 </verb></tscreen>
915
916 inside you're function that changes the widget.
917
918 What the above snippet does is run all pending events and high priority 
919 idle functions, then return immediately (the drawing is done in a 
920 high priority idle function).
921
922 <!-- ***************************************************************** -->
923 <sect>About gdk
924 <!-- ***************************************************************** -->
925
926 <!-- ----------------------------------------------------------------- -->
927 <sect1>What is gdk?
928 <p>
929 gdk is basically a wrapper around the standard Xlib function calls. If you are
930 at all familiar with Xlib, a lot of the functions in gdk will require little 
931 or no getting used to. All functions are written to provide an easy way 
932 to access Xlib functions in an easier an slightly more intuitive manner. 
933 In addition, since gdk uses glib (see below), it will be more portable 
934 and safer to use on multiple platforms.
935
936 <!-- Examples, anybody? I've been mulling some over. NF -->
937    
938 <sect1>How do I use color allocation?
939 <p>
940 One of the nice things about GDK is that it's based on top of Xlib; this is 
941 also a problem, especially in the area of color management. If you want 
942 to use color in your program (drawing a rectangle or such, your code 
943 should look something like this:
944 <tscreen>
945 <verb>
946 {
947   GdkColor *color;
948   int width, height;
949   GtkWidget *widget;
950   GdkGC *gc;
951
952   ...
953   
954   /* first, create a GC to draw on */
955   gc = gdk_gc_new(widget->window);
956
957   /* find proper dimensions for rectangle */
958   gdk_window_get_size(widget->window, &amp;width, &amp;height);
959
960   /* the color we want to use */
961   color = (GdkColor *)malloc(sizeof(GdkColor));
962   
963   /* red, green, and blue are passed values, indicating the RGB triple
964    * of the color we want to draw. Note that the values of the RGB components
965    * within the GdkColor are taken from 0 to 65535, not 0 to 255.
966    */
967   color->red = red * (65535/255);
968   color->green = green * (65535/255);
969   color->blue = blue * (65535/255);
970   
971   /* the pixel value indicates the index in the colormap of the color.
972    * it is simply a combination of the RGB values we set earlier
973    */
974   color->pixel = (gulong)(red*65536 + green*256 + blue);
975
976   /* However, the pixel valule is only truly valid on 24-bit (TrueColor)
977    * displays. Therefore, this call is required so that GDK and X can
978    * give us the closest color available in the colormap
979    */
980   gdk_color_alloc(gtk_widget_get_colormap(widget), color);
981
982   /* set the foreground to our color */
983   gdk_gc_set_foreground(gc, color);
984   
985   /* draw the rectangle */
986   gdk_draw_rectangle(widget->window, gc, 1, 0, 0, width, height);
987
988   ...
989 }
990 </verb>
991 </tscreen>
992
993 <!-- ***************************************************************** -->
994 <sect>About glib
995 <!-- ***************************************************************** -->
996
997 <!-- ----------------------------------------------------------------- -->
998 <sect1>What is glib?
999 <p>
1000 glib is a library of useful functions and definitions available for use 
1001 when creating GDK and GTK applications. It provides replacements for some
1002 standard libc functions, such as malloc, which are buggy on some systems.
1003 <p>
1004 It also provides routines for handling:
1005 <itemize>
1006 <item>Doubly Linked Lists
1007 <item>Singly Linked Lists
1008 <item>Timers
1009 <item>String Handling
1010 <item>A Lexical Scanner
1011 <item>Error Functions
1012 </itemize>
1013
1014 <!-- Some Examples might be useful here! NF -->         
1015
1016 <!-- ----------------------------------------------------------------- -->
1017 <sect1>Why use g_print, g_malloc, g_strdup and fellow glib functions ?  
1018 <p>
1019 Thanks to Tim Janik who wrote to gtk-list: (slightly modified)
1020 <quote>
1021 Regarding g_malloc(), g_free() and siblings, these functions are much safer
1022 than thier libc equivalences.  For example, g_free() just returns if called 
1023 with NULL.  Also, if USE_DMALLOC is defined, the definition for these 
1024 functions changes (in glib.h) to use MALLOC(), FREE() etc...  If MEM_PROFILE
1025 or MEM_CHECK are defined, there are even small statistics made counting
1026 the used block sizes (shown by g_mem_profile() / g_mem_check()).
1027 <p>
1028 Considering the fact that glib provides an interface for memory chunks
1029 to save space if you have lots of blocks that are always the same size
1030 and to mark them ALLOC_ONLY if needed, it is just straight forward to
1031 create a small saver (debug able) wrapper around the normal malloc/free
1032 stuff as well - just like gdk covers Xlib. ;)
1033 <p>
1034 Using g_error() and g_warning() inside of applications like the GIMP
1035 that fully rely on gtk even gives the opportunity to pop up a window
1036 showing the messages inside of a gtk window with your own handler
1037 (by using g_set_error_handler()) along the lines of gtk_print()
1038 (inside of gtkmain.c).
1039 </quote>
1040
1041 <!-- ***************************************************************** -->
1042 <sect>GTK+ FAQ Contributions, Maintainers and Copyright
1043 <p>
1044 If you would like to make a contribution to the FAQ, send either one of us
1045 an e-mail message with the exact text you think should be included (question and
1046 answer).  With your help, this document can grow and become more useful!
1047
1048 This document is maintained by Nathan Froyd 
1049 <htmlurl url="mailto:maestrox@geocities.com" name="&lt;maestrox@geocities.com&gt;">
1050 and Tony Gale <htmlurl url="mailto:gale@gimp.org" name="&lt;gale@gimp.org&gt;">. 
1051 This FAQ was created by Shawn T. Amundson <htmlurl url="mailto:amundson@gimp.org" 
1052 name="&lt;amundson@gimp.org&gt;">who continues to provide support.
1053
1054 The GTK+ FAQ is Copyright (C) 1997,1998 by Shawn T. Amundson, Nathan Froyd and Tony Gale.
1055
1056 Permission is granted to make and distribute verbatim copies of this manual provided the 
1057 copyright notice and this permission notice are preserved on all copies.
1058
1059 Permission is granted to copy and distribute modified versions of this document under the conditions 
1060 for verbatim copying, provided that this copyright notice is included exactly as in the original, 
1061 and that the entire resulting derived work is distributed under the terms of a permission 
1062 notice identical to this one.
1063
1064 Permission is granted to copy and distribute translations of this document into another language, 
1065 under the above conditions for modified versions.
1066
1067 If you are intending to incorporate this document into a published work, please contact one of
1068 the maintainers, and we will make an effort to ensure that you have the most up to date 
1069 information available.
1070
1071 There is no guarentee that this document lives up to its intended
1072 purpose.  This is simply provided as a free resource.  As such,
1073 the authors and maintainers of the information provided within can 
1074 not make any guarentee that the information is even accurate.
1075
1076 </article>