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