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