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_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 );
#endif
M_BRUSHDATA->m_colour = color;
RealizeResource();
}
/* TODO REMOVE
void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
{
Unshare();
@@ -200,12 +216,14 @@ void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRE
RealizeResource();
}
*/
bool wxBrush::RealizeResource()
{
return true;
}
/*
unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
{
if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
@@ -220,6 +238,7 @@ unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
return 0;
}
}
*/
short wxBrush::MacGetTheme() const
{

View File

@@ -23,60 +23,108 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
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;
col->red = (red << 8) + red;
col->blue = (blue << 8) + blue;
col->green = (green << 8) + green;
InitCGColorRef(col);
}
void wxColour::Init()
void wxColour::GetRGBColor( RGBColor *col ) const
{
m_isInit = false;
m_red =
m_blue =
m_green = 0;
wxComposeRGBColor( &m_pixel, m_red, m_blue, m_green );
col->red = (m_red << 8) + m_red;
col->blue = (m_blue << 8) + m_blue;
col->green = (m_green << 8) + m_green;
}
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)
{
FromRGBColor((WXCOLORREF *)&col);
InitRGBColor(col);
return *this;
}
wxColour& wxColour::operator=(CGColorRef col)
{
InitCGColorRef(col);
return *this;
}
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) );
CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
// 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);
cgImageRef = NULL;
}

View File

@@ -58,6 +58,19 @@ static const double RAD2DEG = 180.0 / M_PI;
#pragma mark -
#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
class wxMacCoreGraphicsPattern
@@ -119,7 +132,7 @@ public :
virtual void Render( CGContextRef ctxRef )
{
if (m_image != NULL)
HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image );
wxMacDrawCGImage( ctxRef, &m_imageBounds, m_image );
}
protected :
@@ -695,7 +708,8 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
// we need the scale here ...
Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) );
RGBColor atsuColor = MAC_WXCOLORREF( col.GetPixel() );
RGBColor atsuColor ;
col.GetRGBColor( &atsuColor );
ATSUAttributeTag atsuTags[] =
{
kATSUSizeTag ,
@@ -1648,13 +1662,13 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDo
else
{
((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->Apply(this);
HIViewDrawCGImage( m_cgContext , &r , image );
wxMacDrawCGImage( m_cgContext , &r , image );
}
}
}
else
{
HIViewDrawCGImage( m_cgContext , &r , image );
wxMacDrawCGImage( m_cgContext , &r , image );
}
CGImageRelease( image );
}

View File

@@ -2729,13 +2729,13 @@ void wxMacDataBrowserListCtrlControl::DrawItem(
{
if (color.Ok())
labelColor = MAC_WXCOLORREF( color.GetPixel() );
color.GetRGBColor(&labelColor);
else if (list->GetTextColour().Ok())
labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
list->GetTextColour().GetRGBColor(&labelColor);
if (bgColor.Ok())
{
backgroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
bgColor.GetRGBColor(&backgroundColor);
CGContextSaveGState(context);
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);
}
#ifndef __LP64__
void wxMetafile::SetPICT(void* pictHandle)
{
UnRef();
@@ -218,6 +219,7 @@ void wxMetafile::SetPICT(void* pictHandle)
QDPictRelease( pictRef );
((wxMetafileRefData*) m_refData)->Close();
}
#endif
bool wxMetaFile::Play(wxDC *dc)
{

View File

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

View File

@@ -32,7 +32,6 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
{
int major, minor;
wxColour resultColor;
RGBColor macRGB;
ThemeBrush colorBrushID;
wxGetOsVersion( &major, &minor );
@@ -79,16 +78,17 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
break ;
case wxSYS_COLOUR_HIGHLIGHT:
{
#if 0
// NB: enable this case as desired
colorBrushID = kThemeBrushAlternatePrimaryHighlightColor;
colorBrushID = kThemeBrushAlternatePrimaryHighlightColor;
#else
colorBrushID = kThemeBrushPrimaryHighlightColor;
colorBrushID = kThemeBrushPrimaryHighlightColor;
#endif
GetThemeBrushAsColor( colorBrushID, 32, true, &macRGB );
resultColor = wxColor( macRGB );
CGColorRef color ;
HIThemeBrushCreateCGColor( colorBrushID, &color );
resultColor = wxColor( color );
}
break ;
case wxSYS_COLOUR_BTNHIGHLIGHT:
@@ -109,11 +109,15 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
// NB: enable this case as desired
resultColor = *wxWHITE ;
#else
GetThemeBrushAsColor( kThemeBrushPrimaryHighlightColor, 32, true, &macRGB );
if ((macRGB.red + macRGB.green + macRGB.blue) == 0)
resultColor = *wxWHITE ;
else
resultColor = *wxBLACK ;
{
CGColorRef color ;
HIThemeBrushCreateCGColor( kThemeBrushPrimaryHighlightColor, &color );
wxColour highlightcolor( color );
if ((highlightcolor.Red() + highlightcolor.Green() + highlightcolor.Blue() ) == 0)
resultColor = *wxWHITE ;
else
resultColor = *wxBLACK ;
}
#endif
break ;
@@ -234,8 +238,13 @@ int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(w
// TODO: case wxSYS_SHOW_SOUNDS:
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.);
#endif
default:
// unsupported metric
break;

View File

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

View File

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

View File

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

View File

@@ -9,35 +9,4 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#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__
// TODO REMOVE