]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/utils.mm
added Vietnamese translations
[wxWidgets.git] / src / osx / cocoa / utils.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/utils.mm
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
33 #include <CoreServices/CoreServices.h>
34 #include "wx/osx/dcclient.h"
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
44 void wxBell()
45 {
46 NSBeep();
47 }
48
49 // ----------------------------------------------------------------------------
50 // Common Event Support
51 // ----------------------------------------------------------------------------
52
53 void wxMacWakeUp()
54 {
55 // TODO
56 }
57
58 #endif // wxUSE_BASE
59
60 #if wxUSE_GUI
61
62 bool wxApp::DoInitGui()
63 {
64 [NSApplication sharedApplication];
65 [NSApp finishLaunching];
66 return true;
67 }
68
69 void wxApp::DoCleanUp()
70 {
71 }
72
73 void 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
88 void wxGetMousePosition( int* x, int* y )
89 {
90 wxPoint pt = wxFromNSPoint(NULL, [NSEvent mouseLocation]);
91 };
92
93 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
94 {
95 return new wxOSXTimerImpl(timer);
96 }
97
98 int gs_wxBusyCursorCount = 0;
99 extern wxCursor gMacCurrentCursor;
100 wxCursor gMacStoredActiveCursor;
101
102 // Set the cursor to the busy cursor for all windows
103 void 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
116 void 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
131 bool wxIsBusy()
132 {
133 return (gs_wxBusyCursorCount > 0);
134 }
135
136 void wxMacGlobalToLocal( WindowRef window , Point*pt )
137 {
138 }
139
140 void wxMacLocalToGlobal( WindowRef window , Point*pt )
141 {
142 }
143
144 wxBitmap 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
166 CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
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
179 #endif // wxUSE_GUI
180
181
182
183 #endif // wxOSX_USE_COCOA