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
, kEventControlHit
} ,
161 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
162 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
164 { kEventClassControl
, kEventControlDraw
} ,
165 #if TARGET_API_MAC_OSX
166 { kEventClassControl
, kEventControlVisibilityChanged
} ,
167 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
168 { kEventClassControl
, kEventControlHiliteChanged
} ,
170 { kEventClassControl
, kEventControlSetFocusPart
} ,
172 { kEventClassService
, kEventServiceGetTypes
},
173 { kEventClassService
, kEventServiceCopy
},
174 { kEventClassService
, kEventServicePaste
},
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177 // { kEventClassControl , kEventControlBoundsChanged } ,
180 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
182 OSStatus result
= eventNotHandledErr
;
184 wxMacCarbonEvent
cEvent( event
) ;
186 ControlRef controlRef
;
187 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
189 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
191 switch ( GetEventKind( event
) )
193 #if TARGET_API_MAC_OSX
194 case kEventControlDraw
:
196 RgnHandle updateRgn
= NULL
;
197 RgnHandle allocatedRgn
= NULL
;
198 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
200 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
202 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
206 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
208 // as this update region is in native window locals we must adapt it to wx window local
209 allocatedRgn
= NewRgn() ;
210 CopyRgn( updateRgn
, allocatedRgn
) ;
212 // hide the given region by the new region that must be shifted
213 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
214 updateRgn
= allocatedRgn
;
219 GetRegionBounds( updateRgn
, &rgnBounds
) ;
221 #if wxMAC_DEBUG_REDRAW
222 if ( thisWindow
->MacIsUserPane() )
224 static float color
= 0.5 ;
227 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
245 #if wxMAC_USE_CORE_GRAPHICS
246 bool created
= false ;
247 CGContextRef cgContext
= NULL
;
248 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
249 wxASSERT_MSG( err
== noErr
, wxT("Unable to retrieve CGContextRef") ) ;
250 thisWindow
->MacSetCGContextRef( cgContext
) ;
253 wxMacCGContextStateSaver
sg( cgContext
) ;
254 // make sure the context is having its origin at the wx-window coordinates of the
255 // view (read at the top of this file about the differences)
256 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
257 CGContextTranslateCTM( cgContext
, -thisWindow
->MacGetLeftBorderSize() , -thisWindow
->MacGetTopBorderSize() );
260 wxWindow
* iter
= thisWindow
;
263 alpha
*= (float) iter
->GetTransparent()/255.0 ;
264 if ( iter
->IsTopLevel() )
267 iter
= iter
->GetParent() ;
270 CGContextSetAlpha( cgContext
, alpha
) ;
272 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
275 #if wxMAC_USE_CORE_GRAPHICS
276 thisWindow
->MacSetCGContextRef( NULL
) ;
280 CGContextRelease( cgContext
) ;
285 DisposeRgn( allocatedRgn
) ;
289 case kEventControlVisibilityChanged
:
290 thisWindow
->MacVisibilityChanged() ;
293 case kEventControlEnabledStateChanged
:
294 thisWindow
->MacEnabledStateChanged() ;
297 case kEventControlHiliteChanged
:
298 thisWindow
->MacHiliteChanged() ;
302 // we emulate this event under Carbon CFM
303 case kEventControlSetFocusPart
:
305 Boolean focusEverything
= false ;
306 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
309 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
314 if ( controlPart
== kControlFocusNoPart
)
317 if ( thisWindow
->GetCaret() )
318 thisWindow
->GetCaret()->OnKillFocus();
321 static bool inKillFocusEvent
= false ;
323 if ( !inKillFocusEvent
)
325 inKillFocusEvent
= true ;
326 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
327 event
.SetEventObject(thisWindow
);
328 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
329 inKillFocusEvent
= false ;
334 // panel wants to track the window which was the last to have focus in it
335 wxChildFocusEvent
eventFocus(thisWindow
);
336 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
339 if ( thisWindow
->GetCaret() )
340 thisWindow
->GetCaret()->OnSetFocus();
343 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
344 event
.SetEventObject(thisWindow
);
345 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
348 if ( thisWindow
->MacIsUserPane() )
353 case kEventControlHit
:
354 result
= thisWindow
->MacControlHit( handler
, event
) ;
364 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
366 OSStatus result
= eventNotHandledErr
;
368 wxMacCarbonEvent
cEvent( event
) ;
370 ControlRef controlRef
;
371 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
372 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
373 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
375 switch ( GetEventKind( event
) )
377 case kEventServiceGetTypes
:
381 textCtrl
->GetSelection( &from
, &to
) ;
383 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
385 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
386 if ( textCtrl
->IsEditable() )
387 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
389 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
390 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
392 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
396 CFArrayAppendValue(copyTypes
, typestring
) ;
398 CFArrayAppendValue(pasteTypes
, typestring
) ;
400 CFRelease( typestring
) ;
408 case kEventServiceCopy
:
413 textCtrl
->GetSelection( &from
, &to
) ;
414 wxString val
= textCtrl
->GetValue() ;
415 val
= val
.Mid( from
, to
- from
) ;
416 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
417 verify_noerr( ClearScrap( &scrapRef
) ) ;
418 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
423 case kEventServicePaste
:
426 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
427 Size textSize
, pastedSize
;
428 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
430 char *content
= new char[textSize
] ;
431 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
432 content
[textSize
- 1] = 0 ;
435 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
437 textCtrl
->WriteText( wxString( content
) ) ;
452 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
454 OSStatus result
= eventNotHandledErr
;
455 wxWindowMac
* focus
= (wxWindowMac
*) data
;
457 wchar_t* uniChars
= NULL
;
458 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
460 UniChar
* charBuf
= NULL
;
461 ByteCount dataSize
= 0 ;
464 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
466 numChars
= dataSize
/ sizeof( UniChar
) + 1;
469 if ( (size_t) numChars
* 2 > sizeof(buf
) )
470 charBuf
= new UniChar
[ numChars
] ;
474 uniChars
= new wchar_t[ numChars
] ;
475 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
476 charBuf
[ numChars
- 1 ] = 0;
477 #if SIZEOF_WCHAR_T == 2
478 uniChars
= (wchar_t*) charBuf
;
479 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
481 // the resulting string will never have more chars than the utf16 version, so this is safe
482 wxMBConvUTF16 converter
;
483 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
487 switch ( GetEventKind( event
) )
489 case kEventTextInputUpdateActiveInputArea
:
491 // An IME input event may return several characters, but we need to send one char at a time to
493 for (int pos
=0 ; pos
< numChars
; pos
++)
495 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
496 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
497 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
499 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
500 if ( wxTheApp
->MacSendCharEvent(
501 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
506 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
510 case kEventTextInputUnicodeForKeyEvent
:
512 UInt32 keyCode
, modifiers
;
515 unsigned char charCode
;
517 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
518 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
519 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
520 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
521 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
523 UInt32 message
= (keyCode
<< 8) + charCode
;
525 // An IME input event may return several characters, but we need to send one char at a time to
527 for (int pos
=0 ; pos
< numChars
; pos
++)
529 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
530 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
531 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
533 if ( wxTheApp
->MacSendCharEvent(
534 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
539 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
548 if ( charBuf
!= buf
)
554 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
556 OSStatus result
= eventNotHandledErr
;
557 wxWindowMac
* focus
= (wxWindowMac
*) data
;
561 wxMacCarbonEvent
cEvent( event
) ;
562 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
564 wxMenuItem
* item
= NULL
;
565 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
566 int id
= wxMacCommandToId( command
.commandID
) ;
570 wxASSERT( itemMenu
!= NULL
) ;
572 switch ( cEvent
.GetKind() )
574 case kEventProcessCommand
:
576 if (item
->IsCheckable())
577 item
->Check( !item
->IsChecked() ) ;
579 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
583 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
584 event
.SetEventObject(focus
);
585 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
587 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
593 case kEventCommandUpdateStatus
:
595 wxUpdateUIEvent
event(id
);
596 event
.SetEventObject( itemMenu
);
598 bool processed
= false;
600 // Try the menu's event handler
602 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
604 processed
= handler
->ProcessEvent(event
);
607 // Try the window the menu was popped up from
608 // (and up through the hierarchy)
611 const wxMenuBase
*menu
= itemMenu
;
614 wxWindow
*win
= menu
->GetInvokingWindow();
617 processed
= win
->GetEventHandler()->ProcessEvent(event
);
621 menu
= menu
->GetParent();
627 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
632 // if anything changed, update the changed attribute
633 if (event
.GetSetText())
634 itemMenu
->SetLabel(id
, event
.GetText());
635 if (event
.GetSetChecked())
636 itemMenu
->Check(id
, event
.GetChecked());
637 if (event
.GetSetEnabled())
638 itemMenu
->Enable(id
, event
.GetEnabled());
652 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
654 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
655 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
656 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
657 OSStatus result
= eventNotHandledErr
;
659 switch ( GetEventClass( event
) )
661 case kEventClassCommand
:
662 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
665 case kEventClassControl
:
666 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
669 case kEventClassService
:
670 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
673 case kEventClassTextInput
:
674 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
681 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
686 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
688 #if !TARGET_API_MAC_OSX
690 // ---------------------------------------------------------------------------
691 // UserPane events for non OSX builds
692 // ---------------------------------------------------------------------------
694 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
696 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
698 win
->MacControlUserPaneDrawProc(part
) ;
700 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
702 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
704 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
706 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
708 return kControlNoPart
;
710 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
712 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
714 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
716 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
718 return kControlNoPart
;
720 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
722 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
724 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
726 win
->MacControlUserPaneIdleProc() ;
728 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
730 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
732 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
734 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
736 return kControlNoPart
;
738 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
740 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
742 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
744 win
->MacControlUserPaneActivateProc(activating
) ;
746 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
748 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
750 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
752 return win
->MacControlUserPaneFocusProc(action
) ;
754 return kControlNoPart
;
756 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
758 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
760 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
762 win
->MacControlUserPaneBackgroundProc(info
) ;
764 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
766 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
769 RgnHandle rgn
= NewRgn() ;
771 MacWindowToRootWindow( &x
, &y
) ;
772 OffsetRgn( rgn
, -x
, -y
) ;
773 wxMacWindowStateSaver
sv( this ) ;
774 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
775 MacDoRedraw( rgn
, 0 ) ;
779 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
781 return kControlNoPart
;
784 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
786 return kControlNoPart
;
789 void wxWindowMac::MacControlUserPaneIdleProc()
793 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
795 return kControlNoPart
;
798 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
802 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
804 if ( AcceptsFocus() )
807 return kControlNoPart
;
810 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
816 // ---------------------------------------------------------------------------
817 // Scrollbar Tracking for all
818 // ---------------------------------------------------------------------------
820 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
821 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
825 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
827 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
830 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
832 // ===========================================================================
834 // ===========================================================================
836 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
838 static MacControlMap wxWinMacControlList
;
840 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
842 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
844 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
847 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
849 // adding NULL ControlRef is (first) surely a result of an error and
850 // (secondly) breaks native event processing
851 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
853 wxWinMacControlList
[inControl
] = control
;
856 void wxRemoveMacControlAssociation(wxWindow
*control
)
858 // iterate over all the elements in the class
859 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
860 // we should go on...
866 MacControlMap::iterator it
;
867 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
869 if ( it
->second
== control
)
871 wxWinMacControlList
.erase(it
);
879 // ----------------------------------------------------------------------------
880 // constructors and such
881 // ----------------------------------------------------------------------------
883 wxWindowMac::wxWindowMac()
888 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
893 const wxString
& name
)
896 Create(parent
, id
, pos
, size
, style
, name
);
899 void wxWindowMac::Init()
905 #if WXWIN_COMPATIBILITY_2_4
906 m_backgroundTransparent
= false;
909 #if wxMAC_USE_CORE_GRAPHICS
910 m_cgContextRef
= NULL
;
913 // as all windows are created with WS_VISIBLE style...
916 m_hScrollBar
= NULL
;
917 m_vScrollBar
= NULL
;
918 m_macBackgroundBrush
= wxNullBrush
;
920 m_macIsUserPane
= true;
921 m_clipChildren
= false ;
922 m_cachedClippedRectValid
= false ;
924 // we need a valid font for the encodings
925 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
928 wxWindowMac::~wxWindowMac()
932 m_isBeingDeleted
= true;
934 MacInvalidateBorders() ;
936 #ifndef __WXUNIVERSAL__
937 // VS: make sure there's no wxFrame with last focus set to us:
938 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
940 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
943 if ( frame
->GetLastFocus() == this )
944 frame
->SetLastFocus((wxWindow
*)NULL
);
950 // destroy children before destroying this window itself
953 // wxRemoveMacControlAssociation( this ) ;
954 // If we delete an item, we should initialize the parent panel,
955 // because it could now be invalid.
956 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
959 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
960 tlw
->SetDefaultItem(NULL
);
963 if ( m_peer
&& m_peer
->Ok() )
965 // in case the callback might be called during destruction
966 wxRemoveMacControlAssociation( this) ;
967 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
968 // we currently are not using this hook
969 // ::SetControlColorProc( *m_peer , NULL ) ;
973 if ( g_MacLastWindow
== this )
974 g_MacLastWindow
= NULL
;
976 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
979 if ( frame
->GetLastFocus() == this )
980 frame
->SetLastFocus( NULL
) ;
983 // delete our drop target if we've got one
984 #if wxUSE_DRAG_AND_DROP
985 if ( m_dropTarget
!= NULL
)
995 WXWidget
wxWindowMac::GetHandle() const
997 return (WXWidget
) m_peer
->GetControlRef() ;
1000 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1002 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1003 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1004 GetEventTypeCount(eventList
), eventList
, this,
1005 (EventHandlerRef
*)&m_macControlEventHandler
);
1007 #if !TARGET_API_MAC_OSX
1008 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1010 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1011 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1012 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1013 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1014 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1015 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1016 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1017 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1023 bool wxWindowMac::Create(wxWindowMac
*parent
,
1028 const wxString
& name
)
1030 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1032 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1035 m_windowVariant
= parent
->GetWindowVariant() ;
1037 if ( m_macIsUserPane
)
1039 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1042 | kControlSupportsEmbedding
1043 | kControlSupportsLiveFeedback
1044 | kControlGetsFocusOnClick
1045 // | kControlHasSpecialBackground
1046 // | kControlSupportsCalcBestRect
1047 | kControlHandlesTracking
1048 | kControlSupportsFocus
1049 | kControlWantsActivate
1050 | kControlWantsIdle
;
1052 m_peer
= new wxMacControl(this) ;
1053 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1054 verify_noerr( err
);
1056 MacPostControlCreate(pos
, size
) ;
1059 #ifndef __WXUNIVERSAL__
1060 // Don't give scrollbars to wxControls unless they ask for them
1061 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1062 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1064 MacCreateScrollBars( style
) ;
1068 wxWindowCreateEvent
event(this);
1069 GetEventHandler()->AddPendingEvent(event
);
1074 void wxWindowMac::MacChildAdded()
1077 m_vScrollBar
->Raise() ;
1079 m_hScrollBar
->Raise() ;
1082 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1084 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1086 m_peer
->SetReference( (URefCon
) this ) ;
1087 GetParent()->AddChild( this );
1089 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1091 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1092 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1093 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1094 GetParent()->MacChildAdded() ;
1096 // adjust font, controlsize etc
1097 DoSetWindowVariant( m_windowVariant
) ;
1099 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1101 if (!m_macIsUserPane
)
1102 SetInitialBestSize(size
);
1104 SetCursor( *wxSTANDARD_CURSOR
) ;
1107 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1109 // Don't assert, in case we set the window variant before
1110 // the window is created
1111 // wxASSERT( m_peer->Ok() ) ;
1113 m_windowVariant
= variant
;
1115 if (m_peer
== NULL
|| !m_peer
->Ok())
1119 ThemeFontID themeFont
= kThemeSystemFont
;
1121 // we will get that from the settings later
1122 // and make this NORMAL later, but first
1123 // we have a few calculations that we must fix
1127 case wxWINDOW_VARIANT_NORMAL
:
1128 size
= kControlSizeNormal
;
1129 themeFont
= kThemeSystemFont
;
1132 case wxWINDOW_VARIANT_SMALL
:
1133 size
= kControlSizeSmall
;
1134 themeFont
= kThemeSmallSystemFont
;
1137 case wxWINDOW_VARIANT_MINI
:
1138 if (UMAGetSystemVersion() >= 0x1030 )
1140 // not always defined in the headers
1146 size
= kControlSizeSmall
;
1147 themeFont
= kThemeSmallSystemFont
;
1151 case wxWINDOW_VARIANT_LARGE
:
1152 size
= kControlSizeLarge
;
1153 themeFont
= kThemeSystemFont
;
1157 wxFAIL_MSG(_T("unexpected window variant"));
1161 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1164 font
.MacCreateThemeFont( themeFont
) ;
1168 void wxWindowMac::MacUpdateControlFont()
1170 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1174 bool wxWindowMac::SetFont(const wxFont
& font
)
1176 bool retval
= wxWindowBase::SetFont( font
);
1178 MacUpdateControlFont() ;
1183 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1185 bool retval
= wxWindowBase::SetForegroundColour( col
);
1188 MacUpdateControlFont();
1193 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1195 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1199 wxColour
newCol(GetBackgroundColour());
1201 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1202 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1203 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1204 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1206 brush
.SetColour( newCol
) ;
1208 MacSetBackgroundBrush( brush
) ;
1209 MacUpdateControlFont() ;
1214 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1216 m_macBackgroundBrush
= brush
;
1217 m_peer
->SetBackground( brush
) ;
1220 bool wxWindowMac::MacCanFocus() const
1222 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1223 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1224 // but the value range is nowhere documented
1225 Boolean keyExistsAndHasValidFormat
;
1226 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1227 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1229 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1235 UInt32 features
= 0 ;
1236 m_peer
->GetFeatures( &features
) ;
1238 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1242 void wxWindowMac::SetFocus()
1244 if ( !AcceptsFocus() )
1247 wxWindow
* former
= FindFocus() ;
1248 if ( former
== this )
1251 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1252 // we can only leave in case of an error
1253 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1254 if ( err
== errCouldntSetFocus
)
1257 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1259 #if !TARGET_API_MAC_OSX
1260 // emulate carbon events when running under CarbonLib where they are not natively available
1263 EventRef evRef
= NULL
;
1265 err
= MacCreateEvent(
1266 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1267 kEventAttributeUserEvent
, &evRef
);
1268 verify_noerr( err
);
1270 wxMacCarbonEvent
cEvent( evRef
) ;
1271 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1272 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1274 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1275 ReleaseEvent( evRef
) ;
1278 // send new focus event
1280 EventRef evRef
= NULL
;
1282 err
= MacCreateEvent(
1283 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1284 kEventAttributeUserEvent
, &evRef
);
1285 verify_noerr( err
);
1287 wxMacCarbonEvent
cEvent( evRef
) ;
1288 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1289 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1291 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1292 ReleaseEvent( evRef
) ;
1297 void wxWindowMac::DoCaptureMouse()
1299 wxApp::s_captureWindow
= this ;
1302 wxWindow
* wxWindowBase::GetCapture()
1304 return wxApp::s_captureWindow
;
1307 void wxWindowMac::DoReleaseMouse()
1309 wxApp::s_captureWindow
= NULL
;
1312 #if wxUSE_DRAG_AND_DROP
1314 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1316 if ( m_dropTarget
!= NULL
)
1317 delete m_dropTarget
;
1319 m_dropTarget
= pDropTarget
;
1320 if ( m_dropTarget
!= NULL
)
1328 // Old-style File Manager Drag & Drop
1329 void wxWindowMac::DragAcceptFiles(bool accept
)
1334 // Returns the size of the native control. In the case of the toplevel window
1335 // this is the content area root control
1337 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1338 int& w
, int& h
) const
1340 wxFAIL_MSG( wxT("Not currently supported") ) ;
1343 // From a wx position / size calculate the appropriate size of the native control
1345 bool wxWindowMac::MacGetBoundsForControl(
1349 int& w
, int& h
, bool adjustOrigin
) const
1351 // the desired size, minus the border pixels gives the correct size of the control
1355 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1356 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1357 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1359 x
+= MacGetLeftBorderSize() ;
1360 y
+= MacGetTopBorderSize() ;
1361 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1362 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1365 AdjustForParentClientOrigin( x
, y
) ;
1367 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1368 if ( !GetParent()->IsTopLevel() )
1370 x
-= GetParent()->MacGetLeftBorderSize() ;
1371 y
-= GetParent()->MacGetTopBorderSize() ;
1377 // Get window size (not client size)
1378 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1381 m_peer
->GetRect( &bounds
) ;
1384 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1386 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1389 // get the position of the bounds of this window in client coordinates of its parent
1390 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1393 m_peer
->GetRect( &bounds
) ;
1395 int x1
= bounds
.left
;
1396 int y1
= bounds
.top
;
1398 // get the wx window position from the native one
1399 x1
-= MacGetLeftBorderSize() ;
1400 y1
-= MacGetTopBorderSize() ;
1402 if ( !IsTopLevel() )
1404 wxWindow
*parent
= GetParent();
1407 // we must first adjust it to be in window coordinates of the parent,
1408 // as otherwise it gets lost by the ClientAreaOrigin fix
1409 x1
+= parent
->MacGetLeftBorderSize() ;
1410 y1
+= parent
->MacGetTopBorderSize() ;
1412 // and now to client coordinates
1413 wxPoint
pt(parent
->GetClientAreaOrigin());
1425 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1427 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1428 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1430 Point localwhere
= { 0, 0 } ;
1437 wxMacGlobalToLocal( window
, &localwhere
) ;
1444 MacRootWindowToWindow( x
, y
) ;
1446 wxPoint origin
= GetClientAreaOrigin() ;
1453 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1455 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1456 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1458 wxPoint origin
= GetClientAreaOrigin() ;
1464 MacWindowToRootWindow( x
, y
) ;
1466 Point localwhere
= { 0, 0 };
1472 wxMacLocalToGlobal( window
, &localwhere
) ;
1480 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1482 wxPoint origin
= GetClientAreaOrigin() ;
1488 MacWindowToRootWindow( x
, y
) ;
1491 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1493 MacRootWindowToWindow( x
, y
) ;
1495 wxPoint origin
= GetClientAreaOrigin() ;
1502 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1511 if ( !IsTopLevel() )
1513 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1516 pt
.x
-= MacGetLeftBorderSize() ;
1517 pt
.y
-= MacGetTopBorderSize() ;
1518 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1528 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1537 MacWindowToRootWindow( &x1
, &y1
) ;
1545 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1554 if ( !IsTopLevel() )
1556 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1559 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1560 pt
.x
+= MacGetLeftBorderSize() ;
1561 pt
.y
+= MacGetTopBorderSize() ;
1571 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1580 MacRootWindowToWindow( &x1
, &y1
) ;
1588 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1590 RgnHandle rgn
= NewRgn() ;
1592 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1594 Rect structure
, content
;
1596 GetRegionBounds( rgn
, &content
) ;
1597 m_peer
->GetRect( &structure
) ;
1598 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1600 left
= content
.left
- structure
.left
;
1601 top
= content
.top
- structure
.top
;
1602 right
= structure
.right
- content
.right
;
1603 bottom
= structure
.bottom
- content
.bottom
;
1607 left
= top
= right
= bottom
= 0 ;
1613 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1615 wxSize sizeTotal
= size
;
1617 RgnHandle rgn
= NewRgn() ;
1618 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1620 Rect content
, structure
;
1621 GetRegionBounds( rgn
, &content
) ;
1622 m_peer
->GetRect( &structure
) ;
1624 // structure is in parent coordinates, but we only need width and height, so it's ok
1626 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1627 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1632 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1633 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1638 // Get size *available for subwindows* i.e. excluding menu bar etc.
1639 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1643 RgnHandle rgn
= NewRgn() ;
1645 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1646 GetRegionBounds( rgn
, &content
) ;
1648 m_peer
->GetRect( &content
) ;
1651 ww
= content
.right
- content
.left
;
1652 hh
= content
.bottom
- content
.top
;
1654 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1655 hh
-= m_hScrollBar
->GetSize().y
;
1657 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1658 ww
-= m_vScrollBar
->GetSize().x
;
1666 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1668 if (m_cursor
== cursor
)
1671 if (wxNullCursor
== cursor
)
1673 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1678 if ( ! wxWindowBase::SetCursor( cursor
) )
1682 wxASSERT_MSG( m_cursor
.Ok(),
1683 wxT("cursor must be valid after call to the base version"));
1685 wxWindowMac
*mouseWin
= 0 ;
1687 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1688 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1690 ControlPartCode part
;
1691 ControlRef control
;
1693 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1695 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1700 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1702 // TODO: If we ever get a GetCurrentEvent... replacement
1703 // for the mouse position, use it...
1708 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1710 mouseWin
= wxFindControlFromMacControl( control
) ;
1712 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1714 QDSwapPort( savePort
, NULL
) ;
1718 if ( mouseWin
== this && !wxIsBusy() )
1719 m_cursor
.MacInstall() ;
1725 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1727 menu
->SetInvokingWindow(this);
1730 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1732 wxPoint mouse
= wxGetMousePosition();
1738 ClientToScreen( &x
, &y
) ;
1741 menu
->MacBeforeDisplay( true ) ;
1742 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1743 if ( HiWord(menuResult
) != 0 )
1746 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1747 int id
= wxMacCommandToId( macid
);
1748 wxMenuItem
* item
= NULL
;
1750 item
= menu
->FindItem( id
, &realmenu
) ;
1753 if (item
->IsCheckable())
1754 item
->Check( !item
->IsChecked() ) ;
1756 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1760 menu
->MacAfterDisplay( true ) ;
1761 menu
->SetInvokingWindow( NULL
);
1767 // ----------------------------------------------------------------------------
1769 // ----------------------------------------------------------------------------
1773 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1775 wxWindowBase::DoSetToolTip(tooltip
);
1778 m_tooltip
->SetWindow(this);
1783 void wxWindowMac::MacInvalidateBorders()
1785 if ( m_peer
== NULL
)
1788 bool vis
= MacIsReallyShown() ;
1792 int outerBorder
= MacGetLeftBorderSize() ;
1793 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1796 if ( outerBorder
== 0 )
1799 // now we know that we have something to do at all
1801 // as the borders are drawn on the parent we have to properly invalidate all these areas
1802 RgnHandle updateInner
, updateOuter
;
1805 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1806 updateInner
= NewRgn() ;
1807 updateOuter
= NewRgn() ;
1809 m_peer
->GetRect( &rect
) ;
1810 RectRgn( updateInner
, &rect
) ;
1811 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1812 RectRgn( updateOuter
, &rect
) ;
1813 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1815 #ifdef __WXMAC_OSX__
1816 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1818 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1820 InvalWindowRgn( tlw
, updateOuter
) ;
1823 DisposeRgn( updateOuter
) ;
1824 DisposeRgn( updateInner
) ;
1827 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1829 // this is never called for a toplevel window, so we know we have a parent
1830 int former_x
, former_y
, former_w
, former_h
;
1832 // Get true coordinates of former position
1833 DoGetPosition( &former_x
, &former_y
) ;
1834 DoGetSize( &former_w
, &former_h
) ;
1836 wxWindow
*parent
= GetParent();
1839 wxPoint
pt(parent
->GetClientAreaOrigin());
1844 int actualWidth
= width
;
1845 int actualHeight
= height
;
1849 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1850 actualWidth
= m_minWidth
;
1851 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1852 actualHeight
= m_minHeight
;
1853 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1854 actualWidth
= m_maxWidth
;
1855 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1856 actualHeight
= m_maxHeight
;
1858 bool doMove
= false, doResize
= false ;
1860 if ( actualX
!= former_x
|| actualY
!= former_y
)
1863 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1866 if ( doMove
|| doResize
)
1868 // as the borders are drawn outside the native control, we adjust now
1870 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1871 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1872 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1875 wxMacRectToNative( &bounds
, &r
) ;
1877 if ( !GetParent()->IsTopLevel() )
1878 wxMacWindowToNative( GetParent() , &r
) ;
1880 MacInvalidateBorders() ;
1882 m_cachedClippedRectValid
= false ;
1883 m_peer
->SetRect( &r
) ;
1885 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1887 MacInvalidateBorders() ;
1889 MacRepositionScrollBars() ;
1892 wxPoint
point(actualX
, actualY
);
1893 wxMoveEvent
event(point
, m_windowId
);
1894 event
.SetEventObject(this);
1895 GetEventHandler()->ProcessEvent(event
) ;
1900 MacRepositionScrollBars() ;
1901 wxSize
size(actualWidth
, actualHeight
);
1902 wxSizeEvent
event(size
, m_windowId
);
1903 event
.SetEventObject(this);
1904 GetEventHandler()->ProcessEvent(event
);
1909 wxSize
wxWindowMac::DoGetBestSize() const
1911 if ( m_macIsUserPane
|| IsTopLevel() )
1912 return wxWindowBase::DoGetBestSize() ;
1914 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1915 int bestWidth
, bestHeight
;
1917 m_peer
->GetBestRect( &bestsize
) ;
1918 if ( EmptyRect( &bestsize
) )
1923 bestsize
.bottom
= 16 ;
1925 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1927 bestsize
.bottom
= 16 ;
1930 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1932 bestsize
.bottom
= 24 ;
1937 // return wxWindowBase::DoGetBestSize() ;
1941 bestWidth
= bestsize
.right
- bestsize
.left
;
1942 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1943 if ( bestHeight
< 10 )
1946 return wxSize(bestWidth
, bestHeight
);
1949 // set the size of the window: if the dimensions are positive, just use them,
1950 // but if any of them is equal to -1, it means that we must find the value for
1951 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1952 // which case -1 is a valid value for x and y)
1954 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1955 // the width/height to best suit our contents, otherwise we reuse the current
1957 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1959 // get the current size and position...
1960 int currentX
, currentY
;
1961 int currentW
, currentH
;
1963 GetPosition(¤tX
, ¤tY
);
1964 GetSize(¤tW
, ¤tH
);
1966 // ... and don't do anything (avoiding flicker) if it's already ok
1967 if ( x
== currentX
&& y
== currentY
&&
1968 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1971 MacRepositionScrollBars() ; // we might have a real position shift
1976 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1978 if ( x
== wxDefaultCoord
)
1980 if ( y
== wxDefaultCoord
)
1984 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1986 wxSize size
= wxDefaultSize
;
1987 if ( width
== wxDefaultCoord
)
1989 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1991 size
= DoGetBestSize();
1996 // just take the current one
2001 if ( height
== wxDefaultCoord
)
2003 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2005 if ( size
.x
== wxDefaultCoord
)
2006 size
= DoGetBestSize();
2007 // else: already called DoGetBestSize() above
2013 // just take the current one
2018 DoMoveWindow( x
, y
, width
, height
);
2021 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2023 RgnHandle rgn
= NewRgn() ;
2025 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2027 GetRegionBounds( rgn
, &content
) ;
2037 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2040 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2042 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2044 int currentclientwidth
, currentclientheight
;
2045 int currentwidth
, currentheight
;
2047 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2048 GetSize( ¤twidth
, ¤theight
) ;
2050 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2051 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2055 void wxWindowMac::SetLabel(const wxString
& title
)
2057 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2059 if ( m_peer
&& m_peer
->Ok() )
2060 m_peer
->SetLabel( m_label
) ;
2065 wxString
wxWindowMac::GetLabel() const
2070 bool wxWindowMac::Show(bool show
)
2072 bool former
= MacIsReallyShown() ;
2073 if ( !wxWindowBase::Show(show
) )
2076 // TODO: use visibilityChanged Carbon Event for OSX
2078 m_peer
->SetVisibility( show
, true ) ;
2080 if ( former
!= MacIsReallyShown() )
2081 MacPropagateVisibilityChanged() ;
2086 bool wxWindowMac::Enable(bool enable
)
2088 wxASSERT( m_peer
->Ok() ) ;
2089 bool former
= MacIsReallyEnabled() ;
2090 if ( !wxWindowBase::Enable(enable
) )
2093 m_peer
->Enable( enable
) ;
2095 if ( former
!= MacIsReallyEnabled() )
2096 MacPropagateEnabledStateChanged() ;
2102 // status change propagations (will be not necessary for OSX later )
2105 void wxWindowMac::MacPropagateVisibilityChanged()
2107 #if !TARGET_API_MAC_OSX
2108 MacVisibilityChanged() ;
2111 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2114 child
= node
->GetData();
2115 if ( child
->IsShown() )
2116 child
->MacPropagateVisibilityChanged() ;
2118 node
= node
->GetNext();
2123 void wxWindowMac::MacPropagateEnabledStateChanged()
2125 #if !TARGET_API_MAC_OSX
2126 MacEnabledStateChanged() ;
2129 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2132 child
= node
->GetData();
2133 if ( child
->IsEnabled() )
2134 child
->MacPropagateEnabledStateChanged() ;
2136 node
= node
->GetNext();
2141 void wxWindowMac::MacPropagateHiliteChanged()
2143 #if !TARGET_API_MAC_OSX
2144 MacHiliteChanged() ;
2147 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2150 child
= node
->GetData();
2151 if (child
/* && child->IsEnabled() */)
2152 child
->MacPropagateHiliteChanged() ;
2154 node
= node
->GetNext();
2160 // status change notifications
2163 void wxWindowMac::MacVisibilityChanged()
2167 void wxWindowMac::MacHiliteChanged()
2171 void wxWindowMac::MacEnabledStateChanged()
2176 // status queries on the inherited window's state
2179 bool wxWindowMac::MacIsReallyShown()
2181 // only under OSX the visibility of the TLW is taken into account
2182 if ( m_isBeingDeleted
)
2185 #if TARGET_API_MAC_OSX
2186 if ( m_peer
&& m_peer
->Ok() )
2187 return m_peer
->IsVisible();
2190 wxWindow
* win
= this ;
2191 while ( win
->IsShown() )
2193 if ( win
->IsTopLevel() )
2196 win
= win
->GetParent() ;
2204 bool wxWindowMac::MacIsReallyEnabled()
2206 return m_peer
->IsEnabled() ;
2209 bool wxWindowMac::MacIsReallyHilited()
2211 return m_peer
->IsActive();
2214 void wxWindowMac::MacFlashInvalidAreas()
2216 #if TARGET_API_MAC_OSX
2217 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2221 int wxWindowMac::GetCharHeight() const
2223 wxClientDC
dc( (wxWindowMac
*)this ) ;
2225 return dc
.GetCharHeight() ;
2228 int wxWindowMac::GetCharWidth() const
2230 wxClientDC
dc( (wxWindowMac
*)this ) ;
2232 return dc
.GetCharWidth() ;
2235 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2236 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2238 const wxFont
*fontToUse
= theFont
;
2240 fontToUse
= &m_font
;
2242 wxClientDC
dc( (wxWindowMac
*) this ) ;
2244 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2245 if ( externalLeading
)
2246 *externalLeading
= le
;
2256 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2257 * we always intersect with the entire window, not only with the client area
2260 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2262 if ( m_peer
== NULL
)
2265 if ( !MacIsReallyShown() )
2272 wxMacRectToNative( rect
, &r
) ;
2273 m_peer
->SetNeedsDisplay( &r
) ;
2277 m_peer
->SetNeedsDisplay() ;
2281 void wxWindowMac::Freeze()
2283 #if TARGET_API_MAC_OSX
2284 if ( !m_frozenness
++ )
2286 if ( m_peer
&& m_peer
->Ok() )
2287 m_peer
->SetDrawingEnabled( false ) ;
2292 void wxWindowMac::Thaw()
2294 #if TARGET_API_MAC_OSX
2295 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2297 if ( !--m_frozenness
)
2299 if ( m_peer
&& m_peer
->Ok() )
2301 m_peer
->SetDrawingEnabled( true ) ;
2302 m_peer
->InvalidateWithChildren() ;
2308 bool wxWindowMac::IsFrozen() const
2310 return m_frozenness
!= 0;
2313 wxWindowMac
*wxGetActiveWindow()
2315 // actually this is a windows-only concept
2319 // Coordinates relative to the window
2320 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2322 // We really don't move the mouse programmatically under Mac.
2325 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2327 if ( MacGetTopLevelWindow() == NULL
)
2330 #if TARGET_API_MAC_OSX
2331 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2338 event
.GetDC()->Clear() ;
2342 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2347 int wxWindowMac::GetScrollPos(int orient
) const
2349 if ( orient
== wxHORIZONTAL
)
2352 return m_hScrollBar
->GetThumbPosition() ;
2357 return m_vScrollBar
->GetThumbPosition() ;
2363 // This now returns the whole range, not just the number
2364 // of positions that we can scroll.
2365 int wxWindowMac::GetScrollRange(int orient
) const
2367 if ( orient
== wxHORIZONTAL
)
2370 return m_hScrollBar
->GetRange() ;
2375 return m_vScrollBar
->GetRange() ;
2381 int wxWindowMac::GetScrollThumb(int orient
) const
2383 if ( orient
== wxHORIZONTAL
)
2386 return m_hScrollBar
->GetThumbSize() ;
2391 return m_vScrollBar
->GetThumbSize() ;
2397 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2399 if ( orient
== wxHORIZONTAL
)
2402 m_hScrollBar
->SetThumbPosition( pos
) ;
2407 m_vScrollBar
->SetThumbPosition( pos
) ;
2412 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2413 // our own window origin is at leftOrigin/rightOrigin
2416 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2422 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2423 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2425 // back to the surrounding frame rectangle
2426 m_peer
->GetRect( &rect
) ;
2427 InsetRect( &rect
, -1 , -1 ) ;
2429 #if wxMAC_USE_CORE_GRAPHICS
2431 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2432 rect
.bottom
- rect
.top
) ;
2434 HIThemeFrameDrawInfo info
;
2435 memset( &info
, 0 , sizeof(info
) ) ;
2439 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2440 info
.isFocused
= hasFocus
;
2442 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2443 wxASSERT( cgContext
) ;
2445 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2447 info
.kind
= kHIThemeFrameTextFieldSquare
;
2448 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2450 else if ( HasFlag(wxSIMPLE_BORDER
) )
2452 info
.kind
= kHIThemeFrameListBox
;
2453 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2455 else if ( hasFocus
)
2457 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2460 m_peer
->GetRect( &rect
) ;
2461 if ( hasBothScrollbars
)
2463 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2464 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2465 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2466 HIThemeGrowBoxDrawInfo info
;
2467 memset( &info
, 0, sizeof(info
) ) ;
2469 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2470 info
.kind
= kHIThemeGrowBoxKindNone
;
2471 info
.size
= kHIThemeGrowBoxSizeNormal
;
2472 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2473 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2478 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2482 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2483 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2486 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2487 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2488 else if ( HasFlag(wxSIMPLE_BORDER
) )
2489 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2492 DrawThemeFocusRect( &rect
, true ) ;
2494 if ( hasBothScrollbars
)
2496 // GetThemeStandaloneGrowBoxBounds
2497 // DrawThemeStandaloneNoGrowBox
2503 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2505 if ( child
== m_hScrollBar
)
2506 m_hScrollBar
= NULL
;
2507 if ( child
== m_vScrollBar
)
2508 m_vScrollBar
= NULL
;
2510 wxWindowBase::RemoveChild( child
) ;
2513 // New function that will replace some of the above.
2514 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2515 int range
, bool refresh
)
2518 bool triggerSizeEvent
= false;
2520 if ( orient
== wxHORIZONTAL
)
2524 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2525 if ( m_hScrollBar
->IsShown() != showScroller
)
2527 m_hScrollBar
->Show( showScroller
);
2528 triggerSizeEvent
= true;
2531 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2538 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2539 if ( m_vScrollBar
->IsShown() != showScroller
)
2541 m_vScrollBar
->Show( showScroller
) ;
2542 triggerSizeEvent
= true;
2545 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2549 MacRepositionScrollBars() ;
2550 if ( triggerSizeEvent
)
2552 wxSizeEvent
event(GetSize(), m_windowId
);
2553 event
.SetEventObject(this);
2554 GetEventHandler()->ProcessEvent(event
);
2558 // Does a physical scroll
2559 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2561 if ( dx
== 0 && dy
== 0 )
2564 int width
, height
;
2565 GetClientSize( &width
, &height
) ;
2568 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2569 // area is scrolled, this does not occur if width and height are 2 pixels less,
2570 // TODO: write optimal workaround
2571 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2573 scrollrect
.Intersect( *rect
) ;
2575 if ( m_peer
->GetNeedsDisplay() )
2577 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2578 // either immediate redraw or full invalidate
2580 // is the better overall solution, as it does not slow down scrolling
2581 m_peer
->SetNeedsDisplay() ;
2583 // this would be the preferred version for fast drawing controls
2585 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2586 if ( UMAGetSystemVersion() >= 0x1030 )
2587 HIViewRender(m_peer
->GetControlRef()) ;
2594 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2595 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2596 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2598 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2599 // either immediate redraw or full invalidate
2601 // is the better overall solution, as it does not slow down scrolling
2602 m_peer
->SetNeedsDisplay() ;
2604 // this would be the preferred version for fast drawing controls
2606 HIViewRender(m_peer
->GetControlRef()) ;
2612 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2614 child
= node
->GetData();
2617 if (child
== m_vScrollBar
)
2619 if (child
== m_hScrollBar
)
2621 if (child
->IsTopLevel())
2624 child
->GetPosition( &x
, &y
);
2625 child
->GetSize( &w
, &h
);
2628 wxRect
rc( x
, y
, w
, h
);
2629 if (rect
->Intersects( rc
))
2630 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2634 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2639 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2641 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2643 wxScrollWinEvent wevent
;
2644 wevent
.SetPosition(event
.GetPosition());
2645 wevent
.SetOrientation(event
.GetOrientation());
2646 wevent
.SetEventObject(this);
2648 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2649 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2650 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2651 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2652 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2653 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2654 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2655 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2656 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2657 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2658 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2659 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2660 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2661 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2662 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2663 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2665 GetEventHandler()->ProcessEvent(wevent
);
2669 // Get the window with the focus
2670 wxWindowMac
*wxWindowBase::DoFindFocus()
2672 ControlRef control
;
2673 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2674 return wxFindControlFromMacControl( control
) ;
2677 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2679 // panel wants to track the window which was the last to have focus in it,
2680 // so we want to set ourselves as the window which last had focus
2682 // notice that it's also important to do it upwards the tree because
2683 // otherwise when the top level panel gets focus, it won't set it back to
2684 // us, but to some other sibling
2686 // CS: don't know if this is still needed:
2687 //wxChildFocusEvent eventFocus(this);
2688 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2690 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2692 #if wxMAC_USE_CORE_GRAPHICS
2693 GetParent()->Refresh() ;
2695 wxMacWindowStateSaver
sv( this ) ;
2698 m_peer
->GetRect( &rect
) ;
2699 // auf den umgebenden Rahmen zur\9fck
2700 InsetRect( &rect
, -1 , -1 ) ;
2702 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2706 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2708 rect
.right
+= pt
.x
;
2710 rect
.bottom
+= pt
.y
;
2713 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2714 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2715 if ( !bIsFocusEvent
)
2717 // as this erases part of the frame we have to redraw borders
2718 // and because our z-ordering is not always correct (staticboxes)
2719 // we have to invalidate things, we cannot simple redraw
2720 MacInvalidateBorders() ;
2728 void wxWindowMac::OnInternalIdle()
2730 // This calls the UI-update mechanism (querying windows for
2731 // menu/toolbar/control state information)
2732 if (wxUpdateUIEvent::CanUpdate(this))
2733 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2736 // Raise the window to the top of the Z order
2737 void wxWindowMac::Raise()
2739 m_peer
->SetZOrder( true , NULL
) ;
2742 // Lower the window to the bottom of the Z order
2743 void wxWindowMac::Lower()
2745 m_peer
->SetZOrder( false , NULL
) ;
2748 // static wxWindow *gs_lastWhich = NULL;
2750 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2752 // first trigger a set cursor event
2754 wxPoint clientorigin
= GetClientAreaOrigin() ;
2755 wxSize clientsize
= GetClientSize() ;
2757 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2759 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2761 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2762 if ( processedEvtSetCursor
&& event
.HasCursor() )
2764 cursor
= event
.GetCursor() ;
2768 // the test for processedEvtSetCursor is here to prevent using m_cursor
2769 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2770 // it - this is a way to say that our cursor shouldn't be used for this
2772 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2775 if ( !wxIsBusy() && !GetParent() )
2776 cursor
= *wxSTANDARD_CURSOR
;
2780 cursor
.MacInstall() ;
2783 return cursor
.Ok() ;
2786 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2790 return m_tooltip
->GetTip() ;
2793 return wxEmptyString
;
2796 void wxWindowMac::ClearBackground()
2802 void wxWindowMac::Update()
2804 #if TARGET_API_MAC_OSX
2805 MacGetTopLevelWindow()->MacPerformUpdates() ;
2807 ::Draw1Control( m_peer
->GetControlRef() ) ;
2811 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2813 wxTopLevelWindowMac
* win
= NULL
;
2814 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2816 win
= wxFindWinFromMacWindow( window
) ;
2821 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2823 MacUpdateClippedRects() ;
2825 return m_cachedClippedClientRect
;
2828 const wxRect
& wxWindowMac::MacGetClippedRect() const
2830 MacUpdateClippedRects() ;
2832 return m_cachedClippedRect
;
2835 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2837 MacUpdateClippedRects() ;
2839 return m_cachedClippedRectWithOuterStructure
;
2842 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2844 static wxRegion emptyrgn
;
2846 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2848 MacUpdateClippedRects() ;
2849 if ( includeOuterStructures
)
2850 return m_cachedClippedRegionWithOuterStructure
;
2852 return m_cachedClippedRegion
;
2860 void wxWindowMac::MacUpdateClippedRects() const
2862 if ( m_cachedClippedRectValid
)
2865 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2866 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2867 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2868 // to add focus borders everywhere
2870 Rect r
, rIncludingOuterStructures
;
2872 m_peer
->GetRect( &r
) ;
2873 r
.left
-= MacGetLeftBorderSize() ;
2874 r
.top
-= MacGetTopBorderSize() ;
2875 r
.bottom
+= MacGetBottomBorderSize() ;
2876 r
.right
+= MacGetRightBorderSize() ;
2883 rIncludingOuterStructures
= r
;
2884 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2886 wxRect cl
= GetClientRect() ;
2887 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2891 const wxWindow
* child
= this ;
2892 const wxWindow
* parent
= NULL
;
2894 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2896 if ( parent
->MacIsChildOfClientArea(child
) )
2898 size
= parent
->GetClientSize() ;
2899 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2905 // this will be true for scrollbars, toolbars etc.
2906 size
= parent
->GetSize() ;
2907 y
= parent
->MacGetTopBorderSize() ;
2908 x
= parent
->MacGetLeftBorderSize() ;
2909 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2910 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2913 parent
->MacWindowToRootWindow( &x
, &y
) ;
2914 MacRootWindowToWindow( &x
, &y
) ;
2916 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2918 // the wxwindow and client rects will always be clipped
2919 SectRect( &r
, &rparent
, &r
) ;
2920 SectRect( &rClient
, &rparent
, &rClient
) ;
2922 // the structure only at 'hard' borders
2923 if ( parent
->MacClipChildren() ||
2924 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2926 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2932 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2933 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2934 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2935 m_cachedClippedRectWithOuterStructure
= wxRect(
2936 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2937 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2938 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2940 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2941 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2942 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2944 m_cachedClippedRectValid
= true ;
2948 This function must not change the updatergn !
2950 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2952 bool handled
= false ;
2954 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2955 GetRegionBounds( updatergn
, &updatebounds
) ;
2957 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2959 if ( !EmptyRgn(updatergn
) )
2961 RgnHandle newupdate
= NewRgn() ;
2962 wxSize point
= GetClientSize() ;
2963 wxPoint origin
= GetClientAreaOrigin() ;
2964 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2965 SectRgn( newupdate
, updatergn
, newupdate
) ;
2967 // first send an erase event to the entire update area
2969 // for the toplevel window this really is the entire area
2970 // for all the others only their client area, otherwise they
2971 // might be drawing with full alpha and eg put blue into
2972 // the grow-box area of a scrolled window (scroll sample)
2973 wxDC
* dc
= new wxWindowDC(this);
2975 dc
->SetClippingRegion(wxRegion(updatergn
));
2977 dc
->SetClippingRegion(wxRegion(newupdate
));
2979 wxEraseEvent
eevent( GetId(), dc
);
2980 eevent
.SetEventObject( this );
2981 GetEventHandler()->ProcessEvent( eevent
);
2985 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2986 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2987 m_updateRegion
= newupdate
;
2988 DisposeRgn( newupdate
) ;
2990 if ( !m_updateRegion
.Empty() )
2992 // paint the window itself
2995 event
.SetTimestamp(time
);
2996 event
.SetEventObject(this);
2997 GetEventHandler()->ProcessEvent(event
);
3001 // now we cannot rely on having its borders drawn by a window itself, as it does not
3002 // get the updateRgn wide enough to always do so, so we do it from the parent
3003 // this would also be the place to draw any custom backgrounds for native controls
3004 // in Composited windowing
3005 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3009 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3011 child
= node
->GetData();
3014 if (child
== m_vScrollBar
)
3016 if (child
== m_hScrollBar
)
3018 if (child
->IsTopLevel())
3020 if (!child
->IsShown())
3023 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3025 child
->GetPosition( &x
, &y
);
3026 child
->GetSize( &w
, &h
);
3027 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3028 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3029 InsetRect( &childRect
, -10 , -10) ;
3031 if ( RectInRgn( &childRect
, updatergn
) )
3033 // paint custom borders
3034 wxNcPaintEvent
eventNc( child
->GetId() );
3035 eventNc
.SetEventObject( child
);
3036 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3038 #if wxMAC_USE_CORE_GRAPHICS
3039 child
->MacPaintBorders(0, 0) ;
3042 wxWindowDC
dc(this) ;
3043 dc
.SetClippingRegion(wxRegion(updatergn
));
3044 wxMacPortSetter
helper(&dc
) ;
3045 child
->MacPaintBorders(0, 0) ;
3057 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3059 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3063 if ( iter
->IsTopLevel() )
3064 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3066 iter
= iter
->GetParent() ;
3072 void wxWindowMac::MacCreateScrollBars( long style
)
3074 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3076 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3078 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3079 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3080 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3082 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3085 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3087 GetClientSize( &width
, &height
) ;
3089 wxPoint
vPoint(width
- scrlsize
, 0) ;
3090 wxSize
vSize(scrlsize
, height
- adjust
) ;
3091 wxPoint
hPoint(0, height
- scrlsize
) ;
3092 wxSize
hSize(width
- adjust
, scrlsize
) ;
3094 if ( style
& wxVSCROLL
)
3095 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3097 if ( style
& wxHSCROLL
)
3098 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3101 // because the create does not take into account the client area origin
3102 // we might have a real position shift
3103 MacRepositionScrollBars() ;
3106 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3108 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3113 void wxWindowMac::MacRepositionScrollBars()
3115 if ( !m_hScrollBar
&& !m_vScrollBar
)
3118 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3119 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3120 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3122 // get real client area
3124 GetSize( &width
, &height
);
3126 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3127 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3129 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3130 wxSize
vSize( scrlsize
, height
- adjust
) ;
3131 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3132 wxSize
hSize( width
- adjust
, scrlsize
) ;
3135 int x
= 0, y
= 0, w
, h
;
3136 GetSize( &w
, &h
) ;
3138 MacClientToRootWindow( &x
, &y
) ;
3139 MacClientToRootWindow( &w
, &h
) ;
3141 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3143 int totW
= 10000 , totH
= 10000;
3146 if ( iter
->IsTopLevel() )
3148 iter
->GetSize( &totW
, &totH
) ;
3152 iter
= iter
->GetParent() ;
3166 if ( w
- x
>= totW
)
3171 if ( h
- y
>= totH
)
3179 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3181 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3184 bool wxWindowMac::AcceptsFocus() const
3186 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3189 void wxWindowMac::MacSuperChangedPosition()
3191 // only window-absolute structures have to be moved i.e. controls
3193 m_cachedClippedRectValid
= false ;
3196 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3199 child
= node
->GetData();
3200 child
->MacSuperChangedPosition() ;
3202 node
= node
->GetNext();
3206 void wxWindowMac::MacTopLevelWindowChangedPosition()
3208 // only screen-absolute structures have to be moved i.e. glcanvas
3211 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3214 child
= node
->GetData();
3215 child
->MacTopLevelWindowChangedPosition() ;
3217 node
= node
->GetNext();
3221 long wxWindowMac::MacGetLeftBorderSize() const
3228 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3230 // this metric is only the 'outset' outside the simple frame rect
3231 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3234 else if (HasFlag(wxSIMPLE_BORDER
))
3236 // this metric is only the 'outset' outside the simple frame rect
3237 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3244 long wxWindowMac::MacGetRightBorderSize() const
3246 // they are all symmetric in mac themes
3247 return MacGetLeftBorderSize() ;
3250 long wxWindowMac::MacGetTopBorderSize() const
3252 // they are all symmetric in mac themes
3253 return MacGetLeftBorderSize() ;
3256 long wxWindowMac::MacGetBottomBorderSize() const
3258 // they are all symmetric in mac themes
3259 return MacGetLeftBorderSize() ;
3262 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3264 return style
& ~wxBORDER_MASK
;
3267 // Find the wxWindowMac at the current mouse position, returning the mouse
3269 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3271 pt
= wxGetMousePosition();
3272 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3277 // Get the current mouse position.
3278 wxPoint
wxGetMousePosition()
3282 wxGetMousePosition( &x
, &y
);
3284 return wxPoint(x
, y
);
3287 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3289 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3291 // copied from wxGTK : CS
3292 // VZ: shouldn't we move this to base class then?
3294 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3297 // (a) it's a command event and so is propagated to the parent
3298 // (b) under MSW it can be generated from kbd too
3299 // (c) it uses screen coords (because of (a))
3300 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3302 this->ClientToScreen(event
.GetPosition()));
3303 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3312 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3314 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3315 CallNextEventHandler(
3316 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3317 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3320 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3324 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3328 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3329 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3334 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3336 return eventNotHandledErr
;
3339 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3341 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3342 if ( !wxWindowBase::Reparent(newParent
) )
3345 // copied from MacPostControlCreate
3346 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3348 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3350 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3355 bool wxWindowMac::SetTransparent(wxByte alpha
)
3357 #if wxMAC_USE_CORE_GRAPHICS
3358 if ( alpha
!= m_macAlpha
)
3360 m_macAlpha
= alpha
;
3370 bool wxWindowMac::CanSetTransparent()
3372 #if wxMAC_USE_CORE_GRAPHICS
3379 wxByte
wxWindowMac::GetTransparent() const