]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
new menu code
[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 // ============================================================================
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 // Early versions of MacOS X don't refresh backgrounds properly,
585 // so refresh the whole window on activation and deactivation.
586 long osVersion = UMAGetSystemVersion();
587 if (osVersion >= 0x1000 && osVersion < 0x1020)
588 Refresh(TRUE);
589 else
590 MacSuperEnabled( inIsActivating ) ;
591 }
592
593 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
594 {
595 }
596
597 void wxTopLevelWindowMac::SetTitle(const wxString& title)
598 {
599 wxWindow::SetTitle( title ) ;
600
601 wxString label ;
602
603 if( wxApp::s_macDefaultEncodingIsPC )
604 label = wxMacMakeMacStringFromPC( m_label ) ;
605 else
606 label = m_label ;
607
608 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
609 }
610
611 bool wxTopLevelWindowMac::Show(bool show)
612 {
613 if ( !wxWindow::Show(show) )
614 return FALSE;
615
616 if (show)
617 {
618 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil);
619 ::SelectWindow( (WindowRef)m_macWindow ) ;
620 // no need to generate events here, they will get them triggered by macos
621 // actually they should be , but apparently they are not
622 wxSize size(m_width, m_height);
623 wxSizeEvent event(size, m_windowId);
624 event.SetEventObject(this);
625 GetEventHandler()->ProcessEvent(event);
626 }
627 else
628 {
629 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil);
630 }
631
632 if ( !show )
633 {
634 }
635 else
636 {
637 Refresh() ;
638 }
639
640 return TRUE;
641 }
642
643 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
644 {
645 int former_x = m_x ;
646 int former_y = m_y ;
647 int former_w = m_width ;
648 int former_h = m_height ;
649
650 int actualWidth = width;
651 int actualHeight = height;
652 int actualX = x;
653 int actualY = y;
654
655 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
656 actualWidth = m_minWidth;
657 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
658 actualHeight = m_minHeight;
659 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
660 actualWidth = m_maxWidth;
661 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
662 actualHeight = m_maxHeight;
663
664 bool doMove = false ;
665 bool doResize = false ;
666
667 if ( actualX != former_x || actualY != former_y )
668 {
669 doMove = true ;
670 }
671 if ( actualWidth != former_w || actualHeight != former_h )
672 {
673 doResize = true ;
674 }
675
676 if ( doMove || doResize )
677 {
678 m_x = actualX ;
679 m_y = actualY ;
680 m_width = actualWidth ;
681 m_height = actualHeight ;
682
683 if ( doMove )
684 ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost
685
686 if ( doResize )
687 ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true);
688
689 // the OS takes care of invalidating and erasing the new area so we only have to
690 // take care of refreshing for full repaints
691
692 if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
693 Refresh() ;
694
695
696 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
697 {
698 wxFrame* frame = (wxFrame*) this ;
699 frame->PositionStatusBar();
700 frame->PositionToolBar();
701 }
702 if ( doMove )
703 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
704
705 MacRepositionScrollBars() ;
706 if ( doMove )
707 {
708 wxPoint point(m_x, m_y);
709 wxMoveEvent event(point, m_windowId);
710 event.SetEventObject(this);
711 GetEventHandler()->ProcessEvent(event) ;
712 }
713 if ( doResize )
714 {
715 MacRepositionScrollBars() ;
716 wxSize size(m_width, m_height);
717 wxSizeEvent event(size, m_windowId);
718 event.SetEventObject(this);
719 GetEventHandler()->ProcessEvent(event);
720 }
721 }
722
723 }
724
725 /*
726 * Invalidation Mechanism
727 *
728 * The update mechanism reflects exactely the windows mechanism
729 * the rect gets added to the window invalidate region, if the eraseBackground flag
730 * has been true for any part of the update rgn the background is erased in the entire region
731 * not just in the specified rect.
732 *
733 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
734 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
735 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
736 * will get the eraseBackground event first
737 */
738
739 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
740 {
741 GrafPtr formerPort ;
742 GetPort( &formerPort ) ;
743 SetPortWindowPort( (WindowRef)m_macWindow ) ;
744
745 m_macNeedsErasing |= eraseBackground ;
746
747 // if we already know that we will have to erase, there's no need to track the rest
748 if ( !m_macNeedsErasing)
749 {
750 // we end only here if eraseBackground is false
751 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
752 // we will have to erase anyway
753
754 RgnHandle updateRgn = NewRgn();
755 RgnHandle diffRgn = NewRgn() ;
756 if ( updateRgn && diffRgn )
757 {
758 GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
759 Point pt = {0,0} ;
760 LocalToGlobal( &pt ) ;
761 OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
762 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
763 if ( !EmptyRgn( diffRgn ) )
764 {
765 m_macNeedsErasing = true ;
766 }
767 }
768 if ( updateRgn )
769 DisposeRgn( updateRgn );
770 if ( diffRgn )
771 DisposeRgn( diffRgn );
772
773 if ( !m_macNeedsErasing )
774 {
775 RgnHandle rectRgn = NewRgn() ;
776 SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
777 UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
778 DisposeRgn( rectRgn ) ;
779 }
780 }
781 InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
782 // turn this on to debug the refreshing cycle
783 #if wxMAC_DEBUG_REDRAW
784 PaintRect( rect ) ;
785 #endif
786 SetPort( formerPort ) ;
787 }
788