]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/devtips.h
added wxWidgets samples
[wxWidgets.git] / docs / doxygen / devtips.h
CommitLineData
15b6757b
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: devtips.h
3// Purpose: Cross-platform development page of the Doxygen manual
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9
10/*!
11
12 @page multiplatform_page Multi-platform development with wxWidgets
13
14 This chapter describes the practical details of using wxWidgets. Please
15 see the file install.txt for up-to-date installation instructions, and
16 changes.txt for differences between versions.
17
18 @li @ref includefiles
19 @li @ref libraries
20 @li @ref configuration
21 @li @ref makefiles
22 @li @ref windowsfiles
23 @li @ref allocatingobjects
24 @li @ref architecturedependency
25 @li @ref conditionalcompilation
26 @li @ref cpp
27 @li @ref filehandling
28
29 <hr>
30
36c9828f 31
15b6757b 32 @section includefiles Include files
36c9828f 33
25c4a27c 34 The main include file is @c "wx/wx.h"; this includes the most commonly
15b6757b 35 used modules of wxWidgets.
36c9828f 36
15b6757b
FM
37 To save on compilation time, include only those header files relevant to the
38 source file. If you are using precompiled headers, you should include
39 the following section before any other includes:
36c9828f 40
15b6757b
FM
41 @verbatim
42 // For compilers that support precompilation, includes "wx.h".
43 #include <wx/wxprec.h>
36c9828f 44
15b6757b
FM
45 #ifdef __BORLANDC__
46 #pragma hdrstop
47 #endif
36c9828f 48
15b6757b
FM
49 #ifndef WX_PRECOMP
50 // Include your minimal set of headers here, or wx.h
51 #include <wx/wx.h>
52 #endif
36c9828f 53
15b6757b
FM
54 ... now your other include files ...
55 @endverbatim
36c9828f 56
25c4a27c 57 The file @c "wx/wxprec.h" includes @c "wx/wx.h". Although this incantation
15b6757b
FM
58 may seem quirky, it is in fact the end result of a lot of experimentation,
59 and several Windows compilers to use precompilation which is largely automatic for
60 compilers with necessary support. Currently it is used for Visual C++ (including
61 embedded Visual C++), Borland C++, Open Watcom C++, Digital Mars C++
62 and newer versions of GCC.
63 Some compilers might need extra work from the application developer to set the
64 build environment up as necessary for the support.
36c9828f 65
15b6757b
FM
66
67
68 @section libraries Libraries
36c9828f 69
15b6757b
FM
70 Most ports of wxWidgets can create either a static library or a shared
71 library. wxWidgets can also be built in multilib and monolithic variants.
a3465294 72 See the @ref libraries_page for more information on these.
36c9828f 73
15b6757b
FM
74
75
76 @section configuration Configuration
36c9828f 77
15b6757b
FM
78 When using project files and makefiles directly to build wxWidgets,
79 options are configurable in the file
25c4a27c 80 @c "wx/XXX/setup.h" where XXX is the required platform (such as msw, motif, gtk, mac). Some
15b6757b
FM
81 settings are a matter of taste, some help with platform-specific problems, and
82 others can be set to minimize the size of the library. Please see the setup.h file
25c4a27c 83 and @c install.txt files for details on configuration.
36c9828f 84
15b6757b
FM
85 When using the 'configure' script to configure wxWidgets (on Unix and other platforms where
86 configure is available), the corresponding setup.h files are generated automatically
87 along with suitable makefiles. When using the RPM packages
88 for installing wxWidgets on Linux, a correct setup.h is shipped in the package and
89 this must not be changed.
36c9828f 90
15b6757b
FM
91
92
93 @section makefiles Makefiles
36c9828f 94
15b6757b
FM
95 On Microsoft Windows, wxWidgets has a different set of makefiles for each
96 compiler, because each compiler's 'make' tool is slightly different.
97 Popular Windows compilers that we cater for, and the corresponding makefile
98 extensions, include: Microsoft Visual C++ (.vc), Borland C++ (.bcc),
99 OpenWatcom C++ (.wat) and MinGW/Cygwin (.gcc). Makefiles are provided
100 for the wxWidgets library itself, samples, demos, and utilities.
36c9828f 101
15b6757b
FM
102 On Linux, Mac and OS/2, you use the 'configure' command to
103 generate the necessary makefiles. You should also use this method when
104 building with MinGW/Cygwin on Windows.
36c9828f 105
15b6757b
FM
106 We also provide project files for some compilers, such as
107 Microsoft VC++. However, we recommend using makefiles
108 to build the wxWidgets library itself, because makefiles
109 can be more powerful and less manual intervention is required.
36c9828f 110
15b6757b
FM
111 On Windows using a compiler other than MinGW/Cygwin, you would
112 build the wxWidgets library from the build/msw directory
113 which contains the relevant makefiles.
36c9828f 114
15b6757b
FM
115 On Windows using MinGW/Cygwin, and on Unix, MacOS X and OS/2, you invoke
116 'configure' (found in the top-level of the wxWidgets source hierarchy),
117 from within a suitable empty directory for containing makefiles, object files and
118 libraries.
36c9828f 119
15b6757b
FM
120 For details on using makefiles, configure, and project files,
121 please see docs/xxx/install.txt in your distribution, where
122 xxx is the platform of interest, such as msw, gtk, x11, mac.
36c9828f 123
15b6757b
FM
124
125
126 @section windowsfiles Windows-specific files
36c9828f 127
15b6757b
FM
128 wxWidgets application compilation under MS Windows requires at least one
129 extra file: a resource file.
36c9828f 130
15b6757b 131 @subsection resources Resource file
36c9828f 132
15b6757b
FM
133 The least that must be defined in the Windows resource file (extension RC)
134 is the following statement:
36c9828f 135
15b6757b
FM
136 @verbatim
137 #include "wx/msw/wx.rc"
138 @endverbatim
36c9828f 139
15b6757b
FM
140 which includes essential internal wxWidgets definitions. The resource script
141 may also contain references to icons, cursors, etc., for example:
36c9828f 142
15b6757b
FM
143 @verbatim
144 wxicon icon wx.ico
145 @endverbatim
36c9828f 146
15b6757b
FM
147 The icon can then be referenced by name when creating a frame icon. See
148 the MS Windows SDK documentation.
36c9828f 149
25c4a27c
FM
150 @note include wx.rc @e after any ICON statements
151 so programs that search your executable for icons (such
152 as the Program Manager) find your application icon first.
36c9828f 153
15b6757b
FM
154
155
156 @section allocatingobjects Allocating and deleting wxWidgets objects
36c9828f 157
15b6757b 158 In general, classes derived from wxWindow must dynamically allocated
25c4a27c 159 with @e new and deleted with @e delete. If you delete a window,
15b6757b
FM
160 all of its children and descendants will be automatically deleted,
161 so you don't need to delete these descendants explicitly.
36c9828f 162
25c4a27c 163 When deleting a frame or dialog, use @b Destroy rather than @b delete so
15b6757b
FM
164 that the wxWidgets delayed deletion can take effect. This waits until idle time
165 (when all messages have been processed) to actually delete the window, to avoid
166 problems associated with the GUI sending events to deleted windows.
36c9828f 167
15b6757b
FM
168 Don't create a window on the stack, because this will interfere
169 with delayed deletion.
36c9828f 170
15b6757b
FM
171 If you decide to allocate a C++ array of objects (such as wxBitmap) that may
172 be cleaned up by wxWidgets, make sure you delete the array explicitly
25c4a27c 173 before wxWidgets has a chance to do so on exit, since calling @e delete on
15b6757b 174 array members will cause memory problems.
36c9828f 175
15b6757b
FM
176 wxColour can be created statically: it is not automatically cleaned
177 up and is unlikely to be shared between other objects; it is lightweight
178 enough for copies to be made.
36c9828f 179
15b6757b
FM
180 Beware of deleting objects such as a wxPen or wxBitmap if they are still in use.
181 Windows is particularly sensitive to this: so make sure you
182 make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deleting
183 a drawing object that may be in use. Code that doesn't do this will probably work
184 fine on some platforms, and then fail under Windows.
36c9828f 185
15b6757b
FM
186
187
188 @section architecturedependency Architecture dependency
36c9828f 189
15b6757b
FM
190 A problem which sometimes arises from writing multi-platform programs is that
191 the basic C types are not defined the same on all platforms. This holds true
36c9828f 192 for both the length in bits of the standard types (such as int and long) as
15b6757b
FM
193 well as their byte order, which might be little endian (typically
194 on Intel computers) or big endian (typically on some Unix workstations). wxWidgets
195 defines types and macros that make it easy to write architecture independent
196 code. The types are:
36c9828f 197
15b6757b 198 wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte
36c9828f 199
15b6757b 200 where wxInt32 stands for a 32-bit signed integer type etc. You can also check
a3465294
FM
201 which architecture the program is compiled on using the wxBYTE_ORDER define
202 which is either wxBIG_ENDIAN or wxLITTLE_ENDIAN (in the future maybe wxPDP_ENDIAN
15b6757b 203 as well).
36c9828f 204
15b6757b 205 The macros handling bit-swapping with respect to the applications endianness
25c4a27c 206 are described in the @ref byteordermacros section.
36c9828f 207
15b6757b
FM
208
209
210 @section conditionalcompilation Conditional compilation
36c9828f 211
15b6757b
FM
212 One of the purposes of wxWidgets is to reduce the need for conditional
213 compilation in source code, which can be messy and confusing to follow.
214 However, sometimes it is necessary to incorporate platform-specific
25c4a27c
FM
215 features (such as metafile use under MS Windows). The @ref wxusedef
216 symbols listed in the file @c setup.h may be used for this purpose,
15b6757b 217 along with any user-supplied ones.
36c9828f 218
15b6757b
FM
219
220
221 @section cpp C++ issues
36c9828f 222
15b6757b 223 The following documents some miscellaneous C++ issues.
36c9828f 224
15b6757b 225 @subsection templates Templates
36c9828f 226
15b6757b
FM
227 wxWidgets does not use templates (except for some advanced features that
228 are switched off by default) since it is a notoriously unportable feature.
36c9828f 229
15b6757b 230 @subsection rtti RTTI
36c9828f 231
15b6757b
FM
232 wxWidgets does not use C++ run-time type information since wxWidgets provides
233 its own run-time type information system, implemented using macros.
36c9828f 234
15b6757b 235 @subsection null Type of NULL
36c9828f 236
15b6757b
FM
237 Some compilers (e.g. the native IRIX cc) define NULL to be 0L so that
238 no conversion to pointers is allowed. Because of that, all these
36c9828f 239 occurrences of NULL in the GTK+ port use an explicit conversion such
15b6757b 240 as
36c9828f 241
25c4a27c 242 @code
15b6757b 243 wxWindow *my_window = (wxWindow*) NULL;
25c4a27c 244 @endcode
36c9828f 245
15b6757b
FM
246 It is recommended to adhere to this in all code using wxWidgets as
247 this make the code (a bit) more portable.
36c9828f 248
15b6757b 249 @subsection precompiledheaders Precompiled headers
36c9828f 250
15b6757b
FM
251 Some compilers, such as Borland C++ and Microsoft C++, support
252 precompiled headers. This can save a great deal of compiling time. The
25c4a27c 253 recommended approach is to precompile @c "wx.h", using this
15b6757b
FM
254 precompiled header for compiling both wxWidgets itself and any
255 wxWidgets applications. For Windows compilers, two dummy source files
256 are provided (one for normal applications and one for creating DLLs)
257 to allow initial creation of the precompiled header.
36c9828f 258
15b6757b
FM
259 However, there are several downsides to using precompiled headers. One
260 is that to take advantage of the facility, you often need to include
261 more header files than would normally be the case. This means that
262 changing a header file will cause more recompilations (in the case of
25c4a27c 263 wxWidgets, everything needs to be recompiled since everything includes @c "wx.h" !)
36c9828f 264
15b6757b
FM
265 A related problem is that for compilers that don't have precompiled
266 headers, including a lot of header files slows down compilation
267 considerably. For this reason, you will find (in the common
268 X and Windows parts of the library) conditional
269 compilation that under Unix, includes a minimal set of headers;
25c4a27c 270 and when using Visual C++, includes @c wx.h. This should help provide
15b6757b
FM
271 the optimal compilation for each compiler, although it is
272 biased towards the precompiled headers facility available
273 in Microsoft C++.
36c9828f 274
15b6757b
FM
275
276
277 @section filehandling File handling
36c9828f 278
15b6757b
FM
279 When building an application which may be used under different
280 environments, one difficulty is coping with documents which may be
281 moved to different directories on other machines. Saving a file which
282 has pointers to full pathnames is going to be inherently unportable.
36c9828f 283
15b6757b
FM
284 One approach is to store filenames on their own, with no directory
285 information. The application then searches into a list of standard
25c4a27c 286 paths (platform-specific) through the use of wxStandardPaths.
36c9828f 287
25c4a27c 288 Eventually you may want to use also the wxPathList class.
36c9828f 289
15b6757b
FM
290 Nowadays the limitations of DOS 8+3 filenames doesn't apply anymore.
291 Most modern operating systems allow at least 255 characters in the filename;
36c9828f 292 the exact maximum length, as well as the characters allowed in the filenames,
15b6757b
FM
293 are OS-specific so you should try to avoid extremely long (> 255 chars) filenames
294 and/or filenames with non-ANSI characters.
36c9828f 295
15b6757b
FM
296 Another thing you need to keep in mind is that all Windows operating systems
297 are case-insensitive, while Unix operating systems (Linux, Mac, etc) are
298 case-sensitive.
36c9828f 299
15b6757b
FM
300 Also, for text files, different OSes use different End Of Lines (EOL).
301 Windows uses CR+LF convention, Linux uses LF only, Mac CR only.
36c9828f 302
25c4a27c 303 The wxTextFile, wxTextInputStream, wxTextOutputStream classes help to abstract
15b6757b 304 from these differences.
25c4a27c 305 Of course, there are also 3rd party utilities such as @c dos2unix and @c unix2dos
15b6757b 306 which do the EOL conversions.
36c9828f 307
25c4a27c 308 See also the @ref filefunctions section of the reference
15b6757b 309 manual for the description of miscellaneous file handling functions.
36c9828f 310
15b6757b 311*/