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