]> git.saurik.com Git - wxWidgets.git/blame - interface/pen.h
delay setting the window shape until it is realized (slightly modified patch 1935497)
[wxWidgets.git] / interface / pen.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.h
8024723d 3// Purpose: interface of wxPen* classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
8024723d
FM
9/**
10 The possible styles for a wxPen.
11*/
12enum wxPenStyle
13{
1413ac04
FM
14 wxPENSTYLE_INVALID = -1,
15
8024723d
FM
16 wxPENSTYLE_SOLID,
17 /**< Solid style. */
18
19 wxPENSTYLE_DOT,
20 /**< Dotted style. */
21
22 wxPENSTYLE_LONG_DASH,
23 /**< Long dashed style. */
24
25 wxPENSTYLE_SHORT_DASH,
26 /**< Short dashed style. */
27
28 wxPENSTYLE_DOT_DASH,
29 /**< Dot and dash style. */
30
31 wxPENSTYLE_USER_DASH,
32 /**< Use the user dashes: see wxPen::SetDashes. */
33
34 wxPENSTYLE_TRANSPARENT,
35 /**< No pen is used. */
36
37 wxPENSTYLE_STIPPLE_MASK_OPAQUE,
38 /**< @todo WHAT's this? */
39
40 wxPENSTYLE_STIPPLE_MASK,
41 /**< @todo WHAT's this? */
42
43 wxPENSTYLE_STIPPLE,
44 /**< Use the stipple bitmap. */
45
46 wxPENSTYLE_BDIAGONAL_HATCH,
47 /**< Backward diagonal hatch. */
48
49 wxPENSTYLE_CROSSDIAG_HATCH,
50 /**< Cross-diagonal hatch. */
51
52 wxPENSTYLE_FDIAGONAL_HATCH,
53 /**< Forward diagonal hatch. */
54
55 wxPENSTYLE_CROSS_HATCH,
56 /**< Cross hatch. */
57
58 wxPENSTYLE_HORIZONTAL_HATCH,
59 /**< Horizontal hatch. */
60
61 wxPENSTYLE_VERTICAL_HATCH,
62 /**< Vertical hatch. */
63
64 wxPENSTYLE_FIRST_HATCH = wxPENSTYLE_BDIAGONAL_HATCH,
1413ac04 65 wxPENSTYLE_LAST_HATCH = wxPENSTYLE_VERTICAL_HATCH
8024723d
FM
66};
67
68/**
69 The possible join values of a wxPen.
70
71 @todo use wxPENJOIN_ prefix
72*/
73enum wxPenJoin
74{
75 wxJOIN_INVALID = -1,
76
77 wxJOIN_BEVEL = 120,
78 wxJOIN_MITER,
79 wxJOIN_ROUND,
80};
81
82
83/**
84 The possible cap values of a wxPen.
85
86 @todo use wxPENCAP_ prefix
87*/
88enum wxPenCap
89{
90 wxCAP_INVALID = -1,
91
92 wxCAP_ROUND = 130,
93 wxCAP_PROJECTING,
94 wxCAP_BUTT
95};
96
97
98
23324ae1
FM
99/**
100 @class wxPen
101 @wxheader{pen.h}
7c913512 102
23324ae1 103 A pen is a drawing tool for drawing outlines. It is used for drawing
8024723d
FM
104 lines and painting the outline of rectangles, ellipses, etc.
105 It has a colour, a width and a style.
106
74bf4e64
FM
107 @remarks
108
8024723d
FM
109 On a monochrome display, wxWidgets shows all non-white pens as black.
110
111 Do not initialize objects on the stack before the program commences,
112 since other required structures may not have been set up yet.
74bf4e64 113 Instead, define global pointers to objects and create them in wxApp::OnInit()
8024723d
FM
114 or when required.
115
116 An application may wish to dynamically create pens with different characteristics,
117 and there is the consequent danger that a large number of duplicate pens will
118 be created. Therefore an application may wish to get a pointer to a pen by using
74bf4e64 119 the global list of pens ::wxThePenList, and calling the member function
8024723d
FM
120 wxPenList::FindOrCreatePen().
121 See the entry for wxPenList.
122
74bf4e64
FM
123 This class uses @ref overview_refcount "reference counting and copy-on-write" internally
124 so that assignments between two instances of this class are very cheap.
8024723d
FM
125 You can therefore use actual objects instead of pointers without efficiency problems.
126 If an instance of this class is changed it will create its own data internally
127 so that other instances, which previously shared the data using the reference
128 counting, are not affected.
7c913512 129
23324ae1
FM
130 @library{wxcore}
131 @category{gdi}
7c913512 132
23324ae1 133 @stdobjects
74bf4e64
FM
134 ::wxNullPen
135
136 <b>Predefined pointers:</b> ::wxRED_PEN, ::wxCYAN_PEN, ::wxGREEN_PEN,
137 ::wxBLACK_PEN, ::wxWHITE_PEN, ::wxTRANSPARENT_PEN, ::wxBLACK_DASHED_PEN,
138 ::wxGREY_PEN, ::wxMEDIUM_GREY_PEN, ::wxLIGHT_GREY_PEN
7c913512 139
74bf4e64 140 @see wxPenList, wxDC, wxDC::SetPen()
23324ae1
FM
141*/
142class wxPen : public wxGDIObject
143{
144public:
23324ae1 145 /**
74bf4e64 146 Default constructor. The pen will be uninitialised, and IsOk() will return @false.
8024723d
FM
147 */
148 wxPen();
149
150 /**
151 Constructs a pen from a colour object, pen width and style.
8024723d 152
7c913512 153 @param colour
4cc4bfaf 154 A colour object.
7c913512 155 @param width
4cc4bfaf 156 Pen width. Under Windows, the pen width cannot be greater than 1 if
74bf4e64 157 the style is @c wxDOT, @c wxLONG_DASH, @c wxSHORT_DASH, @c wxDOT_DASH, or @c wxUSER_DASH.
7c913512 158 @param style
8024723d
FM
159 The style may be one of the ::wxPenStyle values.
160
23324ae1 161 @remarks Different versions of Windows and different versions of other
4cc4bfaf
FM
162 platforms support very different subsets of the styles
163 above - there is no similarity even between Windows95
164 and Windows98 - so handle with care.
8024723d 165
74bf4e64
FM
166 @see SetStyle(), SetColour(), SetWidth()
167 */
168 wxPen(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
169
170 /**
171 Constructs a stippled pen from a stipple bitmap and a width.
172
173 @param width
174 Pen width. Under Windows, the pen width cannot be greater than 1 if
175 the style is @c wxDOT, @c wxLONG_DASH, @c wxSHORT_DASH, @c wxDOT_DASH, or @c wxUSER_DASH.
176 @param stipple
177 A stipple bitmap.
178
179 @see SetWidth(), SetStipple()
180 */
181 wxPen(const wxBitmap& stipple, int width);
182
183 /**
184 Copy constructor, uses @ref overview_refcount.
185
186 @param pen
187 A pointer or reference to a pen to copy.
23324ae1 188 */
7c913512 189 wxPen(const wxPen& pen);
23324ae1
FM
190
191 /**
192 Destructor.
74bf4e64 193 @see @ref overview_refcount_destruct "reference-counted object destruction"
8024723d 194
23324ae1 195 @remarks Although all remaining pens are deleted when the application
4cc4bfaf
FM
196 exits, the application should try to clean up all pens
197 itself. This is because wxWidgets cannot know if a
198 pointer to the pen object is stored in an application
199 data structure, and there is a risk of double deletion.
23324ae1
FM
200 */
201 ~wxPen();
202
203 /**
74bf4e64
FM
204 Returns the pen cap style, which may be one of @c wxCAP_ROUND, @c
205 wxCAP_PROJECTING and @c wxCAP_BUTT.
206
207 The default is @c wxCAP_ROUND.
8024723d 208
4cc4bfaf 209 @see SetCap()
23324ae1 210 */
231b9591 211 virtual wxPenCap GetCap() const;
23324ae1
FM
212
213 /**
214 Returns a reference to the pen colour.
8024723d 215
4cc4bfaf 216 @see SetColour()
23324ae1 217 */
231b9591 218 virtual wxColour GetColour() const;
23324ae1
FM
219
220 /**
221 Gets an array of dashes (defined as char in X, DWORD under Windows).
4cc4bfaf 222 @a dashes is a pointer to the internal array. Do not deallocate or store this
23324ae1 223 pointer.
74bf4e64
FM
224
225 @return The number of dashes associated with this pen.
8024723d 226
4cc4bfaf 227 @see SetDashes()
23324ae1 228 */
231b9591 229 virtual int GetDashes(wxDash** dashes) const;
23324ae1
FM
230
231 /**
74bf4e64
FM
232 Returns the pen join style, which may be one of @c wxJOIN_BEVEL, @c
233 wxJOIN_ROUND and @c wxJOIN_MITER.
234
235 The default is @c wxJOIN_ROUND.
8024723d 236
4cc4bfaf 237 @see SetJoin()
23324ae1 238 */
231b9591 239 virtual wxPenJoin GetJoin() const;
23324ae1
FM
240
241 /**
242 Gets a pointer to the stipple bitmap.
8024723d 243
4cc4bfaf 244 @see SetStipple()
23324ae1 245 */
231b9591 246 virtual wxBitmap* GetStipple() const;
23324ae1
FM
247
248 /**
249 Returns the pen style.
8024723d 250
4cc4bfaf 251 @see wxPen(), SetStyle()
23324ae1 252 */
231b9591 253 virtual wxPenStyle GetStyle() const;
23324ae1
FM
254
255 /**
256 Returns the pen width.
8024723d 257
4cc4bfaf 258 @see SetWidth()
23324ae1 259 */
231b9591 260 virtual int GetWidth() const;
23324ae1
FM
261
262 /**
263 Returns @true if the pen is initialised.
264 */
328f5751 265 bool IsOk() const;
23324ae1
FM
266
267 /**
74bf4e64
FM
268 Sets the pen cap style, which may be one of @c wxCAP_ROUND, @c wxCAP_PROJECTING
269 and @c wxCAP_BUTT. The default is @c wxCAP_ROUND.
8024723d 270
4cc4bfaf 271 @see GetCap()
23324ae1 272 */
231b9591 273 virtual void SetCap(wxPenCap capStyle);
23324ae1
FM
274
275 //@{
276 /**
277 The pen's colour is changed to the given colour.
8024723d 278
4cc4bfaf 279 @see GetColour()
23324ae1 280 */
231b9591
FM
281 virtual void SetColour(wxColour& colour);
282 virtual void SetColour(unsigned char red, unsigned char green, unsigned char blue);
23324ae1
FM
283 //@}
284
285 /**
286 Associates an array of pointers to dashes (defined as char in X, DWORD under
74bf4e64
FM
287 Windows) with the pen.
288
289 The array is not deallocated by wxPen, but neither must it be deallocated by
290 the calling application until the pen is deleted or this function is called
291 with a @NULL array.
8024723d 292
4cc4bfaf 293 @see GetDashes()
23324ae1 294 */
231b9591 295 virtual void SetDashes(int n, wxDash* dashes);
23324ae1
FM
296
297 /**
74bf4e64
FM
298 Sets the pen join style, which may be one of @c wxJOIN_BEVEL, @c wxJOIN_ROUND
299 and @c wxJOIN_MITER.
300
301 The default is @c wxJOIN_ROUND.
8024723d 302
4cc4bfaf 303 @see GetJoin()
23324ae1 304 */
231b9591 305 virtual void SetJoin(wxPenJoin join_style);
23324ae1
FM
306
307 /**
308 Sets the bitmap for stippling.
8024723d 309
4cc4bfaf 310 @see GetStipple()
23324ae1 311 */
231b9591 312 virtual void SetStipple(wxBitmap* stipple);
23324ae1
FM
313
314 /**
315 Set the pen style.
8024723d 316
4cc4bfaf 317 @see wxPen()
23324ae1 318 */
231b9591 319 virtual void SetStyle(wxPenStyle style);
23324ae1
FM
320
321 /**
322 Sets the pen width.
8024723d 323
4cc4bfaf 324 @see GetWidth()
23324ae1 325 */
231b9591 326 virtual void SetWidth(int width);
23324ae1
FM
327
328 /**
329 Inequality operator.
74bf4e64 330 See @ref overview_refcount_equality "reference-counted object comparison" for
23324ae1
FM
331 more info.
332 */
333 bool operator !=(const wxPen& pen);
334
335 /**
74bf4e64 336 Assignment operator, using @ref overview_refcount.
23324ae1
FM
337 */
338 wxPen operator =(const wxPen& pen);
339
340 /**
341 Equality operator.
74bf4e64 342 See @ref overview_refcount_equality "reference-counted object comparison" for
23324ae1
FM
343 more info.
344 */
345 bool operator ==(const wxPen& pen);
346};
e54c96f1 347
e54c96f1 348/**
231b9591 349 An empty pen.
e54c96f1
FM
350*/
351wxPen wxNullPen;
352
e54c96f1 353/**
231b9591 354 Red pen.
e54c96f1
FM
355*/
356wxPen wxRED_PEN;
357
358/**
231b9591 359 Cyan pen.
e54c96f1
FM
360*/
361wxPen wxCYAN_PEN;
362
363/**
231b9591 364 Green pen.
e54c96f1
FM
365*/
366wxPen wxGREEN_PEN;
367
368/**
231b9591 369 Black pen.
e54c96f1
FM
370*/
371wxPen wxBLACK_PEN;
372
373/**
231b9591 374 White pen.
e54c96f1
FM
375*/
376wxPen wxWHITE_PEN;
377
378/**
231b9591 379 Transparent pen.
e54c96f1
FM
380*/
381wxPen wxTRANSPARENT_PEN;
382
383/**
231b9591 384 Black dashed pen.
e54c96f1
FM
385*/
386wxPen wxBLACK_DASHED_PEN;
387
388/**
231b9591 389 Grey pen.
e54c96f1
FM
390*/
391wxPen wxGREY_PEN;
392
393/**
231b9591 394 Medium-grey pen.
e54c96f1
FM
395*/
396wxPen wxMEDIUM_GREY_PEN;
397
398/**
231b9591 399 Light-grey pen.
e54c96f1
FM
400*/
401wxPen wxLIGHT_GREY_PEN;
402
403
8024723d
FM
404
405/**
406 @class wxPenList
407 @wxheader{gdicmn.h}
408
409 There is only one instance of this class: ::wxThePenList.
410 Use this object to search for a previously created pen of the desired
411 type and create it if not already found. In some windowing systems,
412 the pen may be a scarce resource, so it can pay to reuse old
413 resources if possible. When an application finishes, all pens will
414 be deleted and their resources freed, eliminating the possibility of
415 'memory leaks'. However, it is best not to rely on this automatic
416 cleanup because it can lead to double deletion in some circumstances.
417
418 There are two mechanisms in recent versions of wxWidgets which make the
419 pen list less useful than it once was. Under Windows, scarce resources
420 are cleaned up internally if they are not being used. Also, a referencing
421 counting mechanism applied to all GDI objects means that some sharing
422 of underlying resources is possible. You don't have to keep track of pointers,
423 working out when it is safe delete a pen, because the referencing counting does
424 it for you. For example, you can set a pen in a device context, and then
425 immediately delete the pen you passed, because the pen is 'copied'.
426
427 So you may find it easier to ignore the pen list, and instead create
428 and copy pens as you see fit. If your Windows resource meter suggests
429 your application is using too many resources, you can resort to using
430 GDI lists to share objects explicitly.
431
432 The only compelling use for the pen list is for wxWidgets to keep
433 track of pens in order to clean them up on exit. It is also kept for
434 backward compatibility with earlier versions of wxWidgets.
435
436 @library{wxcore}
437 @category{gdi}
438
439 @stdobjects
440 ::wxThePenList
441
442 @see wxPen
443*/
444class wxPenList
445{
446public:
447 /**
448 Constructor. The application should not construct its own pen list:
449 use the object pointer ::wxThePenList.
450 */
451 wxPenList();
452
453 /**
454 Finds a pen with the specified attributes and returns it, else creates a
455 new pen, adds it to the pen list, and returns it.
456
457 @param colour
458 Colour object.
459 @param width
460 Width of pen.
461 @param style
462 Pen style. See ::wxPenStyle for a list of styles.
463 */
5d2d8f6a
VZ
464 wxPen* FindOrCreatePen(const wxColour& colour,
465 int width = 1,
466 wxPenStyle style = wxPENSTYLE_SOLID);
8024723d
FM
467};
468
469/**
470 The global list of wxPen objects ready to be re-used (for better performances).
471*/
472wxPenList* wxThePenList;
473