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