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