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