]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/utils.mm
Update OpenVMS compile support
[wxWidgets.git] / src / osx / cocoa / utils.mm
CommitLineData
33e90275 1/////////////////////////////////////////////////////////////////////////////
0f9b48d1 2// Name: src/osx/cocoa/utils.mm
33e90275
SC
3// Purpose: various cocoa utility functions
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id: utils.mm 48805 2007-09-19 14:52:25Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/wxprec.h"
15
16#include "wx/utils.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/app.h"
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 "wx/osx/private.h"
30
31#if wxUSE_GUI
32#if wxOSX_USE_COCOA_OR_CARBON
33e90275 33 #include <CoreServices/CoreServices.h>
928e7a7e 34 #include "wx/osx/dcclient.h"
33e90275
SC
35 #include "wx/osx/private/timer.h"
36#endif
37#endif // wxUSE_GUI
38
39#if wxOSX_USE_COCOA
40
41#if wxUSE_BASE
42
43// Emit a beeeeeep
44void wxBell()
45{
46 NSBeep();
47}
48
49// ----------------------------------------------------------------------------
50// Common Event Support
51// ----------------------------------------------------------------------------
52
53void wxMacWakeUp()
54{
55 // TODO
56}
57
58#endif // wxUSE_BASE
dbeddfb9 59
36eca861
SC
60#if wxUSE_GUI
61
dbeddfb9
SC
62bool wxApp::DoInitGui()
63{
64 [NSApplication sharedApplication];
65 [NSApp finishLaunching];
66 return true;
67}
68
69void wxApp::DoCleanUp()
70{
71}
33e90275 72
33e90275
SC
73void wxClientDisplayRect(int *x, int *y, int *width, int *height)
74{
75 NSRect displayRect = [[NSScreen mainScreen] visibleFrame];
76 wxRect r = wxFromNSRect( NULL, displayRect );
77 if ( x )
78 *x = r.x;
79 if ( y )
80 *y = r.y;
81 if ( width )
82 *width = r.GetWidth();
83 if ( height )
84 *height = r.GetHeight();
85
86}
87
88void wxGetMousePosition( int* x, int* y )
89{
90 wxPoint pt = wxFromNSPoint(NULL, [NSEvent mouseLocation]);
91};
92
93wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
94{
dbeddfb9 95 return new wxOSXTimerImpl(timer);
33e90275
SC
96}
97
98int gs_wxBusyCursorCount = 0;
99extern wxCursor gMacCurrentCursor;
100wxCursor gMacStoredActiveCursor;
101
102// Set the cursor to the busy cursor for all windows
103void wxBeginBusyCursor(const wxCursor *cursor)
104{
105 if (gs_wxBusyCursorCount++ == 0)
106 {
107 gMacStoredActiveCursor = gMacCurrentCursor;
108 cursor->MacInstall();
109
110 wxSetCursor(*cursor);
111 }
112 //else: nothing to do, already set
113}
114
115// Restore cursor to normal
116void wxEndBusyCursor()
117{
118 wxCHECK_RET( gs_wxBusyCursorCount > 0,
119 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
120
121 if (--gs_wxBusyCursorCount == 0)
122 {
123 gMacStoredActiveCursor.MacInstall();
124 gMacStoredActiveCursor = wxNullCursor;
125
126 wxSetCursor(wxNullCursor);
127 }
128}
129
130// true if we're between the above two calls
131bool wxIsBusy()
132{
133 return (gs_wxBusyCursorCount > 0);
134}
135
136void wxMacGlobalToLocal( WindowRef window , Point*pt )
137{
138}
139
140void wxMacLocalToGlobal( WindowRef window , Point*pt )
141{
142}
143
928e7a7e
KO
144wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
145{
146 // wxScreenDC is derived from wxWindowDC, so a screen dc will
147 // call this method when a Blit is performed with it as a source.
148 if (!m_window)
149 return wxNullBitmap;
150
151 wxSize sz = m_window->GetSize();
152
153 int left = subrect != NULL ? subrect->x : 0 ;
154 int top = subrect != NULL ? subrect->y : 0 ;
155 int width = subrect != NULL ? subrect->width : sz.x;
156 int height = subrect != NULL ? subrect->height : sz.y ;
157
158 NSRect rect = NSMakeRect(left, top, width, height );
159 NSView* view = (NSView*) m_window->GetHandle();
160 [view lockFocus];
161 // we use this method as other methods force a repaint, and this method can be
162 // called from OnPaint, even with the window's paint dc as source (see wxHTMLWindow)
163 NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain];
164 [view unlockFocus];
165
cfea8e61 166 CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
928e7a7e
KO
167
168 wxBitmap bitmap(CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
169 CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
170 // since our context is upside down we dont use CGContextDrawImage
171 wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ;
172 CGImageRelease(cgImageRef);
173 cgImageRef = NULL;
174 [rep release];
175
176 return bitmap;
177}
178
33e90275
SC
179#endif // wxUSE_GUI
180
181
182
183#endif // wxOSX_USE_COCOA