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