]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/body.tex
added wxTopLevelWindow::RequestUserAttention(); documented it and implemented it...
[wxWidgets.git] / docs / latex / wx / body.tex
CommitLineData
a660d684
KB
1\chapter{Introduction}\label{introduction}
2\pagenumbering{arabic}%
3\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
4\setfooter{\thepage}{}{}{}{}{\thepage}%
5
fc2171bd 6\section{What is wxWidgets?}
a660d684 7
fc2171bd 8wxWidgets is a C++ framework providing GUI (Graphical User
fa482912 9Interface) and other facilities on more than one platform. Version 2 currently
bd330a69
JS
10supports all desktop versions of MS Windows, Unix with GTK+, Unix with Motif,
11and MacOS. An OS/2 port is in progress.
a660d684 12
fc2171bd 13wxWidgets was originally developed at the Artificial Intelligence
fa482912 14Applications Institute, University of Edinburgh, for internal use,
bd330a69 15and was first made publicly available in 1992.
fa482912 16Version 2 is a vastly improved version written and maintained by
bd330a69 17Julian Smart, Robert Roebling, Vadim Zeitlin, Vaclav Slavik and many others.
a660d684 18
bd330a69 19This manual contains a class reference and topic overviews.
fc2171bd 20For a selection of wxWidgets tutorials, please see the documentation page on the \urlref{wxWidgets web site}{http://www.wxwidgets.org}.
a660d684
KB
21
22Please note that in the following, ``MS Windows" often refers to all
23platforms related to Microsoft Windows, including 16-bit and 32-bit
24variants, unless otherwise stated. All trademarks are acknowledged.
25
26\section{Why another cross-platform development tool?}
27
fc2171bd 28wxWidgets was developed to provide a cheap and flexible way to maximize
a660d684 29investment in GUI application development. While a number of commercial
8a2c6ef8 30class libraries already existed for cross-platform development,
a660d684
KB
31none met all of the following criteria:
32
33\begin{enumerate}\itemsep=0pt
34\item low price;
35\item source availability;
36\item simplicity of programming;
37\item support for a wide range of compilers.
38\end{enumerate}
39
fc2171bd 40Since wxWidgets was started, several other free or almost-free
bd330a69
JS
41GUI frameworks have emerged. However, none has the range of
42features, flexibility, documentation and the well-established
fc2171bd 43development team that wxWidgets has.
bd330a69 44
fc2171bd 45As open source software, wxWidgets has benefited from comments,
bd330a69 46ideas, bug fixes, enhancements and the sheer enthusiasm of
fc2171bd 47users. This gives wxWidgets a certain advantage over its
bd330a69
JS
48commercial competitors (and over free libraries without an
49independent development team), plus a robustness against the
50transience of one individual or company. This openness and
51availability of source code is especially important when the
52future of thousands of lines of application code may depend upon
53the longevity of the underlying class library.
54
55Version 2 goes much further than previous versions in terms of
56generality and features, allowing applications to be produced
57that are often indistinguishable from those produced using
58single-platform toolkits such as Motif, GTK+ and MFC.
59
60The importance of using a platform-independent class library
61cannot be overstated, since GUI application development is very
62time-consuming, and sustained popularity of particular GUIs
63cannot be guaranteed. Code can very quickly become obsolete if
fc2171bd 64it addresses the wrong platform or audience. wxWidgets helps to
bd330a69 65insulate the programmer from these winds of change. Although
fc2171bd 66wxWidgets may not be suitable for every application (such as an
bd330a69
JS
67OLE-intensive program), it provides access to most of the
68functionality a GUI program normally requires, plus many extras
69such as network programming, PostScript output, and HTML
70rendering; and it can of course be extended as needs dictate.
71As a bonus, it provides a far cleaner and easier programming
72interface than the native APIs. Programmers may find it
fc2171bd 73worthwhile to use wxWidgets even if they are developing on only
bd330a69 74one platform.
a660d684 75
fc2171bd 76It is impossible to sum up the functionality of wxWidgets in a few paragraphs, but
a660d684
KB
77here are some of the benefits:
78
79\begin{itemize}\itemsep=0pt
80\item Low cost (free, in fact!)
81\item You get the source.
8a2c6ef8 82\item Available on a variety of popular platforms.
ccaaf5b0 83\item Works with almost all popular C++ compilers and Python.
fa482912
JS
84\item Over 50 example programs.
85\item Over 1000 pages of printable and on-line documentation.
8a2c6ef8
JS
86\item Includes Tex2RTF, to allow you to produce your own documentation
87in Windows Help, HTML and Word RTF formats.
a660d684 88\item Simple-to-use, object-oriented API.
8a2c6ef8
JS
89\item Flexible event system.
90\item Graphics calls include lines, rounded rectangles, splines, polylines, etc.
f6bcfd97 91\item Constraint-based and sizer-based layouts.
a660d684 92\item Print/preview and document/view architectures.
8a2c6ef8 93\item Toolbar, notebook, tree control, advanced list control classes.
ccaaf5b0 94\item PostScript generation under Unix, normal MS Windows printing on the PC.
62448488
JS
95\item MDI (Multiple Document Interface) support.
96\item Can be used to create DLLs under Windows, dynamic libraries on Unix.
a660d684
KB
97\item Common dialogs for file browsing, printing, colour selection, etc.
98\item Under MS Windows, support for creating metafiles and copying
99them to the clipboard.
62448488 100\item An API for invoking help from applications.
fa482912 101\item Ready-to-use HTML window (supporting a subset of HTML).
8a2c6ef8 102\item Network support via a family of socket and protocol classes.
f6bcfd97 103\item Support for platform independent image processing.
ccaaf5b0 104\item Built-in support for many file formats (BMP, PNG, JPEG, GIF, XPM, PNM, PCX).
a660d684
KB
105\end{itemize}
106
d958c9bd 107\begin{comment}
ccaaf5b0
RR
108\section{Changes from version 2.0}\label{versionchanges20}
109
110These are a few of the differences between versions 2.0 and 2.2.
111
112Removals:
113
114\begin{itemize}\itemsep=0pt
115\item GTK 1.0 no longer supported.
116\end{itemize}
117
118Additions and changes:
119
120\begin{itemize}\itemsep=0pt
121\item Corrected many classes to conform better to documented behaviour.
122\item Added handlers for more image formats (Now GIF, JPEG, PCX, BMP, XPM, PNG, PNM).
123\item Improved support for socket and network functions.
124\item Support for different national font encodings.
125\item Sizer based layout system.
126\item HTML widget and help system.
127\item Added some controls (e.g. wxSpinCtrl) and supplemented many.
128\item Many optical improvements to GTK port.
129\item Support for menu accelerators in GTK port.
130\item Enhanced and improved support for scrolling, including child windows.
f6bcfd97 131\item Complete rewrite of clipboard and drag and drop classes.
ccaaf5b0
RR
132\item Improved support for ODBC databases.
133\item Improved tab traversal in dialogs.
134\end{itemize}
d958c9bd 135\end{comment}
ccaaf5b0 136
fc2171bd 137\section{wxWidgets requirements}\label{requirements}
a660d684 138
fc2171bd 139To make use of wxWidgets, you currently need one of the following setups.
a660d684 140
1d0b7ed3 141(a) MS-Windows:
a660d684
KB
142
143\begin{enumerate}\itemsep=0pt
144\item A 486 or higher PC running MS Windows.
8a2c6ef8
JS
145\item A Windows compiler: most are supported, but please see {\tt install.txt} for
146details. Supported compilers include Microsoft Visual C++ 4.0 or higher, Borland C++, Cygwin,
0497e172 147MinGW, Metrowerks CodeWarrior.
bd0df01f 148\item At least 60 MB of disk space.
a660d684
KB
149\end{enumerate}
150
bd0df01f 151(b) Unix:
a660d684
KB
152
153\begin{enumerate}\itemsep=0pt
91b8de8d 154\item Almost any C++ compiler, including GNU C++ (EGCS 1.1.1 or above).
e3ba9f88 155\item Almost any Unix workstation, and one of: GTK+ 1.2, GTK+ 2.0, Motif 1.2 or higher, Lesstif.
0497e172 156If using the wxX11 port, no such widget set is required.
bd0df01f 157\item At least 60 MB of disk space.
a660d684
KB
158\end{enumerate}
159
1d0b7ed3
GD
160(c) Mac OS/Mac OS X:
161
162\begin{enumerate}\itemsep=0pt
163\item A PowerPC Mac running Mac OS 8.6/9.x (eg. Classic) or Mac OS X 10.x.
164\item CodeWarrior 5.3, 6 or 7 for Classic Mac OS.
165\item The Apple Developer Tools (eg. GNU C++) or CodeWarrior 7 for Mac OS X.
166\item At least 60 MB of disk space.
167\end{enumerate}
168
fc2171bd 169\section{Availability and location of wxWidgets}
a660d684 170
fc2171bd
JS
171\winhelponly{wxWidgets is available by anonymous FTP and World Wide Web
172from ftp://biolpc22.york.ac.uk/pub and/or http://www.wxwidgets.org.}
173\winhelpignore{wxWidgets is available by anonymous FTP and World Wide Web
f44b23b6 174from \urlref{ftp://biolpc22.york.ac.uk/pub}{ftp://biolpc22.york.ac.uk/pub}
fc2171bd 175and/or \urlref{http://www.wxwidgets.org}{http://www.wxwidgets.org}.}
a660d684 176
d958c9bd 177You can also buy a CD-ROM using the form on the Web site.
448af9a4 178
2edb0bde 179\section{Acknowledgements}
a660d684 180
bd0df01f 181Thanks are due to AIAI for being willing to release the original version of
fc2171bd 182wxWidgets into the public domain, and to our patient partners.
bd0df01f 183
fc2171bd 184We would particularly like to thank the following for their contributions to wxWidgets, and the many others who have been involved in
bd0df01f
JS
185the project over the years. Apologies for any unintentional omissions from this list.
186
ecd7e67e
WS
187Yiorgos Adamopoulos, Jamshid Afshar, Alejandro Aguilar-Sierra, AIAI,
188Patrick Albert, Karsten Ballueder, Mattia Barbon, Michael Bedward,
189Kai Bendorf, Yura Bidus, Keith Gary Boyce, Chris Breeze, Pete Britton,
6652e1a7 190Ian Brown, C. Buckley, Marco Cavallini, Dmitri Chubraev, Robin Corbet, Cecil Coupe,
ecd7e67e
WS
191Stefan Csomor, Andrew Davison, Gilles Depeyrot, Neil Dudman, Robin Dunn,
192Hermann Dunkel, Jos van Eijndhoven, Chris Elliott, David Elliott, Tom Felici,
193Thomas Fettig, Matthew Flatt, Pasquale Foggia, Josep Fortiana, Todd Fries,
194Dominic Gallagher, Guillermo Rodriguez Garcia, Wolfram Gloger, Norbert Grotz,
195Stefan Gunter, Bill Hale, Patrick Halke, Stefan Hammes, Guillaume Helle,
196Harco de Hilster, Cord Hockemeyer, Markus Holzem, Olaf Klein, Leif Jensen,
197Bart Jourquin, Guilhem Lavaux, Ron Lee, Jan Lessner, Nicholas Liebmann,
198Torsten Liermann, Per Lindqvist, Thomas Runge, Tatu M\"{a}nnist\"{o},
199Scott Maxwell, Thomas Myers, Oliver Niedung, Stefan Neis, Hernan Otero,
200Ian Perrigo, Timothy Peters, Giordano Pezzoli, Harri Pasanen, Thomaso Paoletti,
201Garrett Potts, Marcel Rasche, Robert Roebling, Dino Scaringella,
202Jobst Schmalenbach, Arthur Seaton, Paul Shirley, Wlodzimierz `ABX' Skiba,
203Vaclav Slavik, Julian Smart, Stein Somers, Petr Smilauer, Neil Smith,
204Kari Syst\"{a}, George Tasker, Arthur Tetzlaff-Deas, Jonathan Tonberg,
205Jyrki Tuomi, Janos Vegh, Andrea Venturoli, David Webster, Otto Wyss,
206Vadim Zeitlin, Xiaokun Zhu, Edward Zimmermann.
a660d684
KB
207
208`Graphplace', the basis for the wxGraphLayout library, is copyright Dr. Jos
209T.J. van Eijndhoven of Eindhoven University of Technology. The code has
210been used in wxGraphLayout with his permission.
211
bd0df01f 212We also acknowledge the author of XFIG, the excellent Unix drawing tool,
a660d684
KB
213from the source of which we have borrowed some spline drawing code.
214His copyright is included below.
215
216{\it XFig2.1 is copyright (c) 1985 by Supoj Sutanthavibul. Permission to
217use, copy, modify, distribute, and sell this software and its
218documentation for any purpose is hereby granted without fee, provided
219that the above copyright notice appear in all copies and that both that
220copyright notice and this permission notice appear in supporting
221documentation, and that the name of M.I.T. not be used in advertising or
222publicity pertaining to distribution of the software without specific,
223written prior permission. M.I.T. makes no representations about the
224suitability of this software for any purpose. It is provided ``as is''
225without express or implied warranty.}
226
fc2171bd 227\chapter{Multi-platform development with wxWidgets}\label{multiplat}
a660d684
KB
228\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
229\setfooter{\thepage}{}{}{}{}{\thepage}%
230
fc2171bd 231This chapter describes the practical details of using wxWidgets. Please
a660d684
KB
232see the file install.txt for up-to-date installation instructions, and
233changes.txt for differences between versions.
234
235\section{Include files}
236
bd0df01f 237The main include file is {\tt "wx/wx.h"}; this includes the most commonly
fc2171bd 238used modules of wxWidgets.
a660d684
KB
239
240To save on compilation time, include only those header files relevant to the
241source file. If you are using precompiled headers, you should include
242the following section before any other includes:
243
244\begin{verbatim}
245// For compilers that support precompilation, includes "wx.h".
bd0df01f 246#include <wx/wxprec.h>
a660d684
KB
247
248#ifdef __BORLANDC__
249#pragma hdrstop
250#endif
251
252#ifndef WX_PRECOMP
bd0df01f
JS
253// Include your minimal set of headers here, or wx.h
254#include <wx/wx.h>
a660d684
KB
255#endif
256
257... now your other include files ...
258\end{verbatim}
259
bd0df01f 260The file {\tt "wx/wxprec.h"} includes {\tt "wx/wx.h"}. Although this incantation
a660d684
KB
261may seem quirky, it is in fact the end result of a lot of experimentation,
262and several Windows compilers to use precompilation (those tested are Microsoft Visual C++, Borland C++
263and Watcom C++).
264
bd0df01f 265Borland precompilation is largely automatic. Visual C++ requires specification of {\tt "wx/wxprec.h"} as
a660d684
KB
266the file to use for precompilation. Watcom C++ is automatic apart from the specification of
267the .pch file. Watcom C++ is strange in requiring the precompiled header to be used only for
268object files compiled in the same directory as that in which the precompiled header was created.
fc2171bd 269Therefore, the wxWidgets Watcom C++ makefiles go through hoops deleting and recreating
a660d684
KB
270a single precompiled header file for each module, thus preventing an accumulation of many
271multi-megabyte .pch files.
272
273\section{Libraries}
274
fc2171bd
JS
275Most ports of wxWidgets can create either a static library or a shared
276library. wxWidgets can also be built in multilib and monolithic variants.
0497e172
JS
277See the \helpref{libraries list}{librarieslist} for more
278information on these.
a660d684
KB
279
280\section{Configuration}
281
fc2171bd 282When using project files and makefiles directly to build wxWidgets,
0497e172 283options are configurable in the file
ccaaf5b0
RR
284\rtfsp{\tt "wx/XXX/setup.h"} where XXX is the required platform (such as msw, motif, gtk, mac). Some
285settings are a matter of taste, some help with platform-specific problems, and
62448488
JS
286others can be set to minimize the size of the library. Please see the setup.h file
287and {\tt install.txt} files for details on configuration.
a660d684 288
fc2171bd 289When using the 'configure' script to configure wxWidgets (on Unix and other platforms where
0497e172
JS
290configure is available), the corresponding setup.h files are generated automatically
291along with suitable makefiles. When using the RPM packages
fc2171bd 292for installing wxWidgets on Linux, a correct setup.h is shipped in the package and
ccaaf5b0
RR
293this must not be changed.
294
a660d684
KB
295\section{Makefiles}
296
fc2171bd 297On Microsoft Windows, wxWidgets has a different set of makefiles for each
0497e172
JS
298compiler, because each compiler's 'make' tool is slightly different.
299Popular Windows compilers that we cater for, and the corresponding makefile
300extensions, include: Microsoft Visual C++ (.vc), Borland C++ (.bcc),
301OpenWatcom C++ (.wat) and MinGW/Cygwin (.gcc). Makefiles are provided
fc2171bd 302for the wxWidgets library itself, samples, demos, and utilities.
0497e172
JS
303
304On Linux, Mac and OS/2, you use the 'configure' command to
305generate the necessary makefiles. You should also use this method when
306building with MinGW/Cygwin on Windows.
307
308We also provide project files for some compilers, such as
309Microsoft VC++. However, we recommend using makefiles
fc2171bd 310to build the wxWidgets library itself, because makefiles
0497e172
JS
311can be more powerful and less manual intervention is required.
312
313On Windows using a compiler other than MinGW/Cygwin, you would
fc2171bd 314build the wxWidgets library from the build/msw directory
0497e172
JS
315which contains the relevant makefiles.
316
317On Windows using MinGW/Cygwin, and on Unix, MacOS X and OS/2, you invoke
fc2171bd 318'configure' (found in the top-level of the wxWidgets source hierarchy),
0497e172
JS
319from within a suitable empty directory for containing makefiles, object files and
320libraries.
321
322For details on using makefiles, configure, and project files,
323please see docs/xxx/install.txt in your distribution, where
324xxx is the platform of interest, such as msw, gtk, x11, mac.
a660d684
KB
325
326\section{Windows-specific files}
327
fc2171bd 328wxWidgets application compilation under MS Windows requires at least two
a660d684
KB
329extra files, resource and module definition files.
330
331\subsection{Resource file}\label{resources}
332
333The least that must be defined in the Windows resource file (extension RC)
334is the following statement:
335
336\begin{verbatim}
0497e172 337#include "wx/msw/wx.rc"
a660d684
KB
338\end{verbatim}
339
fc2171bd 340which includes essential internal wxWidgets definitions. The resource script
a660d684
KB
341may also contain references to icons, cursors, etc., for example:
342
343\begin{verbatim}
344wxicon icon wx.ico
345\end{verbatim}
346
347The icon can then be referenced by name when creating a frame icon. See
348the MS Windows SDK documentation.
349
350\normalbox{Note: include wx.rc {\it after} any ICON statements
351so programs that search your executable for icons (such
352as the Program Manager) find your application icon first.}
353
fc2171bd 354\section{Allocating and deleting wxWidgets objects}
a660d684
KB
355
356In general, classes derived from wxWindow must dynamically allocated
357with {\it new} and deleted with {\it delete}. If you delete a window,
358all of its children and descendants will be automatically deleted,
359so you don't need to delete these descendants explicitly.
360
bd0df01f 361When deleting a frame or dialog, use {\bf Destroy} rather than {\bf delete} so
fc2171bd 362that the wxWidgets delayed deletion can take effect. This waits until idle time
bd0df01f
JS
363(when all messages have been processed) to actually delete the window, to avoid
364problems associated with the GUI sending events to deleted windows.
a660d684 365
bd0df01f
JS
366Don't create a window on the stack, because this will interfere
367with delayed deletion.
a660d684
KB
368
369If you decide to allocate a C++ array of objects (such as wxBitmap) that may
fc2171bd
JS
370be cleaned up by wxWidgets, make sure you delete the array explicitly
371before wxWidgets has a chance to do so on exit, since calling {\it delete} on
a660d684
KB
372array members will cause memory problems.
373
374wxColour can be created statically: it is not automatically cleaned
375up and is unlikely to be shared between other objects; it is lightweight
376enough for copies to be made.
377
378Beware of deleting objects such as a wxPen or wxBitmap if they are still in use.
379Windows is particularly sensitive to this: so make sure you
bd0df01f 380make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deleting
a660d684
KB
381a drawing object that may be in use. Code that doesn't do this will probably work
382fine on some platforms, and then fail under Windows.
383
91b8de8d
RR
384\section{Architecture dependency}
385
386A problem which sometimes arises from writing multi-platform programs is that
f6bcfd97 387the basic C types are not defined the same on all platforms. This holds true
91b8de8d
RR
388for both the length in bits of the standard types (such as int and long) as
389well as their byte order, which might be little endian (typically
fc2171bd 390on Intel computers) or big endian (typically on some Unix workstations). wxWidgets
91b8de8d
RR
391defines types and macros that make it easy to write architecture independent
392code. The types are:
393
394wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte
395
396where wxInt32 stands for a 32-bit signed integer type etc. You can also check
397which architecture the program is compiled on using the wxBYTE\_ORDER define
398which is either wxBIG\_ENDIAN or wxLITTLE\_ENDIAN (in the future maybe wxPDP\_ENDIAN
399as well).
400
401The macros handling bit-swapping with respect to the applications endianness
81c9effa 402are described in the \helpref{Byte order macros}{byteordermacros} section.
91b8de8d 403
a660d684
KB
404\section{Conditional compilation}
405
fc2171bd 406One of the purposes of wxWidgets is to reduce the need for conditional
a660d684
KB
407compilation in source code, which can be messy and confusing to follow.
408However, sometimes it is necessary to incorporate platform-specific
62448488
JS
409features (such as metafile use under MS Windows). The symbols
410listed in the file {\tt symbols.txt} may be used for this purpose,
411along with any user-supplied ones.
b8de493f 412
a660d684
KB
413\section{C++ issues}
414
bd0df01f 415The following documents some miscellaneous C++ issues.
a660d684
KB
416
417\subsection{Templates}
418
fc2171bd 419wxWidgets does not use templates (except for some advanced features that
0497e172 420are switched off by default) since it is a notoriously unportable feature.
a660d684 421
12a44087
RR
422\subsection{RTTI}
423
fc2171bd 424wxWidgets does not use C++ run-time type information since wxWidgets provides
12a44087
RR
425its own run-time type information system, implemented using macros.
426
427\subsection{Type of NULL}
428
429Some compilers (e.g. the native IRIX cc) define NULL to be 0L so that
430no conversion to pointers is allowed. Because of that, all these
0497e172 431occurrences of NULL in the GTK+ port use an explicit conversion such
12a44087
RR
432as
433
434{\small
435\begin{verbatim}
436 wxWindow *my_window = (wxWindow*) NULL;
437\end{verbatim}
d2c2afc9 438}%
12a44087 439
fc2171bd 440It is recommended to adhere to this in all code using wxWidgets as
12a44087
RR
441this make the code (a bit) more portable.
442
a660d684
KB
443\subsection{Precompiled headers}
444
445Some compilers, such as Borland C++ and Microsoft C++, support
446precompiled headers. This can save a great deal of compiling time. The
8a2c6ef8 447recommended approach is to precompile {\tt "wx.h"}, using this
fc2171bd
JS
448precompiled header for compiling both wxWidgets itself and any
449wxWidgets applications. For Windows compilers, two dummy source files
a660d684
KB
450are provided (one for normal applications and one for creating DLLs)
451to allow initial creation of the precompiled header.
452
453However, there are several downsides to using precompiled headers. One
454is that to take advantage of the facility, you often need to include
455more header files than would normally be the case. This means that
456changing a header file will cause more recompilations (in the case of
fc2171bd 457wxWidgets, everything needs to be recompiled since everything includes {\tt "wx.h"}!)
a660d684
KB
458
459A related problem is that for compilers that don't have precompiled
460headers, including a lot of header files slows down compilation
461considerably. For this reason, you will find (in the common
462X and Windows parts of the library) conditional
bd0df01f 463compilation that under Unix, includes a minimal set of headers;
a660d684
KB
464and when using Visual C++, includes {\tt wx.h}. This should help provide
465the optimal compilation for each compiler, although it is
f6bcfd97 466biased towards the precompiled headers facility available
a660d684
KB
467in Microsoft C++.
468
469\section{File handling}
470
471When building an application which may be used under different
472environments, one difficulty is coping with documents which may be
473moved to different directories on other machines. Saving a file which
474has pointers to full pathnames is going to be inherently unportable. One
475approach is to store filenames on their own, with no directory
476information. The application searches through a number of locally
477defined directories to find the file. To support this, the class {\bf
478wxPathList} makes adding directories and searching for files easy, and
62448488 479the global function {\bf wxFileNameFromPath} allows the application to
a660d684
KB
480strip off the filename from the path if the filename must be stored.
481This has undesirable ramifications for people who have documents of the
482same name in different directories.
483
484As regards the limitations of DOS 8+3 single-case filenames versus
bd0df01f 485unrestricted Unix filenames, the best solution is to use DOS filenames
a660d684
KB
486for your application, and also for document filenames {\it if} the user
487is likely to be switching platforms regularly. Obviously this latter
488choice is up to the application user to decide. Some programs (such as
489YACC and LEX) generate filenames incompatible with DOS; the best
bd0df01f 490solution here is to have your Unix makefile rename the generated files
a660d684 491to something more compatible before transferring the source to DOS.
bd0df01f 492Transferring DOS files to Unix is no problem, of course, apart from EOL
a660d684
KB
493conversion for which there should be a utility available (such as
494dos2unix).
495
496See also the File Functions section of the reference manual for
497descriptions of miscellaneous file handling functions.
498
fc2171bd 499\chapter{Utilities and libraries supplied with wxWidgets}\label{utilities}
a660d684
KB
500\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
501\setfooter{\thepage}{}{}{}{}{\thepage}%
502
fc2171bd 503In addition to the core wxWidgets library, a number of further
bd330a69 504libraries and utilities are supplied with each distribution.
a660d684 505
bd330a69 506Some are under the 'contrib' hierarchy which mirrors the
fc2171bd 507structure of the main wxWidgets hierarchy. See also the 'utils'
bd330a69 508hierarchy. The first place to look for documentation about
fc2171bd 509these tools and libraries is under the wxWidgets 'docs' hierarchy,
7af3ca16 510for example {\tt docs/htmlhelp/fl.chm}.
a660d684 511
bd330a69 512For other user-contributed packages, please see the Contributions page
fc2171bd 513on the \urlref{wxWidgets Web site}{http://www.wxwidgets.org}.
a660d684 514
bd330a69 515\begin{description}\itemsep=0pt
d8908b52 516\item[{\bf Helpview}]
fc2171bd
JS
517Helpview is a program for displaying wxWidgets HTML
518Help files. In many cases, you may wish to use the wxWidgets HTML
bd330a69
JS
519Help classes from within your application, but this provides a
520handy stand-alone viewer. See \helpref{wxHTML Notes}{wxhtml} for more details.
7af3ca16 521You can find it in {\tt samples/html/helpview}.
d8908b52 522\item[{\bf Tex2RTF}]
fc2171bd 523Supplied with wxWidgets is a utility called Tex2RTF for converting\rtfsp
bd330a69 524\LaTeX\ manuals HTML, MS HTML Help, wxHTML Help, RTF, and Windows
fc2171bd 525Help RTF formats. Tex2RTF is used for the wxWidgets manuals and can be used independently
bd330a69
JS
526by authors wishing to create on-line and printed manuals from the same\rtfsp
527\LaTeX\ source. Please see the separate documentation for Tex2RTF.
7af3ca16 528You can find it under {\tt utils/tex2rtf}.
d8908b52 529\item[{\bf Helpgen}]
bd330a69
JS
530Helpgen takes C++ header files and generates a Tex2RTF-compatible
531documentation file for each class it finds, using comments as appropriate.
532This is a good way to start a reference for a set of classes.
31be2bd8 533Helpgen can be found in {\tt utils/HelpGen}.
31be2bd8
JS
534\item[{\bf Emulator}]
535Xnest-based display emulator for X11-based PDA applications. On some
536systems, the Xnest window does not synchronise with the
537'skin' window. This program can be found in {\tt utils/emulator}.
31be2bd8 538\item[{\bf Configuration Tool}]
fc2171bd
JS
539The wxWidgets Configuration Tool is a work in progress
540intended to make it easier to configure wxWidgets
31be2bd8
JS
541features in detail. It exports setup.h configurations and will
542eventually generate makefile config files. Invoking compilers is
543also on the cards. Since configurations are
544handled one at a time, the tool is of limited used until further
545development can be done. The program can be found in {\tt utils/configtool}.
d8908b52 546\item[{\bf XRC resource system}]
965b4f87 547This is the sizer-aware resource system, and uses
bd330a69
JS
548XML-based resource specifications that can be generated by tools
549such as \urlref{wxDesigner}{http://www.roebling.de} and XRC's own wxrcedit.
7af3ca16 550You can find this in {\tt contrib/src/xrc}, {\tt contrib/include/wx/xrc}, {\tt contrib/samples/xrc}, and {\tt contrib/utils/wxrcedit}.
bd330a69 551For more information, see the \helpref{XML-based resource system overview}{xrcoverview}.
d8908b52 552\item[{\bf Object Graphics Library}]
bd330a69
JS
553OGL defines an API for applications that need to display objects connected by lines.
554The objects can be moved around and interacted with.
7af3ca16 555You can find this in {\tt contrib/src/ogl}, {\tt contrib/include/wx/ogl}, and {\tt contrib/samples/ogl}.
d8908b52 556\item[{\bf Frame Layout library}]
bd330a69 557FL provides sophisticated pane dragging and docking facilities.
7af3ca16 558You can find this in {\tt contrib/src/fl}, {\tt contrib/include/wx/fl}, and {\tt contrib/samples/fl}.
d8908b52 559\item[{\bf Gizmos library}]
bd330a69
JS
560Gizmos is a collection of useful widgets and other classes. Classes include wxLEDNumberCtrl,
561wxEditableListBox, wxMultiCellCanvas.
3b34ec62 562You can find this in {\tt contrib/src/gizmos}, {\tt contrib/include/wx/gizmos}, and {\tt contrib/samples/gizmos}.
d8908b52 563\item[{\bf Net library}]
bd330a69
JS
564Net is a collection of very simple mail and web related classes. Currently
565there is only wxEmail, which makes it easy to send email messages via MAPI on Windows or sendmail on Unix.
7af3ca16 566You can find this in {\tt contrib/src/net} and {\tt contrib/include/wx/net}.
d8908b52 567\item[{\bf Animate library}]
bd330a69
JS
568Animate allows you to load animated GIFs and play them on a window. The library can be extended
569to use other animation formats.
7af3ca16 570You can find this in {\tt contrib/src/animate}, {\tt contrib/include/wx/animate}, and {\tt contrib/samples/animate}.
d8908b52 571\item[{\bf MMedia library}]
bd330a69 572Mmedia supports a variety of multimedia functionality. The status of this library is currently unclear.
7af3ca16 573You can find this in {\tt contrib/src/mmedia}, {\tt contrib/include/wx/mmedia}, and {\tt contrib/samples/mmedia}.
d8908b52 574\item[{\bf Styled Text Control library}]
bd330a69 575STC is a wrapper around Scintilla, a syntax-highlighting text editor.
7af3ca16 576You can find this in {\tt contrib/src/stc}, {\tt contrib/include/wx/stc}, and {\tt contrib/samples/stc}.
d8908b52 577\item[{\bf Plot}]
bd330a69 578Plot is a simple curve plotting library.
7af3ca16 579You can find this in {\tt contrib/src/plot}, {\tt contrib/include/wx/plot}, and {\tt contrib/samples/plot}.
bd330a69 580\end{description}
a660d684
KB
581
582\chapter{Programming strategies}\label{strategies}
583\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
584\setfooter{\thepage}{}{}{}{}{\thepage}%
585
586This chapter is intended to list strategies that may be useful when
fc2171bd 587writing and debugging wxWidgets programs. If you have any good tips,
a660d684
KB
588please submit them for inclusion here.
589
590\section{Strategies for reducing programming errors}
591
592\subsection{Use ASSERT}
593
fc2171bd 594Although I haven't done this myself within wxWidgets, it is good
a660d684
KB
595practice to use ASSERT statements liberally, that check for conditions that
596should or should not hold, and print out appropriate error messages.
fc2171bd 597These can be compiled out of a non-debugging version of wxWidgets
a660d684
KB
598and your application. Using ASSERT is an example of `defensive programming':
599it can alert you to problems later on.
600
601\subsection{Use wxString in preference to character arrays}
602
603Using wxString can be much safer and more convenient than using char *.
f6bcfd97 604Again, I haven't practiced what I'm preaching, but I'm now trying to use
a660d684 605wxString wherever possible. You can reduce the possibility of memory
f6bcfd97 606leaks substantially, and it is much more convenient to use the overloaded
a660d684
KB
607operators than functions such as strcmp. wxString won't add a significant
608overhead to your program; the overhead is compensated for by easier
609manipulation (which means less code).
610
611The same goes for other data types: use classes wherever possible.
612
613\section{Strategies for portability}
614
615\subsection{Use relative positioning or constraints}
616
617Don't use absolute panel item positioning if you can avoid it. Different GUIs have
618very differently sized panel items. Consider using the constraint system, although this
8a2c6ef8 619can be complex to program.
a660d684 620
fc2171bd 621Alternatively, you could use alternative .wrc (wxWidgets resource files) on different
a660d684
KB
622platforms, with slightly different dimensions in each. Or space your panel items out
623to avoid problems.
624
fc2171bd 625\subsection{Use wxWidgets resource files}
a660d684 626
fc2171bd 627Use .xrc (wxWidgets resource files) where possible, because they can be easily changed
965b4f87 628independently of source code.
a660d684 629
6b037754 630\section{Strategies for debugging}\label{debugstrategies}
a660d684
KB
631
632\subsection{Positive thinking}
633
f6bcfd97 634It is common to blow up the problem in one's imagination, so that it seems to threaten
a660d684
KB
635weeks, months or even years of work. The problem you face may seem insurmountable:
636but almost never is. Once you have been programming for some time, you will be able
637to remember similar incidents that threw you into the depths of despair. But
638remember, you always solved the problem, somehow!
639
640Perseverance is often the key, even though a seemingly trivial problem
641can take an apparently inordinate amount of time to solve. In the end,
642you will probably wonder why you worried so much. That's not to say it
643isn't painful at the time. Try not to worry -- there are many more important
644things in life.
645
646\subsection{Simplify the problem}
647
648Reduce the code exhibiting the problem to the smallest program possible
649that exhibits the problem. If it is not possible to reduce a large and
650complex program to a very small program, then try to ensure your code
651doesn't hide the problem (you may have attempted to minimize the problem
652in some way: but now you want to expose it).
653
654With luck, you can add a small amount of code that causes the program
655to go from functioning to non-functioning state. This should give a clue
656to the problem. In some cases though, such as memory leaks or wrong
657deallocation, this can still give totally spurious results!
658
a660d684
KB
659\subsection{Use a debugger}
660
f6bcfd97
BP
661This sounds like facetious advice, but it is surprising how often people
662don't use a debugger. Often it is an overhead to install or learn how to
a660d684 663use a debugger, but it really is essential for anything but the most
6b037754
JS
664trivial programs.
665
666\subsection{Use logging functions}
667
668There is a variety of logging functions that you can use in your program:
669see \helpref{Logging functions}{logfunctions}.
a660d684
KB
670
671Using tracing statements may be more convenient than using the debugger
672in some circumstances (such as when your debugger doesn't support a lot
673of debugging code, or you wish to print a bunch of variables).
674
fc2171bd 675\subsection{Use the wxWidgets debugging facilities}
6b037754
JS
676
677You can use wxDebugContext to check for
fc2171bd
JS
678memory leaks and corrupt memory: in fact in debugging mode, wxWidgets will
679automatically check for memory leaks at the end of the program if wxWidgets is suitably
6b037754
JS
680configured. Depending on the operating system and compiler, more or less
681specific information about the problem will be logged.
a660d684 682
6b037754
JS
683You should also use \helpref{debug macros}{debugmacros} as part of a `defensive programming' strategy,
684scattering wxASSERTs liberally to test for problems in your code as early as possible. Forward thinking
685will save a surprising amount of time in the long run.
686
687See the \helpref{debugging overview}{debuggingoverview} for further information.
a660d684 688