#ifndef _WX_BRUSH_H_
#define _WX_BRUSH_H_
-#include "wx/gdicmn.h"
-#include "wx/gdiobj.h"
-#include "wx/bitmap.h"
-
-class WXDLLIMPEXP_FWD_CORE wxBrush;
-
-class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
-{
- friend class WXDLLIMPEXP_FWD_CORE wxBrush;
-public:
- wxBrushRefData();
- wxBrushRefData(const wxBrushRefData& rData);
- virtual ~wxBrushRefData();
-
- bool operator == (const wxBrushRefData& data) const
- {
- return (m_nStyle == data.m_nStyle &&
- m_vStipple.IsSameAs(data.m_vStipple) &&
- m_vColour == data.m_vColour);
- }
-
-protected:
- wxBrushStyle m_nStyle;
- wxBitmap m_vStipple;
- wxColour m_vColour;
- WXHBRUSH m_hBrush; // in OS/2 GPI this will be the PS the pen is associated with
- AREABUNDLE m_vBundle;
-};
-
-#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
+class WXDLLIMPEXP_FWD_CORE wxColour;
+class WXDLLIMPEXP_FWD_CORE wxBitmap;
// Brush
class WXDLLEXPORT wxBrush: public wxBrushBase
virtual void SetStyle(wxBrushStyle nStyle);
virtual void SetStipple(const wxBitmap& rStipple);
- inline wxColour& GetColour(void) const { return (M_BRUSHDATA ? M_BRUSHDATA->m_vColour : wxNullColour); };
- virtual wxBrushStyle GetStyle(void) const { return (M_BRUSHDATA ? M_BRUSHDATA->m_nStyle : wxBRUSHSTYLE_INVALID); };
- inline wxBitmap* GetStipple(void) const { return (M_BRUSHDATA ? & M_BRUSHDATA->m_vStipple : NULL); };
- inline int GetPS(void) const { return (M_BRUSHDATA ? M_BRUSHDATA->m_hBrush : 0); };
+ wxColour GetColour(void) const;
+ virtual wxBrushStyle GetStyle(void) const;
+ wxBitmap* GetStipple(void) const;
+ int GetPS(void) const;
//
// Implementation
typedef long wxPMDash;
-class WXDLLIMPEXP_FWD_CORE wxPen;
-
-class WXDLLEXPORT wxPenRefData: public wxGDIRefData
-{
- friend class WXDLLIMPEXP_FWD_CORE wxPen;
-public:
- wxPenRefData();
- wxPenRefData(const wxPenRefData& rData);
- virtual ~wxPenRefData();
-
- bool operator==(const wxPenRefData& data) const
- {
- // we intentionally don't compare m_hPen fields here
- return m_nStyle == data.m_nStyle &&
- m_nWidth == data.m_nWidth &&
- m_nJoin == data.m_nJoin &&
- m_nCap == data.m_nCap &&
- m_vColour == data.m_vColour &&
- (m_nStyle != wxPENSTYLE_STIPPLE || m_vStipple.IsSameAs(data.m_vStipple)) &&
- (m_nStyle != wxPENSTYLE_USER_DASH ||
- (m_dash == data.m_dash &&
- memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0));
- }
-
-protected:
- int m_nWidth;
- wxPenStyle m_nStyle;
- wxPenJoin m_nJoin;
- wxPenCap m_nCap;
- wxBitmap m_vStipple;
- int m_nbDash;
- wxDash * m_dash;
- wxColour m_vColour;
- WXHPEN m_hPen;// in OS/2 GPI this will be the PS the pen is associated with
-};
-
-#define M_PENDATA ((wxPenRefData *)m_refData)
-
+// ----------------------------------------------------------------------------
// Pen
+// ----------------------------------------------------------------------------
+
class WXDLLEXPORT wxPen : public wxPenBase
{
public:
- wxPen();
+ wxPen() { }
wxPen( const wxColour& rColour
,int nWidth = 1
,wxPenStyle nStyle = wxPENSTYLE_SOLID
wxPen( const wxBitmap& rStipple
,int nWidth
);
- virtual ~wxPen();
-
- inline bool operator == (const wxPen& rPen) const
- {
- const wxPenRefData *penData = (wxPenRefData *)rPen.m_refData;
-
- // an invalid pen is only equal to another invalid pen
- return m_refData ? penData && *M_PENDATA == *penData : !penData;
- }
+ virtual ~wxPen() { }
+ bool operator == (const wxPen& rPen) const;
inline bool operator != (const wxPen& rPen) const
{ return !(*this == rPen); }
void SetCap(wxPenCap nCap);
void SetPS(HPS hPS);
- inline wxColour& GetColour(void) const { return (M_PENDATA ? M_PENDATA->m_vColour : wxNullColour); };
- inline int GetWidth(void) const { return (M_PENDATA ? M_PENDATA->m_nWidth : -1); };
- inline wxPenStyle GetStyle(void) const { return (M_PENDATA ? M_PENDATA->m_nStyle : wxPENSTYLE_INVALID); };
- inline wxPenJoin GetJoin(void) const { return (M_PENDATA ? M_PENDATA->m_nJoin : wxJOIN_INVALID); };
- inline wxPenCap GetCap(void) const { return (M_PENDATA ? M_PENDATA->m_nCap : wxCAP_INVALID); };
- inline int GetPS(void) const { return (M_PENDATA ? M_PENDATA->m_hPen : 0); };
- inline int GetDashes(wxDash **ptr) const
- {
- *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
- return (M_PENDATA ? M_PENDATA->m_nbDash : -1);
- }
- inline wxDash* GetDash() const { return (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*)NULL); };
- inline int GetDashCount() const { return (M_PENDATA ? M_PENDATA->m_nbDash : 0); };
-
- inline wxBitmap* GetStipple(void) const { return (M_PENDATA ? (& M_PENDATA->m_vStipple) : (wxBitmap*) NULL); };
+ wxColour& GetColour(void) const;
+ int GetWidth(void) const;
+ wxPenStyle GetStyle(void) const;
+ wxPenJoin GetJoin(void) const;
+ wxPenCap GetCap(void) const;
+ int GetPS(void) const;
+ int GetDashes(wxDash **ptr) const;
+ wxDash* GetDash() const;
+ int GetDashCount() const;
+ wxBitmap* GetStipple(void) const;
//
// Implementation
#include "wx/os2/private.h"
-#include "assert.h"
+class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
+{
+ friend class WXDLLIMPEXP_FWD_CORE wxBrush;
+public:
+ wxBrushRefData(const wxColour& colour = wxNullColour, wxBrushStyle style = wxBRUSHSTYLE_SOLID);
+ wxBrushRefData(const wxBitmap& stipple);
+ wxBrushRefData(const wxBrushRefData& rData);
+ virtual ~wxBrushRefData();
+
+ bool operator == (const wxBrushRefData& data) const
+ {
+ return (m_nStyle == data.m_nStyle &&
+ m_vStipple.IsSameAs(data.m_vStipple) &&
+ m_vColour == data.m_vColour);
+ }
+
+protected:
+ wxBrushStyle m_nStyle;
+ wxBitmap m_vStipple;
+ wxColour m_vColour;
+ WXHBRUSH m_hBrush; // in OS/2 GPI this will be the PS the pen is associated with
+ AREABUNDLE m_vBundle;
+};
+
+#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
+
+// ============================================================================
+// wxBrushRefData implementation
+// ============================================================================
IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
-wxBrushRefData::wxBrushRefData()
+// ----------------------------------------------------------------------------
+// wxBrushRefData ctors/dtor
+// ----------------------------------------------------------------------------
+
+wxBrushRefData::wxBrushRefData(const wxColour& colour, wxBrushStyle style)
+ : m_vColour(colour)
{
- m_nStyle = wxSOLID;
+ m_nStyle = style;
m_hBrush = 0;
memset(&m_vBundle, '\0', sizeof(AREABUNDLE));
} // end of wxBrushRefData::wxBrushRefData
+wxBrushRefData::wxBrushRefData(const wxBitmap& stipple)
+{
+ m_vStipple = stipple;
+ m_nStyle = stipple.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
+ : wxBRUSHSTYLE_STIPPLE;
+
+ m_hBrush = NULL;
+ memset(&m_vBundle, '\0', sizeof(AREABUNDLE));
+}
+
wxBrushRefData::wxBrushRefData(const wxBrushRefData& rData)
+ : wxGDIRefData(),
+ m_vStipple(rData.m_vStipple),
+ m_vColour(rData.m_vColour)
{
m_nStyle = rData.m_nStyle;
- m_vStipple = rData.m_vStipple;
- m_vColour = rData.m_vColour;
m_hBrush = 0;
memcpy(&m_vBundle, &rData.m_vBundle, sizeof(AREABUNDLE));
} // end of wxBrushRefData::wxBrushRefData
{
} // end of wxBrushRefData::~wxBrushRefData
-//
-// Brushes
-//
+// ============================================================================
+// wxBrush implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxBrush ctors/dtor
+// ----------------------------------------------------------------------------
+
wxBrush::wxBrush()
{
} // end of wxBrush::wxBrush
, wxBrushStyle nStyle
)
{
- m_refData = new wxBrushRefData;
-
- M_BRUSHDATA->m_vColour = rColour;
- M_BRUSHDATA->m_nStyle = nStyle;
- M_BRUSHDATA->m_hBrush = 0;
- memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
+ m_refData = new wxBrushRefData(rColour, nStyle);
RealizeResource();
} // end of wxBrush::wxBrush
#if FUTURE_WXWIN_COMPATIBILITY_3_0
wxBrush::wxBrush(const wxColour& col, int style)
{
- m_refData = new wxBrushRefData;
-
- M_BRUSHDATA->m_vColour = col;
- M_BRUSHDATA->m_nStyle = (wxBrushStyle)style;
- M_BRUSHDATA->m_hBrush = 0;
- memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
+ m_refData = new wxBrushRefData(col, (wxBrushStyle)style);
RealizeResource();
}
wxBrush::wxBrush(const wxBitmap& rStipple)
{
- m_refData = new wxBrushRefData;
-
- M_BRUSHDATA->m_nStyle = wxSTIPPLE;
- M_BRUSHDATA->m_vStipple = rStipple;
- M_BRUSHDATA->m_hBrush = 0;
- memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
+ m_refData = new wxBrushRefData(rStipple);
RealizeResource();
} // end of wxBrush::wxBrush
return false;
} // end of wxBrush::RealizeResource
+// ----------------------------------------------------------------------------
+// wxBrush accessors
+// ----------------------------------------------------------------------------
+
+wxColour wxBrush::GetColour() const
+{
+ wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") );
+
+ return M_BRUSHDATA->m_vColour;
+}
+
+wxBrushStyle wxBrush::GetStyle() const
+{
+ wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID, _T("invalid brush") );
+
+ return M_BRUSHDATA->m_nStyle;
+}
+
+wxBitmap *wxBrush::GetStipple() const
+{
+ wxCHECK_MSG( Ok(), NULL, _T("invalid brush") );
+
+ return &(M_BRUSHDATA->m_vStipple);
+}
+
+int wxBrush::GetPS() const
+{
+ wxCHECK_MSG( Ok(), 0, _T("invalid brush") );
+
+ return M_BRUSHDATA->m_hBrush;
+}
+
WXHANDLE wxBrush::GetResourceHandle() const
{
- if (!M_BRUSHDATA)
- return 0;
+ wxCHECK_MSG( Ok(), 0, _T("invalid brush") );
+
return (WXHANDLE)M_BRUSHDATA->m_hBrush;
} // end of wxBrush::GetResourceHandle
return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
} // end of wxBrush::IsFree
+// ----------------------------------------------------------------------------
+// wxBrush setters
+// ----------------------------------------------------------------------------
+
void wxBrush::SetColour( const wxColour& rColour )
{
AllocExclusive();
RealizeResource();
} // end of WxWinGdi_CPen::SetPS
+// ----------------------------------------------------------------------------
+// wxBrush house keeping stuff
+// ----------------------------------------------------------------------------
bool wxBrush::operator == (
const wxBrush& brush
#endif
#include "wx/os2/private.h"
-#include "assert.h"
-IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
+class WXDLLIMPEXP_FWD_CORE wxPen;
+
+// ----------------------------------------------------------------------------
+// wxPenRefData: contains information about an HPEN and its handle
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxPenRefData: public wxGDIRefData
+{
+ friend class WXDLLIMPEXP_FWD_CORE wxPen;
+public:
+ wxPenRefData();
+ wxPenRefData(const wxPenRefData& rData);
+ wxPenRefData(const wxColour& col, int width, wxPenStyle style);
+ wxPenRefData(const wxBitmap& stipple, int width);
+ virtual ~wxPenRefData();
+
+ bool operator==(const wxPenRefData& data) const
+ {
+ // we intentionally don't compare m_hPen fields here
+ return m_nStyle == data.m_nStyle &&
+ m_nWidth == data.m_nWidth &&
+ m_nJoin == data.m_nJoin &&
+ m_nCap == data.m_nCap &&
+ m_vColour == data.m_vColour &&
+ (m_nStyle != wxPENSTYLE_STIPPLE || m_vStipple.IsSameAs(data.m_vStipple)) &&
+ (m_nStyle != wxPENSTYLE_USER_DASH ||
+ (m_dash == data.m_dash &&
+ memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0));
+ }
+
+private:
+ // initialize the fields which have reasonable default values
+ //
+ // doesn't initialize m_width and m_style which must be initialize in ctor
+ void Init()
+ {
+ m_nJoin = wxJOIN_ROUND;
+ m_nCap = wxCAP_ROUND;
+ m_nbDash = 0;
+ m_dash = NULL;
+ m_hPen = 0;
+ }
+
+ int m_nWidth;
+ wxPenStyle m_nStyle;
+ wxPenJoin m_nJoin;
+ wxPenCap m_nCap;
+ wxBitmap m_vStipple;
+ int m_nbDash;
+ wxDash * m_dash;
+ wxColour m_vColour;
+ WXHPEN m_hPen;// in OS/2 GPI this will be the PS the pen is associated with
+
+ DECLARE_NO_ASSIGN_CLASS(wxPenRefData)
+};
+
+#define M_PENDATA ((wxPenRefData *)m_refData)
+
+// ----------------------------------------------------------------------------
+// wxPenRefData ctors/dtor
+// ----------------------------------------------------------------------------
wxPenRefData::wxPenRefData()
{
+ Init();
+
m_nStyle = wxPENSTYLE_SOLID;
m_nWidth = 1;
- m_nJoin = wxJOIN_ROUND ;
- m_nCap = wxCAP_ROUND ;
- m_nbDash = 0 ;
- m_dash = (wxDash*)NULL;
- m_hPen = 0L;
} // end of wxPenRefData::wxPenRefData
wxPenRefData::wxPenRefData(
m_hPen = 0L;
} // end of wxPenRefData::wxPenRefData
-wxPenRefData::~wxPenRefData()
+wxPenRefData::wxPenRefData(const wxColour& col, int width, wxPenStyle style)
{
-} // end of wxPenRefData::~wxPenRefData
+ Init();
+
+ m_nStyle = style;
+ m_nWidth = width;
-//
-// Pens
-//
-wxPen::wxPen()
+ m_vColour = col;
+}
+
+wxPenRefData::wxPenRefData(const wxBitmap& stipple, int width)
{
-} // end of wxPen::wxPen
+ Init();
+
+ m_nStyle = wxPENSTYLE_STIPPLE;
+ m_nWidth = width;
+
+ m_vStipple = stipple;
+}
-wxPen::~wxPen()
+wxPenRefData::~wxPenRefData()
{
-} // end of wxPen::wxPen
+} // end of wxPenRefData::~wxPenRefData
+
+// ----------------------------------------------------------------------------
+// wxPen
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
-// Should implement Create
wxPen::wxPen(
const wxColour& rColour
, int nWidth
, wxPenStyle nStyle
)
{
- m_refData = new wxPenRefData;
-
- M_PENDATA->m_vColour = rColour;
- M_PENDATA->m_nWidth = nWidth;
- M_PENDATA->m_nStyle = nStyle;
- M_PENDATA->m_nJoin = wxJOIN_ROUND ;
- M_PENDATA->m_nCap = wxCAP_ROUND ;
- M_PENDATA->m_hPen = 0L;
+ m_refData = new wxPenRefData(rColour, nWidth, nStyle);
RealizeResource();
} // end of wxPen::wxPen
#if FUTURE_WXWIN_COMPATIBILITY_3_0
wxPen::wxPen(const wxColour& colour, int width, int style)
{
- m_refData = new wxPenRefData;
-
- M_PENDATA->m_vColour = colour;
- M_PENDATA->m_nWidth = width;
- M_PENDATA->m_nStyle = (wxPenStyle)nStyle;
- M_PENDATA->m_nJoin = wxJOIN_ROUND ;
- M_PENDATA->m_nCap = wxCAP_ROUND ;
- M_PENDATA->m_hPen = 0L;
+ m_refData = new wxPenRefData(colour, width, (wxPenStyle)style);
RealizeResource();
}
, int nWidth
)
{
- m_refData = new wxPenRefData;
-
- M_PENDATA->m_vStipple = rStipple;
- M_PENDATA->m_nWidth = nWidth;
- M_PENDATA->m_nStyle = wxSTIPPLE;
- M_PENDATA->m_nJoin = wxJOIN_ROUND ;
- M_PENDATA->m_nCap = wxCAP_ROUND ;
- M_PENDATA->m_hPen = 0;
+ m_refData = new wxPenRefData (rStipple, nWidth);
RealizeResource();
} // end of wxPen::wxPen
{
AllocExclusive();
M_PENDATA->m_vStipple = rStipple;
- M_PENDATA->m_nStyle = wxSTIPPLE;
+ M_PENDATA->m_nStyle = wxPENSTYLE_STIPPLE;
RealizeResource();
} // end of wxPen::SetStipple
RealizeResource();
} // end of wxPen::SetCap
+wxColour& wxPen::GetColour() const
+{
+ wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
+
+ return M_PENDATA->m_vColour;
+}
+
+int wxPen::GetWidth() const
+{
+ wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
+
+ return M_PENDATA->m_nWidth;
+}
+
+wxPenStyle wxPen::GetStyle() const
+{
+ wxCHECK_MSG( Ok(), wxPENSTYLE_INVALID, wxT("invalid pen") );
+
+ return M_PENDATA->m_nStyle;
+}
+
+wxPenJoin wxPen::GetJoin() const
+{
+ wxCHECK_MSG( Ok(), wxJOIN_INVALID, wxT("invalid pen") );
+
+ return M_PENDATA->m_nJoin;
+}
+
+wxPenCap wxPen::GetCap() const
+{
+ wxCHECK_MSG( Ok(), wxCAP_INVALID, wxT("invalid pen") );
+
+ return M_PENDATA->m_nCap;
+}
+
+int wxPen::GetPS() const
+{
+ wxCHECK_MSG( Ok(), 0, wxT("invalid pen") );
+
+ return M_PENDATA->m_hPen;
+}
+
+int wxPen::GetDashes(wxDash** ptr) const
+{
+ wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
+
+ *ptr = M_PENDATA->m_dash;
+ return M_PENDATA->m_nbDash;
+}
+
+wxDash* wxPen::GetDash() const
+{
+ wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
+
+ return M_PENDATA->m_dash;
+}
+
+int wxPen::GetDashCount() const
+{
+ wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
+
+ return M_PENDATA->m_nbDash;
+}
+
+wxBitmap* wxPen::GetStipple() const
+{
+ wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
+
+ return &(M_PENDATA->m_vStipple);
+}
+
int wx2os2PenStyle(
wxPenStyle nWxStyle
)