]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: pen.h | |
3 | // Purpose: wxPen class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
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 | class WXDLLEXPORT wxPenRefData: public wxGDIRefData | |
28 | { | |
29 | friend class WXDLLEXPORT wxPen; | |
30 | public: | |
31 | wxPenRefData(); | |
32 | wxPenRefData(const wxPenRefData& data); | |
33 | ~wxPenRefData(); | |
34 | ||
35 | protected: | |
36 | int m_width; | |
37 | int m_style; | |
38 | int m_join ; | |
39 | int m_cap ; | |
40 | wxBitmap m_stipple ; | |
41 | int m_nbDash ; | |
42 | wxDash * m_dash ; | |
43 | wxColour m_colour; | |
44 | WXHPEN m_hPen; | |
45 | ||
46 | private: | |
47 | // Cannot use | |
48 | // DECLARE_NO_COPY_CLASS(wxPenRefData) | |
49 | // because copy constructor is explicitly declared above; | |
50 | // but no copy assignment operator is defined, so declare | |
51 | // it private to prevent the compiler from defining it: | |
52 | wxPenRefData& operator=(const wxPenRefData&); | |
53 | }; | |
54 | ||
55 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
56 | #define wxPENDATA(x) ((wxPenRefData *)(x).m_refData) | |
57 | ||
58 | // Pen | |
59 | class WXDLLEXPORT wxPen: public wxGDIObject | |
60 | { | |
61 | DECLARE_DYNAMIC_CLASS(wxPen) | |
62 | public: | |
63 | wxPen(); | |
64 | wxPen(const wxColour& col, int width = 1, int style = wxSOLID); | |
65 | wxPen(const wxBitmap& stipple, int width); | |
66 | inline wxPen(const wxPen& pen) { Ref(pen); } | |
67 | ~wxPen(); | |
68 | ||
69 | inline wxPen& operator = (const wxPen& pen) { if (*this == pen) return (*this); Ref(pen); return *this; } | |
70 | inline bool operator == (const wxPen& pen) const | |
71 | { | |
72 | // It is impossible to know if the user dashes have changed, | |
73 | // so we must assume that they have | |
74 | if ( m_refData && pen.m_refData ) | |
75 | { | |
76 | if ( M_PENDATA->m_nbDash != 0 || wxPENDATA(pen)->m_nbDash != 0 ) | |
77 | return false; | |
78 | } | |
79 | return m_refData == pen.m_refData; | |
80 | } | |
81 | inline bool operator != (const wxPen& pen) const | |
82 | { | |
83 | // It is impossible to know if the user dashes have changed, | |
84 | // so we must assume that they have | |
85 | if ( m_refData && pen.m_refData ) | |
86 | { | |
87 | if ( M_PENDATA->m_nbDash != 0 || wxPENDATA(pen)->m_nbDash != 0 ) | |
88 | return true; | |
89 | } | |
90 | return m_refData != pen.m_refData; | |
91 | } | |
92 | ||
93 | virtual bool Ok() const { return (m_refData != NULL) ; } | |
94 | ||
95 | // Override in order to recreate the pen | |
96 | void SetColour(const wxColour& col) ; | |
97 | void SetColour(unsigned char r, unsigned char g, unsigned char b); | |
98 | ||
99 | void SetWidth(int width) ; | |
100 | void SetStyle(int style) ; | |
101 | void SetStipple(const wxBitmap& stipple) ; | |
102 | void SetDashes(int nb_dashes, const wxDash *dash) ; | |
103 | void SetJoin(int join) ; | |
104 | void SetCap(int cap) ; | |
105 | ||
106 | inline wxColour& GetColour() const { return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); }; | |
107 | inline int GetWidth() const { return (M_PENDATA ? M_PENDATA->m_width : 0); }; | |
108 | inline int GetStyle() const { return (M_PENDATA ? M_PENDATA->m_style : 0); }; | |
109 | inline int GetJoin() const { return (M_PENDATA ? M_PENDATA->m_join : 0); }; | |
110 | inline int GetCap() const { return (M_PENDATA ? M_PENDATA->m_cap : 0); }; | |
111 | inline int GetDashes(wxDash **ptr) const | |
112 | { | |
113 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); | |
114 | return (M_PENDATA ? M_PENDATA->m_nbDash : 0); | |
115 | } | |
116 | wxDash* GetDash() const { return (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*)NULL); }; | |
117 | inline int GetDashCount() const { return (M_PENDATA ? M_PENDATA->m_nbDash : 0); }; | |
118 | ||
119 | inline wxBitmap *GetStipple() const { return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); }; | |
120 | ||
121 | // Internal | |
122 | bool RealizeResource(); | |
123 | bool FreeResource(bool force = FALSE); | |
124 | WXHANDLE GetResourceHandle() const; | |
125 | bool IsFree() const; | |
126 | void Unshare(); | |
127 | }; | |
128 | ||
129 | int wx2msPenStyle(int wx_style); | |
130 | ||
131 | #endif | |
132 | // _WX_PEN_H_ |