]>
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 | ||
20 | #ifdef __GNUG__ | |
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" |
a15eb0a5 SC |
39 | #endif //WX_PRECOMP |
40 | ||
5f0b2f22 | 41 | #include "wx/mac/uma.h" |
422644a3 | 42 | #include "wx/mac/aga.h" |
7c091673 | 43 | #include "wx/app.h" |
5f0b2f22 | 44 | #include "wx/tooltip.h" |
a07c1212 | 45 | #include "wx/dnd.h" |
1f90939c SC |
46 | #if wxUSE_SYSTEM_OPTIONS |
47 | #include "wx/sysopt.h" | |
48 | #endif | |
5f0b2f22 | 49 | |
7f0c3a63 | 50 | #include <ToolUtils.h> |
dd49c691 | 51 | |
a15eb0a5 SC |
52 | // ---------------------------------------------------------------------------- |
53 | // globals | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | // list of all frames and modeless dialogs | |
32b5be3d RR |
57 | wxWindowList wxModelessWindows; |
58 | ||
6a7e6411 RD |
59 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
60 | ||
a15eb0a5 SC |
61 | // ============================================================================ |
62 | // wxTopLevelWindowMac implementation | |
63 | // ============================================================================ | |
64 | ||
facd6764 SC |
65 | BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) |
66 | END_EVENT_TABLE() | |
67 | ||
68 | ||
851b3a88 SC |
69 | // --------------------------------------------------------------------------- |
70 | // Carbon Events | |
71 | // --------------------------------------------------------------------------- | |
72 | ||
851b3a88 SC |
73 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
74 | ||
1542ea39 | 75 | static const EventTypeSpec eventList[] = |
851b3a88 | 76 | { |
facd6764 | 77 | // TODO remove control related event like key and mouse (except for WindowLeave events) |
949cb163 | 78 | #if 1 |
851b3a88 | 79 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , |
c5c9378c | 80 | |
e40298d5 | 81 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
82 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
83 | { kEventClassKeyboard, kEventRawKeyUp } , | |
84 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
facd6764 | 85 | #endif |
c5c9378c | 86 | |
16a76184 | 87 | { kEventClassWindow , kEventWindowShown } , |
851b3a88 SC |
88 | { kEventClassWindow , kEventWindowActivated } , |
89 | { kEventClassWindow , kEventWindowDeactivated } , | |
90 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
91 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
92 | { kEventClassWindow , kEventWindowClose } , | |
93 | ||
facd6764 SC |
94 | // we have to catch these events on the toplevel window level, as controls don't get the |
95 | // raw mouse events anymore | |
96 | ||
851b3a88 SC |
97 | { kEventClassMouse , kEventMouseDown } , |
98 | { kEventClassMouse , kEventMouseUp } , | |
de127c69 | 99 | { kEventClassMouse , kEventMouseWheelMoved } , |
851b3a88 SC |
100 | { kEventClassMouse , kEventMouseMoved } , |
101 | { kEventClassMouse , kEventMouseDragged } , | |
851b3a88 SC |
102 | } ; |
103 | ||
104 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
105 | { | |
106 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 107 | |
c5c9378c | 108 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 109 | char charCode ; |
1542ea39 | 110 | UInt32 keyCode ; |
c5c9378c | 111 | UInt32 modifiers ; |
e40298d5 | 112 | Point point ; |
c5c9378c SC |
113 | |
114 | EventRef rawEvent ; | |
1542ea39 | 115 | |
c5c9378c | 116 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 117 | |
e40298d5 JS |
118 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
119 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
120 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
121 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
122 | sizeof( Point ), NULL, &point ); | |
123 | ||
e40298d5 JS |
124 | switch ( GetEventKind( event ) ) |
125 | { | |
126 | case kEventTextInputUnicodeForKeyEvent : | |
ace07c80 | 127 | // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not |
5d2e69e8 | 128 | // get its own kEventTextInputUnicodeForKeyEvent, so we route back the |
ace07c80 SC |
129 | wxControl* control = wxDynamicCast( focus , wxControl ) ; |
130 | if ( control ) | |
131 | { | |
facd6764 | 132 | ControlRef macControl = (ControlRef) control->GetHandle() ; |
ace07c80 SC |
133 | if ( macControl ) |
134 | { | |
135 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
136 | result = noErr ; | |
137 | } | |
138 | } | |
139 | /* | |
140 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
77a4354e VZ |
141 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; |
142 | UInt32 message = (keyCode << 8) + charCode; | |
143 | ||
1542ea39 | 144 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
145 | focus , message , modifiers , when , point.h , point.v ) ) |
146 | { | |
147 | result = noErr ; | |
148 | } | |
ace07c80 | 149 | */ |
e40298d5 JS |
150 | break ; |
151 | } | |
c5c9378c SC |
152 | |
153 | return result ; | |
154 | } | |
155 | ||
156 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
157 | { | |
158 | OSStatus result = eventNotHandledErr ; | |
159 | ||
160 | wxWindow* focus = wxWindow::FindFocus() ; | |
92a7272f SC |
161 | if ( focus == NULL ) |
162 | return result ; | |
163 | ||
e40298d5 | 164 | char charCode ; |
1542ea39 | 165 | UInt32 keyCode ; |
c5c9378c | 166 | UInt32 modifiers ; |
e40298d5 JS |
167 | Point point ; |
168 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
169 | ||
170 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); | |
171 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
172 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
173 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
174 | sizeof( Point ), NULL, &point ); | |
175 | ||
176 | UInt32 message = (keyCode << 8) + charCode; | |
177 | switch( GetEventKind( event ) ) | |
178 | { | |
179 | case kEventRawKeyRepeat : | |
180 | case kEventRawKeyDown : | |
e40298d5 | 181 | { |
404f1d80 SC |
182 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
183 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
184 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
185 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( | |
186 | focus , message , modifiers , when , point.h , point.v ) ) | |
187 | { | |
188 | result = noErr ; | |
189 | } | |
190 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
e40298d5 JS |
191 | } |
192 | break ; | |
193 | case kEventRawKeyUp : | |
1542ea39 | 194 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
e40298d5 JS |
195 | focus , message , modifiers , when , point.h , point.v ) ) |
196 | { | |
197 | result = noErr ; | |
198 | } | |
199 | break ; | |
200 | case kEventRawKeyModifiersChanged : | |
201 | { | |
202 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
203 | ||
204 | event.m_shiftDown = modifiers & shiftKey; | |
205 | event.m_controlDown = modifiers & controlKey; | |
206 | event.m_altDown = modifiers & optionKey; | |
207 | event.m_metaDown = modifiers & cmdKey; | |
208 | ||
209 | event.m_x = point.h; | |
210 | event.m_y = point.v; | |
211 | event.m_timeStamp = when; | |
212 | wxWindow* focus = wxWindow::FindFocus() ; | |
213 | event.SetEventObject(focus); | |
214 | ||
8d60dc8a | 215 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) |
e40298d5 JS |
216 | { |
217 | event.m_keyCode = WXK_CONTROL ; | |
218 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
219 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
220 | } | |
8d60dc8a | 221 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
222 | { |
223 | event.m_keyCode = WXK_SHIFT ; | |
224 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
225 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
226 | } | |
8d60dc8a | 227 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) |
e40298d5 JS |
228 | { |
229 | event.m_keyCode = WXK_ALT ; | |
230 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
231 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
232 | } | |
b7aec135 SC |
233 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey ) |
234 | { | |
235 | event.m_keyCode = WXK_COMMAND ; | |
236 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
237 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
238 | } | |
e40298d5 JS |
239 | wxTheApp->s_lastModifiers = modifiers ; |
240 | } | |
241 | break ; | |
242 | } | |
851b3a88 SC |
243 | |
244 | return result ; | |
245 | } | |
246 | ||
facd6764 SC |
247 | // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr |
248 | // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the | |
249 | // mouse down at all | |
851b3a88 | 250 | |
facd6764 | 251 | // This handler can also be called from app level where data (ie target window) may be null or a non wx window |
1542ea39 | 252 | |
facd6764 | 253 | wxWindow* g_MacLastWindow = NULL ; |
a3195b73 | 254 | |
facd6764 SC |
255 | static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) |
256 | { | |
257 | UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ; | |
258 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
67245665 | 259 | |
facd6764 SC |
260 | // this parameter are not given for all events |
261 | EventMouseButton button = 0 ; | |
262 | UInt32 clickCount = 0 ; | |
263 | cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ; | |
264 | cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ; | |
265 | ||
266 | wxevent.m_x = screenMouseLocation.h; | |
267 | wxevent.m_y = screenMouseLocation.v; | |
268 | wxevent.m_shiftDown = modifiers & shiftKey; | |
269 | wxevent.m_controlDown = modifiers & controlKey; | |
270 | wxevent.m_altDown = modifiers & optionKey; | |
271 | wxevent.m_metaDown = modifiers & cmdKey; | |
272 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
273 | // a control click is interpreted as a right click | |
274 | if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) | |
851b3a88 | 275 | { |
facd6764 SC |
276 | button = kEventMouseButtonSecondary ; |
277 | } | |
278 | ||
279 | // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers | |
280 | // this button | |
281 | if ( button != 0 && cEvent.GetKind() != kEventMouseUp ) | |
282 | { | |
283 | switch( button ) | |
e40298d5 | 284 | { |
facd6764 SC |
285 | case kEventMouseButtonPrimary : |
286 | wxevent.m_leftDown = true ; | |
e40298d5 | 287 | break ; |
facd6764 SC |
288 | case kEventMouseButtonSecondary : |
289 | wxevent.m_rightDown = true ; | |
e40298d5 | 290 | break ; |
facd6764 SC |
291 | case kEventMouseButtonTertiary : |
292 | wxevent.m_middleDown = true ; | |
e40298d5 | 293 | break ; |
facd6764 SC |
294 | } |
295 | } | |
296 | // determinate the correct click button | |
297 | if ( button == kEventMouseButtonSecondary ) | |
298 | { | |
299 | if (cEvent.GetKind() == kEventMouseDown ) | |
92a7272f | 300 | wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ; |
facd6764 SC |
301 | else if ( cEvent.GetKind() == kEventMouseUp ) |
302 | wxevent.SetEventType(wxEVT_RIGHT_UP ) ; | |
303 | } | |
304 | else if ( button == kEventMouseButtonTertiary ) | |
305 | { | |
306 | if (cEvent.GetKind() == kEventMouseDown ) | |
307 | wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; | |
308 | else if ( cEvent.GetKind() == kEventMouseUp ) | |
309 | wxevent.SetEventType(wxEVT_MIDDLE_UP ) ; | |
310 | } | |
311 | else | |
312 | { | |
313 | if (cEvent.GetKind() == kEventMouseDown ) | |
314 | wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; | |
315 | else if ( cEvent.GetKind() == kEventMouseUp ) | |
316 | wxevent.SetEventType(wxEVT_LEFT_UP ) ; | |
317 | else if ( cEvent.GetKind() == kEventMouseWheelMoved ) | |
318 | { | |
319 | wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ; | |
320 | ||
321 | // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; | |
322 | SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ; | |
323 | ||
324 | wxevent.m_wheelRotation = delta; | |
325 | wxevent.m_wheelDelta = 1; | |
326 | wxevent.m_linesPerAction = 1; | |
327 | } | |
328 | else | |
329 | wxevent.SetEventType(wxEVT_MOTION ) ; | |
330 | } | |
331 | } | |
332 | ||
333 | ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart ) | |
334 | { | |
335 | if ( superControl ) | |
336 | { | |
337 | UInt16 childrenCount = 0 ; | |
338 | OSStatus err = CountSubControls( superControl , &childrenCount ) ; | |
339 | if ( err == errControlIsNotEmbedder ) | |
340 | return NULL ; | |
341 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
342 | ||
343 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
344 | { | |
345 | ControlHandle sibling ; | |
346 | err = GetIndexedSubControl( superControl , i , & sibling ) ; | |
347 | if ( err == errControlIsNotEmbedder ) | |
348 | return NULL ; | |
349 | ||
350 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
351 | if ( IsControlVisible( sibling ) ) | |
352 | { | |
353 | Rect r ; | |
354 | GetControlBounds( sibling , &r ) ; | |
355 | if ( MacPtInRect( location , &r ) ) | |
de127c69 | 356 | { |
facd6764 SC |
357 | ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ; |
358 | if ( child ) | |
359 | return child ; | |
360 | else | |
de127c69 | 361 | { |
facd6764 SC |
362 | *outPart = TestControl( sibling , location ) ; |
363 | return sibling ; | |
de127c69 GD |
364 | } |
365 | } | |
facd6764 | 366 | } |
e40298d5 JS |
367 | } |
368 | } | |
facd6764 SC |
369 | return NULL ; |
370 | } | |
1542ea39 | 371 | |
facd6764 SC |
372 | ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) |
373 | { | |
374 | #if TARGET_API_MAC_OSX | |
7741dfb1 | 375 | if ( UMAGetSystemVersion() >= 0x1030 ) |
30e0b1c9 SC |
376 | return FindControlUnderMouse( location , window , outPart ) ; |
377 | #endif | |
facd6764 SC |
378 | ControlRef rootControl = NULL ; |
379 | verify_noerr( GetRootControl( window , &rootControl ) ) ; | |
380 | return wxMacFindSubControl( location , rootControl , outPart ) ; | |
30e0b1c9 | 381 | |
facd6764 SC |
382 | } |
383 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
384 | { | |
385 | ||
386 | OSStatus result = eventNotHandledErr ; | |
387 | ||
388 | wxMacCarbonEvent cEvent( event ) ; | |
389 | ||
390 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
391 | Point windowMouseLocation = screenMouseLocation ; | |
392 | ||
393 | WindowRef window ; | |
394 | short windowPart = ::FindWindow(screenMouseLocation, &window); | |
395 | ||
396 | wxWindow* currentMouseWindow = NULL ; | |
7741dfb1 | 397 | |
facd6764 SC |
398 | if ( window ) |
399 | { | |
400 | // calculate window relative coordinates | |
401 | GrafPtr port; | |
402 | ::GetPort( &port ) ; | |
403 | ::SetPort( UMAGetWindowPort(window ) ) ; | |
404 | ::GlobalToLocal( &windowMouseLocation ) ; | |
405 | ::SetPort( port ) ; | |
406 | ||
407 | if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) | |
408 | { | |
409 | currentMouseWindow = wxTheApp->s_captureWindow ; | |
410 | } | |
411 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
412 | { | |
413 | ControlPartCode part ; | |
414 | ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ; | |
b19bf058 SC |
415 | if ( control == 0 ) |
416 | currentMouseWindow = (wxWindow*) data ; | |
417 | else | |
418 | currentMouseWindow = wxFindControlFromMacControl( control ) ; | |
facd6764 SC |
419 | } |
420 | } | |
421 | ||
422 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); | |
423 | SetupMouseEvent( wxevent , cEvent ) ; | |
424 | ||
425 | // handle all enter / leave events | |
426 | ||
427 | if ( currentMouseWindow != g_MacLastWindow ) | |
428 | { | |
429 | if ( g_MacLastWindow ) | |
430 | { | |
431 | wxMouseEvent eventleave(wxevent); | |
432 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
433 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
434 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
435 | ||
436 | #if wxUSE_TOOLTIPS | |
437 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
438 | #endif // wxUSE_TOOLTIPS | |
439 | g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave); | |
440 | } | |
441 | if ( currentMouseWindow ) | |
442 | { | |
443 | wxMouseEvent evententer(wxevent); | |
444 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
445 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
446 | evententer.SetEventObject( currentMouseWindow ) ; | |
447 | #if wxUSE_TOOLTIPS | |
448 | wxToolTip::RelayEvent( currentMouseWindow , evententer); | |
449 | #endif // wxUSE_TOOLTIPS | |
450 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
451 | } | |
452 | g_MacLastWindow = currentMouseWindow ; | |
453 | } | |
454 | ||
455 | if ( windowPart == inMenuBar ) | |
456 | { | |
457 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
458 | if ( cEvent.GetKind() == kEventMouseDown ) | |
459 | { | |
460 | ::MenuSelect( screenMouseLocation ) ; | |
461 | result = noErr ; | |
462 | } | |
463 | } // if ( windowPart == inMenuBar ) | |
464 | else if ( currentMouseWindow ) | |
465 | { | |
466 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
467 | ||
468 | wxevent.SetEventObject( currentMouseWindow ) ; | |
469 | ||
470 | // update cursor | |
471 | ||
472 | wxWindow* cursorTarget = currentMouseWindow ; | |
473 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
474 | ||
475 | while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
476 | { | |
477 | cursorTarget = cursorTarget->GetParent() ; | |
478 | if ( cursorTarget ) | |
479 | cursorPoint += cursorTarget->GetPosition() ; | |
480 | } | |
1542ea39 | 481 | |
facd6764 | 482 | // update focus |
851b3a88 | 483 | |
facd6764 SC |
484 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) |
485 | { | |
486 | // set focus to this window | |
487 | if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) | |
488 | currentMouseWindow->SetFocus(); | |
489 | } | |
490 | ||
491 | // make tooltips current | |
492 | ||
493 | #if wxUSE_TOOLTIPS | |
494 | if ( wxevent.GetEventType() == wxEVT_MOTION | |
495 | || wxevent.GetEventType() == wxEVT_ENTER_WINDOW | |
496 | || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
497 | wxToolTip::RelayEvent( currentMouseWindow , wxevent); | |
498 | #endif // wxUSE_TOOLTIPS | |
499 | if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
500 | result = noErr; | |
30e0b1c9 SC |
501 | else |
502 | { | |
503 | ControlPartCode dummyPart ; | |
504 | // if built-in find control is finding the wrong control (ie static box instead of overlaid | |
505 | // button, we cannot let the standard handler do its job, but must handle manually | |
506 | ||
507 | if ( ( cEvent.GetKind() == kEventMouseDown ) && | |
508 | (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != | |
509 | wxMacFindControlUnderMouse( windowMouseLocation , window , &dummyPart ) ) ) | |
510 | { | |
511 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
512 | HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , windowMouseLocation , | |
513 | modifiers , (ControlActionUPP ) -1 ) ; | |
514 | result = noErr ; | |
515 | } | |
516 | } | |
facd6764 SC |
517 | if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow ) |
518 | { | |
519 | wxTheApp->s_captureWindow = NULL ; | |
520 | // update cursor ? | |
521 | } | |
522 | } // else if ( currentMouseWindow ) | |
523 | return result ; | |
851b3a88 | 524 | } |
facd6764 SC |
525 | |
526 | static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
851b3a88 SC |
527 | { |
528 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 529 | |
facd6764 SC |
530 | wxMacCarbonEvent cEvent( event ) ; |
531 | ||
532 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; | |
e40298d5 | 533 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
1542ea39 | 534 | |
e40298d5 JS |
535 | switch( GetEventKind( event ) ) |
536 | { | |
e40298d5 | 537 | case kEventWindowActivated : |
facd6764 SC |
538 | { |
539 | toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; | |
facd6764 SC |
540 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); |
541 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
542 | wxevent.SetEventObject(toplevelWindow); | |
543 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 544 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 545 | break ; |
facd6764 | 546 | } |
e40298d5 | 547 | case kEventWindowDeactivated : |
facd6764 SC |
548 | { |
549 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
550 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
551 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
552 | wxevent.SetEventObject(toplevelWindow); | |
553 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 554 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 555 | break ; |
facd6764 | 556 | } |
16a76184 SC |
557 | case kEventWindowShown : |
558 | toplevelWindow->Refresh() ; | |
559 | result = noErr ; | |
560 | break ; | |
e40298d5 JS |
561 | case kEventWindowClose : |
562 | toplevelWindow->Close() ; | |
563 | result = noErr ; | |
564 | break ; | |
565 | case kEventWindowBoundsChanged : | |
facd6764 SC |
566 | { |
567 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
568 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
569 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
570 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
e40298d5 | 571 | { |
facd6764 SC |
572 | // according to the other ports we handle this within the OS level |
573 | // resize event, not within a wxSizeEvent | |
574 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
575 | if ( frame ) | |
576 | { | |
577 | #if wxUSE_STATUSBAR | |
578 | frame->PositionStatusBar(); | |
579 | #endif | |
580 | #if wxUSE_TOOLBAR | |
581 | frame->PositionToolBar(); | |
582 | #endif | |
583 | } | |
1542ea39 | 584 | |
facd6764 SC |
585 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; |
586 | event.SetEventObject( toplevelWindow ) ; | |
851b3a88 | 587 | |
facd6764 | 588 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; |
e40298d5 | 589 | } |
facd6764 SC |
590 | if ( attributes & kWindowBoundsChangeOriginChanged ) |
591 | { | |
592 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
593 | event.SetEventObject( toplevelWindow ) ; | |
594 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
595 | } | |
596 | result = noErr ; | |
e40298d5 | 597 | break ; |
facd6764 | 598 | } |
f81bfef9 | 599 | case kEventWindowBoundsChanging : |
facd6764 SC |
600 | { |
601 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
602 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
83901ec2 | 603 | |
facd6764 SC |
604 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) |
605 | { | |
29281095 SC |
606 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates |
607 | int left , top , right , bottom ; | |
608 | toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ; | |
609 | wxRect r( newRect.left - left , newRect.top - top , | |
610 | newRect.right - newRect.left + left + right , newRect.bottom - newRect.top + top + bottom ) ; | |
facd6764 SC |
611 | // this is a EVT_SIZING not a EVT_SIZE type ! |
612 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
613 | wxevent.SetEventObject( toplevelWindow ) ; | |
614 | wxRect adjustR = r ; | |
615 | if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
facd6764 | 616 | adjustR = wxevent.GetRect() ; |
29281095 | 617 | |
facd6764 SC |
618 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) |
619 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
2c25bd55 | 620 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) |
facd6764 SC |
621 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; |
622 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
623 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
2c25bd55 | 624 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) |
facd6764 | 625 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; |
34952e03 | 626 | Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; |
facd6764 SC |
627 | if ( !EqualRect( &newRect , &adjustedRect ) ) |
628 | cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; | |
f81bfef9 | 629 | } |
facd6764 SC |
630 | |
631 | result = noErr ; | |
f81bfef9 | 632 | break ; |
facd6764 | 633 | } |
e40298d5 JS |
634 | default : |
635 | break ; | |
636 | } | |
637 | return result ; | |
851b3a88 SC |
638 | } |
639 | ||
facd6764 | 640 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
641 | { |
642 | OSStatus result = eventNotHandledErr ; | |
643 | ||
644 | switch ( GetEventClass( event ) ) | |
645 | { | |
c5c9378c | 646 | case kEventClassKeyboard : |
e40298d5 | 647 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 648 | break ; |
851b3a88 | 649 | case kEventClassTextInput : |
e40298d5 | 650 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
651 | break ; |
652 | case kEventClassWindow : | |
facd6764 | 653 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; |
e40298d5 | 654 | break ; |
851b3a88 | 655 | case kEventClassMouse : |
facd6764 | 656 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; |
e40298d5 | 657 | break ; |
851b3a88 SC |
658 | default : |
659 | break ; | |
660 | } | |
661 | return result ; | |
662 | } | |
663 | ||
facd6764 | 664 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) |
851b3a88 | 665 | |
5f0b2f22 SC |
666 | // --------------------------------------------------------------------------- |
667 | // wxWindowMac utility functions | |
668 | // --------------------------------------------------------------------------- | |
669 | ||
670 | // Find an item given the Macintosh Window Reference | |
671 | ||
facd6764 SC |
672 | wxList wxWinMacWindowList(wxKEY_INTEGER); |
673 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
5f0b2f22 | 674 | { |
facd6764 | 675 | wxNode *node = wxWinMacWindowList.Find((long)inWindowRef); |
5f0b2f22 SC |
676 | if (!node) |
677 | return NULL; | |
eb22f2a6 | 678 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
679 | } |
680 | ||
facd6764 SC |
681 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; |
682 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
5f0b2f22 SC |
683 | { |
684 | // adding NULL WindowRef is (first) surely a result of an error and | |
685 | // (secondly) breaks menu command processing | |
427ff662 | 686 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 | 687 | |
facd6764 SC |
688 | if ( !wxWinMacWindowList.Find((long)inWindowRef) ) |
689 | wxWinMacWindowList.Append((long)inWindowRef, win); | |
5f0b2f22 SC |
690 | } |
691 | ||
facd6764 | 692 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; |
5f0b2f22 SC |
693 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) |
694 | { | |
facd6764 | 695 | wxWinMacWindowList.DeleteObject(win); |
5f0b2f22 SC |
696 | } |
697 | ||
698 | ||
a15eb0a5 SC |
699 | // ---------------------------------------------------------------------------- |
700 | // wxTopLevelWindowMac creation | |
701 | // ---------------------------------------------------------------------------- | |
702 | ||
245f3581 | 703 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
5f0b2f22 | 704 | |
a15eb0a5 SC |
705 | void wxTopLevelWindowMac::Init() |
706 | { | |
707 | m_iconized = | |
708 | m_maximizeOnShow = FALSE; | |
6a17ca35 | 709 | m_macWindow = NULL ; |
facd6764 SC |
710 | #if TARGET_API_MAC_OSX |
711 | m_macUsesCompositing = TRUE; | |
712 | #else | |
713 | m_macUsesCompositing = FALSE; | |
714 | #endif | |
7c091673 | 715 | m_macEventHandler = NULL ; |
a15eb0a5 SC |
716 | } |
717 | ||
118f012e SC |
718 | class wxMacDeferredWindowDeleter : public wxObject |
719 | { | |
720 | public : | |
1542ea39 RD |
721 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
722 | { | |
723 | m_macWindow = windowRef ; | |
118f012e | 724 | } |
1542ea39 RD |
725 | virtual ~wxMacDeferredWindowDeleter() |
726 | { | |
727 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
728 | } |
729 | protected : | |
730 | WindowRef m_macWindow ; | |
731 | } ; | |
732 | ||
a15eb0a5 SC |
733 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
734 | wxWindowID id, | |
735 | const wxString& title, | |
736 | const wxPoint& pos, | |
737 | const wxSize& size, | |
738 | long style, | |
739 | const wxString& name) | |
740 | { | |
741 | // init our fields | |
742 | Init(); | |
743 | ||
744 | m_windowStyle = style; | |
745 | ||
746 | SetName(name); | |
747 | ||
748 | m_windowId = id == -1 ? NewControlId() : id; | |
749 | ||
facd6764 SC |
750 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
751 | ||
94d1d0f4 SC |
752 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
753 | ||
a15eb0a5 SC |
754 | wxTopLevelWindows.Append(this); |
755 | ||
756 | if ( parent ) | |
757 | parent->AddChild(this); | |
758 | ||
759 | return TRUE; | |
760 | } | |
761 | ||
762 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
763 | { | |
6a17ca35 SC |
764 | if ( m_macWindow ) |
765 | { | |
766 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 767 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 768 | } |
1542ea39 | 769 | |
7c091673 SC |
770 | if ( m_macEventHandler ) |
771 | { | |
772 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
773 | m_macEventHandler = NULL ; | |
774 | } | |
851b3a88 | 775 | |
5f0b2f22 SC |
776 | wxRemoveMacWindowAssociation( this ) ; |
777 | ||
a15eb0a5 SC |
778 | if ( wxModelessWindows.Find(this) ) |
779 | wxModelessWindows.DeleteObject(this); | |
a15eb0a5 SC |
780 | } |
781 | ||
782 | ||
783 | // ---------------------------------------------------------------------------- | |
784 | // wxTopLevelWindowMac maximize/minimize | |
785 | // ---------------------------------------------------------------------------- | |
786 | ||
787 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
788 | { | |
1f90939c SC |
789 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
790 | wxMacWindowClipper clip (this); | |
b7aec135 | 791 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; |
facd6764 SC |
792 | /* |
793 | Rect r ; | |
794 | GDHandle device = NULL ; | |
795 | verify_noerr( GetWindowGreatestAreaDevice( (WindowRef) m_macWindow , kWindowContentRgn , | |
796 | &device , NULL ) ; | |
797 | verify_noerr( GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ) ; | |
b7aec135 SC |
798 | |
799 | Rect tempRect ; | |
800 | GrafPtr port ; | |
801 | GetPort( &port ) ; | |
802 | Point pt = { 0, 0 } ; | |
803 | SetPortWindowPort((WindowRef)m_macWindow) ; | |
804 | LocalToGlobal( &pt ) ; | |
805 | SetPort( port ) ; | |
806 | ||
807 | GetWindowPortBounds((WindowRef)m_macWindow, &tempRect ) ; | |
808 | SetSize( pt.h , pt.v , tempRect.right-tempRect.left , | |
809 | tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); | |
facd6764 | 810 | */ |
a15eb0a5 SC |
811 | } |
812 | ||
813 | bool wxTopLevelWindowMac::IsMaximized() const | |
814 | { | |
b7aec135 | 815 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
816 | } |
817 | ||
818 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
819 | { | |
b7aec135 SC |
820 | if ( IsWindowCollapsable((WindowRef)m_macWindow) ) |
821 | CollapseWindow((WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
822 | } |
823 | ||
824 | bool wxTopLevelWindowMac::IsIconized() const | |
825 | { | |
b7aec135 | 826 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
827 | } |
828 | ||
829 | void wxTopLevelWindowMac::Restore() | |
830 | { | |
831 | // not available on mac | |
832 | } | |
833 | ||
834 | // ---------------------------------------------------------------------------- | |
835 | // wxTopLevelWindowMac misc | |
836 | // ---------------------------------------------------------------------------- | |
837 | ||
facd6764 SC |
838 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
839 | { | |
840 | return wxPoint(0,0) ; | |
841 | } | |
842 | ||
a15eb0a5 SC |
843 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) |
844 | { | |
845 | // this sets m_icon | |
846 | wxTopLevelWindowBase::SetIcon(icon); | |
847 | } | |
5f0b2f22 | 848 | |
facd6764 SC |
849 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
850 | { | |
851 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
852 | ||
853 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
854 | { | |
855 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
856 | } | |
857 | } | |
858 | ||
949cb163 SC |
859 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
860 | { | |
861 | if ( m_macEventHandler != NULL ) | |
862 | { | |
863 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
864 | } | |
865 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
866 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); | |
867 | } | |
868 | ||
5f0b2f22 SC |
869 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
870 | const wxPoint& pos, | |
871 | const wxSize& size, | |
872 | long style, | |
1542ea39 | 873 | const wxString& name ) |
5f0b2f22 | 874 | { |
47ac4f9b | 875 | OSStatus err = noErr ; |
e40298d5 JS |
876 | SetName(name); |
877 | m_windowStyle = style; | |
878 | m_isShown = FALSE; | |
1542ea39 | 879 | |
e40298d5 | 880 | // create frame. |
1542ea39 | 881 | |
5f0b2f22 | 882 | Rect theBoundsRect; |
1542ea39 | 883 | |
facd6764 SC |
884 | int x = (int)pos.x; |
885 | int y = (int)pos.y; | |
886 | if ( y < 50 ) | |
887 | y = 50 ; | |
888 | if ( x < 20 ) | |
889 | x = 20 ; | |
1542ea39 | 890 | |
facd6764 SC |
891 | int w = WidthDefault(size.x); |
892 | int h = HeightDefault(size.y); | |
1542ea39 | 893 | |
facd6764 | 894 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 895 | |
5f0b2f22 | 896 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 897 | |
5f0b2f22 SC |
898 | WindowClass wclass = 0; |
899 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 900 | |
f5744893 | 901 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 902 | { |
1542ea39 | 903 | if ( |
f5744893 SC |
904 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
905 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
906 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 907 | ) |
5f0b2f22 | 908 | { |
f5744893 SC |
909 | wclass = kFloatingWindowClass ; |
910 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
911 | { | |
912 | attr |= kWindowSideTitlebarAttribute ; | |
913 | } | |
914 | } | |
915 | else | |
916 | { | |
917 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
918 | } |
919 | } | |
920 | else if ( HasFlag( wxCAPTION ) ) | |
921 | { | |
1542ea39 | 922 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
923 | } |
924 | else | |
925 | { | |
f5744893 | 926 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 927 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
928 | { |
929 | wclass = kDocumentWindowClass ; | |
930 | } | |
931 | else | |
932 | { | |
933 | wclass = kPlainWindowClass ; | |
934 | } | |
5f0b2f22 | 935 | } |
1542ea39 | 936 | |
47ac4f9b | 937 | if ( HasFlag( wxMINIMIZE_BOX ) ) |
5f0b2f22 | 938 | { |
5f0b2f22 SC |
939 | attr |= kWindowCollapseBoxAttribute ; |
940 | } | |
47ac4f9b SC |
941 | if ( HasFlag( wxMAXIMIZE_BOX ) ) |
942 | { | |
943 | attr |= kWindowFullZoomAttribute ; | |
944 | } | |
5f0b2f22 SC |
945 | if ( HasFlag( wxRESIZE_BORDER ) ) |
946 | { | |
947 | attr |= kWindowResizableAttribute ; | |
948 | } | |
47ac4f9b | 949 | if ( HasFlag( wxCLOSE_BOX) ) |
5f0b2f22 SC |
950 | { |
951 | attr |= kWindowCloseBoxAttribute ; | |
952 | } | |
1542ea39 | 953 | |
eb630bf1 DS |
954 | if (UMAGetSystemVersion() >= 0x1000) |
955 | { | |
facd6764 | 956 | // turn on live resizing (OS X only) |
eb630bf1 DS |
957 | attr |= kWindowLiveResizeAttribute; |
958 | } | |
959 | ||
6a7e6411 | 960 | if (HasFlag(wxSTAY_ON_TOP)) |
eb630bf1 | 961 | wclass = kUtilityWindowClass; |
6a7e6411 | 962 | |
facd6764 SC |
963 | #if TARGET_API_MAC_OSX |
964 | attr |= kWindowCompositingAttribute; | |
d66c3960 | 965 | #endif |
1f90939c | 966 | |
6a7e6411 RD |
967 | if ( HasFlag(wxFRAME_SHAPED) ) |
968 | { | |
969 | WindowDefSpec customWindowDefSpec; | |
970 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
971 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
972 | ||
47ac4f9b | 973 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
974 | attr, &theBoundsRect, |
975 | (WindowRef*) &m_macWindow); | |
976 | } | |
977 | else | |
978 | { | |
47ac4f9b | 979 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
980 | } |
981 | ||
47ac4f9b | 982 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
f83b6761 SC |
983 | |
984 | // the create commands are only for content rect, so we have to set the size again as | |
985 | // structure bounds | |
986 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; | |
987 | ||
facd6764 SC |
988 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
989 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
990 | if ( m_macUsesCompositing ) | |
1f90939c | 991 | { |
facd6764 | 992 | ::GetRootControl( (WindowRef)m_macWindow, (ControlRef*)&m_macControl ) ; |
1f90939c SC |
993 | } |
994 | else | |
995 | { | |
facd6764 | 996 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlRef*)&m_macControl ) ; |
1f90939c | 997 | } |
73fe67bd | 998 | // the root control level handleer |
949cb163 | 999 | MacInstallEventHandler() ; |
facd6764 | 1000 | |
73fe67bd | 1001 | // the frame window event handler |
e40298d5 | 1002 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 | 1003 | MacInstallTopLevelWindowEventHandler() ; |
b19bf058 | 1004 | |
facd6764 | 1005 | m_macFocus = NULL ; |
6a7e6411 RD |
1006 | |
1007 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1008 | { | |
1009 | // default shape matches the window size | |
facd6764 | 1010 | wxRegion rgn(0, 0, w, h); |
6a7e6411 RD |
1011 | SetShape(rgn); |
1012 | } | |
3dfafdb9 RD |
1013 | |
1014 | wxWindowCreateEvent event(this); | |
1015 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1016 | } |
1017 | ||
5d2e69e8 | 1018 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 1019 | { |
5d2e69e8 | 1020 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
1021 | } |
1022 | ||
5f0b2f22 SC |
1023 | // Raise the window to the top of the Z order |
1024 | void wxTopLevelWindowMac::Raise() | |
1025 | { | |
7f3c339c | 1026 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1027 | } |
1028 | ||
1029 | // Lower the window to the bottom of the Z order | |
1030 | void wxTopLevelWindowMac::Lower() | |
1031 | { | |
76a5e5d2 | 1032 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
1033 | } |
1034 | ||
851b3a88 | 1035 | |
245f3581 DE |
1036 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1037 | { | |
1038 | if(s_macDeactivateWindow) | |
1039 | { | |
365796b1 | 1040 | wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow); |
245f3581 DE |
1041 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1042 | } | |
1043 | } | |
1044 | ||
851b3a88 | 1045 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) |
5f0b2f22 | 1046 | { |
17f8d2a7 VZ |
1047 | // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this); |
1048 | ||
245f3581 DE |
1049 | if(s_macDeactivateWindow==this) |
1050 | s_macDeactivateWindow=NULL; | |
1051 | MacDelayedDeactivation(timestamp); | |
8ab50549 | 1052 | MacPropagateHiliteChanged() ; |
5f0b2f22 SC |
1053 | } |
1054 | ||
1055 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1056 | { | |
1057 | wxWindow::SetTitle( title ) ; | |
16a76184 | 1058 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; |
5f0b2f22 SC |
1059 | } |
1060 | ||
1061 | bool wxTopLevelWindowMac::Show(bool show) | |
1062 | { | |
facd6764 | 1063 | if ( !wxTopLevelWindowBase::Show(show) ) |
5f0b2f22 SC |
1064 | return FALSE; |
1065 | ||
1066 | if (show) | |
1542ea39 | 1067 | { |
1f90939c SC |
1068 | #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003 |
1069 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1070 | { | |
1071 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1072 | } | |
1073 | else | |
1074 | #endif | |
1075 | { | |
1076 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); | |
1077 | } | |
1078 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
facd6764 SC |
1079 | // as apps expect a size event to occur at this moment |
1080 | wxSizeEvent event( GetSize() , m_windowId); | |
1f90939c SC |
1081 | event.SetEventObject(this); |
1082 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1083 | } |
1084 | else | |
1085 | { | |
1f90939c SC |
1086 | #if wxUSE_SYSTEM_OPTIONS |
1087 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1088 | { | |
1089 | ::HideWindow((WindowRef) m_macWindow ); | |
1090 | } | |
1091 | else | |
1092 | #endif | |
1093 | { | |
1094 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); | |
1095 | } | |
5f0b2f22 SC |
1096 | } |
1097 | ||
facd6764 | 1098 | MacPropagateVisibilityChanged() ; |
5f0b2f22 | 1099 | |
facd6764 | 1100 | return TRUE ; |
5f0b2f22 SC |
1101 | } |
1102 | ||
facd6764 SC |
1103 | // we are still using coordinates of the content view, todo switch to structure bounds |
1104 | ||
29281095 SC |
1105 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1106 | { | |
1107 | Rect content ; | |
1108 | Rect structure ; | |
1109 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; | |
1110 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1111 | ||
1112 | left = content.left - structure.left ; | |
1113 | top = content.top - structure.top ; | |
1114 | right = structure.right - content.right ; | |
1115 | bottom = structure.bottom - content.bottom ; | |
1116 | } | |
1117 | ||
5f0b2f22 SC |
1118 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1119 | { | |
facd6764 SC |
1120 | Rect bounds = { y , x , y + height , x + width } ; |
1121 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
5f0b2f22 SC |
1122 | } |
1123 | ||
facd6764 | 1124 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1125 | { |
facd6764 SC |
1126 | Rect bounds ; |
1127 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1128 | if(x) *x = bounds.left ; | |
1129 | if(y) *y = bounds.top ; | |
1130 | } | |
1131 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1132 | { | |
1133 | Rect bounds ; | |
1134 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1135 | if(width) *width = bounds.right - bounds.left ; | |
1136 | if(height) *height = bounds.bottom - bounds.top ; | |
1137 | } | |
1542ea39 | 1138 | |
facd6764 SC |
1139 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1140 | { | |
1141 | Rect bounds ; | |
1142 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1143 | if(width) *width = bounds.right - bounds.left ; | |
1144 | if(height) *height = bounds.bottom - bounds.top ; | |
1145 | } | |
1542ea39 | 1146 | |
facd6764 SC |
1147 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
1148 | { | |
1149 | #if TARGET_API_MAC_OSX | |
1150 | UInt32 attr = 0 ; | |
1151 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1152 | wxASSERT_MSG( attr & kWindowCompositingAttribute , | |
1153 | wxT("Cannot set metal appearance on a non-compositing window") ) ; | |
1154 | ||
1155 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1156 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1157 | #endif | |
1158 | } | |
1542ea39 | 1159 | |
6aab345b SC |
1160 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
1161 | { | |
1162 | #if TARGET_API_MAC_OSX | |
1163 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1164 | #else | |
1165 | return false ; | |
1166 | #endif | |
1167 | } | |
1168 | ||
facd6764 SC |
1169 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
1170 | { | |
1171 | ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ; | |
1172 | } | |
1542ea39 | 1173 | |
facd6764 SC |
1174 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
1175 | { | |
1176 | UInt32 attr = 0 ; | |
1177 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1178 | return attr ; | |
5f0b2f22 | 1179 | } |
a07c1212 | 1180 | |
facd6764 SC |
1181 | // --------------------------------------------------------------------------- |
1182 | // Shape implementation | |
1183 | // --------------------------------------------------------------------------- | |
1184 | ||
6a7e6411 | 1185 | |
1542ea39 RD |
1186 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1187 | { | |
6a7e6411 RD |
1188 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1189 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1190 | ||
1191 | // The empty region signifies that the shape should be removed from the | |
1192 | // window. | |
1193 | if ( region.IsEmpty() ) | |
1194 | { | |
1195 | wxSize sz = GetClientSize(); | |
1196 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1197 | return SetShape(rgn); | |
1198 | } | |
1199 | ||
1200 | // Make a copy of the region | |
1201 | RgnHandle shapeRegion = NewRgn(); | |
1202 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1203 | ||
1204 | // Dispose of any shape region we may already have | |
1205 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1206 | if ( oldRgn ) | |
1207 | DisposeRgn(oldRgn); | |
1208 | ||
1209 | // Save the region so we can use it later | |
1210 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1211 | ||
1212 | // Tell the window manager that the window has changed shape | |
1213 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1214 | return TRUE; | |
1215 | } | |
1216 | ||
6a7e6411 RD |
1217 | // --------------------------------------------------------------------------- |
1218 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1219 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1220 | // --------------------------------------------------------------------------- | |
1221 | ||
6a7e6411 RD |
1222 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1223 | { | |
1224 | GetWindowPortBounds(window, inRect); | |
1225 | Point pt = {inRect->left, inRect->top}; | |
1226 | SetPort((GrafPtr) GetWindowPort(window)); | |
1227 | LocalToGlobal(&pt); | |
1228 | inRect->top = pt.v; | |
1229 | inRect->left = pt.h; | |
1230 | inRect->bottom += pt.v; | |
1231 | inRect->right += pt.h; | |
1232 | } | |
1233 | ||
1234 | ||
1235 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1236 | { | |
1237 | /*------------------------------------------------------ | |
1238 | Define which options your custom window supports. | |
1239 | --------------------------------------------------------*/ | |
1240 | //just enable everything for our demo | |
1241 | *(OptionBits*)param=//kWindowCanGrow| | |
1242 | //kWindowCanZoom| | |
1243 | //kWindowCanCollapse| | |
1244 | //kWindowCanGetWindowRegion| | |
1245 | //kWindowHasTitleBar| | |
1246 | //kWindowSupportsDragHilite| | |
1247 | kWindowCanDrawInCurrentPort| | |
1248 | //kWindowCanMeasureTitle| | |
1249 | kWindowWantsDisposeAtProcessDeath| | |
1250 | kWindowSupportsSetGrowImageRegion| | |
1251 | kWindowDefSupportsColorGrafPort; | |
1252 | return 1; | |
1542ea39 | 1253 | } |
6a7e6411 RD |
1254 | |
1255 | // The content region is left as a rectangle matching the window size, this is | |
1256 | // so the origin in the paint event, and etc. still matches what the | |
1257 | // programmer expects. | |
1258 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1259 | { | |
1260 | SetEmptyRgn(rgn); | |
1261 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1262 | if (win) | |
1263 | { | |
b19bf058 SC |
1264 | Rect r ; |
1265 | wxShapedMacWindowGetPos(window, &r ) ; | |
1266 | RectRgn( rgn , &r ) ; | |
6a7e6411 RD |
1267 | } |
1268 | } | |
1269 | ||
1270 | // The structure region is set to the shape given to the SetShape method. | |
1271 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1272 | { | |
1273 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1274 | ||
1275 | SetEmptyRgn(rgn); | |
1276 | if (cachedRegion) | |
1277 | { | |
1278 | Rect windowRect; | |
1279 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1280 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1281 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1282 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1283 | } | |
1284 | } | |
1285 | ||
1286 | ||
1287 | ||
1288 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1289 | { | |
1290 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1291 | ||
1292 | switch(rgnRec->regionCode) | |
1293 | { | |
1294 | case kWindowStructureRgn: | |
1295 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1296 | break; | |
1297 | case kWindowContentRgn: | |
1298 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1299 | break; | |
1300 | default: | |
1301 | SetEmptyRgn(rgnRec->winRgn); | |
1302 | } //switch | |
1303 | ||
1304 | return noErr; | |
1305 | } | |
1306 | ||
1307 | ||
1308 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1309 | { | |
1310 | /*------------------------------------------------------ | |
1311 | Determine the region of the window which was hit | |
1312 | --------------------------------------------------------*/ | |
1313 | Point hitPoint; | |
1314 | static RgnHandle tempRgn=nil; | |
1315 | ||
1316 | if(!tempRgn) | |
1317 | tempRgn=NewRgn(); | |
1318 | ||
1319 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1320 | ||
1321 | //Mac OS 8.5 or later | |
1322 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1323 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1324 | return wInContent; | |
1325 | ||
1326 | return wNoHit;//no significant area was hit. | |
1327 | } | |
1328 | ||
1329 | ||
1330 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1331 | { | |
1332 | switch(message) | |
1333 | { | |
1334 | case kWindowMsgHitTest: | |
1335 | return wxShapedMacWindowHitTest(window,param); | |
1336 | ||
1337 | case kWindowMsgGetFeatures: | |
1338 | return wxShapedMacWindowGetFeatures(window,param); | |
1339 | ||
1340 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1341 | case kWindowMsgGetRegion: | |
1342 | return wxShapedMacWindowGetRegion(window,param); | |
1343 | } | |
1344 | ||
1345 | return 0; | |
1346 | } | |
1925be65 | 1347 | |
6a7e6411 | 1348 | // --------------------------------------------------------------------------- |
1925be65 | 1349 |