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