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 wxMAC_USE_CORE_GRAPHICS
941 m_cgContextRef
= NULL
;
944 // as all windows are created with WS_VISIBLE style...
947 m_hScrollBar
= NULL
;
948 m_vScrollBar
= NULL
;
949 m_macBackgroundBrush
= wxNullBrush
;
951 m_macIsUserPane
= true;
952 m_clipChildren
= false ;
953 m_cachedClippedRectValid
= false ;
955 // we need a valid font for the encodings
956 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
959 wxWindowMac::~wxWindowMac()
963 m_isBeingDeleted
= true;
965 MacInvalidateBorders() ;
967 #ifndef __WXUNIVERSAL__
968 // VS: make sure there's no wxFrame with last focus set to us:
969 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
971 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
974 if ( frame
->GetLastFocus() == this )
975 frame
->SetLastFocus((wxWindow
*)NULL
);
981 // destroy children before destroying this window itself
984 // wxRemoveMacControlAssociation( this ) ;
985 // If we delete an item, we should initialize the parent panel,
986 // because it could now be invalid.
987 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
990 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
991 tlw
->SetDefaultItem(NULL
);
994 if ( m_peer
&& m_peer
->Ok() )
996 // in case the callback might be called during destruction
997 wxRemoveMacControlAssociation( this) ;
998 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
999 // we currently are not using this hook
1000 // ::SetControlColorProc( *m_peer , NULL ) ;
1004 if ( g_MacLastWindow
== this )
1005 g_MacLastWindow
= NULL
;
1007 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1010 if ( frame
->GetLastFocus() == this )
1011 frame
->SetLastFocus( NULL
) ;
1014 // delete our drop target if we've got one
1015 #if wxUSE_DRAG_AND_DROP
1016 if ( m_dropTarget
!= NULL
)
1018 delete m_dropTarget
;
1019 m_dropTarget
= NULL
;
1026 WXWidget
wxWindowMac::GetHandle() const
1028 return (WXWidget
) m_peer
->GetControlRef() ;
1031 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1033 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1034 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1035 GetEventTypeCount(eventList
), eventList
, this,
1036 (EventHandlerRef
*)&m_macControlEventHandler
);
1038 #if !TARGET_API_MAC_OSX
1039 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1041 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1042 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1043 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1044 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1045 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1046 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1047 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1048 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1054 bool wxWindowMac::Create(wxWindowMac
*parent
,
1059 const wxString
& name
)
1061 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1063 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1066 m_windowVariant
= parent
->GetWindowVariant() ;
1068 if ( m_macIsUserPane
)
1070 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1073 | kControlSupportsEmbedding
1074 | kControlSupportsLiveFeedback
1075 | kControlGetsFocusOnClick
1076 // | kControlHasSpecialBackground
1077 // | kControlSupportsCalcBestRect
1078 | kControlHandlesTracking
1079 | kControlSupportsFocus
1080 | kControlWantsActivate
1081 | kControlWantsIdle
;
1083 m_peer
= new wxMacControl(this) ;
1084 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1085 verify_noerr( err
);
1087 MacPostControlCreate(pos
, size
) ;
1090 #ifndef __WXUNIVERSAL__
1091 // Don't give scrollbars to wxControls unless they ask for them
1092 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1093 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1095 MacCreateScrollBars( style
) ;
1099 wxWindowCreateEvent
event(this);
1100 GetEventHandler()->AddPendingEvent(event
);
1105 void wxWindowMac::MacChildAdded()
1108 m_vScrollBar
->Raise() ;
1110 m_hScrollBar
->Raise() ;
1113 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1115 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1117 m_peer
->SetReference( (URefCon
) this ) ;
1118 GetParent()->AddChild( this );
1120 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1122 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1123 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1124 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1125 GetParent()->MacChildAdded() ;
1127 // adjust font, controlsize etc
1128 DoSetWindowVariant( m_windowVariant
) ;
1130 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1132 if (!m_macIsUserPane
)
1133 SetInitialSize(size
);
1135 SetCursor( *wxSTANDARD_CURSOR
) ;
1138 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1140 // Don't assert, in case we set the window variant before
1141 // the window is created
1142 // wxASSERT( m_peer->Ok() ) ;
1144 m_windowVariant
= variant
;
1146 if (m_peer
== NULL
|| !m_peer
->Ok())
1150 ThemeFontID themeFont
= kThemeSystemFont
;
1152 // we will get that from the settings later
1153 // and make this NORMAL later, but first
1154 // we have a few calculations that we must fix
1158 case wxWINDOW_VARIANT_NORMAL
:
1159 size
= kControlSizeNormal
;
1160 themeFont
= kThemeSystemFont
;
1163 case wxWINDOW_VARIANT_SMALL
:
1164 size
= kControlSizeSmall
;
1165 themeFont
= kThemeSmallSystemFont
;
1168 case wxWINDOW_VARIANT_MINI
:
1169 if (UMAGetSystemVersion() >= 0x1030 )
1171 // not always defined in the headers
1177 size
= kControlSizeSmall
;
1178 themeFont
= kThemeSmallSystemFont
;
1182 case wxWINDOW_VARIANT_LARGE
:
1183 size
= kControlSizeLarge
;
1184 themeFont
= kThemeSystemFont
;
1188 wxFAIL_MSG(_T("unexpected window variant"));
1192 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1195 font
.MacCreateThemeFont( themeFont
) ;
1199 void wxWindowMac::MacUpdateControlFont()
1201 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1205 bool wxWindowMac::SetFont(const wxFont
& font
)
1207 bool retval
= wxWindowBase::SetFont( font
);
1209 MacUpdateControlFont() ;
1214 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1216 bool retval
= wxWindowBase::SetForegroundColour( col
);
1219 MacUpdateControlFont();
1224 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1226 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1230 wxColour
newCol(GetBackgroundColour());
1232 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1233 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1234 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1235 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1237 brush
.SetColour( newCol
) ;
1239 MacSetBackgroundBrush( brush
) ;
1240 MacUpdateControlFont() ;
1245 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1247 m_macBackgroundBrush
= brush
;
1248 m_peer
->SetBackground( brush
) ;
1251 bool wxWindowMac::MacCanFocus() const
1253 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1254 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1255 // but the value range is nowhere documented
1256 Boolean keyExistsAndHasValidFormat
;
1257 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1258 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1260 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1266 UInt32 features
= 0 ;
1267 m_peer
->GetFeatures( &features
) ;
1269 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1273 void wxWindowMac::SetFocus()
1275 if ( !AcceptsFocus() )
1278 wxWindow
* former
= FindFocus() ;
1279 if ( former
== this )
1282 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1283 // we can only leave in case of an error
1284 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1285 if ( err
== errCouldntSetFocus
)
1288 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1290 #if !TARGET_API_MAC_OSX
1291 // emulate carbon events when running under CarbonLib where they are not natively available
1294 EventRef evRef
= NULL
;
1296 err
= MacCreateEvent(
1297 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1298 kEventAttributeUserEvent
, &evRef
);
1299 verify_noerr( err
);
1301 wxMacCarbonEvent
cEvent( evRef
) ;
1302 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1303 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1305 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1306 ReleaseEvent( evRef
) ;
1309 // send new focus event
1311 EventRef evRef
= NULL
;
1313 err
= MacCreateEvent(
1314 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1315 kEventAttributeUserEvent
, &evRef
);
1316 verify_noerr( err
);
1318 wxMacCarbonEvent
cEvent( evRef
) ;
1319 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1320 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1322 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1323 ReleaseEvent( evRef
) ;
1328 void wxWindowMac::DoCaptureMouse()
1330 wxApp::s_captureWindow
= this ;
1333 wxWindow
* wxWindowBase::GetCapture()
1335 return wxApp::s_captureWindow
;
1338 void wxWindowMac::DoReleaseMouse()
1340 wxApp::s_captureWindow
= NULL
;
1343 #if wxUSE_DRAG_AND_DROP
1345 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1347 if ( m_dropTarget
!= NULL
)
1348 delete m_dropTarget
;
1350 m_dropTarget
= pDropTarget
;
1351 if ( m_dropTarget
!= NULL
)
1359 // Old-style File Manager Drag & Drop
1360 void wxWindowMac::DragAcceptFiles(bool accept
)
1365 // Returns the size of the native control. In the case of the toplevel window
1366 // this is the content area root control
1368 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1369 int& w
, int& h
) const
1371 wxFAIL_MSG( wxT("Not currently supported") ) ;
1374 // From a wx position / size calculate the appropriate size of the native control
1376 bool wxWindowMac::MacGetBoundsForControl(
1380 int& w
, int& h
, bool adjustOrigin
) const
1382 // the desired size, minus the border pixels gives the correct size of the control
1386 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1387 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1388 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1390 x
+= MacGetLeftBorderSize() ;
1391 y
+= MacGetTopBorderSize() ;
1392 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1393 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1396 AdjustForParentClientOrigin( x
, y
) ;
1398 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1399 if ( !GetParent()->IsTopLevel() )
1401 x
-= GetParent()->MacGetLeftBorderSize() ;
1402 y
-= GetParent()->MacGetTopBorderSize() ;
1408 // Get window size (not client size)
1409 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1412 m_peer
->GetRect( &bounds
) ;
1415 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1417 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1420 // get the position of the bounds of this window in client coordinates of its parent
1421 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1424 m_peer
->GetRect( &bounds
) ;
1426 int x1
= bounds
.left
;
1427 int y1
= bounds
.top
;
1429 // get the wx window position from the native one
1430 x1
-= MacGetLeftBorderSize() ;
1431 y1
-= MacGetTopBorderSize() ;
1433 if ( !IsTopLevel() )
1435 wxWindow
*parent
= GetParent();
1438 // we must first adjust it to be in window coordinates of the parent,
1439 // as otherwise it gets lost by the ClientAreaOrigin fix
1440 x1
+= parent
->MacGetLeftBorderSize() ;
1441 y1
+= parent
->MacGetTopBorderSize() ;
1443 // and now to client coordinates
1444 wxPoint
pt(parent
->GetClientAreaOrigin());
1456 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1458 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1459 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1461 Point localwhere
= { 0, 0 } ;
1468 wxMacGlobalToLocal( window
, &localwhere
) ;
1475 MacRootWindowToWindow( x
, y
) ;
1477 wxPoint origin
= GetClientAreaOrigin() ;
1484 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1486 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1487 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1489 wxPoint origin
= GetClientAreaOrigin() ;
1495 MacWindowToRootWindow( x
, y
) ;
1497 Point localwhere
= { 0, 0 };
1503 wxMacLocalToGlobal( window
, &localwhere
) ;
1511 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1513 wxPoint origin
= GetClientAreaOrigin() ;
1519 MacWindowToRootWindow( x
, y
) ;
1522 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1524 MacRootWindowToWindow( x
, y
) ;
1526 wxPoint origin
= GetClientAreaOrigin() ;
1533 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1542 if ( !IsTopLevel() )
1544 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1547 pt
.x
-= MacGetLeftBorderSize() ;
1548 pt
.y
-= MacGetTopBorderSize() ;
1549 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1559 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1568 MacWindowToRootWindow( &x1
, &y1
) ;
1576 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1585 if ( !IsTopLevel() )
1587 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1590 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1591 pt
.x
+= MacGetLeftBorderSize() ;
1592 pt
.y
+= MacGetTopBorderSize() ;
1602 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1611 MacRootWindowToWindow( &x1
, &y1
) ;
1619 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1621 RgnHandle rgn
= NewRgn() ;
1623 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1625 Rect structure
, content
;
1627 GetRegionBounds( rgn
, &content
) ;
1628 m_peer
->GetRect( &structure
) ;
1629 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1631 left
= content
.left
- structure
.left
;
1632 top
= content
.top
- structure
.top
;
1633 right
= structure
.right
- content
.right
;
1634 bottom
= structure
.bottom
- content
.bottom
;
1638 left
= top
= right
= bottom
= 0 ;
1644 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1646 wxSize sizeTotal
= size
;
1648 RgnHandle rgn
= NewRgn() ;
1649 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1651 Rect content
, structure
;
1652 GetRegionBounds( rgn
, &content
) ;
1653 m_peer
->GetRect( &structure
) ;
1655 // structure is in parent coordinates, but we only need width and height, so it's ok
1657 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1658 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1663 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1664 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1669 // Get size *available for subwindows* i.e. excluding menu bar etc.
1670 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1674 RgnHandle rgn
= NewRgn() ;
1676 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1677 GetRegionBounds( rgn
, &content
) ;
1679 m_peer
->GetRect( &content
) ;
1682 ww
= content
.right
- content
.left
;
1683 hh
= content
.bottom
- content
.top
;
1685 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1686 hh
-= m_hScrollBar
->GetSize().y
;
1688 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1689 ww
-= m_vScrollBar
->GetSize().x
;
1697 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1699 if (m_cursor
.IsSameAs(cursor
))
1704 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1709 if ( ! wxWindowBase::SetCursor( cursor
) )
1713 wxASSERT_MSG( m_cursor
.Ok(),
1714 wxT("cursor must be valid after call to the base version"));
1716 wxWindowMac
*mouseWin
= 0 ;
1718 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1719 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1721 ControlPartCode part
;
1722 ControlRef control
;
1724 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1726 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1731 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1733 // TODO: If we ever get a GetCurrentEvent... replacement
1734 // for the mouse position, use it...
1739 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1741 mouseWin
= wxFindControlFromMacControl( control
) ;
1743 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1745 QDSwapPort( savePort
, NULL
) ;
1749 if ( mouseWin
== this && !wxIsBusy() )
1750 m_cursor
.MacInstall() ;
1756 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1758 menu
->SetInvokingWindow(this);
1761 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1763 wxPoint mouse
= wxGetMousePosition();
1769 ClientToScreen( &x
, &y
) ;
1772 menu
->MacBeforeDisplay( true ) ;
1773 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1774 if ( HiWord(menuResult
) != 0 )
1777 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1778 int id
= wxMacCommandToId( macid
);
1779 wxMenuItem
* item
= NULL
;
1781 item
= menu
->FindItem( id
, &realmenu
) ;
1784 if (item
->IsCheckable())
1785 item
->Check( !item
->IsChecked() ) ;
1787 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1791 menu
->MacAfterDisplay( true ) ;
1792 menu
->SetInvokingWindow( NULL
);
1798 // ----------------------------------------------------------------------------
1800 // ----------------------------------------------------------------------------
1804 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1806 wxWindowBase::DoSetToolTip(tooltip
);
1809 m_tooltip
->SetWindow(this);
1814 void wxWindowMac::MacInvalidateBorders()
1816 if ( m_peer
== NULL
)
1819 bool vis
= MacIsReallyShown() ;
1823 int outerBorder
= MacGetLeftBorderSize() ;
1824 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1827 if ( outerBorder
== 0 )
1830 // now we know that we have something to do at all
1832 // as the borders are drawn on the parent we have to properly invalidate all these areas
1833 RgnHandle updateInner
, updateOuter
;
1836 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1837 updateInner
= NewRgn() ;
1838 updateOuter
= NewRgn() ;
1840 m_peer
->GetRect( &rect
) ;
1841 RectRgn( updateInner
, &rect
) ;
1842 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1843 RectRgn( updateOuter
, &rect
) ;
1844 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1846 #ifdef __WXMAC_OSX__
1847 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1849 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1851 InvalWindowRgn( tlw
, updateOuter
) ;
1854 DisposeRgn( updateOuter
) ;
1855 DisposeRgn( updateInner
) ;
1858 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1860 // this is never called for a toplevel window, so we know we have a parent
1861 int former_x
, former_y
, former_w
, former_h
;
1863 // Get true coordinates of former position
1864 DoGetPosition( &former_x
, &former_y
) ;
1865 DoGetSize( &former_w
, &former_h
) ;
1867 wxWindow
*parent
= GetParent();
1870 wxPoint
pt(parent
->GetClientAreaOrigin());
1875 int actualWidth
= width
;
1876 int actualHeight
= height
;
1880 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1881 actualWidth
= m_minWidth
;
1882 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1883 actualHeight
= m_minHeight
;
1884 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1885 actualWidth
= m_maxWidth
;
1886 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1887 actualHeight
= m_maxHeight
;
1889 bool doMove
= false, doResize
= false ;
1891 if ( actualX
!= former_x
|| actualY
!= former_y
)
1894 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1897 if ( doMove
|| doResize
)
1899 // as the borders are drawn outside the native control, we adjust now
1901 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1902 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1903 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1906 wxMacRectToNative( &bounds
, &r
) ;
1908 if ( !GetParent()->IsTopLevel() )
1909 wxMacWindowToNative( GetParent() , &r
) ;
1911 MacInvalidateBorders() ;
1913 m_cachedClippedRectValid
= false ;
1914 m_peer
->SetRect( &r
) ;
1916 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1918 MacInvalidateBorders() ;
1920 MacRepositionScrollBars() ;
1923 wxPoint
point(actualX
, actualY
);
1924 wxMoveEvent
event(point
, m_windowId
);
1925 event
.SetEventObject(this);
1926 GetEventHandler()->ProcessEvent(event
) ;
1931 MacRepositionScrollBars() ;
1932 wxSize
size(actualWidth
, actualHeight
);
1933 wxSizeEvent
event(size
, m_windowId
);
1934 event
.SetEventObject(this);
1935 GetEventHandler()->ProcessEvent(event
);
1940 wxSize
wxWindowMac::DoGetBestSize() const
1942 if ( m_macIsUserPane
|| IsTopLevel() )
1943 return wxWindowBase::DoGetBestSize() ;
1945 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1946 int bestWidth
, bestHeight
;
1948 m_peer
->GetBestRect( &bestsize
) ;
1949 if ( EmptyRect( &bestsize
) )
1954 bestsize
.bottom
= 16 ;
1956 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1958 bestsize
.bottom
= 16 ;
1961 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1963 bestsize
.bottom
= 24 ;
1968 // return wxWindowBase::DoGetBestSize() ;
1972 bestWidth
= bestsize
.right
- bestsize
.left
;
1973 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1974 if ( bestHeight
< 10 )
1977 return wxSize(bestWidth
, bestHeight
);
1980 // set the size of the window: if the dimensions are positive, just use them,
1981 // but if any of them is equal to -1, it means that we must find the value for
1982 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1983 // which case -1 is a valid value for x and y)
1985 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1986 // the width/height to best suit our contents, otherwise we reuse the current
1988 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1990 // get the current size and position...
1991 int currentX
, currentY
;
1992 int currentW
, currentH
;
1994 GetPosition(¤tX
, ¤tY
);
1995 GetSize(¤tW
, ¤tH
);
1997 // ... and don't do anything (avoiding flicker) if it's already ok
1998 if ( x
== currentX
&& y
== currentY
&&
1999 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2002 MacRepositionScrollBars() ; // we might have a real position shift
2007 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2009 if ( x
== wxDefaultCoord
)
2011 if ( y
== wxDefaultCoord
)
2015 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2017 wxSize size
= wxDefaultSize
;
2018 if ( width
== wxDefaultCoord
)
2020 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2022 size
= DoGetBestSize();
2027 // just take the current one
2032 if ( height
== wxDefaultCoord
)
2034 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2036 if ( size
.x
== wxDefaultCoord
)
2037 size
= DoGetBestSize();
2038 // else: already called DoGetBestSize() above
2044 // just take the current one
2049 DoMoveWindow( x
, y
, width
, height
);
2052 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2054 RgnHandle rgn
= NewRgn() ;
2056 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2058 GetRegionBounds( rgn
, &content
) ;
2068 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2071 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2073 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2075 int currentclientwidth
, currentclientheight
;
2076 int currentwidth
, currentheight
;
2078 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2079 GetSize( ¤twidth
, ¤theight
) ;
2081 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2082 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2086 void wxWindowMac::SetLabel(const wxString
& title
)
2088 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2090 if ( m_peer
&& m_peer
->Ok() )
2091 m_peer
->SetLabel( m_label
) ;
2096 wxString
wxWindowMac::GetLabel() const
2101 bool wxWindowMac::Show(bool show
)
2103 bool former
= MacIsReallyShown() ;
2104 if ( !wxWindowBase::Show(show
) )
2107 // TODO: use visibilityChanged Carbon Event for OSX
2109 m_peer
->SetVisibility( show
, true ) ;
2111 if ( former
!= MacIsReallyShown() )
2112 MacPropagateVisibilityChanged() ;
2117 bool wxWindowMac::Enable(bool enable
)
2119 wxASSERT( m_peer
->Ok() ) ;
2120 bool former
= MacIsReallyEnabled() ;
2121 if ( !wxWindowBase::Enable(enable
) )
2124 m_peer
->Enable( enable
) ;
2126 if ( former
!= MacIsReallyEnabled() )
2127 MacPropagateEnabledStateChanged() ;
2133 // status change propagations (will be not necessary for OSX later )
2136 void wxWindowMac::MacPropagateVisibilityChanged()
2138 #if !TARGET_API_MAC_OSX
2139 MacVisibilityChanged() ;
2142 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2145 child
= node
->GetData();
2146 if ( child
->IsShown() )
2147 child
->MacPropagateVisibilityChanged() ;
2149 node
= node
->GetNext();
2154 void wxWindowMac::MacPropagateEnabledStateChanged()
2156 #if !TARGET_API_MAC_OSX
2157 MacEnabledStateChanged() ;
2160 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2163 child
= node
->GetData();
2164 if ( child
->IsEnabled() )
2165 child
->MacPropagateEnabledStateChanged() ;
2167 node
= node
->GetNext();
2172 void wxWindowMac::MacPropagateHiliteChanged()
2174 #if !TARGET_API_MAC_OSX
2175 MacHiliteChanged() ;
2178 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2181 child
= node
->GetData();
2182 if (child
/* && child->IsEnabled() */)
2183 child
->MacPropagateHiliteChanged() ;
2185 node
= node
->GetNext();
2191 // status change notifications
2194 void wxWindowMac::MacVisibilityChanged()
2198 void wxWindowMac::MacHiliteChanged()
2202 void wxWindowMac::MacEnabledStateChanged()
2207 // status queries on the inherited window's state
2210 bool wxWindowMac::MacIsReallyShown()
2212 // only under OSX the visibility of the TLW is taken into account
2213 if ( m_isBeingDeleted
)
2216 #if TARGET_API_MAC_OSX
2217 if ( m_peer
&& m_peer
->Ok() )
2218 return m_peer
->IsVisible();
2221 wxWindow
* win
= this ;
2222 while ( win
->IsShown() )
2224 if ( win
->IsTopLevel() )
2227 win
= win
->GetParent() ;
2235 bool wxWindowMac::MacIsReallyEnabled()
2237 return m_peer
->IsEnabled() ;
2240 bool wxWindowMac::MacIsReallyHilited()
2242 return m_peer
->IsActive();
2245 void wxWindowMac::MacFlashInvalidAreas()
2247 #if TARGET_API_MAC_OSX
2248 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2252 int wxWindowMac::GetCharHeight() const
2254 wxClientDC
dc( (wxWindowMac
*)this ) ;
2256 return dc
.GetCharHeight() ;
2259 int wxWindowMac::GetCharWidth() const
2261 wxClientDC
dc( (wxWindowMac
*)this ) ;
2263 return dc
.GetCharWidth() ;
2266 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2267 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2269 const wxFont
*fontToUse
= theFont
;
2271 fontToUse
= &m_font
;
2273 wxClientDC
dc( (wxWindowMac
*) this ) ;
2275 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2276 if ( externalLeading
)
2277 *externalLeading
= le
;
2287 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2288 * we always intersect with the entire window, not only with the client area
2291 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2293 if ( m_peer
== NULL
)
2296 if ( !MacIsReallyShown() )
2303 wxMacRectToNative( rect
, &r
) ;
2304 m_peer
->SetNeedsDisplay( &r
) ;
2308 m_peer
->SetNeedsDisplay() ;
2312 void wxWindowMac::Freeze()
2314 #if TARGET_API_MAC_OSX
2315 if ( !m_frozenness
++ )
2317 if ( m_peer
&& m_peer
->Ok() )
2318 m_peer
->SetDrawingEnabled( false ) ;
2323 void wxWindowMac::Thaw()
2325 #if TARGET_API_MAC_OSX
2326 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2328 if ( !--m_frozenness
)
2330 if ( m_peer
&& m_peer
->Ok() )
2332 m_peer
->SetDrawingEnabled( true ) ;
2333 m_peer
->InvalidateWithChildren() ;
2339 bool wxWindowMac::IsFrozen() const
2341 return m_frozenness
!= 0;
2344 wxWindowMac
*wxGetActiveWindow()
2346 // actually this is a windows-only concept
2350 // Coordinates relative to the window
2351 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2353 // We really don't move the mouse programmatically under Mac.
2356 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2358 if ( MacGetTopLevelWindow() == NULL
)
2361 #if TARGET_API_MAC_OSX
2362 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2369 event
.GetDC()->Clear() ;
2373 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2378 int wxWindowMac::GetScrollPos(int orient
) const
2380 if ( orient
== wxHORIZONTAL
)
2383 return m_hScrollBar
->GetThumbPosition() ;
2388 return m_vScrollBar
->GetThumbPosition() ;
2394 // This now returns the whole range, not just the number
2395 // of positions that we can scroll.
2396 int wxWindowMac::GetScrollRange(int orient
) const
2398 if ( orient
== wxHORIZONTAL
)
2401 return m_hScrollBar
->GetRange() ;
2406 return m_vScrollBar
->GetRange() ;
2412 int wxWindowMac::GetScrollThumb(int orient
) const
2414 if ( orient
== wxHORIZONTAL
)
2417 return m_hScrollBar
->GetThumbSize() ;
2422 return m_vScrollBar
->GetThumbSize() ;
2428 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2430 if ( orient
== wxHORIZONTAL
)
2433 m_hScrollBar
->SetThumbPosition( pos
) ;
2438 m_vScrollBar
->SetThumbPosition( pos
) ;
2443 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2444 // our own window origin is at leftOrigin/rightOrigin
2447 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2453 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2454 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2456 // back to the surrounding frame rectangle
2457 m_peer
->GetRect( &rect
) ;
2458 InsetRect( &rect
, -1 , -1 ) ;
2460 #if wxMAC_USE_CORE_GRAPHICS
2462 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2463 rect
.bottom
- rect
.top
) ;
2465 HIThemeFrameDrawInfo info
;
2466 memset( &info
, 0 , sizeof(info
) ) ;
2470 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2471 info
.isFocused
= hasFocus
;
2473 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2474 wxASSERT( cgContext
) ;
2476 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2478 info
.kind
= kHIThemeFrameTextFieldSquare
;
2479 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2481 else if ( HasFlag(wxSIMPLE_BORDER
) )
2483 info
.kind
= kHIThemeFrameListBox
;
2484 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2486 else if ( hasFocus
)
2488 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2491 m_peer
->GetRect( &rect
) ;
2492 if ( hasBothScrollbars
)
2494 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2495 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2496 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2497 HIThemeGrowBoxDrawInfo info
;
2498 memset( &info
, 0, sizeof(info
) ) ;
2500 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2501 info
.kind
= kHIThemeGrowBoxKindNone
;
2502 info
.size
= kHIThemeGrowBoxSizeNormal
;
2503 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2504 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2509 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2513 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2514 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2517 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2518 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2519 else if ( HasFlag(wxSIMPLE_BORDER
) )
2520 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2523 DrawThemeFocusRect( &rect
, true ) ;
2525 if ( hasBothScrollbars
)
2527 // GetThemeStandaloneGrowBoxBounds
2528 // DrawThemeStandaloneNoGrowBox
2534 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2536 if ( child
== m_hScrollBar
)
2537 m_hScrollBar
= NULL
;
2538 if ( child
== m_vScrollBar
)
2539 m_vScrollBar
= NULL
;
2541 wxWindowBase::RemoveChild( child
) ;
2544 // New function that will replace some of the above.
2545 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2546 int range
, bool refresh
)
2549 bool triggerSizeEvent
= false;
2551 if ( orient
== wxHORIZONTAL
)
2555 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2556 if ( m_hScrollBar
->IsShown() != showScroller
)
2558 m_hScrollBar
->Show( showScroller
);
2559 triggerSizeEvent
= true;
2562 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2569 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2570 if ( m_vScrollBar
->IsShown() != showScroller
)
2572 m_vScrollBar
->Show( showScroller
) ;
2573 triggerSizeEvent
= true;
2576 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2580 MacRepositionScrollBars() ;
2581 if ( triggerSizeEvent
)
2583 wxSizeEvent
event(GetSize(), m_windowId
);
2584 event
.SetEventObject(this);
2585 GetEventHandler()->ProcessEvent(event
);
2589 // Does a physical scroll
2590 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2592 if ( dx
== 0 && dy
== 0 )
2595 int width
, height
;
2596 GetClientSize( &width
, &height
) ;
2599 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2600 // area is scrolled, this does not occur if width and height are 2 pixels less,
2601 // TODO: write optimal workaround
2602 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2604 scrollrect
.Intersect( *rect
) ;
2606 if ( m_peer
->GetNeedsDisplay() )
2608 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2609 // either immediate redraw or full invalidate
2611 // is the better overall solution, as it does not slow down scrolling
2612 m_peer
->SetNeedsDisplay() ;
2614 // this would be the preferred version for fast drawing controls
2616 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2617 if ( UMAGetSystemVersion() >= 0x1030 )
2618 HIViewRender(m_peer
->GetControlRef()) ;
2625 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2626 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2627 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2629 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2630 // either immediate redraw or full invalidate
2632 // is the better overall solution, as it does not slow down scrolling
2633 m_peer
->SetNeedsDisplay() ;
2635 // this would be the preferred version for fast drawing controls
2637 HIViewRender(m_peer
->GetControlRef()) ;
2643 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2645 child
= node
->GetData();
2648 if (child
== m_vScrollBar
)
2650 if (child
== m_hScrollBar
)
2652 if (child
->IsTopLevel())
2655 child
->GetPosition( &x
, &y
);
2656 child
->GetSize( &w
, &h
);
2659 wxRect
rc( x
, y
, w
, h
);
2660 if (rect
->Intersects( rc
))
2661 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2665 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2670 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2672 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2674 wxScrollWinEvent wevent
;
2675 wevent
.SetPosition(event
.GetPosition());
2676 wevent
.SetOrientation(event
.GetOrientation());
2677 wevent
.SetEventObject(this);
2679 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2680 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2681 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2682 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2683 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2684 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2685 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2686 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2687 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2688 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2689 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2690 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2691 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2692 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2693 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2694 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2696 GetEventHandler()->ProcessEvent(wevent
);
2700 // Get the window with the focus
2701 wxWindowMac
*wxWindowBase::DoFindFocus()
2703 ControlRef control
;
2704 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2705 return wxFindControlFromMacControl( control
) ;
2708 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2710 // panel wants to track the window which was the last to have focus in it,
2711 // so we want to set ourselves as the window which last had focus
2713 // notice that it's also important to do it upwards the tree because
2714 // otherwise when the top level panel gets focus, it won't set it back to
2715 // us, but to some other sibling
2717 // CS: don't know if this is still needed:
2718 //wxChildFocusEvent eventFocus(this);
2719 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2721 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2723 #if wxMAC_USE_CORE_GRAPHICS
2724 GetParent()->Refresh() ;
2726 wxMacWindowStateSaver
sv( this ) ;
2729 m_peer
->GetRect( &rect
) ;
2730 // auf den umgebenden Rahmen zur\9fck
2731 InsetRect( &rect
, -1 , -1 ) ;
2733 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2737 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2739 rect
.right
+= pt
.x
;
2741 rect
.bottom
+= pt
.y
;
2744 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2745 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2746 if ( !bIsFocusEvent
)
2748 // as this erases part of the frame we have to redraw borders
2749 // and because our z-ordering is not always correct (staticboxes)
2750 // we have to invalidate things, we cannot simple redraw
2751 MacInvalidateBorders() ;
2759 void wxWindowMac::OnInternalIdle()
2761 // This calls the UI-update mechanism (querying windows for
2762 // menu/toolbar/control state information)
2763 if (wxUpdateUIEvent::CanUpdate(this))
2764 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2767 // Raise the window to the top of the Z order
2768 void wxWindowMac::Raise()
2770 m_peer
->SetZOrder( true , NULL
) ;
2773 // Lower the window to the bottom of the Z order
2774 void wxWindowMac::Lower()
2776 m_peer
->SetZOrder( false , NULL
) ;
2779 // static wxWindow *gs_lastWhich = NULL;
2781 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2783 // first trigger a set cursor event
2785 wxPoint clientorigin
= GetClientAreaOrigin() ;
2786 wxSize clientsize
= GetClientSize() ;
2788 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2790 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2792 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2793 if ( processedEvtSetCursor
&& event
.HasCursor() )
2795 cursor
= event
.GetCursor() ;
2799 // the test for processedEvtSetCursor is here to prevent using m_cursor
2800 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2801 // it - this is a way to say that our cursor shouldn't be used for this
2803 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2806 if ( !wxIsBusy() && !GetParent() )
2807 cursor
= *wxSTANDARD_CURSOR
;
2811 cursor
.MacInstall() ;
2814 return cursor
.Ok() ;
2817 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2821 return m_tooltip
->GetTip() ;
2824 return wxEmptyString
;
2827 void wxWindowMac::ClearBackground()
2833 void wxWindowMac::Update()
2835 #if TARGET_API_MAC_OSX
2836 MacGetTopLevelWindow()->MacPerformUpdates() ;
2838 ::Draw1Control( m_peer
->GetControlRef() ) ;
2842 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2844 wxTopLevelWindowMac
* win
= NULL
;
2845 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2847 win
= wxFindWinFromMacWindow( window
) ;
2852 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2854 MacUpdateClippedRects() ;
2856 return m_cachedClippedClientRect
;
2859 const wxRect
& wxWindowMac::MacGetClippedRect() const
2861 MacUpdateClippedRects() ;
2863 return m_cachedClippedRect
;
2866 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2868 MacUpdateClippedRects() ;
2870 return m_cachedClippedRectWithOuterStructure
;
2873 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2875 static wxRegion emptyrgn
;
2877 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2879 MacUpdateClippedRects() ;
2880 if ( includeOuterStructures
)
2881 return m_cachedClippedRegionWithOuterStructure
;
2883 return m_cachedClippedRegion
;
2891 void wxWindowMac::MacUpdateClippedRects() const
2893 if ( m_cachedClippedRectValid
)
2896 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2897 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2898 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2899 // to add focus borders everywhere
2901 Rect r
, rIncludingOuterStructures
;
2903 m_peer
->GetRect( &r
) ;
2904 r
.left
-= MacGetLeftBorderSize() ;
2905 r
.top
-= MacGetTopBorderSize() ;
2906 r
.bottom
+= MacGetBottomBorderSize() ;
2907 r
.right
+= MacGetRightBorderSize() ;
2914 rIncludingOuterStructures
= r
;
2915 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2917 wxRect cl
= GetClientRect() ;
2918 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2922 const wxWindow
* child
= this ;
2923 const wxWindow
* parent
= NULL
;
2925 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2927 if ( parent
->MacIsChildOfClientArea(child
) )
2929 size
= parent
->GetClientSize() ;
2930 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2936 // this will be true for scrollbars, toolbars etc.
2937 size
= parent
->GetSize() ;
2938 y
= parent
->MacGetTopBorderSize() ;
2939 x
= parent
->MacGetLeftBorderSize() ;
2940 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2941 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2944 parent
->MacWindowToRootWindow( &x
, &y
) ;
2945 MacRootWindowToWindow( &x
, &y
) ;
2947 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2949 // the wxwindow and client rects will always be clipped
2950 SectRect( &r
, &rparent
, &r
) ;
2951 SectRect( &rClient
, &rparent
, &rClient
) ;
2953 // the structure only at 'hard' borders
2954 if ( parent
->MacClipChildren() ||
2955 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2957 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2963 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2964 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2965 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2966 m_cachedClippedRectWithOuterStructure
= wxRect(
2967 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2968 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2969 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2971 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2972 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2973 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2975 m_cachedClippedRectValid
= true ;
2979 This function must not change the updatergn !
2981 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2983 bool handled
= false ;
2985 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2986 GetRegionBounds( updatergn
, &updatebounds
) ;
2988 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2990 if ( !EmptyRgn(updatergn
) )
2992 RgnHandle newupdate
= NewRgn() ;
2993 wxSize point
= GetClientSize() ;
2994 wxPoint origin
= GetClientAreaOrigin() ;
2995 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2996 SectRgn( newupdate
, updatergn
, newupdate
) ;
2998 // first send an erase event to the entire update area
3000 // for the toplevel window this really is the entire area
3001 // for all the others only their client area, otherwise they
3002 // might be drawing with full alpha and eg put blue into
3003 // the grow-box area of a scrolled window (scroll sample)
3004 wxDC
* dc
= new wxWindowDC(this);
3006 dc
->SetClippingRegion(wxRegion(updatergn
));
3008 dc
->SetClippingRegion(wxRegion(newupdate
));
3010 wxEraseEvent
eevent( GetId(), dc
);
3011 eevent
.SetEventObject( this );
3012 GetEventHandler()->ProcessEvent( eevent
);
3016 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3017 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3018 m_updateRegion
= newupdate
;
3019 DisposeRgn( newupdate
) ;
3021 if ( !m_updateRegion
.Empty() )
3023 // paint the window itself
3026 event
.SetTimestamp(time
);
3027 event
.SetEventObject(this);
3028 GetEventHandler()->ProcessEvent(event
);
3032 // now we cannot rely on having its borders drawn by a window itself, as it does not
3033 // get the updateRgn wide enough to always do so, so we do it from the parent
3034 // this would also be the place to draw any custom backgrounds for native controls
3035 // in Composited windowing
3036 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3040 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3042 child
= node
->GetData();
3045 if (child
== m_vScrollBar
)
3047 if (child
== m_hScrollBar
)
3049 if (child
->IsTopLevel())
3051 if (!child
->IsShown())
3054 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3056 child
->GetPosition( &x
, &y
);
3057 child
->GetSize( &w
, &h
);
3058 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3059 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3060 InsetRect( &childRect
, -10 , -10) ;
3062 if ( RectInRgn( &childRect
, updatergn
) )
3064 // paint custom borders
3065 wxNcPaintEvent
eventNc( child
->GetId() );
3066 eventNc
.SetEventObject( child
);
3067 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3069 #if wxMAC_USE_CORE_GRAPHICS
3070 child
->MacPaintBorders(0, 0) ;
3073 wxWindowDC
dc(this) ;
3074 dc
.SetClippingRegion(wxRegion(updatergn
));
3075 wxMacPortSetter
helper(&dc
) ;
3076 child
->MacPaintBorders(0, 0) ;
3088 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3090 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3094 if ( iter
->IsTopLevel() )
3095 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3097 iter
= iter
->GetParent() ;
3103 void wxWindowMac::MacCreateScrollBars( long style
)
3105 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3107 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3109 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3110 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3111 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3113 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3116 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3118 GetClientSize( &width
, &height
) ;
3120 wxPoint
vPoint(width
- scrlsize
, 0) ;
3121 wxSize
vSize(scrlsize
, height
- adjust
) ;
3122 wxPoint
hPoint(0, height
- scrlsize
) ;
3123 wxSize
hSize(width
- adjust
, scrlsize
) ;
3125 if ( style
& wxVSCROLL
)
3126 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3128 if ( style
& wxHSCROLL
)
3129 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3132 // because the create does not take into account the client area origin
3133 // we might have a real position shift
3134 MacRepositionScrollBars() ;
3137 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3139 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3144 void wxWindowMac::MacRepositionScrollBars()
3146 if ( !m_hScrollBar
&& !m_vScrollBar
)
3149 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3150 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3151 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3153 // get real client area
3155 GetSize( &width
, &height
);
3157 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3158 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3160 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3161 wxSize
vSize( scrlsize
, height
- adjust
) ;
3162 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3163 wxSize
hSize( width
- adjust
, scrlsize
) ;
3166 int x
= 0, y
= 0, w
, h
;
3167 GetSize( &w
, &h
) ;
3169 MacClientToRootWindow( &x
, &y
) ;
3170 MacClientToRootWindow( &w
, &h
) ;
3172 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3174 int totW
= 10000 , totH
= 10000;
3177 if ( iter
->IsTopLevel() )
3179 iter
->GetSize( &totW
, &totH
) ;
3183 iter
= iter
->GetParent() ;
3197 if ( w
- x
>= totW
)
3202 if ( h
- y
>= totH
)
3210 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3212 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3215 bool wxWindowMac::AcceptsFocus() const
3217 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3220 void wxWindowMac::MacSuperChangedPosition()
3222 // only window-absolute structures have to be moved i.e. controls
3224 m_cachedClippedRectValid
= false ;
3227 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3230 child
= node
->GetData();
3231 child
->MacSuperChangedPosition() ;
3233 node
= node
->GetNext();
3237 void wxWindowMac::MacTopLevelWindowChangedPosition()
3239 // only screen-absolute structures have to be moved i.e. glcanvas
3242 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3245 child
= node
->GetData();
3246 child
->MacTopLevelWindowChangedPosition() ;
3248 node
= node
->GetNext();
3252 long wxWindowMac::MacGetLeftBorderSize() const
3259 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3261 // this metric is only the 'outset' outside the simple frame rect
3262 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3265 else if (HasFlag(wxSIMPLE_BORDER
))
3267 // this metric is only the 'outset' outside the simple frame rect
3268 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3275 long wxWindowMac::MacGetRightBorderSize() const
3277 // they are all symmetric in mac themes
3278 return MacGetLeftBorderSize() ;
3281 long wxWindowMac::MacGetTopBorderSize() const
3283 // they are all symmetric in mac themes
3284 return MacGetLeftBorderSize() ;
3287 long wxWindowMac::MacGetBottomBorderSize() const
3289 // they are all symmetric in mac themes
3290 return MacGetLeftBorderSize() ;
3293 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3295 return style
& ~wxBORDER_MASK
;
3298 // Find the wxWindowMac at the current mouse position, returning the mouse
3300 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3302 pt
= wxGetMousePosition();
3303 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3308 // Get the current mouse position.
3309 wxPoint
wxGetMousePosition()
3313 wxGetMousePosition( &x
, &y
);
3315 return wxPoint(x
, y
);
3318 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3320 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3322 // copied from wxGTK : CS
3323 // VZ: shouldn't we move this to base class then?
3325 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3328 // (a) it's a command event and so is propagated to the parent
3329 // (b) under MSW it can be generated from kbd too
3330 // (c) it uses screen coords (because of (a))
3331 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3333 this->ClientToScreen(event
.GetPosition()));
3334 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3343 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3345 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3346 CallNextEventHandler(
3347 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3348 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3351 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3355 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3359 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3360 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3365 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3367 return eventNotHandledErr
;
3370 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3372 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3373 if ( !wxWindowBase::Reparent(newParent
) )
3376 // copied from MacPostControlCreate
3377 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3379 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3381 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3386 bool wxWindowMac::SetTransparent(wxByte alpha
)
3388 #if wxMAC_USE_CORE_GRAPHICS
3389 if ( alpha
!= m_macAlpha
)
3391 m_macAlpha
= alpha
;
3401 bool wxWindowMac::CanSetTransparent()
3403 #if wxMAC_USE_CORE_GRAPHICS
3410 wxByte
wxWindowMac::GetTransparent() const