]>
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"
22 #include "wx/toplevel.h"
27 #include "wx/apptrait.h"
36 // #include "MoreFilesX.h"
38 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
39 #include <AudioToolbox/AudioServices.h>
42 #include "wx/osx/private.h"
44 #ifdef wxOSX_USE_COCOA
45 // to get the themeing APIs
46 #include <Carbon/Carbon.h>
49 #include "wx/osx/private/timer.h"
51 #include "wx/evtloop.h"
53 #if defined(__MWERKS__) && wxUSE_UNICODE
54 #if __MWERKS__ < 0x4100
59 // Check whether this window wants to process messages, e.g. Stop button
60 // in long calculations.
61 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
67 // Return true if we have a colour display
68 bool wxColourDisplay()
73 #if wxOSX_USE_COCOA_OR_CARBON
74 // Returns depth of screen
77 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
81 // Get size of display
82 void wxDisplaySize(int *width
, int *height
)
84 // TODO adapt for multi-displays
85 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
87 *width
= (int)bounds
.size
.width
;
89 *height
= (int)bounds
.size
.height
;
94 // ----------------------------------------------------------------------------
95 // Launch document with default app
96 // ----------------------------------------------------------------------------
98 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
102 static const char * const OPEN_CMD
= "/usr/bin/open";
103 if ( wxFileExists(OPEN_CMD
) &&
104 wxExecute(wxString(OPEN_CMD
) + " " + document
) )
110 // ----------------------------------------------------------------------------
111 // Launch default browser
112 // ----------------------------------------------------------------------------
114 bool wxDoLaunchDefaultBrowser(const wxString
& url
, int flags
)
117 wxCFRef
< CFURLRef
> curl( CFURLCreateWithString( kCFAllocatorDefault
,
118 wxCFStringRef( url
), NULL
) );
119 OSStatus err
= LSOpenCFURLRef( curl
, NULL
);
127 wxLogDebug(wxT("Browser Launch error %d"), (int) err
);
136 void wxDisplaySizeMM(int *width
, int *height
)
138 wxDisplaySize(width
, height
);
139 // on mac 72 is fixed (at least now;-)
140 double cvPt2Mm
= 25.4 / 72;
143 *width
= int( *width
* cvPt2Mm
);
146 *height
= int( *height
* cvPt2Mm
);
150 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
152 // We suppose that toolkit version is the same as OS version under Mac
153 wxGetOsVersion(verMaj
, verMin
);
158 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
160 return new wxEventLoop
;
163 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
165 return wxGenericFindWindowAtPoint(pt
);
169 Return the generic RGB color space. This is a 'get' function and the caller should
170 not release the returned value unless the caller retains it first. Usually callers
171 of this routine will immediately use the returned colorspace with CoreGraphics
172 so they typically do not need to retain it themselves.
174 This function creates the generic RGB color space once and hangs onto it so it can
175 return it whenever this function is called.
178 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
180 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
182 if (genericRGBColorSpace
== NULL
)
185 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
187 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
191 return genericRGBColorSpace
;
194 #if wxOSX_USE_COCOA_OR_CARBON
196 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
199 HIThemeBrushCreateCGColor( brush
, &color
);
203 //---------------------------------------------------------------------------
204 // Mac Specific string utility functions
205 //---------------------------------------------------------------------------
207 void wxMacStringToPascal( const wxString
&from
, unsigned char * to
)
209 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
210 int len
= strlen(buf
);
215 memcpy( (char*) &to
[1] , buf
, len
);
218 wxString
wxMacMakeStringFromPascal( const unsigned char * from
)
220 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
223 #endif // wxOSX_USE_COCOA_OR_CARBON