reformatted to fit in the page width

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14995 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-04-07 17:33:28 +00:00
parent 04c4c93f00
commit a582395301

View File

@@ -4,82 +4,83 @@
0. Introduction 0. Introduction
--------------- ---------------
Since the introduction of wxArtProvider class, it is no longer desired to hardcode Since the introduction of wxArtProvider class, it is no longer desired to
art resources (e.g. icons and toolbar or button bitmaps) into the code. This was hardcode art resources (e.g. icons and toolbar or button bitmaps) into the
previously done either by including the bitmap in win32 resource file code. This was previously done either by including the bitmap in win32
(include/wx/msw/wx.rc) or by including XPM files in the code. resource file (include/wx/msw/wx.rc) or by including XPM files in the code.
wxArtProvider should be used instead, to allow users to customize the look of their wxArtProvider should be used instead, to allow users to customize the look of
wxWindows app. This technote is a detailed description of steps needed when adding their wxWindows app. This technote is a detailed description of steps needed
new bitmap/icon. when adding new bitmap/icon.
1. Adding new resource 1. Adding new resource
---------------------- ----------------------
(Please see wxArtProvider reference documentation for explanation of "art ID" and (Please see wxArtProvider reference documentation for explanation of "art ID"
"art client" terms.) and "art client" terms.)
First of all, you have to add new wxArtID constant to include/wx/artprov.h. Look for First of all, you have to add new wxArtID constant to include/wx/artprov.h.
"Art IDs" and add new definition to the list, e.g. Look for "Art IDs" and add new definition to the list, e.g.
#define wxART_MY_BITMAP _T("my_bitmap") #define wxART_MY_BITMAP _T("my_bitmap")
It may happen that the intended use of the new resource doesn't fit into any of defined It may happen that the intended use of the new resource doesn't fit into any
client categories (search for "Art clients" in the header). In case the new resource is of defined client categories (search for "Art clients" in the header). In case
part of a larger category, you need to define a new client. Just add it to the list of the new resource is part of a larger category, you need to define a new
existing clients: client. Just add it to the list of existing clients:
#define wxART_MY_CLIENT _T("my_client_C") #define wxART_MY_CLIENT _T("my_client_C")
(Note that you *have* to add the trailing "_C"!) (Note that you *have* to add the trailing "_C"!)
Alternatively, you may use wxART_OTHER when accessing the resource if the bitmap is Alternatively, you may use wxART_OTHER when accessing the resource if the
standalone. bitmap is standalone.
Once the header is updated, it's time to add XPM file with the bitmap to $(wx)/art. Add Once the header is updated, it's time to add XPM file with the bitmap to
it to $(wx)/art if it is platform-independent or to $(wx)/art/$(toolkit) if it is $(wx)/art. Add it to $(wx)/art if it is platform-independent or to
something specific to one of the toolkits. Note that "specific to one of the toolkits" $(wx)/art/$(toolkit) if it is something specific to one of the toolkits. Note
doesn't mean that the bitmap is *used* by only one toolkit, but that it doesn't make that "specific to one of the toolkits" doesn't mean that the bitmap is *used*
sense for any of the others! For example, a GTK wxART_WARNING icon by only one toolkit, but that it doesn't make sense for any of the others! For
($(wx)/art/gtk/warning.xpm) is specific to wxGTK, but new_dir.xpm makes sense even under example, a GTK wxART_WARNING icon ($(wx)/art/gtk/warning.xpm) is specific to
wxMSW even though it is currently only used by the generic file dialog. Remember that wxGTK, but new_dir.xpm makes sense even under wxMSW even though it is
wxArtProvider can be used by users, not only the library. currently only used by the generic file dialog. Remember that wxArtProvider
can be used by users, not only the library.
Finally, wxDefaultArtProvider in $(wx)/src/common/artstd.cpp must be updated. This Finally, wxDefaultArtProvider in $(wx)/src/common/artstd.cpp must be updated.
consists of two steps: This consists of two steps:
a) add #include line for your XPM file, e.g. a) add #include line for your XPM file, e.g. #include "../../art/my_bmp.xpm"
#include "../../art/my_bmp.xpm" b) add ART(...) line to wxDefaultArtProvider::CreateBitmap(). The first
b) add ART(...) line to wxDefaultArtProvider::CreateBitmap(). The first argument argument is wxArtID, the other is XPM file name (w/o extension), e.g.
is wxArtID, the other is XPM file name (w/o extension), e.g. ART(wxART_MY_BITMAP, my_bmp)
ART(wxART_MY_BITMAP, my_bmp)
That's all. The bitmap is now available to wxArtProvider users. That's all. The bitmap is now available to wxArtProvider users.
Note: there's no difference between icons and bitmaps, always treat them as bitmaps Note: there's no difference between icons and bitmaps, always treat them as
inside wx(Default)ArtProvider. bitmaps inside wx(Default)ArtProvider.
2. Accessing the resource 2. Accessing the resource
------------------------- -------------------------
The file that will use the bitmap needs to include "wx/artprov.h". The code to access The file that will use the bitmap needs to include "wx/artprov.h". The code to
the bitmap (or icon) is trivial: access the bitmap (or icon) is trivial:
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_MY_BITMAP, wxART_MY_CLIENT); wxBitmap bmp = wxArtProvider::GetBitmap(wxART_MY_BITMAP, wxART_MY_CLIENT);
// this would be "wxBitmap bmp(my_bmp_xpm);" before // this would be "wxBitmap bmp(my_bmp_xpm);" before
wxIcon icon = wxArtProvider::GetIcon(wxART_MY_ICON, wxART_MY_CLIENT); wxIcon icon = wxArtProvider::GetIcon(wxART_MY_ICON, wxART_MY_CLIENT);
Substitute wxART_MY_CLIENT in the example with a suitable client ID. If the client Substitute wxART_MY_CLIENT in the example with a suitable client ID. If the
is wxART_OTHER you may write only wxArtProvider::GetBitmap(wxART_MY_BITMAP). client is wxART_OTHER you may write only
wxArtProvider::GetBitmap(wxART_MY_BITMAP).
3. Providing a demo 3. Providing a demo
------------------- -------------------
It is highly desirable to let the users know what stock bitmaps are available in It is highly desirable to let the users know what stock bitmaps are available
wxWindows. The "artprov" sample serves this purpose: it contains a browser dialog in wxWindows. The "artprov" sample serves this purpose: it contains a browser
that displays all available art resources. dialog that displays all available art resources.
It has to be updated to accomodate for new bitmaps. Fortunately, this is trivial: It has to be updated to accomodate for new bitmaps. Fortunately, this is
open $(wx)/samples/artprov/artbrows.cpp in text editor and trivial: open $(wx)/samples/artprov/artbrows.cpp in text editor and
ART_ICON(wxART_MY_BITMAP) ART_ICON(wxART_MY_BITMAP) line to the FillBitmaps() function.
line to the FillBitmaps() function.
Similarly, if you add a new client, please update FillClients() by adding new Similarly, if you add a new client, please update FillClients() by adding new
client to the end of the list. client to the end of the list.