]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toplevel.cpp
trying to fix dmc warning about potential overload ambiguity
[wxWidgets.git] / src / mac / carbon / toplevel.cpp
CommitLineData
a15eb0a5
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: mac/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
3d1a4878 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
a15eb0a5
SC
21 #pragma implementation "toplevel.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
422644a3 34 #include "wx/frame.h"
a15eb0a5
SC
35 #include "wx/string.h"
36 #include "wx/log.h"
37 #include "wx/intl.h"
37ec2bd3 38 #include "wx/settings.h"
179e085f 39 #include "wx/control.h"
a15eb0a5
SC
40#endif //WX_PRECOMP
41
5f0b2f22 42#include "wx/mac/uma.h"
422644a3 43#include "wx/mac/aga.h"
7c091673 44#include "wx/app.h"
5f0b2f22 45#include "wx/tooltip.h"
a07c1212 46#include "wx/dnd.h"
1f90939c
SC
47#if wxUSE_SYSTEM_OPTIONS
48 #include "wx/sysopt.h"
49#endif
5f0b2f22 50
7f0c3a63 51#include <ToolUtils.h>
dd49c691 52
eab19a7c
RN
53//For targeting OSX
54#include "wx/mac/private.h"
55
a15eb0a5
SC
56// ----------------------------------------------------------------------------
57// globals
58// ----------------------------------------------------------------------------
59
60// list of all frames and modeless dialogs
32b5be3d
RR
61wxWindowList wxModelessWindows;
62
6a7e6411
RD
63static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);
64
a15eb0a5
SC
65// ============================================================================
66// wxTopLevelWindowMac implementation
67// ============================================================================
68
facd6764
SC
69BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase)
70END_EVENT_TABLE()
71
72
851b3a88
SC
73// ---------------------------------------------------------------------------
74// Carbon Events
75// ---------------------------------------------------------------------------
76
851b3a88
SC
77extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
78
1542ea39 79static const EventTypeSpec eventList[] =
851b3a88 80{
facd6764 81 // TODO remove control related event like key and mouse (except for WindowLeave events)
949cb163 82#if 1
851b3a88 83 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
c5c9378c 84
e40298d5 85 { kEventClassKeyboard, kEventRawKeyDown } ,
c5c9378c
SC
86 { kEventClassKeyboard, kEventRawKeyRepeat } ,
87 { kEventClassKeyboard, kEventRawKeyUp } ,
88 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
facd6764 89#endif
c5c9378c 90
16a76184 91 { kEventClassWindow , kEventWindowShown } ,
851b3a88
SC
92 { kEventClassWindow , kEventWindowActivated } ,
93 { kEventClassWindow , kEventWindowDeactivated } ,
94 { kEventClassWindow , kEventWindowBoundsChanging } ,
95 { kEventClassWindow , kEventWindowBoundsChanged } ,
96 { kEventClassWindow , kEventWindowClose } ,
97
facd6764
SC
98 // we have to catch these events on the toplevel window level, as controls don't get the
99 // raw mouse events anymore
100
851b3a88
SC
101 { kEventClassMouse , kEventMouseDown } ,
102 { kEventClassMouse , kEventMouseUp } ,
de127c69 103 { kEventClassMouse , kEventMouseWheelMoved } ,
851b3a88
SC
104 { kEventClassMouse , kEventMouseMoved } ,
105 { kEventClassMouse , kEventMouseDragged } ,
851b3a88
SC
106} ;
107
108static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
109{
110 OSStatus result = eventNotHandledErr ;
851b3a88 111
c5c9378c 112 wxWindow* focus = wxWindow::FindFocus() ;
e40298d5 113 char charCode ;
1542ea39 114 UInt32 keyCode ;
c5c9378c 115 UInt32 modifiers ;
e40298d5 116 Point point ;
c5c9378c
SC
117
118 EventRef rawEvent ;
1542ea39 119
c5c9378c 120 GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
1542ea39 121
e40298d5
JS
122 GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
123 GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
124 GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
125 GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL,
126 sizeof( Point ), NULL, &point );
127
e40298d5
JS
128 switch ( GetEventKind( event ) )
129 {
130 case kEventTextInputUnicodeForKeyEvent :
ace07c80 131 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
5d2e69e8 132 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
ace07c80
SC
133 wxControl* control = wxDynamicCast( focus , wxControl ) ;
134 if ( control )
135 {
facd6764 136 ControlRef macControl = (ControlRef) control->GetHandle() ;
ace07c80
SC
137 if ( macControl )
138 {
139 ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ;
140 result = noErr ;
141 }
142 }
143 /*
144 // this may lead to double events sent to a window in case all handlers have skipped the key down event
77a4354e
VZ
145 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
146 UInt32 message = (keyCode << 8) + charCode;
147
1542ea39 148 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
e40298d5
JS
149 focus , message , modifiers , when , point.h , point.v ) )
150 {
151 result = noErr ;
152 }
ace07c80 153 */
e40298d5
JS
154 break ;
155 }
c5c9378c
SC
156
157 return result ;
158}
159
160static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
161{
162 OSStatus result = eventNotHandledErr ;
b3bd613a
RR
163 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
164 // FindFocus does not return the actual focus window,but the enclosing window
165 wxWindow* focus = wxWindow::DoFindFocus();
92a7272f
SC
166 if ( focus == NULL )
167 return result ;
168
e40298d5 169 char charCode ;
1542ea39 170 UInt32 keyCode ;
c5c9378c 171 UInt32 modifiers ;
e40298d5
JS
172 Point point ;
173 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
174
175 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
176 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
177 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
178 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
179 sizeof( Point ), NULL, &point );
180
181 UInt32 message = (keyCode << 8) + charCode;
182 switch( GetEventKind( event ) )
183 {
184 case kEventRawKeyRepeat :
185 case kEventRawKeyDown :
e40298d5 186 {
404f1d80
SC
187 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
188 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
189 wxTheApp->MacSetCurrentEvent( event , handler ) ;
190 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
191 focus , message , modifiers , when , point.h , point.v ) )
192 {
193 result = noErr ;
194 }
195 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
e40298d5
JS
196 }
197 break ;
198 case kEventRawKeyUp :
1542ea39 199 if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
e40298d5
JS
200 focus , message , modifiers , when , point.h , point.v ) )
201 {
202 result = noErr ;
203 }
204 break ;
205 case kEventRawKeyModifiersChanged :
206 {
207 wxKeyEvent event(wxEVT_KEY_DOWN);
208
209 event.m_shiftDown = modifiers & shiftKey;
210 event.m_controlDown = modifiers & controlKey;
211 event.m_altDown = modifiers & optionKey;
212 event.m_metaDown = modifiers & cmdKey;
213
214 event.m_x = point.h;
215 event.m_y = point.v;
687706f5 216 event.SetTimestamp(when);
e40298d5
JS
217 event.SetEventObject(focus);
218
8d60dc8a 219 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
e40298d5
JS
220 {
221 event.m_keyCode = WXK_CONTROL ;
222 event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
223 focus->GetEventHandler()->ProcessEvent( event ) ;
224 }
8d60dc8a 225 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
e40298d5
JS
226 {
227 event.m_keyCode = WXK_SHIFT ;
228 event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
229 focus->GetEventHandler()->ProcessEvent( event ) ;
230 }
8d60dc8a 231 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
e40298d5
JS
232 {
233 event.m_keyCode = WXK_ALT ;
234 event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
235 focus->GetEventHandler()->ProcessEvent( event ) ;
236 }
b7aec135
SC
237 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey )
238 {
239 event.m_keyCode = WXK_COMMAND ;
240 event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
241 focus->GetEventHandler()->ProcessEvent( event ) ;
242 }
e40298d5
JS
243 wxTheApp->s_lastModifiers = modifiers ;
244 }
245 break ;
246 }
851b3a88
SC
247
248 return result ;
249}
250
facd6764
SC
251// we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
252// for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
253// mouse down at all
851b3a88 254
facd6764 255// This handler can also be called from app level where data (ie target window) may be null or a non wx window
1542ea39 256
facd6764 257wxWindow* g_MacLastWindow = NULL ;
a3195b73 258
86a9144f
SC
259static EventMouseButton lastButton = 0 ;
260
facd6764
SC
261static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
262{
263 UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ;
264 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
67245665 265
facd6764
SC
266 // this parameter are not given for all events
267 EventMouseButton button = 0 ;
268 UInt32 clickCount = 0 ;
269 cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ;
270 cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ;
271
272 wxevent.m_x = screenMouseLocation.h;
273 wxevent.m_y = screenMouseLocation.v;
274 wxevent.m_shiftDown = modifiers & shiftKey;
275 wxevent.m_controlDown = modifiers & controlKey;
276 wxevent.m_altDown = modifiers & optionKey;
277 wxevent.m_metaDown = modifiers & cmdKey;
278 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
279 // a control click is interpreted as a right click
280 if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
851b3a88 281 {
facd6764
SC
282 button = kEventMouseButtonSecondary ;
283 }
86a9144f
SC
284
285 // we must make sure that our synthetic 'right' button corresponds in
286 // mouse down, moved and mouse up, and does not deliver a right down and left up
287
288 if ( cEvent.GetKind() == kEventMouseDown )
289 lastButton = button ;
4e4e6dce
SC
290
291 if ( button == 0 )
292 lastButton = 0 ;
86a9144f
SC
293 else if ( lastButton )
294 button = lastButton ;
facd6764
SC
295
296 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
297 // this button
298 if ( button != 0 && cEvent.GetKind() != kEventMouseUp )
299 {
300 switch( button )
e40298d5 301 {
facd6764
SC
302 case kEventMouseButtonPrimary :
303 wxevent.m_leftDown = true ;
e40298d5 304 break ;
facd6764
SC
305 case kEventMouseButtonSecondary :
306 wxevent.m_rightDown = true ;
e40298d5 307 break ;
facd6764
SC
308 case kEventMouseButtonTertiary :
309 wxevent.m_middleDown = true ;
e40298d5 310 break ;
facd6764
SC
311 }
312 }
90ff87d7
SC
313 // translate into wx types
314 switch ( cEvent.GetKind() )
facd6764 315 {
90ff87d7
SC
316 case kEventMouseDown :
317 switch( button )
318 {
319 case kEventMouseButtonPrimary :
320 wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
321 break ;
322 case kEventMouseButtonSecondary :
323 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
324 break ;
325 case kEventMouseButtonTertiary :
326 wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
327 break ;
328 }
329 break ;
330 case kEventMouseUp :
331 switch( button )
332 {
333 case kEventMouseButtonPrimary :
334 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
335 break ;
336 case kEventMouseButtonSecondary :
337 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
338 break ;
339 case kEventMouseButtonTertiary :
340 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
341 break ;
342 }
343 break ;
2cce9b11
JS
344 case kEventMouseWheelMoved :
345 {
facd6764
SC
346 wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ;
347
348 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
349 SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ;
350
351 wxevent.m_wheelRotation = delta;
352 wxevent.m_wheelDelta = 1;
353 wxevent.m_linesPerAction = 1;
90ff87d7 354 break ;
2cce9b11 355 }
90ff87d7 356 default :
facd6764 357 wxevent.SetEventType(wxEVT_MOTION ) ;
90ff87d7
SC
358 break ;
359 }
facd6764
SC
360}
361
789ae0cf 362ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, Point location , ControlRef superControl , ControlPartCode *outPart )
facd6764
SC
363{
364 if ( superControl )
365 {
366 UInt16 childrenCount = 0 ;
367 OSStatus err = CountSubControls( superControl , &childrenCount ) ;
368 if ( err == errControlIsNotEmbedder )
369 return NULL ;
370 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
371
372 for ( UInt16 i = childrenCount ; i >=1 ; --i )
373 {
374 ControlHandle sibling ;
375 err = GetIndexedSubControl( superControl , i , & sibling ) ;
376 if ( err == errControlIsNotEmbedder )
377 return NULL ;
378
379 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
380 if ( IsControlVisible( sibling ) )
381 {
382 Rect r ;
d6fd667b 383 UMAGetControlBoundsInWindowCoords( sibling , &r ) ;
facd6764 384 if ( MacPtInRect( location , &r ) )
de127c69 385 {
789ae0cf 386 ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ;
facd6764
SC
387 if ( child )
388 return child ;
389 else
de127c69 390 {
d6fd667b 391 Point testLocation = location ;
789ae0cf
SC
392
393 if ( toplevelWindow && toplevelWindow->MacUsesCompositing() )
394 {
395 testLocation.h -= r.left ;
396 testLocation.v -= r.top ;
397 }
398
d6fd667b 399 *outPart = TestControl( sibling , testLocation ) ;
facd6764 400 return sibling ;
de127c69
GD
401 }
402 }
facd6764 403 }
e40298d5
JS
404 }
405 }
facd6764
SC
406 return NULL ;
407}
1542ea39 408
789ae0cf 409ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow , Point location , WindowRef window , ControlPartCode *outPart )
facd6764
SC
410{
411#if TARGET_API_MAC_OSX
789ae0cf 412 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow == 0 || toplevelWindow->MacUsesCompositing() ) )
30e0b1c9
SC
413 return FindControlUnderMouse( location , window , outPart ) ;
414#endif
facd6764
SC
415 ControlRef rootControl = NULL ;
416 verify_noerr( GetRootControl( window , &rootControl ) ) ;
789ae0cf 417 return wxMacFindSubControl( toplevelWindow , location , rootControl , outPart ) ;
30e0b1c9 418
facd6764
SC
419}
420pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
421{
789ae0cf 422 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
facd6764
SC
423
424 OSStatus result = eventNotHandledErr ;
425
426 wxMacCarbonEvent cEvent( event ) ;
427
428 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
429 Point windowMouseLocation = screenMouseLocation ;
430
431 WindowRef window ;
432 short windowPart = ::FindWindow(screenMouseLocation, &window);
433
434 wxWindow* currentMouseWindow = NULL ;
d88ffaaa
SC
435 ControlRef control = NULL ;
436
facd6764
SC
437 if ( window )
438 {
d6fd667b 439 QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ;
facd6764
SC
440
441 if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent )
442 {
443 currentMouseWindow = wxTheApp->s_captureWindow ;
444 }
445 else if ( (IsWindowActive(window) && windowPart == inContent) )
446 {
447 ControlPartCode part ;
789ae0cf 448 control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ;
d88ffaaa 449 // if there is no control below the mouse position, send the event to the toplevel window itself
b19bf058
SC
450 if ( control == 0 )
451 currentMouseWindow = (wxWindow*) data ;
452 else
b16f4bfa 453 {
b19bf058 454 currentMouseWindow = wxFindControlFromMacControl( control ) ;
8198ae50 455 if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved )
b16f4bfa 456 {
179e085f 457#if wxUSE_TOOLBAR
b16f4bfa
SC
458 // for wxToolBar to function we have to send certaint events to it
459 // instead of its children (wxToolBarTools)
460 ControlRef parent ;
461 GetSuperControl(control, &parent );
462 wxWindow *wxParent = wxFindControlFromMacControl( parent ) ;
463 if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) )
464 currentMouseWindow = wxParent ;
179e085f 465#endif
b16f4bfa
SC
466 }
467 }
facd6764
SC
468 }
469 }
d88ffaaa 470
facd6764
SC
471 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
472 SetupMouseEvent( wxevent , cEvent ) ;
473
474 // handle all enter / leave events
475
476 if ( currentMouseWindow != g_MacLastWindow )
477 {
478 if ( g_MacLastWindow )
479 {
480 wxMouseEvent eventleave(wxevent);
481 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
482 g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
483 eventleave.SetEventObject( g_MacLastWindow ) ;
484
485#if wxUSE_TOOLTIPS
486 wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
487#endif // wxUSE_TOOLTIPS
488 g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave);
489 }
490 if ( currentMouseWindow )
491 {
492 wxMouseEvent evententer(wxevent);
493 evententer.SetEventType( wxEVT_ENTER_WINDOW );
494 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
495 evententer.SetEventObject( currentMouseWindow ) ;
496#if wxUSE_TOOLTIPS
497 wxToolTip::RelayEvent( currentMouseWindow , evententer);
498#endif // wxUSE_TOOLTIPS
499 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
500 }
501 g_MacLastWindow = currentMouseWindow ;
502 }
503
504 if ( windowPart == inMenuBar )
505 {
506 // special case menu bar, as we are having a low-level runloop we must do it ourselves
507 if ( cEvent.GetKind() == kEventMouseDown )
508 {
509 ::MenuSelect( screenMouseLocation ) ;
510 result = noErr ;
511 }
512 } // if ( windowPart == inMenuBar )
513 else if ( currentMouseWindow )
514 {
e10e9469 515 wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
62ade180
RR
516
517 currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
facd6764
SC
518
519 wxevent.SetEventObject( currentMouseWindow ) ;
520
facd6764
SC
521 // make tooltips current
522
523 #if wxUSE_TOOLTIPS
524 if ( wxevent.GetEventType() == wxEVT_MOTION
525 || wxevent.GetEventType() == wxEVT_ENTER_WINDOW
526 || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW )
527 wxToolTip::RelayEvent( currentMouseWindow , wxevent);
528 #endif // wxUSE_TOOLTIPS
529 if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
62ade180
RR
530 {
531 if ((currentMouseWindowParent != NULL) &&
532 (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
533 currentMouseWindow = NULL;
534
facd6764 535 result = noErr;
62ade180 536 }
30e0b1c9
SC
537 else
538 {
f90387b4
VZ
539 // if the user code did _not_ handle the event, then perform the
540 // default processing
541 if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
542 {
543 // ... that is set focus to this window
544 if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow)
545 currentMouseWindow->SetFocus();
546 }
547
30e0b1c9
SC
548 ControlPartCode dummyPart ;
549 // if built-in find control is finding the wrong control (ie static box instead of overlaid
550 // button, we cannot let the standard handler do its job, but must handle manually
551
23ad132c
SC
552 if ( ( cEvent.GetKind() == kEventMouseDown )
553#ifdef __WXMAC_OSX__
554 &&
30e0b1c9 555 (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) !=
789ae0cf 556 wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) )
23ad132c
SC
557#endif
558 )
30e0b1c9 559 {
7ce1a4e1
SC
560 if ( currentMouseWindow->MacIsReallyEnabled() )
561 {
562 EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
563 Point clickLocation = windowMouseLocation ;
789ae0cf
SC
564
565 if ( toplevelWindow->MacUsesCompositing() )
566 currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ;
567
7ce1a4e1
SC
568 HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation ,
569 modifiers , (ControlActionUPP ) -1 ) ;
e10e9469 570
62ade180
RR
571 if ((currentMouseWindowParent != NULL) &&
572 (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
e10e9469 573 currentMouseWindow = NULL;
7ce1a4e1 574 }
30e0b1c9
SC
575 result = noErr ;
576 }
577 }
facd6764
SC
578 if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow )
579 {
580 wxTheApp->s_captureWindow = NULL ;
581 // update cursor ?
582 }
6d63e2fc
SC
583
584 // update cursor
585
586 wxWindow* cursorTarget = currentMouseWindow ;
587 wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
588
589 while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
590 {
591 cursorTarget = cursorTarget->GetParent() ;
592 if ( cursorTarget )
e10e9469 593 cursorPoint += cursorTarget->GetPosition();
6d63e2fc
SC
594 }
595
facd6764 596 } // else if ( currentMouseWindow )
d88ffaaa
SC
597 else
598 {
599 // don't mess with controls we don't know about
600 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
601 // so we try sending them the correct control directly
e4b7e0b4 602 if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control )
d88ffaaa
SC
603 {
604 EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
605 Point clickLocation = windowMouseLocation ;
789ae0cf
SC
606 if ( toplevelWindow->MacUsesCompositing() )
607 {
608#ifdef __WXMAC_OSX__
609 HIPoint hiPoint ;
610 hiPoint.x = clickLocation.h ;
611 hiPoint.y = clickLocation.v ;
612 HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ;
613 clickLocation.h = (int)hiPoint.x ;
614 clickLocation.v = (int)hiPoint.y ;
d88ffaaa 615#endif
789ae0cf 616 }
d88ffaaa
SC
617 HandleControlClick( control , clickLocation ,
618 modifiers , (ControlActionUPP ) -1 ) ;
619 result = noErr ;
620 }
621 }
facd6764 622 return result ;
851b3a88 623}
facd6764
SC
624
625static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
851b3a88
SC
626{
627 OSStatus result = eventNotHandledErr ;
851b3a88 628
facd6764
SC
629 wxMacCarbonEvent cEvent( event ) ;
630
631 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
e40298d5 632 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
1542ea39 633
e40298d5
JS
634 switch( GetEventKind( event ) )
635 {
e40298d5 636 case kEventWindowActivated :
facd6764
SC
637 {
638 toplevelWindow->MacActivate( cEvent.GetTicks() , true) ;
facd6764
SC
639 wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId());
640 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
641 wxevent.SetEventObject(toplevelWindow);
642 toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
73fe67bd 643 // we still sending an eventNotHandledErr in order to allow for default processing
e40298d5 644 break ;
facd6764 645 }
e40298d5 646 case kEventWindowDeactivated :
facd6764
SC
647 {
648 toplevelWindow->MacActivate(cEvent.GetTicks() , false) ;
649 wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId());
650 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
651 wxevent.SetEventObject(toplevelWindow);
652 toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
73fe67bd 653 // we still sending an eventNotHandledErr in order to allow for default processing
e40298d5 654 break ;
facd6764 655 }
16a76184
SC
656 case kEventWindowShown :
657 toplevelWindow->Refresh() ;
658 result = noErr ;
659 break ;
e40298d5
JS
660 case kEventWindowClose :
661 toplevelWindow->Close() ;
662 result = noErr ;
663 break ;
664 case kEventWindowBoundsChanged :
facd6764
SC
665 {
666 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
667 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
668 wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
669 if ( attributes & kWindowBoundsChangeSizeChanged )
e40298d5 670 {
facd6764
SC
671 // according to the other ports we handle this within the OS level
672 // resize event, not within a wxSizeEvent
673 wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ;
674 if ( frame )
675 {
676 #if wxUSE_STATUSBAR
677 frame->PositionStatusBar();
678 #endif
679 #if wxUSE_TOOLBAR
680 frame->PositionToolBar();
681 #endif
682 }
1542ea39 683
facd6764
SC
684 wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
685 event.SetEventObject( toplevelWindow ) ;
851b3a88 686
facd6764 687 toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
e40298d5 688 }
facd6764
SC
689 if ( attributes & kWindowBoundsChangeOriginChanged )
690 {
691 wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ;
692 event.SetEventObject( toplevelWindow ) ;
693 toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
694 }
695 result = noErr ;
e40298d5 696 break ;
facd6764 697 }
f81bfef9 698 case kEventWindowBoundsChanging :
facd6764
SC
699 {
700 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
701 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
83901ec2 702
facd6764
SC
703 if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) )
704 {
29281095
SC
705 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
706 int left , top , right , bottom ;
707 toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ;
708 wxRect r( newRect.left - left , newRect.top - top ,
709 newRect.right - newRect.left + left + right , newRect.bottom - newRect.top + top + bottom ) ;
facd6764
SC
710 // this is a EVT_SIZING not a EVT_SIZE type !
711 wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ;
712 wxevent.SetEventObject( toplevelWindow ) ;
713 wxRect adjustR = r ;
714 if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) )
facd6764 715 adjustR = wxevent.GetRect() ;
29281095 716
facd6764
SC
717 if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() )
718 adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ;
2c25bd55 719 if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() )
facd6764
SC
720 adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ;
721 if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() )
722 adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ;
2c25bd55 723 if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() )
facd6764 724 adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ;
4a5f2351 725 const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ;
facd6764 726 if ( !EqualRect( &newRect , &adjustedRect ) )
1f919f38 727 cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ;
f81bfef9 728 }
facd6764 729
789ae0cf 730 result = noErr ;
f81bfef9 731 break ;
facd6764 732 }
e40298d5
JS
733 default :
734 break ;
735 }
736 return result ;
851b3a88
SC
737}
738
facd6764 739pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
851b3a88
SC
740{
741 OSStatus result = eventNotHandledErr ;
742
743 switch ( GetEventClass( event ) )
744 {
c5c9378c 745 case kEventClassKeyboard :
e40298d5 746 result = KeyboardEventHandler( handler, event , data ) ;
c5c9378c 747 break ;
851b3a88 748 case kEventClassTextInput :
e40298d5 749 result = TextInputEventHandler( handler, event , data ) ;
851b3a88
SC
750 break ;
751 case kEventClassWindow :
facd6764 752 result = wxMacTopLevelWindowEventHandler( handler, event , data ) ;
e40298d5 753 break ;
851b3a88 754 case kEventClassMouse :
facd6764 755 result = wxMacTopLevelMouseEventHandler( handler, event , data ) ;
e40298d5 756 break ;
851b3a88
SC
757 default :
758 break ;
759 }
760 return result ;
761}
762
facd6764 763DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler )
851b3a88 764
5f0b2f22
SC
765// ---------------------------------------------------------------------------
766// wxWindowMac utility functions
767// ---------------------------------------------------------------------------
768
769// Find an item given the Macintosh Window Reference
770
71f2fb52 771#if KEY_wxList_DEPRECATED
facd6764
SC
772wxList wxWinMacWindowList(wxKEY_INTEGER);
773wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
5f0b2f22 774{
facd6764 775 wxNode *node = wxWinMacWindowList.Find((long)inWindowRef);
5f0b2f22
SC
776 if (!node)
777 return NULL;
eb22f2a6 778 return (wxTopLevelWindowMac *)node->GetData();
5f0b2f22
SC
779}
780
facd6764
SC
781void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
782void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
5f0b2f22
SC
783{
784 // adding NULL WindowRef is (first) surely a result of an error and
785 // (secondly) breaks menu command processing
427ff662 786 wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
5f0b2f22 787
facd6764
SC
788 if ( !wxWinMacWindowList.Find((long)inWindowRef) )
789 wxWinMacWindowList.Append((long)inWindowRef, win);
5f0b2f22
SC
790}
791
facd6764 792void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
5f0b2f22
SC
793void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
794{
facd6764 795 wxWinMacWindowList.DeleteObject(win);
5f0b2f22 796}
71f2fb52 797#else
5f0b2f22 798
71f2fb52
RN
799WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap);
800
801static MacWindowMap wxWinMacWindowList;
802
803wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
804{
805 MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
806
807 return (node == wxWinMacWindowList.end()) ? NULL : node->second;
808}
809
810void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
811void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
812{
813 // adding NULL WindowRef is (first) surely a result of an error and
814 // nothing else :-)
815 wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
816
817 wxWinMacWindowList[inWindowRef] = win;
818}
819
820void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
821void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
822{
823 MacWindowMap::iterator it;
824 for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
825 {
826 if ( it->second == win )
827 {
828 wxWinMacWindowList.erase(it);
829 break;
830 }
831 }
832}
833#endif // deprecated wxList
5f0b2f22 834
a15eb0a5
SC
835// ----------------------------------------------------------------------------
836// wxTopLevelWindowMac creation
837// ----------------------------------------------------------------------------
838
245f3581 839wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
5f0b2f22 840
c5985061
SC
841typedef struct
842{
843 wxPoint m_position ;
844 wxSize m_size ;
845} FullScreenData ;
846
a15eb0a5
SC
847void wxTopLevelWindowMac::Init()
848{
849 m_iconized =
850 m_maximizeOnShow = FALSE;
6a17ca35 851 m_macWindow = NULL ;
facd6764 852#if TARGET_API_MAC_OSX
789ae0cf
SC
853 if ( UMAGetSystemVersion() >= 0x1030 )
854 {
855 m_macUsesCompositing = TRUE;
856 }
857 else
facd6764 858#endif
789ae0cf
SC
859 {
860 m_macUsesCompositing = FALSE;
861 }
7c091673 862 m_macEventHandler = NULL ;
c5985061 863 m_macFullScreenData = NULL ;
a15eb0a5
SC
864}
865
118f012e
SC
866class wxMacDeferredWindowDeleter : public wxObject
867{
868public :
1542ea39
RD
869 wxMacDeferredWindowDeleter( WindowRef windowRef )
870 {
871 m_macWindow = windowRef ;
118f012e 872 }
1542ea39
RD
873 virtual ~wxMacDeferredWindowDeleter()
874 {
875 UMADisposeWindow( (WindowRef) m_macWindow ) ;
118f012e
SC
876 }
877 protected :
878 WindowRef m_macWindow ;
879} ;
880
a15eb0a5
SC
881bool wxTopLevelWindowMac::Create(wxWindow *parent,
882 wxWindowID id,
883 const wxString& title,
884 const wxPoint& pos,
885 const wxSize& size,
886 long style,
887 const wxString& name)
888{
889 // init our fields
890 Init();
891
892 m_windowStyle = style;
893
894 SetName(name);
895
896 m_windowId = id == -1 ? NewControlId() : id;
c2bc1e2a 897 wxWindow::SetTitle( title ) ;
a15eb0a5 898
facd6764
SC
899 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
900
94d1d0f4
SC
901 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
902
a15eb0a5
SC
903 wxTopLevelWindows.Append(this);
904
905 if ( parent )
906 parent->AddChild(this);
907
908 return TRUE;
909}
910
911wxTopLevelWindowMac::~wxTopLevelWindowMac()
912{
6a17ca35
SC
913 if ( m_macWindow )
914 {
915 wxToolTip::NotifyWindowDelete(m_macWindow) ;
118f012e 916 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
6a17ca35 917 }
1542ea39 918
7c091673
SC
919 if ( m_macEventHandler )
920 {
921 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
922 m_macEventHandler = NULL ;
923 }
851b3a88 924
5f0b2f22
SC
925 wxRemoveMacWindowAssociation( this ) ;
926
a15eb0a5
SC
927 if ( wxModelessWindows.Find(this) )
928 wxModelessWindows.DeleteObject(this);
c5985061
SC
929
930 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
931 delete data ;
932 m_macFullScreenData = NULL ;
a15eb0a5
SC
933}
934
935
936// ----------------------------------------------------------------------------
937// wxTopLevelWindowMac maximize/minimize
938// ----------------------------------------------------------------------------
939
940void wxTopLevelWindowMac::Maximize(bool maximize)
941{
1f90939c
SC
942 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
943 wxMacWindowClipper clip (this);
b7aec135 944 ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ;
a15eb0a5
SC
945}
946
947bool wxTopLevelWindowMac::IsMaximized() const
948{
b7aec135 949 return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;
a15eb0a5
SC
950}
951
952void wxTopLevelWindowMac::Iconize(bool iconize)
953{
b7aec135
SC
954 if ( IsWindowCollapsable((WindowRef)m_macWindow) )
955 CollapseWindow((WindowRef)m_macWindow , iconize ) ;
a15eb0a5
SC
956}
957
958bool wxTopLevelWindowMac::IsIconized() const
959{
b7aec135 960 return IsWindowCollapsed((WindowRef)m_macWindow ) ;
a15eb0a5
SC
961}
962
963void wxTopLevelWindowMac::Restore()
964{
965 // not available on mac
966}
967
968// ----------------------------------------------------------------------------
969// wxTopLevelWindowMac misc
970// ----------------------------------------------------------------------------
971
facd6764
SC
972wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const
973{
974 return wxPoint(0,0) ;
975}
976
a15eb0a5
SC
977void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
978{
979 // this sets m_icon
980 wxTopLevelWindowBase::SetIcon(icon);
981}
5f0b2f22 982
facd6764
SC
983void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
984{
985 wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ;
986
987 if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme )
988 {
989 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ;
990 }
991}
992
949cb163
SC
993void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
994{
995 if ( m_macEventHandler != NULL )
996 {
997 verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;
998 }
999 InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(),
1000 GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler);
1001}
1002
5f0b2f22
SC
1003void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
1004 const wxPoint& pos,
1005 const wxSize& size,
1006 long style,
1542ea39 1007 const wxString& name )
5f0b2f22 1008{
47ac4f9b 1009 OSStatus err = noErr ;
e40298d5
JS
1010 SetName(name);
1011 m_windowStyle = style;
1012 m_isShown = FALSE;
1542ea39 1013
e40298d5 1014 // create frame.
1542ea39 1015
5f0b2f22 1016 Rect theBoundsRect;
1542ea39 1017
facd6764
SC
1018 int x = (int)pos.x;
1019 int y = (int)pos.y;
5a486641
SC
1020
1021 wxRect display = wxGetClientDisplayRect() ;
1022
1023 if ( x == wxDefaultPosition.x )
1024 x = display.x ;
1025
1026 if ( y == wxDefaultPosition.y )
1027 y = display.y ;
1542ea39 1028
facd6764
SC
1029 int w = WidthDefault(size.x);
1030 int h = HeightDefault(size.y);
1542ea39 1031
facd6764 1032 ::SetRect(&theBoundsRect, x, y , x + w, y + h);
1542ea39 1033
5f0b2f22 1034 // translate the window attributes in the appropriate window class and attributes
1542ea39 1035
5f0b2f22
SC
1036 WindowClass wclass = 0;
1037 WindowAttributes attr = kWindowNoAttributes ;
e353795e 1038 WindowGroupRef group = NULL ;
1542ea39 1039
f5744893 1040 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
5f0b2f22 1041 {
1542ea39 1042 if (
f5744893
SC
1043 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
1044 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
1045 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
e40298d5 1046 )
5f0b2f22 1047 {
f5744893
SC
1048 wclass = kFloatingWindowClass ;
1049 if ( HasFlag(wxTINY_CAPTION_VERT) )
1050 {
1051 attr |= kWindowSideTitlebarAttribute ;
1052 }
1053 }
1054 else
1055 {
1056 wclass = kPlainWindowClass ;
5f0b2f22
SC
1057 }
1058 }
1059 else if ( HasFlag( wxCAPTION ) )
1060 {
1542ea39 1061 wclass = kDocumentWindowClass ;
5f0b2f22 1062 }
eab19a7c 1063#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
3e17bc3f
RN
1064 else if ( HasFlag( wxFRAME_DRAWER ) )
1065 {
1066 wclass = kDrawerWindowClass;
789ae0cf
SC
1067 // we must force compositing on a drawer
1068 m_macUsesCompositing = TRUE ;
3e17bc3f
RN
1069 }
1070#endif //10.2 and up
5f0b2f22
SC
1071 else
1072 {
f5744893 1073 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
47ac4f9b 1074 HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )
f5744893
SC
1075 {
1076 wclass = kDocumentWindowClass ;
1077 }
1078 else
1079 {
1080 wclass = kPlainWindowClass ;
1081 }
5f0b2f22 1082 }
1542ea39 1083
47ac4f9b 1084 if ( HasFlag( wxMINIMIZE_BOX ) )
5f0b2f22 1085 {
5f0b2f22
SC
1086 attr |= kWindowCollapseBoxAttribute ;
1087 }
47ac4f9b
SC
1088 if ( HasFlag( wxMAXIMIZE_BOX ) )
1089 {
1090 attr |= kWindowFullZoomAttribute ;
1091 }
5f0b2f22
SC
1092 if ( HasFlag( wxRESIZE_BORDER ) )
1093 {
1094 attr |= kWindowResizableAttribute ;
1095 }
47ac4f9b 1096 if ( HasFlag( wxCLOSE_BOX) )
5f0b2f22
SC
1097 {
1098 attr |= kWindowCloseBoxAttribute ;
1099 }
1542ea39 1100
eb630bf1
DS
1101 if (UMAGetSystemVersion() >= 0x1000)
1102 {
facd6764 1103 // turn on live resizing (OS X only)
eb630bf1
DS
1104 attr |= kWindowLiveResizeAttribute;
1105 }
1106
e353795e
SC
1107 if ( HasFlag(wxSTAY_ON_TOP) )
1108 {
1109 group = GetWindowGroupOfClass(kUtilityWindowClass) ;
1110 }
6a7e6411 1111
facd6764 1112#if TARGET_API_MAC_OSX
789ae0cf
SC
1113 if ( m_macUsesCompositing )
1114 attr |= kWindowCompositingAttribute;
d66c3960 1115#endif
1f90939c 1116
6a7e6411
RD
1117 if ( HasFlag(wxFRAME_SHAPED) )
1118 {
1119 WindowDefSpec customWindowDefSpec;
1120 customWindowDefSpec.defType = kWindowDefProcPtr;
1121 customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);
1122
47ac4f9b 1123 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
6a7e6411
RD
1124 attr, &theBoundsRect,
1125 (WindowRef*) &m_macWindow);
1126 }
1127 else
1128 {
47ac4f9b 1129 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
6a7e6411
RD
1130 }
1131
e353795e
SC
1132 if ( err == noErr && m_macWindow != NULL && group != NULL )
1133 SetWindowGroup( (WindowRef) m_macWindow , group ) ;
1134
47ac4f9b 1135 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
f83b6761
SC
1136
1137 // the create commands are only for content rect, so we have to set the size again as
1138 // structure bounds
1139 SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;
1140
facd6764
SC
1141 wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ;
1142 UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ;
1f1c8bd4 1143 m_peer = new wxMacControl(this , true /*isRootControl*/) ;
3a9dc061 1144#if TARGET_API_MAC_OSX
789ae0cf
SC
1145
1146 if ( m_macUsesCompositing )
f57d9215 1147 {
789ae0cf
SC
1148 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1149 // the content view, so we have to retrieve it explicitely
1150 HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID ,
1151 m_peer->GetControlRefAddr() ) ;
1152 if ( !m_peer->Ok() )
1153 {
1154 // compatibility mode fallback
1155 GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ;
1156 }
f57d9215 1157 }
3a9dc061 1158#endif
789ae0cf
SC
1159 {
1160 ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ;
1161 }
73fe67bd 1162 // the root control level handleer
5ca0d812 1163 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ;
facd6764 1164
73fe67bd 1165 // the frame window event handler
e40298d5 1166 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
949cb163 1167 MacInstallTopLevelWindowEventHandler() ;
b19bf058 1168
facd6764 1169 m_macFocus = NULL ;
6a7e6411
RD
1170
1171 if ( HasFlag(wxFRAME_SHAPED) )
1172 {
1173 // default shape matches the window size
facd6764 1174 wxRegion rgn(0, 0, w, h);
6a7e6411
RD
1175 SetShape(rgn);
1176 }
3dfafdb9
RD
1177
1178 wxWindowCreateEvent event(this);
1179 GetEventHandler()->ProcessEvent(event);
5f0b2f22
SC
1180}
1181
5d2e69e8 1182void wxTopLevelWindowMac::ClearBackground()
5f0b2f22 1183{
5d2e69e8 1184 wxWindow::ClearBackground() ;
5f0b2f22
SC
1185}
1186
5f0b2f22
SC
1187// Raise the window to the top of the Z order
1188void wxTopLevelWindowMac::Raise()
1189{
7f3c339c 1190 ::SelectWindow( (WindowRef)m_macWindow ) ;
5f0b2f22
SC
1191}
1192
1193// Lower the window to the bottom of the Z order
1194void wxTopLevelWindowMac::Lower()
1195{
76a5e5d2 1196 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
5f0b2f22
SC
1197}
1198
851b3a88 1199
245f3581
DE
1200void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp)
1201{
1202 if(s_macDeactivateWindow)
1203 {
365796b1 1204 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow);
245f3581
DE
1205 s_macDeactivateWindow->MacActivate(timestamp, false);
1206 }
1207}
1208
851b3a88 1209void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
5f0b2f22 1210{
17f8d2a7
VZ
1211 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1212
245f3581
DE
1213 if(s_macDeactivateWindow==this)
1214 s_macDeactivateWindow=NULL;
1215 MacDelayedDeactivation(timestamp);
8ab50549 1216 MacPropagateHiliteChanged() ;
5f0b2f22
SC
1217}
1218
1219void wxTopLevelWindowMac::SetTitle(const wxString& title)
1220{
1221 wxWindow::SetTitle( title ) ;
16a76184 1222 UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;
5f0b2f22
SC
1223}
1224
1225bool wxTopLevelWindowMac::Show(bool show)
1226{
facd6764 1227 if ( !wxTopLevelWindowBase::Show(show) )
5f0b2f22
SC
1228 return FALSE;
1229
1230 if (show)
1542ea39 1231 {
1f90939c
SC
1232 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1233 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )
1234 {
1235 ::ShowWindow( (WindowRef)m_macWindow );
1236 }
1237 else
1238 #endif
1239 {
1240 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil);
1241 }
1242 ::SelectWindow( (WindowRef)m_macWindow ) ;
facd6764
SC
1243 // as apps expect a size event to occur at this moment
1244 wxSizeEvent event( GetSize() , m_windowId);
1f90939c
SC
1245 event.SetEventObject(this);
1246 GetEventHandler()->ProcessEvent(event);
5f0b2f22
SC
1247 }
1248 else
1249 {
1f90939c
SC
1250 #if wxUSE_SYSTEM_OPTIONS
1251 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )
1252 {
1253 ::HideWindow((WindowRef) m_macWindow );
1254 }
1255 else
1256 #endif
1257 {
1258 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil);
1259 }
5f0b2f22
SC
1260 }
1261
facd6764 1262 MacPropagateVisibilityChanged() ;
5f0b2f22 1263
facd6764 1264 return TRUE ;
5f0b2f22
SC
1265}
1266
c5985061
SC
1267bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style)
1268{
1269 if ( show )
1270 {
1271 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
1272 delete data ;
1273 data = new FullScreenData() ;
1274
1275 m_macFullScreenData = data ;
1276 data->m_position = GetPosition() ;
1277 data->m_size = GetSize() ;
1278
1279 if ( style & wxFULLSCREEN_NOMENUBAR )
1280 {
1281 HideMenuBar() ;
1282 }
1283 int left , top , right , bottom ;
1284 wxRect client = wxGetClientDisplayRect() ;
1285
1286 int x, y, w, h ;
1287
1288 x = client.x ;
1289 y = client.y ;
1290 w = client.width ;
1291 h = client.height ;
1292
1293 MacGetContentAreaInset( left , top , right , bottom ) ;
1294
1295 if ( style & wxFULLSCREEN_NOCAPTION )
1296 {
1297 y -= top ;
1298 h += top ;
1299 }
1300 if ( style & wxFULLSCREEN_NOBORDER )
1301 {
1302 x -= left ;
1303 w += left + right ;
1304 h += bottom ;
1305 }
1306 if ( style & wxFULLSCREEN_NOTOOLBAR )
1307 {
3c86150d
SC
1308 // TODO
1309 }
1310 if ( style & wxFULLSCREEN_NOSTATUSBAR )
1311 {
1312 // TODO
c5985061
SC
1313 }
1314 SetSize( x , y , w, h ) ;
1315 }
1316 else
1317 {
1318 ShowMenuBar() ;
1319 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
1320 SetPosition( data->m_position ) ;
1321 SetSize( data->m_size ) ;
1322 delete data ;
1323 m_macFullScreenData = NULL ;
1324 }
1325 return FALSE;
1326}
1327
1328bool wxTopLevelWindowMac::IsFullScreen() const
1329{
1330 return m_macFullScreenData != NULL ;
1331}
1332
facd6764
SC
1333// we are still using coordinates of the content view, todo switch to structure bounds
1334
29281095
SC
1335void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1336{
1337 Rect content ;
1338 Rect structure ;
1339 GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ;
1340 GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ;
1341
1342 left = content.left - structure.left ;
1343 top = content.top - structure.top ;
1344 right = structure.right - content.right ;
1345 bottom = structure.bottom - content.bottom ;
1346}
1347
5f0b2f22
SC
1348void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
1349{
facd6764
SC
1350 Rect bounds = { y , x , y + height , x + width } ;
1351 verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
5f0b2f22
SC
1352}
1353
facd6764 1354void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const
5f0b2f22 1355{
facd6764
SC
1356 Rect bounds ;
1357 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1358 if(x) *x = bounds.left ;
1359 if(y) *y = bounds.top ;
1360}
1361void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const
1362{
1363 Rect bounds ;
1364 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1365 if(width) *width = bounds.right - bounds.left ;
1366 if(height) *height = bounds.bottom - bounds.top ;
1367}
1542ea39 1368
facd6764
SC
1369void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const
1370{
1371 Rect bounds ;
1372 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ;
1373 if(width) *width = bounds.right - bounds.left ;
1374 if(height) *height = bounds.bottom - bounds.top ;
1375}
1542ea39 1376
facd6764
SC
1377void wxTopLevelWindowMac::MacSetMetalAppearance( bool set )
1378{
1379#if TARGET_API_MAC_OSX
789ae0cf 1380 wxASSERT_MSG( m_macUsesCompositing ,
facd6764
SC
1381 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1382
1383 MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
1384 set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
1385#endif
1386}
1542ea39 1387
6aab345b
SC
1388bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1389{
1390#if TARGET_API_MAC_OSX
1391 return MacGetWindowAttributes() & kWindowMetalAttribute ;
1392#else
1393 return false ;
1394#endif
1395}
1396
facd6764
SC
1397void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
1398{
1399 ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ;
1400}
1542ea39 1401
facd6764
SC
1402wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const
1403{
1404 UInt32 attr = 0 ;
1405 GetWindowAttributes((WindowRef) m_macWindow , &attr ) ;
1406 return attr ;
5f0b2f22 1407}
a07c1212 1408
3feeb1e1
SC
1409// Attracts the users attention to this window if the application is
1410// inactive (should be called when a background event occurs)
1411
1412static pascal void wxMacNMResponse( NMRecPtr ptr )
1413{
1414 NMRemove( ptr ) ;
1415 DisposePtr( (Ptr) ptr ) ;
1416}
1417
1418
1419void wxTopLevelWindowMac::RequestUserAttention(int flags )
1420{
1421 NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
1422 static wxMacNMUPP nmupp( wxMacNMResponse )
1423 ;
1424 memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
1425 notificationRequest->qType = nmType ;
1426 notificationRequest->nmMark = 1 ;
1427 notificationRequest->nmIcon = 0 ;
1428 notificationRequest->nmSound = 0 ;
1429 notificationRequest->nmStr = NULL ;
1430 notificationRequest->nmResp = nmupp ;
1431 verify_noerr( NMInstall( notificationRequest ) ) ;
1432}
1433
facd6764
SC
1434// ---------------------------------------------------------------------------
1435// Shape implementation
1436// ---------------------------------------------------------------------------
1437
6a7e6411 1438
1542ea39
RD
1439bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
1440{
6a7e6411
RD
1441 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
1442 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1443
1444 // The empty region signifies that the shape should be removed from the
1445 // window.
1446 if ( region.IsEmpty() )
1447 {
1448 wxSize sz = GetClientSize();
1449 wxRegion rgn(0, 0, sz.x, sz.y);
1450 return SetShape(rgn);
1451 }
1452
1453 // Make a copy of the region
1454 RgnHandle shapeRegion = NewRgn();
1455 CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion );
1456
1457 // Dispose of any shape region we may already have
1458 RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() );
1459 if ( oldRgn )
1460 DisposeRgn(oldRgn);
1461
1462 // Save the region so we can use it later
1463 SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion);
1464
1465 // Tell the window manager that the window has changed shape
1466 ReshapeCustomWindow((WindowRef)MacGetWindowRef());
1467 return TRUE;
1468}
1469
6a7e6411
RD
1470// ---------------------------------------------------------------------------
1471// Support functions for shaped windows, based on Apple's CustomWindow sample at
1472// http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1473// ---------------------------------------------------------------------------
1474
6a7e6411
RD
1475static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
1476{
1477 GetWindowPortBounds(window, inRect);
1478 Point pt = {inRect->left, inRect->top};
d6fd667b 1479 QDLocalToGlobalPoint( GetWindowPort(window) , &pt ) ;
6a7e6411
RD
1480 inRect->top = pt.v;
1481 inRect->left = pt.h;
1482 inRect->bottom += pt.v;
1483 inRect->right += pt.h;
1484}
1485
1486
1487static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param)
1488{
1489 /*------------------------------------------------------
1490 Define which options your custom window supports.
1491 --------------------------------------------------------*/
1492 //just enable everything for our demo
1493 *(OptionBits*)param=//kWindowCanGrow|
1494 //kWindowCanZoom|
1495 //kWindowCanCollapse|
1496 //kWindowCanGetWindowRegion|
1497 //kWindowHasTitleBar|
1498 //kWindowSupportsDragHilite|
1499 kWindowCanDrawInCurrentPort|
1500 //kWindowCanMeasureTitle|
1501 kWindowWantsDisposeAtProcessDeath|
ae53adb4 1502 kWindowSupportsGetGrowImageRegion|
6a7e6411
RD
1503 kWindowDefSupportsColorGrafPort;
1504 return 1;
1542ea39 1505}
6a7e6411
RD
1506
1507// The content region is left as a rectangle matching the window size, this is
1508// so the origin in the paint event, and etc. still matches what the
1509// programmer expects.
1510static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
1511{
1512 SetEmptyRgn(rgn);
1513 wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window);
1514 if (win)
1515 {
b19bf058
SC
1516 Rect r ;
1517 wxShapedMacWindowGetPos(window, &r ) ;
1518 RectRgn( rgn , &r ) ;
6a7e6411
RD
1519 }
1520}
1521
1522// The structure region is set to the shape given to the SetShape method.
1523static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
1524{
1525 RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
1526
1527 SetEmptyRgn(rgn);
1528 if (cachedRegion)
1529 {
1530 Rect windowRect;
1531 wxShapedMacWindowGetPos(window, &windowRect); //how big is the window
1532 CopyRgn(cachedRegion, rgn); //make a copy of our cached region
1533 OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
1534 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1535 }
1536}
1537
1538
1539
1540static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
1541{
1542 GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param;
1543
1544 switch(rgnRec->regionCode)
1545 {
1546 case kWindowStructureRgn:
1547 wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
1548 break;
1549 case kWindowContentRgn:
1550 wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
1551 break;
1552 default:
1553 SetEmptyRgn(rgnRec->winRgn);
1554 } //switch
1555
1556 return noErr;
1557}
1558
1559
1560static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param)
1561{
1562 /*------------------------------------------------------
1563 Determine the region of the window which was hit
1564 --------------------------------------------------------*/
1565 Point hitPoint;
1566 static RgnHandle tempRgn=nil;
1567
1568 if(!tempRgn)
1569 tempRgn=NewRgn();
1570
1571 SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked
1572
1573 //Mac OS 8.5 or later
1574 wxShapedMacWindowStructureRegion(window, tempRgn);
1575 if (PtInRgn(hitPoint, tempRgn)) //in window content region?
1576 return wInContent;
1577
1578 return wNoHit;//no significant area was hit.
1579}
1580
1581
1582static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param)
1583{
1584 switch(message)
1585 {
1586 case kWindowMsgHitTest:
1587 return wxShapedMacWindowHitTest(window,param);
1588
1589 case kWindowMsgGetFeatures:
1590 return wxShapedMacWindowGetFeatures(window,param);
1591
1592 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1593 case kWindowMsgGetRegion:
1594 return wxShapedMacWindowGetRegion(window,param);
1595 }
1596
1597 return 0;
1598}
1925be65 1599
6a7e6411 1600// ---------------------------------------------------------------------------
1925be65 1601