1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
35 #include "wx/string.h"
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
43 #include "wx/tooltip.h"
46 #define wxMAC_DEBUG_REDRAW 0
47 #ifndef wxMAC_DEBUG_REDRAW
48 #define wxMAC_DEBUG_REDRAW 0
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // list of all frames and modeless dialogs
56 wxWindowList wxModelessWindows
;
58 // double click testing
59 static Point gs_lastWhere
;
60 static long gs_lastWhen
= 0;
62 // ============================================================================
63 // wxTopLevelWindowMac implementation
64 // ============================================================================
66 // ---------------------------------------------------------------------------
68 // ---------------------------------------------------------------------------
72 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
74 static const EventTypeSpec eventList
[] =
76 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
78 { kEventClassKeyboard
, kEventRawKeyDown
} ,
79 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
80 { kEventClassKeyboard
, kEventRawKeyUp
} ,
81 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
83 { kEventClassWindow
, kEventWindowUpdate
} ,
84 { kEventClassWindow
, kEventWindowActivated
} ,
85 { kEventClassWindow
, kEventWindowDeactivated
} ,
86 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
87 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
88 { kEventClassWindow
, kEventWindowClose
} ,
90 { kEventClassMouse
, kEventMouseDown
} ,
91 { kEventClassMouse
, kEventMouseUp
} ,
92 { kEventClassMouse
, kEventMouseMoved
} ,
93 { kEventClassMouse
, kEventMouseDragged
} ,
97 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
99 OSStatus result
= eventNotHandledErr
;
101 wxWindow
* focus
= wxWindow::FindFocus() ;
106 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
110 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
112 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
113 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
114 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
115 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
116 sizeof( Point
), NULL
, &point
);
118 UInt32 message
= (keyCode
<< 8) + charCode
;
120 switch ( GetEventKind( event
) )
122 case kEventTextInputUnicodeForKeyEvent
:
123 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
124 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
134 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
136 OSStatus result
= eventNotHandledErr
;
138 wxWindow
* focus
= wxWindow::FindFocus() ;
143 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
145 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
146 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
147 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
148 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
149 sizeof( Point
), NULL
, &point
);
151 UInt32 message
= (keyCode
<< 8) + charCode
;
152 switch( GetEventKind( event
) )
154 case kEventRawKeyRepeat
:
155 case kEventRawKeyDown
:
156 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
157 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
162 case kEventRawKeyUp
:
163 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyUpEvent(
164 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
169 case kEventRawKeyModifiersChanged
:
171 wxKeyEvent
event(wxEVT_KEY_DOWN
);
173 event
.m_shiftDown
= modifiers
& shiftKey
;
174 event
.m_controlDown
= modifiers
& controlKey
;
175 event
.m_altDown
= modifiers
& optionKey
;
176 event
.m_metaDown
= modifiers
& cmdKey
;
180 event
.m_timeStamp
= when
;
181 wxWindow
* focus
= wxWindow::FindFocus() ;
182 event
.SetEventObject(focus
);
184 if ( (modifiers
^ wxTheApp
->s_lastModifiers
) & controlKey
)
186 event
.m_keyCode
= WXK_CONTROL
;
187 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
188 focus
->GetEventHandler()->ProcessEvent( event
) ;
190 if ( (modifiers
^ wxTheApp
->s_lastModifiers
) & shiftKey
)
192 event
.m_keyCode
= WXK_SHIFT
;
193 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
194 focus
->GetEventHandler()->ProcessEvent( event
) ;
196 if ( (modifiers
^ wxTheApp
->s_lastModifiers
) & optionKey
)
198 event
.m_keyCode
= WXK_ALT
;
199 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
200 focus
->GetEventHandler()->ProcessEvent( event
) ;
202 wxTheApp
->s_lastModifiers
= modifiers
;
210 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
212 OSStatus result
= eventNotHandledErr
;
214 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
216 UInt32 modifiers
= 0;
217 EventMouseButton button
= 0 ;
220 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
221 sizeof( Point
), NULL
, &point
);
222 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
223 sizeof( UInt32
), NULL
, &modifiers
);
224 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
225 sizeof( EventMouseButton
), NULL
, &button
);
226 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
227 sizeof( UInt32
), NULL
, &click
);
229 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
230 modifiers
+= btnState
;
233 short windowPart
= ::FindWindow(point
, &window
);
235 if ( IsWindowActive(window
) && windowPart
== inContent
)
237 switch ( GetEventKind( event
) )
239 case kEventMouseDown
:
240 toplevelWindow
->MacFireMouseEvent( mouseDown
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
244 toplevelWindow
->MacFireMouseEvent( mouseUp
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
247 case kEventMouseMoved
:
248 toplevelWindow
->MacFireMouseEvent( nullEvent
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
251 case kEventMouseDragged
:
252 toplevelWindow
->MacFireMouseEvent( nullEvent
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
264 static pascal OSStatus
WindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
266 OSStatus result
= eventNotHandledErr
;
267 OSStatus err
= noErr
;
270 WindowRef windowRef
;
271 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
273 GetEventParameter( event
, kEventParamDirectObject
, typeWindowRef
, NULL
,
274 sizeof( WindowRef
), NULL
, &windowRef
);
276 switch( GetEventKind( event
) )
278 case kEventWindowUpdate
:
279 if ( !wxPendingDelete
.Member(toplevelWindow
) )
280 toplevelWindow
->MacUpdate( EventTimeToTicks( GetEventTime( event
) ) ) ;
283 case kEventWindowActivated
:
284 toplevelWindow
->MacActivate( EventTimeToTicks( GetEventTime( event
) ) , true) ;
287 case kEventWindowDeactivated
:
288 toplevelWindow
->MacActivate( EventTimeToTicks( GetEventTime( event
) ) , false) ;
291 case kEventWindowClose
:
292 toplevelWindow
->Close() ;
295 case kEventWindowBoundsChanged
:
296 err
= GetEventParameter( event
, kEventParamAttributes
, typeUInt32
,
297 NULL
, sizeof( UInt32
), NULL
, &attributes
);
300 Rect newContentRect
;
302 GetEventParameter( event
, kEventParamCurrentBounds
, typeQDRectangle
, NULL
,
303 sizeof( newContentRect
), NULL
, &newContentRect
);
305 toplevelWindow
->SetSize( newContentRect
.left
, newContentRect
.top
,
306 newContentRect
.right
- newContentRect
.left
,
307 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
318 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
320 OSStatus result
= eventNotHandledErr
;
322 switch ( GetEventClass( event
) )
324 case kEventClassKeyboard
:
325 result
= KeyboardEventHandler( handler
, event
, data
) ;
327 case kEventClassTextInput
:
328 result
= TextInputEventHandler( handler
, event
, data
) ;
330 case kEventClassWindow
:
331 result
= WindowEventHandler( handler
, event
, data
) ;
333 case kEventClassMouse
:
334 result
= MouseEventHandler( handler
, event
, data
) ;
342 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
346 // ---------------------------------------------------------------------------
347 // wxWindowMac utility functions
348 // ---------------------------------------------------------------------------
350 // Find an item given the Macintosh Window Reference
352 wxList
*wxWinMacWindowList
= NULL
;
353 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WXWindow inWindowRef
)
355 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
358 return (wxTopLevelWindowMac
*)node
->GetData();
361 void wxAssociateWinWithMacWindow(WXWindow inWindowRef
, wxTopLevelWindowMac
*win
)
363 // adding NULL WindowRef is (first) surely a result of an error and
364 // (secondly) breaks menu command processing
365 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
367 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
368 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
371 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
373 wxWinMacWindowList
->DeleteObject(win
);
377 // ----------------------------------------------------------------------------
378 // wxTopLevelWindowMac creation
379 // ----------------------------------------------------------------------------
381 WXHWND
wxTopLevelWindowMac::s_macWindowInUpdate
= NULL
;
383 void wxTopLevelWindowMac::Init()
386 m_maximizeOnShow
= FALSE
;
387 m_macNoEraseUpdateRgn
= NewRgn() ;
388 m_macNeedsErasing
= false ;
391 m_macEventHandler
= NULL
;
395 class wxMacDeferredWindowDeleter
: public wxObject
398 wxMacDeferredWindowDeleter( WindowRef windowRef
)
400 m_macWindow
= windowRef
;
402 virtual ~wxMacDeferredWindowDeleter()
404 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
407 WindowRef m_macWindow
;
410 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
412 const wxString
& title
,
416 const wxString
& name
)
421 m_windowStyle
= style
;
425 m_windowId
= id
== -1 ? NewControlId() : id
;
427 wxTopLevelWindows
.Append(this);
430 parent
->AddChild(this);
435 wxTopLevelWindowMac::~wxTopLevelWindowMac()
439 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
440 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
444 if ( m_macEventHandler
)
446 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
447 m_macEventHandler
= NULL
;
451 wxRemoveMacWindowAssociation( this ) ;
453 if ( wxModelessWindows
.Find(this) )
454 wxModelessWindows
.DeleteObject(this);
456 DisposeRgn( (RgnHandle
) m_macNoEraseUpdateRgn
) ;
460 // ----------------------------------------------------------------------------
461 // wxTopLevelWindowMac maximize/minimize
462 // ----------------------------------------------------------------------------
464 void wxTopLevelWindowMac::Maximize(bool maximize
)
466 // not available on mac
469 bool wxTopLevelWindowMac::IsMaximized() const
474 void wxTopLevelWindowMac::Iconize(bool iconize
)
476 // not available on mac
479 bool wxTopLevelWindowMac::IsIconized() const
481 // mac dialogs cannot be iconized
485 void wxTopLevelWindowMac::Restore()
487 // not available on mac
490 // ----------------------------------------------------------------------------
491 // wxTopLevelWindowMac misc
492 // ----------------------------------------------------------------------------
494 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
497 wxTopLevelWindowBase::SetIcon(icon
);
500 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
504 const wxString
& name
)
507 m_windowStyle
= style
;
528 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
530 // translate the window attributes in the appropriate window class and attributes
532 WindowClass wclass
= 0;
533 WindowAttributes attr
= kWindowNoAttributes
;
535 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
538 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
539 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
540 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
543 wclass
= kFloatingWindowClass
;
544 if ( HasFlag(wxTINY_CAPTION_VERT
) )
546 attr
|= kWindowSideTitlebarAttribute
;
552 wclass
= kPlainWindowClass
;
554 wclass
= kFloatingWindowClass
;
558 else if ( HasFlag( wxCAPTION
) )
560 wclass
= kDocumentWindowClass
;
564 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
565 HasFlag( wxSYSTEM_MENU
) )
567 wclass
= kDocumentWindowClass
;
572 wclass
= kPlainWindowClass
;
574 wclass
= kModalWindowClass
;
579 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
581 attr
|= kWindowFullZoomAttribute
;
582 attr
|= kWindowCollapseBoxAttribute
;
584 if ( HasFlag( wxRESIZE_BORDER
) )
586 attr
|= kWindowResizableAttribute
;
588 if ( HasFlag( wxSYSTEM_MENU
) )
590 attr
|= kWindowCloseBoxAttribute
;
593 ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
594 wxAssociateWinWithMacWindow( m_macWindow
, this ) ;
595 UMASetWTitle( (WindowRef
)m_macWindow
, title
) ;
596 ::CreateRootControl( (WindowRef
)m_macWindow
, (ControlHandle
*)&m_macRootControl
) ;
598 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
599 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacWindowEventHandlerUPP(),
600 GetEventTypeCount(eventList
), eventList
, this, &((EventHandlerRef
)m_macEventHandler
));
605 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin
, WXRECTPTR clipRect
, WXHWND
*window
, wxWindowMac
** rootwin
)
607 ((Point
*)localOrigin
)->h
= 0;
608 ((Point
*)localOrigin
)->v
= 0;
609 ((Rect
*)clipRect
)->left
= 0;
610 ((Rect
*)clipRect
)->top
= 0;
611 ((Rect
*)clipRect
)->right
= m_width
;
612 ((Rect
*)clipRect
)->bottom
= m_height
;
613 *window
= m_macWindow
;
617 void wxTopLevelWindowMac::Clear()
622 WXWidget
wxTopLevelWindowMac::MacGetContainerForEmbedding()
624 return m_macRootControl
;
628 void wxTopLevelWindowMac::MacUpdate( long timestamp
)
630 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
632 BeginUpdate( (WindowRef
)m_macWindow
) ;
634 RgnHandle updateRgn
= NewRgn();
635 RgnHandle diffRgn
= NewRgn() ;
636 if ( updateRgn
&& diffRgn
)
639 // macos internal control redraws clean up areas we'd like to redraw ourselves
640 // therefore we pick the boundary rect and make sure we can redraw it
641 RgnHandle trueUpdateRgn
= NewRgn() ;
642 Rect trueUpdateRgnBoundary
;
643 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), trueUpdateRgn
);
644 GetRegionBounds( trueUpdateRgn
, &trueUpdateRgnBoundary
) ;
645 RectRgn( (RgnHandle
) updateRgn
, &trueUpdateRgnBoundary
) ;
647 DisposeRgn( trueUpdateRgn
) ;
648 SetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
) ;
650 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
652 DiffRgn( updateRgn
, (RgnHandle
) m_macNoEraseUpdateRgn
, diffRgn
) ;
653 if ( !EmptyRgn( updateRgn
) )
655 MacRedraw( updateRgn
, timestamp
, m_macNeedsErasing
|| !EmptyRgn( diffRgn
) ) ;
659 DisposeRgn( updateRgn
);
661 DisposeRgn( diffRgn
);
662 EndUpdate( (WindowRef
)m_macWindow
) ;
663 SetEmptyRgn( (RgnHandle
) m_macNoEraseUpdateRgn
) ;
664 m_macNeedsErasing
= false ;
668 // Raise the window to the top of the Z order
669 void wxTopLevelWindowMac::Raise()
671 ::SelectWindow( (WindowRef
)m_macWindow
) ;
674 // Lower the window to the bottom of the Z order
675 void wxTopLevelWindowMac::Lower()
677 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
680 void wxTopLevelWindowMac::MacFireMouseEvent(
681 wxUint16 kind
, wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
683 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
684 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
685 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
687 event
.m_leftDown
= isDown
&& !controlDown
;
689 event
.m_middleDown
= FALSE
;
690 event
.m_rightDown
= isDown
&& controlDown
;
692 if ( kind
== mouseDown
)
695 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
697 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
699 else if ( kind
== mouseUp
)
702 event
.SetEventType(wxEVT_RIGHT_UP
) ;
704 event
.SetEventType(wxEVT_LEFT_UP
) ;
708 event
.SetEventType(wxEVT_MOTION
) ;
711 event
.m_shiftDown
= modifiers
& shiftKey
;
712 event
.m_controlDown
= modifiers
& controlKey
;
713 event
.m_altDown
= modifiers
& optionKey
;
714 event
.m_metaDown
= modifiers
& cmdKey
;
722 ::SetPort( UMAGetWindowPort( (WindowRef
)m_macWindow
) ) ;
723 ::GlobalToLocal( &localwhere
) ;
726 if ( kind
== mouseDown
)
728 if ( timestamp
- gs_lastWhen
<= GetDblTime() )
730 if ( abs( localwhere
.h
- gs_lastWhere
.h
) < 3 && abs( localwhere
.v
- gs_lastWhere
.v
) < 3 )
732 // This is not right if the second mouse down
733 // event occured in a differen window. We
734 // correct this in MacDispatchMouseEvent.
736 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
738 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
744 gs_lastWhen
= timestamp
;
746 gs_lastWhere
= localwhere
;
749 event
.m_x
= localwhere
.h
;
750 event
.m_y
= localwhere
.v
;
754 event
.m_timeStamp
= timestamp
;
755 event
.SetEventObject(this);
756 if ( wxTheApp
->s_captureWindow
)
760 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
763 event
.SetEventObject( wxTheApp
->s_captureWindow
) ;
764 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
766 if ( kind
== mouseUp
)
768 wxTheApp
->s_captureWindow
= NULL
;
771 m_cursor
.MacInstall() ;
777 MacDispatchMouseEvent( event
) ;
783 void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev
, short part
)
785 MacFireMouseEvent( mouseDown
, ((EventRecord
*)ev
)->where
.h
, ((EventRecord
*)ev
)->where
.v
,
786 ((EventRecord
*)ev
)->modifiers
, ((EventRecord
*)ev
)->when
) ;
789 void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev
, short part
)
795 MacFireMouseEvent( mouseUp
, ((EventRecord
*)ev
)->where
.h
, ((EventRecord
*)ev
)->where
.v
,
796 ((EventRecord
*)ev
)->modifiers
, ((EventRecord
*)ev
)->when
) ;
802 void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev
, short part
)
808 MacFireMouseEvent( nullEvent
/*moved*/ , ((EventRecord
*)ev
)->where
.h
, ((EventRecord
*)ev
)->where
.v
,
809 ((EventRecord
*)ev
)->modifiers
, ((EventRecord
*)ev
)->when
) ;
817 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
819 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
820 event
.m_timeStamp
= timestamp
;
821 event
.SetEventObject(this);
823 GetEventHandler()->ProcessEvent(event
);
825 UMAHighlightAndActivateWindow( (WindowRef
)m_macWindow
, inIsActivating
) ;
827 // Early versions of MacOS X don't refresh backgrounds properly,
828 // so refresh the whole window on activation and deactivation.
829 long osVersion
= UMAGetSystemVersion();
830 if (osVersion
>= 0x1000 && osVersion
< 0x1020)
836 // for the moment we have to resolve some redrawing issues like this
837 // the OS is stealing some redrawing areas as soon as it draws a control
844 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev
)
850 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
852 wxWindow::SetTitle( title
) ;
853 UMASetWTitle( (WindowRef
)m_macWindow
, title
) ;
856 bool wxTopLevelWindowMac::Show(bool show
)
858 if ( !wxWindow::Show(show
) )
863 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
864 ::SelectWindow( (WindowRef
)m_macWindow
) ;
865 // no need to generate events here, they will get them triggered by macos
866 // actually they should be , but apparently they are not
867 wxSize
size(m_width
, m_height
);
868 wxSizeEvent
event(size
, m_windowId
);
869 event
.SetEventObject(this);
870 GetEventHandler()->ProcessEvent(event
);
874 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
888 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
892 int former_w
= m_width
;
893 int former_h
= m_height
;
895 int actualWidth
= width
;
896 int actualHeight
= height
;
900 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
901 actualWidth
= m_minWidth
;
902 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
903 actualHeight
= m_minHeight
;
904 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
905 actualWidth
= m_maxWidth
;
906 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
907 actualHeight
= m_maxHeight
;
909 bool doMove
= false ;
910 bool doResize
= false ;
912 if ( actualX
!= former_x
|| actualY
!= former_y
)
916 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
921 if ( doMove
|| doResize
)
925 m_width
= actualWidth
;
926 m_height
= actualHeight
;
929 ::MoveWindow((WindowRef
)m_macWindow
, m_x
, m_y
, false); // don't make frontmost
932 ::SizeWindow((WindowRef
)m_macWindow
, m_width
, m_height
, true);
934 // the OS takes care of invalidating and erasing the new area so we only have to
935 // take care of refreshing for full repaints
937 if ( doResize
&& !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
941 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
943 wxFrame
* frame
= (wxFrame
*) this ;
944 frame
->PositionStatusBar();
945 frame
->PositionToolBar();
948 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
950 MacRepositionScrollBars() ;
953 wxPoint
point(m_x
, m_y
);
954 wxMoveEvent
event(point
, m_windowId
);
955 event
.SetEventObject(this);
956 GetEventHandler()->ProcessEvent(event
) ;
960 MacRepositionScrollBars() ;
961 wxSize
size(m_width
, m_height
);
962 wxSizeEvent
event(size
, m_windowId
);
963 event
.SetEventObject(this);
964 GetEventHandler()->ProcessEvent(event
);
971 * Invalidation Mechanism
973 * The update mechanism reflects exactely the windows mechanism
974 * the rect gets added to the window invalidate region, if the eraseBackground flag
975 * has been true for any part of the update rgn the background is erased in the entire region
976 * not just in the specified rect.
978 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
979 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
980 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
981 * will get the eraseBackground event first
984 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect
, bool eraseBackground
)
987 GetPort( &formerPort
) ;
988 SetPortWindowPort( (WindowRef
)m_macWindow
) ;
990 m_macNeedsErasing
|= eraseBackground
;
992 // if we already know that we will have to erase, there's no need to track the rest
993 if ( !m_macNeedsErasing
)
995 // we end only here if eraseBackground is false
996 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
997 // we will have to erase anyway
999 RgnHandle updateRgn
= NewRgn();
1000 RgnHandle diffRgn
= NewRgn() ;
1001 if ( updateRgn
&& diffRgn
)
1003 GetWindowUpdateRgn( (WindowRef
)m_macWindow
, updateRgn
);
1005 LocalToGlobal( &pt
) ;
1006 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1007 DiffRgn( updateRgn
, (RgnHandle
) m_macNoEraseUpdateRgn
, diffRgn
) ;
1008 if ( !EmptyRgn( diffRgn
) )
1010 m_macNeedsErasing
= true ;
1014 DisposeRgn( updateRgn
);
1016 DisposeRgn( diffRgn
);
1018 if ( !m_macNeedsErasing
)
1020 RgnHandle rectRgn
= NewRgn() ;
1021 SetRectRgn( rectRgn
, ((Rect
*)rect
)->left
, ((Rect
*)rect
)->top
, ((Rect
*)rect
)->right
, ((Rect
*)rect
)->bottom
) ;
1022 UnionRgn( (RgnHandle
) m_macNoEraseUpdateRgn
, rectRgn
, (RgnHandle
) m_macNoEraseUpdateRgn
) ;
1023 DisposeRgn( rectRgn
) ;
1026 InvalWindowRect( (WindowRef
)m_macWindow
, (Rect
*)rect
) ;
1027 // turn this on to debug the refreshing cycle
1028 #if wxMAC_DEBUG_REDRAW
1031 SetPort( formerPort
) ;
1034 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)