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"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
49 #define MAC_SCROLLBAR_SIZE 16
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 // TODO EVT_PAINT(wxWindowMac::OnPaint)
85 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
86 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
87 // EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
88 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
93 #define wxMAC_DEBUG_REDRAW 0
94 #ifndef wxMAC_DEBUG_REDRAW
95 #define wxMAC_DEBUG_REDRAW 0
98 #define wxMAC_USE_THEME_BORDER 0
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
105 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
107 #if TARGET_API_MAC_OSX
109 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
111 kEventControlVisibilityChanged
= 157
117 static const EventTypeSpec eventList
[] =
119 { kEventClassControl
, kEventControlHit
} ,
120 #if TARGET_API_MAC_OSX
121 { kEventClassControl
, kEventControlDraw
} ,
122 { kEventClassControl
, kEventControlVisibilityChanged
} ,
123 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
124 { kEventClassControl
, kEventControlHiliteChanged
} ,
125 { kEventClassControl
, kEventControlSetFocusPart
} ,
127 { kEventClassService
, kEventServiceGetTypes
},
128 { kEventClassService
, kEventServiceCopy
},
129 { kEventClassService
, kEventServicePaste
},
131 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
132 // { kEventClassControl , kEventControlBoundsChanged } ,
136 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
138 OSStatus result
= eventNotHandledErr
;
140 wxMacCarbonEvent
cEvent( event
) ;
142 ControlRef controlRef
;
143 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
145 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
147 switch( GetEventKind( event
) )
149 #if TARGET_API_MAC_OSX
150 case kEventControlDraw
:
152 RgnHandle updateRgn
= NULL
;
154 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
155 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
157 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
159 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
162 // in case we would need a coregraphics compliant background erase first
163 // now usable to track redraws
164 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
165 if ( thisWindow
->MacIsUserPane() )
167 static float color
= 0.5 ;
170 HIViewGetBounds( controlRef
, &bounds
);
171 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
172 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
173 CGContextFillRect( cgContext
, bounds
);
184 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
188 case kEventControlVisibilityChanged
:
189 thisWindow
->MacVisibilityChanged() ;
191 case kEventControlEnabledStateChanged
:
192 thisWindow
->MacEnabledStateChanged() ;
194 case kEventControlHiliteChanged
:
195 thisWindow
->MacHiliteChanged() ;
197 case kEventControlSetFocusPart
:
199 Boolean focusEverything
= false ;
200 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
201 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
204 if ( controlPart
== kControlFocusNoPart
)
207 if ( thisWindow
->GetCaret() )
209 thisWindow
->GetCaret()->OnKillFocus();
211 #endif // wxUSE_CARET
212 wxFocusEvent
event(wxEVT_KILL_FOCUS
, thisWindow
->GetId());
213 event
.SetEventObject(thisWindow
);
214 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
218 // panel wants to track the window which was the last to have focus in it
219 wxChildFocusEvent
eventFocus(thisWindow
);
220 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
223 if ( thisWindow
->GetCaret() )
225 thisWindow
->GetCaret()->OnSetFocus();
227 #endif // wxUSE_CARET
229 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
230 event
.SetEventObject(thisWindow
);
231 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
233 if ( thisWindow
->MacIsUserPane() )
238 case kEventControlHit
:
240 result
= thisWindow
->MacControlHit( handler
, event
) ;
249 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
251 OSStatus result
= eventNotHandledErr
;
253 wxMacCarbonEvent
cEvent( event
) ;
255 ControlRef controlRef
;
256 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
257 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
258 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
260 switch( GetEventKind( event
) )
262 case kEventServiceGetTypes
:
266 textCtrl
->GetSelection( &from
, &to
) ;
268 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
270 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
271 if ( textCtrl
->IsEditable() )
272 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
274 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
275 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
277 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
281 CFArrayAppendValue (copyTypes
, typestring
) ;
283 CFArrayAppendValue (pasteTypes
, typestring
) ;
284 CFRelease( typestring
) ;
290 case kEventServiceCopy
:
294 textCtrl
->GetSelection( &from
, &to
) ;
295 wxString val
= textCtrl
->GetValue() ;
296 val
= val
.Mid( from
, to
- from
) ;
297 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
298 verify_noerr( ClearScrap( &scrapRef
) ) ;
299 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
303 case kEventServicePaste
:
306 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
307 Size textSize
, pastedSize
;
308 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
310 char *content
= new char[textSize
] ;
311 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
312 content
[textSize
-1] = 0 ;
314 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
316 textCtrl
->WriteText( wxString( content
) ) ;
327 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
329 OSStatus result
= eventNotHandledErr
;
331 switch ( GetEventClass( event
) )
333 case kEventClassControl
:
334 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
336 case kEventClassService
:
337 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
344 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
346 // ---------------------------------------------------------------------------
347 // UserPane events for non OSX builds
348 // ---------------------------------------------------------------------------
350 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
352 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
353 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
354 win
->MacControlUserPaneDrawProc(part
) ;
357 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
359 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
360 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
361 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
364 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
366 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
367 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
368 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
371 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
373 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
374 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
375 win
->MacControlUserPaneIdleProc() ;
378 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
380 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
381 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
382 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
385 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
387 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
388 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
389 win
->MacControlUserPaneActivateProc(activating
) ;
392 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
394 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
395 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
396 return win
->MacControlUserPaneFocusProc(action
) ;
399 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
401 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
402 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
403 win
->MacControlUserPaneBackgroundProc(info
) ;
406 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
408 RgnHandle rgn
= NewRgn() ;
410 wxMacWindowStateSaver
sv( this ) ;
411 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
412 MacDoRedraw( rgn
, 0 ) ;
416 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
418 return kControlNoPart
;
421 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
423 return kControlNoPart
;
426 void wxWindowMac::MacControlUserPaneIdleProc()
430 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
432 return kControlNoPart
;
435 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
439 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
441 return kControlNoPart
;
444 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
448 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
449 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
450 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
451 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
452 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
453 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
454 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
455 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
457 // ===========================================================================
459 // ===========================================================================
461 wxList
wxWinMacControlList(wxKEY_INTEGER
);
463 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
465 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
468 return (wxControl
*)node
->GetData();
471 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
473 // adding NULL ControlRef is (first) surely a result of an error and
474 // (secondly) breaks native event processing
475 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
477 if ( !wxWinMacControlList
.Find((long)inControl
) )
478 wxWinMacControlList
.Append((long)inControl
, control
);
481 void wxRemoveMacControlAssociation(wxWindow
*control
)
483 wxWinMacControlList
.DeleteObject(control
);
487 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
489 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
491 // we have to setup the brush in the current port and return noErr
492 // or return an error code so that the control manager walks further up the
493 // hierarchy to find a correct background
495 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
497 OSStatus status
= paramErr
;
500 case kControlMsgApplyTextColor
:
502 case kControlMsgSetUpBackground
:
504 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
508 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
512 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
514 // this clipping is only needed for non HIView
516 RgnHandle clip
= NewRgn() ;
519 wx
->MacWindowToRootWindow( &x
,&y
) ;
520 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
521 OffsetRgn( clip
, x
, y
) ;
528 else if ( wx->MacIsUserPane() )
530 // if we don't have a valid brush for such a control, we have to call the
531 // setup of our parent ourselves
532 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
545 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
546 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
550 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
553 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
558 // ----------------------------------------------------------------------------
559 // constructors and such
560 // ----------------------------------------------------------------------------
562 wxWindowMac::wxWindowMac()
567 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
572 const wxString
& name
)
575 Create(parent
, id
, pos
, size
, style
, name
);
578 void wxWindowMac::Init()
582 #if WXWIN_COMPATIBILITY_2_4
583 m_backgroundTransparent
= FALSE
;
586 // as all windows are created with WS_VISIBLE style...
589 m_hScrollBar
= NULL
;
590 m_vScrollBar
= NULL
;
591 m_macBackgroundBrush
= wxNullBrush
;
593 m_macIsUserPane
= TRUE
;
595 // make sure all proc ptrs are available
597 if ( gControlUserPaneDrawUPP
== NULL
)
599 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
600 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
601 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
602 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
603 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
604 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
605 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
606 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
608 if ( wxMacLiveScrollbarActionUPP
== NULL
)
610 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
613 if ( wxMacSetupControlBackgroundUPP
== NULL
)
615 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
618 // we need a valid font for the encodings
619 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
623 wxWindowMac::~wxWindowMac()
627 m_isBeingDeleted
= TRUE
;
629 #ifndef __WXUNIVERSAL__
630 // VS: make sure there's no wxFrame with last focus set to us:
631 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
633 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
636 if ( frame
->GetLastFocus() == this )
638 frame
->SetLastFocus((wxWindow
*)NULL
);
643 #endif // __WXUNIVERSAL__
645 // wxRemoveMacControlAssociation( this ) ;
646 // If we delete an item, we should initialize the parent panel,
647 // because it could now be invalid.
648 wxWindow
*parent
= GetParent() ;
651 if (parent
->GetDefaultItem() == (wxButton
*) this)
652 parent
->SetDefaultItem(NULL
);
654 if ( m_peer
&& m_peer
->Ok() )
656 // in case the callback might be called during destruction
657 wxRemoveMacControlAssociation( this) ;
658 ::SetControlColorProc( *m_peer
, NULL
) ;
659 ::DisposeControl( *m_peer
) ;
662 if ( g_MacLastWindow
== this )
664 g_MacLastWindow
= NULL
;
667 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
670 if ( frame
->GetLastFocus() == this )
671 frame
->SetLastFocus( NULL
) ;
676 // delete our drop target if we've got one
677 #if wxUSE_DRAG_AND_DROP
678 if ( m_dropTarget
!= NULL
)
683 #endif // wxUSE_DRAG_AND_DROP
687 WXWidget
wxWindowMac::GetHandle() const
689 return (WXWidget
) (ControlRef
) *m_peer
;
693 void wxWindowMac::MacInstallEventHandler()
695 wxAssociateControlWithMacControl( *m_peer
, this ) ;
696 InstallControlEventHandler( *m_peer
, GetwxMacWindowEventHandlerUPP(),
697 GetEventTypeCount(eventList
), eventList
, this,
698 (EventHandlerRef
*)&m_macControlEventHandler
);
703 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
707 const wxString
& name
)
709 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
711 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
714 parent
->AddChild(this);
716 m_windowVariant
= parent
->GetWindowVariant() ;
718 if ( m_macIsUserPane
)
720 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
723 | kControlSupportsEmbedding
724 // | kControlSupportsLiveFeedback
725 // | kControlHasSpecialBackground
726 // | kControlSupportsCalcBestRect
727 // | kControlHandlesTracking
728 | kControlSupportsFocus
729 // | kControlWantsActivate
730 // | kControlWantsIdle
733 m_peer
= new wxMacControl() ;
734 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, *m_peer
);
737 MacPostControlCreate(pos
,size
) ;
738 #if !TARGET_API_MAC_OSX
739 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
740 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
741 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
742 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
743 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
744 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
745 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
746 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
747 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
748 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
749 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
750 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
751 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
752 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
753 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
754 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
757 #ifndef __WXUNIVERSAL__
758 // Don't give scrollbars to wxControls unless they ask for them
759 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
760 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
762 MacCreateScrollBars( style
) ;
766 wxWindowCreateEvent
event(this);
767 GetEventHandler()->AddPendingEvent(event
);
772 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
774 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
776 ::SetControlReference( *m_peer
, (long) this ) ;
778 MacInstallEventHandler();
780 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
781 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
782 ::EmbedControl( *m_peer
, container
) ;
784 // adjust font, controlsize etc
785 DoSetWindowVariant( m_windowVariant
) ;
787 #if !TARGET_API_MAC_OSX
788 // eventually we can fix some clipping issues be reactivating this hook
789 //if ( m_macIsUserPane )
790 // SetControlColorProc( *m_peer , wxMacSetupControlBackgroundUPP ) ;
793 UMASetControlTitle( *m_peer
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
795 if (!m_macIsUserPane
)
797 SetInitialBestSize(size
);
800 SetCursor( *wxSTANDARD_CURSOR
) ;
803 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
805 // Don't assert, in case we set the window variant before
806 // the window is created
807 // wxASSERT( m_peer->Ok() ) ;
809 m_windowVariant
= variant
;
811 if (m_peer
== NULL
|| !m_peer
->Ok())
815 ThemeFontID themeFont
= kThemeSystemFont
;
817 // we will get that from the settings later
818 // and make this NORMAL later, but first
819 // we have a few calculations that we must fix
823 case wxWINDOW_VARIANT_NORMAL
:
824 size
= kControlSizeNormal
;
825 themeFont
= kThemeSystemFont
;
827 case wxWINDOW_VARIANT_SMALL
:
828 size
= kControlSizeSmall
;
829 themeFont
= kThemeSmallSystemFont
;
831 case wxWINDOW_VARIANT_MINI
:
832 if (UMAGetSystemVersion() >= 0x1030 )
834 // not always defined in the headers
840 size
= kControlSizeSmall
;
841 themeFont
= kThemeSmallSystemFont
;
844 case wxWINDOW_VARIANT_LARGE
:
845 size
= kControlSizeLarge
;
846 themeFont
= kThemeSystemFont
;
849 wxFAIL_MSG(_T("unexpected window variant"));
852 ::SetControlData( *m_peer
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
855 font
.MacCreateThemeFont( themeFont
) ;
859 void wxWindowMac::MacUpdateControlFont()
861 ControlFontStyleRec fontStyle
;
862 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
864 switch( m_font
.MacGetThemeFontID() )
866 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
867 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
868 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
869 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
871 fontStyle
.flags
= kControlUseFontMask
;
875 fontStyle
.font
= m_font
.MacGetFontNum() ;
876 fontStyle
.style
= m_font
.MacGetFontStyle() ;
877 fontStyle
.size
= m_font
.MacGetFontSize() ;
878 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
881 fontStyle
.just
= teJustLeft
;
882 fontStyle
.flags
|= kControlUseJustMask
;
883 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
884 fontStyle
.just
= teJustCenter
;
885 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
886 fontStyle
.just
= teJustRight
;
889 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
890 fontStyle
.flags
|= kControlUseForeColorMask
;
892 ::SetControlFontStyle( *m_peer
, &fontStyle
);
896 bool wxWindowMac::SetFont(const wxFont
& font
)
898 bool retval
= !wxWindowBase::SetFont( font
) ;
900 MacUpdateControlFont() ;
905 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
907 if ( !wxWindowBase::SetForegroundColour(col
) )
910 MacUpdateControlFont() ;
915 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
917 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
921 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
923 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
925 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
927 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
931 brush
.SetColour( col
) ;
933 MacSetBackgroundBrush( brush
) ;
935 MacUpdateControlFont() ;
941 bool wxWindowMac::MacCanFocus() const
943 // there is currently no way to determine whether the window is running in full keyboard
944 // access mode, therefore we cannot rely on these features, yet the only other way would be
945 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
946 // in event handlers...
947 UInt32 features
= 0 ;
948 GetControlFeatures( *m_peer
, &features
) ;
949 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
953 void wxWindowMac::SetFocus()
955 if ( AcceptsFocus() )
957 #if !TARGET_API_MAC_OSX
958 wxWindow
* former
= FindFocus() ;
960 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
961 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
962 // leave in case of an error
963 if ( err
== errCouldntSetFocus
)
966 #if !TARGET_API_MAC_OSX
967 // emulate carbon events when running under carbonlib where they are not natively available
970 EventRef evRef
= NULL
;
971 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
974 wxMacCarbonEvent
cEvent( evRef
) ;
975 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
976 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
978 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
979 ReleaseEvent(evRef
) ;
981 // send new focus event
983 EventRef evRef
= NULL
;
984 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
987 wxMacCarbonEvent
cEvent( evRef
) ;
988 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
989 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
991 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
992 ReleaseEvent(evRef
) ;
999 void wxWindowMac::DoCaptureMouse()
1001 wxTheApp
->s_captureWindow
= this ;
1004 wxWindow
* wxWindowBase::GetCapture()
1006 return wxTheApp
->s_captureWindow
;
1009 void wxWindowMac::DoReleaseMouse()
1011 wxTheApp
->s_captureWindow
= NULL
;
1014 #if wxUSE_DRAG_AND_DROP
1016 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1018 if ( m_dropTarget
!= 0 ) {
1019 delete m_dropTarget
;
1022 m_dropTarget
= pDropTarget
;
1023 if ( m_dropTarget
!= 0 )
1031 // Old style file-manager drag&drop
1032 void wxWindowMac::DragAcceptFiles(bool accept
)
1037 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1038 int& w
, int& h
) const
1041 GetControlBounds( *m_peer
, &bounds
) ;
1046 w
= bounds
.right
- bounds
.left
;
1047 h
= bounds
.bottom
- bounds
.top
;
1049 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1052 Point tlworigin
= { 0 , 0 } ;
1053 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1059 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1062 int& w
, int& h
, bool adjustOrigin
) const
1066 // todo the default calls may be used as soon as PostCreateControl Is moved here
1067 w
= size
.x
; // WidthDefault( size.x );
1068 h
= size
.y
; // HeightDefault( size.y ) ;
1069 #if !TARGET_API_MAC_OSX
1070 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1073 AdjustForParentClientOrigin( x
, y
) ;
1078 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1080 #if TARGET_API_MAC_OSX
1081 int x1
, y1
, w1
,h1
;
1082 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1088 GetControlBounds( *m_peer
, &bounds
) ;
1089 if(x
) *x
= bounds
.right
- bounds
.left
;
1090 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1094 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1096 #if TARGET_API_MAC_OSX
1097 int x1
, y1
, w1
,h1
;
1098 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1099 if ( !IsTopLevel() )
1101 wxWindow
*parent
= GetParent();
1104 wxPoint
pt(parent
->GetClientAreaOrigin());
1113 GetControlBounds( *m_peer
, &bounds
) ;
1114 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1116 int xx
= bounds
.left
;
1117 int yy
= bounds
.top
;
1119 if ( !GetParent()->IsTopLevel() )
1121 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1127 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1136 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1138 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1140 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1143 Point localwhere
= {0,0} ;
1145 if(x
) localwhere
.h
= * x
;
1146 if(y
) localwhere
.v
= * y
;
1148 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1149 if(x
) *x
= localwhere
.h
;
1150 if(y
) *y
= localwhere
.v
;
1153 MacRootWindowToWindow( x
, y
) ;
1155 wxPoint origin
= GetClientAreaOrigin() ;
1156 if(x
) *x
-= origin
.x
;
1157 if(y
) *y
-= origin
.y
;
1160 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1162 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1163 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1165 wxPoint origin
= GetClientAreaOrigin() ;
1166 if(x
) *x
+= origin
.x
;
1167 if(y
) *y
+= origin
.y
;
1169 MacWindowToRootWindow( x
, y
) ;
1172 Point localwhere
= { 0,0 };
1173 if(x
) localwhere
.h
= * x
;
1174 if(y
) localwhere
.v
= * y
;
1175 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1176 if(x
) *x
= localwhere
.h
;
1177 if(y
) *y
= localwhere
.v
;
1181 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1183 wxPoint origin
= GetClientAreaOrigin() ;
1184 if(x
) *x
+= origin
.x
;
1185 if(y
) *y
+= origin
.y
;
1187 MacWindowToRootWindow( x
, y
) ;
1190 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1192 MacRootWindowToWindow( x
, y
) ;
1194 wxPoint origin
= GetClientAreaOrigin() ;
1195 if(x
) *x
-= origin
.x
;
1196 if(y
) *y
-= origin
.y
;
1199 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1201 #if TARGET_API_MAC_OSX
1203 if ( x
) pt
.x
= *x
;
1204 if ( y
) pt
.y
= *y
;
1206 if ( !IsTopLevel() )
1207 HIViewConvertPoint( &pt
, *m_peer
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1209 if ( x
) *x
= (int) pt
.x
;
1210 if ( y
) *y
= (int) pt
.y
;
1212 if ( !IsTopLevel() )
1215 GetControlBounds( *m_peer
, &bounds
) ;
1216 if(x
) *x
+= bounds
.left
;
1217 if(y
) *y
+= bounds
.top
;
1222 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1227 MacWindowToRootWindow( &x1
, &y1
) ;
1232 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1234 #if TARGET_API_MAC_OSX
1236 if ( x
) pt
.x
= *x
;
1237 if ( y
) pt
.y
= *y
;
1239 if ( !IsTopLevel() )
1240 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , *m_peer
) ;
1242 if ( x
) *x
= (int) pt
.x
;
1243 if ( y
) *y
= (int) pt
.y
;
1245 if ( !IsTopLevel() )
1248 GetControlBounds( *m_peer
, &bounds
) ;
1249 if(x
) *x
-= bounds
.left
;
1250 if(y
) *y
-= bounds
.top
;
1255 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1260 MacRootWindowToWindow( &x1
, &y1
) ;
1265 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1267 RgnHandle rgn
= NewRgn() ;
1269 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1271 GetRegionBounds( rgn
, &content
) ;
1276 GetControlBounds( *m_peer
, &content
) ;
1279 GetControlBounds( *m_peer
, &structure
) ;
1280 #if !TARGET_API_MAC_OSX
1281 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1283 left
= content
.left
- structure
.left
;
1284 top
= content
.top
- structure
.top
;
1285 right
= structure
.right
- content
.right
;
1286 bottom
= structure
.bottom
- content
.bottom
;
1289 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1291 wxSize sizeTotal
= size
;
1293 RgnHandle rgn
= NewRgn() ;
1297 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1299 GetRegionBounds( rgn
, &content
) ;
1304 GetControlBounds( *m_peer
, &content
) ;
1307 GetControlBounds( *m_peer
, &structure
) ;
1308 #if !TARGET_API_MAC_OSX
1309 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1312 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1313 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1315 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1316 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1322 // Get size *available for subwindows* i.e. excluding menu bar etc.
1323 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1327 RgnHandle rgn
= NewRgn() ;
1329 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1331 GetRegionBounds( rgn
, &content
) ;
1336 GetControlBounds( *m_peer
, &content
) ;
1338 #if !TARGET_API_MAC_OSX
1340 GetControlBounds( *m_peer
, &structure
) ;
1341 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1343 ww
= content
.right
- content
.left
;
1344 hh
= content
.bottom
- content
.top
;
1346 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1347 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1349 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1355 GetSize( &w
, &h
) ;
1357 MacClientToRootWindow( &x1
, &y1
) ;
1358 MacClientToRootWindow( &w
, &h
) ;
1360 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1362 int totW
= 10000 , totH
= 10000;
1365 if ( iter
->IsTopLevel() )
1367 iter
->GetSize( &totW
, &totH
) ;
1371 iter
= iter
->GetParent() ;
1374 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1376 hh
-= MAC_SCROLLBAR_SIZE
;
1382 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1384 ww
-= MAC_SCROLLBAR_SIZE
;
1396 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1398 if (m_cursor
== cursor
)
1401 if (wxNullCursor
== cursor
)
1403 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1408 if ( ! wxWindowBase::SetCursor( cursor
) )
1412 wxASSERT_MSG( m_cursor
.Ok(),
1413 wxT("cursor must be valid after call to the base version"));
1417 TODO why do we have to use current coordinates ?
1420 wxWindowMac *mouseWin ;
1423 // Change the cursor NOW if we're within the correct window
1426 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1428 if ( mouseWin == this && !wxIsBusy() )
1430 m_cursor.MacInstall() ;
1436 m_cursor
.MacInstall() ;
1443 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1445 menu
->SetInvokingWindow(this);
1448 if ( x
== -1 && y
== -1 )
1450 wxPoint mouse
= wxGetMousePosition();
1451 x
= mouse
.x
; y
= mouse
.y
;
1455 ClientToScreen( &x
, &y
) ;
1458 menu
->MacBeforeDisplay( true ) ;
1459 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1460 if ( HiWord(menuResult
) != 0 )
1463 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1464 wxMenuItem
* item
= NULL
;
1466 item
= menu
->FindItem(id
, &realmenu
) ;
1467 if (item
->IsCheckable())
1469 item
->Check( !item
->IsChecked() ) ;
1471 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1473 menu
->MacAfterDisplay( true ) ;
1475 menu
->SetInvokingWindow(NULL
);
1481 // ----------------------------------------------------------------------------
1483 // ----------------------------------------------------------------------------
1487 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1489 wxWindowBase::DoSetToolTip(tooltip
);
1492 m_tooltip
->SetWindow(this);
1495 #endif // wxUSE_TOOLTIPS
1497 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1499 int former_x
, former_y
, former_w
, former_h
;
1500 #if !TARGET_API_MAC_OSX
1501 DoGetPosition( &former_x
, &former_y
) ;
1502 DoGetSize( &former_w
, &former_h
) ;
1504 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1507 int actualWidth
= width
;
1508 int actualHeight
= height
;
1512 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1513 actualWidth
= m_minWidth
;
1514 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1515 actualHeight
= m_minHeight
;
1516 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1517 actualWidth
= m_maxWidth
;
1518 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1519 actualHeight
= m_maxHeight
;
1521 bool doMove
= false ;
1522 bool doResize
= false ;
1524 if ( actualX
!= former_x
|| actualY
!= former_y
)
1528 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1533 if ( doMove
|| doResize
)
1535 // we don't adjust twice for the origin
1536 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1537 bool vis
= IsControlVisible( *m_peer
) ;
1538 #if TARGET_API_MAC_OSX
1539 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1541 SetControlVisibility( *m_peer
, false , true ) ;
1542 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1543 HIViewSetFrame ( *m_peer
, &hir
) ;
1545 SetControlVisibility( *m_peer
, true , true ) ;
1548 SetControlVisibility( *m_peer
, false , true ) ;
1549 SetControlBounds( *m_peer
, &r
) ;
1551 SetControlVisibility( *m_peer
, true , true ) ;
1553 MacRepositionScrollBars() ;
1556 wxPoint
point(actualX
,actualY
);
1557 wxMoveEvent
event(point
, m_windowId
);
1558 event
.SetEventObject(this);
1559 GetEventHandler()->ProcessEvent(event
) ;
1563 MacRepositionScrollBars() ;
1564 wxSize
size(actualWidth
, actualHeight
);
1565 wxSizeEvent
event(size
, m_windowId
);
1566 event
.SetEventObject(this);
1567 GetEventHandler()->ProcessEvent(event
);
1573 wxSize
wxWindowMac::DoGetBestSize() const
1575 if ( m_macIsUserPane
|| IsTopLevel() )
1576 return wxWindowBase::DoGetBestSize() ;
1578 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1579 short baselineoffset
;
1580 int bestWidth
, bestHeight
;
1581 ::GetBestControlRect( *m_peer
, &bestsize
, &baselineoffset
) ;
1583 if ( EmptyRect( &bestsize
) )
1586 bestsize
.left
= bestsize
.top
= 0 ;
1587 bestsize
.right
= 16 ;
1588 bestsize
.bottom
= 16 ;
1589 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1591 bestsize
.bottom
= 16 ;
1593 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1595 bestsize
.bottom
= 24 ;
1599 // return wxWindowBase::DoGetBestSize() ;
1603 bestWidth
= bestsize
.right
- bestsize
.left
;
1604 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1605 if ( bestHeight
< 10 )
1608 return wxSize(bestWidth
, bestHeight
);
1609 // return wxWindowBase::DoGetBestSize() ;
1613 // set the size of the window: if the dimensions are positive, just use them,
1614 // but if any of them is equal to -1, it means that we must find the value for
1615 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1616 // which case -1 is a valid value for x and y)
1618 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1619 // the width/height to best suit our contents, otherwise we reuse the current
1621 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1623 // get the current size and position...
1624 int currentX
, currentY
;
1625 GetPosition(¤tX
, ¤tY
);
1627 int currentW
,currentH
;
1628 GetSize(¤tW
, ¤tH
);
1630 // ... and don't do anything (avoiding flicker) if it's already ok
1631 if ( x
== currentX
&& y
== currentY
&&
1632 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1635 MacRepositionScrollBars() ; // we might have a real position shift
1639 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1641 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1644 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1646 wxSize
size(-1, -1);
1649 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1651 size
= DoGetBestSize();
1656 // just take the current one
1663 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1667 size
= DoGetBestSize();
1669 //else: already called DoGetBestSize() above
1675 // just take the current one
1680 DoMoveWindow(x
, y
, width
, height
);
1684 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1686 RgnHandle rgn
= NewRgn() ;
1688 GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) ;
1689 GetRegionBounds( rgn
, &content
) ;
1691 #if !TARGET_API_MAC_OSX
1692 // if the content rgn is empty / not supported
1693 // don't attempt to correct the coordinates to wxWindow relative ones
1694 if (!::EmptyRect( &content
) )
1697 GetControlBounds( *m_peer
, &structure
) ;
1698 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1702 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1705 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1707 if ( clientheight
!= -1 || clientheight
!= -1 )
1709 int currentclientwidth
, currentclientheight
;
1710 int currentwidth
, currentheight
;
1712 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1713 GetSize( ¤twidth
, ¤theight
) ;
1715 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1716 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1720 void wxWindowMac::SetTitle(const wxString
& title
)
1722 m_label
= wxStripMenuCodes(title
) ;
1724 if ( m_peer
&& m_peer
->Ok() )
1726 UMASetControlTitle( *m_peer
, m_label
, m_font
.GetEncoding() ) ;
1731 wxString
wxWindowMac::GetTitle() const
1736 bool wxWindowMac::Show(bool show
)
1738 if ( !wxWindowBase::Show(show
) )
1741 // TODO use visibilityChanged Carbon Event for OSX
1742 bool former
= MacIsReallyShown() ;
1744 SetControlVisibility( *m_peer
, show
, true ) ;
1745 if ( former
!= MacIsReallyShown() )
1746 MacPropagateVisibilityChanged() ;
1750 bool wxWindowMac::Enable(bool enable
)
1752 wxASSERT( m_peer
->Ok() ) ;
1753 if ( !wxWindowBase::Enable(enable
) )
1756 bool former
= MacIsReallyEnabled() ;
1757 #if TARGET_API_MAC_OSX
1759 EnableControl( *m_peer
) ;
1761 DisableControl( *m_peer
) ;
1764 ActivateControl( *m_peer
) ;
1766 DeactivateControl( *m_peer
) ;
1769 if ( former
!= MacIsReallyEnabled() )
1770 MacPropagateEnabledStateChanged() ;
1775 // status change propagations (will be not necessary for OSX later )
1778 void wxWindowMac::MacPropagateVisibilityChanged()
1780 #if !TARGET_API_MAC_OSX
1781 MacVisibilityChanged() ;
1783 wxWindowListNode
*node
= GetChildren().GetFirst();
1786 wxWindowMac
*child
= node
->GetData();
1787 if ( child
->IsShown() )
1788 child
->MacPropagateVisibilityChanged( ) ;
1789 node
= node
->GetNext();
1794 void wxWindowMac::MacPropagateEnabledStateChanged( )
1796 #if !TARGET_API_MAC_OSX
1797 MacEnabledStateChanged() ;
1799 wxWindowListNode
*node
= GetChildren().GetFirst();
1802 wxWindowMac
*child
= node
->GetData();
1803 if ( child
->IsEnabled() )
1804 child
->MacPropagateEnabledStateChanged() ;
1805 node
= node
->GetNext();
1810 void wxWindowMac::MacPropagateHiliteChanged( )
1812 #if !TARGET_API_MAC_OSX
1813 MacHiliteChanged() ;
1815 wxWindowListNode
*node
= GetChildren().GetFirst();
1818 wxWindowMac
*child
= node
->GetData();
1819 // if ( child->IsEnabled() )
1820 child
->MacPropagateHiliteChanged() ;
1821 node
= node
->GetNext();
1827 // status change notifications
1830 void wxWindowMac::MacVisibilityChanged()
1834 void wxWindowMac::MacHiliteChanged()
1838 void wxWindowMac::MacEnabledStateChanged()
1843 // status queries on the inherited window's state
1846 bool wxWindowMac::MacIsReallyShown()
1848 // only under OSX the visibility of the TLW is taken into account
1849 #if TARGET_API_MAC_OSX
1850 return IsControlVisible( *m_peer
) ;
1852 wxWindow
* win
= this ;
1853 while( win
->IsShown() )
1855 if ( win
->IsTopLevel() )
1858 win
= win
->GetParent() ;
1867 bool wxWindowMac::MacIsReallyEnabled()
1869 #if TARGET_API_MAC_OSX
1870 return IsControlEnabled( *m_peer
) ;
1872 return IsControlActive( *m_peer
) ;
1876 bool wxWindowMac::MacIsReallyHilited()
1878 return IsControlActive( *m_peer
) ;
1881 void wxWindowMac::MacFlashInvalidAreas()
1883 #if TARGET_API_MAC_OSX
1884 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1892 int wxWindowMac::GetCharHeight() const
1894 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1895 return dc
.GetCharHeight() ;
1898 int wxWindowMac::GetCharWidth() const
1900 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1901 return dc
.GetCharWidth() ;
1904 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1905 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1907 const wxFont
*fontToUse
= theFont
;
1909 fontToUse
= &m_font
;
1911 wxClientDC
dc( (wxWindowMac
*) this ) ;
1913 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1914 if ( externalLeading
)
1915 *externalLeading
= le
;
1925 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1926 * we always intersect with the entire window, not only with the client area
1929 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1931 #if TARGET_API_MAC_OSX
1933 HIViewSetNeedsDisplay( *m_peer
, true ) ;
1936 RgnHandle update
= NewRgn() ;
1937 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1938 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1939 wxPoint origin
= GetClientAreaOrigin() ;
1940 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1941 HIViewSetNeedsDisplayInRegion( *m_peer
, update
, true ) ;
1945 RgnHandle updateRgn = NewRgn() ;
1948 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1952 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1953 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1955 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1956 DisposeRgn(updateRgn) ;
1958 if ( IsControlVisible( *m_peer
) )
1960 SetControlVisibility( *m_peer
, false , false ) ;
1961 SetControlVisibility( *m_peer
, true , true ) ;
1964 if ( MacGetTopLevelWindow() == NULL )
1967 if ( !IsControlVisible( *m_peer ) )
1970 wxPoint client = GetClientAreaOrigin();
1973 int x2 = m_width - client.x;
1974 int y2 = m_height - client.y;
1976 if (IsKindOf( CLASSINFO(wxButton)))
1978 // buttons have an "aura"
1985 Rect clientrect = { y1, x1, y2, x2 };
1989 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1990 SectRect( &clientrect , &r , &clientrect ) ;
1993 if ( !EmptyRect( &clientrect ) )
1995 int top = 0 , left = 0 ;
1997 MacClientToRootWindow( &left , &top ) ;
1998 OffsetRect( &clientrect , left , top ) ;
2000 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2006 void wxWindowMac::Freeze()
2008 #if TARGET_API_MAC_OSX
2009 if ( !m_frozenness
++ )
2011 HIViewSetDrawingEnabled( *m_peer
, false ) ;
2016 #if TARGET_API_MAC_OSX
2017 static void InvalidateControlAndChildren( HIViewRef control
)
2019 HIViewSetNeedsDisplay( control
, true ) ;
2020 UInt16 childrenCount
= 0 ;
2021 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2022 if ( err
== errControlIsNotEmbedder
)
2024 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2026 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2029 err
= GetIndexedSubControl( control
, i
, & child
) ;
2030 if ( err
== errControlIsNotEmbedder
)
2032 InvalidateControlAndChildren( child
) ;
2037 void wxWindowMac::Thaw()
2039 #if TARGET_API_MAC_OSX
2040 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2042 if ( !--m_frozenness
)
2044 HIViewSetDrawingEnabled( *m_peer
, true ) ;
2045 InvalidateControlAndChildren( *m_peer
) ;
2046 // HIViewSetNeedsDisplay( *m_peer , true ) ;
2051 void wxWindowMac::MacRedrawControl()
2054 if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) )
2056 #if TARGET_API_MAC_CARBON
2059 wxClientDC dc(this) ;
2060 wxMacPortSetter helper(&dc) ;
2061 wxMacWindowClipper clipper(this) ;
2062 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2063 UMADrawControl( *m_peer ) ;
2070 void wxWindowMac::OnPaint(wxPaintEvent& event)
2072 // why don't we skip that here ?
2076 wxWindowMac
*wxGetActiveWindow()
2078 // actually this is a windows-only concept
2082 // Coordinates relative to the window
2083 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2085 // We really don't move the mouse programmatically under Mac.
2088 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2090 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2095 event
.GetDC()->Clear() ;
2098 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2100 wxWindowDC
dc(this) ;
2101 wxMacPortSetter
helper(&dc
) ;
2103 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2106 int wxWindowMac::GetScrollPos(int orient
) const
2108 if ( orient
== wxHORIZONTAL
)
2111 return m_hScrollBar
->GetThumbPosition() ;
2116 return m_vScrollBar
->GetThumbPosition() ;
2121 // This now returns the whole range, not just the number
2122 // of positions that we can scroll.
2123 int wxWindowMac::GetScrollRange(int orient
) const
2125 if ( orient
== wxHORIZONTAL
)
2128 return m_hScrollBar
->GetRange() ;
2133 return m_vScrollBar
->GetRange() ;
2138 int wxWindowMac::GetScrollThumb(int orient
) const
2140 if ( orient
== wxHORIZONTAL
)
2143 return m_hScrollBar
->GetThumbSize() ;
2148 return m_vScrollBar
->GetThumbSize() ;
2153 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2155 if ( orient
== wxHORIZONTAL
)
2158 m_hScrollBar
->SetThumbPosition( pos
) ;
2163 m_vScrollBar
->SetThumbPosition( pos
) ;
2167 void wxWindowMac::MacPaintBorders( int left
, int top
)
2173 wxGetOsVersion( &major
, &minor
);
2175 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2176 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2178 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2179 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2180 // OS X has lighter border edges than classic:
2183 darkShadow
.red
= 0x8E8E;
2184 darkShadow
.green
= 0x8E8E;
2185 darkShadow
.blue
= 0x8E8E;
2186 lightShadow
.red
= 0xBDBD;
2187 lightShadow
.green
= 0xBDBD;
2188 lightShadow
.blue
= 0xBDBD;
2194 GetSize( &w
, &h
) ;
2195 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2197 #if wxMAC_USE_THEME_BORDER
2198 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2201 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2202 InsetRect( &rect , border , border );
2203 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2206 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2208 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2209 RGBForeColor( &face
);
2210 MoveTo( left
+ 0 , top
+ h
- 2 );
2211 LineTo( left
+ 0 , top
+ 0 );
2212 LineTo( left
+ w
- 2 , top
+ 0 );
2214 MoveTo( left
+ 2 , top
+ h
- 3 );
2215 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2216 LineTo( left
+ w
- 3 , top
+ 2 );
2218 RGBForeColor( sunken
? &face
: &darkShadow
);
2219 MoveTo( left
+ 0 , top
+ h
- 1 );
2220 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2221 LineTo( left
+ w
- 1 , top
+ 0 );
2223 RGBForeColor( sunken
? &lightShadow
: &white
);
2224 MoveTo( left
+ 1 , top
+ h
- 3 );
2225 LineTo( left
+ 1, top
+ 1 );
2226 LineTo( left
+ w
- 3 , top
+ 1 );
2228 RGBForeColor( sunken
? &white
: &lightShadow
);
2229 MoveTo( left
+ 1 , top
+ h
- 2 );
2230 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2231 LineTo( left
+ w
- 2 , top
+ 1 );
2233 RGBForeColor( sunken
? &darkShadow
: &face
);
2234 MoveTo( left
+ 2 , top
+ h
- 4 );
2235 LineTo( left
+ 2 , top
+ 2 );
2236 LineTo( left
+ w
- 4 , top
+ 2 );
2239 else if (HasFlag(wxSIMPLE_BORDER
))
2241 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2242 RGBForeColor( &darkShadow
) ;
2243 FrameRect( &rect
) ;
2247 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2249 if ( child
== m_hScrollBar
)
2250 m_hScrollBar
= NULL
;
2251 if ( child
== m_vScrollBar
)
2252 m_vScrollBar
= NULL
;
2254 wxWindowBase::RemoveChild( child
) ;
2257 // New function that will replace some of the above.
2258 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2259 int range
, bool refresh
)
2261 if ( orient
== wxHORIZONTAL
)
2265 if ( range
== 0 || thumbVisible
>= range
)
2267 if ( m_hScrollBar
->IsShown() )
2268 m_hScrollBar
->Show(false) ;
2272 if ( !m_hScrollBar
->IsShown() )
2273 m_hScrollBar
->Show(true) ;
2274 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2282 if ( range
== 0 || thumbVisible
>= range
)
2284 if ( m_vScrollBar
->IsShown() )
2285 m_vScrollBar
->Show(false) ;
2289 if ( !m_vScrollBar
->IsShown() )
2290 m_vScrollBar
->Show(true) ;
2291 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2295 MacRepositionScrollBars() ;
2298 // Does a physical scroll
2299 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2301 if( dx
== 0 && dy
==0 )
2307 int width
, height
;
2308 GetClientSize( &width
, &height
) ;
2309 #if TARGET_API_MAC_OSX
2310 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2311 // area is scrolled, this does not occur if width and height are 2 pixels less,
2312 // TODO write optimal workaround
2313 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2316 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2317 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2319 if ( HIViewGetNeedsDisplay( *m_peer
) )
2321 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2322 // either immediate redraw or full invalidate
2324 // is the better overall solution, as it does not slow down scrolling
2325 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2327 // this would be the preferred version for fast drawing controls
2328 if( UMAGetSystemVersion() < 0x1030 )
2331 HIViewRender(*m_peer
) ;
2334 HIViewScrollRect ( *m_peer
, &scrollrect
, dx
,dy
) ;
2341 RgnHandle updateRgn
= NewRgn() ;
2344 wxClientDC
dc(this) ;
2345 wxMacPortSetter
helper(&dc
) ;
2347 GetControlBounds( *m_peer
, &scrollrect
);
2348 scrollrect
.top
+= MacGetTopBorderSize() ;
2349 scrollrect
.left
+= MacGetLeftBorderSize() ;
2350 scrollrect
.bottom
= scrollrect
.top
+ height
;
2351 scrollrect
.right
= scrollrect
.left
+ width
;
2355 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2356 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2357 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2359 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2361 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2365 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2367 wxWindowMac
*child
= node
->GetData();
2368 if (child
== m_vScrollBar
) continue;
2369 if (child
== m_hScrollBar
) continue;
2370 if (child
->IsTopLevel()) continue;
2373 child
->GetPosition( &x
, &y
);
2375 child
->GetSize( &w
, &h
);
2379 if (rect
->Intersects(rc
))
2380 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2384 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2389 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2391 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2393 wxScrollWinEvent wevent
;
2394 wevent
.SetPosition(event
.GetPosition());
2395 wevent
.SetOrientation(event
.GetOrientation());
2396 wevent
.m_eventObject
= this;
2398 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2399 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2400 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2401 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2402 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2403 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2404 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2405 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2406 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2407 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2408 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2409 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2410 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2411 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2412 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2413 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2415 GetEventHandler()->ProcessEvent(wevent
);
2419 // Get the window with the focus
2420 wxWindowMac
*wxWindowBase::FindFocus()
2422 ControlRef control
;
2423 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2424 return wxFindControlFromMacControl( control
) ;
2427 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2429 // panel wants to track the window which was the last to have focus in it,
2430 // so we want to set ourselves as the window which last had focus
2432 // notice that it's also important to do it upwards the tree becaus
2433 // otherwise when the top level panel gets focus, it won't set it back to
2434 // us, but to some other sibling
2436 // CS:don't know if this is still needed:
2437 //wxChildFocusEvent eventFocus(this);
2438 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2443 void wxWindowMac::OnInternalIdle()
2445 // This calls the UI-update mechanism (querying windows for
2446 // menu/toolbar/control state information)
2447 if (wxUpdateUIEvent::CanUpdate(this))
2448 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2451 // Raise the window to the top of the Z order
2452 void wxWindowMac::Raise()
2454 #if TARGET_API_MAC_OSX
2455 HIViewSetZOrder(*m_peer
,kHIViewZOrderAbove
, NULL
) ;
2459 // Lower the window to the bottom of the Z order
2460 void wxWindowMac::Lower()
2462 #if TARGET_API_MAC_OSX
2463 HIViewSetZOrder(*m_peer
,kHIViewZOrderBelow
, NULL
) ;
2468 // static wxWindow *gs_lastWhich = NULL;
2470 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2472 // first trigger a set cursor event
2474 wxPoint clientorigin
= GetClientAreaOrigin() ;
2475 wxSize clientsize
= GetClientSize() ;
2477 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2479 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2481 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2482 if ( processedEvtSetCursor
&& event
.HasCursor() )
2484 cursor
= event
.GetCursor() ;
2489 // the test for processedEvtSetCursor is here to prevent using m_cursor
2490 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2491 // it - this is a way to say that our cursor shouldn't be used for this
2493 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2503 cursor
= *wxSTANDARD_CURSOR
;
2507 cursor
.MacInstall() ;
2509 return cursor
.Ok() ;
2512 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2516 return m_tooltip
->GetTip() ;
2518 return wxEmptyString
;
2521 void wxWindowMac::Update()
2523 #if TARGET_API_MAC_OSX
2524 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2525 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2526 // for composited windows this also triggers a redraw of all
2527 // invalid views in the window
2528 if( UMAGetSystemVersion() >= 0x1030 )
2529 HIWindowFlush(window
) ;
2533 // the only way to trigger the redrawing on earlier systems is to call
2536 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2537 UInt32 currentEventClass
= 0 ;
2538 UInt32 currentEventKind
= 0 ;
2539 if ( currentEvent
!= NULL
)
2541 currentEventClass
= ::GetEventClass( currentEvent
) ;
2542 currentEventKind
= ::GetEventKind( currentEvent
) ;
2544 if ( currentEventClass
!= kEventClassMenu
)
2546 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2549 OSStatus status
= noErr
;
2550 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2553 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2556 ::Draw1Control( *m_peer
) ;
2560 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2562 wxTopLevelWindowMac
* win
= NULL
;
2563 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2566 win
= wxFindWinFromMacWindow( window
) ;
2570 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2574 RgnHandle visRgn
= NewRgn() ;
2575 RgnHandle tempRgn
= NewRgn() ;
2576 if ( IsControlVisible( *m_peer
) )
2578 GetControlBounds( *m_peer
, &r
) ;
2579 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2581 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2582 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2591 if ( includeOuterStructures
)
2592 InsetRect( &r
, -3 , -3 ) ;
2593 RectRgn( visRgn
, &r
) ;
2594 if ( !IsTopLevel() )
2596 wxWindow
* child
= this ;
2597 wxWindow
* parent
= child
->GetParent() ;
2602 // we have to find a better clipping algorithm here, in order not to clip things
2603 // positioned like status and toolbar
2604 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2606 size
= parent
->GetSize() ;
2611 size
= parent
->GetClientSize() ;
2612 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2616 parent
->MacWindowToRootWindow( &x
, &y
) ;
2617 MacRootWindowToWindow( &x
, &y
) ;
2619 SetRectRgn( tempRgn
,
2620 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2621 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2622 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2624 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2625 if ( parent
->IsTopLevel() )
2628 parent
= child
->GetParent() ;
2633 wxRegion vis
= visRgn
;
2634 DisposeRgn( visRgn
) ;
2635 DisposeRgn( tempRgn
) ;
2640 This function must not change the updatergn !
2642 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2644 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2645 bool handled
= false ;
2647 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2649 RgnHandle newupdate
= NewRgn() ;
2650 wxSize point
= GetClientSize() ;
2651 wxPoint origin
= GetClientAreaOrigin() ;
2652 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2653 SectRgn( newupdate
, updatergn
, newupdate
) ;
2654 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2655 m_updateRegion
= newupdate
;
2656 DisposeRgn( newupdate
) ;
2659 if ( !EmptyRgn(updatergn
) )
2661 wxWindowDC
dc(this);
2662 if (!EmptyRgn(updatergn
))
2663 dc
.SetClippingRegion(wxRegion(updatergn
));
2665 wxEraseEvent
eevent( GetId(), &dc
);
2666 eevent
.SetEventObject( this );
2667 GetEventHandler()->ProcessEvent( eevent
);
2669 if ( !m_updateRegion
.Empty() )
2671 // paint the window itself
2673 event
.m_timeStamp
= time
;
2674 event
.SetEventObject(this);
2675 handled
= GetEventHandler()->ProcessEvent(event
);
2677 // paint custom borders
2678 wxNcPaintEvent
eventNc( GetId() );
2679 eventNc
.SetEventObject( this );
2680 GetEventHandler()->ProcessEvent( eventNc
);
2686 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2688 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2689 // updatergn is always already clipped to our boundaries
2690 // if we are in compositing mode then it is in relative to the upper left of the control
2691 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2692 // of the toplevel window
2693 // it is in window coordinates, not in client coordinates
2695 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2696 RgnHandle ownUpdateRgn
= NewRgn() ;
2697 CopyRgn( updatergn
, ownUpdateRgn
) ;
2699 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2702 UMAGetControlBoundsInWindowCoords( *m_peer
, &bounds
);
2703 RgnHandle controlRgn
= NewRgn();
2704 RectRgn( controlRgn
, &bounds
);
2705 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2706 // the window update region
2707 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2708 DisposeRgn( controlRgn
);
2710 //KO: convert ownUpdateRgn to local coordinates
2711 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2714 MacDoRedraw( ownUpdateRgn
, time
) ;
2715 DisposeRgn( ownUpdateRgn
) ;
2719 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2721 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2725 if ( iter
->IsTopLevel() )
2726 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2728 iter
= iter
->GetParent() ;
2730 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2734 void wxWindowMac::MacCreateScrollBars( long style
)
2736 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2738 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2739 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2741 GetClientSize( &width
, &height
) ;
2743 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2744 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2745 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2746 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2748 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2749 vSize
, wxVERTICAL
);
2751 if ( style
& wxVSCROLL
)
2757 m_vScrollBar
->Show(false) ;
2759 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2760 hSize
, wxHORIZONTAL
);
2761 if ( style
& wxHSCROLL
)
2766 m_hScrollBar
->Show(false) ;
2769 // because the create does not take into account the client area origin
2770 MacRepositionScrollBars() ; // we might have a real position shift
2773 void wxWindowMac::MacRepositionScrollBars()
2775 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2776 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2778 // get real client area
2782 GetSize( &width
, &height
) ;
2784 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2785 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2787 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2788 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2789 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2790 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2796 GetSize( &w
, &h
) ;
2798 MacClientToRootWindow( &x
, &y
) ;
2799 MacClientToRootWindow( &w
, &h
) ;
2801 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2803 int totW
= 10000 , totH
= 10000;
2806 if ( iter
->IsTopLevel() )
2808 iter
->GetSize( &totW
, &totH
) ;
2812 iter
= iter
->GetParent() ;
2840 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2844 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2848 bool wxWindowMac::AcceptsFocus() const
2850 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2853 void wxWindowMac::MacSuperChangedPosition()
2855 // only window-absolute structures have to be moved i.e. controls
2857 wxWindowListNode
*node
= GetChildren().GetFirst();
2860 wxWindowMac
*child
= node
->GetData();
2861 child
->MacSuperChangedPosition() ;
2862 node
= node
->GetNext();
2866 void wxWindowMac::MacTopLevelWindowChangedPosition()
2868 // only screen-absolute structures have to be moved i.e. glcanvas
2870 wxWindowListNode
*node
= GetChildren().GetFirst();
2873 wxWindowMac
*child
= node
->GetData();
2874 child
->MacTopLevelWindowChangedPosition() ;
2875 node
= node
->GetNext();
2879 long wxWindowMac::MacGetLeftBorderSize( ) const
2884 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2887 #if wxMAC_USE_THEME_BORDER
2888 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2892 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2895 #if wxMAC_USE_THEME_BORDER
2896 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2900 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2907 long wxWindowMac::MacGetRightBorderSize( ) const
2909 // they are all symmetric in mac themes
2910 return MacGetLeftBorderSize() ;
2913 long wxWindowMac::MacGetTopBorderSize( ) const
2915 // they are all symmetric in mac themes
2916 return MacGetLeftBorderSize() ;
2919 long wxWindowMac::MacGetBottomBorderSize( ) const
2921 // they are all symmetric in mac themes
2922 return MacGetLeftBorderSize() ;
2925 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2927 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2930 // Find the wxWindowMac at the current mouse position, returning the mouse
2932 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2934 pt
= wxGetMousePosition();
2935 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2939 // Get the current mouse position.
2940 wxPoint
wxGetMousePosition()
2943 wxGetMousePosition(& x
, & y
);
2944 return wxPoint(x
, y
);
2947 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2949 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2951 // copied from wxGTK : CS
2952 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2955 // (a) it's a command event and so is propagated to the parent
2956 // (b) under MSW it can be generated from kbd too
2957 // (c) it uses screen coords (because of (a))
2958 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2960 this->ClientToScreen(event
.GetPosition()));
2961 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2970 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2974 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2978 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2979 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2983 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2985 return eventNotHandledErr
;