]> git.saurik.com Git - wxWidgets.git/blob - src/mac/toplevel.cpp
wxCheckWindowWndProc() now checks for the original window proc in the window class...
[wxWidgets.git] / src / mac / 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 if ( wxModelessWindows.Find(this) )
175 wxModelessWindows.DeleteObject(this);
176
177 DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
178 }
179
180
181 // ----------------------------------------------------------------------------
182 // wxTopLevelWindowMac maximize/minimize
183 // ----------------------------------------------------------------------------
184
185 void wxTopLevelWindowMac::Maximize(bool maximize)
186 {
187 // not available on mac
188 }
189
190 bool wxTopLevelWindowMac::IsMaximized() const
191 {
192 return false ;
193 }
194
195 void wxTopLevelWindowMac::Iconize(bool iconize)
196 {
197 // not available on mac
198 }
199
200 bool wxTopLevelWindowMac::IsIconized() const
201 {
202 // mac dialogs cannot be iconized
203 return FALSE;
204 }
205
206 void wxTopLevelWindowMac::Restore()
207 {
208 // not available on mac
209 }
210
211 // ----------------------------------------------------------------------------
212 // wxTopLevelWindowMac misc
213 // ----------------------------------------------------------------------------
214
215 void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
216 {
217 // this sets m_icon
218 wxTopLevelWindowBase::SetIcon(icon);
219 }
220
221 #if TARGET_CARBON
222
223 EventHandlerUPP wxMacWindowEventHandlerUPP = NULL ;
224
225 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
226
227 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
228 {
229 OSStatus result = eventNotHandledErr ;
230 EventRecord rec ;
231 switch ( GetEventClass( event ) )
232 {
233 case kEventClassTextInput :
234 if ( wxMacConvertEventToRecord( event , &rec ) )
235 {
236 short keycode ;
237 short keychar ;
238 keychar = short(rec.message & charCodeMask);
239 keycode = short(rec.message & keyCodeMask) >> 8 ;
240 wxWindow* focus = wxWindow::FindFocus() ;
241 // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
242 if ( (rec.modifiers & controlKey) && keychar >= 0 && keychar < 0x20 )
243 {
244 keychar += 0x40 ;
245 }
246 long keyval = wxMacTranslateKey(keychar, keycode) ;
247 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( focus , keyval , rec.modifiers , rec.when , rec.where.h , rec.where.v ) )
248 {
249 // was handled internally
250 result = noErr ;
251 }
252 }
253 break ;
254 default :
255 break ;
256 }
257 return result ;
258 }
259
260 #endif
261
262 void wxTopLevelWindowMac::MacInstallEventHandler()
263 {
264 #if TARGET_CARBON
265 if ( wxMacWindowEventHandlerUPP == NULL )
266 {
267 wxMacWindowEventHandlerUPP = NewEventHandlerUPP( wxMacWindowEventHandler ) ;
268 }
269
270 static const EventTypeSpec eventList[] =
271 {
272 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }
273 } ;
274 if ( m_macEventHandler )
275 {
276 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
277 m_macEventHandler = NULL ;
278 }
279 InstallWindowEventHandler(MAC_WXHWND(m_macWindow), wxMacWindowEventHandlerUPP, WXSIZEOF(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
280 #endif
281 }
282
283 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
284 const wxPoint& pos,
285 const wxSize& size,
286 long style,
287 const wxString& name )
288 {
289 SetName(name);
290 m_windowStyle = style;
291 m_isShown = FALSE;
292
293 // create frame.
294
295 Rect theBoundsRect;
296
297 m_x = (int)pos.x;
298 m_y = (int)pos.y;
299 if ( m_y < 50 )
300 m_y = 50 ;
301 if ( m_x < 20 )
302 m_x = 20 ;
303
304 m_width = size.x;
305 if (m_width == -1)
306 m_width = 20;
307 m_height = size.y;
308 if (m_height == -1)
309 m_height = 20;
310
311 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
312
313 // translate the window attributes in the appropriate window class and attributes
314
315 WindowClass wclass = 0;
316 WindowAttributes attr = kWindowNoAttributes ;
317
318 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
319 {
320 if (
321 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
322 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
323 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
324 )
325 {
326 wclass = kFloatingWindowClass ;
327 if ( HasFlag(wxTINY_CAPTION_VERT) )
328 {
329 attr |= kWindowSideTitlebarAttribute ;
330 }
331 }
332 else
333 {
334 wclass = kPlainWindowClass ;
335 }
336 }
337 else if ( HasFlag( wxCAPTION ) )
338 {
339 if ( HasFlag( wxDIALOG_MODAL ) )
340 {
341 wclass = kDocumentWindowClass ; // kMovableModalWindowClass ;
342 }
343 else
344 {
345 wclass = kDocumentWindowClass ;
346 }
347 }
348 else
349 {
350 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
351 HasFlag( wxSYSTEM_MENU ) )
352 {
353 wclass = kDocumentWindowClass ;
354 }
355 else
356 {
357 wclass = kPlainWindowClass ;
358 }
359 }
360
361 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
362 {
363 attr |= kWindowFullZoomAttribute ;
364 attr |= kWindowCollapseBoxAttribute ;
365 }
366 if ( HasFlag( wxRESIZE_BORDER ) )
367 {
368 attr |= kWindowResizableAttribute ;
369 }
370 if ( HasFlag( wxSYSTEM_MENU ) )
371 {
372 attr |= kWindowCloseBoxAttribute ;
373 }
374
375 ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
376 wxAssociateWinWithMacWindow( m_macWindow , this ) ;
377 wxString label ;
378 if( wxApp::s_macDefaultEncodingIsPC )
379 label = wxMacMakeMacStringFromPC( title ) ;
380 else
381 label = title ;
382 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
383 ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
384 MacInstallEventHandler() ;
385
386 m_macFocus = NULL ;
387 }
388
389 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
390 {
391 ((Point*)localOrigin)->h = 0;
392 ((Point*)localOrigin)->v = 0;
393 ((Rect*)clipRect)->left = 0;
394 ((Rect*)clipRect)->top = 0;
395 ((Rect*)clipRect)->right = m_width;
396 ((Rect*)clipRect)->bottom = m_height;
397 *window = m_macWindow ;
398 *rootwin = this ;
399 }
400
401 void wxTopLevelWindowMac::Clear()
402 {
403 wxWindow::Clear() ;
404 }
405
406 WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding()
407 {
408 return m_macRootControl ;
409 }
410
411
412 void wxTopLevelWindowMac::MacUpdate( long timestamp)
413 {
414
415 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
416
417 BeginUpdate( (WindowRef)m_macWindow ) ;
418
419 RgnHandle updateRgn = NewRgn();
420 RgnHandle diffRgn = NewRgn() ;
421 if ( updateRgn && diffRgn )
422 {
423 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
424 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
425 if ( !EmptyRgn( updateRgn ) )
426 {
427 MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ;
428 }
429 }
430 if ( updateRgn )
431 DisposeRgn( updateRgn );
432 if ( diffRgn )
433 DisposeRgn( diffRgn );
434 EndUpdate( (WindowRef)m_macWindow ) ;
435 SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
436 m_macNeedsErasing = false ;
437 }
438
439
440 // Raise the window to the top of the Z order
441 void wxTopLevelWindowMac::Raise()
442 {
443 ::BringToFront( (WindowRef)m_macWindow ) ;
444 }
445
446 // Lower the window to the bottom of the Z order
447 void wxTopLevelWindowMac::Lower()
448 {
449 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
450 }
451
452 void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
453 {
454 EventRecord *ev = (EventRecord*) evr ;
455 wxMouseEvent event(wxEVT_LEFT_DOWN);
456 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
457 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
458
459 event.m_leftDown = isDown && !controlDown;
460
461 event.m_middleDown = FALSE;
462 event.m_rightDown = isDown && controlDown;
463
464 if ( ev->what == mouseDown )
465 {
466 if ( controlDown )
467 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
468 else
469 event.SetEventType(wxEVT_LEFT_DOWN ) ;
470 }
471 else if ( ev->what == mouseUp )
472 {
473 if ( controlDown )
474 event.SetEventType(wxEVT_RIGHT_UP ) ;
475 else
476 event.SetEventType(wxEVT_LEFT_UP ) ;
477 }
478 else
479 {
480 event.SetEventType(wxEVT_MOTION ) ;
481 }
482
483 event.m_shiftDown = ev->modifiers & shiftKey;
484 event.m_controlDown = ev->modifiers & controlKey;
485 event.m_altDown = ev->modifiers & optionKey;
486 event.m_metaDown = ev->modifiers & cmdKey;
487
488 Point localwhere = ev->where ;
489
490 GrafPtr port ;
491 ::GetPort( &port ) ;
492 ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
493 ::GlobalToLocal( &localwhere ) ;
494 ::SetPort( port ) ;
495
496 if ( ev->what == mouseDown )
497 {
498 if ( ev->when - gs_lastWhen <= GetDblTime() )
499 {
500 if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
501 {
502 // This is not right if the second mouse down
503 // event occured in a differen window. We
504 // correct this in MacDispatchMouseEvent.
505 if ( controlDown )
506 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
507 else
508 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
509 }
510 gs_lastWhen = 0 ;
511 }
512 else
513 {
514 gs_lastWhen = ev->when ;
515 }
516 gs_lastWhere = localwhere ;
517 }
518
519 event.m_x = localwhere.h;
520 event.m_y = localwhere.v;
521 event.m_x += m_x;
522 event.m_y += m_y;
523
524 event.m_timeStamp = ev->when;
525 event.SetEventObject(this);
526 if ( wxTheApp->s_captureWindow )
527 {
528 int x = event.m_x ;
529 int y = event.m_y ;
530 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
531 event.m_x = x ;
532 event.m_y = y ;
533 event.SetEventObject( wxTheApp->s_captureWindow ) ;
534 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
535
536 if ( ev->what == mouseUp )
537 {
538 wxTheApp->s_captureWindow = NULL ;
539 if ( wxBusyCursorCount == 0 )
540 {
541 m_cursor.MacInstall() ;
542 }
543 }
544 }
545 else
546 {
547 MacDispatchMouseEvent( event ) ;
548 }
549 }
550
551 void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
552 {
553 MacFireMouseEvent( ev ) ;
554 }
555
556 void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
557 {
558 switch (part)
559 {
560 case inContent:
561 {
562 MacFireMouseEvent( ev ) ;
563 }
564 break ;
565 }
566 }
567
568 void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
569 {
570 switch (part)
571 {
572 case inContent:
573 {
574 MacFireMouseEvent( ev ) ;
575 }
576 break ;
577 }
578 }
579 void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating )
580 {
581 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
582 event.m_timeStamp = ((EventRecord*)ev)->when ;
583 event.SetEventObject(this);
584
585 GetEventHandler()->ProcessEvent(event);
586
587 UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
588
589 MacSuperEnabled( inIsActivating ) ;
590 }
591
592 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
593 {
594 }
595
596 void wxTopLevelWindowMac::SetTitle(const wxString& title)
597 {
598 wxWindow::SetTitle( title ) ;
599
600 wxString label ;
601
602 if( wxApp::s_macDefaultEncodingIsPC )
603 label = wxMacMakeMacStringFromPC( m_label ) ;
604 else
605 label = m_label ;
606
607 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
608 }
609
610 bool wxTopLevelWindowMac::Show(bool show)
611 {
612 if ( !wxWindow::Show(show) )
613 return FALSE;
614
615 if (show)
616 {
617 ::ShowWindow( (WindowRef)m_macWindow ) ;
618 ::SelectWindow( (WindowRef)m_macWindow ) ;
619 // no need to generate events here, they will get them triggered by macos
620 // actually they should be , but apparently they are not
621 wxSize size(m_width, m_height);
622 wxSizeEvent event(size, m_windowId);
623 event.SetEventObject(this);
624 GetEventHandler()->ProcessEvent(event);
625 }
626 else
627 {
628 ::HideWindow( (WindowRef)m_macWindow ) ;
629 }
630
631 if ( !show )
632 {
633 }
634 else
635 {
636 Refresh() ;
637 }
638
639 return TRUE;
640 }
641
642 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
643 {
644 int former_x = m_x ;
645 int former_y = m_y ;
646 int former_w = m_width ;
647 int former_h = m_height ;
648
649 int actualWidth = width;
650 int actualHeight = height;
651 int actualX = x;
652 int actualY = y;
653
654 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
655 actualWidth = m_minWidth;
656 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
657 actualHeight = m_minHeight;
658 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
659 actualWidth = m_maxWidth;
660 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
661 actualHeight = m_maxHeight;
662
663 bool doMove = false ;
664 bool doResize = false ;
665
666 if ( actualX != former_x || actualY != former_y )
667 {
668 doMove = true ;
669 }
670 if ( actualWidth != former_w || actualHeight != former_h )
671 {
672 doResize = true ;
673 }
674
675 if ( doMove || doResize )
676 {
677 m_x = actualX ;
678 m_y = actualY ;
679 m_width = actualWidth ;
680 m_height = actualHeight ;
681
682 if ( doMove )
683 ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost
684
685 if ( doResize )
686 ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true);
687
688 // the OS takes care of invalidating and erasing the new area
689 // we have erased the old one
690
691 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
692 {
693 wxFrame* frame = (wxFrame*) this ;
694 frame->PositionStatusBar();
695 frame->PositionToolBar();
696 }
697 if ( doMove )
698 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
699
700 MacRepositionScrollBars() ;
701 if ( doMove )
702 {
703 wxPoint point(m_x, m_y);
704 wxMoveEvent event(point, m_windowId);
705 event.SetEventObject(this);
706 GetEventHandler()->ProcessEvent(event) ;
707 }
708 if ( doResize )
709 {
710 MacRepositionScrollBars() ;
711 wxSize size(m_width, m_height);
712 wxSizeEvent event(size, m_windowId);
713 event.SetEventObject(this);
714 GetEventHandler()->ProcessEvent(event);
715 }
716 }
717
718 }
719
720 /*
721 * Invalidation Mechanism
722 *
723 * The update mechanism reflects exactely the windows mechanism
724 * the rect gets added to the window invalidate region, if the eraseBackground flag
725 * has been true for any part of the update rgn the background is erased in the entire region
726 * not just in the specified rect.
727 *
728 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
729 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
730 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
731 * will get the eraseBackground event first
732 */
733
734 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
735 {
736 GrafPtr formerPort ;
737 GetPort( &formerPort ) ;
738 SetPortWindowPort( (WindowRef)m_macWindow ) ;
739
740 m_macNeedsErasing |= eraseBackground ;
741
742 // if we already know that we will have to erase, there's no need to track the rest
743 if ( !m_macNeedsErasing)
744 {
745 // we end only here if eraseBackground is false
746 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
747 // we will have to erase anyway
748
749 RgnHandle updateRgn = NewRgn();
750 RgnHandle diffRgn = NewRgn() ;
751 if ( updateRgn && diffRgn )
752 {
753 GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
754 Point pt = {0,0} ;
755 LocalToGlobal( &pt ) ;
756 OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
757 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
758 if ( !EmptyRgn( diffRgn ) )
759 {
760 m_macNeedsErasing = true ;
761 }
762 }
763 if ( updateRgn )
764 DisposeRgn( updateRgn );
765 if ( diffRgn )
766 DisposeRgn( diffRgn );
767
768 if ( !m_macNeedsErasing )
769 {
770 RgnHandle rectRgn = NewRgn() ;
771 SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
772 UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
773 DisposeRgn( rectRgn ) ;
774 }
775 }
776 InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
777 // turn this on to debug the refreshing cycle
778 #if wxMAC_DEBUG_REDRAW
779 PaintRect( rect ) ;
780 #endif
781 SetPort( formerPort ) ;
782 }
783