]>
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"
43 #include "wx/osx/private/timer.h"
45 #include "wx/evtloop.h"
47 #if defined(__MWERKS__) && wxUSE_UNICODE
48 #if __MWERKS__ < 0x4100
53 // Check whether this window wants to process messages, e.g. Stop button
54 // in long calculations.
55 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
61 // Return true if we have a colour display
62 bool wxColourDisplay()
67 #if wxOSX_USE_COCOA_OR_CARBON
68 // Returns depth of screen
71 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
75 // Get size of display
76 void wxDisplaySize(int *width
, int *height
)
78 // TODO adapt for multi-displays
79 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
81 *width
= (int)bounds
.size
.width
;
83 *height
= (int)bounds
.size
.height
;
88 // ----------------------------------------------------------------------------
89 // Launch document with default app
90 // ----------------------------------------------------------------------------
92 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
96 static const char * const OPEN_CMD
= "/usr/bin/open";
97 if ( wxFileExists(OPEN_CMD
) &&
98 wxExecute(wxString(OPEN_CMD
) + " " + document
) )
104 // ----------------------------------------------------------------------------
105 // Launch default browser
106 // ----------------------------------------------------------------------------
108 bool wxDoLaunchDefaultBrowser(const wxString
& url
, int flags
)
111 wxCFRef
< CFURLRef
> curl( CFURLCreateWithString( kCFAllocatorDefault
,
112 wxCFStringRef( url
), NULL
) );
113 OSStatus err
= LSOpenCFURLRef( curl
, NULL
);
121 wxLogDebug(wxT("Browser Launch error %d"), (int) err
);
130 void wxDisplaySizeMM(int *width
, int *height
)
132 wxDisplaySize(width
, height
);
133 // on mac 72 is fixed (at least now;-)
134 double cvPt2Mm
= 25.4 / 72;
137 *width
= int( *width
* cvPt2Mm
);
140 *height
= int( *height
* cvPt2Mm
);
144 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
146 // We suppose that toolkit version is the same as OS version under Mac
147 wxGetOsVersion(verMaj
, verMin
);
152 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
154 return new wxEventLoop
;
157 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
159 return wxGenericFindWindowAtPoint(pt
);
163 Return the generic RGB color space. This is a 'get' function and the caller should
164 not release the returned value unless the caller retains it first. Usually callers
165 of this routine will immediately use the returned colorspace with CoreGraphics
166 so they typically do not need to retain it themselves.
168 This function creates the generic RGB color space once and hangs onto it so it can
169 return it whenever this function is called.
172 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
174 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
176 if (genericRGBColorSpace
== NULL
)
179 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
181 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
185 return genericRGBColorSpace
;
188 #if wxOSX_USE_COCOA_OR_CARBON
190 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
193 HIThemeBrushCreateCGColor( brush
, &color
);
197 //---------------------------------------------------------------------------
198 // Mac Specific string utility functions
199 //---------------------------------------------------------------------------
201 void wxMacStringToPascal( const wxString
&from
, unsigned char * to
)
203 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
204 int len
= strlen(buf
);
209 memcpy( (char*) &to
[1] , buf
, len
);
212 wxString
wxMacMakeStringFromPascal( const unsigned char * from
)
214 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
217 #endif // wxOSX_USE_COCOA_OR_CARBON