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