cleanup and cgcolor changeds

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50172 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2007-11-22 18:15:16 +00:00
parent 115563867d
commit 276ee5334d
12 changed files with 160 additions and 107 deletions

View File

@@ -183,13 +183,29 @@ void wxBrush::MacSetTheme(ThemeBrush macThemeBrush)
M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme; M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
M_BRUSHDATA->m_macThemeBrush = macThemeBrush; M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
RGBColor color ; RGBColor color = { 0,0,0 } ;
#ifdef __LP64__
CGColorRef colorref = 0;
HIThemeBrushCreateCGColor( macThemeBrush, &colorref );
size_t noComp = CGColorGetNumberOfComponents( colorref );
if ( noComp >=3 && noComp <= 4 )
{
// TODO verify whether we really are on a RGB color space
const CGFloat *components = CGColorGetComponents( colorref );
color.red = (int)(components[0]*255+0.5);
color.green = (int)(components[1]*255+0.5);
color.blue = (int)(components[2]*255+0.5);
}
CFRelease( colorref );
#else
GetThemeBrushAsColor( macThemeBrush , 32, true, &color ); GetThemeBrushAsColor( macThemeBrush , 32, true, &color );
#endif
M_BRUSHDATA->m_colour = color; M_BRUSHDATA->m_colour = color;
RealizeResource(); RealizeResource();
} }
/* TODO REMOVE
void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent) void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
{ {
Unshare(); Unshare();
@@ -200,12 +216,14 @@ void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRE
RealizeResource(); RealizeResource();
} }
*/
bool wxBrush::RealizeResource() bool wxBrush::RealizeResource()
{ {
return true; return true;
} }
/*
unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
{ {
if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground ) if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
@@ -220,6 +238,7 @@ unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
return 0; return 0;
} }
} }
*/
short wxBrush::MacGetTheme() const short wxBrush::MacGetTheme() const
{ {

View File

@@ -23,60 +23,108 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
wxColour::wxColour(const RGBColor& col) wxColour::wxColour(const RGBColor& col)
{ {
FromRGBColor((WXCOLORREF *)&col); InitRGBColor(col);
} }
static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green ) wxColour::wxColour(CGColorRef col)
{ {
RGBColor* col = (RGBColor*) color; InitCGColorRef(col);
col->red = (red << 8) + red;
col->blue = (blue << 8) + blue;
col->green = (green << 8) + green;
} }
void wxColour::Init() void wxColour::GetRGBColor( RGBColor *col ) const
{ {
m_isInit = false; col->red = (m_red << 8) + m_red;
m_red = col->blue = (m_blue << 8) + m_blue;
m_blue = col->green = (m_green << 8) + m_green;
m_green = 0;
wxComposeRGBColor( &m_pixel, m_red, m_blue, m_green );
} }
wxColour::~wxColour () wxColour::~wxColour ()
{ {
} }
void wxColour::InitRGBA (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
m_red = r;
m_green = g;
m_blue = b;
m_alpha = a ;
m_isInit = true;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green );
}
void wxColour::FromRGBColor( WXCOLORREF* color )
{
RGBColor* col = (RGBColor*) color;
memcpy( &m_pixel, color, 6 );
m_red = col->red >> 8;
m_blue = col->blue >> 8;
m_green = col->green >> 8;
m_alpha = 255;
}
wxColour& wxColour::operator=(const RGBColor& col) wxColour& wxColour::operator=(const RGBColor& col)
{ {
FromRGBColor((WXCOLORREF *)&col); InitRGBColor(col);
return *this;
}
wxColour& wxColour::operator=(CGColorRef col)
{
InitCGColorRef(col);
return *this; return *this;
} }
bool wxColour::IsOk() const bool wxColour::IsOk() const
{ {
return m_isInit; return m_cgColour.get() != NULL;
} }
void wxColour::InitRGBA (ChannelType r, ChannelType g, ChannelType b, ChannelType a)
{
m_red = r;
m_green = g;
m_blue = b;
m_alpha = a ;
CGColorRef col = 0 ;
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
if ( CGColorCreateGenericRGB )
col = CGColorCreateGenericRGB( r / 255.0, g / 255.0, b / 255.0, a / 255.0 );
else
#endif
{
CGFloat components[4] = { r / 255.0, g / 255.0, b / 255.0, a / 255.0 } ;
col = CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ;
}
m_cgColour.reset( col );
}
void wxColour::InitRGBColor( const RGBColor& col )
{
m_red = col.red >> 8;
m_blue = col.blue >> 8;
m_green = col.green >> 8;
m_alpha = wxALPHA_OPAQUE;
CGColorRef cfcol;
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
if ( CGColorCreateGenericRGB )
cfcol = CGColorCreateGenericRGB( col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0, 1.0 );
else
#endif
{
CGFloat components[4] = { col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0, 1.0 } ;
cfcol = CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ;
}
m_cgColour.reset( cfcol );
}
void wxColour::InitCGColorRef( CGColorRef col )
{
m_cgColour.reset( col );
size_t noComp = CGColorGetNumberOfComponents( col );
if ( noComp >=3 && noComp <= 4 )
{
// TODO verify whether we really are on a RGB color space
const CGFloat *components = CGColorGetComponents( col );
m_red = (int)(components[0]*255+0.5);
m_green = (int)(components[1]*255+0.5);
m_blue = (int)(components[2]*255+0.5);
if ( noComp == 4 )
m_alpha = (int)(components[3]*255+0.5);
else
m_alpha = wxALPHA_OPAQUE;
}
else
{
m_alpha = wxALPHA_OPAQUE;
m_red = m_green = m_blue = 0;
}
}
bool wxColour::operator == (const wxColour& colour) const
{
return ( (IsOk() == colour.IsOk()) && (!IsOk() ||
CGColorEqualToColor( m_cgColour, colour.m_cgColour ) ) );
}

