]>
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) ; | |
facd6764 SC |
515 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); |
516 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
517 | wxevent.SetEventObject(toplevelWindow); | |
518 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 519 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 520 | break ; |
facd6764 | 521 | } |
e40298d5 | 522 | case kEventWindowDeactivated : |
facd6764 SC |
523 | { |
524 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
525 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
526 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
527 | wxevent.SetEventObject(toplevelWindow); | |
528 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 529 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 530 | break ; |
facd6764 | 531 | } |
16a76184 SC |
532 | case kEventWindowShown : |
533 | toplevelWindow->Refresh() ; | |
534 | result = noErr ; | |
535 | break ; | |
e40298d5 JS |
536 | case kEventWindowClose : |
537 | toplevelWindow->Close() ; | |
538 | result = noErr ; | |
539 | break ; | |
540 | case kEventWindowBoundsChanged : | |
facd6764 SC |
541 | { |
542 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
543 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
544 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
545 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
e40298d5 | 546 | { |
facd6764 SC |
547 | // according to the other ports we handle this within the OS level |
548 | // resize event, not within a wxSizeEvent | |
549 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
550 | if ( frame ) | |
551 | { | |
552 | #if wxUSE_STATUSBAR | |
553 | frame->PositionStatusBar(); | |
554 | #endif | |
555 | #if wxUSE_TOOLBAR | |
556 | frame->PositionToolBar(); | |
557 | #endif | |
558 | } | |
1542ea39 | 559 | |
facd6764 SC |
560 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; |
561 | event.SetEventObject( toplevelWindow ) ; | |
851b3a88 | 562 | |
facd6764 | 563 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; |
e40298d5 | 564 | } |
facd6764 SC |
565 | if ( attributes & kWindowBoundsChangeOriginChanged ) |
566 | { | |
567 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
568 | event.SetEventObject( toplevelWindow ) ; | |
569 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
570 | } | |
571 | result = noErr ; | |
e40298d5 | 572 | break ; |
facd6764 | 573 | } |
f81bfef9 | 574 | case kEventWindowBoundsChanging : |
facd6764 SC |
575 | { |
576 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
577 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
578 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
83901ec2 | 579 | |
facd6764 SC |
580 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) |
581 | { | |
582 | // this is a EVT_SIZING not a EVT_SIZE type ! | |
583 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
584 | wxevent.SetEventObject( toplevelWindow ) ; | |
585 | wxRect adjustR = r ; | |
586 | if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
f81bfef9 | 587 | { |
facd6764 | 588 | adjustR = wxevent.GetRect() ; |
f81bfef9 | 589 | } |
facd6764 SC |
590 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) |
591 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
592 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxHeight() ) | |
593 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; | |
594 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
595 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
596 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinHeight() ) | |
597 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; | |
598 | Rect adjustedRect = { adjustR.y , adjustR.x , adjustR.y + adjustR.height , adjustR.x + adjustR.width } ; | |
599 | if ( !EqualRect( &newRect , &adjustedRect ) ) | |
600 | cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; | |
f81bfef9 | 601 | } |
facd6764 SC |
602 | |
603 | result = noErr ; | |
f81bfef9 | 604 | break ; |
facd6764 | 605 | } |
e40298d5 JS |
606 | default : |
607 | break ; | |
608 | } | |
609 | return result ; | |
851b3a88 SC |
610 | } |
611 | ||
facd6764 | 612 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
613 | { |
614 | OSStatus result = eventNotHandledErr ; | |
615 | ||
616 | switch ( GetEventClass( event ) ) | |
617 | { | |
c5c9378c | 618 | case kEventClassKeyboard : |
e40298d5 | 619 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 620 | break ; |
851b3a88 | 621 | case kEventClassTextInput : |
e40298d5 | 622 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
623 | break ; |
624 | case kEventClassWindow : | |
facd6764 | 625 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; |
e40298d5 | 626 | break ; |
851b3a88 | 627 | case kEventClassMouse : |
facd6764 | 628 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; |
e40298d5 | 629 | break ; |
851b3a88 SC |
630 | default : |
631 | break ; | |
632 | } | |
633 | return result ; | |
634 | } | |
635 | ||
facd6764 | 636 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) |
851b3a88 | 637 | |
5f0b2f22 SC |
638 | // --------------------------------------------------------------------------- |
639 | // wxWindowMac utility functions | |
640 | // --------------------------------------------------------------------------- | |
641 | ||
642 | // Find an item given the Macintosh Window Reference | |
643 | ||
facd6764 SC |
644 | wxList wxWinMacWindowList(wxKEY_INTEGER); |
645 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
5f0b2f22 | 646 | { |
facd6764 | 647 | wxNode *node = wxWinMacWindowList.Find((long)inWindowRef); |
5f0b2f22 SC |
648 | if (!node) |
649 | return NULL; | |
eb22f2a6 | 650 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
651 | } |
652 | ||
facd6764 SC |
653 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; |
654 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
5f0b2f22 SC |
655 | { |
656 | // adding NULL WindowRef is (first) surely a result of an error and | |
657 | // (secondly) breaks menu command processing | |
427ff662 | 658 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 | 659 | |
facd6764 SC |
660 | if ( !wxWinMacWindowList.Find((long)inWindowRef) ) |
661 | wxWinMacWindowList.Append((long)inWindowRef, win); | |
5f0b2f22 SC |
662 | } |
663 | ||
facd6764 | 664 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; |
5f0b2f22 SC |
665 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) |
666 | { | |
facd6764 | 667 | wxWinMacWindowList.DeleteObject(win); |
5f0b2f22 SC |
668 | } |
669 | ||
670 | ||
a15eb0a5 SC |
671 | // ---------------------------------------------------------------------------- |
672 | // wxTopLevelWindowMac creation | |
673 | // ---------------------------------------------------------------------------- | |
674 | ||
245f3581 | 675 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
5f0b2f22 | 676 | |
a15eb0a5 SC |
677 | void wxTopLevelWindowMac::Init() |
678 | { | |
679 | m_iconized = | |
680 | m_maximizeOnShow = FALSE; | |
6a17ca35 | 681 | m_macWindow = NULL ; |
facd6764 SC |
682 | #if TARGET_API_MAC_OSX |
683 | m_macUsesCompositing = TRUE; | |
684 | #else | |
685 | m_macUsesCompositing = FALSE; | |
686 | #endif | |
7c091673 | 687 | m_macEventHandler = NULL ; |
a15eb0a5 SC |
688 | } |
689 | ||
118f012e SC |
690 | class wxMacDeferredWindowDeleter : public wxObject |
691 | { | |
692 | public : | |
1542ea39 RD |
693 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
694 | { | |
695 | m_macWindow = windowRef ; | |
118f012e | 696 | } |
1542ea39 RD |
697 | virtual ~wxMacDeferredWindowDeleter() |
698 | { | |
699 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
700 | } |
701 | protected : | |
702 | WindowRef m_macWindow ; | |
703 | } ; | |
704 | ||
a15eb0a5 SC |
705 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
706 | wxWindowID id, | |
707 | const wxString& title, | |
708 | const wxPoint& pos, | |
709 | const wxSize& size, | |
710 | long style, | |
711 | const wxString& name) | |
712 | { | |
713 | // init our fields | |
714 | Init(); | |
715 | ||
716 | m_windowStyle = style; | |
717 | ||
718 | SetName(name); | |
719 | ||
720 | m_windowId = id == -1 ? NewControlId() : id; | |
721 | ||
facd6764 SC |
722 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
723 | ||
a15eb0a5 SC |
724 | wxTopLevelWindows.Append(this); |
725 | ||
726 | if ( parent ) | |
727 | parent->AddChild(this); | |
728 | ||
729 | return TRUE; | |
730 | } | |
731 | ||
732 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
733 | { | |
6a17ca35 SC |
734 | if ( m_macWindow ) |
735 | { | |
736 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 737 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 738 | } |
1542ea39 | 739 | |
7c091673 SC |
740 | if ( m_macEventHandler ) |
741 | { | |
742 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
743 | m_macEventHandler = NULL ; | |
744 | } | |
851b3a88 | 745 | |
5f0b2f22 SC |
746 | wxRemoveMacWindowAssociation( this ) ; |
747 | ||
a15eb0a5 SC |
748 | if ( wxModelessWindows.Find(this) ) |
749 | wxModelessWindows.DeleteObject(this); | |
a15eb0a5 SC |
750 | } |
751 | ||
752 | ||
753 | // ---------------------------------------------------------------------------- | |
754 | // wxTopLevelWindowMac maximize/minimize | |
755 | // ---------------------------------------------------------------------------- | |
756 | ||
757 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
758 | { | |
1f90939c SC |
759 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
760 | wxMacWindowClipper clip (this); | |
b7aec135 | 761 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; |
facd6764 SC |
762 | /* |
763 | Rect r ; | |
764 | GDHandle device = NULL ; | |
765 | verify_noerr( GetWindowGreatestAreaDevice( (WindowRef) m_macWindow , kWindowContentRgn , | |
766 | &device , NULL ) ; | |
767 | verify_noerr( GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ) ; | |
b7aec135 SC |
768 | |
769 | Rect tempRect ; | |
770 | GrafPtr port ; | |
771 | GetPort( &port ) ; | |
772 | Point pt = { 0, 0 } ; | |
773 | SetPortWindowPort((WindowRef)m_macWindow) ; | |
774 | LocalToGlobal( &pt ) ; | |
775 | SetPort( port ) ; | |
776 | ||
777 | GetWindowPortBounds((WindowRef)m_macWindow, &tempRect ) ; | |
778 | SetSize( pt.h , pt.v , tempRect.right-tempRect.left , | |
779 | tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); | |
facd6764 | 780 | */ |
a15eb0a5 SC |
781 | } |
782 | ||
783 | bool wxTopLevelWindowMac::IsMaximized() const | |
784 | { | |
b7aec135 | 785 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
786 | } |
787 | ||
788 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
789 | { | |
b7aec135 SC |
790 | if ( IsWindowCollapsable((WindowRef)m_macWindow) ) |
791 | CollapseWindow((WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
792 | } |
793 | ||
794 | bool wxTopLevelWindowMac::IsIconized() const | |
795 | { | |
b7aec135 | 796 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
797 | } |
798 | ||
799 | void wxTopLevelWindowMac::Restore() | |
800 | { | |
801 | // not available on mac | |
802 | } | |
803 | ||
804 | // ---------------------------------------------------------------------------- | |
805 | // wxTopLevelWindowMac misc | |
806 | // ---------------------------------------------------------------------------- | |
807 | ||
facd6764 SC |
808 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
809 | { | |
810 | return wxPoint(0,0) ; | |
811 | } | |
812 | ||
a15eb0a5 SC |
813 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) |
814 | { | |
815 | // this sets m_icon | |
816 | wxTopLevelWindowBase::SetIcon(icon); | |
817 | } | |
5f0b2f22 | 818 | |
facd6764 SC |
819 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
820 | { | |
821 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
822 | ||
823 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
824 | { | |
825 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
826 | } | |
827 | } | |
828 | ||
949cb163 SC |
829 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
830 | { | |
831 | if ( m_macEventHandler != NULL ) | |
832 | { | |
833 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
834 | } | |
835 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
836 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); | |
837 | } | |
838 | ||
5f0b2f22 SC |
839 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
840 | const wxPoint& pos, | |
841 | const wxSize& size, | |
842 | long style, | |
1542ea39 | 843 | const wxString& name ) |
5f0b2f22 | 844 | { |
47ac4f9b | 845 | OSStatus err = noErr ; |
e40298d5 JS |
846 | SetName(name); |
847 | m_windowStyle = style; | |
848 | m_isShown = FALSE; | |
1542ea39 | 849 | |
e40298d5 | 850 | // create frame. |
1542ea39 | 851 | |
5f0b2f22 | 852 | Rect theBoundsRect; |
1542ea39 | 853 | |
facd6764 SC |
854 | int x = (int)pos.x; |
855 | int y = (int)pos.y; | |
856 | if ( y < 50 ) | |
857 | y = 50 ; | |
858 | if ( x < 20 ) | |
859 | x = 20 ; | |
1542ea39 | 860 | |
facd6764 SC |
861 | int w = WidthDefault(size.x); |
862 | int h = HeightDefault(size.y); | |
1542ea39 | 863 | |
facd6764 | 864 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 865 | |
5f0b2f22 | 866 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 867 | |
5f0b2f22 SC |
868 | WindowClass wclass = 0; |
869 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 870 | |
f5744893 | 871 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 872 | { |
1542ea39 | 873 | if ( |
f5744893 SC |
874 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
875 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
876 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 877 | ) |
5f0b2f22 | 878 | { |
f5744893 SC |
879 | wclass = kFloatingWindowClass ; |
880 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
881 | { | |
882 | attr |= kWindowSideTitlebarAttribute ; | |
883 | } | |
884 | } | |
885 | else | |
886 | { | |
887 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
888 | } |
889 | } | |
890 | else if ( HasFlag( wxCAPTION ) ) | |
891 | { | |
1542ea39 | 892 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
893 | } |
894 | else | |
895 | { | |
f5744893 | 896 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 897 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
898 | { |
899 | wclass = kDocumentWindowClass ; | |
900 | } | |
901 | else | |
902 | { | |
903 | wclass = kPlainWindowClass ; | |
904 | } | |
5f0b2f22 | 905 | } |
1542ea39 | 906 | |
47ac4f9b | 907 | if ( HasFlag( wxMINIMIZE_BOX ) ) |
5f0b2f22 | 908 | { |
5f0b2f22 SC |
909 | attr |= kWindowCollapseBoxAttribute ; |
910 | } | |
47ac4f9b SC |
911 | if ( HasFlag( wxMAXIMIZE_BOX ) ) |
912 | { | |
913 | attr |= kWindowFullZoomAttribute ; | |
914 | } | |
5f0b2f22 SC |
915 | if ( HasFlag( wxRESIZE_BORDER ) ) |
916 | { | |
917 | attr |= kWindowResizableAttribute ; | |
918 | } | |
47ac4f9b | 919 | if ( HasFlag( wxCLOSE_BOX) ) |
5f0b2f22 SC |
920 | { |
921 | attr |= kWindowCloseBoxAttribute ; | |
922 | } | |
1542ea39 | 923 | |
eb630bf1 DS |
924 | if (UMAGetSystemVersion() >= 0x1000) |
925 | { | |
facd6764 | 926 | // turn on live resizing (OS X only) |
eb630bf1 DS |
927 | attr |= kWindowLiveResizeAttribute; |
928 | } | |
929 | ||
6a7e6411 | 930 | if (HasFlag(wxSTAY_ON_TOP)) |
eb630bf1 | 931 | wclass = kUtilityWindowClass; |
6a7e6411 | 932 | |
facd6764 SC |
933 | #if TARGET_API_MAC_OSX |
934 | attr |= kWindowCompositingAttribute; | |
d66c3960 | 935 | #endif |
1f90939c | 936 | |
6a7e6411 RD |
937 | if ( HasFlag(wxFRAME_SHAPED) ) |
938 | { | |
939 | WindowDefSpec customWindowDefSpec; | |
940 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
941 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
942 | ||
47ac4f9b | 943 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
944 | attr, &theBoundsRect, |
945 | (WindowRef*) &m_macWindow); | |
946 | } | |
947 | else | |
948 | { | |
47ac4f9b | 949 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
950 | } |
951 | ||
47ac4f9b | 952 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
facd6764 SC |
953 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
954 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
955 | if ( m_macUsesCompositing ) | |
1f90939c | 956 | { |
facd6764 | 957 | ::GetRootControl( (WindowRef)m_macWindow, (ControlRef*)&m_macControl ) ; |
1f90939c SC |
958 | } |
959 | else | |
960 | { | |
facd6764 | 961 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlRef*)&m_macControl ) ; |
1f90939c | 962 | } |
73fe67bd | 963 | // the root control level handleer |
949cb163 | 964 | MacInstallEventHandler() ; |
facd6764 | 965 | |
73fe67bd | 966 | // the frame window event handler |
e40298d5 | 967 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 SC |
968 | MacInstallTopLevelWindowEventHandler() ; |
969 | ||
facd6764 | 970 | m_macFocus = NULL ; |
6a7e6411 RD |
971 | |
972 | if ( HasFlag(wxFRAME_SHAPED) ) | |
973 | { | |
974 | // default shape matches the window size | |
facd6764 | 975 | wxRegion rgn(0, 0, w, h); |
6a7e6411 RD |
976 | SetShape(rgn); |
977 | } | |
3dfafdb9 RD |
978 | |
979 | wxWindowCreateEvent event(this); | |
980 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
981 | } |
982 | ||
5d2e69e8 | 983 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 984 | { |
5d2e69e8 | 985 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
986 | } |
987 | ||
5f0b2f22 SC |
988 | // Raise the window to the top of the Z order |
989 | void wxTopLevelWindowMac::Raise() | |
990 | { | |
7f3c339c | 991 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
992 | } |
993 | ||
994 | // Lower the window to the bottom of the Z order | |
995 | void wxTopLevelWindowMac::Lower() | |
996 | { | |
76a5e5d2 | 997 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
998 | } |
999 | ||
851b3a88 | 1000 | |
245f3581 DE |
1001 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1002 | { | |
1003 | if(s_macDeactivateWindow) | |
1004 | { | |
365796b1 | 1005 | wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow); |
245f3581 DE |
1006 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1007 | } | |
1008 | } | |
1009 | ||
851b3a88 | 1010 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) |
5f0b2f22 | 1011 | { |
17f8d2a7 VZ |
1012 | // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this); |
1013 | ||
245f3581 DE |
1014 | if(s_macDeactivateWindow==this) |
1015 | s_macDeactivateWindow=NULL; | |
1016 | MacDelayedDeactivation(timestamp); | |
8ab50549 | 1017 | MacPropagateHiliteChanged() ; |
5f0b2f22 SC |
1018 | } |
1019 | ||
1020 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1021 | { | |
1022 | wxWindow::SetTitle( title ) ; | |
16a76184 | 1023 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; |
5f0b2f22 SC |
1024 | } |
1025 | ||
1026 | bool wxTopLevelWindowMac::Show(bool show) | |
1027 | { | |
facd6764 | 1028 | if ( !wxTopLevelWindowBase::Show(show) ) |
5f0b2f22 SC |
1029 | return FALSE; |
1030 | ||
1031 | if (show) | |
1542ea39 | 1032 | { |
1f90939c SC |
1033 | #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003 |
1034 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1035 | { | |
1036 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1037 | } | |
1038 | else | |
1039 | #endif | |
1040 | { | |
1041 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); | |
1042 | } | |
1043 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
facd6764 SC |
1044 | // as apps expect a size event to occur at this moment |
1045 | wxSizeEvent event( GetSize() , m_windowId); | |
1f90939c SC |
1046 | event.SetEventObject(this); |
1047 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1048 | } |
1049 | else | |
1050 | { | |
1f90939c SC |
1051 | #if wxUSE_SYSTEM_OPTIONS |
1052 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1053 | { | |
1054 | ::HideWindow((WindowRef) m_macWindow ); | |
1055 | } | |
1056 | else | |
1057 | #endif | |
1058 | { | |
1059 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); | |
1060 | } | |
5f0b2f22 SC |
1061 | } |
1062 | ||
facd6764 | 1063 | MacPropagateVisibilityChanged() ; |
5f0b2f22 | 1064 | |
facd6764 | 1065 | return TRUE ; |
5f0b2f22 SC |
1066 | } |
1067 | ||
facd6764 SC |
1068 | // we are still using coordinates of the content view, todo switch to structure bounds |
1069 | ||
5f0b2f22 SC |
1070 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1071 | { | |
facd6764 SC |
1072 | Rect bounds = { y , x , y + height , x + width } ; |
1073 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
5f0b2f22 SC |
1074 | } |
1075 | ||
facd6764 | 1076 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1077 | { |
facd6764 SC |
1078 | Rect bounds ; |
1079 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1080 | if(x) *x = bounds.left ; | |
1081 | if(y) *y = bounds.top ; | |
1082 | } | |
1083 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1084 | { | |
1085 | Rect bounds ; | |
1086 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1087 | if(width) *width = bounds.right - bounds.left ; | |
1088 | if(height) *height = bounds.bottom - bounds.top ; | |
1089 | } | |
1542ea39 | 1090 | |
facd6764 SC |
1091 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1092 | { | |
1093 | Rect bounds ; | |
1094 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1095 | if(width) *width = bounds.right - bounds.left ; | |
1096 | if(height) *height = bounds.bottom - bounds.top ; | |
1097 | } | |
1542ea39 | 1098 | |
facd6764 SC |
1099 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
1100 | { | |
1101 | #if TARGET_API_MAC_OSX | |
1102 | UInt32 attr = 0 ; | |
1103 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1104 | wxASSERT_MSG( attr & kWindowCompositingAttribute , | |
1105 | wxT("Cannot set metal appearance on a non-compositing window") ) ; | |
1106 | ||
1107 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1108 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1109 | #endif | |
1110 | } | |
1542ea39 | 1111 | |
6aab345b SC |
1112 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
1113 | { | |
1114 | #if TARGET_API_MAC_OSX | |
1115 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1116 | #else | |
1117 | return false ; | |
1118 | #endif | |
1119 | } | |
1120 | ||
facd6764 SC |
1121 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
1122 | { | |
1123 | ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ; | |
1124 | } | |
1542ea39 | 1125 | |
facd6764 SC |
1126 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
1127 | { | |
1128 | UInt32 attr = 0 ; | |
1129 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1130 | return attr ; | |
5f0b2f22 | 1131 | } |
a07c1212 | 1132 | |
facd6764 SC |
1133 | // --------------------------------------------------------------------------- |
1134 | // Shape implementation | |
1135 | // --------------------------------------------------------------------------- | |
1136 | ||
6a7e6411 | 1137 | |
1542ea39 RD |
1138 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1139 | { | |
6a7e6411 RD |
1140 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1141 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1142 | ||
1143 | // The empty region signifies that the shape should be removed from the | |
1144 | // window. | |
1145 | if ( region.IsEmpty() ) | |
1146 | { | |
1147 | wxSize sz = GetClientSize(); | |
1148 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1149 | return SetShape(rgn); | |
1150 | } | |
1151 | ||
1152 | // Make a copy of the region | |
1153 | RgnHandle shapeRegion = NewRgn(); | |
1154 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1155 | ||
1156 | // Dispose of any shape region we may already have | |
1157 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1158 | if ( oldRgn ) | |
1159 | DisposeRgn(oldRgn); | |
1160 | ||
1161 | // Save the region so we can use it later | |
1162 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1163 | ||
1164 | // Tell the window manager that the window has changed shape | |
1165 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1166 | return TRUE; | |
1167 | } | |
1168 | ||
6a7e6411 RD |
1169 | // --------------------------------------------------------------------------- |
1170 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1171 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1172 | // --------------------------------------------------------------------------- | |
1173 | ||
6a7e6411 RD |
1174 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1175 | { | |
1176 | GetWindowPortBounds(window, inRect); | |
1177 | Point pt = {inRect->left, inRect->top}; | |
1178 | SetPort((GrafPtr) GetWindowPort(window)); | |
1179 | LocalToGlobal(&pt); | |
1180 | inRect->top = pt.v; | |
1181 | inRect->left = pt.h; | |
1182 | inRect->bottom += pt.v; | |
1183 | inRect->right += pt.h; | |
1184 | } | |
1185 | ||
1186 | ||
1187 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1188 | { | |
1189 | /*------------------------------------------------------ | |
1190 | Define which options your custom window supports. | |
1191 | --------------------------------------------------------*/ | |
1192 | //just enable everything for our demo | |
1193 | *(OptionBits*)param=//kWindowCanGrow| | |
1194 | //kWindowCanZoom| | |
1195 | //kWindowCanCollapse| | |
1196 | //kWindowCanGetWindowRegion| | |
1197 | //kWindowHasTitleBar| | |
1198 | //kWindowSupportsDragHilite| | |
1199 | kWindowCanDrawInCurrentPort| | |
1200 | //kWindowCanMeasureTitle| | |
1201 | kWindowWantsDisposeAtProcessDeath| | |
1202 | kWindowSupportsSetGrowImageRegion| | |
1203 | kWindowDefSupportsColorGrafPort; | |
1204 | return 1; | |
1542ea39 | 1205 | } |
6a7e6411 RD |
1206 | |
1207 | // The content region is left as a rectangle matching the window size, this is | |
1208 | // so the origin in the paint event, and etc. still matches what the | |
1209 | // programmer expects. | |
1210 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1211 | { | |
1212 | SetEmptyRgn(rgn); | |
1213 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1214 | if (win) | |
1215 | { | |
1216 | wxRect r = win->GetRect(); | |
1217 | SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); | |
1218 | } | |
1219 | } | |
1220 | ||
1221 | // The structure region is set to the shape given to the SetShape method. | |
1222 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1223 | { | |
1224 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1225 | ||
1226 | SetEmptyRgn(rgn); | |
1227 | if (cachedRegion) | |
1228 | { | |
1229 | Rect windowRect; | |
1230 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1231 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1232 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1233 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1234 | } | |
1235 | } | |
1236 | ||
1237 | ||
1238 | ||
1239 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1240 | { | |
1241 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1242 | ||
1243 | switch(rgnRec->regionCode) | |
1244 | { | |
1245 | case kWindowStructureRgn: | |
1246 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1247 | break; | |
1248 | case kWindowContentRgn: | |
1249 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1250 | break; | |
1251 | default: | |
1252 | SetEmptyRgn(rgnRec->winRgn); | |
1253 | } //switch | |
1254 | ||
1255 | return noErr; | |
1256 | } | |
1257 | ||
1258 | ||
1259 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1260 | { | |
1261 | /*------------------------------------------------------ | |
1262 | Determine the region of the window which was hit | |
1263 | --------------------------------------------------------*/ | |
1264 | Point hitPoint; | |
1265 | static RgnHandle tempRgn=nil; | |
1266 | ||
1267 | if(!tempRgn) | |
1268 | tempRgn=NewRgn(); | |
1269 | ||
1270 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1271 | ||
1272 | //Mac OS 8.5 or later | |
1273 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1274 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1275 | return wInContent; | |
1276 | ||
1277 | return wNoHit;//no significant area was hit. | |
1278 | } | |
1279 | ||
1280 | ||
1281 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1282 | { | |
1283 | switch(message) | |
1284 | { | |
1285 | case kWindowMsgHitTest: | |
1286 | return wxShapedMacWindowHitTest(window,param); | |
1287 | ||
1288 | case kWindowMsgGetFeatures: | |
1289 | return wxShapedMacWindowGetFeatures(window,param); | |
1290 | ||
1291 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1292 | case kWindowMsgGetRegion: | |
1293 | return wxShapedMacWindowGetRegion(window,param); | |
1294 | } | |
1295 | ||
1296 | return 0; | |
1297 | } | |
1925be65 | 1298 | |
6a7e6411 | 1299 | // --------------------------------------------------------------------------- |
1925be65 | 1300 |