]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
make sure we are removing ourselves from the focus of the toplevel frame when deletin...
[wxWidgets.git] / src / mac / carbon / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 24.09.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
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"
34 #include "wx/frame.h"
35 #include "wx/string.h"
36 #include "wx/log.h"
37 #include "wx/intl.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/app.h"
43 #include "wx/tooltip.h"
44 #include "wx/dnd.h"
45
46 #define wxMAC_DEBUG_REDRAW 0
47 #ifndef wxMAC_DEBUG_REDRAW
48 #define wxMAC_DEBUG_REDRAW 0
49 #endif
50
51 // ----------------------------------------------------------------------------
52 // globals
53 // ----------------------------------------------------------------------------
54
55 // list of all frames and modeless dialogs
56 wxWindowList wxModelessWindows;
57
58 // double click testing
59 static Point gs_lastWhere;
60 static long gs_lastWhen = 0;
61
62 // cursor stuff
63 extern int wxBusyCursorCount;
64
65
66 // ============================================================================
67 // wxTopLevelWindowMac implementation
68 // ============================================================================
69
70 // ---------------------------------------------------------------------------
71 // wxWindowMac utility functions
72 // ---------------------------------------------------------------------------
73
74 // Find an item given the Macintosh Window Reference
75
76 wxList *wxWinMacWindowList = NULL;
77 wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef)
78 {
79 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
80 if (!node)
81 return NULL;
82 return (wxTopLevelWindowMac *)node->Data();
83 }
84
85 void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win)
86 {
87 // adding NULL WindowRef is (first) surely a result of an error and
88 // (secondly) breaks menu command processing
89 wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
90
91 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
92 wxWinMacWindowList->Append((long)inWindowRef, win);
93 }
94
95 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
96 {
97 wxWinMacWindowList->DeleteObject(win);
98 }
99
100
101 // ----------------------------------------------------------------------------
102 // wxTopLevelWindowMac creation
103 // ----------------------------------------------------------------------------
104
105 WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
106
107 void wxTopLevelWindowMac::Init()
108 {
109 m_iconized =
110 m_maximizeOnShow = FALSE;
111 m_macNoEraseUpdateRgn = NewRgn() ;
112 m_macNeedsErasing = false ;
113 m_macWindow = NULL ;
114 m_macEventHandler = NULL ;
115 }
116
117 class wxMacDeferredWindowDeleter : public wxObject
118 {
119 public :
120 wxMacDeferredWindowDeleter( WindowRef windowRef )
121 {
122 m_macWindow = windowRef ;
123 }
124 virtual ~wxMacDeferredWindowDeleter()
125 {
126 UMADisposeWindow( (WindowRef) m_macWindow ) ;
127 }
128 protected :
129 WindowRef m_macWindow ;
130 } ;
131
132 bool wxTopLevelWindowMac::Create(wxWindow *parent,
133 wxWindowID id,
134 const wxString& title,
135 const wxPoint& pos,
136 const wxSize& size,
137 long style,
138 const wxString& name)
139 {
140 // init our fields
141 Init();
142
143 m_windowStyle = style;
144
145 SetName(name);
146
147 m_windowId = id == -1 ? NewControlId() : id;
148
149 wxTopLevelWindows.Append(this);
150
151 if ( parent )
152 parent->AddChild(this);
153
154 return TRUE;
155 }
156
157 wxTopLevelWindowMac::~wxTopLevelWindowMac()
158 {
159 if ( m_macWindow )
160 {
161 wxToolTip::NotifyWindowDelete(m_macWindow) ;
162 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
163 }
164
165 #if TARGET_CARBON
166 if ( m_macEventHandler )
167 {
168 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
169 m_macEventHandler = NULL ;
170 }
171 #endif
172 wxRemoveMacWindowAssociation( this ) ;
173
174 wxTopLevelWindows.DeleteObject(this);
175
176 if ( wxModelessWindows.Find(this) )
177 wxModelessWindows.DeleteObject(this);
178
179 // If this is the last top-level window, exit.
180 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
181 {
182 wxTheApp->SetTopWindow(NULL);
183
184 if ( wxTheApp->GetExitOnFrameDelete() )
185 {
186 wxTheApp->ExitMainLoop() ;
187 }
188 }
189 DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
190 }
191
192
193 // ----------------------------------------------------------------------------
194 // wxTopLevelWindowMac maximize/minimize
195 // ----------------------------------------------------------------------------
196
197 void wxTopLevelWindowMac::Maximize(bool maximize)
198 {
199 // not available on mac
200 }
201
202 bool wxTopLevelWindowMac::IsMaximized() const
203 {
204 return false ;
205 }
206
207 void wxTopLevelWindowMac::Iconize(bool iconize)
208 {
209 // not available on mac
210 }
211
212 bool wxTopLevelWindowMac::IsIconized() const
213 {
214 // mac dialogs cannot be iconized
215 return FALSE;
216 }
217
218 void wxTopLevelWindowMac::Restore()
219 {
220 // not available on mac
221 }
222
223 // ----------------------------------------------------------------------------
224 // wxTopLevelWindowMac misc
225 // ----------------------------------------------------------------------------
226
227 void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
228 {
229 // this sets m_icon
230 wxTopLevelWindowBase::SetIcon(icon);
231 }
232
233 #if TARGET_CARBON
234
235 EventHandlerUPP wxMacWindowEventHandlerUPP = NULL ;
236
237 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
238 {
239 OSStatus result = eventNotHandledErr ;
240 EventRecord rec ;
241 switch ( GetEventClass( event ) )
242 {
243 case kEventClassTextInput :
244 if ( wxMacConvertEventToRecord( event , &rec ) )
245 {
246 wxTheApp->MacHandleOneEvent( &rec ) ;
247 result = noErr ;
248 }
249 break ;
250 default :
251 break ;
252 }
253 return result ;
254 }
255
256 #endif
257
258 void wxTopLevelWindowMac::MacInstallEventHandler()
259 {
260 #if TARGET_CARBON
261 if ( wxMacWindowEventHandlerUPP == NULL )
262 {
263 wxMacWindowEventHandlerUPP = NewEventHandlerUPP( wxMacWindowEventHandler ) ;
264 }
265
266 static const EventTypeSpec eventList[] =
267 {
268 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }
269 } ;
270 if ( m_macEventHandler )
271 {
272 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
273 m_macEventHandler = NULL ;
274 }
275 InstallWindowEventHandler(MAC_WXHWND(m_macWindow), wxMacWindowEventHandlerUPP, WXSIZEOF(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
276 #endif
277 }
278
279 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
280 const wxPoint& pos,
281 const wxSize& size,
282 long style,
283 const wxString& name )
284 {
285 SetName(name);
286 m_windowStyle = style;
287 m_isShown = FALSE;
288
289 // create frame.
290
291 Rect theBoundsRect;
292
293 m_x = (int)pos.x;
294 m_y = (int)pos.y;
295 if ( m_y < 50 )
296 m_y = 50 ;
297 if ( m_x < 20 )
298 m_x = 20 ;
299
300 m_width = size.x;
301 if (m_width == -1)
302 m_width = 20;
303 m_height = size.y;
304 if (m_height == -1)
305 m_height = 20;
306
307 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
308
309 // translate the window attributes in the appropriate window class and attributes
310
311 WindowClass wclass = 0;
312 WindowAttributes attr = kWindowNoAttributes ;
313
314 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
315 {
316 if (
317 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
318 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
319 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
320 )
321 {
322 wclass = kFloatingWindowClass ;
323 if ( HasFlag(wxTINY_CAPTION_VERT) )
324 {
325 attr |= kWindowSideTitlebarAttribute ;
326 }
327 }
328 else
329 {
330 wclass = kPlainWindowClass ;
331 }
332 }
333 else if ( HasFlag( wxCAPTION ) )
334 {
335 if ( HasFlag( wxDIALOG_MODAL ) )
336 {
337 wclass = kDocumentWindowClass ; // kMovableModalWindowClass ;
338 }
339 else
340 {
341 wclass = kDocumentWindowClass ;
342 }
343 }
344 else
345 {
346 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
347 HasFlag( wxSYSTEM_MENU ) )
348 {
349 wclass = kDocumentWindowClass ;
350 }
351 else
352 {
353 wclass = kPlainWindowClass ;
354 }
355 }
356
357 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
358 {
359 attr |= kWindowFullZoomAttribute ;
360 attr |= kWindowCollapseBoxAttribute ;
361 }
362 if ( HasFlag( wxRESIZE_BORDER ) )
363 {
364 attr |= kWindowResizableAttribute ;
365 }
366 if ( HasFlag( wxSYSTEM_MENU ) )
367 {
368 attr |= kWindowCloseBoxAttribute ;
369 }
370
371 ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
372 wxAssociateWinWithMacWindow( m_macWindow , this ) ;
373 wxString label ;
374 if( wxApp::s_macDefaultEncodingIsPC )
375 label = wxMacMakeMacStringFromPC( title ) ;
376 else
377 label = title ;
378 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
379 ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
380 MacInstallEventHandler() ;
381
382 m_macFocus = NULL ;
383 }
384
385 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
386 {
387 ((Point*)localOrigin)->h = 0;
388 ((Point*)localOrigin)->v = 0;
389 ((Rect*)clipRect)->left = 0;
390 ((Rect*)clipRect)->top = 0;
391 ((Rect*)clipRect)->right = m_width;
392 ((Rect*)clipRect)->bottom = m_height;
393 *window = m_macWindow ;
394 *rootwin = this ;
395 }
396
397 void wxTopLevelWindowMac::Clear()
398 {
399 wxWindow::Clear() ;
400 }
401
402 WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding()
403 {
404 return m_macRootControl ;
405 }
406
407
408 void wxTopLevelWindowMac::MacUpdate( long timestamp)
409 {
410
411 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
412
413 BeginUpdate( (WindowRef)m_macWindow ) ;
414
415 RgnHandle updateRgn = NewRgn();
416 RgnHandle diffRgn = NewRgn() ;
417 if ( updateRgn && diffRgn )
418 {
419 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
420 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
421 if ( !EmptyRgn( updateRgn ) )
422 {
423 MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ;
424 }
425 }
426 if ( updateRgn )
427 DisposeRgn( updateRgn );
428 if ( diffRgn )
429 DisposeRgn( diffRgn );
430 EndUpdate( (WindowRef)m_macWindow ) ;
431 SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
432 m_macNeedsErasing = false ;
433 }
434
435
436 // Raise the window to the top of the Z order
437 void wxTopLevelWindowMac::Raise()
438 {
439 ::BringToFront( (WindowRef)m_macWindow ) ;
440 }
441
442 // Lower the window to the bottom of the Z order
443 void wxTopLevelWindowMac::Lower()
444 {
445 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
446 }
447
448 void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
449 {
450 EventRecord *ev = (EventRecord*) evr ;
451 wxMouseEvent event(wxEVT_LEFT_DOWN);
452 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
453 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
454
455 event.m_leftDown = isDown && !controlDown;
456
457 event.m_middleDown = FALSE;
458 event.m_rightDown = isDown && controlDown;
459
460 if ( ev->what == mouseDown )
461 {
462 if ( controlDown )
463 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
464 else
465 event.SetEventType(wxEVT_LEFT_DOWN ) ;
466 }
467 else if ( ev->what == mouseUp )
468 {
469 if ( controlDown )
470 event.SetEventType(wxEVT_RIGHT_UP ) ;
471 else
472 event.SetEventType(wxEVT_LEFT_UP ) ;
473 }
474 else
475 {
476 event.SetEventType(wxEVT_MOTION ) ;
477 }
478
479 event.m_shiftDown = ev->modifiers & shiftKey;
480 event.m_controlDown = ev->modifiers & controlKey;
481 event.m_altDown = ev->modifiers & optionKey;
482 event.m_metaDown = ev->modifiers & cmdKey;
483
484 Point localwhere = ev->where ;
485
486 GrafPtr port ;
487 ::GetPort( &port ) ;
488 ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
489 ::GlobalToLocal( &localwhere ) ;
490 ::SetPort( port ) ;
491
492 if ( ev->what == mouseDown )
493 {
494 if ( ev->when - gs_lastWhen <= GetDblTime() )
495 {
496 if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
497 {
498 // This is not right if the second mouse down
499 // event occured in a differen window. We
500 // correct this in MacDispatchMouseEvent.
501 if ( controlDown )
502 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
503 else
504 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
505 }
506 gs_lastWhen = 0 ;
507 }
508 else
509 {
510 gs_lastWhen = ev->when ;
511 }
512 gs_lastWhere = localwhere ;
513 }
514
515 event.m_x = localwhere.h;
516 event.m_y = localwhere.v;
517 event.m_x += m_x;
518 event.m_y += m_y;
519
520 event.m_timeStamp = ev->when;
521 event.SetEventObject(this);
522 if ( wxTheApp->s_captureWindow )
523 {
524 int x = event.m_x ;
525 int y = event.m_y ;
526 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
527 event.m_x = x ;
528 event.m_y = y ;
529 event.SetEventObject( wxTheApp->s_captureWindow ) ;
530 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
531
532 if ( ev->what == mouseUp )
533 {
534 wxTheApp->s_captureWindow = NULL ;
535 if ( wxBusyCursorCount == 0 )
536 {
537 m_cursor.MacInstall() ;
538 }
539 }
540 }
541 else
542 {
543 MacDispatchMouseEvent( event ) ;
544 }
545 }
546
547 void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
548 {
549 MacFireMouseEvent( ev ) ;
550 }
551
552 void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
553 {
554 switch (part)
555 {
556 case inContent:
557 {
558 MacFireMouseEvent( ev ) ;
559 }
560 break ;
561 }
562 }
563
564 void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
565 {
566 switch (part)
567 {
568 case inContent:
569 {
570 MacFireMouseEvent( ev ) ;
571 }
572 break ;
573 }
574 }
575 void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating )
576 {
577 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
578 event.m_timeStamp = ((EventRecord*)ev)->when ;
579 event.SetEventObject(this);
580
581 GetEventHandler()->ProcessEvent(event);
582
583 UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
584
585 MacSuperEnabled( inIsActivating ) ;
586 }
587
588 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
589 {
590 }
591
592 void wxTopLevelWindowMac::SetTitle(const wxString& title)
593 {
594 wxWindow::SetTitle( title ) ;
595
596 wxString label ;
597
598 if( wxApp::s_macDefaultEncodingIsPC )
599 label = wxMacMakeMacStringFromPC( m_label ) ;
600 else
601 label = m_label ;
602
603 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
604 }
605
606 bool wxTopLevelWindowMac::Show(bool show)
607 {
608 if ( !wxWindow::Show(show) )
609 return FALSE;
610
611 if (show)
612 {
613 ::ShowWindow( (WindowRef)m_macWindow ) ;
614 ::SelectWindow( (WindowRef)m_macWindow ) ;
615 // no need to generate events here, they will get them triggered by macos
616 // actually they should be , but apparently they are not
617 wxSize size(m_width, m_height);
618 wxSizeEvent event(size, m_windowId);
619 event.SetEventObject(this);
620 GetEventHandler()->ProcessEvent(event);
621 }
622 else
623 {
624 ::HideWindow( (WindowRef)m_macWindow ) ;
625 }
626
627 if ( !show )
628 {
629 }
630 else
631 {
632 Refresh() ;
633 }
634
635 return TRUE;
636 }
637
638 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
639 {
640 int former_x = m_x ;
641 int former_y = m_y ;
642 int former_w = m_width ;
643 int former_h = m_height ;
644
645 int actualWidth = width;
646 int actualHeight = height;
647 int actualX = x;
648 int actualY = y;
649
650 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
651 actualWidth = m_minWidth;
652 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
653 actualHeight = m_minHeight;
654 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
655 actualWidth = m_maxWidth;
656 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
657 actualHeight = m_maxHeight;
658
659 bool doMove = false ;
660 bool doResize = false ;
661
662 if ( actualX != former_x || actualY != former_y )
663 {
664 doMove = true ;
665 }
666 if ( actualWidth != former_w || actualHeight != former_h )
667 {
668 doResize = true ;
669 }
670
671 if ( doMove || doResize )
672 {
673 m_x = actualX ;
674 m_y = actualY ;
675 m_width = actualWidth ;
676 m_height = actualHeight ;
677
678 if ( doMove )
679 ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost
680
681 if ( doResize )
682 ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true);
683
684 // the OS takes care of invalidating and erasing the new area
685 // we have erased the old one
686
687 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
688 {
689 wxFrame* frame = (wxFrame*) this ;
690 frame->PositionStatusBar();
691 frame->PositionToolBar();
692 }
693 if ( doMove )
694 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
695
696 MacRepositionScrollBars() ;
697 if ( doMove )
698 {
699 wxPoint point(m_x, m_y);
700 wxMoveEvent event(point, m_windowId);
701 event.SetEventObject(this);
702 GetEventHandler()->ProcessEvent(event) ;
703 }
704 if ( doResize )
705 {
706 MacRepositionScrollBars() ;
707 wxSize size(m_width, m_height);
708 wxSizeEvent event(size, m_windowId);
709 event.SetEventObject(this);
710 GetEventHandler()->ProcessEvent(event);
711 }
712 }
713
714 }
715
716 /*
717 * Invalidation Mechanism
718 *
719 * The update mechanism reflects exactely the windows mechanism
720 * the rect gets added to the window invalidate region, if the eraseBackground flag
721 * has been true for any part of the update rgn the background is erased in the entire region
722 * not just in the specified rect.
723 *
724 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
725 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
726 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
727 * will get the eraseBackground event first
728 */
729
730 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
731 {
732 GrafPtr formerPort ;
733 GetPort( &formerPort ) ;
734 SetPortWindowPort( (WindowRef)m_macWindow ) ;
735
736 m_macNeedsErasing |= eraseBackground ;
737
738 // if we already know that we will have to erase, there's no need to track the rest
739 if ( !m_macNeedsErasing)
740 {
741 // we end only here if eraseBackground is false
742 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
743 // we will have to erase anyway
744
745 RgnHandle updateRgn = NewRgn();
746 RgnHandle diffRgn = NewRgn() ;
747 if ( updateRgn && diffRgn )
748 {
749 GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
750 Point pt = {0,0} ;
751 LocalToGlobal( &pt ) ;
752 OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
753 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
754 if ( !EmptyRgn( diffRgn ) )
755 {
756 m_macNeedsErasing = true ;
757 }
758 }
759 if ( updateRgn )
760 DisposeRgn( updateRgn );
761 if ( diffRgn )
762 DisposeRgn( diffRgn );
763
764 if ( !m_macNeedsErasing )
765 {
766 RgnHandle rectRgn = NewRgn() ;
767 SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
768 UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
769 DisposeRgn( rectRgn ) ;
770 }
771 }
772 InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
773 // turn this on to debug the refreshing cycle
774 #if wxMAC_DEBUG_REDRAW
775 PaintRect( rect ) ;
776 #endif
777 SetPort( formerPort ) ;
778 }
779