View File

@@ -745,7 +745,7 @@ bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
m_bitmap.Create( CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) ); m_bitmap.Create( CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) ); CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
// since our context is upside down we dont use CGContextDrawImage // since our context is upside down we dont use CGContextDrawImage
HIViewDrawCGImage( (CGContextRef) m_bitmap.GetHBITMAP() , &r, cgImageRef ) ; wxMacDrawCGImage( (CGContextRef) m_bitmap.GetHBITMAP() , &r, cgImageRef ) ;
CGImageRelease(cgImageRef); CGImageRelease(cgImageRef);
cgImageRef = NULL; cgImageRef = NULL;
} }

View File

@@ -58,6 +58,19 @@ static const double RAD2DEG = 180.0 / M_PI;
#pragma mark - #pragma mark -
#pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
OSStatus wxMacDrawCGImage(
CGContextRef inContext,
const HIRect * inBounds,
CGImageRef inImage)
{
#ifdef __LP64__
// todo flip
CGContextDrawImage(inContext, *inBounds, inImage );
#else
HIViewDrawCGImage( inContext, inBounds, inImage );
#endif
}
// CGPattern wrapper class: always allocate on heap, never call destructor // CGPattern wrapper class: always allocate on heap, never call destructor
class wxMacCoreGraphicsPattern class wxMacCoreGraphicsPattern
@@ -119,7 +132,7 @@ public :
virtual void Render( CGContextRef ctxRef ) virtual void Render( CGContextRef ctxRef )
{ {
if (m_image != NULL) if (m_image != NULL)
HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image ); wxMacDrawCGImage( ctxRef, &m_imageBounds, m_image );
} }
protected : protected :
@@ -695,7 +708,8 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
// we need the scale here ... // we need the scale here ...
Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) ); Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) );
RGBColor atsuColor = MAC_WXCOLORREF( col.GetPixel() ); RGBColor atsuColor ;
col.GetRGBColor( &atsuColor );
ATSUAttributeTag atsuTags[] = ATSUAttributeTag atsuTags[] =
{ {
kATSUSizeTag , kATSUSizeTag ,
@@ -1648,13 +1662,13 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDo
else else
{ {
((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->Apply(this); ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->Apply(this);
HIViewDrawCGImage( m_cgContext , &r , image ); wxMacDrawCGImage( m_cgContext , &r , image );
} }
} }
} }
else else
{ {
HIViewDrawCGImage( m_cgContext , &r , image ); wxMacDrawCGImage( m_cgContext , &r , image );
} }
CGImageRelease( image ); CGImageRelease( image );
} }

View File

