]>
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
61 // TODO BEGIN move to utils_osx.cpp
66 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
68 // TODO : try to find out ...
72 #if wxOSX_USE_COCOA_OR_CARBON
74 // have a fast version for mac code that returns the version as a return value
76 long UMAGetSystemVersion()
78 static SInt32 sUMASystemVersion
= 0 ;
79 if ( sUMASystemVersion
== 0 )
81 verify_noerr(Gestalt(gestaltSystemVersion
, &sUMASystemVersion
));
83 return sUMASystemVersion
;
86 // our OS version is the same in non GUI and GUI cases
87 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
90 Gestalt(gestaltSystemVersion
, &theSystem
);
92 if ( majorVsn
!= NULL
)
93 *majorVsn
= (theSystem
>> 8);
95 if ( minorVsn
!= NULL
)
96 *minorVsn
= (theSystem
& 0xFF);
98 return wxOS_MAC_OSX_DARWIN
;
101 #include <sys/utsname.h>
103 wxString
wxGetOsDescription()
107 return wxString::Format(_T("Mac OS X (%s %s %s)"),
108 wxString::FromAscii(name
.sysname
).c_str(),
109 wxString::FromAscii(name
.release
).c_str(),
110 wxString::FromAscii(name
.machine
).c_str());
113 #endif // wxOSX_USE_COCOA_OR_CARBON
116 //---------------------------------------------------------------------------
117 // wxMac Specific utility functions
118 //---------------------------------------------------------------------------
120 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
122 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
123 int len
= strlen(buf
);
128 memcpy( (char*) &to
[1] , buf
, len
);
131 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
133 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
140 // Check whether this window wants to process messages, e.g. Stop button
141 // in long calculations.
142 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
148 // Return true if we have a colour display
149 bool wxColourDisplay()
154 #if wxOSX_USE_COCOA_OR_CARBON
155 // Returns depth of screen
158 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
162 // Get size of display
163 void wxDisplaySize(int *width
, int *height
)
165 // TODO adapt for multi-displays
166 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
168 *width
= (int)bounds
.size
.width
;
170 *height
= (int)bounds
.size
.height
;
174 void wxDisplaySizeMM(int *width
, int *height
)
176 wxDisplaySize(width
, height
);
177 // on mac 72 is fixed (at least now;-)
178 double cvPt2Mm
= 25.4 / 72;
181 *width
= int( *width
* cvPt2Mm
);
184 *height
= int( *height
* cvPt2Mm
);
188 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
190 // We suppose that toolkit version is the same as OS version under Mac
191 wxGetOsVersion(verMaj
, verMin
);
196 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
198 return new wxEventLoop
;
201 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
203 return wxGenericFindWindowAtPoint(pt
);
207 Return the generic RGB color space. This is a 'get' function and the caller should
208 not release the returned value unless the caller retains it first. Usually callers
209 of this routine will immediately use the returned colorspace with CoreGraphics
210 so they typically do not need to retain it themselves.
212 This function creates the generic RGB color space once and hangs onto it so it can
213 return it whenever this function is called.
216 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
218 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
220 if (genericRGBColorSpace
== NULL
)
223 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
225 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
229 return genericRGBColorSpace
;
232 #if wxOSX_USE_COCOA_OR_CARBON
234 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
237 HIThemeBrushCreateCGColor( brush
, &color
);
241 #endif // wxOSX_USE_COCOA_OR_CARBON
243 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
245 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
248 m_isRootControl
= isRootControl
;
252 wxWidgetImpl::wxWidgetImpl()
257 wxWidgetImpl::~wxWidgetImpl()
261 void wxWidgetImpl::Init()
263 m_isRootControl
= false;
265 m_needsFocusRect
= false;
268 void wxWidgetImpl::Destroy()
272 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
274 m_needsFocusRect
= needs
;
277 bool wxWidgetImpl::NeedsFocusRect() const
279 return m_needsFocusRect
;