1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
39 #include "wx/toolbar.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
74 #endif // __WXUNIVERSAL__/__WXMAC__
76 #if !USE_SHARED_LIBRARY
78 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
79 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
80 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
81 // TODO EVT_PAINT(wxWindowMac::OnPaint)
82 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
83 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
84 // EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
85 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 0
97 // ---------------------------------------------------------------------------
99 // ---------------------------------------------------------------------------
101 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
102 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
104 #if TARGET_API_MAC_OSX
106 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
108 kEventControlVisibilityChanged
= 157
114 static const EventTypeSpec eventList
[] =
116 { kEventClassControl
, kEventControlHit
} ,
117 #if TARGET_API_MAC_OSX
118 { kEventClassControl
, kEventControlDraw
} ,
119 { kEventClassControl
, kEventControlVisibilityChanged
} ,
120 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
121 { kEventClassControl
, kEventControlHiliteChanged
} ,
122 { kEventClassControl
, kEventControlSetFocusPart
} ,
124 { kEventClassService
, kEventServiceGetTypes
},
125 { kEventClassService
, kEventServiceCopy
},
126 { kEventClassService
, kEventServicePaste
},
128 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
129 // { kEventClassControl , kEventControlBoundsChanged } ,
133 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
135 OSStatus result
= eventNotHandledErr
;
137 wxMacCarbonEvent
cEvent( event
) ;
139 ControlRef controlRef
;
140 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
142 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
144 switch( GetEventKind( event
) )
146 #if TARGET_API_MAC_OSX
147 case kEventControlDraw
:
149 RgnHandle updateRgn
= NULL
;
151 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
152 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
154 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
156 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
159 // in case we would need a coregraphics compliant background erase first
160 // now usable to track redraws
161 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
162 if ( thisWindow
->MacIsUserPane() )
164 static float color
= 0.5 ;
167 HIViewGetBounds( controlRef
, &bounds
);
168 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
169 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
170 CGContextFillRect( cgContext
, bounds
);
181 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
185 case kEventControlVisibilityChanged
:
186 thisWindow
->MacVisibilityChanged() ;
188 case kEventControlEnabledStateChanged
:
189 thisWindow
->MacEnabledStateChanged() ;
191 case kEventControlHiliteChanged
:
192 thisWindow
->MacHiliteChanged() ;
194 case kEventControlSetFocusPart
:
196 Boolean focusEverything
= false ;
197 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
198 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
201 if ( controlPart
== kControlFocusNoPart
)
204 if ( thisWindow
->GetCaret() )
206 thisWindow
->GetCaret()->OnKillFocus();
208 #endif // wxUSE_CARET
209 wxFocusEvent
event(wxEVT_KILL_FOCUS
, thisWindow
->GetId());
210 event
.SetEventObject(thisWindow
);
211 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
215 // panel wants to track the window which was the last to have focus in it
216 wxChildFocusEvent
eventFocus(thisWindow
);
217 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
220 if ( thisWindow
->GetCaret() )
222 thisWindow
->GetCaret()->OnSetFocus();
224 #endif // wxUSE_CARET
226 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
227 event
.SetEventObject(thisWindow
);
228 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
233 case kEventControlHit
:
235 result
= thisWindow
->MacControlHit( handler
, event
) ;
244 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
246 OSStatus result
= eventNotHandledErr
;
248 wxMacCarbonEvent
cEvent( event
) ;
250 ControlRef controlRef
;
251 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
252 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
253 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
255 switch( GetEventKind( event
) )
257 case kEventServiceGetTypes
:
261 textCtrl
->GetSelection( &from
, &to
) ;
263 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
265 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
266 if ( textCtrl
->IsEditable() )
267 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
269 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
270 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
272 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
276 CFArrayAppendValue (copyTypes
, typestring
) ;
278 CFArrayAppendValue (pasteTypes
, typestring
) ;
279 CFRelease( typestring
) ;
285 case kEventServiceCopy
:
289 textCtrl
->GetSelection( &from
, &to
) ;
290 wxString val
= textCtrl
->GetValue() ;
291 val
= val
.Mid( from
, to
- from
) ;
292 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
293 verify_noerr( ClearScrap( &scrapRef
) ) ;
294 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
298 case kEventServicePaste
:
301 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
302 Size textSize
, pastedSize
;
303 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
305 char *content
= new char[textSize
] ;
306 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
307 content
[textSize
-1] = 0 ;
308 textCtrl
->WriteText( wxString( content
) ) ;
318 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
320 OSStatus result
= eventNotHandledErr
;
322 switch ( GetEventClass( event
) )
324 case kEventClassControl
:
325 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
327 case kEventClassService
:
328 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
335 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
337 // ---------------------------------------------------------------------------
338 // UserPane events for non OSX builds
339 // ---------------------------------------------------------------------------
341 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
343 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
344 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
345 win
->MacControlUserPaneDrawProc(part
) ;
348 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
350 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
351 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
352 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
355 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
357 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
358 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
359 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
362 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
364 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
365 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
366 win
->MacControlUserPaneIdleProc() ;
369 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
371 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
372 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
373 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
376 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
378 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
379 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
380 win
->MacControlUserPaneActivateProc(activating
) ;
383 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
385 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
386 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
387 return win
->MacControlUserPaneFocusProc(action
) ;
390 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
392 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
393 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
394 win
->MacControlUserPaneBackgroundProc(info
) ;
397 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
399 RgnHandle rgn
= NewRgn() ;
401 wxMacWindowStateSaver
sv( this ) ;
402 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
403 MacDoRedraw( rgn
, 0 ) ;
407 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
409 return kControlNoPart
;
412 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
414 return kControlNoPart
;
417 void wxWindowMac::MacControlUserPaneIdleProc()
421 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
423 return kControlNoPart
;
426 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
430 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
432 return kControlNoPart
;
435 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
439 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
440 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
441 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
442 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
443 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
444 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
445 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
446 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
448 // ===========================================================================
450 // ===========================================================================
452 wxList
wxWinMacControlList(wxKEY_INTEGER
);
454 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
456 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
459 return (wxControl
*)node
->GetData();
462 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
464 // adding NULL ControlRef is (first) surely a result of an error and
465 // (secondly) breaks native event processing
466 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
468 if ( !wxWinMacControlList
.Find((long)inControl
) )
469 wxWinMacControlList
.Append((long)inControl
, control
);
472 void wxRemoveMacControlAssociation(wxWindow
*control
)
474 wxWinMacControlList
.DeleteObject(control
);
478 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
480 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
482 // we have to setup the brush in the current port and return noErr
483 // or return an error code so that the control manager walks further up the
484 // hierarchy to find a correct background
486 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
488 OSStatus status
= paramErr
;
491 case kControlMsgApplyTextColor
:
493 case kControlMsgSetUpBackground
:
495 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
499 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
503 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
505 // this clipping is only needed for non HIView
507 RgnHandle clip
= NewRgn() ;
510 wx
->MacWindowToRootWindow( &x
,&y
) ;
511 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
512 OffsetRgn( clip
, x
, y
) ;
519 else if ( wx->MacIsUserPane() )
521 // if we don't have a valid brush for such a control, we have to call the
522 // setup of our parent ourselves
523 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
536 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
537 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
541 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
544 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
549 // ----------------------------------------------------------------------------
550 // constructors and such
551 // ----------------------------------------------------------------------------
553 void wxWindowMac::Init()
556 #if WXWIN_COMPATIBILITY_2_4
557 m_backgroundTransparent
= FALSE
;
560 // as all windows are created with WS_VISIBLE style...
563 m_hScrollBar
= NULL
;
564 m_vScrollBar
= NULL
;
565 m_macBackgroundBrush
= wxNullBrush
;
567 m_macControl
= NULL
;
569 m_macIsUserPane
= TRUE
;
571 // make sure all proc ptrs are available
573 if ( gControlUserPaneDrawUPP
== NULL
)
575 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
576 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
577 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
578 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
579 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
580 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
581 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
582 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
584 if ( wxMacLiveScrollbarActionUPP
== NULL
)
586 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
589 if ( wxMacSetupControlBackgroundUPP
== NULL
)
591 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
594 // we need a valid font for the encodings
595 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
599 wxWindowMac::~wxWindowMac()
603 m_isBeingDeleted
= TRUE
;
605 #ifndef __WXUNIVERSAL__
606 // VS: make sure there's no wxFrame with last focus set to us:
607 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
609 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
612 if ( frame
->GetLastFocus() == this )
614 frame
->SetLastFocus((wxWindow
*)NULL
);
619 #endif // __WXUNIVERSAL__
621 // wxRemoveMacControlAssociation( this ) ;
622 // If we delete an item, we should initialize the parent panel,
623 // because it could now be invalid.
624 wxWindow
*parent
= GetParent() ;
627 if (parent
->GetDefaultItem() == (wxButton
*) this)
628 parent
->SetDefaultItem(NULL
);
630 if ( (ControlRef
) m_macControl
)
632 // in case the callback might be called during destruction
633 wxRemoveMacControlAssociation( this) ;
634 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
635 ::DisposeControl( (ControlRef
) m_macControl
) ;
636 m_macControl
= NULL
;
639 if ( g_MacLastWindow
== this )
641 g_MacLastWindow
= NULL
;
644 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
647 if ( frame
->GetLastFocus() == this )
648 frame
->SetLastFocus( NULL
) ;
653 // delete our drop target if we've got one
654 #if wxUSE_DRAG_AND_DROP
655 if ( m_dropTarget
!= NULL
)
660 #endif // wxUSE_DRAG_AND_DROP
665 void wxWindowMac::MacInstallEventHandler()
667 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
668 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
669 GetEventTypeCount(eventList
), eventList
, this,
670 (EventHandlerRef
*)&m_macControlEventHandler
);
675 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
679 const wxString
& name
)
681 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
683 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
686 parent
->AddChild(this);
688 m_windowVariant
= parent
->GetWindowVariant() ;
690 if ( m_macIsUserPane
)
692 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
695 | kControlSupportsEmbedding
696 // | kControlSupportsLiveFeedback
697 // | kControlHasSpecialBackground
698 // | kControlSupportsCalcBestRect
699 // | kControlHandlesTracking
700 | kControlSupportsFocus
701 // | kControlWantsActivate
702 // | kControlWantsIdle
705 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
707 MacPostControlCreate(pos
,size
) ;
708 #if !TARGET_API_MAC_OSX
709 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
710 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
711 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
712 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
713 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
714 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
715 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
716 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
717 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
718 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
719 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
720 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
721 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
722 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
723 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
724 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
727 #ifndef __WXUNIVERSAL__
728 // Don't give scrollbars to wxControls unless they ask for them
729 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
730 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
732 MacCreateScrollBars( style
) ;
736 wxWindowCreateEvent
event(this);
737 GetEventHandler()->AddPendingEvent(event
);
742 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
744 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
746 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
748 MacInstallEventHandler();
750 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
751 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
752 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
754 // adjust font, controlsize etc
755 DoSetWindowVariant( m_windowVariant
) ;
757 #if !TARGET_API_MAC_OSX
758 // eventually we can fix some clipping issues be reactivating this hook
759 //if ( m_macIsUserPane )
760 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
763 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
765 wxSize new_size
= size
;
766 if (!m_macIsUserPane
)
768 SetInitialBestSize(size
);
771 SetCursor( *wxSTANDARD_CURSOR
) ;
775 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
777 // Don't assert, in case we set the window variant before
778 // the window is created
779 // wxASSERT( m_macControl != NULL ) ;
781 m_windowVariant
= variant
;
787 ThemeFontID themeFont
= kThemeSystemFont
;
789 // we will get that from the settings later
790 // and make this NORMAL later, but first
791 // we have a few calculations that we must fix
795 case wxWINDOW_VARIANT_NORMAL
:
796 size
= kControlSizeNormal
;
797 themeFont
= kThemeSystemFont
;
799 case wxWINDOW_VARIANT_SMALL
:
800 size
= kControlSizeSmall
;
801 themeFont
= kThemeSmallSystemFont
;
803 case wxWINDOW_VARIANT_MINI
:
804 if (UMAGetSystemVersion() >= 0x1030 )
806 // not always defined in the headers
812 size
= kControlSizeSmall
;
813 themeFont
= kThemeSmallSystemFont
;
816 case wxWINDOW_VARIANT_LARGE
:
817 size
= kControlSizeLarge
;
818 themeFont
= kThemeSystemFont
;
821 wxFAIL_MSG(_T("unexpected window variant"));
824 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
827 font
.MacCreateThemeFont( themeFont
) ;
831 void wxWindowMac::MacUpdateControlFont()
833 ControlFontStyleRec fontStyle
;
834 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
836 switch( m_font
.MacGetThemeFontID() )
838 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
839 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
840 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
841 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
843 fontStyle
.flags
= kControlUseFontMask
;
847 fontStyle
.font
= m_font
.MacGetFontNum() ;
848 fontStyle
.style
= m_font
.MacGetFontStyle() ;
849 fontStyle
.size
= m_font
.MacGetFontSize() ;
850 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
853 fontStyle
.just
= teJustLeft
;
854 fontStyle
.flags
|= kControlUseJustMask
;
855 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
856 fontStyle
.just
= teJustCenter
;
857 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
858 fontStyle
.just
= teJustRight
;
861 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
862 fontStyle
.flags
|= kControlUseForeColorMask
;
864 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
868 bool wxWindowMac::SetFont(const wxFont
& font
)
870 bool retval
= !wxWindowBase::SetFont( font
) ;
872 MacUpdateControlFont() ;
877 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
879 if ( !wxWindowBase::SetForegroundColour(col
) )
882 MacUpdateControlFont() ;
887 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
889 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
893 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
895 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
897 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
899 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
903 brush
.SetColour( col
) ;
905 MacSetBackgroundBrush( brush
) ;
907 MacUpdateControlFont() ;
913 bool wxWindowMac::MacCanFocus() const
916 // there is currently no way to determinate whether the window is running in full keyboard
917 // access mode, therefore we cannot rely on these features yet
918 UInt32 features
= 0 ;
919 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
920 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
926 void wxWindowMac::SetFocus()
928 if ( AcceptsFocus() )
930 #if !TARGET_API_MAC_OSX
931 wxWindow
* former
= FindFocus() ;
933 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
934 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
935 // leave in case of an error
936 if ( err
== errCouldntSetFocus
)
939 #if !TARGET_API_MAC_OSX
940 // emulate carbon events when running under carbonlib where they are not natively available
943 EventRef evRef
= NULL
;
944 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
947 wxMacCarbonEvent
cEvent( evRef
) ;
948 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
949 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
951 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
952 ReleaseEvent(evRef
) ;
954 // send new focus event
956 EventRef evRef
= NULL
;
957 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
960 wxMacCarbonEvent
cEvent( evRef
) ;
961 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
962 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
964 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
965 ReleaseEvent(evRef
) ;
972 void wxWindowMac::DoCaptureMouse()
974 wxTheApp
->s_captureWindow
= this ;
977 wxWindow
* wxWindowBase::GetCapture()
979 return wxTheApp
->s_captureWindow
;
982 void wxWindowMac::DoReleaseMouse()
984 wxTheApp
->s_captureWindow
= NULL
;
987 #if wxUSE_DRAG_AND_DROP
989 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
991 if ( m_dropTarget
!= 0 ) {
995 m_dropTarget
= pDropTarget
;
996 if ( m_dropTarget
!= 0 )
1004 // Old style file-manager drag&drop
1005 void wxWindowMac::DragAcceptFiles(bool accept
)
1010 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1011 int& w
, int& h
) const
1014 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1019 w
= bounds
.right
- bounds
.left
;
1020 h
= bounds
.bottom
- bounds
.top
;
1022 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1025 Point tlworigin
= { 0 , 0 } ;
1027 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1028 ::LocalToGlobal( &tlworigin
) ;
1036 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1039 int& w
, int& h
, bool adjustOrigin
) const
1043 // todo the default calls may be used as soon as PostCreateControl Is moved here
1044 w
= size
.x
; // WidthDefault( size.x );
1045 h
= size
.y
; // HeightDefault( size.y ) ;
1046 #if !TARGET_API_MAC_OSX
1047 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1050 AdjustForParentClientOrigin( x
, y
) ;
1055 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1057 #if TARGET_API_MAC_OSX
1058 int x1
, y1
, w1
,h1
;
1059 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1065 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1066 if(x
) *x
= bounds
.right
- bounds
.left
;
1067 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1071 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1073 #if TARGET_API_MAC_OSX
1074 int x1
, y1
, w1
,h1
;
1075 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1076 if ( !IsTopLevel() )
1078 wxWindow
*parent
= GetParent();
1081 wxPoint
pt(parent
->GetClientAreaOrigin());
1090 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1091 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1093 int xx
= bounds
.left
;
1094 int yy
= bounds
.top
;
1096 if ( !GetParent()->IsTopLevel() )
1098 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1104 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1113 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1115 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1117 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1120 Point localwhere
= {0,0} ;
1122 if(x
) localwhere
.h
= * x
;
1123 if(y
) localwhere
.v
= * y
;
1125 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1126 ::GlobalToLocal( &localwhere
) ;
1127 if(x
) *x
= localwhere
.h
;
1128 if(y
) *y
= localwhere
.v
;
1131 MacRootWindowToWindow( x
, y
) ;
1133 wxPoint origin
= GetClientAreaOrigin() ;
1134 if(x
) *x
-= origin
.x
;
1135 if(y
) *y
-= origin
.y
;
1138 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1140 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1141 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1143 wxPoint origin
= GetClientAreaOrigin() ;
1144 if(x
) *x
+= origin
.x
;
1145 if(y
) *y
+= origin
.y
;
1147 MacWindowToRootWindow( x
, y
) ;
1150 Point localwhere
= { 0,0 };
1151 if(x
) localwhere
.h
= * x
;
1152 if(y
) localwhere
.v
= * y
;
1154 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1155 ::LocalToGlobal( &localwhere
) ;
1156 if(x
) *x
= localwhere
.h
;
1157 if(y
) *y
= localwhere
.v
;
1161 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1163 wxPoint origin
= GetClientAreaOrigin() ;
1164 if(x
) *x
+= origin
.x
;
1165 if(y
) *y
+= origin
.y
;
1167 MacWindowToRootWindow( x
, y
) ;
1170 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1172 MacRootWindowToWindow( x
, y
) ;
1174 wxPoint origin
= GetClientAreaOrigin() ;
1175 if(x
) *x
-= origin
.x
;
1176 if(y
) *y
-= origin
.y
;
1179 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1181 #if TARGET_API_MAC_OSX
1183 if ( x
) pt
.x
= *x
;
1184 if ( y
) pt
.y
= *y
;
1186 if ( !IsTopLevel() )
1187 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1189 if ( x
) *x
= (int) pt
.x
;
1190 if ( y
) *y
= (int) pt
.y
;
1192 if ( !IsTopLevel() )
1195 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1196 if(x
) *x
+= bounds
.left
;
1197 if(y
) *y
+= bounds
.top
;
1202 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1207 MacWindowToRootWindow( &x1
, &y1
) ;
1212 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1214 #if TARGET_API_MAC_OSX
1216 if ( x
) pt
.x
= *x
;
1217 if ( y
) pt
.y
= *y
;
1219 if ( !IsTopLevel() )
1220 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1222 if ( x
) *x
= (int) pt
.x
;
1223 if ( y
) *y
= (int) pt
.y
;
1225 if ( !IsTopLevel() )
1228 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1229 if(x
) *x
-= bounds
.left
;
1230 if(y
) *y
-= bounds
.top
;
1235 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1240 MacRootWindowToWindow( &x1
, &y1
) ;
1245 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1247 RgnHandle rgn
= NewRgn() ;
1249 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1251 GetRegionBounds( rgn
, &content
) ;
1256 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1259 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1260 #if !TARGET_API_MAC_OSX
1261 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1263 left
= content
.left
- structure
.left
;
1264 top
= content
.top
- structure
.top
;
1265 right
= structure
.right
- content
.right
;
1266 bottom
= structure
.bottom
- content
.bottom
;
1269 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1271 wxSize sizeTotal
= size
;
1273 RgnHandle rgn
= NewRgn() ;
1277 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1279 GetRegionBounds( rgn
, &content
) ;
1284 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1287 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1288 #if !TARGET_API_MAC_OSX
1289 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1292 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1293 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1295 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1296 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1302 // Get size *available for subwindows* i.e. excluding menu bar etc.
1303 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1307 RgnHandle rgn
= NewRgn() ;
1309 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1311 GetRegionBounds( rgn
, &content
) ;
1316 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1318 #if !TARGET_API_MAC_OSX
1320 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1321 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1323 ww
= content
.right
- content
.left
;
1324 hh
= content
.bottom
- content
.top
;
1326 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1327 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1329 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1335 GetSize( &w
, &h
) ;
1337 MacClientToRootWindow( &x1
, &y1
) ;
1338 MacClientToRootWindow( &w
, &h
) ;
1340 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1342 int totW
= 10000 , totH
= 10000;
1345 if ( iter
->IsTopLevel() )
1347 iter
->GetSize( &totW
, &totH
) ;
1351 iter
= iter
->GetParent() ;
1354 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1356 hh
-= MAC_SCROLLBAR_SIZE
;
1362 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1364 ww
-= MAC_SCROLLBAR_SIZE
;
1376 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1378 if (m_cursor
== cursor
)
1381 if (wxNullCursor
== cursor
)
1383 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1388 if ( ! wxWindowBase::SetCursor( cursor
) )
1392 wxASSERT_MSG( m_cursor
.Ok(),
1393 wxT("cursor must be valid after call to the base version"));
1397 TODO why do we have to use current coordinates ?
1400 wxWindowMac *mouseWin ;
1403 // Change the cursor NOW if we're within the correct window
1406 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1408 if ( mouseWin == this && !wxIsBusy() )
1410 m_cursor.MacInstall() ;
1416 m_cursor
.MacInstall() ;
1423 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1425 menu
->SetInvokingWindow(this);
1427 ClientToScreen( &x
, &y
) ;
1429 menu
->MacBeforeDisplay( true ) ;
1430 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1431 if ( HiWord(menuResult
) != 0 )
1434 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1435 wxMenuItem
* item
= NULL
;
1437 item
= menu
->FindItem(id
, &realmenu
) ;
1438 if (item
->IsCheckable())
1440 item
->Check( !item
->IsChecked() ) ;
1442 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1444 menu
->MacAfterDisplay( true ) ;
1446 menu
->SetInvokingWindow(NULL
);
1452 // ----------------------------------------------------------------------------
1454 // ----------------------------------------------------------------------------
1458 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1460 wxWindowBase::DoSetToolTip(tooltip
);
1463 m_tooltip
->SetWindow(this);
1466 #endif // wxUSE_TOOLTIPS
1468 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1470 int former_x
, former_y
, former_w
, former_h
;
1471 #if !TARGET_API_MAC_OSX
1472 DoGetPosition( &former_x
, &former_y
) ;
1473 DoGetSize( &former_w
, &former_h
) ;
1475 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1478 int actualWidth
= width
;
1479 int actualHeight
= height
;
1483 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1484 actualWidth
= m_minWidth
;
1485 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1486 actualHeight
= m_minHeight
;
1487 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1488 actualWidth
= m_maxWidth
;
1489 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1490 actualHeight
= m_maxHeight
;
1492 bool doMove
= false ;
1493 bool doResize
= false ;
1495 if ( actualX
!= former_x
|| actualY
!= former_y
)
1499 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1504 if ( doMove
|| doResize
)
1506 // we don't adjust twice for the origin
1507 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1508 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1509 #if TARGET_API_MAC_OSX
1510 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1512 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1513 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1514 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1516 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1519 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1520 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1522 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1524 MacRepositionScrollBars() ;
1527 wxPoint
point(actualX
,actualY
);
1528 wxMoveEvent
event(point
, m_windowId
);
1529 event
.SetEventObject(this);
1530 GetEventHandler()->ProcessEvent(event
) ;
1534 MacRepositionScrollBars() ;
1535 wxSize
size(actualWidth
, actualHeight
);
1536 wxSizeEvent
event(size
, m_windowId
);
1537 event
.SetEventObject(this);
1538 GetEventHandler()->ProcessEvent(event
);
1544 wxSize
wxWindowMac::DoGetBestSize() const
1546 if ( m_macIsUserPane
|| IsTopLevel() )
1547 return wxWindowBase::DoGetBestSize() ;
1549 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1550 short baselineoffset
;
1551 int bestWidth
, bestHeight
;
1552 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1554 if ( EmptyRect( &bestsize
) )
1557 bestsize
.left
= bestsize
.top
= 0 ;
1558 bestsize
.right
= 16 ;
1559 bestsize
.bottom
= 16 ;
1560 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1562 bestsize
.bottom
= 16 ;
1564 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1566 bestsize
.bottom
= 24 ;
1570 // return wxWindowBase::DoGetBestSize() ;
1574 bestWidth
= bestsize
.right
- bestsize
.left
;
1575 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1576 if ( bestHeight
< 10 )
1579 return wxSize(bestWidth
, bestHeight
);
1580 // return wxWindowBase::DoGetBestSize() ;
1584 // set the size of the window: if the dimensions are positive, just use them,
1585 // but if any of them is equal to -1, it means that we must find the value for
1586 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1587 // which case -1 is a valid value for x and y)
1589 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1590 // the width/height to best suit our contents, otherwise we reuse the current
1592 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1594 // get the current size and position...
1595 int currentX
, currentY
;
1596 GetPosition(¤tX
, ¤tY
);
1598 int currentW
,currentH
;
1599 GetSize(¤tW
, ¤tH
);
1601 // ... and don't do anything (avoiding flicker) if it's already ok
1602 if ( x
== currentX
&& y
== currentY
&&
1603 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1606 MacRepositionScrollBars() ; // we might have a real position shift
1610 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1612 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1615 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1617 wxSize
size(-1, -1);
1620 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1622 size
= DoGetBestSize();
1627 // just take the current one
1634 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1638 size
= DoGetBestSize();
1640 //else: already called DoGetBestSize() above
1646 // just take the current one
1651 DoMoveWindow(x
, y
, width
, height
);
1655 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1657 RgnHandle rgn
= NewRgn() ;
1659 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1660 GetRegionBounds( rgn
, &content
) ;
1662 #if !TARGET_API_MAC_OSX
1663 // if the content rgn is empty / not supported
1664 // don't attempt to correct the coordinates to wxWindow relative ones
1665 if (!::EmptyRect( &content
) )
1668 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1669 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1673 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1676 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1678 if ( clientheight
!= -1 || clientheight
!= -1 )
1680 int currentclientwidth
, currentclientheight
;
1681 int currentwidth
, currentheight
;
1683 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1684 GetSize( ¤twidth
, ¤theight
) ;
1686 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1687 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1691 void wxWindowMac::SetTitle(const wxString
& title
)
1693 m_label
= wxStripMenuCodes(title
) ;
1697 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1702 wxString
wxWindowMac::GetTitle() const
1707 bool wxWindowMac::Show(bool show
)
1709 if ( !wxWindowBase::Show(show
) )
1712 // TODO use visibilityChanged Carbon Event for OSX
1713 bool former
= MacIsReallyShown() ;
1715 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1716 if ( former
!= MacIsReallyShown() )
1717 MacPropagateVisibilityChanged() ;
1721 bool wxWindowMac::Enable(bool enable
)
1723 wxASSERT( m_macControl
!= NULL
) ;
1724 if ( !wxWindowBase::Enable(enable
) )
1727 bool former
= MacIsReallyEnabled() ;
1728 #if TARGET_API_MAC_OSX
1730 EnableControl( (ControlRef
) m_macControl
) ;
1732 DisableControl( (ControlRef
) m_macControl
) ;
1735 ActivateControl( (ControlRef
) m_macControl
) ;
1737 DeactivateControl( (ControlRef
) m_macControl
) ;
1740 if ( former
!= MacIsReallyEnabled() )
1741 MacPropagateEnabledStateChanged() ;
1746 // status change propagations (will be not necessary for OSX later )
1749 void wxWindowMac::MacPropagateVisibilityChanged()
1751 #if !TARGET_API_MAC_OSX
1752 MacVisibilityChanged() ;
1754 wxWindowListNode
*node
= GetChildren().GetFirst();
1757 wxWindowMac
*child
= node
->GetData();
1758 if ( child
->IsShown() )
1759 child
->MacPropagateVisibilityChanged( ) ;
1760 node
= node
->GetNext();
1765 void wxWindowMac::MacPropagateEnabledStateChanged( )
1767 #if !TARGET_API_MAC_OSX
1768 MacEnabledStateChanged() ;
1770 wxWindowListNode
*node
= GetChildren().GetFirst();
1773 wxWindowMac
*child
= node
->GetData();
1774 if ( child
->IsEnabled() )
1775 child
->MacPropagateEnabledStateChanged() ;
1776 node
= node
->GetNext();
1781 void wxWindowMac::MacPropagateHiliteChanged( )
1783 #if !TARGET_API_MAC_OSX
1784 MacHiliteChanged() ;
1786 wxWindowListNode
*node
= GetChildren().GetFirst();
1789 wxWindowMac
*child
= node
->GetData();
1790 // if ( child->IsEnabled() )
1791 child
->MacPropagateHiliteChanged() ;
1792 node
= node
->GetNext();
1798 // status change notifications
1801 void wxWindowMac::MacVisibilityChanged()
1805 void wxWindowMac::MacHiliteChanged()
1809 void wxWindowMac::MacEnabledStateChanged()
1814 // status queries on the inherited window's state
1817 bool wxWindowMac::MacIsReallyShown()
1819 // only under OSX the visibility of the TLW is taken into account
1820 #if TARGET_API_MAC_OSX
1821 return IsControlVisible( (ControlRef
) m_macControl
) ;
1823 wxWindow
* win
= this ;
1824 while( win
->IsShown() )
1826 if ( win
->IsTopLevel() )
1829 win
= win
->GetParent() ;
1838 bool wxWindowMac::MacIsReallyEnabled()
1840 #if TARGET_API_MAC_OSX
1841 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1843 return IsControlActive( (ControlRef
) m_macControl
) ;
1847 bool wxWindowMac::MacIsReallyHilited()
1849 return IsControlActive( (ControlRef
) m_macControl
) ;
1856 int wxWindowMac::GetCharHeight() const
1858 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1859 return dc
.GetCharHeight() ;
1862 int wxWindowMac::GetCharWidth() const
1864 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1865 return dc
.GetCharWidth() ;
1868 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1869 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1871 const wxFont
*fontToUse
= theFont
;
1873 fontToUse
= &m_font
;
1875 wxClientDC
dc( (wxWindowMac
*) this ) ;
1877 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1878 if ( externalLeading
)
1879 *externalLeading
= le
;
1889 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1890 * we always intersect with the entire window, not only with the client area
1893 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1895 #if TARGET_API_MAC_OSX
1897 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1900 RgnHandle update
= NewRgn() ;
1901 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1902 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1903 wxPoint origin
= GetClientAreaOrigin() ;
1904 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1905 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1909 RgnHandle updateRgn = NewRgn() ;
1912 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1916 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1917 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1919 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1920 DisposeRgn(updateRgn) ;
1922 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1924 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1925 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1928 if ( MacGetTopLevelWindow() == NULL )
1931 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1934 wxPoint client = GetClientAreaOrigin();
1937 int x2 = m_width - client.x;
1938 int y2 = m_height - client.y;
1940 if (IsKindOf( CLASSINFO(wxButton)))
1942 // buttons have an "aura"
1949 Rect clientrect = { y1, x1, y2, x2 };
1953 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1954 SectRect( &clientrect , &r , &clientrect ) ;
1957 if ( !EmptyRect( &clientrect ) )
1959 int top = 0 , left = 0 ;
1961 MacClientToRootWindow( &left , &top ) ;
1962 OffsetRect( &clientrect , left , top ) ;
1964 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1970 void wxWindowMac::Freeze()
1972 #if TARGET_API_MAC_OSX
1973 if ( !m_frozenness
++ )
1975 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1980 #if TARGET_API_MAC_OSX
1981 static void InvalidateControlAndChildren( HIViewRef control
)
1983 HIViewSetNeedsDisplay( control
, true ) ;
1984 UInt16 childrenCount
= 0 ;
1985 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1986 if ( err
== errControlIsNotEmbedder
)
1988 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1990 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1993 err
= GetIndexedSubControl( control
, i
, & child
) ;
1994 if ( err
== errControlIsNotEmbedder
)
1996 InvalidateControlAndChildren( child
) ;
2001 void wxWindowMac::Thaw()
2003 #if TARGET_API_MAC_OSX
2004 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2006 if ( !--m_frozenness
)
2008 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2009 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2010 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2015 void wxWindowMac::MacRedrawControl()
2018 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2020 #if TARGET_API_MAC_CARBON
2023 wxClientDC dc(this) ;
2024 wxMacPortSetter helper(&dc) ;
2025 wxMacWindowClipper clipper(this) ;
2026 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2027 UMADrawControl( (ControlRef) m_macControl ) ;
2034 void wxWindowMac::OnPaint(wxPaintEvent& event)
2036 // why don't we skip that here ?
2040 wxWindowMac
*wxGetActiveWindow()
2042 // actually this is a windows-only concept
2046 // Coordinates relative to the window
2047 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2049 // We really don't move the mouse programmatically under Mac.
2052 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2054 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2059 event
.GetDC()->Clear() ;
2062 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2064 wxWindowDC
dc(this) ;
2065 wxMacPortSetter
helper(&dc
) ;
2067 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2070 int wxWindowMac::GetScrollPos(int orient
) const
2072 if ( orient
== wxHORIZONTAL
)
2075 return m_hScrollBar
->GetThumbPosition() ;
2080 return m_vScrollBar
->GetThumbPosition() ;
2085 // This now returns the whole range, not just the number
2086 // of positions that we can scroll.
2087 int wxWindowMac::GetScrollRange(int orient
) const
2089 if ( orient
== wxHORIZONTAL
)
2092 return m_hScrollBar
->GetRange() ;
2097 return m_vScrollBar
->GetRange() ;
2102 int wxWindowMac::GetScrollThumb(int orient
) const
2104 if ( orient
== wxHORIZONTAL
)
2107 return m_hScrollBar
->GetThumbSize() ;
2112 return m_vScrollBar
->GetThumbSize() ;
2117 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2119 if ( orient
== wxHORIZONTAL
)
2122 m_hScrollBar
->SetThumbPosition( pos
) ;
2127 m_vScrollBar
->SetThumbPosition( pos
) ;
2131 void wxWindowMac::MacPaintBorders( int left
, int top
)
2137 wxGetOsVersion( &major
, &minor
);
2139 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2140 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2142 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2143 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2144 // OS X has lighter border edges than classic:
2147 darkShadow
.red
= 0x8E8E;
2148 darkShadow
.green
= 0x8E8E;
2149 darkShadow
.blue
= 0x8E8E;
2150 lightShadow
.red
= 0xBDBD;
2151 lightShadow
.green
= 0xBDBD;
2152 lightShadow
.blue
= 0xBDBD;
2158 GetSize( &w
, &h
) ;
2159 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2161 #if wxMAC_USE_THEME_BORDER
2162 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2165 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2166 InsetRect( &rect , border , border );
2167 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2170 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2172 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2173 RGBForeColor( &face
);
2174 MoveTo( left
+ 0 , top
+ h
- 2 );
2175 LineTo( left
+ 0 , top
+ 0 );
2176 LineTo( left
+ w
- 2 , top
+ 0 );
2178 MoveTo( left
+ 2 , top
+ h
- 3 );
2179 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2180 LineTo( left
+ w
- 3 , top
+ 2 );
2182 RGBForeColor( sunken
? &face
: &darkShadow
);
2183 MoveTo( left
+ 0 , top
+ h
- 1 );
2184 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2185 LineTo( left
+ w
- 1 , top
+ 0 );
2187 RGBForeColor( sunken
? &lightShadow
: &white
);
2188 MoveTo( left
+ 1 , top
+ h
- 3 );
2189 LineTo( left
+ 1, top
+ 1 );
2190 LineTo( left
+ w
- 3 , top
+ 1 );
2192 RGBForeColor( sunken
? &white
: &lightShadow
);
2193 MoveTo( left
+ 1 , top
+ h
- 2 );
2194 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2195 LineTo( left
+ w
- 2 , top
+ 1 );
2197 RGBForeColor( sunken
? &darkShadow
: &face
);
2198 MoveTo( left
+ 2 , top
+ h
- 4 );
2199 LineTo( left
+ 2 , top
+ 2 );
2200 LineTo( left
+ w
- 4 , top
+ 2 );
2203 else if (HasFlag(wxSIMPLE_BORDER
))
2205 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2206 RGBForeColor( &darkShadow
) ;
2207 FrameRect( &rect
) ;
2211 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2213 if ( child
== m_hScrollBar
)
2214 m_hScrollBar
= NULL
;
2215 if ( child
== m_vScrollBar
)
2216 m_vScrollBar
= NULL
;
2218 wxWindowBase::RemoveChild( child
) ;
2221 // New function that will replace some of the above.
2222 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2223 int range
, bool refresh
)
2225 if ( orient
== wxHORIZONTAL
)
2229 if ( range
== 0 || thumbVisible
>= range
)
2231 if ( m_hScrollBar
->IsShown() )
2232 m_hScrollBar
->Show(false) ;
2236 if ( !m_hScrollBar
->IsShown() )
2237 m_hScrollBar
->Show(true) ;
2238 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2246 if ( range
== 0 || thumbVisible
>= range
)
2248 if ( m_vScrollBar
->IsShown() )
2249 m_vScrollBar
->Show(false) ;
2253 if ( !m_vScrollBar
->IsShown() )
2254 m_vScrollBar
->Show(true) ;
2255 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2259 MacRepositionScrollBars() ;
2262 // Does a physical scroll
2263 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2265 if( dx
== 0 && dy
==0 )
2270 wxClientDC
dc(this) ;
2271 wxMacPortSetter
helper(&dc
) ;
2273 int width
, height
;
2274 GetClientSize( &width
, &height
) ;
2281 // TODO take out the boundaries
2282 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2284 RgnHandle updateRgn
= NewRgn() ;
2287 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2288 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2289 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2291 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2293 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2294 // but it seems the update only refreshes the background of the control, rather than calling
2295 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2296 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2299 // we also have to scroll the update rgn in this rectangle
2300 // in order not to loose updates
2302 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2303 RgnHandle formerUpdateRgn
= NewRgn() ;
2304 RgnHandle scrollRgn
= NewRgn() ;
2305 RectRgn( scrollRgn
, &scrollrect
) ;
2306 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2308 LocalToGlobal( &pt
) ;
2309 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2310 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2311 if ( !EmptyRgn( formerUpdateRgn
) )
2313 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2314 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2315 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2317 InvalWindowRgn(rootWindow
, updateRgn
) ;
2318 DisposeRgn( updateRgn
) ;
2319 DisposeRgn( formerUpdateRgn
) ;
2320 DisposeRgn( scrollRgn
) ;
2324 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2326 wxWindowMac
*child
= node
->GetData();
2327 if (child
== m_vScrollBar
) continue;
2328 if (child
== m_hScrollBar
) continue;
2329 if (child
->IsTopLevel()) continue;
2332 child
->GetPosition( &x
, &y
);
2334 child
->GetSize( &w
, &h
);
2338 if (rect
->Intersects(rc
))
2339 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2343 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2347 // TODO remove, was moved higher up Update() ;
2351 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2353 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2355 wxScrollWinEvent wevent
;
2356 wevent
.SetPosition(event
.GetPosition());
2357 wevent
.SetOrientation(event
.GetOrientation());
2358 wevent
.m_eventObject
= this;
2360 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2361 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2362 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2363 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2364 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2365 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2366 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2367 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2368 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2369 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2370 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2371 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2372 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2373 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2374 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2375 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2377 GetEventHandler()->ProcessEvent(wevent
);
2381 // Get the window with the focus
2382 wxWindowMac
*wxWindowBase::FindFocus()
2384 ControlRef control
;
2385 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2386 return wxFindControlFromMacControl( control
) ;
2389 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2391 // panel wants to track the window which was the last to have focus in it,
2392 // so we want to set ourselves as the window which last had focus
2394 // notice that it's also important to do it upwards the tree becaus
2395 // otherwise when the top level panel gets focus, it won't set it back to
2396 // us, but to some other sibling
2398 // CS:don't know if this is still needed:
2399 //wxChildFocusEvent eventFocus(this);
2400 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2405 void wxWindowMac::OnInternalIdle()
2407 // This calls the UI-update mechanism (querying windows for
2408 // menu/toolbar/control state information)
2409 if (wxUpdateUIEvent::CanUpdate(this))
2410 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2413 // Raise the window to the top of the Z order
2414 void wxWindowMac::Raise()
2416 #if TARGET_API_MAC_OSX
2417 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2421 // Lower the window to the bottom of the Z order
2422 void wxWindowMac::Lower()
2424 #if TARGET_API_MAC_OSX
2425 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2430 // static wxWindow *gs_lastWhich = NULL;
2432 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2434 // first trigger a set cursor event
2436 wxPoint clientorigin
= GetClientAreaOrigin() ;
2437 wxSize clientsize
= GetClientSize() ;
2439 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2441 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2443 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2444 if ( processedEvtSetCursor
&& event
.HasCursor() )
2446 cursor
= event
.GetCursor() ;
2451 // the test for processedEvtSetCursor is here to prevent using m_cursor
2452 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2453 // it - this is a way to say that our cursor shouldn't be used for this
2455 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2465 cursor
= *wxSTANDARD_CURSOR
;
2469 cursor
.MacInstall() ;
2471 return cursor
.Ok() ;
2474 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2478 return m_tooltip
->GetTip() ;
2480 return wxEmptyString
;
2483 void wxWindowMac::Update()
2485 #if TARGET_API_MAC_OSX
2486 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2488 ::Draw1Control( (ControlRef
) m_macControl
) ;
2492 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2494 wxTopLevelWindowMac
* win
= NULL
;
2495 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2498 win
= wxFindWinFromMacWindow( window
) ;
2502 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2506 RgnHandle visRgn
= NewRgn() ;
2507 RgnHandle tempRgn
= NewRgn() ;
2508 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2510 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2511 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2513 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2514 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2523 if ( includeOuterStructures
)
2524 InsetRect( &r
, -3 , -3 ) ;
2525 RectRgn( visRgn
, &r
) ;
2526 if ( !IsTopLevel() )
2528 wxWindow
* child
= this ;
2529 wxWindow
* parent
= child
->GetParent() ;
2534 // we have to find a better clipping algorithm here, in order not to clip things
2535 // positioned like status and toolbar
2536 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2538 size
= parent
->GetSize() ;
2543 size
= parent
->GetClientSize() ;
2544 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2548 parent
->MacWindowToRootWindow( &x
, &y
) ;
2549 MacRootWindowToWindow( &x
, &y
) ;
2551 SetRectRgn( tempRgn
,
2552 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2553 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2554 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2556 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2557 if ( parent
->IsTopLevel() )
2560 parent
= child
->GetParent() ;
2565 wxRegion vis
= visRgn
;
2566 DisposeRgn( visRgn
) ;
2567 DisposeRgn( tempRgn
) ;
2572 This function must not change the updatergn !
2574 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2576 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2577 bool handled
= false ;
2579 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2581 RgnHandle newupdate
= NewRgn() ;
2582 wxSize point
= GetClientSize() ;
2583 wxPoint origin
= GetClientAreaOrigin() ;
2584 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2585 SectRgn( newupdate
, updatergn
, newupdate
) ;
2586 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2587 m_updateRegion
= newupdate
;
2588 DisposeRgn( newupdate
) ;
2591 if ( !EmptyRgn(updatergn
) )
2593 wxWindowDC
dc(this);
2594 if (!EmptyRgn(updatergn
))
2595 dc
.SetClippingRegion(wxRegion(updatergn
));
2597 wxEraseEvent
eevent( GetId(), &dc
);
2598 eevent
.SetEventObject( this );
2599 GetEventHandler()->ProcessEvent( eevent
);
2601 if ( !m_updateRegion
.Empty() )
2603 // paint the window itself
2605 event
.m_timeStamp
= time
;
2606 event
.SetEventObject(this);
2607 handled
= GetEventHandler()->ProcessEvent(event
);
2609 // paint custom borders
2610 wxNcPaintEvent
eventNc( GetId() );
2611 eventNc
.SetEventObject( this );
2612 GetEventHandler()->ProcessEvent( eventNc
);
2618 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2620 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2621 // updatergn is always already clipped to our boundaries
2622 // if we are in compositing mode then it is in relative to the upper left of the control
2623 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2624 // of the toplevel window
2625 // it is in window coordinates, not in client coordinates
2627 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2628 RgnHandle ownUpdateRgn
= NewRgn() ;
2629 CopyRgn( updatergn
, ownUpdateRgn
) ;
2631 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2634 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2635 RgnHandle controlRgn
= NewRgn();
2636 RectRgn( controlRgn
, &bounds
);
2637 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2638 // the window update region
2639 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2640 DisposeRgn( controlRgn
);
2642 //KO: convert ownUpdateRgn to local coordinates
2643 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2646 MacDoRedraw( ownUpdateRgn
, time
) ;
2647 DisposeRgn( ownUpdateRgn
) ;
2651 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2653 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2657 if ( iter
->IsTopLevel() )
2658 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2660 iter
= iter
->GetParent() ;
2662 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2666 void wxWindowMac::MacCreateScrollBars( long style
)
2668 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2670 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2671 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2673 GetClientSize( &width
, &height
) ;
2675 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2676 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2677 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2678 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2680 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2681 vSize
, wxVERTICAL
);
2683 if ( style
& wxVSCROLL
)
2689 m_vScrollBar
->Show(false) ;
2691 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2692 hSize
, wxHORIZONTAL
);
2693 if ( style
& wxHSCROLL
)
2698 m_hScrollBar
->Show(false) ;
2701 // because the create does not take into account the client area origin
2702 MacRepositionScrollBars() ; // we might have a real position shift
2705 void wxWindowMac::MacRepositionScrollBars()
2707 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2708 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2710 // get real client area
2714 GetSize( &width
, &height
) ;
2716 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2717 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2719 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2720 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2721 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2722 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2728 GetSize( &w
, &h
) ;
2730 MacClientToRootWindow( &x
, &y
) ;
2731 MacClientToRootWindow( &w
, &h
) ;
2733 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2735 int totW
= 10000 , totH
= 10000;
2738 if ( iter
->IsTopLevel() )
2740 iter
->GetSize( &totW
, &totH
) ;
2744 iter
= iter
->GetParent() ;
2772 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2776 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2780 bool wxWindowMac::AcceptsFocus() const
2782 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2785 void wxWindowMac::MacSuperChangedPosition()
2787 // only window-absolute structures have to be moved i.e. controls
2789 wxWindowListNode
*node
= GetChildren().GetFirst();
2792 wxWindowMac
*child
= node
->GetData();
2793 child
->MacSuperChangedPosition() ;
2794 node
= node
->GetNext();
2798 void wxWindowMac::MacTopLevelWindowChangedPosition()
2800 // only screen-absolute structures have to be moved i.e. glcanvas
2802 wxWindowListNode
*node
= GetChildren().GetFirst();
2805 wxWindowMac
*child
= node
->GetData();
2806 child
->MacTopLevelWindowChangedPosition() ;
2807 node
= node
->GetNext();
2811 long wxWindowMac::MacGetLeftBorderSize( ) const
2816 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2819 #if wxMAC_USE_THEME_BORDER
2820 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2824 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2827 #if wxMAC_USE_THEME_BORDER
2828 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2832 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2839 long wxWindowMac::MacGetRightBorderSize( ) const
2841 // they are all symmetric in mac themes
2842 return MacGetLeftBorderSize() ;
2845 long wxWindowMac::MacGetTopBorderSize( ) const
2847 // they are all symmetric in mac themes
2848 return MacGetLeftBorderSize() ;
2851 long wxWindowMac::MacGetBottomBorderSize( ) const
2853 // they are all symmetric in mac themes
2854 return MacGetLeftBorderSize() ;
2857 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2859 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2862 // Find the wxWindowMac at the current mouse position, returning the mouse
2864 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2866 pt
= wxGetMousePosition();
2867 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2871 // Get the current mouse position.
2872 wxPoint
wxGetMousePosition()
2875 wxGetMousePosition(& x
, & y
);
2876 return wxPoint(x
, y
);
2879 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2881 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2883 // copied from wxGTK : CS
2884 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2887 // (a) it's a command event and so is propagated to the parent
2888 // (b) under MSW it can be generated from kbd too
2889 // (c) it uses screen coords (because of (a))
2890 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2892 this->ClientToScreen(event
.GetPosition()));
2893 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2902 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2906 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2910 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2911 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2915 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2917 return eventNotHandledErr
;