]>
Commit | Line | Data |
---|---|---|
a15eb0a5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/toplevel.cpp | |
d66c3960 SC |
3 | // Purpose: implements wxTopLevelWindow for Mac |
4 | // Author: Stefan Csomor | |
a15eb0a5 SC |
5 | // Modified by: |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
d66c3960 | 8 | // Copyright: (c) 2001-2004 Stefan Csomor |
65571936 | 9 | // License: wxWindows licence |
a15eb0a5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
3d1a4878 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a15eb0a5 SC |
21 | #pragma implementation "toplevel.h" |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | #include "wx/toplevel.h" | |
422644a3 | 34 | #include "wx/frame.h" |
a15eb0a5 SC |
35 | #include "wx/string.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
37ec2bd3 | 38 | #include "wx/settings.h" |
2d17efa9 | 39 | #include "wx/strconv.h" |
179e085f | 40 | #include "wx/control.h" |
a15eb0a5 SC |
41 | #endif //WX_PRECOMP |
42 | ||
5f0b2f22 | 43 | #include "wx/mac/uma.h" |
422644a3 | 44 | #include "wx/mac/aga.h" |
7c091673 | 45 | #include "wx/app.h" |
5f0b2f22 | 46 | #include "wx/tooltip.h" |
a07c1212 | 47 | #include "wx/dnd.h" |
1f90939c SC |
48 | #if wxUSE_SYSTEM_OPTIONS |
49 | #include "wx/sysopt.h" | |
50 | #endif | |
5f0b2f22 | 51 | |
7f0c3a63 | 52 | #include <ToolUtils.h> |
dd49c691 | 53 | |
eab19a7c RN |
54 | //For targeting OSX |
55 | #include "wx/mac/private.h" | |
56 | ||
a15eb0a5 SC |
57 | // ---------------------------------------------------------------------------- |
58 | // globals | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | // list of all frames and modeless dialogs | |
32b5be3d RR |
62 | wxWindowList wxModelessWindows; |
63 | ||
6a7e6411 RD |
64 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
65 | ||
a15eb0a5 SC |
66 | // ============================================================================ |
67 | // wxTopLevelWindowMac implementation | |
68 | // ============================================================================ | |
69 | ||
facd6764 SC |
70 | BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) |
71 | END_EVENT_TABLE() | |
72 | ||
73 | ||
851b3a88 SC |
74 | // --------------------------------------------------------------------------- |
75 | // Carbon Events | |
76 | // --------------------------------------------------------------------------- | |
77 | ||
851b3a88 SC |
78 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
79 | ||
1542ea39 | 80 | static const EventTypeSpec eventList[] = |
851b3a88 | 81 | { |
facd6764 | 82 | // TODO remove control related event like key and mouse (except for WindowLeave events) |
949cb163 | 83 | #if 1 |
851b3a88 | 84 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , |
c5c9378c | 85 | |
e40298d5 | 86 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
87 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
88 | { kEventClassKeyboard, kEventRawKeyUp } , | |
89 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
facd6764 | 90 | #endif |
c5c9378c | 91 | |
16a76184 | 92 | { kEventClassWindow , kEventWindowShown } , |
851b3a88 SC |
93 | { kEventClassWindow , kEventWindowActivated } , |
94 | { kEventClassWindow , kEventWindowDeactivated } , | |
95 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
96 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
97 | { kEventClassWindow , kEventWindowClose } , | |
98 | ||
facd6764 SC |
99 | // we have to catch these events on the toplevel window level, as controls don't get the |
100 | // raw mouse events anymore | |
101 | ||
851b3a88 SC |
102 | { kEventClassMouse , kEventMouseDown } , |
103 | { kEventClassMouse , kEventMouseUp } , | |
de127c69 | 104 | { kEventClassMouse , kEventMouseWheelMoved } , |
851b3a88 SC |
105 | { kEventClassMouse , kEventMouseMoved } , |
106 | { kEventClassMouse , kEventMouseDragged } , | |
851b3a88 SC |
107 | } ; |
108 | ||
109 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
110 | { | |
111 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 112 | |
c5c9378c | 113 | wxWindow* focus = wxWindow::FindFocus() ; |
19fc48c6 | 114 | unsigned char charCode ; |
1542ea39 | 115 | UInt32 keyCode ; |
c5c9378c | 116 | UInt32 modifiers ; |
e40298d5 | 117 | Point point ; |
c5c9378c SC |
118 | |
119 | EventRef rawEvent ; | |
1542ea39 | 120 | |
c5c9378c | 121 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 122 | |
e40298d5 JS |
123 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
124 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
125 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
126 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
127 | sizeof( Point ), NULL, &point ); | |
128 | ||
e40298d5 JS |
129 | switch ( GetEventKind( event ) ) |
130 | { | |
131 | case kEventTextInputUnicodeForKeyEvent : | |
ace07c80 | 132 | // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not |
5d2e69e8 | 133 | // get its own kEventTextInputUnicodeForKeyEvent, so we route back the |
ace07c80 SC |
134 | wxControl* control = wxDynamicCast( focus , wxControl ) ; |
135 | if ( control ) | |
136 | { | |
facd6764 | 137 | ControlRef macControl = (ControlRef) control->GetHandle() ; |
ace07c80 SC |
138 | if ( macControl ) |
139 | { | |
140 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
141 | result = noErr ; | |
142 | } | |
143 | } | |
144 | /* | |
145 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
77a4354e VZ |
146 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; |
147 | UInt32 message = (keyCode << 8) + charCode; | |
148 | ||
1542ea39 | 149 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
150 | focus , message , modifiers , when , point.h , point.v ) ) |
151 | { | |
152 | result = noErr ; | |
153 | } | |
ace07c80 | 154 | */ |
e40298d5 JS |
155 | break ; |
156 | } | |
c5c9378c SC |
157 | |
158 | return result ; | |
159 | } | |
160 | ||
161 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
162 | { | |
163 | OSStatus result = eventNotHandledErr ; | |
b3bd613a RR |
164 | // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl) |
165 | // FindFocus does not return the actual focus window,but the enclosing window | |
166 | wxWindow* focus = wxWindow::DoFindFocus(); | |
92a7272f SC |
167 | if ( focus == NULL ) |
168 | return result ; | |
169 | ||
19fc48c6 | 170 | unsigned char charCode ; |
2d17efa9 | 171 | wxChar uniChar = 0 ; |
1542ea39 | 172 | UInt32 keyCode ; |
c5c9378c | 173 | UInt32 modifiers ; |
e40298d5 JS |
174 | Point point ; |
175 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
176 | ||
2d17efa9 SC |
177 | #if wxUSE_UNICODE |
178 | UInt32 dataSize = 0 ; | |
179 | if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize , NULL ) == noErr ) | |
180 | { | |
181 | UniChar buf[2] ; | |
182 | ||
183 | UniChar* charBuf = buf ; | |
184 | ||
185 | if ( dataSize > 4 ) | |
186 | charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; | |
187 | GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; | |
188 | #if SIZEOF_WCHAR_T == 2 | |
189 | uniChar = charBuf[0] ; | |
190 | #else | |
191 | wxMBConvUTF16BE converter ; | |
192 | converter.MB2WC( &uniChar , (const char*)charBuf , 1 ) ; | |
193 | #endif | |
194 | if ( dataSize > 4 ) | |
195 | delete[] charBuf ; | |
196 | } | |
197 | #endif | |
198 | ||
e40298d5 JS |
199 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
200 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
201 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
202 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
203 | sizeof( Point ), NULL, &point ); | |
2d17efa9 | 204 | |
e40298d5 JS |
205 | UInt32 message = (keyCode << 8) + charCode; |
206 | switch( GetEventKind( event ) ) | |
207 | { | |
208 | case kEventRawKeyRepeat : | |
209 | case kEventRawKeyDown : | |
e40298d5 | 210 | { |
404f1d80 SC |
211 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
212 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
213 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
214 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( | |
2d17efa9 | 215 | focus , message , modifiers , when , point.h , point.v , uniChar ) ) |
404f1d80 SC |
216 | { |
217 | result = noErr ; | |
218 | } | |
219 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
e40298d5 JS |
220 | } |
221 | break ; | |
222 | case kEventRawKeyUp : | |
1542ea39 | 223 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
2d17efa9 | 224 | focus , message , modifiers , when , point.h , point.v , uniChar ) ) |
e40298d5 JS |
225 | { |
226 | result = noErr ; | |
227 | } | |
228 | break ; | |
229 | case kEventRawKeyModifiersChanged : | |
230 | { | |
231 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
232 | ||
233 | event.m_shiftDown = modifiers & shiftKey; | |
234 | event.m_controlDown = modifiers & controlKey; | |
235 | event.m_altDown = modifiers & optionKey; | |
236 | event.m_metaDown = modifiers & cmdKey; | |
2d17efa9 SC |
237 | #if wxUSE_UNICODE |
238 | event.m_uniChar = uniChar ; | |
239 | #endif | |
e40298d5 JS |
240 | event.m_x = point.h; |
241 | event.m_y = point.v; | |
687706f5 | 242 | event.SetTimestamp(when); |
e40298d5 JS |
243 | event.SetEventObject(focus); |
244 | ||
2a1f999f | 245 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & controlKey ) |
e40298d5 JS |
246 | { |
247 | event.m_keyCode = WXK_CONTROL ; | |
248 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
249 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
250 | } | |
2a1f999f | 251 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
252 | { |
253 | event.m_keyCode = WXK_SHIFT ; | |
254 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
255 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
256 | } | |
2a1f999f | 257 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & optionKey ) |
e40298d5 JS |
258 | { |
259 | event.m_keyCode = WXK_ALT ; | |
260 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
261 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
262 | } | |
2a1f999f | 263 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & cmdKey ) |
b7aec135 SC |
264 | { |
265 | event.m_keyCode = WXK_COMMAND ; | |
266 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
267 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
268 | } | |
2a1f999f | 269 | wxApp::s_lastModifiers = modifiers ; |
e40298d5 JS |
270 | } |
271 | break ; | |
272 | } | |
851b3a88 SC |
273 | |
274 | return result ; | |
275 | } | |
276 | ||
facd6764 SC |
277 | // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr |
278 | // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the | |
279 | // mouse down at all | |
851b3a88 | 280 | |
facd6764 | 281 | // This handler can also be called from app level where data (ie target window) may be null or a non wx window |
1542ea39 | 282 | |
facd6764 | 283 | wxWindow* g_MacLastWindow = NULL ; |
a3195b73 | 284 | |
86a9144f SC |
285 | static EventMouseButton lastButton = 0 ; |
286 | ||
facd6764 SC |
287 | static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) |
288 | { | |
289 | UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ; | |
290 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
67245665 | 291 | |
facd6764 SC |
292 | // this parameter are not given for all events |
293 | EventMouseButton button = 0 ; | |
294 | UInt32 clickCount = 0 ; | |
295 | cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ; | |
296 | cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ; | |
297 | ||
298 | wxevent.m_x = screenMouseLocation.h; | |
299 | wxevent.m_y = screenMouseLocation.v; | |
300 | wxevent.m_shiftDown = modifiers & shiftKey; | |
301 | wxevent.m_controlDown = modifiers & controlKey; | |
302 | wxevent.m_altDown = modifiers & optionKey; | |
303 | wxevent.m_metaDown = modifiers & cmdKey; | |
304 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
305 | // a control click is interpreted as a right click | |
306 | if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) | |
851b3a88 | 307 | { |
facd6764 SC |
308 | button = kEventMouseButtonSecondary ; |
309 | } | |
86a9144f | 310 | |
b343fb9f SC |
311 | // otherwise we report double clicks by connecting a left click with a ctrl-left click |
312 | if ( clickCount > 1 && button != lastButton ) | |
313 | clickCount = 1 ; | |
314 | ||
86a9144f SC |
315 | // we must make sure that our synthetic 'right' button corresponds in |
316 | // mouse down, moved and mouse up, and does not deliver a right down and left up | |
317 | ||
318 | if ( cEvent.GetKind() == kEventMouseDown ) | |
319 | lastButton = button ; | |
4e4e6dce SC |
320 | |
321 | if ( button == 0 ) | |
322 | lastButton = 0 ; | |
86a9144f SC |
323 | else if ( lastButton ) |
324 | button = lastButton ; | |
facd6764 SC |
325 | |
326 | // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers | |
327 | // this button | |
328 | if ( button != 0 && cEvent.GetKind() != kEventMouseUp ) | |
329 | { | |
330 | switch( button ) | |
e40298d5 | 331 | { |
facd6764 SC |
332 | case kEventMouseButtonPrimary : |
333 | wxevent.m_leftDown = true ; | |
e40298d5 | 334 | break ; |
facd6764 SC |
335 | case kEventMouseButtonSecondary : |
336 | wxevent.m_rightDown = true ; | |
e40298d5 | 337 | break ; |
facd6764 SC |
338 | case kEventMouseButtonTertiary : |
339 | wxevent.m_middleDown = true ; | |
e40298d5 | 340 | break ; |
facd6764 SC |
341 | } |
342 | } | |
90ff87d7 SC |
343 | // translate into wx types |
344 | switch ( cEvent.GetKind() ) | |
facd6764 | 345 | { |
90ff87d7 SC |
346 | case kEventMouseDown : |
347 | switch( button ) | |
348 | { | |
349 | case kEventMouseButtonPrimary : | |
350 | wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; | |
351 | break ; | |
352 | case kEventMouseButtonSecondary : | |
353 | wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ; | |
354 | break ; | |
355 | case kEventMouseButtonTertiary : | |
356 | wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; | |
357 | break ; | |
358 | } | |
359 | break ; | |
360 | case kEventMouseUp : | |
361 | switch( button ) | |
362 | { | |
363 | case kEventMouseButtonPrimary : | |
364 | wxevent.SetEventType( wxEVT_LEFT_UP ) ; | |
365 | break ; | |
366 | case kEventMouseButtonSecondary : | |
367 | wxevent.SetEventType( wxEVT_RIGHT_UP ) ; | |
368 | break ; | |
369 | case kEventMouseButtonTertiary : | |
370 | wxevent.SetEventType( wxEVT_MIDDLE_UP ) ; | |
371 | break ; | |
372 | } | |
373 | break ; | |
2cce9b11 JS |
374 | case kEventMouseWheelMoved : |
375 | { | |
facd6764 SC |
376 | wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ; |
377 | ||
378 | // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; | |
379 | SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ; | |
380 | ||
381 | wxevent.m_wheelRotation = delta; | |
382 | wxevent.m_wheelDelta = 1; | |
383 | wxevent.m_linesPerAction = 1; | |
90ff87d7 | 384 | break ; |
2cce9b11 | 385 | } |
90ff87d7 | 386 | default : |
facd6764 | 387 | wxevent.SetEventType(wxEVT_MOTION ) ; |
90ff87d7 SC |
388 | break ; |
389 | } | |
facd6764 SC |
390 | } |
391 | ||
789ae0cf | 392 | ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, Point location , ControlRef superControl , ControlPartCode *outPart ) |
facd6764 SC |
393 | { |
394 | if ( superControl ) | |
395 | { | |
396 | UInt16 childrenCount = 0 ; | |
397 | OSStatus err = CountSubControls( superControl , &childrenCount ) ; | |
398 | if ( err == errControlIsNotEmbedder ) | |
399 | return NULL ; | |
400 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
401 | ||
402 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
403 | { | |
404 | ControlHandle sibling ; | |
405 | err = GetIndexedSubControl( superControl , i , & sibling ) ; | |
406 | if ( err == errControlIsNotEmbedder ) | |
407 | return NULL ; | |
408 | ||
409 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
410 | if ( IsControlVisible( sibling ) ) | |
411 | { | |
412 | Rect r ; | |
d6fd667b | 413 | UMAGetControlBoundsInWindowCoords( sibling , &r ) ; |
facd6764 | 414 | if ( MacPtInRect( location , &r ) ) |
de127c69 | 415 | { |
789ae0cf | 416 | ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ; |
facd6764 SC |
417 | if ( child ) |
418 | return child ; | |
419 | else | |
de127c69 | 420 | { |
d6fd667b | 421 | Point testLocation = location ; |
789ae0cf SC |
422 | |
423 | if ( toplevelWindow && toplevelWindow->MacUsesCompositing() ) | |
424 | { | |
425 | testLocation.h -= r.left ; | |
426 | testLocation.v -= r.top ; | |
427 | } | |
428 | ||
d6fd667b | 429 | *outPart = TestControl( sibling , testLocation ) ; |
facd6764 | 430 | return sibling ; |
de127c69 GD |
431 | } |
432 | } | |
facd6764 | 433 | } |
e40298d5 JS |
434 | } |
435 | } | |
facd6764 SC |
436 | return NULL ; |
437 | } | |
1542ea39 | 438 | |
789ae0cf | 439 | ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow , Point location , WindowRef window , ControlPartCode *outPart ) |
facd6764 SC |
440 | { |
441 | #if TARGET_API_MAC_OSX | |
789ae0cf | 442 | if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow == 0 || toplevelWindow->MacUsesCompositing() ) ) |
30e0b1c9 SC |
443 | return FindControlUnderMouse( location , window , outPart ) ; |
444 | #endif | |
facd6764 SC |
445 | ControlRef rootControl = NULL ; |
446 | verify_noerr( GetRootControl( window , &rootControl ) ) ; | |
789ae0cf | 447 | return wxMacFindSubControl( toplevelWindow , location , rootControl , outPart ) ; |
30e0b1c9 | 448 | |
facd6764 SC |
449 | } |
450 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
451 | { | |
789ae0cf | 452 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
facd6764 SC |
453 | |
454 | OSStatus result = eventNotHandledErr ; | |
455 | ||
456 | wxMacCarbonEvent cEvent( event ) ; | |
457 | ||
458 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
459 | Point windowMouseLocation = screenMouseLocation ; | |
460 | ||
461 | WindowRef window ; | |
462 | short windowPart = ::FindWindow(screenMouseLocation, &window); | |
463 | ||
464 | wxWindow* currentMouseWindow = NULL ; | |
d88ffaaa SC |
465 | ControlRef control = NULL ; |
466 | ||
facd6764 SC |
467 | if ( window ) |
468 | { | |
d6fd667b | 469 | QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; |
facd6764 | 470 | |
2a1f999f | 471 | if ( wxApp::s_captureWindow && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) |
facd6764 | 472 | { |
2a1f999f | 473 | currentMouseWindow = wxApp::s_captureWindow ; |
facd6764 SC |
474 | } |
475 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
476 | { | |
477 | ControlPartCode part ; | |
789ae0cf | 478 | control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ; |
d88ffaaa | 479 | // if there is no control below the mouse position, send the event to the toplevel window itself |
b19bf058 SC |
480 | if ( control == 0 ) |
481 | currentMouseWindow = (wxWindow*) data ; | |
482 | else | |
b16f4bfa | 483 | { |
b19bf058 | 484 | currentMouseWindow = wxFindControlFromMacControl( control ) ; |
8198ae50 | 485 | if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved ) |
b16f4bfa | 486 | { |
179e085f | 487 | #if wxUSE_TOOLBAR |
b16f4bfa SC |
488 | // for wxToolBar to function we have to send certaint events to it |
489 | // instead of its children (wxToolBarTools) | |
490 | ControlRef parent ; | |
491 | GetSuperControl(control, &parent ); | |
492 | wxWindow *wxParent = wxFindControlFromMacControl( parent ) ; | |
493 | if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) ) | |
494 | currentMouseWindow = wxParent ; | |
179e085f | 495 | #endif |
b16f4bfa SC |
496 | } |
497 | } | |
facd6764 SC |
498 | } |
499 | } | |
d88ffaaa | 500 | |
facd6764 SC |
501 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); |
502 | SetupMouseEvent( wxevent , cEvent ) ; | |
503 | ||
504 | // handle all enter / leave events | |
505 | ||
506 | if ( currentMouseWindow != g_MacLastWindow ) | |
507 | { | |
508 | if ( g_MacLastWindow ) | |
509 | { | |
510 | wxMouseEvent eventleave(wxevent); | |
511 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
512 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
513 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
514 | ||
515 | #if wxUSE_TOOLTIPS | |
516 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
517 | #endif // wxUSE_TOOLTIPS | |
518 | g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave); | |
519 | } | |
520 | if ( currentMouseWindow ) | |
521 | { | |
522 | wxMouseEvent evententer(wxevent); | |
523 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
524 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
525 | evententer.SetEventObject( currentMouseWindow ) ; | |
526 | #if wxUSE_TOOLTIPS | |
527 | wxToolTip::RelayEvent( currentMouseWindow , evententer); | |
528 | #endif // wxUSE_TOOLTIPS | |
529 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
530 | } | |
531 | g_MacLastWindow = currentMouseWindow ; | |
532 | } | |
533 | ||
534 | if ( windowPart == inMenuBar ) | |
535 | { | |
536 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
537 | if ( cEvent.GetKind() == kEventMouseDown ) | |
538 | { | |
539 | ::MenuSelect( screenMouseLocation ) ; | |
540 | result = noErr ; | |
541 | } | |
542 | } // if ( windowPart == inMenuBar ) | |
543 | else if ( currentMouseWindow ) | |
544 | { | |
e10e9469 | 545 | wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent(); |
62ade180 RR |
546 | |
547 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
facd6764 SC |
548 | |
549 | wxevent.SetEventObject( currentMouseWindow ) ; | |
550 | ||
facd6764 SC |
551 | // make tooltips current |
552 | ||
553 | #if wxUSE_TOOLTIPS | |
554 | if ( wxevent.GetEventType() == wxEVT_MOTION | |
555 | || wxevent.GetEventType() == wxEVT_ENTER_WINDOW | |
556 | || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
557 | wxToolTip::RelayEvent( currentMouseWindow , wxevent); | |
558 | #endif // wxUSE_TOOLTIPS | |
559 | if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
62ade180 RR |
560 | { |
561 | if ((currentMouseWindowParent != NULL) && | |
562 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
563 | currentMouseWindow = NULL; | |
564 | ||
facd6764 | 565 | result = noErr; |
62ade180 | 566 | } |
30e0b1c9 SC |
567 | else |
568 | { | |
f90387b4 VZ |
569 | // if the user code did _not_ handle the event, then perform the |
570 | // default processing | |
571 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) | |
572 | { | |
573 | // ... that is set focus to this window | |
574 | if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) | |
575 | currentMouseWindow->SetFocus(); | |
576 | } | |
577 | ||
30e0b1c9 SC |
578 | ControlPartCode dummyPart ; |
579 | // if built-in find control is finding the wrong control (ie static box instead of overlaid | |
580 | // button, we cannot let the standard handler do its job, but must handle manually | |
581 | ||
23ad132c SC |
582 | if ( ( cEvent.GetKind() == kEventMouseDown ) |
583 | #ifdef __WXMAC_OSX__ | |
584 | && | |
30e0b1c9 | 585 | (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != |
789ae0cf | 586 | wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) ) |
23ad132c SC |
587 | #endif |
588 | ) | |
30e0b1c9 | 589 | { |
7ce1a4e1 SC |
590 | if ( currentMouseWindow->MacIsReallyEnabled() ) |
591 | { | |
592 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
593 | Point clickLocation = windowMouseLocation ; | |
789ae0cf SC |
594 | |
595 | if ( toplevelWindow->MacUsesCompositing() ) | |
596 | currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; | |
597 | ||
7ce1a4e1 SC |
598 | HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , |
599 | modifiers , (ControlActionUPP ) -1 ) ; | |
e10e9469 | 600 | |
62ade180 RR |
601 | if ((currentMouseWindowParent != NULL) && |
602 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
e10e9469 | 603 | currentMouseWindow = NULL; |
7ce1a4e1 | 604 | } |
30e0b1c9 SC |
605 | result = noErr ; |
606 | } | |
607 | } | |
2a1f999f | 608 | if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow ) |
facd6764 | 609 | { |
2a1f999f | 610 | wxApp::s_captureWindow = NULL ; |
facd6764 SC |
611 | // update cursor ? |
612 | } | |
6d63e2fc SC |
613 | |
614 | // update cursor | |
615 | ||
616 | wxWindow* cursorTarget = currentMouseWindow ; | |
617 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
618 | ||
619 | while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
620 | { | |
621 | cursorTarget = cursorTarget->GetParent() ; | |
622 | if ( cursorTarget ) | |
e10e9469 | 623 | cursorPoint += cursorTarget->GetPosition(); |
6d63e2fc SC |
624 | } |
625 | ||
facd6764 | 626 | } // else if ( currentMouseWindow ) |
d88ffaaa SC |
627 | else |
628 | { | |
629 | // don't mess with controls we don't know about | |
630 | // for some reason returning eventNotHandledErr does not lead to the correct behaviour | |
631 | // so we try sending them the correct control directly | |
e4b7e0b4 | 632 | if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) |
d88ffaaa SC |
633 | { |
634 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
635 | Point clickLocation = windowMouseLocation ; | |
789ae0cf SC |
636 | if ( toplevelWindow->MacUsesCompositing() ) |
637 | { | |
638 | #ifdef __WXMAC_OSX__ | |
639 | HIPoint hiPoint ; | |
640 | hiPoint.x = clickLocation.h ; | |
641 | hiPoint.y = clickLocation.v ; | |
642 | HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; | |
643 | clickLocation.h = (int)hiPoint.x ; | |
644 | clickLocation.v = (int)hiPoint.y ; | |
d88ffaaa | 645 | #endif |
789ae0cf | 646 | } |
d88ffaaa SC |
647 | HandleControlClick( control , clickLocation , |
648 | modifiers , (ControlActionUPP ) -1 ) ; | |
649 | result = noErr ; | |
650 | } | |
651 | } | |
facd6764 | 652 | return result ; |
851b3a88 | 653 | } |
facd6764 SC |
654 | |
655 | static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
851b3a88 SC |
656 | { |
657 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 658 | |
facd6764 SC |
659 | wxMacCarbonEvent cEvent( event ) ; |
660 | ||
661 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; | |
e40298d5 | 662 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
1542ea39 | 663 | |
e40298d5 JS |
664 | switch( GetEventKind( event ) ) |
665 | { | |
e40298d5 | 666 | case kEventWindowActivated : |
facd6764 SC |
667 | { |
668 | toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; | |
facd6764 SC |
669 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); |
670 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
671 | wxevent.SetEventObject(toplevelWindow); | |
672 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 673 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 674 | break ; |
facd6764 | 675 | } |
e40298d5 | 676 | case kEventWindowDeactivated : |
facd6764 SC |
677 | { |
678 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
679 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
680 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
681 | wxevent.SetEventObject(toplevelWindow); | |
682 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 683 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 684 | break ; |
facd6764 | 685 | } |
16a76184 SC |
686 | case kEventWindowShown : |
687 | toplevelWindow->Refresh() ; | |
688 | result = noErr ; | |
689 | break ; | |
e40298d5 JS |
690 | case kEventWindowClose : |
691 | toplevelWindow->Close() ; | |
692 | result = noErr ; | |
693 | break ; | |
694 | case kEventWindowBoundsChanged : | |
facd6764 SC |
695 | { |
696 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
697 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
698 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
699 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
e40298d5 | 700 | { |
facd6764 SC |
701 | // according to the other ports we handle this within the OS level |
702 | // resize event, not within a wxSizeEvent | |
703 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
704 | if ( frame ) | |
705 | { | |
706 | #if wxUSE_STATUSBAR | |
707 | frame->PositionStatusBar(); | |
708 | #endif | |
709 | #if wxUSE_TOOLBAR | |
710 | frame->PositionToolBar(); | |
711 | #endif | |
712 | } | |
1542ea39 | 713 | |
facd6764 SC |
714 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; |
715 | event.SetEventObject( toplevelWindow ) ; | |
851b3a88 | 716 | |
facd6764 | 717 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; |
5e533062 | 718 | toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
e40298d5 | 719 | } |
facd6764 SC |
720 | if ( attributes & kWindowBoundsChangeOriginChanged ) |
721 | { | |
722 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
723 | event.SetEventObject( toplevelWindow ) ; | |
724 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
725 | } | |
726 | result = noErr ; | |
e40298d5 | 727 | break ; |
facd6764 | 728 | } |
f81bfef9 | 729 | case kEventWindowBoundsChanging : |
facd6764 SC |
730 | { |
731 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
732 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
83901ec2 | 733 | |
facd6764 SC |
734 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) |
735 | { | |
29281095 SC |
736 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates |
737 | int left , top , right , bottom ; | |
738 | toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ; | |
739 | wxRect r( newRect.left - left , newRect.top - top , | |
740 | newRect.right - newRect.left + left + right , newRect.bottom - newRect.top + top + bottom ) ; | |
facd6764 SC |
741 | // this is a EVT_SIZING not a EVT_SIZE type ! |
742 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
743 | wxevent.SetEventObject( toplevelWindow ) ; | |
744 | wxRect adjustR = r ; | |
745 | if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
facd6764 | 746 | adjustR = wxevent.GetRect() ; |
29281095 | 747 | |
facd6764 SC |
748 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) |
749 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
2c25bd55 | 750 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) |
facd6764 SC |
751 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; |
752 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
753 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
2c25bd55 | 754 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) |
facd6764 | 755 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; |
4a5f2351 | 756 | const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; |
facd6764 | 757 | if ( !EqualRect( &newRect , &adjustedRect ) ) |
1f919f38 | 758 | cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ; |
4817190d | 759 | toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
f81bfef9 | 760 | } |
facd6764 | 761 | |
789ae0cf | 762 | result = noErr ; |
f81bfef9 | 763 | break ; |
facd6764 | 764 | } |
e40298d5 JS |
765 | default : |
766 | break ; | |
767 | } | |
768 | return result ; | |
851b3a88 SC |
769 | } |
770 | ||
facd6764 | 771 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
772 | { |
773 | OSStatus result = eventNotHandledErr ; | |
774 | ||
775 | switch ( GetEventClass( event ) ) | |
776 | { | |
c5c9378c | 777 | case kEventClassKeyboard : |
e40298d5 | 778 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 779 | break ; |
851b3a88 | 780 | case kEventClassTextInput : |
e40298d5 | 781 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
782 | break ; |
783 | case kEventClassWindow : | |
facd6764 | 784 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; |
e40298d5 | 785 | break ; |
851b3a88 | 786 | case kEventClassMouse : |
facd6764 | 787 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; |
e40298d5 | 788 | break ; |
851b3a88 SC |
789 | default : |
790 | break ; | |
791 | } | |
792 | return result ; | |
793 | } | |
794 | ||
facd6764 | 795 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) |
851b3a88 | 796 | |
5f0b2f22 SC |
797 | // --------------------------------------------------------------------------- |
798 | // wxWindowMac utility functions | |
799 | // --------------------------------------------------------------------------- | |
800 | ||
801 | // Find an item given the Macintosh Window Reference | |
802 | ||
71f2fb52 | 803 | #if KEY_wxList_DEPRECATED |
facd6764 SC |
804 | wxList wxWinMacWindowList(wxKEY_INTEGER); |
805 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
5f0b2f22 | 806 | { |
facd6764 | 807 | wxNode *node = wxWinMacWindowList.Find((long)inWindowRef); |
5f0b2f22 SC |
808 | if (!node) |
809 | return NULL; | |
eb22f2a6 | 810 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
811 | } |
812 | ||
facd6764 SC |
813 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; |
814 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
5f0b2f22 SC |
815 | { |
816 | // adding NULL WindowRef is (first) surely a result of an error and | |
817 | // (secondly) breaks menu command processing | |
427ff662 | 818 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 | 819 | |
facd6764 SC |
820 | if ( !wxWinMacWindowList.Find((long)inWindowRef) ) |
821 | wxWinMacWindowList.Append((long)inWindowRef, win); | |
5f0b2f22 SC |
822 | } |
823 | ||
facd6764 | 824 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; |
5f0b2f22 SC |
825 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) |
826 | { | |
facd6764 | 827 | wxWinMacWindowList.DeleteObject(win); |
5f0b2f22 | 828 | } |
71f2fb52 | 829 | #else |
5f0b2f22 | 830 | |
71f2fb52 RN |
831 | WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap); |
832 | ||
833 | static MacWindowMap wxWinMacWindowList; | |
834 | ||
835 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
836 | { | |
837 | MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); | |
838 | ||
839 | return (node == wxWinMacWindowList.end()) ? NULL : node->second; | |
840 | } | |
841 | ||
842 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; | |
843 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
844 | { | |
845 | // adding NULL WindowRef is (first) surely a result of an error and | |
846 | // nothing else :-) | |
847 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
848 | ||
849 | wxWinMacWindowList[inWindowRef] = win; | |
850 | } | |
851 | ||
852 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; | |
853 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
854 | { | |
855 | MacWindowMap::iterator it; | |
856 | for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) | |
857 | { | |
858 | if ( it->second == win ) | |
859 | { | |
860 | wxWinMacWindowList.erase(it); | |
861 | break; | |
862 | } | |
863 | } | |
864 | } | |
865 | #endif // deprecated wxList | |
5f0b2f22 | 866 | |
a15eb0a5 SC |
867 | // ---------------------------------------------------------------------------- |
868 | // wxTopLevelWindowMac creation | |
869 | // ---------------------------------------------------------------------------- | |
870 | ||
245f3581 | 871 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
5f0b2f22 | 872 | |
c5985061 SC |
873 | typedef struct |
874 | { | |
875 | wxPoint m_position ; | |
876 | wxSize m_size ; | |
877 | } FullScreenData ; | |
878 | ||
a15eb0a5 SC |
879 | void wxTopLevelWindowMac::Init() |
880 | { | |
881 | m_iconized = | |
882 | m_maximizeOnShow = FALSE; | |
6a17ca35 | 883 | m_macWindow = NULL ; |
facd6764 | 884 | #if TARGET_API_MAC_OSX |
789ae0cf SC |
885 | if ( UMAGetSystemVersion() >= 0x1030 ) |
886 | { | |
887 | m_macUsesCompositing = TRUE; | |
888 | } | |
889 | else | |
facd6764 | 890 | #endif |
789ae0cf SC |
891 | { |
892 | m_macUsesCompositing = FALSE; | |
893 | } | |
7c091673 | 894 | m_macEventHandler = NULL ; |
c5985061 | 895 | m_macFullScreenData = NULL ; |
a15eb0a5 SC |
896 | } |
897 | ||
118f012e SC |
898 | class wxMacDeferredWindowDeleter : public wxObject |
899 | { | |
900 | public : | |
1542ea39 RD |
901 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
902 | { | |
903 | m_macWindow = windowRef ; | |
118f012e | 904 | } |
1542ea39 RD |
905 | virtual ~wxMacDeferredWindowDeleter() |
906 | { | |
907 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
908 | } |
909 | protected : | |
910 | WindowRef m_macWindow ; | |
911 | } ; | |
912 | ||
a15eb0a5 SC |
913 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
914 | wxWindowID id, | |
915 | const wxString& title, | |
916 | const wxPoint& pos, | |
917 | const wxSize& size, | |
918 | long style, | |
919 | const wxString& name) | |
920 | { | |
921 | // init our fields | |
922 | Init(); | |
923 | ||
924 | m_windowStyle = style; | |
925 | ||
926 | SetName(name); | |
927 | ||
928 | m_windowId = id == -1 ? NewControlId() : id; | |
c2bc1e2a | 929 | wxWindow::SetTitle( title ) ; |
a15eb0a5 | 930 | |
facd6764 SC |
931 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
932 | ||
94d1d0f4 | 933 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
5bd78bbc JS |
934 | |
935 | if (GetExtraStyle() & wxFRAME_EX_METAL) | |
936 | MacSetMetalAppearance(true); | |
94d1d0f4 | 937 | |
a15eb0a5 SC |
938 | wxTopLevelWindows.Append(this); |
939 | ||
940 | if ( parent ) | |
941 | parent->AddChild(this); | |
942 | ||
943 | return TRUE; | |
944 | } | |
945 | ||
946 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
947 | { | |
6a17ca35 SC |
948 | if ( m_macWindow ) |
949 | { | |
c81c6d54 | 950 | #if wxUSE_TOOLTIPS |
6a17ca35 | 951 | wxToolTip::NotifyWindowDelete(m_macWindow) ; |
c81c6d54 | 952 | #endif |
118f012e | 953 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 954 | } |
1542ea39 | 955 | |
7c091673 SC |
956 | if ( m_macEventHandler ) |
957 | { | |
958 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
959 | m_macEventHandler = NULL ; | |
960 | } | |
851b3a88 | 961 | |
5f0b2f22 SC |
962 | wxRemoveMacWindowAssociation( this ) ; |
963 | ||
a15eb0a5 SC |
964 | if ( wxModelessWindows.Find(this) ) |
965 | wxModelessWindows.DeleteObject(this); | |
c5985061 SC |
966 | |
967 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
968 | delete data ; | |
969 | m_macFullScreenData = NULL ; | |
a15eb0a5 SC |
970 | } |
971 | ||
972 | ||
973 | // ---------------------------------------------------------------------------- | |
974 | // wxTopLevelWindowMac maximize/minimize | |
975 | // ---------------------------------------------------------------------------- | |
976 | ||
977 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
978 | { | |
699b6af4 SC |
979 | // TODO Check, is this still necessary |
980 | #if 0 | |
1f90939c SC |
981 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
982 | wxMacWindowClipper clip (this); | |
699b6af4 SC |
983 | #endif |
984 | if ( !IsWindowInStandardState( (WindowRef)m_macWindow, NULL, NULL) ) | |
985 | { | |
986 | Rect rect; | |
987 | GetWindowBounds((WindowRef)m_macWindow, kWindowGlobalPortRgn, &rect); | |
988 | SetWindowIdealUserState((WindowRef)m_macWindow, &rect); | |
989 | SetWindowUserState((WindowRef)m_macWindow, &rect); | |
990 | } | |
b7aec135 | 991 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; |
a15eb0a5 SC |
992 | } |
993 | ||
994 | bool wxTopLevelWindowMac::IsMaximized() const | |
995 | { | |
b7aec135 | 996 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
997 | } |
998 | ||
999 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
1000 | { | |
b7aec135 SC |
1001 | if ( IsWindowCollapsable((WindowRef)m_macWindow) ) |
1002 | CollapseWindow((WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
1003 | } |
1004 | ||
1005 | bool wxTopLevelWindowMac::IsIconized() const | |
1006 | { | |
b7aec135 | 1007 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
1008 | } |
1009 | ||
1010 | void wxTopLevelWindowMac::Restore() | |
1011 | { | |
699b6af4 SC |
1012 | if ( IsMaximized() ) |
1013 | Maximize(false); | |
1014 | else if ( IsIconized() ) | |
1015 | Iconize(false); | |
a15eb0a5 SC |
1016 | } |
1017 | ||
1018 | // ---------------------------------------------------------------------------- | |
1019 | // wxTopLevelWindowMac misc | |
1020 | // ---------------------------------------------------------------------------- | |
1021 | ||
facd6764 SC |
1022 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
1023 | { | |
1024 | return wxPoint(0,0) ; | |
1025 | } | |
1026 | ||
a15eb0a5 SC |
1027 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) |
1028 | { | |
1029 | // this sets m_icon | |
1030 | wxTopLevelWindowBase::SetIcon(icon); | |
1031 | } | |
5f0b2f22 | 1032 | |
facd6764 SC |
1033 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
1034 | { | |
1035 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
1036 | ||
1037 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
1038 | { | |
1039 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
1040 | } | |
1041 | } | |
1042 | ||
949cb163 SC |
1043 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
1044 | { | |
1045 | if ( m_macEventHandler != NULL ) | |
1046 | { | |
1047 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1048 | } | |
1049 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
1050 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); | |
1051 | } | |
1052 | ||
5f0b2f22 SC |
1053 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
1054 | const wxPoint& pos, | |
1055 | const wxSize& size, | |
1056 | long style, | |
1542ea39 | 1057 | const wxString& name ) |
5f0b2f22 | 1058 | { |
47ac4f9b | 1059 | OSStatus err = noErr ; |
e40298d5 JS |
1060 | SetName(name); |
1061 | m_windowStyle = style; | |
1062 | m_isShown = FALSE; | |
1542ea39 | 1063 | |
e40298d5 | 1064 | // create frame. |
1542ea39 | 1065 | |
5f0b2f22 | 1066 | Rect theBoundsRect; |
1542ea39 | 1067 | |
facd6764 SC |
1068 | int x = (int)pos.x; |
1069 | int y = (int)pos.y; | |
5a486641 SC |
1070 | |
1071 | wxRect display = wxGetClientDisplayRect() ; | |
1072 | ||
1073 | if ( x == wxDefaultPosition.x ) | |
1074 | x = display.x ; | |
1075 | ||
1076 | if ( y == wxDefaultPosition.y ) | |
1077 | y = display.y ; | |
1542ea39 | 1078 | |
facd6764 SC |
1079 | int w = WidthDefault(size.x); |
1080 | int h = HeightDefault(size.y); | |
1542ea39 | 1081 | |
facd6764 | 1082 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 1083 | |
5f0b2f22 | 1084 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 1085 | |
5f0b2f22 SC |
1086 | WindowClass wclass = 0; |
1087 | WindowAttributes attr = kWindowNoAttributes ; | |
e353795e | 1088 | WindowGroupRef group = NULL ; |
1542ea39 | 1089 | |
f5744893 | 1090 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 1091 | { |
1542ea39 | 1092 | if ( |
f5744893 SC |
1093 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
1094 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
1095 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 1096 | ) |
5f0b2f22 | 1097 | { |
f5744893 SC |
1098 | wclass = kFloatingWindowClass ; |
1099 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
1100 | { | |
1101 | attr |= kWindowSideTitlebarAttribute ; | |
1102 | } | |
1103 | } | |
1104 | else | |
1105 | { | |
1106 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
1107 | } |
1108 | } | |
1109 | else if ( HasFlag( wxCAPTION ) ) | |
1110 | { | |
1542ea39 | 1111 | wclass = kDocumentWindowClass ; |
5f0b2f22 | 1112 | } |
eab19a7c | 1113 | #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) |
3e17bc3f RN |
1114 | else if ( HasFlag( wxFRAME_DRAWER ) ) |
1115 | { | |
1116 | wclass = kDrawerWindowClass; | |
789ae0cf SC |
1117 | // we must force compositing on a drawer |
1118 | m_macUsesCompositing = TRUE ; | |
3e17bc3f RN |
1119 | } |
1120 | #endif //10.2 and up | |
5f0b2f22 SC |
1121 | else |
1122 | { | |
f5744893 | 1123 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 1124 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
1125 | { |
1126 | wclass = kDocumentWindowClass ; | |
1127 | } | |
1128 | else | |
1129 | { | |
1130 | wclass = kPlainWindowClass ; | |
1131 | } | |
5f0b2f22 | 1132 | } |
1542ea39 | 1133 | |
38e605eb | 1134 | if ( HasFlag( wxMINIMIZE_BOX ) && wclass != kPlainWindowClass ) |
5f0b2f22 | 1135 | { |
5f0b2f22 SC |
1136 | attr |= kWindowCollapseBoxAttribute ; |
1137 | } | |
38e605eb | 1138 | if ( HasFlag( wxMAXIMIZE_BOX ) && wclass != kPlainWindowClass ) |
47ac4f9b SC |
1139 | { |
1140 | attr |= kWindowFullZoomAttribute ; | |
1141 | } | |
38e605eb | 1142 | if ( HasFlag( wxRESIZE_BORDER ) && wclass != kPlainWindowClass ) |
5f0b2f22 SC |
1143 | { |
1144 | attr |= kWindowResizableAttribute ; | |
1145 | } | |
38e605eb | 1146 | if ( HasFlag( wxCLOSE_BOX) && wclass != kPlainWindowClass ) |
5f0b2f22 SC |
1147 | { |
1148 | attr |= kWindowCloseBoxAttribute ; | |
1149 | } | |
1542ea39 | 1150 | |
eb630bf1 DS |
1151 | if (UMAGetSystemVersion() >= 0x1000) |
1152 | { | |
facd6764 | 1153 | // turn on live resizing (OS X only) |
eb630bf1 DS |
1154 | attr |= kWindowLiveResizeAttribute; |
1155 | } | |
1156 | ||
e353795e SC |
1157 | if ( HasFlag(wxSTAY_ON_TOP) ) |
1158 | { | |
1159 | group = GetWindowGroupOfClass(kUtilityWindowClass) ; | |
1160 | } | |
6a7e6411 | 1161 | |
facd6764 | 1162 | #if TARGET_API_MAC_OSX |
789ae0cf SC |
1163 | if ( m_macUsesCompositing ) |
1164 | attr |= kWindowCompositingAttribute; | |
d66c3960 | 1165 | #endif |
1f90939c | 1166 | |
6a7e6411 RD |
1167 | if ( HasFlag(wxFRAME_SHAPED) ) |
1168 | { | |
1169 | WindowDefSpec customWindowDefSpec; | |
1170 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
1171 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
1172 | ||
47ac4f9b | 1173 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
1174 | attr, &theBoundsRect, |
1175 | (WindowRef*) &m_macWindow); | |
1176 | } | |
1177 | else | |
1178 | { | |
47ac4f9b | 1179 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
1180 | } |
1181 | ||
e353795e SC |
1182 | if ( err == noErr && m_macWindow != NULL && group != NULL ) |
1183 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1184 | ||
47ac4f9b | 1185 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
f83b6761 SC |
1186 | |
1187 | // the create commands are only for content rect, so we have to set the size again as | |
1188 | // structure bounds | |
1189 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; | |
1190 | ||
facd6764 SC |
1191 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
1192 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
1f1c8bd4 | 1193 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; |
3a9dc061 | 1194 | #if TARGET_API_MAC_OSX |
789ae0cf SC |
1195 | |
1196 | if ( m_macUsesCompositing ) | |
f57d9215 | 1197 | { |
789ae0cf SC |
1198 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of |
1199 | // the content view, so we have to retrieve it explicitely | |
1200 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
1201 | m_peer->GetControlRefAddr() ) ; | |
1202 | if ( !m_peer->Ok() ) | |
1203 | { | |
1204 | // compatibility mode fallback | |
1205 | GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1206 | } | |
f57d9215 | 1207 | } |
3a9dc061 | 1208 | #endif |
789ae0cf SC |
1209 | { |
1210 | ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1211 | } | |
73fe67bd | 1212 | // the root control level handleer |
5ca0d812 | 1213 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; |
facd6764 | 1214 | |
73fe67bd | 1215 | // the frame window event handler |
e40298d5 | 1216 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 | 1217 | MacInstallTopLevelWindowEventHandler() ; |
b19bf058 | 1218 | |
14c96cf2 SC |
1219 | DoSetWindowVariant( m_windowVariant ) ; |
1220 | ||
facd6764 | 1221 | m_macFocus = NULL ; |
6a7e6411 RD |
1222 | |
1223 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1224 | { | |
1225 | // default shape matches the window size | |
facd6764 | 1226 | wxRegion rgn(0, 0, w, h); |
6a7e6411 RD |
1227 | SetShape(rgn); |
1228 | } | |
3dfafdb9 RD |
1229 | |
1230 | wxWindowCreateEvent event(this); | |
1231 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1232 | } |
1233 | ||
5d2e69e8 | 1234 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 1235 | { |
5d2e69e8 | 1236 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
1237 | } |
1238 | ||
5f0b2f22 SC |
1239 | // Raise the window to the top of the Z order |
1240 | void wxTopLevelWindowMac::Raise() | |
1241 | { | |
7f3c339c | 1242 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1243 | } |
1244 | ||
1245 | // Lower the window to the bottom of the Z order | |
1246 | void wxTopLevelWindowMac::Lower() | |
1247 | { | |
76a5e5d2 | 1248 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
1249 | } |
1250 | ||
851b3a88 | 1251 | |
245f3581 DE |
1252 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1253 | { | |
1254 | if(s_macDeactivateWindow) | |
1255 | { | |
365796b1 | 1256 | wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow); |
245f3581 DE |
1257 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1258 | } | |
1259 | } | |
1260 | ||
851b3a88 | 1261 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) |
5f0b2f22 | 1262 | { |
17f8d2a7 VZ |
1263 | // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this); |
1264 | ||
245f3581 DE |
1265 | if(s_macDeactivateWindow==this) |
1266 | s_macDeactivateWindow=NULL; | |
1267 | MacDelayedDeactivation(timestamp); | |
8ab50549 | 1268 | MacPropagateHiliteChanged() ; |
5f0b2f22 SC |
1269 | } |
1270 | ||
1271 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1272 | { | |
1273 | wxWindow::SetTitle( title ) ; | |
16a76184 | 1274 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; |
5f0b2f22 SC |
1275 | } |
1276 | ||
1277 | bool wxTopLevelWindowMac::Show(bool show) | |
1278 | { | |
facd6764 | 1279 | if ( !wxTopLevelWindowBase::Show(show) ) |
5f0b2f22 SC |
1280 | return FALSE; |
1281 | ||
1282 | if (show) | |
1542ea39 | 1283 | { |
1f90939c SC |
1284 | #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003 |
1285 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1286 | { | |
1287 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1288 | } | |
1289 | else | |
1290 | #endif | |
1291 | { | |
1292 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); | |
1293 | } | |
1294 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
facd6764 SC |
1295 | // as apps expect a size event to occur at this moment |
1296 | wxSizeEvent event( GetSize() , m_windowId); | |
1f90939c SC |
1297 | event.SetEventObject(this); |
1298 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1299 | } |
1300 | else | |
1301 | { | |
1f90939c SC |
1302 | #if wxUSE_SYSTEM_OPTIONS |
1303 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1304 | { | |
1305 | ::HideWindow((WindowRef) m_macWindow ); | |
1306 | } | |
1307 | else | |
1308 | #endif | |
1309 | { | |
1310 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); | |
1311 | } | |
5f0b2f22 SC |
1312 | } |
1313 | ||
facd6764 | 1314 | MacPropagateVisibilityChanged() ; |
5f0b2f22 | 1315 | |
facd6764 | 1316 | return TRUE ; |
5f0b2f22 SC |
1317 | } |
1318 | ||
c5985061 SC |
1319 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) |
1320 | { | |
1321 | if ( show ) | |
1322 | { | |
1323 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
1324 | delete data ; | |
1325 | data = new FullScreenData() ; | |
1326 | ||
1327 | m_macFullScreenData = data ; | |
1328 | data->m_position = GetPosition() ; | |
1329 | data->m_size = GetSize() ; | |
1330 | ||
1331 | if ( style & wxFULLSCREEN_NOMENUBAR ) | |
1332 | { | |
1333 | HideMenuBar() ; | |
1334 | } | |
1335 | int left , top , right , bottom ; | |
1336 | wxRect client = wxGetClientDisplayRect() ; | |
1337 | ||
1338 | int x, y, w, h ; | |
1339 | ||
1340 | x = client.x ; | |
1341 | y = client.y ; | |
1342 | w = client.width ; | |
1343 | h = client.height ; | |
1344 | ||
1345 | MacGetContentAreaInset( left , top , right , bottom ) ; | |
1346 | ||
1347 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
1348 | { | |
1349 | y -= top ; | |
1350 | h += top ; | |
1351 | } | |
1352 | if ( style & wxFULLSCREEN_NOBORDER ) | |
1353 | { | |
1354 | x -= left ; | |
1355 | w += left + right ; | |
1356 | h += bottom ; | |
1357 | } | |
1358 | if ( style & wxFULLSCREEN_NOTOOLBAR ) | |
1359 | { | |
3c86150d SC |
1360 | // TODO |
1361 | } | |
1362 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) | |
1363 | { | |
1364 | // TODO | |
c5985061 SC |
1365 | } |
1366 | SetSize( x , y , w, h ) ; | |
1367 | } | |
1368 | else | |
1369 | { | |
1370 | ShowMenuBar() ; | |
1371 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
1372 | SetPosition( data->m_position ) ; | |
1373 | SetSize( data->m_size ) ; | |
1374 | delete data ; | |
1375 | m_macFullScreenData = NULL ; | |
1376 | } | |
1377 | return FALSE; | |
1378 | } | |
1379 | ||
1380 | bool wxTopLevelWindowMac::IsFullScreen() const | |
1381 | { | |
1382 | return m_macFullScreenData != NULL ; | |
1383 | } | |
1384 | ||
facd6764 SC |
1385 | // we are still using coordinates of the content view, todo switch to structure bounds |
1386 | ||
29281095 SC |
1387 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1388 | { | |
1389 | Rect content ; | |
1390 | Rect structure ; | |
1391 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; | |
1392 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1393 | ||
1394 | left = content.left - structure.left ; | |
1395 | top = content.top - structure.top ; | |
1396 | right = structure.right - content.right ; | |
1397 | bottom = structure.bottom - content.bottom ; | |
1398 | } | |
1399 | ||
5f0b2f22 SC |
1400 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1401 | { | |
c9698388 | 1402 | m_cachedClippedRectValid = false ; |
facd6764 SC |
1403 | Rect bounds = { y , x , y + height , x + width } ; |
1404 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
4817190d | 1405 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
5f0b2f22 SC |
1406 | } |
1407 | ||
facd6764 | 1408 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1409 | { |
facd6764 SC |
1410 | Rect bounds ; |
1411 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1412 | if(x) *x = bounds.left ; | |
1413 | if(y) *y = bounds.top ; | |
1414 | } | |
1415 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1416 | { | |
1417 | Rect bounds ; | |
1418 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1419 | if(width) *width = bounds.right - bounds.left ; | |
1420 | if(height) *height = bounds.bottom - bounds.top ; | |
1421 | } | |
1542ea39 | 1422 | |
facd6764 SC |
1423 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1424 | { | |
1425 | Rect bounds ; | |
1426 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1427 | if(width) *width = bounds.right - bounds.left ; | |
1428 | if(height) *height = bounds.bottom - bounds.top ; | |
1429 | } | |
1542ea39 | 1430 | |
facd6764 SC |
1431 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
1432 | { | |
1433 | #if TARGET_API_MAC_OSX | |
789ae0cf | 1434 | wxASSERT_MSG( m_macUsesCompositing , |
facd6764 SC |
1435 | wxT("Cannot set metal appearance on a non-compositing window") ) ; |
1436 | ||
1437 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1438 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1439 | #endif | |
1440 | } | |
1542ea39 | 1441 | |
6aab345b SC |
1442 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
1443 | { | |
1444 | #if TARGET_API_MAC_OSX | |
1445 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1446 | #else | |
1447 | return false ; | |
1448 | #endif | |
1449 | } | |
1450 | ||
facd6764 SC |
1451 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
1452 | { | |
1453 | ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ; | |
1454 | } | |
1542ea39 | 1455 | |
facd6764 SC |
1456 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
1457 | { | |
1458 | UInt32 attr = 0 ; | |
1459 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1460 | return attr ; | |
5f0b2f22 | 1461 | } |
a07c1212 | 1462 | |
92346151 SC |
1463 | void wxTopLevelWindowMac::MacPerformUpdates() |
1464 | { | |
1465 | #if TARGET_API_MAC_OSX | |
1466 | if ( m_macUsesCompositing ) | |
1467 | { | |
1468 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
1469 | // for composited windows this also triggers a redraw of all | |
1470 | // invalid views in the window | |
1471 | if( UMAGetSystemVersion() >= 0x1030 ) | |
1472 | HIWindowFlush((WindowRef) m_macWindow) ; | |
1473 | else | |
1474 | #endif | |
1475 | { | |
1476 | // the only way to trigger the redrawing on earlier systems is to call | |
1477 | // ReceiveNextEvent | |
1478 | ||
1479 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
1480 | UInt32 currentEventClass = 0 ; | |
1481 | UInt32 currentEventKind = 0 ; | |
1482 | if ( currentEvent != NULL ) | |
1483 | { | |
1484 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
1485 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
1486 | } | |
1487 | if ( currentEventClass != kEventClassMenu ) | |
1488 | { | |
1489 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
1490 | EventRef theEvent; | |
1491 | OSStatus status = noErr ; | |
1492 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
1493 | } | |
1494 | } | |
1495 | } | |
1496 | else | |
1497 | #endif | |
1498 | { | |
1499 | BeginUpdate( (WindowRef) m_macWindow ) ; | |
1500 | ||
1501 | RgnHandle updateRgn = NewRgn(); | |
1502 | if ( updateRgn ) | |
1503 | { | |
1504 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); | |
1505 | UpdateControls( (WindowRef)m_macWindow , updateRgn ) ; | |
1506 | // if ( !EmptyRgn( updateRgn ) ) | |
1507 | // MacDoRedraw( updateRgn , 0 , true) ; | |
1508 | DisposeRgn( updateRgn ); | |
1509 | } | |
1510 | EndUpdate( (WindowRef)m_macWindow ) ; | |
1511 | QDFlushPortBuffer( GetWindowPort( (WindowRef)m_macWindow ) , NULL ) ; | |
1512 | } | |
1513 | } | |
1514 | ||
3feeb1e1 SC |
1515 | // Attracts the users attention to this window if the application is |
1516 | // inactive (should be called when a background event occurs) | |
1517 | ||
1518 | static pascal void wxMacNMResponse( NMRecPtr ptr ) | |
1519 | { | |
1520 | NMRemove( ptr ) ; | |
1521 | DisposePtr( (Ptr) ptr ) ; | |
1522 | } | |
1523 | ||
1524 | ||
1525 | void wxTopLevelWindowMac::RequestUserAttention(int flags ) | |
1526 | { | |
1527 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
1528 | static wxMacNMUPP nmupp( wxMacNMResponse ) | |
1529 | ; | |
1530 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; | |
1531 | notificationRequest->qType = nmType ; | |
1532 | notificationRequest->nmMark = 1 ; | |
1533 | notificationRequest->nmIcon = 0 ; | |
1534 | notificationRequest->nmSound = 0 ; | |
1535 | notificationRequest->nmStr = NULL ; | |
1536 | notificationRequest->nmResp = nmupp ; | |
1537 | verify_noerr( NMInstall( notificationRequest ) ) ; | |
1538 | } | |
1539 | ||
facd6764 SC |
1540 | // --------------------------------------------------------------------------- |
1541 | // Shape implementation | |
1542 | // --------------------------------------------------------------------------- | |
1543 | ||
6a7e6411 | 1544 | |
1542ea39 RD |
1545 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1546 | { | |
6a7e6411 RD |
1547 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1548 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1549 | ||
1550 | // The empty region signifies that the shape should be removed from the | |
1551 | // window. | |
1552 | if ( region.IsEmpty() ) | |
1553 | { | |
1554 | wxSize sz = GetClientSize(); | |
1555 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1556 | return SetShape(rgn); | |
1557 | } | |
1558 | ||
1559 | // Make a copy of the region | |
1560 | RgnHandle shapeRegion = NewRgn(); | |
1561 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1562 | ||
1563 | // Dispose of any shape region we may already have | |
1564 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1565 | if ( oldRgn ) | |
1566 | DisposeRgn(oldRgn); | |
1567 | ||
1568 | // Save the region so we can use it later | |
1569 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1570 | ||
1571 | // Tell the window manager that the window has changed shape | |
1572 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1573 | return TRUE; | |
1574 | } | |
1575 | ||
6a7e6411 RD |
1576 | // --------------------------------------------------------------------------- |
1577 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1578 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1579 | // --------------------------------------------------------------------------- | |
1580 | ||
6a7e6411 RD |
1581 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1582 | { | |
1583 | GetWindowPortBounds(window, inRect); | |
1584 | Point pt = {inRect->left, inRect->top}; | |
d6fd667b | 1585 | QDLocalToGlobalPoint( GetWindowPort(window) , &pt ) ; |
6a7e6411 RD |
1586 | inRect->top = pt.v; |
1587 | inRect->left = pt.h; | |
1588 | inRect->bottom += pt.v; | |
1589 | inRect->right += pt.h; | |
1590 | } | |
1591 | ||
1592 | ||
1593 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1594 | { | |
1595 | /*------------------------------------------------------ | |
1596 | Define which options your custom window supports. | |
1597 | --------------------------------------------------------*/ | |
1598 | //just enable everything for our demo | |
1599 | *(OptionBits*)param=//kWindowCanGrow| | |
1600 | //kWindowCanZoom| | |
1601 | //kWindowCanCollapse| | |
1602 | //kWindowCanGetWindowRegion| | |
1603 | //kWindowHasTitleBar| | |
1604 | //kWindowSupportsDragHilite| | |
1605 | kWindowCanDrawInCurrentPort| | |
1606 | //kWindowCanMeasureTitle| | |
1607 | kWindowWantsDisposeAtProcessDeath| | |
ae53adb4 | 1608 | kWindowSupportsGetGrowImageRegion| |
6a7e6411 RD |
1609 | kWindowDefSupportsColorGrafPort; |
1610 | return 1; | |
1542ea39 | 1611 | } |
6a7e6411 RD |
1612 | |
1613 | // The content region is left as a rectangle matching the window size, this is | |
1614 | // so the origin in the paint event, and etc. still matches what the | |
1615 | // programmer expects. | |
1616 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1617 | { | |
1618 | SetEmptyRgn(rgn); | |
1619 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1620 | if (win) | |
1621 | { | |
b19bf058 SC |
1622 | Rect r ; |
1623 | wxShapedMacWindowGetPos(window, &r ) ; | |
1624 | RectRgn( rgn , &r ) ; | |
6a7e6411 RD |
1625 | } |
1626 | } | |
1627 | ||
1628 | // The structure region is set to the shape given to the SetShape method. | |
1629 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1630 | { | |
1631 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1632 | ||
1633 | SetEmptyRgn(rgn); | |
1634 | if (cachedRegion) | |
1635 | { | |
1636 | Rect windowRect; | |
1637 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1638 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1639 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1640 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1641 | } | |
1642 | } | |
1643 | ||
1644 | ||
1645 | ||
1646 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1647 | { | |
1648 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1649 | ||
1650 | switch(rgnRec->regionCode) | |
1651 | { | |
1652 | case kWindowStructureRgn: | |
1653 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1654 | break; | |
1655 | case kWindowContentRgn: | |
1656 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1657 | break; | |
1658 | default: | |
1659 | SetEmptyRgn(rgnRec->winRgn); | |
1660 | } //switch | |
1661 | ||
1662 | return noErr; | |
1663 | } | |
1664 | ||
1665 | ||
1666 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1667 | { | |
1668 | /*------------------------------------------------------ | |
1669 | Determine the region of the window which was hit | |
1670 | --------------------------------------------------------*/ | |
1671 | Point hitPoint; | |
1672 | static RgnHandle tempRgn=nil; | |
1673 | ||
1674 | if(!tempRgn) | |
1675 | tempRgn=NewRgn(); | |
1676 | ||
1677 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1678 | ||
1679 | //Mac OS 8.5 or later | |
1680 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1681 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1682 | return wInContent; | |
1683 | ||
1684 | return wNoHit;//no significant area was hit. | |
1685 | } | |
1686 | ||
1687 | ||
1688 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1689 | { | |
1690 | switch(message) | |
1691 | { | |
1692 | case kWindowMsgHitTest: | |
1693 | return wxShapedMacWindowHitTest(window,param); | |
1694 | ||
1695 | case kWindowMsgGetFeatures: | |
1696 | return wxShapedMacWindowGetFeatures(window,param); | |
1697 | ||
1698 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1699 | case kWindowMsgGetRegion: | |
1700 | return wxShapedMacWindowGetRegion(window,param); | |
1701 | } | |
1702 | ||
1703 | return 0; | |
1704 | } | |
1925be65 | 1705 | |
6a7e6411 | 1706 | // --------------------------------------------------------------------------- |
1925be65 | 1707 |