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
) ;
215 if (thisWindow
->MacIsUserPane())
220 // panel wants to track the window which was the last to have focus in it
221 wxChildFocusEvent
eventFocus(thisWindow
);
222 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
225 if ( thisWindow
->GetCaret() )
227 thisWindow
->GetCaret()->OnSetFocus();
229 #endif // wxUSE_CARET
231 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
232 event
.SetEventObject(thisWindow
);
233 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
234 if (thisWindow
->MacIsUserPane())
240 case kEventControlHit
:
242 result
= thisWindow
->MacControlHit( handler
, event
) ;
251 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
253 OSStatus result
= eventNotHandledErr
;
255 wxMacCarbonEvent
cEvent( event
) ;
257 ControlRef controlRef
;
258 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
259 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
260 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
262 switch( GetEventKind( event
) )
264 case kEventServiceGetTypes
:
268 textCtrl
->GetSelection( &from
, &to
) ;
270 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
272 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
273 if ( textCtrl
->IsEditable() )
274 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
276 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
277 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
279 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
283 CFArrayAppendValue (copyTypes
, typestring
) ;
285 CFArrayAppendValue (pasteTypes
, typestring
) ;
286 CFRelease( typestring
) ;
292 case kEventServiceCopy
:
296 textCtrl
->GetSelection( &from
, &to
) ;
297 wxString val
= textCtrl
->GetValue() ;
298 val
= val
.Mid( from
, to
- from
) ;
299 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
300 verify_noerr( ClearScrap( &scrapRef
) ) ;
301 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
305 case kEventServicePaste
:
308 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
309 Size textSize
, pastedSize
;
310 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
312 char *content
= new char[textSize
] ;
313 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
314 content
[textSize
-1] = 0 ;
316 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
318 textCtrl
->WriteText( wxString( content
) ) ;
329 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
331 OSStatus result
= eventNotHandledErr
;
333 switch ( GetEventClass( event
) )
335 case kEventClassControl
:
336 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
338 case kEventClassService
:
339 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
346 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
348 // ---------------------------------------------------------------------------
349 // UserPane events for non OSX builds
350 // ---------------------------------------------------------------------------
352 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
354 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
355 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
356 win
->MacControlUserPaneDrawProc(part
) ;
359 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
361 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
362 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
363 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
366 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
368 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
369 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
370 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
373 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
375 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
376 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
377 win
->MacControlUserPaneIdleProc() ;
380 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
382 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
383 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
384 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
387 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
389 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
390 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
391 win
->MacControlUserPaneActivateProc(activating
) ;
394 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
396 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
397 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
398 return win
->MacControlUserPaneFocusProc(action
) ;
401 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
403 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
404 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
405 win
->MacControlUserPaneBackgroundProc(info
) ;
408 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
410 RgnHandle rgn
= NewRgn() ;
412 wxMacWindowStateSaver
sv( this ) ;
413 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
414 MacDoRedraw( rgn
, 0 ) ;
418 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
420 return kControlNoPart
;
423 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
425 return kControlNoPart
;
428 void wxWindowMac::MacControlUserPaneIdleProc()
432 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
434 return kControlNoPart
;
437 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
441 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
443 return kControlNoPart
;
446 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
450 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
451 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
452 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
453 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
454 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
455 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
456 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
457 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
459 // ===========================================================================
461 // ===========================================================================
463 wxList
wxWinMacControlList(wxKEY_INTEGER
);
465 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
467 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
470 return (wxControl
*)node
->GetData();
473 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
475 // adding NULL ControlRef is (first) surely a result of an error and
476 // (secondly) breaks native event processing
477 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
479 if ( !wxWinMacControlList
.Find((long)inControl
) )
480 wxWinMacControlList
.Append((long)inControl
, control
);
483 void wxRemoveMacControlAssociation(wxWindow
*control
)
485 wxWinMacControlList
.DeleteObject(control
);
489 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
491 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
493 // we have to setup the brush in the current port and return noErr
494 // or return an error code so that the control manager walks further up the
495 // hierarchy to find a correct background
497 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
499 OSStatus status
= paramErr
;
502 case kControlMsgApplyTextColor
:
504 case kControlMsgSetUpBackground
:
506 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
510 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
514 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
516 // this clipping is only needed for non HIView
518 RgnHandle clip
= NewRgn() ;
521 wx
->MacWindowToRootWindow( &x
,&y
) ;
522 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
523 OffsetRgn( clip
, x
, y
) ;
530 else if ( wx->MacIsUserPane() )
532 // if we don't have a valid brush for such a control, we have to call the
533 // setup of our parent ourselves
534 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
547 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
548 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
552 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
555 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
560 // ----------------------------------------------------------------------------
561 // constructors and such
562 // ----------------------------------------------------------------------------
564 void wxWindowMac::Init()
567 #if WXWIN_COMPATIBILITY_2_4
568 m_backgroundTransparent
= FALSE
;
571 // as all windows are created with WS_VISIBLE style...
574 m_hScrollBar
= NULL
;
575 m_vScrollBar
= NULL
;
576 m_macBackgroundBrush
= wxNullBrush
;
578 m_macControl
= NULL
;
580 m_macIsUserPane
= TRUE
;
582 // make sure all proc ptrs are available
584 if ( gControlUserPaneDrawUPP
== NULL
)
586 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
587 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
588 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
589 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
590 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
591 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
592 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
593 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
595 if ( wxMacLiveScrollbarActionUPP
== NULL
)
597 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
600 if ( wxMacSetupControlBackgroundUPP
== NULL
)
602 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
605 // we need a valid font for the encodings
606 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
610 wxWindowMac::~wxWindowMac()
614 m_isBeingDeleted
= TRUE
;
616 #ifndef __WXUNIVERSAL__
617 // VS: make sure there's no wxFrame with last focus set to us:
618 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
620 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
623 if ( frame
->GetLastFocus() == this )
625 frame
->SetLastFocus((wxWindow
*)NULL
);
630 #endif // __WXUNIVERSAL__
632 // wxRemoveMacControlAssociation( this ) ;
633 // If we delete an item, we should initialize the parent panel,
634 // because it could now be invalid.
635 wxWindow
*parent
= GetParent() ;
638 if (parent
->GetDefaultItem() == (wxButton
*) this)
639 parent
->SetDefaultItem(NULL
);
641 if ( (ControlRef
) m_macControl
)
643 // in case the callback might be called during destruction
644 wxRemoveMacControlAssociation( this) ;
645 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
646 ::DisposeControl( (ControlRef
) m_macControl
) ;
647 m_macControl
= NULL
;
650 if ( g_MacLastWindow
== this )
652 g_MacLastWindow
= NULL
;
655 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
658 if ( frame
->GetLastFocus() == this )
659 frame
->SetLastFocus( NULL
) ;
664 // delete our drop target if we've got one
665 #if wxUSE_DRAG_AND_DROP
666 if ( m_dropTarget
!= NULL
)
671 #endif // wxUSE_DRAG_AND_DROP
676 void wxWindowMac::MacInstallEventHandler()
678 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
679 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
680 GetEventTypeCount(eventList
), eventList
, this,
681 (EventHandlerRef
*)&m_macControlEventHandler
);
686 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
690 const wxString
& name
)
692 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
694 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
697 parent
->AddChild(this);
699 m_windowVariant
= parent
->GetWindowVariant() ;
701 if ( m_macIsUserPane
)
703 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
706 | kControlSupportsEmbedding
707 // | kControlSupportsLiveFeedback
708 // | kControlHasSpecialBackground
709 // | kControlSupportsCalcBestRect
710 // | kControlHandlesTracking
711 | kControlSupportsFocus
712 // | kControlWantsActivate
713 // | kControlWantsIdle
716 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
718 MacPostControlCreate(pos
,size
) ;
719 #if !TARGET_API_MAC_OSX
720 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
721 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
722 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
723 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
724 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
725 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
726 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
727 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
728 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
729 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
730 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
731 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
732 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
733 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
734 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
735 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
738 #ifndef __WXUNIVERSAL__
739 // Don't give scrollbars to wxControls unless they ask for them
740 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
741 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
743 MacCreateScrollBars( style
) ;
747 wxWindowCreateEvent
event(this);
748 GetEventHandler()->AddPendingEvent(event
);
753 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
755 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
757 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
759 MacInstallEventHandler();
761 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
762 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
763 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
765 // adjust font, controlsize etc
766 DoSetWindowVariant( m_windowVariant
) ;
768 #if !TARGET_API_MAC_OSX
769 // eventually we can fix some clipping issues be reactivating this hook
770 //if ( m_macIsUserPane )
771 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
774 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
776 wxSize new_size
= size
;
777 if (!m_macIsUserPane
)
779 SetInitialBestSize(size
);
782 SetCursor( *wxSTANDARD_CURSOR
) ;
786 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
788 // Don't assert, in case we set the window variant before
789 // the window is created
790 // wxASSERT( m_macControl != NULL ) ;
792 m_windowVariant
= variant
;
798 ThemeFontID themeFont
= kThemeSystemFont
;
800 // we will get that from the settings later
801 // and make this NORMAL later, but first
802 // we have a few calculations that we must fix
806 case wxWINDOW_VARIANT_NORMAL
:
807 size
= kControlSizeNormal
;
808 themeFont
= kThemeSystemFont
;
810 case wxWINDOW_VARIANT_SMALL
:
811 size
= kControlSizeSmall
;
812 themeFont
= kThemeSmallSystemFont
;
814 case wxWINDOW_VARIANT_MINI
:
815 if (UMAGetSystemVersion() >= 0x1030 )
817 // not always defined in the headers
823 size
= kControlSizeSmall
;
824 themeFont
= kThemeSmallSystemFont
;
827 case wxWINDOW_VARIANT_LARGE
:
828 size
= kControlSizeLarge
;
829 themeFont
= kThemeSystemFont
;
832 wxFAIL_MSG(_T("unexpected window variant"));
835 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
838 font
.MacCreateThemeFont( themeFont
) ;
842 void wxWindowMac::MacUpdateControlFont()
844 ControlFontStyleRec fontStyle
;
845 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
847 switch( m_font
.MacGetThemeFontID() )
849 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
850 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
851 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
852 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
854 fontStyle
.flags
= kControlUseFontMask
;
858 fontStyle
.font
= m_font
.MacGetFontNum() ;
859 fontStyle
.style
= m_font
.MacGetFontStyle() ;
860 fontStyle
.size
= m_font
.MacGetFontSize() ;
861 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
864 fontStyle
.just
= teJustLeft
;
865 fontStyle
.flags
|= kControlUseJustMask
;
866 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
867 fontStyle
.just
= teJustCenter
;
868 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
869 fontStyle
.just
= teJustRight
;
872 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
873 fontStyle
.flags
|= kControlUseForeColorMask
;
875 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
879 bool wxWindowMac::SetFont(const wxFont
& font
)
881 bool retval
= !wxWindowBase::SetFont( font
) ;
883 MacUpdateControlFont() ;
888 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
890 if ( !wxWindowBase::SetForegroundColour(col
) )
893 MacUpdateControlFont() ;
898 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
900 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
904 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
906 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
908 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
910 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
914 brush
.SetColour( col
) ;
916 MacSetBackgroundBrush( brush
) ;
918 MacUpdateControlFont() ;
924 bool wxWindowMac::MacCanFocus() const
927 // there is currently no way to determinate whether the window is running in full keyboard
928 // access mode, therefore we cannot rely on these features yet
929 UInt32 features
= 0 ;
930 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
931 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
937 void wxWindowMac::SetFocus()
939 if ( AcceptsFocus() )
941 #if !TARGET_API_MAC_OSX
942 wxWindow
* former
= FindFocus() ;
944 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
945 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
946 // leave in case of an error
947 if ( err
== errCouldntSetFocus
)
950 #if !TARGET_API_MAC_OSX
951 // emulate carbon events when running under carbonlib where they are not natively available
954 EventRef evRef
= NULL
;
955 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
958 wxMacCarbonEvent
cEvent( evRef
) ;
959 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
960 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
962 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
963 ReleaseEvent(evRef
) ;
965 // send new focus event
967 EventRef evRef
= NULL
;
968 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
971 wxMacCarbonEvent
cEvent( evRef
) ;
972 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
973 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
975 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
976 ReleaseEvent(evRef
) ;
983 void wxWindowMac::DoCaptureMouse()
985 wxTheApp
->s_captureWindow
= this ;
988 wxWindow
* wxWindowBase::GetCapture()
990 return wxTheApp
->s_captureWindow
;
993 void wxWindowMac::DoReleaseMouse()
995 wxTheApp
->s_captureWindow
= NULL
;
998 #if wxUSE_DRAG_AND_DROP
1000 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1002 if ( m_dropTarget
!= 0 ) {
1003 delete m_dropTarget
;
1006 m_dropTarget
= pDropTarget
;
1007 if ( m_dropTarget
!= 0 )
1015 // Old style file-manager drag&drop
1016 void wxWindowMac::DragAcceptFiles(bool accept
)
1021 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1022 int& w
, int& h
) const
1025 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1030 w
= bounds
.right
- bounds
.left
;
1031 h
= bounds
.bottom
- bounds
.top
;
1033 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1036 Point tlworigin
= { 0 , 0 } ;
1038 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1039 ::LocalToGlobal( &tlworigin
) ;
1047 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1050 int& w
, int& h
, bool adjustOrigin
) const
1054 // todo the default calls may be used as soon as PostCreateControl Is moved here
1055 w
= size
.x
; // WidthDefault( size.x );
1056 h
= size
.y
; // HeightDefault( size.y ) ;
1057 #if !TARGET_API_MAC_OSX
1058 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1061 AdjustForParentClientOrigin( x
, y
) ;
1066 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1068 #if TARGET_API_MAC_OSX
1069 int x1
, y1
, w1
,h1
;
1070 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1076 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1077 if(x
) *x
= bounds
.right
- bounds
.left
;
1078 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1082 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1084 #if TARGET_API_MAC_OSX
1085 int x1
, y1
, w1
,h1
;
1086 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1087 if ( !IsTopLevel() )
1089 wxWindow
*parent
= GetParent();
1092 wxPoint
pt(parent
->GetClientAreaOrigin());
1101 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1102 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1104 int xx
= bounds
.left
;
1105 int yy
= bounds
.top
;
1107 if ( !GetParent()->IsTopLevel() )
1109 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1115 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1124 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1126 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1128 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1131 Point localwhere
= {0,0} ;
1133 if(x
) localwhere
.h
= * x
;
1134 if(y
) localwhere
.v
= * y
;
1136 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1137 ::GlobalToLocal( &localwhere
) ;
1138 if(x
) *x
= localwhere
.h
;
1139 if(y
) *y
= localwhere
.v
;
1142 MacRootWindowToWindow( x
, y
) ;
1144 wxPoint origin
= GetClientAreaOrigin() ;
1145 if(x
) *x
-= origin
.x
;
1146 if(y
) *y
-= origin
.y
;
1149 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1151 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1152 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1154 wxPoint origin
= GetClientAreaOrigin() ;
1155 if(x
) *x
+= origin
.x
;
1156 if(y
) *y
+= origin
.y
;
1158 MacWindowToRootWindow( x
, y
) ;
1161 Point localwhere
= { 0,0 };
1162 if(x
) localwhere
.h
= * x
;
1163 if(y
) localwhere
.v
= * y
;
1165 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1166 ::LocalToGlobal( &localwhere
) ;
1167 if(x
) *x
= localwhere
.h
;
1168 if(y
) *y
= localwhere
.v
;
1172 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1174 wxPoint origin
= GetClientAreaOrigin() ;
1175 if(x
) *x
+= origin
.x
;
1176 if(y
) *y
+= origin
.y
;
1178 MacWindowToRootWindow( x
, y
) ;
1181 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1183 MacRootWindowToWindow( x
, y
) ;
1185 wxPoint origin
= GetClientAreaOrigin() ;
1186 if(x
) *x
-= origin
.x
;
1187 if(y
) *y
-= origin
.y
;
1190 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1192 #if TARGET_API_MAC_OSX
1194 if ( x
) pt
.x
= *x
;
1195 if ( y
) pt
.y
= *y
;
1197 if ( !IsTopLevel() )
1198 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1200 if ( x
) *x
= (int) pt
.x
;
1201 if ( y
) *y
= (int) pt
.y
;
1203 if ( !IsTopLevel() )
1206 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1207 if(x
) *x
+= bounds
.left
;
1208 if(y
) *y
+= bounds
.top
;
1213 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1218 MacWindowToRootWindow( &x1
, &y1
) ;
1223 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1225 #if TARGET_API_MAC_OSX
1227 if ( x
) pt
.x
= *x
;
1228 if ( y
) pt
.y
= *y
;
1230 if ( !IsTopLevel() )
1231 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1233 if ( x
) *x
= (int) pt
.x
;
1234 if ( y
) *y
= (int) pt
.y
;
1236 if ( !IsTopLevel() )
1239 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1240 if(x
) *x
-= bounds
.left
;
1241 if(y
) *y
-= bounds
.top
;
1246 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1251 MacRootWindowToWindow( &x1
, &y1
) ;
1256 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1258 RgnHandle rgn
= NewRgn() ;
1260 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1262 GetRegionBounds( rgn
, &content
) ;
1267 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1270 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1271 #if !TARGET_API_MAC_OSX
1272 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1274 left
= content
.left
- structure
.left
;
1275 top
= content
.top
- structure
.top
;
1276 right
= structure
.right
- content
.right
;
1277 bottom
= structure
.bottom
- content
.bottom
;
1280 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1282 wxSize sizeTotal
= size
;
1284 RgnHandle rgn
= NewRgn() ;
1288 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1290 GetRegionBounds( rgn
, &content
) ;
1295 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1298 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1299 #if !TARGET_API_MAC_OSX
1300 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1303 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1304 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1306 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1307 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1313 // Get size *available for subwindows* i.e. excluding menu bar etc.
1314 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1318 RgnHandle rgn
= NewRgn() ;
1320 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1322 GetRegionBounds( rgn
, &content
) ;
1327 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1329 #if !TARGET_API_MAC_OSX
1331 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1332 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1334 ww
= content
.right
- content
.left
;
1335 hh
= content
.bottom
- content
.top
;
1337 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1338 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1340 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1346 GetSize( &w
, &h
) ;
1348 MacClientToRootWindow( &x1
, &y1
) ;
1349 MacClientToRootWindow( &w
, &h
) ;
1351 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1353 int totW
= 10000 , totH
= 10000;
1356 if ( iter
->IsTopLevel() )
1358 iter
->GetSize( &totW
, &totH
) ;
1362 iter
= iter
->GetParent() ;
1365 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1367 hh
-= MAC_SCROLLBAR_SIZE
;
1373 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1375 ww
-= MAC_SCROLLBAR_SIZE
;
1387 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1389 if (m_cursor
== cursor
)
1392 if (wxNullCursor
== cursor
)
1394 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1399 if ( ! wxWindowBase::SetCursor( cursor
) )
1403 wxASSERT_MSG( m_cursor
.Ok(),
1404 wxT("cursor must be valid after call to the base version"));
1408 TODO why do we have to use current coordinates ?
1411 wxWindowMac *mouseWin ;
1414 // Change the cursor NOW if we're within the correct window
1417 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1419 if ( mouseWin == this && !wxIsBusy() )
1421 m_cursor.MacInstall() ;
1427 m_cursor
.MacInstall() ;
1434 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1436 menu
->SetInvokingWindow(this);
1438 ClientToScreen( &x
, &y
) ;
1440 menu
->MacBeforeDisplay( true ) ;
1441 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1442 if ( HiWord(menuResult
) != 0 )
1445 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1446 wxMenuItem
* item
= NULL
;
1448 item
= menu
->FindItem(id
, &realmenu
) ;
1449 if (item
->IsCheckable())
1451 item
->Check( !item
->IsChecked() ) ;
1453 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1455 menu
->MacAfterDisplay( true ) ;
1457 menu
->SetInvokingWindow(NULL
);
1463 // ----------------------------------------------------------------------------
1465 // ----------------------------------------------------------------------------
1469 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1471 wxWindowBase::DoSetToolTip(tooltip
);
1474 m_tooltip
->SetWindow(this);
1477 #endif // wxUSE_TOOLTIPS
1479 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1481 int former_x
, former_y
, former_w
, former_h
;
1482 #if !TARGET_API_MAC_OSX
1483 DoGetPosition( &former_x
, &former_y
) ;
1484 DoGetSize( &former_w
, &former_h
) ;
1486 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1489 int actualWidth
= width
;
1490 int actualHeight
= height
;
1494 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1495 actualWidth
= m_minWidth
;
1496 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1497 actualHeight
= m_minHeight
;
1498 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1499 actualWidth
= m_maxWidth
;
1500 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1501 actualHeight
= m_maxHeight
;
1503 bool doMove
= false ;
1504 bool doResize
= false ;
1506 if ( actualX
!= former_x
|| actualY
!= former_y
)
1510 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1515 if ( doMove
|| doResize
)
1517 // we don't adjust twice for the origin
1518 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1519 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1520 #if TARGET_API_MAC_OSX
1521 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1523 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1524 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1525 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1527 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1530 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1531 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1533 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1535 MacRepositionScrollBars() ;
1538 wxPoint
point(actualX
,actualY
);
1539 wxMoveEvent
event(point
, m_windowId
);
1540 event
.SetEventObject(this);
1541 GetEventHandler()->ProcessEvent(event
) ;
1545 MacRepositionScrollBars() ;
1546 wxSize
size(actualWidth
, actualHeight
);
1547 wxSizeEvent
event(size
, m_windowId
);
1548 event
.SetEventObject(this);
1549 GetEventHandler()->ProcessEvent(event
);
1555 wxSize
wxWindowMac::DoGetBestSize() const
1557 if ( m_macIsUserPane
|| IsTopLevel() )
1558 return wxWindowBase::DoGetBestSize() ;
1560 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1561 short baselineoffset
;
1562 int bestWidth
, bestHeight
;
1563 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1565 if ( EmptyRect( &bestsize
) )
1568 bestsize
.left
= bestsize
.top
= 0 ;
1569 bestsize
.right
= 16 ;
1570 bestsize
.bottom
= 16 ;
1571 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1573 bestsize
.bottom
= 16 ;
1575 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1577 bestsize
.bottom
= 24 ;
1581 // return wxWindowBase::DoGetBestSize() ;
1585 bestWidth
= bestsize
.right
- bestsize
.left
;
1586 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1587 if ( bestHeight
< 10 )
1590 return wxSize(bestWidth
, bestHeight
);
1591 // return wxWindowBase::DoGetBestSize() ;
1595 // set the size of the window: if the dimensions are positive, just use them,
1596 // but if any of them is equal to -1, it means that we must find the value for
1597 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1598 // which case -1 is a valid value for x and y)
1600 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1601 // the width/height to best suit our contents, otherwise we reuse the current
1603 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1605 // get the current size and position...
1606 int currentX
, currentY
;
1607 GetPosition(¤tX
, ¤tY
);
1609 int currentW
,currentH
;
1610 GetSize(¤tW
, ¤tH
);
1612 // ... and don't do anything (avoiding flicker) if it's already ok
1613 if ( x
== currentX
&& y
== currentY
&&
1614 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1617 MacRepositionScrollBars() ; // we might have a real position shift
1621 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1623 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1626 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1628 wxSize
size(-1, -1);
1631 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1633 size
= DoGetBestSize();
1638 // just take the current one
1645 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1649 size
= DoGetBestSize();
1651 //else: already called DoGetBestSize() above
1657 // just take the current one
1662 DoMoveWindow(x
, y
, width
, height
);
1666 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1668 RgnHandle rgn
= NewRgn() ;
1670 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1671 GetRegionBounds( rgn
, &content
) ;
1673 #if !TARGET_API_MAC_OSX
1674 // if the content rgn is empty / not supported
1675 // don't attempt to correct the coordinates to wxWindow relative ones
1676 if (!::EmptyRect( &content
) )
1679 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1680 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1684 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1687 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1689 if ( clientheight
!= -1 || clientheight
!= -1 )
1691 int currentclientwidth
, currentclientheight
;
1692 int currentwidth
, currentheight
;
1694 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1695 GetSize( ¤twidth
, ¤theight
) ;
1697 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1698 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1702 void wxWindowMac::SetTitle(const wxString
& title
)
1704 m_label
= wxStripMenuCodes(title
) ;
1708 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1713 wxString
wxWindowMac::GetTitle() const
1718 bool wxWindowMac::Show(bool show
)
1720 if ( !wxWindowBase::Show(show
) )
1723 // TODO use visibilityChanged Carbon Event for OSX
1724 bool former
= MacIsReallyShown() ;
1726 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1727 if ( former
!= MacIsReallyShown() )
1728 MacPropagateVisibilityChanged() ;
1732 bool wxWindowMac::Enable(bool enable
)
1734 wxASSERT( m_macControl
!= NULL
) ;
1735 if ( !wxWindowBase::Enable(enable
) )
1738 bool former
= MacIsReallyEnabled() ;
1739 #if TARGET_API_MAC_OSX
1741 EnableControl( (ControlRef
) m_macControl
) ;
1743 DisableControl( (ControlRef
) m_macControl
) ;
1746 ActivateControl( (ControlRef
) m_macControl
) ;
1748 DeactivateControl( (ControlRef
) m_macControl
) ;
1751 if ( former
!= MacIsReallyEnabled() )
1752 MacPropagateEnabledStateChanged() ;
1757 // status change propagations (will be not necessary for OSX later )
1760 void wxWindowMac::MacPropagateVisibilityChanged()
1762 #if !TARGET_API_MAC_OSX
1763 MacVisibilityChanged() ;
1765 wxWindowListNode
*node
= GetChildren().GetFirst();
1768 wxWindowMac
*child
= node
->GetData();
1769 if ( child
->IsShown() )
1770 child
->MacPropagateVisibilityChanged( ) ;
1771 node
= node
->GetNext();
1776 void wxWindowMac::MacPropagateEnabledStateChanged( )
1778 #if !TARGET_API_MAC_OSX
1779 MacEnabledStateChanged() ;
1781 wxWindowListNode
*node
= GetChildren().GetFirst();
1784 wxWindowMac
*child
= node
->GetData();
1785 if ( child
->IsEnabled() )
1786 child
->MacPropagateEnabledStateChanged() ;
1787 node
= node
->GetNext();
1792 void wxWindowMac::MacPropagateHiliteChanged( )
1794 #if !TARGET_API_MAC_OSX
1795 MacHiliteChanged() ;
1797 wxWindowListNode
*node
= GetChildren().GetFirst();
1800 wxWindowMac
*child
= node
->GetData();
1801 // if ( child->IsEnabled() )
1802 child
->MacPropagateHiliteChanged() ;
1803 node
= node
->GetNext();
1809 // status change notifications
1812 void wxWindowMac::MacVisibilityChanged()
1816 void wxWindowMac::MacHiliteChanged()
1820 void wxWindowMac::MacEnabledStateChanged()
1825 // status queries on the inherited window's state
1828 bool wxWindowMac::MacIsReallyShown()
1830 // only under OSX the visibility of the TLW is taken into account
1831 #if TARGET_API_MAC_OSX
1832 return IsControlVisible( (ControlRef
) m_macControl
) ;
1834 wxWindow
* win
= this ;
1835 while( win
->IsShown() )
1837 if ( win
->IsTopLevel() )
1840 win
= win
->GetParent() ;
1849 bool wxWindowMac::MacIsReallyEnabled()
1851 #if TARGET_API_MAC_OSX
1852 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1854 return IsControlActive( (ControlRef
) m_macControl
) ;
1858 bool wxWindowMac::MacIsReallyHilited()
1860 return IsControlActive( (ControlRef
) m_macControl
) ;
1867 int wxWindowMac::GetCharHeight() const
1869 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1870 return dc
.GetCharHeight() ;
1873 int wxWindowMac::GetCharWidth() const
1875 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1876 return dc
.GetCharWidth() ;
1879 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1880 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1882 const wxFont
*fontToUse
= theFont
;
1884 fontToUse
= &m_font
;
1886 wxClientDC
dc( (wxWindowMac
*) this ) ;
1888 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1889 if ( externalLeading
)
1890 *externalLeading
= le
;
1900 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1901 * we always intersect with the entire window, not only with the client area
1904 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1906 #if TARGET_API_MAC_OSX
1908 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1911 RgnHandle update
= NewRgn() ;
1912 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1913 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1914 wxPoint origin
= GetClientAreaOrigin() ;
1915 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1916 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1920 RgnHandle updateRgn = NewRgn() ;
1923 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1927 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1928 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1930 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1931 DisposeRgn(updateRgn) ;
1933 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1935 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1936 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1939 if ( MacGetTopLevelWindow() == NULL )
1942 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1945 wxPoint client = GetClientAreaOrigin();
1948 int x2 = m_width - client.x;
1949 int y2 = m_height - client.y;
1951 if (IsKindOf( CLASSINFO(wxButton)))
1953 // buttons have an "aura"
1960 Rect clientrect = { y1, x1, y2, x2 };
1964 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1965 SectRect( &clientrect , &r , &clientrect ) ;
1968 if ( !EmptyRect( &clientrect ) )
1970 int top = 0 , left = 0 ;
1972 MacClientToRootWindow( &left , &top ) ;
1973 OffsetRect( &clientrect , left , top ) ;
1975 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1981 void wxWindowMac::Freeze()
1983 #if TARGET_API_MAC_OSX
1984 if ( !m_frozenness
++ )
1986 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1991 #if TARGET_API_MAC_OSX
1992 static void InvalidateControlAndChildren( HIViewRef control
)
1994 HIViewSetNeedsDisplay( control
, true ) ;
1995 UInt16 childrenCount
= 0 ;
1996 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1997 if ( err
== errControlIsNotEmbedder
)
1999 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2001 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2004 err
= GetIndexedSubControl( control
, i
, & child
) ;
2005 if ( err
== errControlIsNotEmbedder
)
2007 InvalidateControlAndChildren( child
) ;
2012 void wxWindowMac::Thaw()
2014 #if TARGET_API_MAC_OSX
2015 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2017 if ( !--m_frozenness
)
2019 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2020 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2021 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2026 void wxWindowMac::MacRedrawControl()
2029 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2031 #if TARGET_API_MAC_CARBON
2034 wxClientDC dc(this) ;
2035 wxMacPortSetter helper(&dc) ;
2036 wxMacWindowClipper clipper(this) ;
2037 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2038 UMADrawControl( (ControlRef) m_macControl ) ;
2045 void wxWindowMac::OnPaint(wxPaintEvent& event)
2047 // why don't we skip that here ?
2051 wxWindowMac
*wxGetActiveWindow()
2053 // actually this is a windows-only concept
2057 // Coordinates relative to the window
2058 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2060 // We really don't move the mouse programmatically under Mac.
2063 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2065 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2070 event
.GetDC()->Clear() ;
2073 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2075 wxWindowDC
dc(this) ;
2076 wxMacPortSetter
helper(&dc
) ;
2078 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2081 int wxWindowMac::GetScrollPos(int orient
) const
2083 if ( orient
== wxHORIZONTAL
)
2086 return m_hScrollBar
->GetThumbPosition() ;
2091 return m_vScrollBar
->GetThumbPosition() ;
2096 // This now returns the whole range, not just the number
2097 // of positions that we can scroll.
2098 int wxWindowMac::GetScrollRange(int orient
) const
2100 if ( orient
== wxHORIZONTAL
)
2103 return m_hScrollBar
->GetRange() ;
2108 return m_vScrollBar
->GetRange() ;
2113 int wxWindowMac::GetScrollThumb(int orient
) const
2115 if ( orient
== wxHORIZONTAL
)
2118 return m_hScrollBar
->GetThumbSize() ;
2123 return m_vScrollBar
->GetThumbSize() ;
2128 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2130 if ( orient
== wxHORIZONTAL
)
2133 m_hScrollBar
->SetThumbPosition( pos
) ;
2138 m_vScrollBar
->SetThumbPosition( pos
) ;
2142 void wxWindowMac::MacPaintBorders( int left
, int top
)
2148 wxGetOsVersion( &major
, &minor
);
2150 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2151 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2153 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2154 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2155 // OS X has lighter border edges than classic:
2158 darkShadow
.red
= 0x8E8E;
2159 darkShadow
.green
= 0x8E8E;
2160 darkShadow
.blue
= 0x8E8E;
2161 lightShadow
.red
= 0xBDBD;
2162 lightShadow
.green
= 0xBDBD;
2163 lightShadow
.blue
= 0xBDBD;
2169 GetSize( &w
, &h
) ;
2170 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2172 #if wxMAC_USE_THEME_BORDER
2173 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2176 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2177 InsetRect( &rect , border , border );
2178 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2181 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2183 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2184 RGBForeColor( &face
);
2185 MoveTo( left
+ 0 , top
+ h
- 2 );
2186 LineTo( left
+ 0 , top
+ 0 );
2187 LineTo( left
+ w
- 2 , top
+ 0 );
2189 MoveTo( left
+ 2 , top
+ h
- 3 );
2190 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2191 LineTo( left
+ w
- 3 , top
+ 2 );
2193 RGBForeColor( sunken
? &face
: &darkShadow
);
2194 MoveTo( left
+ 0 , top
+ h
- 1 );
2195 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2196 LineTo( left
+ w
- 1 , top
+ 0 );
2198 RGBForeColor( sunken
? &lightShadow
: &white
);
2199 MoveTo( left
+ 1 , top
+ h
- 3 );
2200 LineTo( left
+ 1, top
+ 1 );
2201 LineTo( left
+ w
- 3 , top
+ 1 );
2203 RGBForeColor( sunken
? &white
: &lightShadow
);
2204 MoveTo( left
+ 1 , top
+ h
- 2 );
2205 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2206 LineTo( left
+ w
- 2 , top
+ 1 );
2208 RGBForeColor( sunken
? &darkShadow
: &face
);
2209 MoveTo( left
+ 2 , top
+ h
- 4 );
2210 LineTo( left
+ 2 , top
+ 2 );
2211 LineTo( left
+ w
- 4 , top
+ 2 );
2214 else if (HasFlag(wxSIMPLE_BORDER
))
2216 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2217 RGBForeColor( &darkShadow
) ;
2218 FrameRect( &rect
) ;
2222 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2224 if ( child
== m_hScrollBar
)
2225 m_hScrollBar
= NULL
;
2226 if ( child
== m_vScrollBar
)
2227 m_vScrollBar
= NULL
;
2229 wxWindowBase::RemoveChild( child
) ;
2232 // New function that will replace some of the above.
2233 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2234 int range
, bool refresh
)
2236 if ( orient
== wxHORIZONTAL
)
2240 if ( range
== 0 || thumbVisible
>= range
)
2242 if ( m_hScrollBar
->IsShown() )
2243 m_hScrollBar
->Show(false) ;
2247 if ( !m_hScrollBar
->IsShown() )
2248 m_hScrollBar
->Show(true) ;
2249 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2257 if ( range
== 0 || thumbVisible
>= range
)
2259 if ( m_vScrollBar
->IsShown() )
2260 m_vScrollBar
->Show(false) ;
2264 if ( !m_vScrollBar
->IsShown() )
2265 m_vScrollBar
->Show(true) ;
2266 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2270 MacRepositionScrollBars() ;
2273 // Does a physical scroll
2274 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2276 if( dx
== 0 && dy
==0 )
2281 wxClientDC
dc(this) ;
2282 wxMacPortSetter
helper(&dc
) ;
2284 int width
, height
;
2285 GetClientSize( &width
, &height
) ;
2292 // TODO take out the boundaries
2293 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2295 RgnHandle updateRgn
= NewRgn() ;
2298 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2299 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2300 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2302 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2304 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2305 // but it seems the update only refreshes the background of the control, rather than calling
2306 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2307 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2310 // we also have to scroll the update rgn in this rectangle
2311 // in order not to loose updates
2313 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2314 RgnHandle formerUpdateRgn
= NewRgn() ;
2315 RgnHandle scrollRgn
= NewRgn() ;
2316 RectRgn( scrollRgn
, &scrollrect
) ;
2317 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2319 LocalToGlobal( &pt
) ;
2320 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2321 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2322 if ( !EmptyRgn( formerUpdateRgn
) )
2324 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2325 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2326 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2328 InvalWindowRgn(rootWindow
, updateRgn
) ;
2329 DisposeRgn( updateRgn
) ;
2330 DisposeRgn( formerUpdateRgn
) ;
2331 DisposeRgn( scrollRgn
) ;
2335 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2337 wxWindowMac
*child
= node
->GetData();
2338 if (child
== m_vScrollBar
) continue;
2339 if (child
== m_hScrollBar
) continue;
2340 if (child
->IsTopLevel()) continue;
2343 child
->GetPosition( &x
, &y
);
2345 child
->GetSize( &w
, &h
);
2349 if (rect
->Intersects(rc
))
2350 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2354 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2358 // TODO remove, was moved higher up Update() ;
2362 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2364 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2366 wxScrollWinEvent wevent
;
2367 wevent
.SetPosition(event
.GetPosition());
2368 wevent
.SetOrientation(event
.GetOrientation());
2369 wevent
.m_eventObject
= this;
2371 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2372 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2373 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2374 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2375 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2377 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2378 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2379 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2380 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2381 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2382 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2383 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2384 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2385 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2386 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2388 GetEventHandler()->ProcessEvent(wevent
);
2392 // Get the window with the focus
2393 wxWindowMac
*wxWindowBase::FindFocus()
2395 ControlRef control
;
2396 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2397 return wxFindControlFromMacControl( control
) ;
2400 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2402 // panel wants to track the window which was the last to have focus in it,
2403 // so we want to set ourselves as the window which last had focus
2405 // notice that it's also important to do it upwards the tree becaus
2406 // otherwise when the top level panel gets focus, it won't set it back to
2407 // us, but to some other sibling
2409 // CS:don't know if this is still needed:
2410 //wxChildFocusEvent eventFocus(this);
2411 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2416 void wxWindowMac::OnInternalIdle()
2418 // This calls the UI-update mechanism (querying windows for
2419 // menu/toolbar/control state information)
2420 if (wxUpdateUIEvent::CanUpdate(this))
2421 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2424 // Raise the window to the top of the Z order
2425 void wxWindowMac::Raise()
2427 #if TARGET_API_MAC_OSX
2428 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2432 // Lower the window to the bottom of the Z order
2433 void wxWindowMac::Lower()
2435 #if TARGET_API_MAC_OSX
2436 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2441 // static wxWindow *gs_lastWhich = NULL;
2443 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2445 // first trigger a set cursor event
2447 wxPoint clientorigin
= GetClientAreaOrigin() ;
2448 wxSize clientsize
= GetClientSize() ;
2450 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2452 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2454 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2455 if ( processedEvtSetCursor
&& event
.HasCursor() )
2457 cursor
= event
.GetCursor() ;
2462 // the test for processedEvtSetCursor is here to prevent using m_cursor
2463 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2464 // it - this is a way to say that our cursor shouldn't be used for this
2466 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2476 cursor
= *wxSTANDARD_CURSOR
;
2480 cursor
.MacInstall() ;
2482 return cursor
.Ok() ;
2485 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2489 return m_tooltip
->GetTip() ;
2491 return wxEmptyString
;
2494 void wxWindowMac::Update()
2496 #if TARGET_API_MAC_OSX
2497 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2499 ::Draw1Control( (ControlRef
) m_macControl
) ;
2503 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2505 wxTopLevelWindowMac
* win
= NULL
;
2506 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2509 win
= wxFindWinFromMacWindow( window
) ;
2513 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2517 RgnHandle visRgn
= NewRgn() ;
2518 RgnHandle tempRgn
= NewRgn() ;
2519 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2521 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2522 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2524 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2525 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2534 if ( includeOuterStructures
)
2535 InsetRect( &r
, -3 , -3 ) ;
2536 RectRgn( visRgn
, &r
) ;
2537 if ( !IsTopLevel() )
2539 wxWindow
* child
= this ;
2540 wxWindow
* parent
= child
->GetParent() ;
2545 // we have to find a better clipping algorithm here, in order not to clip things
2546 // positioned like status and toolbar
2547 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2549 size
= parent
->GetSize() ;
2554 size
= parent
->GetClientSize() ;
2555 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2559 parent
->MacWindowToRootWindow( &x
, &y
) ;
2560 MacRootWindowToWindow( &x
, &y
) ;
2562 SetRectRgn( tempRgn
,
2563 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2564 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2565 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2567 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2568 if ( parent
->IsTopLevel() )
2571 parent
= child
->GetParent() ;
2576 wxRegion vis
= visRgn
;
2577 DisposeRgn( visRgn
) ;
2578 DisposeRgn( tempRgn
) ;
2583 This function must not change the updatergn !
2585 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2587 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2588 bool handled
= false ;
2590 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2592 RgnHandle newupdate
= NewRgn() ;
2593 wxSize point
= GetClientSize() ;
2594 wxPoint origin
= GetClientAreaOrigin() ;
2595 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2596 SectRgn( newupdate
, updatergn
, newupdate
) ;
2597 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2598 m_updateRegion
= newupdate
;
2599 DisposeRgn( newupdate
) ;
2602 if ( !EmptyRgn(updatergn
) )
2604 wxWindowDC
dc(this);
2605 if (!EmptyRgn(updatergn
))
2606 dc
.SetClippingRegion(wxRegion(updatergn
));
2608 wxEraseEvent
eevent( GetId(), &dc
);
2609 eevent
.SetEventObject( this );
2610 GetEventHandler()->ProcessEvent( eevent
);
2612 if ( !m_updateRegion
.Empty() )
2614 // paint the window itself
2616 event
.m_timeStamp
= time
;
2617 event
.SetEventObject(this);
2618 handled
= GetEventHandler()->ProcessEvent(event
);
2620 // paint custom borders
2621 wxNcPaintEvent
eventNc( GetId() );
2622 eventNc
.SetEventObject( this );
2623 GetEventHandler()->ProcessEvent( eventNc
);
2629 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2631 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2632 // updatergn is always already clipped to our boundaries
2633 // if we are in compositing mode then it is in relative to the upper left of the control
2634 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2635 // of the toplevel window
2636 // it is in window coordinates, not in client coordinates
2638 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2639 RgnHandle ownUpdateRgn
= NewRgn() ;
2640 CopyRgn( updatergn
, ownUpdateRgn
) ;
2642 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2645 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2646 RgnHandle controlRgn
= NewRgn();
2647 RectRgn( controlRgn
, &bounds
);
2648 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2649 // the window update region
2650 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2651 DisposeRgn( controlRgn
);
2653 //KO: convert ownUpdateRgn to local coordinates
2654 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2657 MacDoRedraw( ownUpdateRgn
, time
) ;
2658 DisposeRgn( ownUpdateRgn
) ;
2662 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2664 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2668 if ( iter
->IsTopLevel() )
2669 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2671 iter
= iter
->GetParent() ;
2673 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2677 void wxWindowMac::MacCreateScrollBars( long style
)
2679 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2681 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2682 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2684 GetClientSize( &width
, &height
) ;
2686 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2687 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2688 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2689 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2691 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2692 vSize
, wxVERTICAL
);
2694 if ( style
& wxVSCROLL
)
2700 m_vScrollBar
->Show(false) ;
2702 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2703 hSize
, wxHORIZONTAL
);
2704 if ( style
& wxHSCROLL
)
2709 m_hScrollBar
->Show(false) ;
2712 // because the create does not take into account the client area origin
2713 MacRepositionScrollBars() ; // we might have a real position shift
2716 void wxWindowMac::MacRepositionScrollBars()
2718 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2719 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2721 // get real client area
2725 GetSize( &width
, &height
) ;
2727 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2728 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2730 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2731 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2732 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2733 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2739 GetSize( &w
, &h
) ;
2741 MacClientToRootWindow( &x
, &y
) ;
2742 MacClientToRootWindow( &w
, &h
) ;
2744 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2746 int totW
= 10000 , totH
= 10000;
2749 if ( iter
->IsTopLevel() )
2751 iter
->GetSize( &totW
, &totH
) ;
2755 iter
= iter
->GetParent() ;
2783 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2787 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2791 bool wxWindowMac::AcceptsFocus() const
2793 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2796 void wxWindowMac::MacSuperChangedPosition()
2798 // only window-absolute structures have to be moved i.e. controls
2800 wxWindowListNode
*node
= GetChildren().GetFirst();
2803 wxWindowMac
*child
= node
->GetData();
2804 child
->MacSuperChangedPosition() ;
2805 node
= node
->GetNext();
2809 void wxWindowMac::MacTopLevelWindowChangedPosition()
2811 // only screen-absolute structures have to be moved i.e. glcanvas
2813 wxWindowListNode
*node
= GetChildren().GetFirst();
2816 wxWindowMac
*child
= node
->GetData();
2817 child
->MacTopLevelWindowChangedPosition() ;
2818 node
= node
->GetNext();
2822 long wxWindowMac::MacGetLeftBorderSize( ) const
2827 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2830 #if wxMAC_USE_THEME_BORDER
2831 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2835 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2838 #if wxMAC_USE_THEME_BORDER
2839 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2843 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2850 long wxWindowMac::MacGetRightBorderSize( ) const
2852 // they are all symmetric in mac themes
2853 return MacGetLeftBorderSize() ;
2856 long wxWindowMac::MacGetTopBorderSize( ) const
2858 // they are all symmetric in mac themes
2859 return MacGetLeftBorderSize() ;
2862 long wxWindowMac::MacGetBottomBorderSize( ) const
2864 // they are all symmetric in mac themes
2865 return MacGetLeftBorderSize() ;
2868 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2870 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2873 // Find the wxWindowMac at the current mouse position, returning the mouse
2875 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2877 pt
= wxGetMousePosition();
2878 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2882 // Get the current mouse position.
2883 wxPoint
wxGetMousePosition()
2886 wxGetMousePosition(& x
, & y
);
2887 return wxPoint(x
, y
);
2890 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2892 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2894 // copied from wxGTK : CS
2895 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2898 // (a) it's a command event and so is propagated to the parent
2899 // (b) under MSW it can be generated from kbd too
2900 // (c) it uses screen coords (because of (a))
2901 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2903 this->ClientToScreen(event
.GetPosition()));
2904 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2913 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2917 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2921 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2922 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2926 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2928 return eventNotHandledErr
;