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