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 wxColour
newCol(GetBackgroundColour());
922 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
924 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
926 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
928 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
932 brush
.SetColour( newCol
) ;
934 MacSetBackgroundBrush( brush
) ;
936 MacUpdateControlFont() ;
942 bool wxWindowMac::MacCanFocus() const
944 // there is currently no way to determine whether the window is running in full keyboard
945 // access mode, therefore we cannot rely on these features, yet the only other way would be
946 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
947 // in event handlers...
948 UInt32 features
= 0 ;
949 GetControlFeatures( *m_peer
, &features
) ;
950 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
954 void wxWindowMac::SetFocus()
956 if ( AcceptsFocus() )
958 #if !TARGET_API_MAC_OSX
959 wxWindow
* former
= FindFocus() ;
961 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
962 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
963 // leave in case of an error
964 if ( err
== errCouldntSetFocus
)
967 #if !TARGET_API_MAC_OSX
968 // emulate carbon events when running under carbonlib where they are not natively available
971 EventRef evRef
= NULL
;
972 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
975 wxMacCarbonEvent
cEvent( evRef
) ;
976 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
977 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
979 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
980 ReleaseEvent(evRef
) ;
982 // send new focus event
984 EventRef evRef
= NULL
;
985 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
988 wxMacCarbonEvent
cEvent( evRef
) ;
989 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
990 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
992 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
993 ReleaseEvent(evRef
) ;
1000 void wxWindowMac::DoCaptureMouse()
1002 wxTheApp
->s_captureWindow
= this ;
1005 wxWindow
* wxWindowBase::GetCapture()
1007 return wxTheApp
->s_captureWindow
;
1010 void wxWindowMac::DoReleaseMouse()
1012 wxTheApp
->s_captureWindow
= NULL
;
1015 #if wxUSE_DRAG_AND_DROP
1017 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1019 if ( m_dropTarget
!= 0 ) {
1020 delete m_dropTarget
;
1023 m_dropTarget
= pDropTarget
;
1024 if ( m_dropTarget
!= 0 )
1032 // Old style file-manager drag&drop
1033 void wxWindowMac::DragAcceptFiles(bool accept
)
1038 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1039 int& w
, int& h
) const
1042 GetControlBounds( *m_peer
, &bounds
) ;
1047 w
= bounds
.right
- bounds
.left
;
1048 h
= bounds
.bottom
- bounds
.top
;
1050 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1053 Point tlworigin
= { 0 , 0 } ;
1054 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1060 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1063 int& w
, int& h
, bool adjustOrigin
) const
1067 // todo the default calls may be used as soon as PostCreateControl Is moved here
1068 w
= size
.x
; // WidthDefault( size.x );
1069 h
= size
.y
; // HeightDefault( size.y ) ;
1070 #if !TARGET_API_MAC_OSX
1071 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1074 AdjustForParentClientOrigin( x
, y
) ;
1079 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1081 #if TARGET_API_MAC_OSX
1082 int x1
, y1
, w1
,h1
;
1083 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1089 GetControlBounds( *m_peer
, &bounds
) ;
1090 if(x
) *x
= bounds
.right
- bounds
.left
;
1091 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1095 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1097 #if TARGET_API_MAC_OSX
1098 int x1
, y1
, w1
,h1
;
1099 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1100 if ( !IsTopLevel() )
1102 wxWindow
*parent
= GetParent();
1105 wxPoint
pt(parent
->GetClientAreaOrigin());
1114 GetControlBounds( *m_peer
, &bounds
) ;
1115 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1117 int xx
= bounds
.left
;
1118 int yy
= bounds
.top
;
1120 if ( !GetParent()->IsTopLevel() )
1122 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1128 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1137 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1139 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1141 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1144 Point localwhere
= {0,0} ;
1146 if(x
) localwhere
.h
= * x
;
1147 if(y
) localwhere
.v
= * y
;
1149 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1150 if(x
) *x
= localwhere
.h
;
1151 if(y
) *y
= localwhere
.v
;
1154 MacRootWindowToWindow( x
, y
) ;
1156 wxPoint origin
= GetClientAreaOrigin() ;
1157 if(x
) *x
-= origin
.x
;
1158 if(y
) *y
-= origin
.y
;
1161 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1163 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1164 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1166 wxPoint origin
= GetClientAreaOrigin() ;
1167 if(x
) *x
+= origin
.x
;
1168 if(y
) *y
+= origin
.y
;
1170 MacWindowToRootWindow( x
, y
) ;
1173 Point localwhere
= { 0,0 };
1174 if(x
) localwhere
.h
= * x
;
1175 if(y
) localwhere
.v
= * y
;
1176 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1177 if(x
) *x
= localwhere
.h
;
1178 if(y
) *y
= localwhere
.v
;
1182 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1184 wxPoint origin
= GetClientAreaOrigin() ;
1185 if(x
) *x
+= origin
.x
;
1186 if(y
) *y
+= origin
.y
;
1188 MacWindowToRootWindow( x
, y
) ;
1191 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1193 MacRootWindowToWindow( x
, y
) ;
1195 wxPoint origin
= GetClientAreaOrigin() ;
1196 if(x
) *x
-= origin
.x
;
1197 if(y
) *y
-= origin
.y
;
1200 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1202 #if TARGET_API_MAC_OSX
1204 if ( x
) pt
.x
= *x
;
1205 if ( y
) pt
.y
= *y
;
1207 if ( !IsTopLevel() )
1209 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1211 HIViewConvertPoint( &pt
, *m_peer
, (ControlRef
) top
->GetHandle() ) ;
1214 if ( x
) *x
= (int) pt
.x
;
1215 if ( y
) *y
= (int) pt
.y
;
1217 if ( !IsTopLevel() )
1220 GetControlBounds( *m_peer
, &bounds
) ;
1221 if(x
) *x
+= bounds
.left
;
1222 if(y
) *y
+= bounds
.top
;
1227 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1232 MacWindowToRootWindow( &x1
, &y1
) ;
1237 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1239 #if TARGET_API_MAC_OSX
1241 if ( x
) pt
.x
= *x
;
1242 if ( y
) pt
.y
= *y
;
1244 if ( !IsTopLevel() )
1245 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , *m_peer
) ;
1247 if ( x
) *x
= (int) pt
.x
;
1248 if ( y
) *y
= (int) pt
.y
;
1250 if ( !IsTopLevel() )
1253 GetControlBounds( *m_peer
, &bounds
) ;
1254 if(x
) *x
-= bounds
.left
;
1255 if(y
) *y
-= bounds
.top
;
1260 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1265 MacRootWindowToWindow( &x1
, &y1
) ;
1270 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1272 RgnHandle rgn
= NewRgn() ;
1274 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1276 GetRegionBounds( rgn
, &content
) ;
1281 GetControlBounds( *m_peer
, &content
) ;
1284 GetControlBounds( *m_peer
, &structure
) ;
1285 #if !TARGET_API_MAC_OSX
1286 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1288 left
= content
.left
- structure
.left
;
1289 top
= content
.top
- structure
.top
;
1290 right
= structure
.right
- content
.right
;
1291 bottom
= structure
.bottom
- content
.bottom
;
1294 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1296 wxSize sizeTotal
= size
;
1298 RgnHandle rgn
= NewRgn() ;
1302 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1304 GetRegionBounds( rgn
, &content
) ;
1309 GetControlBounds( *m_peer
, &content
) ;
1312 GetControlBounds( *m_peer
, &structure
) ;
1313 #if !TARGET_API_MAC_OSX
1314 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1317 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1318 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1320 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1321 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1327 // Get size *available for subwindows* i.e. excluding menu bar etc.
1328 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1332 RgnHandle rgn
= NewRgn() ;
1334 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1336 GetRegionBounds( rgn
, &content
) ;
1341 GetControlBounds( *m_peer
, &content
) ;
1343 #if !TARGET_API_MAC_OSX
1345 GetControlBounds( *m_peer
, &structure
) ;
1346 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1348 ww
= content
.right
- content
.left
;
1349 hh
= content
.bottom
- content
.top
;
1351 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1352 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1354 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1360 GetSize( &w
, &h
) ;
1362 MacClientToRootWindow( &x1
, &y1
) ;
1363 MacClientToRootWindow( &w
, &h
) ;
1365 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1367 int totW
= 10000 , totH
= 10000;
1370 if ( iter
->IsTopLevel() )
1372 iter
->GetSize( &totW
, &totH
) ;
1376 iter
= iter
->GetParent() ;
1379 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1381 hh
-= MAC_SCROLLBAR_SIZE
;
1387 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1389 ww
-= MAC_SCROLLBAR_SIZE
;
1401 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1403 if (m_cursor
== cursor
)
1406 if (wxNullCursor
== cursor
)
1408 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1413 if ( ! wxWindowBase::SetCursor( cursor
) )
1417 wxASSERT_MSG( m_cursor
.Ok(),
1418 wxT("cursor must be valid after call to the base version"));
1422 TODO why do we have to use current coordinates ?
1425 wxWindowMac *mouseWin ;
1428 // Change the cursor NOW if we're within the correct window
1431 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1433 if ( mouseWin == this && !wxIsBusy() )
1435 m_cursor.MacInstall() ;
1441 m_cursor
.MacInstall() ;
1448 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1450 menu
->SetInvokingWindow(this);
1453 if ( x
== -1 && y
== -1 )
1455 wxPoint mouse
= wxGetMousePosition();
1456 x
= mouse
.x
; y
= mouse
.y
;
1460 ClientToScreen( &x
, &y
) ;
1463 menu
->MacBeforeDisplay( true ) ;
1464 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1465 if ( HiWord(menuResult
) != 0 )
1468 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1469 wxMenuItem
* item
= NULL
;
1471 item
= menu
->FindItem(id
, &realmenu
) ;
1472 if (item
->IsCheckable())
1474 item
->Check( !item
->IsChecked() ) ;
1476 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1478 menu
->MacAfterDisplay( true ) ;
1480 menu
->SetInvokingWindow(NULL
);
1486 // ----------------------------------------------------------------------------
1488 // ----------------------------------------------------------------------------
1492 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1494 wxWindowBase::DoSetToolTip(tooltip
);
1497 m_tooltip
->SetWindow(this);
1500 #endif // wxUSE_TOOLTIPS
1502 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1504 int former_x
, former_y
, former_w
, former_h
;
1505 #if !TARGET_API_MAC_OSX
1506 DoGetPosition( &former_x
, &former_y
) ;
1507 DoGetSize( &former_w
, &former_h
) ;
1509 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1512 int actualWidth
= width
;
1513 int actualHeight
= height
;
1517 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1518 actualWidth
= m_minWidth
;
1519 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1520 actualHeight
= m_minHeight
;
1521 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1522 actualWidth
= m_maxWidth
;
1523 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1524 actualHeight
= m_maxHeight
;
1526 bool doMove
= false ;
1527 bool doResize
= false ;
1529 if ( actualX
!= former_x
|| actualY
!= former_y
)
1533 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1538 if ( doMove
|| doResize
)
1540 // we don't adjust twice for the origin
1541 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1542 bool vis
= IsControlVisible( *m_peer
) ;
1543 #if TARGET_API_MAC_OSX
1544 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1546 SetControlVisibility( *m_peer
, false , true ) ;
1547 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1548 HIViewSetFrame ( *m_peer
, &hir
) ;
1550 SetControlVisibility( *m_peer
, true , true ) ;
1553 SetControlVisibility( *m_peer
, false , true ) ;
1554 SetControlBounds( *m_peer
, &r
) ;
1556 SetControlVisibility( *m_peer
, true , true ) ;
1558 MacRepositionScrollBars() ;
1561 wxPoint
point(actualX
,actualY
);
1562 wxMoveEvent
event(point
, m_windowId
);
1563 event
.SetEventObject(this);
1564 GetEventHandler()->ProcessEvent(event
) ;
1568 MacRepositionScrollBars() ;
1569 wxSize
size(actualWidth
, actualHeight
);
1570 wxSizeEvent
event(size
, m_windowId
);
1571 event
.SetEventObject(this);
1572 GetEventHandler()->ProcessEvent(event
);
1578 wxSize
wxWindowMac::DoGetBestSize() const
1580 if ( m_macIsUserPane
|| IsTopLevel() )
1581 return wxWindowBase::DoGetBestSize() ;
1583 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1584 short baselineoffset
;
1585 int bestWidth
, bestHeight
;
1586 ::GetBestControlRect( *m_peer
, &bestsize
, &baselineoffset
) ;
1588 if ( EmptyRect( &bestsize
) )
1591 bestsize
.left
= bestsize
.top
= 0 ;
1592 bestsize
.right
= 16 ;
1593 bestsize
.bottom
= 16 ;
1594 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1596 bestsize
.bottom
= 16 ;
1598 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1600 bestsize
.bottom
= 24 ;
1604 // return wxWindowBase::DoGetBestSize() ;
1608 bestWidth
= bestsize
.right
- bestsize
.left
;
1609 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1610 if ( bestHeight
< 10 )
1613 return wxSize(bestWidth
, bestHeight
);
1614 // return wxWindowBase::DoGetBestSize() ;
1618 // set the size of the window: if the dimensions are positive, just use them,
1619 // but if any of them is equal to -1, it means that we must find the value for
1620 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1621 // which case -1 is a valid value for x and y)
1623 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1624 // the width/height to best suit our contents, otherwise we reuse the current
1626 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1628 // get the current size and position...
1629 int currentX
, currentY
;
1630 GetPosition(¤tX
, ¤tY
);
1632 int currentW
,currentH
;
1633 GetSize(¤tW
, ¤tH
);
1635 // ... and don't do anything (avoiding flicker) if it's already ok
1636 if ( x
== currentX
&& y
== currentY
&&
1637 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1640 MacRepositionScrollBars() ; // we might have a real position shift
1644 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1646 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1649 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1651 wxSize
size(-1, -1);
1654 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1656 size
= DoGetBestSize();
1661 // just take the current one
1668 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1672 size
= DoGetBestSize();
1674 //else: already called DoGetBestSize() above
1680 // just take the current one
1685 DoMoveWindow(x
, y
, width
, height
);
1689 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1691 RgnHandle rgn
= NewRgn() ;
1693 GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) ;
1694 GetRegionBounds( rgn
, &content
) ;
1696 #if !TARGET_API_MAC_OSX
1697 // if the content rgn is empty / not supported
1698 // don't attempt to correct the coordinates to wxWindow relative ones
1699 if (!::EmptyRect( &content
) )
1702 GetControlBounds( *m_peer
, &structure
) ;
1703 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1707 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1710 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1712 if ( clientheight
!= -1 || clientheight
!= -1 )
1714 int currentclientwidth
, currentclientheight
;
1715 int currentwidth
, currentheight
;
1717 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1718 GetSize( ¤twidth
, ¤theight
) ;
1720 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1721 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1725 void wxWindowMac::SetTitle(const wxString
& title
)
1727 m_label
= wxStripMenuCodes(title
) ;
1729 if ( m_peer
&& m_peer
->Ok() )
1731 UMASetControlTitle( *m_peer
, m_label
, m_font
.GetEncoding() ) ;
1736 wxString
wxWindowMac::GetTitle() const
1741 bool wxWindowMac::Show(bool show
)
1743 if ( !wxWindowBase::Show(show
) )
1746 // TODO use visibilityChanged Carbon Event for OSX
1747 bool former
= MacIsReallyShown() ;
1749 SetControlVisibility( *m_peer
, show
, true ) ;
1750 if ( former
!= MacIsReallyShown() )
1751 MacPropagateVisibilityChanged() ;
1755 bool wxWindowMac::Enable(bool enable
)
1757 wxASSERT( m_peer
->Ok() ) ;
1758 if ( !wxWindowBase::Enable(enable
) )
1761 bool former
= MacIsReallyEnabled() ;
1762 #if TARGET_API_MAC_OSX
1764 EnableControl( *m_peer
) ;
1766 DisableControl( *m_peer
) ;
1769 ActivateControl( *m_peer
) ;
1771 DeactivateControl( *m_peer
) ;
1774 if ( former
!= MacIsReallyEnabled() )
1775 MacPropagateEnabledStateChanged() ;
1780 // status change propagations (will be not necessary for OSX later )
1783 void wxWindowMac::MacPropagateVisibilityChanged()
1785 #if !TARGET_API_MAC_OSX
1786 MacVisibilityChanged() ;
1788 wxWindowListNode
*node
= GetChildren().GetFirst();
1791 wxWindowMac
*child
= node
->GetData();
1792 if ( child
->IsShown() )
1793 child
->MacPropagateVisibilityChanged( ) ;
1794 node
= node
->GetNext();
1799 void wxWindowMac::MacPropagateEnabledStateChanged( )
1801 #if !TARGET_API_MAC_OSX
1802 MacEnabledStateChanged() ;
1804 wxWindowListNode
*node
= GetChildren().GetFirst();
1807 wxWindowMac
*child
= node
->GetData();
1808 if ( child
->IsEnabled() )
1809 child
->MacPropagateEnabledStateChanged() ;
1810 node
= node
->GetNext();
1815 void wxWindowMac::MacPropagateHiliteChanged( )
1817 #if !TARGET_API_MAC_OSX
1818 MacHiliteChanged() ;
1820 wxWindowListNode
*node
= GetChildren().GetFirst();
1823 wxWindowMac
*child
= node
->GetData();
1824 // if ( child->IsEnabled() )
1825 child
->MacPropagateHiliteChanged() ;
1826 node
= node
->GetNext();
1832 // status change notifications
1835 void wxWindowMac::MacVisibilityChanged()
1839 void wxWindowMac::MacHiliteChanged()
1843 void wxWindowMac::MacEnabledStateChanged()
1848 // status queries on the inherited window's state
1851 bool wxWindowMac::MacIsReallyShown()
1853 // only under OSX the visibility of the TLW is taken into account
1854 #if TARGET_API_MAC_OSX
1855 return IsControlVisible( *m_peer
) ;
1857 wxWindow
* win
= this ;
1858 while( win
->IsShown() )
1860 if ( win
->IsTopLevel() )
1863 win
= win
->GetParent() ;
1872 bool wxWindowMac::MacIsReallyEnabled()
1874 #if TARGET_API_MAC_OSX
1875 return IsControlEnabled( *m_peer
) ;
1877 return IsControlActive( *m_peer
) ;
1881 bool wxWindowMac::MacIsReallyHilited()
1883 return IsControlActive( *m_peer
) ;
1886 void wxWindowMac::MacFlashInvalidAreas()
1888 #if TARGET_API_MAC_OSX
1889 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1897 int wxWindowMac::GetCharHeight() const
1899 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1900 return dc
.GetCharHeight() ;
1903 int wxWindowMac::GetCharWidth() const
1905 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1906 return dc
.GetCharWidth() ;
1909 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1910 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1912 const wxFont
*fontToUse
= theFont
;
1914 fontToUse
= &m_font
;
1916 wxClientDC
dc( (wxWindowMac
*) this ) ;
1918 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1919 if ( externalLeading
)
1920 *externalLeading
= le
;
1930 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1931 * we always intersect with the entire window, not only with the client area
1934 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1936 #if TARGET_API_MAC_OSX
1938 HIViewSetNeedsDisplay( *m_peer
, true ) ;
1941 RgnHandle update
= NewRgn() ;
1942 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1943 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1944 wxPoint origin
= GetClientAreaOrigin() ;
1945 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1946 HIViewSetNeedsDisplayInRegion( *m_peer
, update
, true ) ;
1950 RgnHandle updateRgn = NewRgn() ;
1953 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1957 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1958 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1960 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1961 DisposeRgn(updateRgn) ;
1963 if ( IsControlVisible( *m_peer
) )
1965 SetControlVisibility( *m_peer
, false , false ) ;
1966 SetControlVisibility( *m_peer
, true , true ) ;
1969 if ( MacGetTopLevelWindow() == NULL )
1972 if ( !IsControlVisible( *m_peer ) )
1975 wxPoint client = GetClientAreaOrigin();
1978 int x2 = m_width - client.x;
1979 int y2 = m_height - client.y;
1981 if (IsKindOf( CLASSINFO(wxButton)))
1983 // buttons have an "aura"
1990 Rect clientrect = { y1, x1, y2, x2 };
1994 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1995 SectRect( &clientrect , &r , &clientrect ) ;
1998 if ( !EmptyRect( &clientrect ) )
2000 int top = 0 , left = 0 ;
2002 MacClientToRootWindow( &left , &top ) ;
2003 OffsetRect( &clientrect , left , top ) ;
2005 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2011 void wxWindowMac::Freeze()
2013 #if TARGET_API_MAC_OSX
2014 if ( !m_frozenness
++ )
2016 HIViewSetDrawingEnabled( *m_peer
, false ) ;
2021 #if TARGET_API_MAC_OSX
2022 static void InvalidateControlAndChildren( HIViewRef control
)
2024 HIViewSetNeedsDisplay( control
, true ) ;
2025 UInt16 childrenCount
= 0 ;
2026 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2027 if ( err
== errControlIsNotEmbedder
)
2029 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2031 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2034 err
= GetIndexedSubControl( control
, i
, & child
) ;
2035 if ( err
== errControlIsNotEmbedder
)
2037 InvalidateControlAndChildren( child
) ;
2042 void wxWindowMac::Thaw()
2044 #if TARGET_API_MAC_OSX
2045 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2047 if ( !--m_frozenness
)
2049 HIViewSetDrawingEnabled( *m_peer
, true ) ;
2050 InvalidateControlAndChildren( *m_peer
) ;
2051 // HIViewSetNeedsDisplay( *m_peer , true ) ;
2056 void wxWindowMac::MacRedrawControl()
2059 if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) )
2061 #if TARGET_API_MAC_CARBON
2064 wxClientDC dc(this) ;
2065 wxMacPortSetter helper(&dc) ;
2066 wxMacWindowClipper clipper(this) ;
2067 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2068 UMADrawControl( *m_peer ) ;
2075 void wxWindowMac::OnPaint(wxPaintEvent& event)
2077 // why don't we skip that here ?
2081 wxWindowMac
*wxGetActiveWindow()
2083 // actually this is a windows-only concept
2087 // Coordinates relative to the window
2088 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2090 // We really don't move the mouse programmatically under Mac.
2093 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2095 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2100 event
.GetDC()->Clear() ;
2103 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2105 wxWindowDC
dc(this) ;
2106 wxMacPortSetter
helper(&dc
) ;
2108 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2111 int wxWindowMac::GetScrollPos(int orient
) const
2113 if ( orient
== wxHORIZONTAL
)
2116 return m_hScrollBar
->GetThumbPosition() ;
2121 return m_vScrollBar
->GetThumbPosition() ;
2126 // This now returns the whole range, not just the number
2127 // of positions that we can scroll.
2128 int wxWindowMac::GetScrollRange(int orient
) const
2130 if ( orient
== wxHORIZONTAL
)
2133 return m_hScrollBar
->GetRange() ;
2138 return m_vScrollBar
->GetRange() ;
2143 int wxWindowMac::GetScrollThumb(int orient
) const
2145 if ( orient
== wxHORIZONTAL
)
2148 return m_hScrollBar
->GetThumbSize() ;
2153 return m_vScrollBar
->GetThumbSize() ;
2158 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2160 if ( orient
== wxHORIZONTAL
)
2163 m_hScrollBar
->SetThumbPosition( pos
) ;
2168 m_vScrollBar
->SetThumbPosition( pos
) ;
2172 void wxWindowMac::MacPaintBorders( int left
, int top
)
2178 wxGetOsVersion( &major
, &minor
);
2180 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2181 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2183 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2184 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2185 // OS X has lighter border edges than classic:
2188 darkShadow
.red
= 0x8E8E;
2189 darkShadow
.green
= 0x8E8E;
2190 darkShadow
.blue
= 0x8E8E;
2191 lightShadow
.red
= 0xBDBD;
2192 lightShadow
.green
= 0xBDBD;
2193 lightShadow
.blue
= 0xBDBD;
2199 GetSize( &w
, &h
) ;
2200 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2202 #if wxMAC_USE_THEME_BORDER
2203 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2206 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2207 InsetRect( &rect , border , border );
2208 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2211 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2213 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2214 RGBForeColor( &face
);
2215 MoveTo( left
+ 0 , top
+ h
- 2 );
2216 LineTo( left
+ 0 , top
+ 0 );
2217 LineTo( left
+ w
- 2 , top
+ 0 );
2219 MoveTo( left
+ 2 , top
+ h
- 3 );
2220 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2221 LineTo( left
+ w
- 3 , top
+ 2 );
2223 RGBForeColor( sunken
? &face
: &darkShadow
);
2224 MoveTo( left
+ 0 , top
+ h
- 1 );
2225 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2226 LineTo( left
+ w
- 1 , top
+ 0 );
2228 RGBForeColor( sunken
? &lightShadow
: &white
);
2229 MoveTo( left
+ 1 , top
+ h
- 3 );
2230 LineTo( left
+ 1, top
+ 1 );
2231 LineTo( left
+ w
- 3 , top
+ 1 );
2233 RGBForeColor( sunken
? &white
: &lightShadow
);
2234 MoveTo( left
+ 1 , top
+ h
- 2 );
2235 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2236 LineTo( left
+ w
- 2 , top
+ 1 );
2238 RGBForeColor( sunken
? &darkShadow
: &face
);
2239 MoveTo( left
+ 2 , top
+ h
- 4 );
2240 LineTo( left
+ 2 , top
+ 2 );
2241 LineTo( left
+ w
- 4 , top
+ 2 );
2244 else if (HasFlag(wxSIMPLE_BORDER
))
2246 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2247 RGBForeColor( &darkShadow
) ;
2248 FrameRect( &rect
) ;
2252 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2254 if ( child
== m_hScrollBar
)
2255 m_hScrollBar
= NULL
;
2256 if ( child
== m_vScrollBar
)
2257 m_vScrollBar
= NULL
;
2259 wxWindowBase::RemoveChild( child
) ;
2262 // New function that will replace some of the above.
2263 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2264 int range
, bool refresh
)
2266 if ( orient
== wxHORIZONTAL
)
2270 if ( range
== 0 || thumbVisible
>= range
)
2272 if ( m_hScrollBar
->IsShown() )
2273 m_hScrollBar
->Show(false) ;
2277 if ( !m_hScrollBar
->IsShown() )
2278 m_hScrollBar
->Show(true) ;
2279 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2287 if ( range
== 0 || thumbVisible
>= range
)
2289 if ( m_vScrollBar
->IsShown() )
2290 m_vScrollBar
->Show(false) ;
2294 if ( !m_vScrollBar
->IsShown() )
2295 m_vScrollBar
->Show(true) ;
2296 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2300 MacRepositionScrollBars() ;
2303 // Does a physical scroll
2304 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2306 if( dx
== 0 && dy
==0 )
2312 int width
, height
;
2313 GetClientSize( &width
, &height
) ;
2314 #if TARGET_API_MAC_OSX
2315 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2316 // area is scrolled, this does not occur if width and height are 2 pixels less,
2317 // TODO write optimal workaround
2318 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2321 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2322 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2324 if ( HIViewGetNeedsDisplay( *m_peer
) )
2326 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2327 // either immediate redraw or full invalidate
2329 // is the better overall solution, as it does not slow down scrolling
2330 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2332 // this would be the preferred version for fast drawing controls
2333 if( UMAGetSystemVersion() < 0x1030 )
2336 HIViewRender(*m_peer
) ;
2339 HIViewScrollRect ( *m_peer
, &scrollrect
, dx
,dy
) ;
2346 RgnHandle updateRgn
= NewRgn() ;
2349 wxClientDC
dc(this) ;
2350 wxMacPortSetter
helper(&dc
) ;
2352 GetControlBounds( *m_peer
, &scrollrect
);
2353 scrollrect
.top
+= MacGetTopBorderSize() ;
2354 scrollrect
.left
+= MacGetLeftBorderSize() ;
2355 scrollrect
.bottom
= scrollrect
.top
+ height
;
2356 scrollrect
.right
= scrollrect
.left
+ width
;
2360 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2361 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2362 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2364 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2366 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2370 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2372 wxWindowMac
*child
= node
->GetData();
2373 if (child
== m_vScrollBar
) continue;
2374 if (child
== m_hScrollBar
) continue;
2375 if (child
->IsTopLevel()) continue;
2378 child
->GetPosition( &x
, &y
);
2380 child
->GetSize( &w
, &h
);
2384 if (rect
->Intersects(rc
))
2385 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2389 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2394 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2396 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2398 wxScrollWinEvent wevent
;
2399 wevent
.SetPosition(event
.GetPosition());
2400 wevent
.SetOrientation(event
.GetOrientation());
2401 wevent
.m_eventObject
= this;
2403 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2404 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2405 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2406 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2407 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2408 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2409 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2410 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2411 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2412 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2413 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2414 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2415 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2416 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2417 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2418 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2420 GetEventHandler()->ProcessEvent(wevent
);
2424 // Get the window with the focus
2425 wxWindowMac
*wxWindowBase::FindFocus()
2427 ControlRef control
;
2428 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2429 return wxFindControlFromMacControl( control
) ;
2432 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2434 // panel wants to track the window which was the last to have focus in it,
2435 // so we want to set ourselves as the window which last had focus
2437 // notice that it's also important to do it upwards the tree becaus
2438 // otherwise when the top level panel gets focus, it won't set it back to
2439 // us, but to some other sibling
2441 // CS:don't know if this is still needed:
2442 //wxChildFocusEvent eventFocus(this);
2443 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2448 void wxWindowMac::OnInternalIdle()
2450 // This calls the UI-update mechanism (querying windows for
2451 // menu/toolbar/control state information)
2452 if (wxUpdateUIEvent::CanUpdate(this))
2453 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2456 // Raise the window to the top of the Z order
2457 void wxWindowMac::Raise()
2459 #if TARGET_API_MAC_OSX
2460 HIViewSetZOrder(*m_peer
,kHIViewZOrderAbove
, NULL
) ;
2464 // Lower the window to the bottom of the Z order
2465 void wxWindowMac::Lower()
2467 #if TARGET_API_MAC_OSX
2468 HIViewSetZOrder(*m_peer
,kHIViewZOrderBelow
, NULL
) ;
2473 // static wxWindow *gs_lastWhich = NULL;
2475 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2477 // first trigger a set cursor event
2479 wxPoint clientorigin
= GetClientAreaOrigin() ;
2480 wxSize clientsize
= GetClientSize() ;
2482 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2484 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2486 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2487 if ( processedEvtSetCursor
&& event
.HasCursor() )
2489 cursor
= event
.GetCursor() ;
2494 // the test for processedEvtSetCursor is here to prevent using m_cursor
2495 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2496 // it - this is a way to say that our cursor shouldn't be used for this
2498 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2508 cursor
= *wxSTANDARD_CURSOR
;
2512 cursor
.MacInstall() ;
2514 return cursor
.Ok() ;
2517 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2521 return m_tooltip
->GetTip() ;
2523 return wxEmptyString
;
2526 void wxWindowMac::Update()
2528 #if TARGET_API_MAC_OSX
2529 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2530 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2531 // for composited windows this also triggers a redraw of all
2532 // invalid views in the window
2533 if( UMAGetSystemVersion() >= 0x1030 )
2534 HIWindowFlush(window
) ;
2538 // the only way to trigger the redrawing on earlier systems is to call
2541 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2542 UInt32 currentEventClass
= 0 ;
2543 UInt32 currentEventKind
= 0 ;
2544 if ( currentEvent
!= NULL
)
2546 currentEventClass
= ::GetEventClass( currentEvent
) ;
2547 currentEventKind
= ::GetEventKind( currentEvent
) ;
2549 if ( currentEventClass
!= kEventClassMenu
)
2551 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2554 OSStatus status
= noErr
;
2555 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2558 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2561 ::Draw1Control( *m_peer
) ;
2565 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2567 wxTopLevelWindowMac
* win
= NULL
;
2568 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2571 win
= wxFindWinFromMacWindow( window
) ;
2575 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2579 RgnHandle visRgn
= NewRgn() ;
2580 RgnHandle tempRgn
= NewRgn() ;
2581 if ( IsControlVisible( *m_peer
) )
2583 GetControlBounds( *m_peer
, &r
) ;
2584 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2586 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2587 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2596 if ( includeOuterStructures
)
2597 InsetRect( &r
, -3 , -3 ) ;
2598 RectRgn( visRgn
, &r
) ;
2599 if ( !IsTopLevel() )
2601 wxWindow
* child
= this ;
2602 wxWindow
* parent
= child
->GetParent() ;
2607 // we have to find a better clipping algorithm here, in order not to clip things
2608 // positioned like status and toolbar
2609 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2611 size
= parent
->GetSize() ;
2616 size
= parent
->GetClientSize() ;
2617 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2621 parent
->MacWindowToRootWindow( &x
, &y
) ;
2622 MacRootWindowToWindow( &x
, &y
) ;
2624 SetRectRgn( tempRgn
,
2625 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2626 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2627 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2629 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2630 if ( parent
->IsTopLevel() )
2633 parent
= child
->GetParent() ;
2638 wxRegion vis
= visRgn
;
2639 DisposeRgn( visRgn
) ;
2640 DisposeRgn( tempRgn
) ;
2645 This function must not change the updatergn !
2647 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2649 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2650 bool handled
= false ;
2652 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2654 RgnHandle newupdate
= NewRgn() ;
2655 wxSize point
= GetClientSize() ;
2656 wxPoint origin
= GetClientAreaOrigin() ;
2657 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2658 SectRgn( newupdate
, updatergn
, newupdate
) ;
2659 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2660 m_updateRegion
= newupdate
;
2661 DisposeRgn( newupdate
) ;
2664 if ( !EmptyRgn(updatergn
) )
2666 wxWindowDC
dc(this);
2667 if (!EmptyRgn(updatergn
))
2668 dc
.SetClippingRegion(wxRegion(updatergn
));
2670 wxEraseEvent
eevent( GetId(), &dc
);
2671 eevent
.SetEventObject( this );
2672 GetEventHandler()->ProcessEvent( eevent
);
2674 if ( !m_updateRegion
.Empty() )
2676 // paint the window itself
2678 event
.m_timeStamp
= time
;
2679 event
.SetEventObject(this);
2680 handled
= GetEventHandler()->ProcessEvent(event
);
2682 // paint custom borders
2683 wxNcPaintEvent
eventNc( GetId() );
2684 eventNc
.SetEventObject( this );
2685 GetEventHandler()->ProcessEvent( eventNc
);
2691 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2693 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2694 // updatergn is always already clipped to our boundaries
2695 // if we are in compositing mode then it is in relative to the upper left of the control
2696 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2697 // of the toplevel window
2698 // it is in window coordinates, not in client coordinates
2700 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2701 RgnHandle ownUpdateRgn
= NewRgn() ;
2702 CopyRgn( updatergn
, ownUpdateRgn
) ;
2704 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2707 UMAGetControlBoundsInWindowCoords( *m_peer
, &bounds
);
2708 RgnHandle controlRgn
= NewRgn();
2709 RectRgn( controlRgn
, &bounds
);
2710 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2711 // the window update region
2712 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2713 DisposeRgn( controlRgn
);
2715 //KO: convert ownUpdateRgn to local coordinates
2716 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2719 MacDoRedraw( ownUpdateRgn
, time
) ;
2720 DisposeRgn( ownUpdateRgn
) ;
2724 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2726 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2730 if ( iter
->IsTopLevel() )
2731 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2733 iter
= iter
->GetParent() ;
2735 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2739 void wxWindowMac::MacCreateScrollBars( long style
)
2741 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2743 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2744 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2746 GetClientSize( &width
, &height
) ;
2748 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2749 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2750 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2751 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2753 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2754 vSize
, wxVERTICAL
);
2756 if ( style
& wxVSCROLL
)
2762 m_vScrollBar
->Show(false) ;
2764 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2765 hSize
, wxHORIZONTAL
);
2766 if ( style
& wxHSCROLL
)
2771 m_hScrollBar
->Show(false) ;
2774 // because the create does not take into account the client area origin
2775 MacRepositionScrollBars() ; // we might have a real position shift
2778 void wxWindowMac::MacRepositionScrollBars()
2780 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2781 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2783 // get real client area
2787 GetSize( &width
, &height
) ;
2789 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2790 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2792 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2793 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2794 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2795 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2801 GetSize( &w
, &h
) ;
2803 MacClientToRootWindow( &x
, &y
) ;
2804 MacClientToRootWindow( &w
, &h
) ;
2806 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2808 int totW
= 10000 , totH
= 10000;
2811 if ( iter
->IsTopLevel() )
2813 iter
->GetSize( &totW
, &totH
) ;
2817 iter
= iter
->GetParent() ;
2845 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2849 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2853 bool wxWindowMac::AcceptsFocus() const
2855 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2858 void wxWindowMac::MacSuperChangedPosition()
2860 // only window-absolute structures have to be moved i.e. controls
2862 wxWindowListNode
*node
= GetChildren().GetFirst();
2865 wxWindowMac
*child
= node
->GetData();
2866 child
->MacSuperChangedPosition() ;
2867 node
= node
->GetNext();
2871 void wxWindowMac::MacTopLevelWindowChangedPosition()
2873 // only screen-absolute structures have to be moved i.e. glcanvas
2875 wxWindowListNode
*node
= GetChildren().GetFirst();
2878 wxWindowMac
*child
= node
->GetData();
2879 child
->MacTopLevelWindowChangedPosition() ;
2880 node
= node
->GetNext();
2884 long wxWindowMac::MacGetLeftBorderSize( ) const
2889 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2892 #if wxMAC_USE_THEME_BORDER
2893 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2897 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2900 #if wxMAC_USE_THEME_BORDER
2901 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2905 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2912 long wxWindowMac::MacGetRightBorderSize( ) const
2914 // they are all symmetric in mac themes
2915 return MacGetLeftBorderSize() ;
2918 long wxWindowMac::MacGetTopBorderSize( ) const
2920 // they are all symmetric in mac themes
2921 return MacGetLeftBorderSize() ;
2924 long wxWindowMac::MacGetBottomBorderSize( ) const
2926 // they are all symmetric in mac themes
2927 return MacGetLeftBorderSize() ;
2930 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2932 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2935 // Find the wxWindowMac at the current mouse position, returning the mouse
2937 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2939 pt
= wxGetMousePosition();
2940 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2944 // Get the current mouse position.
2945 wxPoint
wxGetMousePosition()
2948 wxGetMousePosition(& x
, & y
);
2949 return wxPoint(x
, y
);
2952 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2954 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2956 // copied from wxGTK : CS
2957 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2960 // (a) it's a command event and so is propagated to the parent
2961 // (b) under MSW it can be generated from kbd too
2962 // (c) it uses screen coords (because of (a))
2963 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2965 this->ClientToScreen(event
.GetPosition()));
2966 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2975 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2979 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2983 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2984 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2988 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2990 return eventNotHandledErr
;