]>
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 ) ; | |
937013e0 | 214 | focus->HandleWindowEvent( event ) ; |
e40298d5 | 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 ) ; | |
937013e0 | 220 | focus->HandleWindowEvent( event ) ; |
e40298d5 | 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 ) ; | |
937013e0 | 226 | focus->HandleWindowEvent( event ) ; |
e40298d5 | 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 ) ; | |
937013e0 | 232 | focus->HandleWindowEvent( event ) ; |
b7aec135 | 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 | ||
3c393c0a SC |
393 | #define NEW_CAPTURE_HANDLING 1 |
394 | ||
89954433 VZ |
395 | pascal OSStatus |
396 | wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), | |
397 | EventRef event, | |
398 | void *data) | |
facd6764 | 399 | { |
789ae0cf | 400 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
902725ee | 401 | |
facd6764 SC |
402 | OSStatus result = eventNotHandledErr ; |
403 | ||
404 | wxMacCarbonEvent cEvent( event ) ; | |
902725ee | 405 | |
facd6764 SC |
406 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; |
407 | Point windowMouseLocation = screenMouseLocation ; | |
408 | ||
30c23e74 | 409 | WindowRef window = NULL; |
facd6764 SC |
410 | short windowPart = ::FindWindow(screenMouseLocation, &window); |
411 | ||
412 | wxWindow* currentMouseWindow = NULL ; | |
d88ffaaa | 413 | ControlRef control = NULL ; |
902725ee | 414 | |
3c393c0a SC |
415 | #if NEW_CAPTURE_HANDLING |
416 | if ( wxApp::s_captureWindow ) | |
417 | { | |
418 | window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ; | |
8fc754bf | 419 | windowPart = inContent ; |
3c393c0a SC |
420 | } |
421 | #endif | |
fb5246be | 422 | |
facd6764 SC |
423 | if ( window ) |
424 | { | |
7cd7bc23 | 425 | wxMacGlobalToLocal( window, &windowMouseLocation ) ; |
facd6764 | 426 | |
3c393c0a SC |
427 | if ( wxApp::s_captureWindow |
428 | #if !NEW_CAPTURE_HANDLING | |
429 | && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent | |
430 | #endif | |
431 | ) | |
facd6764 | 432 | { |
2a1f999f | 433 | currentMouseWindow = wxApp::s_captureWindow ; |
facd6764 SC |
434 | } |
435 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
436 | { | |
437 | ControlPartCode part ; | |
6239ee05 | 438 | control = FindControlUnderMouse( windowMouseLocation , window , &part ) ; |
d88ffaaa | 439 | // if there is no control below the mouse position, send the event to the toplevel window itself |
b19bf058 | 440 | if ( control == 0 ) |
a979e444 | 441 | { |
b19bf058 | 442 | currentMouseWindow = (wxWindow*) data ; |
a979e444 | 443 | } |
b19bf058 | 444 | else |
b16f4bfa | 445 | { |
6239ee05 SC |
446 | currentMouseWindow = (wxWindow*) wxFindControlFromMacControl( control ) ; |
447 | #ifndef __WXUNIVERSAL__ | |
8198ae50 | 448 | if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved ) |
b16f4bfa | 449 | { |
179e085f | 450 | #if wxUSE_TOOLBAR |
902725ee WS |
451 | // for wxToolBar to function we have to send certaint events to it |
452 | // instead of its children (wxToolBarTools) | |
b16f4bfa SC |
453 | ControlRef parent ; |
454 | GetSuperControl(control, &parent ); | |
6239ee05 | 455 | wxWindow *wxParent = (wxWindow*) wxFindControlFromMacControl( parent ) ; |
b16f4bfa SC |
456 | if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) ) |
457 | currentMouseWindow = wxParent ; | |
179e085f | 458 | #endif |
b16f4bfa | 459 | } |
6239ee05 | 460 | #endif |
b16f4bfa | 461 | } |
f0756835 VZ |
462 | |
463 | // disabled windows must not get any input messages | |
464 | if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() ) | |
465 | currentMouseWindow = NULL; | |
902725ee | 466 | } |
facd6764 | 467 | } |
902725ee | 468 | |
facd6764 SC |
469 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); |
470 | SetupMouseEvent( wxevent , cEvent ) ; | |
471 | ||
472 | // handle all enter / leave events | |
902725ee | 473 | |
facd6764 SC |
474 | if ( currentMouseWindow != g_MacLastWindow ) |
475 | { | |
476 | if ( g_MacLastWindow ) | |
477 | { | |
478 | wxMouseEvent eventleave(wxevent); | |
479 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
480 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
481 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
d4bd6c97 | 482 | wxevent.SetId( g_MacLastWindow->GetId() ) ; |
a979e444 | 483 | |
facd6764 SC |
484 | #if wxUSE_TOOLTIPS |
485 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
a979e444 DS |
486 | #endif |
487 | ||
937013e0 | 488 | g_MacLastWindow->HandleWindowEvent(eventleave); |
facd6764 | 489 | } |
52c3df99 | 490 | |
facd6764 SC |
491 | if ( currentMouseWindow ) |
492 | { | |
493 | wxMouseEvent evententer(wxevent); | |
494 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
495 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
496 | evententer.SetEventObject( currentMouseWindow ) ; | |
d4bd6c97 | 497 | wxevent.SetId( currentMouseWindow->GetId() ) ; |
a979e444 | 498 | |
facd6764 | 499 | #if wxUSE_TOOLTIPS |
a979e444 DS |
500 | wxToolTip::RelayEvent( currentMouseWindow , evententer ); |
501 | #endif | |
502 | ||
937013e0 | 503 | currentMouseWindow->HandleWindowEvent(evententer); |
facd6764 | 504 | } |
52c3df99 | 505 | |
facd6764 SC |
506 | g_MacLastWindow = currentMouseWindow ; |
507 | } | |
902725ee | 508 | |
facd6764 SC |
509 | if ( windowPart == inMenuBar ) |
510 | { | |
511 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
512 | if ( cEvent.GetKind() == kEventMouseDown ) | |
513 | { | |
514 | ::MenuSelect( screenMouseLocation ) ; | |
6239ee05 | 515 | ::HiliteMenu(0); |
facd6764 SC |
516 | result = noErr ; |
517 | } | |
52c3df99 | 518 | } |
facd6764 SC |
519 | else if ( currentMouseWindow ) |
520 | { | |
e10e9469 | 521 | wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent(); |
62ade180 RR |
522 | |
523 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
902725ee | 524 | |
facd6764 | 525 | wxevent.SetEventObject( currentMouseWindow ) ; |
d4bd6c97 | 526 | wxevent.SetId( currentMouseWindow->GetId() ) ; |
facd6764 | 527 | |
facd6764 | 528 | // make tooltips current |
902725ee | 529 | |
a979e444 | 530 | #if wxUSE_TOOLTIPS |
f124c908 | 531 | if ( wxevent.GetEventType() == wxEVT_MOTION ) |
a979e444 DS |
532 | wxToolTip::RelayEvent( currentMouseWindow , wxevent ); |
533 | #endif | |
534 | ||
937013e0 | 535 | if ( currentMouseWindow->HandleWindowEvent(wxevent) ) |
62ade180 | 536 | { |
902725ee | 537 | if ((currentMouseWindowParent != NULL) && |
62ade180 RR |
538 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) |
539 | currentMouseWindow = NULL; | |
902725ee | 540 | |
facd6764 | 541 | result = noErr; |
62ade180 | 542 | } |
30e0b1c9 SC |
543 | else |
544 | { | |
f90387b4 VZ |
545 | // if the user code did _not_ handle the event, then perform the |
546 | // default processing | |
547 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) | |
548 | { | |
549 | // ... that is set focus to this window | |
ad02525d | 550 | if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow) |
f90387b4 VZ |
551 | currentMouseWindow->SetFocus(); |
552 | } | |
30e0b1c9 | 553 | } |
52c3df99 | 554 | |
2a1f999f | 555 | if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow ) |
facd6764 | 556 | { |
2a1f999f | 557 | wxApp::s_captureWindow = NULL ; |
facd6764 SC |
558 | // update cursor ? |
559 | } | |
6d63e2fc SC |
560 | |
561 | // update cursor | |
902725ee | 562 | |
6d63e2fc SC |
563 | wxWindow* cursorTarget = currentMouseWindow ; |
564 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
565 | ||
ddcbe732 JS |
566 | extern wxCursor gGlobalCursor; |
567 | ||
568 | if (!gGlobalCursor.IsOk()) | |
6d63e2fc | 569 | { |
ddcbe732 JS |
570 | while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) |
571 | { | |
572 | cursorTarget = cursorTarget->GetParent() ; | |
573 | if ( cursorTarget ) | |
574 | cursorPoint += cursorTarget->GetPosition(); | |
575 | } | |
6d63e2fc SC |
576 | } |
577 | ||
f124c908 VZ |
578 | } |
579 | else // currentMouseWindow == NULL | |
d88ffaaa SC |
580 | { |
581 | // don't mess with controls we don't know about | |
582 | // for some reason returning eventNotHandledErr does not lead to the correct behaviour | |
583 | // so we try sending them the correct control directly | |
e4b7e0b4 | 584 | if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) |
d88ffaaa SC |
585 | { |
586 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
587 | Point clickLocation = windowMouseLocation ; | |
e1673e52 | 588 | |
f21449ae SC |
589 | HIPoint hiPoint ; |
590 | hiPoint.x = clickLocation.h ; | |
591 | hiPoint.y = clickLocation.v ; | |
592 | HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; | |
593 | clickLocation.h = (int)hiPoint.x ; | |
594 | clickLocation.v = (int)hiPoint.y ; | |
52c3df99 DS |
595 | |
596 | HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ; | |
d88ffaaa SC |
597 | result = noErr ; |
598 | } | |
599 | } | |
a979e444 | 600 | |
facd6764 | 601 | return result ; |
851b3a88 | 602 | } |
facd6764 | 603 | |
89954433 VZ |
604 | static pascal OSStatus |
605 | wxMacTopLevelWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), | |
606 | EventRef event, | |
607 | void *data) | |
851b3a88 SC |
608 | { |
609 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 610 | |
facd6764 | 611 | wxMacCarbonEvent cEvent( event ) ; |
902725ee | 612 | |
facd6764 | 613 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; |
e40298d5 | 614 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
1542ea39 | 615 | |
52c3df99 | 616 | switch ( GetEventKind( event ) ) |
e40298d5 | 617 | { |
e40298d5 | 618 | case kEventWindowActivated : |
facd6764 SC |
619 | { |
620 | toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; | |
facd6764 SC |
621 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); |
622 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
623 | wxevent.SetEventObject(toplevelWindow); | |
937013e0 | 624 | toplevelWindow->HandleWindowEvent(wxevent); |
73fe67bd | 625 | // we still sending an eventNotHandledErr in order to allow for default processing |
facd6764 | 626 | } |
52c3df99 DS |
627 | break ; |
628 | ||
e40298d5 | 629 | case kEventWindowDeactivated : |
facd6764 SC |
630 | { |
631 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
632 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
633 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
634 | wxevent.SetEventObject(toplevelWindow); | |
937013e0 | 635 | toplevelWindow->HandleWindowEvent(wxevent); |
73fe67bd | 636 | // we still sending an eventNotHandledErr in order to allow for default processing |
facd6764 | 637 | } |
52c3df99 DS |
638 | break ; |
639 | ||
902725ee | 640 | case kEventWindowShown : |
902725ee WS |
641 | toplevelWindow->Refresh() ; |
642 | result = noErr ; | |
643 | break ; | |
52c3df99 | 644 | |
e40298d5 | 645 | case kEventWindowClose : |
52c3df99 | 646 | toplevelWindow->Close() ; |
e40298d5 JS |
647 | result = noErr ; |
648 | break ; | |
52c3df99 | 649 | |
e40298d5 | 650 | case kEventWindowBoundsChanged : |
facd6764 | 651 | { |
52c3df99 | 652 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes, typeUInt32) ; |
facd6764 SC |
653 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; |
654 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
655 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
e40298d5 | 656 | { |
6239ee05 | 657 | #ifndef __WXUNIVERSAL__ |
facd6764 SC |
658 | // according to the other ports we handle this within the OS level |
659 | // resize event, not within a wxSizeEvent | |
660 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
661 | if ( frame ) | |
662 | { | |
6f02a879 | 663 | frame->PositionBars(); |
facd6764 | 664 | } |
6239ee05 | 665 | #endif |
facd6764 SC |
666 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; |
667 | event.SetEventObject( toplevelWindow ) ; | |
851b3a88 | 668 | |
937013e0 | 669 | toplevelWindow->HandleWindowEvent(event) ; |
5e533062 | 670 | toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
e40298d5 | 671 | } |
52c3df99 | 672 | |
facd6764 SC |
673 | if ( attributes & kWindowBoundsChangeOriginChanged ) |
674 | { | |
675 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
676 | event.SetEventObject( toplevelWindow ) ; | |
937013e0 | 677 | toplevelWindow->HandleWindowEvent(event) ; |
facd6764 | 678 | } |
52c3df99 | 679 | |
facd6764 | 680 | result = noErr ; |
facd6764 | 681 | } |
52c3df99 DS |
682 | break ; |
683 | ||
f81bfef9 | 684 | case kEventWindowBoundsChanging : |
facd6764 SC |
685 | { |
686 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
687 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
83901ec2 | 688 | |
facd6764 SC |
689 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) |
690 | { | |
29281095 SC |
691 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates |
692 | int left , top , right , bottom ; | |
693 | toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ; | |
52c3df99 DS |
694 | |
695 | wxRect r( | |
696 | newRect.left - left, | |
697 | newRect.top - top, | |
698 | newRect.right - newRect.left + left + right, | |
699 | newRect.bottom - newRect.top + top + bottom ) ; | |
700 | ||
facd6764 SC |
701 | // this is a EVT_SIZING not a EVT_SIZE type ! |
702 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
703 | wxevent.SetEventObject( toplevelWindow ) ; | |
704 | wxRect adjustR = r ; | |
937013e0 | 705 | if ( toplevelWindow->HandleWindowEvent(wxevent) ) |
facd6764 | 706 | adjustR = wxevent.GetRect() ; |
29281095 | 707 | |
facd6764 SC |
708 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) |
709 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
2c25bd55 | 710 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) |
facd6764 SC |
711 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; |
712 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
713 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
2c25bd55 | 714 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) |
facd6764 | 715 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; |
4a5f2351 | 716 | const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; |
facd6764 | 717 | if ( !EqualRect( &newRect , &adjustedRect ) ) |
1f919f38 | 718 | cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ; |
4817190d | 719 | toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
f81bfef9 | 720 | } |
facd6764 | 721 | |
902725ee | 722 | result = noErr ; |
facd6764 | 723 | } |
52c3df99 DS |
724 | break ; |
725 | ||
4488a1d3 VZ |
726 | case kEventWindowGetRegion : |
727 | { | |
728 | if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
729 | { | |
730 | WindowRegionCode windowRegionCode ; | |
731 | ||
732 | // Fetch the region code that is being queried | |
733 | GetEventParameter( event, | |
734 | kEventParamWindowRegionCode, | |
735 | typeWindowRegionCode, NULL, | |
736 | sizeof windowRegionCode, NULL, | |
737 | &windowRegionCode ) ; | |
738 | ||
739 | // If it is the opaque region code then set the | |
740 | // region to empty and return noErr to stop event | |
741 | // propagation | |
742 | if ( windowRegionCode == kWindowOpaqueRgn ) { | |
743 | RgnHandle region; | |
744 | GetEventParameter( event, | |
745 | kEventParamRgnHandle, | |
746 | typeQDRgnHandle, NULL, | |
747 | sizeof region, NULL, | |
748 | ®ion) ; | |
749 | SetEmptyRgn(region) ; | |
750 | result = noErr ; | |
751 | } | |
752 | } | |
753 | } | |
754 | break ; | |
755 | ||
e40298d5 JS |
756 | default : |
757 | break ; | |
758 | } | |
52c3df99 | 759 | |
e40298d5 | 760 | return result ; |
851b3a88 SC |
761 | } |
762 | ||
ffc75ee4 SC |
763 | // mix this in from window.cpp |
764 | pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; | |
765 | ||
facd6764 | 766 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
767 | { |
768 | OSStatus result = eventNotHandledErr ; | |
769 | ||
770 | switch ( GetEventClass( event ) ) | |
771 | { | |
ffc75ee4 SC |
772 | case kEventClassTextInput : |
773 | result = wxMacUnicodeTextEventHandler( handler, event , data ) ; | |
774 | break ; | |
775 | ||
c5c9378c | 776 | case kEventClassKeyboard : |
e40298d5 | 777 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 778 | break ; |
52c3df99 | 779 | |
851b3a88 | 780 | case kEventClassWindow : |
facd6764 | 781 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; |
e40298d5 | 782 | break ; |
52c3df99 | 783 | |
851b3a88 | 784 | case kEventClassMouse : |
facd6764 | 785 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; |
e40298d5 | 786 | break ; |
52c3df99 | 787 | |
851b3a88 SC |
788 | default : |
789 | break ; | |
790 | } | |
52c3df99 | 791 | |
851b3a88 SC |
792 | return result ; |
793 | } | |
794 | ||
facd6764 | 795 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) |
851b3a88 | 796 | |
5f0b2f22 SC |
797 | // --------------------------------------------------------------------------- |
798 | // wxWindowMac utility functions | |
799 | // --------------------------------------------------------------------------- | |
800 | ||
801 | // Find an item given the Macintosh Window Reference | |
802 | ||
71f2fb52 RN |
803 | WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap); |
804 | ||
805 | static MacWindowMap wxWinMacWindowList; | |
806 | ||
807 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
808 | { | |
809 | MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); | |
810 | ||
811 | return (node == wxWinMacWindowList.end()) ? NULL : node->second; | |
812 | } | |
813 | ||
814 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; | |
815 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
816 | { | |
817 | // adding NULL WindowRef is (first) surely a result of an error and | |
818 | // nothing else :-) | |
819 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
820 | ||
821 | wxWinMacWindowList[inWindowRef] = win; | |
822 | } | |
823 | ||
824 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; | |
825 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
826 | { | |
827 | MacWindowMap::iterator it; | |
828 | for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) | |
829 | { | |
830 | if ( it->second == win ) | |
831 | { | |
832 | wxWinMacWindowList.erase(it); | |
833 | break; | |
834 | } | |
835 | } | |
836 | } | |
5f0b2f22 | 837 | |
a15eb0a5 SC |
838 | // ---------------------------------------------------------------------------- |
839 | // wxTopLevelWindowMac creation | |
840 | // ---------------------------------------------------------------------------- | |
841 | ||
245f3581 | 842 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
5f0b2f22 | 843 | |
902725ee | 844 | typedef struct |
c5985061 SC |
845 | { |
846 | wxPoint m_position ; | |
902725ee | 847 | wxSize m_size ; |
f3b2e2d7 | 848 | bool m_wasResizable ; |
716d0327 | 849 | } FullScreenData ; |
c5985061 | 850 | |
a15eb0a5 SC |
851 | void wxTopLevelWindowMac::Init() |
852 | { | |
853 | m_iconized = | |
902725ee | 854 | m_maximizeOnShow = false; |
6a17ca35 | 855 | m_macWindow = NULL ; |
52c3df99 | 856 | |
7c091673 | 857 | m_macEventHandler = NULL ; |
c5985061 | 858 | m_macFullScreenData = NULL ; |
a15eb0a5 SC |
859 | } |
860 | ||
6239ee05 | 861 | wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef ) |
118f012e | 862 | { |
6239ee05 SC |
863 | m_macWindow = windowRef ; |
864 | } | |
52c3df99 | 865 | |
6239ee05 SC |
866 | wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter() |
867 | { | |
7fc641af | 868 | DisposeWindow( (WindowRef) m_macWindow ) ; |
6239ee05 | 869 | } |
118f012e | 870 | |
a15eb0a5 SC |
871 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
872 | wxWindowID id, | |
873 | const wxString& title, | |
874 | const wxPoint& pos, | |
875 | const wxSize& size, | |
876 | long style, | |
877 | const wxString& name) | |
878 | { | |
879 | // init our fields | |
880 | Init(); | |
881 | ||
882 | m_windowStyle = style; | |
883 | ||
52c3df99 | 884 | SetName( name ); |
a15eb0a5 SC |
885 | |
886 | m_windowId = id == -1 ? NewControlId() : id; | |
fb5246be | 887 | wxWindow::SetLabel( title ) ; |
a15eb0a5 | 888 | |
6239ee05 | 889 | DoMacCreateRealWindow( parent, title, pos , size , style , name ) ; |
facd6764 | 890 | |
3ef4abec | 891 | SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); |
902725ee | 892 | |
5bd78bbc JS |
893 | if (GetExtraStyle() & wxFRAME_EX_METAL) |
894 | MacSetMetalAppearance(true); | |
94d1d0f4 | 895 | |
a15eb0a5 SC |
896 | wxTopLevelWindows.Append(this); |
897 | ||
898 | if ( parent ) | |
899 | parent->AddChild(this); | |
900 | ||
902725ee | 901 | return true; |
a15eb0a5 SC |
902 | } |
903 | ||
904 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
905 | { | |
6a17ca35 SC |
906 | if ( m_macWindow ) |
907 | { | |
c81c6d54 | 908 | #if wxUSE_TOOLTIPS |
6a17ca35 | 909 | wxToolTip::NotifyWindowDelete(m_macWindow) ; |
c81c6d54 | 910 | #endif |
118f012e | 911 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 912 | } |
1542ea39 | 913 | |
7c091673 SC |
914 | if ( m_macEventHandler ) |
915 | { | |
916 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
917 | m_macEventHandler = NULL ; | |
918 | } | |
851b3a88 | 919 | |
5f0b2f22 SC |
920 | wxRemoveMacWindowAssociation( this ) ; |
921 | ||
a15eb0a5 SC |
922 | if ( wxModelessWindows.Find(this) ) |
923 | wxModelessWindows.DeleteObject(this); | |
902725ee | 924 | |
c5985061 SC |
925 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; |
926 | delete data ; | |
927 | m_macFullScreenData = NULL ; | |
09ac36f8 SC |
928 | |
929 | // avoid dangling refs | |
930 | if ( s_macDeactivateWindow == this ) | |
931 | s_macDeactivateWindow = NULL; | |
a15eb0a5 SC |
932 | } |
933 | ||
934 | ||
935 | // ---------------------------------------------------------------------------- | |
936 | // wxTopLevelWindowMac maximize/minimize | |
937 | // ---------------------------------------------------------------------------- | |
938 | ||
939 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
940 | { | |
6643c354 SC |
941 | Point idealSize = { 0 , 0 } ; |
942 | if ( maximize ) | |
943 | { | |
7cd7bc23 SC |
944 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 |
945 | HIRect bounds ; | |
946 | HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal, | |
947 | &bounds); | |
948 | idealSize.h = bounds.size.width; | |
949 | idealSize.v = bounds.size.height; | |
950 | #else | |
6643c354 SC |
951 | Rect rect ; |
952 | GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ; | |
953 | idealSize.h = rect.right - rect.left ; | |
954 | idealSize.v = rect.bottom - rect.top ; | |
7cd7bc23 | 955 | #endif |
6643c354 SC |
956 | } |
957 | ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ; | |
a15eb0a5 SC |
958 | } |
959 | ||
960 | bool wxTopLevelWindowMac::IsMaximized() const | |
961 | { | |
a979e444 | 962 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
963 | } |
964 | ||
965 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
966 | { | |
52c3df99 DS |
967 | if ( IsWindowCollapsable( (WindowRef)m_macWindow) ) |
968 | CollapseWindow( (WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
969 | } |
970 | ||
971 | bool wxTopLevelWindowMac::IsIconized() const | |
972 | { | |
b7aec135 | 973 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
974 | } |
975 | ||
976 | void wxTopLevelWindowMac::Restore() | |
977 | { | |
902725ee | 978 | if ( IsMaximized() ) |
699b6af4 | 979 | Maximize(false); |
902725ee | 980 | else if ( IsIconized() ) |
699b6af4 | 981 | Iconize(false); |
a15eb0a5 SC |
982 | } |
983 | ||
984 | // ---------------------------------------------------------------------------- | |
985 | // wxTopLevelWindowMac misc | |
986 | // ---------------------------------------------------------------------------- | |
987 | ||
facd6764 SC |
988 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
989 | { | |
52c3df99 | 990 | return wxPoint(0, 0) ; |
facd6764 SC |
991 | } |
992 | ||
5389e505 | 993 | bool wxTopLevelWindowMac::SetBackgroundColour(const wxColour& c ) |
902725ee | 994 | { |
5389e505 SC |
995 | wxColour col = c; |
996 | if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ) | |
997 | col = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)); | |
998 | else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ) | |
999 | col = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)); | |
1000 | ||
a01d9a25 SC |
1001 | if ( !wxTopLevelWindowBase::SetBackgroundColour(col) && m_hasBgCol ) |
1002 | return false ; | |
1003 | ||
5389e505 | 1004 | if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) ) |
3ef4abec | 1005 | { |
a01d9a25 | 1006 | SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ; |
3ef4abec SC |
1007 | SetBackgroundStyle(wxBG_STYLE_CUSTOM); |
1008 | } | |
5389e505 | 1009 | else if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) ) |
3ef4abec | 1010 | { |
a01d9a25 | 1011 | SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ; |
3ef4abec SC |
1012 | SetBackgroundStyle(wxBG_STYLE_CUSTOM); |
1013 | } | |
a01d9a25 SC |
1014 | return true; |
1015 | } | |
facd6764 | 1016 | |
6239ee05 SC |
1017 | void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) |
1018 | { | |
1019 | InstallWindowEventHandler(window, GetwxMacTopLevelEventHandlerUPP(), | |
1020 | GetEventTypeCount(eventList), eventList, ref, handler ); | |
1021 | } | |
1022 | ||
902725ee | 1023 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
949cb163 SC |
1024 | { |
1025 | if ( m_macEventHandler != NULL ) | |
1026 | { | |
1027 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1028 | } | |
6239ee05 | 1029 | wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this); |
949cb163 SC |
1030 | } |
1031 | ||
a979e444 DS |
1032 | void wxTopLevelWindowMac::MacCreateRealWindow( |
1033 | const wxString& title, | |
1034 | const wxPoint& pos, | |
1035 | const wxSize& size, | |
1036 | long style, | |
1037 | const wxString& name ) | |
6239ee05 SC |
1038 | { |
1039 | DoMacCreateRealWindow( NULL, title, pos, size, style, name ); | |
1040 | } | |
1041 | ||
1042 | void wxTopLevelWindowMac::DoMacCreateRealWindow( | |
0d6fba37 | 1043 | wxWindow* parent, |
6239ee05 SC |
1044 | const wxString& title, |
1045 | const wxPoint& pos, | |
1046 | const wxSize& size, | |
1047 | long style, | |
1048 | const wxString& name ) | |
5f0b2f22 | 1049 | { |
47ac4f9b | 1050 | OSStatus err = noErr ; |
e40298d5 JS |
1051 | SetName(name); |
1052 | m_windowStyle = style; | |
902725ee | 1053 | m_isShown = false; |
1542ea39 | 1054 | |
e40298d5 | 1055 | // create frame. |
facd6764 SC |
1056 | int x = (int)pos.x; |
1057 | int y = (int)pos.y; | |
902725ee | 1058 | |
52c3df99 | 1059 | Rect theBoundsRect; |
5a486641 SC |
1060 | wxRect display = wxGetClientDisplayRect() ; |
1061 | ||
1062 | if ( x == wxDefaultPosition.x ) | |
1063 | x = display.x ; | |
902725ee | 1064 | |
5a486641 SC |
1065 | if ( y == wxDefaultPosition.y ) |
1066 | y = display.y ; | |
1542ea39 | 1067 | |
facd6764 SC |
1068 | int w = WidthDefault(size.x); |
1069 | int h = HeightDefault(size.y); | |
1542ea39 | 1070 | |
facd6764 | 1071 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 1072 | |
5f0b2f22 | 1073 | // translate the window attributes in the appropriate window class and attributes |
5f0b2f22 SC |
1074 | WindowClass wclass = 0; |
1075 | WindowAttributes attr = kWindowNoAttributes ; | |
e353795e | 1076 | WindowGroupRef group = NULL ; |
0d6fba37 VZ |
1077 | bool activationScopeSet = false; |
1078 | WindowActivationScope activationScope = kWindowActivationScopeNone; | |
1542ea39 | 1079 | |
f5744893 | 1080 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 1081 | { |
1542ea39 | 1082 | if ( |
f5744893 SC |
1083 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
1084 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
1085 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 1086 | ) |
5f0b2f22 | 1087 | { |
6239ee05 SC |
1088 | if ( HasFlag( wxSTAY_ON_TOP ) ) |
1089 | wclass = kUtilityWindowClass; | |
1090 | else | |
1091 | wclass = kFloatingWindowClass ; | |
52c3df99 | 1092 | |
f5744893 | 1093 | if ( HasFlag(wxTINY_CAPTION_VERT) ) |
f5744893 | 1094 | attr |= kWindowSideTitlebarAttribute ; |
f5744893 SC |
1095 | } |
1096 | else | |
1097 | { | |
1098 | wclass = kPlainWindowClass ; | |
0d6fba37 VZ |
1099 | activationScopeSet = true; |
1100 | activationScope = kWindowActivationScopeNone; | |
5f0b2f22 SC |
1101 | } |
1102 | } | |
a0232aa5 RD |
1103 | else if ( HasFlag( wxPOPUP_WINDOW ) ) |
1104 | { | |
1105 | // TEMPORARY HACK! | |
1106 | // Until we've got a real wxPopupWindow class on wxMac make it a | |
1107 | // little easier for wxFrame to be used to emulate it and workaround | |
1108 | // the lack of wxPopupWindow. | |
1109 | if ( HasFlag( wxBORDER_NONE ) ) | |
1110 | wclass = kHelpWindowClass ; // has no border | |
1111 | else | |
1112 | wclass = kPlainWindowClass ; // has a single line border, it will have to do for now | |
1113 | //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we?? | |
89954433 | 1114 | group = GetWindowGroupOfClass( // float above other windows |
a0232aa5 RD |
1115 | kFloatingWindowClass) ; |
1116 | } | |
5f0b2f22 SC |
1117 | else if ( HasFlag( wxCAPTION ) ) |
1118 | { | |
1542ea39 | 1119 | wclass = kDocumentWindowClass ; |
22e3c5bd | 1120 | attr |= kWindowInWindowMenuAttribute ; |
5f0b2f22 | 1121 | } |
3e17bc3f RN |
1122 | else if ( HasFlag( wxFRAME_DRAWER ) ) |
1123 | { | |
1124 | wclass = kDrawerWindowClass; | |
3e17bc3f | 1125 | } |
5f0b2f22 SC |
1126 | else |
1127 | { | |
f5744893 | 1128 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 1129 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
1130 | { |
1131 | wclass = kDocumentWindowClass ; | |
1132 | } | |
6239ee05 SC |
1133 | else if ( HasFlag( wxNO_BORDER ) ) |
1134 | { | |
1135 | wclass = kSimpleWindowClass ; | |
1136 | } | |
f5744893 SC |
1137 | else |
1138 | { | |
1139 | wclass = kPlainWindowClass ; | |
1140 | } | |
5f0b2f22 | 1141 | } |
1542ea39 | 1142 | |
52c3df99 | 1143 | if ( wclass != kPlainWindowClass ) |
5f0b2f22 | 1144 | { |
52c3df99 DS |
1145 | if ( HasFlag( wxMINIMIZE_BOX ) ) |
1146 | attr |= kWindowCollapseBoxAttribute ; | |
1147 | ||
1148 | if ( HasFlag( wxMAXIMIZE_BOX ) ) | |
1149 | attr |= kWindowFullZoomAttribute ; | |
1150 | ||
1151 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
1152 | attr |= kWindowResizableAttribute ; | |
1153 | ||
1154 | if ( HasFlag( wxCLOSE_BOX) ) | |
1155 | attr |= kWindowCloseBoxAttribute ; | |
5f0b2f22 | 1156 | } |
03561a3c | 1157 | attr |= kWindowLiveResizeAttribute; |
eb630bf1 | 1158 | |
e353795e | 1159 | if ( HasFlag(wxSTAY_ON_TOP) ) |
e353795e | 1160 | group = GetWindowGroupOfClass(kUtilityWindowClass) ; |
6a7e6411 | 1161 | |
a0232aa5 RD |
1162 | if ( HasFlag( wxFRAME_FLOAT_ON_PARENT ) ) |
1163 | group = GetWindowGroupOfClass(kFloatingWindowClass) ; | |
89954433 | 1164 | |
6239ee05 SC |
1165 | if ( group == NULL && parent != NULL ) |
1166 | { | |
1167 | WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef(); | |
1168 | if( parenttlw ) | |
1169 | group = GetWindowGroupParent( GetWindowGroup( parenttlw ) ); | |
1170 | } | |
0d6fba37 | 1171 | |
f21449ae | 1172 | attr |= kWindowCompositingAttribute; |
24fcd264 SC |
1173 | #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale) |
1174 | attr |= kWindowFrameworkScaledAttribute; | |
d66c3960 | 1175 | #endif |
902725ee | 1176 | |
6a7e6411 RD |
1177 | if ( HasFlag(wxFRAME_SHAPED) ) |
1178 | { | |
1179 | WindowDefSpec customWindowDefSpec; | |
1180 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
89954433 | 1181 | customWindowDefSpec.u.defProc = |
7cd7bc23 SC |
1182 | #ifdef __LP64__ |
1183 | (WindowDefUPP) wxShapedMacWindowDef; | |
1184 | #else | |
1185 | NewWindowDefUPP(wxShapedMacWindowDef); | |
1186 | #endif | |
47ac4f9b | 1187 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
1188 | attr, &theBoundsRect, |
1189 | (WindowRef*) &m_macWindow); | |
1190 | } | |
1191 | else | |
1192 | { | |
47ac4f9b | 1193 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
1194 | } |
1195 | ||
e353795e SC |
1196 | if ( err == noErr && m_macWindow != NULL && group != NULL ) |
1197 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1198 | ||
47ac4f9b | 1199 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
f83b6761 | 1200 | |
832f330f | 1201 | // setup a separate group for each window, so that overlays can be handled easily |
0d6fba37 | 1202 | |
6239ee05 SC |
1203 | WindowGroupRef overlaygroup = NULL; |
1204 | verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup )); | |
1205 | verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow ))); | |
1206 | verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup )); | |
0d6fba37 VZ |
1207 | |
1208 | if ( activationScopeSet ) | |
1209 | { | |
1210 | verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope )); | |
1211 | } | |
89954433 | 1212 | |
a979e444 DS |
1213 | // the create commands are only for content rect, |
1214 | // so we have to set the size again as structure bounds | |
f83b6761 SC |
1215 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; |
1216 | ||
facd6764 | 1217 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
34a3ed01 | 1218 | SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) ); |
1f1c8bd4 | 1219 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; |
902725ee | 1220 | |
f21449ae SC |
1221 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of |
1222 | // the content view, so we have to retrieve it explicitly | |
1223 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
1224 | m_peer->GetControlRefAddr() ) ; | |
1225 | if ( !m_peer->Ok() ) | |
789ae0cf | 1226 | { |
f21449ae SC |
1227 | // compatibility mode fallback |
1228 | GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; | |
789ae0cf | 1229 | } |
52c3df99 DS |
1230 | |
1231 | // the root control level handler | |
5ca0d812 | 1232 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; |
facd6764 | 1233 | |
9dc1d180 JS |
1234 | // Causes the inner part of the window not to be metal |
1235 | // if the style is used before window creation. | |
1236 | #if 0 // TARGET_API_MAC_OSX | |
8ec0a8fa SC |
1237 | if ( m_macUsesCompositing && m_macWindow != NULL ) |
1238 | { | |
1239 | if ( GetExtraStyle() & wxFRAME_EX_METAL ) | |
1240 | MacSetMetalAppearance( true ) ; | |
1241 | } | |
1242 | #endif | |
52c3df99 | 1243 | |
893727e5 KO |
1244 | if ( m_macWindow != NULL ) |
1245 | { | |
1246 | MacSetUnifiedAppearance( true ) ; | |
1247 | } | |
893727e5 | 1248 | |
6239ee05 SC |
1249 | HIViewRef growBoxRef = 0 ; |
1250 | err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); | |
1251 | if ( err == noErr && growBoxRef != 0 ) | |
1252 | HIGrowBoxViewSetTransparent( growBoxRef, true ) ; | |
1253 | ||
73fe67bd | 1254 | // the frame window event handler |
e40298d5 | 1255 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 | 1256 | MacInstallTopLevelWindowEventHandler() ; |
b19bf058 | 1257 | |
14c96cf2 SC |
1258 | DoSetWindowVariant( m_windowVariant ) ; |
1259 | ||
facd6764 | 1260 | m_macFocus = NULL ; |
6a7e6411 RD |
1261 | |
1262 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1263 | { | |
1264 | // default shape matches the window size | |
52c3df99 DS |
1265 | wxRegion rgn( 0, 0, w, h ); |
1266 | SetShape( rgn ); | |
6a7e6411 | 1267 | } |
3dfafdb9 RD |
1268 | |
1269 | wxWindowCreateEvent event(this); | |
937013e0 | 1270 | HandleWindowEvent(event); |
5f0b2f22 SC |
1271 | } |
1272 | ||
5d2e69e8 | 1273 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 1274 | { |
5d2e69e8 | 1275 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
1276 | } |
1277 | ||
5f0b2f22 SC |
1278 | // Raise the window to the top of the Z order |
1279 | void wxTopLevelWindowMac::Raise() | |
1280 | { | |
7f3c339c | 1281 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1282 | } |
1283 | ||
1284 | // Lower the window to the bottom of the Z order | |
1285 | void wxTopLevelWindowMac::Lower() | |
1286 | { | |
76a5e5d2 | 1287 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
1288 | } |
1289 | ||
245f3581 DE |
1290 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1291 | { | |
52c3df99 | 1292 | if (s_macDeactivateWindow) |
245f3581 | 1293 | { |
f02a4ffa VZ |
1294 | wxLogTrace(TRACE_ACTIVATE, |
1295 | wxT("Doing delayed deactivation of %p"), | |
1296 | s_macDeactivateWindow); | |
52c3df99 | 1297 | |
245f3581 DE |
1298 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1299 | } | |
1300 | } | |
1301 | ||
89954433 | 1302 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) ) |
5f0b2f22 | 1303 | { |
f02a4ffa | 1304 | wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); |
17f8d2a7 | 1305 | |
52c3df99 DS |
1306 | if (s_macDeactivateWindow == this) |
1307 | s_macDeactivateWindow = NULL; | |
1308 | ||
245f3581 | 1309 | MacDelayedDeactivation(timestamp); |
5f0b2f22 SC |
1310 | } |
1311 | ||
1312 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1313 | { | |
fb5246be | 1314 | wxWindow::SetLabel( title ) ; |
34a3ed01 | 1315 | SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) ) ; |
5f0b2f22 SC |
1316 | } |
1317 | ||
d4bd6c97 | 1318 | wxString wxTopLevelWindowMac::GetTitle() const |
fb5246be WS |
1319 | { |
1320 | return wxWindow::GetLabel(); | |
1321 | } | |
1322 | ||
5f0b2f22 SC |
1323 | bool wxTopLevelWindowMac::Show(bool show) |
1324 | { | |
facd6764 | 1325 | if ( !wxTopLevelWindowBase::Show(show) ) |
902725ee | 1326 | return false; |
5f0b2f22 | 1327 | |
03561a3c | 1328 | bool plainTransition = true; |
21e77aa1 | 1329 | |
a979e444 | 1330 | #if wxUSE_SYSTEM_OPTIONS |
21e77aa1 DS |
1331 | if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) |
1332 | plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; | |
1333 | #endif | |
52c3df99 | 1334 | |
21e77aa1 DS |
1335 | if (show) |
1336 | { | |
8c8f6a4b | 1337 | if ( plainTransition ) |
1f90939c | 1338 | ::ShowWindow( (WindowRef)m_macWindow ); |
1f90939c | 1339 | else |
52c3df99 | 1340 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); |
52c3df99 | 1341 | |
1f90939c | 1342 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
52c3df99 DS |
1343 | |
1344 | // because apps expect a size event to occur at this moment | |
a979e444 | 1345 | wxSizeEvent event(GetSize() , m_windowId); |
1f90939c | 1346 | event.SetEventObject(this); |
937013e0 | 1347 | HandleWindowEvent(event); |
5f0b2f22 SC |
1348 | } |
1349 | else | |
1350 | { | |
8c8f6a4b | 1351 | if ( plainTransition ) |
21e77aa1 | 1352 | ::HideWindow( (WindowRef)m_macWindow ); |
1f90939c | 1353 | else |
21e77aa1 | 1354 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); |
5f0b2f22 SC |
1355 | } |
1356 | ||
902725ee | 1357 | return true ; |
5f0b2f22 SC |
1358 | } |
1359 | ||
8e181eae SC |
1360 | bool wxTopLevelWindowMac::ShowWithEffect(wxShowEffect effect, |
1361 | unsigned timeout, | |
1362 | wxDirection dir) | |
1363 | { | |
1364 | // TODO factor common code | |
1365 | if ( !wxTopLevelWindowBase::Show(true) ) | |
1366 | return false; | |
1367 | ||
1368 | WindowTransitionEffect transition = 0 ; | |
1369 | switch( effect ) | |
1370 | { | |
1371 | case wxSHOW_EFFECT_ROLL : | |
1372 | case wxSHOW_EFFECT_SLIDE : | |
1373 | transition = kWindowGenieTransitionEffect; | |
1374 | break; | |
1375 | case wxSHOW_EFFECT_BLEND : | |
1376 | transition = kWindowFadeTransitionEffect; | |
1377 | break; | |
1378 | case wxSHOW_EFFECT_EXPAND : | |
1379 | default : | |
1380 | // having sheets would be fine, but this might lead to a repositioning | |
1381 | #if 0 | |
1382 | if ( GetParent() ) | |
1383 | transition = kWindowSheetTransitionEffect; | |
1384 | else | |
1385 | #endif | |
1386 | transition = kWindowZoomTransitionEffect; | |
1387 | break; | |
1388 | } | |
1389 | ||
1390 | TransitionWindowOptions options; | |
1391 | options.version = 0; | |
1392 | options.duration = timeout / 1000.0; | |
1393 | options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0; | |
1394 | options.userData = 0; | |
1395 | ||
1396 | wxSize size = wxGetDisplaySize(); | |
1397 | Rect bounds; | |
1398 | GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds ); | |
1399 | CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top ); | |
1400 | ||
1401 | if ( dir & wxRIGHT ) | |
1402 | { | |
1403 | hiBounds.origin.x = size.x; | |
1404 | hiBounds.size.width = 0; | |
1405 | } | |
1406 | if ( dir & wxUP ) | |
1407 | { | |
1408 | hiBounds.origin.y = 0; | |
1409 | hiBounds.size.height = 0; | |
1410 | } | |
1411 | if ( dir & wxDOWN ) | |
1412 | { | |
1413 | hiBounds.origin.y = size.y; | |
1414 | hiBounds.size.height = 0; | |
1415 | } | |
1416 | if ( dir & wxLEFT ) | |
1417 | { | |
1418 | hiBounds.origin.x = 0; | |
1419 | hiBounds.size.width = 0; | |
1420 | } | |
1421 | ||
1422 | ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowShowTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL , | |
1423 | false, &options ); | |
1424 | ||
1425 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1426 | ||
1427 | // because apps expect a size event to occur at this moment | |
1428 | wxSizeEvent event(GetSize() , m_windowId); | |
1429 | event.SetEventObject(this); | |
937013e0 | 1430 | HandleWindowEvent(event); |
8e181eae SC |
1431 | |
1432 | return true; | |
1433 | } | |
1434 | ||
1435 | bool wxTopLevelWindowMac::HideWithEffect(wxShowEffect effect, | |
1436 | unsigned timeout , | |
1437 | wxDirection dir ) | |
1438 | { | |
1439 | if ( !wxTopLevelWindowBase::Show(false) ) | |
1440 | return false; | |
1441 | ||
1442 | WindowTransitionEffect transition = 0 ; | |
1443 | switch( effect ) | |
1444 | { | |
1445 | case wxSHOW_EFFECT_ROLL : | |
1446 | case wxSHOW_EFFECT_SLIDE : | |
1447 | transition = kWindowGenieTransitionEffect; | |
1448 | break; | |
1449 | case wxSHOW_EFFECT_BLEND : | |
1450 | transition = kWindowFadeTransitionEffect; | |
1451 | break; | |
1452 | case wxSHOW_EFFECT_EXPAND : | |
1453 | default: | |
1454 | #if 0 | |
1455 | if ( GetParent() ) | |
1456 | transition = kWindowSheetTransitionEffect; | |
1457 | else | |
1458 | #endif | |
1459 | transition = kWindowZoomTransitionEffect; | |
1460 | break; | |
1461 | } | |
1462 | TransitionWindowOptions options; | |
1463 | options.version = 0; | |
1464 | options.duration = timeout / 1000.0; | |
1465 | options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0; | |
1466 | options.userData = 0; | |
1467 | ||
1468 | wxSize size = wxGetDisplaySize(); | |
1469 | Rect bounds; | |
1470 | GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds ); | |
1471 | CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top ); | |
1472 | ||
1473 | if ( dir & wxRIGHT ) | |
1474 | { | |
1475 | hiBounds.origin.x = size.x; | |
1476 | hiBounds.size.width = 0; | |
1477 | } | |
1478 | if ( dir & wxUP ) | |
1479 | { | |
1480 | hiBounds.origin.y = 0; | |
1481 | hiBounds.size.height = 0; | |
1482 | } | |
1483 | if ( dir & wxDOWN ) | |
1484 | { | |
1485 | hiBounds.origin.y = size.y; | |
1486 | hiBounds.size.height = 0; | |
1487 | } | |
1488 | if ( dir & wxLEFT ) | |
1489 | { | |
1490 | hiBounds.origin.x = 0; | |
1491 | hiBounds.size.width = 0; | |
1492 | } | |
1493 | ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowHideTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL , | |
1494 | false, &options ); | |
1495 | ||
1496 | return true; | |
1497 | } | |
1498 | ||
c5985061 | 1499 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) |
902725ee | 1500 | { |
c5985061 SC |
1501 | if ( show ) |
1502 | { | |
1503 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
1504 | delete data ; | |
1505 | data = new FullScreenData() ; | |
902725ee | 1506 | |
c5985061 SC |
1507 | m_macFullScreenData = data ; |
1508 | data->m_position = GetPosition() ; | |
1509 | data->m_size = GetSize() ; | |
f3b2e2d7 | 1510 | data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ; |
902725ee | 1511 | |
c5985061 | 1512 | if ( style & wxFULLSCREEN_NOMENUBAR ) |
52c3df99 DS |
1513 | HideMenuBar() ; |
1514 | ||
c5985061 SC |
1515 | wxRect client = wxGetClientDisplayRect() ; |
1516 | ||
52c3df99 | 1517 | int left , top , right , bottom ; |
c5985061 | 1518 | int x, y, w, h ; |
902725ee | 1519 | |
c5985061 SC |
1520 | x = client.x ; |
1521 | y = client.y ; | |
1522 | w = client.width ; | |
1523 | h = client.height ; | |
902725ee | 1524 | |
c5985061 SC |
1525 | MacGetContentAreaInset( left , top , right , bottom ) ; |
1526 | ||
1527 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
1528 | { | |
1529 | y -= top ; | |
1530 | h += top ; | |
1531 | } | |
52c3df99 | 1532 | |
c5985061 SC |
1533 | if ( style & wxFULLSCREEN_NOBORDER ) |
1534 | { | |
1535 | x -= left ; | |
1536 | w += left + right ; | |
1537 | h += bottom ; | |
1538 | } | |
52c3df99 | 1539 | |
c5985061 SC |
1540 | if ( style & wxFULLSCREEN_NOTOOLBAR ) |
1541 | { | |
3c86150d SC |
1542 | // TODO |
1543 | } | |
52c3df99 | 1544 | |
3c86150d SC |
1545 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) |
1546 | { | |
1547 | // TODO | |
c5985061 | 1548 | } |
52c3df99 | 1549 | |
c5985061 | 1550 | SetSize( x , y , w, h ) ; |
172da31f | 1551 | if ( data->m_wasResizable ) |
f3b2e2d7 | 1552 | MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ; |
c5985061 SC |
1553 | } |
1554 | else | |
1555 | { | |
1556 | ShowMenuBar() ; | |
1557 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
172da31f | 1558 | if ( data->m_wasResizable ) |
f3b2e2d7 | 1559 | MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ; |
c5985061 SC |
1560 | SetPosition( data->m_position ) ; |
1561 | SetSize( data->m_size ) ; | |
52c3df99 | 1562 | |
c5985061 SC |
1563 | delete data ; |
1564 | m_macFullScreenData = NULL ; | |
1565 | } | |
52c3df99 | 1566 | |
902725ee | 1567 | return false; |
c5985061 SC |
1568 | } |
1569 | ||
902725ee WS |
1570 | bool wxTopLevelWindowMac::IsFullScreen() const |
1571 | { | |
1572 | return m_macFullScreenData != NULL ; | |
c5985061 SC |
1573 | } |
1574 | ||
50f3c41d | 1575 | |
07880314 | 1576 | bool wxTopLevelWindowMac::SetTransparent(wxByte alpha) |
50f3c41d | 1577 | { |
24fcd264 | 1578 | OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, float(alpha)/255.0); |
50f3c41d RD |
1579 | return result == noErr; |
1580 | } | |
1581 | ||
1582 | ||
07880314 | 1583 | bool wxTopLevelWindowMac::CanSetTransparent() |
50f3c41d RD |
1584 | { |
1585 | return true; | |
1586 | } | |
1587 | ||
1588 | ||
30c23e74 | 1589 | void wxTopLevelWindowMac::SetExtraStyle(long exStyle) |
8ec0a8fa SC |
1590 | { |
1591 | if ( GetExtraStyle() == exStyle ) | |
1592 | return ; | |
30c23e74 | 1593 | |
8ec0a8fa | 1594 | wxTopLevelWindowBase::SetExtraStyle( exStyle ) ; |
52c3df99 | 1595 | |
f21449ae | 1596 | if ( m_macWindow != NULL ) |
8ec0a8fa SC |
1597 | { |
1598 | bool metal = GetExtraStyle() & wxFRAME_EX_METAL ; | |
893727e5 | 1599 | |
8ec0a8fa | 1600 | if ( MacGetMetalAppearance() != metal ) |
893727e5 KO |
1601 | { |
1602 | if ( MacGetUnifiedAppearance() ) | |
1603 | MacSetUnifiedAppearance( !metal ) ; | |
89954433 | 1604 | |
8ec0a8fa | 1605 | MacSetMetalAppearance( metal ) ; |
893727e5 | 1606 | } |
8ec0a8fa | 1607 | } |
8ec0a8fa SC |
1608 | } |
1609 | ||
4488a1d3 VZ |
1610 | bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style) |
1611 | { | |
1612 | if ( !wxTopLevelWindowBase::SetBackgroundStyle(style) ) | |
1613 | return false ; | |
1614 | ||
1615 | WindowRef windowRef = HIViewGetWindow( (HIViewRef)GetHandle() ); | |
1616 | ||
1617 | if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
1618 | { | |
1619 | OSStatus err = HIWindowChangeFeatures( windowRef, 0, kWindowIsOpaque ); | |
1620 | verify_noerr( err ); | |
1621 | err = ReshapeCustomWindow( windowRef ); | |
1622 | verify_noerr( err ); | |
1623 | } | |
1624 | ||
1625 | return true ; | |
1626 | } | |
1627 | ||
30c23e74 | 1628 | // TODO: switch to structure bounds - |
21e77aa1 | 1629 | // we are still using coordinates of the content view |
21e77aa1 | 1630 | // |
29281095 SC |
1631 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1632 | { | |
21e77aa1 DS |
1633 | Rect content, structure ; |
1634 | ||
29281095 SC |
1635 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; |
1636 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1637 | ||
1638 | left = content.left - structure.left ; | |
1639 | top = content.top - structure.top ; | |
1640 | right = structure.right - content.right ; | |
1641 | bottom = structure.bottom - content.bottom ; | |
1642 | } | |
1643 | ||
5f0b2f22 SC |
1644 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1645 | { | |
c9698388 | 1646 | m_cachedClippedRectValid = false ; |
facd6764 SC |
1647 | Rect bounds = { y , x , y + height , x + width } ; |
1648 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
4817190d | 1649 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
5f0b2f22 SC |
1650 | } |
1651 | ||
facd6764 | 1652 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1653 | { |
facd6764 | 1654 | Rect bounds ; |
52c3df99 | 1655 | |
facd6764 | 1656 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; |
52c3df99 DS |
1657 | |
1658 | if (x) | |
1659 | *x = bounds.left ; | |
1660 | if (y) | |
1661 | *y = bounds.top ; | |
facd6764 | 1662 | } |
52c3df99 | 1663 | |
facd6764 SC |
1664 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const |
1665 | { | |
1666 | Rect bounds ; | |
52c3df99 | 1667 | |
facd6764 | 1668 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; |
52c3df99 DS |
1669 | |
1670 | if (width) | |
1671 | *width = bounds.right - bounds.left ; | |
1672 | if (height) | |
1673 | *height = bounds.bottom - bounds.top ; | |
facd6764 | 1674 | } |
1542ea39 | 1675 | |
facd6764 SC |
1676 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1677 | { | |
1678 | Rect bounds ; | |
52c3df99 | 1679 | |
facd6764 | 1680 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; |
52c3df99 DS |
1681 | |
1682 | if (width) | |
1683 | *width = bounds.right - bounds.left ; | |
1684 | if (height) | |
1685 | *height = bounds.bottom - bounds.top ; | |
facd6764 | 1686 | } |
1542ea39 | 1687 | |
6239ee05 SC |
1688 | void wxTopLevelWindowMac::DoCentre(int dir) |
1689 | { | |
1690 | if ( m_macWindow != 0 ) | |
1691 | wxTopLevelWindowBase::DoCentre(dir); | |
1692 | } | |
1693 | ||
902725ee | 1694 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
facd6764 | 1695 | { |
893727e5 KO |
1696 | if ( MacGetUnifiedAppearance() ) |
1697 | MacSetUnifiedAppearance( false ) ; | |
89954433 | 1698 | |
902725ee | 1699 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , |
facd6764 | 1700 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; |
facd6764 | 1701 | } |
1542ea39 | 1702 | |
902725ee | 1703 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
6aab345b | 1704 | { |
6aab345b | 1705 | return MacGetWindowAttributes() & kWindowMetalAttribute ; |
6aab345b SC |
1706 | } |
1707 | ||
893727e5 KO |
1708 | void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set ) |
1709 | { | |
e1673e52 SC |
1710 | if ( MacGetMetalAppearance() ) |
1711 | MacSetMetalAppearance( false ) ; | |
1712 | ||
1713 | MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes , | |
1714 | set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ; | |
1715 | ||
1716 | // For some reason, Tiger uses white as the background color for this appearance, | |
1717 | // while most apps using it use the typical striped background. Restore that behavior | |
1718 | // for wx. | |
1719 | // TODO: Determine if we need this on Leopard as well. (should be harmless either way, | |
1720 | // though) | |
e014851e | 1721 | SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; |
893727e5 KO |
1722 | } |
1723 | ||
1724 | bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const | |
1725 | { | |
e1673e52 | 1726 | return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ; |
893727e5 KO |
1727 | } |
1728 | ||
902725ee | 1729 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
facd6764 | 1730 | { |
52c3df99 | 1731 | ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ; |
facd6764 | 1732 | } |
1542ea39 | 1733 | |
902725ee | 1734 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
facd6764 SC |
1735 | { |
1736 | UInt32 attr = 0 ; | |
52c3df99 DS |
1737 | GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ; |
1738 | ||
facd6764 | 1739 | return attr ; |
5f0b2f22 | 1740 | } |
a07c1212 | 1741 | |
902725ee | 1742 | void wxTopLevelWindowMac::MacPerformUpdates() |
92346151 | 1743 | { |
f21449ae SC |
1744 | // for composited windows this also triggers a redraw of all |
1745 | // invalid views in the window | |
80f3f3be | 1746 | HIWindowFlush((WindowRef) m_macWindow) ; |
92346151 SC |
1747 | } |
1748 | ||
3feeb1e1 SC |
1749 | // Attracts the users attention to this window if the application is |
1750 | // inactive (should be called when a background event occurs) | |
1751 | ||
1752 | static pascal void wxMacNMResponse( NMRecPtr ptr ) | |
1753 | { | |
1754 | NMRemove( ptr ) ; | |
a979e444 | 1755 | DisposePtr( (Ptr)ptr ) ; |
3feeb1e1 SC |
1756 | } |
1757 | ||
89954433 | 1758 | void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags)) |
3feeb1e1 SC |
1759 | { |
1760 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
52c3df99 DS |
1761 | static wxMacNMUPP nmupp( wxMacNMResponse ); |
1762 | ||
3feeb1e1 SC |
1763 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; |
1764 | notificationRequest->qType = nmType ; | |
1765 | notificationRequest->nmMark = 1 ; | |
1766 | notificationRequest->nmIcon = 0 ; | |
1767 | notificationRequest->nmSound = 0 ; | |
1768 | notificationRequest->nmStr = NULL ; | |
1769 | notificationRequest->nmResp = nmupp ; | |
52c3df99 | 1770 | |
3feeb1e1 SC |
1771 | verify_noerr( NMInstall( notificationRequest ) ) ; |
1772 | } | |
1773 | ||
facd6764 SC |
1774 | // --------------------------------------------------------------------------- |
1775 | // Shape implementation | |
1776 | // --------------------------------------------------------------------------- | |
1777 | ||
6a7e6411 | 1778 | |
1542ea39 RD |
1779 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1780 | { | |
902725ee | 1781 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, |
6a7e6411 RD |
1782 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); |
1783 | ||
a979e444 DS |
1784 | // The empty region signifies that the shape |
1785 | // should be removed from the window. | |
6a7e6411 RD |
1786 | if ( region.IsEmpty() ) |
1787 | { | |
1788 | wxSize sz = GetClientSize(); | |
1789 | wxRegion rgn(0, 0, sz.x, sz.y); | |
3c393c0a SC |
1790 | if ( rgn.IsEmpty() ) |
1791 | return false ; | |
1792 | else | |
1793 | return SetShape(rgn); | |
6a7e6411 RD |
1794 | } |
1795 | ||
1796 | // Make a copy of the region | |
1797 | RgnHandle shapeRegion = NewRgn(); | |
812e3c47 | 1798 | HIShapeGetAsQDRgn( region.GetWXHRGN(), shapeRegion ); |
6a7e6411 RD |
1799 | |
1800 | // Dispose of any shape region we may already have | |
1801 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1802 | if ( oldRgn ) | |
1803 | DisposeRgn(oldRgn); | |
1804 | ||
1805 | // Save the region so we can use it later | |
7cd7bc23 | 1806 | SetWRefCon((WindowRef)MacGetWindowRef(), (URefCon)shapeRegion); |
6a7e6411 | 1807 | |
52c3df99 | 1808 | // inform the window manager that the window has changed shape |
6a7e6411 | 1809 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); |
52c3df99 | 1810 | |
902725ee | 1811 | return true; |
6a7e6411 RD |
1812 | } |
1813 | ||
6a7e6411 RD |
1814 | // --------------------------------------------------------------------------- |
1815 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1816 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1817 | // --------------------------------------------------------------------------- | |
1818 | ||
6a7e6411 RD |
1819 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1820 | { | |
1821 | GetWindowPortBounds(window, inRect); | |
7cd7bc23 SC |
1822 | Point pt = { inRect->top ,inRect->left }; |
1823 | wxMacLocalToGlobal( window, &pt ) ; | |
1824 | inRect->bottom += pt.v - inRect->top; | |
1825 | inRect->right += pt.h - inRect->left; | |
6a7e6411 RD |
1826 | inRect->top = pt.v; |
1827 | inRect->left = pt.h; | |
6a7e6411 RD |
1828 | } |
1829 | ||
89954433 | 1830 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param) |
6a7e6411 RD |
1831 | { |
1832 | /*------------------------------------------------------ | |
1833 | Define which options your custom window supports. | |
1834 | --------------------------------------------------------*/ | |
1835 | //just enable everything for our demo | |
52c3df99 DS |
1836 | *(OptionBits*)param = |
1837 | //kWindowCanGrow | | |
1838 | //kWindowCanZoom | | |
6639b056 | 1839 | kWindowCanCollapse | |
52c3df99 DS |
1840 | //kWindowCanGetWindowRegion | |
1841 | //kWindowHasTitleBar | | |
1842 | //kWindowSupportsDragHilite | | |
1843 | kWindowCanDrawInCurrentPort | | |
1844 | //kWindowCanMeasureTitle | | |
1845 | kWindowWantsDisposeAtProcessDeath | | |
1846 | kWindowSupportsGetGrowImageRegion | | |
1847 | kWindowDefSupportsColorGrafPort; | |
1848 | ||
6a7e6411 | 1849 | return 1; |
1542ea39 | 1850 | } |
6a7e6411 RD |
1851 | |
1852 | // The content region is left as a rectangle matching the window size, this is | |
1853 | // so the origin in the paint event, and etc. still matches what the | |
1854 | // programmer expects. | |
1855 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1856 | { | |
1857 | SetEmptyRgn(rgn); | |
1858 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1859 | if (win) | |
1860 | { | |
b19bf058 | 1861 | Rect r ; |
52c3df99 | 1862 | wxShapedMacWindowGetPos( window, &r ) ; |
b19bf058 | 1863 | RectRgn( rgn , &r ) ; |
6a7e6411 RD |
1864 | } |
1865 | } | |
1866 | ||
1867 | // The structure region is set to the shape given to the SetShape method. | |
1868 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1869 | { | |
1870 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1871 | ||
1872 | SetEmptyRgn(rgn); | |
1873 | if (cachedRegion) | |
1874 | { | |
1875 | Rect windowRect; | |
902725ee WS |
1876 | wxShapedMacWindowGetPos(window, &windowRect); // how big is the window |
1877 | CopyRgn(cachedRegion, rgn); // make a copy of our cached region | |
6a7e6411 | 1878 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window |
902725ee | 1879 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size |
6a7e6411 RD |
1880 | } |
1881 | } | |
1882 | ||
6a7e6411 RD |
1883 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) |
1884 | { | |
52c3df99 DS |
1885 | GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param; |
1886 | ||
1887 | if (rgnRec == NULL) | |
1888 | return paramErr; | |
6a7e6411 | 1889 | |
52c3df99 | 1890 | switch (rgnRec->regionCode) |
6a7e6411 RD |
1891 | { |
1892 | case kWindowStructureRgn: | |
1893 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1894 | break; | |
52c3df99 | 1895 | |
6a7e6411 RD |
1896 | case kWindowContentRgn: |
1897 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1898 | break; | |
52c3df99 | 1899 | |
6a7e6411 RD |
1900 | default: |
1901 | SetEmptyRgn(rgnRec->winRgn); | |
52c3df99 DS |
1902 | break; |
1903 | } | |
6a7e6411 RD |
1904 | |
1905 | return noErr; | |
1906 | } | |
1907 | ||
52c3df99 DS |
1908 | // Determine the region of the window which was hit |
1909 | // | |
1910 | static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param) | |
6a7e6411 | 1911 | { |
6a7e6411 | 1912 | Point hitPoint; |
52c3df99 | 1913 | static RgnHandle tempRgn = NULL; |
6a7e6411 | 1914 | |
52c3df99 DS |
1915 | if (tempRgn == NULL) |
1916 | tempRgn = NewRgn(); | |
6a7e6411 | 1917 | |
52c3df99 DS |
1918 | // get the point clicked |
1919 | SetPt( &hitPoint, LoWord(param), HiWord(param) ); | |
6a7e6411 | 1920 | |
52c3df99 | 1921 | // Mac OS 8.5 or later |
6a7e6411 | 1922 | wxShapedMacWindowStructureRegion(window, tempRgn); |
52c3df99 | 1923 | if (PtInRgn( hitPoint, tempRgn )) //in window content region? |
6a7e6411 RD |
1924 | return wInContent; |
1925 | ||
52c3df99 DS |
1926 | // no significant area was hit |
1927 | return wNoHit; | |
6a7e6411 RD |
1928 | } |
1929 | ||
89954433 | 1930 | static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param) |
6a7e6411 | 1931 | { |
52c3df99 | 1932 | switch (message) |
6a7e6411 RD |
1933 | { |
1934 | case kWindowMsgHitTest: | |
52c3df99 | 1935 | return wxShapedMacWindowHitTest(window, param); |
6a7e6411 RD |
1936 | |
1937 | case kWindowMsgGetFeatures: | |
52c3df99 | 1938 | return wxShapedMacWindowGetFeatures(window, param); |
6a7e6411 RD |
1939 | |
1940 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1941 | case kWindowMsgGetRegion: | |
52c3df99 DS |
1942 | return wxShapedMacWindowGetRegion(window, param); |
1943 | ||
1944 | default: | |
1945 | break; | |
6a7e6411 RD |
1946 | } |
1947 | ||
1948 | return 0; | |
1949 | } |