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