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