]> git.saurik.com Git - wxWidgets.git/blob - src/mac/toplevel.cpp
Regenerate makefiles.
[wxWidgets.git] / src / mac / toplevel.cpp
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"
34 #include "wx/frame.h"
35 #include "wx/string.h"
36 #include "wx/log.h"
37 #include "wx/intl.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/app.h"
43 #include "wx/tooltip.h"
44 #include "wx/dnd.h"
45
46 #define wxMAC_DEBUG_REDRAW 0
47 #ifndef wxMAC_DEBUG_REDRAW
48 #define wxMAC_DEBUG_REDRAW 0
49 #endif
50
51 // ----------------------------------------------------------------------------
52 // globals
53 // ----------------------------------------------------------------------------
54
55 // list of all frames and modeless dialogs
56 wxWindowList wxModelessWindows;
57
58 // double click testing
59 static Point gs_lastWhere;
60 static long gs_lastWhen = 0;
61
62 // ============================================================================
63 // wxTopLevelWindowMac implementation
64 // ============================================================================
65
66 // ---------------------------------------------------------------------------
67 // Carbon Events
68 // ---------------------------------------------------------------------------
69
70 #if TARGET_CARBON
71
72 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
73
74 static const EventTypeSpec eventList[] =
75 {
76 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
77 /*
78 { kEventClassKeyboard, kEventRawKeyDown } ,
79 { kEventClassKeyboard, kEventRawKeyRepeat } ,
80 { kEventClassKeyboard, kEventRawKeyUp } ,
81 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
82 */
83 { kEventClassWindow , kEventWindowUpdate } ,
84 { kEventClassWindow , kEventWindowActivated } ,
85 { kEventClassWindow , kEventWindowDeactivated } ,
86 { kEventClassWindow , kEventWindowBoundsChanging } ,
87 { kEventClassWindow , kEventWindowBoundsChanged } ,
88 { kEventClassWindow , kEventWindowClose } ,
89
90 { kEventClassMouse , kEventMouseDown } ,
91 { kEventClassMouse , kEventMouseUp } ,
92 { kEventClassMouse , kEventMouseMoved } ,
93 { kEventClassMouse , kEventMouseDragged } ,
94
95 } ;
96
97 static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
98 {
99 OSStatus result = eventNotHandledErr ;
100 EventRecord rec ;
101
102 if ( wxMacConvertEventToRecord( event , &rec ) )
103 {
104 wxTheApp->m_macCurrentEvent = &rec ;
105 wxWindow* focus = wxWindow::FindFocus() ;
106 if ( (focus != NULL) && !UMAMenuEvent(&rec) && wxTheApp->MacSendKeyDownEvent( focus , rec.message , rec.modifiers , rec.when , rec.where.h , rec.where.v ) )
107 {
108 // was handled internally
109 result = noErr ;
110 }
111 }
112
113 return result ;
114 }
115
116 static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
117 {
118 OSStatus result = eventNotHandledErr ;
119
120 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
121 Point point ;
122 UInt32 modifiers = 0;
123 EventMouseButton button = 0 ;
124 UInt32 click = 0 ;
125
126 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
127 sizeof( Point ), NULL, &point );
128 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL,
129 sizeof( UInt32 ), NULL, &modifiers );
130 GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL,
131 sizeof( EventMouseButton ), NULL, &button );
132 GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL,
133 sizeof( UInt32 ), NULL, &click );
134
135 if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
136 modifiers += btnState ;
137
138 WindowRef window ;
139 short windowPart = ::FindWindow(point, &window);
140
141 if ( IsWindowActive(window) && windowPart == inContent )
142 {
143 switch ( GetEventKind( event ) )
144 {
145 case kEventMouseDown :
146 toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
147 result = noErr ;
148 break ;
149 case kEventMouseUp :
150 toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
151 result = noErr ;
152 break ;
153 case kEventMouseMoved :
154 toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
155 result = noErr ;
156 break ;
157 case kEventMouseDragged :
158 toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
159 result = noErr ;
160 break ;
161 default :
162 break ;
163 }
164 }
165
166 return result ;
167
168
169 }
170 static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
171 {
172 OSStatus result = eventNotHandledErr ;
173 OSStatus err = noErr ;
174
175 UInt32 attributes;
176 WindowRef windowRef ;
177 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
178
179 GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL,
180 sizeof( WindowRef ), NULL, &windowRef );
181
182 switch( GetEventKind( event ) )
183 {
184 case kEventWindowUpdate :
185 if ( !wxPendingDelete.Member(toplevelWindow) )
186 toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ;
187 result = noErr ;
188 break ;
189 case kEventWindowActivated :
190 toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ;
191 result = noErr ;
192 break ;
193 case kEventWindowDeactivated :
194 toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ;
195 result = noErr ;
196 break ;
197 case kEventWindowClose :
198 toplevelWindow->Close() ;
199 result = noErr ;
200 break ;
201 case kEventWindowBoundsChanged :
202 err = GetEventParameter( event, kEventParamAttributes, typeUInt32,
203 NULL, sizeof( UInt32 ), NULL, &attributes );
204 if ( err == noErr )
205 {
206 Rect newContentRect ;
207
208 GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL,
209 sizeof( newContentRect ), NULL, &newContentRect );
210
211 toplevelWindow->SetSize( newContentRect.left , newContentRect.top ,
212 newContentRect.right - newContentRect.left ,
213 newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
214
215 result = noErr;
216 }
217 break ;
218 default :
219 break ;
220 }
221 return result ;
222 }
223
224 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
225 {
226 OSStatus result = eventNotHandledErr ;
227
228 switch ( GetEventClass( event ) )
229 {
230 case kEventClassTextInput :
231 result = TextInputEventHandler( handler, event , data ) ;
232 break ;
233 case kEventClassWindow :
234 result = WindowEventHandler( handler, event , data ) ;
235 break ;
236 case kEventClassMouse :
237 result = MouseEventHandler( handler, event , data ) ;
238 break ;
239 default :
240 break ;
241 }
242 return result ;
243 }
244
245 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
246
247 #endif
248
249 // ---------------------------------------------------------------------------
250 // wxWindowMac utility functions
251 // ---------------------------------------------------------------------------
252
253 // Find an item given the Macintosh Window Reference
254
255 wxList *wxWinMacWindowList = NULL;
256 wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef)
257 {
258 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
259 if (!node)
260 return NULL;
261 return (wxTopLevelWindowMac *)node->GetData();
262 }
263
264 void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win)
265 {
266 // adding NULL WindowRef is (first) surely a result of an error and
267 // (secondly) breaks menu command processing
268 wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
269
270 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
271 wxWinMacWindowList->Append((long)inWindowRef, win);
272 }
273
274 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
275 {
276 wxWinMacWindowList->DeleteObject(win);
277 }
278
279
280 // ----------------------------------------------------------------------------
281 // wxTopLevelWindowMac creation
282 // ----------------------------------------------------------------------------
283
284 WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
285
286 void wxTopLevelWindowMac::Init()
287 {
288 m_iconized =
289 m_maximizeOnShow = FALSE;
290 m_macNoEraseUpdateRgn = NewRgn() ;
291 m_macNeedsErasing = false ;
292 m_macWindow = NULL ;
293 #if TARGET_CARBON
294 m_macEventHandler = NULL ;
295 #endif
296 }
297
298 class wxMacDeferredWindowDeleter : public wxObject
299 {
300 public :
301 wxMacDeferredWindowDeleter( WindowRef windowRef )
302 {
303 m_macWindow = windowRef ;
304 }
305 virtual ~wxMacDeferredWindowDeleter()
306 {
307 UMADisposeWindow( (WindowRef) m_macWindow ) ;
308 }
309 protected :
310 WindowRef m_macWindow ;
311 } ;
312
313 bool wxTopLevelWindowMac::Create(wxWindow *parent,
314 wxWindowID id,
315 const wxString& title,
316 const wxPoint& pos,
317 const wxSize& size,
318 long style,
319 const wxString& name)
320 {
321 // init our fields
322 Init();
323
324 m_windowStyle = style;
325
326 SetName(name);
327
328 m_windowId = id == -1 ? NewControlId() : id;
329
330 wxTopLevelWindows.Append(this);
331
332 if ( parent )
333 parent->AddChild(this);
334
335 return TRUE;
336 }
337
338 wxTopLevelWindowMac::~wxTopLevelWindowMac()
339 {
340 if ( m_macWindow )
341 {
342 wxToolTip::NotifyWindowDelete(m_macWindow) ;
343 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
344 }
345
346 #if TARGET_CARBON
347 if ( m_macEventHandler )
348 {
349 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
350 m_macEventHandler = NULL ;
351 }
352 #endif
353
354 wxRemoveMacWindowAssociation( this ) ;
355
356 if ( wxModelessWindows.Find(this) )
357 wxModelessWindows.DeleteObject(this);
358
359 DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
360 }
361
362
363 // ----------------------------------------------------------------------------
364 // wxTopLevelWindowMac maximize/minimize
365 // ----------------------------------------------------------------------------
366
367 void wxTopLevelWindowMac::Maximize(bool maximize)
368 {
369 // not available on mac
370 }
371
372 bool wxTopLevelWindowMac::IsMaximized() const
373 {
374 return false ;
375 }
376
377 void wxTopLevelWindowMac::Iconize(bool iconize)
378 {
379 // not available on mac
380 }
381
382 bool wxTopLevelWindowMac::IsIconized() const
383 {
384 // mac dialogs cannot be iconized
385 return FALSE;
386 }
387
388 void wxTopLevelWindowMac::Restore()
389 {
390 // not available on mac
391 }
392
393 // ----------------------------------------------------------------------------
394 // wxTopLevelWindowMac misc
395 // ----------------------------------------------------------------------------
396
397 void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
398 {
399 // this sets m_icon
400 wxTopLevelWindowBase::SetIcon(icon);
401 }
402
403 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
404 const wxPoint& pos,
405 const wxSize& size,
406 long style,
407 const wxString& name )
408 {
409 SetName(name);
410 m_windowStyle = style;
411 m_isShown = FALSE;
412
413 // create frame.
414
415 Rect theBoundsRect;
416
417 m_x = (int)pos.x;
418 m_y = (int)pos.y;
419 if ( m_y < 50 )
420 m_y = 50 ;
421 if ( m_x < 20 )
422 m_x = 20 ;
423
424 m_width = size.x;
425 if (m_width == -1)
426 m_width = 20;
427 m_height = size.y;
428 if (m_height == -1)
429 m_height = 20;
430
431 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
432
433 // translate the window attributes in the appropriate window class and attributes
434
435 WindowClass wclass = 0;
436 WindowAttributes attr = kWindowNoAttributes ;
437
438 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
439 {
440 if (
441 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
442 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
443 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
444 )
445 {
446 wclass = kFloatingWindowClass ;
447 if ( HasFlag(wxTINY_CAPTION_VERT) )
448 {
449 attr |= kWindowSideTitlebarAttribute ;
450 }
451 }
452 else
453 {
454 #if TARGET_CARBON
455 wclass = kPlainWindowClass ;
456 #else
457 wclass = kFloatingWindowClass ;
458 #endif
459 }
460 }
461 else if ( HasFlag( wxCAPTION ) )
462 {
463 if ( HasFlag( wxDIALOG_MODAL ) )
464 {
465 wclass = kDocumentWindowClass ; // kMovableModalWindowClass ;
466 }
467 else
468 {
469 wclass = kDocumentWindowClass ;
470 }
471 }
472 else
473 {
474 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
475 HasFlag( wxSYSTEM_MENU ) )
476 {
477 wclass = kDocumentWindowClass ;
478 }
479 else
480 {
481 #if TARGET_CARBON
482 wclass = kPlainWindowClass ;
483 #else
484 wclass = kModalWindowClass ;
485 #endif
486 }
487 }
488
489 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
490 {
491 attr |= kWindowFullZoomAttribute ;
492 attr |= kWindowCollapseBoxAttribute ;
493 }
494 if ( HasFlag( wxRESIZE_BORDER ) )
495 {
496 attr |= kWindowResizableAttribute ;
497 }
498 if ( HasFlag( wxSYSTEM_MENU ) )
499 {
500 attr |= kWindowCloseBoxAttribute ;
501 }
502
503 ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
504 wxAssociateWinWithMacWindow( m_macWindow , this ) ;
505 wxString label ;
506 if( wxApp::s_macDefaultEncodingIsPC )
507 label = wxMacMakeMacStringFromPC( title ) ;
508 else
509 label = title ;
510 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
511 ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
512 #if TARGET_CARBON
513 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
514 InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(),
515 GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
516 #endif
517 m_macFocus = NULL ;
518 }
519
520 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
521 {
522 ((Point*)localOrigin)->h = 0;
523 ((Point*)localOrigin)->v = 0;
524 ((Rect*)clipRect)->left = 0;
525 ((Rect*)clipRect)->top = 0;
526 ((Rect*)clipRect)->right = m_width;
527 ((Rect*)clipRect)->bottom = m_height;
528 *window = m_macWindow ;
529 *rootwin = this ;
530 }
531
532 void wxTopLevelWindowMac::Clear()
533 {
534 wxWindow::Clear() ;
535 }
536
537 WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding()
538 {
539 return m_macRootControl ;
540 }
541
542
543 void wxTopLevelWindowMac::MacUpdate( long timestamp)
544 {
545
546 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
547
548 BeginUpdate( (WindowRef)m_macWindow ) ;
549
550 RgnHandle updateRgn = NewRgn();
551 RgnHandle diffRgn = NewRgn() ;
552 if ( updateRgn && diffRgn )
553 {
554 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
555 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
556 if ( !EmptyRgn( updateRgn ) )
557 {
558 MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ;
559 }
560 }
561 if ( updateRgn )
562 DisposeRgn( updateRgn );
563 if ( diffRgn )
564 DisposeRgn( diffRgn );
565 EndUpdate( (WindowRef)m_macWindow ) ;
566 SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
567 m_macNeedsErasing = false ;
568 }
569
570
571 // Raise the window to the top of the Z order
572 void wxTopLevelWindowMac::Raise()
573 {
574 ::BringToFront( (WindowRef)m_macWindow ) ;
575 }
576
577 // Lower the window to the bottom of the Z order
578 void wxTopLevelWindowMac::Lower()
579 {
580 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
581 }
582
583 void wxTopLevelWindowMac::MacFireMouseEvent(
584 wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp )
585 {
586 wxMouseEvent event(wxEVT_LEFT_DOWN);
587 bool isDown = !(modifiers & btnState) ; // 1 is for up
588 bool controlDown = modifiers & controlKey ; // for simulating right mouse
589
590 event.m_leftDown = isDown && !controlDown;
591
592 event.m_middleDown = FALSE;
593 event.m_rightDown = isDown && controlDown;
594
595 if ( kind == mouseDown )
596 {
597 if ( controlDown )
598 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
599 else
600 event.SetEventType(wxEVT_LEFT_DOWN ) ;
601 }
602 else if ( kind == mouseUp )
603 {
604 if ( controlDown )
605 event.SetEventType(wxEVT_RIGHT_UP ) ;
606 else
607 event.SetEventType(wxEVT_LEFT_UP ) ;
608 }
609 else
610 {
611 event.SetEventType(wxEVT_MOTION ) ;
612 }
613
614 event.m_shiftDown = modifiers & shiftKey;
615 event.m_controlDown = modifiers & controlKey;
616 event.m_altDown = modifiers & optionKey;
617 event.m_metaDown = modifiers & cmdKey;
618
619 Point localwhere ;
620 localwhere.h = x ;
621 localwhere.v = y ;
622
623 GrafPtr port ;
624 ::GetPort( &port ) ;
625 ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
626 ::GlobalToLocal( &localwhere ) ;
627 ::SetPort( port ) ;
628
629 if ( kind == mouseDown )
630 {
631 if ( timestamp - gs_lastWhen <= GetDblTime() )
632 {
633 if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
634 {
635 // This is not right if the second mouse down
636 // event occured in a differen window. We
637 // correct this in MacDispatchMouseEvent.
638 if ( controlDown )
639 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
640 else
641 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
642 }
643 gs_lastWhen = 0 ;
644 }
645 else
646 {
647 gs_lastWhen = timestamp ;
648 }
649 gs_lastWhere = localwhere ;
650 }
651
652 event.m_x = localwhere.h;
653 event.m_y = localwhere.v;
654 event.m_x += m_x;
655 event.m_y += m_y;
656
657 event.m_timeStamp = timestamp;
658 event.SetEventObject(this);
659 if ( wxTheApp->s_captureWindow )
660 {
661 int x = event.m_x ;
662 int y = event.m_y ;
663 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
664 event.m_x = x ;
665 event.m_y = y ;
666 event.SetEventObject( wxTheApp->s_captureWindow ) ;
667 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
668
669 if ( kind == mouseUp )
670 {
671 wxTheApp->s_captureWindow = NULL ;
672 if ( !wxIsBusy() )
673 {
674 m_cursor.MacInstall() ;
675 }
676 }
677 }
678 else
679 {
680 MacDispatchMouseEvent( event ) ;
681 }
682 }
683 #if !TARGET_CARBON
684
685 void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
686 {
687 MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,
688 ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;
689 }
690
691 void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
692 {
693 switch (part)
694 {
695 case inContent:
696 {
697 MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,
698 ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;
699 }
700 break ;
701 }
702 }
703
704 void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
705 {
706 switch (part)
707 {
708 case inContent:
709 {
710 MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,
711 ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;
712 }
713 break ;
714 }
715 }
716
717 #endif
718
719 void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
720 {
721 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
722 event.m_timeStamp = timestamp ;
723 event.SetEventObject(this);
724
725 GetEventHandler()->ProcessEvent(event);
726
727 UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
728
729 // Early versions of MacOS X don't refresh backgrounds properly,
730 // so refresh the whole window on activation and deactivation.
731 long osVersion = UMAGetSystemVersion();
732 if (osVersion >= 0x1000 && osVersion < 0x1020)
733 Refresh(TRUE);
734 else
735 MacSuperEnabled( inIsActivating ) ;
736 }
737
738 #if !TARGET_CARBON
739
740 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
741 {
742 }
743
744 #endif
745
746 void wxTopLevelWindowMac::SetTitle(const wxString& title)
747 {
748 wxWindow::SetTitle( title ) ;
749
750 wxString label ;
751
752 if( wxApp::s_macDefaultEncodingIsPC )
753 label = wxMacMakeMacStringFromPC( m_label ) ;
754 else
755 label = m_label ;
756
757 UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
758 }
759
760 bool wxTopLevelWindowMac::Show(bool show)
761 {
762 if ( !wxWindow::Show(show) )
763 return FALSE;
764
765 if (show)
766 {
767 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil);
768 ::SelectWindow( (WindowRef)m_macWindow ) ;
769 // no need to generate events here, they will get them triggered by macos
770 // actually they should be , but apparently they are not
771 wxSize size(m_width, m_height);
772 wxSizeEvent event(size, m_windowId);
773 event.SetEventObject(this);
774 GetEventHandler()->ProcessEvent(event);
775 }
776 else
777 {
778 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil);
779 }
780
781 if ( !show )
782 {
783 }
784 else
785 {
786 Refresh() ;
787 }
788
789 return TRUE;
790 }
791
792 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
793 {
794 int former_x = m_x ;
795 int former_y = m_y ;
796 int former_w = m_width ;
797 int former_h = m_height ;
798
799 int actualWidth = width;
800 int actualHeight = height;
801 int actualX = x;
802 int actualY = y;
803
804 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
805 actualWidth = m_minWidth;
806 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
807 actualHeight = m_minHeight;
808 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
809 actualWidth = m_maxWidth;
810 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
811 actualHeight = m_maxHeight;
812
813 bool doMove = false ;
814 bool doResize = false ;
815
816 if ( actualX != former_x || actualY != former_y )
817 {
818 doMove = true ;
819 }
820 if ( actualWidth != former_w || actualHeight != former_h )
821 {
822 doResize = true ;
823 }
824
825 if ( doMove || doResize )
826 {
827 m_x = actualX ;
828 m_y = actualY ;
829 m_width = actualWidth ;
830 m_height = actualHeight ;
831
832 if ( doMove )
833 ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost
834
835 if ( doResize )
836 ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true);
837
838 // the OS takes care of invalidating and erasing the new area so we only have to
839 // take care of refreshing for full repaints
840
841 if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
842 Refresh() ;
843
844
845 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
846 {
847 wxFrame* frame = (wxFrame*) this ;
848 frame->PositionStatusBar();
849 frame->PositionToolBar();
850 }
851 if ( doMove )
852 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
853
854 MacRepositionScrollBars() ;
855 if ( doMove )
856 {
857 wxPoint point(m_x, m_y);
858 wxMoveEvent event(point, m_windowId);
859 event.SetEventObject(this);
860 GetEventHandler()->ProcessEvent(event) ;
861 }
862 if ( doResize )
863 {
864 MacRepositionScrollBars() ;
865 wxSize size(m_width, m_height);
866 wxSizeEvent event(size, m_windowId);
867 event.SetEventObject(this);
868 GetEventHandler()->ProcessEvent(event);
869 }
870 }
871
872 }
873
874 /*
875 * Invalidation Mechanism
876 *
877 * The update mechanism reflects exactely the windows mechanism
878 * the rect gets added to the window invalidate region, if the eraseBackground flag
879 * has been true for any part of the update rgn the background is erased in the entire region
880 * not just in the specified rect.
881 *
882 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
883 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
884 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
885 * will get the eraseBackground event first
886 */
887
888 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
889 {
890 GrafPtr formerPort ;
891 GetPort( &formerPort ) ;
892 SetPortWindowPort( (WindowRef)m_macWindow ) ;
893
894 m_macNeedsErasing |= eraseBackground ;
895
896 // if we already know that we will have to erase, there's no need to track the rest
897 if ( !m_macNeedsErasing)
898 {
899 // we end only here if eraseBackground is false
900 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
901 // we will have to erase anyway
902
903 RgnHandle updateRgn = NewRgn();
904 RgnHandle diffRgn = NewRgn() ;
905 if ( updateRgn && diffRgn )
906 {
907 GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
908 Point pt = {0,0} ;
909 LocalToGlobal( &pt ) ;
910 OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
911 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
912 if ( !EmptyRgn( diffRgn ) )
913 {
914 m_macNeedsErasing = true ;
915 }
916 }
917 if ( updateRgn )
918 DisposeRgn( updateRgn );
919 if ( diffRgn )
920 DisposeRgn( diffRgn );
921
922 if ( !m_macNeedsErasing )
923 {
924 RgnHandle rectRgn = NewRgn() ;
925 SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
926 UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
927 DisposeRgn( rectRgn ) ;
928 }
929 }
930 InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
931 // turn this on to debug the refreshing cycle
932 #if wxMAC_DEBUG_REDRAW
933 PaintRect( rect ) ;
934 #endif
935 SetPort( formerPort ) ;
936 }
937