]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/pen.h
added wxCopyRectToRECT()
[wxWidgets.git] / include / wx / msw / pen.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/pen.h
3 // Purpose: wxPen class
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin: fixed operator=(), ==(), !=()
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PEN_H_
13 #define _WX_PEN_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "pen.h"
17 #endif
18
19 #include "wx/gdiobj.h"
20 #include "wx/bitmap.h"
21 #include "wx/colour.h"
22
23 typedef WXDWORD wxMSWDash;
24
25 class WXDLLEXPORT wxPen;
26
27 // VZ: this class should be made private
28 class WXDLLEXPORT wxPenRefData : public wxGDIRefData
29 {
30 public:
31 wxPenRefData();
32 wxPenRefData(const wxPenRefData& data);
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 }
48
49 protected:
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;
59
60 private:
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:
68 wxPenRefData& operator=(const wxPenRefData&);
69 };
70
71 #define M_PENDATA ((wxPenRefData *)m_refData)
72 #define wxPENDATA(x) ((wxPenRefData *)(x).m_refData)
73
74 // ----------------------------------------------------------------------------
75 // Pen
76 // ----------------------------------------------------------------------------
77
78 class WXDLLEXPORT wxPen : public wxGDIObject
79 {
80 public:
81 wxPen();
82 wxPen(const wxColour& col, int width = 1, int style = wxSOLID);
83 wxPen(const wxBitmap& stipple, int width);
84 wxPen(const wxPen& pen) : wxGDIObject(pen) { Ref(pen); }
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();
135 bool FreeResource(bool force = false);
136 WXHANDLE GetResourceHandle() const;
137 bool IsFree() const;
138 void Unshare();
139
140 private:
141 DECLARE_DYNAMIC_CLASS(wxPen)
142 };
143
144 #endif // _WX_PEN_H_
145