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