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