1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
56 #if wxUSE_DRAG_AND_DROP
60 #include "wx/mac/uma.h"
62 #define MAC_SCROLLBAR_SIZE 15
63 #define MAC_SMALL_SCROLLBAR_SIZE 11
67 #include <ToolUtils.h>
69 #include <MacTextEditor.h>
72 #if TARGET_API_MAC_OSX
74 #include <HIToolbox/HIView.h>
80 #ifdef __WXUNIVERSAL__
81 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
83 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
86 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
87 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
88 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
89 #if TARGET_API_MAC_OSX
90 EVT_PAINT(wxWindowMac::OnPaint
)
92 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
93 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
94 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
97 #define wxMAC_DEBUG_REDRAW 0
98 #ifndef wxMAC_DEBUG_REDRAW
99 #define wxMAC_DEBUG_REDRAW 0
102 // ---------------------------------------------------------------------------
103 // Utility Routines to move between different coordinate systems
104 // ---------------------------------------------------------------------------
107 * Right now we have the following setup :
108 * a border that is not part of the native control is always outside the
109 * control's border (otherwise we loose all native intelligence, future ways
110 * may be to have a second embedding control responsible for drawing borders
111 * and backgrounds eventually)
112 * so all this border calculations have to be taken into account when calling
113 * native methods or getting native oriented data
114 * so we have three coordinate systems here
115 * wx client coordinates
116 * wx window coordinates (including window frames)
121 // originating from native control
125 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
127 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
130 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
132 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
136 // directed towards native control
139 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
141 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
144 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
146 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 #if TARGET_API_MAC_OSX
155 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
158 kEventControlVisibilityChanged
= 157
164 static const EventTypeSpec eventList
[] =
166 { kEventClassCommand
, kEventProcessCommand
} ,
167 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
169 { kEventClassControl
, kEventControlGetClickActivation
} ,
170 { kEventClassControl
, kEventControlHit
} ,
172 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
173 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
175 { kEventClassControl
, kEventControlDraw
} ,
176 #if TARGET_API_MAC_OSX
177 { kEventClassControl
, kEventControlVisibilityChanged
} ,
178 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
179 { kEventClassControl
, kEventControlHiliteChanged
} ,
181 { kEventClassControl
, kEventControlActivate
} ,
182 { kEventClassControl
, kEventControlDeactivate
} ,
184 { kEventClassControl
, kEventControlSetFocusPart
} ,
186 { kEventClassService
, kEventServiceGetTypes
},
187 { kEventClassService
, kEventServiceCopy
},
188 { kEventClassService
, kEventServicePaste
},
190 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
191 // { kEventClassControl , kEventControlBoundsChanged } ,
194 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
196 OSStatus result
= eventNotHandledErr
;
198 wxMacCarbonEvent
cEvent( event
) ;
200 ControlRef controlRef
;
201 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
203 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
205 switch ( GetEventKind( event
) )
207 #if TARGET_API_MAC_OSX
208 case kEventControlDraw
:
210 RgnHandle updateRgn
= NULL
;
211 RgnHandle allocatedRgn
= NULL
;
212 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
214 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
216 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
220 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
222 // as this update region is in native window locals we must adapt it to wx window local
223 allocatedRgn
= NewRgn() ;
224 CopyRgn( updateRgn
, allocatedRgn
) ;
226 // hide the given region by the new region that must be shifted
227 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
228 updateRgn
= allocatedRgn
;
233 GetRegionBounds( updateRgn
, &rgnBounds
) ;
235 #if wxMAC_DEBUG_REDRAW
236 if ( thisWindow
->MacIsUserPane() )
238 static float color
= 0.5 ;
241 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
243 HIViewGetBounds( controlRef
, &bounds
);
244 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
245 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
246 CGContextFillRect( cgContext
, bounds
);
259 #if wxMAC_USE_CORE_GRAPHICS
260 bool created
= false ;
261 CGContextRef cgContext
= NULL
;
262 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
263 wxASSERT_MSG( err
== noErr
, wxT("Unable to retrieve CGContextRef") ) ;
264 thisWindow
->MacSetCGContextRef( cgContext
) ;
267 wxMacCGContextStateSaver
sg( cgContext
) ;
270 wxWindow
* iter
= thisWindow
;
273 alpha
*= (float) iter
->GetTransparent()/255.0 ;
274 if ( iter
->IsTopLevel() )
277 iter
= iter
->GetParent() ;
280 CGContextSetAlpha( cgContext
, alpha
) ;
282 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
285 #if wxMAC_USE_CORE_GRAPHICS
286 thisWindow
->MacSetCGContextRef( NULL
) ;
290 CGContextRelease( cgContext
) ;
295 DisposeRgn( allocatedRgn
) ;
299 case kEventControlVisibilityChanged
:
300 thisWindow
->MacVisibilityChanged() ;
303 case kEventControlEnabledStateChanged
:
304 thisWindow
->MacEnabledStateChanged() ;
307 case kEventControlHiliteChanged
:
308 thisWindow
->MacHiliteChanged() ;
311 case kEventControlActivate
:
312 case kEventControlDeactivate
:
313 if ( thisWindow
->IsKindOf( CLASSINFO( wxTreeCtrl
) )
314 || thisWindow
->IsKindOf( CLASSINFO( wxListCtrl
) )
316 thisWindow
->Refresh();
318 //thisWindow->MacActivateStateChanged() ;
322 // we emulate this event under Carbon CFM
323 case kEventControlSetFocusPart
:
325 Boolean focusEverything
= false ;
326 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
329 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
334 if ( controlPart
== kControlFocusNoPart
)
337 if ( thisWindow
->GetCaret() )
338 thisWindow
->GetCaret()->OnKillFocus();
341 static bool inKillFocusEvent
= false ;
343 if ( !inKillFocusEvent
)
345 inKillFocusEvent
= true ;
346 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
347 event
.SetEventObject(thisWindow
);
348 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
349 inKillFocusEvent
= false ;
354 // panel wants to track the window which was the last to have focus in it
355 wxChildFocusEvent
eventFocus(thisWindow
);
356 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
359 if ( thisWindow
->GetCaret() )
360 thisWindow
->GetCaret()->OnSetFocus();
363 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
364 event
.SetEventObject(thisWindow
);
365 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
368 if ( thisWindow
->MacIsUserPane() )
373 case kEventControlHit
:
374 result
= thisWindow
->MacControlHit( handler
, event
) ;
377 case kEventControlGetClickActivation
:
379 // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
380 WindowRef owner
= cEvent
.GetParameter
<WindowRef
>(kEventParamWindowRef
);
381 if ( !IsWindowActive(owner
) )
383 cEvent
.SetParameter(kEventParamClickActivation
,(UInt32
) kActivateAndIgnoreClick
) ;
396 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
398 OSStatus result
= eventNotHandledErr
;
400 wxMacCarbonEvent
cEvent( event
) ;
402 ControlRef controlRef
;
403 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
404 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
405 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
407 switch ( GetEventKind( event
) )
409 case kEventServiceGetTypes
:
413 textCtrl
->GetSelection( &from
, &to
) ;
415 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
417 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
418 if ( textCtrl
->IsEditable() )
419 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
421 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
422 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
424 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
428 CFArrayAppendValue(copyTypes
, typestring
) ;
430 CFArrayAppendValue(pasteTypes
, typestring
) ;
432 CFRelease( typestring
) ;
440 case kEventServiceCopy
:
445 textCtrl
->GetSelection( &from
, &to
) ;
446 wxString val
= textCtrl
->GetValue() ;
447 val
= val
.Mid( from
, to
- from
) ;
448 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
449 verify_noerr( ClearScrap( &scrapRef
) ) ;
450 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
455 case kEventServicePaste
:
458 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
459 Size textSize
, pastedSize
;
460 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
462 char *content
= new char[textSize
] ;
463 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
464 content
[textSize
- 1] = 0 ;
467 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
469 textCtrl
->WriteText( wxString( content
) ) ;
484 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
486 OSStatus result
= eventNotHandledErr
;
487 wxWindowMac
* focus
= (wxWindowMac
*) data
;
489 wchar_t* uniChars
= NULL
;
490 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
492 UniChar
* charBuf
= NULL
;
493 ByteCount dataSize
= 0 ;
496 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
498 numChars
= dataSize
/ sizeof( UniChar
) + 1;
501 if ( (size_t) numChars
* 2 > sizeof(buf
) )
502 charBuf
= new UniChar
[ numChars
] ;
506 uniChars
= new wchar_t[ numChars
] ;
507 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
508 charBuf
[ numChars
- 1 ] = 0;
509 #if SIZEOF_WCHAR_T == 2
510 uniChars
= (wchar_t*) charBuf
;
511 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
513 // the resulting string will never have more chars than the utf16 version, so this is safe
514 wxMBConvUTF16 converter
;
515 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
519 switch ( GetEventKind( event
) )
521 case kEventTextInputUpdateActiveInputArea
:
523 // An IME input event may return several characters, but we need to send one char at a time to
525 for (int pos
=0 ; pos
< numChars
; pos
++)
527 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
528 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
529 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
531 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
532 if ( wxTheApp
->MacSendCharEvent(
533 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
538 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
542 case kEventTextInputUnicodeForKeyEvent
:
544 UInt32 keyCode
, modifiers
;
547 unsigned char charCode
;
549 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
550 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
551 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
552 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
553 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
555 UInt32 message
= (keyCode
<< 8) + charCode
;
557 // An IME input event may return several characters, but we need to send one char at a time to
559 for (int pos
=0 ; pos
< numChars
; pos
++)
561 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
562 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
563 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
565 if ( wxTheApp
->MacSendCharEvent(
566 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
571 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
580 if ( charBuf
!= buf
)
586 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
588 OSStatus result
= eventNotHandledErr
;
589 wxWindowMac
* focus
= (wxWindowMac
*) data
;
593 wxMacCarbonEvent
cEvent( event
) ;
594 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
596 wxMenuItem
* item
= NULL
;
597 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
598 int id
= wxMacCommandToId( command
.commandID
) ;
602 wxASSERT( itemMenu
!= NULL
) ;
604 switch ( cEvent
.GetKind() )
606 case kEventProcessCommand
:
608 if (item
->IsCheckable())
609 item
->Check( !item
->IsChecked() ) ;
611 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
615 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
616 event
.SetEventObject(focus
);
617 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
619 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
625 case kEventCommandUpdateStatus
:
627 wxUpdateUIEvent
event(id
);
628 event
.SetEventObject( itemMenu
);
630 bool processed
= false;
632 // Try the menu's event handler
634 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
636 processed
= handler
->ProcessEvent(event
);
639 // Try the window the menu was popped up from
640 // (and up through the hierarchy)
643 const wxMenuBase
*menu
= itemMenu
;
646 wxWindow
*win
= menu
->GetInvokingWindow();
649 processed
= win
->GetEventHandler()->ProcessEvent(event
);
653 menu
= menu
->GetParent();
659 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
664 // if anything changed, update the changed attribute
665 if (event
.GetSetText())
666 itemMenu
->SetLabel(id
, event
.GetText());
667 if (event
.GetSetChecked())
668 itemMenu
->Check(id
, event
.GetChecked());
669 if (event
.GetSetEnabled())
670 itemMenu
->Enable(id
, event
.GetEnabled());
684 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
686 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
687 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
688 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
689 OSStatus result
= eventNotHandledErr
;
691 switch ( GetEventClass( event
) )
693 case kEventClassCommand
:
694 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
697 case kEventClassControl
:
698 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
701 case kEventClassService
:
702 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
705 case kEventClassTextInput
:
706 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
713 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
718 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
720 #if !TARGET_API_MAC_OSX
722 // ---------------------------------------------------------------------------
723 // UserPane events for non OSX builds
724 // ---------------------------------------------------------------------------
726 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
728 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
730 win
->MacControlUserPaneDrawProc(part
) ;
732 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
734 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
736 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
738 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
740 return kControlNoPart
;
742 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
744 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
746 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
748 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
750 return kControlNoPart
;
752 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
754 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
756 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
758 win
->MacControlUserPaneIdleProc() ;
760 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
762 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
764 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
766 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
768 return kControlNoPart
;
770 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
772 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
774 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
776 win
->MacControlUserPaneActivateProc(activating
) ;
778 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
780 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
782 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
784 return win
->MacControlUserPaneFocusProc(action
) ;
786 return kControlNoPart
;
788 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
790 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
792 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
794 win
->MacControlUserPaneBackgroundProc(info
) ;
796 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
798 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
801 RgnHandle rgn
= NewRgn() ;
803 MacWindowToRootWindow( &x
, &y
) ;
804 OffsetRgn( rgn
, -x
, -y
) ;
805 wxMacWindowStateSaver
sv( this ) ;
806 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
807 MacDoRedraw( rgn
, 0 ) ;
811 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
813 return kControlNoPart
;
816 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
818 return kControlNoPart
;
821 void wxWindowMac::MacControlUserPaneIdleProc()
825 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
827 return kControlNoPart
;
830 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
834 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
836 if ( AcceptsFocus() )
839 return kControlNoPart
;
842 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
848 // ---------------------------------------------------------------------------
849 // Scrollbar Tracking for all
850 // ---------------------------------------------------------------------------
852 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
853 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
857 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
859 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
862 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
864 // ===========================================================================
866 // ===========================================================================
868 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
870 static MacControlMap wxWinMacControlList
;
872 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
874 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
876 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
879 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
881 // adding NULL ControlRef is (first) surely a result of an error and
882 // (secondly) breaks native event processing
883 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
885 wxWinMacControlList
[inControl
] = control
;
888 void wxRemoveMacControlAssociation(wxWindow
*control
)
890 // iterate over all the elements in the class
891 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
892 // we should go on...
898 MacControlMap::iterator it
;
899 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
901 if ( it
->second
== control
)
903 wxWinMacControlList
.erase(it
);
911 // ----------------------------------------------------------------------------
912 // constructors and such
913 // ----------------------------------------------------------------------------
915 wxWindowMac::wxWindowMac()
920 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
925 const wxString
& name
)
928 Create(parent
, id
, pos
, size
, style
, name
);
931 void wxWindowMac::Init()
937 #if WXWIN_COMPATIBILITY_2_4
938 m_backgroundTransparent
= false;
941 #if wxMAC_USE_CORE_GRAPHICS
942 m_cgContextRef
= NULL
;
945 // as all windows are created with WS_VISIBLE style...
948 m_hScrollBar
= NULL
;
949 m_vScrollBar
= NULL
;
950 m_macBackgroundBrush
= wxNullBrush
;
952 m_macIsUserPane
= true;
953 m_clipChildren
= false ;
954 m_cachedClippedRectValid
= false ;
956 // we need a valid font for the encodings
957 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
960 wxWindowMac::~wxWindowMac()
964 m_isBeingDeleted
= true;
966 MacInvalidateBorders() ;
968 #ifndef __WXUNIVERSAL__
969 // VS: make sure there's no wxFrame with last focus set to us:
970 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
972 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
975 if ( frame
->GetLastFocus() == this )
976 frame
->SetLastFocus((wxWindow
*)NULL
);
982 // destroy children before destroying this window itself
985 // wxRemoveMacControlAssociation( this ) ;
986 // If we delete an item, we should initialize the parent panel,
987 // because it could now be invalid.
988 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
991 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
992 tlw
->SetDefaultItem(NULL
);
995 if ( m_peer
&& m_peer
->Ok() )
997 // in case the callback might be called during destruction
998 wxRemoveMacControlAssociation( this) ;
999 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1000 // we currently are not using this hook
1001 // ::SetControlColorProc( *m_peer , NULL ) ;
1005 if ( g_MacLastWindow
== this )
1006 g_MacLastWindow
= NULL
;
1008 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1011 if ( frame
->GetLastFocus() == this )
1012 frame
->SetLastFocus( NULL
) ;
1015 // delete our drop target if we've got one
1016 #if wxUSE_DRAG_AND_DROP
1017 if ( m_dropTarget
!= NULL
)
1019 delete m_dropTarget
;
1020 m_dropTarget
= NULL
;
1027 WXWidget
wxWindowMac::GetHandle() const
1029 return (WXWidget
) m_peer
->GetControlRef() ;
1032 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1034 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1035 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1036 GetEventTypeCount(eventList
), eventList
, this,
1037 (EventHandlerRef
*)&m_macControlEventHandler
);
1039 #if !TARGET_API_MAC_OSX
1040 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1042 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1043 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1044 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1045 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1046 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1047 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1048 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1049 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1055 bool wxWindowMac::Create(wxWindowMac
*parent
,
1060 const wxString
& name
)
1062 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1064 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1067 m_windowVariant
= parent
->GetWindowVariant() ;
1069 if ( m_macIsUserPane
)
1071 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1074 | kControlSupportsEmbedding
1075 | kControlSupportsLiveFeedback
1076 | kControlGetsFocusOnClick
1077 // | kControlHasSpecialBackground
1078 // | kControlSupportsCalcBestRect
1079 | kControlHandlesTracking
1080 | kControlSupportsFocus
1081 | kControlWantsActivate
1082 | kControlWantsIdle
;
1084 m_peer
= new wxMacControl(this) ;
1085 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1086 verify_noerr( err
);
1088 MacPostControlCreate(pos
, size
) ;
1091 #ifndef __WXUNIVERSAL__
1092 // Don't give scrollbars to wxControls unless they ask for them
1093 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1094 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1096 MacCreateScrollBars( style
) ;
1100 wxWindowCreateEvent
event(this);
1101 GetEventHandler()->AddPendingEvent(event
);
1106 void wxWindowMac::MacChildAdded()
1109 m_vScrollBar
->Raise() ;
1111 m_hScrollBar
->Raise() ;
1114 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1116 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1118 m_peer
->SetReference( (URefCon
) this ) ;
1119 GetParent()->AddChild( this );
1121 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1123 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1124 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1125 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1126 GetParent()->MacChildAdded() ;
1128 // adjust font, controlsize etc
1129 DoSetWindowVariant( m_windowVariant
) ;
1131 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1133 if (!m_macIsUserPane
)
1134 SetInitialSize(size
);
1136 SetCursor( *wxSTANDARD_CURSOR
) ;
1139 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1141 // Don't assert, in case we set the window variant before
1142 // the window is created
1143 // wxASSERT( m_peer->Ok() ) ;
1145 m_windowVariant
= variant
;
1147 if (m_peer
== NULL
|| !m_peer
->Ok())
1151 ThemeFontID themeFont
= kThemeSystemFont
;
1153 // we will get that from the settings later
1154 // and make this NORMAL later, but first
1155 // we have a few calculations that we must fix
1159 case wxWINDOW_VARIANT_NORMAL
:
1160 size
= kControlSizeNormal
;
1161 themeFont
= kThemeSystemFont
;
1164 case wxWINDOW_VARIANT_SMALL
:
1165 size
= kControlSizeSmall
;
1166 themeFont
= kThemeSmallSystemFont
;
1169 case wxWINDOW_VARIANT_MINI
:
1170 if (UMAGetSystemVersion() >= 0x1030 )
1172 // not always defined in the headers
1178 size
= kControlSizeSmall
;
1179 themeFont
= kThemeSmallSystemFont
;
1183 case wxWINDOW_VARIANT_LARGE
:
1184 size
= kControlSizeLarge
;
1185 themeFont
= kThemeSystemFont
;
1189 wxFAIL_MSG(_T("unexpected window variant"));
1193 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1196 font
.MacCreateThemeFont( themeFont
) ;
1200 void wxWindowMac::MacUpdateControlFont()
1202 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1206 bool wxWindowMac::SetFont(const wxFont
& font
)
1208 bool retval
= wxWindowBase::SetFont( font
);
1210 MacUpdateControlFont() ;
1215 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1217 bool retval
= wxWindowBase::SetForegroundColour( col
);
1220 MacUpdateControlFont();
1225 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1227 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1231 wxColour
newCol(GetBackgroundColour());
1233 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1234 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1235 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1236 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1238 brush
.SetColour( newCol
) ;
1240 MacSetBackgroundBrush( brush
) ;
1241 MacUpdateControlFont() ;
1246 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1248 m_macBackgroundBrush
= brush
;
1249 m_peer
->SetBackground( brush
) ;
1252 bool wxWindowMac::MacCanFocus() const
1254 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1255 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1256 // but the value range is nowhere documented
1257 Boolean keyExistsAndHasValidFormat
;
1258 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1259 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1261 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1267 UInt32 features
= 0 ;
1268 m_peer
->GetFeatures( &features
) ;
1270 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1274 void wxWindowMac::SetFocus()
1276 if ( !AcceptsFocus() )
1279 wxWindow
* former
= FindFocus() ;
1280 if ( former
== this )
1283 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1284 // we can only leave in case of an error
1285 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1286 if ( err
== errCouldntSetFocus
)
1289 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1291 #if !TARGET_API_MAC_OSX
1292 // emulate carbon events when running under CarbonLib where they are not natively available
1295 EventRef evRef
= NULL
;
1297 err
= MacCreateEvent(
1298 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1299 kEventAttributeUserEvent
, &evRef
);
1300 verify_noerr( err
);
1302 wxMacCarbonEvent
cEvent( evRef
) ;
1303 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1304 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1306 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1307 ReleaseEvent( evRef
) ;
1310 // send new focus event
1312 EventRef evRef
= NULL
;
1314 err
= MacCreateEvent(
1315 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1316 kEventAttributeUserEvent
, &evRef
);
1317 verify_noerr( err
);
1319 wxMacCarbonEvent
cEvent( evRef
) ;
1320 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1321 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1323 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1324 ReleaseEvent( evRef
) ;
1329 void wxWindowMac::DoCaptureMouse()
1331 wxApp::s_captureWindow
= this ;
1334 wxWindow
* wxWindowBase::GetCapture()
1336 return wxApp::s_captureWindow
;
1339 void wxWindowMac::DoReleaseMouse()
1341 wxApp::s_captureWindow
= NULL
;
1344 #if wxUSE_DRAG_AND_DROP
1346 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1348 if ( m_dropTarget
!= NULL
)
1349 delete m_dropTarget
;
1351 m_dropTarget
= pDropTarget
;
1352 if ( m_dropTarget
!= NULL
)
1360 // Old-style File Manager Drag & Drop
1361 void wxWindowMac::DragAcceptFiles(bool accept
)
1366 // Returns the size of the native control. In the case of the toplevel window
1367 // this is the content area root control
1369 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1370 int& w
, int& h
) const
1372 wxFAIL_MSG( wxT("Not currently supported") ) ;
1375 // From a wx position / size calculate the appropriate size of the native control
1377 bool wxWindowMac::MacGetBoundsForControl(
1381 int& w
, int& h
, bool adjustOrigin
) const
1383 // the desired size, minus the border pixels gives the correct size of the control
1387 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1388 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1389 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1391 x
+= MacGetLeftBorderSize() ;
1392 y
+= MacGetTopBorderSize() ;
1393 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1394 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1397 AdjustForParentClientOrigin( x
, y
) ;
1399 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1400 if ( !GetParent()->IsTopLevel() )
1402 x
-= GetParent()->MacGetLeftBorderSize() ;
1403 y
-= GetParent()->MacGetTopBorderSize() ;
1409 // Get window size (not client size)
1410 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1413 m_peer
->GetRect( &bounds
) ;
1416 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1418 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1421 // get the position of the bounds of this window in client coordinates of its parent
1422 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1425 m_peer
->GetRect( &bounds
) ;
1427 int x1
= bounds
.left
;
1428 int y1
= bounds
.top
;
1430 // get the wx window position from the native one
1431 x1
-= MacGetLeftBorderSize() ;
1432 y1
-= MacGetTopBorderSize() ;
1434 if ( !IsTopLevel() )
1436 wxWindow
*parent
= GetParent();
1439 // we must first adjust it to be in window coordinates of the parent,
1440 // as otherwise it gets lost by the ClientAreaOrigin fix
1441 x1
+= parent
->MacGetLeftBorderSize() ;
1442 y1
+= parent
->MacGetTopBorderSize() ;
1444 // and now to client coordinates
1445 wxPoint
pt(parent
->GetClientAreaOrigin());
1457 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1459 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1460 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1462 Point localwhere
= { 0, 0 } ;
1469 wxMacGlobalToLocal( window
, &localwhere
) ;
1476 MacRootWindowToWindow( x
, y
) ;
1478 wxPoint origin
= GetClientAreaOrigin() ;
1485 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1487 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1488 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1490 wxPoint origin
= GetClientAreaOrigin() ;
1496 MacWindowToRootWindow( x
, y
) ;
1498 Point localwhere
= { 0, 0 };
1504 wxMacLocalToGlobal( window
, &localwhere
) ;
1512 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1514 wxPoint origin
= GetClientAreaOrigin() ;
1520 MacWindowToRootWindow( x
, y
) ;
1523 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1525 MacRootWindowToWindow( x
, y
) ;
1527 wxPoint origin
= GetClientAreaOrigin() ;
1534 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1543 if ( !IsTopLevel() )
1545 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1548 pt
.x
-= MacGetLeftBorderSize() ;
1549 pt
.y
-= MacGetTopBorderSize() ;
1550 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1560 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1569 MacWindowToRootWindow( &x1
, &y1
) ;
1577 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1586 if ( !IsTopLevel() )
1588 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1591 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1592 pt
.x
+= MacGetLeftBorderSize() ;
1593 pt
.y
+= MacGetTopBorderSize() ;
1603 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1612 MacRootWindowToWindow( &x1
, &y1
) ;
1620 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1622 RgnHandle rgn
= NewRgn() ;
1624 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1626 Rect structure
, content
;
1628 GetRegionBounds( rgn
, &content
) ;
1629 m_peer
->GetRect( &structure
) ;
1630 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1632 left
= content
.left
- structure
.left
;
1633 top
= content
.top
- structure
.top
;
1634 right
= structure
.right
- content
.right
;
1635 bottom
= structure
.bottom
- content
.bottom
;
1639 left
= top
= right
= bottom
= 0 ;
1645 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1647 wxSize sizeTotal
= size
;
1649 RgnHandle rgn
= NewRgn() ;
1650 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1652 Rect content
, structure
;
1653 GetRegionBounds( rgn
, &content
) ;
1654 m_peer
->GetRect( &structure
) ;
1656 // structure is in parent coordinates, but we only need width and height, so it's ok
1658 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1659 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1664 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1665 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1670 // Get size *available for subwindows* i.e. excluding menu bar etc.
1671 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1675 RgnHandle rgn
= NewRgn() ;
1677 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1678 GetRegionBounds( rgn
, &content
) ;
1680 m_peer
->GetRect( &content
) ;
1683 ww
= content
.right
- content
.left
;
1684 hh
= content
.bottom
- content
.top
;
1686 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1687 hh
-= m_hScrollBar
->GetSize().y
;
1689 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1690 ww
-= m_vScrollBar
->GetSize().x
;
1698 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1700 if (m_cursor
.IsSameAs(cursor
))
1705 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1710 if ( ! wxWindowBase::SetCursor( cursor
) )
1714 wxASSERT_MSG( m_cursor
.Ok(),
1715 wxT("cursor must be valid after call to the base version"));
1717 wxWindowMac
*mouseWin
= 0 ;
1719 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1720 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1722 ControlPartCode part
;
1723 ControlRef control
;
1725 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1727 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1732 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1734 // TODO: If we ever get a GetCurrentEvent... replacement
1735 // for the mouse position, use it...
1740 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1742 mouseWin
= wxFindControlFromMacControl( control
) ;
1744 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1746 QDSwapPort( savePort
, NULL
) ;
1750 if ( mouseWin
== this && !wxIsBusy() )
1751 m_cursor
.MacInstall() ;
1757 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1759 menu
->SetInvokingWindow(this);
1762 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1764 wxPoint mouse
= wxGetMousePosition();
1770 ClientToScreen( &x
, &y
) ;
1773 menu
->MacBeforeDisplay( true ) ;
1774 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1775 if ( HiWord(menuResult
) != 0 )
1778 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1779 int id
= wxMacCommandToId( macid
);
1780 wxMenuItem
* item
= NULL
;
1782 item
= menu
->FindItem( id
, &realmenu
) ;
1785 if (item
->IsCheckable())
1786 item
->Check( !item
->IsChecked() ) ;
1788 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1792 menu
->MacAfterDisplay( true ) ;
1793 menu
->SetInvokingWindow( NULL
);
1799 // ----------------------------------------------------------------------------
1801 // ----------------------------------------------------------------------------
1805 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1807 wxWindowBase::DoSetToolTip(tooltip
);
1810 m_tooltip
->SetWindow(this);
1815 void wxWindowMac::MacInvalidateBorders()
1817 if ( m_peer
== NULL
)
1820 bool vis
= MacIsReallyShown() ;
1824 int outerBorder
= MacGetLeftBorderSize() ;
1825 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1828 if ( outerBorder
== 0 )
1831 // now we know that we have something to do at all
1833 // as the borders are drawn on the parent we have to properly invalidate all these areas
1834 RgnHandle updateInner
, updateOuter
;
1837 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1838 updateInner
= NewRgn() ;
1839 updateOuter
= NewRgn() ;
1841 m_peer
->GetRect( &rect
) ;
1842 RectRgn( updateInner
, &rect
) ;
1843 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1844 RectRgn( updateOuter
, &rect
) ;
1845 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1847 #ifdef __WXMAC_OSX__
1848 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1850 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1852 InvalWindowRgn( tlw
, updateOuter
) ;
1855 DisposeRgn( updateOuter
) ;
1856 DisposeRgn( updateInner
) ;
1859 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1861 // this is never called for a toplevel window, so we know we have a parent
1862 int former_x
, former_y
, former_w
, former_h
;
1864 // Get true coordinates of former position
1865 DoGetPosition( &former_x
, &former_y
) ;
1866 DoGetSize( &former_w
, &former_h
) ;
1868 wxWindow
*parent
= GetParent();
1871 wxPoint
pt(parent
->GetClientAreaOrigin());
1876 int actualWidth
= width
;
1877 int actualHeight
= height
;
1881 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1882 actualWidth
= m_minWidth
;
1883 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1884 actualHeight
= m_minHeight
;
1885 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1886 actualWidth
= m_maxWidth
;
1887 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1888 actualHeight
= m_maxHeight
;
1890 bool doMove
= false, doResize
= false ;
1892 if ( actualX
!= former_x
|| actualY
!= former_y
)
1895 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1898 if ( doMove
|| doResize
)
1900 // as the borders are drawn outside the native control, we adjust now
1902 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1903 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1904 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1907 wxMacRectToNative( &bounds
, &r
) ;
1909 if ( !GetParent()->IsTopLevel() )
1910 wxMacWindowToNative( GetParent() , &r
) ;
1912 MacInvalidateBorders() ;
1914 m_cachedClippedRectValid
= false ;
1915 m_peer
->SetRect( &r
) ;
1917 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1919 MacInvalidateBorders() ;
1921 MacRepositionScrollBars() ;
1924 wxPoint
point(actualX
, actualY
);
1925 wxMoveEvent
event(point
, m_windowId
);
1926 event
.SetEventObject(this);
1927 GetEventHandler()->ProcessEvent(event
) ;
1932 MacRepositionScrollBars() ;
1933 wxSize
size(actualWidth
, actualHeight
);
1934 wxSizeEvent
event(size
, m_windowId
);
1935 event
.SetEventObject(this);
1936 GetEventHandler()->ProcessEvent(event
);
1941 wxSize
wxWindowMac::DoGetBestSize() const
1943 if ( m_macIsUserPane
|| IsTopLevel() )
1944 return wxWindowBase::DoGetBestSize() ;
1946 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1947 int bestWidth
, bestHeight
;
1949 m_peer
->GetBestRect( &bestsize
) ;
1950 if ( EmptyRect( &bestsize
) )
1955 bestsize
.bottom
= 16 ;
1957 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1959 bestsize
.bottom
= 16 ;
1962 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1964 bestsize
.bottom
= 24 ;
1969 // return wxWindowBase::DoGetBestSize() ;
1973 bestWidth
= bestsize
.right
- bestsize
.left
;
1974 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1975 if ( bestHeight
< 10 )
1978 return wxSize(bestWidth
, bestHeight
);
1981 // set the size of the window: if the dimensions are positive, just use them,
1982 // but if any of them is equal to -1, it means that we must find the value for
1983 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1984 // which case -1 is a valid value for x and y)
1986 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1987 // the width/height to best suit our contents, otherwise we reuse the current
1989 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1991 // get the current size and position...
1992 int currentX
, currentY
;
1993 int currentW
, currentH
;
1995 GetPosition(¤tX
, ¤tY
);
1996 GetSize(¤tW
, ¤tH
);
1998 // ... and don't do anything (avoiding flicker) if it's already ok
1999 if ( x
== currentX
&& y
== currentY
&&
2000 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2003 MacRepositionScrollBars() ; // we might have a real position shift
2008 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2010 if ( x
== wxDefaultCoord
)
2012 if ( y
== wxDefaultCoord
)
2016 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2018 wxSize size
= wxDefaultSize
;
2019 if ( width
== wxDefaultCoord
)
2021 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2023 size
= DoGetBestSize();
2028 // just take the current one
2033 if ( height
== wxDefaultCoord
)
2035 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2037 if ( size
.x
== wxDefaultCoord
)
2038 size
= DoGetBestSize();
2039 // else: already called DoGetBestSize() above
2045 // just take the current one
2050 DoMoveWindow( x
, y
, width
, height
);
2053 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2055 RgnHandle rgn
= NewRgn() ;
2057 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2059 GetRegionBounds( rgn
, &content
) ;
2069 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2072 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2074 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2076 int currentclientwidth
, currentclientheight
;
2077 int currentwidth
, currentheight
;
2079 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2080 GetSize( ¤twidth
, ¤theight
) ;
2082 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2083 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2087 void wxWindowMac::SetLabel(const wxString
& title
)
2089 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2091 if ( m_peer
&& m_peer
->Ok() )
2092 m_peer
->SetLabel( m_label
) ;
2097 wxString
wxWindowMac::GetLabel() const
2102 bool wxWindowMac::Show(bool show
)
2104 bool former
= MacIsReallyShown() ;
2105 if ( !wxWindowBase::Show(show
) )
2108 // TODO: use visibilityChanged Carbon Event for OSX
2110 m_peer
->SetVisibility( show
, true ) ;
2112 if ( former
!= MacIsReallyShown() )
2113 MacPropagateVisibilityChanged() ;
2118 bool wxWindowMac::Enable(bool enable
)
2120 wxASSERT( m_peer
->Ok() ) ;
2121 bool former
= MacIsReallyEnabled() ;
2122 if ( !wxWindowBase::Enable(enable
) )
2125 m_peer
->Enable( enable
) ;
2127 if ( former
!= MacIsReallyEnabled() )
2128 MacPropagateEnabledStateChanged() ;
2134 // status change propagations (will be not necessary for OSX later )
2137 void wxWindowMac::MacPropagateVisibilityChanged()
2139 #if !TARGET_API_MAC_OSX
2140 MacVisibilityChanged() ;
2143 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2146 child
= node
->GetData();
2147 if ( child
->IsShown() )
2148 child
->MacPropagateVisibilityChanged() ;
2150 node
= node
->GetNext();
2155 void wxWindowMac::MacPropagateEnabledStateChanged()
2157 #if !TARGET_API_MAC_OSX
2158 MacEnabledStateChanged() ;
2161 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2164 child
= node
->GetData();
2165 if ( child
->IsEnabled() )
2166 child
->MacPropagateEnabledStateChanged() ;
2168 node
= node
->GetNext();
2173 void wxWindowMac::MacPropagateHiliteChanged()
2175 #if !TARGET_API_MAC_OSX
2176 MacHiliteChanged() ;
2179 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2182 child
= node
->GetData();
2183 if (child
/* && child->IsEnabled() */)
2184 child
->MacPropagateHiliteChanged() ;
2186 node
= node
->GetNext();
2192 // status change notifications
2195 void wxWindowMac::MacVisibilityChanged()
2199 void wxWindowMac::MacHiliteChanged()
2203 void wxWindowMac::MacEnabledStateChanged()
2208 // status queries on the inherited window's state
2211 bool wxWindowMac::MacIsReallyShown()
2213 // only under OSX the visibility of the TLW is taken into account
2214 if ( m_isBeingDeleted
)
2217 #if TARGET_API_MAC_OSX
2218 if ( m_peer
&& m_peer
->Ok() )
2219 return m_peer
->IsVisible();
2222 wxWindow
* win
= this ;
2223 while ( win
->IsShown() )
2225 if ( win
->IsTopLevel() )
2228 win
= win
->GetParent() ;
2236 bool wxWindowMac::MacIsReallyEnabled()
2238 return m_peer
->IsEnabled() ;
2241 bool wxWindowMac::MacIsReallyHilited()
2243 return m_peer
->IsActive();
2246 void wxWindowMac::MacFlashInvalidAreas()
2248 #if TARGET_API_MAC_OSX
2249 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2253 int wxWindowMac::GetCharHeight() const
2255 wxClientDC
dc( (wxWindowMac
*)this ) ;
2257 return dc
.GetCharHeight() ;
2260 int wxWindowMac::GetCharWidth() const
2262 wxClientDC
dc( (wxWindowMac
*)this ) ;
2264 return dc
.GetCharWidth() ;
2267 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2268 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2270 const wxFont
*fontToUse
= theFont
;
2272 fontToUse
= &m_font
;
2274 wxClientDC
dc( (wxWindowMac
*) this ) ;
2276 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2277 if ( externalLeading
)
2278 *externalLeading
= le
;
2288 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2289 * we always intersect with the entire window, not only with the client area
2292 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2294 if ( m_peer
== NULL
)
2297 if ( !MacIsReallyShown() )
2304 wxMacRectToNative( rect
, &r
) ;
2305 m_peer
->SetNeedsDisplay( &r
) ;
2309 m_peer
->SetNeedsDisplay() ;
2313 void wxWindowMac::Freeze()
2315 #if TARGET_API_MAC_OSX
2316 if ( !m_frozenness
++ )
2318 if ( m_peer
&& m_peer
->Ok() )
2319 m_peer
->SetDrawingEnabled( false ) ;
2324 void wxWindowMac::Thaw()
2326 #if TARGET_API_MAC_OSX
2327 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2329 if ( !--m_frozenness
)
2331 if ( m_peer
&& m_peer
->Ok() )
2333 m_peer
->SetDrawingEnabled( true ) ;
2334 m_peer
->InvalidateWithChildren() ;
2340 bool wxWindowMac::IsFrozen() const
2342 return m_frozenness
!= 0;
2345 wxWindowMac
*wxGetActiveWindow()
2347 // actually this is a windows-only concept
2351 // Coordinates relative to the window
2352 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2354 // We really don't move the mouse programmatically under Mac.
2357 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2359 if ( MacGetTopLevelWindow() == NULL
)
2362 #if TARGET_API_MAC_OSX
2363 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2370 event
.GetDC()->Clear() ;
2374 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2379 int wxWindowMac::GetScrollPos(int orient
) const
2381 if ( orient
== wxHORIZONTAL
)
2384 return m_hScrollBar
->GetThumbPosition() ;
2389 return m_vScrollBar
->GetThumbPosition() ;
2395 // This now returns the whole range, not just the number
2396 // of positions that we can scroll.
2397 int wxWindowMac::GetScrollRange(int orient
) const
2399 if ( orient
== wxHORIZONTAL
)
2402 return m_hScrollBar
->GetRange() ;
2407 return m_vScrollBar
->GetRange() ;
2413 int wxWindowMac::GetScrollThumb(int orient
) const
2415 if ( orient
== wxHORIZONTAL
)
2418 return m_hScrollBar
->GetThumbSize() ;
2423 return m_vScrollBar
->GetThumbSize() ;
2429 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2431 if ( orient
== wxHORIZONTAL
)
2434 m_hScrollBar
->SetThumbPosition( pos
) ;
2439 m_vScrollBar
->SetThumbPosition( pos
) ;
2444 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2445 // our own window origin is at leftOrigin/rightOrigin
2448 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2454 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2455 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2457 // back to the surrounding frame rectangle
2458 m_peer
->GetRect( &rect
) ;
2459 InsetRect( &rect
, -1 , -1 ) ;
2461 #if wxMAC_USE_CORE_GRAPHICS
2463 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2464 rect
.bottom
- rect
.top
) ;
2466 HIThemeFrameDrawInfo info
;
2467 memset( &info
, 0 , sizeof(info
) ) ;
2471 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2472 info
.isFocused
= hasFocus
;
2474 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2475 wxASSERT( cgContext
) ;
2477 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2479 info
.kind
= kHIThemeFrameTextFieldSquare
;
2480 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2482 else if ( HasFlag(wxSIMPLE_BORDER
) )
2484 info
.kind
= kHIThemeFrameListBox
;
2485 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2487 else if ( hasFocus
)
2489 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2492 m_peer
->GetRect( &rect
) ;
2493 if ( hasBothScrollbars
)
2495 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2496 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2497 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2498 HIThemeGrowBoxDrawInfo info
;
2499 memset( &info
, 0, sizeof(info
) ) ;
2501 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2502 info
.kind
= kHIThemeGrowBoxKindNone
;
2503 info
.size
= kHIThemeGrowBoxSizeNormal
;
2504 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2505 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2510 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2514 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2515 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2518 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2519 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2520 else if ( HasFlag(wxSIMPLE_BORDER
) )
2521 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2524 DrawThemeFocusRect( &rect
, true ) ;
2526 if ( hasBothScrollbars
)
2528 // GetThemeStandaloneGrowBoxBounds
2529 // DrawThemeStandaloneNoGrowBox
2535 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2537 if ( child
== m_hScrollBar
)
2538 m_hScrollBar
= NULL
;
2539 if ( child
== m_vScrollBar
)
2540 m_vScrollBar
= NULL
;
2542 wxWindowBase::RemoveChild( child
) ;
2545 // New function that will replace some of the above.
2546 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2547 int range
, bool refresh
)
2550 bool triggerSizeEvent
= false;
2552 if ( orient
== wxHORIZONTAL
)
2556 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2557 if ( m_hScrollBar
->IsShown() != showScroller
)
2559 m_hScrollBar
->Show( showScroller
);
2560 triggerSizeEvent
= true;
2563 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2570 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2571 if ( m_vScrollBar
->IsShown() != showScroller
)
2573 m_vScrollBar
->Show( showScroller
) ;
2574 triggerSizeEvent
= true;
2577 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2581 MacRepositionScrollBars() ;
2582 if ( triggerSizeEvent
)
2584 wxSizeEvent
event(GetSize(), m_windowId
);
2585 event
.SetEventObject(this);
2586 GetEventHandler()->ProcessEvent(event
);
2590 // Does a physical scroll
2591 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2593 if ( dx
== 0 && dy
== 0 )
2596 int width
, height
;
2597 GetClientSize( &width
, &height
) ;
2600 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2601 // area is scrolled, this does not occur if width and height are 2 pixels less,
2602 // TODO: write optimal workaround
2603 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2605 scrollrect
.Intersect( *rect
) ;
2607 if ( m_peer
->GetNeedsDisplay() )
2609 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2610 // either immediate redraw or full invalidate
2612 // is the better overall solution, as it does not slow down scrolling
2613 m_peer
->SetNeedsDisplay() ;
2615 // this would be the preferred version for fast drawing controls
2617 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2618 if ( UMAGetSystemVersion() >= 0x1030 )
2619 HIViewRender(m_peer
->GetControlRef()) ;
2626 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2627 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2628 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2630 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2631 // either immediate redraw or full invalidate
2633 // is the better overall solution, as it does not slow down scrolling
2634 m_peer
->SetNeedsDisplay() ;
2636 // this would be the preferred version for fast drawing controls
2638 HIViewRender(m_peer
->GetControlRef()) ;
2644 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2646 child
= node
->GetData();
2649 if (child
== m_vScrollBar
)
2651 if (child
== m_hScrollBar
)
2653 if (child
->IsTopLevel())
2656 child
->GetPosition( &x
, &y
);
2657 child
->GetSize( &w
, &h
);
2660 wxRect
rc( x
, y
, w
, h
);
2661 if (rect
->Intersects( rc
))
2662 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2666 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2671 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2673 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2675 wxScrollWinEvent wevent
;
2676 wevent
.SetPosition(event
.GetPosition());
2677 wevent
.SetOrientation(event
.GetOrientation());
2678 wevent
.SetEventObject(this);
2680 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2681 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2682 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2683 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2684 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2685 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2686 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2687 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2688 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2689 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2690 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2691 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2692 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2693 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2694 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2695 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2697 GetEventHandler()->ProcessEvent(wevent
);
2701 // Get the window with the focus
2702 wxWindowMac
*wxWindowBase::DoFindFocus()
2704 ControlRef control
;
2705 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2706 return wxFindControlFromMacControl( control
) ;
2709 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2711 // panel wants to track the window which was the last to have focus in it,
2712 // so we want to set ourselves as the window which last had focus
2714 // notice that it's also important to do it upwards the tree because
2715 // otherwise when the top level panel gets focus, it won't set it back to
2716 // us, but to some other sibling
2718 // CS: don't know if this is still needed:
2719 //wxChildFocusEvent eventFocus(this);
2720 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2722 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2724 #if wxMAC_USE_CORE_GRAPHICS
2725 GetParent()->Refresh() ;
2727 wxMacWindowStateSaver
sv( this ) ;
2730 m_peer
->GetRect( &rect
) ;
2731 // auf den umgebenden Rahmen zur\9fck
2732 InsetRect( &rect
, -1 , -1 ) ;
2734 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2738 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2740 rect
.right
+= pt
.x
;
2742 rect
.bottom
+= pt
.y
;
2745 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2746 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2747 if ( !bIsFocusEvent
)
2749 // as this erases part of the frame we have to redraw borders
2750 // and because our z-ordering is not always correct (staticboxes)
2751 // we have to invalidate things, we cannot simple redraw
2752 MacInvalidateBorders() ;
2760 void wxWindowMac::OnInternalIdle()
2762 // This calls the UI-update mechanism (querying windows for
2763 // menu/toolbar/control state information)
2764 if (wxUpdateUIEvent::CanUpdate(this))
2765 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2768 // Raise the window to the top of the Z order
2769 void wxWindowMac::Raise()
2771 m_peer
->SetZOrder( true , NULL
) ;
2774 // Lower the window to the bottom of the Z order
2775 void wxWindowMac::Lower()
2777 m_peer
->SetZOrder( false , NULL
) ;
2780 // static wxWindow *gs_lastWhich = NULL;
2782 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2784 // first trigger a set cursor event
2786 wxPoint clientorigin
= GetClientAreaOrigin() ;
2787 wxSize clientsize
= GetClientSize() ;
2789 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2791 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2793 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2794 if ( processedEvtSetCursor
&& event
.HasCursor() )
2796 cursor
= event
.GetCursor() ;
2800 // the test for processedEvtSetCursor is here to prevent using m_cursor
2801 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2802 // it - this is a way to say that our cursor shouldn't be used for this
2804 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2807 if ( !wxIsBusy() && !GetParent() )
2808 cursor
= *wxSTANDARD_CURSOR
;
2812 cursor
.MacInstall() ;
2815 return cursor
.Ok() ;
2818 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2822 return m_tooltip
->GetTip() ;
2825 return wxEmptyString
;
2828 void wxWindowMac::ClearBackground()
2834 void wxWindowMac::Update()
2836 #if TARGET_API_MAC_OSX
2837 MacGetTopLevelWindow()->MacPerformUpdates() ;
2839 ::Draw1Control( m_peer
->GetControlRef() ) ;
2843 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2845 wxTopLevelWindowMac
* win
= NULL
;
2846 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2848 win
= wxFindWinFromMacWindow( window
) ;
2853 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2855 MacUpdateClippedRects() ;
2857 return m_cachedClippedClientRect
;
2860 const wxRect
& wxWindowMac::MacGetClippedRect() const
2862 MacUpdateClippedRects() ;
2864 return m_cachedClippedRect
;
2867 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2869 MacUpdateClippedRects() ;
2871 return m_cachedClippedRectWithOuterStructure
;
2874 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2876 static wxRegion emptyrgn
;
2878 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2880 MacUpdateClippedRects() ;
2881 if ( includeOuterStructures
)
2882 return m_cachedClippedRegionWithOuterStructure
;
2884 return m_cachedClippedRegion
;
2892 void wxWindowMac::MacUpdateClippedRects() const
2894 if ( m_cachedClippedRectValid
)
2897 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2898 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2899 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2900 // to add focus borders everywhere
2902 Rect r
, rIncludingOuterStructures
;
2904 m_peer
->GetRect( &r
) ;
2905 r
.left
-= MacGetLeftBorderSize() ;
2906 r
.top
-= MacGetTopBorderSize() ;
2907 r
.bottom
+= MacGetBottomBorderSize() ;
2908 r
.right
+= MacGetRightBorderSize() ;
2915 rIncludingOuterStructures
= r
;
2916 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2918 wxRect cl
= GetClientRect() ;
2919 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2923 const wxWindow
* child
= this ;
2924 const wxWindow
* parent
= NULL
;
2926 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2928 if ( parent
->MacIsChildOfClientArea(child
) )
2930 size
= parent
->GetClientSize() ;
2931 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2937 // this will be true for scrollbars, toolbars etc.
2938 size
= parent
->GetSize() ;
2939 y
= parent
->MacGetTopBorderSize() ;
2940 x
= parent
->MacGetLeftBorderSize() ;
2941 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2942 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2945 parent
->MacWindowToRootWindow( &x
, &y
) ;
2946 MacRootWindowToWindow( &x
, &y
) ;
2948 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2950 // the wxwindow and client rects will always be clipped
2951 SectRect( &r
, &rparent
, &r
) ;
2952 SectRect( &rClient
, &rparent
, &rClient
) ;
2954 // the structure only at 'hard' borders
2955 if ( parent
->MacClipChildren() ||
2956 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2958 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2964 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2965 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2966 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2967 m_cachedClippedRectWithOuterStructure
= wxRect(
2968 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2969 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2970 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2972 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2973 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2974 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2976 m_cachedClippedRectValid
= true ;
2980 This function must not change the updatergn !
2982 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2984 bool handled
= false ;
2986 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2987 GetRegionBounds( updatergn
, &updatebounds
) ;
2989 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2991 if ( !EmptyRgn(updatergn
) )
2993 RgnHandle newupdate
= NewRgn() ;
2994 wxSize point
= GetClientSize() ;
2995 wxPoint origin
= GetClientAreaOrigin() ;
2996 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2997 SectRgn( newupdate
, updatergn
, newupdate
) ;
2999 // first send an erase event to the entire update area
3001 // for the toplevel window this really is the entire area
3002 // for all the others only their client area, otherwise they
3003 // might be drawing with full alpha and eg put blue into
3004 // the grow-box area of a scrolled window (scroll sample)
3005 wxDC
* dc
= new wxWindowDC(this);
3007 dc
->SetClippingRegion(wxRegion(updatergn
));
3009 dc
->SetClippingRegion(wxRegion(newupdate
));
3011 wxEraseEvent
eevent( GetId(), dc
);
3012 eevent
.SetEventObject( this );
3013 GetEventHandler()->ProcessEvent( eevent
);
3017 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3018 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3019 m_updateRegion
= newupdate
;
3020 DisposeRgn( newupdate
) ;
3022 if ( !m_updateRegion
.Empty() )
3024 // paint the window itself
3027 event
.SetTimestamp(time
);
3028 event
.SetEventObject(this);
3029 GetEventHandler()->ProcessEvent(event
);
3033 // now we cannot rely on having its borders drawn by a window itself, as it does not
3034 // get the updateRgn wide enough to always do so, so we do it from the parent
3035 // this would also be the place to draw any custom backgrounds for native controls
3036 // in Composited windowing
3037 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3041 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3043 child
= node
->GetData();
3046 if (child
== m_vScrollBar
)
3048 if (child
== m_hScrollBar
)
3050 if (child
->IsTopLevel())
3052 if (!child
->IsShown())
3055 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3057 child
->GetPosition( &x
, &y
);
3058 child
->GetSize( &w
, &h
);
3059 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3060 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3061 InsetRect( &childRect
, -10 , -10) ;
3063 if ( RectInRgn( &childRect
, updatergn
) )
3065 // paint custom borders
3066 wxNcPaintEvent
eventNc( child
->GetId() );
3067 eventNc
.SetEventObject( child
);
3068 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3070 #if wxMAC_USE_CORE_GRAPHICS
3071 child
->MacPaintBorders(0, 0) ;
3074 wxWindowDC
dc(this) ;
3075 dc
.SetClippingRegion(wxRegion(updatergn
));
3076 wxMacPortSetter
helper(&dc
) ;
3077 child
->MacPaintBorders(0, 0) ;
3089 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3091 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3095 if ( iter
->IsTopLevel() )
3096 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3098 iter
= iter
->GetParent() ;
3104 void wxWindowMac::MacCreateScrollBars( long style
)
3106 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3108 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3110 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3111 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3112 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3114 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3117 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3119 GetClientSize( &width
, &height
) ;
3121 wxPoint
vPoint(width
- scrlsize
, 0) ;
3122 wxSize
vSize(scrlsize
, height
- adjust
) ;
3123 wxPoint
hPoint(0, height
- scrlsize
) ;
3124 wxSize
hSize(width
- adjust
, scrlsize
) ;
3126 if ( style
& wxVSCROLL
)
3127 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3129 if ( style
& wxHSCROLL
)
3130 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3133 // because the create does not take into account the client area origin
3134 // we might have a real position shift
3135 MacRepositionScrollBars() ;
3138 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3140 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3145 void wxWindowMac::MacRepositionScrollBars()
3147 if ( !m_hScrollBar
&& !m_vScrollBar
)
3150 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3151 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3152 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3154 // get real client area
3156 GetSize( &width
, &height
);
3158 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3159 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3161 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3162 wxSize
vSize( scrlsize
, height
- adjust
) ;
3163 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3164 wxSize
hSize( width
- adjust
, scrlsize
) ;
3167 int x
= 0, y
= 0, w
, h
;
3168 GetSize( &w
, &h
) ;
3170 MacClientToRootWindow( &x
, &y
) ;
3171 MacClientToRootWindow( &w
, &h
) ;
3173 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3175 int totW
= 10000 , totH
= 10000;
3178 if ( iter
->IsTopLevel() )
3180 iter
->GetSize( &totW
, &totH
) ;
3184 iter
= iter
->GetParent() ;
3198 if ( w
- x
>= totW
)
3203 if ( h
- y
>= totH
)
3211 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3213 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3216 bool wxWindowMac::AcceptsFocus() const
3218 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3221 void wxWindowMac::MacSuperChangedPosition()
3223 // only window-absolute structures have to be moved i.e. controls
3225 m_cachedClippedRectValid
= false ;
3228 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3231 child
= node
->GetData();
3232 child
->MacSuperChangedPosition() ;
3234 node
= node
->GetNext();
3238 void wxWindowMac::MacTopLevelWindowChangedPosition()
3240 // only screen-absolute structures have to be moved i.e. glcanvas
3243 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3246 child
= node
->GetData();
3247 child
->MacTopLevelWindowChangedPosition() ;
3249 node
= node
->GetNext();
3253 long wxWindowMac::MacGetLeftBorderSize() const
3260 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3262 // this metric is only the 'outset' outside the simple frame rect
3263 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3266 else if (HasFlag(wxSIMPLE_BORDER
))
3268 // this metric is only the 'outset' outside the simple frame rect
3269 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3276 long wxWindowMac::MacGetRightBorderSize() const
3278 // they are all symmetric in mac themes
3279 return MacGetLeftBorderSize() ;
3282 long wxWindowMac::MacGetTopBorderSize() const
3284 // they are all symmetric in mac themes
3285 return MacGetLeftBorderSize() ;
3288 long wxWindowMac::MacGetBottomBorderSize() const
3290 // they are all symmetric in mac themes
3291 return MacGetLeftBorderSize() ;
3294 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3296 return style
& ~wxBORDER_MASK
;
3299 // Find the wxWindowMac at the current mouse position, returning the mouse
3301 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3303 pt
= wxGetMousePosition();
3304 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3309 // Get the current mouse position.
3310 wxPoint
wxGetMousePosition()
3314 wxGetMousePosition( &x
, &y
);
3316 return wxPoint(x
, y
);
3319 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3321 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3323 // copied from wxGTK : CS
3324 // VZ: shouldn't we move this to base class then?
3326 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3329 // (a) it's a command event and so is propagated to the parent
3330 // (b) under MSW it can be generated from kbd too
3331 // (c) it uses screen coords (because of (a))
3332 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3334 this->ClientToScreen(event
.GetPosition()));
3335 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3344 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3346 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3347 CallNextEventHandler(
3348 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3349 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3352 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3356 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3360 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3361 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3366 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3368 return eventNotHandledErr
;
3371 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3373 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3374 if ( !wxWindowBase::Reparent(newParent
) )
3377 // copied from MacPostControlCreate
3378 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3380 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3382 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3387 bool wxWindowMac::SetTransparent(wxByte alpha
)
3389 #if wxMAC_USE_CORE_GRAPHICS
3390 if ( alpha
!= m_macAlpha
)
3392 m_macAlpha
= alpha
;
3402 bool wxWindowMac::CanSetTransparent()
3404 #if wxMAC_USE_CORE_GRAPHICS
3411 wxByte
wxWindowMac::GetTransparent() const