fixes, adding paint handler for non OSX case toplevel window
[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 #if !TARGET_API_MAC_OSX
854 if ( (ControlRef) control == m_peer->GetControlRef() )
855 {
856 m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ;
857 m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ;
858 m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ;
859 m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ;
860 m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ;
861 m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ;
862 m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ;
863 m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ;
864 }
865 #endif
866
867 }
868
869 // Constructor
870 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
871 const wxPoint& pos,
872 const wxSize& size,
873 long style,
874 const wxString& name)
875 {
876 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
877
878 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
879 return FALSE;
880
881 m_windowVariant = parent->GetWindowVariant() ;
882
883 if ( m_macIsUserPane )
884 {
885 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
886
887 UInt32 features = 0
888 | kControlSupportsEmbedding
889 // | kControlSupportsLiveFeedback
890 // | kControlHasSpecialBackground
891 // | kControlSupportsCalcBestRect
892 // | kControlHandlesTracking
893 | kControlSupportsFocus
894 // | kControlWantsActivate
895 // | kControlWantsIdle
896 ;
897
898 m_peer = new wxMacControl() ;
899 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
900
901
902 MacPostControlCreate(pos,size) ;
903 }
904 #ifndef __WXUNIVERSAL__
905 // Don't give scrollbars to wxControls unless they ask for them
906 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
907 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
908 {
909 MacCreateScrollBars( style ) ;
910 }
911 #endif
912
913 wxWindowCreateEvent event(this);
914 GetEventHandler()->AddPendingEvent(event);
915
916 return TRUE;
917 }
918
919 void wxWindowMac::MacChildAdded()
920 {
921 if ( m_vScrollBar )
922 {
923 m_vScrollBar->Raise() ;
924 }
925 if ( m_hScrollBar )
926 {
927 m_hScrollBar->Raise() ;
928 }
929
930 }
931
932 void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
933 {
934 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
935
936 m_peer->SetReference( (long) this ) ;
937 GetParent()->AddChild(this);
938
939 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
940
941 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
942 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
943 ::EmbedControl( m_peer->GetControlRef() , container ) ;
944 GetParent()->MacChildAdded() ;
945
946 // adjust font, controlsize etc
947 DoSetWindowVariant( m_windowVariant ) ;
948
949 #if !TARGET_API_MAC_OSX
950 // eventually we can fix some clipping issues be reactivating this hook
951 //if ( m_macIsUserPane )
952 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
953 #endif
954 m_peer->SetTitle( wxStripMenuCodes(m_label) ) ;
955
956 if (!m_macIsUserPane)
957 {
958 SetInitialBestSize(size);
959 }
960
961 SetCursor( *wxSTANDARD_CURSOR ) ;
962 }
963
964 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
965 {
966 // Don't assert, in case we set the window variant before
967 // the window is created
968 // wxASSERT( m_peer->Ok() ) ;
969
970 m_windowVariant = variant ;
971
972 if (m_peer == NULL || !m_peer->Ok())
973 return;
974
975 ControlSize size ;
976 ThemeFontID themeFont = kThemeSystemFont ;
977
978 // we will get that from the settings later
979 // and make this NORMAL later, but first
980 // we have a few calculations that we must fix
981
982 switch ( variant )
983 {
984 case wxWINDOW_VARIANT_NORMAL :
985 size = kControlSizeNormal;
986 themeFont = kThemeSystemFont ;
987 break ;
988 case wxWINDOW_VARIANT_SMALL :
989 size = kControlSizeSmall;
990 themeFont = kThemeSmallSystemFont ;
991 break ;
992 case wxWINDOW_VARIANT_MINI :
993 if (UMAGetSystemVersion() >= 0x1030 )
994 {
995 // not always defined in the headers
996 size = 3 ;
997 themeFont = 109 ;
998 }
999 else
1000 {
1001 size = kControlSizeSmall;
1002 themeFont = kThemeSmallSystemFont ;
1003 }
1004 break ;
1005 case wxWINDOW_VARIANT_LARGE :
1006 size = kControlSizeLarge;
1007 themeFont = kThemeSystemFont ;
1008 break ;
1009 default:
1010 wxFAIL_MSG(_T("unexpected window variant"));
1011 break ;
1012 }
1013 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ;
1014
1015 wxFont font ;
1016 font.MacCreateThemeFont( themeFont ) ;
1017 SetFont( font ) ;
1018 }
1019
1020 void wxWindowMac::MacUpdateControlFont()
1021 {
1022 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1023 Refresh() ;
1024 }
1025
1026 bool wxWindowMac::SetFont(const wxFont& font)
1027 {
1028 bool retval = wxWindowBase::SetFont( font ) ;
1029
1030 MacUpdateControlFont() ;
1031
1032 return retval;
1033 }
1034
1035 bool wxWindowMac::SetForegroundColour(const wxColour& col )
1036 {
1037 if ( !wxWindowBase::SetForegroundColour(col) )
1038 return false ;
1039
1040 MacUpdateControlFont() ;
1041
1042 return true ;
1043 }
1044
1045 bool wxWindowMac::SetBackgroundColour(const wxColour& col )
1046 {
1047 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1048 return false ;
1049
1050 wxBrush brush ;
1051 wxColour newCol(GetBackgroundColour());
1052 if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1053 {
1054 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
1055 }
1056 else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
1057 {
1058 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
1059 }
1060 else
1061 {
1062 brush.SetColour( newCol ) ;
1063 }
1064 MacSetBackgroundBrush( brush ) ;
1065
1066 MacUpdateControlFont() ;
1067
1068 return true ;
1069 }
1070
1071 void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
1072 {
1073 m_macBackgroundBrush = brush ;
1074 m_peer->SetBackground( brush ) ;
1075 }
1076
1077 bool wxWindowMac::MacCanFocus() const
1078 {
1079 // there is currently no way to determine whether the window is running in full keyboard
1080 // access mode, therefore we cannot rely on these features, yet the only other way would be
1081 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1082 // in event handlers...
1083 UInt32 features = 0 ;
1084 m_peer->GetFeatures( & features ) ;
1085 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
1086 }
1087
1088
1089 void wxWindowMac::SetFocus()
1090 {
1091 if ( AcceptsFocus() )
1092 {
1093
1094 wxWindow* former = FindFocus() ;
1095 if ( former == this )
1096 return ;
1097
1098 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
1099 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1100 // leave in case of an error
1101 if ( err == errCouldntSetFocus )
1102 return ;
1103
1104 #if !TARGET_API_MAC_OSX
1105 // emulate carbon events when running under carbonlib where they are not natively available
1106 if ( former )
1107 {
1108 EventRef evRef = NULL ;
1109 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1110 &evRef ) );
1111
1112 wxMacCarbonEvent cEvent( evRef ) ;
1113 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
1114 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
1115
1116 wxMacWindowEventHandler( NULL , evRef , former ) ;
1117 ReleaseEvent(evRef) ;
1118 }
1119 // send new focus event
1120 {
1121 EventRef evRef = NULL ;
1122 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1123 &evRef ) );
1124
1125 wxMacCarbonEvent cEvent( evRef ) ;
1126 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
1127 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
1128
1129 wxMacWindowEventHandler( NULL , evRef , this ) ;
1130 ReleaseEvent(evRef) ;
1131 }
1132 #endif
1133 }
1134 }
1135
1136
1137 void wxWindowMac::DoCaptureMouse()
1138 {
1139 wxTheApp->s_captureWindow = this ;
1140 }
1141
1142 wxWindow* wxWindowBase::GetCapture()
1143 {
1144 return wxTheApp->s_captureWindow ;
1145 }
1146
1147 void wxWindowMac::DoReleaseMouse()
1148 {
1149 wxTheApp->s_captureWindow = NULL ;
1150 }
1151
1152 #if wxUSE_DRAG_AND_DROP
1153
1154 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
1155 {
1156 if ( m_dropTarget != 0 ) {
1157 delete m_dropTarget;
1158 }
1159
1160 m_dropTarget = pDropTarget;
1161 if ( m_dropTarget != 0 )
1162 {
1163 // TODO
1164 }
1165 }
1166
1167 #endif
1168
1169 // Old style file-manager drag&drop
1170 void wxWindowMac::DragAcceptFiles(bool accept)
1171 {
1172 // TODO
1173 }
1174
1175 // Returns the size of the native control. In the case of the toplevel window
1176 // this is the content area root control
1177
1178 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
1179 int& w, int& h) const
1180 {
1181 Rect bounds ;
1182 m_peer->GetRect( &bounds ) ;
1183
1184
1185 x = bounds.left ;
1186 y = bounds.top ;
1187 w = bounds.right - bounds.left ;
1188 h = bounds.bottom - bounds.top ;
1189 }
1190
1191 // From a wx position / size calculate the appropriate size of the native control
1192
1193 bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
1194 const wxSize& size,
1195 int& x, int& y,
1196 int& w, int& h , bool adjustOrigin ) const
1197 {
1198 // the desired size, minus the border pixels gives the correct size of the control
1199
1200 x = (int)pos.x;
1201 y = (int)pos.y;
1202 // todo the default calls may be used as soon as PostCreateControl Is moved here
1203 w = size.x ; // WidthDefault( size.x );
1204 h = size.y ; // HeightDefault( size.y ) ;
1205 #if !TARGET_API_MAC_OSX
1206 GetParent()->MacWindowToRootWindow( &x , &y ) ;
1207 #endif
1208
1209 x += MacGetLeftBorderSize() ;
1210 y += MacGetTopBorderSize() ;
1211 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1212 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1213
1214 if ( adjustOrigin )
1215 AdjustForParentClientOrigin( x , y ) ;
1216 #if TARGET_API_MAC_OSX
1217 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1218 if ( ! GetParent()->IsTopLevel() )
1219 {
1220 x -= GetParent()->MacGetLeftBorderSize() ;
1221 y -= GetParent()->MacGetTopBorderSize() ;
1222 }
1223 #endif
1224 return true ;
1225 }
1226
1227 // Get window size (not client size)
1228 void wxWindowMac::DoGetSize(int *x, int *y) const
1229 {
1230 // take the size of the control and add the borders that have to be drawn outside
1231 int x1 , y1 , w1 , h1 ;
1232
1233 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
1234
1235 w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1236 h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1237
1238 if(x) *x = w1 ;
1239 if(y) *y = h1 ;
1240 }
1241
1242 // get the position of the bounds of this window in client coordinates of its parent
1243 void wxWindowMac::DoGetPosition(int *x, int *y) const
1244 {
1245 int x1 , y1 , w1 ,h1 ;
1246 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
1247 x1 -= MacGetLeftBorderSize() ;
1248 y1 -= MacGetTopBorderSize() ;
1249 // to non-client
1250 #if !TARGET_API_MAC_OSX
1251 if ( !GetParent()->IsTopLevel() )
1252 {
1253 Rect bounds ;
1254 GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
1255 x1 -= bounds.left ;
1256 y1 -= bounds.top ;
1257 }
1258 #endif
1259 if ( !IsTopLevel() )
1260 {
1261 wxWindow *parent = GetParent();
1262 if ( parent )
1263 {
1264 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1265 x1 += parent->MacGetLeftBorderSize() ;
1266 y1 += parent->MacGetTopBorderSize() ;
1267 // and now to client coordinates
1268 wxPoint pt(parent->GetClientAreaOrigin());
1269 x1 -= pt.x ;
1270 y1 -= pt.y ;
1271 }
1272 }
1273 if(x) *x = x1 ;
1274 if(y) *y = y1 ;
1275 }
1276
1277 void wxWindowMac::DoScreenToClient(int *x, int *y) const
1278 {
1279 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1280
1281 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1282
1283 {
1284 Point localwhere = {0,0} ;
1285
1286 if(x) localwhere.h = * x ;
1287 if(y) localwhere.v = * y ;
1288
1289 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
1290 if(x) *x = localwhere.h ;
1291 if(y) *y = localwhere.v ;
1292
1293 }
1294 MacRootWindowToWindow( x , y ) ;
1295
1296 wxPoint origin = GetClientAreaOrigin() ;
1297 if(x) *x -= origin.x ;
1298 if(y) *y -= origin.y ;
1299 }
1300
1301 void wxWindowMac::DoClientToScreen(int *x, int *y) const
1302 {
1303 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1304 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1305
1306 wxPoint origin = GetClientAreaOrigin() ;
1307 if(x) *x += origin.x ;
1308 if(y) *y += origin.y ;
1309
1310 MacWindowToRootWindow( x , y ) ;
1311
1312 {
1313 Point localwhere = { 0,0 };
1314 if(x) localwhere.h = * x ;
1315 if(y) localwhere.v = * y ;
1316 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
1317 if(x) *x = localwhere.h ;
1318 if(y) *y = localwhere.v ;
1319 }
1320 }
1321
1322 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
1323 {
1324 wxPoint origin = GetClientAreaOrigin() ;
1325 if(x) *x += origin.x ;
1326 if(y) *y += origin.y ;
1327
1328 MacWindowToRootWindow( x , y ) ;
1329 }
1330
1331 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1332 {
1333 MacRootWindowToWindow( x , y ) ;
1334
1335 wxPoint origin = GetClientAreaOrigin() ;
1336 if(x) *x -= origin.x ;
1337 if(y) *y -= origin.y ;
1338 }
1339
1340 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1341 {
1342 #if TARGET_API_MAC_OSX
1343 wxPoint pt ;
1344 if ( x ) pt.x = *x ;
1345 if ( y ) pt.y = *y ;
1346
1347 if ( !IsTopLevel() )
1348 {
1349 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1350 if (top)
1351 {
1352 pt.x -= MacGetLeftBorderSize() ;
1353 pt.y -= MacGetTopBorderSize() ;
1354 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1355 }
1356 }
1357
1358 if ( x ) *x = (int) pt.x ;
1359 if ( y ) *y = (int) pt.y ;
1360 #else
1361 if ( !IsTopLevel() )
1362 {
1363 Rect bounds ;
1364 m_peer->GetRect( &bounds ) ;
1365 if(x) *x += bounds.left - MacGetLeftBorderSize() ;
1366 if(y) *y += bounds.top - MacGetTopBorderSize() ;
1367 }
1368 #endif
1369 }
1370
1371 void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1372 {
1373 int x1 , y1 ;
1374 if ( x ) x1 = *x ;
1375 if ( y ) y1 = *y ;
1376 MacWindowToRootWindow( &x1 , &y1 ) ;
1377 if ( x ) *x = x1 ;
1378 if ( y ) *y = y1 ;
1379 }
1380
1381 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1382 {
1383 #if TARGET_API_MAC_OSX
1384 wxPoint pt ;
1385 if ( x ) pt.x = *x ;
1386 if ( y ) pt.y = *y ;
1387
1388 if ( !IsTopLevel() )
1389 {
1390 wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ;
1391 pt.x += MacGetLeftBorderSize() ;
1392 pt.y += MacGetTopBorderSize() ;
1393 }
1394
1395 if ( x ) *x = (int) pt.x ;
1396 if ( y ) *y = (int) pt.y ;
1397 #else
1398 if ( !IsTopLevel() )
1399 {
1400 Rect bounds ;
1401 m_peer->GetRect( &bounds ) ;
1402 if(x) *x -= bounds.left + MacGetLeftBorderSize() ;
1403 if(y) *y -= bounds.top + MacGetTopBorderSize() ;
1404 }
1405 #endif
1406 }
1407
1408 void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1409 {
1410 int x1 , y1 ;
1411 if ( x ) x1 = *x ;
1412 if ( y ) y1 = *y ;
1413 MacRootWindowToWindow( &x1 , &y1 ) ;
1414 if ( x ) *x = x1 ;
1415 if ( y ) *y = y1 ;
1416 }
1417
1418 void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1419 {
1420 RgnHandle rgn = NewRgn() ;
1421 Rect content ;
1422 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1423 {
1424 GetRegionBounds( rgn , &content ) ;
1425 }
1426 else
1427 {
1428 m_peer->GetRect( &content ) ;
1429 }
1430 DisposeRgn( rgn ) ;
1431 Rect structure ;
1432 m_peer->GetRect( &structure ) ;
1433 #if !TARGET_API_MAC_OSX
1434 OffsetRect( &content , -structure.left , -structure.top ) ;
1435 #endif
1436 left = content.left - structure.left ;
1437 top = content.top - structure.top ;
1438 right = structure.right - content.right ;
1439 bottom = structure.bottom - content.bottom ;
1440 }
1441
1442 wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1443 {
1444 wxSize sizeTotal = size;
1445
1446 RgnHandle rgn = NewRgn() ;
1447
1448 Rect content ;
1449
1450 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1451 {
1452 GetRegionBounds( rgn , &content ) ;
1453 }
1454 else
1455 {
1456 m_peer->GetRect( &content ) ;
1457 }
1458 DisposeRgn( rgn ) ;
1459 Rect structure ;
1460 m_peer->GetRect( &structure ) ;
1461 #if !TARGET_API_MAC_OSX
1462 OffsetRect( &content , -structure.left , -structure.top ) ;
1463 #endif
1464
1465 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1466 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
1467
1468 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1469 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1470
1471 return sizeTotal;
1472 }
1473
1474
1475 // Get size *available for subwindows* i.e. excluding menu bar etc.
1476 void wxWindowMac::DoGetClientSize(int *x, int *y) const
1477 {
1478 int ww, hh;
1479
1480 RgnHandle rgn = NewRgn() ;
1481 Rect content ;
1482 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1483 {
1484 GetRegionBounds( rgn , &content ) ;
1485 }
1486 else
1487 {
1488 m_peer->GetRect( &content ) ;
1489 }
1490 DisposeRgn( rgn ) ;
1491 #if !TARGET_API_MAC_OSX
1492 Rect structure ;
1493 m_peer->GetRect( &structure ) ;
1494 OffsetRect( &content , -structure.left , -structure.top ) ;
1495 #endif
1496 ww = content.right - content.left ;
1497 hh = content.bottom - content.top ;
1498 /*
1499 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1500 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1501 */
1502 /*
1503 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1504 {
1505 int x1 = 0 ;
1506 int y1 = 0 ;
1507 int w ;
1508 int h ;
1509 GetSize( &w , &h ) ;
1510
1511 MacClientToRootWindow( &x1 , &y1 ) ;
1512 MacClientToRootWindow( &w , &h ) ;
1513
1514 wxWindowMac *iter = (wxWindowMac*)this ;
1515
1516 int totW = 10000 , totH = 10000;
1517 while( iter )
1518 {
1519 if ( iter->IsTopLevel() )
1520 {
1521 iter->GetSize( &totW , &totH ) ;
1522 break ;
1523 }
1524
1525 iter = iter->GetParent() ;
1526 }
1527
1528 if (m_hScrollBar && m_hScrollBar->IsShown() )
1529 {
1530 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1531 if ( h-y1 >= totH )
1532 {
1533 hh += 1 ;
1534 }
1535 }
1536 if (m_vScrollBar && m_vScrollBar->IsShown() )
1537 {
1538 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1539 if ( w-x1 >= totW )
1540 {
1541 ww += 1 ;
1542 }
1543 }
1544 }
1545 */
1546 if (m_hScrollBar && m_hScrollBar->IsShown() )
1547 {
1548 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1549 }
1550 if (m_vScrollBar && m_vScrollBar->IsShown() )
1551 {
1552 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1553 }
1554 if(x) *x = ww;
1555 if(y) *y = hh;
1556
1557 }
1558
1559 bool wxWindowMac::SetCursor(const wxCursor& cursor)
1560 {
1561 if (m_cursor == cursor)
1562 return FALSE;
1563
1564 if (wxNullCursor == cursor)
1565 {
1566 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1567 return FALSE ;
1568 }
1569 else
1570 {
1571 if ( ! wxWindowBase::SetCursor( cursor ) )
1572 return FALSE ;
1573 }
1574
1575 wxASSERT_MSG( m_cursor.Ok(),
1576 wxT("cursor must be valid after call to the base version"));
1577
1578
1579 wxWindowMac *mouseWin = 0 ;
1580 {
1581 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1582 CGrafPtr savePort ;
1583 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1584
1585 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1586 // position, use it...
1587
1588 Point pt ;
1589 GetMouse( &pt ) ;
1590 ControlPartCode part ;
1591 ControlRef control ;
1592 control = wxMacFindControlUnderMouse( pt , window , &part ) ;
1593 if ( control )
1594 mouseWin = wxFindControlFromMacControl( control ) ;
1595
1596 if ( swapped )
1597 QDSwapPort( savePort , NULL ) ;
1598 }
1599
1600 if ( mouseWin == this && !wxIsBusy() )
1601 {
1602 m_cursor.MacInstall() ;
1603 }
1604
1605 return TRUE ;
1606 }
1607
1608 #if wxUSE_MENUS
1609 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1610 {
1611 menu->SetInvokingWindow(this);
1612 menu->UpdateUI();
1613
1614 if ( x == -1 && y == -1 )
1615 {
1616 wxPoint mouse = wxGetMousePosition();
1617 x = mouse.x; y = mouse.y;
1618 }
1619 else
1620 {
1621 ClientToScreen( &x , &y ) ;
1622 }
1623
1624 menu->MacBeforeDisplay( true ) ;
1625 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1626 if ( HiWord(menuResult) != 0 )
1627 {
1628 MenuCommand id ;
1629 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1630 wxMenuItem* item = NULL ;
1631 wxMenu* realmenu ;
1632 item = menu->FindItem(id, &realmenu) ;
1633 if (item->IsCheckable())
1634 {
1635 item->Check( !item->IsChecked() ) ;
1636 }
1637 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1638 }
1639 menu->MacAfterDisplay( true ) ;
1640
1641 menu->SetInvokingWindow(NULL);
1642
1643 return TRUE;
1644 }
1645 #endif
1646
1647 // ----------------------------------------------------------------------------
1648 // tooltips
1649 // ----------------------------------------------------------------------------
1650
1651 #if wxUSE_TOOLTIPS
1652
1653 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1654 {
1655 wxWindowBase::DoSetToolTip(tooltip);
1656
1657 if ( m_tooltip )
1658 m_tooltip->SetWindow(this);
1659 }
1660
1661 #endif // wxUSE_TOOLTIPS
1662
1663 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1664 {
1665 // this is never called for a toplevel window, so we know we have a parent
1666 int former_x , former_y , former_w, former_h ;
1667
1668 // Get true coordinates of former position
1669 DoGetPosition( &former_x , &former_y ) ;
1670 DoGetSize( &former_w , &former_h ) ;
1671
1672 wxWindow *parent = GetParent();
1673 if ( parent )
1674 {
1675 wxPoint pt(parent->GetClientAreaOrigin());
1676 former_x += pt.x ;
1677 former_y += pt.y ;
1678 }
1679
1680 int actualWidth = width;
1681 int actualHeight = height;
1682 int actualX = x;
1683 int actualY = y;
1684
1685 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1686 actualWidth = m_minWidth;
1687 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1688 actualHeight = m_minHeight;
1689 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1690 actualWidth = m_maxWidth;
1691 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1692 actualHeight = m_maxHeight;
1693
1694 bool doMove = false ;
1695 bool doResize = false ;
1696
1697 if ( actualX != former_x || actualY != former_y )
1698 {
1699 doMove = true ;
1700 }
1701 if ( actualWidth != former_w || actualHeight != former_h )
1702 {
1703 doResize = true ;
1704 }
1705
1706 if ( doMove || doResize )
1707 {
1708 // we don't adjust twice for the origin
1709 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
1710 bool vis = m_peer->IsVisible();
1711
1712 int outerBorder = MacGetLeftBorderSize() ;
1713 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1714 outerBorder += 4 ;
1715
1716 if ( vis && ( outerBorder > 0 ) )
1717 {
1718 // as the borders are drawn on the parent we have to properly invalidate all these areas
1719 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1720
1721 Rect rect ;
1722
1723 m_peer->GetRect( &rect ) ;
1724 RectRgn( updateInner , &rect ) ;
1725 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1726 RectRgn( updateOuter , &rect ) ;
1727 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1728 wxPoint parent(0,0);
1729 #if TARGET_API_MAC_OSX
1730 // no offsetting needed when compositing
1731 #else
1732 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1733 parent -= GetParent()->GetClientAreaOrigin() ;
1734 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1735 #endif
1736 CopyRgn( updateOuter , updateTotal ) ;
1737
1738 rect = r ;
1739 RectRgn( updateInner , &rect ) ;
1740 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1741 RectRgn( updateOuter , &rect ) ;
1742 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1743
1744 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1745 UnionRgn( updateOuter , updateTotal , updateTotal ) ;
1746
1747 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1748 DisposeRgn(updateOuter) ;
1749 DisposeRgn(updateInner) ;
1750 DisposeRgn(updateTotal) ;
1751 }
1752
1753 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1754 if ( vis )
1755 m_peer->SetVisibility( false , true ) ;
1756
1757 m_peer->SetRect( &r ) ;
1758 if ( vis )
1759 m_peer->SetVisibility( true , true ) ;
1760
1761 MacRepositionScrollBars() ;
1762 if ( doMove )
1763 {
1764 wxPoint point(actualX,actualY);
1765 wxMoveEvent event(point, m_windowId);
1766 event.SetEventObject(this);
1767 GetEventHandler()->ProcessEvent(event) ;
1768 }
1769 if ( doResize )
1770 {
1771 MacRepositionScrollBars() ;
1772 wxSize size(actualWidth, actualHeight);
1773 wxSizeEvent event(size, m_windowId);
1774 event.SetEventObject(this);
1775 GetEventHandler()->ProcessEvent(event);
1776 }
1777 }
1778
1779 }
1780
1781 wxSize wxWindowMac::DoGetBestSize() const
1782 {
1783 if ( m_macIsUserPane || IsTopLevel() )
1784 return wxWindowBase::DoGetBestSize() ;
1785
1786 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1787 int bestWidth, bestHeight ;
1788 m_peer->GetBestRect( &bestsize ) ;
1789
1790 if ( EmptyRect( &bestsize ) )
1791 {
1792 bestsize.left = bestsize.top = 0 ;
1793 bestsize.right = 16 ;
1794 bestsize.bottom = 16 ;
1795 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1796 {
1797 bestsize.bottom = 16 ;
1798 }
1799 #if wxUSE_SPINBTN
1800 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1801 {
1802 bestsize.bottom = 24 ;
1803 }
1804 #endif // wxUSE_SPINBTN
1805 else
1806 {
1807 // return wxWindowBase::DoGetBestSize() ;
1808 }
1809 }
1810
1811 bestWidth = bestsize.right - bestsize.left ;
1812 bestHeight = bestsize.bottom - bestsize.top ;
1813 if ( bestHeight < 10 )
1814 bestHeight = 13 ;
1815
1816 return wxSize(bestWidth, bestHeight);
1817 }
1818
1819
1820 // set the size of the window: if the dimensions are positive, just use them,
1821 // but if any of them is equal to -1, it means that we must find the value for
1822 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1823 // which case -1 is a valid value for x and y)
1824 //
1825 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1826 // the width/height to best suit our contents, otherwise we reuse the current
1827 // width/height
1828 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1829 {
1830 // get the current size and position...
1831 int currentX, currentY;
1832 GetPosition(&currentX, &currentY);
1833
1834 int currentW,currentH;
1835 GetSize(&currentW, &currentH);
1836
1837 // ... and don't do anything (avoiding flicker) if it's already ok
1838 if ( x == currentX && y == currentY &&
1839 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1840 {
1841 // TODO REMOVE
1842 MacRepositionScrollBars() ; // we might have a real position shift
1843 return;
1844 }
1845
1846 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1847 x = currentX;
1848 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1849 y = currentY;
1850
1851 AdjustForParentClientOrigin(x, y, sizeFlags);
1852
1853 wxSize size(-1, -1);
1854 if ( width == -1 )
1855 {
1856 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1857 {
1858 size = DoGetBestSize();
1859 width = size.x;
1860 }
1861 else
1862 {
1863 // just take the current one
1864 width = currentW;
1865 }
1866 }
1867
1868 if ( height == -1 )
1869 {
1870 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1871 {
1872 if ( size.x == -1 )
1873 {
1874 size = DoGetBestSize();
1875 }
1876 //else: already called DoGetBestSize() above
1877
1878 height = size.y;
1879 }
1880 else
1881 {
1882 // just take the current one
1883 height = currentH;
1884 }
1885 }
1886
1887 DoMoveWindow(x, y, width, height);
1888
1889 }
1890
1891 wxPoint wxWindowMac::GetClientAreaOrigin() const
1892 {
1893 RgnHandle rgn = NewRgn() ;
1894 Rect content ;
1895 m_peer->GetRegion( kControlContentMetaPart , rgn ) ;
1896 GetRegionBounds( rgn , &content ) ;
1897 DisposeRgn( rgn ) ;
1898 #if !TARGET_API_MAC_OSX
1899 // if the content rgn is empty / not supported
1900 // don't attempt to correct the coordinates to wxWindow relative ones
1901 if (!::EmptyRect( &content ) )
1902 {
1903 Rect structure ;
1904 m_peer->GetRect( &structure ) ;
1905 OffsetRect( &content , -structure.left , -structure.top ) ;
1906 }
1907 #endif
1908
1909 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1910 }
1911
1912 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1913 {
1914 if ( clientheight != -1 || clientheight != -1 )
1915 {
1916 int currentclientwidth , currentclientheight ;
1917 int currentwidth , currentheight ;
1918
1919 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1920 GetSize( &currentwidth , &currentheight ) ;
1921
1922 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1923 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1924 }
1925 }
1926
1927 void wxWindowMac::SetTitle(const wxString& title)
1928 {
1929 m_label = wxStripMenuCodes(title) ;
1930
1931 if ( m_peer && m_peer->Ok() )
1932 {
1933 m_peer->SetTitle( m_label ) ;
1934 }
1935 Refresh() ;
1936 }
1937
1938 wxString wxWindowMac::GetTitle() const
1939 {
1940 return m_label ;
1941 }
1942
1943 bool wxWindowMac::Show(bool show)
1944 {
1945 if ( !wxWindowBase::Show(show) )
1946 return FALSE;
1947
1948 // TODO use visibilityChanged Carbon Event for OSX
1949 if ( m_peer )
1950 {
1951 bool former = MacIsReallyShown() ;
1952
1953 m_peer->SetVisibility( show , true ) ;
1954 if ( former != MacIsReallyShown() )
1955 MacPropagateVisibilityChanged() ;
1956 }
1957 return TRUE;
1958 }
1959
1960 bool wxWindowMac::Enable(bool enable)
1961 {
1962 wxASSERT( m_peer->Ok() ) ;
1963 if ( !wxWindowBase::Enable(enable) )
1964 return FALSE;
1965
1966 bool former = MacIsReallyEnabled() ;
1967 m_peer->Enable( enable ) ;
1968
1969 if ( former != MacIsReallyEnabled() )
1970 MacPropagateEnabledStateChanged() ;
1971 return TRUE;
1972 }
1973
1974 //
1975 // status change propagations (will be not necessary for OSX later )
1976 //
1977
1978 void wxWindowMac::MacPropagateVisibilityChanged()
1979 {
1980 #if !TARGET_API_MAC_OSX
1981 MacVisibilityChanged() ;
1982
1983 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1984 while ( node )
1985 {
1986 wxWindowMac *child = node->GetData();
1987 if ( child->IsShown() )
1988 child->MacPropagateVisibilityChanged( ) ;
1989 node = node->GetNext();
1990 }
1991 #endif
1992 }
1993
1994 void wxWindowMac::MacPropagateEnabledStateChanged( )
1995 {
1996 #if !TARGET_API_MAC_OSX
1997 MacEnabledStateChanged() ;
1998
1999 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2000 while ( node )
2001 {
2002 wxWindowMac *child = node->GetData();
2003 if ( child->IsEnabled() )
2004 child->MacPropagateEnabledStateChanged() ;
2005 node = node->GetNext();
2006 }
2007 #endif
2008 }
2009
2010 void wxWindowMac::MacPropagateHiliteChanged( )
2011 {
2012 #if !TARGET_API_MAC_OSX
2013 MacHiliteChanged() ;
2014
2015 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2016 while ( node )
2017 {
2018 wxWindowMac *child = node->GetData();
2019 // if ( child->IsEnabled() )
2020 child->MacPropagateHiliteChanged() ;
2021 node = node->GetNext();
2022 }
2023 #endif
2024 }
2025
2026 //
2027 // status change notifications
2028 //
2029
2030 void wxWindowMac::MacVisibilityChanged()
2031 {
2032 }
2033
2034 void wxWindowMac::MacHiliteChanged()
2035 {
2036 }
2037
2038 void wxWindowMac::MacEnabledStateChanged()
2039 {
2040 }
2041
2042 //
2043 // status queries on the inherited window's state
2044 //
2045
2046 bool wxWindowMac::MacIsReallyShown()
2047 {
2048 // only under OSX the visibility of the TLW is taken into account
2049 if ( m_isBeingDeleted )
2050 return false ;
2051
2052 #if TARGET_API_MAC_OSX
2053 if ( m_peer && m_peer->Ok() )
2054 return m_peer->IsVisible();
2055 #endif
2056 wxWindow* win = this ;
2057 while( win->IsShown() )
2058 {
2059 if ( win->IsTopLevel() )
2060 return true ;
2061
2062 win = win->GetParent() ;
2063 if ( win == NULL )
2064 return true ;
2065
2066 } ;
2067 return false ;
2068 }
2069
2070 bool wxWindowMac::MacIsReallyEnabled()
2071 {
2072 return m_peer->IsEnabled() ;
2073 }
2074
2075 bool wxWindowMac::MacIsReallyHilited()
2076 {
2077 return m_peer->IsActive();
2078 }
2079
2080 void wxWindowMac::MacFlashInvalidAreas()
2081 {
2082 #if TARGET_API_MAC_OSX
2083 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2084 #endif
2085 }
2086
2087 //
2088 //
2089 //
2090
2091 int wxWindowMac::GetCharHeight() const
2092 {
2093 wxClientDC dc ( (wxWindowMac*)this ) ;
2094 return dc.GetCharHeight() ;
2095 }
2096
2097 int wxWindowMac::GetCharWidth() const
2098 {
2099 wxClientDC dc ( (wxWindowMac*)this ) ;
2100 return dc.GetCharWidth() ;
2101 }
2102
2103 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
2104 int *descent, int *externalLeading, const wxFont *theFont ) const
2105 {
2106 const wxFont *fontToUse = theFont;
2107 if ( !fontToUse )
2108 fontToUse = &m_font;
2109
2110 wxClientDC dc( (wxWindowMac*) this ) ;
2111 long lx,ly,ld,le ;
2112 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2113 if ( externalLeading )
2114 *externalLeading = le ;
2115 if ( descent )
2116 *descent = ld ;
2117 if ( x )
2118 *x = lx ;
2119 if ( y )
2120 *y = ly ;
2121 }
2122
2123 /*
2124 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2125 * we always intersect with the entire window, not only with the client area
2126 */
2127
2128 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
2129 {
2130 if ( m_peer == NULL )
2131 return ;
2132
2133 #if TARGET_API_MAC_OSX
2134 if ( rect == NULL )
2135 m_peer->SetNeedsDisplay( true ) ;
2136 else
2137 {
2138 RgnHandle update = NewRgn() ;
2139 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2140 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
2141 wxPoint origin = GetClientAreaOrigin() ;
2142 OffsetRgn( update, origin.x , origin.y ) ;
2143 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2144 // inset
2145 OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2146 m_peer->SetNeedsDisplay( true , update) ;
2147 DisposeRgn( update ) ;
2148 }
2149 #else
2150 /*
2151 RgnHandle updateRgn = NewRgn() ;
2152 if ( rect == NULL )
2153 {
2154 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2155 }
2156 else
2157 {
2158 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2159 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2160 }
2161 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2162 DisposeRgn(updateRgn) ;
2163 */
2164 if ( m_peer->IsVisible())
2165 {
2166 m_peer->SetVisibility( false , false ) ;
2167 m_peer->SetVisibility( true , true ) ;
2168 }
2169 /*
2170 if ( MacGetTopLevelWindow() == NULL )
2171 return ;
2172
2173 if ( !m_peer->IsVisible())
2174 return ;
2175
2176 wxPoint client = GetClientAreaOrigin();
2177 int x1 = -client.x;
2178 int y1 = -client.y;
2179 int x2 = m_width - client.x;
2180 int y2 = m_height - client.y;
2181
2182 if (IsKindOf( CLASSINFO(wxButton)))
2183 {
2184 // buttons have an "aura"
2185 y1 -= 5;
2186 x1 -= 5;
2187 y2 += 5;
2188 x2 += 5;
2189 }
2190
2191 Rect clientrect = { y1, x1, y2, x2 };
2192
2193 if ( rect )
2194 {
2195 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2196 SectRect( &clientrect , &r , &clientrect ) ;
2197 }
2198
2199 if ( !EmptyRect( &clientrect ) )
2200 {
2201 int top = 0 , left = 0 ;
2202
2203 MacClientToRootWindow( &left , &top ) ;
2204 OffsetRect( &clientrect , left , top ) ;
2205
2206 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2207 }
2208 */
2209 #endif
2210 }
2211
2212 void wxWindowMac::Freeze()
2213 {
2214 #if TARGET_API_MAC_OSX
2215 if ( !m_frozenness++ )
2216 {
2217 if ( m_peer && m_peer->Ok() )
2218 m_peer->SetDrawingEnabled( false ) ;
2219 }
2220 #endif
2221 }
2222
2223
2224 void wxWindowMac::Thaw()
2225 {
2226 #if TARGET_API_MAC_OSX
2227 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
2228
2229 if ( !--m_frozenness )
2230 {
2231 if ( m_peer && m_peer->Ok() )
2232 {
2233 m_peer->SetDrawingEnabled( true ) ;
2234 m_peer->InvalidateWithChildren() ;
2235 }
2236 }
2237 #endif
2238 }
2239
2240 wxWindowMac *wxGetActiveWindow()
2241 {
2242 // actually this is a windows-only concept
2243 return NULL;
2244 }
2245
2246 // Coordinates relative to the window
2247 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
2248 {
2249 // We really don't move the mouse programmatically under Mac.
2250 }
2251
2252 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
2253 {
2254 #if TARGET_API_MAC_OSX
2255 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
2256 {
2257 event.Skip() ;
2258 }
2259 else
2260 #endif
2261 {
2262 event.GetDC()->Clear() ;
2263 }
2264 }
2265
2266 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2267 {
2268 event.Skip() ;
2269 }
2270
2271 int wxWindowMac::GetScrollPos(int orient) const
2272 {
2273 if ( orient == wxHORIZONTAL )
2274 {
2275 if ( m_hScrollBar )
2276 return m_hScrollBar->GetThumbPosition() ;
2277 }
2278 else
2279 {
2280 if ( m_vScrollBar )
2281 return m_vScrollBar->GetThumbPosition() ;
2282 }
2283 return 0;
2284 }
2285
2286 // This now returns the whole range, not just the number
2287 // of positions that we can scroll.
2288 int wxWindowMac::GetScrollRange(int orient) const
2289 {
2290 if ( orient == wxHORIZONTAL )
2291 {
2292 if ( m_hScrollBar )
2293 return m_hScrollBar->GetRange() ;
2294 }
2295 else
2296 {
2297 if ( m_vScrollBar )
2298 return m_vScrollBar->GetRange() ;
2299 }
2300 return 0;
2301 }
2302
2303 int wxWindowMac::GetScrollThumb(int orient) const
2304 {
2305 if ( orient == wxHORIZONTAL )
2306 {
2307 if ( m_hScrollBar )
2308 return m_hScrollBar->GetThumbSize() ;
2309 }
2310 else
2311 {
2312 if ( m_vScrollBar )
2313 return m_vScrollBar->GetThumbSize() ;
2314 }
2315 return 0;
2316 }
2317
2318 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
2319 {
2320 if ( orient == wxHORIZONTAL )
2321 {
2322 if ( m_hScrollBar )
2323 m_hScrollBar->SetThumbPosition( pos ) ;
2324 }
2325 else
2326 {
2327 if ( m_vScrollBar )
2328 m_vScrollBar->SetThumbPosition( pos ) ;
2329 }
2330 }
2331
2332 //
2333 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2334 // our own window origin is at leftOrigin/rightOrigin
2335 //
2336
2337 void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2338 {
2339 if( IsTopLevel() )
2340 return ;
2341
2342 Rect rect ;
2343 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2344 bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2345
2346 m_peer->GetRect( &rect ) ;
2347 InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2348
2349 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2350 if ( HIThemeDrawFrame != 0)
2351 {
2352 Rect srect = rect ;
2353 HIThemeFrameDrawInfo info ;
2354 memset( &info, 0 , sizeof( info ) ) ;
2355
2356 info.version = 0 ;
2357 info.kind = 0 ;
2358 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2359 info.isFocused = hasFocus ;
2360 bool draw = false ;
2361
2362 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2363 wxASSERT( cgContext ) ;
2364
2365 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2366 {
2367 SInt32 border = 0 ;
2368 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2369 InsetRect( &srect , border , border );
2370 info.kind = kHIThemeFrameTextFieldSquare ;
2371 draw = true ;
2372 }
2373 else if (HasFlag(wxSIMPLE_BORDER))
2374 {
2375 SInt32 border = 0 ;
2376 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2377 InsetRect( &srect , border , border );
2378 info.kind = kHIThemeFrameListBox ;
2379 draw = true ;
2380 }
2381
2382 if ( draw )
2383 {
2384 CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
2385 srect.bottom - srect.top ) ;
2386 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2387 }
2388 else if ( hasFocus )
2389 {
2390 srect = rect ;
2391 CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
2392 srect.bottom - srect.top ) ;
2393 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2394 }
2395
2396 m_peer->GetRect( &rect ) ;
2397 if ( hasBothScrollbars )
2398 {
2399 srect = rect ;
2400 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
2401 CGRect cgrect = CGRectMake( srect.right - size , srect.bottom - size , size , size ) ;
2402 CGPoint cgpoint = CGPointMake( srect.right - size , srect.bottom - size ) ;
2403 HIThemeGrowBoxDrawInfo info ;
2404 memset( &info, 0 , sizeof( info ) ) ;
2405 info.version = 0 ;
2406 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2407 info.kind = kHIThemeGrowBoxKindNone ;
2408 info.size = kHIThemeGrowBoxSizeNormal ;
2409 info.direction = kThemeGrowRight | kThemeGrowDown ;
2410 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2411 }
2412 }
2413 else
2414 #endif
2415 {
2416 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2417 if (top)
2418 {
2419 wxPoint pt(0,0) ;
2420 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2421 rect.left += pt.x ;
2422 rect.right += pt.x ;
2423 rect.top += pt.y ;
2424 rect.bottom += pt.y ;
2425 }
2426
2427 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2428 {
2429 Rect srect = rect ;
2430 SInt32 border = 0 ;
2431 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2432 InsetRect( &srect , border , border );
2433 DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2434 }
2435 else if (HasFlag(wxSIMPLE_BORDER))
2436 {
2437 Rect srect = rect ;
2438 SInt32 border = 0 ;
2439 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2440 InsetRect( &srect , border , border );
2441 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2442 }
2443
2444 if ( hasFocus )
2445 {
2446 Rect srect = rect ;
2447 DrawThemeFocusRect( &srect , true ) ;
2448 }
2449 if ( hasBothScrollbars )
2450 {
2451 // GetThemeStandaloneGrowBoxBounds
2452 //DrawThemeStandaloneNoGrowBox
2453 }
2454 }
2455 }
2456
2457 void wxWindowMac::RemoveChild( wxWindowBase *child )
2458 {
2459 if ( child == m_hScrollBar )
2460 m_hScrollBar = NULL ;
2461 if ( child == m_vScrollBar )
2462 m_vScrollBar = NULL ;
2463
2464 wxWindowBase::RemoveChild( child ) ;
2465 }
2466
2467 // New function that will replace some of the above.
2468 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2469 int range, bool refresh)
2470 {
2471 if ( orient == wxHORIZONTAL )
2472 {
2473 if ( m_hScrollBar )
2474 {
2475 if ( range == 0 || thumbVisible >= range )
2476 {
2477 if ( m_hScrollBar->IsShown() )
2478 m_hScrollBar->Show(false) ;
2479 }
2480 else
2481 {
2482 if ( !m_hScrollBar->IsShown() )
2483 m_hScrollBar->Show(true) ;
2484 }
2485 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2486 }
2487 }
2488 else
2489 {
2490 if ( m_vScrollBar )
2491 {
2492 if ( range == 0 || thumbVisible >= range )
2493 {
2494 if ( m_vScrollBar->IsShown() )
2495 m_vScrollBar->Show(false) ;
2496 }
2497 else
2498 {
2499 if ( !m_vScrollBar->IsShown() )
2500 m_vScrollBar->Show(true) ;
2501 }
2502 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2503 }
2504 }
2505 MacRepositionScrollBars() ;
2506 }
2507
2508 // Does a physical scroll
2509 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2510 {
2511 if( dx == 0 && dy ==0 )
2512 return ;
2513
2514
2515 {
2516
2517 int width , height ;
2518 GetClientSize( &width , &height ) ;
2519 #if TARGET_API_MAC_OSX
2520 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2521 // area is scrolled, this does not occur if width and height are 2 pixels less,
2522 // TODO write optimal workaround
2523 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
2524 if ( rect )
2525 {
2526 scrollrect.Intersect( *rect ) ;
2527 }
2528 if ( m_peer->GetNeedsDisplay() )
2529 {
2530 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2531 // either immediate redraw or full invalidate
2532 #if 1
2533 // is the better overall solution, as it does not slow down scrolling
2534 m_peer->SetNeedsDisplay( true ) ;
2535 #else
2536 // this would be the preferred version for fast drawing controls
2537 if( UMAGetSystemVersion() < 0x1030 )
2538 Update() ;
2539 else
2540 HIViewRender(m_peer->GetControlRef()) ;
2541 #endif
2542 }
2543 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2544 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2545 m_peer->ScrollRect( scrollrect , dx , dy ) ;
2546 #else
2547
2548 wxPoint pos;
2549 pos.x = pos.y = 0;
2550
2551 Rect scrollrect;
2552 RgnHandle updateRgn = NewRgn() ;
2553
2554 {
2555 wxClientDC dc(this) ;
2556 wxMacPortSetter helper(&dc) ;
2557
2558 m_peer->GetRect( &scrollrect ) ;
2559 scrollrect.top += MacGetTopBorderSize() ;
2560 scrollrect.left += MacGetLeftBorderSize() ;
2561 scrollrect.bottom = scrollrect.top + height ;
2562 scrollrect.right = scrollrect.left + width ;
2563
2564 if ( rect )
2565 {
2566 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2567 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2568 SectRect( &scrollrect , &r , &scrollrect ) ;
2569 }
2570 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2571
2572 // now scroll the former update region as well and add the new update region
2573
2574 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2575 RgnHandle formerUpdateRgn = NewRgn() ;
2576 RgnHandle scrollRgn = NewRgn() ;
2577 RectRgn( scrollRgn , &scrollrect ) ;
2578 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2579 Point pt = {0,0} ;
2580 LocalToGlobal( &pt ) ;
2581 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2582 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2583 if ( !EmptyRgn( formerUpdateRgn ) )
2584 {
2585 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2586 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2587 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2588 }
2589 InvalWindowRgn(rootWindow , updateRgn ) ;
2590 DisposeRgn( updateRgn ) ;
2591 DisposeRgn( formerUpdateRgn ) ;
2592 DisposeRgn( scrollRgn ) ;
2593 }
2594 #endif
2595 }
2596
2597 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2598 {
2599 wxWindowMac *child = node->GetData();
2600 if (child == m_vScrollBar) continue;
2601 if (child == m_hScrollBar) continue;
2602 if (child->IsTopLevel()) continue;
2603
2604 int x,y;
2605 child->GetPosition( &x, &y );
2606 int w,h;
2607 child->GetSize( &w, &h );
2608 if (rect)
2609 {
2610 wxRect rc(x,y,w,h);
2611 if (rect->Intersects(rc))
2612 child->SetSize( x+dx, y+dy, w, h );
2613 }
2614 else
2615 {
2616 child->SetSize( x+dx, y+dy, w, h );
2617 }
2618 }
2619 }
2620
2621 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2622 {
2623 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
2624 {
2625 wxScrollWinEvent wevent;
2626 wevent.SetPosition(event.GetPosition());
2627 wevent.SetOrientation(event.GetOrientation());
2628 wevent.SetEventObject(this);
2629
2630 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2631 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2632 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2633 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2634 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2635 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2636 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2637 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2638 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2639 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2640 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2641 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2642 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2643 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2644 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2645 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
2646
2647 GetEventHandler()->ProcessEvent(wevent);
2648 }
2649 }
2650
2651 // Get the window with the focus
2652 wxWindowMac *wxWindowBase::DoFindFocus()
2653 {
2654 ControlRef control ;
2655 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2656 return wxFindControlFromMacControl( control ) ;
2657 }
2658
2659 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2660 {
2661 // panel wants to track the window which was the last to have focus in it,
2662 // so we want to set ourselves as the window which last had focus
2663 //
2664 // notice that it's also important to do it upwards the tree becaus
2665 // otherwise when the top level panel gets focus, it won't set it back to
2666 // us, but to some other sibling
2667
2668 // CS:don't know if this is still needed:
2669 //wxChildFocusEvent eventFocus(this);
2670 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2671
2672 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2673 {
2674 #if !wxMAC_USE_CORE_GRAPHICS
2675 wxMacWindowStateSaver sv( this ) ;
2676
2677 int w , h ;
2678 int x , y ;
2679 x = y = 0 ;
2680 MacWindowToRootWindow( &x , &y ) ;
2681 GetSize( &w , &h ) ;
2682 Rect rect = {y , x , h + y , w + x } ;
2683
2684 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2685 DrawThemeFocusRect( &rect , true ) ;
2686 else
2687 {
2688 DrawThemeFocusRect( &rect , false ) ;
2689
2690 // as this erases part of the frame we have to redraw borders
2691 // and because our z-ordering is not always correct (staticboxes)
2692 // we have to invalidate things, we cannot simple redraw
2693 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
2694 RectRgn( updateInner , &rect ) ;
2695 InsetRect( &rect , -4 , -4 ) ;
2696 RectRgn( updateOuter , &rect ) ;
2697 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
2698 wxPoint parent(0,0);
2699 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
2700 parent -= GetParent()->GetClientAreaOrigin() ;
2701 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
2702 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
2703 DisposeRgn(updateOuter) ;
2704 DisposeRgn(updateInner) ;
2705 }
2706 #else
2707 GetParent()->Refresh() ;
2708 #endif
2709 }
2710
2711 event.Skip();
2712 }
2713
2714 void wxWindowMac::OnInternalIdle()
2715 {
2716 // This calls the UI-update mechanism (querying windows for
2717 // menu/toolbar/control state information)
2718 if (wxUpdateUIEvent::CanUpdate(this))
2719 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2720 }
2721
2722 // Raise the window to the top of the Z order
2723 void wxWindowMac::Raise()
2724 {
2725 m_peer->SetZOrder( true , NULL ) ;
2726 }
2727
2728 // Lower the window to the bottom of the Z order
2729 void wxWindowMac::Lower()
2730 {
2731 m_peer->SetZOrder( false , NULL ) ;
2732 }
2733
2734
2735 // static wxWindow *gs_lastWhich = NULL;
2736
2737 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2738 {
2739 // first trigger a set cursor event
2740
2741 wxPoint clientorigin = GetClientAreaOrigin() ;
2742 wxSize clientsize = GetClientSize() ;
2743 wxCursor cursor ;
2744 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2745 {
2746 wxSetCursorEvent event( pt.x , pt.y );
2747
2748 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2749 if ( processedEvtSetCursor && event.HasCursor() )
2750 {
2751 cursor = event.GetCursor() ;
2752 }
2753 else
2754 {
2755
2756 // the test for processedEvtSetCursor is here to prevent using m_cursor
2757 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2758 // it - this is a way to say that our cursor shouldn't be used for this
2759 // point
2760 if ( !processedEvtSetCursor && m_cursor.Ok() )
2761 {
2762 cursor = m_cursor ;
2763 }
2764 if ( wxIsBusy() )
2765 {
2766 }
2767 else
2768 {
2769 if ( !GetParent() )
2770 cursor = *wxSTANDARD_CURSOR ;
2771 }
2772 }
2773 if ( cursor.Ok() )
2774 cursor.MacInstall() ;
2775 }
2776 return cursor.Ok() ;
2777 }
2778
2779 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2780 {
2781 if ( m_tooltip )
2782 {
2783 return m_tooltip->GetTip() ;
2784 }
2785 return wxEmptyString ;
2786 }
2787
2788 void wxWindowMac::ClearBackground()
2789 {
2790 Refresh() ;
2791 Update() ;
2792 }
2793
2794 void wxWindowMac::Update()
2795 {
2796 #if TARGET_API_MAC_OSX
2797
2798 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2799 WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ;
2800
2801 // for composited windows this also triggers a redraw of all
2802 // invalid views in the window
2803 if( UMAGetSystemVersion() >= 0x1030 )
2804 HIWindowFlush(window) ;
2805 else
2806 #endif
2807 {
2808 // the only way to trigger the redrawing on earlier systems is to call
2809 // ReceiveNextEvent
2810
2811 EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
2812 UInt32 currentEventClass = 0 ;
2813 UInt32 currentEventKind = 0 ;
2814 if ( currentEvent != NULL )
2815 {
2816 currentEventClass = ::GetEventClass( currentEvent ) ;
2817 currentEventKind = ::GetEventKind( currentEvent ) ;
2818 }
2819 if ( currentEventClass != kEventClassMenu )
2820 {
2821 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2822
2823 EventRef theEvent;
2824 OSStatus status = noErr ;
2825 status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ;
2826 }
2827 else
2828 m_peer->SetNeedsDisplay( true ) ;
2829 }
2830 #else
2831 ::Draw1Control( m_peer->GetControlRef() ) ;
2832 #endif
2833 }
2834
2835 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2836 {
2837 wxTopLevelWindowMac* win = NULL ;
2838 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2839 if ( window )
2840 {
2841 win = wxFindWinFromMacWindow( window ) ;
2842 }
2843 return win ;
2844 }
2845 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2846 {
2847 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2848 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2849 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2850 // to add focus borders everywhere
2851
2852 Rect r ;
2853 RgnHandle visRgn = NewRgn() ;
2854 RgnHandle tempRgn = NewRgn() ;
2855 if ( !m_isBeingDeleted && m_peer->IsVisible())
2856 {
2857 m_peer->GetRect( &r ) ;
2858 r.left -= MacGetLeftBorderSize() ;
2859 r.top -= MacGetTopBorderSize() ;
2860 r.bottom += MacGetBottomBorderSize() ;
2861 r.right += MacGetRightBorderSize() ;
2862
2863 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2864 {
2865 MacRootWindowToWindow( &r.left , & r.top ) ;
2866 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2867 }
2868 else
2869 {
2870 r.right -= r.left ;
2871 r.bottom -= r.top ;
2872 r.left = 0 ;
2873 r.top = 0 ;
2874 }
2875 if ( includeOuterStructures )
2876 InsetRect( &r , -4 , -4 ) ;
2877 RectRgn( visRgn , &r ) ;
2878
2879 if ( !IsTopLevel() )
2880 {
2881 wxWindow* child = this ;
2882 wxWindow* parent = child->GetParent() ;
2883 while( parent )
2884 {
2885 int x , y ;
2886 wxSize size ;
2887 // we have to find a better clipping algorithm here, in order not to clip things
2888 // positioned like status and toolbar
2889 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2890 {
2891 size = parent->GetSize() ;
2892 x = y = 0 ;
2893 }
2894 else
2895 {
2896 size = parent->GetClientSize() ;
2897 wxPoint origin = parent->GetClientAreaOrigin() ;
2898 x = origin.x ;
2899 y = origin.y ;
2900 }
2901 parent->MacWindowToRootWindow( &x, &y ) ;
2902 MacRootWindowToWindow( &x , &y ) ;
2903
2904 if ( !includeOuterStructures || (
2905 parent->MacClipChildren() ||
2906 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() )
2907 ) )
2908 {
2909 SetRectRgn( tempRgn ,
2910 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2911 x + size.x - parent->MacGetRightBorderSize(),
2912 y + size.y - parent->MacGetBottomBorderSize()) ;
2913
2914 SectRgn( visRgn , tempRgn , visRgn ) ;
2915 }
2916 if ( parent->IsTopLevel() )
2917 break ;
2918 child = parent ;
2919 parent = child->GetParent() ;
2920 }
2921 }
2922 }
2923
2924 wxRegion vis = visRgn ;
2925 DisposeRgn( visRgn ) ;
2926 DisposeRgn( tempRgn ) ;
2927 return vis ;
2928 }
2929
2930 /*
2931 This function must not change the updatergn !
2932 */
2933 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2934 {
2935 RgnHandle updatergn = (RgnHandle) updatergnr ;
2936 bool handled = false ;
2937 Rect updatebounds ;
2938 GetRegionBounds( updatergn , &updatebounds ) ;
2939
2940 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2941
2942 if ( !EmptyRgn(updatergn) )
2943 {
2944 RgnHandle newupdate = NewRgn() ;
2945 wxSize point = GetClientSize() ;
2946 wxPoint origin = GetClientAreaOrigin() ;
2947 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2948 SectRgn( newupdate , updatergn , newupdate ) ;
2949
2950 // first send an erase event to the entire update area
2951 {
2952 // for the toplevel window this really is the entire area
2953 // for all the others only their client area, otherwise they
2954 // might be drawing with full alpha and eg put blue into
2955 // the grow-box area of a scrolled window (scroll sample)
2956 wxDC* dc ;
2957 if ( IsTopLevel() )
2958 dc = new wxWindowDC(this);
2959 else
2960 dc = new wxClientDC(this);
2961 dc->SetClippingRegion(wxRegion(updatergn));
2962 wxEraseEvent eevent( GetId(), dc );
2963 eevent.SetEventObject( this );
2964 GetEventHandler()->ProcessEvent( eevent );
2965 delete dc ;
2966 }
2967
2968 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2969 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2970 m_updateRegion = newupdate ;
2971 DisposeRgn( newupdate ) ;
2972
2973 if ( !m_updateRegion.Empty() )
2974 {
2975 // paint the window itself
2976
2977 wxPaintEvent event;
2978 event.SetTimestamp(time);
2979 event.SetEventObject(this);
2980 GetEventHandler()->ProcessEvent(event);
2981 handled = true ;
2982 }
2983
2984 // now we cannot rely on having its borders drawn by a window itself, as it does not
2985 // get the updateRgn wide enough to always do so, so we do it from the parent
2986 // this would also be the place to draw any custom backgrounds for native controls
2987 // in Composited windowing
2988 wxPoint clientOrigin = GetClientAreaOrigin() ;
2989
2990 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2991 {
2992 wxWindowMac *child = node->GetData();
2993 if (child == m_vScrollBar) continue;
2994 if (child == m_hScrollBar) continue;
2995 if (child->IsTopLevel()) continue;
2996 if (!child->IsShown()) continue;
2997
2998 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2999
3000 int x,y;
3001 child->GetPosition( &x, &y );
3002 int w,h;
3003 child->GetSize( &w, &h );
3004 Rect childRect = { y , x , y + h , x + w } ;
3005 OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
3006 InsetRect( &childRect , -10 , -10) ;
3007
3008 if ( RectInRgn( &childRect , updatergn ) )
3009 {
3010
3011 // paint custom borders
3012 wxNcPaintEvent eventNc( child->GetId() );
3013 eventNc.SetEventObject( child );
3014 if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
3015 {
3016 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3017 if ( HIThemeDrawFrame != 0)
3018 {
3019 child->MacPaintBorders(0,0) ;
3020 }
3021 else
3022 #endif
3023 {
3024 wxWindowDC dc(this) ;
3025 dc.SetClippingRegion(wxRegion(updatergn));
3026 wxMacPortSetter helper(&dc) ;
3027 child->MacPaintBorders(0,0) ;
3028 }
3029 }
3030 }
3031 }
3032 }
3033 return handled ;
3034 }
3035
3036
3037 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
3038 {
3039 wxWindowMac *iter = (wxWindowMac*)this ;
3040
3041 while( iter )
3042 {
3043 if ( iter->IsTopLevel() )
3044 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
3045
3046 iter = iter->GetParent() ;
3047 }
3048 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3049 return NULL ;
3050 }
3051
3052 void wxWindowMac::MacCreateScrollBars( long style )
3053 {
3054 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
3055
3056 if ( style & ( wxVSCROLL | wxHSCROLL ) )
3057 {
3058 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
3059 int scrlsize = MAC_SCROLLBAR_SIZE ;
3060 wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ;
3061 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
3062 {
3063 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
3064 variant = wxWINDOW_VARIANT_SMALL ;
3065 }
3066
3067 int adjust = hasBoth ? scrlsize - 1: 0 ;
3068 int width, height ;
3069 GetClientSize( &width , &height ) ;
3070
3071 wxPoint vPoint(width-scrlsize, 0) ;
3072 wxSize vSize(scrlsize, height - adjust) ;
3073 wxPoint hPoint(0 , height-scrlsize ) ;
3074 wxSize hSize( width - adjust, scrlsize) ;
3075
3076
3077 if ( style & wxVSCROLL )
3078 {
3079 m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint,
3080 vSize , wxVERTICAL);
3081 }
3082
3083 if ( style & wxHSCROLL )
3084 {
3085 m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint,
3086 hSize , wxHORIZONTAL);
3087 }
3088 }
3089
3090
3091 // because the create does not take into account the client area origin
3092 MacRepositionScrollBars() ; // we might have a real position shift
3093 }
3094
3095 void wxWindowMac::MacRepositionScrollBars()
3096 {
3097 if ( !m_hScrollBar && !m_vScrollBar )
3098 return ;
3099
3100 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
3101 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
3102 int adjust = hasBoth ? scrlsize - 1 : 0 ;
3103
3104 // get real client area
3105
3106 int width ;
3107 int height ;
3108 GetSize( &width , &height ) ;
3109
3110 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
3111 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
3112
3113 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
3114 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
3115 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
3116 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
3117 /*
3118 int x = 0 ;
3119 int y = 0 ;
3120 int w ;
3121 int h ;
3122 GetSize( &w , &h ) ;
3123
3124 MacClientToRootWindow( &x , &y ) ;
3125 MacClientToRootWindow( &w , &h ) ;
3126
3127 wxWindowMac *iter = (wxWindowMac*)this ;
3128
3129 int totW = 10000 , totH = 10000;
3130 while( iter )
3131 {
3132 if ( iter->IsTopLevel() )
3133 {
3134 iter->GetSize( &totW , &totH ) ;
3135 break ;
3136 }
3137
3138 iter = iter->GetParent() ;
3139 }
3140
3141 if ( x == 0 )
3142 {
3143 hPoint.x = -1 ;
3144 hSize.x += 1 ;
3145 }
3146 if ( y == 0 )
3147 {
3148 vPoint.y = -1 ;
3149 vSize.y += 1 ;
3150 }
3151
3152 if ( w-x >= totW )
3153 {
3154 hSize.x += 1 ;
3155 vPoint.x += 1 ;
3156 }
3157
3158 if ( h-y >= totH )
3159 {
3160 vSize.y += 1 ;
3161 hPoint.y += 1 ;
3162 }
3163 */
3164 if ( m_vScrollBar )
3165 {
3166 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
3167 }
3168 if ( m_hScrollBar )
3169 {
3170 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
3171 }
3172 }
3173
3174 bool wxWindowMac::AcceptsFocus() const
3175 {
3176 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3177 }
3178
3179 void wxWindowMac::MacSuperChangedPosition()
3180 {
3181 // only window-absolute structures have to be moved i.e. controls
3182
3183 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3184 while ( node )
3185 {
3186 wxWindowMac *child = node->GetData();
3187 child->MacSuperChangedPosition() ;
3188 node = node->GetNext();
3189 }
3190 }
3191
3192 void wxWindowMac::MacTopLevelWindowChangedPosition()
3193 {
3194 // only screen-absolute structures have to be moved i.e. glcanvas
3195
3196 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3197 while ( node )
3198 {
3199 wxWindowMac *child = node->GetData();
3200 child->MacTopLevelWindowChangedPosition() ;
3201 node = node->GetNext();
3202 }
3203 }
3204
3205 long wxWindowMac::MacGetLeftBorderSize( ) const
3206 {
3207 if( IsTopLevel() )
3208 return 0 ;
3209
3210 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
3211 {
3212 SInt32 border = 3 ;
3213 return border ;
3214 }
3215 else if ( m_windowStyle &wxDOUBLE_BORDER)
3216 {
3217 SInt32 border = 3 ;
3218 return border ;
3219 }
3220 else if (m_windowStyle &wxSIMPLE_BORDER)
3221 {
3222 return 1 ;
3223 }
3224 return 0 ;
3225 }
3226
3227 long wxWindowMac::MacGetRightBorderSize( ) const
3228 {
3229 // they are all symmetric in mac themes
3230 return MacGetLeftBorderSize() ;
3231 }
3232
3233 long wxWindowMac::MacGetTopBorderSize( ) const
3234 {
3235 // they are all symmetric in mac themes
3236 return MacGetLeftBorderSize() ;
3237 }
3238
3239 long wxWindowMac::MacGetBottomBorderSize( ) const
3240 {
3241 // they are all symmetric in mac themes
3242 return MacGetLeftBorderSize() ;
3243 }
3244
3245 long wxWindowMac::MacRemoveBordersFromStyle( long style )
3246 {
3247 return style & ~wxBORDER_MASK ;
3248 }
3249
3250 // Find the wxWindowMac at the current mouse position, returning the mouse
3251 // position.
3252 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
3253 {
3254 pt = wxGetMousePosition();
3255 wxWindowMac* found = wxFindWindowAtPoint(pt);
3256 return found;
3257 }
3258
3259 // Get the current mouse position.
3260 wxPoint wxGetMousePosition()
3261 {
3262 int x, y;
3263 wxGetMousePosition(& x, & y);
3264 return wxPoint(x, y);
3265 }
3266
3267 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
3268 {
3269 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
3270 {
3271 // copied from wxGTK : CS
3272 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3273 // except that:
3274 //
3275 // (a) it's a command event and so is propagated to the parent
3276 // (b) under MSW it can be generated from kbd too
3277 // (c) it uses screen coords (because of (a))
3278 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
3279 this->GetId(),
3280 this->ClientToScreen(event.GetPosition()));
3281 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
3282 event.Skip() ;
3283 }
3284 else
3285 {
3286 event.Skip() ;
3287 }
3288 }
3289
3290 void wxWindowMac::OnPaint( wxPaintEvent & event )
3291 {
3292 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
3293 {
3294 CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
3295 }
3296 }
3297
3298 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
3299 {
3300 }
3301
3302 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3303 {
3304 int x ,y , w ,h ;
3305
3306 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
3307 Rect bounds = { y , x , y+h , x+w };
3308 return bounds ;
3309 }
3310
3311 wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
3312 {
3313 return eventNotHandledErr ;
3314 }
3315
3316