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