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