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