From f162a338013ec8be1f2fe29a0111a07cdcb0c5e9 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 7 Jul 2003 18:53:00 +0000 Subject: [PATCH] First hack at wxBrush for wxCocoa git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21747 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build/bakefiles/files.bkl | 2 +- include/wx/cocoa/brush.h | 89 ++++++++-------- src/cocoa/brush.cpp | 122 --------------------- src/cocoa/brush.mm | 216 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 264 insertions(+), 165 deletions(-) delete mode 100644 src/cocoa/brush.cpp create mode 100644 src/cocoa/brush.mm diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index f7f99d1fcc..54b60437f4 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1467,7 +1467,7 @@ src/cocoa/app.mm src/cocoa/bmpbuttn.mm src/cocoa/bitmap.mm - src/cocoa/brush.cpp + src/cocoa/brush.mm src/cocoa/button.mm src/cocoa/checkbox.mm src/cocoa/checklst.mm diff --git a/include/wx/cocoa/brush.h b/include/wx/cocoa/brush.h index 205e7b7a2d..28e4efa76f 100644 --- a/include/wx/cocoa/brush.h +++ b/include/wx/cocoa/brush.h @@ -1,20 +1,16 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: brush.h +// Name: include/wx/cocoa/brush.h // Purpose: wxBrush class -// Author: AUTHOR +// Author: David Elliott // Modified by: -// Created: ??/??/98 +// Created: 2003/07/03 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR +// Copyright: (c) 2003 David Elliott // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_BRUSH_H_ -#define _WX_BRUSH_H_ - -#if defined(__GNUG__) && !defined(__APPLE__) -#pragma interface "brush.h" -#endif +#ifndef __WX_COCOA_BRUSH_H__ +#define __WX_COCOA_BRUSH_H__ #include "wx/gdicmn.h" #include "wx/gdiobj.h" @@ -22,47 +18,56 @@ class WXDLLEXPORT wxBrush; -// Brush +// ======================================================================== +// wxBrush +// ======================================================================== class WXDLLEXPORT wxBrush: public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxBrush) - + DECLARE_DYNAMIC_CLASS(wxBrush) +// ------------------------------------------------------------------------ +// initialization +// ------------------------------------------------------------------------ public: - wxBrush(); - wxBrush(const wxColour& col, int style); - wxBrush(const wxBitmap& stipple); - wxBrush(const wxBrush& brush) - : wxGDIObject() - { Ref(brush); } - ~wxBrush(); + wxBrush(); + wxBrush(const wxColour& col, int style); + wxBrush(const wxBitmap& stipple); + wxBrush(const wxBrush& brush) + : wxGDIObject() + { Ref(brush); } + ~wxBrush(); - virtual void SetColour(const wxColour& col) ; - virtual void SetColour(unsigned char r, unsigned char g, unsigned char b) ; - virtual void SetStyle(int style) ; - virtual void SetStipple(const wxBitmap& stipple) ; +// ------------------------------------------------------------------------ +// Implementation +// ------------------------------------------------------------------------ + virtual void SetColour(const wxColour& col) ; + virtual void SetColour(unsigned char r, unsigned char g, unsigned char b) ; + virtual void SetStyle(int style) ; + virtual void SetStipple(const wxBitmap& stipple) ; - wxBrush& operator = (const wxBrush& brush) - { if (*this == brush) return (*this); Ref(brush); return *this; } - bool operator == (const wxBrush& brush) - { return m_refData == brush.m_refData; } - bool operator != (const wxBrush& brush) - { return m_refData != brush.m_refData; } + // assignment + wxBrush& operator = (const wxBrush& brush) + { if (*this == brush) return (*this); Ref(brush); return *this; } - wxColour& GetColour() const ; - int GetStyle() const ; - wxBitmap *GetStipple() const ; + // comparison + bool operator == (const wxBrush& brush) + { return m_refData == brush.m_refData; } + bool operator != (const wxBrush& brush) + { return m_refData != brush.m_refData; } - virtual bool Ok() const { return (m_refData != NULL) ; } + // accessors + wxColour GetColour() const; + int GetStyle() const; + wxBitmap *GetStipple() const; -// Implementation + virtual bool Ok() const + { return (m_refData != NULL); } - // Useful helper: create the brush resource - bool RealizeResource(); + // wxObjectRefData + wxObjectRefData *CreateRefData() const; + wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; - // When setting properties, we must make sure we're not changing - // another object - void Unshare(); + // wxCocoa + WX_NSColor GetNSColor(); }; -#endif - // _WX_BRUSH_H_ +#endif // __WX_COCOA_BRUSH_H__ diff --git a/src/cocoa/brush.cpp b/src/cocoa/brush.cpp deleted file mode 100644 index ddf9d8f4ed..0000000000 --- a/src/cocoa/brush.cpp +++ /dev/null @@ -1,122 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: brush.cpp -// Purpose: wxBrush -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 -// RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "brush.h" -#endif - -#include "wx/setup.h" -#include "wx/utils.h" -#include "wx/brush.h" - -#if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) -#endif - -#if 0 // WTF -wxBrushRefData::wxBrushRefData() -{ - m_style = wxSOLID; -// TODO: null data -} - -wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) -{ - m_style = data.m_style; - m_stipple = data.m_stipple; - m_colour = data.m_colour; -/* TODO: null data - m_hBrush = 0; -*/ -} - -wxBrushRefData::~wxBrushRefData() -{ -// TODO: delete data -} -#endif - -// Brushes -wxBrush::wxBrush() -{ - if ( wxTheBrushList ) - wxTheBrushList->AddBrush(this); -} - -wxBrush::~wxBrush() -{ - if ( wxTheBrushList ) - wxTheBrushList->RemoveBrush(this); -} - -wxBrush::wxBrush(const wxColour& col, int Style) -{ - if ( wxTheBrushList ) - wxTheBrushList->AddBrush(this); -} - -wxBrush::wxBrush(const wxBitmap& stipple) -{ - if ( wxTheBrushList ) - wxTheBrushList->AddBrush(this); -} - -void wxBrush::Unshare() -{ -} - -void wxBrush::SetColour(const wxColour& col) -{ - Unshare(); - RealizeResource(); -} - -void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) -{ - Unshare(); - - - RealizeResource(); -} - -void wxBrush::SetStyle(int Style) -{ - Unshare(); - - - RealizeResource(); -} - -void wxBrush::SetStipple(const wxBitmap& Stipple) -{ - Unshare(); - - - RealizeResource(); -} - -bool wxBrush::RealizeResource() -{ -// TODO: create the brush - return FALSE; -} - -int wxBrush::GetStyle() const -{ -return 0; -} - -wxColour& wxBrush::GetColour() const -{ - return *wxWHITE; -} - -// vi:sts=4:sw=5:et diff --git a/src/cocoa/brush.mm b/src/cocoa/brush.mm new file mode 100644 index 0000000000..bb835b291b --- /dev/null +++ b/src/cocoa/brush.mm @@ -0,0 +1,216 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/cocoa/brush.mm +// Purpose: wxBrush +// Author: David Elliott +// Modified by: +// Created: 2003/07/03 +// RCS-ID: $Id$ +// Copyright: (c) 2003 David Elliott +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/setup.h" +#include "wx/utils.h" +#include "wx/brush.h" +#include "wx/colour.h" + +#import + +class WXDLLEXPORT wxBrushRefData: public wxGDIRefData +{ +public: + wxBrushRefData(const wxColour& colour = wxNullColour, int style = wxSOLID); + wxBrushRefData(const wxBitmap& stipple); + wxBrushRefData(const wxBrushRefData& data); + virtual ~wxBrushRefData(); + + WX_NSColor GetNSColor(); + void Free(); + + bool operator==(const wxBrushRefData& data) const; + + // accessors + const wxColour& GetColour() const { return m_colour; } + int GetStyle() const { return m_style; } + wxBitmap *GetStipple() { return &m_stipple; } + + void SetColour(const wxColour& colour) { Free(); m_colour = colour; } + void SetStyle(int style) { Free(); m_style = style; } + void SetStipple(const wxBitmap& stipple) { Free(); DoSetStipple(stipple); } + +private: + void DoSetStipple(const wxBitmap& stipple); + + WX_NSColor m_cocoaNSColor; + int m_style; + wxBitmap m_stipple; + wxColour m_colour; + + // no assignment operator, the objects of this class are shared and never + // assigned after being created once + wxBrushRefData& operator=(const wxBrushRefData&); +}; + +#define M_BRUSHDATA ((wxBrushRefData *)m_refData) +IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) + +wxBrushRefData::wxBrushRefData(const wxColour& colour, int style) +{ + m_cocoaNSColor = NULL; + m_style = wxSOLID; + m_colour = colour; +} + +wxBrushRefData::wxBrushRefData(const wxBitmap& stipple) +{ + m_cocoaNSColor = NULL; + DoSetStipple(stipple); +} + +wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) +{ + m_cocoaNSColor = data.m_cocoaNSColor; + [m_cocoaNSColor retain]; + m_style = data.m_style; + m_stipple = data.m_stipple; + m_colour = data.m_colour; +} + +wxBrushRefData::~wxBrushRefData() +{ + Free(); +} + +void wxBrushRefData::Free() +{ + [m_cocoaNSColor release]; + m_cocoaNSColor = NULL; +} + +bool wxBrushRefData::operator==(const wxBrushRefData& data) const +{ + // don't compare our NSColor + return m_style == data.m_style && + m_colour == data.m_colour && + m_stipple == data.m_stipple; +} + +void wxBrushRefData::DoSetStipple(const wxBitmap& stipple) +{ + m_stipple = stipple; + m_style = stipple.GetMask() ? wxSTIPPLE_MASK_OPAQUE : wxSTIPPLE; +} + +WX_NSColor wxBrushRefData::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; + case wxSTIPPLE_MASK_OPAQUE: + // This should be easy when wxBitmap works. +// 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: + 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; +} + +// Brushes +wxBrush::wxBrush() +{ + m_refData = new wxBrushRefData; +} + +wxBrush::~wxBrush() +{ +} + +wxBrush::wxBrush(const wxColour& col, int style) +{ + m_refData = new wxBrushRefData(col, style); +} + +wxBrush::wxBrush(const wxBitmap& stipple) +{ + m_refData = new wxBrushRefData(stipple); +} + +wxObjectRefData *wxBrush::CreateRefData() const +{ + return new wxBrushRefData; +} + +wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +{ + return new wxBrushRefData(*(wxBrushRefData *)data); +} + +void wxBrush::SetColour(const wxColour& col) +{ + AllocExclusive(); + M_BRUSHDATA->SetColour(col); +} + +void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) +{ + AllocExclusive(); + M_BRUSHDATA->SetColour(wxColour(r,g,b)); +} + +void wxBrush::SetStyle(int style) +{ + AllocExclusive(); + M_BRUSHDATA->SetStyle(style); +} + +void wxBrush::SetStipple(const wxBitmap& stipple) +{ + AllocExclusive(); + M_BRUSHDATA->SetStipple(stipple); +} + +wxColour wxBrush::GetColour() const +{ + wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") ); + return M_BRUSHDATA->GetColour(); +} + +int wxBrush::GetStyle() const +{ + wxCHECK_MSG( Ok(), 0, _T("invalid brush") ); + return M_BRUSHDATA->GetStyle(); +} + +wxBitmap *wxBrush::GetStipple() const +{ + wxCHECK_MSG( Ok(), 0, _T("invalid brush") ); + return M_BRUSHDATA->GetStipple(); +} + +WX_NSColor wxBrush::GetNSColor() +{ + wxCHECK_MSG( Ok(), NULL, _T("invalid brush") ); + return M_BRUSHDATA->GetNSColor(); +} + -- 2.45.2