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 void wxWindowMac::Init()
565 #if WXWIN_COMPATIBILITY_2_4
566 m_backgroundTransparent
= FALSE
;
569 // as all windows are created with WS_VISIBLE style...
572 m_hScrollBar
= NULL
;
573 m_vScrollBar
= NULL
;
574 m_macBackgroundBrush
= wxNullBrush
;
576 m_macControl
= NULL
;
578 m_macIsUserPane
= TRUE
;
580 // make sure all proc ptrs are available
582 if ( gControlUserPaneDrawUPP
== NULL
)
584 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
585 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
586 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
587 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
588 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
589 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
590 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
591 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
593 if ( wxMacLiveScrollbarActionUPP
== NULL
)
595 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
598 if ( wxMacSetupControlBackgroundUPP
== NULL
)
600 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
603 // we need a valid font for the encodings
604 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
608 wxWindowMac::~wxWindowMac()
612 m_isBeingDeleted
= TRUE
;
614 #ifndef __WXUNIVERSAL__
615 // VS: make sure there's no wxFrame with last focus set to us:
616 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
618 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
621 if ( frame
->GetLastFocus() == this )
623 frame
->SetLastFocus((wxWindow
*)NULL
);
628 #endif // __WXUNIVERSAL__
630 // wxRemoveMacControlAssociation( this ) ;
631 // If we delete an item, we should initialize the parent panel,
632 // because it could now be invalid.
633 wxWindow
*parent
= GetParent() ;
636 if (parent
->GetDefaultItem() == (wxButton
*) this)
637 parent
->SetDefaultItem(NULL
);
639 if ( (ControlRef
) m_macControl
)
641 // in case the callback might be called during destruction
642 wxRemoveMacControlAssociation( this) ;
643 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
644 ::DisposeControl( (ControlRef
) m_macControl
) ;
645 m_macControl
= NULL
;
648 if ( g_MacLastWindow
== this )
650 g_MacLastWindow
= NULL
;
653 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
656 if ( frame
->GetLastFocus() == this )
657 frame
->SetLastFocus( NULL
) ;
662 // delete our drop target if we've got one
663 #if wxUSE_DRAG_AND_DROP
664 if ( m_dropTarget
!= NULL
)
669 #endif // wxUSE_DRAG_AND_DROP
674 void wxWindowMac::MacInstallEventHandler()
676 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
677 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
678 GetEventTypeCount(eventList
), eventList
, this,
679 (EventHandlerRef
*)&m_macControlEventHandler
);
684 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
688 const wxString
& name
)
690 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
692 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
695 parent
->AddChild(this);
697 m_windowVariant
= parent
->GetWindowVariant() ;
699 if ( m_macIsUserPane
)
701 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
704 | kControlSupportsEmbedding
705 // | kControlSupportsLiveFeedback
706 // | kControlHasSpecialBackground
707 // | kControlSupportsCalcBestRect
708 // | kControlHandlesTracking
709 | kControlSupportsFocus
710 // | kControlWantsActivate
711 // | kControlWantsIdle
714 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
716 MacPostControlCreate(pos
,size
) ;
717 #if !TARGET_API_MAC_OSX
718 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
719 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
720 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
721 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
722 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
723 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
724 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
725 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
726 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
727 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
728 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
729 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
730 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
731 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
732 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
733 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
736 #ifndef __WXUNIVERSAL__
737 // Don't give scrollbars to wxControls unless they ask for them
738 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
739 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
741 MacCreateScrollBars( style
) ;
745 wxWindowCreateEvent
event(this);
746 GetEventHandler()->AddPendingEvent(event
);
751 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
753 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
755 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
757 MacInstallEventHandler();
759 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
760 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
761 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
763 // adjust font, controlsize etc
764 DoSetWindowVariant( m_windowVariant
) ;
766 #if !TARGET_API_MAC_OSX
767 // eventually we can fix some clipping issues be reactivating this hook
768 //if ( m_macIsUserPane )
769 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
772 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
774 if (!m_macIsUserPane
)
776 SetInitialBestSize(size
);
779 SetCursor( *wxSTANDARD_CURSOR
) ;
782 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
784 // Don't assert, in case we set the window variant before
785 // the window is created
786 // wxASSERT( m_macControl != NULL ) ;
788 m_windowVariant
= variant
;
794 ThemeFontID themeFont
= kThemeSystemFont
;
796 // we will get that from the settings later
797 // and make this NORMAL later, but first
798 // we have a few calculations that we must fix
802 case wxWINDOW_VARIANT_NORMAL
:
803 size
= kControlSizeNormal
;
804 themeFont
= kThemeSystemFont
;
806 case wxWINDOW_VARIANT_SMALL
:
807 size
= kControlSizeSmall
;
808 themeFont
= kThemeSmallSystemFont
;
810 case wxWINDOW_VARIANT_MINI
:
811 if (UMAGetSystemVersion() >= 0x1030 )
813 // not always defined in the headers
819 size
= kControlSizeSmall
;
820 themeFont
= kThemeSmallSystemFont
;
823 case wxWINDOW_VARIANT_LARGE
:
824 size
= kControlSizeLarge
;
825 themeFont
= kThemeSystemFont
;
828 wxFAIL_MSG(_T("unexpected window variant"));
831 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
834 font
.MacCreateThemeFont( themeFont
) ;
838 void wxWindowMac::MacUpdateControlFont()
840 ControlFontStyleRec fontStyle
;
841 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
843 switch( m_font
.MacGetThemeFontID() )
845 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
846 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
847 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
848 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
850 fontStyle
.flags
= kControlUseFontMask
;
854 fontStyle
.font
= m_font
.MacGetFontNum() ;
855 fontStyle
.style
= m_font
.MacGetFontStyle() ;
856 fontStyle
.size
= m_font
.MacGetFontSize() ;
857 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
860 fontStyle
.just
= teJustLeft
;
861 fontStyle
.flags
|= kControlUseJustMask
;
862 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
863 fontStyle
.just
= teJustCenter
;
864 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
865 fontStyle
.just
= teJustRight
;
868 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
869 fontStyle
.flags
|= kControlUseForeColorMask
;
871 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
875 bool wxWindowMac::SetFont(const wxFont
& font
)
877 bool retval
= !wxWindowBase::SetFont( font
) ;
879 MacUpdateControlFont() ;
884 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
886 if ( !wxWindowBase::SetForegroundColour(col
) )
889 MacUpdateControlFont() ;
894 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
896 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
900 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
902 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
904 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
906 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
910 brush
.SetColour( col
) ;
912 MacSetBackgroundBrush( brush
) ;
914 MacUpdateControlFont() ;
920 bool wxWindowMac::MacCanFocus() const
923 // there is currently no way to determinate whether the window is running in full keyboard
924 // access mode, therefore we cannot rely on these features yet
925 UInt32 features
= 0 ;
926 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
927 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
933 void wxWindowMac::SetFocus()
935 if ( AcceptsFocus() )
937 #if !TARGET_API_MAC_OSX
938 wxWindow
* former
= FindFocus() ;
940 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
941 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
942 // leave in case of an error
943 if ( err
== errCouldntSetFocus
)
946 #if !TARGET_API_MAC_OSX
947 // emulate carbon events when running under carbonlib where they are not natively available
950 EventRef evRef
= NULL
;
951 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
954 wxMacCarbonEvent
cEvent( evRef
) ;
955 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
956 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
958 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
959 ReleaseEvent(evRef
) ;
961 // send new focus event
963 EventRef evRef
= NULL
;
964 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
967 wxMacCarbonEvent
cEvent( evRef
) ;
968 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
969 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
971 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
972 ReleaseEvent(evRef
) ;
979 void wxWindowMac::DoCaptureMouse()
981 wxTheApp
->s_captureWindow
= this ;
984 wxWindow
* wxWindowBase::GetCapture()
986 return wxTheApp
->s_captureWindow
;
989 void wxWindowMac::DoReleaseMouse()
991 wxTheApp
->s_captureWindow
= NULL
;
994 #if wxUSE_DRAG_AND_DROP
996 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
998 if ( m_dropTarget
!= 0 ) {
1002 m_dropTarget
= pDropTarget
;
1003 if ( m_dropTarget
!= 0 )
1011 // Old style file-manager drag&drop
1012 void wxWindowMac::DragAcceptFiles(bool accept
)
1017 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1018 int& w
, int& h
) const
1021 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1026 w
= bounds
.right
- bounds
.left
;
1027 h
= bounds
.bottom
- bounds
.top
;
1029 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1032 Point tlworigin
= { 0 , 0 } ;
1034 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1035 ::LocalToGlobal( &tlworigin
) ;
1043 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1046 int& w
, int& h
, bool adjustOrigin
) const
1050 // todo the default calls may be used as soon as PostCreateControl Is moved here
1051 w
= size
.x
; // WidthDefault( size.x );
1052 h
= size
.y
; // HeightDefault( size.y ) ;
1053 #if !TARGET_API_MAC_OSX
1054 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1057 AdjustForParentClientOrigin( x
, y
) ;
1062 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1064 #if TARGET_API_MAC_OSX
1065 int x1
, y1
, w1
,h1
;
1066 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1072 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1073 if(x
) *x
= bounds
.right
- bounds
.left
;
1074 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1078 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1080 #if TARGET_API_MAC_OSX
1081 int x1
, y1
, w1
,h1
;
1082 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1083 if ( !IsTopLevel() )
1085 wxWindow
*parent
= GetParent();
1088 wxPoint
pt(parent
->GetClientAreaOrigin());
1097 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1098 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1100 int xx
= bounds
.left
;
1101 int yy
= bounds
.top
;
1103 if ( !GetParent()->IsTopLevel() )
1105 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1111 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1120 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1122 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1124 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1127 Point localwhere
= {0,0} ;
1129 if(x
) localwhere
.h
= * x
;
1130 if(y
) localwhere
.v
= * y
;
1132 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1133 ::GlobalToLocal( &localwhere
) ;
1134 if(x
) *x
= localwhere
.h
;
1135 if(y
) *y
= localwhere
.v
;
1138 MacRootWindowToWindow( x
, y
) ;
1140 wxPoint origin
= GetClientAreaOrigin() ;
1141 if(x
) *x
-= origin
.x
;
1142 if(y
) *y
-= origin
.y
;
1145 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1147 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1148 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1150 wxPoint origin
= GetClientAreaOrigin() ;
1151 if(x
) *x
+= origin
.x
;
1152 if(y
) *y
+= origin
.y
;
1154 MacWindowToRootWindow( x
, y
) ;
1157 Point localwhere
= { 0,0 };
1158 if(x
) localwhere
.h
= * x
;
1159 if(y
) localwhere
.v
= * y
;
1161 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1162 ::LocalToGlobal( &localwhere
) ;
1163 if(x
) *x
= localwhere
.h
;
1164 if(y
) *y
= localwhere
.v
;
1168 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1170 wxPoint origin
= GetClientAreaOrigin() ;
1171 if(x
) *x
+= origin
.x
;
1172 if(y
) *y
+= origin
.y
;
1174 MacWindowToRootWindow( x
, y
) ;
1177 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1179 MacRootWindowToWindow( x
, y
) ;
1181 wxPoint origin
= GetClientAreaOrigin() ;
1182 if(x
) *x
-= origin
.x
;
1183 if(y
) *y
-= origin
.y
;
1186 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1188 #if TARGET_API_MAC_OSX
1190 if ( x
) pt
.x
= *x
;
1191 if ( y
) pt
.y
= *y
;
1193 if ( !IsTopLevel() )
1194 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1196 if ( x
) *x
= (int) pt
.x
;
1197 if ( y
) *y
= (int) pt
.y
;
1199 if ( !IsTopLevel() )
1202 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1203 if(x
) *x
+= bounds
.left
;
1204 if(y
) *y
+= bounds
.top
;
1209 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1214 MacWindowToRootWindow( &x1
, &y1
) ;
1219 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1221 #if TARGET_API_MAC_OSX
1223 if ( x
) pt
.x
= *x
;
1224 if ( y
) pt
.y
= *y
;
1226 if ( !IsTopLevel() )
1227 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1229 if ( x
) *x
= (int) pt
.x
;
1230 if ( y
) *y
= (int) pt
.y
;
1232 if ( !IsTopLevel() )
1235 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1236 if(x
) *x
-= bounds
.left
;
1237 if(y
) *y
-= bounds
.top
;
1242 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1247 MacRootWindowToWindow( &x1
, &y1
) ;
1252 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1254 RgnHandle rgn
= NewRgn() ;
1256 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1258 GetRegionBounds( rgn
, &content
) ;
1263 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1266 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1267 #if !TARGET_API_MAC_OSX
1268 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1270 left
= content
.left
- structure
.left
;
1271 top
= content
.top
- structure
.top
;
1272 right
= structure
.right
- content
.right
;
1273 bottom
= structure
.bottom
- content
.bottom
;
1276 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1278 wxSize sizeTotal
= size
;
1280 RgnHandle rgn
= NewRgn() ;
1284 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1286 GetRegionBounds( rgn
, &content
) ;
1291 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1294 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1295 #if !TARGET_API_MAC_OSX
1296 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1299 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1300 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1302 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1303 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1309 // Get size *available for subwindows* i.e. excluding menu bar etc.
1310 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1314 RgnHandle rgn
= NewRgn() ;
1316 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1318 GetRegionBounds( rgn
, &content
) ;
1323 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1325 #if !TARGET_API_MAC_OSX
1327 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1328 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1330 ww
= content
.right
- content
.left
;
1331 hh
= content
.bottom
- content
.top
;
1333 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1334 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1336 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1342 GetSize( &w
, &h
) ;
1344 MacClientToRootWindow( &x1
, &y1
) ;
1345 MacClientToRootWindow( &w
, &h
) ;
1347 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1349 int totW
= 10000 , totH
= 10000;
1352 if ( iter
->IsTopLevel() )
1354 iter
->GetSize( &totW
, &totH
) ;
1358 iter
= iter
->GetParent() ;
1361 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1363 hh
-= MAC_SCROLLBAR_SIZE
;
1369 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1371 ww
-= MAC_SCROLLBAR_SIZE
;
1383 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1385 if (m_cursor
== cursor
)
1388 if (wxNullCursor
== cursor
)
1390 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1395 if ( ! wxWindowBase::SetCursor( cursor
) )
1399 wxASSERT_MSG( m_cursor
.Ok(),
1400 wxT("cursor must be valid after call to the base version"));
1404 TODO why do we have to use current coordinates ?
1407 wxWindowMac *mouseWin ;
1410 // Change the cursor NOW if we're within the correct window
1413 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1415 if ( mouseWin == this && !wxIsBusy() )
1417 m_cursor.MacInstall() ;
1423 m_cursor
.MacInstall() ;
1430 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1432 menu
->SetInvokingWindow(this);
1434 ClientToScreen( &x
, &y
) ;
1436 menu
->MacBeforeDisplay( true ) ;
1437 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1438 if ( HiWord(menuResult
) != 0 )
1441 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1442 wxMenuItem
* item
= NULL
;
1444 item
= menu
->FindItem(id
, &realmenu
) ;
1445 if (item
->IsCheckable())
1447 item
->Check( !item
->IsChecked() ) ;
1449 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1451 menu
->MacAfterDisplay( true ) ;
1453 menu
->SetInvokingWindow(NULL
);
1459 // ----------------------------------------------------------------------------
1461 // ----------------------------------------------------------------------------
1465 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1467 wxWindowBase::DoSetToolTip(tooltip
);
1470 m_tooltip
->SetWindow(this);
1473 #endif // wxUSE_TOOLTIPS
1475 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1477 int former_x
, former_y
, former_w
, former_h
;
1478 #if !TARGET_API_MAC_OSX
1479 DoGetPosition( &former_x
, &former_y
) ;
1480 DoGetSize( &former_w
, &former_h
) ;
1482 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1485 int actualWidth
= width
;
1486 int actualHeight
= height
;
1490 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1491 actualWidth
= m_minWidth
;
1492 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1493 actualHeight
= m_minHeight
;
1494 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1495 actualWidth
= m_maxWidth
;
1496 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1497 actualHeight
= m_maxHeight
;
1499 bool doMove
= false ;
1500 bool doResize
= false ;
1502 if ( actualX
!= former_x
|| actualY
!= former_y
)
1506 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1511 if ( doMove
|| doResize
)
1513 // we don't adjust twice for the origin
1514 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1515 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1516 #if TARGET_API_MAC_OSX
1517 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1519 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1520 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1521 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1523 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1526 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1527 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1529 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1531 MacRepositionScrollBars() ;
1534 wxPoint
point(actualX
,actualY
);
1535 wxMoveEvent
event(point
, m_windowId
);
1536 event
.SetEventObject(this);
1537 GetEventHandler()->ProcessEvent(event
) ;
1541 MacRepositionScrollBars() ;
1542 wxSize
size(actualWidth
, actualHeight
);
1543 wxSizeEvent
event(size
, m_windowId
);
1544 event
.SetEventObject(this);
1545 GetEventHandler()->ProcessEvent(event
);
1551 wxSize
wxWindowMac::DoGetBestSize() const
1553 if ( m_macIsUserPane
|| IsTopLevel() )
1554 return wxWindowBase::DoGetBestSize() ;
1556 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1557 short baselineoffset
;
1558 int bestWidth
, bestHeight
;
1559 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1561 if ( EmptyRect( &bestsize
) )
1564 bestsize
.left
= bestsize
.top
= 0 ;
1565 bestsize
.right
= 16 ;
1566 bestsize
.bottom
= 16 ;
1567 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1569 bestsize
.bottom
= 16 ;
1571 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1573 bestsize
.bottom
= 24 ;
1577 // return wxWindowBase::DoGetBestSize() ;
1581 bestWidth
= bestsize
.right
- bestsize
.left
;
1582 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1583 if ( bestHeight
< 10 )
1586 return wxSize(bestWidth
, bestHeight
);
1587 // return wxWindowBase::DoGetBestSize() ;
1591 // set the size of the window: if the dimensions are positive, just use them,
1592 // but if any of them is equal to -1, it means that we must find the value for
1593 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1594 // which case -1 is a valid value for x and y)
1596 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1597 // the width/height to best suit our contents, otherwise we reuse the current
1599 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1601 // get the current size and position...
1602 int currentX
, currentY
;
1603 GetPosition(¤tX
, ¤tY
);
1605 int currentW
,currentH
;
1606 GetSize(¤tW
, ¤tH
);
1608 // ... and don't do anything (avoiding flicker) if it's already ok
1609 if ( x
== currentX
&& y
== currentY
&&
1610 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1613 MacRepositionScrollBars() ; // we might have a real position shift
1617 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1619 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1622 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1624 wxSize
size(-1, -1);
1627 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1629 size
= DoGetBestSize();
1634 // just take the current one
1641 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1645 size
= DoGetBestSize();
1647 //else: already called DoGetBestSize() above
1653 // just take the current one
1658 DoMoveWindow(x
, y
, width
, height
);
1662 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1664 RgnHandle rgn
= NewRgn() ;
1666 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1667 GetRegionBounds( rgn
, &content
) ;
1669 #if !TARGET_API_MAC_OSX
1670 // if the content rgn is empty / not supported
1671 // don't attempt to correct the coordinates to wxWindow relative ones
1672 if (!::EmptyRect( &content
) )
1675 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1676 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1680 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1683 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1685 if ( clientheight
!= -1 || clientheight
!= -1 )
1687 int currentclientwidth
, currentclientheight
;
1688 int currentwidth
, currentheight
;
1690 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1691 GetSize( ¤twidth
, ¤theight
) ;
1693 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1694 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1698 void wxWindowMac::SetTitle(const wxString
& title
)
1700 m_label
= wxStripMenuCodes(title
) ;
1704 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1709 wxString
wxWindowMac::GetTitle() const
1714 bool wxWindowMac::Show(bool show
)
1716 if ( !wxWindowBase::Show(show
) )
1719 // TODO use visibilityChanged Carbon Event for OSX
1720 bool former
= MacIsReallyShown() ;
1722 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1723 if ( former
!= MacIsReallyShown() )
1724 MacPropagateVisibilityChanged() ;
1728 bool wxWindowMac::Enable(bool enable
)
1730 wxASSERT( m_macControl
!= NULL
) ;
1731 if ( !wxWindowBase::Enable(enable
) )
1734 bool former
= MacIsReallyEnabled() ;
1735 #if TARGET_API_MAC_OSX
1737 EnableControl( (ControlRef
) m_macControl
) ;
1739 DisableControl( (ControlRef
) m_macControl
) ;
1742 ActivateControl( (ControlRef
) m_macControl
) ;
1744 DeactivateControl( (ControlRef
) m_macControl
) ;
1747 if ( former
!= MacIsReallyEnabled() )
1748 MacPropagateEnabledStateChanged() ;
1753 // status change propagations (will be not necessary for OSX later )
1756 void wxWindowMac::MacPropagateVisibilityChanged()
1758 #if !TARGET_API_MAC_OSX
1759 MacVisibilityChanged() ;
1761 wxWindowListNode
*node
= GetChildren().GetFirst();
1764 wxWindowMac
*child
= node
->GetData();
1765 if ( child
->IsShown() )
1766 child
->MacPropagateVisibilityChanged( ) ;
1767 node
= node
->GetNext();
1772 void wxWindowMac::MacPropagateEnabledStateChanged( )
1774 #if !TARGET_API_MAC_OSX
1775 MacEnabledStateChanged() ;
1777 wxWindowListNode
*node
= GetChildren().GetFirst();
1780 wxWindowMac
*child
= node
->GetData();
1781 if ( child
->IsEnabled() )
1782 child
->MacPropagateEnabledStateChanged() ;
1783 node
= node
->GetNext();
1788 void wxWindowMac::MacPropagateHiliteChanged( )
1790 #if !TARGET_API_MAC_OSX
1791 MacHiliteChanged() ;
1793 wxWindowListNode
*node
= GetChildren().GetFirst();
1796 wxWindowMac
*child
= node
->GetData();
1797 // if ( child->IsEnabled() )
1798 child
->MacPropagateHiliteChanged() ;
1799 node
= node
->GetNext();
1805 // status change notifications
1808 void wxWindowMac::MacVisibilityChanged()
1812 void wxWindowMac::MacHiliteChanged()
1816 void wxWindowMac::MacEnabledStateChanged()
1821 // status queries on the inherited window's state
1824 bool wxWindowMac::MacIsReallyShown()
1826 // only under OSX the visibility of the TLW is taken into account
1827 #if TARGET_API_MAC_OSX
1828 return IsControlVisible( (ControlRef
) m_macControl
) ;
1830 wxWindow
* win
= this ;
1831 while( win
->IsShown() )
1833 if ( win
->IsTopLevel() )
1836 win
= win
->GetParent() ;
1845 bool wxWindowMac::MacIsReallyEnabled()
1847 #if TARGET_API_MAC_OSX
1848 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1850 return IsControlActive( (ControlRef
) m_macControl
) ;
1854 bool wxWindowMac::MacIsReallyHilited()
1856 return IsControlActive( (ControlRef
) m_macControl
) ;
1859 void wxWindowMac::MacFlashInvalidAreas()
1861 #if TARGET_API_MAC_OSX
1862 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1870 int wxWindowMac::GetCharHeight() const
1872 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1873 return dc
.GetCharHeight() ;
1876 int wxWindowMac::GetCharWidth() const
1878 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1879 return dc
.GetCharWidth() ;
1882 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1883 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1885 const wxFont
*fontToUse
= theFont
;
1887 fontToUse
= &m_font
;
1889 wxClientDC
dc( (wxWindowMac
*) this ) ;
1891 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1892 if ( externalLeading
)
1893 *externalLeading
= le
;
1903 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1904 * we always intersect with the entire window, not only with the client area
1907 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1909 #if TARGET_API_MAC_OSX
1911 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1914 RgnHandle update
= NewRgn() ;
1915 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1916 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1917 wxPoint origin
= GetClientAreaOrigin() ;
1918 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1919 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1923 RgnHandle updateRgn = NewRgn() ;
1926 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1930 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1931 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1933 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1934 DisposeRgn(updateRgn) ;
1936 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1938 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1939 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1942 if ( MacGetTopLevelWindow() == NULL )
1945 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1948 wxPoint client = GetClientAreaOrigin();
1951 int x2 = m_width - client.x;
1952 int y2 = m_height - client.y;
1954 if (IsKindOf( CLASSINFO(wxButton)))
1956 // buttons have an "aura"
1963 Rect clientrect = { y1, x1, y2, x2 };
1967 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1968 SectRect( &clientrect , &r , &clientrect ) ;
1971 if ( !EmptyRect( &clientrect ) )
1973 int top = 0 , left = 0 ;
1975 MacClientToRootWindow( &left , &top ) ;
1976 OffsetRect( &clientrect , left , top ) ;
1978 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1984 void wxWindowMac::Freeze()
1986 #if TARGET_API_MAC_OSX
1987 if ( !m_frozenness
++ )
1989 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1994 #if TARGET_API_MAC_OSX
1995 static void InvalidateControlAndChildren( HIViewRef control
)
1997 HIViewSetNeedsDisplay( control
, true ) ;
1998 UInt16 childrenCount
= 0 ;
1999 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2000 if ( err
== errControlIsNotEmbedder
)
2002 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2004 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2007 err
= GetIndexedSubControl( control
, i
, & child
) ;
2008 if ( err
== errControlIsNotEmbedder
)
2010 InvalidateControlAndChildren( child
) ;
2015 void wxWindowMac::Thaw()
2017 #if TARGET_API_MAC_OSX
2018 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2020 if ( !--m_frozenness
)
2022 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2023 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2024 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2029 void wxWindowMac::MacRedrawControl()
2032 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2034 #if TARGET_API_MAC_CARBON
2037 wxClientDC dc(this) ;
2038 wxMacPortSetter helper(&dc) ;
2039 wxMacWindowClipper clipper(this) ;
2040 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2041 UMADrawControl( (ControlRef) m_macControl ) ;
2048 void wxWindowMac::OnPaint(wxPaintEvent& event)
2050 // why don't we skip that here ?
2054 wxWindowMac
*wxGetActiveWindow()
2056 // actually this is a windows-only concept
2060 // Coordinates relative to the window
2061 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2063 // We really don't move the mouse programmatically under Mac.
2066 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2068 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2073 event
.GetDC()->Clear() ;
2076 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2078 wxWindowDC
dc(this) ;
2079 wxMacPortSetter
helper(&dc
) ;
2081 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2084 int wxWindowMac::GetScrollPos(int orient
) const
2086 if ( orient
== wxHORIZONTAL
)
2089 return m_hScrollBar
->GetThumbPosition() ;
2094 return m_vScrollBar
->GetThumbPosition() ;
2099 // This now returns the whole range, not just the number
2100 // of positions that we can scroll.
2101 int wxWindowMac::GetScrollRange(int orient
) const
2103 if ( orient
== wxHORIZONTAL
)
2106 return m_hScrollBar
->GetRange() ;
2111 return m_vScrollBar
->GetRange() ;
2116 int wxWindowMac::GetScrollThumb(int orient
) const
2118 if ( orient
== wxHORIZONTAL
)
2121 return m_hScrollBar
->GetThumbSize() ;
2126 return m_vScrollBar
->GetThumbSize() ;
2131 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2133 if ( orient
== wxHORIZONTAL
)
2136 m_hScrollBar
->SetThumbPosition( pos
) ;
2141 m_vScrollBar
->SetThumbPosition( pos
) ;
2145 void wxWindowMac::MacPaintBorders( int left
, int top
)
2151 wxGetOsVersion( &major
, &minor
);
2153 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2154 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2156 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2157 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2158 // OS X has lighter border edges than classic:
2161 darkShadow
.red
= 0x8E8E;
2162 darkShadow
.green
= 0x8E8E;
2163 darkShadow
.blue
= 0x8E8E;
2164 lightShadow
.red
= 0xBDBD;
2165 lightShadow
.green
= 0xBDBD;
2166 lightShadow
.blue
= 0xBDBD;
2172 GetSize( &w
, &h
) ;
2173 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2175 #if wxMAC_USE_THEME_BORDER
2176 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2179 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2180 InsetRect( &rect , border , border );
2181 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2184 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2186 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2187 RGBForeColor( &face
);
2188 MoveTo( left
+ 0 , top
+ h
- 2 );
2189 LineTo( left
+ 0 , top
+ 0 );
2190 LineTo( left
+ w
- 2 , top
+ 0 );
2192 MoveTo( left
+ 2 , top
+ h
- 3 );
2193 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2194 LineTo( left
+ w
- 3 , top
+ 2 );
2196 RGBForeColor( sunken
? &face
: &darkShadow
);
2197 MoveTo( left
+ 0 , top
+ h
- 1 );
2198 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2199 LineTo( left
+ w
- 1 , top
+ 0 );
2201 RGBForeColor( sunken
? &lightShadow
: &white
);
2202 MoveTo( left
+ 1 , top
+ h
- 3 );
2203 LineTo( left
+ 1, top
+ 1 );
2204 LineTo( left
+ w
- 3 , top
+ 1 );
2206 RGBForeColor( sunken
? &white
: &lightShadow
);
2207 MoveTo( left
+ 1 , top
+ h
- 2 );
2208 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2209 LineTo( left
+ w
- 2 , top
+ 1 );
2211 RGBForeColor( sunken
? &darkShadow
: &face
);
2212 MoveTo( left
+ 2 , top
+ h
- 4 );
2213 LineTo( left
+ 2 , top
+ 2 );
2214 LineTo( left
+ w
- 4 , top
+ 2 );
2217 else if (HasFlag(wxSIMPLE_BORDER
))
2219 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2220 RGBForeColor( &darkShadow
) ;
2221 FrameRect( &rect
) ;
2225 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2227 if ( child
== m_hScrollBar
)
2228 m_hScrollBar
= NULL
;
2229 if ( child
== m_vScrollBar
)
2230 m_vScrollBar
= NULL
;
2232 wxWindowBase::RemoveChild( child
) ;
2235 // New function that will replace some of the above.
2236 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2237 int range
, bool refresh
)
2239 if ( orient
== wxHORIZONTAL
)
2243 if ( range
== 0 || thumbVisible
>= range
)
2245 if ( m_hScrollBar
->IsShown() )
2246 m_hScrollBar
->Show(false) ;
2250 if ( !m_hScrollBar
->IsShown() )
2251 m_hScrollBar
->Show(true) ;
2252 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2260 if ( range
== 0 || thumbVisible
>= range
)
2262 if ( m_vScrollBar
->IsShown() )
2263 m_vScrollBar
->Show(false) ;
2267 if ( !m_vScrollBar
->IsShown() )
2268 m_vScrollBar
->Show(true) ;
2269 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2273 MacRepositionScrollBars() ;
2276 // Does a physical scroll
2277 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2279 if( dx
== 0 && dy
==0 )
2285 int width
, height
;
2286 GetClientSize( &width
, &height
) ;
2287 #if TARGET_API_MAC_OSX
2288 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2289 // area is scrolled, this does not occur if width and height are 2 pixels less,
2290 // TODO write optimal workaround
2291 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2294 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2295 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2297 if ( HIViewGetNeedsDisplay( (ControlRef
) m_macControl
) )
2299 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2300 // either immediate redraw or full invalidate
2302 // is the better overall solution, as it does not slow down scrolling
2303 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2305 // this would be the preferred version for fast drawing controls
2306 if( UMAGetSystemVersion() < 0x1030 )
2309 HIViewRender((ControlRef
) m_macControl
) ;
2312 HIViewScrollRect ( (ControlRef
) m_macControl
, &scrollrect
, dx
,dy
) ;
2319 RgnHandle updateRgn
= NewRgn() ;
2322 wxClientDC
dc(this) ;
2323 wxMacPortSetter
helper(&dc
) ;
2325 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2326 scrollrect
.top
+= MacGetTopBorderSize() ;
2327 scrollrect
.left
+= MacGetLeftBorderSize() ;
2328 scrollrect
.bottom
= scrollrect
.top
+ height
;
2329 scrollrect
.right
= scrollrect
.left
+ width
;
2333 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2334 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2335 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2337 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2339 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2343 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2345 wxWindowMac
*child
= node
->GetData();
2346 if (child
== m_vScrollBar
) continue;
2347 if (child
== m_hScrollBar
) continue;
2348 if (child
->IsTopLevel()) continue;
2351 child
->GetPosition( &x
, &y
);
2353 child
->GetSize( &w
, &h
);
2357 if (rect
->Intersects(rc
))
2358 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2362 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2367 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2369 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2371 wxScrollWinEvent wevent
;
2372 wevent
.SetPosition(event
.GetPosition());
2373 wevent
.SetOrientation(event
.GetOrientation());
2374 wevent
.m_eventObject
= this;
2376 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2377 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2378 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2379 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2380 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2381 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2382 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2383 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2384 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2385 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2386 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2387 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2388 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2389 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2390 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2391 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2393 GetEventHandler()->ProcessEvent(wevent
);
2397 // Get the window with the focus
2398 wxWindowMac
*wxWindowBase::FindFocus()
2400 ControlRef control
;
2401 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2402 return wxFindControlFromMacControl( control
) ;
2405 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2407 // panel wants to track the window which was the last to have focus in it,
2408 // so we want to set ourselves as the window which last had focus
2410 // notice that it's also important to do it upwards the tree becaus
2411 // otherwise when the top level panel gets focus, it won't set it back to
2412 // us, but to some other sibling
2414 // CS:don't know if this is still needed:
2415 //wxChildFocusEvent eventFocus(this);
2416 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2421 void wxWindowMac::OnInternalIdle()
2423 // This calls the UI-update mechanism (querying windows for
2424 // menu/toolbar/control state information)
2425 if (wxUpdateUIEvent::CanUpdate(this))
2426 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2429 // Raise the window to the top of the Z order
2430 void wxWindowMac::Raise()
2432 #if TARGET_API_MAC_OSX
2433 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2437 // Lower the window to the bottom of the Z order
2438 void wxWindowMac::Lower()
2440 #if TARGET_API_MAC_OSX
2441 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2446 // static wxWindow *gs_lastWhich = NULL;
2448 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2450 // first trigger a set cursor event
2452 wxPoint clientorigin
= GetClientAreaOrigin() ;
2453 wxSize clientsize
= GetClientSize() ;
2455 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2457 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2459 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2460 if ( processedEvtSetCursor
&& event
.HasCursor() )
2462 cursor
= event
.GetCursor() ;
2467 // the test for processedEvtSetCursor is here to prevent using m_cursor
2468 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2469 // it - this is a way to say that our cursor shouldn't be used for this
2471 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2481 cursor
= *wxSTANDARD_CURSOR
;
2485 cursor
.MacInstall() ;
2487 return cursor
.Ok() ;
2490 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2494 return m_tooltip
->GetTip() ;
2496 return wxEmptyString
;
2499 void wxWindowMac::Update()
2501 #if TARGET_API_MAC_OSX
2502 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2503 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2504 // for composited windows this also triggers a redraw of all
2505 // invalid views in the window
2506 if( UMAGetSystemVersion() >= 0x1030 )
2507 HIWindowFlush(window
) ;
2511 // the only way to trigger the redrawing on earlier systems is to call
2514 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2515 UInt32 currentEventClass
= 0 ;
2516 UInt32 currentEventKind
= 0 ;
2517 if ( currentEvent
!= NULL
)
2519 currentEventClass
= ::GetEventClass( currentEvent
) ;
2520 currentEventKind
= ::GetEventKind( currentEvent
) ;
2522 if ( currentEventClass
!= kEventClassMenu
)
2524 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2527 OSStatus status
= noErr
;
2528 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2531 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2534 ::Draw1Control( (ControlRef
) m_macControl
) ;
2538 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2540 wxTopLevelWindowMac
* win
= NULL
;
2541 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2544 win
= wxFindWinFromMacWindow( window
) ;
2548 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2552 RgnHandle visRgn
= NewRgn() ;
2553 RgnHandle tempRgn
= NewRgn() ;
2554 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2556 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2557 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2559 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2560 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2569 if ( includeOuterStructures
)
2570 InsetRect( &r
, -3 , -3 ) ;
2571 RectRgn( visRgn
, &r
) ;
2572 if ( !IsTopLevel() )
2574 wxWindow
* child
= this ;
2575 wxWindow
* parent
= child
->GetParent() ;
2580 // we have to find a better clipping algorithm here, in order not to clip things
2581 // positioned like status and toolbar
2582 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2584 size
= parent
->GetSize() ;
2589 size
= parent
->GetClientSize() ;
2590 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2594 parent
->MacWindowToRootWindow( &x
, &y
) ;
2595 MacRootWindowToWindow( &x
, &y
) ;
2597 SetRectRgn( tempRgn
,
2598 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2599 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2600 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2602 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2603 if ( parent
->IsTopLevel() )
2606 parent
= child
->GetParent() ;
2611 wxRegion vis
= visRgn
;
2612 DisposeRgn( visRgn
) ;
2613 DisposeRgn( tempRgn
) ;
2618 This function must not change the updatergn !
2620 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2622 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2623 bool handled
= false ;
2625 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2627 RgnHandle newupdate
= NewRgn() ;
2628 wxSize point
= GetClientSize() ;
2629 wxPoint origin
= GetClientAreaOrigin() ;
2630 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2631 SectRgn( newupdate
, updatergn
, newupdate
) ;
2632 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2633 m_updateRegion
= newupdate
;
2634 DisposeRgn( newupdate
) ;
2637 if ( !EmptyRgn(updatergn
) )
2639 wxWindowDC
dc(this);
2640 if (!EmptyRgn(updatergn
))
2641 dc
.SetClippingRegion(wxRegion(updatergn
));
2643 wxEraseEvent
eevent( GetId(), &dc
);
2644 eevent
.SetEventObject( this );
2645 GetEventHandler()->ProcessEvent( eevent
);
2647 if ( !m_updateRegion
.Empty() )
2649 // paint the window itself
2651 event
.m_timeStamp
= time
;
2652 event
.SetEventObject(this);
2653 handled
= GetEventHandler()->ProcessEvent(event
);
2655 // paint custom borders
2656 wxNcPaintEvent
eventNc( GetId() );
2657 eventNc
.SetEventObject( this );
2658 GetEventHandler()->ProcessEvent( eventNc
);
2664 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2666 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2667 // updatergn is always already clipped to our boundaries
2668 // if we are in compositing mode then it is in relative to the upper left of the control
2669 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2670 // of the toplevel window
2671 // it is in window coordinates, not in client coordinates
2673 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2674 RgnHandle ownUpdateRgn
= NewRgn() ;
2675 CopyRgn( updatergn
, ownUpdateRgn
) ;
2677 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2680 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2681 RgnHandle controlRgn
= NewRgn();
2682 RectRgn( controlRgn
, &bounds
);
2683 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2684 // the window update region
2685 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2686 DisposeRgn( controlRgn
);
2688 //KO: convert ownUpdateRgn to local coordinates
2689 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2692 MacDoRedraw( ownUpdateRgn
, time
) ;
2693 DisposeRgn( ownUpdateRgn
) ;
2697 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2699 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2703 if ( iter
->IsTopLevel() )
2704 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2706 iter
= iter
->GetParent() ;
2708 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2712 void wxWindowMac::MacCreateScrollBars( long style
)
2714 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2716 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2717 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2719 GetClientSize( &width
, &height
) ;
2721 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2722 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2723 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2724 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2726 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2727 vSize
, wxVERTICAL
);
2729 if ( style
& wxVSCROLL
)
2735 m_vScrollBar
->Show(false) ;
2737 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2738 hSize
, wxHORIZONTAL
);
2739 if ( style
& wxHSCROLL
)
2744 m_hScrollBar
->Show(false) ;
2747 // because the create does not take into account the client area origin
2748 MacRepositionScrollBars() ; // we might have a real position shift
2751 void wxWindowMac::MacRepositionScrollBars()
2753 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2754 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2756 // get real client area
2760 GetSize( &width
, &height
) ;
2762 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2763 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2765 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2766 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2767 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2768 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2774 GetSize( &w
, &h
) ;
2776 MacClientToRootWindow( &x
, &y
) ;
2777 MacClientToRootWindow( &w
, &h
) ;
2779 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2781 int totW
= 10000 , totH
= 10000;
2784 if ( iter
->IsTopLevel() )
2786 iter
->GetSize( &totW
, &totH
) ;
2790 iter
= iter
->GetParent() ;
2818 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2822 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2826 bool wxWindowMac::AcceptsFocus() const
2828 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2831 void wxWindowMac::MacSuperChangedPosition()
2833 // only window-absolute structures have to be moved i.e. controls
2835 wxWindowListNode
*node
= GetChildren().GetFirst();
2838 wxWindowMac
*child
= node
->GetData();
2839 child
->MacSuperChangedPosition() ;
2840 node
= node
->GetNext();
2844 void wxWindowMac::MacTopLevelWindowChangedPosition()
2846 // only screen-absolute structures have to be moved i.e. glcanvas
2848 wxWindowListNode
*node
= GetChildren().GetFirst();
2851 wxWindowMac
*child
= node
->GetData();
2852 child
->MacTopLevelWindowChangedPosition() ;
2853 node
= node
->GetNext();
2857 long wxWindowMac::MacGetLeftBorderSize( ) const
2862 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2865 #if wxMAC_USE_THEME_BORDER
2866 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2870 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2873 #if wxMAC_USE_THEME_BORDER
2874 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2878 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2885 long wxWindowMac::MacGetRightBorderSize( ) const
2887 // they are all symmetric in mac themes
2888 return MacGetLeftBorderSize() ;
2891 long wxWindowMac::MacGetTopBorderSize( ) const
2893 // they are all symmetric in mac themes
2894 return MacGetLeftBorderSize() ;
2897 long wxWindowMac::MacGetBottomBorderSize( ) const
2899 // they are all symmetric in mac themes
2900 return MacGetLeftBorderSize() ;
2903 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2905 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2908 // Find the wxWindowMac at the current mouse position, returning the mouse
2910 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2912 pt
= wxGetMousePosition();
2913 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2917 // Get the current mouse position.
2918 wxPoint
wxGetMousePosition()
2921 wxGetMousePosition(& x
, & y
);
2922 return wxPoint(x
, y
);
2925 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2927 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2929 // copied from wxGTK : CS
2930 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2933 // (a) it's a command event and so is propagated to the parent
2934 // (b) under MSW it can be generated from kbd too
2935 // (c) it uses screen coords (because of (a))
2936 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2938 this->ClientToScreen(event
.GetPosition()));
2939 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2948 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2952 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2956 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2957 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2961 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2963 return eventNotHandledErr
;