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