2008-02-21 16:11:25 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: devtips.h
|
|
|
|
// Purpose: Cross-platform development page of the Doxygen manual
|
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-02-21 16:11:25 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-03-12 04:50:42 -04:00
|
|
|
/**
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2013-11-12 13:06:37 -05:00
|
|
|
@page page_multiplatform Cross-Platform Development Tips
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2012-11-03 14:29:28 -04:00
|
|
|
@tableofcontents
|
|
|
|
|
2013-11-12 13:06:37 -05:00
|
|
|
This chapter describes some general tips related to cross-platform development.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_includefiles Include Files
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
The main include file is @c "wx/wx.h"; this includes the most commonly used
|
|
|
|
modules of wxWidgets.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
To save on compilation time, include only those header files relevant to the
|
2008-04-02 01:29:12 -04:00
|
|
|
source file. If you are using @b precompiled headers, you should include the
|
|
|
|
following section before any other includes:
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@verbatim
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include <wx/wxprec.h>
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
#ifdef __BORLANDC__
|
2008-04-02 01:29:12 -04:00
|
|
|
# pragma hdrstop
|
2008-03-22 13:49:09 -04:00
|
|
|
#endif
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
#ifndef WX_PRECOMP
|
2008-04-02 01:29:12 -04:00
|
|
|
// Include your minimal set of headers here, or wx.h
|
|
|
|
# include <wx/wx.h>
|
2008-03-22 13:49:09 -04:00
|
|
|
#endif
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
... now your other include files ...
|
|
|
|
@endverbatim
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
The file @c "wx/wxprec.h" includes @c "wx/wx.h". Although this incantation may
|
|
|
|
seem quirky, it is in fact the end result of a lot of experimentation, and
|
|
|
|
several Windows compilers to use precompilation which is largely automatic for
|
|
|
|
compilers with necessary support. Currently it is used for Visual C++
|
2014-05-16 09:01:23 -04:00
|
|
|
(including embedded Visual C++), Borland C++ and newer versions of GCC. Some
|
|
|
|
compilers might need extra work from the application developer to set the build
|
|
|
|
environment up as necessary for the support.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@section page_multiplatform_libraries Libraries
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
All ports of wxWidgets can create either a @b static library or a @b shared
|
|
|
|
library.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
When a program is linked against a @e static library, the machine code from the
|
|
|
|
object files for any external functions used by the program is copied from the
|
|
|
|
library into the final executable.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@e Shared libraries are handled with a more advanced form of linking, which
|
|
|
|
makes the executable file smaller. They use the extension @c ".so" (Shared
|
|
|
|
Object) under Linux and @c ".dll" (Dynamic Link Library) under Windows.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
An executable file linked against a shared library contains only a small table
|
|
|
|
of the functions it requires, instead of the complete machine code from the
|
|
|
|
object files for the external functions. Before the executable file starts
|
|
|
|
running, the machine code for the external functions is copied into memory from
|
|
|
|
the shared library file on disk by the operating system - a process referred to
|
|
|
|
as @e dynamic linking.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Dynamic linking makes executable files smaller and saves disk space, because
|
|
|
|
one copy of a library can be shared between multiple programs. Most operating
|
|
|
|
systems also provide a virtual memory mechanism which allows one copy of a
|
|
|
|
shared library in physical memory to be used by all running programs, saving
|
2008-03-31 09:27:33 -04:00
|
|
|
memory as well as disk space.
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Furthermore, shared libraries make it possible to update a library without
|
|
|
|
recompiling the programs which use it (provided the interface to the library
|
|
|
|
does not change).
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
wxWidgets can also be built in @b multilib and @b monolithic variants. See the
|
|
|
|
@ref page_libs for more information on these.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@section page_multiplatform_configuration Configuration
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
When using project files and makefiles directly to build wxWidgets, options are
|
|
|
|
configurable in the file @c "wx/XXX/setup.h" where XXX is the required
|
|
|
|
platform (such as @c msw, @c motif, @c gtk, @c mac).
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Some settings are a matter of taste, some help with platform-specific problems,
|
|
|
|
and others can be set to minimize the size of the library. Please see the
|
|
|
|
@c "setup.h" file and @c "install.txt" files for details on configuration.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
When using the @c "configure" script to configure wxWidgets (on Unix and other
|
|
|
|
platforms where configure is available), the corresponding @c "setup.h" files
|
|
|
|
are generated automatically along with suitable makefiles.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
When using the RPM packages (or DEB or other forms of @e binaries) for
|
|
|
|
installing wxWidgets on Linux, a correct @c "setup.h" is shipped in the package
|
|
|
|
and this must not be changed.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@section page_multiplatform_makefiles Makefiles
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
On Microsoft Windows, wxWidgets has a different set of makefiles for each
|
2008-04-02 01:29:12 -04:00
|
|
|
compiler, because each compiler's @c 'make' tool is slightly different. Popular
|
|
|
|
Windows compilers that we cater for, and the corresponding makefile extensions,
|
2014-05-16 09:01:06 -04:00
|
|
|
include: Microsoft Visual C++ (.vc), Borland C++ (.bcc) and MinGW/Cygwin
|
|
|
|
(.gcc). Makefiles are provided for the wxWidgets library itself, samples,
|
|
|
|
demos, and utilities.
|
2008-04-02 01:29:12 -04:00
|
|
|
|
|
|
|
On Linux, Mac and OS/2, you use the @c 'configure' command to generate the
|
|
|
|
necessary makefiles. You should also use this method when building with
|
2008-03-31 09:27:33 -04:00
|
|
|
MinGW/Cygwin on Windows.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
We also provide project files for some compilers, such as Microsoft VC++.
|
|
|
|
However, we recommend using makefiles to build the wxWidgets library itself,
|
|
|
|
because makefiles can be more powerful and less manual intervention is
|
|
|
|
required.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
On Windows using a compiler other than MinGW/Cygwin, you would build the
|
|
|
|
wxWidgets library from the @c "build/msw" directory which contains the relevant
|
|
|
|
makefiles.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2013-11-12 13:06:37 -05:00
|
|
|
On Windows using MinGW/Cygwin, and on Unix, OS X and OS/2, you invoke
|
2008-04-02 01:29:12 -04:00
|
|
|
'configure' (found in the top-level of the wxWidgets source hierarchy), from
|
|
|
|
within a suitable empty directory for containing makefiles, object files and
|
|
|
|
libraries.
|
|
|
|
|
|
|
|
For details on using makefiles, configure, and project files, please see
|
|
|
|
@c "docs/xxx/install.txt" in your distribution, where @c "xxx" is the platform
|
|
|
|
of interest, such as @c msw, @c gtk, @c x11, @c mac.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-19 04:12:58 -04:00
|
|
|
All wxWidgets makefiles are generated using Bakefile <http://www.bakefile.org/>.
|
|
|
|
wxWidgets also provides (in the @c "build/bakefiles/wxpresets" folder) the
|
|
|
|
wxWidgets bakefile presets. These files allow you to create bakefiles for your
|
|
|
|
own wxWidgets-based applications very easily.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_winresources Windows Resource Files
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
wxWidgets application compilation under MS Windows requires at least one extra
|
|
|
|
file: a resource file.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
The least that must be defined in the Windows resource file (extension RC) is
|
|
|
|
the following statement:
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@verbatim
|
|
|
|
#include "wx/msw/wx.rc"
|
|
|
|
@endverbatim
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
which includes essential internal wxWidgets definitions. The resource script
|
|
|
|
may also contain references to icons, cursors, etc., for example:
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@verbatim
|
|
|
|
wxicon icon wx.ico
|
|
|
|
@endverbatim
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
The icon can then be referenced by name when creating a frame icon. See the
|
|
|
|
Microsoft Windows SDK documentation.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@note Include "wx.rc" @e after any ICON statements so programs that search your
|
|
|
|
executable for icons (such as the Program Manager) find your application
|
|
|
|
icon first.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_allocatingobjects Allocating and Deleting wxWidgets Objects
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
In general, classes derived from wxWindow must dynamically allocated with
|
|
|
|
@e new and deleted with @e delete. If you delete a window, all of its children
|
|
|
|
and descendants will be automatically deleted, so you don't need to delete
|
|
|
|
these descendants explicitly.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
When deleting a frame or dialog, use @b Destroy rather than @b delete so that
|
|
|
|
the wxWidgets delayed deletion can take effect. This waits until idle time
|
2008-03-22 13:49:09 -04:00
|
|
|
(when all messages have been processed) to actually delete the window, to avoid
|
|
|
|
problems associated with the GUI sending events to deleted windows.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2011-01-19 05:46:31 -05:00
|
|
|
In general wxWindow-derived objects should always be allocated on the heap
|
|
|
|
as wxWidgets will destroy them itself. The only, but important, exception to
|
|
|
|
this rule are the modal dialogs, i.e. wxDialog objects which are shown using
|
|
|
|
wxDialog::ShowModal() method. They may be allocated on the stack and, indeed,
|
|
|
|
usually are local variables to ensure that they are destroyed on scope exit as
|
|
|
|
wxWidgets does not destroy them unlike with all the other windows. So while it
|
|
|
|
is still possible to allocate modal dialogs on the heap, you should still
|
|
|
|
destroy or delete them explicitly in this case instead of relying on wxWidgets
|
|
|
|
doing it.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
If you decide to allocate a C++ array of objects (such as wxBitmap) that may be
|
|
|
|
cleaned up by wxWidgets, make sure you delete the array explicitly before
|
|
|
|
wxWidgets has a chance to do so on exit, since calling @e delete on array
|
|
|
|
members will cause memory problems.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
wxColour can be created statically: it is not automatically cleaned
|
|
|
|
up and is unlikely to be shared between other objects; it is lightweight
|
|
|
|
enough for copies to be made.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Beware of deleting objects such as a wxPen or wxBitmap if they are still in
|
|
|
|
use. Windows is particularly sensitive to this, so make sure you make calls
|
|
|
|
like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before
|
|
|
|
deleting a drawing object that may be in use. Code that doesn't do this will
|
|
|
|
probably work fine on some platforms, and then fail under Windows.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_architecturedependency Architecture Dependency
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
A problem which sometimes arises from writing multi-platform programs is that
|
|
|
|
the basic C types are not defined the same on all platforms. This holds true
|
|
|
|
for both the length in bits of the standard types (such as int and long) as
|
2008-04-02 01:29:12 -04:00
|
|
|
well as their byte order, which might be little endian (typically on Intel
|
|
|
|
computers) or big endian (typically on some Unix workstations). wxWidgets
|
2008-03-22 13:49:09 -04:00
|
|
|
defines types and macros that make it easy to write architecture independent
|
|
|
|
code. The types are:
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
where wxInt32 stands for a 32-bit signed integer type etc. You can also check
|
|
|
|
which architecture the program is compiled on using the wxBYTE_ORDER define
|
2008-04-02 01:29:12 -04:00
|
|
|
which is either wxBIG_ENDIAN or wxLITTLE_ENDIAN (in the future maybe
|
|
|
|
wxPDP_ENDIAN as well).
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
The macros handling bit-swapping with respect to the applications endianness
|
2008-03-25 03:57:30 -04:00
|
|
|
are described in the @ref group_funcmacro_byteorder section.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_conditionalcompilation Conditional Compilation
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
One of the purposes of wxWidgets is to reduce the need for conditional
|
|
|
|
compilation in source code, which can be messy and confusing to follow.
|
2008-04-02 01:29:12 -04:00
|
|
|
However, sometimes it is necessary to incorporate platform-specific features
|
|
|
|
(such as metafile use under MS Windows). The @ref page_wxusedef symbols listed
|
|
|
|
in the file @c setup.h may be used for this purpose, along with any
|
|
|
|
user-supplied ones.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_cpp C++ Issues
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
The following documents some miscellaneous C++ issues.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
@subsection page_multiplatform_cpp_templates Templates
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
wxWidgets does not use templates (except for some advanced features that are
|
|
|
|
switched off by default) since it is a notoriously unportable feature.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_cpp_rtti Runtime Type Information (RTTI)
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
wxWidgets does not use C++ run-time type information since wxWidgets provides
|
|
|
|
its own run-time type information system, implemented using macros.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_cpp_precompiledheaders Precompiled Headers
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Some compilers, such as Borland C++ and Microsoft C++, support precompiled
|
|
|
|
headers. This can save a great deal of compiling time. The recommended approach
|
|
|
|
is to precompile @c "wx.h", using this precompiled header for compiling both
|
|
|
|
wxWidgets itself and any wxWidgets applications. For Windows compilers, two
|
|
|
|
dummy source files are provided (one for normal applications and one for
|
|
|
|
creating DLLs) to allow initial creation of the precompiled header.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
However, there are several downsides to using precompiled headers. One is that
|
|
|
|
to take advantage of the facility, you often need to include more header files
|
|
|
|
than would normally be the case. This means that changing a header file will
|
|
|
|
cause more recompilations (in the case of wxWidgets, everything needs to be
|
|
|
|
recompiled since everything includes @c "wx.h").
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
A related problem is that for compilers that don't have precompiled headers,
|
|
|
|
including a lot of header files slows down compilation considerably. For this
|
|
|
|
reason, you will find (in the common X and Windows parts of the library)
|
|
|
|
conditional compilation that under Unix, includes a minimal set of headers; and
|
|
|
|
when using Visual C++, includes @c "wx.h". This should help provide the optimal
|
|
|
|
compilation for each compiler, although it is biased towards the precompiled
|
|
|
|
headers facility available in Microsoft C++.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_filehandling File Handling
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
When building an application which may be used under different environments,
|
|
|
|
one difficulty is coping with documents which may be moved to different
|
|
|
|
directories on other machines. Saving a file which has pointers to full
|
|
|
|
pathnames is going to be inherently unportable.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
One approach is to store filenames on their own, with no directory information.
|
|
|
|
The application then searches into a list of standard paths (platform-specific)
|
|
|
|
through the use of wxStandardPaths.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
Eventually you may want to use also the wxPathList class.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Nowadays the limitations of DOS 8+3 filenames doesn't apply anymore. Most
|
|
|
|
modern operating systems allow at least 255 characters in the filename; the
|
|
|
|
exact maximum length, as well as the characters allowed in the filenames, are
|
|
|
|
OS-specific so you should try to avoid extremely long (> 255 chars) filenames
|
2008-03-22 13:49:09 -04:00
|
|
|
and/or filenames with non-ANSI characters.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
Another thing you need to keep in mind is that all Windows operating systems
|
|
|
|
are case-insensitive, while Unix operating systems (Linux, Mac, etc) are
|
|
|
|
case-sensitive.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Also, for text files, different OSes use different End Of Lines (EOL). Windows
|
|
|
|
uses CR+LF convention, Linux uses LF only, Mac CR only.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-22 13:49:09 -04:00
|
|
|
The wxTextFile, wxTextInputStream, wxTextOutputStream classes help to abstract
|
2008-04-02 01:29:12 -04:00
|
|
|
from these differences. Of course, there are also 3rd party utilities such as
|
|
|
|
@c dos2unix and @c unix2dos which do the EOL conversions.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
See also the @ref group_funcmacro_file section of the reference manual for the
|
|
|
|
description of miscellaneous file handling functions.
|
2008-02-21 16:11:25 -05:00
|
|
|
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
|
|
|
|
@section page_multiplatform_reducingerr Reducing Programming Errors
|
2008-03-31 09:27:33 -04:00
|
|
|
|
|
|
|
@subsection page_multiplatform_reducingerr_useassert Use ASSERT
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
It is good practice to use ASSERT statements liberally, that check for
|
|
|
|
conditions that should or should not hold, and print out appropriate error
|
|
|
|
messages.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
These can be compiled out of a non-debugging version of wxWidgets and your
|
|
|
|
application. Using ASSERT is an example of `defensive programming': it can
|
|
|
|
alert you to problems later on.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
See wxASSERT() for more info.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_reducingerr_usewxstring Use wxString in Preference to Character Arrays
|
2008-03-31 09:27:33 -04:00
|
|
|
|
|
|
|
Using wxString can be much safer and more convenient than using @c wxChar*.
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
You can reduce the possibility of memory leaks substantially, and it is much
|
|
|
|
more convenient to use the overloaded operators than functions such as
|
|
|
|
@c strcmp. wxString won't add a significant overhead to your program; the
|
|
|
|
overhead is compensated for by easier manipulation (which means less code).
|
2008-03-31 09:27:33 -04:00
|
|
|
|
|
|
|
The same goes for other data types: use classes wherever possible.
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@section page_multiplatform_gui GUI Design
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@li <b>Use Sizers:</b> Don't use absolute panel item positioning if you can
|
|
|
|
avoid it. Every platform's native controls have very different sizes.
|
|
|
|
Consider using the @ref overview_sizer instead.
|
|
|
|
@li <b>Use wxWidgets Resource Files:</b> Use @c XRC (wxWidgets resource files)
|
|
|
|
where possible, because they can be easily changed independently of source
|
|
|
|
code. See the @ref overview_xrc for more info.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@section page_multiplatform_debug Debugging
|
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_debug_positivethinking Positive Thinking
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
It is common to blow up the problem in one's imagination, so that it seems to
|
|
|
|
threaten weeks, months or even years of work. The problem you face may seem
|
|
|
|
insurmountable: but almost never is. Once you have been programming for some
|
|
|
|
time, you will be able to remember similar incidents that threw you into the
|
|
|
|
depths of despair. But remember, you always solved the problem, somehow!
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Perseverance is often the key, even though a seemingly trivial problem can take
|
|
|
|
an apparently inordinate amount of time to solve. In the end, you will probably
|
|
|
|
wonder why you worried so much. That's not to say it isn't painful at the time.
|
|
|
|
Try not to worry -- there are many more important things in life.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_debug_simplifyproblem Simplify the Problem
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Reduce the code exhibiting the problem to the smallest program possible that
|
|
|
|
exhibits the problem. If it is not possible to reduce a large and complex
|
|
|
|
program to a very small program, then try to ensure your code doesn't hide the
|
|
|
|
problem (you may have attempted to minimize the problem in some way: but now
|
|
|
|
you want to expose it).
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
With luck, you can add a small amount of code that causes the program to go
|
|
|
|
from functioning to non-functioning state. This should give a clue to the
|
|
|
|
problem. In some cases though, such as memory leaks or wrong deallocation, this
|
|
|
|
can still give totally spurious results!
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_debug_usedebugger Use a Debugger
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
This sounds like facetious advice, but it is surprising how often people don't
|
|
|
|
use a debugger. Often it is an overhead to install or learn how to use a
|
|
|
|
debugger, but it really is essential for anything but the most trivial
|
|
|
|
programs.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_debug_uselogging Use Logging Functions
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
There is a variety of logging functions that you can use in your program: see
|
|
|
|
@ref group_funcmacro_log.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
Using tracing statements may be more convenient than using the debugger in some
|
|
|
|
circumstances (such as when your debugger doesn't support a lot of debugging
|
|
|
|
code, or you wish to print a bunch of variables).
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
@subsection page_multiplatform_debug_usedebuggingfacilities Use the wxWidgets Debugging Facilities
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-04-02 01:29:12 -04:00
|
|
|
You can use wxDebugContext to check for memory leaks and corrupt memory: in
|
|
|
|
fact in debugging mode, wxWidgets will automatically check for memory leaks at
|
|
|
|
the end of the program if wxWidgets is suitably configured. Depending on the
|
|
|
|
operating system and compiler, more or less specific information about the
|
|
|
|
problem will be logged.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
2008-09-25 09:39:27 -04:00
|
|
|
You should also use @ref group_funcmacro_debug as part of a "defensive
|
2008-04-02 01:29:12 -04:00
|
|
|
programming" strategy, scattering wxASSERT()s liberally to test for problems in
|
|
|
|
your code as early as possible. Forward thinking will save a surprising amount
|
|
|
|
of time in the long run.
|
2008-03-31 09:27:33 -04:00
|
|
|
|
|
|
|
See the @ref overview_debugging for further information.
|
|
|
|
|
2008-02-21 16:11:25 -05:00
|
|
|
*/
|
2008-04-02 01:29:12 -04:00
|
|
|
|