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