| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: wx/palmos/pen.h |
| 3 | // Purpose: wxPen class |
| 4 | // Author: William Osborne - minimal working wxPalmOS port |
| 5 | // Modified by: |
| 6 | // Created: 10/13/04 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) William Osborne |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifndef _WX_PEN_H_ |
| 13 | #define _WX_PEN_H_ |
| 14 | |
| 15 | #include "wx/gdiobj.h" |
| 16 | #include "wx/bitmap.h" |
| 17 | #include "wx/colour.h" |
| 18 | |
| 19 | typedef WXDWORD wxMSWDash; |
| 20 | |
| 21 | class WXDLLIMPEXP_FWD_CORE wxPen; |
| 22 | |
| 23 | // VZ: this class should be made private |
| 24 | class WXDLLEXPORT wxPenRefData : public wxGDIRefData |
| 25 | { |
| 26 | public: |
| 27 | wxPenRefData(); |
| 28 | wxPenRefData(const wxPenRefData& data); |
| 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.IsSameAs(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 | } |
| 44 | |
| 45 | protected: |
| 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; |
| 55 | |
| 56 | private: |
| 57 | friend class WXDLLIMPEXP_FWD_CORE 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: |
| 64 | wxPenRefData& operator=(const wxPenRefData&); |
| 65 | }; |
| 66 | |
| 67 | #define M_PENDATA ((wxPenRefData *)m_refData) |
| 68 | #define wxPENDATA(x) ((wxPenRefData *)(x).m_refData) |
| 69 | |
| 70 | // ---------------------------------------------------------------------------- |
| 71 | // Pen |
| 72 | // ---------------------------------------------------------------------------- |
| 73 | |
| 74 | class WXDLLEXPORT wxPen : public wxGDIObject |
| 75 | { |
| 76 | public: |
| 77 | wxPen(); |
| 78 | wxPen(const wxColour& col, int width = 1, int style = wxSOLID); |
| 79 | wxPen(const wxBitmap& stipple, int width); |
| 80 | virtual ~wxPen(); |
| 81 | |
| 82 | bool operator==(const wxPen& pen) const |
| 83 | { |
| 84 | const wxPenRefData *penData = (wxPenRefData *)pen.m_refData; |
| 85 | |
| 86 | // an invalid pen is only equal to another invalid pen |
| 87 | return m_refData ? penData && *M_PENDATA == *penData : !penData; |
| 88 | } |
| 89 | |
| 90 | bool operator!=(const wxPen& pen) const { return !(*this == pen); } |
| 91 | |
| 92 | virtual bool Ok() const { return IsOk(); } |
| 93 | virtual bool IsOk() 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 | wxColour& GetColour() const { return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); }; |
| 107 | int GetWidth() const { return (M_PENDATA ? M_PENDATA->m_width : 0); }; |
| 108 | int GetStyle() const { return (M_PENDATA ? M_PENDATA->m_style : 0); }; |
| 109 | int GetJoin() const { return (M_PENDATA ? M_PENDATA->m_join : 0); }; |
| 110 | int GetCap() const { return (M_PENDATA ? M_PENDATA->m_cap : 0); }; |
| 111 | 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 | private: |
| 129 | DECLARE_DYNAMIC_CLASS(wxPen) |
| 130 | }; |
| 131 | |
| 132 | #endif // _WX_PEN_H_ |