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