First hack at wxBrush for wxCocoa
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21747 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1467,7 +1467,7 @@
|
|||||||
src/cocoa/app.mm
|
src/cocoa/app.mm
|
||||||
src/cocoa/bmpbuttn.mm
|
src/cocoa/bmpbuttn.mm
|
||||||
src/cocoa/bitmap.mm
|
src/cocoa/bitmap.mm
|
||||||
src/cocoa/brush.cpp
|
src/cocoa/brush.mm
|
||||||
src/cocoa/button.mm
|
src/cocoa/button.mm
|
||||||
src/cocoa/checkbox.mm
|
src/cocoa/checkbox.mm
|
||||||
src/cocoa/checklst.mm
|
src/cocoa/checklst.mm
|
||||||
|
@@ -1,20 +1,16 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: brush.h
|
// Name: include/wx/cocoa/brush.h
|
||||||
// Purpose: wxBrush class
|
// Purpose: wxBrush class
|
||||||
// Author: AUTHOR
|
// Author: David Elliott <dfe@cox.net>
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: ??/??/98
|
// Created: 2003/07/03
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) AUTHOR
|
// Copyright: (c) 2003 David Elliott
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_BRUSH_H_
|
#ifndef __WX_COCOA_BRUSH_H__
|
||||||
#define _WX_BRUSH_H_
|
#define __WX_COCOA_BRUSH_H__
|
||||||
|
|
||||||
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
||||||
#pragma interface "brush.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/gdicmn.h"
|
#include "wx/gdicmn.h"
|
||||||
#include "wx/gdiobj.h"
|
#include "wx/gdiobj.h"
|
||||||
@@ -22,11 +18,15 @@
|
|||||||
|
|
||||||
class WXDLLEXPORT wxBrush;
|
class WXDLLEXPORT wxBrush;
|
||||||
|
|
||||||
// Brush
|
// ========================================================================
|
||||||
|
// wxBrush
|
||||||
|
// ========================================================================
|
||||||
class WXDLLEXPORT wxBrush: public wxGDIObject
|
class WXDLLEXPORT wxBrush: public wxGDIObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxBrush)
|
DECLARE_DYNAMIC_CLASS(wxBrush)
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// initialization
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
public:
|
public:
|
||||||
wxBrush();
|
wxBrush();
|
||||||
wxBrush(const wxColour& col, int style);
|
wxBrush(const wxColour& col, int style);
|
||||||
@@ -36,33 +36,38 @@ public:
|
|||||||
{ Ref(brush); }
|
{ Ref(brush); }
|
||||||
~wxBrush();
|
~wxBrush();
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Implementation
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
virtual void SetColour(const wxColour& col) ;
|
virtual void SetColour(const wxColour& col) ;
|
||||||
virtual void SetColour(unsigned char r, unsigned char g, unsigned char b) ;
|
virtual void SetColour(unsigned char r, unsigned char g, unsigned char b) ;
|
||||||
virtual void SetStyle(int style) ;
|
virtual void SetStyle(int style) ;
|
||||||
virtual void SetStipple(const wxBitmap& stipple) ;
|
virtual void SetStipple(const wxBitmap& stipple) ;
|
||||||
|
|
||||||
|
// assignment
|
||||||
wxBrush& operator = (const wxBrush& brush)
|
wxBrush& operator = (const wxBrush& brush)
|
||||||
{ if (*this == brush) return (*this); Ref(brush); return *this; }
|
{ if (*this == brush) return (*this); Ref(brush); return *this; }
|
||||||
|
|
||||||
|
// comparison
|
||||||
bool operator == (const wxBrush& brush)
|
bool operator == (const wxBrush& brush)
|
||||||
{ return m_refData == brush.m_refData; }
|
{ return m_refData == brush.m_refData; }
|
||||||
bool operator != (const wxBrush& brush)
|
bool operator != (const wxBrush& brush)
|
||||||
{ return m_refData != brush.m_refData; }
|
{ return m_refData != brush.m_refData; }
|
||||||
|
|
||||||
wxColour& GetColour() const ;
|
// accessors
|
||||||
|
wxColour GetColour() const;
|
||||||
int GetStyle() const;
|
int GetStyle() const;
|
||||||
wxBitmap *GetStipple() const;
|
wxBitmap *GetStipple() const;
|
||||||
|
|
||||||
virtual bool Ok() const { return (m_refData != NULL) ; }
|
virtual bool Ok() const
|
||||||
|
{ return (m_refData != NULL); }
|
||||||
|
|
||||||
// Implementation
|
// wxObjectRefData
|
||||||
|
wxObjectRefData *CreateRefData() const;
|
||||||
|
wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
||||||
|
|
||||||
// Useful helper: create the brush resource
|
// wxCocoa
|
||||||
bool RealizeResource();
|
WX_NSColor GetNSColor();
|
||||||
|
|
||||||
// When setting properties, we must make sure we're not changing
|
|
||||||
// another object
|
|
||||||
void Unshare();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // __WX_COCOA_BRUSH_H__
|
||||||
// _WX_BRUSH_H_
|
|
||||||
|
@@ -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
|
|
216
src/cocoa/brush.mm
Normal file
216
src/cocoa/brush.mm
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/cocoa/brush.mm
|
||||||
|
// Purpose: wxBrush
|
||||||
|
// Author: David Elliott <dfe@cox.net>
|
||||||
|
// 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 <AppKit/NSColor.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user