1 \chapter{Introduction
}\label{introduction
}
2 \pagenumbering{arabic
}%
3 \setheader{{\it CHAPTER
\thechapter}}{}{}{}{}{{\it CHAPTER
\thechapter}}%
4 \setfooter{\thepage}{}{}{}{}{\thepage}%
6 \section{What is wxWindows?
}
8 wxWindows is a C++ framework providing GUI (Graphical User
9 Interface) and other facilities on more than one platform. Version
2.0 currently
10 supports subsets MS Windows (
16-bit, Windows
95 and Windows NT) and GTK.
12 wxWindows was originally developed at the Artificial Intelligence
13 Applications Institute, University of Edinburgh, for internal use.
14 wxWindows has been released into the public domain in the hope
15 that others will also find it useful. Version
2.0 is written and
16 maintained by Julian Smart, Robert Roebling and others.
18 This manual discusses wxWindows in the context of multi-platform
19 development.
\helpignore{For more detail on the wxWindows version
2.0 API
20 (Application Programming Interface) please refer to the separate
21 wxWindows reference manual.
}
23 Please note that in the following, ``MS Windows" often refers to all
24 platforms related to Microsoft Windows, including
16-bit and
32-bit
25 variants, unless otherwise stated. All trademarks are acknowledged.
27 \section{Why another cross-platform development tool?
}
29 wxWindows was developed to provide a cheap and flexible way to maximize
30 investment in GUI application development. While a number of commercial
31 class libraries already exist for cross-platform development,
32 none met all of the following criteria:
34 \begin{enumerate
}\itemsep=
0pt
36 \item source availability;
37 \item simplicity of programming;
38 \item support for a wide range of compilers.
41 As public domain software and a project open to everyone, wxWindows has
42 benefited from comments, ideas, bug fixes, enhancements and the sheer
43 enthusiasm of users, especially via the Internet. This gives wxWindows a
44 certain advantage over its commercial brothers, and a robustness against
45 the transience of one individual or company. This openness and
46 availability of source code is especially important when the future of
47 thousands of lines of application code may depend upon the longevity of
48 the underlying class library.
50 In writing wxWindows, completeness has sometimes been traded for
51 portability and simplicity of programming. Version
2.0 goes much
52 further than previous versions in terms of generality and features,
53 allowing applications to be produced
54 that are often indistinguishable from those produced using single-platform
56 such as Motif and MFC.
58 wxWindows
2.0 currently maps to two native APIs: GTK and
59 MS Windows. Motif, Xt and Mac ports are also in preparation.
61 The importance of using a platform-independent class library cannot be
62 overstated, since GUI application development is very time-consuming,
63 and sustained popularity of particular GUIs cannot be guaranteed.
64 Code can very quickly become obsolete if it addresses the wrong
65 platform or audience. wxWindows helps to insulate the programmer from
66 these winds of change. Although wxWindows may not be suitable for
67 every application, it provides access to most of the functionality a
68 GUI program normally requires, plus some extras such as form
69 construction, interprocess communication and PostScript output, and
70 can of course be extended as needs dictate. As a bonus, it provides
71 a cleaner programming interface than the native
72 APIs. Programmers may find it worthwhile to use wxWindows even if they
73 are developing on only one platform.
75 It is impossible to sum up the functionality of wxWindows in a few paragraphs, but
76 here are some of the benefits:
78 \begin{itemize
}\itemsep=
0pt
79 \item Low cost (free, in fact!)
80 \item You get the source.
81 \item Several example programs.
82 \item Over
700 pages of printable and on-line documentation.
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
88 \item Easy, object-oriented interprocess comms (DDE subset) under Unix and
90 \item Encapsulated PostScript generation under Unix, normal MS Windows printing on the
92 \item MDI support under Windows and GTK.
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
96 them to the clipboard.
97 \item Hypertext help facility, with an API for invocation from applications.
98 \item Dialog Editor for building dialogs.
101 \section{Changes from version
1.xx
}\label{versionchanges
}
103 These are a few of the major differences between versions
1.xx and
2.0.
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
113 can 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.
118 Additions and changes:
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
127 virtual 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
130 mouse clicks or key presses on controls can now be intercepted;
131 \item the status bar is now a separate class, wxStatusBar, and is
132 implemented 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
136 \item new dialogs: wxPageSetupDialog, wxFileDialog, wxDirDialog,
137 wxMessageDialog, wxSingleChoiceDialog, wxTextEntryDialog;
138 \item GDI objects are reference-counted and are now passed to most functions
139 by reference, making memory management far easier;
140 \item wxSystemSettings class allows querying for various system-wide properties
141 such 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
145 \item device contexts are no longer accessed using wxWindow::GetDC - they are created
146 temporarily 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
149 event 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
151 the relationship between controls and application data;
152 \item the documentation has been revised, with more cross-referencing.
155 Platform-specific changes:
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
162 \item MDI classes brought out of wxFrame into separate classes, and made more flexible.
165 \section{wxWindows requirements
}\label{requirements
}
167 To make use of wxWindows, you currently need one or both of the
172 \begin{enumerate
}\itemsep=
0pt
173 \item A
486 or higher PC running MS Windows.
174 \item One of Microsoft Visual C++
4.0 or higher, Borland C++, Gnu-Win32.
175 \item At least
60 MB of disk space.
180 \begin{enumerate
}\itemsep=
0pt
181 \item Almost any C++ compiler, including GNU C++.
182 \item Almost any Unix workstation, and GTK
1.0 or higher.
183 \item At least
60 MB of disk space.
186 \section{Availability and location of wxWindows
}
188 wxWindows is currently available from the Artificial Intelligence
189 Applications Institute by anonymous FTP and World Wide Web:
192 ftp://ftp.aiai.ed.ac.uk/pub/packages/wxwin
193 http://web.ukonline.co.uk/julian.smart/wxwin
196 \section{Acknowledgments
}
198 Thanks are due to AIAI for being willing to release the original version of
199 wxWindows into the public domain, and to our patient wives Harriet, Tanja and others.
201 We would particularly like to thank the following for their contributions to wxWindows, and the many others who have been involved in
202 the project over the years. Apologies for any unintentional omissions from this list.
204 Yiorgos Adamopoulos, Jamshid Afshar, Alejandro Aguilar-Sierra, AIAI, Patrick Albert, Karsten Ballueder, Michael Bedward, Kai Bendorf, Yura Bidus, Keith
205 Gary Boyce, Chris Breeze, Pete Britton, Ian Brown, C. Buckley, Dmitri Chubraev, Robin Corbet, Cecil Coupe, Andrew Davison, Neil Dudman, Robin
206 Dunn, Hermann Dunkel, Jos van Eijndhoven, Tom Felici, Thomas Fettig, Matthew Flatt, Pasquale Foggia, Josep Fortiana, Todd Fries, Dominic Gallagher,
207 Wolfram Gloger, Norbert Grotz, Stefan Gunter, Bill Hale, Patrick Halke, Stefan Hammes, Guillaume Helle, Harco de Hilster, Cord Hockemeyer, Markus
208 Holzem, Olaf Klein, Leif Jensen, Bart Jourquin, Guilhem Lavaux, Jan Lessner, Nicholas Liebmann, Torsten Liermann, Per Lindqvist, Thomas Runge, Tatu
209 M\"
{a
}nnist\"
{o
}, Scott Maxwell, Thomas Myers, Oliver Niedung, Hernan Otero, Ian Perrigo, Timothy Peters, Giordano Pezzoli, Harri Pasanen, Thomaso Paoletti,
210 Garrett Potts, Marcel Rasche, Robert Roebling, Dino Scaringella, Jobst Schmalenbach, Arthur Seaton, Paul Shirley, Stein Somers, Petr Smilauer, Neil Smith,
211 Kari Syst\"
{a
}, Arthur Tetzlaff-Deas, Jonathan Tonberg, Jyrki Tuomi, Janos Vegh, Andrea Venturoli, Vadim Zeitlin, Xiaokun Zhu, Edward Zimmermann.
213 `Graphplace', the basis for the wxGraphLayout library, is copyright Dr. Jos
214 T.J. van Eijndhoven of Eindhoven University of Technology. The code has
215 been used in wxGraphLayout with his permission.
217 We also acknowledge the author of XFIG, the excellent Unix drawing tool,
218 from the source of which we have borrowed some spline drawing code.
219 His copyright is included below.
221 {\it XFig2.1 is copyright (c)
1985 by Supoj Sutanthavibul. Permission to
222 use, copy, modify, distribute, and sell this software and its
223 documentation for any purpose is hereby granted without fee, provided
224 that the above copyright notice appear in all copies and that both that
225 copyright notice and this permission notice appear in supporting
226 documentation, and that the name of M.I.T. not be used in advertising or
227 publicity pertaining to distribution of the software without specific,
228 written prior permission. M.I.T. makes no representations about the
229 suitability of this software for any purpose. It is provided ``as is''
230 without express or implied warranty.
}
232 \chapter{Multi-platform development with wxWindows
}\label{multiplat
}
233 \setheader{{\it CHAPTER
\thechapter}}{}{}{}{}{{\it CHAPTER
\thechapter}}%
234 \setfooter{\thepage}{}{}{}{}{\thepage}%
236 This chapter describes the practical details of using wxWindows. Please
237 see the file install.txt for up-to-date installation instructions, and
238 changes.txt for differences between versions.
240 \section{Include files
}
242 The main include file is
{\tt "wx/wx.h"
}; this includes the most commonly
243 used modules of wxWindows.
245 To save on compilation time, include only those header files relevant to the
246 source file. If you are using precompiled headers, you should include
247 the following section before any other includes:
250 // For compilers that support precompilation, includes "wx.h".
251 #include <wx/wxprec.h>
258 // Include your minimal set of headers here, or wx.h
262 ... now your other include files ...
265 The file
{\tt "wx/wxprec.h"
} includes
{\tt "wx/wx.h"
}. Although this incantation
266 may seem quirky, it is in fact the end result of a lot of experimentation,
267 and several Windows compilers to use precompilation (those tested are Microsoft Visual C++, Borland C++
270 Borland precompilation is largely automatic. Visual C++ requires specification of
{\tt "wx/wxprec.h"
} as
271 the file to use for precompilation. Watcom C++ is automatic apart from the specification of
272 the .pch file. Watcom C++ is strange in requiring the precompiled header to be used only for
273 object files compiled in the same directory as that in which the precompiled header was created.
274 Therefore, the wxWindows Watcom C++ makefiles go through hoops deleting and recreating
275 a single precompiled header file for each module, thus preventing an accumulation of many
276 multi-megabyte .pch files.
280 Please the wxGTK documentation for use of the Unix version of wxWindows.
281 Under Windows, use the library wx.lib for stand-alone Windows
282 applications, or wxdll.lib for creating DLLs.
284 \section{Configuration
}
286 The following lists the options configurable in the file
287 \rtfsp{\tt "wx/msw/setup.h"
} and
{\tt "wx/gtk/setup.h"
} Some settings are a matter
288 of taste, some help with platform-specific problems, and
289 others can be set to minimize the size of the library.
291 \subsection{General features
}
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,
298 and necessary for the
document/view framework.
}
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
302 with the extended arguments of the debugging wxObject new and delete operators. If this causes problems
303 for your compiler, set to
0.
}
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
306 if the value of DEBUG is defined to more than
0.
}
307 \twocolitem{USE
\_METAFILE}{If
1, Windows Metafile code is compiled.
}
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
310 to make use of either native Windows printing facilities, or the wxPostScriptDC class depending
311 on the wxApp::SetPrintMode setting.
}
312 \twocolitem{USE
\_PRINTING\_ARCHITECTURE}{If
1, wxPrinter, wxPrintout and related classes are compiled
313 for the print/preview framework.
}
314 \twocolitem{USE
\_RESOURCES}{If
1, win.ini or .Xdefaults-style resource read/write code is compiled.
}
315 \twocolitem{USE
\_WX\_RESOURCES}{If
1, wxWindows resource file (.WXR) code is compiled.
}
318 \subsection{Windows and NT features
}
321 \twocolitem{CTL3D
}{CTL3D should only be used for
16-bit Windows programs.
322 On Windows
95 and NT, native
3D effects are used. If you want to
323 use it and don't already have CTL3D installed, copy the files in
324 contrib/ctl3d to appropriate places (ctl3dv2.lib/ctl3d32.lib into your compiler lib
325 directory, ctl3d.h into an include directory, and ctl3dv2.dll into
326 windows/system). You may need to find a compiler-specific version of ctl3dv2.lib
327 or ctl3d32.lib. Define CTL3D to be
1 in wx
\_setup.h and link your executables with ctl3dv2.lib
329 \twocolitem{USE
\_ODBC}{If
1, compiles wxDatabase and wxRecordSet classes for ODBC
330 access. Requires sql.h, sqlext.h files if set to
1 (see topic on database support).
}
335 At the moment there is no attempt to make Unix makefiles and
336 PC makefiles compatible, i.e. one makefile is required for
339 Sample makefiles for Unix (suffix .UNX), MS C++ (suffix .DOS and .NT), Borland
340 C++ (.BCC) and Symantec C++ (.SC) are included for the library, demos
341 and utilities. The NT, Borland and Symantec makefiles cannot be
342 guaranteed to be up-to-date since the author does not have
345 The controlling makefile for wxWindows is in the platform-specific
346 directory, such as
{\tt src/msw
} or
{\tt src/x
}. This makefile will
347 recursively execute the makefile in
{\tt src/base
}.
349 \subsection{Windows makefiles
}
351 For Microsoft C++, normally it is only necessary to type
{\tt nmake -f
352 makefile.dos
} (or an alias or batch file which does this). By default,
353 binaries are made with debugging information, and no optimization. Use
354 FINAL=
1 on the command line to remove debugging information (this only
355 really necessary at the link stage), and DLL=
1 to make a DLL version of
356 the library, if building a library.
358 \subsection{Unix makefiles
}
362 Debugging information is included by default; you may add DEBUG= as an
363 argument to make to compile without it, or use the Unix
{\bf strip
}
364 command to remove debugging information from an executable.
366 \normalbox{{\it Important note:
} Most compiler flags are kept centrally in
367 src/make.env, which is included by all other makefiles. This is the
368 file to edit to tailor wxWindows compilation to your environment.
}
370 \section{Windows-specific files
}
372 wxWindows application compilation under MS Windows requires at least two
373 extra files, resource and module definition files.
375 \subsection{Resource file
}\label{resources
}
377 The least that must be defined in the Windows resource file (extension RC)
378 is the following statement:
381 rcinclude "wx/msw/wx.rc"
384 which includes essential internal wxWindows definitions. The resource script
385 may also contain references to icons, cursors, etc., for example:
391 The icon can then be referenced by name when creating a frame icon. See
392 the MS Windows SDK documentation.
394 \normalbox{Note: include wx.rc
{\it after
} any ICON statements
395 so programs that search your executable for icons (such
396 as the Program Manager) find your application icon first.
}
398 \subsection{Module definition file
}
400 A module definition file (extension DEF) is required for
16-bit applications, and
401 looks like the following:
408 CODE PRELOAD MOVEABLE DISCARDABLE
409 DATA PRELOAD MOVEABLE MULTIPLE
414 The only lines which will usually have to be changed per application are
415 NAME and DESCRIPTION.
417 \subsection{Allocating and deleting wxWindows objects
}
419 In general, classes derived from wxWindow must dynamically allocated
420 with
{\it new
} and deleted with
{\it delete
}. If you delete a window,
421 all of its children and descendants will be automatically deleted,
422 so you don't need to delete these descendants explicitly.
424 When deleting a frame or dialog, use
{\bf Destroy
} rather than
{\bf delete
} so
425 that 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
427 problems associated with the GUI sending events to deleted windows.
429 Don't create a window on the stack, because this will interfere
430 with delayed deletion.
432 If you decide to allocate a C++ array of objects (such as wxBitmap) that may
433 be cleaned up by wxWindows, make sure you delete the array explicitly
434 before wxWindows has a chance to do so on exit, since calling
{\it delete
} on
435 array members will cause memory problems.
437 wxColour can be created statically: it is not automatically cleaned
438 up and is unlikely to be shared between other objects; it is lightweight
439 enough for copies to be made.
441 Beware of deleting objects such as a wxPen or wxBitmap if they are still in use.
442 Windows is particularly sensitive to this: so make sure you
443 make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deleting
444 a drawing object that may be in use. Code that doesn't do this will probably work
445 fine on some platforms, and then fail under Windows.
447 \section{Conditional compilation
}
449 One of the purposes of wxWindows is to reduce the need for conditional
450 compilation in source code, which can be messy and confusing to follow.
451 However, sometimes it is necessary to incorporate platform-specific
452 features (such as metafile use under MS Windows). The following identifiers
453 may be used for this purpose, along with any user-supplied ones:
458 __X__ any X, but not GTK
461 __WXMSW__ Any Windows
464 __WIN95__ GUI for Windows
95 and above; NT
4.0 and above.
494 __GNUWIN32__ Gnu-Win32 compiler
496 __GNUG__ Gnu C++ on any platform
497 __BORLANDC__ Borland C++
498 __WATCOMC__ Watcom C++
499 __SYMANTECC__ Symantec C++
504 {\bf wxWindows modes:
}
507 __WXDEBUG__ usage: #ifdef __DEBUG__ (=> debug mode, else => release)
513 The following documents some miscellaneous C++ issues.
515 \subsection{Templates
}
517 wxWindows does not use templates since it is a notoriously unportable feature.
519 \subsection{Precompiled headers
}
521 Some compilers, such as Borland C++ and Microsoft C++, support
522 precompiled headers. This can save a great deal of compiling time. The
523 recommended approach is to precompile
{\tt ``wx.h''
}, using this
524 precompiled header for compiling both wxWindows itself and any
525 wxWindows applications. For Windows compilers, two dummy source files
526 are provided (one for normal applications and one for creating DLLs)
527 to allow initial creation of the precompiled header.
529 However, there are several downsides to using precompiled headers. One
530 is that to take advantage of the facility, you often need to include
531 more header files than would normally be the case. This means that
532 changing a header file will cause more recompilations (in the case of
533 wxWindows, everything needs to be recompiled since everything includes
536 A related problem is that for compilers that don't have precompiled
537 headers, including a lot of header files slows down compilation
538 considerably. For this reason, you will find (in the common
539 X and Windows parts of the library) conditional
540 compilation that under Unix, includes a minimal set of headers;
541 and when using Visual C++, includes
{\tt wx.h
}. This should help provide
542 the optimal compilation for each compiler, although it is
543 biassed towards the precompiled headers facility available
546 \section{File handling
}
548 When building an application which may be used under different
549 environments, one difficulty is coping with documents which may be
550 moved to different directories on other machines. Saving a file which
551 has pointers to full pathnames is going to be inherently unportable. One
552 approach is to store filenames on their own, with no directory
553 information. The application searches through a number of locally
554 defined directories to find the file. To support this, the class
{\bf
555 wxPathList
} makes adding directories and searching for files easy, and
556 the global function
{\bf FileNameFromPath
} allows the application to
557 strip off the filename from the path if the filename must be stored.
558 This has undesirable ramifications for people who have documents of the
559 same name in different directories.
561 As regards the limitations of DOS
8+
3 single-case filenames versus
562 unrestricted Unix filenames, the best solution is to use DOS filenames
563 for your application, and also for
document filenames
{\it if
} the user
564 is likely to be switching platforms regularly. Obviously this latter
565 choice is up to the application user to decide. Some programs (such as
566 YACC and LEX) generate filenames incompatible with DOS; the best
567 solution here is to have your Unix makefile rename the generated files
568 to something more compatible before transferring the source to DOS.
569 Transferring DOS files to Unix is no problem, of course, apart from EOL
570 conversion for which there should be a utility available (such as
573 See also the File Functions section of the reference manual for
574 descriptions of miscellaneous file handling functions.
576 \chapter{Utilities supplied with wxWindows
}\label{utilities
}
577 \setheader{{\it CHAPTER
\thechapter}}{}{}{}{}{{\it CHAPTER
\thechapter}}%
578 \setfooter{\thepage}{}{}{}{}{\thepage}%
580 A number of `extras' are supplied with wxWindows, to complement
581 the GUI functionality in the main class library. These are found
582 below the utils directory and usually have their own source, library
583 and documentation directories. For larger user-contributed packages,
584 see the directory /pub/packages/wxwin/contrib.
586 \section{wxHelp
}\label{wxhelp
}
588 wxHelp is a stand-alone program, written using wxWindows,
589 for displaying hypertext help. It is necessary since not all target
590 systems (notably X) supply an adequate
591 standard for on-line help. wxHelp is modelled on the MS Windows help
592 system, with contents, search and browse buttons, but does not reformat
593 text to suit the size of window, as WinHelp does, and its input files
594 are uncompressed ASCII with some embedded font commands and an .xlp
595 extension. Most wxWindows documentation (user manuals and class
596 references) is supplied in wxHelp format, and also in Windows Help
597 format. The wxWindows
2.0 project will presently use an HTML widget
598 in a new and improved wxHelp implementation, under X.
600 Note that an application can be programmed to use Windows Help under
601 MS Windows, and wxHelp under X. An alternative help viewer under X is
602 Mosaic, a World Wide Web viewer that uses HTML as its native hypertext
603 format. However, this is not currently integrated with wxWindows
606 wxHelp works in two modes---edit and end-user. In edit mode, an ASCII
607 file may be marked up with different fonts and colours, and divided into
608 sections. In end-user mode, no editing is possible, and the user browses
609 principally by clicking on highlighted blocks.
611 When an application invokes wxHelp, subsequent sections, blocks or
612 files may be viewed using the same instance of wxHelp since the two
613 programs are linked using wxWindows interprocess communication
614 facilities. When the application exits, that application's instance of
615 wxHelp may be made to exit also. See the
{\bf wxHelpControllerBase
} entry in the
616 reference section for how an application controls wxHelp.
618 \section{Tex2RTF
}\label{textortf
}
620 Supplied with wxWindows is a utility called Tex2RTF for converting
\rtfsp
621 \LaTeX\ manuals to the following formats:
625 wxWindows help system format (XLP).
627 Rich Text Format suitable for importing into a word processor.
628 \item[Windows Help RTF
]
629 Rich Text Format suitable for compiling into a WinHelp HLP file with the
632 HTML is the native format for Mosaic, the main hypertext viewer for
633 the World Wide Web. Since it is freely available it is a good candidate
634 for being the wxWindows help system under X, as an alternative to wxHelp.
637 Tex2RTF is used for the wxWindows manuals and can be used independently
638 by authors wishing to create on-line and printed manuals from the same
\rtfsp
639 \LaTeX\ source. Please see the separate documentation for Tex2RTF.
641 \section{wxTreeLayout
}
643 This is a simple class library for drawing trees in a reasonably pretty
644 fashion. It provides only minimal default drawing capabilities, since
645 the algorithm is meant to be used for implementing custom tree-based
648 Directed graphs may also be drawn using this library, if cycles are
649 removed before the nodes and arcs are passed to the algorithm.
651 Tree displays are used in many applications: directory browsers,
652 hypertext systems, class browsers, and decision trees are a few
655 See the separate manual and the directory utils/wxtree.
657 \section{wxGraphLayout
}
659 The wxGraphLayout class is based on a tool called `graphplace' by Dr.
660 Jos 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
662 in a sensible manner. There are many applications (such as diagramming)
663 where it is required to display a graph with no human intervention. Even
664 if manual repositioning is later required, this algorithm can make a good
667 See the separate manual and the directory utils/wxgraph.
669 \section{Colours
}\label{coloursampler
}
671 A colour sampler for viewing colours and their names on each
675 \chapter{Tutorial
}\label{tutorial
}
676 \setheader{{\it CHAPTER
\thechapter}}{}{}{}{}{{\it CHAPTER
\thechapter}}%
677 \setfooter{\thepage}{}{}{}{}{\thepage}%
681 \chapter{Programming strategies
}\label{strategies
}
682 \setheader{{\it CHAPTER
\thechapter}}{}{}{}{}{{\it CHAPTER
\thechapter}}%
683 \setfooter{\thepage}{}{}{}{}{\thepage}%
685 This chapter is intended to list strategies that may be useful when
686 writing and debugging wxWindows programs. If you have any good tips,
687 please submit them for inclusion here.
689 \section{Strategies for reducing programming errors
}
691 \subsection{Use ASSERT
}
693 Although I haven't done this myself within wxWindows, it is good
694 practice to use ASSERT statements liberally, that check for conditions that
695 should or should not hold, and print out appropriate error messages.
696 These can be compiled out of a non-debugging version of wxWindows
697 and your application. Using ASSERT is an example of `defensive programming':
698 it can alert you to problems later on.
700 \subsection{Use wxString in preference to character arrays
}
702 Using wxString can be much safer and more convenient than using char *.
703 Again, I haven't practised what I'm preaching, but I'm now trying to use
704 wxString wherever possible. You can reduce the possibility of memory
705 leaks substantially, and it's much more convenient to use the overloaded
706 operators than functions such as strcmp. wxString won't add a significant
707 overhead to your program; the overhead is compensated for by easier
708 manipulation (which means less code).
710 The same goes for other data types: use classes wherever possible.
712 \section{Strategies for portability
}
714 \subsection{Use relative positioning or constraints
}
716 Don't use absolute panel item positioning if you can avoid it. Different GUIs have
717 very differently sized panel items. Consider using the constraint system, although this
718 can be complex to program. If you needs are simple, the default relative positioning
719 behaviour may be adequate (using default position values and wxPanel::NewLine).
721 Alternatively, you could use alternative .wrc (wxWindows resource files) on different
722 platforms, with slightly different dimensions in each. Or space your panel items out
725 \subsection{Use wxWindows resource files
}
727 Use .wrc (wxWindows resource files) where possible, because they can be easily changed
728 independently of source code. Bitmap resources can be set up to load different
729 kinds of bitmap depending on platform (see the section on resource files).
731 \section{Strategies for debugging
}\label{debugstrategies
}
733 \subsection{Positive thinking
}
735 It's common to blow up the problem in one's imagination, so that it seems to threaten
736 weeks, months or even years of work. The problem you face may seem insurmountable:
737 but almost never is. Once you have been programming for some time, you will be able
738 to remember similar incidents that threw you into the depths of despair. But
739 remember, you always solved the problem, somehow!
741 Perseverance is often the key, even though a seemingly trivial problem
742 can take an apparently inordinate amount of time to solve. In the end,
743 you will probably wonder why you worried so much. That's not to say it
744 isn't painful at the time. Try not to worry -- there are many more important
747 \subsection{Simplify the problem
}
749 Reduce the code exhibiting the problem to the smallest program possible
750 that exhibits the problem. If it is not possible to reduce a large and
751 complex program to a very small program, then try to ensure your code
752 doesn't hide the problem (you may have attempted to minimize the problem
753 in some way: but now you want to expose it).
755 With luck, you can add a small amount of code that causes the program
756 to go from functioning to non-functioning state. This should give a clue
757 to the problem. In some cases though, such as memory leaks or wrong
758 deallocation, this can still give totally spurious results!
760 \subsection{Use a debugger
}
762 This sounds like facetious advice, but it's surprising how often people
763 don't use a debugger. Often it's an overhead to install or learn how to
764 use a debugger, but it really is essential for anything but the most
767 \subsection{Use logging functions
}
769 There is a variety of logging functions that you can use in your program:
770 see
\helpref{Logging functions
}{logfunctions
}.
772 Using tracing statements may be more convenient than using the debugger
773 in some circumstances (such as when your debugger doesn't support a lot
774 of debugging code, or you wish to print a bunch of variables).
776 \subsection{Use the wxWindows debugging facilities
}
778 You can use wxDebugContext to check for
779 memory leaks and corrupt memory: in fact in debugging mode, wxWindows will
780 automatically check for memory leaks at the end of the program if wxWindows is suitably
781 configured. Depending on the operating system and compiler, more or less
782 specific information about the problem will be logged.
784 You should also use
\helpref{debug macros
}{debugmacros
} as part of a `defensive programming' strategy,
785 scattering wxASSERTs liberally to test for problems in your code as early as possible. Forward thinking
786 will save a surprising amount of time in the long run.
788 See the
\helpref{debugging overview
}{debuggingoverview
} for further information.
790 \subsection{Check Windows debug messages
}
792 Under Windows, it's worth running your program with DBWIN running or
793 some other program that shows Windows-generated debug messages. It's
794 possible it'll show invalid handles being used. You may have fun seeing
795 what commercial programs cause these normally hidden errors! Microsoft
796 recommend using the debugging version of Windows, which shows up even
797 more problems. However, I doubt it's worth the hassle for most
798 applications. wxWindows is designed to minimize the possibility of such
799 errors, but they can still happen occasionally, slipping through unnoticed
800 because they are not severe enough to cause a crash.
802 \subsection{Genetic mutation
}
804 If we had sophisticated genetic algorithm tools that could be applied
805 to programming, we could use them. Until then, a common -- if rather irrational --
806 technique is to just make arbitrary changes to the code until something
807 different happens. You may have an intuition why a change will make a difference;
808 otherwise, just try altering the order of code, comment lines out, anything
809 to get over an impasse. Obviously, this is usually a last resort.