]> git.saurik.com Git - wxWidgets.git/blame - src/osx/utils_osx.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[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}
90#endif
91
92void wxDisplaySizeMM(int *width, int *height)
93{
94 wxDisplaySize(width, height);
95 // on mac 72 is fixed (at least now;-)
96 double cvPt2Mm = 25.4 / 72;
97
98 if (width != NULL)
99 *width = int( *width * cvPt2Mm );
100
101 if (height != NULL)
102 *height = int( *height * cvPt2Mm );
103}
104
105
106wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
107{
108 // We suppose that toolkit version is the same as OS version under Mac
109 wxGetOsVersion(verMaj, verMin);
110
111 return wxPORT_OSX;
112}
113
114wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
115{
116 return new wxEventLoop;
117}
118
119wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
120{
121 return wxGenericFindWindowAtPoint(pt);
122}
123
124/*
125 Return the generic RGB color space. This is a 'get' function and the caller should
126 not release the returned value unless the caller retains it first. Usually callers
127 of this routine will immediately use the returned colorspace with CoreGraphics
128 so they typically do not need to retain it themselves.
129
130 This function creates the generic RGB color space once and hangs onto it so it can
131 return it whenever this function is called.
132*/
133
134CGColorSpaceRef wxMacGetGenericRGBColorSpace()
135{
136 static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
137
138 if (genericRGBColorSpace == NULL)
139 {
140#if wxOSX_USE_IPHONE
141 genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
142#else
143 genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
144#endif
145 }
146
147 return genericRGBColorSpace;
148}
149
150#if wxOSX_USE_COCOA_OR_CARBON
151
152CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
153{
154 CGColorRef color ;
155 HIThemeBrushCreateCGColor( brush, &color );
156 return color;
157}
158
1e181c7a
SC
159//---------------------------------------------------------------------------
160// Mac Specific string utility functions
161//---------------------------------------------------------------------------
162
163void wxMacStringToPascal( const wxString&from , unsigned char * to )
164{
165 wxCharBuffer buf = from.mb_str( wxConvLocal );
166 int len = strlen(buf);
167
168 if ( len > 255 )
169 len = 255;
170 to[0] = len;
171 memcpy( (char*) &to[1] , buf , len );
172}
173
174wxString wxMacMakeStringFromPascal( const unsigned char * from )
175{
176 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
177}
178
3ccc5735 179#endif // wxOSX_USE_COCOA_OR_CARBON