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
) ;
256 wxWindow
* iter
= thisWindow
;
259 alpha
*= (float) iter
->GetTransparent()/255.0 ;
260 if ( iter
->IsTopLevel() )
263 iter
= iter
->GetParent() ;
266 CGContextSetAlpha( cgContext
, alpha
) ;
268 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
271 #if wxMAC_USE_CORE_GRAPHICS
272 thisWindow
->MacSetCGContextRef( NULL
) ;
276 CGContextRelease( cgContext
) ;
281 DisposeRgn( allocatedRgn
) ;
285 case kEventControlVisibilityChanged
:
286 thisWindow
->MacVisibilityChanged() ;
289 case kEventControlEnabledStateChanged
:
290 thisWindow
->MacEnabledStateChanged() ;
293 case kEventControlHiliteChanged
:
294 thisWindow
->MacHiliteChanged() ;
298 // we emulate this event under Carbon CFM
299 case kEventControlSetFocusPart
:
301 Boolean focusEverything
= false ;
302 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
305 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
310 if ( controlPart
== kControlFocusNoPart
)
313 if ( thisWindow
->GetCaret() )
314 thisWindow
->GetCaret()->OnKillFocus();
317 static bool inKillFocusEvent
= false ;
319 if ( !inKillFocusEvent
)
321 inKillFocusEvent
= true ;
322 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
323 event
.SetEventObject(thisWindow
);
324 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
325 inKillFocusEvent
= false ;
330 // panel wants to track the window which was the last to have focus in it
331 wxChildFocusEvent
eventFocus(thisWindow
);
332 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
335 if ( thisWindow
->GetCaret() )
336 thisWindow
->GetCaret()->OnSetFocus();
339 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
340 event
.SetEventObject(thisWindow
);
341 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
344 if ( thisWindow
->MacIsUserPane() )
349 case kEventControlHit
:
350 result
= thisWindow
->MacControlHit( handler
, event
) ;
360 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
362 OSStatus result
= eventNotHandledErr
;
364 wxMacCarbonEvent
cEvent( event
) ;
366 ControlRef controlRef
;
367 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
368 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
369 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
371 switch ( GetEventKind( event
) )
373 case kEventServiceGetTypes
:
377 textCtrl
->GetSelection( &from
, &to
) ;
379 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
381 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
382 if ( textCtrl
->IsEditable() )
383 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
385 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
386 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
388 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
392 CFArrayAppendValue(copyTypes
, typestring
) ;
394 CFArrayAppendValue(pasteTypes
, typestring
) ;
396 CFRelease( typestring
) ;
404 case kEventServiceCopy
:
409 textCtrl
->GetSelection( &from
, &to
) ;
410 wxString val
= textCtrl
->GetValue() ;
411 val
= val
.Mid( from
, to
- from
) ;
412 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
413 verify_noerr( ClearScrap( &scrapRef
) ) ;
414 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
419 case kEventServicePaste
:
422 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
423 Size textSize
, pastedSize
;
424 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
426 char *content
= new char[textSize
] ;
427 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
428 content
[textSize
- 1] = 0 ;
431 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
433 textCtrl
->WriteText( wxString( content
) ) ;
448 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
450 OSStatus result
= eventNotHandledErr
;
451 wxWindowMac
* focus
= (wxWindowMac
*) data
;
453 wchar_t* uniChars
= NULL
;
454 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
456 UniChar
* charBuf
= NULL
;
457 ByteCount dataSize
= 0 ;
460 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
462 numChars
= dataSize
/ sizeof( UniChar
) + 1;
465 if ( (size_t) numChars
* 2 > sizeof(buf
) )
466 charBuf
= new UniChar
[ numChars
] ;
470 uniChars
= new wchar_t[ numChars
] ;
471 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
472 charBuf
[ numChars
- 1 ] = 0;
473 #if SIZEOF_WCHAR_T == 2
474 uniChars
= (wchar_t*) charBuf
;
475 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
477 // the resulting string will never have more chars than the utf16 version, so this is safe
478 wxMBConvUTF16 converter
;
479 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
483 switch ( GetEventKind( event
) )
485 case kEventTextInputUpdateActiveInputArea
:
487 // An IME input event may return several characters, but we need to send one char at a time to
489 for (int pos
=0 ; pos
< numChars
; pos
++)
491 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
492 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
493 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
495 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
496 if ( wxTheApp
->MacSendCharEvent(
497 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
502 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
506 case kEventTextInputUnicodeForKeyEvent
:
508 UInt32 keyCode
, modifiers
;
511 unsigned char charCode
;
513 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
514 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
515 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
516 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
517 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
519 UInt32 message
= (keyCode
<< 8) + charCode
;
521 // An IME input event may return several characters, but we need to send one char at a time to
523 for (int pos
=0 ; pos
< numChars
; pos
++)
525 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
526 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
527 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
529 if ( wxTheApp
->MacSendCharEvent(
530 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
535 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
544 if ( charBuf
!= buf
)
550 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
552 OSStatus result
= eventNotHandledErr
;
553 wxWindowMac
* focus
= (wxWindowMac
*) data
;
557 wxMacCarbonEvent
cEvent( event
) ;
558 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
560 wxMenuItem
* item
= NULL
;
561 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
562 int id
= wxMacCommandToId( command
.commandID
) ;
566 wxASSERT( itemMenu
!= NULL
) ;
568 switch ( cEvent
.GetKind() )
570 case kEventProcessCommand
:
572 if (item
->IsCheckable())
573 item
->Check( !item
->IsChecked() ) ;
575 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
579 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
580 event
.SetEventObject(focus
);
581 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
583 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
589 case kEventCommandUpdateStatus
:
591 wxUpdateUIEvent
event(id
);
592 event
.SetEventObject( itemMenu
);
594 bool processed
= false;
596 // Try the menu's event handler
598 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
600 processed
= handler
->ProcessEvent(event
);
603 // Try the window the menu was popped up from
604 // (and up through the hierarchy)
607 const wxMenuBase
*menu
= itemMenu
;
610 wxWindow
*win
= menu
->GetInvokingWindow();
613 processed
= win
->GetEventHandler()->ProcessEvent(event
);
617 menu
= menu
->GetParent();
623 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
628 // if anything changed, update the changed attribute
629 if (event
.GetSetText())
630 itemMenu
->SetLabel(id
, event
.GetText());
631 if (event
.GetSetChecked())
632 itemMenu
->Check(id
, event
.GetChecked());
633 if (event
.GetSetEnabled())
634 itemMenu
->Enable(id
, event
.GetEnabled());
648 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
650 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
651 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
652 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
653 OSStatus result
= eventNotHandledErr
;
655 switch ( GetEventClass( event
) )
657 case kEventClassCommand
:
658 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
661 case kEventClassControl
:
662 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
665 case kEventClassService
:
666 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
669 case kEventClassTextInput
:
670 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
677 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
682 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
684 #if !TARGET_API_MAC_OSX
686 // ---------------------------------------------------------------------------
687 // UserPane events for non OSX builds
688 // ---------------------------------------------------------------------------
690 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
692 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
694 win
->MacControlUserPaneDrawProc(part
) ;
696 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
698 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
700 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
702 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
704 return kControlNoPart
;
706 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
708 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
710 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
712 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
714 return kControlNoPart
;
716 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
718 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
720 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
722 win
->MacControlUserPaneIdleProc() ;
724 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
726 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
728 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
730 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
732 return kControlNoPart
;
734 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
736 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
738 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
740 win
->MacControlUserPaneActivateProc(activating
) ;
742 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
744 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
746 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
748 return win
->MacControlUserPaneFocusProc(action
) ;
750 return kControlNoPart
;
752 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
754 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
756 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
758 win
->MacControlUserPaneBackgroundProc(info
) ;
760 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
762 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
765 RgnHandle rgn
= NewRgn() ;
767 MacWindowToRootWindow( &x
, &y
) ;
768 OffsetRgn( rgn
, -x
, -y
) ;
769 wxMacWindowStateSaver
sv( this ) ;
770 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
771 MacDoRedraw( rgn
, 0 ) ;
775 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
777 return kControlNoPart
;
780 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
782 return kControlNoPart
;
785 void wxWindowMac::MacControlUserPaneIdleProc()
789 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
791 return kControlNoPart
;
794 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
798 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
800 if ( AcceptsFocus() )
803 return kControlNoPart
;
806 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
812 // ---------------------------------------------------------------------------
813 // Scrollbar Tracking for all
814 // ---------------------------------------------------------------------------
816 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
817 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
821 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
823 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
826 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
828 // ===========================================================================
830 // ===========================================================================
832 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
834 static MacControlMap wxWinMacControlList
;
836 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
838 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
840 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
843 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
845 // adding NULL ControlRef is (first) surely a result of an error and
846 // (secondly) breaks native event processing
847 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
849 wxWinMacControlList
[inControl
] = control
;
852 void wxRemoveMacControlAssociation(wxWindow
*control
)
854 // iterate over all the elements in the class
855 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
856 // we should go on...
862 MacControlMap::iterator it
;
863 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
865 if ( it
->second
== control
)
867 wxWinMacControlList
.erase(it
);
875 // ----------------------------------------------------------------------------
876 // constructors and such
877 // ----------------------------------------------------------------------------
879 wxWindowMac::wxWindowMac()
884 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
889 const wxString
& name
)
892 Create(parent
, id
, pos
, size
, style
, name
);
895 void wxWindowMac::Init()
901 #if WXWIN_COMPATIBILITY_2_4
902 m_backgroundTransparent
= false;
905 #if wxMAC_USE_CORE_GRAPHICS
906 m_cgContextRef
= NULL
;
909 // as all windows are created with WS_VISIBLE style...
912 m_hScrollBar
= NULL
;
913 m_vScrollBar
= NULL
;
914 m_macBackgroundBrush
= wxNullBrush
;
916 m_macIsUserPane
= true;
917 m_clipChildren
= false ;
918 m_cachedClippedRectValid
= false ;
920 // we need a valid font for the encodings
921 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
924 wxWindowMac::~wxWindowMac()
928 m_isBeingDeleted
= true;
930 MacInvalidateBorders() ;
932 #ifndef __WXUNIVERSAL__
933 // VS: make sure there's no wxFrame with last focus set to us:
934 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
936 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
939 if ( frame
->GetLastFocus() == this )
940 frame
->SetLastFocus((wxWindow
*)NULL
);
946 // destroy children before destroying this window itself
949 // wxRemoveMacControlAssociation( this ) ;
950 // If we delete an item, we should initialize the parent panel,
951 // because it could now be invalid.
952 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
955 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
956 tlw
->SetDefaultItem(NULL
);
959 if ( m_peer
&& m_peer
->Ok() )
961 // in case the callback might be called during destruction
962 wxRemoveMacControlAssociation( this) ;
963 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
964 // we currently are not using this hook
965 // ::SetControlColorProc( *m_peer , NULL ) ;
969 if ( g_MacLastWindow
== this )
970 g_MacLastWindow
= NULL
;
972 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
975 if ( frame
->GetLastFocus() == this )
976 frame
->SetLastFocus( NULL
) ;
979 // delete our drop target if we've got one
980 #if wxUSE_DRAG_AND_DROP
981 if ( m_dropTarget
!= NULL
)
991 WXWidget
wxWindowMac::GetHandle() const
993 return (WXWidget
) m_peer
->GetControlRef() ;
996 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
998 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
999 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1000 GetEventTypeCount(eventList
), eventList
, this,
1001 (EventHandlerRef
*)&m_macControlEventHandler
);
1003 #if !TARGET_API_MAC_OSX
1004 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1006 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1007 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1008 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1009 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1010 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1011 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1012 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1013 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1019 bool wxWindowMac::Create(wxWindowMac
*parent
,
1024 const wxString
& name
)
1026 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1028 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1031 m_windowVariant
= parent
->GetWindowVariant() ;
1033 if ( m_macIsUserPane
)
1035 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1038 | kControlSupportsEmbedding
1039 | kControlSupportsLiveFeedback
1040 | kControlGetsFocusOnClick
1041 // | kControlHasSpecialBackground
1042 // | kControlSupportsCalcBestRect
1043 | kControlHandlesTracking
1044 | kControlSupportsFocus
1045 | kControlWantsActivate
1046 | kControlWantsIdle
;
1048 m_peer
= new wxMacControl(this) ;
1049 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1050 verify_noerr( err
);
1052 MacPostControlCreate(pos
, size
) ;
1055 #ifndef __WXUNIVERSAL__
1056 // Don't give scrollbars to wxControls unless they ask for them
1057 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1058 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1060 MacCreateScrollBars( style
) ;
1064 wxWindowCreateEvent
event(this);
1065 GetEventHandler()->AddPendingEvent(event
);
1070 void wxWindowMac::MacChildAdded()
1073 m_vScrollBar
->Raise() ;
1075 m_hScrollBar
->Raise() ;
1078 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1080 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1082 m_peer
->SetReference( (URefCon
) this ) ;
1083 GetParent()->AddChild( this );
1085 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1087 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1088 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1089 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1090 GetParent()->MacChildAdded() ;
1092 // adjust font, controlsize etc
1093 DoSetWindowVariant( m_windowVariant
) ;
1095 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1097 if (!m_macIsUserPane
)
1098 SetInitialBestSize(size
);
1100 SetCursor( *wxSTANDARD_CURSOR
) ;
1103 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1105 // Don't assert, in case we set the window variant before
1106 // the window is created
1107 // wxASSERT( m_peer->Ok() ) ;
1109 m_windowVariant
= variant
;
1111 if (m_peer
== NULL
|| !m_peer
->Ok())
1115 ThemeFontID themeFont
= kThemeSystemFont
;
1117 // we will get that from the settings later
1118 // and make this NORMAL later, but first
1119 // we have a few calculations that we must fix
1123 case wxWINDOW_VARIANT_NORMAL
:
1124 size
= kControlSizeNormal
;
1125 themeFont
= kThemeSystemFont
;
1128 case wxWINDOW_VARIANT_SMALL
:
1129 size
= kControlSizeSmall
;
1130 themeFont
= kThemeSmallSystemFont
;
1133 case wxWINDOW_VARIANT_MINI
:
1134 if (UMAGetSystemVersion() >= 0x1030 )
1136 // not always defined in the headers
1142 size
= kControlSizeSmall
;
1143 themeFont
= kThemeSmallSystemFont
;
1147 case wxWINDOW_VARIANT_LARGE
:
1148 size
= kControlSizeLarge
;
1149 themeFont
= kThemeSystemFont
;
1153 wxFAIL_MSG(_T("unexpected window variant"));
1157 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1160 font
.MacCreateThemeFont( themeFont
) ;
1164 void wxWindowMac::MacUpdateControlFont()
1166 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1170 bool wxWindowMac::SetFont(const wxFont
& font
)
1172 bool retval
= wxWindowBase::SetFont( font
);
1174 MacUpdateControlFont() ;
1179 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1181 bool retval
= wxWindowBase::SetForegroundColour( col
);
1184 MacUpdateControlFont();
1189 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1191 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1195 wxColour
newCol(GetBackgroundColour());
1197 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1198 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1199 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1200 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1202 brush
.SetColour( newCol
) ;
1204 MacSetBackgroundBrush( brush
) ;
1205 MacUpdateControlFont() ;
1210 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1212 m_macBackgroundBrush
= brush
;
1213 m_peer
->SetBackground( brush
) ;
1216 bool wxWindowMac::MacCanFocus() const
1218 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1219 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1220 // but the value range is nowhere documented
1221 Boolean keyExistsAndHasValidFormat
;
1222 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1223 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1225 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1231 UInt32 features
= 0 ;
1232 m_peer
->GetFeatures( &features
) ;
1234 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1238 void wxWindowMac::SetFocus()
1240 if ( !AcceptsFocus() )
1243 wxWindow
* former
= FindFocus() ;
1244 if ( former
== this )
1247 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1248 // we can only leave in case of an error
1249 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1250 if ( err
== errCouldntSetFocus
)
1253 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1255 #if !TARGET_API_MAC_OSX
1256 // emulate carbon events when running under CarbonLib where they are not natively available
1259 EventRef evRef
= NULL
;
1261 err
= MacCreateEvent(
1262 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1263 kEventAttributeUserEvent
, &evRef
);
1264 verify_noerr( err
);
1266 wxMacCarbonEvent
cEvent( evRef
) ;
1267 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1268 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1270 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1271 ReleaseEvent( evRef
) ;
1274 // send new focus event
1276 EventRef evRef
= NULL
;
1278 err
= MacCreateEvent(
1279 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1280 kEventAttributeUserEvent
, &evRef
);
1281 verify_noerr( err
);
1283 wxMacCarbonEvent
cEvent( evRef
) ;
1284 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1285 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1287 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1288 ReleaseEvent( evRef
) ;
1293 void wxWindowMac::DoCaptureMouse()
1295 wxApp::s_captureWindow
= this ;
1298 wxWindow
* wxWindowBase::GetCapture()
1300 return wxApp::s_captureWindow
;
1303 void wxWindowMac::DoReleaseMouse()
1305 wxApp::s_captureWindow
= NULL
;
1308 #if wxUSE_DRAG_AND_DROP
1310 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1312 if ( m_dropTarget
!= NULL
)
1313 delete m_dropTarget
;
1315 m_dropTarget
= pDropTarget
;
1316 if ( m_dropTarget
!= NULL
)
1324 // Old-style File Manager Drag & Drop
1325 void wxWindowMac::DragAcceptFiles(bool accept
)
1330 // Returns the size of the native control. In the case of the toplevel window
1331 // this is the content area root control
1333 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1334 int& w
, int& h
) const
1336 wxFAIL_MSG( wxT("Not currently supported") ) ;
1339 // From a wx position / size calculate the appropriate size of the native control
1341 bool wxWindowMac::MacGetBoundsForControl(
1345 int& w
, int& h
, bool adjustOrigin
) const
1347 // the desired size, minus the border pixels gives the correct size of the control
1351 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1352 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1353 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1355 x
+= MacGetLeftBorderSize() ;
1356 y
+= MacGetTopBorderSize() ;
1357 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1358 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1361 AdjustForParentClientOrigin( x
, y
) ;
1363 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1364 if ( !GetParent()->IsTopLevel() )
1366 x
-= GetParent()->MacGetLeftBorderSize() ;
1367 y
-= GetParent()->MacGetTopBorderSize() ;
1373 // Get window size (not client size)
1374 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1377 m_peer
->GetRect( &bounds
) ;
1380 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1382 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1385 // get the position of the bounds of this window in client coordinates of its parent
1386 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1389 m_peer
->GetRect( &bounds
) ;
1391 int x1
= bounds
.left
;
1392 int y1
= bounds
.top
;
1394 // get the wx window position from the native one
1395 x1
-= MacGetLeftBorderSize() ;
1396 y1
-= MacGetTopBorderSize() ;
1398 if ( !IsTopLevel() )
1400 wxWindow
*parent
= GetParent();
1403 // we must first adjust it to be in window coordinates of the parent,
1404 // as otherwise it gets lost by the ClientAreaOrigin fix
1405 x1
+= parent
->MacGetLeftBorderSize() ;
1406 y1
+= parent
->MacGetTopBorderSize() ;
1408 // and now to client coordinates
1409 wxPoint
pt(parent
->GetClientAreaOrigin());
1421 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1423 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1424 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1426 Point localwhere
= { 0, 0 } ;
1433 wxMacGlobalToLocal( window
, &localwhere
) ;
1440 MacRootWindowToWindow( x
, y
) ;
1442 wxPoint origin
= GetClientAreaOrigin() ;
1449 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1451 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1452 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1454 wxPoint origin
= GetClientAreaOrigin() ;
1460 MacWindowToRootWindow( x
, y
) ;
1462 Point localwhere
= { 0, 0 };
1468 wxMacLocalToGlobal( window
, &localwhere
) ;
1476 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1478 wxPoint origin
= GetClientAreaOrigin() ;
1484 MacWindowToRootWindow( x
, y
) ;
1487 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1489 MacRootWindowToWindow( x
, y
) ;
1491 wxPoint origin
= GetClientAreaOrigin() ;
1498 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1507 if ( !IsTopLevel() )
1509 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1512 pt
.x
-= MacGetLeftBorderSize() ;
1513 pt
.y
-= MacGetTopBorderSize() ;
1514 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1524 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1533 MacWindowToRootWindow( &x1
, &y1
) ;
1541 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1550 if ( !IsTopLevel() )
1552 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1555 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1556 pt
.x
+= MacGetLeftBorderSize() ;
1557 pt
.y
+= MacGetTopBorderSize() ;
1567 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1576 MacRootWindowToWindow( &x1
, &y1
) ;
1584 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1586 RgnHandle rgn
= NewRgn() ;
1588 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1590 Rect structure
, content
;
1592 GetRegionBounds( rgn
, &content
) ;
1593 m_peer
->GetRect( &structure
) ;
1594 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1596 left
= content
.left
- structure
.left
;
1597 top
= content
.top
- structure
.top
;
1598 right
= structure
.right
- content
.right
;
1599 bottom
= structure
.bottom
- content
.bottom
;
1603 left
= top
= right
= bottom
= 0 ;
1609 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1611 wxSize sizeTotal
= size
;
1613 RgnHandle rgn
= NewRgn() ;
1614 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1616 Rect content
, structure
;
1617 GetRegionBounds( rgn
, &content
) ;
1618 m_peer
->GetRect( &structure
) ;
1620 // structure is in parent coordinates, but we only need width and height, so it's ok
1622 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1623 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1628 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1629 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1634 // Get size *available for subwindows* i.e. excluding menu bar etc.
1635 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1639 RgnHandle rgn
= NewRgn() ;
1641 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1642 GetRegionBounds( rgn
, &content
) ;
1644 m_peer
->GetRect( &content
) ;
1647 ww
= content
.right
- content
.left
;
1648 hh
= content
.bottom
- content
.top
;
1650 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1651 hh
-= m_hScrollBar
->GetSize().y
;
1653 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1654 ww
-= m_vScrollBar
->GetSize().x
;
1662 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1664 if (m_cursor
.IsSameAs(cursor
))
1669 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1674 if ( ! wxWindowBase::SetCursor( cursor
) )
1678 wxASSERT_MSG( m_cursor
.Ok(),
1679 wxT("cursor must be valid after call to the base version"));
1681 wxWindowMac
*mouseWin
= 0 ;
1683 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1684 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1686 ControlPartCode part
;
1687 ControlRef control
;
1689 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1691 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1696 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1698 // TODO: If we ever get a GetCurrentEvent... replacement
1699 // for the mouse position, use it...
1704 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1706 mouseWin
= wxFindControlFromMacControl( control
) ;
1708 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1710 QDSwapPort( savePort
, NULL
) ;
1714 if ( mouseWin
== this && !wxIsBusy() )
1715 m_cursor
.MacInstall() ;
1721 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1723 menu
->SetInvokingWindow(this);
1726 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1728 wxPoint mouse
= wxGetMousePosition();
1734 ClientToScreen( &x
, &y
) ;
1737 menu
->MacBeforeDisplay( true ) ;
1738 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1739 if ( HiWord(menuResult
) != 0 )
1742 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1743 int id
= wxMacCommandToId( macid
);
1744 wxMenuItem
* item
= NULL
;
1746 item
= menu
->FindItem( id
, &realmenu
) ;
1749 if (item
->IsCheckable())
1750 item
->Check( !item
->IsChecked() ) ;
1752 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1756 menu
->MacAfterDisplay( true ) ;
1757 menu
->SetInvokingWindow( NULL
);
1763 // ----------------------------------------------------------------------------
1765 // ----------------------------------------------------------------------------
1769 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1771 wxWindowBase::DoSetToolTip(tooltip
);
1774 m_tooltip
->SetWindow(this);
1779 void wxWindowMac::MacInvalidateBorders()
1781 if ( m_peer
== NULL
)
1784 bool vis
= MacIsReallyShown() ;
1788 int outerBorder
= MacGetLeftBorderSize() ;
1789 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1792 if ( outerBorder
== 0 )
1795 // now we know that we have something to do at all
1797 // as the borders are drawn on the parent we have to properly invalidate all these areas
1798 RgnHandle updateInner
, updateOuter
;
1801 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1802 updateInner
= NewRgn() ;
1803 updateOuter
= NewRgn() ;
1805 m_peer
->GetRect( &rect
) ;
1806 RectRgn( updateInner
, &rect
) ;
1807 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1808 RectRgn( updateOuter
, &rect
) ;
1809 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1811 #ifdef __WXMAC_OSX__
1812 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1814 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1816 InvalWindowRgn( tlw
, updateOuter
) ;
1819 DisposeRgn( updateOuter
) ;
1820 DisposeRgn( updateInner
) ;
1823 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1825 // this is never called for a toplevel window, so we know we have a parent
1826 int former_x
, former_y
, former_w
, former_h
;
1828 // Get true coordinates of former position
1829 DoGetPosition( &former_x
, &former_y
) ;
1830 DoGetSize( &former_w
, &former_h
) ;
1832 wxWindow
*parent
= GetParent();
1835 wxPoint
pt(parent
->GetClientAreaOrigin());
1840 int actualWidth
= width
;
1841 int actualHeight
= height
;
1845 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1846 actualWidth
= m_minWidth
;
1847 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1848 actualHeight
= m_minHeight
;
1849 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1850 actualWidth
= m_maxWidth
;
1851 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1852 actualHeight
= m_maxHeight
;
1854 bool doMove
= false, doResize
= false ;
1856 if ( actualX
!= former_x
|| actualY
!= former_y
)
1859 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1862 if ( doMove
|| doResize
)
1864 // as the borders are drawn outside the native control, we adjust now
1866 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1867 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1868 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1871 wxMacRectToNative( &bounds
, &r
) ;
1873 if ( !GetParent()->IsTopLevel() )
1874 wxMacWindowToNative( GetParent() , &r
) ;
1876 MacInvalidateBorders() ;
1878 m_cachedClippedRectValid
= false ;
1879 m_peer
->SetRect( &r
) ;
1881 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1883 MacInvalidateBorders() ;
1885 MacRepositionScrollBars() ;
1888 wxPoint
point(actualX
, actualY
);
1889 wxMoveEvent
event(point
, m_windowId
);
1890 event
.SetEventObject(this);
1891 GetEventHandler()->ProcessEvent(event
) ;
1896 MacRepositionScrollBars() ;
1897 wxSize
size(actualWidth
, actualHeight
);
1898 wxSizeEvent
event(size
, m_windowId
);
1899 event
.SetEventObject(this);
1900 GetEventHandler()->ProcessEvent(event
);
1905 wxSize
wxWindowMac::DoGetBestSize() const
1907 if ( m_macIsUserPane
|| IsTopLevel() )
1908 return wxWindowBase::DoGetBestSize() ;
1910 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1911 int bestWidth
, bestHeight
;
1913 m_peer
->GetBestRect( &bestsize
) ;
1914 if ( EmptyRect( &bestsize
) )
1919 bestsize
.bottom
= 16 ;
1921 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1923 bestsize
.bottom
= 16 ;
1926 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1928 bestsize
.bottom
= 24 ;
1933 // return wxWindowBase::DoGetBestSize() ;
1937 bestWidth
= bestsize
.right
- bestsize
.left
;
1938 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1939 if ( bestHeight
< 10 )
1942 return wxSize(bestWidth
, bestHeight
);
1945 // set the size of the window: if the dimensions are positive, just use them,
1946 // but if any of them is equal to -1, it means that we must find the value for
1947 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1948 // which case -1 is a valid value for x and y)
1950 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1951 // the width/height to best suit our contents, otherwise we reuse the current
1953 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1955 // get the current size and position...
1956 int currentX
, currentY
;
1957 int currentW
, currentH
;
1959 GetPosition(¤tX
, ¤tY
);
1960 GetSize(¤tW
, ¤tH
);
1962 // ... and don't do anything (avoiding flicker) if it's already ok
1963 if ( x
== currentX
&& y
== currentY
&&
1964 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1967 MacRepositionScrollBars() ; // we might have a real position shift
1972 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1974 if ( x
== wxDefaultCoord
)
1976 if ( y
== wxDefaultCoord
)
1980 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1982 wxSize size
= wxDefaultSize
;
1983 if ( width
== wxDefaultCoord
)
1985 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1987 size
= DoGetBestSize();
1992 // just take the current one
1997 if ( height
== wxDefaultCoord
)
1999 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2001 if ( size
.x
== wxDefaultCoord
)
2002 size
= DoGetBestSize();
2003 // else: already called DoGetBestSize() above
2009 // just take the current one
2014 DoMoveWindow( x
, y
, width
, height
);
2017 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2019 RgnHandle rgn
= NewRgn() ;
2021 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2023 GetRegionBounds( rgn
, &content
) ;
2033 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2036 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2038 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2040 int currentclientwidth
, currentclientheight
;
2041 int currentwidth
, currentheight
;
2043 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2044 GetSize( ¤twidth
, ¤theight
) ;
2046 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2047 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2051 void wxWindowMac::SetLabel(const wxString
& title
)
2053 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2055 if ( m_peer
&& m_peer
->Ok() )
2056 m_peer
->SetLabel( m_label
) ;
2061 wxString
wxWindowMac::GetLabel() const
2066 bool wxWindowMac::Show(bool show
)
2068 bool former
= MacIsReallyShown() ;
2069 if ( !wxWindowBase::Show(show
) )
2072 // TODO: use visibilityChanged Carbon Event for OSX
2074 m_peer
->SetVisibility( show
, true ) ;
2076 if ( former
!= MacIsReallyShown() )
2077 MacPropagateVisibilityChanged() ;
2082 bool wxWindowMac::Enable(bool enable
)
2084 wxASSERT( m_peer
->Ok() ) ;
2085 bool former
= MacIsReallyEnabled() ;
2086 if ( !wxWindowBase::Enable(enable
) )
2089 m_peer
->Enable( enable
) ;
2091 if ( former
!= MacIsReallyEnabled() )
2092 MacPropagateEnabledStateChanged() ;
2098 // status change propagations (will be not necessary for OSX later )
2101 void wxWindowMac::MacPropagateVisibilityChanged()
2103 #if !TARGET_API_MAC_OSX
2104 MacVisibilityChanged() ;
2107 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2110 child
= node
->GetData();
2111 if ( child
->IsShown() )
2112 child
->MacPropagateVisibilityChanged() ;
2114 node
= node
->GetNext();
2119 void wxWindowMac::MacPropagateEnabledStateChanged()
2121 #if !TARGET_API_MAC_OSX
2122 MacEnabledStateChanged() ;
2125 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2128 child
= node
->GetData();
2129 if ( child
->IsEnabled() )
2130 child
->MacPropagateEnabledStateChanged() ;
2132 node
= node
->GetNext();
2137 void wxWindowMac::MacPropagateHiliteChanged()
2139 #if !TARGET_API_MAC_OSX
2140 MacHiliteChanged() ;
2143 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2146 child
= node
->GetData();
2147 if (child
/* && child->IsEnabled() */)
2148 child
->MacPropagateHiliteChanged() ;
2150 node
= node
->GetNext();
2156 // status change notifications
2159 void wxWindowMac::MacVisibilityChanged()
2163 void wxWindowMac::MacHiliteChanged()
2167 void wxWindowMac::MacEnabledStateChanged()
2172 // status queries on the inherited window's state
2175 bool wxWindowMac::MacIsReallyShown()
2177 // only under OSX the visibility of the TLW is taken into account
2178 if ( m_isBeingDeleted
)
2181 #if TARGET_API_MAC_OSX
2182 if ( m_peer
&& m_peer
->Ok() )
2183 return m_peer
->IsVisible();
2186 wxWindow
* win
= this ;
2187 while ( win
->IsShown() )
2189 if ( win
->IsTopLevel() )
2192 win
= win
->GetParent() ;
2200 bool wxWindowMac::MacIsReallyEnabled()
2202 return m_peer
->IsEnabled() ;
2205 bool wxWindowMac::MacIsReallyHilited()
2207 return m_peer
->IsActive();
2210 void wxWindowMac::MacFlashInvalidAreas()
2212 #if TARGET_API_MAC_OSX
2213 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2217 int wxWindowMac::GetCharHeight() const
2219 wxClientDC
dc( (wxWindowMac
*)this ) ;
2221 return dc
.GetCharHeight() ;
2224 int wxWindowMac::GetCharWidth() const
2226 wxClientDC
dc( (wxWindowMac
*)this ) ;
2228 return dc
.GetCharWidth() ;
2231 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2232 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2234 const wxFont
*fontToUse
= theFont
;
2236 fontToUse
= &m_font
;
2238 wxClientDC
dc( (wxWindowMac
*) this ) ;
2240 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2241 if ( externalLeading
)
2242 *externalLeading
= le
;
2252 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2253 * we always intersect with the entire window, not only with the client area
2256 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2258 if ( m_peer
== NULL
)
2261 if ( !MacIsReallyShown() )
2268 wxMacRectToNative( rect
, &r
) ;
2269 m_peer
->SetNeedsDisplay( &r
) ;
2273 m_peer
->SetNeedsDisplay() ;
2277 void wxWindowMac::Freeze()
2279 #if TARGET_API_MAC_OSX
2280 if ( !m_frozenness
++ )
2282 if ( m_peer
&& m_peer
->Ok() )
2283 m_peer
->SetDrawingEnabled( false ) ;
2288 void wxWindowMac::Thaw()
2290 #if TARGET_API_MAC_OSX
2291 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2293 if ( !--m_frozenness
)
2295 if ( m_peer
&& m_peer
->Ok() )
2297 m_peer
->SetDrawingEnabled( true ) ;
2298 m_peer
->InvalidateWithChildren() ;
2304 bool wxWindowMac::IsFrozen() const
2306 return m_frozenness
!= 0;
2309 wxWindowMac
*wxGetActiveWindow()
2311 // actually this is a windows-only concept
2315 // Coordinates relative to the window
2316 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2318 // We really don't move the mouse programmatically under Mac.
2321 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2323 if ( MacGetTopLevelWindow() == NULL
)
2326 #if TARGET_API_MAC_OSX
2327 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2334 event
.GetDC()->Clear() ;
2338 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2343 int wxWindowMac::GetScrollPos(int orient
) const
2345 if ( orient
== wxHORIZONTAL
)
2348 return m_hScrollBar
->GetThumbPosition() ;
2353 return m_vScrollBar
->GetThumbPosition() ;
2359 // This now returns the whole range, not just the number
2360 // of positions that we can scroll.
2361 int wxWindowMac::GetScrollRange(int orient
) const
2363 if ( orient
== wxHORIZONTAL
)
2366 return m_hScrollBar
->GetRange() ;
2371 return m_vScrollBar
->GetRange() ;
2377 int wxWindowMac::GetScrollThumb(int orient
) const
2379 if ( orient
== wxHORIZONTAL
)
2382 return m_hScrollBar
->GetThumbSize() ;
2387 return m_vScrollBar
->GetThumbSize() ;
2393 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2395 if ( orient
== wxHORIZONTAL
)
2398 m_hScrollBar
->SetThumbPosition( pos
) ;
2403 m_vScrollBar
->SetThumbPosition( pos
) ;
2408 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2409 // our own window origin is at leftOrigin/rightOrigin
2412 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2418 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2419 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2421 // back to the surrounding frame rectangle
2422 m_peer
->GetRect( &rect
) ;
2423 InsetRect( &rect
, -1 , -1 ) ;
2425 #if wxMAC_USE_CORE_GRAPHICS
2427 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2428 rect
.bottom
- rect
.top
) ;
2430 HIThemeFrameDrawInfo info
;
2431 memset( &info
, 0 , sizeof(info
) ) ;
2435 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2436 info
.isFocused
= hasFocus
;
2438 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2439 wxASSERT( cgContext
) ;
2441 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2443 info
.kind
= kHIThemeFrameTextFieldSquare
;
2444 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2446 else if ( HasFlag(wxSIMPLE_BORDER
) )
2448 info
.kind
= kHIThemeFrameListBox
;
2449 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2451 else if ( hasFocus
)
2453 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2456 m_peer
->GetRect( &rect
) ;
2457 if ( hasBothScrollbars
)
2459 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2460 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2461 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2462 HIThemeGrowBoxDrawInfo info
;
2463 memset( &info
, 0, sizeof(info
) ) ;
2465 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2466 info
.kind
= kHIThemeGrowBoxKindNone
;
2467 info
.size
= kHIThemeGrowBoxSizeNormal
;
2468 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2469 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2474 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2478 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2479 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2482 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2483 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2484 else if ( HasFlag(wxSIMPLE_BORDER
) )
2485 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2488 DrawThemeFocusRect( &rect
, true ) ;
2490 if ( hasBothScrollbars
)
2492 // GetThemeStandaloneGrowBoxBounds
2493 // DrawThemeStandaloneNoGrowBox
2499 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2501 if ( child
== m_hScrollBar
)
2502 m_hScrollBar
= NULL
;
2503 if ( child
== m_vScrollBar
)
2504 m_vScrollBar
= NULL
;
2506 wxWindowBase::RemoveChild( child
) ;
2509 // New function that will replace some of the above.
2510 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2511 int range
, bool refresh
)
2514 bool triggerSizeEvent
= false;
2516 if ( orient
== wxHORIZONTAL
)
2520 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2521 if ( m_hScrollBar
->IsShown() != showScroller
)
2523 m_hScrollBar
->Show( showScroller
);
2524 triggerSizeEvent
= true;
2527 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2534 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2535 if ( m_vScrollBar
->IsShown() != showScroller
)
2537 m_vScrollBar
->Show( showScroller
) ;
2538 triggerSizeEvent
= true;
2541 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2545 MacRepositionScrollBars() ;
2546 if ( triggerSizeEvent
)
2548 wxSizeEvent
event(GetSize(), m_windowId
);
2549 event
.SetEventObject(this);
2550 GetEventHandler()->ProcessEvent(event
);
2554 // Does a physical scroll
2555 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2557 if ( dx
== 0 && dy
== 0 )
2560 int width
, height
;
2561 GetClientSize( &width
, &height
) ;
2564 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2565 // area is scrolled, this does not occur if width and height are 2 pixels less,
2566 // TODO: write optimal workaround
2567 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2569 scrollrect
.Intersect( *rect
) ;
2571 if ( m_peer
->GetNeedsDisplay() )
2573 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2574 // either immediate redraw or full invalidate
2576 // is the better overall solution, as it does not slow down scrolling
2577 m_peer
->SetNeedsDisplay() ;
2579 // this would be the preferred version for fast drawing controls
2581 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2582 if ( UMAGetSystemVersion() >= 0x1030 )
2583 HIViewRender(m_peer
->GetControlRef()) ;
2590 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2591 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2592 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2594 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2595 // either immediate redraw or full invalidate
2597 // is the better overall solution, as it does not slow down scrolling
2598 m_peer
->SetNeedsDisplay() ;
2600 // this would be the preferred version for fast drawing controls
2602 HIViewRender(m_peer
->GetControlRef()) ;
2608 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2610 child
= node
->GetData();
2613 if (child
== m_vScrollBar
)
2615 if (child
== m_hScrollBar
)
2617 if (child
->IsTopLevel())
2620 child
->GetPosition( &x
, &y
);
2621 child
->GetSize( &w
, &h
);
2624 wxRect
rc( x
, y
, w
, h
);
2625 if (rect
->Intersects( rc
))
2626 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2630 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2635 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2637 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2639 wxScrollWinEvent wevent
;
2640 wevent
.SetPosition(event
.GetPosition());
2641 wevent
.SetOrientation(event
.GetOrientation());
2642 wevent
.SetEventObject(this);
2644 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2645 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2646 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2647 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2648 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2649 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2650 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2651 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2652 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2653 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2654 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2655 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2656 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2657 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2658 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2659 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2661 GetEventHandler()->ProcessEvent(wevent
);
2665 // Get the window with the focus
2666 wxWindowMac
*wxWindowBase::DoFindFocus()
2668 ControlRef control
;
2669 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2670 return wxFindControlFromMacControl( control
) ;
2673 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2675 // panel wants to track the window which was the last to have focus in it,
2676 // so we want to set ourselves as the window which last had focus
2678 // notice that it's also important to do it upwards the tree because
2679 // otherwise when the top level panel gets focus, it won't set it back to
2680 // us, but to some other sibling
2682 // CS: don't know if this is still needed:
2683 //wxChildFocusEvent eventFocus(this);
2684 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2686 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2688 #if wxMAC_USE_CORE_GRAPHICS
2689 GetParent()->Refresh() ;
2691 wxMacWindowStateSaver
sv( this ) ;
2694 m_peer
->GetRect( &rect
) ;
2695 // auf den umgebenden Rahmen zur\9fck
2696 InsetRect( &rect
, -1 , -1 ) ;
2698 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2702 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2704 rect
.right
+= pt
.x
;
2706 rect
.bottom
+= pt
.y
;
2709 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2710 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2711 if ( !bIsFocusEvent
)
2713 // as this erases part of the frame we have to redraw borders
2714 // and because our z-ordering is not always correct (staticboxes)
2715 // we have to invalidate things, we cannot simple redraw
2716 MacInvalidateBorders() ;
2724 void wxWindowMac::OnInternalIdle()
2726 // This calls the UI-update mechanism (querying windows for
2727 // menu/toolbar/control state information)
2728 if (wxUpdateUIEvent::CanUpdate(this))
2729 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2732 // Raise the window to the top of the Z order
2733 void wxWindowMac::Raise()
2735 m_peer
->SetZOrder( true , NULL
) ;
2738 // Lower the window to the bottom of the Z order
2739 void wxWindowMac::Lower()
2741 m_peer
->SetZOrder( false , NULL
) ;
2744 // static wxWindow *gs_lastWhich = NULL;
2746 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2748 // first trigger a set cursor event
2750 wxPoint clientorigin
= GetClientAreaOrigin() ;
2751 wxSize clientsize
= GetClientSize() ;
2753 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2755 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2757 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2758 if ( processedEvtSetCursor
&& event
.HasCursor() )
2760 cursor
= event
.GetCursor() ;
2764 // the test for processedEvtSetCursor is here to prevent using m_cursor
2765 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2766 // it - this is a way to say that our cursor shouldn't be used for this
2768 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2771 if ( !wxIsBusy() && !GetParent() )
2772 cursor
= *wxSTANDARD_CURSOR
;
2776 cursor
.MacInstall() ;
2779 return cursor
.Ok() ;
2782 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2786 return m_tooltip
->GetTip() ;
2789 return wxEmptyString
;
2792 void wxWindowMac::ClearBackground()
2798 void wxWindowMac::Update()
2800 #if TARGET_API_MAC_OSX
2801 MacGetTopLevelWindow()->MacPerformUpdates() ;
2803 ::Draw1Control( m_peer
->GetControlRef() ) ;
2807 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2809 wxTopLevelWindowMac
* win
= NULL
;
2810 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2812 win
= wxFindWinFromMacWindow( window
) ;
2817 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2819 MacUpdateClippedRects() ;
2821 return m_cachedClippedClientRect
;
2824 const wxRect
& wxWindowMac::MacGetClippedRect() const
2826 MacUpdateClippedRects() ;
2828 return m_cachedClippedRect
;
2831 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2833 MacUpdateClippedRects() ;
2835 return m_cachedClippedRectWithOuterStructure
;
2838 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2840 static wxRegion emptyrgn
;
2842 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2844 MacUpdateClippedRects() ;
2845 if ( includeOuterStructures
)
2846 return m_cachedClippedRegionWithOuterStructure
;
2848 return m_cachedClippedRegion
;
2856 void wxWindowMac::MacUpdateClippedRects() const
2858 if ( m_cachedClippedRectValid
)
2861 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2862 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2863 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2864 // to add focus borders everywhere
2866 Rect r
, rIncludingOuterStructures
;
2868 m_peer
->GetRect( &r
) ;
2869 r
.left
-= MacGetLeftBorderSize() ;
2870 r
.top
-= MacGetTopBorderSize() ;
2871 r
.bottom
+= MacGetBottomBorderSize() ;
2872 r
.right
+= MacGetRightBorderSize() ;
2879 rIncludingOuterStructures
= r
;
2880 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2882 wxRect cl
= GetClientRect() ;
2883 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2887 const wxWindow
* child
= this ;
2888 const wxWindow
* parent
= NULL
;
2890 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2892 if ( parent
->MacIsChildOfClientArea(child
) )
2894 size
= parent
->GetClientSize() ;
2895 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2901 // this will be true for scrollbars, toolbars etc.
2902 size
= parent
->GetSize() ;
2903 y
= parent
->MacGetTopBorderSize() ;
2904 x
= parent
->MacGetLeftBorderSize() ;
2905 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2906 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2909 parent
->MacWindowToRootWindow( &x
, &y
) ;
2910 MacRootWindowToWindow( &x
, &y
) ;
2912 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2914 // the wxwindow and client rects will always be clipped
2915 SectRect( &r
, &rparent
, &r
) ;
2916 SectRect( &rClient
, &rparent
, &rClient
) ;
2918 // the structure only at 'hard' borders
2919 if ( parent
->MacClipChildren() ||
2920 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2922 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2928 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2929 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2930 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2931 m_cachedClippedRectWithOuterStructure
= wxRect(
2932 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2933 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2934 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2936 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2937 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2938 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2940 m_cachedClippedRectValid
= true ;
2944 This function must not change the updatergn !
2946 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2948 bool handled
= false ;
2950 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2951 GetRegionBounds( updatergn
, &updatebounds
) ;
2953 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2955 if ( !EmptyRgn(updatergn
) )
2957 RgnHandle newupdate
= NewRgn() ;
2958 wxSize point
= GetClientSize() ;
2959 wxPoint origin
= GetClientAreaOrigin() ;
2960 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2961 SectRgn( newupdate
, updatergn
, newupdate
) ;
2963 // first send an erase event to the entire update area
2965 // for the toplevel window this really is the entire area
2966 // for all the others only their client area, otherwise they
2967 // might be drawing with full alpha and eg put blue into
2968 // the grow-box area of a scrolled window (scroll sample)
2969 wxDC
* dc
= new wxWindowDC(this);
2971 dc
->SetClippingRegion(wxRegion(updatergn
));
2973 dc
->SetClippingRegion(wxRegion(newupdate
));
2975 wxEraseEvent
eevent( GetId(), dc
);
2976 eevent
.SetEventObject( this );
2977 GetEventHandler()->ProcessEvent( eevent
);
2981 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2982 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2983 m_updateRegion
= newupdate
;
2984 DisposeRgn( newupdate
) ;
2986 if ( !m_updateRegion
.Empty() )
2988 // paint the window itself
2991 event
.SetTimestamp(time
);
2992 event
.SetEventObject(this);
2993 GetEventHandler()->ProcessEvent(event
);
2997 // now we cannot rely on having its borders drawn by a window itself, as it does not
2998 // get the updateRgn wide enough to always do so, so we do it from the parent
2999 // this would also be the place to draw any custom backgrounds for native controls
3000 // in Composited windowing
3001 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3005 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3007 child
= node
->GetData();
3010 if (child
== m_vScrollBar
)
3012 if (child
== m_hScrollBar
)
3014 if (child
->IsTopLevel())
3016 if (!child
->IsShown())
3019 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3021 child
->GetPosition( &x
, &y
);
3022 child
->GetSize( &w
, &h
);
3023 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3024 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3025 InsetRect( &childRect
, -10 , -10) ;
3027 if ( RectInRgn( &childRect
, updatergn
) )
3029 // paint custom borders
3030 wxNcPaintEvent
eventNc( child
->GetId() );
3031 eventNc
.SetEventObject( child
);
3032 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3034 #if wxMAC_USE_CORE_GRAPHICS
3035 child
->MacPaintBorders(0, 0) ;
3038 wxWindowDC
dc(this) ;
3039 dc
.SetClippingRegion(wxRegion(updatergn
));
3040 wxMacPortSetter
helper(&dc
) ;
3041 child
->MacPaintBorders(0, 0) ;
3053 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3055 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3059 if ( iter
->IsTopLevel() )
3060 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3062 iter
= iter
->GetParent() ;
3068 void wxWindowMac::MacCreateScrollBars( long style
)
3070 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3072 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3074 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3075 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3076 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3078 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3081 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3083 GetClientSize( &width
, &height
) ;
3085 wxPoint
vPoint(width
- scrlsize
, 0) ;
3086 wxSize
vSize(scrlsize
, height
- adjust
) ;
3087 wxPoint
hPoint(0, height
- scrlsize
) ;
3088 wxSize
hSize(width
- adjust
, scrlsize
) ;
3090 if ( style
& wxVSCROLL
)
3091 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3093 if ( style
& wxHSCROLL
)
3094 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3097 // because the create does not take into account the client area origin
3098 // we might have a real position shift
3099 MacRepositionScrollBars() ;
3102 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3104 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3109 void wxWindowMac::MacRepositionScrollBars()
3111 if ( !m_hScrollBar
&& !m_vScrollBar
)
3114 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3115 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3116 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3118 // get real client area
3120 GetSize( &width
, &height
);
3122 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3123 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3125 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3126 wxSize
vSize( scrlsize
, height
- adjust
) ;
3127 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3128 wxSize
hSize( width
- adjust
, scrlsize
) ;
3131 int x
= 0, y
= 0, w
, h
;
3132 GetSize( &w
, &h
) ;
3134 MacClientToRootWindow( &x
, &y
) ;
3135 MacClientToRootWindow( &w
, &h
) ;
3137 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3139 int totW
= 10000 , totH
= 10000;
3142 if ( iter
->IsTopLevel() )
3144 iter
->GetSize( &totW
, &totH
) ;
3148 iter
= iter
->GetParent() ;
3162 if ( w
- x
>= totW
)
3167 if ( h
- y
>= totH
)
3175 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3177 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3180 bool wxWindowMac::AcceptsFocus() const
3182 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3185 void wxWindowMac::MacSuperChangedPosition()
3187 // only window-absolute structures have to be moved i.e. controls
3189 m_cachedClippedRectValid
= false ;
3192 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3195 child
= node
->GetData();
3196 child
->MacSuperChangedPosition() ;
3198 node
= node
->GetNext();
3202 void wxWindowMac::MacTopLevelWindowChangedPosition()
3204 // only screen-absolute structures have to be moved i.e. glcanvas
3207 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3210 child
= node
->GetData();
3211 child
->MacTopLevelWindowChangedPosition() ;
3213 node
= node
->GetNext();
3217 long wxWindowMac::MacGetLeftBorderSize() const
3224 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3226 // this metric is only the 'outset' outside the simple frame rect
3227 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3230 else if (HasFlag(wxSIMPLE_BORDER
))
3232 // this metric is only the 'outset' outside the simple frame rect
3233 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3240 long wxWindowMac::MacGetRightBorderSize() const
3242 // they are all symmetric in mac themes
3243 return MacGetLeftBorderSize() ;
3246 long wxWindowMac::MacGetTopBorderSize() const
3248 // they are all symmetric in mac themes
3249 return MacGetLeftBorderSize() ;
3252 long wxWindowMac::MacGetBottomBorderSize() const
3254 // they are all symmetric in mac themes
3255 return MacGetLeftBorderSize() ;
3258 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3260 return style
& ~wxBORDER_MASK
;
3263 // Find the wxWindowMac at the current mouse position, returning the mouse
3265 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3267 pt
= wxGetMousePosition();
3268 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3273 // Get the current mouse position.
3274 wxPoint
wxGetMousePosition()
3278 wxGetMousePosition( &x
, &y
);
3280 return wxPoint(x
, y
);
3283 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3285 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3287 // copied from wxGTK : CS
3288 // VZ: shouldn't we move this to base class then?
3290 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3293 // (a) it's a command event and so is propagated to the parent
3294 // (b) under MSW it can be generated from kbd too
3295 // (c) it uses screen coords (because of (a))
3296 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3298 this->ClientToScreen(event
.GetPosition()));
3299 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3308 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3310 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3311 CallNextEventHandler(
3312 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3313 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3316 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3320 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3324 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3325 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3330 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3332 return eventNotHandledErr
;
3335 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3337 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3338 if ( !wxWindowBase::Reparent(newParent
) )
3341 // copied from MacPostControlCreate
3342 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3344 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3346 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3351 bool wxWindowMac::SetTransparent(wxByte alpha
)
3353 #if wxMAC_USE_CORE_GRAPHICS
3354 if ( alpha
!= m_macAlpha
)
3356 m_macAlpha
= alpha
;
3366 bool wxWindowMac::CanSetTransparent()
3368 #if wxMAC_USE_CORE_GRAPHICS
3375 wxByte
wxWindowMac::GetTransparent() const