]>
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 | ||
569ef72a | 6 | \section{What is wxWidgets?}\label{whatis} |
a660d684 | 7 | |
fc2171bd | 8 | wxWidgets is a C++ framework providing GUI (Graphical User |
fa482912 | 9 | Interface) and other facilities on more than one platform. Version 2 currently |
bd330a69 JS |
10 | supports all desktop versions of MS Windows, Unix with GTK+, Unix with Motif, |
11 | and MacOS. An OS/2 port is in progress. | |
a660d684 | 12 | |
fc2171bd | 13 | wxWidgets was originally developed at the Artificial Intelligence |
fa482912 | 14 | Applications Institute, University of Edinburgh, for internal use, |
bd330a69 | 15 | and was first made publicly available in 1992. |
fa482912 | 16 | Version 2 is a vastly improved version written and maintained by |
bd330a69 | 17 | Julian Smart, Robert Roebling, Vadim Zeitlin, Vaclav Slavik and many others. |
a660d684 | 18 | |
bd330a69 | 19 | This manual contains a class reference and topic overviews. |
fc2171bd | 20 | For a selection of wxWidgets tutorials, please see the documentation page on the \urlref{wxWidgets web site}{http://www.wxwidgets.org}. |
a660d684 KB |
21 | |
22 | Please note that in the following, ``MS Windows" often refers to all | |
23 | platforms related to Microsoft Windows, including 16-bit and 32-bit | |
24 | variants, unless otherwise stated. All trademarks are acknowledged. | |
25 | ||
569ef72a | 26 | \section{Why another cross-platform development tool?}\label{why} |
a660d684 | 27 | |
fc2171bd | 28 | wxWidgets was developed to provide a cheap and flexible way to maximize |
a660d684 | 29 | investment in GUI application development. While a number of commercial |
8a2c6ef8 | 30 | class libraries already existed for cross-platform development, |
a660d684 KB |
31 | none met all of the following criteria: |
32 | ||
33 | \begin{enumerate}\itemsep=0pt | |
34 | \item low price; | |
35 | \item source availability; | |
36 | \item simplicity of programming; | |
37 | \item support for a wide range of compilers. | |
38 | \end{enumerate} | |
39 | ||
fc2171bd | 40 | Since wxWidgets was started, several other free or almost-free |
bd330a69 JS |
41 | GUI frameworks have emerged. However, none has the range of |
42 | features, flexibility, documentation and the well-established | |
fc2171bd | 43 | development team that wxWidgets has. |
bd330a69 | 44 | |
fc2171bd | 45 | As open source software, wxWidgets has benefited from comments, |
bd330a69 | 46 | ideas, bug fixes, enhancements and the sheer enthusiasm of |
fc2171bd | 47 | users. This gives wxWidgets a certain advantage over its |
bd330a69 JS |
48 | commercial competitors (and over free libraries without an |
49 | independent development team), plus a robustness against the | |
50 | transience of one individual or company. This openness and | |
51 | availability of source code is especially important when the | |
52 | future of thousands of lines of application code may depend upon | |
53 | the longevity of the underlying class library. | |
54 | ||
55 | Version 2 goes much further than previous versions in terms of | |
56 | generality and features, allowing applications to be produced | |
57 | that are often indistinguishable from those produced using | |
58 | single-platform toolkits such as Motif, GTK+ and MFC. | |
59 | ||
60 | The importance of using a platform-independent class library | |
61 | cannot be overstated, since GUI application development is very | |
62 | time-consuming, and sustained popularity of particular GUIs | |
63 | cannot be guaranteed. Code can very quickly become obsolete if | |
fc2171bd | 64 | it addresses the wrong platform or audience. wxWidgets helps to |
bd330a69 | 65 | insulate the programmer from these winds of change. Although |
fc2171bd | 66 | wxWidgets may not be suitable for every application (such as an |
bd330a69 JS |
67 | OLE-intensive program), it provides access to most of the |
68 | functionality a GUI program normally requires, plus many extras | |
69 | such as network programming, PostScript output, and HTML | |
70 | rendering; and it can of course be extended as needs dictate. | |
71 | As a bonus, it provides a far cleaner and easier programming | |
72 | interface than the native APIs. Programmers may find it | |
fc2171bd | 73 | worthwhile to use wxWidgets even if they are developing on only |
bd330a69 | 74 | one platform. |
a660d684 | 75 | |
fc2171bd | 76 | It is impossible to sum up the functionality of wxWidgets in a few paragraphs, but |
a660d684 KB |
77 | here are some of the benefits: |
78 | ||
79 | \begin{itemize}\itemsep=0pt | |
80 | \item Low cost (free, in fact!) | |
81 | \item You get the source. | |
8a2c6ef8 | 82 | \item Available on a variety of popular platforms. |
ccaaf5b0 | 83 | \item Works with almost all popular C++ compilers and Python. |
fa482912 JS |
84 | \item Over 50 example programs. |
85 | \item Over 1000 pages of printable and on-line documentation. | |
8a2c6ef8 JS |
86 | \item Includes Tex2RTF, to allow you to produce your own documentation |
87 | in Windows Help, HTML and Word RTF formats. | |
a660d684 | 88 | \item Simple-to-use, object-oriented API. |
8a2c6ef8 JS |
89 | \item Flexible event system. |
90 | \item Graphics calls include lines, rounded rectangles, splines, polylines, etc. | |
f6bcfd97 | 91 | \item Constraint-based and sizer-based layouts. |
a660d684 | 92 | \item Print/preview and document/view architectures. |
8a2c6ef8 | 93 | \item Toolbar, notebook, tree control, advanced list control classes. |
ccaaf5b0 | 94 | \item PostScript generation under Unix, normal MS Windows printing on the PC. |
62448488 JS |
95 | \item MDI (Multiple Document Interface) support. |
96 | \item Can be used to create DLLs under Windows, dynamic libraries on Unix. | |
a660d684 KB |
97 | \item Common dialogs for file browsing, printing, colour selection, etc. |
98 | \item Under MS Windows, support for creating metafiles and copying | |
99 | them to the clipboard. | |
62448488 | 100 | \item An API for invoking help from applications. |
fa482912 | 101 | \item Ready-to-use HTML window (supporting a subset of HTML). |
8a2c6ef8 | 102 | \item Network support via a family of socket and protocol classes. |
f6bcfd97 | 103 | \item Support for platform independent image processing. |
ccaaf5b0 | 104 | \item Built-in support for many file formats (BMP, PNG, JPEG, GIF, XPM, PNM, PCX). |
a660d684 KB |
105 | \end{itemize} |
106 | ||
d958c9bd | 107 | \begin{comment} |
ccaaf5b0 RR |
108 | \section{Changes from version 2.0}\label{versionchanges20} |
109 | ||
110 | These are a few of the differences between versions 2.0 and 2.2. | |
111 | ||
112 | Removals: | |
113 | ||
114 | \begin{itemize}\itemsep=0pt | |
115 | \item GTK 1.0 no longer supported. | |
116 | \end{itemize} | |
117 | ||
118 | Additions and changes: | |
119 | ||
120 | \begin{itemize}\itemsep=0pt | |
121 | \item Corrected many classes to conform better to documented behaviour. | |
122 | \item Added handlers for more image formats (Now GIF, JPEG, PCX, BMP, XPM, PNG, PNM). | |
123 | \item Improved support for socket and network functions. | |
124 | \item Support for different national font encodings. | |
125 | \item Sizer based layout system. | |
126 | \item HTML widget and help system. | |
127 | \item Added some controls (e.g. wxSpinCtrl) and supplemented many. | |
128 | \item Many optical improvements to GTK port. | |
129 | \item Support for menu accelerators in GTK port. | |
130 | \item Enhanced and improved support for scrolling, including child windows. | |
f6bcfd97 | 131 | \item Complete rewrite of clipboard and drag and drop classes. |
ccaaf5b0 RR |
132 | \item Improved support for ODBC databases. |
133 | \item Improved tab traversal in dialogs. | |
134 | \end{itemize} | |
d958c9bd | 135 | \end{comment} |
ccaaf5b0 | 136 | |
fc2171bd | 137 | \section{wxWidgets requirements}\label{requirements} |
a660d684 | 138 | |
fc2171bd | 139 | To make use of wxWidgets, you currently need one of the following setups. |
a660d684 | 140 | |
1d0b7ed3 | 141 | (a) MS-Windows: |
a660d684 KB |
142 | |
143 | \begin{enumerate}\itemsep=0pt | |
13cf3832 WS |
144 | \item A 32-bit or 64-bit PC running MS Windows. |
145 | \item A Windows compiler: MS Visual C++ (embedded Visual C++ for wxWinCE | |
146 | port), Borland C++, Watcom C++, Cygwin, MinGW, Metrowerks CodeWarrior, | |
147 | Digital Mars C++. See {\tt install.txt} for details about compiler | |
148 | version supported. | |
149 | \item At least 100 MB of disk space for source tree and additional space for | |
150 | libraries and application building (depends on compiler and build settings). | |
a660d684 KB |
151 | \end{enumerate} |
152 | ||
bd0df01f | 153 | (b) Unix: |
a660d684 KB |
154 | |
155 | \begin{enumerate}\itemsep=0pt | |
91b8de8d | 156 | \item Almost any C++ compiler, including GNU C++ (EGCS 1.1.1 or above). |
e3ba9f88 | 157 | \item Almost any Unix workstation, and one of: GTK+ 1.2, GTK+ 2.0, Motif 1.2 or higher, Lesstif. |
0497e172 | 158 | If using the wxX11 port, no such widget set is required. |
13cf3832 WS |
159 | \item At least 100 MB of disk space for source tree and additional space for |
160 | libraries and application building (depends on compiler and build settings). | |
a660d684 KB |
161 | \end{enumerate} |
162 | ||
1d0b7ed3 GD |
163 | (c) Mac OS/Mac OS X: |
164 | ||
165 | \begin{enumerate}\itemsep=0pt | |
166 | \item A PowerPC Mac running Mac OS 8.6/9.x (eg. Classic) or Mac OS X 10.x. | |
167 | \item CodeWarrior 5.3, 6 or 7 for Classic Mac OS. | |
13cf3832 WS |
168 | \item The Apple Developer Tools (eg. GNU C++), CodeWarrior 7 or above for Mac OS X. |
169 | \item At least 100 MB of disk space for source tree and additional space for | |
170 | libraries and application building (depends on compiler and build settings). | |
1d0b7ed3 GD |
171 | \end{enumerate} |
172 | ||
569ef72a | 173 | \section{Availability and location of wxWidgets}\label{where} |
a660d684 | 174 | |
fc2171bd JS |
175 | \winhelponly{wxWidgets is available by anonymous FTP and World Wide Web |
176 | from ftp://biolpc22.york.ac.uk/pub and/or http://www.wxwidgets.org.} | |
177 | \winhelpignore{wxWidgets is available by anonymous FTP and World Wide Web | |
f44b23b6 | 178 | from \urlref{ftp://biolpc22.york.ac.uk/pub}{ftp://biolpc22.york.ac.uk/pub} |
fc2171bd | 179 | and/or \urlref{http://www.wxwidgets.org}{http://www.wxwidgets.org}.} |
a660d684 | 180 | |
d958c9bd | 181 | You can also buy a CD-ROM using the form on the Web site. |
448af9a4 | 182 | |
569ef72a | 183 | \section{Acknowledgements}\label{acknowledgements} |
a660d684 | 184 | |
bd0df01f | 185 | Thanks are due to AIAI for being willing to release the original version of |
fc2171bd | 186 | wxWidgets into the public domain, and to our patient partners. |
bd0df01f | 187 | |
fc2171bd | 188 | We would particularly like to thank the following for their contributions to wxWidgets, and the many others who have been involved in |
bd0df01f JS |
189 | the project over the years. Apologies for any unintentional omissions from this list. |
190 | ||
ecd7e67e WS |
191 | Yiorgos Adamopoulos, Jamshid Afshar, Alejandro Aguilar-Sierra, AIAI, |
192 | Patrick Albert, Karsten Ballueder, Mattia Barbon, Michael Bedward, | |
193 | Kai Bendorf, Yura Bidus, Keith Gary Boyce, Chris Breeze, Pete Britton, | |
6652e1a7 | 194 | Ian Brown, C. Buckley, Marco Cavallini, Dmitri Chubraev, Robin Corbet, Cecil Coupe, |
ecd7e67e WS |
195 | Stefan Csomor, Andrew Davison, Gilles Depeyrot, Neil Dudman, Robin Dunn, |
196 | Hermann Dunkel, Jos van Eijndhoven, Chris Elliott, David Elliott, Tom Felici, | |
197 | Thomas Fettig, Matthew Flatt, Pasquale Foggia, Josep Fortiana, Todd Fries, | |
198 | Dominic Gallagher, Guillermo Rodriguez Garcia, Wolfram Gloger, Norbert Grotz, | |
199 | Stefan Gunter, Bill Hale, Patrick Halke, Stefan Hammes, Guillaume Helle, | |
200 | Harco de Hilster, Cord Hockemeyer, Markus Holzem, Olaf Klein, Leif Jensen, | |
201 | Bart Jourquin, Guilhem Lavaux, Ron Lee, Jan Lessner, Nicholas Liebmann, | |
202 | Torsten Liermann, Per Lindqvist, Thomas Runge, Tatu M\"{a}nnist\"{o}, | |
203 | Scott Maxwell, Thomas Myers, Oliver Niedung, Stefan Neis, Hernan Otero, | |
204 | Ian Perrigo, Timothy Peters, Giordano Pezzoli, Harri Pasanen, Thomaso Paoletti, | |
205 | Garrett Potts, Marcel Rasche, Robert Roebling, Dino Scaringella, | |
206 | Jobst Schmalenbach, Arthur Seaton, Paul Shirley, Wlodzimierz `ABX' Skiba, | |
207 | Vaclav Slavik, Julian Smart, Stein Somers, Petr Smilauer, Neil Smith, | |
208 | Kari Syst\"{a}, George Tasker, Arthur Tetzlaff-Deas, Jonathan Tonberg, | |
209 | Jyrki Tuomi, Janos Vegh, Andrea Venturoli, David Webster, Otto Wyss, | |
210 | Vadim Zeitlin, Xiaokun Zhu, Edward Zimmermann. | |
a660d684 KB |
211 | |
212 | `Graphplace', the basis for the wxGraphLayout library, is copyright Dr. Jos | |
213 | T.J. van Eijndhoven of Eindhoven University of Technology. The code has | |
214 | been used in wxGraphLayout with his permission. | |
215 | ||
bd0df01f | 216 | We also acknowledge the author of XFIG, the excellent Unix drawing tool, |
a660d684 KB |
217 | from the source of which we have borrowed some spline drawing code. |
218 | His copyright is included below. | |
219 | ||
220 | {\it XFig2.1 is copyright (c) 1985 by Supoj Sutanthavibul. Permission to | |
221 | use, copy, modify, distribute, and sell this software and its | |
222 | documentation for any purpose is hereby granted without fee, provided | |
223 | that the above copyright notice appear in all copies and that both that | |
224 | copyright notice and this permission notice appear in supporting | |
225 | documentation, and that the name of M.I.T. not be used in advertising or | |
226 | publicity pertaining to distribution of the software without specific, | |
227 | written prior permission. M.I.T. makes no representations about the | |
228 | suitability of this software for any purpose. It is provided ``as is'' | |
229 | without express or implied warranty.} | |
230 | ||
fc2171bd | 231 | \chapter{Multi-platform development with wxWidgets}\label{multiplat} |
a660d684 KB |
232 | \setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}% |
233 | \setfooter{\thepage}{}{}{}{}{\thepage}% | |
234 | ||
fc2171bd | 235 | This chapter describes the practical details of using wxWidgets. Please |
a660d684 KB |
236 | see the file install.txt for up-to-date installation instructions, and |
237 | changes.txt for differences between versions. | |
238 | ||
569ef72a | 239 | \section{Include files}\label{includefiles} |
a660d684 | 240 | |
bd0df01f | 241 | The main include file is {\tt "wx/wx.h"}; this includes the most commonly |
fc2171bd | 242 | used modules of wxWidgets. |
a660d684 KB |
243 | |
244 | To save on compilation time, include only those header files relevant to the | |
245 | source file. If you are using precompiled headers, you should include | |
246 | the following section before any other includes: | |
247 | ||
248 | \begin{verbatim} | |
249 | // For compilers that support precompilation, includes "wx.h". | |
bd0df01f | 250 | #include <wx/wxprec.h> |
a660d684 KB |
251 | |
252 | #ifdef __BORLANDC__ | |
253 | #pragma hdrstop | |
254 | #endif | |
255 | ||
256 | #ifndef WX_PRECOMP | |
bd0df01f JS |
257 | // Include your minimal set of headers here, or wx.h |
258 | #include <wx/wx.h> | |
a660d684 KB |
259 | #endif |
260 | ||
261 | ... now your other include files ... | |
262 | \end{verbatim} | |
263 | ||
bd0df01f | 264 | The file {\tt "wx/wxprec.h"} includes {\tt "wx/wx.h"}. Although this incantation |
a660d684 | 265 | may seem quirky, it is in fact the end result of a lot of experimentation, |
13cf3832 WS |
266 | and several Windows compilers to use precompilation which is largely automatic for |
267 | compilers with necessary support. Currently it is used for Visual C++ (including | |
268 | embedded Visual C++), Borland C++, Open Watcom C++ and newer versions of GCC. | |
a660d684 | 269 | |
569ef72a | 270 | \section{Libraries}\label{libraries} |
a660d684 | 271 | |
fc2171bd JS |
272 | Most ports of wxWidgets can create either a static library or a shared |
273 | library. wxWidgets can also be built in multilib and monolithic variants. | |
0497e172 JS |
274 | See the \helpref{libraries list}{librarieslist} for more |
275 | information on these. | |
a660d684 | 276 | |
569ef72a | 277 | \section{Configuration}\label{configuration} |
a660d684 | 278 | |
fc2171bd | 279 | When using project files and makefiles directly to build wxWidgets, |
0497e172 | 280 | options are configurable in the file |
ccaaf5b0 RR |
281 | \rtfsp{\tt "wx/XXX/setup.h"} where XXX is the required platform (such as msw, motif, gtk, mac). Some |
282 | settings are a matter of taste, some help with platform-specific problems, and | |
62448488 JS |
283 | others can be set to minimize the size of the library. Please see the setup.h file |
284 | and {\tt install.txt} files for details on configuration. | |
a660d684 | 285 | |
fc2171bd | 286 | When using the 'configure' script to configure wxWidgets (on Unix and other platforms where |
0497e172 JS |
287 | configure is available), the corresponding setup.h files are generated automatically |
288 | along with suitable makefiles. When using the RPM packages | |
fc2171bd | 289 | for installing wxWidgets on Linux, a correct setup.h is shipped in the package and |
ccaaf5b0 RR |
290 | this must not be changed. |
291 | ||
569ef72a | 292 | \section{Makefiles}\label{makefiles} |
a660d684 | 293 | |
fc2171bd | 294 | On Microsoft Windows, wxWidgets has a different set of makefiles for each |
0497e172 JS |
295 | compiler, because each compiler's 'make' tool is slightly different. |
296 | Popular Windows compilers that we cater for, and the corresponding makefile | |
297 | extensions, include: Microsoft Visual C++ (.vc), Borland C++ (.bcc), | |
298 | OpenWatcom C++ (.wat) and MinGW/Cygwin (.gcc). Makefiles are provided | |
fc2171bd | 299 | for the wxWidgets library itself, samples, demos, and utilities. |
0497e172 JS |
300 | |
301 | On Linux, Mac and OS/2, you use the 'configure' command to | |
302 | generate the necessary makefiles. You should also use this method when | |
303 | building with MinGW/Cygwin on Windows. | |
304 | ||
305 | We also provide project files for some compilers, such as | |
306 | Microsoft VC++. However, we recommend using makefiles | |
fc2171bd | 307 | to build the wxWidgets library itself, because makefiles |
0497e172 JS |
308 | can be more powerful and less manual intervention is required. |
309 | ||
310 | On Windows using a compiler other than MinGW/Cygwin, you would | |
fc2171bd | 311 | build the wxWidgets library from the build/msw directory |
0497e172 JS |
312 | which contains the relevant makefiles. |
313 | ||
314 | On Windows using MinGW/Cygwin, and on Unix, MacOS X and OS/2, you invoke | |
fc2171bd | 315 | 'configure' (found in the top-level of the wxWidgets source hierarchy), |
0497e172 JS |
316 | from within a suitable empty directory for containing makefiles, object files and |
317 | libraries. | |
318 | ||
319 | For details on using makefiles, configure, and project files, | |
320 | please see docs/xxx/install.txt in your distribution, where | |
321 | xxx is the platform of interest, such as msw, gtk, x11, mac. | |
a660d684 | 322 | |
569ef72a | 323 | \section{Windows-specific files}\label{windowsfiles} |
a660d684 | 324 | |
fc2171bd | 325 | wxWidgets application compilation under MS Windows requires at least two |
a660d684 KB |
326 | extra files, resource and module definition files. |
327 | ||
328 | \subsection{Resource file}\label{resources} | |
329 | ||
330 | The least that must be defined in the Windows resource file (extension RC) | |
331 | is the following statement: | |
332 | ||
333 | \begin{verbatim} | |
0497e172 | 334 | #include "wx/msw/wx.rc" |
a660d684 KB |
335 | \end{verbatim} |
336 | ||
fc2171bd | 337 | which includes essential internal wxWidgets definitions. The resource script |
a660d684 KB |
338 | may also contain references to icons, cursors, etc., for example: |
339 | ||
340 | \begin{verbatim} | |
341 | wxicon icon wx.ico | |
342 | \end{verbatim} | |
343 | ||
344 | The icon can then be referenced by name when creating a frame icon. See | |
345 | the MS Windows SDK documentation. | |
346 | ||
347 | \normalbox{Note: include wx.rc {\it after} any ICON statements | |
348 | so programs that search your executable for icons (such | |
349 | as the Program Manager) find your application icon first.} | |
350 | ||
569ef72a | 351 | \section{Allocating and deleting wxWidgets objects}\label{allocatingobjects} |
a660d684 KB |
352 | |
353 | In general, classes derived from wxWindow must dynamically allocated | |
354 | with {\it new} and deleted with {\it delete}. If you delete a window, | |
355 | all of its children and descendants will be automatically deleted, | |
356 | so you don't need to delete these descendants explicitly. | |
357 | ||
bd0df01f | 358 | When deleting a frame or dialog, use {\bf Destroy} rather than {\bf delete} so |
fc2171bd | 359 | that the wxWidgets delayed deletion can take effect. This waits until idle time |
bd0df01f JS |
360 | (when all messages have been processed) to actually delete the window, to avoid |
361 | problems associated with the GUI sending events to deleted windows. | |
a660d684 | 362 | |
bd0df01f JS |
363 | Don't create a window on the stack, because this will interfere |
364 | with delayed deletion. | |
a660d684 KB |
365 | |
366 | If you decide to allocate a C++ array of objects (such as wxBitmap) that may | |
fc2171bd JS |
367 | be cleaned up by wxWidgets, make sure you delete the array explicitly |
368 | before wxWidgets has a chance to do so on exit, since calling {\it delete} on | |
a660d684 KB |
369 | array members will cause memory problems. |
370 | ||
371 | wxColour can be created statically: it is not automatically cleaned | |
372 | up and is unlikely to be shared between other objects; it is lightweight | |
373 | enough for copies to be made. | |
374 | ||
375 | Beware of deleting objects such as a wxPen or wxBitmap if they are still in use. | |
376 | Windows is particularly sensitive to this: so make sure you | |
bd0df01f | 377 | make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deleting |
a660d684 KB |
378 | a drawing object that may be in use. Code that doesn't do this will probably work |
379 | fine on some platforms, and then fail under Windows. | |
380 | ||
569ef72a | 381 | \section{Architecture dependency}\label{architecturedependency} |
91b8de8d RR |
382 | |
383 | A problem which sometimes arises from writing multi-platform programs is that | |
f6bcfd97 | 384 | the basic C types are not defined the same on all platforms. This holds true |
91b8de8d RR |
385 | for both the length in bits of the standard types (such as int and long) as |
386 | well as their byte order, which might be little endian (typically | |
fc2171bd | 387 | on Intel computers) or big endian (typically on some Unix workstations). wxWidgets |
91b8de8d RR |
388 | defines types and macros that make it easy to write architecture independent |
389 | code. The types are: | |
390 | ||
391 | wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte | |
392 | ||
393 | where wxInt32 stands for a 32-bit signed integer type etc. You can also check | |
394 | which architecture the program is compiled on using the wxBYTE\_ORDER define | |
395 | which is either wxBIG\_ENDIAN or wxLITTLE\_ENDIAN (in the future maybe wxPDP\_ENDIAN | |
396 | as well). | |
397 | ||
398 | The macros handling bit-swapping with respect to the applications endianness | |
81c9effa | 399 | are described in the \helpref{Byte order macros}{byteordermacros} section. |
91b8de8d | 400 | |
569ef72a | 401 | \section{Conditional compilation}\label{conditionalcompilation} |
a660d684 | 402 | |
fc2171bd | 403 | One of the purposes of wxWidgets is to reduce the need for conditional |
a660d684 KB |
404 | compilation in source code, which can be messy and confusing to follow. |
405 | However, sometimes it is necessary to incorporate platform-specific | |
62448488 JS |
406 | features (such as metafile use under MS Windows). The symbols |
407 | listed in the file {\tt symbols.txt} may be used for this purpose, | |
408 | along with any user-supplied ones. | |
b8de493f | 409 | |
569ef72a | 410 | \section{C++ issues}\label{cpp} |
a660d684 | 411 | |
bd0df01f | 412 | The following documents some miscellaneous C++ issues. |
a660d684 | 413 | |
a203f6c0 | 414 | \subsection{Templates}\label{templates} |
a660d684 | 415 | |
fc2171bd | 416 | wxWidgets does not use templates (except for some advanced features that |
0497e172 | 417 | are switched off by default) since it is a notoriously unportable feature. |
a660d684 | 418 | |
a203f6c0 | 419 | \subsection{RTTI}\label{rtti} |
12a44087 | 420 | |
fc2171bd | 421 | wxWidgets does not use C++ run-time type information since wxWidgets provides |
12a44087 RR |
422 | its own run-time type information system, implemented using macros. |
423 | ||
a203f6c0 | 424 | \subsection{Type of NULL}\label{null} |
12a44087 RR |
425 | |
426 | Some compilers (e.g. the native IRIX cc) define NULL to be 0L so that | |
427 | no conversion to pointers is allowed. Because of that, all these | |
0497e172 | 428 | occurrences of NULL in the GTK+ port use an explicit conversion such |
12a44087 RR |
429 | as |
430 | ||
431 | {\small | |
432 | \begin{verbatim} | |
433 | wxWindow *my_window = (wxWindow*) NULL; | |
434 | \end{verbatim} | |
d2c2afc9 | 435 | }% |
12a44087 | 436 | |
fc2171bd | 437 | It is recommended to adhere to this in all code using wxWidgets as |
12a44087 RR |
438 | this make the code (a bit) more portable. |
439 | ||
a203f6c0 | 440 | \subsection{Precompiled headers}\label{precompiledheaders} |
a660d684 KB |
441 | |
442 | Some compilers, such as Borland C++ and Microsoft C++, support | |
443 | precompiled headers. This can save a great deal of compiling time. The | |
8a2c6ef8 | 444 | recommended approach is to precompile {\tt "wx.h"}, using this |
fc2171bd JS |
445 | precompiled header for compiling both wxWidgets itself and any |
446 | wxWidgets applications. For Windows compilers, two dummy source files | |
a660d684 KB |
447 | are provided (one for normal applications and one for creating DLLs) |
448 | to allow initial creation of the precompiled header. | |
449 | ||
450 | However, there are several downsides to using precompiled headers. One | |
451 | is that to take advantage of the facility, you often need to include | |
452 | more header files than would normally be the case. This means that | |
453 | changing a header file will cause more recompilations (in the case of | |
fc2171bd | 454 | wxWidgets, everything needs to be recompiled since everything includes {\tt "wx.h"}!) |
a660d684 KB |
455 | |
456 | A related problem is that for compilers that don't have precompiled | |
457 | headers, including a lot of header files slows down compilation | |
458 | considerably. For this reason, you will find (in the common | |
459 | X and Windows parts of the library) conditional | |
bd0df01f | 460 | compilation that under Unix, includes a minimal set of headers; |
a660d684 KB |
461 | and when using Visual C++, includes {\tt wx.h}. This should help provide |
462 | the optimal compilation for each compiler, although it is | |
f6bcfd97 | 463 | biased towards the precompiled headers facility available |
a660d684 KB |
464 | in Microsoft C++. |
465 | ||
569ef72a | 466 | \section{File handling}\label{filehandling} |
a660d684 KB |
467 | |
468 | When building an application which may be used under different | |
469 | environments, one difficulty is coping with documents which may be | |
470 | moved to different directories on other machines. Saving a file which | |
471 | has pointers to full pathnames is going to be inherently unportable. One | |
472 | approach is to store filenames on their own, with no directory | |
473 | information. The application searches through a number of locally | |
474 | defined directories to find the file. To support this, the class {\bf | |
475 | wxPathList} makes adding directories and searching for files easy, and | |
62448488 | 476 | the global function {\bf wxFileNameFromPath} allows the application to |
a660d684 KB |
477 | strip off the filename from the path if the filename must be stored. |
478 | This has undesirable ramifications for people who have documents of the | |
479 | same name in different directories. | |
480 | ||
481 | As regards the limitations of DOS 8+3 single-case filenames versus | |
bd0df01f | 482 | unrestricted Unix filenames, the best solution is to use DOS filenames |
a660d684 KB |
483 | for your application, and also for document filenames {\it if} the user |
484 | is likely to be switching platforms regularly. Obviously this latter | |
485 | choice is up to the application user to decide. Some programs (such as | |
486 | YACC and LEX) generate filenames incompatible with DOS; the best | |
bd0df01f | 487 | solution here is to have your Unix makefile rename the generated files |
a660d684 | 488 | to something more compatible before transferring the source to DOS. |
bd0df01f | 489 | Transferring DOS files to Unix is no problem, of course, apart from EOL |
a660d684 KB |
490 | conversion for which there should be a utility available (such as |
491 | dos2unix). | |
492 | ||
493 | See also the File Functions section of the reference manual for | |
494 | descriptions of miscellaneous file handling functions. | |
495 | ||
fc2171bd | 496 | \chapter{Utilities and libraries supplied with wxWidgets}\label{utilities} |
a660d684 KB |
497 | \setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}% |
498 | \setfooter{\thepage}{}{}{}{}{\thepage}% | |
499 | ||
fc2171bd | 500 | In addition to the core wxWidgets library, a number of further |
bd330a69 | 501 | libraries and utilities are supplied with each distribution. |
a660d684 | 502 | |
bd330a69 | 503 | Some are under the 'contrib' hierarchy which mirrors the |
fc2171bd | 504 | structure of the main wxWidgets hierarchy. See also the 'utils' |
bd330a69 | 505 | hierarchy. The first place to look for documentation about |
fc2171bd | 506 | these tools and libraries is under the wxWidgets 'docs' hierarchy, |
7af3ca16 | 507 | for example {\tt docs/htmlhelp/fl.chm}. |
a660d684 | 508 | |
bd330a69 | 509 | For other user-contributed packages, please see the Contributions page |
fc2171bd | 510 | on the \urlref{wxWidgets Web site}{http://www.wxwidgets.org}. |
a660d684 | 511 | |
bd330a69 | 512 | \begin{description}\itemsep=0pt |
d8908b52 | 513 | \item[{\bf Helpview}] |
fc2171bd JS |
514 | Helpview is a program for displaying wxWidgets HTML |
515 | Help files. In many cases, you may wish to use the wxWidgets HTML | |
bd330a69 JS |
516 | Help classes from within your application, but this provides a |
517 | handy stand-alone viewer. See \helpref{wxHTML Notes}{wxhtml} for more details. | |
7af3ca16 | 518 | You can find it in {\tt samples/html/helpview}. |
d8908b52 | 519 | \item[{\bf Tex2RTF}] |
fc2171bd | 520 | Supplied with wxWidgets is a utility called Tex2RTF for converting\rtfsp |
bd330a69 | 521 | \LaTeX\ manuals HTML, MS HTML Help, wxHTML Help, RTF, and Windows |
fc2171bd | 522 | Help RTF formats. Tex2RTF is used for the wxWidgets manuals and can be used independently |
bd330a69 JS |
523 | by authors wishing to create on-line and printed manuals from the same\rtfsp |
524 | \LaTeX\ source. Please see the separate documentation for Tex2RTF. | |
7af3ca16 | 525 | You can find it under {\tt utils/tex2rtf}. |
d8908b52 | 526 | \item[{\bf Helpgen}] |
bd330a69 JS |
527 | Helpgen takes C++ header files and generates a Tex2RTF-compatible |
528 | documentation file for each class it finds, using comments as appropriate. | |
529 | This is a good way to start a reference for a set of classes. | |
31be2bd8 | 530 | Helpgen can be found in {\tt utils/HelpGen}. |
31be2bd8 JS |
531 | \item[{\bf Emulator}] |
532 | Xnest-based display emulator for X11-based PDA applications. On some | |
533 | systems, the Xnest window does not synchronise with the | |
534 | 'skin' window. This program can be found in {\tt utils/emulator}. | |
31be2bd8 | 535 | \item[{\bf Configuration Tool}] |
fc2171bd JS |
536 | The wxWidgets Configuration Tool is a work in progress |
537 | intended to make it easier to configure wxWidgets | |
31be2bd8 JS |
538 | features in detail. It exports setup.h configurations and will |
539 | eventually generate makefile config files. Invoking compilers is | |
540 | also on the cards. Since configurations are | |
541 | handled one at a time, the tool is of limited used until further | |
542 | development can be done. The program can be found in {\tt utils/configtool}. | |
d8908b52 | 543 | \item[{\bf XRC resource system}] |
965b4f87 | 544 | This is the sizer-aware resource system, and uses |
bd330a69 JS |
545 | XML-based resource specifications that can be generated by tools |
546 | such as \urlref{wxDesigner}{http://www.roebling.de} and XRC's own wxrcedit. | |
f6bb64a6 | 547 | You can find this in {\tt src/xrc}, {\tt include/wx/xrc}, {\tt samples/xrc}, and {\tt utils/wxrcedit}. |
bd330a69 | 548 | For more information, see the \helpref{XML-based resource system overview}{xrcoverview}. |
d8908b52 | 549 | \item[{\bf Object Graphics Library}] |
bd330a69 JS |
550 | OGL defines an API for applications that need to display objects connected by lines. |
551 | The objects can be moved around and interacted with. | |
7af3ca16 | 552 | You can find this in {\tt contrib/src/ogl}, {\tt contrib/include/wx/ogl}, and {\tt contrib/samples/ogl}. |
d8908b52 | 553 | \item[{\bf Frame Layout library}] |
bd330a69 | 554 | FL provides sophisticated pane dragging and docking facilities. |
7af3ca16 | 555 | You can find this in {\tt contrib/src/fl}, {\tt contrib/include/wx/fl}, and {\tt contrib/samples/fl}. |
d8908b52 | 556 | \item[{\bf Gizmos library}] |
bd330a69 JS |
557 | Gizmos is a collection of useful widgets and other classes. Classes include wxLEDNumberCtrl, |
558 | wxEditableListBox, wxMultiCellCanvas. | |
3b34ec62 | 559 | You can find this in {\tt contrib/src/gizmos}, {\tt contrib/include/wx/gizmos}, and {\tt contrib/samples/gizmos}. |
d8908b52 | 560 | \item[{\bf Net library}] |
bd330a69 JS |
561 | Net is a collection of very simple mail and web related classes. Currently |
562 | there is only wxEmail, which makes it easy to send email messages via MAPI on Windows or sendmail on Unix. | |
7af3ca16 | 563 | You can find this in {\tt contrib/src/net} and {\tt contrib/include/wx/net}. |
d8908b52 | 564 | \item[{\bf Animate library}] |
bd330a69 JS |
565 | Animate allows you to load animated GIFs and play them on a window. The library can be extended |
566 | to use other animation formats. | |
7af3ca16 | 567 | You can find this in {\tt contrib/src/animate}, {\tt contrib/include/wx/animate}, and {\tt contrib/samples/animate}. |
d8908b52 | 568 | \item[{\bf MMedia library}] |
bd330a69 | 569 | Mmedia supports a variety of multimedia functionality. The status of this library is currently unclear. |
7af3ca16 | 570 | You can find this in {\tt contrib/src/mmedia}, {\tt contrib/include/wx/mmedia}, and {\tt contrib/samples/mmedia}. |
d8908b52 | 571 | \item[{\bf Styled Text Control library}] |
bd330a69 | 572 | STC is a wrapper around Scintilla, a syntax-highlighting text editor. |
7af3ca16 | 573 | You can find this in {\tt contrib/src/stc}, {\tt contrib/include/wx/stc}, and {\tt contrib/samples/stc}. |
d8908b52 | 574 | \item[{\bf Plot}] |
bd330a69 | 575 | Plot is a simple curve plotting library. |
7af3ca16 | 576 | You can find this in {\tt contrib/src/plot}, {\tt contrib/include/wx/plot}, and {\tt contrib/samples/plot}. |
bd330a69 | 577 | \end{description} |
a660d684 KB |
578 | |
579 | \chapter{Programming strategies}\label{strategies} | |
580 | \setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}% | |
581 | \setfooter{\thepage}{}{}{}{}{\thepage}% | |
582 | ||
583 | This chapter is intended to list strategies that may be useful when | |
fc2171bd | 584 | writing and debugging wxWidgets programs. If you have any good tips, |
a660d684 KB |
585 | please submit them for inclusion here. |
586 | ||
569ef72a | 587 | \section{Strategies for reducing programming errors}\label{reducingerrors} |
a660d684 | 588 | |
a203f6c0 | 589 | \subsection{Use ASSERT}\label{useassert} |
a660d684 | 590 | |
fc2171bd | 591 | Although I haven't done this myself within wxWidgets, it is good |
a660d684 KB |
592 | practice to use ASSERT statements liberally, that check for conditions that |
593 | should or should not hold, and print out appropriate error messages. | |
fc2171bd | 594 | These can be compiled out of a non-debugging version of wxWidgets |
a660d684 KB |
595 | and your application. Using ASSERT is an example of `defensive programming': |
596 | it can alert you to problems later on. | |
597 | ||
a203f6c0 | 598 | \subsection{Use wxString in preference to character arrays}\label{usewxstring} |
a660d684 KB |
599 | |
600 | Using wxString can be much safer and more convenient than using char *. | |
f6bcfd97 | 601 | Again, I haven't practiced what I'm preaching, but I'm now trying to use |
a660d684 | 602 | wxString wherever possible. You can reduce the possibility of memory |
f6bcfd97 | 603 | leaks substantially, and it is much more convenient to use the overloaded |
a660d684 KB |
604 | operators than functions such as strcmp. wxString won't add a significant |
605 | overhead to your program; the overhead is compensated for by easier | |
606 | manipulation (which means less code). | |
607 | ||
608 | The same goes for other data types: use classes wherever possible. | |
609 | ||
569ef72a | 610 | \section{Strategies for portability}\label{portability} |
a660d684 | 611 | |
a203f6c0 | 612 | \subsection{Use relative positioning or constraints}\label{userelativepositioning} |
a660d684 KB |
613 | |
614 | Don't use absolute panel item positioning if you can avoid it. Different GUIs have | |
615 | very differently sized panel items. Consider using the constraint system, although this | |
8a2c6ef8 | 616 | can be complex to program. |
a660d684 | 617 | |
fc2171bd | 618 | Alternatively, you could use alternative .wrc (wxWidgets resource files) on different |
a660d684 KB |
619 | platforms, with slightly different dimensions in each. Or space your panel items out |
620 | to avoid problems. | |
621 | ||
a203f6c0 | 622 | \subsection{Use wxWidgets resource files}\label{useresources} |
a660d684 | 623 | |
fc2171bd | 624 | Use .xrc (wxWidgets resource files) where possible, because they can be easily changed |
965b4f87 | 625 | independently of source code. |
a660d684 | 626 | |
6b037754 | 627 | \section{Strategies for debugging}\label{debugstrategies} |
a660d684 | 628 | |
a203f6c0 | 629 | \subsection{Positive thinking}\label{positivethinking} |
a660d684 | 630 | |
f6bcfd97 | 631 | It is common to blow up the problem in one's imagination, so that it seems to threaten |
a660d684 KB |
632 | weeks, months or even years of work. The problem you face may seem insurmountable: |
633 | but almost never is. Once you have been programming for some time, you will be able | |
634 | to remember similar incidents that threw you into the depths of despair. But | |
635 | remember, you always solved the problem, somehow! | |
636 | ||
637 | Perseverance is often the key, even though a seemingly trivial problem | |
638 | can take an apparently inordinate amount of time to solve. In the end, | |
639 | you will probably wonder why you worried so much. That's not to say it | |
640 | isn't painful at the time. Try not to worry -- there are many more important | |
641 | things in life. | |
642 | ||
a203f6c0 | 643 | \subsection{Simplify the problem}\label{simplifyproblem} |
a660d684 KB |
644 | |
645 | Reduce the code exhibiting the problem to the smallest program possible | |
646 | that exhibits the problem. If it is not possible to reduce a large and | |
647 | complex program to a very small program, then try to ensure your code | |
648 | doesn't hide the problem (you may have attempted to minimize the problem | |
649 | in some way: but now you want to expose it). | |
650 | ||
651 | With luck, you can add a small amount of code that causes the program | |
652 | to go from functioning to non-functioning state. This should give a clue | |
653 | to the problem. In some cases though, such as memory leaks or wrong | |
654 | deallocation, this can still give totally spurious results! | |
655 | ||
a203f6c0 | 656 | \subsection{Use a debugger}\label{usedebugger} |
a660d684 | 657 | |
f6bcfd97 BP |
658 | This sounds like facetious advice, but it is surprising how often people |
659 | don't use a debugger. Often it is an overhead to install or learn how to | |
a660d684 | 660 | use a debugger, but it really is essential for anything but the most |
6b037754 JS |
661 | trivial programs. |
662 | ||
a203f6c0 | 663 | \subsection{Use logging functions}\label{uselogging} |
6b037754 JS |
664 | |
665 | There is a variety of logging functions that you can use in your program: | |
666 | see \helpref{Logging functions}{logfunctions}. | |
a660d684 KB |
667 | |
668 | Using tracing statements may be more convenient than using the debugger | |
669 | in some circumstances (such as when your debugger doesn't support a lot | |
670 | of debugging code, or you wish to print a bunch of variables). | |
671 | ||
a203f6c0 | 672 | \subsection{Use the wxWidgets debugging facilities}\label{usedebuggingfacilities} |
6b037754 JS |
673 | |
674 | You can use wxDebugContext to check for | |
fc2171bd JS |
675 | memory leaks and corrupt memory: in fact in debugging mode, wxWidgets will |
676 | automatically check for memory leaks at the end of the program if wxWidgets is suitably | |
6b037754 JS |
677 | configured. Depending on the operating system and compiler, more or less |
678 | specific information about the problem will be logged. | |
a660d684 | 679 | |
6b037754 JS |
680 | You should also use \helpref{debug macros}{debugmacros} as part of a `defensive programming' strategy, |
681 | scattering wxASSERTs liberally to test for problems in your code as early as possible. Forward thinking | |
682 | will save a surprising amount of time in the long run. | |
683 | ||
684 | See the \helpref{debugging overview}{debuggingoverview} for further information. | |
a660d684 | 685 |