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