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