]>
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
;
93 // ----------------------------------------------------------------------------
94 // Launch document with default app
95 // ----------------------------------------------------------------------------
97 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
101 static const char * const OPEN_CMD
= "/usr/bin/open";
102 if ( wxFileExists(OPEN_CMD
) &&
103 wxExecute(wxString(OPEN_CMD
) + " " + document
) )
109 // ----------------------------------------------------------------------------
110 // Launch default browser
111 // ----------------------------------------------------------------------------
113 bool wxDoLaunchDefaultBrowser(const wxString
& url
, int flags
)
116 wxCFRef
< CFURLRef
> curl( CFURLCreateWithString( kCFAllocatorDefault
,
117 wxCFStringRef( url
), NULL
) );
118 OSStatus err
= LSOpenCFURLRef( curl
, NULL
);
126 wxLogDebug(wxT("Browser Launch error %d"), (int) err
);
135 void wxDisplaySizeMM(int *width
, int *height
)
137 wxDisplaySize(width
, height
);
138 // on mac 72 is fixed (at least now;-)
139 double cvPt2Mm
= 25.4 / 72;
142 *width
= int( *width
* cvPt2Mm
);
145 *height
= int( *height
* cvPt2Mm
);
149 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
151 // We suppose that toolkit version is the same as OS version under Mac
152 wxGetOsVersion(verMaj
, verMin
);
157 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
159 return new wxEventLoop
;
162 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
164 return wxGenericFindWindowAtPoint(pt
);
168 Return the generic RGB color space. This is a 'get' function and the caller should
169 not release the returned value unless the caller retains it first. Usually callers
170 of this routine will immediately use the returned colorspace with CoreGraphics
171 so they typically do not need to retain it themselves.
173 This function creates the generic RGB color space once and hangs onto it so it can
174 return it whenever this function is called.
177 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
179 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
181 if (genericRGBColorSpace
== NULL
)
184 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
186 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
190 return genericRGBColorSpace
;
193 #if wxOSX_USE_COCOA_OR_CARBON
195 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
198 HIThemeBrushCreateCGColor( brush
, &color
);
202 //---------------------------------------------------------------------------
203 // Mac Specific string utility functions
204 //---------------------------------------------------------------------------
206 void wxMacStringToPascal( const wxString
&from
, unsigned char * to
)
208 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
209 int len
= strlen(buf
);
214 memcpy( (char*) &to
[1] , buf
, len
);
217 wxString
wxMacMakeStringFromPascal( const unsigned char * from
)
219 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
222 #endif // wxOSX_USE_COCOA_OR_CARBON