]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_artprov.i
Allow the OOR reference to be saved without doing an INCREF. This
[wxWidgets.git] / wxPython / src / _artprov.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _artprov.i
3// Purpose: SWIG interface stuff for wxArtProvider
4//
5// Author: Robin Dunn
6//
7// Created: 18-June-1999
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19%{
20#include <wx/artprov.h>
21%}
22
23//---------------------------------------------------------------------------
24
25
26// Art clients
27MAKE_CONST_WXSTRING(ART_TOOLBAR);
28MAKE_CONST_WXSTRING(ART_MENU);
29MAKE_CONST_WXSTRING(ART_FRAME_ICON);
30MAKE_CONST_WXSTRING(ART_CMN_DIALOG);
31MAKE_CONST_WXSTRING(ART_HELP_BROWSER);
32MAKE_CONST_WXSTRING(ART_MESSAGE_BOX);
ed2de217 33MAKE_CONST_WXSTRING(ART_BUTTON);
d14a1e28
RD
34MAKE_CONST_WXSTRING(ART_OTHER);
35
36// Art IDs
37MAKE_CONST_WXSTRING(ART_ADD_BOOKMARK);
38MAKE_CONST_WXSTRING(ART_DEL_BOOKMARK);
39MAKE_CONST_WXSTRING(ART_HELP_SIDE_PANEL);
40MAKE_CONST_WXSTRING(ART_HELP_SETTINGS);
41MAKE_CONST_WXSTRING(ART_HELP_BOOK);
42MAKE_CONST_WXSTRING(ART_HELP_FOLDER);
43MAKE_CONST_WXSTRING(ART_HELP_PAGE);
44MAKE_CONST_WXSTRING(ART_GO_BACK);
45MAKE_CONST_WXSTRING(ART_GO_FORWARD);
46MAKE_CONST_WXSTRING(ART_GO_UP);
47MAKE_CONST_WXSTRING(ART_GO_DOWN);
48MAKE_CONST_WXSTRING(ART_GO_TO_PARENT);
49MAKE_CONST_WXSTRING(ART_GO_HOME);
50MAKE_CONST_WXSTRING(ART_FILE_OPEN);
51MAKE_CONST_WXSTRING(ART_PRINT);
52MAKE_CONST_WXSTRING(ART_HELP);
53MAKE_CONST_WXSTRING(ART_TIP);
54MAKE_CONST_WXSTRING(ART_REPORT_VIEW);
55MAKE_CONST_WXSTRING(ART_LIST_VIEW);
56MAKE_CONST_WXSTRING(ART_NEW_DIR);
020303e6
RD
57MAKE_CONST_WXSTRING(ART_HARDDISK);
58MAKE_CONST_WXSTRING(ART_FLOPPY);
59MAKE_CONST_WXSTRING(ART_CDROM);
60MAKE_CONST_WXSTRING(ART_REMOVABLE);
d14a1e28 61MAKE_CONST_WXSTRING(ART_FOLDER);
020303e6 62MAKE_CONST_WXSTRING(ART_FOLDER_OPEN);
d14a1e28
RD
63MAKE_CONST_WXSTRING(ART_GO_DIR_UP);
64MAKE_CONST_WXSTRING(ART_EXECUTABLE_FILE);
65MAKE_CONST_WXSTRING(ART_NORMAL_FILE);
66MAKE_CONST_WXSTRING(ART_TICK_MARK);
67MAKE_CONST_WXSTRING(ART_CROSS_MARK);
68MAKE_CONST_WXSTRING(ART_ERROR);
69MAKE_CONST_WXSTRING(ART_QUESTION);
70MAKE_CONST_WXSTRING(ART_WARNING);
71MAKE_CONST_WXSTRING(ART_INFORMATION);
72MAKE_CONST_WXSTRING(ART_MISSING_IMAGE);
73
74//---------------------------------------------------------------------------
75
76%{ // Python aware wxArtProvider
77class wxPyArtProvider : public wxArtProvider {
78public:
79
80 virtual wxBitmap CreateBitmap(const wxArtID& id,
81 const wxArtClient& client,
82 const wxSize& size) {
83 wxBitmap rval = wxNullBitmap;
da32eb53 84 bool blocked = wxPyBeginBlockThreads();
d14a1e28
RD
85 if ((wxPyCBH_findCallback(m_myInst, "CreateBitmap"))) {
86 PyObject* so = wxPyConstructObject((void*)&size, wxT("wxSize"), 0);
87 PyObject* ro;
88 wxBitmap* ptr;
89 PyObject* s1, *s2;
90 s1 = wx2PyString(id);
91 s2 = wx2PyString(client);
92 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOO)", s1, s2, so));
93 Py_DECREF(so);
94 Py_DECREF(s1);
95 Py_DECREF(s2);
96 if (ro) {
97 if (wxPyConvertSwigPtr(ro, (void**)&ptr, wxT("wxBitmap")))
98 rval = *ptr;
99 Py_DECREF(ro);
100 }
101 }
da32eb53 102 wxPyEndBlockThreads(blocked);
d14a1e28
RD
103 return rval;
104 }
105
106 PYPRIVATE;
107};
108%}
109
110// The one for SWIG to see
dce2bd22
RD
111
112
113
114DocStr(wxPyArtProvider,
115"The wx.ArtProvider class is used to customize the look of wxWidgets
116application. When wxWidgets needs to display an icon or a bitmap (e.g.
117in the standard file dialog), it does not use hard-coded resource but
118asks wx.ArtProvider for it instead. This way the users can plug in
119their own wx.ArtProvider class and easily replace standard art with
120his/her own version. It is easy thing to do: all that is needed is
121to derive a class from wx.ArtProvider, override it's CreateBitmap
122method and register the provider with wx.ArtProvider.PushProvider::
123
124 class MyArtProvider(wx.ArtProvider):
125 def __init__(self):
126 wx.ArtProvider.__init__(self)
127
128 def CreateBitmap(self, artid, client, size):
129 ...
130 return bmp
d07d2bc9 131", "
dce2bd22
RD
132
133Identifying art resources
134-------------------------
135
136Every bitmap is known to wx.ArtProvider under an unique ID that is
ed2de217
RD
137used when requesting a resource from it. The IDs can have one of the
138following predefined values. Additionally, any string recognized by
07faea28
RD
139custom art providers registered using `PushProvider` may be used.
140
141GTK+ Note
142---------
143
144When running under GTK+ 2, GTK+ stock item IDs (e.g. 'gtk-cdrom') may be used
145as well. Additionally, if wxGTK was compiled against GTK+ >= 2.4, then it is
146also possible to load icons from current icon theme by specifying their name
147without the extension and directory components. Icon themes recognized by GTK+
148follow the freedesktop.org Icon Themes specification. Note that themes are
149not guaranteed to contain all icons, so wx.ArtProvider may return wx.NullBitmap
150or wx.NullIcon. The default theme is typically installed in /usr/share/icons/hicolor.
ed2de217 151
dce2bd22
RD
152
153 * wx.ART_ADD_BOOKMARK
154 * wx.ART_DEL_BOOKMARK
155 * wx.ART_HELP_SIDE_PANEL
156 * wx.ART_HELP_SETTINGS
157 * wx.ART_HELP_BOOK
158 * wx.ART_HELP_FOLDER
159 * wx.ART_HELP_PAGE
160 * wx.ART_GO_BACK
161 * wx.ART_GO_FORWARD
162 * wx.ART_GO_UP
163 * wx.ART_GO_DOWN
164 * wx.ART_GO_TO_PARENT
165 * wx.ART_GO_HOME
166 * wx.ART_FILE_OPEN
167 * wx.ART_PRINT
168 * wx.ART_HELP
169 * wx.ART_TIP
170 * wx.ART_REPORT_VIEW
171 * wx.ART_LIST_VIEW
172 * wx.ART_NEW_DIR
173 * wx.ART_FOLDER
174 * wx.ART_GO_DIR_UP
175 * wx.ART_EXECUTABLE_FILE
176 * wx.ART_NORMAL_FILE
177 * wx.ART_TICK_MARK
178 * wx.ART_CROSS_MARK
179 * wx.ART_ERROR
180 * wx.ART_QUESTION
181 * wx.ART_WARNING
182 * wx.ART_INFORMATION
183 * wx.ART_MISSING_IMAGE
184
185
186Clients
187-------
188
189The Client is the entity that calls wx.ArtProvider's `GetBitmap` or
ed2de217 190`GetIcon` function. Client IDs serve as a hint to wx.ArtProvider
dce2bd22
RD
191that is supposed to help it to choose the best looking bitmap. For
192example it is often desirable to use slightly different icons in menus
193and toolbars even though they represent the same action (e.g.
194wx.ART_FILE_OPEN). Remember that this is really only a hint for
195wx.ArtProvider -- it is common that `wx.ArtProvider.GetBitmap` returns
196identical bitmap for different client values!
197
198 * wx.ART_TOOLBAR
199 * wx.ART_MENU
200 * wx.ART_FRAME_ICON
201 * wx.ART_CMN_DIALOG
202 * wx.ART_HELP_BROWSER
203 * wx.ART_MESSAGE_BOX
ed2de217 204 * wx.ART_BUTTON
dce2bd22
RD
205 * wx.ART_OTHER (used for all requests that don't fit into any
206 of the categories above)
207");
208
ab1f7d2a
RD
209MustHaveApp(wxPyArtProvider);
210MustHaveApp(wxPyArtProvider::GetBitmap);
211MustHaveApp(wxPyArtProvider::GetIcon);
212
d14a1e28
RD
213%name(ArtProvider) class wxPyArtProvider /*: public wxObject*/
214{
215public:
216
2b9048c5 217 %pythonAppend wxPyArtProvider "self._setCallbackInfo(self, ArtProvider)"
d14a1e28 218 wxPyArtProvider();
d14a1e28
RD
219
220 void _setCallbackInfo(PyObject* self, PyObject* _class);
221
dce2bd22
RD
222 DocDeclStr(
223 static void , PushProvider(wxPyArtProvider *provider),
d07d2bc9 224 "Add new provider to the top of providers stack.", "");
dce2bd22 225
d14a1e28 226
dce2bd22
RD
227 DocDeclStr(
228 static bool , PopProvider(),
d07d2bc9 229 "Remove latest added provider and delete it.", "");
dce2bd22 230
d14a1e28 231
dce2bd22
RD
232 DocDeclStr(
233 static bool , RemoveProvider(wxPyArtProvider *provider),
234 "Remove provider. The provider must have been added previously! The
d07d2bc9 235provider is _not_ deleted.", "");
dce2bd22 236
d14a1e28 237
dce2bd22
RD
238 DocDeclStr(
239 static wxBitmap , GetBitmap(const wxString& id,
240 const wxString& client = wxPyART_OTHER,
241 const wxSize& size = wxDefaultSize),
242 "Query the providers for bitmap with given ID and return it. Return
d07d2bc9 243wx.NullBitmap if no provider provides it.", "");
dce2bd22 244
d14a1e28 245
dce2bd22
RD
246 DocDeclStr(
247 static wxIcon , GetIcon(const wxString& id,
d14a1e28 248 const wxString& client = wxPyART_OTHER,
dce2bd22
RD
249 const wxSize& size = wxDefaultSize),
250 "Query the providers for icon with given ID and return it. Return
d07d2bc9 251wx.NullIcon if no provider provides it.", "");
dce2bd22 252
d14a1e28 253
1e0c8722 254 %extend { void Destroy() { delete self; }}
d14a1e28
RD
255};
256
257
258
259//---------------------------------------------------------------------------
260%init %{
261 wxPyPtrTypeMap_Add("wxArtProvider", "wxPyArtProvider");
262%}
263//---------------------------------------------------------------------------