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