]>
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 | |
a01d9a25 | 964 | SetBackgroundColour(wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive))); |
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 | ||
a01d9a25 | 1066 | bool wxTopLevelWindowMac::SetBackgroundColour(const wxColour& col ) |
902725ee | 1067 | { |
a01d9a25 SC |
1068 | if ( !wxTopLevelWindowBase::SetBackgroundColour(col) && m_hasBgCol ) |
1069 | return false ; | |
1070 | ||
1071 | if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ) | |
1072 | SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ; | |
1073 | else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ) | |
1074 | SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ; | |
1075 | // TODO BETTER THEME SUPPORT | |
1076 | return true; | |
1077 | } | |
facd6764 | 1078 | |
6239ee05 SC |
1079 | void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) |
1080 | { | |
1081 | InstallWindowEventHandler(window, GetwxMacTopLevelEventHandlerUPP(), | |
1082 | GetEventTypeCount(eventList), eventList, ref, handler ); | |
1083 | } | |
1084 | ||
902725ee | 1085 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
949cb163 SC |
1086 | { |
1087 | if ( m_macEventHandler != NULL ) | |
1088 | { | |
1089 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1090 | } | |
6239ee05 | 1091 | wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this); |
949cb163 SC |
1092 | } |
1093 | ||
a979e444 DS |
1094 | void wxTopLevelWindowMac::MacCreateRealWindow( |
1095 | const wxString& title, | |
1096 | const wxPoint& pos, | |
1097 | const wxSize& size, | |
1098 | long style, | |
1099 | const wxString& name ) | |
6239ee05 SC |
1100 | { |
1101 | DoMacCreateRealWindow( NULL, title, pos, size, style, name ); | |
1102 | } | |
1103 | ||
1104 | void wxTopLevelWindowMac::DoMacCreateRealWindow( | |
0d6fba37 | 1105 | wxWindow* parent, |
6239ee05 SC |
1106 | const wxString& title, |
1107 | const wxPoint& pos, | |
1108 | const wxSize& size, | |
1109 | long style, | |
1110 | const wxString& name ) | |
5f0b2f22 | 1111 | { |
47ac4f9b | 1112 | OSStatus err = noErr ; |
e40298d5 JS |
1113 | SetName(name); |
1114 | m_windowStyle = style; | |
902725ee | 1115 | m_isShown = false; |
1542ea39 | 1116 | |
e40298d5 | 1117 | // create frame. |
facd6764 SC |
1118 | int x = (int)pos.x; |
1119 | int y = (int)pos.y; | |
902725ee | 1120 | |
52c3df99 | 1121 | Rect theBoundsRect; |
5a486641 SC |
1122 | wxRect display = wxGetClientDisplayRect() ; |
1123 | ||
1124 | if ( x == wxDefaultPosition.x ) | |
1125 | x = display.x ; | |
902725ee | 1126 | |
5a486641 SC |
1127 | if ( y == wxDefaultPosition.y ) |
1128 | y = display.y ; | |
1542ea39 | 1129 | |
facd6764 SC |
1130 | int w = WidthDefault(size.x); |
1131 | int h = HeightDefault(size.y); | |
1542ea39 | 1132 | |
facd6764 | 1133 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 1134 | |
5f0b2f22 | 1135 | // translate the window attributes in the appropriate window class and attributes |
5f0b2f22 SC |
1136 | WindowClass wclass = 0; |
1137 | WindowAttributes attr = kWindowNoAttributes ; | |
e353795e | 1138 | WindowGroupRef group = NULL ; |
0d6fba37 VZ |
1139 | bool activationScopeSet = false; |
1140 | WindowActivationScope activationScope = kWindowActivationScopeNone; | |
1542ea39 | 1141 | |
f5744893 | 1142 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 1143 | { |
1542ea39 | 1144 | if ( |
f5744893 SC |
1145 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
1146 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
1147 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 1148 | ) |
5f0b2f22 | 1149 | { |
6239ee05 SC |
1150 | if ( HasFlag( wxSTAY_ON_TOP ) ) |
1151 | wclass = kUtilityWindowClass; | |
1152 | else | |
1153 | wclass = kFloatingWindowClass ; | |
52c3df99 | 1154 | |
f5744893 | 1155 | if ( HasFlag(wxTINY_CAPTION_VERT) ) |
f5744893 | 1156 | attr |= kWindowSideTitlebarAttribute ; |
f5744893 SC |
1157 | } |
1158 | else | |
1159 | { | |
1160 | wclass = kPlainWindowClass ; | |
0d6fba37 VZ |
1161 | activationScopeSet = true; |
1162 | activationScope = kWindowActivationScopeNone; | |
5f0b2f22 SC |
1163 | } |
1164 | } | |
a0232aa5 RD |
1165 | else if ( HasFlag( wxPOPUP_WINDOW ) ) |
1166 | { | |
1167 | // TEMPORARY HACK! | |
1168 | // Until we've got a real wxPopupWindow class on wxMac make it a | |
1169 | // little easier for wxFrame to be used to emulate it and workaround | |
1170 | // the lack of wxPopupWindow. | |
1171 | if ( HasFlag( wxBORDER_NONE ) ) | |
1172 | wclass = kHelpWindowClass ; // has no border | |
1173 | else | |
1174 | wclass = kPlainWindowClass ; // has a single line border, it will have to do for now | |
1175 | //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we?? | |
89954433 | 1176 | group = GetWindowGroupOfClass( // float above other windows |
a0232aa5 RD |
1177 | kFloatingWindowClass) ; |
1178 | } | |
5f0b2f22 SC |
1179 | else if ( HasFlag( wxCAPTION ) ) |
1180 | { | |
1542ea39 | 1181 | wclass = kDocumentWindowClass ; |
22e3c5bd | 1182 | attr |= kWindowInWindowMenuAttribute ; |
5f0b2f22 | 1183 | } |
3e17bc3f RN |
1184 | else if ( HasFlag( wxFRAME_DRAWER ) ) |
1185 | { | |
1186 | wclass = kDrawerWindowClass; | |
3e17bc3f | 1187 | } |
5f0b2f22 SC |
1188 | else |
1189 | { | |
f5744893 | 1190 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 1191 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
1192 | { |
1193 | wclass = kDocumentWindowClass ; | |
1194 | } | |
6239ee05 SC |
1195 | else if ( HasFlag( wxNO_BORDER ) ) |
1196 | { | |
1197 | wclass = kSimpleWindowClass ; | |
1198 | } | |
f5744893 SC |
1199 | else |
1200 | { | |
1201 | wclass = kPlainWindowClass ; | |
1202 | } | |
5f0b2f22 | 1203 | } |
1542ea39 | 1204 | |
52c3df99 | 1205 | if ( wclass != kPlainWindowClass ) |
5f0b2f22 | 1206 | { |
52c3df99 DS |
1207 | if ( HasFlag( wxMINIMIZE_BOX ) ) |
1208 | attr |= kWindowCollapseBoxAttribute ; | |
1209 | ||
1210 | if ( HasFlag( wxMAXIMIZE_BOX ) ) | |
1211 | attr |= kWindowFullZoomAttribute ; | |
1212 | ||
1213 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
1214 | attr |= kWindowResizableAttribute ; | |
1215 | ||
1216 | if ( HasFlag( wxCLOSE_BOX) ) | |
1217 | attr |= kWindowCloseBoxAttribute ; | |
5f0b2f22 | 1218 | } |
03561a3c | 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 | |
6239ee05 SC |
1227 | if ( group == NULL && parent != NULL ) |
1228 | { | |
1229 | WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef(); | |
1230 | if( parenttlw ) | |
1231 | group = GetWindowGroupParent( GetWindowGroup( parenttlw ) ); | |
1232 | } | |
0d6fba37 | 1233 | |
f21449ae | 1234 | attr |= kWindowCompositingAttribute; |
24fcd264 SC |
1235 | #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale) |
1236 | attr |= kWindowFrameworkScaledAttribute; | |
d66c3960 | 1237 | #endif |
902725ee | 1238 | |
6a7e6411 RD |
1239 | if ( HasFlag(wxFRAME_SHAPED) ) |
1240 | { | |
1241 | WindowDefSpec customWindowDefSpec; | |
1242 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
89954433 | 1243 | customWindowDefSpec.u.defProc = |
7cd7bc23 SC |
1244 | #ifdef __LP64__ |
1245 | (WindowDefUPP) wxShapedMacWindowDef; | |
1246 | #else | |
1247 | NewWindowDefUPP(wxShapedMacWindowDef); | |
1248 | #endif | |
47ac4f9b | 1249 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
1250 | attr, &theBoundsRect, |
1251 | (WindowRef*) &m_macWindow); | |
1252 | } | |
1253 | else | |
1254 | { | |
47ac4f9b | 1255 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
1256 | } |
1257 | ||
e353795e SC |
1258 | if ( err == noErr && m_macWindow != NULL && group != NULL ) |
1259 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1260 | ||
47ac4f9b | 1261 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
f83b6761 | 1262 | |
832f330f | 1263 | // setup a separate group for each window, so that overlays can be handled easily |
0d6fba37 | 1264 | |
6239ee05 SC |
1265 | WindowGroupRef overlaygroup = NULL; |
1266 | verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup )); | |
1267 | verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow ))); | |
1268 | verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup )); | |
0d6fba37 VZ |
1269 | |
1270 | if ( activationScopeSet ) | |
1271 | { | |
1272 | verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope )); | |
1273 | } | |
89954433 | 1274 | |
a979e444 DS |
1275 | // the create commands are only for content rect, |
1276 | // so we have to set the size again as structure bounds | |
f83b6761 SC |
1277 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; |
1278 | ||
facd6764 SC |
1279 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
1280 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
1f1c8bd4 | 1281 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; |
902725ee | 1282 | |
f21449ae SC |
1283 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of |
1284 | // the content view, so we have to retrieve it explicitly | |
1285 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
1286 | m_peer->GetControlRefAddr() ) ; | |
1287 | if ( !m_peer->Ok() ) | |
789ae0cf | 1288 | { |
f21449ae SC |
1289 | // compatibility mode fallback |
1290 | GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; | |
789ae0cf | 1291 | } |
52c3df99 DS |
1292 | |
1293 | // the root control level handler | |
5ca0d812 | 1294 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; |
facd6764 | 1295 | |
9dc1d180 JS |
1296 | // Causes the inner part of the window not to be metal |
1297 | // if the style is used before window creation. | |
1298 | #if 0 // TARGET_API_MAC_OSX | |
8ec0a8fa SC |
1299 | if ( m_macUsesCompositing && m_macWindow != NULL ) |
1300 | { | |
1301 | if ( GetExtraStyle() & wxFRAME_EX_METAL ) | |
1302 | MacSetMetalAppearance( true ) ; | |
1303 | } | |
1304 | #endif | |
52c3df99 | 1305 | |
893727e5 KO |
1306 | if ( m_macWindow != NULL ) |
1307 | { | |
1308 | MacSetUnifiedAppearance( true ) ; | |
1309 | } | |
893727e5 | 1310 | |
6239ee05 SC |
1311 | HIViewRef growBoxRef = 0 ; |
1312 | err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); | |
1313 | if ( err == noErr && growBoxRef != 0 ) | |
1314 | HIGrowBoxViewSetTransparent( growBoxRef, true ) ; | |
1315 | ||
73fe67bd | 1316 | // the frame window event handler |
e40298d5 | 1317 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 | 1318 | MacInstallTopLevelWindowEventHandler() ; |
b19bf058 | 1319 | |
14c96cf2 SC |
1320 | DoSetWindowVariant( m_windowVariant ) ; |
1321 | ||
facd6764 | 1322 | m_macFocus = NULL ; |
6a7e6411 RD |
1323 | |
1324 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1325 | { | |
1326 | // default shape matches the window size | |
52c3df99 DS |
1327 | wxRegion rgn( 0, 0, w, h ); |
1328 | SetShape( rgn ); | |
6a7e6411 | 1329 | } |
3dfafdb9 RD |
1330 | |
1331 | wxWindowCreateEvent event(this); | |
1332 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1333 | } |
1334 | ||
5d2e69e8 | 1335 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 1336 | { |
5d2e69e8 | 1337 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
1338 | } |
1339 | ||
5f0b2f22 SC |
1340 | // Raise the window to the top of the Z order |
1341 | void wxTopLevelWindowMac::Raise() | |
1342 | { | |
7f3c339c | 1343 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1344 | } |
1345 | ||
1346 | // Lower the window to the bottom of the Z order | |
1347 | void wxTopLevelWindowMac::Lower() | |
1348 | { | |
76a5e5d2 | 1349 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
1350 | } |
1351 | ||
245f3581 DE |
1352 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1353 | { | |
52c3df99 | 1354 | if (s_macDeactivateWindow) |
245f3581 | 1355 | { |
f02a4ffa VZ |
1356 | wxLogTrace(TRACE_ACTIVATE, |
1357 | wxT("Doing delayed deactivation of %p"), | |
1358 | s_macDeactivateWindow); | |
52c3df99 | 1359 | |
245f3581 DE |
1360 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1361 | } | |
1362 | } | |
1363 | ||
89954433 | 1364 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) ) |
5f0b2f22 | 1365 | { |
f02a4ffa | 1366 | wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); |
17f8d2a7 | 1367 | |
52c3df99 DS |
1368 | if (s_macDeactivateWindow == this) |
1369 | s_macDeactivateWindow = NULL; | |
1370 | ||
245f3581 | 1371 | MacDelayedDeactivation(timestamp); |
5f0b2f22 SC |
1372 | } |
1373 | ||
1374 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1375 | { | |
fb5246be | 1376 | wxWindow::SetLabel( title ) ; |
16a76184 | 1377 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; |
5f0b2f22 SC |
1378 | } |
1379 | ||
d4bd6c97 | 1380 | wxString wxTopLevelWindowMac::GetTitle() const |
fb5246be WS |
1381 | { |
1382 | return wxWindow::GetLabel(); | |
1383 | } | |
1384 | ||
5f0b2f22 SC |
1385 | bool wxTopLevelWindowMac::Show(bool show) |
1386 | { | |
facd6764 | 1387 | if ( !wxTopLevelWindowBase::Show(show) ) |
902725ee | 1388 | return false; |
5f0b2f22 | 1389 | |
03561a3c | 1390 | bool plainTransition = true; |
21e77aa1 | 1391 | |
a979e444 | 1392 | #if wxUSE_SYSTEM_OPTIONS |
21e77aa1 DS |
1393 | if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) |
1394 | plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; | |
1395 | #endif | |
52c3df99 | 1396 | |
21e77aa1 DS |
1397 | if (show) |
1398 | { | |
8c8f6a4b | 1399 | if ( plainTransition ) |
1f90939c | 1400 | ::ShowWindow( (WindowRef)m_macWindow ); |
1f90939c | 1401 | else |
52c3df99 | 1402 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); |
52c3df99 | 1403 | |
1f90939c | 1404 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
52c3df99 DS |
1405 | |
1406 | // because apps expect a size event to occur at this moment | |
a979e444 | 1407 | wxSizeEvent event(GetSize() , m_windowId); |
1f90939c SC |
1408 | event.SetEventObject(this); |
1409 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1410 | } |
1411 | else | |
1412 | { | |
8c8f6a4b | 1413 | if ( plainTransition ) |
21e77aa1 | 1414 | ::HideWindow( (WindowRef)m_macWindow ); |
1f90939c | 1415 | else |
21e77aa1 | 1416 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); |
5f0b2f22 SC |
1417 | } |
1418 | ||
902725ee | 1419 | return true ; |
5f0b2f22 SC |
1420 | } |
1421 | ||
8e181eae SC |
1422 | bool wxTopLevelWindowMac::ShowWithEffect(wxShowEffect effect, |
1423 | unsigned timeout, | |
1424 | wxDirection dir) | |
1425 | { | |
1426 | // TODO factor common code | |
1427 | if ( !wxTopLevelWindowBase::Show(true) ) | |
1428 | return false; | |
1429 | ||
1430 | WindowTransitionEffect transition = 0 ; | |
1431 | switch( effect ) | |
1432 | { | |
1433 | case wxSHOW_EFFECT_ROLL : | |
1434 | case wxSHOW_EFFECT_SLIDE : | |
1435 | transition = kWindowGenieTransitionEffect; | |
1436 | break; | |
1437 | case wxSHOW_EFFECT_BLEND : | |
1438 | transition = kWindowFadeTransitionEffect; | |
1439 | break; | |
1440 | case wxSHOW_EFFECT_EXPAND : | |
1441 | default : | |
1442 | // having sheets would be fine, but this might lead to a repositioning | |
1443 | #if 0 | |
1444 | if ( GetParent() ) | |
1445 | transition = kWindowSheetTransitionEffect; | |
1446 | else | |
1447 | #endif | |
1448 | transition = kWindowZoomTransitionEffect; | |
1449 | break; | |
1450 | } | |
1451 | ||
1452 | TransitionWindowOptions options; | |
1453 | options.version = 0; | |
1454 | options.duration = timeout / 1000.0; | |
1455 | options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0; | |
1456 | options.userData = 0; | |
1457 | ||
1458 | wxSize size = wxGetDisplaySize(); | |
1459 | Rect bounds; | |
1460 | GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds ); | |
1461 | CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top ); | |
1462 | ||
1463 | if ( dir & wxRIGHT ) | |
1464 | { | |
1465 | hiBounds.origin.x = size.x; | |
1466 | hiBounds.size.width = 0; | |
1467 | } | |
1468 | if ( dir & wxUP ) | |
1469 | { | |
1470 | hiBounds.origin.y = 0; | |
1471 | hiBounds.size.height = 0; | |
1472 | } | |
1473 | if ( dir & wxDOWN ) | |
1474 | { | |
1475 | hiBounds.origin.y = size.y; | |
1476 | hiBounds.size.height = 0; | |
1477 | } | |
1478 | if ( dir & wxLEFT ) | |
1479 | { | |
1480 | hiBounds.origin.x = 0; | |
1481 | hiBounds.size.width = 0; | |
1482 | } | |
1483 | ||
1484 | ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowShowTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL , | |
1485 | false, &options ); | |
1486 | ||
1487 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1488 | ||
1489 | // because apps expect a size event to occur at this moment | |
1490 | wxSizeEvent event(GetSize() , m_windowId); | |
1491 | event.SetEventObject(this); | |
1492 | GetEventHandler()->ProcessEvent(event); | |
1493 | ||
1494 | return true; | |
1495 | } | |
1496 | ||
1497 | bool wxTopLevelWindowMac::HideWithEffect(wxShowEffect effect, | |
1498 | unsigned timeout , | |
1499 | wxDirection dir ) | |
1500 | { | |
1501 | if ( !wxTopLevelWindowBase::Show(false) ) | |
1502 | return false; | |
1503 | ||
1504 | WindowTransitionEffect transition = 0 ; | |
1505 | switch( effect ) | |
1506 | { | |
1507 | case wxSHOW_EFFECT_ROLL : | |
1508 | case wxSHOW_EFFECT_SLIDE : | |
1509 | transition = kWindowGenieTransitionEffect; | |
1510 | break; | |
1511 | case wxSHOW_EFFECT_BLEND : | |
1512 | transition = kWindowFadeTransitionEffect; | |
1513 | break; | |
1514 | case wxSHOW_EFFECT_EXPAND : | |
1515 | default: | |
1516 | #if 0 | |
1517 | if ( GetParent() ) | |
1518 | transition = kWindowSheetTransitionEffect; | |
1519 | else | |
1520 | #endif | |
1521 | transition = kWindowZoomTransitionEffect; | |
1522 | break; | |
1523 | } | |
1524 | TransitionWindowOptions options; | |
1525 | options.version = 0; | |
1526 | options.duration = timeout / 1000.0; | |
1527 | options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0; | |
1528 | options.userData = 0; | |
1529 | ||
1530 | wxSize size = wxGetDisplaySize(); | |
1531 | Rect bounds; | |
1532 | GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds ); | |
1533 | CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top ); | |
1534 | ||
1535 | if ( dir & wxRIGHT ) | |
1536 | { | |
1537 | hiBounds.origin.x = size.x; | |
1538 | hiBounds.size.width = 0; | |
1539 | } | |
1540 | if ( dir & wxUP ) | |
1541 | { | |
1542 | hiBounds.origin.y = 0; | |
1543 | hiBounds.size.height = 0; | |
1544 | } | |
1545 | if ( dir & wxDOWN ) | |
1546 | { | |
1547 | hiBounds.origin.y = size.y; | |
1548 | hiBounds.size.height = 0; | |
1549 | } | |
1550 | if ( dir & wxLEFT ) | |
1551 | { | |
1552 | hiBounds.origin.x = 0; | |
1553 | hiBounds.size.width = 0; | |
1554 | } | |
1555 | ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowHideTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL , | |
1556 | false, &options ); | |
1557 | ||
1558 | return true; | |
1559 | } | |
1560 | ||
c5985061 | 1561 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) |
902725ee | 1562 | { |
c5985061 SC |
1563 | if ( show ) |
1564 | { | |
1565 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
1566 | delete data ; | |
1567 | data = new FullScreenData() ; | |
902725ee | 1568 | |
c5985061 SC |
1569 | m_macFullScreenData = data ; |
1570 | data->m_position = GetPosition() ; | |
1571 | data->m_size = GetSize() ; | |
f3b2e2d7 | 1572 | data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ; |
902725ee | 1573 | |
c5985061 | 1574 | if ( style & wxFULLSCREEN_NOMENUBAR ) |
52c3df99 DS |
1575 | HideMenuBar() ; |
1576 | ||
c5985061 SC |
1577 | wxRect client = wxGetClientDisplayRect() ; |
1578 | ||
52c3df99 | 1579 | int left , top , right , bottom ; |
c5985061 | 1580 | int x, y, w, h ; |
902725ee | 1581 | |
c5985061 SC |
1582 | x = client.x ; |
1583 | y = client.y ; | |
1584 | w = client.width ; | |
1585 | h = client.height ; | |
902725ee | 1586 | |
c5985061 SC |
1587 | MacGetContentAreaInset( left , top , right , bottom ) ; |
1588 | ||
1589 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
1590 | { | |
1591 | y -= top ; | |
1592 | h += top ; | |
1593 | } | |
52c3df99 | 1594 | |
c5985061 SC |
1595 | if ( style & wxFULLSCREEN_NOBORDER ) |
1596 | { | |
1597 | x -= left ; | |
1598 | w += left + right ; | |
1599 | h += bottom ; | |
1600 | } | |
52c3df99 | 1601 | |
c5985061 SC |
1602 | if ( style & wxFULLSCREEN_NOTOOLBAR ) |
1603 | { | |
3c86150d SC |
1604 | // TODO |
1605 | } | |
52c3df99 | 1606 | |
3c86150d SC |
1607 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) |
1608 | { | |
1609 | // TODO | |
c5985061 | 1610 | } |
52c3df99 | 1611 | |
c5985061 | 1612 | SetSize( x , y , w, h ) ; |
172da31f | 1613 | if ( data->m_wasResizable ) |
f3b2e2d7 | 1614 | MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ; |
c5985061 SC |
1615 | } |
1616 | else | |
1617 | { | |
1618 | ShowMenuBar() ; | |
1619 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
172da31f | 1620 | if ( data->m_wasResizable ) |
f3b2e2d7 | 1621 | MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ; |
c5985061 SC |
1622 | SetPosition( data->m_position ) ; |
1623 | SetSize( data->m_size ) ; | |
52c3df99 | 1624 | |
c5985061 SC |
1625 | delete data ; |
1626 | m_macFullScreenData = NULL ; | |
1627 | } | |
52c3df99 | 1628 | |
902725ee | 1629 | return false; |
c5985061 SC |
1630 | } |
1631 | ||
902725ee WS |
1632 | bool wxTopLevelWindowMac::IsFullScreen() const |
1633 | { | |
1634 | return m_macFullScreenData != NULL ; | |
c5985061 SC |
1635 | } |
1636 | ||
50f3c41d | 1637 | |
07880314 | 1638 | bool wxTopLevelWindowMac::SetTransparent(wxByte alpha) |
50f3c41d | 1639 | { |
24fcd264 | 1640 | OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, float(alpha)/255.0); |
50f3c41d RD |
1641 | return result == noErr; |
1642 | } | |
1643 | ||
1644 | ||
07880314 | 1645 | bool wxTopLevelWindowMac::CanSetTransparent() |
50f3c41d RD |
1646 | { |
1647 | return true; | |
1648 | } | |
1649 | ||
1650 | ||
30c23e74 | 1651 | void wxTopLevelWindowMac::SetExtraStyle(long exStyle) |
8ec0a8fa SC |
1652 | { |
1653 | if ( GetExtraStyle() == exStyle ) | |
1654 | return ; | |
30c23e74 | 1655 | |
8ec0a8fa | 1656 | wxTopLevelWindowBase::SetExtraStyle( exStyle ) ; |
52c3df99 | 1657 | |
f21449ae | 1658 | if ( m_macWindow != NULL ) |
8ec0a8fa SC |
1659 | { |
1660 | bool metal = GetExtraStyle() & wxFRAME_EX_METAL ; | |
893727e5 | 1661 | |
8ec0a8fa | 1662 | if ( MacGetMetalAppearance() != metal ) |
893727e5 KO |
1663 | { |
1664 | if ( MacGetUnifiedAppearance() ) | |
1665 | MacSetUnifiedAppearance( !metal ) ; | |
89954433 | 1666 | |
8ec0a8fa | 1667 | MacSetMetalAppearance( metal ) ; |
893727e5 | 1668 | } |
8ec0a8fa | 1669 | } |
8ec0a8fa SC |
1670 | } |
1671 | ||
4488a1d3 VZ |
1672 | bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style) |
1673 | { | |
1674 | if ( !wxTopLevelWindowBase::SetBackgroundStyle(style) ) | |
1675 | return false ; | |
1676 | ||
1677 | WindowRef windowRef = HIViewGetWindow( (HIViewRef)GetHandle() ); | |
1678 | ||
1679 | if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
1680 | { | |
1681 | OSStatus err = HIWindowChangeFeatures( windowRef, 0, kWindowIsOpaque ); | |
1682 | verify_noerr( err ); | |
1683 | err = ReshapeCustomWindow( windowRef ); | |
1684 | verify_noerr( err ); | |
1685 | } | |
1686 | ||
1687 | return true ; | |
1688 | } | |
1689 | ||
30c23e74 | 1690 | // TODO: switch to structure bounds - |
21e77aa1 | 1691 | // we are still using coordinates of the content view |
21e77aa1 | 1692 | // |
29281095 SC |
1693 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1694 | { | |
21e77aa1 DS |
1695 | Rect content, structure ; |
1696 | ||
29281095 SC |
1697 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; |
1698 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1699 | ||
1700 | left = content.left - structure.left ; | |
1701 | top = content.top - structure.top ; | |
1702 | right = structure.right - content.right ; | |
1703 | bottom = structure.bottom - content.bottom ; | |
1704 | } | |
1705 | ||
5f0b2f22 SC |
1706 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1707 | { | |
c9698388 | 1708 | m_cachedClippedRectValid = false ; |
facd6764 SC |
1709 | Rect bounds = { y , x , y + height , x + width } ; |
1710 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
4817190d | 1711 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
5f0b2f22 SC |
1712 | } |
1713 | ||
facd6764 | 1714 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1715 | { |
facd6764 | 1716 | Rect bounds ; |
52c3df99 | 1717 | |
facd6764 | 1718 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; |
52c3df99 DS |
1719 | |
1720 | if (x) | |
1721 | *x = bounds.left ; | |
1722 | if (y) | |
1723 | *y = bounds.top ; | |
facd6764 | 1724 | } |
52c3df99 | 1725 | |
facd6764 SC |
1726 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const |
1727 | { | |
1728 | Rect bounds ; | |
52c3df99 | 1729 | |
facd6764 | 1730 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; |
52c3df99 DS |
1731 | |
1732 | if (width) | |
1733 | *width = bounds.right - bounds.left ; | |
1734 | if (height) | |
1735 | *height = bounds.bottom - bounds.top ; | |
facd6764 | 1736 | } |
1542ea39 | 1737 | |
facd6764 SC |
1738 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1739 | { | |
1740 | Rect bounds ; | |
52c3df99 | 1741 | |
facd6764 | 1742 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; |
52c3df99 DS |
1743 | |
1744 | if (width) | |
1745 | *width = bounds.right - bounds.left ; | |
1746 | if (height) | |
1747 | *height = bounds.bottom - bounds.top ; | |
facd6764 | 1748 | } |
1542ea39 | 1749 | |
6239ee05 SC |
1750 | void wxTopLevelWindowMac::DoCentre(int dir) |
1751 | { | |
1752 | if ( m_macWindow != 0 ) | |
1753 | wxTopLevelWindowBase::DoCentre(dir); | |
1754 | } | |
1755 | ||
902725ee | 1756 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
facd6764 | 1757 | { |
893727e5 KO |
1758 | if ( MacGetUnifiedAppearance() ) |
1759 | MacSetUnifiedAppearance( false ) ; | |
89954433 | 1760 | |
902725ee | 1761 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , |
facd6764 | 1762 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; |
facd6764 | 1763 | } |
1542ea39 | 1764 | |
902725ee | 1765 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
6aab345b | 1766 | { |
6aab345b | 1767 | return MacGetWindowAttributes() & kWindowMetalAttribute ; |
6aab345b SC |
1768 | } |
1769 | ||
893727e5 KO |
1770 | void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set ) |
1771 | { | |
e1673e52 SC |
1772 | if ( MacGetMetalAppearance() ) |
1773 | MacSetMetalAppearance( false ) ; | |
1774 | ||
1775 | MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes , | |
1776 | set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ; | |
1777 | ||
1778 | // For some reason, Tiger uses white as the background color for this appearance, | |
1779 | // while most apps using it use the typical striped background. Restore that behavior | |
1780 | // for wx. | |
1781 | // TODO: Determine if we need this on Leopard as well. (should be harmless either way, | |
1782 | // though) | |
1783 | SetBackgroundColour( wxSYS_COLOUR_WINDOW ) ; | |
893727e5 KO |
1784 | } |
1785 | ||
1786 | bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const | |
1787 | { | |
e1673e52 | 1788 | return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ; |
893727e5 KO |
1789 | } |
1790 | ||
902725ee | 1791 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
facd6764 | 1792 | { |
52c3df99 | 1793 | ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ; |
facd6764 | 1794 | } |
1542ea39 | 1795 | |
902725ee | 1796 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
facd6764 SC |
1797 | { |
1798 | UInt32 attr = 0 ; | |
52c3df99 DS |
1799 | GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ; |
1800 | ||
facd6764 | 1801 | return attr ; |
5f0b2f22 | 1802 | } |
a07c1212 | 1803 | |
902725ee | 1804 | void wxTopLevelWindowMac::MacPerformUpdates() |
92346151 | 1805 | { |
f21449ae SC |
1806 | // for composited windows this also triggers a redraw of all |
1807 | // invalid views in the window | |
80f3f3be | 1808 | HIWindowFlush((WindowRef) m_macWindow) ; |
92346151 SC |
1809 | } |
1810 | ||
3feeb1e1 SC |
1811 | // Attracts the users attention to this window if the application is |
1812 | // inactive (should be called when a background event occurs) | |
1813 | ||
1814 | static pascal void wxMacNMResponse( NMRecPtr ptr ) | |
1815 | { | |
1816 | NMRemove( ptr ) ; | |
a979e444 | 1817 | DisposePtr( (Ptr)ptr ) ; |
3feeb1e1 SC |
1818 | } |
1819 | ||
89954433 | 1820 | void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags)) |
3feeb1e1 SC |
1821 | { |
1822 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
52c3df99 DS |
1823 | static wxMacNMUPP nmupp( wxMacNMResponse ); |
1824 | ||
3feeb1e1 SC |
1825 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; |
1826 | notificationRequest->qType = nmType ; | |
1827 | notificationRequest->nmMark = 1 ; | |
1828 | notificationRequest->nmIcon = 0 ; | |
1829 | notificationRequest->nmSound = 0 ; | |
1830 | notificationRequest->nmStr = NULL ; | |
1831 | notificationRequest->nmResp = nmupp ; | |
52c3df99 | 1832 | |
3feeb1e1 SC |
1833 | verify_noerr( NMInstall( notificationRequest ) ) ; |
1834 | } | |
1835 | ||
facd6764 SC |
1836 | // --------------------------------------------------------------------------- |
1837 | // Shape implementation | |
1838 | // --------------------------------------------------------------------------- | |
1839 | ||
6a7e6411 | 1840 | |
1542ea39 RD |
1841 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1842 | { | |
902725ee | 1843 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, |
6a7e6411 RD |
1844 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); |
1845 | ||
a979e444 DS |
1846 | // The empty region signifies that the shape |
1847 | // should be removed from the window. | |
6a7e6411 RD |
1848 | if ( region.IsEmpty() ) |
1849 | { | |
1850 | wxSize sz = GetClientSize(); | |
1851 | wxRegion rgn(0, 0, sz.x, sz.y); | |
3c393c0a SC |
1852 | if ( rgn.IsEmpty() ) |
1853 | return false ; | |
1854 | else | |
1855 | return SetShape(rgn); | |
6a7e6411 RD |
1856 | } |
1857 | ||
1858 | // Make a copy of the region | |
1859 | RgnHandle shapeRegion = NewRgn(); | |
1860 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1861 | ||
1862 | // Dispose of any shape region we may already have | |
1863 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1864 | if ( oldRgn ) | |
1865 | DisposeRgn(oldRgn); | |
1866 | ||
1867 | // Save the region so we can use it later | |
7cd7bc23 | 1868 | SetWRefCon((WindowRef)MacGetWindowRef(), (URefCon)shapeRegion); |
6a7e6411 | 1869 | |
52c3df99 | 1870 | // inform the window manager that the window has changed shape |
6a7e6411 | 1871 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); |
52c3df99 | 1872 | |
902725ee | 1873 | return true; |
6a7e6411 RD |
1874 | } |
1875 | ||
6a7e6411 RD |
1876 | // --------------------------------------------------------------------------- |
1877 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1878 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1879 | // --------------------------------------------------------------------------- | |
1880 | ||
6a7e6411 RD |
1881 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1882 | { | |
1883 | GetWindowPortBounds(window, inRect); | |
7cd7bc23 SC |
1884 | Point pt = { inRect->top ,inRect->left }; |
1885 | wxMacLocalToGlobal( window, &pt ) ; | |
1886 | inRect->bottom += pt.v - inRect->top; | |
1887 | inRect->right += pt.h - inRect->left; | |
6a7e6411 RD |
1888 | inRect->top = pt.v; |
1889 | inRect->left = pt.h; | |
6a7e6411 RD |
1890 | } |
1891 | ||
89954433 | 1892 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param) |
6a7e6411 RD |
1893 | { |
1894 | /*------------------------------------------------------ | |
1895 | Define which options your custom window supports. | |
1896 | --------------------------------------------------------*/ | |
1897 | //just enable everything for our demo | |
52c3df99 DS |
1898 | *(OptionBits*)param = |
1899 | //kWindowCanGrow | | |
1900 | //kWindowCanZoom | | |
1901 | //kWindowCanCollapse | | |
1902 | //kWindowCanGetWindowRegion | | |
1903 | //kWindowHasTitleBar | | |
1904 | //kWindowSupportsDragHilite | | |
1905 | kWindowCanDrawInCurrentPort | | |
1906 | //kWindowCanMeasureTitle | | |
1907 | kWindowWantsDisposeAtProcessDeath | | |
1908 | kWindowSupportsGetGrowImageRegion | | |
1909 | kWindowDefSupportsColorGrafPort; | |
1910 | ||
6a7e6411 | 1911 | return 1; |
1542ea39 | 1912 | } |
6a7e6411 RD |
1913 | |
1914 | // The content region is left as a rectangle matching the window size, this is | |
1915 | // so the origin in the paint event, and etc. still matches what the | |
1916 | // programmer expects. | |
1917 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1918 | { | |
1919 | SetEmptyRgn(rgn); | |
1920 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1921 | if (win) | |
1922 | { | |
b19bf058 | 1923 | Rect r ; |
52c3df99 | 1924 | wxShapedMacWindowGetPos( window, &r ) ; |
b19bf058 | 1925 | RectRgn( rgn , &r ) ; |
6a7e6411 RD |
1926 | } |
1927 | } | |
1928 | ||
1929 | // The structure region is set to the shape given to the SetShape method. | |
1930 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1931 | { | |
1932 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1933 | ||
1934 | SetEmptyRgn(rgn); | |
1935 | if (cachedRegion) | |
1936 | { | |
1937 | Rect windowRect; | |
902725ee WS |
1938 | wxShapedMacWindowGetPos(window, &windowRect); // how big is the window |
1939 | CopyRgn(cachedRegion, rgn); // make a copy of our cached region | |
6a7e6411 | 1940 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window |
902725ee | 1941 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size |
6a7e6411 RD |
1942 | } |
1943 | } | |
1944 | ||
6a7e6411 RD |
1945 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) |
1946 | { | |
52c3df99 DS |
1947 | GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param; |
1948 | ||
1949 | if (rgnRec == NULL) | |
1950 | return paramErr; | |
6a7e6411 | 1951 | |
52c3df99 | 1952 | switch (rgnRec->regionCode) |
6a7e6411 RD |
1953 | { |
1954 | case kWindowStructureRgn: | |
1955 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1956 | break; | |
52c3df99 | 1957 | |
6a7e6411 RD |
1958 | case kWindowContentRgn: |
1959 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1960 | break; | |
52c3df99 | 1961 | |
6a7e6411 RD |
1962 | default: |
1963 | SetEmptyRgn(rgnRec->winRgn); | |
52c3df99 DS |
1964 | break; |
1965 | } | |
6a7e6411 RD |
1966 | |
1967 | return noErr; | |
1968 | } | |
1969 | ||
52c3df99 DS |
1970 | // Determine the region of the window which was hit |
1971 | // | |
1972 | static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param) | |
6a7e6411 | 1973 | { |
6a7e6411 | 1974 | Point hitPoint; |
52c3df99 | 1975 | static RgnHandle tempRgn = NULL; |
6a7e6411 | 1976 | |
52c3df99 DS |
1977 | if (tempRgn == NULL) |
1978 | tempRgn = NewRgn(); | |
6a7e6411 | 1979 | |
52c3df99 DS |
1980 | // get the point clicked |
1981 | SetPt( &hitPoint, LoWord(param), HiWord(param) ); | |
6a7e6411 | 1982 | |
52c3df99 | 1983 | // Mac OS 8.5 or later |
6a7e6411 | 1984 | wxShapedMacWindowStructureRegion(window, tempRgn); |
52c3df99 | 1985 | if (PtInRgn( hitPoint, tempRgn )) //in window content region? |
6a7e6411 RD |
1986 | return wInContent; |
1987 | ||
52c3df99 DS |
1988 | // no significant area was hit |
1989 | return wNoHit; | |
6a7e6411 RD |
1990 | } |
1991 | ||
89954433 | 1992 | static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param) |
6a7e6411 | 1993 | { |
52c3df99 | 1994 | switch (message) |
6a7e6411 RD |
1995 | { |
1996 | case kWindowMsgHitTest: | |
52c3df99 | 1997 | return wxShapedMacWindowHitTest(window, param); |
6a7e6411 RD |
1998 | |
1999 | case kWindowMsgGetFeatures: | |
52c3df99 | 2000 | return wxShapedMacWindowGetFeatures(window, param); |
6a7e6411 RD |
2001 | |
2002 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
2003 | case kWindowMsgGetRegion: | |
52c3df99 DS |
2004 | return wxShapedMacWindowGetRegion(window, param); |
2005 | ||
2006 | default: | |
2007 | break; | |
6a7e6411 RD |
2008 | } |
2009 | ||
2010 | return 0; | |
2011 | } |