]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/tech/tn0015.txt
clean up of memory debugging macros and chanegs to compile with CW7 (patch 548408)
[wxWidgets.git] / docs / tech / tn0015.txt
... / ...
CommitLineData
1 How to add new bitmaps to wxWindows UI elements
2 ===============================================
3
40. Introduction
5---------------
6
7Since the introduction of wxArtProvider class, it is no longer desired to
8hardcode art resources (e.g. icons and toolbar or button bitmaps) into the
9code. This was previously done either by including the bitmap in win32
10resource file (include/wx/msw/wx.rc) or by including XPM files in the code.
11
12wxArtProvider should be used instead, to allow users to customize the look of
13their wxWindows app. This technote is a detailed description of steps needed
14when adding new bitmap/icon.
15
161. Adding new resource
17----------------------
18
19(Please see wxArtProvider reference documentation for explanation of "art ID"
20 and "art client" terms.)
21
22First of all, you have to add new wxArtID constant to include/wx/artprov.h.
23Look for "Art IDs" and add new definition to the list, e.g.
24 #define wxART_MY_BITMAP _T("my_bitmap")
25
26Add it to docs/latex/wx/artprov.tex, too.
27
28It may happen that the intended use of the new resource doesn't fit into any
29of defined client categories (search for "Art clients" in the header). In case
30the new resource is part of a larger category, you need to define a new
31client. Just add it to the list of existing clients (and don't forget to
32update artprov.tex):
33 #define wxART_MY_CLIENT _T("my_client_C")
34(Note that you *have* to add the trailing "_C"!)
35
36Alternatively, you may use wxART_OTHER when accessing the resource if the
37bitmap is standalone.
38
39Once the header is updated, it's time to add XPM file with the bitmap to
40$(wx)/art. Add it to $(wx)/art if it is platform-independent or to
41$(wx)/art/$(toolkit) if it is something specific to one of the toolkits. Note
42that "specific to one of the toolkits" doesn't mean that the bitmap is *used*
43by only one toolkit, but that it doesn't make sense for any of the others! For
44example, a GTK wxART_WARNING icon ($(wx)/art/gtk/warning.xpm) is specific to
45wxGTK, but new_dir.xpm makes sense even under wxMSW even though it is
46currently only used by the generic file dialog. Remember that wxArtProvider
47can be used by users, not only the library.
48
49Finally, wxDefaultArtProvider in $(wx)/src/common/artstd.cpp must be updated.
50This consists of two steps:
51
52 a) add #include line for your XPM file, e.g. #include "../../art/my_bmp.xpm"
53 b) add ART(...) line to wxDefaultArtProvider::CreateBitmap(). The first
54 argument is wxArtID, the other is XPM file name (w/o extension), e.g.
55 ART(wxART_MY_BITMAP, my_bmp)
56
57That's all. The bitmap is now available to wxArtProvider users.
58
59Note: there's no difference between icons and bitmaps, always treat them as
60bitmaps inside wx(Default)ArtProvider.
61
622. Accessing the resource
63-------------------------
64
65The file that will use the bitmap needs to include "wx/artprov.h". The code to
66access the bitmap (or icon) is trivial:
67
68 wxBitmap bmp = wxArtProvider::GetBitmap(wxART_MY_BITMAP, wxART_MY_CLIENT);
69 // this would be "wxBitmap bmp(my_bmp_xpm);" before
70 wxIcon icon = wxArtProvider::GetIcon(wxART_MY_ICON, wxART_MY_CLIENT);
71
72Substitute wxART_MY_CLIENT in the example with a suitable client ID. If the
73client is wxART_OTHER you may write only
74
75 wxArtProvider::GetBitmap(wxART_MY_BITMAP).
76
773. Providing a demo
78-------------------
79
80It is highly desirable to let the users know what stock bitmaps are available
81in wxWindows. The "artprov" sample serves this purpose: it contains a browser
82dialog that displays all available art resources.
83
84It has to be updated to accomodate for new bitmaps. Fortunately, this is
85trivial: open $(wx)/samples/artprov/artbrows.cpp in text editor and
86ART_ICON(wxART_MY_BITMAP) line to the FillBitmaps() function.
87
88Similarly, if you add a new client, please update FillClients() by adding new
89client to the end of the list.
90
91=== EOF ===
92
93Version: $Id$