]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _stockobjs.i | |
3 | // Purpose: SWIG interface defining "stock" GDI objects | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 13-Sept-2003 | |
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 | class wxStockGDI | |
21 | { | |
22 | public: | |
23 | enum Item { | |
24 | BRUSH_BLACK, | |
25 | BRUSH_BLUE, | |
26 | BRUSH_CYAN, | |
27 | BRUSH_GREEN, | |
28 | BRUSH_GREY, | |
29 | BRUSH_LIGHTGREY, | |
30 | BRUSH_MEDIUMGREY, | |
31 | BRUSH_RED, | |
32 | BRUSH_TRANSPARENT, | |
33 | BRUSH_WHITE, | |
34 | COLOUR_BLACK, | |
35 | COLOUR_BLUE, | |
36 | COLOUR_CYAN, | |
37 | COLOUR_GREEN, | |
38 | COLOUR_LIGHTGREY, | |
39 | COLOUR_RED, | |
40 | COLOUR_WHITE, | |
41 | CURSOR_CROSS, | |
42 | CURSOR_HOURGLASS, | |
43 | CURSOR_STANDARD, | |
44 | FONT_ITALIC, | |
45 | FONT_NORMAL, | |
46 | FONT_SMALL, | |
47 | FONT_SWISS, | |
48 | PEN_BLACK, | |
49 | PEN_BLACKDASHED, | |
50 | PEN_CYAN, | |
51 | PEN_GREEN, | |
52 | PEN_GREY, | |
53 | PEN_LIGHTGREY, | |
54 | PEN_MEDIUMGREY, | |
55 | PEN_RED, | |
56 | PEN_TRANSPARENT, | |
57 | PEN_WHITE, | |
58 | ITEMCOUNT | |
59 | }; | |
60 | ||
61 | wxStockGDI(); | |
62 | virtual ~wxStockGDI(); | |
63 | static void DeleteAll(); | |
64 | ||
65 | static wxStockGDI& instance(); | |
66 | ||
67 | static const wxBrush* GetBrush(Item item); | |
68 | static const wxColour* GetColour(Item item); | |
69 | static const wxCursor* GetCursor(Item item); | |
70 | static const wxPen* GetPen(Item item); | |
71 | ||
72 | virtual const wxFont* GetFont(Item item); | |
73 | ||
74 | %pythoncode { | |
75 | def _initStockObjects(): | |
76 | import wx | |
77 | wx.ITALIC_FONT = StockGDI.instance().GetFont(StockGDI.FONT_ITALIC) | |
78 | wx.NORMAL_FONT = StockGDI.instance().GetFont(StockGDI.FONT_NORMAL) | |
79 | wx.SMALL_FONT = StockGDI.instance().GetFont(StockGDI.FONT_SMALL) | |
80 | wx.SWISS_FONT = StockGDI.instance().GetFont(StockGDI.FONT_SWISS) | |
81 | ||
82 | wx.BLACK_DASHED_PEN = StockGDI.GetPen(StockGDI.PEN_BLACKDASHED) | |
83 | wx.BLACK_PEN = StockGDI.GetPen(StockGDI.PEN_BLACK) | |
84 | wx.CYAN_PEN = StockGDI.GetPen(StockGDI.PEN_CYAN) | |
85 | wx.GREEN_PEN = StockGDI.GetPen(StockGDI.PEN_GREEN) | |
86 | wx.GREY_PEN = StockGDI.GetPen(StockGDI.PEN_GREY) | |
87 | wx.LIGHT_GREY_PEN = StockGDI.GetPen(StockGDI.PEN_LIGHTGREY) | |
88 | wx.MEDIUM_GREY_PEN = StockGDI.GetPen(StockGDI.PEN_MEDIUMGREY) | |
89 | wx.RED_PEN = StockGDI.GetPen(StockGDI.PEN_RED) | |
90 | wx.TRANSPARENT_PEN = StockGDI.GetPen(StockGDI.PEN_TRANSPARENT) | |
91 | wx.WHITE_PEN = StockGDI.GetPen(StockGDI.PEN_WHITE) | |
92 | ||
93 | wx.BLACK_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_BLACK) | |
94 | wx.BLUE_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_BLUE) | |
95 | wx.CYAN_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_CYAN) | |
96 | wx.GREEN_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_GREEN) | |
97 | wx.GREY_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_GREY) | |
98 | wx.LIGHT_GREY_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_LIGHTGREY) | |
99 | wx.MEDIUM_GREY_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_MEDIUMGREY) | |
100 | wx.RED_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_RED) | |
101 | wx.TRANSPARENT_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_TRANSPARENT) | |
102 | wx.WHITE_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_WHITE) | |
103 | ||
104 | wx.BLACK = StockGDI.GetColour(StockGDI.COLOUR_BLACK) | |
105 | wx.BLUE = StockGDI.GetColour(StockGDI.COLOUR_BLUE) | |
106 | wx.CYAN = StockGDI.GetColour(StockGDI.COLOUR_CYAN) | |
107 | wx.GREEN = StockGDI.GetColour(StockGDI.COLOUR_GREEN) | |
108 | wx.LIGHT_GREY = StockGDI.GetColour(StockGDI.COLOUR_LIGHTGREY) | |
109 | wx.RED = StockGDI.GetColour(StockGDI.COLOUR_RED) | |
110 | wx.WHITE = StockGDI.GetColour(StockGDI.COLOUR_WHITE) | |
111 | ||
112 | wx.CROSS_CURSOR = StockGDI.GetCursor(StockGDI.CURSOR_CROSS) | |
113 | wx.HOURGLASS_CURSOR = StockGDI.GetCursor(StockGDI.CURSOR_HOURGLASS) | |
114 | wx.STANDARD_CURSOR = StockGDI.GetCursor(StockGDI.CURSOR_STANDARD) | |
115 | ||
116 | _initStockObjects = staticmethod(_initStockObjects) | |
117 | } | |
118 | }; | |
119 | ||
120 | ||
121 | ||
122 | %immutable; | |
123 | %threadWrapperOff; | |
124 | ||
125 | const wxBitmap wxNullBitmap; | |
126 | const wxIcon wxNullIcon; | |
127 | const wxCursor wxNullCursor; | |
128 | const wxPen wxNullPen; | |
129 | const wxBrush wxNullBrush; | |
130 | const wxPalette wxNullPalette; | |
131 | const wxFont wxNullFont; | |
132 | const wxColour wxNullColour; | |
133 | ||
134 | %threadWrapperOn; | |
135 | %mutable; | |
136 | ||
137 | ||
138 | //--------------------------------------------------------------------------- | |
139 | ||
140 | ||
141 | class wxGDIObjListBase { | |
142 | public: | |
143 | wxGDIObjListBase(); | |
144 | ~wxGDIObjListBase(); | |
145 | }; | |
146 | ||
147 | ||
148 | class wxPenList : public wxGDIObjListBase { | |
149 | public: | |
150 | ||
151 | wxPen* FindOrCreatePen(const wxColour& colour, int width, int style); | |
152 | ||
153 | void AddPen(wxPen* pen); | |
154 | void RemovePen(wxPen* pen); | |
155 | %pythoncode { | |
156 | AddPen = wx._deprecated(AddPen) | |
157 | RemovePen = wx._deprecated(RemovePen) | |
158 | } | |
159 | // int GetCount(); | |
160 | }; | |
161 | ||
162 | ||
163 | class wxBrushList : public wxGDIObjListBase { | |
164 | public: | |
165 | ||
166 | wxBrush * FindOrCreateBrush(const wxColour& colour, int style=wxSOLID); | |
167 | ||
168 | void AddBrush(wxBrush *brush); | |
169 | void RemoveBrush(wxBrush *brush); | |
170 | %pythoncode { | |
171 | AddBrush = wx._deprecated(AddBrush) | |
172 | RemoveBrush = wx._deprecated(RemoveBrush) | |
173 | } | |
174 | // int GetCount(); | |
175 | }; | |
176 | ||
177 | ||
178 | class wxFontList : public wxGDIObjListBase { | |
179 | public: | |
180 | ||
181 | wxFont * FindOrCreateFont(int point_size, int family, int style, int weight, | |
182 | bool underline = false, | |
183 | const wxString& facename = wxPyEmptyString, | |
184 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); | |
185 | ||
186 | void AddFont(wxFont* font); | |
187 | void RemoveFont(wxFont *font); | |
188 | %pythoncode { | |
189 | AddFont = wx._deprecated(AddFont) | |
190 | RemoveFont = wx._deprecated(RemoveFont) | |
191 | } | |
192 | ||
193 | // int GetCount(); | |
194 | }; | |
195 | ||
196 | //--------------------------------------------------------------------------- | |
197 | ||
198 | MustHaveApp(wxColourDatabase); | |
199 | ||
200 | class wxColourDatabase { | |
201 | public: | |
202 | wxColourDatabase(); | |
203 | ~wxColourDatabase(); | |
204 | ||
205 | // find colour by name or name for the given colour | |
206 | wxColour Find(const wxString& name) const; | |
207 | wxString FindName(const wxColour& colour) const; | |
208 | %pythoncode { FindColour = Find } | |
209 | ||
210 | // add a new colour to the database | |
211 | void AddColour(const wxString& name, const wxColour& colour); | |
212 | ||
213 | %extend { | |
214 | void Append(const wxString& name, int red, int green, int blue) { | |
215 | self->AddColour(name, wxColour(red, green, blue)); | |
216 | } | |
217 | } | |
218 | }; | |
219 | ||
220 | ||
221 | //--------------------------------------------------------------------------- | |
222 | %newgroup | |
223 | ||
224 | %inline { | |
225 | wxFontList* _wxPyInitTheFontList() { return wxTheFontList; } | |
226 | wxPenList* _wxPyInitThePenList() { return wxThePenList; } | |
227 | wxBrushList* _wxPyInitTheBrushList() { return wxTheBrushList; } | |
228 | wxColourDatabase* _wxPyInitTheColourDatabase() { return wxTheColourDatabase; } | |
229 | } | |
230 | ||
231 | %pythoncode { | |
232 | %# This function makes a class used to do delayed initialization of some | |
233 | %# stock wx objects. When they are used the first time then an init function | |
234 | %# is called to make the real instance, which is then used to replace the | |
235 | %# original instance and class seen by the programmer. | |
236 | def _wxPyMakeDelayedInitWrapper(initFunc): | |
237 | class _wxPyStockObjectWrapper(object): | |
238 | def __init__(self, *args): | |
239 | self._args = args | |
240 | def __getattr__(self, name): | |
241 | obj = initFunc(*self._args) | |
242 | self.__class__ = obj.__class__ | |
243 | self.__dict__ = obj.__dict__ | |
244 | return getattr(self, name) | |
245 | def __str__(self): | |
246 | return self.__getattr__("__str__")() | |
247 | def __repr__(self): | |
248 | return self.__getattr__("__repr__")() | |
249 | return _wxPyStockObjectWrapper | |
250 | ||
251 | wxTheFontList = _wxPyMakeDelayedInitWrapper(_wxPyInitTheFontList)() | |
252 | wxThePenList = _wxPyMakeDelayedInitWrapper(_wxPyInitThePenList)() | |
253 | wxTheBrushList = _wxPyMakeDelayedInitWrapper(_wxPyInitTheBrushList)() | |
254 | wxTheColourDatabase = _wxPyMakeDelayedInitWrapper(_wxPyInitTheColourDatabase)() | |
255 | } | |
256 | ||
257 | //--------------------------------------------------------------------------- | |
258 | ||
259 | %pythoncode { NullColor = NullColour } | |
260 | ||
261 | ||
262 | ||
263 |