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