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 license
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
;
102 if ( wxMacConvertEventToRecord( event
, &rec
) )
104 wxTheApp
->m_macCurrentEvent
= &rec
;
105 wxWindow
* focus
= wxWindow::FindFocus() ;
106 if ( (focus
!= NULL
) && !UMAMenuEvent(&rec
) && wxTheApp
->MacSendKeyDownEvent( focus
, rec
.message
, rec
.modifiers
, rec
.when
, rec
.where
.h
, rec
.where
.v
) )
108 // was handled internally
116 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
118 OSStatus result
= eventNotHandledErr
;
120 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
122 UInt32 modifiers
= 0;
123 EventMouseButton button
= 0 ;
126 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
127 sizeof( Point
), NULL
, &point
);
128 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
129 sizeof( UInt32
), NULL
, &modifiers
);
130 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
131 sizeof( EventMouseButton
), NULL
, &button
);
132 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
133 sizeof( UInt32
), NULL
, &click
);
135 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
136 modifiers
+= btnState
;
139 short windowPart
= ::FindWindow(point
, &window
);
141 if ( IsWindowActive(window
) && windowPart
== inContent
)
143 switch ( GetEventKind( event
) )
145 case kEventMouseDown
:
146 toplevelWindow
->MacFireMouseEvent( mouseDown
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
150 toplevelWindow
->MacFireMouseEvent( mouseUp
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
153 case kEventMouseMoved
:
154 toplevelWindow
->MacFireMouseEvent( nullEvent
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
157 case kEventMouseDragged
:
158 toplevelWindow
->MacFireMouseEvent( nullEvent
, point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
170 static pascal OSStatus
WindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
172 OSStatus result
= eventNotHandledErr
;
173 OSStatus err
= noErr
;
176 WindowRef windowRef
;
177 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
179 GetEventParameter( event
, kEventParamDirectObject
, typeWindowRef
, NULL
,
180 sizeof( WindowRef
), NULL
, &windowRef
);
182 switch( GetEventKind( event
) )
184 case kEventWindowUpdate
:
185 if ( !wxPendingDelete
.Member(toplevelWindow
) )
186 toplevelWindow
->MacUpdate( EventTimeToTicks( GetEventTime( event
) ) ) ;
189 case kEventWindowActivated
:
190 toplevelWindow
->MacActivate( EventTimeToTicks( GetEventTime( event
) ) , true) ;
193 case kEventWindowDeactivated
:
194 toplevelWindow
->MacActivate( EventTimeToTicks( GetEventTime( event
) ) , false) ;
197 case kEventWindowClose
:
198 toplevelWindow
->Close() ;
201 case kEventWindowBoundsChanged
:
202 err
= GetEventParameter( event
, kEventParamAttributes
, typeUInt32
,
203 NULL
, sizeof( UInt32
), NULL
, &attributes
);
206 Rect newContentRect
;
208 GetEventParameter( event
, kEventParamCurrentBounds
, typeQDRectangle
, NULL
,
209 sizeof( newContentRect
), NULL
, &newContentRect
);
211 toplevelWindow
->SetSize( newContentRect
.left
, newContentRect
.top
,
212 newContentRect
.right
- newContentRect
.left
,
213 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
224 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
226 OSStatus result
= eventNotHandledErr
;
228 switch ( GetEventClass( event
) )
230 case kEventClassTextInput
:
231 result
= TextInputEventHandler( handler
, event
, data
) ;
233 case kEventClassWindow
:
234 result
= WindowEventHandler( handler
, event
, data
) ;
236 case kEventClassMouse
:
237 result
= MouseEventHandler( handler
, event
, data
) ;
245 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
249 // ---------------------------------------------------------------------------
250 // wxWindowMac utility functions
251 // ---------------------------------------------------------------------------
253 // Find an item given the Macintosh Window Reference
255 wxList
*wxWinMacWindowList
= NULL
;
256 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WXWindow inWindowRef
)
258 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
261 return (wxTopLevelWindowMac
*)node
->GetData();
264 void wxAssociateWinWithMacWindow(WXWindow inWindowRef
, wxTopLevelWindowMac
*win
)
266 // adding NULL WindowRef is (first) surely a result of an error and
267 // (secondly) breaks menu command processing
268 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
270 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
271 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
274 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
276 wxWinMacWindowList
->DeleteObject(win
);
280 // ----------------------------------------------------------------------------
281 // wxTopLevelWindowMac creation
282 // ----------------------------------------------------------------------------
284 WXHWND
wxTopLevelWindowMac::s_macWindowInUpdate
= NULL
;
286 void wxTopLevelWindowMac::Init()
289 m_maximizeOnShow
= FALSE
;
290 m_macNoEraseUpdateRgn
= NewRgn() ;
291 m_macNeedsErasing
= false ;
294 m_macEventHandler
= NULL
;
298 class wxMacDeferredWindowDeleter
: public wxObject
301 wxMacDeferredWindowDeleter( WindowRef windowRef
)
303 m_macWindow
= windowRef
;
305 virtual ~wxMacDeferredWindowDeleter()
307 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
310 WindowRef m_macWindow
;
313 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
315 const wxString
& title
,
319 const wxString
& name
)
324 m_windowStyle
= style
;
328 m_windowId
= id
== -1 ? NewControlId() : id
;
330 wxTopLevelWindows
.Append(this);
333 parent
->AddChild(this);
338 wxTopLevelWindowMac::~wxTopLevelWindowMac()
342 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
343 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
347 if ( m_macEventHandler
)
349 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
350 m_macEventHandler
= NULL
;
354 wxRemoveMacWindowAssociation( this ) ;
356 if ( wxModelessWindows
.Find(this) )
357 wxModelessWindows
.DeleteObject(this);
359 DisposeRgn( (RgnHandle
) m_macNoEraseUpdateRgn
) ;
363 // ----------------------------------------------------------------------------
364 // wxTopLevelWindowMac maximize/minimize
365 // ----------------------------------------------------------------------------
367 void wxTopLevelWindowMac::Maximize(bool maximize
)
369 // not available on mac
372 bool wxTopLevelWindowMac::IsMaximized() const
377 void wxTopLevelWindowMac::Iconize(bool iconize
)
379 // not available on mac
382 bool wxTopLevelWindowMac::IsIconized() const
384 // mac dialogs cannot be iconized
388 void wxTopLevelWindowMac::Restore()
390 // not available on mac
393 // ----------------------------------------------------------------------------
394 // wxTopLevelWindowMac misc
395 // ----------------------------------------------------------------------------
397 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
400 wxTopLevelWindowBase::SetIcon(icon
);
403 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
407 const wxString
& name
)
410 m_windowStyle
= style
;
431 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
433 // translate the window attributes in the appropriate window class and attributes
435 WindowClass wclass
= 0;
436 WindowAttributes attr
= kWindowNoAttributes
;
438 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
441 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
442 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
443 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
446 wclass
= kFloatingWindowClass
;
447 if ( HasFlag(wxTINY_CAPTION_VERT
) )
449 attr
|= kWindowSideTitlebarAttribute
;
455 wclass
= kPlainWindowClass
;
457 wclass
= kFloatingWindowClass
;
461 else if ( HasFlag( wxCAPTION
) )
463 if ( HasFlag( wxDIALOG_MODAL
) )
465 wclass
= kDocumentWindowClass
; // kMovableModalWindowClass ;
469 wclass
= kDocumentWindowClass
;
474 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
475 HasFlag( wxSYSTEM_MENU
) )
477 wclass
= kDocumentWindowClass
;
482 wclass
= kPlainWindowClass
;
484 wclass
= kModalWindowClass
;
489 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
491 attr
|= kWindowFullZoomAttribute
;
492 attr
|= kWindowCollapseBoxAttribute
;
494 if ( HasFlag( wxRESIZE_BORDER
) )
496 attr
|= kWindowResizableAttribute
;
498 if ( HasFlag( wxSYSTEM_MENU
) )
500 attr
|= kWindowCloseBoxAttribute
;
503 ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
504 wxAssociateWinWithMacWindow( m_macWindow
, this ) ;
506 if( wxApp::s_macDefaultEncodingIsPC
)
507 label
= wxMacMakeMacStringFromPC( title
) ;
510 UMASetWTitleC( (WindowRef
)m_macWindow
, label
) ;
511 ::CreateRootControl( (WindowRef
)m_macWindow
, (ControlHandle
*)&m_macRootControl
) ;
513 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
514 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacWindowEventHandlerUPP(),
515 GetEventTypeCount(eventList
), eventList
, this, &((EventHandlerRef
)m_macEventHandler
));
520 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin
, WXRECTPTR clipRect
, WXHWND
*window
, wxWindowMac
** rootwin
)
522 ((Point
*)localOrigin
)->h
= 0;
523 ((Point
*)localOrigin
)->v
= 0;
524 ((Rect
*)clipRect
)->left
= 0;
525 ((Rect
*)clipRect
)->top
= 0;
526 ((Rect
*)clipRect
)->right
= m_width
;
527 ((Rect
*)clipRect
)->bottom
= m_height
;
528 *window
= m_macWindow
;
532 void wxTopLevelWindowMac::Clear()
537 WXWidget
wxTopLevelWindowMac::MacGetContainerForEmbedding()
539 return m_macRootControl
;
543 void wxTopLevelWindowMac::MacUpdate( long timestamp
)
546 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
548 BeginUpdate( (WindowRef
)m_macWindow
) ;
550 RgnHandle updateRgn
= NewRgn();
551 RgnHandle diffRgn
= NewRgn() ;
552 if ( updateRgn
&& diffRgn
)
554 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
555 DiffRgn( updateRgn
, (RgnHandle
) m_macNoEraseUpdateRgn
, diffRgn
) ;
556 if ( !EmptyRgn( updateRgn
) )
558 MacRedraw( updateRgn
, timestamp
, m_macNeedsErasing
|| !EmptyRgn( diffRgn
) ) ;
562 DisposeRgn( updateRgn
);
564 DisposeRgn( diffRgn
);
565 EndUpdate( (WindowRef
)m_macWindow
) ;
566 SetEmptyRgn( (RgnHandle
) m_macNoEraseUpdateRgn
) ;
567 m_macNeedsErasing
= false ;
571 // Raise the window to the top of the Z order
572 void wxTopLevelWindowMac::Raise()
574 ::BringToFront( (WindowRef
)m_macWindow
) ;
577 // Lower the window to the bottom of the Z order
578 void wxTopLevelWindowMac::Lower()
580 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
583 void wxTopLevelWindowMac::MacFireMouseEvent(
584 wxUint16 kind
, wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
586 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
587 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
588 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
590 event
.m_leftDown
= isDown
&& !controlDown
;
592 event
.m_middleDown
= FALSE
;
593 event
.m_rightDown
= isDown
&& controlDown
;
595 if ( kind
== mouseDown
)
598 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
600 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
602 else if ( kind
== mouseUp
)
605 event
.SetEventType(wxEVT_RIGHT_UP
) ;
607 event
.SetEventType(wxEVT_LEFT_UP
) ;
611 event
.SetEventType(wxEVT_MOTION
) ;
614 event
.m_shiftDown
= modifiers
& shiftKey
;
615 event
.m_controlDown
= modifiers
& controlKey
;
616 event
.m_altDown
= modifiers
& optionKey
;
617 event
.m_metaDown
= modifiers
& cmdKey
;
625 ::SetPort( UMAGetWindowPort( (WindowRef
)m_macWindow
) ) ;
626 ::GlobalToLocal( &localwhere
) ;
629 if ( kind
== mouseDown
)
631 if ( timestamp
- gs_lastWhen
<= GetDblTime() )
633 if ( abs( localwhere
.h
- gs_lastWhere
.h
) < 3 && abs( localwhere
.v
- gs_lastWhere
.v
) < 3 )
635 // This is not right if the second mouse down
636 // event occured in a differen window. We
637 // correct this in MacDispatchMouseEvent.
639 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
641 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
647 gs_lastWhen
= timestamp
;
649 gs_lastWhere
= localwhere
;
652 event
.m_x
= localwhere
.h
;
653 event
.m_y
= localwhere
.v
;
657 event
.m_timeStamp
= timestamp
;
658 event
.SetEventObject(this);
659 if ( wxTheApp
->s_captureWindow
)
663 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
666 event
.SetEventObject( wxTheApp
->s_captureWindow
) ;
667 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
669 if ( kind
== mouseUp
)
671 wxTheApp
->s_captureWindow
= NULL
;
674 m_cursor
.MacInstall() ;
680 MacDispatchMouseEvent( event
) ;
685 void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev
, short part
)
687 MacFireMouseEvent( mouseDown
, ((EventRecord
*)ev
)->where
.h
, ((EventRecord
*)ev
)->where
.v
,
688 ((EventRecord
*)ev
)->modifiers
, ((EventRecord
*)ev
)->when
) ;
691 void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev
, short part
)
697 MacFireMouseEvent( mouseUp
, ((EventRecord
*)ev
)->where
.h
, ((EventRecord
*)ev
)->where
.v
,
698 ((EventRecord
*)ev
)->modifiers
, ((EventRecord
*)ev
)->when
) ;
704 void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev
, short part
)
710 MacFireMouseEvent( nullEvent
/*moved*/ , ((EventRecord
*)ev
)->where
.h
, ((EventRecord
*)ev
)->where
.v
,
711 ((EventRecord
*)ev
)->modifiers
, ((EventRecord
*)ev
)->when
) ;
719 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
721 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
722 event
.m_timeStamp
= timestamp
;
723 event
.SetEventObject(this);
725 GetEventHandler()->ProcessEvent(event
);
727 UMAHighlightAndActivateWindow( (WindowRef
)m_macWindow
, inIsActivating
) ;
729 // Early versions of MacOS X don't refresh backgrounds properly,
730 // so refresh the whole window on activation and deactivation.
731 long osVersion
= UMAGetSystemVersion();
732 if (osVersion
>= 0x1000 && osVersion
< 0x1020)
735 MacSuperEnabled( inIsActivating
) ;
740 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev
)
746 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
748 wxWindow::SetTitle( title
) ;
752 if( wxApp::s_macDefaultEncodingIsPC
)
753 label
= wxMacMakeMacStringFromPC( m_label
) ;
757 UMASetWTitleC( (WindowRef
)m_macWindow
, label
) ;
760 bool wxTopLevelWindowMac::Show(bool show
)
762 if ( !wxWindow::Show(show
) )
767 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
768 ::SelectWindow( (WindowRef
)m_macWindow
) ;
769 // no need to generate events here, they will get them triggered by macos
770 // actually they should be , but apparently they are not
771 wxSize
size(m_width
, m_height
);
772 wxSizeEvent
event(size
, m_windowId
);
773 event
.SetEventObject(this);
774 GetEventHandler()->ProcessEvent(event
);
778 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
792 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
796 int former_w
= m_width
;
797 int former_h
= m_height
;
799 int actualWidth
= width
;
800 int actualHeight
= height
;
804 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
805 actualWidth
= m_minWidth
;
806 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
807 actualHeight
= m_minHeight
;
808 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
809 actualWidth
= m_maxWidth
;
810 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
811 actualHeight
= m_maxHeight
;
813 bool doMove
= false ;
814 bool doResize
= false ;
816 if ( actualX
!= former_x
|| actualY
!= former_y
)
820 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
825 if ( doMove
|| doResize
)
829 m_width
= actualWidth
;
830 m_height
= actualHeight
;
833 ::MoveWindow((WindowRef
)m_macWindow
, m_x
, m_y
, false); // don't make frontmost
836 ::SizeWindow((WindowRef
)m_macWindow
, m_width
, m_height
, true);
838 // the OS takes care of invalidating and erasing the new area so we only have to
839 // take care of refreshing for full repaints
841 if ( doResize
&& !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
845 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
847 wxFrame
* frame
= (wxFrame
*) this ;
848 frame
->PositionStatusBar();
849 frame
->PositionToolBar();
852 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
854 MacRepositionScrollBars() ;
857 wxPoint
point(m_x
, m_y
);
858 wxMoveEvent
event(point
, m_windowId
);
859 event
.SetEventObject(this);
860 GetEventHandler()->ProcessEvent(event
) ;
864 MacRepositionScrollBars() ;
865 wxSize
size(m_width
, m_height
);
866 wxSizeEvent
event(size
, m_windowId
);
867 event
.SetEventObject(this);
868 GetEventHandler()->ProcessEvent(event
);
875 * Invalidation Mechanism
877 * The update mechanism reflects exactely the windows mechanism
878 * the rect gets added to the window invalidate region, if the eraseBackground flag
879 * has been true for any part of the update rgn the background is erased in the entire region
880 * not just in the specified rect.
882 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
883 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
884 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
885 * will get the eraseBackground event first
888 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect
, bool eraseBackground
)
891 GetPort( &formerPort
) ;
892 SetPortWindowPort( (WindowRef
)m_macWindow
) ;
894 m_macNeedsErasing
|= eraseBackground
;
896 // if we already know that we will have to erase, there's no need to track the rest
897 if ( !m_macNeedsErasing
)
899 // we end only here if eraseBackground is false
900 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
901 // we will have to erase anyway
903 RgnHandle updateRgn
= NewRgn();
904 RgnHandle diffRgn
= NewRgn() ;
905 if ( updateRgn
&& diffRgn
)
907 GetWindowUpdateRgn( (WindowRef
)m_macWindow
, updateRgn
);
909 LocalToGlobal( &pt
) ;
910 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
911 DiffRgn( updateRgn
, (RgnHandle
) m_macNoEraseUpdateRgn
, diffRgn
) ;
912 if ( !EmptyRgn( diffRgn
) )
914 m_macNeedsErasing
= true ;
918 DisposeRgn( updateRgn
);
920 DisposeRgn( diffRgn
);
922 if ( !m_macNeedsErasing
)
924 RgnHandle rectRgn
= NewRgn() ;
925 SetRectRgn( rectRgn
, ((Rect
*)rect
)->left
, ((Rect
*)rect
)->top
, ((Rect
*)rect
)->right
, ((Rect
*)rect
)->bottom
) ;
926 UnionRgn( (RgnHandle
) m_macNoEraseUpdateRgn
, rectRgn
, (RgnHandle
) m_macNoEraseUpdateRgn
) ;
927 DisposeRgn( rectRgn
) ;
930 InvalWindowRect( (WindowRef
)m_macWindow
, (Rect
*)rect
) ;
931 // turn this on to debug the refreshing cycle
932 #if wxMAC_DEBUG_REDRAW
935 SetPort( formerPort
) ;