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