]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/utils_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/utils_osx.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: utils.cpp 54886 2008-07-31 13:02:53Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/wxprec.h"
21 #include "wx/toplevel.h"
26 #include "wx/apptrait.h"
35 // #include "MoreFilesX.h"
37 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
38 #include <AudioToolbox/AudioServices.h>
41 #include "wx/osx/private.h"
43 #ifdef wxOSX_USE_COCOA
44 // to get the themeing APIs
45 #include <Carbon/Carbon.h>
48 #include "wx/osx/private/timer.h"
50 #include "wx/evtloop.h"
52 #if defined(__MWERKS__) && wxUSE_UNICODE
53 #if __MWERKS__ < 0x4100
58 // Check whether this window wants to process messages, e.g. Stop button
59 // in long calculations.
60 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
66 // Return true if we have a colour display
67 bool wxColourDisplay()
72 #if wxOSX_USE_COCOA_OR_CARBON
73 // Returns depth of screen
76 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
80 // Get size of display
81 void wxDisplaySize(int *width
, int *height
)
83 // TODO adapt for multi-displays
84 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
86 *width
= (int)bounds
.size
.width
;
88 *height
= (int)bounds
.size
.height
;
92 void wxDisplaySizeMM(int *width
, int *height
)
94 wxDisplaySize(width
, height
);
95 // on mac 72 is fixed (at least now;-)
96 double cvPt2Mm
= 25.4 / 72;
99 *width
= int( *width
* cvPt2Mm
);
102 *height
= int( *height
* cvPt2Mm
);
106 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
108 // We suppose that toolkit version is the same as OS version under Mac
109 wxGetOsVersion(verMaj
, verMin
);
114 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
116 return new wxEventLoop
;
119 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
121 return wxGenericFindWindowAtPoint(pt
);
125 Return the generic RGB color space. This is a 'get' function and the caller should
126 not release the returned value unless the caller retains it first. Usually callers
127 of this routine will immediately use the returned colorspace with CoreGraphics
128 so they typically do not need to retain it themselves.
130 This function creates the generic RGB color space once and hangs onto it so it can
131 return it whenever this function is called.
134 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
136 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
138 if (genericRGBColorSpace
== NULL
)
141 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
143 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
147 return genericRGBColorSpace
;
150 #if wxOSX_USE_COCOA_OR_CARBON
152 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
155 HIThemeBrushCreateCGColor( brush
, &color
);
159 //---------------------------------------------------------------------------
160 // Mac Specific string utility functions
161 //---------------------------------------------------------------------------
163 void wxMacStringToPascal( const wxString
&from
, unsigned char * to
)
165 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
166 int len
= strlen(buf
);
171 memcpy( (char*) &to
[1] , buf
, len
);
174 wxString
wxMacMakeStringFromPascal( const unsigned char * from
)
176 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
179 #endif // wxOSX_USE_COCOA_OR_CARBON