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