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