1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
56 #if wxUSE_DRAG_AND_DROP
60 #include "wx/mac/uma.h"
62 #define MAC_SCROLLBAR_SIZE 15
63 #define MAC_SMALL_SCROLLBAR_SIZE 11
67 #include <ToolUtils.h>
69 #include <MacTextEditor.h>
72 #if TARGET_API_MAC_OSX
74 #include <HIToolbox/HIView.h>
80 #ifdef __WXUNIVERSAL__
81 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
83 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
86 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
87 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
88 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
89 #if TARGET_API_MAC_OSX
90 EVT_PAINT(wxWindowMac::OnPaint
)
92 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
93 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
94 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
97 #define wxMAC_DEBUG_REDRAW 0
98 #ifndef wxMAC_DEBUG_REDRAW
99 #define wxMAC_DEBUG_REDRAW 0
102 // ---------------------------------------------------------------------------
103 // Utility Routines to move between different coordinate systems
104 // ---------------------------------------------------------------------------
107 * Right now we have the following setup :
108 * a border that is not part of the native control is always outside the
109 * control's border (otherwise we loose all native intelligence, future ways
110 * may be to have a second embedding control responsible for drawing borders
111 * and backgrounds eventually)
112 * so all this border calculations have to be taken into account when calling
113 * native methods or getting native oriented data
114 * so we have three coordinate systems here
115 * wx client coordinates
116 * wx window coordinates (including window frames)
121 // originating from native control
125 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
127 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
130 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
132 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
136 // directed towards native control
139 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
141 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
144 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
146 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 #if TARGET_API_MAC_OSX
155 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
158 kEventControlVisibilityChanged
= 157
164 static const EventTypeSpec eventList
[] =
166 { kEventClassCommand
, kEventProcessCommand
} ,
167 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
169 { kEventClassControl
, kEventControlGetClickActivation
} ,
170 { kEventClassControl
, kEventControlHit
} ,
172 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
173 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
175 { kEventClassControl
, kEventControlDraw
} ,
176 #if TARGET_API_MAC_OSX
177 { kEventClassControl
, kEventControlVisibilityChanged
} ,
178 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
179 { kEventClassControl
, kEventControlHiliteChanged
} ,
181 { kEventClassControl
, kEventControlActivate
} ,
182 { kEventClassControl
, kEventControlDeactivate
} ,
184 { kEventClassControl
, kEventControlSetFocusPart
} ,
186 { kEventClassService
, kEventServiceGetTypes
},
187 { kEventClassService
, kEventServiceCopy
},
188 { kEventClassService
, kEventServicePaste
},
190 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
191 // { kEventClassControl , kEventControlBoundsChanged } ,
194 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
196 OSStatus result
= eventNotHandledErr
;
198 wxMacCarbonEvent
cEvent( event
) ;
200 ControlRef controlRef
;
201 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
203 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
205 switch ( GetEventKind( event
) )
207 #if TARGET_API_MAC_OSX
208 case kEventControlDraw
:
210 RgnHandle updateRgn
= NULL
;
211 RgnHandle allocatedRgn
= NULL
;
212 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
214 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
216 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
220 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
222 // as this update region is in native window locals we must adapt it to wx window local
223 allocatedRgn
= NewRgn() ;
224 CopyRgn( updateRgn
, allocatedRgn
) ;
226 // hide the given region by the new region that must be shifted
227 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
228 updateRgn
= allocatedRgn
;
233 GetRegionBounds( updateRgn
, &rgnBounds
) ;
235 #if wxMAC_DEBUG_REDRAW
236 if ( thisWindow
->MacIsUserPane() )
238 static float color
= 0.5 ;
241 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
243 HIViewGetBounds( controlRef
, &bounds
);
244 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
245 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
246 CGContextFillRect( cgContext
, bounds
);
259 #if wxMAC_USE_CORE_GRAPHICS
260 bool created
= false ;
261 CGContextRef cgContext
= NULL
;
262 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
263 wxASSERT_MSG( err
== noErr
, wxT("Unable to retrieve CGContextRef") ) ;
264 thisWindow
->MacSetCGContextRef( cgContext
) ;
267 wxMacCGContextStateSaver
sg( cgContext
) ;
270 wxWindow
* iter
= thisWindow
;
273 alpha
*= (float) iter
->GetTransparent()/255.0 ;
274 if ( iter
->IsTopLevel() )
277 iter
= iter
->GetParent() ;
280 CGContextSetAlpha( cgContext
, alpha
) ;
282 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
285 #if wxMAC_USE_CORE_GRAPHICS
286 thisWindow
->MacSetCGContextRef( NULL
) ;
290 CGContextRelease( cgContext
) ;
295 DisposeRgn( allocatedRgn
) ;
299 case kEventControlVisibilityChanged
:
300 thisWindow
->MacVisibilityChanged() ;
303 case kEventControlEnabledStateChanged
:
304 thisWindow
->MacEnabledStateChanged() ;
307 case kEventControlHiliteChanged
:
308 thisWindow
->MacHiliteChanged() ;
311 case kEventControlActivate
:
312 case kEventControlDeactivate
:
313 // FIXME: we should have a virtual function for this!
315 if ( thisWindow
->IsKindOf( CLASSINFO( wxTreeCtrl
) ) )
316 thisWindow
->Refresh();
319 if ( thisWindow
->IsKindOf( CLASSINFO( wxListCtrl
) ) )
320 thisWindow
->Refresh();
323 #endif // TARGET_API_MAC_OSX
325 // we emulate this event under Carbon CFM
326 case kEventControlSetFocusPart
:
328 Boolean focusEverything
= false ;
329 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
332 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
337 if ( controlPart
== kControlFocusNoPart
)
340 if ( thisWindow
->GetCaret() )
341 thisWindow
->GetCaret()->OnKillFocus();
344 static bool inKillFocusEvent
= false ;
346 if ( !inKillFocusEvent
)
348 inKillFocusEvent
= true ;
349 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
350 event
.SetEventObject(thisWindow
);
351 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
352 inKillFocusEvent
= false ;
357 // panel wants to track the window which was the last to have focus in it
358 wxChildFocusEvent
eventFocus(thisWindow
);
359 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
362 if ( thisWindow
->GetCaret() )
363 thisWindow
->GetCaret()->OnSetFocus();
366 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
367 event
.SetEventObject(thisWindow
);
368 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
371 if ( thisWindow
->MacIsUserPane() )
376 case kEventControlHit
:
377 result
= thisWindow
->MacControlHit( handler
, event
) ;
380 case kEventControlGetClickActivation
:
382 // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
383 WindowRef owner
= cEvent
.GetParameter
<WindowRef
>(kEventParamWindowRef
);
384 if ( !IsWindowActive(owner
) )
386 cEvent
.SetParameter(kEventParamClickActivation
,(UInt32
) kActivateAndIgnoreClick
) ;
399 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
401 OSStatus result
= eventNotHandledErr
;
403 wxMacCarbonEvent
cEvent( event
) ;
405 ControlRef controlRef
;
406 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
407 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
408 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
410 switch ( GetEventKind( event
) )
412 case kEventServiceGetTypes
:
416 textCtrl
->GetSelection( &from
, &to
) ;
418 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
420 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
421 if ( textCtrl
->IsEditable() )
422 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
424 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
425 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
427 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
431 CFArrayAppendValue(copyTypes
, typestring
) ;
433 CFArrayAppendValue(pasteTypes
, typestring
) ;
435 CFRelease( typestring
) ;
443 case kEventServiceCopy
:
448 textCtrl
->GetSelection( &from
, &to
) ;
449 wxString val
= textCtrl
->GetValue() ;
450 val
= val
.Mid( from
, to
- from
) ;
451 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
452 verify_noerr( ClearScrap( &scrapRef
) ) ;
453 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
458 case kEventServicePaste
:
461 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
462 Size textSize
, pastedSize
;
463 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
465 char *content
= new char[textSize
] ;
466 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
467 content
[textSize
- 1] = 0 ;
470 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
472 textCtrl
->WriteText( wxString( content
) ) ;
487 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
489 OSStatus result
= eventNotHandledErr
;
490 wxWindowMac
* focus
= (wxWindowMac
*) data
;
492 wchar_t* uniChars
= NULL
;
493 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
495 UniChar
* charBuf
= NULL
;
496 ByteCount dataSize
= 0 ;
499 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
501 numChars
= dataSize
/ sizeof( UniChar
) + 1;
504 if ( (size_t) numChars
* 2 > sizeof(buf
) )
505 charBuf
= new UniChar
[ numChars
] ;
509 uniChars
= new wchar_t[ numChars
] ;
510 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
511 charBuf
[ numChars
- 1 ] = 0;
512 #if SIZEOF_WCHAR_T == 2
513 uniChars
= (wchar_t*) charBuf
;
514 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
516 // the resulting string will never have more chars than the utf16 version, so this is safe
517 wxMBConvUTF16 converter
;
518 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
522 switch ( GetEventKind( event
) )
524 case kEventTextInputUpdateActiveInputArea
:
526 // An IME input event may return several characters, but we need to send one char at a time to
528 for (int pos
=0 ; pos
< numChars
; pos
++)
530 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
531 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
532 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
534 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
535 if ( wxTheApp
->MacSendCharEvent(
536 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
541 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
545 case kEventTextInputUnicodeForKeyEvent
:
547 UInt32 keyCode
, modifiers
;
550 unsigned char charCode
;
552 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
553 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
554 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
555 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
556 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
558 UInt32 message
= (keyCode
<< 8) + charCode
;
560 // An IME input event may return several characters, but we need to send one char at a time to
562 for (int pos
=0 ; pos
< numChars
; pos
++)
564 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
565 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
566 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
568 if ( wxTheApp
->MacSendCharEvent(
569 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
574 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
583 if ( charBuf
!= buf
)
589 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
591 OSStatus result
= eventNotHandledErr
;
592 wxWindowMac
* focus
= (wxWindowMac
*) data
;
596 wxMacCarbonEvent
cEvent( event
) ;
597 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
599 wxMenuItem
* item
= NULL
;
600 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
601 int id
= wxMacCommandToId( command
.commandID
) ;
605 wxASSERT( itemMenu
!= NULL
) ;
607 switch ( cEvent
.GetKind() )
609 case kEventProcessCommand
:
611 if (item
->IsCheckable())
612 item
->Check( !item
->IsChecked() ) ;
614 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
618 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
619 event
.SetEventObject(focus
);
620 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
622 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
628 case kEventCommandUpdateStatus
:
630 wxUpdateUIEvent
event(id
);
631 event
.SetEventObject( itemMenu
);
633 bool processed
= false;
635 // Try the menu's event handler
637 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
639 processed
= handler
->ProcessEvent(event
);
642 // Try the window the menu was popped up from
643 // (and up through the hierarchy)
646 const wxMenuBase
*menu
= itemMenu
;
649 wxWindow
*win
= menu
->GetInvokingWindow();
652 processed
= win
->GetEventHandler()->ProcessEvent(event
);
656 menu
= menu
->GetParent();
662 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
667 // if anything changed, update the changed attribute
668 if (event
.GetSetText())
669 itemMenu
->SetLabel(id
, event
.GetText());
670 if (event
.GetSetChecked())
671 itemMenu
->Check(id
, event
.GetChecked());
672 if (event
.GetSetEnabled())
673 itemMenu
->Enable(id
, event
.GetEnabled());
687 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
689 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
690 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
691 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
692 OSStatus result
= eventNotHandledErr
;
694 switch ( GetEventClass( event
) )
696 case kEventClassCommand
:
697 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
700 case kEventClassControl
:
701 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
704 case kEventClassService
:
705 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
708 case kEventClassTextInput
:
709 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
716 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
721 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
723 #if !TARGET_API_MAC_OSX
725 // ---------------------------------------------------------------------------
726 // UserPane events for non OSX builds
727 // ---------------------------------------------------------------------------
729 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
731 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
733 win
->MacControlUserPaneDrawProc(part
) ;
735 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
737 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
739 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
741 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
743 return kControlNoPart
;
745 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
747 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
749 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
751 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
753 return kControlNoPart
;
755 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
757 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
759 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
761 win
->MacControlUserPaneIdleProc() ;
763 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
765 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
767 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
769 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
771 return kControlNoPart
;
773 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
775 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
777 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
779 win
->MacControlUserPaneActivateProc(activating
) ;
781 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
783 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
785 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
787 return win
->MacControlUserPaneFocusProc(action
) ;
789 return kControlNoPart
;
791 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
793 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
795 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
797 win
->MacControlUserPaneBackgroundProc(info
) ;
799 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
801 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
804 RgnHandle rgn
= NewRgn() ;
806 MacWindowToRootWindow( &x
, &y
) ;
807 OffsetRgn( rgn
, -x
, -y
) ;
808 wxMacWindowStateSaver
sv( this ) ;
809 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
810 MacDoRedraw( rgn
, 0 ) ;
814 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
816 return kControlNoPart
;
819 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
821 return kControlNoPart
;
824 void wxWindowMac::MacControlUserPaneIdleProc()
828 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
830 return kControlNoPart
;
833 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
837 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
839 if ( AcceptsFocus() )
842 return kControlNoPart
;
845 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
851 // ---------------------------------------------------------------------------
852 // Scrollbar Tracking for all
853 // ---------------------------------------------------------------------------
855 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
856 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
860 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
862 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
865 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
867 // ===========================================================================
869 // ===========================================================================
871 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
873 static MacControlMap wxWinMacControlList
;
875 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
877 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
879 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
882 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
884 // adding NULL ControlRef is (first) surely a result of an error and
885 // (secondly) breaks native event processing
886 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
888 wxWinMacControlList
[inControl
] = control
;
891 void wxRemoveMacControlAssociation(wxWindow
*control
)
893 // iterate over all the elements in the class
894 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
895 // we should go on...
901 MacControlMap::iterator it
;
902 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
904 if ( it
->second
== control
)
906 wxWinMacControlList
.erase(it
);
914 // ----------------------------------------------------------------------------
915 // constructors and such
916 // ----------------------------------------------------------------------------
918 wxWindowMac::wxWindowMac()
923 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
928 const wxString
& name
)
931 Create(parent
, id
, pos
, size
, style
, name
);
934 void wxWindowMac::Init()
940 #if WXWIN_COMPATIBILITY_2_4
941 m_backgroundTransparent
= false;
944 #if wxMAC_USE_CORE_GRAPHICS
945 m_cgContextRef
= NULL
;
948 // as all windows are created with WS_VISIBLE style...
951 m_hScrollBar
= NULL
;
952 m_vScrollBar
= NULL
;
953 m_macBackgroundBrush
= wxNullBrush
;
955 m_macIsUserPane
= true;
956 m_clipChildren
= false ;
957 m_cachedClippedRectValid
= false ;
959 // we need a valid font for the encodings
960 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
963 wxWindowMac::~wxWindowMac()
967 m_isBeingDeleted
= true;
969 MacInvalidateBorders() ;
971 #ifndef __WXUNIVERSAL__
972 // VS: make sure there's no wxFrame with last focus set to us:
973 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
975 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
978 if ( frame
->GetLastFocus() == this )
979 frame
->SetLastFocus((wxWindow
*)NULL
);
985 // destroy children before destroying this window itself
988 // wxRemoveMacControlAssociation( this ) ;
989 // If we delete an item, we should initialize the parent panel,
990 // because it could now be invalid.
991 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
994 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
995 tlw
->SetDefaultItem(NULL
);
998 if ( m_peer
&& m_peer
->Ok() )
1000 // in case the callback might be called during destruction
1001 wxRemoveMacControlAssociation( this) ;
1002 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1003 // we currently are not using this hook
1004 // ::SetControlColorProc( *m_peer , NULL ) ;
1008 if ( g_MacLastWindow
== this )
1009 g_MacLastWindow
= NULL
;
1011 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1014 if ( frame
->GetLastFocus() == this )
1015 frame
->SetLastFocus( NULL
) ;
1018 // delete our drop target if we've got one
1019 #if wxUSE_DRAG_AND_DROP
1020 if ( m_dropTarget
!= NULL
)
1022 delete m_dropTarget
;
1023 m_dropTarget
= NULL
;
1030 WXWidget
wxWindowMac::GetHandle() const
1032 return (WXWidget
) m_peer
->GetControlRef() ;
1035 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1037 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1038 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1039 GetEventTypeCount(eventList
), eventList
, this,
1040 (EventHandlerRef
*)&m_macControlEventHandler
);
1042 #if !TARGET_API_MAC_OSX
1043 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1045 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1046 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1047 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1048 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1049 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1050 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1051 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1052 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1058 bool wxWindowMac::Create(wxWindowMac
*parent
,
1063 const wxString
& name
)
1065 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1067 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1070 m_windowVariant
= parent
->GetWindowVariant() ;
1072 if ( m_macIsUserPane
)
1074 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1077 | kControlSupportsEmbedding
1078 | kControlSupportsLiveFeedback
1079 | kControlGetsFocusOnClick
1080 // | kControlHasSpecialBackground
1081 // | kControlSupportsCalcBestRect
1082 | kControlHandlesTracking
1083 | kControlSupportsFocus
1084 | kControlWantsActivate
1085 | kControlWantsIdle
;
1087 m_peer
= new wxMacControl(this) ;
1088 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1089 verify_noerr( err
);
1091 MacPostControlCreate(pos
, size
) ;
1094 #ifndef __WXUNIVERSAL__
1095 // Don't give scrollbars to wxControls unless they ask for them
1096 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1097 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1099 MacCreateScrollBars( style
) ;
1103 wxWindowCreateEvent
event(this);
1104 GetEventHandler()->AddPendingEvent(event
);
1109 void wxWindowMac::MacChildAdded()
1112 m_vScrollBar
->Raise() ;
1114 m_hScrollBar
->Raise() ;
1117 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1119 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1121 m_peer
->SetReference( (URefCon
) this ) ;
1122 GetParent()->AddChild( this );
1124 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1126 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1127 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1128 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1129 GetParent()->MacChildAdded() ;
1131 // adjust font, controlsize etc
1132 DoSetWindowVariant( m_windowVariant
) ;
1134 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1136 if (!m_macIsUserPane
)
1137 SetInitialSize(size
);
1139 SetCursor( *wxSTANDARD_CURSOR
) ;
1142 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1144 // Don't assert, in case we set the window variant before
1145 // the window is created
1146 // wxASSERT( m_peer->Ok() ) ;
1148 m_windowVariant
= variant
;
1150 if (m_peer
== NULL
|| !m_peer
->Ok())
1154 ThemeFontID themeFont
= kThemeSystemFont
;
1156 // we will get that from the settings later
1157 // and make this NORMAL later, but first
1158 // we have a few calculations that we must fix
1162 case wxWINDOW_VARIANT_NORMAL
:
1163 size
= kControlSizeNormal
;
1164 themeFont
= kThemeSystemFont
;
1167 case wxWINDOW_VARIANT_SMALL
:
1168 size
= kControlSizeSmall
;
1169 themeFont
= kThemeSmallSystemFont
;
1172 case wxWINDOW_VARIANT_MINI
:
1173 if (UMAGetSystemVersion() >= 0x1030 )
1175 // not always defined in the headers
1181 size
= kControlSizeSmall
;
1182 themeFont
= kThemeSmallSystemFont
;
1186 case wxWINDOW_VARIANT_LARGE
:
1187 size
= kControlSizeLarge
;
1188 themeFont
= kThemeSystemFont
;
1192 wxFAIL_MSG(_T("unexpected window variant"));
1196 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1199 font
.MacCreateThemeFont( themeFont
) ;
1203 void wxWindowMac::MacUpdateControlFont()
1205 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1209 bool wxWindowMac::SetFont(const wxFont
& font
)
1211 bool retval
= wxWindowBase::SetFont( font
);
1213 MacUpdateControlFont() ;
1218 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1220 bool retval
= wxWindowBase::SetForegroundColour( col
);
1223 MacUpdateControlFont();
1228 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1230 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1234 wxColour
newCol(GetBackgroundColour());
1236 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1237 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1238 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1239 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1241 brush
.SetColour( newCol
) ;
1243 MacSetBackgroundBrush( brush
) ;
1244 MacUpdateControlFont() ;
1249 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1251 m_macBackgroundBrush
= brush
;
1252 m_peer
->SetBackground( brush
) ;
1255 bool wxWindowMac::MacCanFocus() const
1257 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1258 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1259 // but the value range is nowhere documented
1260 Boolean keyExistsAndHasValidFormat
;
1261 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1262 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1264 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1270 UInt32 features
= 0 ;
1271 m_peer
->GetFeatures( &features
) ;
1273 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1277 void wxWindowMac::SetFocus()
1279 if ( !AcceptsFocus() )
1282 wxWindow
* former
= FindFocus() ;
1283 if ( former
== this )
1286 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1287 // we can only leave in case of an error
1288 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1289 if ( err
== errCouldntSetFocus
)
1292 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1294 #if !TARGET_API_MAC_OSX
1295 // emulate carbon events when running under CarbonLib where they are not natively available
1298 EventRef evRef
= NULL
;
1300 err
= MacCreateEvent(
1301 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1302 kEventAttributeUserEvent
, &evRef
);
1303 verify_noerr( err
);
1305 wxMacCarbonEvent
cEvent( evRef
) ;
1306 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1307 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1309 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1310 ReleaseEvent( evRef
) ;
1313 // send new focus event
1315 EventRef evRef
= NULL
;
1317 err
= MacCreateEvent(
1318 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1319 kEventAttributeUserEvent
, &evRef
);
1320 verify_noerr( err
);
1322 wxMacCarbonEvent
cEvent( evRef
) ;
1323 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1324 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1326 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1327 ReleaseEvent( evRef
) ;
1332 void wxWindowMac::DoCaptureMouse()
1334 wxApp::s_captureWindow
= this ;
1337 wxWindow
* wxWindowBase::GetCapture()
1339 return wxApp::s_captureWindow
;
1342 void wxWindowMac::DoReleaseMouse()
1344 wxApp::s_captureWindow
= NULL
;
1347 #if wxUSE_DRAG_AND_DROP
1349 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1351 if ( m_dropTarget
!= NULL
)
1352 delete m_dropTarget
;
1354 m_dropTarget
= pDropTarget
;
1355 if ( m_dropTarget
!= NULL
)
1363 // Old-style File Manager Drag & Drop
1364 void wxWindowMac::DragAcceptFiles(bool accept
)
1369 // Returns the size of the native control. In the case of the toplevel window
1370 // this is the content area root control
1372 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1373 int& w
, int& h
) const
1375 wxFAIL_MSG( wxT("Not currently supported") ) ;
1378 // From a wx position / size calculate the appropriate size of the native control
1380 bool wxWindowMac::MacGetBoundsForControl(
1384 int& w
, int& h
, bool adjustOrigin
) const
1386 // the desired size, minus the border pixels gives the correct size of the control
1390 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1391 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1392 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1394 x
+= MacGetLeftBorderSize() ;
1395 y
+= MacGetTopBorderSize() ;
1396 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1397 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1400 AdjustForParentClientOrigin( x
, y
) ;
1402 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1403 if ( !GetParent()->IsTopLevel() )
1405 x
-= GetParent()->MacGetLeftBorderSize() ;
1406 y
-= GetParent()->MacGetTopBorderSize() ;
1412 // Get window size (not client size)
1413 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1416 m_peer
->GetRect( &bounds
) ;
1419 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1421 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1424 // get the position of the bounds of this window in client coordinates of its parent
1425 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1428 m_peer
->GetRect( &bounds
) ;
1430 int x1
= bounds
.left
;
1431 int y1
= bounds
.top
;
1433 // get the wx window position from the native one
1434 x1
-= MacGetLeftBorderSize() ;
1435 y1
-= MacGetTopBorderSize() ;
1437 if ( !IsTopLevel() )
1439 wxWindow
*parent
= GetParent();
1442 // we must first adjust it to be in window coordinates of the parent,
1443 // as otherwise it gets lost by the ClientAreaOrigin fix
1444 x1
+= parent
->MacGetLeftBorderSize() ;
1445 y1
+= parent
->MacGetTopBorderSize() ;
1447 // and now to client coordinates
1448 wxPoint
pt(parent
->GetClientAreaOrigin());
1460 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1462 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1463 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1465 Point localwhere
= { 0, 0 } ;
1472 wxMacGlobalToLocal( window
, &localwhere
) ;
1479 MacRootWindowToWindow( x
, y
) ;
1481 wxPoint origin
= GetClientAreaOrigin() ;
1488 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1490 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1491 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1493 wxPoint origin
= GetClientAreaOrigin() ;
1499 MacWindowToRootWindow( x
, y
) ;
1501 Point localwhere
= { 0, 0 };
1507 wxMacLocalToGlobal( window
, &localwhere
) ;
1515 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1517 wxPoint origin
= GetClientAreaOrigin() ;
1523 MacWindowToRootWindow( x
, y
) ;
1526 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1528 MacRootWindowToWindow( x
, y
) ;
1530 wxPoint origin
= GetClientAreaOrigin() ;
1537 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1546 if ( !IsTopLevel() )
1548 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1551 pt
.x
-= MacGetLeftBorderSize() ;
1552 pt
.y
-= MacGetTopBorderSize() ;
1553 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1563 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1572 MacWindowToRootWindow( &x1
, &y1
) ;
1580 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1589 if ( !IsTopLevel() )
1591 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1594 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1595 pt
.x
+= MacGetLeftBorderSize() ;
1596 pt
.y
+= MacGetTopBorderSize() ;
1606 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1615 MacRootWindowToWindow( &x1
, &y1
) ;
1623 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1625 RgnHandle rgn
= NewRgn() ;
1627 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1629 Rect structure
, content
;
1631 GetRegionBounds( rgn
, &content
) ;
1632 m_peer
->GetRect( &structure
) ;
1633 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1635 left
= content
.left
- structure
.left
;
1636 top
= content
.top
- structure
.top
;
1637 right
= structure
.right
- content
.right
;
1638 bottom
= structure
.bottom
- content
.bottom
;
1642 left
= top
= right
= bottom
= 0 ;
1648 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1650 wxSize sizeTotal
= size
;
1652 RgnHandle rgn
= NewRgn() ;
1653 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1655 Rect content
, structure
;
1656 GetRegionBounds( rgn
, &content
) ;
1657 m_peer
->GetRect( &structure
) ;
1659 // structure is in parent coordinates, but we only need width and height, so it's ok
1661 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1662 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1667 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1668 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1673 // Get size *available for subwindows* i.e. excluding menu bar etc.
1674 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1678 RgnHandle rgn
= NewRgn() ;
1680 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1681 GetRegionBounds( rgn
, &content
) ;
1683 m_peer
->GetRect( &content
) ;
1686 ww
= content
.right
- content
.left
;
1687 hh
= content
.bottom
- content
.top
;
1689 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1690 hh
-= m_hScrollBar
->GetSize().y
;
1692 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1693 ww
-= m_vScrollBar
->GetSize().x
;
1701 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1703 if (m_cursor
.IsSameAs(cursor
))
1708 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1713 if ( ! wxWindowBase::SetCursor( cursor
) )
1717 wxASSERT_MSG( m_cursor
.Ok(),
1718 wxT("cursor must be valid after call to the base version"));
1720 wxWindowMac
*mouseWin
= 0 ;
1722 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1723 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1725 ControlPartCode part
;
1726 ControlRef control
;
1728 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1730 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1735 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1737 // TODO: If we ever get a GetCurrentEvent... replacement
1738 // for the mouse position, use it...
1743 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1745 mouseWin
= wxFindControlFromMacControl( control
) ;
1747 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1749 QDSwapPort( savePort
, NULL
) ;
1753 if ( mouseWin
== this && !wxIsBusy() )
1754 m_cursor
.MacInstall() ;
1760 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1762 menu
->SetInvokingWindow(this);
1765 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1767 wxPoint mouse
= wxGetMousePosition();
1773 ClientToScreen( &x
, &y
) ;
1776 menu
->MacBeforeDisplay( true ) ;
1777 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1778 if ( HiWord(menuResult
) != 0 )
1781 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1782 int id
= wxMacCommandToId( macid
);
1783 wxMenuItem
* item
= NULL
;
1785 item
= menu
->FindItem( id
, &realmenu
) ;
1788 if (item
->IsCheckable())
1789 item
->Check( !item
->IsChecked() ) ;
1791 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1795 menu
->MacAfterDisplay( true ) ;
1796 menu
->SetInvokingWindow( NULL
);
1802 // ----------------------------------------------------------------------------
1804 // ----------------------------------------------------------------------------
1808 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1810 wxWindowBase::DoSetToolTip(tooltip
);
1813 m_tooltip
->SetWindow(this);
1818 void wxWindowMac::MacInvalidateBorders()
1820 if ( m_peer
== NULL
)
1823 bool vis
= MacIsReallyShown() ;
1827 int outerBorder
= MacGetLeftBorderSize() ;
1828 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1831 if ( outerBorder
== 0 )
1834 // now we know that we have something to do at all
1836 // as the borders are drawn on the parent we have to properly invalidate all these areas
1837 RgnHandle updateInner
, updateOuter
;
1840 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1841 updateInner
= NewRgn() ;
1842 updateOuter
= NewRgn() ;
1844 m_peer
->GetRect( &rect
) ;
1845 RectRgn( updateInner
, &rect
) ;
1846 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1847 RectRgn( updateOuter
, &rect
) ;
1848 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1850 #ifdef __WXMAC_OSX__
1851 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1853 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1855 InvalWindowRgn( tlw
, updateOuter
) ;
1858 DisposeRgn( updateOuter
) ;
1859 DisposeRgn( updateInner
) ;
1862 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1864 // this is never called for a toplevel window, so we know we have a parent
1865 int former_x
, former_y
, former_w
, former_h
;
1867 // Get true coordinates of former position
1868 DoGetPosition( &former_x
, &former_y
) ;
1869 DoGetSize( &former_w
, &former_h
) ;
1871 wxWindow
*parent
= GetParent();
1874 wxPoint
pt(parent
->GetClientAreaOrigin());
1879 int actualWidth
= width
;
1880 int actualHeight
= height
;
1884 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1885 actualWidth
= m_minWidth
;
1886 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1887 actualHeight
= m_minHeight
;
1888 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1889 actualWidth
= m_maxWidth
;
1890 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1891 actualHeight
= m_maxHeight
;
1893 bool doMove
= false, doResize
= false ;
1895 if ( actualX
!= former_x
|| actualY
!= former_y
)
1898 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1901 if ( doMove
|| doResize
)
1903 // as the borders are drawn outside the native control, we adjust now
1905 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1906 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1907 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1910 wxMacRectToNative( &bounds
, &r
) ;
1912 if ( !GetParent()->IsTopLevel() )
1913 wxMacWindowToNative( GetParent() , &r
) ;
1915 MacInvalidateBorders() ;
1917 m_cachedClippedRectValid
= false ;
1918 m_peer
->SetRect( &r
) ;
1920 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1922 MacInvalidateBorders() ;
1924 MacRepositionScrollBars() ;
1927 wxPoint
point(actualX
, actualY
);
1928 wxMoveEvent
event(point
, m_windowId
);
1929 event
.SetEventObject(this);
1930 GetEventHandler()->ProcessEvent(event
) ;
1935 MacRepositionScrollBars() ;
1936 wxSize
size(actualWidth
, actualHeight
);
1937 wxSizeEvent
event(size
, m_windowId
);
1938 event
.SetEventObject(this);
1939 GetEventHandler()->ProcessEvent(event
);
1944 wxSize
wxWindowMac::DoGetBestSize() const
1946 if ( m_macIsUserPane
|| IsTopLevel() )
1947 return wxWindowBase::DoGetBestSize() ;
1949 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1950 int bestWidth
, bestHeight
;
1952 m_peer
->GetBestRect( &bestsize
) ;
1953 if ( EmptyRect( &bestsize
) )
1958 bestsize
.bottom
= 16 ;
1960 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1962 bestsize
.bottom
= 16 ;
1965 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1967 bestsize
.bottom
= 24 ;
1972 // return wxWindowBase::DoGetBestSize() ;
1976 bestWidth
= bestsize
.right
- bestsize
.left
;
1977 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1978 if ( bestHeight
< 10 )
1981 return wxSize(bestWidth
, bestHeight
);
1984 // set the size of the window: if the dimensions are positive, just use them,
1985 // but if any of them is equal to -1, it means that we must find the value for
1986 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1987 // which case -1 is a valid value for x and y)
1989 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1990 // the width/height to best suit our contents, otherwise we reuse the current
1992 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1994 // get the current size and position...
1995 int currentX
, currentY
;
1996 int currentW
, currentH
;
1998 GetPosition(¤tX
, ¤tY
);
1999 GetSize(¤tW
, ¤tH
);
2001 // ... and don't do anything (avoiding flicker) if it's already ok
2002 if ( x
== currentX
&& y
== currentY
&&
2003 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2006 MacRepositionScrollBars() ; // we might have a real position shift
2011 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2013 if ( x
== wxDefaultCoord
)
2015 if ( y
== wxDefaultCoord
)
2019 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2021 wxSize size
= wxDefaultSize
;
2022 if ( width
== wxDefaultCoord
)
2024 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2026 size
= DoGetBestSize();
2031 // just take the current one
2036 if ( height
== wxDefaultCoord
)
2038 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2040 if ( size
.x
== wxDefaultCoord
)
2041 size
= DoGetBestSize();
2042 // else: already called DoGetBestSize() above
2048 // just take the current one
2053 DoMoveWindow( x
, y
, width
, height
);
2056 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2058 RgnHandle rgn
= NewRgn() ;
2060 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2062 GetRegionBounds( rgn
, &content
) ;
2072 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2075 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2077 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2079 int currentclientwidth
, currentclientheight
;
2080 int currentwidth
, currentheight
;
2082 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2083 GetSize( ¤twidth
, ¤theight
) ;
2085 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2086 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2090 void wxWindowMac::SetLabel(const wxString
& title
)
2092 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2094 if ( m_peer
&& m_peer
->Ok() )
2095 m_peer
->SetLabel( m_label
) ;
2100 wxString
wxWindowMac::GetLabel() const
2105 bool wxWindowMac::Show(bool show
)
2107 bool former
= MacIsReallyShown() ;
2108 if ( !wxWindowBase::Show(show
) )
2111 // TODO: use visibilityChanged Carbon Event for OSX
2113 m_peer
->SetVisibility( show
, true ) ;
2115 if ( former
!= MacIsReallyShown() )
2116 MacPropagateVisibilityChanged() ;
2121 bool wxWindowMac::Enable(bool enable
)
2123 wxASSERT( m_peer
->Ok() ) ;
2124 bool former
= MacIsReallyEnabled() ;
2125 if ( !wxWindowBase::Enable(enable
) )
2128 m_peer
->Enable( enable
) ;
2130 if ( former
!= MacIsReallyEnabled() )
2131 MacPropagateEnabledStateChanged() ;
2137 // status change propagations (will be not necessary for OSX later )
2140 void wxWindowMac::MacPropagateVisibilityChanged()
2142 #if !TARGET_API_MAC_OSX
2143 MacVisibilityChanged() ;
2146 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2149 child
= node
->GetData();
2150 if ( child
->IsShown() )
2151 child
->MacPropagateVisibilityChanged() ;
2153 node
= node
->GetNext();
2158 void wxWindowMac::MacPropagateEnabledStateChanged()
2160 #if !TARGET_API_MAC_OSX
2161 MacEnabledStateChanged() ;
2164 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2167 child
= node
->GetData();
2168 if ( child
->IsEnabled() )
2169 child
->MacPropagateEnabledStateChanged() ;
2171 node
= node
->GetNext();
2176 void wxWindowMac::MacPropagateHiliteChanged()
2178 #if !TARGET_API_MAC_OSX
2179 MacHiliteChanged() ;
2182 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2185 child
= node
->GetData();
2186 if (child
/* && child->IsEnabled() */)
2187 child
->MacPropagateHiliteChanged() ;
2189 node
= node
->GetNext();
2195 // status change notifications
2198 void wxWindowMac::MacVisibilityChanged()
2202 void wxWindowMac::MacHiliteChanged()
2206 void wxWindowMac::MacEnabledStateChanged()
2211 // status queries on the inherited window's state
2214 bool wxWindowMac::MacIsReallyShown()
2216 // only under OSX the visibility of the TLW is taken into account
2217 if ( m_isBeingDeleted
)
2220 #if TARGET_API_MAC_OSX
2221 if ( m_peer
&& m_peer
->Ok() )
2222 return m_peer
->IsVisible();
2225 wxWindow
* win
= this ;
2226 while ( win
->IsShown() )
2228 if ( win
->IsTopLevel() )
2231 win
= win
->GetParent() ;
2239 bool wxWindowMac::MacIsReallyEnabled()
2241 return m_peer
->IsEnabled() ;
2244 bool wxWindowMac::MacIsReallyHilited()
2246 return m_peer
->IsActive();
2249 void wxWindowMac::MacFlashInvalidAreas()
2251 #if TARGET_API_MAC_OSX
2252 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2256 int wxWindowMac::GetCharHeight() const
2258 wxClientDC
dc( (wxWindowMac
*)this ) ;
2260 return dc
.GetCharHeight() ;
2263 int wxWindowMac::GetCharWidth() const
2265 wxClientDC
dc( (wxWindowMac
*)this ) ;
2267 return dc
.GetCharWidth() ;
2270 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2271 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2273 const wxFont
*fontToUse
= theFont
;
2275 fontToUse
= &m_font
;
2277 wxClientDC
dc( (wxWindowMac
*) this ) ;
2279 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2280 if ( externalLeading
)
2281 *externalLeading
= le
;
2291 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2292 * we always intersect with the entire window, not only with the client area
2295 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2297 if ( m_peer
== NULL
)
2300 if ( !MacIsReallyShown() )
2307 wxMacRectToNative( rect
, &r
) ;
2308 m_peer
->SetNeedsDisplay( &r
) ;
2312 m_peer
->SetNeedsDisplay() ;
2316 void wxWindowMac::Freeze()
2318 #if TARGET_API_MAC_OSX
2319 if ( !m_frozenness
++ )
2321 if ( m_peer
&& m_peer
->Ok() )
2322 m_peer
->SetDrawingEnabled( false ) ;
2327 void wxWindowMac::Thaw()
2329 #if TARGET_API_MAC_OSX
2330 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2332 if ( !--m_frozenness
)
2334 if ( m_peer
&& m_peer
->Ok() )
2336 m_peer
->SetDrawingEnabled( true ) ;
2337 m_peer
->InvalidateWithChildren() ;
2343 bool wxWindowMac::IsFrozen() const
2345 return m_frozenness
!= 0;
2348 wxWindowMac
*wxGetActiveWindow()
2350 // actually this is a windows-only concept
2354 // Coordinates relative to the window
2355 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2357 // We really don't move the mouse programmatically under Mac.
2360 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2362 if ( MacGetTopLevelWindow() == NULL
)
2365 #if TARGET_API_MAC_OSX
2366 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2373 event
.GetDC()->Clear() ;
2377 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2382 int wxWindowMac::GetScrollPos(int orient
) const
2384 if ( orient
== wxHORIZONTAL
)
2387 return m_hScrollBar
->GetThumbPosition() ;
2392 return m_vScrollBar
->GetThumbPosition() ;
2398 // This now returns the whole range, not just the number
2399 // of positions that we can scroll.
2400 int wxWindowMac::GetScrollRange(int orient
) const
2402 if ( orient
== wxHORIZONTAL
)
2405 return m_hScrollBar
->GetRange() ;
2410 return m_vScrollBar
->GetRange() ;
2416 int wxWindowMac::GetScrollThumb(int orient
) const
2418 if ( orient
== wxHORIZONTAL
)
2421 return m_hScrollBar
->GetThumbSize() ;
2426 return m_vScrollBar
->GetThumbSize() ;
2432 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2434 if ( orient
== wxHORIZONTAL
)
2437 m_hScrollBar
->SetThumbPosition( pos
) ;
2442 m_vScrollBar
->SetThumbPosition( pos
) ;
2447 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2448 // our own window origin is at leftOrigin/rightOrigin
2451 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2457 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2458 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2460 // back to the surrounding frame rectangle
2461 m_peer
->GetRect( &rect
) ;
2462 InsetRect( &rect
, -1 , -1 ) ;
2464 #if wxMAC_USE_CORE_GRAPHICS
2466 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2467 rect
.bottom
- rect
.top
) ;
2469 HIThemeFrameDrawInfo info
;
2470 memset( &info
, 0 , sizeof(info
) ) ;
2474 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2475 info
.isFocused
= hasFocus
;
2477 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2478 wxASSERT( cgContext
) ;
2480 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2482 info
.kind
= kHIThemeFrameTextFieldSquare
;
2483 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2485 else if ( HasFlag(wxSIMPLE_BORDER
) )
2487 info
.kind
= kHIThemeFrameListBox
;
2488 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2490 else if ( hasFocus
)
2492 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2495 m_peer
->GetRect( &rect
) ;
2496 if ( hasBothScrollbars
)
2498 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2499 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2500 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2501 HIThemeGrowBoxDrawInfo info
;
2502 memset( &info
, 0, sizeof(info
) ) ;
2504 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2505 info
.kind
= kHIThemeGrowBoxKindNone
;
2506 info
.size
= kHIThemeGrowBoxSizeNormal
;
2507 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2508 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2513 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2517 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2518 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2521 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2522 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2523 else if ( HasFlag(wxSIMPLE_BORDER
) )
2524 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2527 DrawThemeFocusRect( &rect
, true ) ;
2529 if ( hasBothScrollbars
)
2531 // GetThemeStandaloneGrowBoxBounds
2532 // DrawThemeStandaloneNoGrowBox
2538 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2540 if ( child
== m_hScrollBar
)
2541 m_hScrollBar
= NULL
;
2542 if ( child
== m_vScrollBar
)
2543 m_vScrollBar
= NULL
;
2545 wxWindowBase::RemoveChild( child
) ;
2548 // New function that will replace some of the above.
2549 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2550 int range
, bool refresh
)
2553 bool triggerSizeEvent
= false;
2555 if ( orient
== wxHORIZONTAL
)
2559 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2560 if ( m_hScrollBar
->IsShown() != showScroller
)
2562 m_hScrollBar
->Show( showScroller
);
2563 triggerSizeEvent
= true;
2566 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2573 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2574 if ( m_vScrollBar
->IsShown() != showScroller
)
2576 m_vScrollBar
->Show( showScroller
) ;
2577 triggerSizeEvent
= true;
2580 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2584 MacRepositionScrollBars() ;
2585 if ( triggerSizeEvent
)
2587 wxSizeEvent
event(GetSize(), m_windowId
);
2588 event
.SetEventObject(this);
2589 GetEventHandler()->ProcessEvent(event
);
2593 // Does a physical scroll
2594 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2596 if ( dx
== 0 && dy
== 0 )
2599 int width
, height
;
2600 GetClientSize( &width
, &height
) ;
2603 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2604 // area is scrolled, this does not occur if width and height are 2 pixels less,
2605 // TODO: write optimal workaround
2606 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2608 scrollrect
.Intersect( *rect
) ;
2610 if ( m_peer
->GetNeedsDisplay() )
2612 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2613 // either immediate redraw or full invalidate
2615 // is the better overall solution, as it does not slow down scrolling
2616 m_peer
->SetNeedsDisplay() ;
2618 // this would be the preferred version for fast drawing controls
2620 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2621 if ( UMAGetSystemVersion() >= 0x1030 )
2622 HIViewRender(m_peer
->GetControlRef()) ;
2629 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2630 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2631 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2633 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2634 // either immediate redraw or full invalidate
2636 // is the better overall solution, as it does not slow down scrolling
2637 m_peer
->SetNeedsDisplay() ;
2639 // this would be the preferred version for fast drawing controls
2641 HIViewRender(m_peer
->GetControlRef()) ;
2647 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2649 child
= node
->GetData();
2652 if (child
== m_vScrollBar
)
2654 if (child
== m_hScrollBar
)
2656 if (child
->IsTopLevel())
2659 child
->GetPosition( &x
, &y
);
2660 child
->GetSize( &w
, &h
);
2663 wxRect
rc( x
, y
, w
, h
);
2664 if (rect
->Intersects( rc
))
2665 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2669 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2674 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2676 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2678 wxScrollWinEvent wevent
;
2679 wevent
.SetPosition(event
.GetPosition());
2680 wevent
.SetOrientation(event
.GetOrientation());
2681 wevent
.SetEventObject(this);
2683 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2684 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2685 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2686 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2687 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2688 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2689 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2690 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2691 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2692 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2693 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2694 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2695 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2696 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2697 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2698 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2700 GetEventHandler()->ProcessEvent(wevent
);
2704 // Get the window with the focus
2705 wxWindowMac
*wxWindowBase::DoFindFocus()
2707 ControlRef control
;
2708 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2709 return wxFindControlFromMacControl( control
) ;
2712 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2714 // panel wants to track the window which was the last to have focus in it,
2715 // so we want to set ourselves as the window which last had focus
2717 // notice that it's also important to do it upwards the tree because
2718 // otherwise when the top level panel gets focus, it won't set it back to
2719 // us, but to some other sibling
2721 // CS: don't know if this is still needed:
2722 //wxChildFocusEvent eventFocus(this);
2723 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2725 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2727 #if wxMAC_USE_CORE_GRAPHICS
2728 GetParent()->Refresh() ;
2730 wxMacWindowStateSaver
sv( this ) ;
2733 m_peer
->GetRect( &rect
) ;
2734 // auf den umgebenden Rahmen zur\9fck
2735 InsetRect( &rect
, -1 , -1 ) ;
2737 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2741 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2743 rect
.right
+= pt
.x
;
2745 rect
.bottom
+= pt
.y
;
2748 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2749 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2750 if ( !bIsFocusEvent
)
2752 // as this erases part of the frame we have to redraw borders
2753 // and because our z-ordering is not always correct (staticboxes)
2754 // we have to invalidate things, we cannot simple redraw
2755 MacInvalidateBorders() ;
2763 void wxWindowMac::OnInternalIdle()
2765 // This calls the UI-update mechanism (querying windows for
2766 // menu/toolbar/control state information)
2767 if (wxUpdateUIEvent::CanUpdate(this))
2768 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2771 // Raise the window to the top of the Z order
2772 void wxWindowMac::Raise()
2774 m_peer
->SetZOrder( true , NULL
) ;
2777 // Lower the window to the bottom of the Z order
2778 void wxWindowMac::Lower()
2780 m_peer
->SetZOrder( false , NULL
) ;
2783 // static wxWindow *gs_lastWhich = NULL;
2785 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2787 // first trigger a set cursor event
2789 wxPoint clientorigin
= GetClientAreaOrigin() ;
2790 wxSize clientsize
= GetClientSize() ;
2792 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2794 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2796 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2797 if ( processedEvtSetCursor
&& event
.HasCursor() )
2799 cursor
= event
.GetCursor() ;
2803 // the test for processedEvtSetCursor is here to prevent using m_cursor
2804 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2805 // it - this is a way to say that our cursor shouldn't be used for this
2807 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2810 if ( !wxIsBusy() && !GetParent() )
2811 cursor
= *wxSTANDARD_CURSOR
;
2815 cursor
.MacInstall() ;
2818 return cursor
.Ok() ;
2821 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2825 return m_tooltip
->GetTip() ;
2828 return wxEmptyString
;
2831 void wxWindowMac::ClearBackground()
2837 void wxWindowMac::Update()
2839 #if TARGET_API_MAC_OSX
2840 MacGetTopLevelWindow()->MacPerformUpdates() ;
2842 ::Draw1Control( m_peer
->GetControlRef() ) ;
2846 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2848 wxTopLevelWindowMac
* win
= NULL
;
2849 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2851 win
= wxFindWinFromMacWindow( window
) ;
2856 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2858 MacUpdateClippedRects() ;
2860 return m_cachedClippedClientRect
;
2863 const wxRect
& wxWindowMac::MacGetClippedRect() const
2865 MacUpdateClippedRects() ;
2867 return m_cachedClippedRect
;
2870 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2872 MacUpdateClippedRects() ;
2874 return m_cachedClippedRectWithOuterStructure
;
2877 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2879 static wxRegion emptyrgn
;
2881 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2883 MacUpdateClippedRects() ;
2884 if ( includeOuterStructures
)
2885 return m_cachedClippedRegionWithOuterStructure
;
2887 return m_cachedClippedRegion
;
2895 void wxWindowMac::MacUpdateClippedRects() const
2897 if ( m_cachedClippedRectValid
)
2900 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2901 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2902 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2903 // to add focus borders everywhere
2905 Rect r
, rIncludingOuterStructures
;
2907 m_peer
->GetRect( &r
) ;
2908 r
.left
-= MacGetLeftBorderSize() ;
2909 r
.top
-= MacGetTopBorderSize() ;
2910 r
.bottom
+= MacGetBottomBorderSize() ;
2911 r
.right
+= MacGetRightBorderSize() ;
2918 rIncludingOuterStructures
= r
;
2919 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2921 wxRect cl
= GetClientRect() ;
2922 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2926 const wxWindow
* child
= this ;
2927 const wxWindow
* parent
= NULL
;
2929 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2931 if ( parent
->MacIsChildOfClientArea(child
) )
2933 size
= parent
->GetClientSize() ;
2934 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2940 // this will be true for scrollbars, toolbars etc.
2941 size
= parent
->GetSize() ;
2942 y
= parent
->MacGetTopBorderSize() ;
2943 x
= parent
->MacGetLeftBorderSize() ;
2944 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2945 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2948 parent
->MacWindowToRootWindow( &x
, &y
) ;
2949 MacRootWindowToWindow( &x
, &y
) ;
2951 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2953 // the wxwindow and client rects will always be clipped
2954 SectRect( &r
, &rparent
, &r
) ;
2955 SectRect( &rClient
, &rparent
, &rClient
) ;
2957 // the structure only at 'hard' borders
2958 if ( parent
->MacClipChildren() ||
2959 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2961 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2967 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2968 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2969 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2970 m_cachedClippedRectWithOuterStructure
= wxRect(
2971 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2972 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2973 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2975 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2976 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2977 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2979 m_cachedClippedRectValid
= true ;
2983 This function must not change the updatergn !
2985 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2987 bool handled
= false ;
2989 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2990 GetRegionBounds( updatergn
, &updatebounds
) ;
2992 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2994 if ( !EmptyRgn(updatergn
) )
2996 RgnHandle newupdate
= NewRgn() ;
2997 wxSize point
= GetClientSize() ;
2998 wxPoint origin
= GetClientAreaOrigin() ;
2999 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3000 SectRgn( newupdate
, updatergn
, newupdate
) ;
3002 // first send an erase event to the entire update area
3004 // for the toplevel window this really is the entire area
3005 // for all the others only their client area, otherwise they
3006 // might be drawing with full alpha and eg put blue into
3007 // the grow-box area of a scrolled window (scroll sample)
3008 wxDC
* dc
= new wxWindowDC(this);
3010 dc
->SetClippingRegion(wxRegion(updatergn
));
3012 dc
->SetClippingRegion(wxRegion(newupdate
));
3014 wxEraseEvent
eevent( GetId(), dc
);
3015 eevent
.SetEventObject( this );
3016 GetEventHandler()->ProcessEvent( eevent
);
3020 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3021 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3022 m_updateRegion
= newupdate
;
3023 DisposeRgn( newupdate
) ;
3025 if ( !m_updateRegion
.Empty() )
3027 // paint the window itself
3030 event
.SetTimestamp(time
);
3031 event
.SetEventObject(this);
3032 GetEventHandler()->ProcessEvent(event
);
3036 // now we cannot rely on having its borders drawn by a window itself, as it does not
3037 // get the updateRgn wide enough to always do so, so we do it from the parent
3038 // this would also be the place to draw any custom backgrounds for native controls
3039 // in Composited windowing
3040 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3044 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3046 child
= node
->GetData();
3049 if (child
== m_vScrollBar
)
3051 if (child
== m_hScrollBar
)
3053 if (child
->IsTopLevel())
3055 if (!child
->IsShown())
3058 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3060 child
->GetPosition( &x
, &y
);
3061 child
->GetSize( &w
, &h
);
3062 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3063 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3064 InsetRect( &childRect
, -10 , -10) ;
3066 if ( RectInRgn( &childRect
, updatergn
) )
3068 // paint custom borders
3069 wxNcPaintEvent
eventNc( child
->GetId() );
3070 eventNc
.SetEventObject( child
);
3071 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3073 #if wxMAC_USE_CORE_GRAPHICS
3074 child
->MacPaintBorders(0, 0) ;
3077 wxWindowDC
dc(this) ;
3078 dc
.SetClippingRegion(wxRegion(updatergn
));
3079 wxMacPortSetter
helper(&dc
) ;
3080 child
->MacPaintBorders(0, 0) ;
3092 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3094 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3098 if ( iter
->IsTopLevel() )
3099 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3101 iter
= iter
->GetParent() ;
3107 void wxWindowMac::MacCreateScrollBars( long style
)
3109 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3111 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3113 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3114 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3115 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3117 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3120 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3122 GetClientSize( &width
, &height
) ;
3124 wxPoint
vPoint(width
- scrlsize
, 0) ;
3125 wxSize
vSize(scrlsize
, height
- adjust
) ;
3126 wxPoint
hPoint(0, height
- scrlsize
) ;
3127 wxSize
hSize(width
- adjust
, scrlsize
) ;
3129 if ( style
& wxVSCROLL
)
3130 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3132 if ( style
& wxHSCROLL
)
3133 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3136 // because the create does not take into account the client area origin
3137 // we might have a real position shift
3138 MacRepositionScrollBars() ;
3141 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3143 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3148 void wxWindowMac::MacRepositionScrollBars()
3150 if ( !m_hScrollBar
&& !m_vScrollBar
)
3153 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3154 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3155 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3157 // get real client area
3159 GetSize( &width
, &height
);
3161 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3162 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3164 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3165 wxSize
vSize( scrlsize
, height
- adjust
) ;
3166 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3167 wxSize
hSize( width
- adjust
, scrlsize
) ;
3170 int x
= 0, y
= 0, w
, h
;
3171 GetSize( &w
, &h
) ;
3173 MacClientToRootWindow( &x
, &y
) ;
3174 MacClientToRootWindow( &w
, &h
) ;
3176 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3178 int totW
= 10000 , totH
= 10000;
3181 if ( iter
->IsTopLevel() )
3183 iter
->GetSize( &totW
, &totH
) ;
3187 iter
= iter
->GetParent() ;
3201 if ( w
- x
>= totW
)
3206 if ( h
- y
>= totH
)
3214 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3216 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3219 bool wxWindowMac::AcceptsFocus() const
3221 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3224 void wxWindowMac::MacSuperChangedPosition()
3226 // only window-absolute structures have to be moved i.e. controls
3228 m_cachedClippedRectValid
= false ;
3231 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3234 child
= node
->GetData();
3235 child
->MacSuperChangedPosition() ;
3237 node
= node
->GetNext();
3241 void wxWindowMac::MacTopLevelWindowChangedPosition()
3243 // only screen-absolute structures have to be moved i.e. glcanvas
3246 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3249 child
= node
->GetData();
3250 child
->MacTopLevelWindowChangedPosition() ;
3252 node
= node
->GetNext();
3256 long wxWindowMac::MacGetLeftBorderSize() const
3263 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3265 // this metric is only the 'outset' outside the simple frame rect
3266 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3269 else if (HasFlag(wxSIMPLE_BORDER
))
3271 // this metric is only the 'outset' outside the simple frame rect
3272 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3279 long wxWindowMac::MacGetRightBorderSize() const
3281 // they are all symmetric in mac themes
3282 return MacGetLeftBorderSize() ;
3285 long wxWindowMac::MacGetTopBorderSize() const
3287 // they are all symmetric in mac themes
3288 return MacGetLeftBorderSize() ;
3291 long wxWindowMac::MacGetBottomBorderSize() const
3293 // they are all symmetric in mac themes
3294 return MacGetLeftBorderSize() ;
3297 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3299 return style
& ~wxBORDER_MASK
;
3302 // Find the wxWindowMac at the current mouse position, returning the mouse
3304 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3306 pt
= wxGetMousePosition();
3307 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3312 // Get the current mouse position.
3313 wxPoint
wxGetMousePosition()
3317 wxGetMousePosition( &x
, &y
);
3319 return wxPoint(x
, y
);
3322 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3324 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3326 // copied from wxGTK : CS
3327 // VZ: shouldn't we move this to base class then?
3329 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3332 // (a) it's a command event and so is propagated to the parent
3333 // (b) under MSW it can be generated from kbd too
3334 // (c) it uses screen coords (because of (a))
3335 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3337 this->ClientToScreen(event
.GetPosition()));
3338 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3347 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3349 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3350 CallNextEventHandler(
3351 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3352 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3355 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3359 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3363 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3364 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3369 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3371 return eventNotHandledErr
;
3374 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3376 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3377 if ( !wxWindowBase::Reparent(newParent
) )
3380 // copied from MacPostControlCreate
3381 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3383 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3385 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3390 bool wxWindowMac::SetTransparent(wxByte alpha
)
3392 #if wxMAC_USE_CORE_GRAPHICS
3393 if ( alpha
!= m_macAlpha
)
3395 m_macAlpha
= alpha
;
3405 bool wxWindowMac::CanSetTransparent()
3407 #if wxMAC_USE_CORE_GRAPHICS
3414 wxByte
wxWindowMac::GetTransparent() const