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