1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/utils.mm
3 // Purpose: various cocoa utility functions
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: utils.mm 48805 2007-09-19 14:52:25Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/wxprec.h"
22 #include "wx/toplevel.h"
27 #include "wx/apptrait.h"
29 #include "wx/osx/private.h"
32 #if wxOSX_USE_COCOA_OR_CARBON
33 #include <CoreServices/CoreServices.h>
34 #include "wx/osx/dcclient.h"
35 #include "wx/osx/private/timer.h"
49 // ----------------------------------------------------------------------------
50 // Common Event Support
51 // ----------------------------------------------------------------------------
62 bool wxApp::DoInitGui()
64 [NSApplication sharedApplication];
65 [NSApp finishLaunching];
69 void wxApp::DoCleanUp()
73 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
75 NSRect displayRect = [[NSScreen mainScreen] visibleFrame];
76 wxRect r = wxFromNSRect( NULL, displayRect );
82 *width = r.GetWidth();
84 *height = r.GetHeight();
88 void wxGetMousePosition( int* x, int* y )
90 wxPoint pt = wxFromNSPoint(NULL, [NSEvent mouseLocation]);
93 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
95 return new wxOSXTimerImpl(timer);
98 int gs_wxBusyCursorCount = 0;
99 extern wxCursor gMacCurrentCursor;
100 wxCursor gMacStoredActiveCursor;
102 // Set the cursor to the busy cursor for all windows
103 void wxBeginBusyCursor(const wxCursor *cursor)
105 if (gs_wxBusyCursorCount++ == 0)
107 gMacStoredActiveCursor = gMacCurrentCursor;
108 cursor->MacInstall();
110 wxSetCursor(*cursor);
112 //else: nothing to do, already set
115 // Restore cursor to normal
116 void wxEndBusyCursor()
118 wxCHECK_RET( gs_wxBusyCursorCount > 0,
119 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
121 if (--gs_wxBusyCursorCount == 0)
123 gMacStoredActiveCursor.MacInstall();
124 gMacStoredActiveCursor = wxNullCursor;
126 wxSetCursor(wxNullCursor);
130 // true if we're between the above two calls
133 return (gs_wxBusyCursorCount > 0);
136 void wxMacGlobalToLocal( WindowRef window , Point*pt )
140 void wxMacLocalToGlobal( WindowRef window , Point*pt )
144 wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
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.
151 wxSize sz = m_window->GetSize();
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 ;
158 NSRect rect = NSMakeRect(left, top, width, height );
159 NSView* view = (NSView*) m_window->GetHandle();
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];
166 CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
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);
183 #endif // wxOSX_USE_COCOA