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() )
1208 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1210 HIViewConvertPoint( &pt
, *m_peer
, (ControlRef
) top
->GetHandle() ) ;
1213 if ( x
) *x
= (int) pt
.x
;
1214 if ( y
) *y
= (int) pt
.y
;
1216 if ( !IsTopLevel() )
1219 GetControlBounds( *m_peer
, &bounds
) ;
1220 if(x
) *x
+= bounds
.left
;
1221 if(y
) *y
+= bounds
.top
;
1226 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1231 MacWindowToRootWindow( &x1
, &y1
) ;
1236 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1238 #if TARGET_API_MAC_OSX
1240 if ( x
) pt
.x
= *x
;
1241 if ( y
) pt
.y
= *y
;
1243 if ( !IsTopLevel() )
1244 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , *m_peer
) ;
1246 if ( x
) *x
= (int) pt
.x
;
1247 if ( y
) *y
= (int) pt
.y
;
1249 if ( !IsTopLevel() )
1252 GetControlBounds( *m_peer
, &bounds
) ;
1253 if(x
) *x
-= bounds
.left
;
1254 if(y
) *y
-= bounds
.top
;
1259 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1264 MacRootWindowToWindow( &x1
, &y1
) ;
1269 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1271 RgnHandle rgn
= NewRgn() ;
1273 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1275 GetRegionBounds( rgn
, &content
) ;
1280 GetControlBounds( *m_peer
, &content
) ;
1283 GetControlBounds( *m_peer
, &structure
) ;
1284 #if !TARGET_API_MAC_OSX
1285 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1287 left
= content
.left
- structure
.left
;
1288 top
= content
.top
- structure
.top
;
1289 right
= structure
.right
- content
.right
;
1290 bottom
= structure
.bottom
- content
.bottom
;
1293 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1295 wxSize sizeTotal
= size
;
1297 RgnHandle rgn
= NewRgn() ;
1301 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1303 GetRegionBounds( rgn
, &content
) ;
1308 GetControlBounds( *m_peer
, &content
) ;
1311 GetControlBounds( *m_peer
, &structure
) ;
1312 #if !TARGET_API_MAC_OSX
1313 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1316 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1317 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1319 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1320 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1326 // Get size *available for subwindows* i.e. excluding menu bar etc.
1327 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1331 RgnHandle rgn
= NewRgn() ;
1333 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1335 GetRegionBounds( rgn
, &content
) ;
1340 GetControlBounds( *m_peer
, &content
) ;
1342 #if !TARGET_API_MAC_OSX
1344 GetControlBounds( *m_peer
, &structure
) ;
1345 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1347 ww
= content
.right
- content
.left
;
1348 hh
= content
.bottom
- content
.top
;
1350 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1351 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1353 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1359 GetSize( &w
, &h
) ;
1361 MacClientToRootWindow( &x1
, &y1
) ;
1362 MacClientToRootWindow( &w
, &h
) ;
1364 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1366 int totW
= 10000 , totH
= 10000;
1369 if ( iter
->IsTopLevel() )
1371 iter
->GetSize( &totW
, &totH
) ;
1375 iter
= iter
->GetParent() ;
1378 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1380 hh
-= MAC_SCROLLBAR_SIZE
;
1386 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1388 ww
-= MAC_SCROLLBAR_SIZE
;
1400 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1402 if (m_cursor
== cursor
)
1405 if (wxNullCursor
== cursor
)
1407 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1412 if ( ! wxWindowBase::SetCursor( cursor
) )
1416 wxASSERT_MSG( m_cursor
.Ok(),
1417 wxT("cursor must be valid after call to the base version"));
1421 TODO why do we have to use current coordinates ?
1424 wxWindowMac *mouseWin ;
1427 // Change the cursor NOW if we're within the correct window
1430 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1432 if ( mouseWin == this && !wxIsBusy() )
1434 m_cursor.MacInstall() ;
1440 m_cursor
.MacInstall() ;
1447 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1449 menu
->SetInvokingWindow(this);
1452 if ( x
== -1 && y
== -1 )
1454 wxPoint mouse
= wxGetMousePosition();
1455 x
= mouse
.x
; y
= mouse
.y
;
1459 ClientToScreen( &x
, &y
) ;
1462 menu
->MacBeforeDisplay( true ) ;
1463 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1464 if ( HiWord(menuResult
) != 0 )
1467 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1468 wxMenuItem
* item
= NULL
;
1470 item
= menu
->FindItem(id
, &realmenu
) ;
1471 if (item
->IsCheckable())
1473 item
->Check( !item
->IsChecked() ) ;
1475 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1477 menu
->MacAfterDisplay( true ) ;
1479 menu
->SetInvokingWindow(NULL
);
1485 // ----------------------------------------------------------------------------
1487 // ----------------------------------------------------------------------------
1491 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1493 wxWindowBase::DoSetToolTip(tooltip
);
1496 m_tooltip
->SetWindow(this);
1499 #endif // wxUSE_TOOLTIPS
1501 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1503 int former_x
, former_y
, former_w
, former_h
;
1504 #if !TARGET_API_MAC_OSX
1505 DoGetPosition( &former_x
, &former_y
) ;
1506 DoGetSize( &former_w
, &former_h
) ;
1508 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1511 int actualWidth
= width
;
1512 int actualHeight
= height
;
1516 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1517 actualWidth
= m_minWidth
;
1518 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1519 actualHeight
= m_minHeight
;
1520 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1521 actualWidth
= m_maxWidth
;
1522 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1523 actualHeight
= m_maxHeight
;
1525 bool doMove
= false ;
1526 bool doResize
= false ;
1528 if ( actualX
!= former_x
|| actualY
!= former_y
)
1532 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1537 if ( doMove
|| doResize
)
1539 // we don't adjust twice for the origin
1540 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1541 bool vis
= IsControlVisible( *m_peer
) ;
1542 #if TARGET_API_MAC_OSX
1543 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1545 SetControlVisibility( *m_peer
, false , true ) ;
1546 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1547 HIViewSetFrame ( *m_peer
, &hir
) ;
1549 SetControlVisibility( *m_peer
, true , true ) ;
1552 SetControlVisibility( *m_peer
, false , true ) ;
1553 SetControlBounds( *m_peer
, &r
) ;
1555 SetControlVisibility( *m_peer
, true , true ) ;
1557 MacRepositionScrollBars() ;
1560 wxPoint
point(actualX
,actualY
);
1561 wxMoveEvent
event(point
, m_windowId
);
1562 event
.SetEventObject(this);
1563 GetEventHandler()->ProcessEvent(event
) ;
1567 MacRepositionScrollBars() ;
1568 wxSize
size(actualWidth
, actualHeight
);
1569 wxSizeEvent
event(size
, m_windowId
);
1570 event
.SetEventObject(this);
1571 GetEventHandler()->ProcessEvent(event
);
1577 wxSize
wxWindowMac::DoGetBestSize() const
1579 if ( m_macIsUserPane
|| IsTopLevel() )
1580 return wxWindowBase::DoGetBestSize() ;
1582 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1583 short baselineoffset
;
1584 int bestWidth
, bestHeight
;
1585 ::GetBestControlRect( *m_peer
, &bestsize
, &baselineoffset
) ;
1587 if ( EmptyRect( &bestsize
) )
1590 bestsize
.left
= bestsize
.top
= 0 ;
1591 bestsize
.right
= 16 ;
1592 bestsize
.bottom
= 16 ;
1593 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1595 bestsize
.bottom
= 16 ;
1597 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1599 bestsize
.bottom
= 24 ;
1603 // return wxWindowBase::DoGetBestSize() ;
1607 bestWidth
= bestsize
.right
- bestsize
.left
;
1608 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1609 if ( bestHeight
< 10 )
1612 return wxSize(bestWidth
, bestHeight
);
1613 // return wxWindowBase::DoGetBestSize() ;
1617 // set the size of the window: if the dimensions are positive, just use them,
1618 // but if any of them is equal to -1, it means that we must find the value for
1619 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1620 // which case -1 is a valid value for x and y)
1622 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1623 // the width/height to best suit our contents, otherwise we reuse the current
1625 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1627 // get the current size and position...
1628 int currentX
, currentY
;
1629 GetPosition(¤tX
, ¤tY
);
1631 int currentW
,currentH
;
1632 GetSize(¤tW
, ¤tH
);
1634 // ... and don't do anything (avoiding flicker) if it's already ok
1635 if ( x
== currentX
&& y
== currentY
&&
1636 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1639 MacRepositionScrollBars() ; // we might have a real position shift
1643 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1645 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1648 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1650 wxSize
size(-1, -1);
1653 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1655 size
= DoGetBestSize();
1660 // just take the current one
1667 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1671 size
= DoGetBestSize();
1673 //else: already called DoGetBestSize() above
1679 // just take the current one
1684 DoMoveWindow(x
, y
, width
, height
);
1688 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1690 RgnHandle rgn
= NewRgn() ;
1692 GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) ;
1693 GetRegionBounds( rgn
, &content
) ;
1695 #if !TARGET_API_MAC_OSX
1696 // if the content rgn is empty / not supported
1697 // don't attempt to correct the coordinates to wxWindow relative ones
1698 if (!::EmptyRect( &content
) )
1701 GetControlBounds( *m_peer
, &structure
) ;
1702 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1706 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1709 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1711 if ( clientheight
!= -1 || clientheight
!= -1 )
1713 int currentclientwidth
, currentclientheight
;
1714 int currentwidth
, currentheight
;
1716 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1717 GetSize( ¤twidth
, ¤theight
) ;
1719 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1720 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1724 void wxWindowMac::SetTitle(const wxString
& title
)
1726 m_label
= wxStripMenuCodes(title
) ;
1728 if ( m_peer
&& m_peer
->Ok() )
1730 UMASetControlTitle( *m_peer
, m_label
, m_font
.GetEncoding() ) ;
1735 wxString
wxWindowMac::GetTitle() const
1740 bool wxWindowMac::Show(bool show
)
1742 if ( !wxWindowBase::Show(show
) )
1745 // TODO use visibilityChanged Carbon Event for OSX
1746 bool former
= MacIsReallyShown() ;
1748 SetControlVisibility( *m_peer
, show
, true ) ;
1749 if ( former
!= MacIsReallyShown() )
1750 MacPropagateVisibilityChanged() ;
1754 bool wxWindowMac::Enable(bool enable
)
1756 wxASSERT( m_peer
->Ok() ) ;
1757 if ( !wxWindowBase::Enable(enable
) )
1760 bool former
= MacIsReallyEnabled() ;
1761 #if TARGET_API_MAC_OSX
1763 EnableControl( *m_peer
) ;
1765 DisableControl( *m_peer
) ;
1768 ActivateControl( *m_peer
) ;
1770 DeactivateControl( *m_peer
) ;
1773 if ( former
!= MacIsReallyEnabled() )
1774 MacPropagateEnabledStateChanged() ;
1779 // status change propagations (will be not necessary for OSX later )
1782 void wxWindowMac::MacPropagateVisibilityChanged()
1784 #if !TARGET_API_MAC_OSX
1785 MacVisibilityChanged() ;
1787 wxWindowListNode
*node
= GetChildren().GetFirst();
1790 wxWindowMac
*child
= node
->GetData();
1791 if ( child
->IsShown() )
1792 child
->MacPropagateVisibilityChanged( ) ;
1793 node
= node
->GetNext();
1798 void wxWindowMac::MacPropagateEnabledStateChanged( )
1800 #if !TARGET_API_MAC_OSX
1801 MacEnabledStateChanged() ;
1803 wxWindowListNode
*node
= GetChildren().GetFirst();
1806 wxWindowMac
*child
= node
->GetData();
1807 if ( child
->IsEnabled() )
1808 child
->MacPropagateEnabledStateChanged() ;
1809 node
= node
->GetNext();
1814 void wxWindowMac::MacPropagateHiliteChanged( )
1816 #if !TARGET_API_MAC_OSX
1817 MacHiliteChanged() ;
1819 wxWindowListNode
*node
= GetChildren().GetFirst();
1822 wxWindowMac
*child
= node
->GetData();
1823 // if ( child->IsEnabled() )
1824 child
->MacPropagateHiliteChanged() ;
1825 node
= node
->GetNext();
1831 // status change notifications
1834 void wxWindowMac::MacVisibilityChanged()
1838 void wxWindowMac::MacHiliteChanged()
1842 void wxWindowMac::MacEnabledStateChanged()
1847 // status queries on the inherited window's state
1850 bool wxWindowMac::MacIsReallyShown()
1852 // only under OSX the visibility of the TLW is taken into account
1853 #if TARGET_API_MAC_OSX
1854 return IsControlVisible( *m_peer
) ;
1856 wxWindow
* win
= this ;
1857 while( win
->IsShown() )
1859 if ( win
->IsTopLevel() )
1862 win
= win
->GetParent() ;
1871 bool wxWindowMac::MacIsReallyEnabled()
1873 #if TARGET_API_MAC_OSX
1874 return IsControlEnabled( *m_peer
) ;
1876 return IsControlActive( *m_peer
) ;
1880 bool wxWindowMac::MacIsReallyHilited()
1882 return IsControlActive( *m_peer
) ;
1885 void wxWindowMac::MacFlashInvalidAreas()
1887 #if TARGET_API_MAC_OSX
1888 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1896 int wxWindowMac::GetCharHeight() const
1898 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1899 return dc
.GetCharHeight() ;
1902 int wxWindowMac::GetCharWidth() const
1904 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1905 return dc
.GetCharWidth() ;
1908 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1909 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1911 const wxFont
*fontToUse
= theFont
;
1913 fontToUse
= &m_font
;
1915 wxClientDC
dc( (wxWindowMac
*) this ) ;
1917 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1918 if ( externalLeading
)
1919 *externalLeading
= le
;
1929 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1930 * we always intersect with the entire window, not only with the client area
1933 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1935 #if TARGET_API_MAC_OSX
1937 HIViewSetNeedsDisplay( *m_peer
, true ) ;
1940 RgnHandle update
= NewRgn() ;
1941 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1942 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1943 wxPoint origin
= GetClientAreaOrigin() ;
1944 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1945 HIViewSetNeedsDisplayInRegion( *m_peer
, update
, true ) ;
1949 RgnHandle updateRgn = NewRgn() ;
1952 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1956 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1957 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1959 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1960 DisposeRgn(updateRgn) ;
1962 if ( IsControlVisible( *m_peer
) )
1964 SetControlVisibility( *m_peer
, false , false ) ;
1965 SetControlVisibility( *m_peer
, true , true ) ;
1968 if ( MacGetTopLevelWindow() == NULL )
1971 if ( !IsControlVisible( *m_peer ) )
1974 wxPoint client = GetClientAreaOrigin();
1977 int x2 = m_width - client.x;
1978 int y2 = m_height - client.y;
1980 if (IsKindOf( CLASSINFO(wxButton)))
1982 // buttons have an "aura"
1989 Rect clientrect = { y1, x1, y2, x2 };
1993 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1994 SectRect( &clientrect , &r , &clientrect ) ;
1997 if ( !EmptyRect( &clientrect ) )
1999 int top = 0 , left = 0 ;
2001 MacClientToRootWindow( &left , &top ) ;
2002 OffsetRect( &clientrect , left , top ) ;
2004 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2010 void wxWindowMac::Freeze()
2012 #if TARGET_API_MAC_OSX
2013 if ( !m_frozenness
++ )
2015 HIViewSetDrawingEnabled( *m_peer
, false ) ;
2020 #if TARGET_API_MAC_OSX
2021 static void InvalidateControlAndChildren( HIViewRef control
)
2023 HIViewSetNeedsDisplay( control
, true ) ;
2024 UInt16 childrenCount
= 0 ;
2025 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2026 if ( err
== errControlIsNotEmbedder
)
2028 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2030 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2033 err
= GetIndexedSubControl( control
, i
, & child
) ;
2034 if ( err
== errControlIsNotEmbedder
)
2036 InvalidateControlAndChildren( child
) ;
2041 void wxWindowMac::Thaw()
2043 #if TARGET_API_MAC_OSX
2044 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2046 if ( !--m_frozenness
)
2048 HIViewSetDrawingEnabled( *m_peer
, true ) ;
2049 InvalidateControlAndChildren( *m_peer
) ;
2050 // HIViewSetNeedsDisplay( *m_peer , true ) ;
2055 void wxWindowMac::MacRedrawControl()
2058 if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) )
2060 #if TARGET_API_MAC_CARBON
2063 wxClientDC dc(this) ;
2064 wxMacPortSetter helper(&dc) ;
2065 wxMacWindowClipper clipper(this) ;
2066 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2067 UMADrawControl( *m_peer ) ;
2074 void wxWindowMac::OnPaint(wxPaintEvent& event)
2076 // why don't we skip that here ?
2080 wxWindowMac
*wxGetActiveWindow()
2082 // actually this is a windows-only concept
2086 // Coordinates relative to the window
2087 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2089 // We really don't move the mouse programmatically under Mac.
2092 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2094 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2099 event
.GetDC()->Clear() ;
2102 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2104 wxWindowDC
dc(this) ;
2105 wxMacPortSetter
helper(&dc
) ;
2107 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2110 int wxWindowMac::GetScrollPos(int orient
) const
2112 if ( orient
== wxHORIZONTAL
)
2115 return m_hScrollBar
->GetThumbPosition() ;
2120 return m_vScrollBar
->GetThumbPosition() ;
2125 // This now returns the whole range, not just the number
2126 // of positions that we can scroll.
2127 int wxWindowMac::GetScrollRange(int orient
) const
2129 if ( orient
== wxHORIZONTAL
)
2132 return m_hScrollBar
->GetRange() ;
2137 return m_vScrollBar
->GetRange() ;
2142 int wxWindowMac::GetScrollThumb(int orient
) const
2144 if ( orient
== wxHORIZONTAL
)
2147 return m_hScrollBar
->GetThumbSize() ;
2152 return m_vScrollBar
->GetThumbSize() ;
2157 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2159 if ( orient
== wxHORIZONTAL
)
2162 m_hScrollBar
->SetThumbPosition( pos
) ;
2167 m_vScrollBar
->SetThumbPosition( pos
) ;
2171 void wxWindowMac::MacPaintBorders( int left
, int top
)
2177 wxGetOsVersion( &major
, &minor
);
2179 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2180 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2182 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2183 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2184 // OS X has lighter border edges than classic:
2187 darkShadow
.red
= 0x8E8E;
2188 darkShadow
.green
= 0x8E8E;
2189 darkShadow
.blue
= 0x8E8E;
2190 lightShadow
.red
= 0xBDBD;
2191 lightShadow
.green
= 0xBDBD;
2192 lightShadow
.blue
= 0xBDBD;
2198 GetSize( &w
, &h
) ;
2199 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2201 #if wxMAC_USE_THEME_BORDER
2202 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2205 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2206 InsetRect( &rect , border , border );
2207 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2210 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2212 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2213 RGBForeColor( &face
);
2214 MoveTo( left
+ 0 , top
+ h
- 2 );
2215 LineTo( left
+ 0 , top
+ 0 );
2216 LineTo( left
+ w
- 2 , top
+ 0 );
2218 MoveTo( left
+ 2 , top
+ h
- 3 );
2219 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2220 LineTo( left
+ w
- 3 , top
+ 2 );
2222 RGBForeColor( sunken
? &face
: &darkShadow
);
2223 MoveTo( left
+ 0 , top
+ h
- 1 );
2224 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2225 LineTo( left
+ w
- 1 , top
+ 0 );
2227 RGBForeColor( sunken
? &lightShadow
: &white
);
2228 MoveTo( left
+ 1 , top
+ h
- 3 );
2229 LineTo( left
+ 1, top
+ 1 );
2230 LineTo( left
+ w
- 3 , top
+ 1 );
2232 RGBForeColor( sunken
? &white
: &lightShadow
);
2233 MoveTo( left
+ 1 , top
+ h
- 2 );
2234 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2235 LineTo( left
+ w
- 2 , top
+ 1 );
2237 RGBForeColor( sunken
? &darkShadow
: &face
);
2238 MoveTo( left
+ 2 , top
+ h
- 4 );
2239 LineTo( left
+ 2 , top
+ 2 );
2240 LineTo( left
+ w
- 4 , top
+ 2 );
2243 else if (HasFlag(wxSIMPLE_BORDER
))
2245 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2246 RGBForeColor( &darkShadow
) ;
2247 FrameRect( &rect
) ;
2251 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2253 if ( child
== m_hScrollBar
)
2254 m_hScrollBar
= NULL
;
2255 if ( child
== m_vScrollBar
)
2256 m_vScrollBar
= NULL
;
2258 wxWindowBase::RemoveChild( child
) ;
2261 // New function that will replace some of the above.
2262 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2263 int range
, bool refresh
)
2265 if ( orient
== wxHORIZONTAL
)
2269 if ( range
== 0 || thumbVisible
>= range
)
2271 if ( m_hScrollBar
->IsShown() )
2272 m_hScrollBar
->Show(false) ;
2276 if ( !m_hScrollBar
->IsShown() )
2277 m_hScrollBar
->Show(true) ;
2278 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2286 if ( range
== 0 || thumbVisible
>= range
)
2288 if ( m_vScrollBar
->IsShown() )
2289 m_vScrollBar
->Show(false) ;
2293 if ( !m_vScrollBar
->IsShown() )
2294 m_vScrollBar
->Show(true) ;
2295 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2299 MacRepositionScrollBars() ;
2302 // Does a physical scroll
2303 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2305 if( dx
== 0 && dy
==0 )
2311 int width
, height
;
2312 GetClientSize( &width
, &height
) ;
2313 #if TARGET_API_MAC_OSX
2314 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2315 // area is scrolled, this does not occur if width and height are 2 pixels less,
2316 // TODO write optimal workaround
2317 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2320 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2321 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2323 if ( HIViewGetNeedsDisplay( *m_peer
) )
2325 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2326 // either immediate redraw or full invalidate
2328 // is the better overall solution, as it does not slow down scrolling
2329 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2331 // this would be the preferred version for fast drawing controls
2332 if( UMAGetSystemVersion() < 0x1030 )
2335 HIViewRender(*m_peer
) ;
2338 HIViewScrollRect ( *m_peer
, &scrollrect
, dx
,dy
) ;
2345 RgnHandle updateRgn
= NewRgn() ;
2348 wxClientDC
dc(this) ;
2349 wxMacPortSetter
helper(&dc
) ;
2351 GetControlBounds( *m_peer
, &scrollrect
);
2352 scrollrect
.top
+= MacGetTopBorderSize() ;
2353 scrollrect
.left
+= MacGetLeftBorderSize() ;
2354 scrollrect
.bottom
= scrollrect
.top
+ height
;
2355 scrollrect
.right
= scrollrect
.left
+ width
;
2359 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2360 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2361 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2363 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2365 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2369 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2371 wxWindowMac
*child
= node
->GetData();
2372 if (child
== m_vScrollBar
) continue;
2373 if (child
== m_hScrollBar
) continue;
2374 if (child
->IsTopLevel()) continue;
2377 child
->GetPosition( &x
, &y
);
2379 child
->GetSize( &w
, &h
);
2383 if (rect
->Intersects(rc
))
2384 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2388 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2393 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2395 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2397 wxScrollWinEvent wevent
;
2398 wevent
.SetPosition(event
.GetPosition());
2399 wevent
.SetOrientation(event
.GetOrientation());
2400 wevent
.m_eventObject
= this;
2402 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2403 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2404 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2405 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2406 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2407 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2408 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2409 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2410 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2411 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2412 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2413 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2414 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2415 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2416 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2417 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2419 GetEventHandler()->ProcessEvent(wevent
);
2423 // Get the window with the focus
2424 wxWindowMac
*wxWindowBase::FindFocus()
2426 ControlRef control
;
2427 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2428 return wxFindControlFromMacControl( control
) ;
2431 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2433 // panel wants to track the window which was the last to have focus in it,
2434 // so we want to set ourselves as the window which last had focus
2436 // notice that it's also important to do it upwards the tree becaus
2437 // otherwise when the top level panel gets focus, it won't set it back to
2438 // us, but to some other sibling
2440 // CS:don't know if this is still needed:
2441 //wxChildFocusEvent eventFocus(this);
2442 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2447 void wxWindowMac::OnInternalIdle()
2449 // This calls the UI-update mechanism (querying windows for
2450 // menu/toolbar/control state information)
2451 if (wxUpdateUIEvent::CanUpdate(this))
2452 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2455 // Raise the window to the top of the Z order
2456 void wxWindowMac::Raise()
2458 #if TARGET_API_MAC_OSX
2459 HIViewSetZOrder(*m_peer
,kHIViewZOrderAbove
, NULL
) ;
2463 // Lower the window to the bottom of the Z order
2464 void wxWindowMac::Lower()
2466 #if TARGET_API_MAC_OSX
2467 HIViewSetZOrder(*m_peer
,kHIViewZOrderBelow
, NULL
) ;
2472 // static wxWindow *gs_lastWhich = NULL;
2474 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2476 // first trigger a set cursor event
2478 wxPoint clientorigin
= GetClientAreaOrigin() ;
2479 wxSize clientsize
= GetClientSize() ;
2481 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2483 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2485 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2486 if ( processedEvtSetCursor
&& event
.HasCursor() )
2488 cursor
= event
.GetCursor() ;
2493 // the test for processedEvtSetCursor is here to prevent using m_cursor
2494 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2495 // it - this is a way to say that our cursor shouldn't be used for this
2497 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2507 cursor
= *wxSTANDARD_CURSOR
;
2511 cursor
.MacInstall() ;
2513 return cursor
.Ok() ;
2516 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2520 return m_tooltip
->GetTip() ;
2522 return wxEmptyString
;
2525 void wxWindowMac::Update()
2527 #if TARGET_API_MAC_OSX
2528 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2529 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2530 // for composited windows this also triggers a redraw of all
2531 // invalid views in the window
2532 if( UMAGetSystemVersion() >= 0x1030 )
2533 HIWindowFlush(window
) ;
2537 // the only way to trigger the redrawing on earlier systems is to call
2540 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2541 UInt32 currentEventClass
= 0 ;
2542 UInt32 currentEventKind
= 0 ;
2543 if ( currentEvent
!= NULL
)
2545 currentEventClass
= ::GetEventClass( currentEvent
) ;
2546 currentEventKind
= ::GetEventKind( currentEvent
) ;
2548 if ( currentEventClass
!= kEventClassMenu
)
2550 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2553 OSStatus status
= noErr
;
2554 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2557 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2560 ::Draw1Control( *m_peer
) ;
2564 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2566 wxTopLevelWindowMac
* win
= NULL
;
2567 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2570 win
= wxFindWinFromMacWindow( window
) ;
2574 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2578 RgnHandle visRgn
= NewRgn() ;
2579 RgnHandle tempRgn
= NewRgn() ;
2580 if ( IsControlVisible( *m_peer
) )
2582 GetControlBounds( *m_peer
, &r
) ;
2583 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2585 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2586 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2595 if ( includeOuterStructures
)
2596 InsetRect( &r
, -3 , -3 ) ;
2597 RectRgn( visRgn
, &r
) ;
2598 if ( !IsTopLevel() )
2600 wxWindow
* child
= this ;
2601 wxWindow
* parent
= child
->GetParent() ;
2606 // we have to find a better clipping algorithm here, in order not to clip things
2607 // positioned like status and toolbar
2608 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2610 size
= parent
->GetSize() ;
2615 size
= parent
->GetClientSize() ;
2616 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2620 parent
->MacWindowToRootWindow( &x
, &y
) ;
2621 MacRootWindowToWindow( &x
, &y
) ;
2623 SetRectRgn( tempRgn
,
2624 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2625 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2626 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2628 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2629 if ( parent
->IsTopLevel() )
2632 parent
= child
->GetParent() ;
2637 wxRegion vis
= visRgn
;
2638 DisposeRgn( visRgn
) ;
2639 DisposeRgn( tempRgn
) ;
2644 This function must not change the updatergn !
2646 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2648 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2649 bool handled
= false ;
2651 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2653 RgnHandle newupdate
= NewRgn() ;
2654 wxSize point
= GetClientSize() ;
2655 wxPoint origin
= GetClientAreaOrigin() ;
2656 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2657 SectRgn( newupdate
, updatergn
, newupdate
) ;
2658 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2659 m_updateRegion
= newupdate
;
2660 DisposeRgn( newupdate
) ;
2663 if ( !EmptyRgn(updatergn
) )
2665 wxWindowDC
dc(this);
2666 if (!EmptyRgn(updatergn
))
2667 dc
.SetClippingRegion(wxRegion(updatergn
));
2669 wxEraseEvent
eevent( GetId(), &dc
);
2670 eevent
.SetEventObject( this );
2671 GetEventHandler()->ProcessEvent( eevent
);
2673 if ( !m_updateRegion
.Empty() )
2675 // paint the window itself
2677 event
.m_timeStamp
= time
;
2678 event
.SetEventObject(this);
2679 handled
= GetEventHandler()->ProcessEvent(event
);
2681 // paint custom borders
2682 wxNcPaintEvent
eventNc( GetId() );
2683 eventNc
.SetEventObject( this );
2684 GetEventHandler()->ProcessEvent( eventNc
);
2690 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2692 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2693 // updatergn is always already clipped to our boundaries
2694 // if we are in compositing mode then it is in relative to the upper left of the control
2695 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2696 // of the toplevel window
2697 // it is in window coordinates, not in client coordinates
2699 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2700 RgnHandle ownUpdateRgn
= NewRgn() ;
2701 CopyRgn( updatergn
, ownUpdateRgn
) ;
2703 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2706 UMAGetControlBoundsInWindowCoords( *m_peer
, &bounds
);
2707 RgnHandle controlRgn
= NewRgn();
2708 RectRgn( controlRgn
, &bounds
);
2709 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2710 // the window update region
2711 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2712 DisposeRgn( controlRgn
);
2714 //KO: convert ownUpdateRgn to local coordinates
2715 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2718 MacDoRedraw( ownUpdateRgn
, time
) ;
2719 DisposeRgn( ownUpdateRgn
) ;
2723 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2725 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2729 if ( iter
->IsTopLevel() )
2730 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2732 iter
= iter
->GetParent() ;
2734 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2738 void wxWindowMac::MacCreateScrollBars( long style
)
2740 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2742 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2743 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2745 GetClientSize( &width
, &height
) ;
2747 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2748 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2749 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2750 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2752 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2753 vSize
, wxVERTICAL
);
2755 if ( style
& wxVSCROLL
)
2761 m_vScrollBar
->Show(false) ;
2763 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2764 hSize
, wxHORIZONTAL
);
2765 if ( style
& wxHSCROLL
)
2770 m_hScrollBar
->Show(false) ;
2773 // because the create does not take into account the client area origin
2774 MacRepositionScrollBars() ; // we might have a real position shift
2777 void wxWindowMac::MacRepositionScrollBars()
2779 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2780 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2782 // get real client area
2786 GetSize( &width
, &height
) ;
2788 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2789 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2791 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2792 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2793 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2794 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2800 GetSize( &w
, &h
) ;
2802 MacClientToRootWindow( &x
, &y
) ;
2803 MacClientToRootWindow( &w
, &h
) ;
2805 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2807 int totW
= 10000 , totH
= 10000;
2810 if ( iter
->IsTopLevel() )
2812 iter
->GetSize( &totW
, &totH
) ;
2816 iter
= iter
->GetParent() ;
2844 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2848 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2852 bool wxWindowMac::AcceptsFocus() const
2854 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2857 void wxWindowMac::MacSuperChangedPosition()
2859 // only window-absolute structures have to be moved i.e. controls
2861 wxWindowListNode
*node
= GetChildren().GetFirst();
2864 wxWindowMac
*child
= node
->GetData();
2865 child
->MacSuperChangedPosition() ;
2866 node
= node
->GetNext();
2870 void wxWindowMac::MacTopLevelWindowChangedPosition()
2872 // only screen-absolute structures have to be moved i.e. glcanvas
2874 wxWindowListNode
*node
= GetChildren().GetFirst();
2877 wxWindowMac
*child
= node
->GetData();
2878 child
->MacTopLevelWindowChangedPosition() ;
2879 node
= node
->GetNext();
2883 long wxWindowMac::MacGetLeftBorderSize( ) const
2888 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2891 #if wxMAC_USE_THEME_BORDER
2892 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2896 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2899 #if wxMAC_USE_THEME_BORDER
2900 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2904 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2911 long wxWindowMac::MacGetRightBorderSize( ) const
2913 // they are all symmetric in mac themes
2914 return MacGetLeftBorderSize() ;
2917 long wxWindowMac::MacGetTopBorderSize( ) const
2919 // they are all symmetric in mac themes
2920 return MacGetLeftBorderSize() ;
2923 long wxWindowMac::MacGetBottomBorderSize( ) const
2925 // they are all symmetric in mac themes
2926 return MacGetLeftBorderSize() ;
2929 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2931 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2934 // Find the wxWindowMac at the current mouse position, returning the mouse
2936 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2938 pt
= wxGetMousePosition();
2939 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2943 // Get the current mouse position.
2944 wxPoint
wxGetMousePosition()
2947 wxGetMousePosition(& x
, & y
);
2948 return wxPoint(x
, y
);
2951 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2953 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2955 // copied from wxGTK : CS
2956 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2959 // (a) it's a command event and so is propagated to the parent
2960 // (b) under MSW it can be generated from kbd too
2961 // (c) it uses screen coords (because of (a))
2962 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2964 this->ClientToScreen(event
.GetPosition()));
2965 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2974 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2978 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2982 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2983 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2987 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2989 return eventNotHandledErr
;