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