]> git.saurik.com Git - wxWidgets.git/blob - src/osx/utils_osx.cpp
adaptions to new osx ouside the main trees
[wxWidgets.git] / src / osx / utils_osx.cpp
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"
20 #if wxUSE_GUI
21 #include "wx/toplevel.h"
22 #include "wx/font.h"
23 #endif
24 #endif
25
26 #include "wx/apptrait.h"
27
28 #include <ctype.h>
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34
35 // #include "MoreFilesX.h"
36
37 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
38 #include <AudioToolbox/AudioServices.h>
39 #endif
40
41 #include "wx/osx/private.h"
42
43 #ifdef wxOSX_USE_COCOA
44 // to get the themeing APIs
45 #include <Carbon/Carbon.h>
46 #endif
47
48 #if wxUSE_GUI
49 #include "wx/osx/private/timer.h"
50 #endif // wxUSE_GUI
51
52 #include "wx/evtloop.h"
53
54 #if defined(__MWERKS__) && wxUSE_UNICODE
55 #if __MWERKS__ < 0x4100
56 #include <wtime.h>
57 #endif
58 #endif
59
60 #if wxUSE_BASE
61
62 extern bool WXDLLEXPORT wxIsDebuggerRunning()
63 {
64 // TODO : try to find out ...
65 return false;
66 }
67
68 #if wxOSX_USE_COCOA_OR_CARBON
69
70 // have a fast version for mac code that returns the version as a return value
71
72 long UMAGetSystemVersion()
73 {
74 static SInt32 sUMASystemVersion = 0 ;
75 if ( sUMASystemVersion == 0 )
76 {
77 verify_noerr(Gestalt(gestaltSystemVersion, &sUMASystemVersion));
78 }
79 return sUMASystemVersion ;
80 }
81
82 // our OS version is the same in non GUI and GUI cases
83 wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn)
84 {
85 SInt32 theSystem;
86 Gestalt(gestaltSystemVersion, &theSystem);
87
88 if ( majorVsn != NULL )
89 *majorVsn = (theSystem >> 8);
90
91 if ( minorVsn != NULL )
92 *minorVsn = (theSystem & 0xFF);
93
94 return wxOS_MAC_OSX_DARWIN;
95 }
96
97 #include <sys/utsname.h>
98
99 wxString wxGetOsDescription()
100 {
101 struct utsname name;
102 uname(&name);
103 return wxString::Format(_T("Mac OS X (%s %s %s)"),
104 wxString::FromAscii(name.sysname).c_str(),
105 wxString::FromAscii(name.release).c_str(),
106 wxString::FromAscii(name.machine).c_str());
107 }
108
109 #endif // wxOSX_USE_COCOA_OR_CARBON
110
111
112 //---------------------------------------------------------------------------
113 // wxMac Specific utility functions
114 //---------------------------------------------------------------------------
115
116 void wxMacStringToPascal( const wxString&from , StringPtr to )
117 {
118 wxCharBuffer buf = from.mb_str( wxConvLocal );
119 int len = strlen(buf);
120
121 if ( len > 255 )
122 len = 255;
123 to[0] = len;
124 memcpy( (char*) &to[1] , buf , len );
125 }
126
127 wxString wxMacMakeStringFromPascal( ConstStringPtr from )
128 {
129 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
130 }
131
132 #endif // wxUSE_BASE
133
134 #if wxUSE_GUI
135
136 // Check whether this window wants to process messages, e.g. Stop button
137 // in long calculations.
138 bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
139 {
140 // TODO
141 return false;
142 }
143
144 // Return true if we have a colour display
145 bool wxColourDisplay()
146 {
147 return true;
148 }
149
150 #if wxOSX_USE_COCOA_OR_CARBON
151 // Returns depth of screen
152 int wxDisplayDepth()
153 {
154 int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
155 return theDepth;
156 }
157
158 // Get size of display
159 void wxDisplaySize(int *width, int *height)
160 {
161 // TODO adapt for multi-displays
162 CGRect bounds = CGDisplayBounds(CGMainDisplayID());
163 if ( width )
164 *width = (int)bounds.size.width ;
165 if ( height )
166 *height = (int)bounds.size.height;
167 }
168 #endif
169
170 void wxDisplaySizeMM(int *width, int *height)
171 {
172 wxDisplaySize(width, height);
173 // on mac 72 is fixed (at least now;-)
174 double cvPt2Mm = 25.4 / 72;
175
176 if (width != NULL)
177 *width = int( *width * cvPt2Mm );
178
179 if (height != NULL)
180 *height = int( *height * cvPt2Mm );
181 }
182
183
184 wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
185 {
186 // We suppose that toolkit version is the same as OS version under Mac
187 wxGetOsVersion(verMaj, verMin);
188
189 return wxPORT_OSX;
190 }
191
192 wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
193 {
194 return new wxEventLoop;
195 }
196
197 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
198 {
199 return wxGenericFindWindowAtPoint(pt);
200 }
201
202 /*
203 Return the generic RGB color space. This is a 'get' function and the caller should
204 not release the returned value unless the caller retains it first. Usually callers
205 of this routine will immediately use the returned colorspace with CoreGraphics
206 so they typically do not need to retain it themselves.
207
208 This function creates the generic RGB color space once and hangs onto it so it can
209 return it whenever this function is called.
210 */
211
212 CGColorSpaceRef wxMacGetGenericRGBColorSpace()
213 {
214 static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
215
216 if (genericRGBColorSpace == NULL)
217 {
218 #if wxOSX_USE_IPHONE
219 genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
220 #else
221 genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
222 #endif
223 }
224
225 return genericRGBColorSpace;
226 }
227
228 #if wxOSX_USE_COCOA_OR_CARBON
229
230 CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
231 {
232 CGColorRef color ;
233 HIThemeBrushCreateCGColor( brush, &color );
234 return color;
235 }
236
237 #endif // wxOSX_USE_COCOA_OR_CARBON
238
239 #endif // wxUSE_GUI