]> git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/devtips.h
added wxWidgets samples
[wxWidgets.git] / docs / doxygen / devtips.h
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
31
32 @section includefiles Include files
33
34 The main include file is @c "wx/wx.h"; this includes the most commonly
35 used modules of wxWidgets.
36
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:
40
41 @verbatim
42 // For compilers that support precompilation, includes "wx.h".
43 #include <wx/wxprec.h>
44
45 #ifdef __BORLANDC__
46 #pragma hdrstop
47 #endif
48
49 #ifndef WX_PRECOMP
50 // Include your minimal set of headers here, or wx.h
51 #include <wx/wx.h>
52 #endif
53
54 ... now your other include files ...
55 @endverbatim
56
57 The file @c "wx/wxprec.h" includes @c "wx/wx.h". Although this incantation
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.
65
66
67
68 @section libraries Libraries
69
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.
72 See the @ref libraries_page for more information on these.
73
74
75
76 @section configuration Configuration
77
78 When using project files and makefiles directly to build wxWidgets,
79 options are configurable in the file
80 @c "wx/XXX/setup.h" where XXX is the required platform (such as msw, motif, gtk, mac). Some
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
83 and @c install.txt files for details on configuration.
84
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.
90
91
92
93 @section makefiles Makefiles
94
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.
101
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.
105
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.
110
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.
114
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.
119
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.
123
124
125
126 @section windowsfiles Windows-specific files
127
128 wxWidgets application compilation under MS Windows requires at least one
129 extra file: a resource file.
130
131 @subsection resources Resource file
132
133 The least that must be defined in the Windows resource file (extension RC)
134 is the following statement:
135
136 @verbatim
137 #include "wx/msw/wx.rc"
138 @endverbatim
139
140 which includes essential internal wxWidgets definitions. The resource script
141 may also contain references to icons, cursors, etc., for example:
142
143 @verbatim
144 wxicon icon wx.ico
145 @endverbatim
146
147 The icon can then be referenced by name when creating a frame icon. See
148 the MS Windows SDK documentation.
149
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.
153
154
155
156 @section allocatingobjects Allocating and deleting wxWidgets objects
157
158 In general, classes derived from wxWindow must dynamically allocated
159 with @e new and deleted with @e delete. If you delete a window,
160 all of its children and descendants will be automatically deleted,
161 so you don't need to delete these descendants explicitly.
162
163 When deleting a frame or dialog, use @b Destroy rather than @b delete so
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.
167
168 Don't create a window on the stack, because this will interfere
169 with delayed deletion.
170
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
173 before wxWidgets has a chance to do so on exit, since calling @e delete on
174 array members will cause memory problems.
175
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.
179
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.
185
186
187
188 @section architecturedependency Architecture dependency
189
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
192 for both the length in bits of the standard types (such as int and long) as
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:
197
198 wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte
199
200 where wxInt32 stands for a 32-bit signed integer type etc. You can also check
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
203 as well).
204
205 The macros handling bit-swapping with respect to the applications endianness
206 are described in the @ref byteordermacros section.
207
208
209
210 @section conditionalcompilation Conditional compilation
211
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
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,
217 along with any user-supplied ones.
218
219
220
221 @section cpp C++ issues
222
223 The following documents some miscellaneous C++ issues.
224
225 @subsection templates Templates
226
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.
229
230 @subsection rtti RTTI
231
232 wxWidgets does not use C++ run-time type information since wxWidgets provides
233 its own run-time type information system, implemented using macros.
234
235 @subsection null Type of NULL
236
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
239 occurrences of NULL in the GTK+ port use an explicit conversion such
240 as
241
242 @code
243 wxWindow *my_window = (wxWindow*) NULL;
244 @endcode
245
246 It is recommended to adhere to this in all code using wxWidgets as
247 this make the code (a bit) more portable.
248
249 @subsection precompiledheaders Precompiled headers
250
251 Some compilers, such as Borland C++ and Microsoft C++, support
252 precompiled headers. This can save a great deal of compiling time. The
253 recommended approach is to precompile @c "wx.h", using this
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.
258
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
263 wxWidgets, everything needs to be recompiled since everything includes @c "wx.h" !)
264
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;
270 and when using Visual C++, includes @c wx.h. This should help provide
271 the optimal compilation for each compiler, although it is
272 biased towards the precompiled headers facility available
273 in Microsoft C++.
274
275
276
277 @section filehandling File handling
278
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.
283
284 One approach is to store filenames on their own, with no directory
285 information. The application then searches into a list of standard
286 paths (platform-specific) through the use of wxStandardPaths.
287
288 Eventually you may want to use also the wxPathList class.
289
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;
292 the exact maximum length, as well as the characters allowed in the filenames,
293 are OS-specific so you should try to avoid extremely long (> 255 chars) filenames
294 and/or filenames with non-ANSI characters.
295
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.
299
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.
302
303 The wxTextFile, wxTextInputStream, wxTextOutputStream classes help to abstract
304 from these differences.
305 Of course, there are also 3rd party utilities such as @c dos2unix and @c unix2dos
306 which do the EOL conversions.
307
308 See also the @ref filefunctions section of the reference
309 manual for the description of miscellaneous file handling functions.
310
311 */