]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
5c57bf07 | 2 | // Name: wx/pen.h |
2bda0e17 KB |
3 | // Purpose: wxPen class |
4 | // Author: Julian Smart | |
5c57bf07 | 5 | // Modified by: Vadim Zeitlin: fixed operator=(), ==(), !=() |
2bda0e17 KB |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
bbcdf8bc | 8 | // Copyright: (c) Julian Smart |
078cf5cb | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_PEN_H_ |
13 | #define _WX_PEN_H_ | |
2bda0e17 | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
5c57bf07 | 16 | #pragma interface "pen.h" |
2bda0e17 KB |
17 | #endif |
18 | ||
19 | #include "wx/gdiobj.h" | |
2432b92d | 20 | #include "wx/bitmap.h" |
ed39ff57 | 21 | #include "wx/colour.h" |
2bda0e17 | 22 | |
236a9de3 | 23 | typedef WXDWORD wxMSWDash; |
2bda0e17 KB |
24 | |
25 | class WXDLLEXPORT wxPen; | |
26 | ||
5c57bf07 VZ |
27 | // VZ: this class should be made private |
28 | class WXDLLEXPORT wxPenRefData : public wxGDIRefData | |
2bda0e17 | 29 | { |
2bda0e17 | 30 | public: |
e4a81a2e | 31 | wxPenRefData(); |
b823f5a1 | 32 | wxPenRefData(const wxPenRefData& data); |
5c57bf07 VZ |
33 | virtual ~wxPenRefData(); |
34 | ||
35 | bool operator==(const wxPenRefData& data) const | |
36 | { | |
37 | // we intentionally don't compare m_hPen fields here | |
38 | return m_style == data.m_style && | |
39 | m_width == data.m_width && | |
40 | m_join == data.m_join && | |
41 | m_cap == data.m_cap && | |
42 | m_colour == data.m_colour && | |
43 | (m_style != wxSTIPPLE || m_stipple == data.m_stipple) && | |
44 | (m_style != wxUSER_DASH || | |
45 | (m_nbDash == data.m_nbDash && | |
46 | memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); | |
47 | } | |
2bda0e17 KB |
48 | |
49 | protected: | |
5c57bf07 VZ |
50 | int m_width; |
51 | int m_style; | |
52 | int m_join; | |
53 | int m_cap; | |
54 | wxBitmap m_stipple; | |
55 | int m_nbDash; | |
56 | wxDash * m_dash; | |
57 | wxColour m_colour; | |
58 | WXHPEN m_hPen; | |
22f3361e VZ |
59 | |
60 | private: | |
5c57bf07 VZ |
61 | friend class WXDLLEXPORT wxPen; |
62 | ||
63 | // Cannot use | |
64 | // DECLARE_NO_COPY_CLASS(wxPenRefData) | |
65 | // because copy constructor is explicitly declared above; | |
66 | // but no copy assignment operator is defined, so declare | |
67 | // it private to prevent the compiler from defining it: | |
22f3361e | 68 | wxPenRefData& operator=(const wxPenRefData&); |
2bda0e17 KB |
69 | }; |
70 | ||
71 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
e2a5251d | 72 | #define wxPENDATA(x) ((wxPenRefData *)(x).m_refData) |
2bda0e17 | 73 | |
5c57bf07 | 74 | // ---------------------------------------------------------------------------- |
2bda0e17 | 75 | // Pen |
5c57bf07 VZ |
76 | // ---------------------------------------------------------------------------- |
77 | ||
78 | class WXDLLEXPORT wxPen : public wxGDIObject | |
2bda0e17 | 79 | { |
2bda0e17 | 80 | public: |
5c57bf07 VZ |
81 | wxPen(); |
82 | wxPen(const wxColour& col, int width = 1, int style = wxSOLID); | |
83 | wxPen(const wxBitmap& stipple, int width); | |
4dddb8a2 | 84 | wxPen(const wxPen& pen) : wxGDIObject(pen) { Ref(pen); } |
5c57bf07 VZ |
85 | virtual ~wxPen(); |
86 | ||
87 | wxPen& operator=(const wxPen& pen) | |
88 | { | |
89 | if ( this != &pen ) | |
90 | Ref(pen); | |
91 | ||
92 | return *this; | |
93 | } | |
94 | ||
95 | bool operator==(const wxPen& pen) const | |
96 | { | |
97 | const wxPenRefData *penData = (wxPenRefData *)pen.m_refData; | |
98 | ||
99 | // an invalid pen is only equal to another invalid pen | |
100 | return m_refData ? penData && *M_PENDATA == *penData : !penData; | |
101 | } | |
102 | ||
103 | bool operator!=(const wxPen& pen) const { return !(*this == pen); } | |
104 | ||
105 | virtual bool Ok() const { return (m_refData != NULL); } | |
106 | ||
107 | // Override in order to recreate the pen | |
108 | void SetColour(const wxColour& col); | |
109 | void SetColour(unsigned char r, unsigned char g, unsigned char b); | |
110 | ||
111 | void SetWidth(int width); | |
112 | void SetStyle(int style); | |
113 | void SetStipple(const wxBitmap& stipple); | |
114 | void SetDashes(int nb_dashes, const wxDash *dash); | |
115 | void SetJoin(int join); | |
116 | void SetCap(int cap); | |
117 | ||
118 | wxColour& GetColour() const { return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); }; | |
119 | int GetWidth() const { return (M_PENDATA ? M_PENDATA->m_width : 0); }; | |
120 | int GetStyle() const { return (M_PENDATA ? M_PENDATA->m_style : 0); }; | |
121 | int GetJoin() const { return (M_PENDATA ? M_PENDATA->m_join : 0); }; | |
122 | int GetCap() const { return (M_PENDATA ? M_PENDATA->m_cap : 0); }; | |
123 | int GetDashes(wxDash **ptr) const | |
124 | { | |
125 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); | |
126 | return (M_PENDATA ? M_PENDATA->m_nbDash : 0); | |
127 | } | |
128 | wxDash* GetDash() const { return (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*)NULL); }; | |
129 | inline int GetDashCount() const { return (M_PENDATA ? M_PENDATA->m_nbDash : 0); }; | |
130 | ||
131 | inline wxBitmap *GetStipple() const { return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); }; | |
132 | ||
133 | // Internal | |
134 | bool RealizeResource(); | |
078cf5cb | 135 | bool FreeResource(bool force = false); |
5c57bf07 VZ |
136 | WXHANDLE GetResourceHandle() const; |
137 | bool IsFree() const; | |
138 | void Unshare(); | |
139 | ||
140 | private: | |
141 | DECLARE_DYNAMIC_CLASS(wxPen) | |
2bda0e17 KB |
142 | }; |
143 | ||
5c57bf07 | 144 | #endif // _WX_PEN_H_ |
2bda0e17 | 145 |