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 if (!m_macIsUserPane
)
778 SetInitialBestSize(size
);
781 SetCursor( *wxSTANDARD_CURSOR
) ;
784 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
786 // Don't assert, in case we set the window variant before
787 // the window is created
788 // wxASSERT( m_macControl != NULL ) ;
790 m_windowVariant
= variant
;
796 ThemeFontID themeFont
= kThemeSystemFont
;
798 // we will get that from the settings later
799 // and make this NORMAL later, but first
800 // we have a few calculations that we must fix
804 case wxWINDOW_VARIANT_NORMAL
:
805 size
= kControlSizeNormal
;
806 themeFont
= kThemeSystemFont
;
808 case wxWINDOW_VARIANT_SMALL
:
809 size
= kControlSizeSmall
;
810 themeFont
= kThemeSmallSystemFont
;
812 case wxWINDOW_VARIANT_MINI
:
813 if (UMAGetSystemVersion() >= 0x1030 )
815 // not always defined in the headers
821 size
= kControlSizeSmall
;
822 themeFont
= kThemeSmallSystemFont
;
825 case wxWINDOW_VARIANT_LARGE
:
826 size
= kControlSizeLarge
;
827 themeFont
= kThemeSystemFont
;
830 wxFAIL_MSG(_T("unexpected window variant"));
833 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
836 font
.MacCreateThemeFont( themeFont
) ;
840 void wxWindowMac::MacUpdateControlFont()
842 ControlFontStyleRec fontStyle
;
843 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
845 switch( m_font
.MacGetThemeFontID() )
847 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
848 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
849 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
850 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
852 fontStyle
.flags
= kControlUseFontMask
;
856 fontStyle
.font
= m_font
.MacGetFontNum() ;
857 fontStyle
.style
= m_font
.MacGetFontStyle() ;
858 fontStyle
.size
= m_font
.MacGetFontSize() ;
859 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
862 fontStyle
.just
= teJustLeft
;
863 fontStyle
.flags
|= kControlUseJustMask
;
864 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
865 fontStyle
.just
= teJustCenter
;
866 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
867 fontStyle
.just
= teJustRight
;
870 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
871 fontStyle
.flags
|= kControlUseForeColorMask
;
873 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
877 bool wxWindowMac::SetFont(const wxFont
& font
)
879 bool retval
= !wxWindowBase::SetFont( font
) ;
881 MacUpdateControlFont() ;
886 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
888 if ( !wxWindowBase::SetForegroundColour(col
) )
891 MacUpdateControlFont() ;
896 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
898 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
902 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
904 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
906 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
908 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
912 brush
.SetColour( col
) ;
914 MacSetBackgroundBrush( brush
) ;
916 MacUpdateControlFont() ;
922 bool wxWindowMac::MacCanFocus() const
925 // there is currently no way to determinate whether the window is running in full keyboard
926 // access mode, therefore we cannot rely on these features yet
927 UInt32 features
= 0 ;
928 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
929 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
935 void wxWindowMac::SetFocus()
937 if ( AcceptsFocus() )
939 #if !TARGET_API_MAC_OSX
940 wxWindow
* former
= FindFocus() ;
942 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
943 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
944 // leave in case of an error
945 if ( err
== errCouldntSetFocus
)
948 #if !TARGET_API_MAC_OSX
949 // emulate carbon events when running under carbonlib where they are not natively available
952 EventRef evRef
= NULL
;
953 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
956 wxMacCarbonEvent
cEvent( evRef
) ;
957 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
958 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
960 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
961 ReleaseEvent(evRef
) ;
963 // send new focus event
965 EventRef evRef
= NULL
;
966 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
969 wxMacCarbonEvent
cEvent( evRef
) ;
970 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
971 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
973 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
974 ReleaseEvent(evRef
) ;
981 void wxWindowMac::DoCaptureMouse()
983 wxTheApp
->s_captureWindow
= this ;
986 wxWindow
* wxWindowBase::GetCapture()
988 return wxTheApp
->s_captureWindow
;
991 void wxWindowMac::DoReleaseMouse()
993 wxTheApp
->s_captureWindow
= NULL
;
996 #if wxUSE_DRAG_AND_DROP
998 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1000 if ( m_dropTarget
!= 0 ) {
1001 delete m_dropTarget
;
1004 m_dropTarget
= pDropTarget
;
1005 if ( m_dropTarget
!= 0 )
1013 // Old style file-manager drag&drop
1014 void wxWindowMac::DragAcceptFiles(bool accept
)
1019 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1020 int& w
, int& h
) const
1023 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1028 w
= bounds
.right
- bounds
.left
;
1029 h
= bounds
.bottom
- bounds
.top
;
1031 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1034 Point tlworigin
= { 0 , 0 } ;
1036 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1037 ::LocalToGlobal( &tlworigin
) ;
1045 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1048 int& w
, int& h
, bool adjustOrigin
) const
1052 // todo the default calls may be used as soon as PostCreateControl Is moved here
1053 w
= size
.x
; // WidthDefault( size.x );
1054 h
= size
.y
; // HeightDefault( size.y ) ;
1055 #if !TARGET_API_MAC_OSX
1056 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1059 AdjustForParentClientOrigin( x
, y
) ;
1064 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1066 #if TARGET_API_MAC_OSX
1067 int x1
, y1
, w1
,h1
;
1068 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1074 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1075 if(x
) *x
= bounds
.right
- bounds
.left
;
1076 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1080 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1082 #if TARGET_API_MAC_OSX
1083 int x1
, y1
, w1
,h1
;
1084 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1085 if ( !IsTopLevel() )
1087 wxWindow
*parent
= GetParent();
1090 wxPoint
pt(parent
->GetClientAreaOrigin());
1099 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1100 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1102 int xx
= bounds
.left
;
1103 int yy
= bounds
.top
;
1105 if ( !GetParent()->IsTopLevel() )
1107 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1113 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1122 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1124 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1126 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1129 Point localwhere
= {0,0} ;
1131 if(x
) localwhere
.h
= * x
;
1132 if(y
) localwhere
.v
= * y
;
1134 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1135 ::GlobalToLocal( &localwhere
) ;
1136 if(x
) *x
= localwhere
.h
;
1137 if(y
) *y
= localwhere
.v
;
1140 MacRootWindowToWindow( x
, y
) ;
1142 wxPoint origin
= GetClientAreaOrigin() ;
1143 if(x
) *x
-= origin
.x
;
1144 if(y
) *y
-= origin
.y
;
1147 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1149 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1150 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1152 wxPoint origin
= GetClientAreaOrigin() ;
1153 if(x
) *x
+= origin
.x
;
1154 if(y
) *y
+= origin
.y
;
1156 MacWindowToRootWindow( x
, y
) ;
1159 Point localwhere
= { 0,0 };
1160 if(x
) localwhere
.h
= * x
;
1161 if(y
) localwhere
.v
= * y
;
1163 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1164 ::LocalToGlobal( &localwhere
) ;
1165 if(x
) *x
= localwhere
.h
;
1166 if(y
) *y
= localwhere
.v
;
1170 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1172 wxPoint origin
= GetClientAreaOrigin() ;
1173 if(x
) *x
+= origin
.x
;
1174 if(y
) *y
+= origin
.y
;
1176 MacWindowToRootWindow( x
, y
) ;
1179 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1181 MacRootWindowToWindow( x
, y
) ;
1183 wxPoint origin
= GetClientAreaOrigin() ;
1184 if(x
) *x
-= origin
.x
;
1185 if(y
) *y
-= origin
.y
;
1188 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1190 #if TARGET_API_MAC_OSX
1192 if ( x
) pt
.x
= *x
;
1193 if ( y
) pt
.y
= *y
;
1195 if ( !IsTopLevel() )
1196 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1198 if ( x
) *x
= (int) pt
.x
;
1199 if ( y
) *y
= (int) pt
.y
;
1201 if ( !IsTopLevel() )
1204 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1205 if(x
) *x
+= bounds
.left
;
1206 if(y
) *y
+= bounds
.top
;
1211 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1216 MacWindowToRootWindow( &x1
, &y1
) ;
1221 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1223 #if TARGET_API_MAC_OSX
1225 if ( x
) pt
.x
= *x
;
1226 if ( y
) pt
.y
= *y
;
1228 if ( !IsTopLevel() )
1229 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1231 if ( x
) *x
= (int) pt
.x
;
1232 if ( y
) *y
= (int) pt
.y
;
1234 if ( !IsTopLevel() )
1237 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1238 if(x
) *x
-= bounds
.left
;
1239 if(y
) *y
-= bounds
.top
;
1244 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1249 MacRootWindowToWindow( &x1
, &y1
) ;
1254 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1256 RgnHandle rgn
= NewRgn() ;
1258 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1260 GetRegionBounds( rgn
, &content
) ;
1265 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1268 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1269 #if !TARGET_API_MAC_OSX
1270 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1272 left
= content
.left
- structure
.left
;
1273 top
= content
.top
- structure
.top
;
1274 right
= structure
.right
- content
.right
;
1275 bottom
= structure
.bottom
- content
.bottom
;
1278 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1280 wxSize sizeTotal
= size
;
1282 RgnHandle rgn
= NewRgn() ;
1286 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1288 GetRegionBounds( rgn
, &content
) ;
1293 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1296 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1297 #if !TARGET_API_MAC_OSX
1298 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1301 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1302 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1304 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1305 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1311 // Get size *available for subwindows* i.e. excluding menu bar etc.
1312 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1316 RgnHandle rgn
= NewRgn() ;
1318 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1320 GetRegionBounds( rgn
, &content
) ;
1325 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1327 #if !TARGET_API_MAC_OSX
1329 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1330 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1332 ww
= content
.right
- content
.left
;
1333 hh
= content
.bottom
- content
.top
;
1335 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1336 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1338 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1344 GetSize( &w
, &h
) ;
1346 MacClientToRootWindow( &x1
, &y1
) ;
1347 MacClientToRootWindow( &w
, &h
) ;
1349 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1351 int totW
= 10000 , totH
= 10000;
1354 if ( iter
->IsTopLevel() )
1356 iter
->GetSize( &totW
, &totH
) ;
1360 iter
= iter
->GetParent() ;
1363 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1365 hh
-= MAC_SCROLLBAR_SIZE
;
1371 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1373 ww
-= MAC_SCROLLBAR_SIZE
;
1385 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1387 if (m_cursor
== cursor
)
1390 if (wxNullCursor
== cursor
)
1392 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1397 if ( ! wxWindowBase::SetCursor( cursor
) )
1401 wxASSERT_MSG( m_cursor
.Ok(),
1402 wxT("cursor must be valid after call to the base version"));
1406 TODO why do we have to use current coordinates ?
1409 wxWindowMac *mouseWin ;
1412 // Change the cursor NOW if we're within the correct window
1415 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1417 if ( mouseWin == this && !wxIsBusy() )
1419 m_cursor.MacInstall() ;
1425 m_cursor
.MacInstall() ;
1432 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1434 menu
->SetInvokingWindow(this);
1436 ClientToScreen( &x
, &y
) ;
1438 menu
->MacBeforeDisplay( true ) ;
1439 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1440 if ( HiWord(menuResult
) != 0 )
1443 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1444 wxMenuItem
* item
= NULL
;
1446 item
= menu
->FindItem(id
, &realmenu
) ;
1447 if (item
->IsCheckable())
1449 item
->Check( !item
->IsChecked() ) ;
1451 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1453 menu
->MacAfterDisplay( true ) ;
1455 menu
->SetInvokingWindow(NULL
);
1461 // ----------------------------------------------------------------------------
1463 // ----------------------------------------------------------------------------
1467 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1469 wxWindowBase::DoSetToolTip(tooltip
);
1472 m_tooltip
->SetWindow(this);
1475 #endif // wxUSE_TOOLTIPS
1477 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1479 int former_x
, former_y
, former_w
, former_h
;
1480 #if !TARGET_API_MAC_OSX
1481 DoGetPosition( &former_x
, &former_y
) ;
1482 DoGetSize( &former_w
, &former_h
) ;
1484 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1487 int actualWidth
= width
;
1488 int actualHeight
= height
;
1492 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1493 actualWidth
= m_minWidth
;
1494 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1495 actualHeight
= m_minHeight
;
1496 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1497 actualWidth
= m_maxWidth
;
1498 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1499 actualHeight
= m_maxHeight
;
1501 bool doMove
= false ;
1502 bool doResize
= false ;
1504 if ( actualX
!= former_x
|| actualY
!= former_y
)
1508 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1513 if ( doMove
|| doResize
)
1515 // we don't adjust twice for the origin
1516 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1517 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1518 #if TARGET_API_MAC_OSX
1519 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1521 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1522 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1523 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1525 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1528 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1529 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1531 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1533 MacRepositionScrollBars() ;
1536 wxPoint
point(actualX
,actualY
);
1537 wxMoveEvent
event(point
, m_windowId
);
1538 event
.SetEventObject(this);
1539 GetEventHandler()->ProcessEvent(event
) ;
1543 MacRepositionScrollBars() ;
1544 wxSize
size(actualWidth
, actualHeight
);
1545 wxSizeEvent
event(size
, m_windowId
);
1546 event
.SetEventObject(this);
1547 GetEventHandler()->ProcessEvent(event
);
1553 wxSize
wxWindowMac::DoGetBestSize() const
1555 if ( m_macIsUserPane
|| IsTopLevel() )
1556 return wxWindowBase::DoGetBestSize() ;
1558 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1559 short baselineoffset
;
1560 int bestWidth
, bestHeight
;
1561 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1563 if ( EmptyRect( &bestsize
) )
1566 bestsize
.left
= bestsize
.top
= 0 ;
1567 bestsize
.right
= 16 ;
1568 bestsize
.bottom
= 16 ;
1569 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1571 bestsize
.bottom
= 16 ;
1573 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1575 bestsize
.bottom
= 24 ;
1579 // return wxWindowBase::DoGetBestSize() ;
1583 bestWidth
= bestsize
.right
- bestsize
.left
;
1584 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1585 if ( bestHeight
< 10 )
1588 return wxSize(bestWidth
, bestHeight
);
1589 // return wxWindowBase::DoGetBestSize() ;
1593 // set the size of the window: if the dimensions are positive, just use them,
1594 // but if any of them is equal to -1, it means that we must find the value for
1595 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1596 // which case -1 is a valid value for x and y)
1598 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1599 // the width/height to best suit our contents, otherwise we reuse the current
1601 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1603 // get the current size and position...
1604 int currentX
, currentY
;
1605 GetPosition(¤tX
, ¤tY
);
1607 int currentW
,currentH
;
1608 GetSize(¤tW
, ¤tH
);
1610 // ... and don't do anything (avoiding flicker) if it's already ok
1611 if ( x
== currentX
&& y
== currentY
&&
1612 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1615 MacRepositionScrollBars() ; // we might have a real position shift
1619 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1621 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1624 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1626 wxSize
size(-1, -1);
1629 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1631 size
= DoGetBestSize();
1636 // just take the current one
1643 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1647 size
= DoGetBestSize();
1649 //else: already called DoGetBestSize() above
1655 // just take the current one
1660 DoMoveWindow(x
, y
, width
, height
);
1664 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1666 RgnHandle rgn
= NewRgn() ;
1668 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1669 GetRegionBounds( rgn
, &content
) ;
1671 #if !TARGET_API_MAC_OSX
1672 // if the content rgn is empty / not supported
1673 // don't attempt to correct the coordinates to wxWindow relative ones
1674 if (!::EmptyRect( &content
) )
1677 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1678 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1682 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1685 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1687 if ( clientheight
!= -1 || clientheight
!= -1 )
1689 int currentclientwidth
, currentclientheight
;
1690 int currentwidth
, currentheight
;
1692 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1693 GetSize( ¤twidth
, ¤theight
) ;
1695 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1696 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1700 void wxWindowMac::SetTitle(const wxString
& title
)
1702 m_label
= wxStripMenuCodes(title
) ;
1706 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1711 wxString
wxWindowMac::GetTitle() const
1716 bool wxWindowMac::Show(bool show
)
1718 if ( !wxWindowBase::Show(show
) )
1721 // TODO use visibilityChanged Carbon Event for OSX
1722 bool former
= MacIsReallyShown() ;
1724 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1725 if ( former
!= MacIsReallyShown() )
1726 MacPropagateVisibilityChanged() ;
1730 bool wxWindowMac::Enable(bool enable
)
1732 wxASSERT( m_macControl
!= NULL
) ;
1733 if ( !wxWindowBase::Enable(enable
) )
1736 bool former
= MacIsReallyEnabled() ;
1737 #if TARGET_API_MAC_OSX
1739 EnableControl( (ControlRef
) m_macControl
) ;
1741 DisableControl( (ControlRef
) m_macControl
) ;
1744 ActivateControl( (ControlRef
) m_macControl
) ;
1746 DeactivateControl( (ControlRef
) m_macControl
) ;
1749 if ( former
!= MacIsReallyEnabled() )
1750 MacPropagateEnabledStateChanged() ;
1755 // status change propagations (will be not necessary for OSX later )
1758 void wxWindowMac::MacPropagateVisibilityChanged()
1760 #if !TARGET_API_MAC_OSX
1761 MacVisibilityChanged() ;
1763 wxWindowListNode
*node
= GetChildren().GetFirst();
1766 wxWindowMac
*child
= node
->GetData();
1767 if ( child
->IsShown() )
1768 child
->MacPropagateVisibilityChanged( ) ;
1769 node
= node
->GetNext();
1774 void wxWindowMac::MacPropagateEnabledStateChanged( )
1776 #if !TARGET_API_MAC_OSX
1777 MacEnabledStateChanged() ;
1779 wxWindowListNode
*node
= GetChildren().GetFirst();
1782 wxWindowMac
*child
= node
->GetData();
1783 if ( child
->IsEnabled() )
1784 child
->MacPropagateEnabledStateChanged() ;
1785 node
= node
->GetNext();
1790 void wxWindowMac::MacPropagateHiliteChanged( )
1792 #if !TARGET_API_MAC_OSX
1793 MacHiliteChanged() ;
1795 wxWindowListNode
*node
= GetChildren().GetFirst();
1798 wxWindowMac
*child
= node
->GetData();
1799 // if ( child->IsEnabled() )
1800 child
->MacPropagateHiliteChanged() ;
1801 node
= node
->GetNext();
1807 // status change notifications
1810 void wxWindowMac::MacVisibilityChanged()
1814 void wxWindowMac::MacHiliteChanged()
1818 void wxWindowMac::MacEnabledStateChanged()
1823 // status queries on the inherited window's state
1826 bool wxWindowMac::MacIsReallyShown()
1828 // only under OSX the visibility of the TLW is taken into account
1829 #if TARGET_API_MAC_OSX
1830 return IsControlVisible( (ControlRef
) m_macControl
) ;
1832 wxWindow
* win
= this ;
1833 while( win
->IsShown() )
1835 if ( win
->IsTopLevel() )
1838 win
= win
->GetParent() ;
1847 bool wxWindowMac::MacIsReallyEnabled()
1849 #if TARGET_API_MAC_OSX
1850 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1852 return IsControlActive( (ControlRef
) m_macControl
) ;
1856 bool wxWindowMac::MacIsReallyHilited()
1858 return IsControlActive( (ControlRef
) m_macControl
) ;
1865 int wxWindowMac::GetCharHeight() const
1867 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1868 return dc
.GetCharHeight() ;
1871 int wxWindowMac::GetCharWidth() const
1873 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1874 return dc
.GetCharWidth() ;
1877 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1878 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1880 const wxFont
*fontToUse
= theFont
;
1882 fontToUse
= &m_font
;
1884 wxClientDC
dc( (wxWindowMac
*) this ) ;
1886 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1887 if ( externalLeading
)
1888 *externalLeading
= le
;
1898 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1899 * we always intersect with the entire window, not only with the client area
1902 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1904 #if TARGET_API_MAC_OSX
1906 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1909 RgnHandle update
= NewRgn() ;
1910 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1911 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1912 wxPoint origin
= GetClientAreaOrigin() ;
1913 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1914 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1918 RgnHandle updateRgn = NewRgn() ;
1921 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1925 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1926 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1928 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1929 DisposeRgn(updateRgn) ;
1931 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1933 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1934 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1937 if ( MacGetTopLevelWindow() == NULL )
1940 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1943 wxPoint client = GetClientAreaOrigin();
1946 int x2 = m_width - client.x;
1947 int y2 = m_height - client.y;
1949 if (IsKindOf( CLASSINFO(wxButton)))
1951 // buttons have an "aura"
1958 Rect clientrect = { y1, x1, y2, x2 };
1962 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1963 SectRect( &clientrect , &r , &clientrect ) ;
1966 if ( !EmptyRect( &clientrect ) )
1968 int top = 0 , left = 0 ;
1970 MacClientToRootWindow( &left , &top ) ;
1971 OffsetRect( &clientrect , left , top ) ;
1973 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1979 void wxWindowMac::Freeze()
1981 #if TARGET_API_MAC_OSX
1982 if ( !m_frozenness
++ )
1984 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1989 #if TARGET_API_MAC_OSX
1990 static void InvalidateControlAndChildren( HIViewRef control
)
1992 HIViewSetNeedsDisplay( control
, true ) ;
1993 UInt16 childrenCount
= 0 ;
1994 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1995 if ( err
== errControlIsNotEmbedder
)
1997 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1999 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2002 err
= GetIndexedSubControl( control
, i
, & child
) ;
2003 if ( err
== errControlIsNotEmbedder
)
2005 InvalidateControlAndChildren( child
) ;
2010 void wxWindowMac::Thaw()
2012 #if TARGET_API_MAC_OSX
2013 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2015 if ( !--m_frozenness
)
2017 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2018 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2019 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2024 void wxWindowMac::MacRedrawControl()
2027 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2029 #if TARGET_API_MAC_CARBON
2032 wxClientDC dc(this) ;
2033 wxMacPortSetter helper(&dc) ;
2034 wxMacWindowClipper clipper(this) ;
2035 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2036 UMADrawControl( (ControlRef) m_macControl ) ;
2043 void wxWindowMac::OnPaint(wxPaintEvent& event)
2045 // why don't we skip that here ?
2049 wxWindowMac
*wxGetActiveWindow()
2051 // actually this is a windows-only concept
2055 // Coordinates relative to the window
2056 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2058 // We really don't move the mouse programmatically under Mac.
2061 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2063 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2068 event
.GetDC()->Clear() ;
2071 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2073 wxWindowDC
dc(this) ;
2074 wxMacPortSetter
helper(&dc
) ;
2076 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2079 int wxWindowMac::GetScrollPos(int orient
) const
2081 if ( orient
== wxHORIZONTAL
)
2084 return m_hScrollBar
->GetThumbPosition() ;
2089 return m_vScrollBar
->GetThumbPosition() ;
2094 // This now returns the whole range, not just the number
2095 // of positions that we can scroll.
2096 int wxWindowMac::GetScrollRange(int orient
) const
2098 if ( orient
== wxHORIZONTAL
)
2101 return m_hScrollBar
->GetRange() ;
2106 return m_vScrollBar
->GetRange() ;
2111 int wxWindowMac::GetScrollThumb(int orient
) const
2113 if ( orient
== wxHORIZONTAL
)
2116 return m_hScrollBar
->GetThumbSize() ;
2121 return m_vScrollBar
->GetThumbSize() ;
2126 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2128 if ( orient
== wxHORIZONTAL
)
2131 m_hScrollBar
->SetThumbPosition( pos
) ;
2136 m_vScrollBar
->SetThumbPosition( pos
) ;
2140 void wxWindowMac::MacPaintBorders( int left
, int top
)
2146 wxGetOsVersion( &major
, &minor
);
2148 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2149 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2151 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2152 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2153 // OS X has lighter border edges than classic:
2156 darkShadow
.red
= 0x8E8E;
2157 darkShadow
.green
= 0x8E8E;
2158 darkShadow
.blue
= 0x8E8E;
2159 lightShadow
.red
= 0xBDBD;
2160 lightShadow
.green
= 0xBDBD;
2161 lightShadow
.blue
= 0xBDBD;
2167 GetSize( &w
, &h
) ;
2168 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2170 #if wxMAC_USE_THEME_BORDER
2171 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2174 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2175 InsetRect( &rect , border , border );
2176 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2179 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2181 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2182 RGBForeColor( &face
);
2183 MoveTo( left
+ 0 , top
+ h
- 2 );
2184 LineTo( left
+ 0 , top
+ 0 );
2185 LineTo( left
+ w
- 2 , top
+ 0 );
2187 MoveTo( left
+ 2 , top
+ h
- 3 );
2188 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2189 LineTo( left
+ w
- 3 , top
+ 2 );
2191 RGBForeColor( sunken
? &face
: &darkShadow
);
2192 MoveTo( left
+ 0 , top
+ h
- 1 );
2193 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2194 LineTo( left
+ w
- 1 , top
+ 0 );
2196 RGBForeColor( sunken
? &lightShadow
: &white
);
2197 MoveTo( left
+ 1 , top
+ h
- 3 );
2198 LineTo( left
+ 1, top
+ 1 );
2199 LineTo( left
+ w
- 3 , top
+ 1 );
2201 RGBForeColor( sunken
? &white
: &lightShadow
);
2202 MoveTo( left
+ 1 , top
+ h
- 2 );
2203 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2204 LineTo( left
+ w
- 2 , top
+ 1 );
2206 RGBForeColor( sunken
? &darkShadow
: &face
);
2207 MoveTo( left
+ 2 , top
+ h
- 4 );
2208 LineTo( left
+ 2 , top
+ 2 );
2209 LineTo( left
+ w
- 4 , top
+ 2 );
2212 else if (HasFlag(wxSIMPLE_BORDER
))
2214 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2215 RGBForeColor( &darkShadow
) ;
2216 FrameRect( &rect
) ;
2220 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2222 if ( child
== m_hScrollBar
)
2223 m_hScrollBar
= NULL
;
2224 if ( child
== m_vScrollBar
)
2225 m_vScrollBar
= NULL
;
2227 wxWindowBase::RemoveChild( child
) ;
2230 // New function that will replace some of the above.
2231 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2232 int range
, bool refresh
)
2234 if ( orient
== wxHORIZONTAL
)
2238 if ( range
== 0 || thumbVisible
>= range
)
2240 if ( m_hScrollBar
->IsShown() )
2241 m_hScrollBar
->Show(false) ;
2245 if ( !m_hScrollBar
->IsShown() )
2246 m_hScrollBar
->Show(true) ;
2247 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2255 if ( range
== 0 || thumbVisible
>= range
)
2257 if ( m_vScrollBar
->IsShown() )
2258 m_vScrollBar
->Show(false) ;
2262 if ( !m_vScrollBar
->IsShown() )
2263 m_vScrollBar
->Show(true) ;
2264 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2268 MacRepositionScrollBars() ;
2271 // Does a physical scroll
2272 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2274 if( dx
== 0 && dy
==0 )
2279 wxClientDC
dc(this) ;
2280 wxMacPortSetter
helper(&dc
) ;
2282 int width
, height
;
2283 GetClientSize( &width
, &height
) ;
2290 // TODO take out the boundaries
2291 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2293 RgnHandle updateRgn
= NewRgn() ;
2296 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2297 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2298 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2300 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2302 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2303 // but it seems the update only refreshes the background of the control, rather than calling
2304 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2305 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2308 // we also have to scroll the update rgn in this rectangle
2309 // in order not to loose updates
2311 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2312 RgnHandle formerUpdateRgn
= NewRgn() ;
2313 RgnHandle scrollRgn
= NewRgn() ;
2314 RectRgn( scrollRgn
, &scrollrect
) ;
2315 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2317 LocalToGlobal( &pt
) ;
2318 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2319 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2320 if ( !EmptyRgn( formerUpdateRgn
) )
2322 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2323 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2324 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2326 InvalWindowRgn(rootWindow
, updateRgn
) ;
2327 DisposeRgn( updateRgn
) ;
2328 DisposeRgn( formerUpdateRgn
) ;
2329 DisposeRgn( scrollRgn
) ;
2333 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2335 wxWindowMac
*child
= node
->GetData();
2336 if (child
== m_vScrollBar
) continue;
2337 if (child
== m_hScrollBar
) continue;
2338 if (child
->IsTopLevel()) continue;
2341 child
->GetPosition( &x
, &y
);
2343 child
->GetSize( &w
, &h
);
2347 if (rect
->Intersects(rc
))
2348 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2352 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2356 // TODO remove, was moved higher up Update() ;
2360 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2362 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2364 wxScrollWinEvent wevent
;
2365 wevent
.SetPosition(event
.GetPosition());
2366 wevent
.SetOrientation(event
.GetOrientation());
2367 wevent
.m_eventObject
= this;
2369 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2370 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2371 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2372 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2373 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2374 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2375 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2377 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2378 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2379 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2380 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2381 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2382 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2383 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2384 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2386 GetEventHandler()->ProcessEvent(wevent
);
2390 // Get the window with the focus
2391 wxWindowMac
*wxWindowBase::FindFocus()
2393 ControlRef control
;
2394 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2395 return wxFindControlFromMacControl( control
) ;
2398 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2400 // panel wants to track the window which was the last to have focus in it,
2401 // so we want to set ourselves as the window which last had focus
2403 // notice that it's also important to do it upwards the tree becaus
2404 // otherwise when the top level panel gets focus, it won't set it back to
2405 // us, but to some other sibling
2407 // CS:don't know if this is still needed:
2408 //wxChildFocusEvent eventFocus(this);
2409 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2414 void wxWindowMac::OnInternalIdle()
2416 // This calls the UI-update mechanism (querying windows for
2417 // menu/toolbar/control state information)
2418 if (wxUpdateUIEvent::CanUpdate(this))
2419 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2422 // Raise the window to the top of the Z order
2423 void wxWindowMac::Raise()
2425 #if TARGET_API_MAC_OSX
2426 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2430 // Lower the window to the bottom of the Z order
2431 void wxWindowMac::Lower()
2433 #if TARGET_API_MAC_OSX
2434 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2439 // static wxWindow *gs_lastWhich = NULL;
2441 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2443 // first trigger a set cursor event
2445 wxPoint clientorigin
= GetClientAreaOrigin() ;
2446 wxSize clientsize
= GetClientSize() ;
2448 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2450 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2452 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2453 if ( processedEvtSetCursor
&& event
.HasCursor() )
2455 cursor
= event
.GetCursor() ;
2460 // the test for processedEvtSetCursor is here to prevent using m_cursor
2461 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2462 // it - this is a way to say that our cursor shouldn't be used for this
2464 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2474 cursor
= *wxSTANDARD_CURSOR
;
2478 cursor
.MacInstall() ;
2480 return cursor
.Ok() ;
2483 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2487 return m_tooltip
->GetTip() ;
2489 return wxEmptyString
;
2492 void wxWindowMac::Update()
2494 #if TARGET_API_MAC_OSX
2495 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2497 ::Draw1Control( (ControlRef
) m_macControl
) ;
2501 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2503 wxTopLevelWindowMac
* win
= NULL
;
2504 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2507 win
= wxFindWinFromMacWindow( window
) ;
2511 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2515 RgnHandle visRgn
= NewRgn() ;
2516 RgnHandle tempRgn
= NewRgn() ;
2517 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2519 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2520 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2522 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2523 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2532 if ( includeOuterStructures
)
2533 InsetRect( &r
, -3 , -3 ) ;
2534 RectRgn( visRgn
, &r
) ;
2535 if ( !IsTopLevel() )
2537 wxWindow
* child
= this ;
2538 wxWindow
* parent
= child
->GetParent() ;
2543 // we have to find a better clipping algorithm here, in order not to clip things
2544 // positioned like status and toolbar
2545 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2547 size
= parent
->GetSize() ;
2552 size
= parent
->GetClientSize() ;
2553 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2557 parent
->MacWindowToRootWindow( &x
, &y
) ;
2558 MacRootWindowToWindow( &x
, &y
) ;
2560 SetRectRgn( tempRgn
,
2561 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2562 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2563 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2565 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2566 if ( parent
->IsTopLevel() )
2569 parent
= child
->GetParent() ;
2574 wxRegion vis
= visRgn
;
2575 DisposeRgn( visRgn
) ;
2576 DisposeRgn( tempRgn
) ;
2581 This function must not change the updatergn !
2583 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2585 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2586 bool handled
= false ;
2588 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2590 RgnHandle newupdate
= NewRgn() ;
2591 wxSize point
= GetClientSize() ;
2592 wxPoint origin
= GetClientAreaOrigin() ;
2593 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2594 SectRgn( newupdate
, updatergn
, newupdate
) ;
2595 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2596 m_updateRegion
= newupdate
;
2597 DisposeRgn( newupdate
) ;
2600 if ( !EmptyRgn(updatergn
) )
2602 wxWindowDC
dc(this);
2603 if (!EmptyRgn(updatergn
))
2604 dc
.SetClippingRegion(wxRegion(updatergn
));
2606 wxEraseEvent
eevent( GetId(), &dc
);
2607 eevent
.SetEventObject( this );
2608 GetEventHandler()->ProcessEvent( eevent
);
2610 if ( !m_updateRegion
.Empty() )
2612 // paint the window itself
2614 event
.m_timeStamp
= time
;
2615 event
.SetEventObject(this);
2616 handled
= GetEventHandler()->ProcessEvent(event
);
2618 // paint custom borders
2619 wxNcPaintEvent
eventNc( GetId() );
2620 eventNc
.SetEventObject( this );
2621 GetEventHandler()->ProcessEvent( eventNc
);
2627 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2629 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2630 // updatergn is always already clipped to our boundaries
2631 // if we are in compositing mode then it is in relative to the upper left of the control
2632 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2633 // of the toplevel window
2634 // it is in window coordinates, not in client coordinates
2636 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2637 RgnHandle ownUpdateRgn
= NewRgn() ;
2638 CopyRgn( updatergn
, ownUpdateRgn
) ;
2640 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2643 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2644 RgnHandle controlRgn
= NewRgn();
2645 RectRgn( controlRgn
, &bounds
);
2646 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2647 // the window update region
2648 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2649 DisposeRgn( controlRgn
);
2651 //KO: convert ownUpdateRgn to local coordinates
2652 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2655 MacDoRedraw( ownUpdateRgn
, time
) ;
2656 DisposeRgn( ownUpdateRgn
) ;
2660 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2662 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2666 if ( iter
->IsTopLevel() )
2667 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2669 iter
= iter
->GetParent() ;
2671 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2675 void wxWindowMac::MacCreateScrollBars( long style
)
2677 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2679 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2680 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2682 GetClientSize( &width
, &height
) ;
2684 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2685 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2686 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2687 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2689 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2690 vSize
, wxVERTICAL
);
2692 if ( style
& wxVSCROLL
)
2698 m_vScrollBar
->Show(false) ;
2700 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2701 hSize
, wxHORIZONTAL
);
2702 if ( style
& wxHSCROLL
)
2707 m_hScrollBar
->Show(false) ;
2710 // because the create does not take into account the client area origin
2711 MacRepositionScrollBars() ; // we might have a real position shift
2714 void wxWindowMac::MacRepositionScrollBars()
2716 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2717 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2719 // get real client area
2723 GetSize( &width
, &height
) ;
2725 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2726 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2728 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2729 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2730 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2731 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2737 GetSize( &w
, &h
) ;
2739 MacClientToRootWindow( &x
, &y
) ;
2740 MacClientToRootWindow( &w
, &h
) ;
2742 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2744 int totW
= 10000 , totH
= 10000;
2747 if ( iter
->IsTopLevel() )
2749 iter
->GetSize( &totW
, &totH
) ;
2753 iter
= iter
->GetParent() ;
2781 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2785 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2789 bool wxWindowMac::AcceptsFocus() const
2791 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2794 void wxWindowMac::MacSuperChangedPosition()
2796 // only window-absolute structures have to be moved i.e. controls
2798 wxWindowListNode
*node
= GetChildren().GetFirst();
2801 wxWindowMac
*child
= node
->GetData();
2802 child
->MacSuperChangedPosition() ;
2803 node
= node
->GetNext();
2807 void wxWindowMac::MacTopLevelWindowChangedPosition()
2809 // only screen-absolute structures have to be moved i.e. glcanvas
2811 wxWindowListNode
*node
= GetChildren().GetFirst();
2814 wxWindowMac
*child
= node
->GetData();
2815 child
->MacTopLevelWindowChangedPosition() ;
2816 node
= node
->GetNext();
2820 long wxWindowMac::MacGetLeftBorderSize( ) const
2825 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2828 #if wxMAC_USE_THEME_BORDER
2829 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2833 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2836 #if wxMAC_USE_THEME_BORDER
2837 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2841 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2848 long wxWindowMac::MacGetRightBorderSize( ) const
2850 // they are all symmetric in mac themes
2851 return MacGetLeftBorderSize() ;
2854 long wxWindowMac::MacGetTopBorderSize( ) const
2856 // they are all symmetric in mac themes
2857 return MacGetLeftBorderSize() ;
2860 long wxWindowMac::MacGetBottomBorderSize( ) const
2862 // they are all symmetric in mac themes
2863 return MacGetLeftBorderSize() ;
2866 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2868 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2871 // Find the wxWindowMac at the current mouse position, returning the mouse
2873 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2875 pt
= wxGetMousePosition();
2876 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2880 // Get the current mouse position.
2881 wxPoint
wxGetMousePosition()
2884 wxGetMousePosition(& x
, & y
);
2885 return wxPoint(x
, y
);
2888 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2890 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2892 // copied from wxGTK : CS
2893 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2896 // (a) it's a command event and so is propagated to the parent
2897 // (b) under MSW it can be generated from kbd too
2898 // (c) it uses screen coords (because of (a))
2899 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2901 this->ClientToScreen(event
.GetPosition()));
2902 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2911 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2915 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2919 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2920 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2924 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2926 return eventNotHandledErr
;