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