@@ -2729,13 +2729,13 @@ void wxMacDataBrowserListCtrlControl::DrawItem(
{ {
if (color.Ok()) if (color.Ok())
labelColor = MAC_WXCOLORREF( color.GetPixel() ); color.GetRGBColor(&labelColor);
else if (list->GetTextColour().Ok()) else if (list->GetTextColour().Ok())
labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() ); list->GetTextColour().GetRGBColor(&labelColor);
if (bgColor.Ok()) if (bgColor.Ok())
{ {
backgroundColor = MAC_WXCOLORREF( bgColor.GetPixel() ); bgColor.GetRGBColor(&backgroundColor);
CGContextSaveGState(context); CGContextSaveGState(context);
CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX, CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX,

View File

@@ -201,6 +201,7 @@ void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
m_refData = new wxMetafileRefData((CFDataRef)mf); m_refData = new wxMetafileRefData((CFDataRef)mf);
} }
#ifndef __LP64__
void wxMetafile::SetPICT(void* pictHandle) void wxMetafile::SetPICT(void* pictHandle)
{ {
UnRef(); UnRef();
@@ -218,6 +219,7 @@ void wxMetafile::SetPICT(void* pictHandle)
QDPictRelease( pictRef ); QDPictRelease( pictRef );
((wxMetafileRefData*) m_refData)->Close(); ((wxMetafileRefData*) m_refData)->Close();
} }
#endif
bool wxMetaFile::Play(wxDC *dc) bool wxMetaFile::Play(wxDC *dc)
{ {

View File

@@ -320,7 +320,7 @@ pascal OSErr FSpGetFullPath( const FSSpec *spec,
return result; return result;
} }
#endif #endif // LP64
// //
// On the mac there are two ways to open a file - one is through apple events and the // On the mac there are two ways to open a file - one is through apple events and the
// finder, another is through mime types. // finder, another is through mime types.

View File

@@ -32,7 +32,6 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
{ {
int major, minor; int major, minor;
wxColour resultColor; wxColour resultColor;
RGBColor macRGB;
ThemeBrush colorBrushID; ThemeBrush colorBrushID;
wxGetOsVersion( &major, &minor ); wxGetOsVersion( &major, &minor );
@@ -79,16 +78,17 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
break ; break ;
case wxSYS_COLOUR_HIGHLIGHT: case wxSYS_COLOUR_HIGHLIGHT:
{
#if 0 #if 0
// NB: enable this case as desired // NB: enable this case as desired
colorBrushID = kThemeBrushAlternatePrimaryHighlightColor; colorBrushID = kThemeBrushAlternatePrimaryHighlightColor;
#else #else
colorBrushID = kThemeBrushPrimaryHighlightColor; colorBrushID = kThemeBrushPrimaryHighlightColor;
#endif #endif
CGColorRef color ;
GetThemeBrushAsColor( colorBrushID, 32, true, &macRGB ); HIThemeBrushCreateCGColor( colorBrushID, &color );
resultColor = wxColor( macRGB ); resultColor = wxColor( color );
}
break ; break ;
case wxSYS_COLOUR_BTNHIGHLIGHT: case wxSYS_COLOUR_BTNHIGHLIGHT:
@@ -109,11 +109,15 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
// NB: enable this case as desired // NB: enable this case as desired
resultColor = *wxWHITE ; resultColor = *wxWHITE ;
#else #else
GetThemeBrushAsColor( kThemeBrushPrimaryHighlightColor, 32, true, &macRGB ); {
if ((macRGB.red + macRGB.green + macRGB.blue) == 0) CGColorRef color ;
resultColor = *wxWHITE ; HIThemeBrushCreateCGColor( kThemeBrushPrimaryHighlightColor, &color );
else wxColour highlightcolor( color );
resultColor = *wxBLACK ; if ((highlightcolor.Red() + highlightcolor.Green() + highlightcolor.Blue() ) == 0)
resultColor = *wxWHITE ;
else
resultColor = *wxBLACK ;
}
#endif #endif
break ; break ;
@@ -234,8 +238,13 @@ int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(w
// TODO: case wxSYS_SHOW_SOUNDS: // TODO: case wxSYS_SHOW_SOUNDS:
case wxSYS_DCLICK_MSEC: case wxSYS_DCLICK_MSEC:
#ifdef __LP64__
// default on mac is 30 ticks, we shouldn't really use wxSYS_DCLICK_MSEC anyway
// but rather rely on the 'click-count' by the system delivered in a mouse event
return 500;
#else
return (int)(GetDblTime() * 1000. / 60.); return (int)(GetDblTime() * 1000. / 60.);
#endif
default: default:
// unsupported metric // unsupported metric
break; break;

View File

@@ -1689,7 +1689,7 @@ void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background,
TXNBackground tback; TXNBackground tback;
tback.bgType = kTXNBackgroundTypeRGB; tback.bgType = kTXNBackgroundTypeRGB;
tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); background.GetRGBColor( &tback.bg.color );
TXNSetBackground( m_txn , &tback ); TXNSetBackground( m_txn , &tback );
@@ -1730,7 +1730,7 @@ void wxMacMLTEControl::SetBackground( const wxBrush &brush )
TXNBackground tback; TXNBackground tback;
tback.bgType = kTXNBackgroundTypeRGB; tback.bgType = kTXNBackgroundTypeRGB;
tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); brush.GetColour().GetRGBColor(&tback.bg.color);
TXNSetBackground( m_txn , &tback ); TXNSetBackground( m_txn , &tback );
} }
@@ -1767,8 +1767,7 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo
if ( style.HasTextColour() ) if ( style.HasTextColour() )
{ {
wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) ); wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) );
color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; style.GetTextColour().GetRGBColor( &color );
typeAttr[typeAttrCount].tag = kTXNQDFontColorAttribute ; typeAttr[typeAttrCount].tag = kTXNQDFontColorAttribute ;
typeAttr[typeAttrCount].size = kTXNQDFontColorAttributeSize ; typeAttr[typeAttrCount].size = kTXNQDFontColorAttributeSize ;
typeAttr[typeAttrCount].data.dataPtr = (void*) &color ; typeAttr[typeAttrCount].data.dataPtr = (void*) &color ;
@@ -3048,7 +3047,8 @@ void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush )
#if 0 #if 0
CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB();
RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; RGBColor col;
brush.GetColour().GetRGBColor(&col) ;
float component[4] ; float component[4] ;
component[0] = col.red / 65536.0 ; component[0] = col.red / 65536.0 ;

