]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/body.tex
Some doc fixes
[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
6\section{What is wxWindows?}
7
8wxWindows is a C++ framework providing GUI (Graphical User
bd0df01f 9Interface) and other facilities on more than one platform. Version 2.0 currently
dbdb39b2
JS
10supports MS Windows (16-bit, Windows 95 and Windows NT), Unix with GTK+, and Unix with Motif.
11A Mac port is in an advanced state.
a660d684
KB
12
13wxWindows was originally developed at the Artificial Intelligence
14Applications Institute, University of Edinburgh, for internal use.
15wxWindows has been released into the public domain in the hope
16that others will also find it useful. Version 2.0 is written and
bd0df01f 17maintained by Julian Smart, Robert Roebling and others.
a660d684
KB
18
19This manual discusses wxWindows in the context of multi-platform
20development.\helpignore{For more detail on the wxWindows version 2.0 API
21(Application Programming Interface) please refer to the separate
22wxWindows reference manual.}
23
24Please note that in the following, ``MS Windows" often refers to all
25platforms related to Microsoft Windows, including 16-bit and 32-bit
26variants, unless otherwise stated. All trademarks are acknowledged.
27
28\section{Why another cross-platform development tool?}
29
30wxWindows was developed to provide a cheap and flexible way to maximize
31investment in GUI application development. While a number of commercial
8a2c6ef8 32class libraries already existed for cross-platform development,
a660d684
KB
33none met all of the following criteria:
34
35\begin{enumerate}\itemsep=0pt
36\item low price;
37\item source availability;
38\item simplicity of programming;
39\item support for a wide range of compilers.
40\end{enumerate}
41
8a2c6ef8
JS
42Since wxWindows was started, several other free or almost-free GUI frameworks have
43emerged. However, none has the range of features, flexibility, documentation and the
44well-established development team that wxWindows has.
45
a660d684
KB
46As public domain software and a project open to everyone, wxWindows has
47benefited from comments, ideas, bug fixes, enhancements and the sheer
48enthusiasm of users, especially via the Internet. This gives wxWindows a
8a2c6ef8
JS
49certain advantage over its commercial competitors (and over free libraries
50without an independent development team), plus a robustness against
a660d684
KB
51the transience of one individual or company. This openness and
52availability of source code is especially important when the future of
53thousands of lines of application code may depend upon the longevity of
54the underlying class library.
55
8a2c6ef8 56Version 2.0 goes much further than previous versions in terms of generality and features,
a660d684
KB
57allowing applications to be produced
58that are often indistinguishable from those produced using single-platform
8a2c6ef8 59toolkits such as Motif and MFC.
a660d684 60
a660d684
KB
61The importance of using a platform-independent class library cannot be
62overstated, since GUI application development is very time-consuming,
63and sustained popularity of particular GUIs cannot be guaranteed.
64Code can very quickly become obsolete if it addresses the wrong
65platform or audience. wxWindows helps to insulate the programmer from
66these winds of change. Although wxWindows may not be suitable for
8a2c6ef8
JS
67every application (such as an OLE-intensive program), it provides access to most of the functionality a
68GUI program normally requires, plus some extras such as network programming
69and PostScript output, and can of course be extended as needs dictate. As a bonus, it provides
a660d684
KB
70a cleaner programming interface than the native
71APIs. Programmers may find it worthwhile to use wxWindows even if they
72are developing on only one platform.
73
74It is impossible to sum up the functionality of wxWindows in a few paragraphs, but
75here are some of the benefits:
76
77\begin{itemize}\itemsep=0pt
78\item Low cost (free, in fact!)
79\item You get the source.
8a2c6ef8
JS
80\item Available on a variety of popular platforms.
81\item Works with almost all popular C++ compilers.
a660d684 82\item Several example programs.
dbdb39b2 83\item Over 900 pages of printable and on-line documentation.
8a2c6ef8
JS
84\item Includes Tex2RTF, to allow you to produce your own documentation
85in Windows Help, HTML and Word RTF formats.
a660d684 86\item Simple-to-use, object-oriented API.
8a2c6ef8
JS
87\item Flexible event system.
88\item Graphics calls include lines, rounded rectangles, splines, polylines, etc.
a660d684
KB
89\item Constraint-based layout option.
90\item Print/preview and document/view architectures.
8a2c6ef8
JS
91\item Toolbar, notebook, tree control, advanced list control classes.
92\item PostScript generation under Unix, normal MS Windows printing on the
a660d684 93PC.
62448488
JS
94\item MDI (Multiple Document Interface) support.
95\item Can be used to create DLLs under Windows, dynamic libraries on Unix.
a660d684
KB
96\item Common dialogs for file browsing, printing, colour selection, etc.
97\item Under MS Windows, support for creating metafiles and copying
98them to the clipboard.
62448488 99\item An API for invoking help from applications.
a660d684 100\item Dialog Editor for building dialogs.
8a2c6ef8 101\item Network support via a family of socket and protocol classes.
a660d684
KB
102\end{itemize}
103
104\section{Changes from version 1.xx}\label{versionchanges}
105
106These are a few of the major differences between versions 1.xx and 2.0.
107
108Removals:
109
110\begin{itemize}\itemsep=0pt
111\item XView is no longer supported;
a660d684 112\item all controls (panel items) no longer have labels attached to them;
62448488 113\item wxForm has been removed;
a660d684
KB
114\item wxCanvasDC, wxPanelDC removed (replaced by wxClientDC, wxWindowDC, wxPaintDC which
115can be used for any window);
116\item wxMultiText, wxTextWindow, wxText removed and replaced by wxTextCtrl;
117\item classes no longer divided into generic and platform-specific parts, for efficiency.
118\end{itemize}
119
120Additions and changes:
121
122\begin{itemize}\itemsep=0pt
123\item class hierarchy changed, and restrictions about subwindow nesting lifted;
124\item header files reorganised to conform to normal C++ standards;
125\item classes less dependent on each another, to reduce executable size;
126\item wxString used instead of char* wherever possible;
127\item the number of separate but mandatory utilities reduced;
128\item the event system has been overhauled, with
129virtual functions and callbacks being replaced with MFC-like event tables;
130\item new controls, such as wxTreeCtrl, wxListCtrl, wxSpinButton;
131\item less inconsistency about what events can be handled, so for example
132mouse clicks or key presses on controls can now be intercepted;
133\item the status bar is now a separate class, wxStatusBar, and is
134implemented in generic wxWindows code;
135\item some renaming of controls for greater consistency;
136\item wxBitmap has the notion of bitmap handlers to allow for extension to new formats
137without ifdefing;
138\item new dialogs: wxPageSetupDialog, wxFileDialog, wxDirDialog,
139wxMessageDialog, wxSingleChoiceDialog, wxTextEntryDialog;
140\item GDI objects are reference-counted and are now passed to most functions
141by reference, making memory management far easier;
142\item wxSystemSettings class allows querying for various system-wide properties
143such as dialog font, colours, user interface element sizes, and so on;
144\item better platform look and feel conformance;
145\item toolbar functionality now separated out into a family of classes with the
146same API;
147\item device contexts are no longer accessed using wxWindow::GetDC - they are created
148temporarily with the window as an argument;
149\item events from sliders and scrollbars can be handled more flexibly;
150\item the handling of window close events has been changed in line with the new
e3065973 151event system;
a660d684
KB
152\item the concept of {\it validator} has been added to allow much easier coding of
153the relationship between controls and application data;
154\item the documentation has been revised, with more cross-referencing.
155\end{itemize}
156
157Platform-specific changes:
158
159\begin{itemize}\itemsep=0pt
160\item The Windows header file (windows.h) is no longer included by wxWindows headers;
161\item wx.dll supported under Visual C++;
162\item the full range of Windows 95 window decorations are supported, such as modal frame
163borders;
164\item MDI classes brought out of wxFrame into separate classes, and made more flexible.
165\end{itemize}
166
167\section{wxWindows requirements}\label{requirements}
168
169To make use of wxWindows, you currently need one or both of the
170following setups.
171
172(a) PC:
173
174\begin{enumerate}\itemsep=0pt
175\item A 486 or higher PC running MS Windows.
8a2c6ef8
JS
176\item A Windows compiler: most are supported, but please see {\tt install.txt} for
177details. Supported compilers include Microsoft Visual C++ 4.0 or higher, Borland C++, Cygwin,
178Metrowerks CodeWarrior.
bd0df01f 179\item At least 60 MB of disk space.
a660d684
KB
180\end{enumerate}
181
bd0df01f 182(b) Unix:
a660d684
KB
183
184\begin{enumerate}\itemsep=0pt
185\item Almost any C++ compiler, including GNU C++.
62448488 186\item Almost any Unix workstation, and one of: GTK+ 1.0, Motif 1.2 or higher, Lesstif.
bd0df01f 187\item At least 60 MB of disk space.
a660d684
KB
188\end{enumerate}
189
190\section{Availability and location of wxWindows}
191
192wxWindows is currently available from the Artificial Intelligence
193Applications Institute by anonymous FTP and World Wide Web:
194
195\begin{verbatim}
62448488 196 ftp://www.remstar.com/pub/wxwin
dbdb39b2 197 http://www.wxwindows.org
a660d684
KB
198\end{verbatim}
199
200\section{Acknowledgments}
201
bd0df01f 202Thanks are due to AIAI for being willing to release the original version of
62448488 203wxWindows into the public domain, and to our patient partners.
bd0df01f
JS
204
205We would particularly like to thank the following for their contributions to wxWindows, and the many others who have been involved in
206the project over the years. Apologies for any unintentional omissions from this list.
207
208Yiorgos Adamopoulos, Jamshid Afshar, Alejandro Aguilar-Sierra, AIAI, Patrick Albert, Karsten Ballueder, Michael Bedward, Kai Bendorf, Yura Bidus, Keith
209Gary Boyce, Chris Breeze, Pete Britton, Ian Brown, C. Buckley, Dmitri Chubraev, Robin Corbet, Cecil Coupe, Andrew Davison, Neil Dudman, Robin
210Dunn, Hermann Dunkel, Jos van Eijndhoven, Tom Felici, Thomas Fettig, Matthew Flatt, Pasquale Foggia, Josep Fortiana, Todd Fries, Dominic Gallagher,
211Wolfram Gloger, Norbert Grotz, Stefan Gunter, Bill Hale, Patrick Halke, Stefan Hammes, Guillaume Helle, Harco de Hilster, Cord Hockemeyer, Markus
212Holzem, Olaf Klein, Leif Jensen, Bart Jourquin, Guilhem Lavaux, Jan Lessner, Nicholas Liebmann, Torsten Liermann, Per Lindqvist, Thomas Runge, Tatu
213M\"{a}nnist\"{o}, Scott Maxwell, Thomas Myers, Oliver Niedung, Hernan Otero, Ian Perrigo, Timothy Peters, Giordano Pezzoli, Harri Pasanen, Thomaso Paoletti,
214Garrett Potts, Marcel Rasche, Robert Roebling, Dino Scaringella, Jobst Schmalenbach, Arthur Seaton, Paul Shirley, Stein Somers, Petr Smilauer, Neil Smith,
215Kari Syst\"{a}, Arthur Tetzlaff-Deas, Jonathan Tonberg, Jyrki Tuomi, Janos Vegh, Andrea Venturoli, Vadim Zeitlin, Xiaokun Zhu, Edward Zimmermann.
a660d684
KB
216
217`Graphplace', the basis for the wxGraphLayout library, is copyright Dr. Jos
218T.J. van Eijndhoven of Eindhoven University of Technology. The code has
219been used in wxGraphLayout with his permission.
220
bd0df01f 221We also acknowledge the author of XFIG, the excellent Unix drawing tool,
a660d684
KB
222from the source of which we have borrowed some spline drawing code.
223His copyright is included below.
224
225{\it XFig2.1 is copyright (c) 1985 by Supoj Sutanthavibul. Permission to
226use, copy, modify, distribute, and sell this software and its
227documentation for any purpose is hereby granted without fee, provided
228that the above copyright notice appear in all copies and that both that
229copyright notice and this permission notice appear in supporting
230documentation, and that the name of M.I.T. not be used in advertising or
231publicity pertaining to distribution of the software without specific,
232written prior permission. M.I.T. makes no representations about the
233suitability of this software for any purpose. It is provided ``as is''
234without express or implied warranty.}
235
236\chapter{Multi-platform development with wxWindows}\label{multiplat}
237\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
238\setfooter{\thepage}{}{}{}{}{\thepage}%
239
240This chapter describes the practical details of using wxWindows. Please
241see the file install.txt for up-to-date installation instructions, and
242changes.txt for differences between versions.
243
244\section{Include files}
245
bd0df01f 246The main include file is {\tt "wx/wx.h"}; this includes the most commonly
a660d684
KB
247used modules of wxWindows.
248
249To save on compilation time, include only those header files relevant to the
250source file. If you are using precompiled headers, you should include
251the following section before any other includes:
252
253\begin{verbatim}
254// For compilers that support precompilation, includes "wx.h".
bd0df01f 255#include <wx/wxprec.h>
a660d684
KB
256
257#ifdef __BORLANDC__
258#pragma hdrstop
259#endif
260
261#ifndef WX_PRECOMP
bd0df01f
JS
262// Include your minimal set of headers here, or wx.h
263#include <wx/wx.h>
a660d684
KB
264#endif
265
266... now your other include files ...
267\end{verbatim}
268
bd0df01f 269The file {\tt "wx/wxprec.h"} includes {\tt "wx/wx.h"}. Although this incantation
a660d684
KB
270may seem quirky, it is in fact the end result of a lot of experimentation,
271and several Windows compilers to use precompilation (those tested are Microsoft Visual C++, Borland C++
272and Watcom C++).
273
bd0df01f 274Borland precompilation is largely automatic. Visual C++ requires specification of {\tt "wx/wxprec.h"} as
a660d684
KB
275the file to use for precompilation. Watcom C++ is automatic apart from the specification of
276the .pch file. Watcom C++ is strange in requiring the precompiled header to be used only for
277object files compiled in the same directory as that in which the precompiled header was created.
278Therefore, the wxWindows Watcom C++ makefiles go through hoops deleting and recreating
279a single precompiled header file for each module, thus preventing an accumulation of many
280multi-megabyte .pch files.
281
282\section{Libraries}
283
62448488 284Please the wxGTK or wxMotif documentation for use of the Unix version of wxWindows.
bd0df01f 285Under Windows, use the library wx.lib for stand-alone Windows
a660d684
KB
286applications, or wxdll.lib for creating DLLs.
287
288\section{Configuration}
289
62448488
JS
290Options are configurable in the file
291\rtfsp{\tt "wx/XXX/setup.h"} where XXX is the required platform (such as msw, motif, gtk, mac). Some settings are a matter
a660d684 292of taste, some help with platform-specific problems, and
62448488
JS
293others can be set to minimize the size of the library. Please see the setup.h file
294and {\tt install.txt} files for details on configuration.
a660d684
KB
295
296\section{Makefiles}
297
bd0df01f 298At the moment there is no attempt to make Unix makefiles and
a660d684 299PC makefiles compatible, i.e. one makefile is required for
62448488
JS
300each environment. wxGTK has its own configure system which can also
301be used with wxMotif, although wxMotif has a simple makefile system of its own.
a660d684 302
bd0df01f 303Sample makefiles for Unix (suffix .UNX), MS C++ (suffix .DOS and .NT), Borland
62448488
JS
304C++ (.BCC and .B32) and Symantec C++ (.SC) are included for the library, demos
305and utilities.
a660d684
KB
306
307The controlling makefile for wxWindows is in the platform-specific
62448488 308directory, such as {\tt src/msw} or {\tt src/motif}.
a660d684 309
62448488 310Please see the platform-specific {\tt install.txt} file for further details.
a660d684
KB
311
312\section{Windows-specific files}
313
314wxWindows application compilation under MS Windows requires at least two
315extra files, resource and module definition files.
316
317\subsection{Resource file}\label{resources}
318
319The least that must be defined in the Windows resource file (extension RC)
320is the following statement:
321
322\begin{verbatim}
bd0df01f 323rcinclude "wx/msw/wx.rc"
a660d684
KB
324\end{verbatim}
325
326which includes essential internal wxWindows definitions. The resource script
327may also contain references to icons, cursors, etc., for example:
328
329\begin{verbatim}
330wxicon icon wx.ico
331\end{verbatim}
332
333The icon can then be referenced by name when creating a frame icon. See
334the MS Windows SDK documentation.
335
336\normalbox{Note: include wx.rc {\it after} any ICON statements
337so programs that search your executable for icons (such
338as the Program Manager) find your application icon first.}
339
340\subsection{Module definition file}
341
bd0df01f
JS
342A module definition file (extension DEF) is required for 16-bit applications, and
343looks like the following:
a660d684
KB
344
345\begin{verbatim}
346NAME Hello
347DESCRIPTION 'Hello'
348EXETYPE WINDOWS
349STUB 'WINSTUB.EXE'
350CODE PRELOAD MOVEABLE DISCARDABLE
351DATA PRELOAD MOVEABLE MULTIPLE
352HEAPSIZE 1024
353STACKSIZE 8192
354\end{verbatim}
355
356The only lines which will usually have to be changed per application are
357NAME and DESCRIPTION.
358
a660d684
KB
359\subsection{Allocating and deleting wxWindows objects}
360
361In general, classes derived from wxWindow must dynamically allocated
362with {\it new} and deleted with {\it delete}. If you delete a window,
363all of its children and descendants will be automatically deleted,
364so you don't need to delete these descendants explicitly.
365
bd0df01f
JS
366When deleting a frame or dialog, use {\bf Destroy} rather than {\bf delete} so
367that the wxWindows delayed deletion can take effect. This waits until idle time
368(when all messages have been processed) to actually delete the window, to avoid
369problems associated with the GUI sending events to deleted windows.
a660d684 370
bd0df01f
JS
371Don't create a window on the stack, because this will interfere
372with delayed deletion.
a660d684
KB
373
374If you decide to allocate a C++ array of objects (such as wxBitmap) that may
375be cleaned up by wxWindows, make sure you delete the array explicitly
376before wxWindows has a chance to do so on exit, since calling {\it delete} on
377array members will cause memory problems.
378
379wxColour can be created statically: it is not automatically cleaned
380up and is unlikely to be shared between other objects; it is lightweight
381enough for copies to be made.
382
383Beware of deleting objects such as a wxPen or wxBitmap if they are still in use.
384Windows is particularly sensitive to this: so make sure you
bd0df01f 385make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deleting
a660d684
KB
386a drawing object that may be in use. Code that doesn't do this will probably work
387fine on some platforms, and then fail under Windows.
388
a660d684
KB
389\section{Conditional compilation}
390
391One of the purposes of wxWindows is to reduce the need for conditional
392compilation in source code, which can be messy and confusing to follow.
393However, sometimes it is necessary to incorporate platform-specific
62448488
JS
394features (such as metafile use under MS Windows). The symbols
395listed in the file {\tt symbols.txt} may be used for this purpose,
396along with any user-supplied ones.
b8de493f 397
a660d684
KB
398\section{C++ issues}
399
bd0df01f 400The following documents some miscellaneous C++ issues.
a660d684
KB
401
402\subsection{Templates}
403
bd0df01f 404wxWindows does not use templates since it is a notoriously unportable feature.
a660d684 405
12a44087
RR
406\subsection{RTTI}
407
408wxWindows does not use run-time type information since wxWindows provides
409its own run-time type information system, implemented using macros.
410
411\subsection{Type of NULL}
412
413Some compilers (e.g. the native IRIX cc) define NULL to be 0L so that
414no conversion to pointers is allowed. Because of that, all these
415occurences of NULL in the GTK port use an explicit conversion such
416as
417
418{\small
419\begin{verbatim}
420 wxWindow *my_window = (wxWindow*) NULL;
421\end{verbatim}
422}
423
424It is recommended to adhere to this in all code using wxWindows as
425this make the code (a bit) more portable.
426
a660d684
KB
427\subsection{Precompiled headers}
428
429Some compilers, such as Borland C++ and Microsoft C++, support
430precompiled headers. This can save a great deal of compiling time. The
8a2c6ef8 431recommended approach is to precompile {\tt "wx.h"}, using this
a660d684
KB
432precompiled header for compiling both wxWindows itself and any
433wxWindows applications. For Windows compilers, two dummy source files
434are provided (one for normal applications and one for creating DLLs)
435to allow initial creation of the precompiled header.
436
437However, there are several downsides to using precompiled headers. One
438is that to take advantage of the facility, you often need to include
439more header files than would normally be the case. This means that
440changing a header file will cause more recompilations (in the case of
8a2c6ef8 441wxWindows, everything needs to be recompiled since everything includes {\tt "wx.h"}!)
a660d684
KB
442
443A related problem is that for compilers that don't have precompiled
444headers, including a lot of header files slows down compilation
445considerably. For this reason, you will find (in the common
446X and Windows parts of the library) conditional
bd0df01f 447compilation that under Unix, includes a minimal set of headers;
a660d684
KB
448and when using Visual C++, includes {\tt wx.h}. This should help provide
449the optimal compilation for each compiler, although it is
450biassed towards the precompiled headers facility available
451in Microsoft C++.
452
453\section{File handling}
454
455When building an application which may be used under different
456environments, one difficulty is coping with documents which may be
457moved to different directories on other machines. Saving a file which
458has pointers to full pathnames is going to be inherently unportable. One
459approach is to store filenames on their own, with no directory
460information. The application searches through a number of locally
461defined directories to find the file. To support this, the class {\bf
462wxPathList} makes adding directories and searching for files easy, and
62448488 463the global function {\bf wxFileNameFromPath} allows the application to
a660d684
KB
464strip off the filename from the path if the filename must be stored.
465This has undesirable ramifications for people who have documents of the
466same name in different directories.
467
468As regards the limitations of DOS 8+3 single-case filenames versus
bd0df01f 469unrestricted Unix filenames, the best solution is to use DOS filenames
a660d684
KB
470for your application, and also for document filenames {\it if} the user
471is likely to be switching platforms regularly. Obviously this latter
472choice is up to the application user to decide. Some programs (such as
473YACC and LEX) generate filenames incompatible with DOS; the best
bd0df01f 474solution here is to have your Unix makefile rename the generated files
a660d684 475to something more compatible before transferring the source to DOS.
bd0df01f 476Transferring DOS files to Unix is no problem, of course, apart from EOL
a660d684
KB
477conversion for which there should be a utility available (such as
478dos2unix).
479
480See also the File Functions section of the reference manual for
481descriptions of miscellaneous file handling functions.
482
62448488 483\begin{comment}
a660d684
KB
484\chapter{Utilities supplied with wxWindows}\label{utilities}
485\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
486\setfooter{\thepage}{}{}{}{}{\thepage}%
487
488A number of `extras' are supplied with wxWindows, to complement
489the GUI functionality in the main class library. These are found
490below the utils directory and usually have their own source, library
8a2c6ef8
JS
491and documentation directories. For other user-contributed packages,
492see the directory ftp://www.remstar.com/pub/wxwin/contrib, which is
493more easily accessed via the Contributions page on the Web site.
a660d684
KB
494
495\section{wxHelp}\label{wxhelp}
496
497wxHelp is a stand-alone program, written using wxWindows,
498for displaying hypertext help. It is necessary since not all target
499systems (notably X) supply an adequate
500standard for on-line help. wxHelp is modelled on the MS Windows help
501system, with contents, search and browse buttons, but does not reformat
502text to suit the size of window, as WinHelp does, and its input files
503are uncompressed ASCII with some embedded font commands and an .xlp
504extension. Most wxWindows documentation (user manuals and class
505references) is supplied in wxHelp format, and also in Windows Help
bd0df01f
JS
506format. The wxWindows 2.0 project will presently use an HTML widget
507in a new and improved wxHelp implementation, under X.
a660d684
KB
508
509Note that an application can be programmed to use Windows Help under
510MS Windows, and wxHelp under X. An alternative help viewer under X is
511Mosaic, a World Wide Web viewer that uses HTML as its native hypertext
512format. However, this is not currently integrated with wxWindows
513applications.
514
515wxHelp works in two modes---edit and end-user. In edit mode, an ASCII
516file may be marked up with different fonts and colours, and divided into
517sections. In end-user mode, no editing is possible, and the user browses
518principally by clicking on highlighted blocks.
519
520When an application invokes wxHelp, subsequent sections, blocks or
521files may be viewed using the same instance of wxHelp since the two
522programs are linked using wxWindows interprocess communication
523facilities. When the application exits, that application's instance of
fe604ccd 524wxHelp may be made to exit also. See the {\bf wxHelpControllerBase} entry in the
a660d684
KB
525reference section for how an application controls wxHelp.
526
527\section{Tex2RTF}\label{textortf}
528
529Supplied with wxWindows is a utility called Tex2RTF for converting\rtfsp
530\LaTeX\ manuals to the following formats:
531
532\begin{description}
533\item[wxHelp]
534wxWindows help system format (XLP).
535\item[Linear RTF]
536Rich Text Format suitable for importing into a word processor.
537\item[Windows Help RTF]
538Rich Text Format suitable for compiling into a WinHelp HLP file with the
539help compiler.
540\item[HTML]
541HTML is the native format for Mosaic, the main hypertext viewer for
542the World Wide Web. Since it is freely available it is a good candidate
543for being the wxWindows help system under X, as an alternative to wxHelp.
544\end{description}
545
546Tex2RTF is used for the wxWindows manuals and can be used independently
547by authors wishing to create on-line and printed manuals from the same\rtfsp
548\LaTeX\ source. Please see the separate documentation for Tex2RTF.
549
550\section{wxTreeLayout}
551
552This is a simple class library for drawing trees in a reasonably pretty
553fashion. It provides only minimal default drawing capabilities, since
554the algorithm is meant to be used for implementing custom tree-based
555tools.
556
557Directed graphs may also be drawn using this library, if cycles are
558removed before the nodes and arcs are passed to the algorithm.
559
560Tree displays are used in many applications: directory browsers,
561hypertext systems, class browsers, and decision trees are a few
562possibilities.
563
564See the separate manual and the directory utils/wxtree.
565
566\section{wxGraphLayout}
567
568The wxGraphLayout class is based on a tool called `graphplace' by Dr.
569Jos T.J. van Eijndhoven of Eindhoven University of Technology. Given a
570(possibly cyclic) directed graph, it does its best to lay out the nodes
571in a sensible manner. There are many applications (such as diagramming)
572where it is required to display a graph with no human intervention. Even
573if manual repositioning is later required, this algorithm can make a good
574first attempt.
575
576See the separate manual and the directory utils/wxgraph.
577
a660d684
KB
578\section{Colours}\label{coloursampler}
579
580A colour sampler for viewing colours and their names on each
581platform.
582
583%
584\chapter{Tutorial}\label{tutorial}
585\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
586\setfooter{\thepage}{}{}{}{}{\thepage}%
587
588To be written.
62448488 589\end{comment}
a660d684
KB
590
591\chapter{Programming strategies}\label{strategies}
592\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
593\setfooter{\thepage}{}{}{}{}{\thepage}%
594
595This chapter is intended to list strategies that may be useful when
596writing and debugging wxWindows programs. If you have any good tips,
597please submit them for inclusion here.
598
599\section{Strategies for reducing programming errors}
600
601\subsection{Use ASSERT}
602
603Although I haven't done this myself within wxWindows, it is good
604practice to use ASSERT statements liberally, that check for conditions that
605should or should not hold, and print out appropriate error messages.
606These can be compiled out of a non-debugging version of wxWindows
607and your application. Using ASSERT is an example of `defensive programming':
608it can alert you to problems later on.
609
610\subsection{Use wxString in preference to character arrays}
611
612Using wxString can be much safer and more convenient than using char *.
613Again, I haven't practised what I'm preaching, but I'm now trying to use
614wxString wherever possible. You can reduce the possibility of memory
615leaks substantially, and it's much more convenient to use the overloaded
616operators than functions such as strcmp. wxString won't add a significant
617overhead to your program; the overhead is compensated for by easier
618manipulation (which means less code).
619
620The same goes for other data types: use classes wherever possible.
621
622\section{Strategies for portability}
623
624\subsection{Use relative positioning or constraints}
625
626Don't use absolute panel item positioning if you can avoid it. Different GUIs have
627very differently sized panel items. Consider using the constraint system, although this
8a2c6ef8 628can be complex to program.
a660d684
KB
629
630Alternatively, you could use alternative .wrc (wxWindows resource files) on different
631platforms, with slightly different dimensions in each. Or space your panel items out
632to avoid problems.
633
634\subsection{Use wxWindows resource files}
635
636Use .wrc (wxWindows resource files) where possible, because they can be easily changed
637independently of source code. Bitmap resources can be set up to load different
638kinds of bitmap depending on platform (see the section on resource files).
639
6b037754 640\section{Strategies for debugging}\label{debugstrategies}
a660d684
KB
641
642\subsection{Positive thinking}
643
644It's common to blow up the problem in one's imagination, so that it seems to threaten
645weeks, months or even years of work. The problem you face may seem insurmountable:
646but almost never is. Once you have been programming for some time, you will be able
647to remember similar incidents that threw you into the depths of despair. But
648remember, you always solved the problem, somehow!
649
650Perseverance is often the key, even though a seemingly trivial problem
651can take an apparently inordinate amount of time to solve. In the end,
652you will probably wonder why you worried so much. That's not to say it
653isn't painful at the time. Try not to worry -- there are many more important
654things in life.
655
656\subsection{Simplify the problem}
657
658Reduce the code exhibiting the problem to the smallest program possible
659that exhibits the problem. If it is not possible to reduce a large and
660complex program to a very small program, then try to ensure your code
661doesn't hide the problem (you may have attempted to minimize the problem
662in some way: but now you want to expose it).
663
664With luck, you can add a small amount of code that causes the program
665to go from functioning to non-functioning state. This should give a clue
666to the problem. In some cases though, such as memory leaks or wrong
667deallocation, this can still give totally spurious results!
668
a660d684
KB
669\subsection{Use a debugger}
670
671This sounds like facetious advice, but it's surprising how often people
672don't use a debugger. Often it's an overhead to install or learn how to
673use a debugger, but it really is essential for anything but the most
6b037754
JS
674trivial programs.
675
676\subsection{Use logging functions}
677
678There is a variety of logging functions that you can use in your program:
679see \helpref{Logging functions}{logfunctions}.
a660d684
KB
680
681Using tracing statements may be more convenient than using the debugger
682in some circumstances (such as when your debugger doesn't support a lot
683of debugging code, or you wish to print a bunch of variables).
684
6b037754
JS
685\subsection{Use the wxWindows debugging facilities}
686
687You can use wxDebugContext to check for
688memory leaks and corrupt memory: in fact in debugging mode, wxWindows will
689automatically check for memory leaks at the end of the program if wxWindows is suitably
690configured. Depending on the operating system and compiler, more or less
691specific information about the problem will be logged.
a660d684 692
6b037754
JS
693You should also use \helpref{debug macros}{debugmacros} as part of a `defensive programming' strategy,
694scattering wxASSERTs liberally to test for problems in your code as early as possible. Forward thinking
695will save a surprising amount of time in the long run.
696
697See the \helpref{debugging overview}{debuggingoverview} for further information.
a660d684
KB
698
699\subsection{Check Windows debug messages}
700
701Under Windows, it's worth running your program with DBWIN running or
702some other program that shows Windows-generated debug messages. It's
703possible it'll show invalid handles being used. You may have fun seeing
704what commercial programs cause these normally hidden errors! Microsoft
705recommend using the debugging version of Windows, which shows up even
706more problems. However, I doubt it's worth the hassle for most
707applications. wxWindows is designed to minimize the possibility of such
708errors, but they can still happen occasionally, slipping through unnoticed
709because they are not severe enough to cause a crash.
6b037754
JS
710
711\subsection{Genetic mutation}
712
713If we had sophisticated genetic algorithm tools that could be applied
714to programming, we could use them. Until then, a common -- if rather irrational --
715technique is to just make arbitrary changes to the code until something
716different happens. You may have an intuition why a change will make a difference;
717otherwise, just try altering the order of code, comment lines out, anything
718to get over an impasse. Obviously, this is usually a last resort.
719