]> git.saurik.com Git - wxWidgets.git/blame - src/osx/utils_osx.cpp
Removed extraneous semicolons and commas (partly fixes #10456).
[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"
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
b2767951 48#include "wx/osx/private/timer.h"
3ccc5735
SC
49
50#include "wx/evtloop.h"
51
52#if defined(__MWERKS__) && wxUSE_UNICODE
53#if __MWERKS__ < 0x4100
54 #include <wtime.h>
55#endif
56#endif
57
3ccc5735
SC
58// Check whether this window wants to process messages, e.g. Stop button
59// in long calculations.
60bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
61{
62 // TODO
63 return false;
64}
65
66// Return true if we have a colour display
67bool wxColourDisplay()
68{
69 return true;
70}
71
72#if wxOSX_USE_COCOA_OR_CARBON
73// Returns depth of screen
74int wxDisplayDepth()
75{
76 int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
77 return theDepth;
78}
79
80// Get size of display
81void wxDisplaySize(int *width, int *height)
82{
83 // TODO adapt for multi-displays
84 CGRect bounds = CGDisplayBounds(CGMainDisplayID());
85 if ( width )
86 *width = (int)bounds.size.width ;
87 if ( height )
88 *height = (int)bounds.size.height;
89}
2ae328d1
SC
90
91#if wxUSE_GUI
92
93// ----------------------------------------------------------------------------
94// Launch document with default app
95// ----------------------------------------------------------------------------
96
97bool wxLaunchDefaultApplication(const wxString& document, int flags)
98{
99 wxUnusedVar(flags);
100
101 static const char * const OPEN_CMD = "/usr/bin/open";
102 if ( wxFileExists(OPEN_CMD) &&
103 wxExecute(wxString(OPEN_CMD) + " " + document) )
104 return true;
105
106 return false;
107}
108
109// ----------------------------------------------------------------------------
110// Launch default browser
111// ----------------------------------------------------------------------------
112
113bool wxDoLaunchDefaultBrowser(const wxString& url, int flags)
114{
115 wxUnusedVar(flags);
116 wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault,
117 wxCFStringRef( url ), NULL ) );
118 OSStatus err = LSOpenCFURLRef( curl , NULL );
119
120 if (err == noErr)
121 {
122 return true;
123 }
124 else
125 {
126 wxLogDebug(wxT("Browser Launch error %d"), (int) err);
127 return false;
128 }
129}
130
131#endif // wxUSE_GUI
132
3ccc5735
SC
133#endif
134
135void wxDisplaySizeMM(int *width, int *height)
136{
137 wxDisplaySize(width, height);
138 // on mac 72 is fixed (at least now;-)
139 double cvPt2Mm = 25.4 / 72;
140
141 if (width != NULL)
142 *width = int( *width * cvPt2Mm );
143
144 if (height != NULL)
145 *height = int( *height * cvPt2Mm );
146}
147
148
149wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
150{
151 // We suppose that toolkit version is the same as OS version under Mac
152 wxGetOsVersion(verMaj, verMin);
153
154 return wxPORT_OSX;
155}
156
157wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
158{
159 return new wxEventLoop;
160}
161
162wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
163{
164 return wxGenericFindWindowAtPoint(pt);
165}
166
167/*
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.
172
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.
175*/
176
177CGColorSpaceRef wxMacGetGenericRGBColorSpace()
178{
179 static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
180
181 if (genericRGBColorSpace == NULL)
182 {
183#if wxOSX_USE_IPHONE
184 genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
185#else
186 genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
187#endif
188 }
189
190 return genericRGBColorSpace;
191}
192
193#if wxOSX_USE_COCOA_OR_CARBON
194
195CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
196{
197 CGColorRef color ;
198 HIThemeBrushCreateCGColor( brush, &color );
199 return color;
200}
201
1e181c7a
SC
202//---------------------------------------------------------------------------
203// Mac Specific string utility functions
204//---------------------------------------------------------------------------
205
206void wxMacStringToPascal( const wxString&from , unsigned char * to )
207{
208 wxCharBuffer buf = from.mb_str( wxConvLocal );
209 int len = strlen(buf);
210
211 if ( len > 255 )
212 len = 255;
213 to[0] = len;
214 memcpy( (char*) &to[1] , buf , len );
215}
216
217wxString wxMacMakeStringFromPascal( const unsigned char * from )
218{
219 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
220}
221
3ccc5735 222#endif // wxOSX_USE_COCOA_OR_CARBON