]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
commented section removed
[wxWidgets.git] / src / mac / carbon / 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 licence
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 #include "ToolUtils.h"
47
48
49 #define wxMAC_DEBUG_REDRAW 0
50 #ifndef wxMAC_DEBUG_REDRAW
51 #define wxMAC_DEBUG_REDRAW 0
52 #endif
53
54 // ----------------------------------------------------------------------------
55 // globals
56 // ----------------------------------------------------------------------------
57
58 // list of all frames and modeless dialogs
59 wxWindowList wxModelessWindows;
60
61 // double click testing
62 static Point gs_lastWhere;
63 static long gs_lastWhen = 0;
64
65
66 #if TARGET_CARBON
67 static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);
68 #endif
69
70 // ============================================================================
71 // wxTopLevelWindowMac implementation
72 // ============================================================================
73
74 // ---------------------------------------------------------------------------
75 // Carbon Events
76 // ---------------------------------------------------------------------------
77
78 #if TARGET_CARBON
79
80 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
81
82 static const EventTypeSpec eventList[] =
83 {
84 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
85
86 { kEventClassKeyboard, kEventRawKeyDown } ,
87 { kEventClassKeyboard, kEventRawKeyRepeat } ,
88 { kEventClassKeyboard, kEventRawKeyUp } ,
89 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
90
91 { kEventClassWindow , kEventWindowUpdate } ,
92 { kEventClassWindow , kEventWindowActivated } ,
93 { kEventClassWindow , kEventWindowDeactivated } ,
94 { kEventClassWindow , kEventWindowBoundsChanging } ,
95 { kEventClassWindow , kEventWindowBoundsChanged } ,
96 { kEventClassWindow , kEventWindowClose } ,
97
98 { kEventClassMouse , kEventMouseDown } ,
99 { kEventClassMouse , kEventMouseUp } ,
100 { kEventClassMouse , kEventMouseMoved } ,
101 { kEventClassMouse , kEventMouseDragged } ,
102
103 } ;
104
105 static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
106 {
107 OSStatus result = eventNotHandledErr ;
108
109 wxWindow* focus = wxWindow::FindFocus() ;
110 char charCode ;
111 UInt32 keyCode ;
112 UInt32 modifiers ;
113 Point point ;
114
115 EventRef rawEvent ;
116
117 GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
118
119 GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
120 GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
121 GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
122 GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL,
123 sizeof( Point ), NULL, &point );
124
125 switch ( GetEventKind( event ) )
126 {
127 case kEventTextInputUnicodeForKeyEvent :
128 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
129 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
130 wxControl* control = wxDynamicCast( focus , wxControl ) ;
131 if ( control )
132 {
133 ControlHandle macControl = (ControlHandle) control->GetMacControl() ;
134 if ( macControl )
135 {
136 ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ;
137 result = noErr ;
138 }
139 }
140 /*
141 // this may lead to double events sent to a window in case all handlers have skipped the key down event
142 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
143 UInt32 message = (keyCode << 8) + charCode;
144
145 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
146 focus , message , modifiers , when , point.h , point.v ) )
147 {
148 result = noErr ;
149 }
150 */
151 break ;
152 }
153
154 return result ;
155 }
156
157 static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
158 {
159 OSStatus result = eventNotHandledErr ;
160
161 wxWindow* focus = wxWindow::FindFocus() ;
162 char charCode ;
163 UInt32 keyCode ;
164 UInt32 modifiers ;
165 Point point ;
166 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
167
168 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
169 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
170 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
171 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
172 sizeof( Point ), NULL, &point );
173
174 UInt32 message = (keyCode << 8) + charCode;
175 switch( GetEventKind( event ) )
176 {
177 case kEventRawKeyRepeat :
178 case kEventRawKeyDown :
179 {
180 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
181 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
182 wxTheApp->MacSetCurrentEvent( event , handler ) ;
183 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
184 focus , message , modifiers , when , point.h , point.v ) )
185 {
186 result = noErr ;
187 }
188 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
189 }
190 break ;
191 case kEventRawKeyUp :
192 if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
193 focus , message , modifiers , when , point.h , point.v ) )
194 {
195 result = noErr ;
196 }
197 break ;
198 case kEventRawKeyModifiersChanged :
199 {
200 wxKeyEvent event(wxEVT_KEY_DOWN);
201
202 event.m_shiftDown = modifiers & shiftKey;
203 event.m_controlDown = modifiers & controlKey;
204 event.m_altDown = modifiers & optionKey;
205 event.m_metaDown = modifiers & cmdKey;
206
207 event.m_x = point.h;
208 event.m_y = point.v;
209 event.m_timeStamp = when;
210 wxWindow* focus = wxWindow::FindFocus() ;
211 event.SetEventObject(focus);
212
213 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
214 {
215 event.m_keyCode = WXK_CONTROL ;
216 event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
217 focus->GetEventHandler()->ProcessEvent( event ) ;
218 }
219 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
220 {
221 event.m_keyCode = WXK_SHIFT ;
222 event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
223 focus->GetEventHandler()->ProcessEvent( event ) ;
224 }
225 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
226 {
227 event.m_keyCode = WXK_ALT ;
228 event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
229 focus->GetEventHandler()->ProcessEvent( event ) ;
230 }
231 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey )
232 {
233 event.m_keyCode = WXK_COMMAND ;
234 event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
235 focus->GetEventHandler()->ProcessEvent( event ) ;
236 }
237 wxTheApp->s_lastModifiers = modifiers ;
238 }
239 break ;
240 }
241
242 return result ;
243 }
244
245 static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
246 {
247 OSStatus result = eventNotHandledErr ;
248
249 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
250 Point point ;
251 UInt32 modifiers = 0;
252 EventMouseButton button = 0 ;
253 UInt32 click = 0 ;
254
255 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
256 sizeof( Point ), NULL, &point );
257 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL,
258 sizeof( UInt32 ), NULL, &modifiers );
259 GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL,
260 sizeof( EventMouseButton ), NULL, &button );
261 GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL,
262 sizeof( UInt32 ), NULL, &click );
263
264 if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
265 modifiers += btnState ;
266
267 WindowRef window ;
268 short windowPart = ::FindWindow(point, &window);
269
270 if ( IsWindowActive(window) && windowPart == inContent )
271 {
272 switch ( GetEventKind( event ) )
273 {
274 case kEventMouseDown :
275 toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
276 result = noErr ;
277 break ;
278 case kEventMouseUp :
279 toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
280 result = noErr ;
281 break ;
282 case kEventMouseMoved :
283 wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
284 result = noErr ;
285 break ;
286 case kEventMouseDragged :
287 toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
288 result = noErr ;
289 break ;
290 default :
291 break ;
292 }
293 }
294
295 return result ;
296
297
298 }
299 static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
300 {
301 OSStatus result = eventNotHandledErr ;
302 OSStatus err = noErr ;
303
304 UInt32 attributes;
305 WindowRef windowRef ;
306 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
307
308 GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL,
309 sizeof( WindowRef ), NULL, &windowRef );
310
311 switch( GetEventKind( event ) )
312 {
313 case kEventWindowUpdate :
314 if ( !wxPendingDelete.Member(toplevelWindow) )
315 toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ;
316 result = noErr ;
317 break ;
318 case kEventWindowActivated :
319 toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ;
320 result = noErr ;
321 break ;
322 case kEventWindowDeactivated :
323 toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ;
324 result = noErr ;
325 break ;
326 case kEventWindowClose :
327 toplevelWindow->Close() ;
328 result = noErr ;
329 break ;
330 case kEventWindowBoundsChanged :
331 err = GetEventParameter( event, kEventParamAttributes, typeUInt32,
332 NULL, sizeof( UInt32 ), NULL, &attributes );
333 if ( err == noErr )
334 {
335 Rect newContentRect ;
336
337 GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL,
338 sizeof( newContentRect ), NULL, &newContentRect );
339
340 toplevelWindow->SetSize( newContentRect.left , newContentRect.top ,
341 newContentRect.right - newContentRect.left ,
342 newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
343
344 result = noErr;
345 }
346 break ;
347 case kEventWindowBoundsChanging :
348 err = GetEventParameter( event, kEventParamAttributes, typeUInt32,
349 NULL, sizeof( UInt32 ), NULL, &attributes );
350 if ( err == noErr )
351 {
352 Rect newContentRect ;
353
354 GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL,
355 sizeof( newContentRect ), NULL, &newContentRect );
356
357 wxSize formerSize = toplevelWindow->GetSize() ;
358
359 if ( (attributes & kWindowBoundsChangeSizeChanged ) ||
360 ( attributes & kWindowBoundsChangeOriginChanged ) )
361 toplevelWindow->SetSize( newContentRect.left , newContentRect.top ,
362 newContentRect.right - newContentRect.left ,
363 newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
364
365 int x , y , w , h ;
366 toplevelWindow->GetPosition( &x , &y ) ;
367 toplevelWindow->GetSize( &w , &h ) ;
368 Rect adjustedRect = { y , x , y + h , x + w } ;
369
370 if ( !EqualRect( &newContentRect , &adjustedRect ) )
371 {
372 SetEventParameter( event , kEventParamCurrentBounds , typeQDRectangle, sizeof( adjustedRect ) , &adjustedRect ) ;
373 }
374
375 if ( toplevelWindow->GetSize() != formerSize )
376 toplevelWindow->Update() ;
377
378 result = noErr ;
379 }
380 break ;
381 default :
382 break ;
383 }
384 return result ;
385 }
386
387 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
388 {
389 OSStatus result = eventNotHandledErr ;
390
391 switch ( GetEventClass( event ) )
392 {
393 case kEventClassKeyboard :
394 result = KeyboardEventHandler( handler, event , data ) ;
395 break ;
396 case kEventClassTextInput :
397 result = TextInputEventHandler( handler, event , data ) ;
398 break ;
399 case kEventClassWindow :
400 result = WindowEventHandler( handler, event , data ) ;
401 break ;
402 case kEventClassMouse :
403 result = MouseEventHandler( handler, event , data ) ;
404 break ;
405 default :
406 break ;
407 }
408 return result ;
409 }
410
411 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
412
413 #endif
414
415 // ---------------------------------------------------------------------------
416 // wxWindowMac utility functions
417 // ---------------------------------------------------------------------------
418
419 // Find an item given the Macintosh Window Reference
420
421 wxList *wxWinMacWindowList = NULL;
422 wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef)
423 {
424 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
425 if (!node)
426 return NULL;
427 return (wxTopLevelWindowMac *)node->GetData();
428 }
429
430 void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win)
431 {
432 // adding NULL WindowRef is (first) surely a result of an error and
433 // (secondly) breaks menu command processing
434 wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
435
436 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
437 wxWinMacWindowList->Append((long)inWindowRef, win);
438 }
439
440 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
441 {
442 wxWinMacWindowList->DeleteObject(win);
443 }
444
445
446 // ----------------------------------------------------------------------------
447 // wxTopLevelWindowMac creation
448 // ----------------------------------------------------------------------------
449
450 WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
451 wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
452
453 void wxTopLevelWindowMac::Init()
454 {
455 m_iconized =
456 m_maximizeOnShow = FALSE;
457 m_macNoEraseUpdateRgn = NewRgn() ;
458 m_macNeedsErasing = false ;
459 m_macWindow = NULL ;
460 #if TARGET_CARBON
461 m_macEventHandler = NULL ;
462 #endif
463 }
464
465 class wxMacDeferredWindowDeleter : public wxObject
466 {
467 public :
468 wxMacDeferredWindowDeleter( WindowRef windowRef )
469 {
470 m_macWindow = windowRef ;
471 }
472 virtual ~wxMacDeferredWindowDeleter()
473 {
474 UMADisposeWindow( (WindowRef) m_macWindow ) ;
475 }
476 protected :
477 WindowRef m_macWindow ;
478 } ;
479
480 bool wxTopLevelWindowMac::Create(wxWindow *parent,
481 wxWindowID id,
482 const wxString& title,
483 const wxPoint& pos,
484 const wxSize& size,
485 long style,
486 const wxString& name)
487 {
488 // init our fields
489 Init();
490
491 m_windowStyle = style;
492
493 SetName(name);
494
495 m_windowId = id == -1 ? NewControlId() : id;
496
497 wxTopLevelWindows.Append(this);
498
499 if ( parent )
500 parent->AddChild(this);
501
502 return TRUE;
503 }
504
505 wxTopLevelWindowMac::~wxTopLevelWindowMac()
506 {
507 if ( m_macWindow )
508 {
509 wxToolTip::NotifyWindowDelete(m_macWindow) ;
510 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
511 }
512
513 #if TARGET_CARBON
514 if ( m_macEventHandler )
515 {
516 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
517 m_macEventHandler = NULL ;
518 }
519 #endif
520
521 wxRemoveMacWindowAssociation( this ) ;
522
523 if ( wxModelessWindows.Find(this) )
524 wxModelessWindows.DeleteObject(this);
525
526 DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
527 }
528
529
530 // ----------------------------------------------------------------------------
531 // wxTopLevelWindowMac maximize/minimize
532 // ----------------------------------------------------------------------------
533
534 void wxTopLevelWindowMac::Maximize(bool maximize)
535 {
536 ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ;
537
538 Rect tempRect ;
539 GrafPtr port ;
540 GetPort( &port ) ;
541 Point pt = { 0, 0 } ;
542 SetPortWindowPort((WindowRef)m_macWindow) ;
543 LocalToGlobal( &pt ) ;
544 SetPort( port ) ;
545
546 GetWindowPortBounds((WindowRef)m_macWindow, &tempRect ) ;
547 SetSize( pt.h , pt.v , tempRect.right-tempRect.left ,
548 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
549 }
550
551 bool wxTopLevelWindowMac::IsMaximized() const
552 {
553 return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;
554 }
555
556 void wxTopLevelWindowMac::Iconize(bool iconize)
557 {
558 if ( IsWindowCollapsable((WindowRef)m_macWindow) )
559 CollapseWindow((WindowRef)m_macWindow , iconize ) ;
560 }
561
562 bool wxTopLevelWindowMac::IsIconized() const
563 {
564 return IsWindowCollapsed((WindowRef)m_macWindow ) ;
565 }
566
567 void wxTopLevelWindowMac::Restore()
568 {
569 // not available on mac
570 }
571
572 // ----------------------------------------------------------------------------
573 // wxTopLevelWindowMac misc
574 // ----------------------------------------------------------------------------
575
576 void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
577 {
578 // this sets m_icon
579 wxTopLevelWindowBase::SetIcon(icon);
580 }
581
582 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
583 const wxPoint& pos,
584 const wxSize& size,
585 long style,
586 const wxString& name )
587 {
588 OSStatus err = noErr ;
589 SetName(name);
590 m_windowStyle = style;
591 m_isShown = FALSE;
592
593 // create frame.
594
595 Rect theBoundsRect;
596
597 m_x = (int)pos.x;
598 m_y = (int)pos.y;
599 if ( m_y < 50 )
600 m_y = 50 ;
601 if ( m_x < 20 )
602 m_x = 20 ;
603
604 m_width = size.x;
605 if (m_width == -1)
606 m_width = 20;
607 m_height = size.y;
608 if (m_height == -1)
609 m_height = 20;
610
611 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
612
613 // translate the window attributes in the appropriate window class and attributes
614
615 WindowClass wclass = 0;
616 WindowAttributes attr = kWindowNoAttributes ;
617
618 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
619 {
620 if (
621 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
622 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
623 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
624 )
625 {
626 wclass = kFloatingWindowClass ;
627 if ( HasFlag(wxTINY_CAPTION_VERT) )
628 {
629 attr |= kWindowSideTitlebarAttribute ;
630 }
631 }
632 else
633 {
634 #if TARGET_CARBON
635 wclass = kPlainWindowClass ;
636 #else
637 wclass = kFloatingWindowClass ;
638 #endif
639 }
640 }
641 else if ( HasFlag( wxCAPTION ) )
642 {
643 wclass = kDocumentWindowClass ;
644 }
645 else
646 {
647 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
648 HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )
649 {
650 wclass = kDocumentWindowClass ;
651 }
652 else
653 {
654 #if TARGET_CARBON
655 wclass = kPlainWindowClass ;
656 #else
657 wclass = kModalWindowClass ;
658 #endif
659 }
660 }
661
662 if ( HasFlag( wxMINIMIZE_BOX ) )
663 {
664 attr |= kWindowCollapseBoxAttribute ;
665 }
666 if ( HasFlag( wxMAXIMIZE_BOX ) )
667 {
668 attr |= kWindowFullZoomAttribute ;
669 }
670 if ( HasFlag( wxRESIZE_BORDER ) )
671 {
672 attr |= kWindowResizableAttribute ;
673 }
674 if ( HasFlag( wxCLOSE_BOX) )
675 {
676 attr |= kWindowCloseBoxAttribute ;
677 }
678
679 #if TARGET_CARBON
680 #if 0 // having problems right now with that
681 if (HasFlag(wxSTAY_ON_TOP))
682 wclass = kUtilityWindowClass;
683 #endif
684 #endif
685
686 #if TARGET_CARBON
687 if ( HasFlag(wxFRAME_SHAPED) )
688 {
689 WindowDefSpec customWindowDefSpec;
690 customWindowDefSpec.defType = kWindowDefProcPtr;
691 customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);
692
693 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
694 attr, &theBoundsRect,
695 (WindowRef*) &m_macWindow);
696 }
697 else
698 #endif
699 {
700 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
701 }
702
703 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
704 wxAssociateWinWithMacWindow( m_macWindow , this ) ;
705 UMASetWTitle( (WindowRef)m_macWindow , title ) ;
706 ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
707 #if TARGET_CARBON
708 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
709 InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(),
710 GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler);
711 #endif
712 m_macFocus = NULL ;
713
714
715 #if TARGET_CARBON
716 if ( HasFlag(wxFRAME_SHAPED) )
717 {
718 // default shape matches the window size
719 wxRegion rgn(0, 0, m_width, m_height);
720 SetShape(rgn);
721 }
722 #endif
723 }
724
725 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin)
726 {
727 ((Point*)localOrigin)->h = 0;
728 ((Point*)localOrigin)->v = 0;
729 ((Rect*)clipRect)->left = 0;
730 ((Rect*)clipRect)->top = 0;
731 ((Rect*)clipRect)->right = m_width;
732 ((Rect*)clipRect)->bottom = m_height;
733 *window = m_macWindow ;
734 *rootwin = this ;
735 }
736
737 void wxTopLevelWindowMac::ClearBackground()
738 {
739 wxWindow::ClearBackground() ;
740 }
741
742 WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding()
743 {
744 return m_macRootControl ;
745 }
746
747
748 void wxTopLevelWindowMac::MacUpdate( long timestamp)
749 {
750 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
751
752 RgnHandle visRgn = NewRgn() ;
753 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn );
754 BeginUpdate( (WindowRef)m_macWindow ) ;
755
756 RgnHandle updateRgn = NewRgn();
757 RgnHandle diffRgn = NewRgn() ;
758
759 if ( updateRgn && diffRgn )
760 {
761 #if 1
762 // macos internal control redraws clean up areas we'd like to redraw ourselves
763 // therefore we pick the boundary rect and make sure we can redraw it
764 // this has to be intersected by the visRgn in order to avoid drawing over its own
765 // boundaries
766 RgnHandle trueUpdateRgn = NewRgn() ;
767 Rect trueUpdateRgnBoundary ;
768 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn );
769 GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ;
770 RectRgn( updateRgn , &trueUpdateRgnBoundary ) ;
771 SectRgn( updateRgn , visRgn , updateRgn ) ;
772 if ( trueUpdateRgn )
773 DisposeRgn( trueUpdateRgn ) ;
774 SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ;
775 #else
776 GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
777 #endif
778 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
779 if ( !EmptyRgn( updateRgn ) )
780 {
781 MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ;
782 }
783 }
784 if ( updateRgn )
785 DisposeRgn( updateRgn );
786 if ( diffRgn )
787 DisposeRgn( diffRgn );
788 if ( visRgn )
789 DisposeRgn( visRgn ) ;
790
791 EndUpdate( (WindowRef)m_macWindow ) ;
792 SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
793 m_macNeedsErasing = false ;
794 }
795
796
797 // Raise the window to the top of the Z order
798 void wxTopLevelWindowMac::Raise()
799 {
800 ::SelectWindow( (WindowRef)m_macWindow ) ;
801 }
802
803 // Lower the window to the bottom of the Z order
804 void wxTopLevelWindowMac::Lower()
805 {
806 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
807 }
808
809 void wxTopLevelWindowMac::MacFireMouseEvent(
810 wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp )
811 {
812 wxMouseEvent event(wxEVT_LEFT_DOWN);
813 bool isDown = !(modifiers & btnState) ; // 1 is for up
814 bool controlDown = modifiers & controlKey ; // for simulating right mouse
815
816 event.m_leftDown = isDown && !controlDown;
817
818 event.m_middleDown = FALSE;
819 event.m_rightDown = isDown && controlDown;
820
821 if ( kind == mouseDown )
822 {
823 if ( controlDown )
824 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
825 else
826 event.SetEventType(wxEVT_LEFT_DOWN ) ;
827 }
828 else if ( kind == mouseUp )
829 {
830 if ( controlDown )
831 event.SetEventType(wxEVT_RIGHT_UP ) ;
832 else
833 event.SetEventType(wxEVT_LEFT_UP ) ;
834 }
835 else
836 {
837 event.SetEventType(wxEVT_MOTION ) ;
838 }
839
840 event.m_shiftDown = modifiers & shiftKey;
841 event.m_controlDown = modifiers & controlKey;
842 event.m_altDown = modifiers & optionKey;
843 event.m_metaDown = modifiers & cmdKey;
844
845 Point localwhere ;
846 localwhere.h = x ;
847 localwhere.v = y ;
848
849 GrafPtr port ;
850 ::GetPort( &port ) ;
851 ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
852 ::GlobalToLocal( &localwhere ) ;
853 ::SetPort( port ) ;
854
855 if ( kind == mouseDown )
856 {
857 if ( timestamp - gs_lastWhen <= (long) GetDblTime() )
858 {
859 if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
860 {
861 // This is not right if the second mouse down
862 // event occured in a differen window. We
863 // correct this in MacDispatchMouseEvent.
864 if ( controlDown )
865 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
866 else
867 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
868 }
869 gs_lastWhen = 0 ;
870 }
871 else
872 {
873 gs_lastWhen = timestamp ;
874 }
875 gs_lastWhere = localwhere ;
876 }
877
878 event.m_x = localwhere.h;
879 event.m_y = localwhere.v;
880 event.m_x += m_x;
881 event.m_y += m_y;
882
883 event.m_timeStamp = timestamp;
884 event.SetEventObject(this);
885 if ( wxTheApp->s_captureWindow )
886 {
887 int x = event.m_x ;
888 int y = event.m_y ;
889 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
890 event.m_x = x ;
891 event.m_y = y ;
892 event.SetEventObject( wxTheApp->s_captureWindow ) ;
893 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
894
895 if ( kind == mouseUp )
896 {
897 wxTheApp->s_captureWindow = NULL ;
898 if ( !wxIsBusy() )
899 {
900 m_cursor.MacInstall() ;
901 }
902 }
903 }
904 else
905 {
906 MacDispatchMouseEvent( event ) ;
907 }
908 }
909
910 #if !TARGET_CARBON
911
912 void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
913 {
914 MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,
915 ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;
916 }
917
918 void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
919 {
920 switch (part)
921 {
922 case inContent:
923 {
924 MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,
925 ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;
926 }
927 break ;
928 }
929 }
930
931 void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
932 {
933 switch (part)
934 {
935 case inContent:
936 {
937 MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,
938 ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;
939 }
940 break ;
941 }
942 }
943
944 #endif
945
946 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp)
947 {
948 if(s_macDeactivateWindow)
949 {
950 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow);
951 s_macDeactivateWindow->MacActivate(timestamp, false);
952 }
953 }
954
955 void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
956 {
957 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
958
959 if(s_macDeactivateWindow==this)
960 s_macDeactivateWindow=NULL;
961 MacDelayedDeactivation(timestamp);
962 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
963 event.m_timeStamp = timestamp ;
964 event.SetEventObject(this);
965
966 GetEventHandler()->ProcessEvent(event);
967
968 UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
969
970 // Early versions of MacOS X don't refresh backgrounds properly,
971 // so refresh the whole window on activation and deactivation.
972 long osVersion = UMAGetSystemVersion();
973 if (osVersion >= 0x1000 && osVersion < 0x1020 )
974 {
975 Refresh(TRUE);
976 }
977 else
978 {
979 // for the moment we have to resolve some redrawing issues like this
980 // the OS is stealing some redrawing areas as soon as it draws a control
981 Refresh(TRUE);
982 }
983 }
984
985 #if !TARGET_CARBON
986
987 void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
988 {
989 }
990
991 #endif
992
993 void wxTopLevelWindowMac::SetTitle(const wxString& title)
994 {
995 wxWindow::SetTitle( title ) ;
996 UMASetWTitle( (WindowRef)m_macWindow , title ) ;
997 }
998
999 bool wxTopLevelWindowMac::Show(bool show)
1000 {
1001 if ( !wxWindow::Show(show) )
1002 return FALSE;
1003
1004 if (show)
1005 {
1006 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil);
1007 ::SelectWindow( (WindowRef)m_macWindow ) ;
1008 // no need to generate events here, they will get them triggered by macos
1009 // actually they should be , but apparently they are not
1010 wxSize size(m_width, m_height);
1011 wxSizeEvent event(size, m_windowId);
1012 event.SetEventObject(this);
1013 GetEventHandler()->ProcessEvent(event);
1014 }
1015 else
1016 {
1017 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil);
1018 }
1019
1020 if ( !show )
1021 {
1022 }
1023 else
1024 {
1025 Refresh() ;
1026 }
1027
1028 return TRUE;
1029 }
1030
1031 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
1032 {
1033 int former_x = m_x ;
1034 int former_y = m_y ;
1035 int former_w = m_width ;
1036 int former_h = m_height ;
1037
1038 int actualWidth = width;
1039 int actualHeight = height;
1040 int actualX = x;
1041 int actualY = y;
1042
1043 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1044 actualWidth = m_minWidth;
1045 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1046 actualHeight = m_minHeight;
1047 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1048 actualWidth = m_maxWidth;
1049 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1050 actualHeight = m_maxHeight;
1051
1052 bool doMove = false ;
1053 bool doResize = false ;
1054
1055 if ( actualX != former_x || actualY != former_y )
1056 {
1057 doMove = true ;
1058 }
1059 if ( actualWidth != former_w || actualHeight != former_h )
1060 {
1061 doResize = true ;
1062 }
1063
1064 if ( doMove || doResize )
1065 {
1066 m_x = actualX ;
1067 m_y = actualY ;
1068 m_width = actualWidth ;
1069 m_height = actualHeight ;
1070
1071 if ( doMove )
1072 ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost
1073
1074 if ( doResize )
1075 ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true);
1076
1077 // the OS takes care of invalidating and erasing the new area so we only have to
1078 // take care of refreshing for full repaints
1079
1080 if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
1081 Refresh() ;
1082
1083
1084 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
1085 {
1086 wxFrame* frame = (wxFrame*) this ;
1087 frame->PositionStatusBar();
1088 frame->PositionToolBar();
1089 }
1090 if ( doMove )
1091 wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
1092
1093 MacRepositionScrollBars() ;
1094 if ( doMove )
1095 {
1096 wxPoint point(m_x, m_y);
1097 wxMoveEvent event(point, m_windowId);
1098 event.SetEventObject(this);
1099 GetEventHandler()->ProcessEvent(event) ;
1100 }
1101 if ( doResize )
1102 {
1103 MacRepositionScrollBars() ;
1104 wxSize size(m_width, m_height);
1105 wxSizeEvent event(size, m_windowId);
1106 event.SetEventObject(this);
1107 GetEventHandler()->ProcessEvent(event);
1108 }
1109 }
1110
1111 }
1112
1113 /*
1114 * Invalidation Mechanism
1115 *
1116 * The update mechanism reflects exactely the windows mechanism
1117 * the rect gets added to the window invalidate region, if the eraseBackground flag
1118 * has been true for any part of the update rgn the background is erased in the entire region
1119 * not just in the specified rect.
1120 *
1121 * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have
1122 * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event
1123 * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window
1124 * will get the eraseBackground event first
1125 */
1126
1127 void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground )
1128 {
1129 GrafPtr formerPort ;
1130 GetPort( &formerPort ) ;
1131 SetPortWindowPort( (WindowRef)m_macWindow ) ;
1132
1133 m_macNeedsErasing |= eraseBackground ;
1134
1135 // if we already know that we will have to erase, there's no need to track the rest
1136 if ( !m_macNeedsErasing)
1137 {
1138 // we end only here if eraseBackground is false
1139 // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn
1140 // we will have to erase anyway
1141
1142 RgnHandle updateRgn = NewRgn();
1143 RgnHandle diffRgn = NewRgn() ;
1144 if ( updateRgn && diffRgn )
1145 {
1146 GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
1147 Point pt = {0,0} ;
1148 LocalToGlobal( &pt ) ;
1149 OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
1150 DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
1151 if ( !EmptyRgn( diffRgn ) )
1152 {
1153 m_macNeedsErasing = true ;
1154 }
1155 }
1156 if ( updateRgn )
1157 DisposeRgn( updateRgn );
1158 if ( diffRgn )
1159 DisposeRgn( diffRgn );
1160
1161 if ( !m_macNeedsErasing )
1162 {
1163 RgnHandle rectRgn = NewRgn() ;
1164 SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
1165 UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
1166 DisposeRgn( rectRgn ) ;
1167 }
1168 }
1169 InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
1170 // turn this on to debug the refreshing cycle
1171 #if wxMAC_DEBUG_REDRAW
1172 PaintRect( rect ) ;
1173 #endif
1174 SetPort( formerPort ) ;
1175 }
1176
1177
1178 bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
1179 {
1180 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
1181 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1182
1183 #if TARGET_CARBON
1184 // The empty region signifies that the shape should be removed from the
1185 // window.
1186 if ( region.IsEmpty() )
1187 {
1188 wxSize sz = GetClientSize();
1189 wxRegion rgn(0, 0, sz.x, sz.y);
1190 return SetShape(rgn);
1191 }
1192
1193 // Make a copy of the region
1194 RgnHandle shapeRegion = NewRgn();
1195 CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion );
1196
1197 // Dispose of any shape region we may already have
1198 RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() );
1199 if ( oldRgn )
1200 DisposeRgn(oldRgn);
1201
1202 // Save the region so we can use it later
1203 SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion);
1204
1205 // Tell the window manager that the window has changed shape
1206 ReshapeCustomWindow((WindowRef)MacGetWindowRef());
1207 return TRUE;
1208 #else
1209 return FALSE;
1210 #endif
1211 }
1212
1213 // ---------------------------------------------------------------------------
1214 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1215 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1216 // ---------------------------------------------------------------------------
1217
1218 #if TARGET_CARBON
1219
1220 static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
1221 {
1222 GetWindowPortBounds(window, inRect);
1223 Point pt = {inRect->left, inRect->top};
1224 SetPort((GrafPtr) GetWindowPort(window));
1225 LocalToGlobal(&pt);
1226 inRect->top = pt.v;
1227 inRect->left = pt.h;
1228 inRect->bottom += pt.v;
1229 inRect->right += pt.h;
1230 }
1231
1232
1233 static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param)
1234 {
1235 /*------------------------------------------------------
1236 Define which options your custom window supports.
1237 --------------------------------------------------------*/
1238 //just enable everything for our demo
1239 *(OptionBits*)param=//kWindowCanGrow|
1240 //kWindowCanZoom|
1241 //kWindowCanCollapse|
1242 //kWindowCanGetWindowRegion|
1243 //kWindowHasTitleBar|
1244 //kWindowSupportsDragHilite|
1245 kWindowCanDrawInCurrentPort|
1246 //kWindowCanMeasureTitle|
1247 kWindowWantsDisposeAtProcessDeath|
1248 kWindowSupportsSetGrowImageRegion|
1249 kWindowDefSupportsColorGrafPort;
1250 return 1;
1251 }
1252
1253 // The content region is left as a rectangle matching the window size, this is
1254 // so the origin in the paint event, and etc. still matches what the
1255 // programmer expects.
1256 static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
1257 {
1258 SetEmptyRgn(rgn);
1259 wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window);
1260 if (win)
1261 {
1262 wxRect r = win->GetRect();
1263 SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
1264 }
1265 }
1266
1267 // The structure region is set to the shape given to the SetShape method.
1268 static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
1269 {
1270 RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
1271
1272 SetEmptyRgn(rgn);
1273 if (cachedRegion)
1274 {
1275 Rect windowRect;
1276 wxShapedMacWindowGetPos(window, &windowRect); //how big is the window
1277 CopyRgn(cachedRegion, rgn); //make a copy of our cached region
1278 OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
1279 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1280 }
1281 }
1282
1283
1284
1285 static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
1286 {
1287 GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param;
1288
1289 switch(rgnRec->regionCode)
1290 {
1291 case kWindowStructureRgn:
1292 wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
1293 break;
1294 case kWindowContentRgn:
1295 wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
1296 break;
1297 default:
1298 SetEmptyRgn(rgnRec->winRgn);
1299 } //switch
1300
1301 return noErr;
1302 }
1303
1304
1305 static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param)
1306 {
1307 /*------------------------------------------------------
1308 Determine the region of the window which was hit
1309 --------------------------------------------------------*/
1310 Point hitPoint;
1311 static RgnHandle tempRgn=nil;
1312
1313 if(!tempRgn)
1314 tempRgn=NewRgn();
1315
1316 SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked
1317
1318 //Mac OS 8.5 or later
1319 wxShapedMacWindowStructureRegion(window, tempRgn);
1320 if (PtInRgn(hitPoint, tempRgn)) //in window content region?
1321 return wInContent;
1322
1323 return wNoHit;//no significant area was hit.
1324 }
1325
1326
1327 static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param)
1328 {
1329 switch(message)
1330 {
1331 case kWindowMsgHitTest:
1332 return wxShapedMacWindowHitTest(window,param);
1333
1334 case kWindowMsgGetFeatures:
1335 return wxShapedMacWindowGetFeatures(window,param);
1336
1337 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1338 case kWindowMsgGetRegion:
1339 return wxShapedMacWindowGetRegion(window,param);
1340 }
1341
1342 return 0;
1343 }
1344
1345 #endif
1346 // ---------------------------------------------------------------------------
1347