]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/body.tex
Added wxDataViewTreeCtrl
[wxWidgets.git] / docs / latex / wx / body.tex
... / ...
CommitLineData
1\chapter{Introduction}\label{introduction}
2\pagenumbering{arabic}%
3\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
4\setfooter{\thepage}{}{}{}{}{\thepage}%
5
6\section{What is wxWidgets?}\label{whatis}
7
8wxWidgets is a C++ framework providing GUI (Graphical User
9Interface) and other facilities on more than one platform. Version 2 and higher
10currently support all desktop versions of MS Windows, Unix with GTK+ 1.x or 2.x,
11Unix with Motif, Unix with just X11, Unix with DirectFB, Mac OS X, OS/2.
12
13wxWidgets was originally developed at the Artificial Intelligence
14Applications Institute, University of Edinburgh, for internal use,
15and was first made publicly available in 1992.
16Version 2 is a vastly improved version written and maintained by
17Julian Smart, Robert Roebling, Vadim Zeitlin, Vaclav Slavik and many others.
18
19This manual contains a class reference and topic overviews.
20For a selection of wxWidgets tutorials, please see the documentation page on the \urlref{wxWidgets web site}{http://www.wxwidgets.org}.
21
22Please note that in the following, ``MS Windows" often refers to all
23platforms related to Microsoft Windows, including 32-bit and 64-bit
24variants, unless otherwise stated. All trademarks are acknowledged.
25
26\section{Why another cross-platform development tool?}\label{why}
27
28wxWidgets was developed to provide a cheap and flexible way to maximize
29investment in GUI application development. While a number of commercial
30class libraries already existed for cross-platform development,
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
40Since wxWidgets was started, several other free or almost-free
41GUI frameworks have emerged. However, none has the range of
42features, flexibility, documentation and the well-established
43development team that wxWidgets has.
44
45As open source software, wxWidgets has benefited from comments,
46ideas, bug fixes, enhancements and the sheer enthusiasm of
47users. This gives wxWidgets a certain advantage over its
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
64it addresses the wrong platform or audience. wxWidgets helps to
65insulate the programmer from these winds of change. Although
66wxWidgets may not be suitable for every application (such as an
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
73worthwhile to use wxWidgets even if they are developing on only
74one platform.
75
76It is impossible to sum up the functionality of wxWidgets in a few paragraphs, but
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.
82\item Available on a variety of popular platforms.
83\item Works with almost all popular C++ compilers and Python.
84\item Over 70 example programs.
85\item Over 1000 pages of printable and on-line documentation.
86\item Simple-to-use, object-oriented API.
87\item Flexible event system.
88\item Graphics calls include lines, rounded rectangles, splines, polylines, etc.
89\item Constraint-based and sizer-based layouts.
90\item Print/preview and document/view architectures.
91\item Toolbar, notebook, tree control, advanced list control classes.
92\item PostScript generation under Unix, normal MS Windows printing on the PC.
93\item MDI (Multiple Document Interface) support.
94\item Can be used to create DLLs under Windows, dynamic libraries on Unix.
95\item Common dialogs for file browsing, printing, colour selection, etc.
96\item Under MS Windows, support for creating metafiles and copying
97them to the clipboard.
98\item An API for invoking help from applications.
99\item Ready-to-use HTML window (supporting a subset of HTML).
100\item Network support via a family of socket and protocol classes.
101\item Support for platform independent image processing.
102\item Built-in support for many file formats (BMP, PNG, JPEG, GIF, XPM, PNM, PCX).
103\item Includes Tex2RTF, to allow you to produce your own documentation
104in Windows Help, HTML and Word RTF formats.
105\end{itemize}
106
107\section{wxWidgets requirements}\label{requirements}
108
109To make use of wxWidgets, you currently need one of the following setups.
110
111(a) MS-Windows:
112
113\begin{enumerate}\itemsep=0pt
114\item A 32-bit or 64-bit PC running MS Windows.
115\item A Windows compiler: MS Visual C++ (embedded Visual C++ for wxWinCE
116port), Borland C++, Watcom C++, Cygwin, MinGW, Metrowerks CodeWarrior,
117Digital Mars C++. See {\tt install.txt} for details about compiler
118version supported.
119\end{enumerate}
120
121(b) Unix:
122
123\begin{enumerate}\itemsep=0pt
124\item Almost any C++ compiler, including GNU C++ and many Unix vendors
125compilers such as Sun CC, HP-UX aCC or SGI mipsPro.
126\item Almost any Unix workstation, and one of: GTK+ 2.4 or higher (GTK+ 1.2.10
127may still be supported but wxGTK1 port is not maintained any longer and lacks
128many features of wxGTK2), Motif 1.2 or higher or Lesstif. If using the wxX11
129port, no such widget set is required.
130\end{enumerate}
131
132(c) Mac OS/Mac OS X:
133
134\begin{enumerate}\itemsep=0pt
135\item A PowerPC or Intel Mac running Mac OS X 10.3 or higher
136\item The Apple Developer Tools (eg. GNU C++) or MetroWerks CodeWarrior (not
137actively supported)
138\end{enumerate}
139
140Under all platforms it's recommended to have large amounts of free hard disk
141space. The exact amount needed depends on the port, compiler and build
142configurations but to give an example, a debug build of the library may take up
143to 500MB.
144
145\section{Availability and location of wxWidgets}\label{where}
146
147\winhelponly{wxWidgets is available by anonymous FTP and World Wide Web
148from ftp://biolpc22.york.ac.uk/pub and/or http://www.wxwidgets.org.}
149\winhelpignore{wxWidgets is available by anonymous FTP and World Wide Web
150from \urlref{ftp://biolpc22.york.ac.uk/pub}{ftp://biolpc22.york.ac.uk/pub}
151and/or \urlref{http://www.wxwidgets.org}{http://www.wxwidgets.org}.}
152
153You can also buy a CD-ROM using the form on the Web site.
154
155\section{Acknowledgements}\label{acknowledgements}
156
157The following is the list of the core, active developers of wxWidgets which keep
158it running and have provided an invaluable, extensive and high-quality amount of
159changes over the many of years of wxWidgets' life:
160
161\begin{description}\itemsep=0pt
162\item Julian Smart
163\item Vadim Zeitlin
164\item Robert Roebling
165\item Robin Dunn
166\item Stefan Csomor
167\item Vaclav Slavik
168\item Paul Cornett
169\item Wlodzimierz `ABX' Skiba
170\item Chris Elliott
171\item David Elliott
172\item Kevin Hock
173\item Stefan Neis
174\item Michael Wetherell
175\end{description}
176
177We would particularly like to thank the following peoples for their contributions
178to wxWidgets, and the many others who have been involved in the project over the years.
179Apologies for any unintentional omissions from this alphabetic list:
180
181Yiorgos Adamopoulos, Jamshid Afshar, Alejandro Aguilar-Sierra, AIAI,
182Patrick Albert, Karsten Ballueder, Mattia Barbon, Michael Bedward,
183Kai Bendorf, Yura Bidus, Keith Gary Boyce, Chris Breeze, Pete Britton,
184Ian Brown, C. Buckley, Marco Cavallini, Dmitri Chubraev, Robin Corbet, Cecil Coupe,
185Andrew Davison, Gilles Depeyrot, Neil Dudman, Hermann Dunkel, Jos van Eijndhoven,
186Tom Felici, Thomas Fettig, Matthew Flatt, Pasquale Foggia, Josep Fortiana, Todd Fries,
187Dominic Gallagher, Guillermo Rodriguez Garcia, Wolfram Gloger, Norbert Grotz,
188Stefan Gunter, Bill Hale, Patrick Halke, Stefan Hammes, Guillaume Helle,
189Harco de Hilster, Cord Hockemeyer, Markus Holzem, Olaf Klein, Leif Jensen,
190Bart Jourquin, Guilhem Lavaux, Ron Lee, Jan Lessner, Nicholas Liebmann,
191Torsten Liermann, Per Lindqvist, Francesco Montorsi, Thomas Runge, Tatu M\"{a}nnist\"{o},
192Scott Maxwell, Thomas Myers, Oliver Niedung, Ryan Norton, Hernan Otero,
193Ian Perrigo, Timothy Peters, Giordano Pezzoli, Harri Pasanen, Thomaso Paoletti,
194Garrett Potts, Marcel Rasche, Dino Scaringella, Jobst Schmalenbach, Arthur Seaton,
195Paul Shirley, Stein Somers, Petr Smilauer, Neil Smith, Kari Syst\"{a}, George Tasker,
196Arthur Tetzlaff-Deas, Jonathan Tonberg, Jyrki Tuomi, Janos Vegh, Andrea Venturoli,
197David Webster, Otto Wyss, Xiaokun Zhu, Edward Zimmermann.
198
199Many thanks also to AIAI for being willing to release the original version of
200wxWidgets into the public domain, and to our patient partners.
201
202`Graphplace', the basis for the wxGraphLayout library, is copyright Dr. Jos
203T.J. van Eijndhoven of Eindhoven University of Technology. The code has
204been used in wxGraphLayout (not in wxWidgets anymore) with his permission.
205
206We also acknowledge the author of XFIG, the excellent Unix drawing tool,
207from the source of which we have borrowed some spline drawing code.
208His copyright is included below.
209
210{\it XFig2.1 is copyright (c) 1985 by Supoj Sutanthavibul. Permission to
211use, copy, modify, distribute, and sell this software and its
212documentation for any purpose is hereby granted without fee, provided
213that the above copyright notice appear in all copies and that both that
214copyright notice and this permission notice appear in supporting
215documentation, and that the name of M.I.T. not be used in advertising or
216publicity pertaining to distribution of the software without specific,
217written prior permission. M.I.T. makes no representations about the
218suitability of this software for any purpose. It is provided ``as is''
219without express or implied warranty.}
220
221\chapter{Multi-platform development with wxWidgets}\label{multiplat}
222\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
223\setfooter{\thepage}{}{}{}{}{\thepage}%
224
225This chapter describes the practical details of using wxWidgets. Please
226see the file install.txt for up-to-date installation instructions, and
227changes.txt for differences between versions.
228
229\section{Include files}\label{includefiles}
230
231The main include file is {\tt "wx/wx.h"}; this includes the most commonly
232used modules of wxWidgets.
233
234To save on compilation time, include only those header files relevant to the
235source file. If you are using precompiled headers, you should include
236the following section before any other includes:
237
238\begin{verbatim}
239// For compilers that support precompilation, includes "wx.h".
240#include <wx/wxprec.h>
241
242#ifdef __BORLANDC__
243#pragma hdrstop
244#endif
245
246#ifndef WX_PRECOMP
247// Include your minimal set of headers here, or wx.h
248#include <wx/wx.h>
249#endif
250
251... now your other include files ...
252\end{verbatim}
253
254The file {\tt "wx/wxprec.h"} includes {\tt "wx/wx.h"}. Although this incantation
255may seem quirky, it is in fact the end result of a lot of experimentation,
256and several Windows compilers to use precompilation which is largely automatic for
257compilers with necessary support. Currently it is used for Visual C++ (including
258embedded Visual C++), Borland C++, Open Watcom C++, Digital Mars C++
259and newer versions of GCC.
260Some compilers might need extra work from the application developer to set the
261build environment up as necessary for the support.
262
263\section{Libraries}\label{libraries}
264
265Most ports of wxWidgets can create either a static library or a shared
266library. wxWidgets can also be built in multilib and monolithic variants.
267See the \helpref{libraries list}{librarieslist} for more
268information on these.
269
270\section{Configuration}\label{configuration}
271
272When using project files and makefiles directly to build wxWidgets,
273options are configurable in the file
274\rtfsp{\tt "wx/XXX/setup.h"} where XXX is the required platform (such as msw, motif, gtk, mac). Some
275settings are a matter of taste, some help with platform-specific problems, and
276others can be set to minimize the size of the library. Please see the setup.h file
277and {\tt install.txt} files for details on configuration.
278
279When using the 'configure' script to configure wxWidgets (on Unix and other platforms where
280configure is available), the corresponding setup.h files are generated automatically
281along with suitable makefiles. When using the RPM packages
282for installing wxWidgets on Linux, a correct setup.h is shipped in the package and
283this must not be changed.
284
285\section{Makefiles}\label{makefiles}
286
287On Microsoft Windows, wxWidgets has a different set of makefiles for each
288compiler, because each compiler's 'make' tool is slightly different.
289Popular Windows compilers that we cater for, and the corresponding makefile
290extensions, include: Microsoft Visual C++ (.vc), Borland C++ (.bcc),
291OpenWatcom C++ (.wat) and MinGW/Cygwin (.gcc). Makefiles are provided
292for the wxWidgets library itself, samples, demos, and utilities.
293
294On Linux, Mac and OS/2, you use the 'configure' command to
295generate the necessary makefiles. You should also use this method when
296building with MinGW/Cygwin on Windows.
297
298We also provide project files for some compilers, such as
299Microsoft VC++. However, we recommend using makefiles
300to build the wxWidgets library itself, because makefiles
301can be more powerful and less manual intervention is required.
302
303On Windows using a compiler other than MinGW/Cygwin, you would
304build the wxWidgets library from the build/msw directory
305which contains the relevant makefiles.
306
307On Windows using MinGW/Cygwin, and on Unix, MacOS X and OS/2, you invoke
308'configure' (found in the top-level of the wxWidgets source hierarchy),
309from within a suitable empty directory for containing makefiles, object files and
310libraries.
311
312For details on using makefiles, configure, and project files,
313please see docs/xxx/install.txt in your distribution, where
314xxx is the platform of interest, such as msw, gtk, x11, mac.
315
316\section{Windows-specific files}\label{windowsfiles}
317
318wxWidgets application compilation under MS Windows requires at least one
319extra file: a resource file.
320
321\subsection{Resource file}\label{resources}
322
323The least that must be defined in the Windows resource file (extension RC)
324is the following statement:
325
326\begin{verbatim}
327#include "wx/msw/wx.rc"
328\end{verbatim}
329
330which includes essential internal wxWidgets definitions. The resource script
331may also contain references to icons, cursors, etc., for example:
332
333\begin{verbatim}
334wxicon icon wx.ico
335\end{verbatim}
336
337The icon can then be referenced by name when creating a frame icon. See
338the MS Windows SDK documentation.
339
340\normalbox{Note: include wx.rc {\it after} any ICON statements
341so programs that search your executable for icons (such
342as the Program Manager) find your application icon first.}
343
344\section{Allocating and deleting wxWidgets objects}\label{allocatingobjects}
345
346In general, classes derived from wxWindow must dynamically allocated
347with {\it new} and deleted with {\it delete}. If you delete a window,
348all of its children and descendants will be automatically deleted,
349so you don't need to delete these descendants explicitly.
350
351When deleting a frame or dialog, use {\bf Destroy} rather than {\bf delete} so
352that the wxWidgets delayed deletion can take effect. This waits until idle time
353(when all messages have been processed) to actually delete the window, to avoid
354problems associated with the GUI sending events to deleted windows.
355
356Don't create a window on the stack, because this will interfere
357with delayed deletion.
358
359If you decide to allocate a C++ array of objects (such as wxBitmap) that may
360be cleaned up by wxWidgets, make sure you delete the array explicitly
361before wxWidgets has a chance to do so on exit, since calling {\it delete} on
362array members will cause memory problems.
363
364wxColour can be created statically: it is not automatically cleaned
365up and is unlikely to be shared between other objects; it is lightweight
366enough for copies to be made.
367
368Beware of deleting objects such as a wxPen or wxBitmap if they are still in use.
369Windows is particularly sensitive to this: so make sure you
370make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deleting
371a drawing object that may be in use. Code that doesn't do this will probably work
372fine on some platforms, and then fail under Windows.
373
374\section{Architecture dependency}\label{architecturedependency}
375
376A problem which sometimes arises from writing multi-platform programs is that
377the basic C types are not defined the same on all platforms. This holds true
378for both the length in bits of the standard types (such as int and long) as
379well as their byte order, which might be little endian (typically
380on Intel computers) or big endian (typically on some Unix workstations). wxWidgets
381defines types and macros that make it easy to write architecture independent
382code. The types are:
383
384wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte
385
386where wxInt32 stands for a 32-bit signed integer type etc. You can also check
387which architecture the program is compiled on using the wxBYTE\_ORDER define
388which is either wxBIG\_ENDIAN or wxLITTLE\_ENDIAN (in the future maybe wxPDP\_ENDIAN
389as well).
390
391The macros handling bit-swapping with respect to the applications endianness
392are described in the \helpref{Byte order macros}{byteordermacros} section.
393
394\section{Conditional compilation}\label{conditionalcompilation}
395
396One of the purposes of wxWidgets is to reduce the need for conditional
397compilation in source code, which can be messy and confusing to follow.
398However, sometimes it is necessary to incorporate platform-specific
399features (such as metafile use under MS Windows). The \helpref{wxUSE\_*}{wxusedef}
400symbols listed in the file {\tt setup.h} may be used for this purpose,
401along with any user-supplied ones.
402
403\section{C++ issues}\label{cpp}
404
405The following documents some miscellaneous C++ issues.
406
407\subsection{Templates}\label{templates}
408
409wxWidgets does not use templates (except for some advanced features that
410are switched off by default) since it is a notoriously unportable feature.
411
412\subsection{RTTI}\label{rtti}
413
414wxWidgets does not use C++ run-time type information since wxWidgets provides
415its own run-time type information system, implemented using macros.
416
417\subsection{Type of NULL}\label{null}
418
419Some compilers (e.g. the native IRIX cc) define NULL to be 0L so that
420no conversion to pointers is allowed. Because of that, all these
421occurrences of NULL in the GTK+ port use an explicit conversion such
422as
423
424{\small
425\begin{verbatim}
426 wxWindow *my_window = (wxWindow*) NULL;
427\end{verbatim}
428}%
429
430It is recommended to adhere to this in all code using wxWidgets as
431this make the code (a bit) more portable.
432
433\subsection{Precompiled headers}\label{precompiledheaders}
434
435Some compilers, such as Borland C++ and Microsoft C++, support
436precompiled headers. This can save a great deal of compiling time. The
437recommended approach is to precompile {\tt "wx.h"}, using this
438precompiled header for compiling both wxWidgets itself and any
439wxWidgets applications. For Windows compilers, two dummy source files
440are provided (one for normal applications and one for creating DLLs)
441to allow initial creation of the precompiled header.
442
443However, there are several downsides to using precompiled headers. One
444is that to take advantage of the facility, you often need to include
445more header files than would normally be the case. This means that
446changing a header file will cause more recompilations (in the case of
447wxWidgets, everything needs to be recompiled since everything includes {\tt "wx.h"}!)
448
449A related problem is that for compilers that don't have precompiled
450headers, including a lot of header files slows down compilation
451considerably. For this reason, you will find (in the common
452X and Windows parts of the library) conditional
453compilation that under Unix, includes a minimal set of headers;
454and when using Visual C++, includes {\tt wx.h}. This should help provide
455the optimal compilation for each compiler, although it is
456biased towards the precompiled headers facility available
457in Microsoft C++.
458
459\section{File handling}\label{filehandling}
460
461When building an application which may be used under different
462environments, one difficulty is coping with documents which may be
463moved to different directories on other machines. Saving a file which
464has pointers to full pathnames is going to be inherently unportable.
465
466One approach is to store filenames on their own, with no directory
467information. The application then searches into a list of standard
468paths (platform-specific) through the use of \helpref{wxStandardPaths}{wxstandardpaths}.
469
470Eventually you may want to use also the \helpref{wxPathList}{wxpathlist} class.
471
472Nowadays the limitations of DOS 8+3 filenames doesn't apply anymore.
473Most modern operating systems allow at least 255 characters in the filename;
474the exact maximum length, as well as the characters allowed in the filenames,
475are OS-specific so you should try to avoid extremely long (> 255 chars) filenames
476and/or filenames with non-ANSI characters.
477
478Another thing you need to keep in mind is that all Windows operating systems
479are case-insensitive, while Unix operating systems (Linux, Mac, etc) are
480case-sensitive.
481
482Also, for text files, different OSes use different End Of Lines (EOL).
483Windows uses CR+LF convention, Linux uses LF only, Mac CR only.
484
485The \helpref{wxTextFile}{wxtextfile},\helpref{wxTextInputStream}{wxtextinputstream},
486\helpref{wxTextOutputStream}{wxtextoutputstream} classes help to abstract
487from these differences.
488Of course, there are also 3rd party utilities such as \tt{dos2unix} and \tt{unix2dos}
489which do the EOL conversions.
490
491See also the \helpref{File Functions}{filefunctions} section of the reference
492manual for the description of miscellaneous file handling functions.
493
494\chapter{Utilities and libraries supplied with wxWidgets}\label{utilities}
495\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
496\setfooter{\thepage}{}{}{}{}{\thepage}%
497
498In addition to the \helpref{wxWidgets libraries}{librarieslist}, some
499additional utilities are supplied in the \tt{utils} hierarchy.
500
501For other user-contributed packages, please see the Contributions page
502on the \urlref{wxWidgets Web site}{http://www.wxwidgets.org}.
503
504\begin{description}\itemsep=0pt
505\item[{\bf Helpview}]
506Helpview is a program for displaying wxWidgets HTML
507Help files. In many cases, you may wish to use the wxWidgets HTML
508Help classes from within your application, but this provides a
509handy stand-alone viewer. See \helpref{wxHTML Notes}{wxhtml} for more details.
510You can find it in {\tt samples/html/helpview}.
511\item[{\bf Tex2RTF}]
512Supplied with wxWidgets is a utility called Tex2RTF for converting\rtfsp
513\LaTeX\ manuals HTML, MS HTML Help, wxHTML Help, RTF, and Windows
514Help RTF formats. Tex2RTF is used for the wxWidgets manuals and can be used independently
515by authors wishing to create on-line and printed manuals from the same\rtfsp
516\LaTeX\ source. Please see the separate documentation for Tex2RTF.
517You can find it under {\tt utils/tex2rtf}.
518\item[{\bf Helpgen}]
519Helpgen takes C++ header files and generates a Tex2RTF-compatible
520documentation file for each class it finds, using comments as appropriate.
521This is a good way to start a reference for a set of classes.
522Helpgen can be found in {\tt utils/HelpGen}.
523\item[{\bf Emulator}]
524Xnest-based display emulator for X11-based PDA applications. On some
525systems, the Xnest window does not synchronise with the
526'skin' window. This program can be found in {\tt utils/emulator}.
527\end{description}
528
529\chapter{Programming strategies}\label{strategies}
530\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
531\setfooter{\thepage}{}{}{}{}{\thepage}%
532
533This chapter is intended to list strategies that may be useful when
534writing and debugging wxWidgets programs. If you have any good tips,
535please submit them for inclusion here.
536
537\section{Strategies for reducing programming errors}\label{reducingerrors}
538
539\subsection{Use ASSERT}\label{useassert}
540
541It is good practice to use ASSERT statements liberally, that check for conditions
542that should or should not hold, and print out appropriate error messages.
543
544These can be compiled out of a non-debugging version of wxWidgets
545and your application. Using ASSERT is an example of `defensive programming':
546it can alert you to problems later on.
547
548See \helpref{wxASSERT}{wxassert} for more info.
549
550\subsection{Use wxString in preference to character arrays}\label{usewxstring}
551
552Using \helpref{wxString}{wxstring} can be much safer and more convenient than using wxChar *.
553
554You can reduce the possibility of memory leaks substantially, and it is much more
555convenient to use the overloaded operators than functions such as \tt{strcmp}.
556wxString won't add a significant overhead to your program; the overhead is compensated
557for by easier manipulation (which means less code).
558
559The same goes for other data types: use classes wherever possible.
560
561\section{Strategies for portability}\label{portability}
562
563\subsection{Use sizers}\label{usesizers}
564
565Don't use absolute panel item positioning if you can avoid it. Different GUIs have
566very differently sized panel items. Consider using the \helpref{sizers}{sizeroverview} instead.
567
568\subsection{Use wxWidgets resource files}\label{useresources}
569
570Use .xrc (wxWidgets resource files) where possible, because they can be easily changed
571independently of source code. See the \helpref{XRC overview}{xrcoverview} for more info.
572
573\section{Strategies for debugging}\label{debugstrategies}
574
575\subsection{Positive thinking}\label{positivethinking}
576
577It is common to blow up the problem in one's imagination, so that it seems to threaten
578weeks, months or even years of work. The problem you face may seem insurmountable:
579but almost never is. Once you have been programming for some time, you will be able
580to remember similar incidents that threw you into the depths of despair. But
581remember, you always solved the problem, somehow!
582
583Perseverance is often the key, even though a seemingly trivial problem
584can take an apparently inordinate amount of time to solve. In the end,
585you will probably wonder why you worried so much. That's not to say it
586isn't painful at the time. Try not to worry -- there are many more important
587things in life.
588
589\subsection{Simplify the problem}\label{simplifyproblem}
590
591Reduce the code exhibiting the problem to the smallest program possible
592that exhibits the problem. If it is not possible to reduce a large and
593complex program to a very small program, then try to ensure your code
594doesn't hide the problem (you may have attempted to minimize the problem
595in some way: but now you want to expose it).
596
597With luck, you can add a small amount of code that causes the program
598to go from functioning to non-functioning state. This should give a clue
599to the problem. In some cases though, such as memory leaks or wrong
600deallocation, this can still give totally spurious results!
601
602\subsection{Use a debugger}\label{usedebugger}
603
604This sounds like facetious advice, but it is surprising how often people
605don't use a debugger. Often it is an overhead to install or learn how to
606use a debugger, but it really is essential for anything but the most
607trivial programs.
608
609\subsection{Use logging functions}\label{uselogging}
610
611There is a variety of logging functions that you can use in your program:
612see \helpref{Logging functions}{logfunctions}.
613
614Using tracing statements may be more convenient than using the debugger
615in some circumstances (such as when your debugger doesn't support a lot
616of debugging code, or you wish to print a bunch of variables).
617
618\subsection{Use the wxWidgets debugging facilities}\label{usedebuggingfacilities}
619
620You can use \helpref{wxDebugContext}{wxdebugcontext} to check for
621memory leaks and corrupt memory: in fact in debugging mode, wxWidgets will
622automatically check for memory leaks at the end of the program if wxWidgets is suitably
623configured. Depending on the operating system and compiler, more or less
624specific information about the problem will be logged.
625
626You should also use \helpref{debug macros}{debugmacros} as part of a `defensive programming' strategy,
627scattering wxASSERTs liberally to test for problems in your code as early as possible. Forward thinking
628will save a surprising amount of time in the long run.
629
630See the \helpref{debugging overview}{debuggingoverview} for further information.
631