carbon cfm / classic fixes
[wxWidgets.git] / src / mac / carbon / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/menu.h"
19 #include "wx/window.h"
20 #include "wx/dc.h"
21 #include "wx/dcclient.h"
22 #include "wx/utils.h"
23 #include "wx/app.h"
24 #include "wx/panel.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
32 #include "wx/frame.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
37 #include "wx/log.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
40
41 #include "wx/toolbar.h"
42 #include "wx/dc.h"
43
44 #if wxUSE_CARET
45 #include "wx/caret.h"
46 #endif // wxUSE_CARET
47
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
50
51 #include "wx/mac/uma.h"
52 #ifndef __DARWIN__
53 #include <Windows.h>
54 #include <ToolUtils.h>
55 #include <Scrap.h>
56 #include <MacTextEditor.h>
57 #endif
58
59 #if TARGET_API_MAC_OSX
60 #ifndef __HIVIEW__
61 #include <HIToolbox/HIView.h>
62 #endif
63 #endif
64
65 #if wxUSE_DRAG_AND_DROP
66 #include "wx/dnd.h"
67 #endif
68
69 #include <string.h>
70
71 extern wxList wxPendingDelete;
72
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
75 #else // __WXMAC__
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
77 #endif // __WXUNIVERSAL__/__WXMAC__
78
79 #if !USE_SHARED_LIBRARY
80
81 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
84 #if TARGET_API_MAC_OSX
85 EVT_PAINT(wxWindowMac::OnPaint)
86 #endif
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
90 END_EVENT_TABLE()
91
92 #endif
93
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
97 #endif
98
99 #define wxMAC_USE_THEME_BORDER 1
100
101 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
104
105 /*
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
116 * native coordinates
117 */
118
119 //
120 // originating from native control
121 //
122
123
124 void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle )
125 {
126 OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
127 }
128
129 void wxMacNativeToWindow( const wxWindow* window , Rect *rect )
130 {
131 OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
132 }
133
134 //
135 // directed towards native control
136 //
137
138 void wxMacWindowToNative( const wxWindow* window , RgnHandle handle )
139 {
140 OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
141 }
142
143 void wxMacWindowToNative( const wxWindow* window , Rect *rect )
144 {
145 OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ;
146 }
147
148
149 // ---------------------------------------------------------------------------
150 // Carbon Events
151 // ---------------------------------------------------------------------------
152
153 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
154 pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ;
155
156 #if TARGET_API_MAC_OSX
157
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
159 enum {
160 kEventControlVisibilityChanged = 157
161 };
162 #endif
163
164 #endif
165
166 static const EventTypeSpec eventList[] =
167 {
168 { kEventClassControl , kEventControlHit } ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl , kEventControlDraw } ,
171 { kEventClassControl , kEventControlVisibilityChanged } ,
172 { kEventClassControl , kEventControlEnabledStateChanged } ,
173 { kEventClassControl , kEventControlHiliteChanged } ,
174 { kEventClassControl , kEventControlSetFocusPart } ,
175
176 { kEventClassService , kEventServiceGetTypes },
177 { kEventClassService , kEventServiceCopy },
178 { kEventClassService , kEventServicePaste },
179
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
182 #endif
183 } ;
184
185 static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
186 {
187 OSStatus result = eventNotHandledErr ;
188
189 wxMacCarbonEvent cEvent( event ) ;
190
191 ControlRef controlRef ;
192 wxWindowMac* thisWindow = (wxWindowMac*) data ;
193
194 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
195
196 switch( GetEventKind( event ) )
197 {
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw :
200 {
201 RgnHandle updateRgn = NULL ;
202 RgnHandle allocatedRgn = NULL ;
203 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
204 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
205 {
206 updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
207 }
208 else
209 {
210 if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
211 {
212 allocatedRgn = NewRgn() ;
213 CopyRgn( updateRgn , allocatedRgn ) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
216 updateRgn = allocatedRgn ;
217 }
218 }
219
220 #if 0
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 if ( thisWindow->MacIsUserPane() )
224 {
225 CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
226 static float color = 0.5 ;
227 static channel = 0 ;
228 HIRect bounds;
229 HIViewGetBounds( controlRef, &bounds );
230 CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 ,
231 channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 );
232 CGContextFillRect( cgContext, bounds );
233 color += 0.1 ;
234 if ( color > 0.9 )
235 {
236 color = 0.5 ;
237 channel++ ;
238 if ( channel == 3 )
239 channel = 0 ;
240 }
241 }
242 #endif
243 {
244 #if wxMAC_USE_CORE_GRAPHICS
245 CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
246 thisWindow->MacSetCGContextRef( cgContext ) ;
247 wxMacCGContextStateSaver sg( cgContext ) ;
248 #endif
249 if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
250 result = noErr ;
251 #if wxMAC_USE_CORE_GRAPHICS
252 thisWindow->MacSetCGContextRef( NULL ) ;
253 #endif
254 }
255 if ( allocatedRgn )
256 DisposeRgn( allocatedRgn ) ;
257 }
258 break ;
259 case kEventControlVisibilityChanged :
260 thisWindow->MacVisibilityChanged() ;
261 break ;
262 case kEventControlEnabledStateChanged :
263 thisWindow->MacEnabledStateChanged() ;
264 break ;
265 case kEventControlHiliteChanged :
266 thisWindow->MacHiliteChanged() ;
267 break ;
268 case kEventControlSetFocusPart :
269 {
270 Boolean focusEverything = false ;
271 ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
272 if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
273 {
274 }
275 if ( controlPart == kControlFocusNoPart )
276 {
277 #if wxUSE_CARET
278 if ( thisWindow->GetCaret() )
279 {
280 thisWindow->GetCaret()->OnKillFocus();
281 }
282 #endif // wxUSE_CARET
283 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
284 event.SetEventObject(thisWindow);
285 thisWindow->GetEventHandler()->ProcessEvent(event) ;
286 }
287 else
288 {
289 // panel wants to track the window which was the last to have focus in it
290 wxChildFocusEvent eventFocus(thisWindow);
291 thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
292
293 #if wxUSE_CARET
294 if ( thisWindow->GetCaret() )
295 {
296 thisWindow->GetCaret()->OnSetFocus();
297 }
298 #endif // wxUSE_CARET
299
300 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
301 event.SetEventObject(thisWindow);
302 thisWindow->GetEventHandler()->ProcessEvent(event) ;
303 }
304 if ( thisWindow->MacIsUserPane() )
305 result = noErr ;
306 }
307 break ;
308 #endif
309 case kEventControlHit :
310 {
311 result = thisWindow->MacControlHit( handler , event ) ;
312 }
313 break ;
314 default :
315 break ;
316 }
317 return result ;
318 }
319
320 static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
321 {
322 OSStatus result = eventNotHandledErr ;
323
324 wxMacCarbonEvent cEvent( event ) ;
325
326 ControlRef controlRef ;
327 wxWindowMac* thisWindow = (wxWindowMac*) data ;
328 wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ;
329 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
330
331 switch( GetEventKind( event ) )
332 {
333 case kEventServiceGetTypes :
334 if( textCtrl )
335 {
336 long from, to ;
337 textCtrl->GetSelection( &from , &to ) ;
338
339 CFMutableArrayRef copyTypes = 0 , pasteTypes = 0;
340 if( from != to )
341 copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ;
342 if ( textCtrl->IsEditable() )
343 pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ;
344
345 static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
346 for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i )
347 {
348 CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]);
349 if ( typestring )
350 {
351 if ( copyTypes )
352 CFArrayAppendValue (copyTypes, typestring) ;
353 if ( pasteTypes )
354 CFArrayAppendValue (pasteTypes, typestring) ;
355 CFRelease( typestring ) ;
356 }
357 }
358 result = noErr ;
359 }
360 break ;
361 case kEventServiceCopy :
362 if ( textCtrl )
363 {
364 long from, to ;
365 textCtrl->GetSelection( &from , &to ) ;
366 wxString val = textCtrl->GetValue() ;
367 val = val.Mid( from , to - from ) ;
368 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
369 verify_noerr( ClearScrap( &scrapRef ) ) ;
370 verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.Length() , val.c_str() ) ) ;
371 result = noErr ;
372 }
373 break ;
374 case kEventServicePaste :
375 if ( textCtrl )
376 {
377 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
378 Size textSize, pastedSize ;
379 verify_noerr( GetScrapFlavorSize (scrapRef, kTXNTextData, &textSize) ) ;
380 textSize++ ;
381 char *content = new char[textSize] ;
382 GetScrapFlavorData (scrapRef, kTXNTextData, &pastedSize, content );
383 content[textSize-1] = 0 ;
384 #if wxUSE_UNICODE
385 textCtrl->WriteText( wxString( content , wxConvLocal ) );
386 #else
387 textCtrl->WriteText( wxString( content ) ) ;
388 #endif
389 delete[] content ;
390 result = noErr ;
391 }
392 break ;
393 }
394
395 return result ;
396 }
397
398 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
399 {
400 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
401 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
402 wxTheApp->MacSetCurrentEvent( event , handler ) ;
403 OSStatus result = eventNotHandledErr ;
404
405 switch ( GetEventClass( event ) )
406 {
407 case kEventClassControl :
408 result = wxMacWindowControlEventHandler( handler, event, data ) ;
409 break ;
410 case kEventClassService :
411 result = wxMacWindowServiceEventHandler( handler, event , data ) ;
412 default :
413 break ;
414 }
415 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
416 return result ;
417 }
418
419 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
420
421 #if !TARGET_API_MAC_OSX
422
423 // ---------------------------------------------------------------------------
424 // UserPane events for non OSX builds
425 // ---------------------------------------------------------------------------
426
427 static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
428 {
429 wxWindow * win = wxFindControlFromMacControl(control) ;
430 if ( win )
431 win->MacControlUserPaneDrawProc(part) ;
432 }
433
434 static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
435 {
436 wxWindow * win = wxFindControlFromMacControl(control) ;
437 if ( win )
438 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
439 else
440 return kControlNoPart ;
441 }
442
443 static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
444 {
445 wxWindow * win = wxFindControlFromMacControl(control) ;
446 if ( win )
447 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
448 else
449 return kControlNoPart ;
450 }
451
452 static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
453 {
454 wxWindow * win = wxFindControlFromMacControl(control) ;
455 if ( win )
456 win->MacControlUserPaneIdleProc() ;
457 }
458
459 static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
460 {
461 wxWindow * win = wxFindControlFromMacControl(control) ;
462 if ( win )
463 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
464 else
465 return kControlNoPart ;
466 }
467
468 static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
469 {
470 wxWindow * win = wxFindControlFromMacControl(control) ;
471 if ( win )
472 win->MacControlUserPaneActivateProc(activating) ;
473 }
474
475 static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
476 {
477 wxWindow * win = wxFindControlFromMacControl(control) ;
478 if ( win )
479 return win->MacControlUserPaneFocusProc(action) ;
480 else
481 return kControlNoPart ;
482 }
483
484 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
485 {
486 wxWindow * win = wxFindControlFromMacControl(control) ;
487 if ( win )
488 win->MacControlUserPaneBackgroundProc(info) ;
489 }
490
491 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
492 {
493 RgnHandle rgn = NewRgn() ;
494 GetClip( rgn ) ;
495 wxMacWindowStateSaver sv( this ) ;
496 SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ;
497 MacDoRedraw( rgn , 0 ) ;
498 DisposeRgn( rgn ) ;
499 }
500
501 wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
502 {
503 return kControlNoPart ;
504 }
505
506 wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
507 {
508 return kControlNoPart ;
509 }
510
511 void wxWindowMac::MacControlUserPaneIdleProc()
512 {
513 }
514
515 wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
516 {
517 return kControlNoPart ;
518 }
519
520 void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
521 {
522 }
523
524 wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
525 {
526 return kControlNoPart ;
527 }
528
529 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
530 {
531 }
532
533 ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ;
534 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ;
535 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ;
536 ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ;
537 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ;
538 ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ;
539 ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ;
540 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ;
541
542 #endif
543
544 // ===========================================================================
545 // implementation
546 // ===========================================================================
547
548 #if KEY_wxList_DEPRECATED
549 wxList wxWinMacControlList(wxKEY_INTEGER);
550
551 wxWindow *wxFindControlFromMacControl(ControlRef inControl )
552 {
553 wxNode *node = wxWinMacControlList.Find((long)inControl);
554 if (!node)
555 return NULL;
556 return (wxControl *)node->GetData();
557 }
558
559 void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
560 {
561 // adding NULL ControlRef is (first) surely a result of an error and
562 // (secondly) breaks native event processing
563 wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
564
565 if ( !wxWinMacControlList.Find((long)inControl) )
566 wxWinMacControlList.Append((long)inControl, control);
567 }
568
569 void wxRemoveMacControlAssociation(wxWindow *control)
570 {
571 wxWinMacControlList.DeleteObject(control);
572 }
573 #else
574
575 WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
576
577 static MacControlMap wxWinMacControlList;
578
579 wxWindow *wxFindControlFromMacControl(ControlRef inControl )
580 {
581 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
582
583 return (node == wxWinMacControlList.end()) ? NULL : node->second;
584 }
585
586 void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
587 {
588 // adding NULL ControlRef is (first) surely a result of an error and
589 // (secondly) breaks native event processing
590 wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
591
592 wxWinMacControlList[inControl] = control;
593 }
594
595 void wxRemoveMacControlAssociation(wxWindow *control)
596 {
597 // iterate over all the elements in the class
598 MacControlMap::iterator it;
599 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
600 {
601 if ( it->second == control )
602 {
603 wxWinMacControlList.erase(it);
604 break;
605 }
606 }
607 }
608 #endif // deprecated wxList
609
610 // UPP functions
611 ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
612
613 ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
614
615 // we have to setup the brush in the current port and return noErr
616 // or return an error code so that the control manager walks further up the
617 // hierarchy to find a correct background
618
619 pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor )
620 {
621 OSStatus status = paramErr ;
622 switch( iMessage )
623 {
624 case kControlMsgApplyTextColor :
625 break ;
626 case kControlMsgSetUpBackground :
627 {
628 wxWindow* wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ;
629 if ( wx != NULL )
630 {
631 /*
632 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
633 if ( brush.Ok() )
634 {
635 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
636 */
637 // this clipping is only needed for non HIView
638
639 RgnHandle clip = NewRgn() ;
640 int x = 0 , y = 0;
641
642 wx->MacWindowToRootWindow( &x,&y ) ;
643 CopyRgn( (RgnHandle) wx->MacGetVisibleRegion().GetWXHRGN() , clip ) ;
644 OffsetRgn( clip , x , y ) ;
645 SetClip( clip ) ;
646 DisposeRgn( clip ) ;
647
648 status = noErr ;
649 /*
650 }
651 else if ( wx->MacIsUserPane() )
652 {
653 // if we don't have a valid brush for such a control, we have to call the
654 // setup of our parent ourselves
655 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
656 }
657 */
658 }
659 }
660 break ;
661 default :
662 break ;
663 }
664 return status ;
665 }
666
667
668 pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
669 pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
670 {
671 if ( partCode != 0)
672 {
673 wxWindow* wx = wxFindControlFromMacControl( control ) ;
674 if ( wx )
675 {
676 wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
677 }
678 }
679 }
680
681 // ----------------------------------------------------------------------------
682 // constructors and such
683 // ----------------------------------------------------------------------------
684
685 wxWindowMac::wxWindowMac()
686 {
687 Init();
688 }
689
690 wxWindowMac::wxWindowMac(wxWindowMac *parent,
691 wxWindowID id,
692 const wxPoint& pos ,
693 const wxSize& size ,
694 long style ,
695 const wxString& name )
696 {
697 Init();
698 Create(parent, id, pos, size, style, name);
699 }
700
701 void wxWindowMac::Init()
702 {
703 m_peer = NULL ;
704 m_frozenness = 0 ;
705 #if WXWIN_COMPATIBILITY_2_4
706 m_backgroundTransparent = FALSE;
707 #endif
708
709 // as all windows are created with WS_VISIBLE style...
710 m_isShown = TRUE;
711
712 m_hScrollBar = NULL ;
713 m_vScrollBar = NULL ;
714 m_macBackgroundBrush = wxNullBrush ;
715
716 m_macIsUserPane = TRUE;
717 #if wxMAC_USE_CORE_GRAPHICS
718 m_cgContextRef = NULL ;
719 #endif
720 // make sure all proc ptrs are available
721
722 #if !TARGET_API_MAC_OSX
723 if ( gControlUserPaneDrawUPP == NULL )
724 {
725 gControlUserPaneDrawUPP = NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc ) ;
726 gControlUserPaneHitTestUPP = NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc ) ;
727 gControlUserPaneTrackingUPP = NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc ) ;
728 gControlUserPaneIdleUPP = NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc ) ;
729 gControlUserPaneKeyDownUPP = NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc ) ;
730 gControlUserPaneActivateUPP = NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc ) ;
731 gControlUserPaneFocusUPP = NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc ) ;
732 gControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc ) ;
733 }
734 #endif
735 if ( wxMacLiveScrollbarActionUPP == NULL )
736 {
737 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
738 }
739
740 if ( wxMacSetupControlBackgroundUPP == NULL )
741 {
742 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
743 }
744
745 // we need a valid font for the encodings
746 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
747 }
748
749 // Destructor
750 wxWindowMac::~wxWindowMac()
751 {
752 SendDestroyEvent();
753
754 m_isBeingDeleted = TRUE;
755
756 if ( m_peer )
757 {
758 // deleting a window while it is shown invalidates the region occupied by border or
759 // focus
760 int outerBorder = MacGetLeftBorderSize() ;
761 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
762 outerBorder += 4 ;
763
764 if ( IsShown() && ( outerBorder > 0 ) )
765 {
766 // as the borders are drawn on the parent we have to properly invalidate all these areas
767 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
768
769 Rect rect ;
770
771 m_peer->GetRect( &rect ) ;
772 RectRgn( updateInner , &rect ) ;
773 InsetRect( &rect , -outerBorder , -outerBorder ) ;
774 RectRgn( updateOuter , &rect ) ;
775 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
776 wxPoint parent(0,0);
777 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
778 parent -= GetParent()->GetClientAreaOrigin() ;
779 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
780 CopyRgn( updateOuter , updateTotal ) ;
781
782 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
783 DisposeRgn(updateOuter) ;
784 DisposeRgn(updateInner) ;
785 DisposeRgn(updateTotal) ;
786 }
787 }
788
789 #ifndef __WXUNIVERSAL__
790 // VS: make sure there's no wxFrame with last focus set to us:
791 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
792 {
793 wxFrame *frame = wxDynamicCast(win, wxFrame);
794 if ( frame )
795 {
796 if ( frame->GetLastFocus() == this )
797 {
798 frame->SetLastFocus((wxWindow*)NULL);
799 }
800 break;
801 }
802 }
803 #endif // __WXUNIVERSAL__
804
805 // destroy children before destroying this window itself
806 DestroyChildren();
807
808 // wxRemoveMacControlAssociation( this ) ;
809 // If we delete an item, we should initialize the parent panel,
810 // because it could now be invalid.
811 wxWindow *parent = GetParent() ;
812 if ( parent )
813 {
814 if (parent->GetDefaultItem() == (wxButton*) this)
815 parent->SetDefaultItem(NULL);
816 }
817 if ( m_peer && m_peer->Ok() )
818 {
819 // in case the callback might be called during destruction
820 wxRemoveMacControlAssociation( this) ;
821 // we currently are not using this hook
822 // ::SetControlColorProc( *m_peer , NULL ) ;
823 m_peer->Dispose() ;
824 }
825
826 if ( g_MacLastWindow == this )
827 {
828 g_MacLastWindow = NULL ;
829 }
830
831 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
832 if ( frame )
833 {
834 if ( frame->GetLastFocus() == this )
835 frame->SetLastFocus( NULL ) ;
836 }
837
838 // delete our drop target if we've got one
839 #if wxUSE_DRAG_AND_DROP
840 if ( m_dropTarget != NULL )
841 {
842 delete m_dropTarget;
843 m_dropTarget = NULL;
844 }
845 #endif // wxUSE_DRAG_AND_DROP
846 delete m_peer ;
847 }
848
849 WXWidget wxWindowMac::GetHandle() const
850 {
851 return (WXWidget) m_peer->GetControlRef() ;
852 }
853
854
855 void wxWindowMac::MacInstallEventHandler( WXWidget control )
856 {
857 wxAssociateControlWithMacControl( (ControlRef) control , this ) ;
858 InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(),
859 GetEventTypeCount(eventList), eventList, this,
860 (EventHandlerRef *)&m_macControlEventHandler);
861 #if !TARGET_API_MAC_OSX
862 if ( (ControlRef) control == m_peer->GetControlRef() )
863 {
864 m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ;
865 m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ;
866 m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ;
867 m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ;
868 m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ;
869 m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ;
870 m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ;
871 m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ;
872 }
873 #endif
874
875 }
876
877 // Constructor
878 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
879 const wxPoint& pos,
880 const wxSize& size,
881 long style,
882 const wxString& name)
883 {
884 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
885
886 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
887 return FALSE;
888
889 m_windowVariant = parent->GetWindowVariant() ;
890
891 if ( m_macIsUserPane )
892 {
893 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
894
895 UInt32 features = 0
896 | kControlSupportsEmbedding
897 // | kControlSupportsLiveFeedback
898 // | kControlHasSpecialBackground
899 // | kControlSupportsCalcBestRect
900 // | kControlHandlesTracking
901 | kControlSupportsFocus
902 // | kControlWantsActivate
903 // | kControlWantsIdle
904 ;
905
906 m_peer = new wxMacControl() ;
907 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
908
909
910 MacPostControlCreate(pos,size) ;
911 }
912 #ifndef __WXUNIVERSAL__
913 // Don't give scrollbars to wxControls unless they ask for them
914 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
915 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
916 {
917 MacCreateScrollBars( style ) ;
918 }
919 #endif
920
921 wxWindowCreateEvent event(this);
922 GetEventHandler()->AddPendingEvent(event);
923
924 return TRUE;
925 }
926
927 void wxWindowMac::MacChildAdded()
928 {
929 if ( m_vScrollBar )
930 {
931 m_vScrollBar->Raise() ;
932 }
933 if ( m_hScrollBar )
934 {
935 m_hScrollBar->Raise() ;
936 }
937
938 }
939
940 void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
941 {
942 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
943
944 m_peer->SetReference( (long) this ) ;
945 GetParent()->AddChild(this);
946
947 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
948
949 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
950 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
951 ::EmbedControl( m_peer->GetControlRef() , container ) ;
952 GetParent()->MacChildAdded() ;
953
954 // adjust font, controlsize etc
955 DoSetWindowVariant( m_windowVariant ) ;
956
957 #if !TARGET_API_MAC_OSX
958 // eventually we can fix some clipping issues be reactivating this hook
959 //if ( m_macIsUserPane )
960 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
961 #endif
962 m_peer->SetTitle( wxStripMenuCodes(m_label) ) ;
963
964 if (!m_macIsUserPane)
965 {
966 SetInitialBestSize(size);
967 }
968
969 SetCursor( *wxSTANDARD_CURSOR ) ;
970 }
971
972 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
973 {
974 // Don't assert, in case we set the window variant before
975 // the window is created
976 // wxASSERT( m_peer->Ok() ) ;
977
978 m_windowVariant = variant ;
979
980 if (m_peer == NULL || !m_peer->Ok())
981 return;
982
983 ControlSize size ;
984 ThemeFontID themeFont = kThemeSystemFont ;
985
986 // we will get that from the settings later
987 // and make this NORMAL later, but first
988 // we have a few calculations that we must fix
989
990 switch ( variant )
991 {
992 case wxWINDOW_VARIANT_NORMAL :
993 size = kControlSizeNormal;
994 themeFont = kThemeSystemFont ;
995 break ;
996 case wxWINDOW_VARIANT_SMALL :
997 size = kControlSizeSmall;
998 themeFont = kThemeSmallSystemFont ;
999 break ;
1000 case wxWINDOW_VARIANT_MINI :
1001 if (UMAGetSystemVersion() >= 0x1030 )
1002 {
1003 // not always defined in the headers
1004 size = 3 ;
1005 themeFont = 109 ;
1006 }
1007 else
1008 {
1009 size = kControlSizeSmall;
1010 themeFont = kThemeSmallSystemFont ;
1011 }
1012 break ;
1013 case wxWINDOW_VARIANT_LARGE :
1014 size = kControlSizeLarge;
1015 themeFont = kThemeSystemFont ;
1016 break ;
1017 default:
1018 wxFAIL_MSG(_T("unexpected window variant"));
1019 break ;
1020 }
1021 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ;
1022
1023 wxFont font ;
1024 font.MacCreateThemeFont( themeFont ) ;
1025 SetFont( font ) ;
1026 }
1027
1028 void wxWindowMac::MacUpdateControlFont()
1029 {
1030 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1031 Refresh() ;
1032 }
1033
1034 bool wxWindowMac::SetFont(const wxFont& font)
1035 {
1036 bool retval = wxWindowBase::SetFont( font ) ;
1037
1038 MacUpdateControlFont() ;
1039
1040 return retval;
1041 }
1042
1043 bool wxWindowMac::SetForegroundColour(const wxColour& col )
1044 {
1045 if ( !wxWindowBase::SetForegroundColour(col) )
1046 return false ;
1047
1048 MacUpdateControlFont() ;
1049
1050 return true ;
1051 }
1052
1053 bool wxWindowMac::SetBackgroundColour(const wxColour& col )
1054 {
1055 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1056 return false ;
1057
1058 wxBrush brush ;
1059 wxColour newCol(GetBackgroundColour());
1060 if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1061 {
1062 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
1063 }
1064 else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
1065 {
1066 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
1067 }
1068 else
1069 {
1070 brush.SetColour( newCol ) ;
1071 }
1072 MacSetBackgroundBrush( brush ) ;
1073
1074 MacUpdateControlFont() ;
1075
1076 return true ;
1077 }
1078
1079 void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
1080 {
1081 m_macBackgroundBrush = brush ;
1082 m_peer->SetBackground( brush ) ;
1083 }
1084
1085 bool wxWindowMac::MacCanFocus() const
1086 {
1087 // there is currently no way to determine whether the window is running in full keyboard
1088 // access mode, therefore we cannot rely on these features, yet the only other way would be
1089 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1090 // in event handlers...
1091 UInt32 features = 0 ;
1092 m_peer->GetFeatures( & features ) ;
1093 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
1094 }
1095
1096
1097 void wxWindowMac::SetFocus()
1098 {
1099 if ( AcceptsFocus() )
1100 {
1101
1102 wxWindow* former = FindFocus() ;
1103 if ( former == this )
1104 return ;
1105
1106 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
1107 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1108 // leave in case of an error
1109 if ( err == errCouldntSetFocus )
1110 return ;
1111
1112 #if !TARGET_API_MAC_OSX
1113 // emulate carbon events when running under carbonlib where they are not natively available
1114 if ( former )
1115 {
1116 EventRef evRef = NULL ;
1117 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1118 &evRef ) );
1119
1120 wxMacCarbonEvent cEvent( evRef ) ;
1121 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
1122 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
1123
1124 wxMacWindowEventHandler( NULL , evRef , former ) ;
1125 ReleaseEvent(evRef) ;
1126 }
1127 // send new focus event
1128 {
1129 EventRef evRef = NULL ;
1130 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1131 &evRef ) );
1132
1133 wxMacCarbonEvent cEvent( evRef ) ;
1134 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
1135 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
1136
1137 wxMacWindowEventHandler( NULL , evRef , this ) ;
1138 ReleaseEvent(evRef) ;
1139 }
1140 #endif
1141 }
1142 }
1143
1144
1145 void wxWindowMac::DoCaptureMouse()
1146 {
1147 wxTheApp->s_captureWindow = this ;
1148 }
1149
1150 wxWindow* wxWindowBase::GetCapture()
1151 {
1152 return wxTheApp->s_captureWindow ;
1153 }
1154
1155 void wxWindowMac::DoReleaseMouse()
1156 {
1157 wxTheApp->s_captureWindow = NULL ;
1158 }
1159
1160 #if wxUSE_DRAG_AND_DROP
1161
1162 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
1163 {
1164 if ( m_dropTarget != 0 ) {
1165 delete m_dropTarget;
1166 }
1167
1168 m_dropTarget = pDropTarget;
1169 if ( m_dropTarget != 0 )
1170 {
1171 // TODO
1172 }
1173 }
1174
1175 #endif
1176
1177 // Old style file-manager drag&drop
1178 void wxWindowMac::DragAcceptFiles(bool accept)
1179 {
1180 // TODO
1181 }
1182
1183 // Returns the size of the native control. In the case of the toplevel window
1184 // this is the content area root control
1185
1186 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
1187 int& w, int& h) const
1188 {
1189 Rect bounds ;
1190 m_peer->GetRect( &bounds ) ;
1191
1192
1193 x = bounds.left ;
1194 y = bounds.top ;
1195 w = bounds.right - bounds.left ;
1196 h = bounds.bottom - bounds.top ;
1197 }
1198
1199 // From a wx position / size calculate the appropriate size of the native control
1200
1201 bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
1202 const wxSize& size,
1203 int& x, int& y,
1204 int& w, int& h , bool adjustOrigin ) const
1205 {
1206 // the desired size, minus the border pixels gives the correct size of the control
1207
1208 x = (int)pos.x;
1209 y = (int)pos.y;
1210 // todo the default calls may be used as soon as PostCreateControl Is moved here
1211 w = size.x ; // WidthDefault( size.x );
1212 h = size.y ; // HeightDefault( size.y ) ;
1213 #if !TARGET_API_MAC_OSX
1214 GetParent()->MacWindowToRootWindow( &x , &y ) ;
1215 #endif
1216
1217 x += MacGetLeftBorderSize() ;
1218 y += MacGetTopBorderSize() ;
1219 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1220 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1221
1222 if ( adjustOrigin )
1223 AdjustForParentClientOrigin( x , y ) ;
1224 #if TARGET_API_MAC_OSX
1225 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1226 if ( ! GetParent()->IsTopLevel() )
1227 {
1228 x -= GetParent()->MacGetLeftBorderSize() ;
1229 y -= GetParent()->MacGetTopBorderSize() ;
1230 }
1231 #endif
1232 return true ;
1233 }
1234
1235 // Get window size (not client size)
1236 void wxWindowMac::DoGetSize(int *x, int *y) const
1237 {
1238 // take the size of the control and add the borders that have to be drawn outside
1239 int x1 , y1 , w1 , h1 ;
1240
1241 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
1242
1243 w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1244 h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1245
1246 if(x) *x = w1 ;
1247 if(y) *y = h1 ;
1248 }
1249
1250 // get the position of the bounds of this window in client coordinates of its parent
1251 void wxWindowMac::DoGetPosition(int *x, int *y) const
1252 {
1253 int x1 , y1 , w1 ,h1 ;
1254 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
1255 x1 -= MacGetLeftBorderSize() ;
1256 y1 -= MacGetTopBorderSize() ;
1257 // to non-client
1258 #if !TARGET_API_MAC_OSX
1259 if ( !GetParent()->IsTopLevel() )
1260 {
1261 Rect bounds ;
1262 GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
1263 x1 -= bounds.left ;
1264 y1 -= bounds.top ;
1265 }
1266 #endif
1267 if ( !IsTopLevel() )
1268 {
1269 wxWindow *parent = GetParent();
1270 if ( parent )
1271 {
1272 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1273 x1 += parent->MacGetLeftBorderSize() ;
1274 y1 += parent->MacGetTopBorderSize() ;
1275 // and now to client coordinates
1276 wxPoint pt(parent->GetClientAreaOrigin());
1277 x1 -= pt.x ;
1278 y1 -= pt.y ;
1279 }
1280 }
1281 if(x) *x = x1 ;
1282 if(y) *y = y1 ;
1283 }
1284
1285 void wxWindowMac::DoScreenToClient(int *x, int *y) const
1286 {
1287 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1288
1289 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1290
1291 {
1292 Point localwhere = {0,0} ;
1293
1294 if(x) localwhere.h = * x ;
1295 if(y) localwhere.v = * y ;
1296
1297 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
1298 if(x) *x = localwhere.h ;
1299 if(y) *y = localwhere.v ;
1300
1301 }
1302 MacRootWindowToWindow( x , y ) ;
1303
1304 wxPoint origin = GetClientAreaOrigin() ;
1305 if(x) *x -= origin.x ;
1306 if(y) *y -= origin.y ;
1307 }
1308
1309 void wxWindowMac::DoClientToScreen(int *x, int *y) const
1310 {
1311 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1312 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1313
1314 wxPoint origin = GetClientAreaOrigin() ;
1315 if(x) *x += origin.x ;
1316 if(y) *y += origin.y ;
1317
1318 MacWindowToRootWindow( x , y ) ;
1319
1320 {
1321 Point localwhere = { 0,0 };
1322 if(x) localwhere.h = * x ;
1323 if(y) localwhere.v = * y ;
1324 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
1325 if(x) *x = localwhere.h ;
1326 if(y) *y = localwhere.v ;
1327 }
1328 }
1329
1330 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
1331 {
1332 wxPoint origin = GetClientAreaOrigin() ;
1333 if(x) *x += origin.x ;
1334 if(y) *y += origin.y ;
1335
1336 MacWindowToRootWindow( x , y ) ;
1337 }
1338
1339 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1340 {
1341 MacRootWindowToWindow( x , y ) ;
1342
1343 wxPoint origin = GetClientAreaOrigin() ;
1344 if(x) *x -= origin.x ;
1345 if(y) *y -= origin.y ;
1346 }
1347
1348 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1349 {
1350 #if TARGET_API_MAC_OSX
1351 wxPoint pt ;
1352 if ( x ) pt.x = *x ;
1353 if ( y ) pt.y = *y ;
1354
1355 if ( !IsTopLevel() )
1356 {
1357 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1358 if (top)
1359 {
1360 pt.x -= MacGetLeftBorderSize() ;
1361 pt.y -= MacGetTopBorderSize() ;
1362 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1363 }
1364 }
1365
1366 if ( x ) *x = (int) pt.x ;
1367 if ( y ) *y = (int) pt.y ;
1368 #else
1369 if ( !IsTopLevel() )
1370 {
1371 Rect bounds ;
1372 m_peer->GetRect( &bounds ) ;
1373 if(x) *x += bounds.left - MacGetLeftBorderSize() ;
1374 if(y) *y += bounds.top - MacGetTopBorderSize() ;
1375 }
1376 #endif
1377 }
1378
1379 void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1380 {
1381 int x1 , y1 ;
1382 if ( x ) x1 = *x ;
1383 if ( y ) y1 = *y ;
1384 MacWindowToRootWindow( &x1 , &y1 ) ;
1385 if ( x ) *x = x1 ;
1386 if ( y ) *y = y1 ;
1387 }
1388
1389 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1390 {
1391 #if TARGET_API_MAC_OSX
1392 wxPoint pt ;
1393 if ( x ) pt.x = *x ;
1394 if ( y ) pt.y = *y ;
1395
1396 if ( !IsTopLevel() )
1397 {
1398 wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ;
1399 pt.x += MacGetLeftBorderSize() ;
1400 pt.y += MacGetTopBorderSize() ;
1401 }
1402
1403 if ( x ) *x = (int) pt.x ;
1404 if ( y ) *y = (int) pt.y ;
1405 #else
1406 if ( !IsTopLevel() )
1407 {
1408 Rect bounds ;
1409 m_peer->GetRect( &bounds ) ;
1410 if(x) *x -= bounds.left + MacGetLeftBorderSize() ;
1411 if(y) *y -= bounds.top + MacGetTopBorderSize() ;
1412 }
1413 #endif
1414 }
1415
1416 void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1417 {
1418 int x1 , y1 ;
1419 if ( x ) x1 = *x ;
1420 if ( y ) y1 = *y ;
1421 MacRootWindowToWindow( &x1 , &y1 ) ;
1422 if ( x ) *x = x1 ;
1423 if ( y ) *y = y1 ;
1424 }
1425
1426 void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1427 {
1428 RgnHandle rgn = NewRgn() ;
1429 Rect content ;
1430 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1431 {
1432 GetRegionBounds( rgn , &content ) ;
1433 }
1434 else
1435 {
1436 m_peer->GetRect( &content ) ;
1437 }
1438 DisposeRgn( rgn ) ;
1439 Rect structure ;
1440 m_peer->GetRect( &structure ) ;
1441 #if !TARGET_API_MAC_OSX
1442 OffsetRect( &content , -structure.left , -structure.top ) ;
1443 #endif
1444 left = content.left - structure.left ;
1445 top = content.top - structure.top ;
1446 right = structure.right - content.right ;
1447 bottom = structure.bottom - content.bottom ;
1448 }
1449
1450 wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1451 {
1452 wxSize sizeTotal = size;
1453
1454 RgnHandle rgn = NewRgn() ;
1455
1456 Rect content ;
1457
1458 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1459 {
1460 GetRegionBounds( rgn , &content ) ;
1461 }
1462 else
1463 {
1464 m_peer->GetRect( &content ) ;
1465 }
1466 DisposeRgn( rgn ) ;
1467 Rect structure ;
1468 m_peer->GetRect( &structure ) ;
1469 #if !TARGET_API_MAC_OSX
1470 OffsetRect( &content , -structure.left , -structure.top ) ;
1471 #endif
1472
1473 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1474 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
1475
1476 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1477 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1478
1479 return sizeTotal;
1480 }
1481
1482
1483 // Get size *available for subwindows* i.e. excluding menu bar etc.
1484 void wxWindowMac::DoGetClientSize(int *x, int *y) const
1485 {
1486 int ww, hh;
1487
1488 RgnHandle rgn = NewRgn() ;
1489 Rect content ;
1490 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1491 {
1492 GetRegionBounds( rgn , &content ) ;
1493 }
1494 else
1495 {
1496 m_peer->GetRect( &content ) ;
1497 }
1498 DisposeRgn( rgn ) ;
1499 #if !TARGET_API_MAC_OSX
1500 Rect structure ;
1501 m_peer->GetRect( &structure ) ;
1502 OffsetRect( &content , -structure.left , -structure.top ) ;
1503 #endif
1504 ww = content.right - content.left ;
1505 hh = content.bottom - content.top ;
1506 /*
1507 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1508 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1509 */
1510 /*
1511 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1512 {
1513 int x1 = 0 ;
1514 int y1 = 0 ;
1515 int w ;
1516 int h ;
1517 GetSize( &w , &h ) ;
1518
1519 MacClientToRootWindow( &x1 , &y1 ) ;
1520 MacClientToRootWindow( &w , &h ) ;
1521
1522 wxWindowMac *iter = (wxWindowMac*)this ;
1523
1524 int totW = 10000 , totH = 10000;
1525 while( iter )
1526 {
1527 if ( iter->IsTopLevel() )
1528 {
1529 iter->GetSize( &totW , &totH ) ;
1530 break ;
1531 }
1532
1533 iter = iter->GetParent() ;
1534 }
1535
1536 if (m_hScrollBar && m_hScrollBar->IsShown() )
1537 {
1538 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1539 if ( h-y1 >= totH )
1540 {
1541 hh += 1 ;
1542 }
1543 }
1544 if (m_vScrollBar && m_vScrollBar->IsShown() )
1545 {
1546 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1547 if ( w-x1 >= totW )
1548 {
1549 ww += 1 ;
1550 }
1551 }
1552 }
1553 */
1554 if (m_hScrollBar && m_hScrollBar->IsShown() )
1555 {
1556 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1557 }
1558 if (m_vScrollBar && m_vScrollBar->IsShown() )
1559 {
1560 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1561 }
1562 if(x) *x = ww;
1563 if(y) *y = hh;
1564
1565 }
1566
1567 bool wxWindowMac::SetCursor(const wxCursor& cursor)
1568 {
1569 if (m_cursor == cursor)
1570 return FALSE;
1571
1572 if (wxNullCursor == cursor)
1573 {
1574 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1575 return FALSE ;
1576 }
1577 else
1578 {
1579 if ( ! wxWindowBase::SetCursor( cursor ) )
1580 return FALSE ;
1581 }
1582
1583 wxASSERT_MSG( m_cursor.Ok(),
1584 wxT("cursor must be valid after call to the base version"));
1585
1586
1587 wxWindowMac *mouseWin = 0 ;
1588 {
1589 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1590 CGrafPtr savePort ;
1591 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1592
1593 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1594 // position, use it...
1595
1596 Point pt ;
1597 GetMouse( &pt ) ;
1598 ControlPartCode part ;
1599 ControlRef control ;
1600 control = wxMacFindControlUnderMouse( pt , window , &part ) ;
1601 if ( control )
1602 mouseWin = wxFindControlFromMacControl( control ) ;
1603
1604 if ( swapped )
1605 QDSwapPort( savePort , NULL ) ;
1606 }
1607
1608 if ( mouseWin == this && !wxIsBusy() )
1609 {
1610 m_cursor.MacInstall() ;
1611 }
1612
1613 return TRUE ;
1614 }
1615
1616 #if wxUSE_MENUS
1617 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1618 {
1619 menu->SetInvokingWindow(this);
1620 menu->UpdateUI();
1621
1622 if ( x == -1 && y == -1 )
1623 {
1624 wxPoint mouse = wxGetMousePosition();
1625 x = mouse.x; y = mouse.y;
1626 }
1627 else
1628 {
1629 ClientToScreen( &x , &y ) ;
1630 }
1631
1632 menu->MacBeforeDisplay( true ) ;
1633 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1634 if ( HiWord(menuResult) != 0 )
1635 {
1636 MenuCommand id ;
1637 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1638 wxMenuItem* item = NULL ;
1639 wxMenu* realmenu ;
1640 item = menu->FindItem(id, &realmenu) ;
1641 if (item->IsCheckable())
1642 {
1643 item->Check( !item->IsChecked() ) ;
1644 }
1645 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1646 }
1647 menu->MacAfterDisplay( true ) ;
1648
1649 menu->SetInvokingWindow(NULL);
1650
1651 return TRUE;
1652 }
1653 #endif
1654
1655 // ----------------------------------------------------------------------------
1656 // tooltips
1657 // ----------------------------------------------------------------------------
1658
1659 #if wxUSE_TOOLTIPS
1660
1661 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1662 {
1663 wxWindowBase::DoSetToolTip(tooltip);
1664
1665 if ( m_tooltip )
1666 m_tooltip->SetWindow(this);
1667 }
1668
1669 #endif // wxUSE_TOOLTIPS
1670
1671 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1672 {
1673 // this is never called for a toplevel window, so we know we have a parent
1674 int former_x , former_y , former_w, former_h ;
1675
1676 // Get true coordinates of former position
1677 DoGetPosition( &former_x , &former_y ) ;
1678 DoGetSize( &former_w , &former_h ) ;
1679
1680 wxWindow *parent = GetParent();
1681 if ( parent )
1682 {
1683 wxPoint pt(parent->GetClientAreaOrigin());
1684 former_x += pt.x ;
1685 former_y += pt.y ;
1686 }
1687
1688 int actualWidth = width;
1689 int actualHeight = height;
1690 int actualX = x;
1691 int actualY = y;
1692
1693 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1694 actualWidth = m_minWidth;
1695 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1696 actualHeight = m_minHeight;
1697 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1698 actualWidth = m_maxWidth;
1699 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1700 actualHeight = m_maxHeight;
1701
1702 bool doMove = false ;
1703 bool doResize = false ;
1704
1705 if ( actualX != former_x || actualY != former_y )
1706 {
1707 doMove = true ;
1708 }
1709 if ( actualWidth != former_w || actualHeight != former_h )
1710 {
1711 doResize = true ;
1712 }
1713
1714 if ( doMove || doResize )
1715 {
1716 // we don't adjust twice for the origin
1717 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
1718 bool vis = m_peer->IsVisible();
1719
1720 int outerBorder = MacGetLeftBorderSize() ;
1721 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1722 outerBorder += 4 ;
1723
1724 if ( vis && ( outerBorder > 0 ) )
1725 {
1726 // as the borders are drawn on the parent we have to properly invalidate all these areas
1727 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1728
1729 Rect rect ;
1730
1731 m_peer->GetRect( &rect ) ;
1732 RectRgn( updateInner , &rect ) ;
1733 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1734 RectRgn( updateOuter , &rect ) ;
1735 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1736 wxPoint parent(0,0);
1737 #if TARGET_API_MAC_OSX
1738 // no offsetting needed when compositing
1739 #else
1740 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1741 parent -= GetParent()->GetClientAreaOrigin() ;
1742 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1743 #endif
1744 CopyRgn( updateOuter , updateTotal ) ;
1745
1746 rect = r ;
1747 RectRgn( updateInner , &rect ) ;
1748 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1749 RectRgn( updateOuter , &rect ) ;
1750 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1751
1752 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1753 UnionRgn( updateOuter , updateTotal , updateTotal ) ;
1754
1755 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1756 DisposeRgn(updateOuter) ;
1757 DisposeRgn(updateInner) ;
1758 DisposeRgn(updateTotal) ;
1759 }
1760
1761 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1762 if ( vis )
1763 m_peer->SetVisibility( false , true ) ;
1764
1765 m_peer->SetRect( &r ) ;
1766 if ( vis )
1767 m_peer->SetVisibility( true , true ) ;
1768
1769 MacRepositionScrollBars() ;
1770 if ( doMove )
1771 {
1772 wxPoint point(actualX,actualY);
1773 wxMoveEvent event(point, m_windowId);
1774 event.SetEventObject(this);
1775 GetEventHandler()->ProcessEvent(event) ;
1776 }
1777 if ( doResize )
1778 {
1779 MacRepositionScrollBars() ;
1780 wxSize size(actualWidth, actualHeight);
1781 wxSizeEvent event(size, m_windowId);
1782 event.SetEventObject(this);
1783 GetEventHandler()->ProcessEvent(event);
1784 }
1785 }
1786
1787 }
1788
1789 wxSize wxWindowMac::DoGetBestSize() const
1790 {
1791 if ( m_macIsUserPane || IsTopLevel() )
1792 return wxWindowBase::DoGetBestSize() ;
1793
1794 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1795 int bestWidth, bestHeight ;
1796 m_peer->GetBestRect( &bestsize ) ;
1797
1798 if ( EmptyRect( &bestsize ) )
1799 {
1800 bestsize.left = bestsize.top = 0 ;
1801 bestsize.right = 16 ;
1802 bestsize.bottom = 16 ;
1803 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1804 {
1805 bestsize.bottom = 16 ;
1806 }
1807 #if wxUSE_SPINBTN
1808 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1809 {
1810 bestsize.bottom = 24 ;
1811 }
1812 #endif // wxUSE_SPINBTN
1813 else
1814 {
1815 // return wxWindowBase::DoGetBestSize() ;
1816 }
1817 }
1818
1819 bestWidth = bestsize.right - bestsize.left ;
1820 bestHeight = bestsize.bottom - bestsize.top ;
1821 if ( bestHeight < 10 )
1822 bestHeight = 13 ;
1823
1824 return wxSize(bestWidth, bestHeight);
1825 }
1826
1827
1828 // set the size of the window: if the dimensions are positive, just use them,
1829 // but if any of them is equal to -1, it means that we must find the value for
1830 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1831 // which case -1 is a valid value for x and y)
1832 //
1833 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1834 // the width/height to best suit our contents, otherwise we reuse the current
1835 // width/height
1836 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1837 {
1838 // get the current size and position...
1839 int currentX, currentY;
1840 GetPosition(&currentX, &currentY);
1841
1842 int currentW,currentH;
1843 GetSize(&currentW, &currentH);
1844
1845 // ... and don't do anything (avoiding flicker) if it's already ok
1846 if ( x == currentX && y == currentY &&
1847 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1848 {
1849 // TODO REMOVE
1850 MacRepositionScrollBars() ; // we might have a real position shift
1851 return;
1852 }
1853
1854 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1855 x = currentX;
1856 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1857 y = currentY;
1858
1859 AdjustForParentClientOrigin(x, y, sizeFlags);
1860
1861 wxSize size(-1, -1);
1862 if ( width == -1 )
1863 {
1864 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1865 {
1866 size = DoGetBestSize();
1867 width = size.x;
1868 }
1869 else
1870 {
1871 // just take the current one
1872 width = currentW;
1873 }
1874 }
1875
1876 if ( height == -1 )
1877 {
1878 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1879 {
1880 if ( size.x == -1 )
1881 {
1882 size = DoGetBestSize();
1883 }
1884 //else: already called DoGetBestSize() above
1885
1886 height = size.y;
1887 }
1888 else
1889 {
1890 // just take the current one
1891 height = currentH;
1892 }
1893 }
1894
1895 DoMoveWindow(x, y, width, height);
1896
1897 }
1898
1899 wxPoint wxWindowMac::GetClientAreaOrigin() const
1900 {
1901 RgnHandle rgn = NewRgn() ;
1902 Rect content ;
1903 m_peer->GetRegion( kControlContentMetaPart , rgn ) ;
1904 GetRegionBounds( rgn , &content ) ;
1905 DisposeRgn( rgn ) ;
1906 #if !TARGET_API_MAC_OSX
1907 // if the content rgn is empty / not supported
1908 // don't attempt to correct the coordinates to wxWindow relative ones
1909 if (!::EmptyRect( &content ) )
1910 {
1911 Rect structure ;
1912 m_peer->GetRect( &structure ) ;
1913 OffsetRect( &content , -structure.left , -structure.top ) ;
1914 }
1915 #endif
1916
1917 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1918 }
1919
1920 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1921 {
1922 if ( clientheight != -1 || clientheight != -1 )
1923 {
1924 int currentclientwidth , currentclientheight ;
1925 int currentwidth , currentheight ;
1926
1927 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1928 GetSize( &currentwidth , &currentheight ) ;
1929
1930 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1931 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1932 }
1933 }
1934
1935 void wxWindowMac::SetTitle(const wxString& title)
1936 {
1937 m_label = wxStripMenuCodes(title) ;
1938
1939 if ( m_peer && m_peer->Ok() )
1940 {
1941 m_peer->SetTitle( m_label ) ;
1942 }
1943 Refresh() ;
1944 }
1945
1946 wxString wxWindowMac::GetTitle() const
1947 {
1948 return m_label ;
1949 }
1950
1951 bool wxWindowMac::Show(bool show)
1952 {
1953 bool former = MacIsReallyShown() ;
1954 if ( !wxWindowBase::Show(show) )
1955 return FALSE;
1956
1957 // TODO use visibilityChanged Carbon Event for OSX
1958 if ( m_peer )
1959 {
1960 m_peer->SetVisibility( show , true ) ;
1961 }
1962 if ( former != MacIsReallyShown() )
1963 MacPropagateVisibilityChanged() ;
1964 return TRUE;
1965 }
1966
1967 bool wxWindowMac::Enable(bool enable)
1968 {
1969 wxASSERT( m_peer->Ok() ) ;
1970 bool former = MacIsReallyEnabled() ;
1971 if ( !wxWindowBase::Enable(enable) )
1972 return FALSE;
1973
1974 m_peer->Enable( enable ) ;
1975
1976 if ( former != MacIsReallyEnabled() )
1977 MacPropagateEnabledStateChanged() ;
1978 return TRUE;
1979 }
1980
1981 //
1982 // status change propagations (will be not necessary for OSX later )
1983 //
1984
1985 void wxWindowMac::MacPropagateVisibilityChanged()
1986 {
1987 #if !TARGET_API_MAC_OSX
1988 MacVisibilityChanged() ;
1989
1990 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1991 while ( node )
1992 {
1993 wxWindowMac *child = node->GetData();
1994 if ( child->IsShown() )
1995 child->MacPropagateVisibilityChanged( ) ;
1996 node = node->GetNext();
1997 }
1998 #endif
1999 }
2000
2001 void wxWindowMac::MacPropagateEnabledStateChanged( )
2002 {
2003 #if !TARGET_API_MAC_OSX
2004 MacEnabledStateChanged() ;
2005
2006 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2007 while ( node )
2008 {
2009 wxWindowMac *child = node->GetData();
2010 if ( child->IsEnabled() )
2011 child->MacPropagateEnabledStateChanged() ;
2012 node = node->GetNext();
2013 }
2014 #endif
2015 }
2016
2017 void wxWindowMac::MacPropagateHiliteChanged( )
2018 {
2019 #if !TARGET_API_MAC_OSX
2020 MacHiliteChanged() ;
2021
2022 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2023 while ( node )
2024 {
2025 wxWindowMac *child = node->GetData();
2026 // if ( child->IsEnabled() )
2027 child->MacPropagateHiliteChanged() ;
2028 node = node->GetNext();
2029 }
2030 #endif
2031 }
2032
2033 //
2034 // status change notifications
2035 //
2036
2037 void wxWindowMac::MacVisibilityChanged()
2038 {
2039 }
2040
2041 void wxWindowMac::MacHiliteChanged()
2042 {
2043 }
2044
2045 void wxWindowMac::MacEnabledStateChanged()
2046 {
2047 }
2048
2049 //
2050 // status queries on the inherited window's state
2051 //
2052
2053 bool wxWindowMac::MacIsReallyShown()
2054 {
2055 // only under OSX the visibility of the TLW is taken into account
2056 if ( m_isBeingDeleted )
2057 return false ;
2058
2059 #if TARGET_API_MAC_OSX
2060 if ( m_peer && m_peer->Ok() )
2061 return m_peer->IsVisible();
2062 #endif
2063 wxWindow* win = this ;
2064 while( win->IsShown() )
2065 {
2066 if ( win->IsTopLevel() )
2067 return true ;
2068
2069 win = win->GetParent() ;
2070 if ( win == NULL )
2071 return true ;
2072
2073 } ;
2074 return false ;
2075 }
2076
2077 bool wxWindowMac::MacIsReallyEnabled()
2078 {
2079 return m_peer->IsEnabled() ;
2080 }
2081
2082 bool wxWindowMac::MacIsReallyHilited()
2083 {
2084 return m_peer->IsActive();
2085 }
2086
2087 void wxWindowMac::MacFlashInvalidAreas()
2088 {
2089 #if TARGET_API_MAC_OSX
2090 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2091 #endif
2092 }
2093
2094 //
2095 //
2096 //
2097
2098 int wxWindowMac::GetCharHeight() const
2099 {
2100 wxClientDC dc ( (wxWindowMac*)this ) ;
2101 return dc.GetCharHeight() ;
2102 }
2103
2104 int wxWindowMac::GetCharWidth() const
2105 {
2106 wxClientDC dc ( (wxWindowMac*)this ) ;
2107 return dc.GetCharWidth() ;
2108 }
2109
2110 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
2111 int *descent, int *externalLeading, const wxFont *theFont ) const
2112 {
2113 const wxFont *fontToUse = theFont;
2114 if ( !fontToUse )
2115 fontToUse = &m_font;
2116
2117 wxClientDC dc( (wxWindowMac*) this ) ;
2118 long lx,ly,ld,le ;
2119 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2120 if ( externalLeading )
2121 *externalLeading = le ;
2122 if ( descent )
2123 *descent = ld ;
2124 if ( x )
2125 *x = lx ;
2126 if ( y )
2127 *y = ly ;
2128 }
2129
2130 /*
2131 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2132 * we always intersect with the entire window, not only with the client area
2133 */
2134
2135 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
2136 {
2137 if ( m_peer == NULL )
2138 return ;
2139
2140 #if TARGET_API_MAC_OSX
2141 if ( rect == NULL )
2142 m_peer->SetNeedsDisplay( true ) ;
2143 else
2144 {
2145 RgnHandle update = NewRgn() ;
2146 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2147 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
2148 wxPoint origin = GetClientAreaOrigin() ;
2149 OffsetRgn( update, origin.x , origin.y ) ;
2150 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2151 // inset
2152 OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2153 m_peer->SetNeedsDisplay( true , update) ;
2154 DisposeRgn( update ) ;
2155 }
2156 #else
2157 /*
2158 RgnHandle updateRgn = NewRgn() ;
2159 if ( rect == NULL )
2160 {
2161 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2162 }
2163 else
2164 {
2165 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2166 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2167 }
2168 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2169 DisposeRgn(updateRgn) ;
2170 */
2171 if ( m_peer->IsVisible())
2172 {
2173 m_peer->SetVisibility( false , false ) ;
2174 m_peer->SetVisibility( true , true ) ;
2175 }
2176 /*
2177 if ( MacGetTopLevelWindow() == NULL )
2178 return ;
2179
2180 if ( !m_peer->IsVisible())
2181 return ;
2182
2183 wxPoint client = GetClientAreaOrigin();
2184 int x1 = -client.x;
2185 int y1 = -client.y;
2186 int x2 = m_width - client.x;
2187 int y2 = m_height - client.y;
2188
2189 if (IsKindOf( CLASSINFO(wxButton)))
2190 {
2191 // buttons have an "aura"
2192 y1 -= 5;
2193 x1 -= 5;
2194 y2 += 5;
2195 x2 += 5;
2196 }
2197
2198 Rect clientrect = { y1, x1, y2, x2 };
2199
2200 if ( rect )
2201 {
2202 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2203 SectRect( &clientrect , &r , &clientrect ) ;
2204 }
2205
2206 if ( !EmptyRect( &clientrect ) )
2207 {
2208 int top = 0 , left = 0 ;
2209
2210 MacClientToRootWindow( &left , &top ) ;
2211 OffsetRect( &clientrect , left , top ) ;
2212
2213 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2214 }
2215 */
2216 #endif
2217 }
2218
2219 void wxWindowMac::Freeze()
2220 {
2221 #if TARGET_API_MAC_OSX
2222 if ( !m_frozenness++ )
2223 {
2224 if ( m_peer && m_peer->Ok() )
2225 m_peer->SetDrawingEnabled( false ) ;
2226 }
2227 #endif
2228 }
2229
2230
2231 void wxWindowMac::Thaw()
2232 {
2233 #if TARGET_API_MAC_OSX
2234 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
2235
2236 if ( !--m_frozenness )
2237 {
2238 if ( m_peer && m_peer->Ok() )
2239 {
2240 m_peer->SetDrawingEnabled( true ) ;
2241 m_peer->InvalidateWithChildren() ;
2242 }
2243 }
2244 #endif
2245 }
2246
2247 wxWindowMac *wxGetActiveWindow()
2248 {
2249 // actually this is a windows-only concept
2250 return NULL;
2251 }
2252
2253 // Coordinates relative to the window
2254 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
2255 {
2256 // We really don't move the mouse programmatically under Mac.
2257 }
2258
2259 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
2260 {
2261 #if TARGET_API_MAC_OSX
2262 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
2263 {
2264 event.Skip() ;
2265 }
2266 else
2267 #endif
2268 {
2269 event.GetDC()->Clear() ;
2270 }
2271 }
2272
2273 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2274 {
2275 event.Skip() ;
2276 }
2277
2278 int wxWindowMac::GetScrollPos(int orient) const
2279 {
2280 if ( orient == wxHORIZONTAL )
2281 {
2282 if ( m_hScrollBar )
2283 return m_hScrollBar->GetThumbPosition() ;
2284 }
2285 else
2286 {
2287 if ( m_vScrollBar )
2288 return m_vScrollBar->GetThumbPosition() ;
2289 }
2290 return 0;
2291 }
2292
2293 // This now returns the whole range, not just the number
2294 // of positions that we can scroll.
2295 int wxWindowMac::GetScrollRange(int orient) const
2296 {
2297 if ( orient == wxHORIZONTAL )
2298 {
2299 if ( m_hScrollBar )
2300 return m_hScrollBar->GetRange() ;
2301 }
2302 else
2303 {
2304 if ( m_vScrollBar )
2305 return m_vScrollBar->GetRange() ;
2306 }
2307 return 0;
2308 }
2309
2310 int wxWindowMac::GetScrollThumb(int orient) const
2311 {
2312 if ( orient == wxHORIZONTAL )
2313 {
2314 if ( m_hScrollBar )
2315 return m_hScrollBar->GetThumbSize() ;
2316 }
2317 else
2318 {
2319 if ( m_vScrollBar )
2320 return m_vScrollBar->GetThumbSize() ;
2321 }
2322 return 0;
2323 }
2324
2325 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
2326 {
2327 if ( orient == wxHORIZONTAL )
2328 {
2329 if ( m_hScrollBar )
2330 m_hScrollBar->SetThumbPosition( pos ) ;
2331 }
2332 else
2333 {
2334 if ( m_vScrollBar )
2335 m_vScrollBar->SetThumbPosition( pos ) ;
2336 }
2337 }
2338
2339 //
2340 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2341 // our own window origin is at leftOrigin/rightOrigin
2342 //
2343
2344 void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2345 {
2346 if( IsTopLevel() )
2347 return ;
2348
2349 Rect rect ;
2350 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2351 bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2352
2353 m_peer->GetRect( &rect ) ;
2354 InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2355
2356 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2357 if ( HIThemeDrawFrame != 0)
2358 {
2359 Rect srect = rect ;
2360 HIThemeFrameDrawInfo info ;
2361 memset( &info, 0 , sizeof( info ) ) ;
2362
2363 info.version = 0 ;
2364 info.kind = 0 ;
2365 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2366 info.isFocused = hasFocus ;
2367 bool draw = false ;
2368
2369 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2370 wxASSERT( cgContext ) ;
2371
2372 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2373 {
2374 SInt32 border = 0 ;
2375 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2376 InsetRect( &srect , border , border );
2377 info.kind = kHIThemeFrameTextFieldSquare ;
2378 draw = true ;
2379 }
2380 else if (HasFlag(wxSIMPLE_BORDER))
2381 {
2382 SInt32 border = 0 ;
2383 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2384 InsetRect( &srect , border , border );
2385 info.kind = kHIThemeFrameListBox ;
2386 draw = true ;
2387 }
2388
2389 if ( draw )
2390 {
2391 CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
2392 srect.bottom - srect.top ) ;
2393 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2394 }
2395 else if ( hasFocus )
2396 {
2397 srect = rect ;
2398 CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
2399 srect.bottom - srect.top ) ;
2400 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2401 }
2402
2403 m_peer->GetRect( &rect ) ;
2404 if ( hasBothScrollbars )
2405 {
2406 srect = rect ;
2407 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
2408 CGRect cgrect = CGRectMake( srect.right - size , srect.bottom - size , size , size ) ;
2409 CGPoint cgpoint = CGPointMake( srect.right - size , srect.bottom - size ) ;
2410 HIThemeGrowBoxDrawInfo info ;
2411 memset( &info, 0 , sizeof( info ) ) ;
2412 info.version = 0 ;
2413 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2414 info.kind = kHIThemeGrowBoxKindNone ;
2415 info.size = kHIThemeGrowBoxSizeNormal ;
2416 info.direction = kThemeGrowRight | kThemeGrowDown ;
2417 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2418 }
2419 }
2420 else
2421 #endif
2422 {
2423 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2424 if (top)
2425 {
2426 wxPoint pt(0,0) ;
2427 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2428 rect.left += pt.x ;
2429 rect.right += pt.x ;
2430 rect.top += pt.y ;
2431 rect.bottom += pt.y ;
2432 }
2433
2434 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2435 {
2436 Rect srect = rect ;
2437 SInt32 border = 0 ;
2438 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2439 InsetRect( &srect , border , border );
2440 DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2441 }
2442 else if (HasFlag(wxSIMPLE_BORDER))
2443 {
2444 Rect srect = rect ;
2445 SInt32 border = 0 ;
2446 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2447 InsetRect( &srect , border , border );
2448 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2449 }
2450
2451 if ( hasFocus )
2452 {
2453 Rect srect = rect ;
2454 DrawThemeFocusRect( &srect , true ) ;
2455 }
2456 if ( hasBothScrollbars )
2457 {
2458 // GetThemeStandaloneGrowBoxBounds
2459 //DrawThemeStandaloneNoGrowBox
2460 }
2461 }
2462 }
2463
2464 void wxWindowMac::RemoveChild( wxWindowBase *child )
2465 {
2466 if ( child == m_hScrollBar )
2467 m_hScrollBar = NULL ;
2468 if ( child == m_vScrollBar )
2469 m_vScrollBar = NULL ;
2470
2471 wxWindowBase::RemoveChild( child ) ;
2472 }
2473
2474 // New function that will replace some of the above.
2475 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2476 int range, bool refresh)
2477 {
2478 if ( orient == wxHORIZONTAL )
2479 {
2480 if ( m_hScrollBar )
2481 {
2482 if ( range == 0 || thumbVisible >= range )
2483 {
2484 if ( m_hScrollBar->IsShown() )
2485 m_hScrollBar->Show(false) ;
2486 }
2487 else
2488 {
2489 if ( !m_hScrollBar->IsShown() )
2490 m_hScrollBar->Show(true) ;
2491 }
2492 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2493 }
2494 }
2495 else
2496 {
2497 if ( m_vScrollBar )
2498 {
2499 if ( range == 0 || thumbVisible >= range )
2500 {
2501 if ( m_vScrollBar->IsShown() )
2502 m_vScrollBar->Show(false) ;
2503 }
2504 else
2505 {
2506 if ( !m_vScrollBar->IsShown() )
2507 m_vScrollBar->Show(true) ;
2508 }
2509 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2510 }
2511 }
2512 MacRepositionScrollBars() ;
2513 }
2514
2515 // Does a physical scroll
2516 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2517 {
2518 if( dx == 0 && dy ==0 )
2519 return ;
2520
2521
2522 {
2523
2524 int width , height ;
2525 GetClientSize( &width , &height ) ;
2526 #if TARGET_API_MAC_OSX
2527 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2528 // area is scrolled, this does not occur if width and height are 2 pixels less,
2529 // TODO write optimal workaround
2530 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
2531 if ( rect )
2532 {
2533 scrollrect.Intersect( *rect ) ;
2534 }
2535 if ( m_peer->GetNeedsDisplay() )
2536 {
2537 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2538 // either immediate redraw or full invalidate
2539 #if 1
2540 // is the better overall solution, as it does not slow down scrolling
2541 m_peer->SetNeedsDisplay( true ) ;
2542 #else
2543 // this would be the preferred version for fast drawing controls
2544 if( UMAGetSystemVersion() < 0x1030 )
2545 Update() ;
2546 else
2547 HIViewRender(m_peer->GetControlRef()) ;
2548 #endif
2549 }
2550 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2551 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2552 m_peer->ScrollRect( scrollrect , dx , dy ) ;
2553 #else
2554
2555 wxPoint pos;
2556 pos.x = pos.y = 0;
2557
2558 Rect scrollrect;
2559 RgnHandle updateRgn = NewRgn() ;
2560
2561 {
2562 wxClientDC dc(this) ;
2563 wxMacPortSetter helper(&dc) ;
2564
2565 m_peer->GetRect( &scrollrect ) ;
2566 scrollrect.top += MacGetTopBorderSize() ;
2567 scrollrect.left += MacGetLeftBorderSize() ;
2568 scrollrect.bottom = scrollrect.top + height ;
2569 scrollrect.right = scrollrect.left + width ;
2570
2571 if ( rect )
2572 {
2573 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2574 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2575 SectRect( &scrollrect , &r , &scrollrect ) ;
2576 }
2577 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2578
2579 // now scroll the former update region as well and add the new update region
2580
2581 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2582 RgnHandle formerUpdateRgn = NewRgn() ;
2583 RgnHandle scrollRgn = NewRgn() ;
2584 RectRgn( scrollRgn , &scrollrect ) ;
2585 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2586 Point pt = {0,0} ;
2587 LocalToGlobal( &pt ) ;
2588 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2589 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2590 if ( !EmptyRgn( formerUpdateRgn ) )
2591 {
2592 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2593 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2594 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2595 }
2596 InvalWindowRgn(rootWindow , updateRgn ) ;
2597 DisposeRgn( updateRgn ) ;
2598 DisposeRgn( formerUpdateRgn ) ;
2599 DisposeRgn( scrollRgn ) ;
2600 }
2601 #endif
2602 }
2603
2604 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2605 {
2606 wxWindowMac *child = node->GetData();
2607 if (child == m_vScrollBar) continue;
2608 if (child == m_hScrollBar) continue;
2609 if (child->IsTopLevel()) continue;
2610
2611 int x,y;
2612 child->GetPosition( &x, &y );
2613 int w,h;
2614 child->GetSize( &w, &h );
2615 if (rect)
2616 {
2617 wxRect rc(x,y,w,h);
2618 if (rect->Intersects(rc))
2619 child->SetSize( x+dx, y+dy, w, h );
2620 }
2621 else
2622 {
2623 child->SetSize( x+dx, y+dy, w, h );
2624 }
2625 }
2626 }
2627
2628 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2629 {
2630 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
2631 {
2632 wxScrollWinEvent wevent;
2633 wevent.SetPosition(event.GetPosition());
2634 wevent.SetOrientation(event.GetOrientation());
2635 wevent.SetEventObject(this);
2636
2637 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2638 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2639 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2640 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2641 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2642 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2643 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2644 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2645 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2646 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2647 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2648 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2649 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2650 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2651 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2652 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
2653
2654 GetEventHandler()->ProcessEvent(wevent);
2655 }
2656 }
2657
2658 // Get the window with the focus
2659 wxWindowMac *wxWindowBase::DoFindFocus()
2660 {
2661 ControlRef control ;
2662 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2663 return wxFindControlFromMacControl( control ) ;
2664 }
2665
2666 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2667 {
2668 // panel wants to track the window which was the last to have focus in it,
2669 // so we want to set ourselves as the window which last had focus
2670 //
2671 // notice that it's also important to do it upwards the tree becaus
2672 // otherwise when the top level panel gets focus, it won't set it back to
2673 // us, but to some other sibling
2674
2675 // CS:don't know if this is still needed:
2676 //wxChildFocusEvent eventFocus(this);
2677 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2678
2679 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2680 {
2681 #if !wxMAC_USE_CORE_GRAPHICS
2682 wxMacWindowStateSaver sv( this ) ;
2683
2684 int w , h ;
2685 int x , y ;
2686 x = y = 0 ;
2687 MacWindowToRootWindow( &x , &y ) ;
2688 GetSize( &w , &h ) ;
2689 Rect rect = {y , x , h + y , w + x } ;
2690
2691 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2692 DrawThemeFocusRect( &rect , true ) ;
2693 else
2694 {
2695 DrawThemeFocusRect( &rect , false ) ;
2696
2697 // as this erases part of the frame we have to redraw borders
2698 // and because our z-ordering is not always correct (staticboxes)
2699 // we have to invalidate things, we cannot simple redraw
2700 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
2701 RectRgn( updateInner , &rect ) ;
2702 InsetRect( &rect , -4 , -4 ) ;
2703 RectRgn( updateOuter , &rect ) ;
2704 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
2705 wxPoint parent(0,0);
2706 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
2707 parent -= GetParent()->GetClientAreaOrigin() ;
2708 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
2709 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
2710 DisposeRgn(updateOuter) ;
2711 DisposeRgn(updateInner) ;
2712 }
2713 #else
2714 GetParent()->Refresh() ;
2715 #endif
2716 }
2717
2718 event.Skip();
2719 }
2720
2721 void wxWindowMac::OnInternalIdle()
2722 {
2723 // This calls the UI-update mechanism (querying windows for
2724 // menu/toolbar/control state information)
2725 if (wxUpdateUIEvent::CanUpdate(this))
2726 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2727 }
2728
2729 // Raise the window to the top of the Z order
2730 void wxWindowMac::Raise()
2731 {
2732 m_peer->SetZOrder( true , NULL ) ;
2733 }
2734
2735 // Lower the window to the bottom of the Z order
2736 void wxWindowMac::Lower()
2737 {
2738 m_peer->SetZOrder( false , NULL ) ;
2739 }
2740
2741
2742 // static wxWindow *gs_lastWhich = NULL;
2743
2744 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2745 {
2746 // first trigger a set cursor event
2747
2748 wxPoint clientorigin = GetClientAreaOrigin() ;
2749 wxSize clientsize = GetClientSize() ;
2750 wxCursor cursor ;
2751 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2752 {
2753 wxSetCursorEvent event( pt.x , pt.y );
2754
2755 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2756 if ( processedEvtSetCursor && event.HasCursor() )
2757 {
2758 cursor = event.GetCursor() ;
2759 }
2760 else
2761 {
2762
2763 // the test for processedEvtSetCursor is here to prevent using m_cursor
2764 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2765 // it - this is a way to say that our cursor shouldn't be used for this
2766 // point
2767 if ( !processedEvtSetCursor && m_cursor.Ok() )
2768 {
2769 cursor = m_cursor ;
2770 }
2771 if ( wxIsBusy() )
2772 {
2773 }
2774 else
2775 {
2776 if ( !GetParent() )
2777 cursor = *wxSTANDARD_CURSOR ;
2778 }
2779 }
2780 if ( cursor.Ok() )
2781 cursor.MacInstall() ;
2782 }
2783 return cursor.Ok() ;
2784 }
2785
2786 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2787 {
2788 if ( m_tooltip )
2789 {
2790 return m_tooltip->GetTip() ;
2791 }
2792 return wxEmptyString ;
2793 }
2794
2795 void wxWindowMac::ClearBackground()
2796 {
2797 Refresh() ;
2798 Update() ;
2799 }
2800
2801 void wxWindowMac::Update()
2802 {
2803 #if TARGET_API_MAC_OSX
2804
2805 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2806 WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ;
2807
2808 // for composited windows this also triggers a redraw of all
2809 // invalid views in the window
2810 if( UMAGetSystemVersion() >= 0x1030 )
2811 HIWindowFlush(window) ;
2812 else
2813 #endif
2814 {
2815 // the only way to trigger the redrawing on earlier systems is to call
2816 // ReceiveNextEvent
2817
2818 EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
2819 UInt32 currentEventClass = 0 ;
2820 UInt32 currentEventKind = 0 ;
2821 if ( currentEvent != NULL )
2822 {
2823 currentEventClass = ::GetEventClass( currentEvent ) ;
2824 currentEventKind = ::GetEventKind( currentEvent ) ;
2825 }
2826 if ( currentEventClass != kEventClassMenu )
2827 {
2828 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2829
2830 EventRef theEvent;
2831 OSStatus status = noErr ;
2832 status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ;
2833 }
2834 else
2835 m_peer->SetNeedsDisplay( true ) ;
2836 }
2837 #else
2838 ::Draw1Control( m_peer->GetControlRef() ) ;
2839 #endif
2840 }
2841
2842 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2843 {
2844 wxTopLevelWindowMac* win = NULL ;
2845 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2846 if ( window )
2847 {
2848 win = wxFindWinFromMacWindow( window ) ;
2849 }
2850 return win ;
2851 }
2852 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2853 {
2854 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2855 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2856 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2857 // to add focus borders everywhere
2858
2859 Rect r ;
2860 RgnHandle visRgn = NewRgn() ;
2861 RgnHandle tempRgn = NewRgn() ;
2862 if ( !m_isBeingDeleted && m_peer->IsVisible())
2863 {
2864 m_peer->GetRect( &r ) ;
2865 r.left -= MacGetLeftBorderSize() ;
2866 r.top -= MacGetTopBorderSize() ;
2867 r.bottom += MacGetBottomBorderSize() ;
2868 r.right += MacGetRightBorderSize() ;
2869
2870 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2871 {
2872 MacRootWindowToWindow( &r.left , & r.top ) ;
2873 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2874 }
2875 else
2876 {
2877 r.right -= r.left ;
2878 r.bottom -= r.top ;
2879 r.left = 0 ;
2880 r.top = 0 ;
2881 }
2882 if ( includeOuterStructures )
2883 InsetRect( &r , -4 , -4 ) ;
2884 RectRgn( visRgn , &r ) ;
2885
2886 if ( !IsTopLevel() )
2887 {
2888 wxWindow* child = this ;
2889 wxWindow* parent = child->GetParent() ;
2890 while( parent )
2891 {
2892 int x , y ;
2893 wxSize size ;
2894 // we have to find a better clipping algorithm here, in order not to clip things
2895 // positioned like status and toolbar
2896 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2897 {
2898 size = parent->GetSize() ;
2899 x = y = 0 ;
2900 }
2901 else
2902 {
2903 size = parent->GetClientSize() ;
2904 wxPoint origin = parent->GetClientAreaOrigin() ;
2905 x = origin.x ;
2906 y = origin.y ;
2907 }
2908 parent->MacWindowToRootWindow( &x, &y ) ;
2909 MacRootWindowToWindow( &x , &y ) ;
2910
2911 if ( !includeOuterStructures || (
2912 parent->MacClipChildren() ||
2913 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() )
2914 ) )
2915 {
2916 SetRectRgn( tempRgn ,
2917 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2918 x + size.x - parent->MacGetRightBorderSize(),
2919 y + size.y - parent->MacGetBottomBorderSize()) ;
2920
2921 SectRgn( visRgn , tempRgn , visRgn ) ;
2922 }
2923 if ( parent->IsTopLevel() )
2924 break ;
2925 child = parent ;
2926 parent = child->GetParent() ;
2927 }
2928 }
2929 }
2930
2931 wxRegion vis = visRgn ;
2932 DisposeRgn( visRgn ) ;
2933 DisposeRgn( tempRgn ) ;
2934 return vis ;
2935 }
2936
2937 /*
2938 This function must not change the updatergn !
2939 */
2940 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2941 {
2942 RgnHandle updatergn = (RgnHandle) updatergnr ;
2943 bool handled = false ;
2944 Rect updatebounds ;
2945 GetRegionBounds( updatergn , &updatebounds ) ;
2946
2947 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2948
2949 if ( !EmptyRgn(updatergn) )
2950 {
2951 RgnHandle newupdate = NewRgn() ;
2952 wxSize point = GetClientSize() ;
2953 wxPoint origin = GetClientAreaOrigin() ;
2954 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2955 SectRgn( newupdate , updatergn , newupdate ) ;
2956
2957 // first send an erase event to the entire update area
2958 {
2959 // for the toplevel window this really is the entire area
2960 // for all the others only their client area, otherwise they
2961 // might be drawing with full alpha and eg put blue into
2962 // the grow-box area of a scrolled window (scroll sample)
2963 wxDC* dc ;
2964 if ( IsTopLevel() )
2965 dc = new wxWindowDC(this);
2966 else
2967 dc = new wxClientDC(this);
2968 dc->SetClippingRegion(wxRegion(updatergn));
2969 wxEraseEvent eevent( GetId(), dc );
2970 eevent.SetEventObject( this );
2971 GetEventHandler()->ProcessEvent( eevent );
2972 delete dc ;
2973 }
2974
2975 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2976 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2977 m_updateRegion = newupdate ;
2978 DisposeRgn( newupdate ) ;
2979
2980 if ( !m_updateRegion.Empty() )
2981 {
2982 // paint the window itself
2983
2984 wxPaintEvent event;
2985 event.SetTimestamp(time);
2986 event.SetEventObject(this);
2987 GetEventHandler()->ProcessEvent(event);
2988 handled = true ;
2989 }
2990
2991 // now we cannot rely on having its borders drawn by a window itself, as it does not
2992 // get the updateRgn wide enough to always do so, so we do it from the parent
2993 // this would also be the place to draw any custom backgrounds for native controls
2994 // in Composited windowing
2995 wxPoint clientOrigin = GetClientAreaOrigin() ;
2996
2997 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2998 {
2999 wxWindowMac *child = node->GetData();
3000 if (child == m_vScrollBar) continue;
3001 if (child == m_hScrollBar) continue;
3002 if (child->IsTopLevel()) continue;
3003 if (!child->IsShown()) continue;
3004
3005 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3006
3007 int x,y;
3008 child->GetPosition( &x, &y );
3009 int w,h;
3010 child->GetSize( &w, &h );
3011 Rect childRect = { y , x , y + h , x + w } ;
3012 OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
3013 InsetRect( &childRect , -10 , -10) ;
3014
3015 if ( RectInRgn( &childRect , updatergn ) )
3016 {
3017
3018 // paint custom borders
3019 wxNcPaintEvent eventNc( child->GetId() );
3020 eventNc.SetEventObject( child );
3021 if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
3022 {
3023 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3024 if ( HIThemeDrawFrame != 0)
3025 {
3026 child->MacPaintBorders(0,0) ;
3027 }
3028 else
3029 #endif
3030 {
3031 wxWindowDC dc(this) ;
3032 dc.SetClippingRegion(wxRegion(updatergn));
3033 wxMacPortSetter helper(&dc) ;
3034 child->MacPaintBorders(0,0) ;
3035 }
3036 }
3037 }
3038 }
3039 }
3040 return handled ;
3041 }
3042
3043
3044 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
3045 {
3046 wxWindowMac *iter = (wxWindowMac*)this ;
3047
3048 while( iter )
3049 {
3050 if ( iter->IsTopLevel() )
3051 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
3052
3053 iter = iter->GetParent() ;
3054 }
3055 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3056 return NULL ;
3057 }
3058
3059 void wxWindowMac::MacCreateScrollBars( long style )
3060 {
3061 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
3062
3063 if ( style & ( wxVSCROLL | wxHSCROLL ) )
3064 {
3065 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
3066 int scrlsize = MAC_SCROLLBAR_SIZE ;
3067 wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ;
3068 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
3069 {
3070 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
3071 variant = wxWINDOW_VARIANT_SMALL ;
3072 }
3073
3074 int adjust = hasBoth ? scrlsize - 1: 0 ;
3075 int width, height ;
3076 GetClientSize( &width , &height ) ;
3077
3078 wxPoint vPoint(width-scrlsize, 0) ;
3079 wxSize vSize(scrlsize, height - adjust) ;
3080 wxPoint hPoint(0 , height-scrlsize ) ;
3081 wxSize hSize( width - adjust, scrlsize) ;
3082
3083
3084 if ( style & wxVSCROLL )
3085 {
3086 m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint,
3087 vSize , wxVERTICAL);
3088 }
3089
3090 if ( style & wxHSCROLL )
3091 {
3092 m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint,
3093 hSize , wxHORIZONTAL);
3094 }
3095 }
3096
3097
3098 // because the create does not take into account the client area origin
3099 MacRepositionScrollBars() ; // we might have a real position shift
3100 }
3101
3102 void wxWindowMac::MacRepositionScrollBars()
3103 {
3104 if ( !m_hScrollBar && !m_vScrollBar )
3105 return ;
3106
3107 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
3108 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
3109 int adjust = hasBoth ? scrlsize - 1 : 0 ;
3110
3111 // get real client area
3112
3113 int width ;
3114 int height ;
3115 GetSize( &width , &height ) ;
3116
3117 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
3118 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
3119
3120 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
3121 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
3122 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
3123 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
3124 /*
3125 int x = 0 ;
3126 int y = 0 ;
3127 int w ;
3128 int h ;
3129 GetSize( &w , &h ) ;
3130
3131 MacClientToRootWindow( &x , &y ) ;
3132 MacClientToRootWindow( &w , &h ) ;
3133
3134 wxWindowMac *iter = (wxWindowMac*)this ;
3135
3136 int totW = 10000 , totH = 10000;
3137 while( iter )
3138 {
3139 if ( iter->IsTopLevel() )
3140 {
3141 iter->GetSize( &totW , &totH ) ;
3142 break ;
3143 }
3144
3145 iter = iter->GetParent() ;
3146 }
3147
3148 if ( x == 0 )
3149 {
3150 hPoint.x = -1 ;
3151 hSize.x += 1 ;
3152 }
3153 if ( y == 0 )
3154 {
3155 vPoint.y = -1 ;
3156 vSize.y += 1 ;
3157 }
3158
3159 if ( w-x >= totW )
3160 {
3161 hSize.x += 1 ;
3162 vPoint.x += 1 ;
3163 }
3164
3165 if ( h-y >= totH )
3166 {
3167 vSize.y += 1 ;
3168 hPoint.y += 1 ;
3169 }
3170 */
3171 if ( m_vScrollBar )
3172 {
3173 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
3174 }
3175 if ( m_hScrollBar )
3176 {
3177 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
3178 }
3179 }
3180
3181 bool wxWindowMac::AcceptsFocus() const
3182 {
3183 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3184 }
3185
3186 void wxWindowMac::MacSuperChangedPosition()
3187 {
3188 // only window-absolute structures have to be moved i.e. controls
3189
3190 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3191 while ( node )
3192 {
3193 wxWindowMac *child = node->GetData();
3194 child->MacSuperChangedPosition() ;
3195 node = node->GetNext();
3196 }
3197 }
3198
3199 void wxWindowMac::MacTopLevelWindowChangedPosition()
3200 {
3201 // only screen-absolute structures have to be moved i.e. glcanvas
3202
3203 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3204 while ( node )
3205 {
3206 wxWindowMac *child = node->GetData();
3207 child->MacTopLevelWindowChangedPosition() ;
3208 node = node->GetNext();
3209 }
3210 }
3211
3212 long wxWindowMac::MacGetLeftBorderSize( ) const
3213 {
3214 if( IsTopLevel() )
3215 return 0 ;
3216
3217 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
3218 {
3219 SInt32 border = 3 ;
3220 return border ;
3221 }
3222 else if ( m_windowStyle &wxDOUBLE_BORDER)
3223 {
3224 SInt32 border = 3 ;
3225 return border ;
3226 }
3227 else if (m_windowStyle &wxSIMPLE_BORDER)
3228 {
3229 return 1 ;
3230 }
3231 return 0 ;
3232 }
3233
3234 long wxWindowMac::MacGetRightBorderSize( ) const
3235 {
3236 // they are all symmetric in mac themes
3237 return MacGetLeftBorderSize() ;
3238 }
3239
3240 long wxWindowMac::MacGetTopBorderSize( ) const
3241 {
3242 // they are all symmetric in mac themes
3243 return MacGetLeftBorderSize() ;
3244 }
3245
3246 long wxWindowMac::MacGetBottomBorderSize( ) const
3247 {
3248 // they are all symmetric in mac themes
3249 return MacGetLeftBorderSize() ;
3250 }
3251
3252 long wxWindowMac::MacRemoveBordersFromStyle( long style )
3253 {
3254 return style & ~wxBORDER_MASK ;
3255 }
3256
3257 // Find the wxWindowMac at the current mouse position, returning the mouse
3258 // position.
3259 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
3260 {
3261 pt = wxGetMousePosition();
3262 wxWindowMac* found = wxFindWindowAtPoint(pt);
3263 return found;
3264 }
3265
3266 // Get the current mouse position.
3267 wxPoint wxGetMousePosition()
3268 {
3269 int x, y;
3270 wxGetMousePosition(& x, & y);
3271 return wxPoint(x, y);
3272 }
3273
3274 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
3275 {
3276 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
3277 {
3278 // copied from wxGTK : CS
3279 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3280 // except that:
3281 //
3282 // (a) it's a command event and so is propagated to the parent
3283 // (b) under MSW it can be generated from kbd too
3284 // (c) it uses screen coords (because of (a))
3285 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
3286 this->GetId(),
3287 this->ClientToScreen(event.GetPosition()));
3288 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
3289 event.Skip() ;
3290 }
3291 else
3292 {
3293 event.Skip() ;
3294 }
3295 }
3296
3297 void wxWindowMac::OnPaint( wxPaintEvent & event )
3298 {
3299 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
3300 {
3301 CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
3302 }
3303 }
3304
3305 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
3306 {
3307 }
3308
3309 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3310 {
3311 int x ,y , w ,h ;
3312
3313 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
3314 Rect bounds = { y , x , y+h , x+w };
3315 return bounds ;
3316 }
3317
3318 wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
3319 {
3320 return eventNotHandledErr ;
3321 }
3322
3323