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