]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toplevel.cpp
cleanup, Carbon Events
[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
a15eb0a5
SC
62// ============================================================================
63// wxTopLevelWindowMac implementation
64// ============================================================================
65
5f0b2f22
SC
66// ---------------------------------------------------------------------------
67// wxWindowMac utility functions
68// ---------------------------------------------------------------------------
69
70// Find an item given the Macintosh Window Reference
71
72wxList *wxWinMacWindowList = NULL;
76a5e5d2 73wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef)
5f0b2f22
SC
74{
75 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
76 if (!node)
77 return NULL;
eb22f2a6 78 return (wxTopLevelWindowMac *)node->GetData();
5f0b2f22
SC
79}
80
76a5e5d2 81void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win)
5f0b2f22
SC
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
91void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
92{
93 wxWinMacWindowList->DeleteObject(win);
94}
95
96
a15eb0a5
SC
97// ----------------------------------------------------------------------------
98// wxTopLevelWindowMac creation
99// ----------------------------------------------------------------------------
100
76a5e5d2 101WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
5f0b2f22 102
a15eb0a5
SC
103void wxTopLevelWindowMac::Init()
104{
105 m_iconized =
106 m_maximizeOnShow = FALSE;
5f0b2f22
SC
107 m_macNoEraseUpdateRgn = NewRgn() ;
108 m_macNeedsErasing = false ;
6a17ca35 109 m_macWindow = NULL ;
7c091673 110 m_macEventHandler = NULL ;
a15eb0a5
SC
111}
112
118f012e
SC
113class wxMacDeferredWindowDeleter : public wxObject
114{
115public :
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
a15eb0a5
SC
128bool 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
153wxTopLevelWindowMac::~wxTopLevelWindowMac()
154{
6a17ca35
SC
155 if ( m_macWindow )
156 {
157 wxToolTip::NotifyWindowDelete(m_macWindow) ;
118f012e 158 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
6a17ca35 159 }
7c091673 160
f75363ee 161#if TARGET_CARBON
7c091673
SC
162 if ( m_macEventHandler )
163 {
164 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
165 m_macEventHandler = NULL ;
166 }
167#endif
5f0b2f22
SC
168 wxRemoveMacWindowAssociation( this ) ;
169
a15eb0a5
SC
170 if ( wxModelessWindows.Find(this) )
171 wxModelessWindows.DeleteObject(this);
172
76a5e5d2 173 DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
a15eb0a5
SC
174}
175
176
177// ----------------------------------------------------------------------------
178// wxTopLevelWindowMac maximize/minimize
179// ----------------------------------------------------------------------------
180
181void wxTopLevelWindowMac::Maximize(bool maximize)
182{
183 // not available on mac
184}
185
186bool wxTopLevelWindowMac::IsMaximized() const
187{
188 return false ;
189}
190
191void wxTopLevelWindowMac::Iconize(bool iconize)
192{
193 // not available on mac
194}
195
196bool wxTopLevelWindowMac::IsIconized() const
197{
ed60b502 198 // mac dialogs cannot be iconized
a15eb0a5
SC
199 return FALSE;
200}
201
202void wxTopLevelWindowMac::Restore()
203{
204 // not available on mac
205}
206
207// ----------------------------------------------------------------------------
208// wxTopLevelWindowMac misc
209// ----------------------------------------------------------------------------
210
211void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
212{
213 // this sets m_icon
214 wxTopLevelWindowBase::SetIcon(icon);
215}
5f0b2f22 216
7c091673
SC
217#if TARGET_CARBON
218
219EventHandlerUPP wxMacWindowEventHandlerUPP = NULL ;
220
ac2d1ca6
SC
221extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
222
7c091673
SC
223pascal 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 {
4dcf0afe 232 wxTheApp->m_macCurrentEvent = &rec ;
ac2d1ca6 233 wxWindow* focus = wxWindow::FindFocus() ;
2b5f62a0 234 if ( (focus != NULL) && !UMAMenuEvent(&rec) && wxTheApp->MacSendKeyDownEvent( focus , rec.message , rec.modifiers , rec.when , rec.where.h , rec.where.v ) )
ac2d1ca6
SC
235 {
236 // was handled internally
237 result = noErr ;
238 }
7c091673
SC
239 }
240 break ;
241 default :
242 break ;
243 }
244 return result ;
245}
246
247#endif
248
249void 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
5f0b2f22
SC
270void 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
f5744893 305 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
5f0b2f22 306 {
f5744893
SC
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 )
5f0b2f22 312 {
f5744893
SC
313 wclass = kFloatingWindowClass ;
314 if ( HasFlag(wxTINY_CAPTION_VERT) )
315 {
316 attr |= kWindowSideTitlebarAttribute ;
317 }
318 }
319 else
320 {
2b5f62a0 321#if TARGET_CARBON
f5744893 322 wclass = kPlainWindowClass ;
2b5f62a0
VZ
323#else
324 wclass = kFloatingWindowClass ;
325#endif
5f0b2f22
SC
326 }
327 }
328 else if ( HasFlag( wxCAPTION ) )
329 {
330 if ( HasFlag( wxDIALOG_MODAL ) )
331 {
60fcb584 332 wclass = kDocumentWindowClass ; // kMovableModalWindowClass ;
5f0b2f22
SC
333 }
334 else
335 {
336 wclass = kDocumentWindowClass ;
337 }
338 }
339 else
340 {
f5744893
SC
341 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
342 HasFlag( wxSYSTEM_MENU ) )
343 {
344 wclass = kDocumentWindowClass ;
345 }
346 else
347 {
2b5f62a0 348#if TARGET_CARBON
f5744893 349 wclass = kPlainWindowClass ;
2b5f62a0
VZ
350#else
351 wclass = kModalWindowClass ;
352#endif
f5744893 353 }
5f0b2f22
SC
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
76a5e5d2 370 ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
5f0b2f22
SC
371 wxAssociateWinWithMacWindow( m_macWindow , this ) ;
372 wxString label ;
373 if( wxApp::s_macDefaultEncodingIsPC )
374 label = wxMacMakeMacStringFromPC( title ) ;
375 else
376 label = title ;
76a5e5d2
SC
377 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
378 ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
7c091673 379 MacInstallEventHandler() ;
5f0b2f22
SC
380
381 m_macFocus = NULL ;
382}
383
76a5e5d2 384void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
5f0b2f22 385{
76a5e5d2
SC
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;
5f0b2f22
SC
392 *window = m_macWindow ;
393 *rootwin = this ;
394}
395
396void wxTopLevelWindowMac::Clear()
397{
7d9d1fd7 398 wxWindow::Clear() ;
5f0b2f22
SC
399}
400
76a5e5d2 401WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding()
5f0b2f22
SC
402{
403 return m_macRootControl ;
404}
405
406
407void wxTopLevelWindowMac::MacUpdate( long timestamp)
408{
76a5e5d2 409
66a09d47 410 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
76a5e5d2
SC
411
412 BeginUpdate( (WindowRef)m_macWindow ) ;
5f0b2f22
SC
413
414 RgnHandle updateRgn = NewRgn();
415 RgnHandle diffRgn = NewRgn() ;
416 if ( updateRgn && diffRgn )
417 {
76a5e5d2
SC
418 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
419 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
5f0b2f22
SC
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 );
76a5e5d2
SC
429 EndUpdate( (WindowRef)m_macWindow ) ;
430 SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
5f0b2f22
SC
431 m_macNeedsErasing = false ;
432}
433
434
435// Raise the window to the top of the Z order
436void wxTopLevelWindowMac::Raise()
437{
76a5e5d2 438 ::BringToFront( (WindowRef)m_macWindow ) ;
5f0b2f22
SC
439}
440
441// Lower the window to the bottom of the Z order
442void wxTopLevelWindowMac::Lower()
443{
76a5e5d2 444 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
5f0b2f22
SC
445}
446
76a5e5d2 447void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
5f0b2f22 448{
76a5e5d2 449 EventRecord *ev = (EventRecord*) evr ;
5f0b2f22
SC
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 ) ;
76a5e5d2 487 ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
5f0b2f22
SC
488 ::GlobalToLocal( &localwhere ) ;
489 ::SetPort( port ) ;
490
491 if ( ev->what == mouseDown )
492 {
32b5be3d 493 if ( ev->when - gs_lastWhen <= GetDblTime() )
5f0b2f22 494 {
32b5be3d 495 if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
5f0b2f22 496 {
32b5be3d
RR
497 // This is not right if the second mouse down
498 // event occured in a differen window. We
499 // correct this in MacDispatchMouseEvent.
5f0b2f22
SC
500 if ( controlDown )
501 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
502 else
503 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
504 }
32b5be3d 505 gs_lastWhen = 0 ;
5f0b2f22
SC
506 }
507 else
508 {
32b5be3d 509 gs_lastWhen = ev->when ;
5f0b2f22 510 }
32b5be3d 511 gs_lastWhere = localwhere ;
5f0b2f22
SC
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
5f0b2f22
SC
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 ;
2e6857fa 528 event.SetEventObject( wxTheApp->s_captureWindow ) ;
5f0b2f22 529 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
ed60b502 530
5f0b2f22
SC
531 if ( ev->what == mouseUp )
532 {
533 wxTheApp->s_captureWindow = NULL ;
6b57b49a 534 if ( !wxIsBusy() )
5f0b2f22
SC
535 {
536 m_cursor.MacInstall() ;
537 }
538 }
539 }
540 else
541 {
542 MacDispatchMouseEvent( event ) ;
543 }
544}
545
76a5e5d2 546void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
5f0b2f22
SC
547{
548 MacFireMouseEvent( ev ) ;
549}
550
76a5e5d2 551void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
5f0b2f22
SC
552{
553 switch (part)
554 {
555 case inContent:
556 {
557 MacFireMouseEvent( ev ) ;
558 }
559 break ;
560 }
561}
562
76a5e5d2 563void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
5f0b2f22
SC
564{
565 switch (part)
566 {
567 case inContent:
568 {
569 MacFireMouseEvent( ev ) ;
570 }
571 break ;
572 }
573}
76a5e5d2 574void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating )
5f0b2f22
SC
575{
576 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
76a5e5d2 577 event.m_timeStamp = ((EventRecord*)ev)->when ;
5f0b2f22
SC
578 event.SetEventObject(this);
579
580 GetEventHandler()->ProcessEvent(event);
581
76a5e5d2 582 UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
5f0b2f22 583
a006e78b
JS
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 ) ;
5f0b2f22
SC
591}
592
76a5e5d2 593void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
5f0b2f22
SC
594{
595}
596
597void 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
76a5e5d2 608 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
5f0b2f22
SC
609}
610
611bool wxTopLevelWindowMac::Show(bool show)
612{
613 if ( !wxWindow::Show(show) )
614 return FALSE;
615
616 if (show)
2b5f62a0
VZ
617 {
618 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil);
76a5e5d2 619 ::SelectWindow( (WindowRef)m_macWindow ) ;
5f0b2f22
SC
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 {
2b5f62a0 629 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil);
5f0b2f22
SC
630 }
631
632 if ( !show )
633 {
634 }
635 else
636 {
637 Refresh() ;
638 }
639
640 return TRUE;
641}
642
643void 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 )
76a5e5d2 684 ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost
5f0b2f22
SC
685
686 if ( doResize )
76a5e5d2 687 ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true);
2b5f62a0
VZ
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() ;
5f0b2f22 694
5f0b2f22
SC
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
76a5e5d2 739void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
5f0b2f22
SC
740{
741 GrafPtr formerPort ;
742 GetPort( &formerPort ) ;
76a5e5d2 743 SetPortWindowPort( (WindowRef)m_macWindow ) ;
5f0b2f22
SC
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 {
76a5e5d2 758 GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
5f0b2f22
SC
759 Point pt = {0,0} ;
760 LocalToGlobal( &pt ) ;
761 OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
76a5e5d2 762 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
5f0b2f22
SC
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() ;
76a5e5d2
SC
776 SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
777 UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
5f0b2f22
SC
778 DisposeRgn( rectRgn ) ;
779 }
780 }
76a5e5d2 781 InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
5f0b2f22 782 // turn this on to debug the refreshing cycle
34dc8f91 783#if wxMAC_DEBUG_REDRAW
5f0b2f22
SC
784 PaintRect( rect ) ;
785#endif
786 SetPort( formerPort ) ;
787}
a07c1212 788