]> git.saurik.com Git - wxWidgets.git/blame - src/osx/utils_osx.cpp
supporting disabled items, closes #11130
[wxWidgets.git] / src / osx / utils_osx.cpp
CommitLineData
3ccc5735
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/utils_osx.cpp
3// Purpose: Various utilities
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id: utils.cpp 54886 2008-07-31 13:02:53Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12
13#include "wx/wxprec.h"
14
15#include "wx/utils.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/app.h"
a56a99ab 20 #include "wx/log.h"
3ccc5735
SC
21 #if wxUSE_GUI
22 #include "wx/toplevel.h"
23 #include "wx/font.h"
24 #endif
25#endif
26
27#include "wx/apptrait.h"
28
29#include <ctype.h>
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <stdarg.h>
35
36// #include "MoreFilesX.h"
37
38#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
39 #include <AudioToolbox/AudioServices.h>
40#endif
41
42#include "wx/osx/private.h"
b2767951 43#include "wx/osx/private/timer.h"
3ccc5735
SC
44
45#include "wx/evtloop.h"
46
47#if defined(__MWERKS__) && wxUSE_UNICODE
48#if __MWERKS__ < 0x4100
49 #include <wtime.h>
50#endif
51#endif
52
3ccc5735
SC
53// Check whether this window wants to process messages, e.g. Stop button
54// in long calculations.
55bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
56{
57 // TODO
58 return false;
59}
60
61// Return true if we have a colour display
62bool wxColourDisplay()
63{
64 return true;
65}
66
67#if wxOSX_USE_COCOA_OR_CARBON
68// Returns depth of screen
69int wxDisplayDepth()
70{
71 int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
72 return theDepth;
73}
74
75// Get size of display
76void wxDisplaySize(int *width, int *height)
77{
78 // TODO adapt for multi-displays
79 CGRect bounds = CGDisplayBounds(CGMainDisplayID());
80 if ( width )
81 *width = (int)bounds.size.width ;
82 if ( height )
83 *height = (int)bounds.size.height;
84}
2ae328d1
SC
85
86#if wxUSE_GUI
87
88// ----------------------------------------------------------------------------
89// Launch document with default app
90// ----------------------------------------------------------------------------
91
92bool wxLaunchDefaultApplication(const wxString& document, int flags)
93{
94 wxUnusedVar(flags);
95
96 static const char * const OPEN_CMD = "/usr/bin/open";
97 if ( wxFileExists(OPEN_CMD) &&
98 wxExecute(wxString(OPEN_CMD) + " " + document) )
99 return true;
100
101 return false;
102}
103
104// ----------------------------------------------------------------------------
105// Launch default browser
106// ----------------------------------------------------------------------------
107
108bool wxDoLaunchDefaultBrowser(const wxString& url, int flags)
109{
110 wxUnusedVar(flags);
111 wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault,
112 wxCFStringRef( url ), NULL ) );
113 OSStatus err = LSOpenCFURLRef( curl , NULL );
114
115 if (err == noErr)
116 {
117 return true;
118 }
119 else
120 {
121 wxLogDebug(wxT("Browser Launch error %d"), (int) err);
122 return false;
123 }
124}
125
126#endif // wxUSE_GUI
127
3ccc5735
SC
128#endif
129
130void wxDisplaySizeMM(int *width, int *height)
131{
132 wxDisplaySize(width, height);
133 // on mac 72 is fixed (at least now;-)
134 double cvPt2Mm = 25.4 / 72;
135
136 if (width != NULL)
137 *width = int( *width * cvPt2Mm );
138
139 if (height != NULL)
140 *height = int( *height * cvPt2Mm );
141}
142
143
144wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
145{
146 // We suppose that toolkit version is the same as OS version under Mac
147 wxGetOsVersion(verMaj, verMin);
148
149 return wxPORT_OSX;
150}
151
152wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
153{
154 return new wxEventLoop;
155}
156
157wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
158{
159 return wxGenericFindWindowAtPoint(pt);
160}
161
162/*
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.
167
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.
170*/
171
172CGColorSpaceRef wxMacGetGenericRGBColorSpace()
173{
174 static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
175
176 if (genericRGBColorSpace == NULL)
177 {
178#if wxOSX_USE_IPHONE
179 genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
180#else
181 genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
182#endif
183 }
184
185 return genericRGBColorSpace;
186}
187
188#if wxOSX_USE_COCOA_OR_CARBON
189
190CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
191{
192 CGColorRef color ;
193 HIThemeBrushCreateCGColor( brush, &color );
194 return color;
195}
196
1e181c7a
SC
197//---------------------------------------------------------------------------
198// Mac Specific string utility functions
199//---------------------------------------------------------------------------
200
201void wxMacStringToPascal( const wxString&from , unsigned char * to )
202{
203 wxCharBuffer buf = from.mb_str( wxConvLocal );
204 int len = strlen(buf);
205
206 if ( len > 255 )
207 len = 255;
208 to[0] = len;
209 memcpy( (char*) &to[1] , buf , len );
210}
211
212wxString wxMacMakeStringFromPascal( const unsigned char * from )
213{
214 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
215}
216
3ccc5735 217#endif // wxOSX_USE_COCOA_OR_CARBON