// Purpose: wxPen class
// Author: David Elliott
// Modified by:
-// Created: 22.03.2003
+// Created: 2003/08/02 (stubs from 22.03.2003)
// RCS-ID: $Id$
// Copyright: (c) 2003 David Elliott
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_PEN_H_
-#define _WX_PEN_H_
-
-#if defined(__GNUG__) && !defined(__APPLE__)
-#pragma interface "pen.h"
-#endif
+#ifndef __WX_COCOA_PEN_H__
+#define __WX_COCOA_PEN_H__
#include "wx/gdiobj.h"
-#include "wx/colour.h"
-#include "wx/bitmap.h"
-
-class WXDLLEXPORT wxPen;
-
-class WXDLLEXPORT wxPenRefData: public wxGDIRefData
-{
- friend class WXDLLEXPORT wxPen;
-public:
- wxPenRefData();
- wxPenRefData(const wxPenRefData& data);
- ~wxPenRefData();
+#include "wx/gdicmn.h"
- wxPenRefData& operator=(const wxPenRefData& data);
+class WXDLLEXPORT wxColour;
+class WXDLLEXPORT wxBitmap;
-protected:
- int m_width;
- int m_style;
- int m_join ;
- int m_cap ;
- wxBitmap m_stipple ;
- int m_nbDash ;
- wxDash * m_dash ;
- wxColour m_colour;
-/* TODO: implementation
- WXHPEN m_hPen;
-*/
-};
-
-#define M_PENDATA ((wxPenRefData *)m_refData)
-
-// Pen
+// ========================================================================
+// wxPen
+// ========================================================================
class WXDLLEXPORT wxPen: public wxGDIObject
{
- DECLARE_DYNAMIC_CLASS(wxPen)
+ DECLARE_DYNAMIC_CLASS(wxPen)
public:
- wxPen();
- wxPen(const wxColour& col, int width = 1, int style = wxSOLID);
- wxPen(const wxBitmap& stipple, int width);
- wxPen(const wxPen& pen)
- : wxGDIObject()
- { Ref(pen); }
- ~wxPen();
-
- inline wxPen& operator = (const wxPen& pen) { if (*this == pen) return (*this); Ref(pen); return *this; }
- inline bool operator == (const wxPen& pen) { return m_refData == pen.m_refData; }
- inline bool operator != (const wxPen& pen) { return m_refData != pen.m_refData; }
-
- virtual bool Ok() const { return (m_refData != NULL) ; }
-
- // Override in order to recreate the pen
- void SetColour(const wxColour& col) ;
- void SetColour(unsigned char r, unsigned char g, unsigned char b) ;
-
- void SetWidth(int width) ;
- void SetStyle(int style) ;
- void SetStipple(const wxBitmap& stipple) ;
- void SetDashes(int nb_dashes, const wxDash *dash) ;
- void SetJoin(int join) ;
- void SetCap(int cap) ;
-
- inline wxColour& GetColour() const { return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); };
- inline int GetWidth() const { return (M_PENDATA ? M_PENDATA->m_width : 0); };
- inline int GetStyle() const { return (M_PENDATA ? M_PENDATA->m_style : 0); };
- inline int GetJoin() const { return (M_PENDATA ? M_PENDATA->m_join : 0); };
- inline int GetCap() const { return (M_PENDATA ? M_PENDATA->m_cap : 0); };
- inline int GetDashes(wxDash **ptr) const {
- *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0);
- }
-
- inline wxBitmap *GetStipple() const { return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); };
-
-// Implementation
-
- // Useful helper: create the brush resource
- bool RealizeResource();
-
- // When setting properties, we must make sure we're not changing
- // another object
- void Unshare();
+ wxPen();
+ wxPen(const wxColour& col, int width = 1, int style = wxSOLID);
+ wxPen(const wxBitmap& stipple, int width);
+ wxPen(const wxPen& pen)
+ : wxGDIObject()
+ { Ref(pen); }
+ ~wxPen();
+
+ // wxObjectRefData
+ wxObjectRefData *CreateRefData() const;
+ wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
+
+ inline wxPen& operator = (const wxPen& pen)
+ { if (*this == pen) return (*this); Ref(pen); return *this; }
+ inline bool operator == (const wxPen& pen)
+ { return m_refData == pen.m_refData; }
+ inline bool operator != (const wxPen& pen)
+ { return m_refData != pen.m_refData; }
+
+ virtual bool Ok() const { return (m_refData != NULL) ; }
+
+ void SetColour(const wxColour& col) ;
+ void SetColour(unsigned char r, unsigned char g, unsigned char b) ;
+
+ void SetWidth(int width);
+ void SetStyle(int style);
+ void SetStipple(const wxBitmap& stipple);
+ void SetDashes(int nb_dashes, const wxDash *dash);
+ void SetJoin(int join);
+ void SetCap(int cap);
+
+ wxColour& GetColour() const;
+ int GetWidth() const;
+ int GetStyle() const;
+ int GetJoin() const;
+ int GetCap() const;
+ int GetDashes(wxDash **ptr) const;
+ wxBitmap *GetStipple() const;
+
+ WX_NSColor GetNSColor();
};
-#endif
- // _WX_PEN_H_
+#endif // __WX_COCOA_PEN_H__
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: src/cocoa/pen.mm
+// Purpose: wxPen
+// Author: David Elliott
+// Modified by:
+// Created: 2003/08/02
+// RCS-ID: $Id$
+// Copyright: (c) 2003 David Elliott
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#include "wx/setup.h"
+#include "wx/pen.h"
+#include "wx/bitmap.h"
+#include "wx/colour.h"
+
+#import <AppKit/NSColor.h>
+
+// ========================================================================
+// wxPenRefData
+// ========================================================================
+class WXDLLEXPORT wxPenRefData: public wxGDIRefData
+{
+ friend class WXDLLEXPORT wxPen;
+public:
+ wxPenRefData(const wxColour& colour = wxNullColour,
+ int width = 1, int style = wxSOLID,
+ const wxBitmap& stipple = wxNullBitmap);
+ wxPenRefData(const wxPenRefData& data);
+ ~wxPenRefData() { Free(); }
+
+ void SetWidth(int Width) { m_width = Width; }
+ void SetStyle(int Style) { m_style = Style; }
+ void SetJoin(int Join) { m_join = Join; }
+ void SetCap(int Cap) { m_cap = Cap; }
+ void SetColour(const wxColour& col) { Free(); m_colour = col; }
+ void SetDashes(int nb_dashes, const wxDash *Dash)
+ {
+ m_nbDash = nb_dashes;
+ m_dash = (wxDash *)Dash;
+ }
+ void SetStipple(const wxBitmap& Stipple)
+ {
+ Free();
+ m_stipple = Stipple;
+ m_style = wxSTIPPLE;
+ }
+ WX_NSColor GetNSColor();
+protected:
+ void Free();
+
+ int m_width;
+ int m_style;
+ int m_join;
+ int m_cap;
+ wxColour m_colour;
+ int m_nbDash;
+ wxDash *m_dash;
+ wxBitmap m_stipple;
+ WX_NSColor m_cocoaNSColor;
+private:
+ // Don't allow assignment
+ wxPenRefData& operator=(const wxPenRefData& data);
+};
+
+#define M_PENDATA ((wxPenRefData *)m_refData)
+
+inline wxPenRefData::wxPenRefData(const wxColour& colour,
+ int width, int style, const wxBitmap& stipple)
+{
+ m_width = width;
+ m_style = style;
+ m_join = wxJOIN_ROUND;
+ m_cap = wxCAP_ROUND;
+ m_colour = colour;
+ m_nbDash = 0;
+ m_dash = 0;
+ m_stipple = stipple;
+ m_cocoaNSColor = nil;
+}
+
+inline wxPenRefData::wxPenRefData(const wxPenRefData& data)
+{
+ m_width = data.m_width;
+ m_style = data.m_style;
+ m_join = data.m_join;
+ m_cap = data.m_cap;
+ m_colour = data.m_colour;
+ m_nbDash = data.m_nbDash;
+ m_dash = data.m_dash;
+ m_stipple = data.m_stipple;
+ m_cocoaNSColor = [data.m_cocoaNSColor retain];
+}
+
+inline void wxPenRefData::Free()
+{
+ [m_cocoaNSColor release];
+ m_cocoaNSColor = nil;
+}
+
+inline WX_NSColor wxPenRefData::GetNSColor()
+{
+ if(!m_cocoaNSColor)
+ {
+ switch( m_style )
+ {
+ case wxTRANSPARENT:
+ m_cocoaNSColor = [[NSColor clearColor] retain];
+ break;
+ case wxSTIPPLE:
+// wxBitmap isn't implemented yet
+// m_cocoaNSColor = [[NSColor colorWithPatternImage: m_stipple.GetNSImage()] retain];
+// break;
+ // The hatch brushes are going to be tricky
+ case wxBDIAGONAL_HATCH:
+ case wxCROSSDIAG_HATCH:
+ case wxFDIAGONAL_HATCH:
+ case wxCROSS_HATCH:
+ case wxHORIZONTAL_HATCH:
+ case wxVERTICAL_HATCH:
+ default:
+ // Dot/dashed pens use solid colors
+ case wxDOT:
+ case wxLONG_DASH:
+ case wxSHORT_DASH:
+ case wxDOT_DASH:
+ case wxUSER_DASH:
+ case wxSOLID:
+ NSColor *colour_NSColor = m_colour.GetNSColor();
+ if(!colour_NSColor)
+ colour_NSColor = [NSColor clearColor];
+ m_cocoaNSColor = [colour_NSColor copyWithZone:nil];
+ break;
+ }
+ }
+ return m_cocoaNSColor;
+}
+
+// ========================================================================
+// wxPen
+// ========================================================================
+IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
+
+wxPen::wxPen()
+{
+}
+
+wxPen::~wxPen()
+{
+}
+
+// Should implement Create
+wxPen::wxPen(const wxColour& colour, int width, int style)
+{
+ m_refData = new wxPenRefData(colour,width,style);
+}
+
+wxPen::wxPen(const wxBitmap& stipple, int width)
+{
+ m_refData = new wxPenRefData(wxNullColour,width,wxSTIPPLE,stipple);
+}
+
+wxObjectRefData *wxPen::CreateRefData() const
+{
+ return new wxPenRefData;
+}
+
+wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
+{
+ return new wxPenRefData(*(wxPenRefData *)data);
+}
+
+void wxPen::SetWidth(int Width)
+{
+ AllocExclusive();
+ M_PENDATA->SetWidth(Width);
+}
+
+void wxPen::SetStyle(int Style)
+{
+ AllocExclusive();
+ M_PENDATA->SetStyle(Style);
+}
+
+void wxPen::SetJoin(int Join)
+{
+ AllocExclusive();
+ M_PENDATA->SetJoin(Join);
+}
+
+void wxPen::SetCap(int Cap)
+{
+ AllocExclusive();
+ M_PENDATA->SetCap(Cap);
+}
+
+void wxPen::SetColour(const wxColour& col)
+{
+ AllocExclusive();
+ M_PENDATA->SetColour(col);
+}
+
+void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
+{
+ AllocExclusive();
+ M_PENDATA->SetColour(wxColour(r, g, b));
+}
+
+void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
+{
+ AllocExclusive();
+ M_PENDATA->SetDashes(nb_dashes, Dash);
+}
+
+void wxPen::SetStipple(const wxBitmap& Stipple)
+{
+ AllocExclusive();
+ M_PENDATA->SetStipple(Stipple);
+}
+
+wxColour& wxPen::GetColour() const
+{
+ return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour);
+}
+
+int wxPen::GetWidth() const
+{
+ return (M_PENDATA ? M_PENDATA->m_width : 0);
+}
+
+int wxPen::GetStyle() const
+{
+ return (M_PENDATA ? M_PENDATA->m_style : 0);
+}
+
+int wxPen::GetJoin() const
+{
+ return (M_PENDATA ? M_PENDATA->m_join : 0);
+}
+
+int wxPen::GetCap() const
+{
+ return (M_PENDATA ? M_PENDATA->m_cap : 0);
+}
+
+int wxPen::GetDashes(wxDash **ptr) const
+{
+ *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0);
+}
+
+wxBitmap *wxPen::GetStipple() const
+{
+ return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL);
+}
+
+WX_NSColor wxPen::GetNSColor()
+{
+ return (M_PENDATA ? M_PENDATA->GetNSColor() : nil);
+}
+