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"
38 #include "wx/tooltip.h"
39 #include "wx/spinctrl.h"
40 #include "wx/geometry.h"
46 #if wxUSE_DRAG_AND_DROP
50 #include "wx/mac/uma.h"
52 #define MAC_SCROLLBAR_SIZE 15
53 #define MAC_SMALL_SCROLLBAR_SIZE 11
57 #include <ToolUtils.h>
59 #include <MacTextEditor.h>
62 #if TARGET_API_MAC_OSX
64 #include <HIToolbox/HIView.h>
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
76 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
77 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
78 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
79 #if TARGET_API_MAC_OSX
80 EVT_PAINT(wxWindowMac::OnPaint
)
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 // ---------------------------------------------------------------------------
93 // Utility Routines to move between different coordinate systems
94 // ---------------------------------------------------------------------------
97 * Right now we have the following setup :
98 * a border that is not part of the native control is always outside the
99 * control's border (otherwise we loose all native intelligence, future ways
100 * may be to have a second embedding control responsible for drawing borders
101 * and backgrounds eventually)
102 * so all this border calculations have to be taken into account when calling
103 * native methods or getting native oriented data
104 * so we have three coordinate systems here
105 * wx client coordinates
106 * wx window coordinates (including window frames)
111 // originating from native control
115 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
117 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
120 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
122 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
126 // directed towards native control
129 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
131 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
134 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
136 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
139 // ---------------------------------------------------------------------------
141 // ---------------------------------------------------------------------------
143 #if TARGET_API_MAC_OSX
145 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
148 kEventControlVisibilityChanged
= 157
154 static const EventTypeSpec eventList
[] =
156 { kEventClassCommand
, kEventProcessCommand
} ,
157 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
159 { kEventClassControl
, kEventControlGetClickActivation
} ,
160 { kEventClassControl
, kEventControlHit
} ,
162 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
163 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
165 { kEventClassControl
, kEventControlDraw
} ,
166 #if TARGET_API_MAC_OSX
167 { kEventClassControl
, kEventControlVisibilityChanged
} ,
168 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
169 { kEventClassControl
, kEventControlHiliteChanged
} ,
171 { kEventClassControl
, kEventControlSetFocusPart
} ,
173 { kEventClassService
, kEventServiceGetTypes
},
174 { kEventClassService
, kEventServiceCopy
},
175 { kEventClassService
, kEventServicePaste
},
177 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
178 // { kEventClassControl , kEventControlBoundsChanged } ,
181 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
183 OSStatus result
= eventNotHandledErr
;
185 wxMacCarbonEvent
cEvent( event
) ;
187 ControlRef controlRef
;
188 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
190 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
192 switch ( GetEventKind( event
) )
194 #if TARGET_API_MAC_OSX
195 case kEventControlDraw
:
197 RgnHandle updateRgn
= NULL
;
198 RgnHandle allocatedRgn
= NULL
;
199 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
201 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
203 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
207 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
209 // as this update region is in native window locals we must adapt it to wx window local
210 allocatedRgn
= NewRgn() ;
211 CopyRgn( updateRgn
, allocatedRgn
) ;
213 // hide the given region by the new region that must be shifted
214 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
215 updateRgn
= allocatedRgn
;
220 GetRegionBounds( updateRgn
, &rgnBounds
) ;
222 #if wxMAC_DEBUG_REDRAW
223 if ( thisWindow
->MacIsUserPane() )
225 static float color
= 0.5 ;
228 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
230 HIViewGetBounds( controlRef
, &bounds
);
231 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
232 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
233 CGContextFillRect( cgContext
, bounds
);
246 #if wxMAC_USE_CORE_GRAPHICS
247 bool created
= false ;
248 CGContextRef cgContext
= NULL
;
249 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
250 wxASSERT_MSG( err
== noErr
, wxT("Unable to retrieve CGContextRef") ) ;
251 thisWindow
->MacSetCGContextRef( cgContext
) ;
254 wxMacCGContextStateSaver
sg( cgContext
) ;
257 wxWindow
* iter
= thisWindow
;
260 alpha
*= (float) iter
->GetTransparent()/255.0 ;
261 if ( iter
->IsTopLevel() )
264 iter
= iter
->GetParent() ;
267 CGContextSetAlpha( cgContext
, alpha
) ;
269 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
272 #if wxMAC_USE_CORE_GRAPHICS
273 thisWindow
->MacSetCGContextRef( NULL
) ;
277 CGContextRelease( cgContext
) ;
282 DisposeRgn( allocatedRgn
) ;
286 case kEventControlVisibilityChanged
:
287 thisWindow
->MacVisibilityChanged() ;
290 case kEventControlEnabledStateChanged
:
291 thisWindow
->MacEnabledStateChanged() ;
294 case kEventControlHiliteChanged
:
295 thisWindow
->MacHiliteChanged() ;
299 // we emulate this event under Carbon CFM
300 case kEventControlSetFocusPart
:
302 Boolean focusEverything
= false ;
303 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
306 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
311 if ( controlPart
== kControlFocusNoPart
)
314 if ( thisWindow
->GetCaret() )
315 thisWindow
->GetCaret()->OnKillFocus();
318 static bool inKillFocusEvent
= false ;
320 if ( !inKillFocusEvent
)
322 inKillFocusEvent
= true ;
323 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
324 event
.SetEventObject(thisWindow
);
325 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
326 inKillFocusEvent
= false ;
331 // panel wants to track the window which was the last to have focus in it
332 wxChildFocusEvent
eventFocus(thisWindow
);
333 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
336 if ( thisWindow
->GetCaret() )
337 thisWindow
->GetCaret()->OnSetFocus();
340 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
341 event
.SetEventObject(thisWindow
);
342 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
345 if ( thisWindow
->MacIsUserPane() )
350 case kEventControlHit
:
351 result
= thisWindow
->MacControlHit( handler
, event
) ;
354 case kEventControlGetClickActivation
:
356 // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
357 WindowRef owner
= cEvent
.GetParameter
<WindowRef
>(kEventParamWindowRef
);
358 if ( !IsWindowActive(owner
) )
360 cEvent
.SetParameter(kEventParamClickActivation
,(UInt32
) kActivateAndIgnoreClick
) ;
373 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
375 OSStatus result
= eventNotHandledErr
;
377 wxMacCarbonEvent
cEvent( event
) ;
379 ControlRef controlRef
;
380 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
381 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
382 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
384 switch ( GetEventKind( event
) )
386 case kEventServiceGetTypes
:
390 textCtrl
->GetSelection( &from
, &to
) ;
392 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
394 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
395 if ( textCtrl
->IsEditable() )
396 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
398 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
399 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
401 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
405 CFArrayAppendValue(copyTypes
, typestring
) ;
407 CFArrayAppendValue(pasteTypes
, typestring
) ;
409 CFRelease( typestring
) ;
417 case kEventServiceCopy
:
422 textCtrl
->GetSelection( &from
, &to
) ;
423 wxString val
= textCtrl
->GetValue() ;
424 val
= val
.Mid( from
, to
- from
) ;
425 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
426 verify_noerr( ClearScrap( &scrapRef
) ) ;
427 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
432 case kEventServicePaste
:
435 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
436 Size textSize
, pastedSize
;
437 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
439 char *content
= new char[textSize
] ;
440 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
441 content
[textSize
- 1] = 0 ;
444 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
446 textCtrl
->WriteText( wxString( content
) ) ;
461 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
463 OSStatus result
= eventNotHandledErr
;
464 wxWindowMac
* focus
= (wxWindowMac
*) data
;
466 wchar_t* uniChars
= NULL
;
467 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
469 UniChar
* charBuf
= NULL
;
470 ByteCount dataSize
= 0 ;
473 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
475 numChars
= dataSize
/ sizeof( UniChar
) + 1;
478 if ( (size_t) numChars
* 2 > sizeof(buf
) )
479 charBuf
= new UniChar
[ numChars
] ;
483 uniChars
= new wchar_t[ numChars
] ;
484 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
485 charBuf
[ numChars
- 1 ] = 0;
486 #if SIZEOF_WCHAR_T == 2
487 uniChars
= (wchar_t*) charBuf
;
488 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
490 // the resulting string will never have more chars than the utf16 version, so this is safe
491 wxMBConvUTF16 converter
;
492 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
496 switch ( GetEventKind( event
) )
498 case kEventTextInputUpdateActiveInputArea
:
500 // An IME input event may return several characters, but we need to send one char at a time to
502 for (int pos
=0 ; pos
< numChars
; pos
++)
504 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
505 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
506 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
508 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
509 if ( wxTheApp
->MacSendCharEvent(
510 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
515 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
519 case kEventTextInputUnicodeForKeyEvent
:
521 UInt32 keyCode
, modifiers
;
524 unsigned char charCode
;
526 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
527 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
528 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
529 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
530 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
532 UInt32 message
= (keyCode
<< 8) + charCode
;
534 // An IME input event may return several characters, but we need to send one char at a time to
536 for (int pos
=0 ; pos
< numChars
; pos
++)
538 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
539 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
540 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
542 if ( wxTheApp
->MacSendCharEvent(
543 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
548 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
557 if ( charBuf
!= buf
)
563 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
565 OSStatus result
= eventNotHandledErr
;
566 wxWindowMac
* focus
= (wxWindowMac
*) data
;
570 wxMacCarbonEvent
cEvent( event
) ;
571 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
573 wxMenuItem
* item
= NULL
;
574 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
575 int id
= wxMacCommandToId( command
.commandID
) ;
579 wxASSERT( itemMenu
!= NULL
) ;
581 switch ( cEvent
.GetKind() )
583 case kEventProcessCommand
:
585 if (item
->IsCheckable())
586 item
->Check( !item
->IsChecked() ) ;
588 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
592 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
593 event
.SetEventObject(focus
);
594 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
596 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
602 case kEventCommandUpdateStatus
:
604 wxUpdateUIEvent
event(id
);
605 event
.SetEventObject( itemMenu
);
607 bool processed
= false;
609 // Try the menu's event handler
611 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
613 processed
= handler
->ProcessEvent(event
);
616 // Try the window the menu was popped up from
617 // (and up through the hierarchy)
620 const wxMenuBase
*menu
= itemMenu
;
623 wxWindow
*win
= menu
->GetInvokingWindow();
626 processed
= win
->GetEventHandler()->ProcessEvent(event
);
630 menu
= menu
->GetParent();
636 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
641 // if anything changed, update the changed attribute
642 if (event
.GetSetText())
643 itemMenu
->SetLabel(id
, event
.GetText());
644 if (event
.GetSetChecked())
645 itemMenu
->Check(id
, event
.GetChecked());
646 if (event
.GetSetEnabled())
647 itemMenu
->Enable(id
, event
.GetEnabled());
661 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
663 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
664 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
665 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
666 OSStatus result
= eventNotHandledErr
;
668 switch ( GetEventClass( event
) )
670 case kEventClassCommand
:
671 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
674 case kEventClassControl
:
675 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
678 case kEventClassService
:
679 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
682 case kEventClassTextInput
:
683 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
690 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
695 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
697 #if !TARGET_API_MAC_OSX
699 // ---------------------------------------------------------------------------
700 // UserPane events for non OSX builds
701 // ---------------------------------------------------------------------------
703 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
705 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
707 win
->MacControlUserPaneDrawProc(part
) ;
709 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
711 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
713 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
715 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
717 return kControlNoPart
;
719 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
721 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
723 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
725 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
727 return kControlNoPart
;
729 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
731 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
733 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
735 win
->MacControlUserPaneIdleProc() ;
737 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
739 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
741 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
743 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
745 return kControlNoPart
;
747 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
749 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
751 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
753 win
->MacControlUserPaneActivateProc(activating
) ;
755 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
757 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
759 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
761 return win
->MacControlUserPaneFocusProc(action
) ;
763 return kControlNoPart
;
765 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
767 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
769 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
771 win
->MacControlUserPaneBackgroundProc(info
) ;
773 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
775 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
778 RgnHandle rgn
= NewRgn() ;
780 MacWindowToRootWindow( &x
, &y
) ;
781 OffsetRgn( rgn
, -x
, -y
) ;
782 wxMacWindowStateSaver
sv( this ) ;
783 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
784 MacDoRedraw( rgn
, 0 ) ;
788 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
790 return kControlNoPart
;
793 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
795 return kControlNoPart
;
798 void wxWindowMac::MacControlUserPaneIdleProc()
802 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
804 return kControlNoPart
;
807 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
811 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
813 if ( AcceptsFocus() )
816 return kControlNoPart
;
819 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
825 // ---------------------------------------------------------------------------
826 // Scrollbar Tracking for all
827 // ---------------------------------------------------------------------------
829 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
830 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
834 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
836 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
839 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
841 // ===========================================================================
843 // ===========================================================================
845 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
847 static MacControlMap wxWinMacControlList
;
849 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
851 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
853 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
856 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
858 // adding NULL ControlRef is (first) surely a result of an error and
859 // (secondly) breaks native event processing
860 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
862 wxWinMacControlList
[inControl
] = control
;
865 void wxRemoveMacControlAssociation(wxWindow
*control
)
867 // iterate over all the elements in the class
868 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
869 // we should go on...
875 MacControlMap::iterator it
;
876 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
878 if ( it
->second
== control
)
880 wxWinMacControlList
.erase(it
);
888 // ----------------------------------------------------------------------------
889 // constructors and such
890 // ----------------------------------------------------------------------------
892 wxWindowMac::wxWindowMac()
897 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
902 const wxString
& name
)
905 Create(parent
, id
, pos
, size
, style
, name
);
908 void wxWindowMac::Init()
914 #if WXWIN_COMPATIBILITY_2_4
915 m_backgroundTransparent
= false;
918 #if wxMAC_USE_CORE_GRAPHICS
919 m_cgContextRef
= NULL
;
922 // as all windows are created with WS_VISIBLE style...
925 m_hScrollBar
= NULL
;
926 m_vScrollBar
= NULL
;
927 m_macBackgroundBrush
= wxNullBrush
;
929 m_macIsUserPane
= true;
930 m_clipChildren
= false ;
931 m_cachedClippedRectValid
= false ;
933 // we need a valid font for the encodings
934 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
937 wxWindowMac::~wxWindowMac()
941 m_isBeingDeleted
= true;
943 MacInvalidateBorders() ;
945 #ifndef __WXUNIVERSAL__
946 // VS: make sure there's no wxFrame with last focus set to us:
947 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
949 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
952 if ( frame
->GetLastFocus() == this )
953 frame
->SetLastFocus((wxWindow
*)NULL
);
959 // destroy children before destroying this window itself
962 // wxRemoveMacControlAssociation( this ) ;
963 // If we delete an item, we should initialize the parent panel,
964 // because it could now be invalid.
965 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
968 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
969 tlw
->SetDefaultItem(NULL
);
972 if ( m_peer
&& m_peer
->Ok() )
974 // in case the callback might be called during destruction
975 wxRemoveMacControlAssociation( this) ;
976 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
977 // we currently are not using this hook
978 // ::SetControlColorProc( *m_peer , NULL ) ;
982 if ( g_MacLastWindow
== this )
983 g_MacLastWindow
= NULL
;
985 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
988 if ( frame
->GetLastFocus() == this )
989 frame
->SetLastFocus( NULL
) ;
992 // delete our drop target if we've got one
993 #if wxUSE_DRAG_AND_DROP
994 if ( m_dropTarget
!= NULL
)
1004 WXWidget
wxWindowMac::GetHandle() const
1006 return (WXWidget
) m_peer
->GetControlRef() ;
1009 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1011 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1012 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1013 GetEventTypeCount(eventList
), eventList
, this,
1014 (EventHandlerRef
*)&m_macControlEventHandler
);
1016 #if !TARGET_API_MAC_OSX
1017 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1019 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1020 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1021 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1022 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1023 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1024 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1025 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1026 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1032 bool wxWindowMac::Create(wxWindowMac
*parent
,
1037 const wxString
& name
)
1039 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1041 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1044 m_windowVariant
= parent
->GetWindowVariant() ;
1046 if ( m_macIsUserPane
)
1048 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1051 | kControlSupportsEmbedding
1052 | kControlSupportsLiveFeedback
1053 | kControlGetsFocusOnClick
1054 // | kControlHasSpecialBackground
1055 // | kControlSupportsCalcBestRect
1056 | kControlHandlesTracking
1057 | kControlSupportsFocus
1058 | kControlWantsActivate
1059 | kControlWantsIdle
;
1061 m_peer
= new wxMacControl(this) ;
1062 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1063 verify_noerr( err
);
1065 MacPostControlCreate(pos
, size
) ;
1068 #ifndef __WXUNIVERSAL__
1069 // Don't give scrollbars to wxControls unless they ask for them
1070 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1071 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1073 MacCreateScrollBars( style
) ;
1077 wxWindowCreateEvent
event(this);
1078 GetEventHandler()->AddPendingEvent(event
);
1083 void wxWindowMac::MacChildAdded()
1086 m_vScrollBar
->Raise() ;
1088 m_hScrollBar
->Raise() ;
1091 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1093 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1095 m_peer
->SetReference( (URefCon
) this ) ;
1096 GetParent()->AddChild( this );
1098 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1100 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1101 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1102 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1103 GetParent()->MacChildAdded() ;
1105 // adjust font, controlsize etc
1106 DoSetWindowVariant( m_windowVariant
) ;
1108 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1110 if (!m_macIsUserPane
)
1111 SetInitialSize(size
);
1113 SetCursor( *wxSTANDARD_CURSOR
) ;
1116 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1118 // Don't assert, in case we set the window variant before
1119 // the window is created
1120 // wxASSERT( m_peer->Ok() ) ;
1122 m_windowVariant
= variant
;
1124 if (m_peer
== NULL
|| !m_peer
->Ok())
1128 ThemeFontID themeFont
= kThemeSystemFont
;
1130 // we will get that from the settings later
1131 // and make this NORMAL later, but first
1132 // we have a few calculations that we must fix
1136 case wxWINDOW_VARIANT_NORMAL
:
1137 size
= kControlSizeNormal
;
1138 themeFont
= kThemeSystemFont
;
1141 case wxWINDOW_VARIANT_SMALL
:
1142 size
= kControlSizeSmall
;
1143 themeFont
= kThemeSmallSystemFont
;
1146 case wxWINDOW_VARIANT_MINI
:
1147 if (UMAGetSystemVersion() >= 0x1030 )
1149 // not always defined in the headers
1155 size
= kControlSizeSmall
;
1156 themeFont
= kThemeSmallSystemFont
;
1160 case wxWINDOW_VARIANT_LARGE
:
1161 size
= kControlSizeLarge
;
1162 themeFont
= kThemeSystemFont
;
1166 wxFAIL_MSG(_T("unexpected window variant"));
1170 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1173 font
.MacCreateThemeFont( themeFont
) ;
1177 void wxWindowMac::MacUpdateControlFont()
1179 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1183 bool wxWindowMac::SetFont(const wxFont
& font
)
1185 bool retval
= wxWindowBase::SetFont( font
);
1187 MacUpdateControlFont() ;
1192 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1194 bool retval
= wxWindowBase::SetForegroundColour( col
);
1197 MacUpdateControlFont();
1202 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1204 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1208 wxColour
newCol(GetBackgroundColour());
1210 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1211 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1212 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1213 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1215 brush
.SetColour( newCol
) ;
1217 MacSetBackgroundBrush( brush
) ;
1218 MacUpdateControlFont() ;
1223 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1225 m_macBackgroundBrush
= brush
;
1226 m_peer
->SetBackground( brush
) ;
1229 bool wxWindowMac::MacCanFocus() const
1231 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1232 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1233 // but the value range is nowhere documented
1234 Boolean keyExistsAndHasValidFormat
;
1235 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1236 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1238 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1244 UInt32 features
= 0 ;
1245 m_peer
->GetFeatures( &features
) ;
1247 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1251 void wxWindowMac::SetFocus()
1253 if ( !AcceptsFocus() )
1256 wxWindow
* former
= FindFocus() ;
1257 if ( former
== this )
1260 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1261 // we can only leave in case of an error
1262 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1263 if ( err
== errCouldntSetFocus
)
1266 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1268 #if !TARGET_API_MAC_OSX
1269 // emulate carbon events when running under CarbonLib where they are not natively available
1272 EventRef evRef
= NULL
;
1274 err
= MacCreateEvent(
1275 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1276 kEventAttributeUserEvent
, &evRef
);
1277 verify_noerr( err
);
1279 wxMacCarbonEvent
cEvent( evRef
) ;
1280 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1281 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1283 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1284 ReleaseEvent( evRef
) ;
1287 // send new focus event
1289 EventRef evRef
= NULL
;
1291 err
= MacCreateEvent(
1292 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1293 kEventAttributeUserEvent
, &evRef
);
1294 verify_noerr( err
);
1296 wxMacCarbonEvent
cEvent( evRef
) ;
1297 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1298 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1300 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1301 ReleaseEvent( evRef
) ;
1306 void wxWindowMac::DoCaptureMouse()
1308 wxApp::s_captureWindow
= this ;
1311 wxWindow
* wxWindowBase::GetCapture()
1313 return wxApp::s_captureWindow
;
1316 void wxWindowMac::DoReleaseMouse()
1318 wxApp::s_captureWindow
= NULL
;
1321 #if wxUSE_DRAG_AND_DROP
1323 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1325 if ( m_dropTarget
!= NULL
)
1326 delete m_dropTarget
;
1328 m_dropTarget
= pDropTarget
;
1329 if ( m_dropTarget
!= NULL
)
1337 // Old-style File Manager Drag & Drop
1338 void wxWindowMac::DragAcceptFiles(bool accept
)
1343 // Returns the size of the native control. In the case of the toplevel window
1344 // this is the content area root control
1346 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1347 int& w
, int& h
) const
1349 wxFAIL_MSG( wxT("Not currently supported") ) ;
1352 // From a wx position / size calculate the appropriate size of the native control
1354 bool wxWindowMac::MacGetBoundsForControl(
1358 int& w
, int& h
, bool adjustOrigin
) const
1360 // the desired size, minus the border pixels gives the correct size of the control
1364 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1365 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1366 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1368 x
+= MacGetLeftBorderSize() ;
1369 y
+= MacGetTopBorderSize() ;
1370 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1371 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1374 AdjustForParentClientOrigin( x
, y
) ;
1376 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1377 if ( !GetParent()->IsTopLevel() )
1379 x
-= GetParent()->MacGetLeftBorderSize() ;
1380 y
-= GetParent()->MacGetTopBorderSize() ;
1386 // Get window size (not client size)
1387 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1390 m_peer
->GetRect( &bounds
) ;
1393 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1395 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1398 // get the position of the bounds of this window in client coordinates of its parent
1399 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1402 m_peer
->GetRect( &bounds
) ;
1404 int x1
= bounds
.left
;
1405 int y1
= bounds
.top
;
1407 // get the wx window position from the native one
1408 x1
-= MacGetLeftBorderSize() ;
1409 y1
-= MacGetTopBorderSize() ;
1411 if ( !IsTopLevel() )
1413 wxWindow
*parent
= GetParent();
1416 // we must first adjust it to be in window coordinates of the parent,
1417 // as otherwise it gets lost by the ClientAreaOrigin fix
1418 x1
+= parent
->MacGetLeftBorderSize() ;
1419 y1
+= parent
->MacGetTopBorderSize() ;
1421 // and now to client coordinates
1422 wxPoint
pt(parent
->GetClientAreaOrigin());
1434 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1436 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1437 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1439 Point localwhere
= { 0, 0 } ;
1446 wxMacGlobalToLocal( window
, &localwhere
) ;
1453 MacRootWindowToWindow( x
, y
) ;
1455 wxPoint origin
= GetClientAreaOrigin() ;
1462 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1464 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1465 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1467 wxPoint origin
= GetClientAreaOrigin() ;
1473 MacWindowToRootWindow( x
, y
) ;
1475 Point localwhere
= { 0, 0 };
1481 wxMacLocalToGlobal( window
, &localwhere
) ;
1489 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1491 wxPoint origin
= GetClientAreaOrigin() ;
1497 MacWindowToRootWindow( x
, y
) ;
1500 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1502 MacRootWindowToWindow( x
, y
) ;
1504 wxPoint origin
= GetClientAreaOrigin() ;
1511 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1520 if ( !IsTopLevel() )
1522 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1525 pt
.x
-= MacGetLeftBorderSize() ;
1526 pt
.y
-= MacGetTopBorderSize() ;
1527 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1537 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1546 MacWindowToRootWindow( &x1
, &y1
) ;
1554 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1563 if ( !IsTopLevel() )
1565 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1568 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1569 pt
.x
+= MacGetLeftBorderSize() ;
1570 pt
.y
+= MacGetTopBorderSize() ;
1580 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1589 MacRootWindowToWindow( &x1
, &y1
) ;
1597 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1599 RgnHandle rgn
= NewRgn() ;
1601 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1603 Rect structure
, content
;
1605 GetRegionBounds( rgn
, &content
) ;
1606 m_peer
->GetRect( &structure
) ;
1607 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1609 left
= content
.left
- structure
.left
;
1610 top
= content
.top
- structure
.top
;
1611 right
= structure
.right
- content
.right
;
1612 bottom
= structure
.bottom
- content
.bottom
;
1616 left
= top
= right
= bottom
= 0 ;
1622 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1624 wxSize sizeTotal
= size
;
1626 RgnHandle rgn
= NewRgn() ;
1627 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1629 Rect content
, structure
;
1630 GetRegionBounds( rgn
, &content
) ;
1631 m_peer
->GetRect( &structure
) ;
1633 // structure is in parent coordinates, but we only need width and height, so it's ok
1635 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1636 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1641 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1642 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1647 // Get size *available for subwindows* i.e. excluding menu bar etc.
1648 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1652 RgnHandle rgn
= NewRgn() ;
1654 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1655 GetRegionBounds( rgn
, &content
) ;
1657 m_peer
->GetRect( &content
) ;
1660 ww
= content
.right
- content
.left
;
1661 hh
= content
.bottom
- content
.top
;
1663 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1664 hh
-= m_hScrollBar
->GetSize().y
;
1666 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1667 ww
-= m_vScrollBar
->GetSize().x
;
1675 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1677 if (m_cursor
.IsSameAs(cursor
))
1682 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1687 if ( ! wxWindowBase::SetCursor( cursor
) )
1691 wxASSERT_MSG( m_cursor
.Ok(),
1692 wxT("cursor must be valid after call to the base version"));
1694 wxWindowMac
*mouseWin
= 0 ;
1696 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1697 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1699 ControlPartCode part
;
1700 ControlRef control
;
1702 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1704 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1709 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1711 // TODO: If we ever get a GetCurrentEvent... replacement
1712 // for the mouse position, use it...
1717 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1719 mouseWin
= wxFindControlFromMacControl( control
) ;
1721 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1723 QDSwapPort( savePort
, NULL
) ;
1727 if ( mouseWin
== this && !wxIsBusy() )
1728 m_cursor
.MacInstall() ;
1734 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1736 menu
->SetInvokingWindow(this);
1739 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1741 wxPoint mouse
= wxGetMousePosition();
1747 ClientToScreen( &x
, &y
) ;
1750 menu
->MacBeforeDisplay( true ) ;
1751 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1752 if ( HiWord(menuResult
) != 0 )
1755 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1756 int id
= wxMacCommandToId( macid
);
1757 wxMenuItem
* item
= NULL
;
1759 item
= menu
->FindItem( id
, &realmenu
) ;
1762 if (item
->IsCheckable())
1763 item
->Check( !item
->IsChecked() ) ;
1765 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1769 menu
->MacAfterDisplay( true ) ;
1770 menu
->SetInvokingWindow( NULL
);
1776 // ----------------------------------------------------------------------------
1778 // ----------------------------------------------------------------------------
1782 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1784 wxWindowBase::DoSetToolTip(tooltip
);
1787 m_tooltip
->SetWindow(this);
1792 void wxWindowMac::MacInvalidateBorders()
1794 if ( m_peer
== NULL
)
1797 bool vis
= MacIsReallyShown() ;
1801 int outerBorder
= MacGetLeftBorderSize() ;
1802 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1805 if ( outerBorder
== 0 )
1808 // now we know that we have something to do at all
1810 // as the borders are drawn on the parent we have to properly invalidate all these areas
1811 RgnHandle updateInner
, updateOuter
;
1814 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1815 updateInner
= NewRgn() ;
1816 updateOuter
= NewRgn() ;
1818 m_peer
->GetRect( &rect
) ;
1819 RectRgn( updateInner
, &rect
) ;
1820 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1821 RectRgn( updateOuter
, &rect
) ;
1822 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1824 #ifdef __WXMAC_OSX__
1825 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1827 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1829 InvalWindowRgn( tlw
, updateOuter
) ;
1832 DisposeRgn( updateOuter
) ;
1833 DisposeRgn( updateInner
) ;
1836 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1838 // this is never called for a toplevel window, so we know we have a parent
1839 int former_x
, former_y
, former_w
, former_h
;
1841 // Get true coordinates of former position
1842 DoGetPosition( &former_x
, &former_y
) ;
1843 DoGetSize( &former_w
, &former_h
) ;
1845 wxWindow
*parent
= GetParent();
1848 wxPoint
pt(parent
->GetClientAreaOrigin());
1853 int actualWidth
= width
;
1854 int actualHeight
= height
;
1858 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1859 actualWidth
= m_minWidth
;
1860 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1861 actualHeight
= m_minHeight
;
1862 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1863 actualWidth
= m_maxWidth
;
1864 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1865 actualHeight
= m_maxHeight
;
1867 bool doMove
= false, doResize
= false ;
1869 if ( actualX
!= former_x
|| actualY
!= former_y
)
1872 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1875 if ( doMove
|| doResize
)
1877 // as the borders are drawn outside the native control, we adjust now
1879 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1880 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1881 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1884 wxMacRectToNative( &bounds
, &r
) ;
1886 if ( !GetParent()->IsTopLevel() )
1887 wxMacWindowToNative( GetParent() , &r
) ;
1889 MacInvalidateBorders() ;
1891 m_cachedClippedRectValid
= false ;
1892 m_peer
->SetRect( &r
) ;
1894 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1896 MacInvalidateBorders() ;
1898 MacRepositionScrollBars() ;
1901 wxPoint
point(actualX
, actualY
);
1902 wxMoveEvent
event(point
, m_windowId
);
1903 event
.SetEventObject(this);
1904 GetEventHandler()->ProcessEvent(event
) ;
1909 MacRepositionScrollBars() ;
1910 wxSize
size(actualWidth
, actualHeight
);
1911 wxSizeEvent
event(size
, m_windowId
);
1912 event
.SetEventObject(this);
1913 GetEventHandler()->ProcessEvent(event
);
1918 wxSize
wxWindowMac::DoGetBestSize() const
1920 if ( m_macIsUserPane
|| IsTopLevel() )
1921 return wxWindowBase::DoGetBestSize() ;
1923 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1924 int bestWidth
, bestHeight
;
1926 m_peer
->GetBestRect( &bestsize
) ;
1927 if ( EmptyRect( &bestsize
) )
1932 bestsize
.bottom
= 16 ;
1934 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1936 bestsize
.bottom
= 16 ;
1939 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1941 bestsize
.bottom
= 24 ;
1946 // return wxWindowBase::DoGetBestSize() ;
1950 bestWidth
= bestsize
.right
- bestsize
.left
;
1951 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1952 if ( bestHeight
< 10 )
1955 return wxSize(bestWidth
, bestHeight
);
1958 // set the size of the window: if the dimensions are positive, just use them,
1959 // but if any of them is equal to -1, it means that we must find the value for
1960 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1961 // which case -1 is a valid value for x and y)
1963 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1964 // the width/height to best suit our contents, otherwise we reuse the current
1966 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1968 // get the current size and position...
1969 int currentX
, currentY
;
1970 int currentW
, currentH
;
1972 GetPosition(¤tX
, ¤tY
);
1973 GetSize(¤tW
, ¤tH
);
1975 // ... and don't do anything (avoiding flicker) if it's already ok
1976 if ( x
== currentX
&& y
== currentY
&&
1977 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1980 MacRepositionScrollBars() ; // we might have a real position shift
1985 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1987 if ( x
== wxDefaultCoord
)
1989 if ( y
== wxDefaultCoord
)
1993 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1995 wxSize size
= wxDefaultSize
;
1996 if ( width
== wxDefaultCoord
)
1998 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2000 size
= DoGetBestSize();
2005 // just take the current one
2010 if ( height
== wxDefaultCoord
)
2012 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2014 if ( size
.x
== wxDefaultCoord
)
2015 size
= DoGetBestSize();
2016 // else: already called DoGetBestSize() above
2022 // just take the current one
2027 DoMoveWindow( x
, y
, width
, height
);
2030 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2032 RgnHandle rgn
= NewRgn() ;
2034 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2036 GetRegionBounds( rgn
, &content
) ;
2046 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2049 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2051 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2053 int currentclientwidth
, currentclientheight
;
2054 int currentwidth
, currentheight
;
2056 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2057 GetSize( ¤twidth
, ¤theight
) ;
2059 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2060 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2064 void wxWindowMac::SetLabel(const wxString
& title
)
2066 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2068 if ( m_peer
&& m_peer
->Ok() )
2069 m_peer
->SetLabel( m_label
) ;
2074 wxString
wxWindowMac::GetLabel() const
2079 bool wxWindowMac::Show(bool show
)
2081 bool former
= MacIsReallyShown() ;
2082 if ( !wxWindowBase::Show(show
) )
2085 // TODO: use visibilityChanged Carbon Event for OSX
2087 m_peer
->SetVisibility( show
, true ) ;
2089 if ( former
!= MacIsReallyShown() )
2090 MacPropagateVisibilityChanged() ;
2095 bool wxWindowMac::Enable(bool enable
)
2097 wxASSERT( m_peer
->Ok() ) ;
2098 bool former
= MacIsReallyEnabled() ;
2099 if ( !wxWindowBase::Enable(enable
) )
2102 m_peer
->Enable( enable
) ;
2104 if ( former
!= MacIsReallyEnabled() )
2105 MacPropagateEnabledStateChanged() ;
2111 // status change propagations (will be not necessary for OSX later )
2114 void wxWindowMac::MacPropagateVisibilityChanged()
2116 #if !TARGET_API_MAC_OSX
2117 MacVisibilityChanged() ;
2120 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2123 child
= node
->GetData();
2124 if ( child
->IsShown() )
2125 child
->MacPropagateVisibilityChanged() ;
2127 node
= node
->GetNext();
2132 void wxWindowMac::MacPropagateEnabledStateChanged()
2134 #if !TARGET_API_MAC_OSX
2135 MacEnabledStateChanged() ;
2138 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2141 child
= node
->GetData();
2142 if ( child
->IsEnabled() )
2143 child
->MacPropagateEnabledStateChanged() ;
2145 node
= node
->GetNext();
2150 void wxWindowMac::MacPropagateHiliteChanged()
2152 #if !TARGET_API_MAC_OSX
2153 MacHiliteChanged() ;
2156 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2159 child
= node
->GetData();
2160 if (child
/* && child->IsEnabled() */)
2161 child
->MacPropagateHiliteChanged() ;
2163 node
= node
->GetNext();
2169 // status change notifications
2172 void wxWindowMac::MacVisibilityChanged()
2176 void wxWindowMac::MacHiliteChanged()
2180 void wxWindowMac::MacEnabledStateChanged()
2185 // status queries on the inherited window's state
2188 bool wxWindowMac::MacIsReallyShown()
2190 // only under OSX the visibility of the TLW is taken into account
2191 if ( m_isBeingDeleted
)
2194 #if TARGET_API_MAC_OSX
2195 if ( m_peer
&& m_peer
->Ok() )
2196 return m_peer
->IsVisible();
2199 wxWindow
* win
= this ;
2200 while ( win
->IsShown() )
2202 if ( win
->IsTopLevel() )
2205 win
= win
->GetParent() ;
2213 bool wxWindowMac::MacIsReallyEnabled()
2215 return m_peer
->IsEnabled() ;
2218 bool wxWindowMac::MacIsReallyHilited()
2220 return m_peer
->IsActive();
2223 void wxWindowMac::MacFlashInvalidAreas()
2225 #if TARGET_API_MAC_OSX
2226 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2230 int wxWindowMac::GetCharHeight() const
2232 wxClientDC
dc( (wxWindowMac
*)this ) ;
2234 return dc
.GetCharHeight() ;
2237 int wxWindowMac::GetCharWidth() const
2239 wxClientDC
dc( (wxWindowMac
*)this ) ;
2241 return dc
.GetCharWidth() ;
2244 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2245 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2247 const wxFont
*fontToUse
= theFont
;
2249 fontToUse
= &m_font
;
2251 wxClientDC
dc( (wxWindowMac
*) this ) ;
2253 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2254 if ( externalLeading
)
2255 *externalLeading
= le
;
2265 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2266 * we always intersect with the entire window, not only with the client area
2269 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2271 if ( m_peer
== NULL
)
2274 if ( !MacIsReallyShown() )
2281 wxMacRectToNative( rect
, &r
) ;
2282 m_peer
->SetNeedsDisplay( &r
) ;
2286 m_peer
->SetNeedsDisplay() ;
2290 void wxWindowMac::Freeze()
2292 #if TARGET_API_MAC_OSX
2293 if ( !m_frozenness
++ )
2295 if ( m_peer
&& m_peer
->Ok() )
2296 m_peer
->SetDrawingEnabled( false ) ;
2301 void wxWindowMac::Thaw()
2303 #if TARGET_API_MAC_OSX
2304 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2306 if ( !--m_frozenness
)
2308 if ( m_peer
&& m_peer
->Ok() )
2310 m_peer
->SetDrawingEnabled( true ) ;
2311 m_peer
->InvalidateWithChildren() ;
2317 bool wxWindowMac::IsFrozen() const
2319 return m_frozenness
!= 0;
2322 wxWindowMac
*wxGetActiveWindow()
2324 // actually this is a windows-only concept
2328 // Coordinates relative to the window
2329 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2331 // We really don't move the mouse programmatically under Mac.
2334 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2336 if ( MacGetTopLevelWindow() == NULL
)
2339 #if TARGET_API_MAC_OSX
2340 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2347 event
.GetDC()->Clear() ;
2351 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2356 int wxWindowMac::GetScrollPos(int orient
) const
2358 if ( orient
== wxHORIZONTAL
)
2361 return m_hScrollBar
->GetThumbPosition() ;
2366 return m_vScrollBar
->GetThumbPosition() ;
2372 // This now returns the whole range, not just the number
2373 // of positions that we can scroll.
2374 int wxWindowMac::GetScrollRange(int orient
) const
2376 if ( orient
== wxHORIZONTAL
)
2379 return m_hScrollBar
->GetRange() ;
2384 return m_vScrollBar
->GetRange() ;
2390 int wxWindowMac::GetScrollThumb(int orient
) const
2392 if ( orient
== wxHORIZONTAL
)
2395 return m_hScrollBar
->GetThumbSize() ;
2400 return m_vScrollBar
->GetThumbSize() ;
2406 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2408 if ( orient
== wxHORIZONTAL
)
2411 m_hScrollBar
->SetThumbPosition( pos
) ;
2416 m_vScrollBar
->SetThumbPosition( pos
) ;
2421 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2422 // our own window origin is at leftOrigin/rightOrigin
2425 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2431 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2432 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2434 // back to the surrounding frame rectangle
2435 m_peer
->GetRect( &rect
) ;
2436 InsetRect( &rect
, -1 , -1 ) ;
2438 #if wxMAC_USE_CORE_GRAPHICS
2440 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2441 rect
.bottom
- rect
.top
) ;
2443 HIThemeFrameDrawInfo info
;
2444 memset( &info
, 0 , sizeof(info
) ) ;
2448 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2449 info
.isFocused
= hasFocus
;
2451 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2452 wxASSERT( cgContext
) ;
2454 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2456 info
.kind
= kHIThemeFrameTextFieldSquare
;
2457 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2459 else if ( HasFlag(wxSIMPLE_BORDER
) )
2461 info
.kind
= kHIThemeFrameListBox
;
2462 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2464 else if ( hasFocus
)
2466 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2469 m_peer
->GetRect( &rect
) ;
2470 if ( hasBothScrollbars
)
2472 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2473 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2474 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2475 HIThemeGrowBoxDrawInfo info
;
2476 memset( &info
, 0, sizeof(info
) ) ;
2478 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2479 info
.kind
= kHIThemeGrowBoxKindNone
;
2480 info
.size
= kHIThemeGrowBoxSizeNormal
;
2481 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2482 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2487 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2491 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2492 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2495 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2496 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2497 else if ( HasFlag(wxSIMPLE_BORDER
) )
2498 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2501 DrawThemeFocusRect( &rect
, true ) ;
2503 if ( hasBothScrollbars
)
2505 // GetThemeStandaloneGrowBoxBounds
2506 // DrawThemeStandaloneNoGrowBox
2512 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2514 if ( child
== m_hScrollBar
)
2515 m_hScrollBar
= NULL
;
2516 if ( child
== m_vScrollBar
)
2517 m_vScrollBar
= NULL
;
2519 wxWindowBase::RemoveChild( child
) ;
2522 // New function that will replace some of the above.
2523 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2524 int range
, bool refresh
)
2527 bool triggerSizeEvent
= false;
2529 if ( orient
== wxHORIZONTAL
)
2533 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2534 if ( m_hScrollBar
->IsShown() != showScroller
)
2536 m_hScrollBar
->Show( showScroller
);
2537 triggerSizeEvent
= true;
2540 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2547 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2548 if ( m_vScrollBar
->IsShown() != showScroller
)
2550 m_vScrollBar
->Show( showScroller
) ;
2551 triggerSizeEvent
= true;
2554 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2558 MacRepositionScrollBars() ;
2559 if ( triggerSizeEvent
)
2561 wxSizeEvent
event(GetSize(), m_windowId
);
2562 event
.SetEventObject(this);
2563 GetEventHandler()->ProcessEvent(event
);
2567 // Does a physical scroll
2568 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2570 if ( dx
== 0 && dy
== 0 )
2573 int width
, height
;
2574 GetClientSize( &width
, &height
) ;
2577 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2578 // area is scrolled, this does not occur if width and height are 2 pixels less,
2579 // TODO: write optimal workaround
2580 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2582 scrollrect
.Intersect( *rect
) ;
2584 if ( m_peer
->GetNeedsDisplay() )
2586 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2587 // either immediate redraw or full invalidate
2589 // is the better overall solution, as it does not slow down scrolling
2590 m_peer
->SetNeedsDisplay() ;
2592 // this would be the preferred version for fast drawing controls
2594 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2595 if ( UMAGetSystemVersion() >= 0x1030 )
2596 HIViewRender(m_peer
->GetControlRef()) ;
2603 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2604 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2605 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2607 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2608 // either immediate redraw or full invalidate
2610 // is the better overall solution, as it does not slow down scrolling
2611 m_peer
->SetNeedsDisplay() ;
2613 // this would be the preferred version for fast drawing controls
2615 HIViewRender(m_peer
->GetControlRef()) ;
2621 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2623 child
= node
->GetData();
2626 if (child
== m_vScrollBar
)
2628 if (child
== m_hScrollBar
)
2630 if (child
->IsTopLevel())
2633 child
->GetPosition( &x
, &y
);
2634 child
->GetSize( &w
, &h
);
2637 wxRect
rc( x
, y
, w
, h
);
2638 if (rect
->Intersects( rc
))
2639 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2643 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2648 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2650 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2652 wxScrollWinEvent wevent
;
2653 wevent
.SetPosition(event
.GetPosition());
2654 wevent
.SetOrientation(event
.GetOrientation());
2655 wevent
.SetEventObject(this);
2657 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2658 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2659 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2660 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2661 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2662 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2663 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2664 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2665 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2666 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2667 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2668 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2669 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2670 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2671 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2672 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2674 GetEventHandler()->ProcessEvent(wevent
);
2678 // Get the window with the focus
2679 wxWindowMac
*wxWindowBase::DoFindFocus()
2681 ControlRef control
;
2682 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2683 return wxFindControlFromMacControl( control
) ;
2686 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2688 // panel wants to track the window which was the last to have focus in it,
2689 // so we want to set ourselves as the window which last had focus
2691 // notice that it's also important to do it upwards the tree because
2692 // otherwise when the top level panel gets focus, it won't set it back to
2693 // us, but to some other sibling
2695 // CS: don't know if this is still needed:
2696 //wxChildFocusEvent eventFocus(this);
2697 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2699 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2701 #if wxMAC_USE_CORE_GRAPHICS
2702 GetParent()->Refresh() ;
2704 wxMacWindowStateSaver
sv( this ) ;
2707 m_peer
->GetRect( &rect
) ;
2708 // auf den umgebenden Rahmen zur\9fck
2709 InsetRect( &rect
, -1 , -1 ) ;
2711 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2715 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2717 rect
.right
+= pt
.x
;
2719 rect
.bottom
+= pt
.y
;
2722 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2723 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2724 if ( !bIsFocusEvent
)
2726 // as this erases part of the frame we have to redraw borders
2727 // and because our z-ordering is not always correct (staticboxes)
2728 // we have to invalidate things, we cannot simple redraw
2729 MacInvalidateBorders() ;
2737 void wxWindowMac::OnInternalIdle()
2739 // This calls the UI-update mechanism (querying windows for
2740 // menu/toolbar/control state information)
2741 if (wxUpdateUIEvent::CanUpdate(this))
2742 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2745 // Raise the window to the top of the Z order
2746 void wxWindowMac::Raise()
2748 m_peer
->SetZOrder( true , NULL
) ;
2751 // Lower the window to the bottom of the Z order
2752 void wxWindowMac::Lower()
2754 m_peer
->SetZOrder( false , NULL
) ;
2757 // static wxWindow *gs_lastWhich = NULL;
2759 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2761 // first trigger a set cursor event
2763 wxPoint clientorigin
= GetClientAreaOrigin() ;
2764 wxSize clientsize
= GetClientSize() ;
2766 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2768 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2770 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2771 if ( processedEvtSetCursor
&& event
.HasCursor() )
2773 cursor
= event
.GetCursor() ;
2777 // the test for processedEvtSetCursor is here to prevent using m_cursor
2778 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2779 // it - this is a way to say that our cursor shouldn't be used for this
2781 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2784 if ( !wxIsBusy() && !GetParent() )
2785 cursor
= *wxSTANDARD_CURSOR
;
2789 cursor
.MacInstall() ;
2792 return cursor
.Ok() ;
2795 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2799 return m_tooltip
->GetTip() ;
2802 return wxEmptyString
;
2805 void wxWindowMac::ClearBackground()
2811 void wxWindowMac::Update()
2813 #if TARGET_API_MAC_OSX
2814 MacGetTopLevelWindow()->MacPerformUpdates() ;
2816 ::Draw1Control( m_peer
->GetControlRef() ) ;
2820 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2822 wxTopLevelWindowMac
* win
= NULL
;
2823 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2825 win
= wxFindWinFromMacWindow( window
) ;
2830 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2832 MacUpdateClippedRects() ;
2834 return m_cachedClippedClientRect
;
2837 const wxRect
& wxWindowMac::MacGetClippedRect() const
2839 MacUpdateClippedRects() ;
2841 return m_cachedClippedRect
;
2844 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2846 MacUpdateClippedRects() ;
2848 return m_cachedClippedRectWithOuterStructure
;
2851 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2853 static wxRegion emptyrgn
;
2855 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2857 MacUpdateClippedRects() ;
2858 if ( includeOuterStructures
)
2859 return m_cachedClippedRegionWithOuterStructure
;
2861 return m_cachedClippedRegion
;
2869 void wxWindowMac::MacUpdateClippedRects() const
2871 if ( m_cachedClippedRectValid
)
2874 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2875 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2876 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2877 // to add focus borders everywhere
2879 Rect r
, rIncludingOuterStructures
;
2881 m_peer
->GetRect( &r
) ;
2882 r
.left
-= MacGetLeftBorderSize() ;
2883 r
.top
-= MacGetTopBorderSize() ;
2884 r
.bottom
+= MacGetBottomBorderSize() ;
2885 r
.right
+= MacGetRightBorderSize() ;
2892 rIncludingOuterStructures
= r
;
2893 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2895 wxRect cl
= GetClientRect() ;
2896 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2900 const wxWindow
* child
= this ;
2901 const wxWindow
* parent
= NULL
;
2903 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2905 if ( parent
->MacIsChildOfClientArea(child
) )
2907 size
= parent
->GetClientSize() ;
2908 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2914 // this will be true for scrollbars, toolbars etc.
2915 size
= parent
->GetSize() ;
2916 y
= parent
->MacGetTopBorderSize() ;
2917 x
= parent
->MacGetLeftBorderSize() ;
2918 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2919 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2922 parent
->MacWindowToRootWindow( &x
, &y
) ;
2923 MacRootWindowToWindow( &x
, &y
) ;
2925 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2927 // the wxwindow and client rects will always be clipped
2928 SectRect( &r
, &rparent
, &r
) ;
2929 SectRect( &rClient
, &rparent
, &rClient
) ;
2931 // the structure only at 'hard' borders
2932 if ( parent
->MacClipChildren() ||
2933 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2935 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2941 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2942 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2943 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2944 m_cachedClippedRectWithOuterStructure
= wxRect(
2945 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2946 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2947 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2949 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2950 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2951 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2953 m_cachedClippedRectValid
= true ;
2957 This function must not change the updatergn !
2959 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2961 bool handled
= false ;
2963 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2964 GetRegionBounds( updatergn
, &updatebounds
) ;
2966 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2968 if ( !EmptyRgn(updatergn
) )
2970 RgnHandle newupdate
= NewRgn() ;
2971 wxSize point
= GetClientSize() ;
2972 wxPoint origin
= GetClientAreaOrigin() ;
2973 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2974 SectRgn( newupdate
, updatergn
, newupdate
) ;
2976 // first send an erase event to the entire update area
2978 // for the toplevel window this really is the entire area
2979 // for all the others only their client area, otherwise they
2980 // might be drawing with full alpha and eg put blue into
2981 // the grow-box area of a scrolled window (scroll sample)
2982 wxDC
* dc
= new wxWindowDC(this);
2984 dc
->SetClippingRegion(wxRegion(updatergn
));
2986 dc
->SetClippingRegion(wxRegion(newupdate
));
2988 wxEraseEvent
eevent( GetId(), dc
);
2989 eevent
.SetEventObject( this );
2990 GetEventHandler()->ProcessEvent( eevent
);
2994 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2995 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2996 m_updateRegion
= newupdate
;
2997 DisposeRgn( newupdate
) ;
2999 if ( !m_updateRegion
.Empty() )
3001 // paint the window itself
3004 event
.SetTimestamp(time
);
3005 event
.SetEventObject(this);
3006 GetEventHandler()->ProcessEvent(event
);
3010 // now we cannot rely on having its borders drawn by a window itself, as it does not
3011 // get the updateRgn wide enough to always do so, so we do it from the parent
3012 // this would also be the place to draw any custom backgrounds for native controls
3013 // in Composited windowing
3014 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3018 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3020 child
= node
->GetData();
3023 if (child
== m_vScrollBar
)
3025 if (child
== m_hScrollBar
)
3027 if (child
->IsTopLevel())
3029 if (!child
->IsShown())
3032 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3034 child
->GetPosition( &x
, &y
);
3035 child
->GetSize( &w
, &h
);
3036 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3037 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3038 InsetRect( &childRect
, -10 , -10) ;
3040 if ( RectInRgn( &childRect
, updatergn
) )
3042 // paint custom borders
3043 wxNcPaintEvent
eventNc( child
->GetId() );
3044 eventNc
.SetEventObject( child
);
3045 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3047 #if wxMAC_USE_CORE_GRAPHICS
3048 child
->MacPaintBorders(0, 0) ;
3051 wxWindowDC
dc(this) ;
3052 dc
.SetClippingRegion(wxRegion(updatergn
));
3053 wxMacPortSetter
helper(&dc
) ;
3054 child
->MacPaintBorders(0, 0) ;
3066 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3068 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3072 if ( iter
->IsTopLevel() )
3073 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3075 iter
= iter
->GetParent() ;
3081 void wxWindowMac::MacCreateScrollBars( long style
)
3083 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3085 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3087 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3088 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3089 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3091 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3094 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3096 GetClientSize( &width
, &height
) ;
3098 wxPoint
vPoint(width
- scrlsize
, 0) ;
3099 wxSize
vSize(scrlsize
, height
- adjust
) ;
3100 wxPoint
hPoint(0, height
- scrlsize
) ;
3101 wxSize
hSize(width
- adjust
, scrlsize
) ;
3103 if ( style
& wxVSCROLL
)
3104 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3106 if ( style
& wxHSCROLL
)
3107 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3110 // because the create does not take into account the client area origin
3111 // we might have a real position shift
3112 MacRepositionScrollBars() ;
3115 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3117 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3122 void wxWindowMac::MacRepositionScrollBars()
3124 if ( !m_hScrollBar
&& !m_vScrollBar
)
3127 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3128 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3129 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3131 // get real client area
3133 GetSize( &width
, &height
);
3135 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3136 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3138 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3139 wxSize
vSize( scrlsize
, height
- adjust
) ;
3140 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3141 wxSize
hSize( width
- adjust
, scrlsize
) ;
3144 int x
= 0, y
= 0, w
, h
;
3145 GetSize( &w
, &h
) ;
3147 MacClientToRootWindow( &x
, &y
) ;
3148 MacClientToRootWindow( &w
, &h
) ;
3150 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3152 int totW
= 10000 , totH
= 10000;
3155 if ( iter
->IsTopLevel() )
3157 iter
->GetSize( &totW
, &totH
) ;
3161 iter
= iter
->GetParent() ;
3175 if ( w
- x
>= totW
)
3180 if ( h
- y
>= totH
)
3188 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3190 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3193 bool wxWindowMac::AcceptsFocus() const
3195 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3198 void wxWindowMac::MacSuperChangedPosition()
3200 // only window-absolute structures have to be moved i.e. controls
3202 m_cachedClippedRectValid
= false ;
3205 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3208 child
= node
->GetData();
3209 child
->MacSuperChangedPosition() ;
3211 node
= node
->GetNext();
3215 void wxWindowMac::MacTopLevelWindowChangedPosition()
3217 // only screen-absolute structures have to be moved i.e. glcanvas
3220 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3223 child
= node
->GetData();
3224 child
->MacTopLevelWindowChangedPosition() ;
3226 node
= node
->GetNext();
3230 long wxWindowMac::MacGetLeftBorderSize() const
3237 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3239 // this metric is only the 'outset' outside the simple frame rect
3240 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3243 else if (HasFlag(wxSIMPLE_BORDER
))
3245 // this metric is only the 'outset' outside the simple frame rect
3246 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3253 long wxWindowMac::MacGetRightBorderSize() const
3255 // they are all symmetric in mac themes
3256 return MacGetLeftBorderSize() ;
3259 long wxWindowMac::MacGetTopBorderSize() const
3261 // they are all symmetric in mac themes
3262 return MacGetLeftBorderSize() ;
3265 long wxWindowMac::MacGetBottomBorderSize() const
3267 // they are all symmetric in mac themes
3268 return MacGetLeftBorderSize() ;
3271 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3273 return style
& ~wxBORDER_MASK
;
3276 // Find the wxWindowMac at the current mouse position, returning the mouse
3278 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3280 pt
= wxGetMousePosition();
3281 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3286 // Get the current mouse position.
3287 wxPoint
wxGetMousePosition()
3291 wxGetMousePosition( &x
, &y
);
3293 return wxPoint(x
, y
);
3296 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3298 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3300 // copied from wxGTK : CS
3301 // VZ: shouldn't we move this to base class then?
3303 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3306 // (a) it's a command event and so is propagated to the parent
3307 // (b) under MSW it can be generated from kbd too
3308 // (c) it uses screen coords (because of (a))
3309 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3311 this->ClientToScreen(event
.GetPosition()));
3312 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3321 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3323 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3324 CallNextEventHandler(
3325 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3326 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3329 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3333 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3337 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3338 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3343 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3345 return eventNotHandledErr
;
3348 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3350 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3351 if ( !wxWindowBase::Reparent(newParent
) )
3354 // copied from MacPostControlCreate
3355 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3357 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3359 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3364 bool wxWindowMac::SetTransparent(wxByte alpha
)
3366 #if wxMAC_USE_CORE_GRAPHICS
3367 if ( alpha
!= m_macAlpha
)
3369 m_macAlpha
= alpha
;
3379 bool wxWindowMac::CanSetTransparent()
3381 #if wxMAC_USE_CORE_GRAPHICS
3388 wxByte
wxWindowMac::GetTransparent() const