]>
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>
49 #include "wx/osx/private/timer.h"
52 #include "wx/evtloop.h"
54 #if defined(__MWERKS__) && wxUSE_UNICODE
55 #if __MWERKS__ < 0x4100
62 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
64 // TODO : try to find out ...
68 #if wxOSX_USE_COCOA_OR_CARBON
70 // have a fast version for mac code that returns the version as a return value
72 long UMAGetSystemVersion()
74 static SInt32 sUMASystemVersion
= 0 ;
75 if ( sUMASystemVersion
== 0 )
77 verify_noerr(Gestalt(gestaltSystemVersion
, &sUMASystemVersion
));
79 return sUMASystemVersion
;
82 // our OS version is the same in non GUI and GUI cases
83 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
86 Gestalt(gestaltSystemVersion
, &theSystem
);
88 if ( majorVsn
!= NULL
)
89 *majorVsn
= (theSystem
>> 8);
91 if ( minorVsn
!= NULL
)
92 *minorVsn
= (theSystem
& 0xFF);
94 return wxOS_MAC_OSX_DARWIN
;
97 #include <sys/utsname.h>
99 wxString
wxGetOsDescription()
103 return wxString::Format(_T("Mac OS X (%s %s %s)"),
104 wxString::FromAscii(name
.sysname
).c_str(),
105 wxString::FromAscii(name
.release
).c_str(),
106 wxString::FromAscii(name
.machine
).c_str());
109 #endif // wxOSX_USE_COCOA_OR_CARBON
112 //---------------------------------------------------------------------------
113 // wxMac Specific utility functions
114 //---------------------------------------------------------------------------
116 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
118 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
119 int len
= strlen(buf
);
124 memcpy( (char*) &to
[1] , buf
, len
);
127 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
129 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
136 // Check whether this window wants to process messages, e.g. Stop button
137 // in long calculations.
138 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
144 // Return true if we have a colour display
145 bool wxColourDisplay()
150 #if wxOSX_USE_COCOA_OR_CARBON
151 // Returns depth of screen
154 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
158 // Get size of display
159 void wxDisplaySize(int *width
, int *height
)
161 // TODO adapt for multi-displays
162 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
164 *width
= (int)bounds
.size
.width
;
166 *height
= (int)bounds
.size
.height
;
170 void wxDisplaySizeMM(int *width
, int *height
)
172 wxDisplaySize(width
, height
);
173 // on mac 72 is fixed (at least now;-)
174 double cvPt2Mm
= 25.4 / 72;
177 *width
= int( *width
* cvPt2Mm
);
180 *height
= int( *height
* cvPt2Mm
);
184 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
186 // We suppose that toolkit version is the same as OS version under Mac
187 wxGetOsVersion(verMaj
, verMin
);
192 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
194 return new wxEventLoop
;
197 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
199 return wxGenericFindWindowAtPoint(pt
);
203 Return the generic RGB color space. This is a 'get' function and the caller should
204 not release the returned value unless the caller retains it first. Usually callers
205 of this routine will immediately use the returned colorspace with CoreGraphics
206 so they typically do not need to retain it themselves.
208 This function creates the generic RGB color space once and hangs onto it so it can
209 return it whenever this function is called.
212 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
214 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
216 if (genericRGBColorSpace
== NULL
)
219 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
221 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
225 return genericRGBColorSpace
;
228 #if wxOSX_USE_COCOA_OR_CARBON
230 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
233 HIThemeBrushCreateCGColor( brush
, &color
);
237 #endif // wxOSX_USE_COCOA_OR_CARBON