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