]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/body.tex
Motif and other mods
[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 509
b8de493f 510
a660d684
KB
511\section{C++ issues}
512
bd0df01f 513The following documents some miscellaneous C++ issues.
a660d684
KB
514
515\subsection{Templates}
516
bd0df01f 517wxWindows does not use templates since it is a notoriously unportable feature.
a660d684
KB
518
519\subsection{Precompiled headers}
520
521Some compilers, such as Borland C++ and Microsoft C++, support
522precompiled headers. This can save a great deal of compiling time. The
523recommended approach is to precompile {\tt ``wx.h''}, using this
524precompiled header for compiling both wxWindows itself and any
525wxWindows applications. For Windows compilers, two dummy source files
526are provided (one for normal applications and one for creating DLLs)
527to allow initial creation of the precompiled header.
528
529However, there are several downsides to using precompiled headers. One
530is that to take advantage of the facility, you often need to include
531more header files than would normally be the case. This means that
532changing a header file will cause more recompilations (in the case of
533wxWindows, everything needs to be recompiled since everything includes
534{\tt ``wx.h''}!)
535
536A related problem is that for compilers that don't have precompiled
537headers, including a lot of header files slows down compilation
538considerably. For this reason, you will find (in the common
539X and Windows parts of the library) conditional
bd0df01f 540compilation that under Unix, includes a minimal set of headers;
a660d684
KB
541and when using Visual C++, includes {\tt wx.h}. This should help provide
542the optimal compilation for each compiler, although it is
543biassed towards the precompiled headers facility available
544in Microsoft C++.
545
546\section{File handling}
547
548When building an application which may be used under different
549environments, one difficulty is coping with documents which may be
550moved to different directories on other machines. Saving a file which
551has pointers to full pathnames is going to be inherently unportable. One
552approach is to store filenames on their own, with no directory
553information. The application searches through a number of locally
554defined directories to find the file. To support this, the class {\bf
555wxPathList} makes adding directories and searching for files easy, and
556the global function {\bf FileNameFromPath} allows the application to
557strip off the filename from the path if the filename must be stored.
558This has undesirable ramifications for people who have documents of the
559same name in different directories.
560
561As regards the limitations of DOS 8+3 single-case filenames versus
bd0df01f 562unrestricted Unix filenames, the best solution is to use DOS filenames
a660d684
KB
563for your application, and also for document filenames {\it if} the user
564is likely to be switching platforms regularly. Obviously this latter
565choice is up to the application user to decide. Some programs (such as
566YACC and LEX) generate filenames incompatible with DOS; the best
bd0df01f 567solution here is to have your Unix makefile rename the generated files
a660d684 568to something more compatible before transferring the source to DOS.
bd0df01f 569Transferring DOS files to Unix is no problem, of course, apart from EOL
a660d684
KB
570conversion for which there should be a utility available (such as
571dos2unix).
572
573See also the File Functions section of the reference manual for
574descriptions of miscellaneous file handling functions.
575
576\chapter{Utilities supplied with wxWindows}\label{utilities}
577\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
578\setfooter{\thepage}{}{}{}{}{\thepage}%
579
580A number of `extras' are supplied with wxWindows, to complement
581the GUI functionality in the main class library. These are found
582below the utils directory and usually have their own source, library
583and documentation directories. For larger user-contributed packages,
584see the directory /pub/packages/wxwin/contrib.
585
586\section{wxHelp}\label{wxhelp}
587
588wxHelp is a stand-alone program, written using wxWindows,
589for displaying hypertext help. It is necessary since not all target
590systems (notably X) supply an adequate
591standard for on-line help. wxHelp is modelled on the MS Windows help
592system, with contents, search and browse buttons, but does not reformat
593text to suit the size of window, as WinHelp does, and its input files
594are uncompressed ASCII with some embedded font commands and an .xlp
595extension. Most wxWindows documentation (user manuals and class
596references) is supplied in wxHelp format, and also in Windows Help
bd0df01f
JS
597format. The wxWindows 2.0 project will presently use an HTML widget
598in a new and improved wxHelp implementation, under X.
a660d684
KB
599
600Note that an application can be programmed to use Windows Help under
601MS Windows, and wxHelp under X. An alternative help viewer under X is
602Mosaic, a World Wide Web viewer that uses HTML as its native hypertext
603format. However, this is not currently integrated with wxWindows
604applications.
605
606wxHelp works in two modes---edit and end-user. In edit mode, an ASCII
607file may be marked up with different fonts and colours, and divided into
608sections. In end-user mode, no editing is possible, and the user browses
609principally by clicking on highlighted blocks.
610
611When an application invokes wxHelp, subsequent sections, blocks or
612files may be viewed using the same instance of wxHelp since the two
613programs are linked using wxWindows interprocess communication
614facilities. When the application exits, that application's instance of
fe604ccd 615wxHelp may be made to exit also. See the {\bf wxHelpControllerBase} entry in the
a660d684
KB
616reference section for how an application controls wxHelp.
617
618\section{Tex2RTF}\label{textortf}
619
620Supplied with wxWindows is a utility called Tex2RTF for converting\rtfsp
621\LaTeX\ manuals to the following formats:
622
623\begin{description}
624\item[wxHelp]
625wxWindows help system format (XLP).
626\item[Linear RTF]
627Rich Text Format suitable for importing into a word processor.
628\item[Windows Help RTF]
629Rich Text Format suitable for compiling into a WinHelp HLP file with the
630help compiler.
631\item[HTML]
632HTML is the native format for Mosaic, the main hypertext viewer for
633the World Wide Web. Since it is freely available it is a good candidate
634for being the wxWindows help system under X, as an alternative to wxHelp.
635\end{description}
636
637Tex2RTF is used for the wxWindows manuals and can be used independently
638by authors wishing to create on-line and printed manuals from the same\rtfsp
639\LaTeX\ source. Please see the separate documentation for Tex2RTF.
640
641\section{wxTreeLayout}
642
643This is a simple class library for drawing trees in a reasonably pretty
644fashion. It provides only minimal default drawing capabilities, since
645the algorithm is meant to be used for implementing custom tree-based
646tools.
647
648Directed graphs may also be drawn using this library, if cycles are
649removed before the nodes and arcs are passed to the algorithm.
650
651Tree displays are used in many applications: directory browsers,
652hypertext systems, class browsers, and decision trees are a few
653possibilities.
654
655See the separate manual and the directory utils/wxtree.
656
657\section{wxGraphLayout}
658
659The wxGraphLayout class is based on a tool called `graphplace' by Dr.
660Jos T.J. van Eijndhoven of Eindhoven University of Technology. Given a
661(possibly cyclic) directed graph, it does its best to lay out the nodes
662in a sensible manner. There are many applications (such as diagramming)
663where it is required to display a graph with no human intervention. Even
664if manual repositioning is later required, this algorithm can make a good
665first attempt.
666
667See the separate manual and the directory utils/wxgraph.
668
a660d684
KB
669\section{Colours}\label{coloursampler}
670
671A colour sampler for viewing colours and their names on each
672platform.
673
674%
675\chapter{Tutorial}\label{tutorial}
676\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
677\setfooter{\thepage}{}{}{}{}{\thepage}%
678
679To be written.
680
681\chapter{Programming strategies}\label{strategies}
682\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
683\setfooter{\thepage}{}{}{}{}{\thepage}%
684
685This chapter is intended to list strategies that may be useful when
686writing and debugging wxWindows programs. If you have any good tips,
687please submit them for inclusion here.
688
689\section{Strategies for reducing programming errors}
690
691\subsection{Use ASSERT}
692
693Although I haven't done this myself within wxWindows, it is good
694practice to use ASSERT statements liberally, that check for conditions that
695should or should not hold, and print out appropriate error messages.
696These can be compiled out of a non-debugging version of wxWindows
697and your application. Using ASSERT is an example of `defensive programming':
698it can alert you to problems later on.
699
700\subsection{Use wxString in preference to character arrays}
701
702Using wxString can be much safer and more convenient than using char *.
703Again, I haven't practised what I'm preaching, but I'm now trying to use
704wxString wherever possible. You can reduce the possibility of memory
705leaks substantially, and it's much more convenient to use the overloaded
706operators than functions such as strcmp. wxString won't add a significant
707overhead to your program; the overhead is compensated for by easier
708manipulation (which means less code).
709
710The same goes for other data types: use classes wherever possible.
711
712\section{Strategies for portability}
713
714\subsection{Use relative positioning or constraints}
715
716Don't use absolute panel item positioning if you can avoid it. Different GUIs have
717very differently sized panel items. Consider using the constraint system, although this
718can be complex to program. If you needs are simple, the default relative positioning
719behaviour may be adequate (using default position values and wxPanel::NewLine).
720
721Alternatively, you could use alternative .wrc (wxWindows resource files) on different
722platforms, with slightly different dimensions in each. Or space your panel items out
723to avoid problems.
724
725\subsection{Use wxWindows resource files}
726
727Use .wrc (wxWindows resource files) where possible, because they can be easily changed
728independently of source code. Bitmap resources can be set up to load different
729kinds of bitmap depending on platform (see the section on resource files).
730
731\section{Strategies for debugging}
732
733\subsection{Positive thinking}
734
735It's common to blow up the problem in one's imagination, so that it seems to threaten
736weeks, months or even years of work. The problem you face may seem insurmountable:
737but almost never is. Once you have been programming for some time, you will be able
738to remember similar incidents that threw you into the depths of despair. But
739remember, you always solved the problem, somehow!
740
741Perseverance is often the key, even though a seemingly trivial problem
742can take an apparently inordinate amount of time to solve. In the end,
743you will probably wonder why you worried so much. That's not to say it
744isn't painful at the time. Try not to worry -- there are many more important
745things in life.
746
747\subsection{Simplify the problem}
748
749Reduce the code exhibiting the problem to the smallest program possible
750that exhibits the problem. If it is not possible to reduce a large and
751complex program to a very small program, then try to ensure your code
752doesn't hide the problem (you may have attempted to minimize the problem
753in some way: but now you want to expose it).
754
755With luck, you can add a small amount of code that causes the program
756to go from functioning to non-functioning state. This should give a clue
757to the problem. In some cases though, such as memory leaks or wrong
758deallocation, this can still give totally spurious results!
759
760\subsection{Genetic mutation}
761
762If we had sophisticated genetic algorithm tools that could be applied
763to programming, we could use them. Until then, a common -- if rather irrational --
764technique is to just make arbitrary changes to the code until something
765different happens. You may have an intuition why a change will make a difference;
766otherwise, just try altering the order of code, comment lines out, anything
767to get over an impasse. Obviously, this is usually a last resort.
768
769\subsection{Use a debugger}
770
771This sounds like facetious advice, but it's surprising how often people
772don't use a debugger. Often it's an overhead to install or learn how to
773use a debugger, but it really is essential for anything but the most
774trivial programs. Some platforms don't allow for debugging, such
775as WIN32s under Windows 3.x. In this case, you might be advised to
776debug under 16-bit Windows and when you're confident, compile for
777WIN32s. In fact WIN32s can be very strict about bad memory handling,
778so testing out under WIN32s is a good thing to do even if you're
779not going to distribute this version. (Unless you've got a good memory checking,
780utility, of course!) Tracking bugs under WIN32s can involve a lot of debug message
781insertion and relinking, so make sure your compiler has a fast linker
782(e.g. Watcom, Symantec).
783
784\subsection{Use tracing code}
785
786You can use wxDebugMsg statements (or the wxDebugStreamBuf class) to
787output to a debugging window such as DBWIN under Windows, or standard
788error under X. If compiling in DEBUG mode, you can use TRACE statements
789that will be compiled out of the final build of your application.
790
791Using tracing statements may be more convenient than using the debugger
792in some circumstances (such as when your debugger doesn't support a lot
793of debugging code, or you wish to print a bunch of variables).
794
795\subsection{Use wxObject::Dump and the wxDebugContext class}
796
797It's good practice to implement the Dump member function for all
798classes derived from wxObject. You can then make use of wxDebugContext
799to dump out information on all objects in the program, if DEBUG is
800defined to be more than zero. You can use wxDebugContext to check for
801memory leaks and corrupt memory. See the debugging topic in the
802reference manual for more information.
803
804\subsection{Check Windows debug messages}
805
806Under Windows, it's worth running your program with DBWIN running or
807some other program that shows Windows-generated debug messages. It's
808possible it'll show invalid handles being used. You may have fun seeing
809what commercial programs cause these normally hidden errors! Microsoft
810recommend using the debugging version of Windows, which shows up even
811more problems. However, I doubt it's worth the hassle for most
812applications. wxWindows is designed to minimize the possibility of such
813errors, but they can still happen occasionally, slipping through unnoticed
814because they are not severe enough to cause a crash.