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