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