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