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