View File

@@ -25,16 +25,8 @@
#include "wx/thread.h" #include "wx/thread.h"
#ifdef __WXMAC__ #include <CoreServices/CoreServices.h>
#ifdef __DARWIN__
#include <CoreServices/CoreServices.h>
#else
#include <DriverServices.h>
#include <Multiprocessing.h>
#endif
#include "wx/mac/uma.h" #include "wx/mac/uma.h"
#endif
// the possible states of the thread: // the possible states of the thread:
// ("=>" shows all possible transitions from this state) // ("=>" shows all possible transitions from this state)

View File

@@ -35,7 +35,7 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include "MoreFilesX.h" // #include "MoreFilesX.h"
#ifndef __DARWIN__ #ifndef __DARWIN__
#include <Threads.h> #include <Threads.h>
@@ -679,7 +679,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
if ( foreground != *wxBLACK ) if ( foreground != *wxBLACK )
{ {
fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() ); foreground.GetRGBColor( &fontStyle.foreColor );
fontStyle.flags |= kControlUseForeColorMask; fontStyle.flags |= kControlUseForeColorMask;
} }

View File

@@ -9,35 +9,4 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h" // TODO REMOVE
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/utils.h"
#endif //ndef WX_PRECOMP
#ifndef __DARWIN__
#include "wx/mac/private.h"
#include "LaunchServices.h"
long wxExecute(const wxString& command, int flags, wxProcess *WXUNUSED(handler))
{
wxASSERT_MSG( flags == wxEXEC_ASYNC,
wxT("wxExecute: Only wxEXEC_ASYNC is supported") );
FSRef fsRef ;
OSErr err = noErr ;
err = wxMacPathToFSRef( command , &fsRef ) ;
if ( noErr == err )
{
err = LSOpenFSRef( &fsRef , NULL ) ;
}
// 0 means execution failed. Returning non-zero is a PID, but not
// on Mac where PIDs are 64 bits and won't fit in a long, so we
// return a dummy value for now.
return ( err == noErr ) ? -1 : 0;
}
#endif //ndef __DARWIN__