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"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/osx/uma.h"
66 #define MAC_SCROLLBAR_SIZE 15
67 #define MAC_SMALL_SCROLLBAR_SIZE 11
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
78 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
79 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
80 EVT_PAINT(wxWindowMac::OnPaint
)
81 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
84 #define wxMAC_DEBUG_REDRAW 0
85 #ifndef wxMAC_DEBUG_REDRAW
86 #define wxMAC_DEBUG_REDRAW 0
89 // ---------------------------------------------------------------------------
90 // Utility Routines to move between different coordinate systems
91 // ---------------------------------------------------------------------------
94 * Right now we have the following setup :
95 * a border that is not part of the native control is always outside the
96 * control's border (otherwise we loose all native intelligence, future ways
97 * may be to have a second embedding control responsible for drawing borders
98 * and backgrounds eventually)
99 * so all this border calculations have to be taken into account when calling
100 * native methods or getting native oriented data
101 * so we have three coordinate systems here
102 * wx client coordinates
103 * wx window coordinates (including window frames)
108 // originating from native control
112 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
114 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
117 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
119 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
123 // directed towards native control
126 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
128 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
131 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
133 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
136 // ---------------------------------------------------------------------------
138 // ---------------------------------------------------------------------------
140 static const EventTypeSpec eventList
[] =
142 { kEventClassCommand
, kEventProcessCommand
} ,
143 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
145 { kEventClassControl
, kEventControlGetClickActivation
} ,
146 { kEventClassControl
, kEventControlHit
} ,
148 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
149 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
151 { kEventClassControl
, kEventControlDraw
} ,
153 { kEventClassControl
, kEventControlVisibilityChanged
} ,
154 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
155 { kEventClassControl
, kEventControlHiliteChanged
} ,
157 { kEventClassControl
, kEventControlActivate
} ,
158 { kEventClassControl
, kEventControlDeactivate
} ,
160 { kEventClassControl
, kEventControlSetFocusPart
} ,
161 { kEventClassControl
, kEventControlFocusPartChanged
} ,
163 { kEventClassService
, kEventServiceGetTypes
},
164 { kEventClassService
, kEventServiceCopy
},
165 { kEventClassService
, kEventServicePaste
},
167 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
168 // { kEventClassControl , kEventControlBoundsChanged } ,
171 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
173 OSStatus result
= eventNotHandledErr
;
174 static wxWindowMac
* targetFocusWindow
= NULL
;
175 static wxWindowMac
* formerFocusWindow
= NULL
;
177 wxMacCarbonEvent
cEvent( event
) ;
179 ControlRef controlRef
;
180 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
182 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
184 switch ( GetEventKind( event
) )
186 case kEventControlDraw
:
188 RgnHandle updateRgn
= NULL
;
189 RgnHandle allocatedRgn
= NULL
;
190 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
192 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
194 HIShapeGetAsQDRgn( visRegion
.GetWXHRGN(), updateRgn
);
198 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
200 // as this update region is in native window locals we must adapt it to wx window local
201 allocatedRgn
= NewRgn() ;
202 CopyRgn( updateRgn
, allocatedRgn
) ;
204 // hide the given region by the new region that must be shifted
205 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
206 updateRgn
= allocatedRgn
;
210 #if wxMAC_DEBUG_REDRAW
211 if ( thisWindow
->MacIsUserPane() )
213 static float color
= 0.5 ;
214 static int channel
= 0 ;
216 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
218 HIViewGetBounds( controlRef
, &bounds
);
219 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
220 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
221 CGContextFillRect( cgContext
, bounds
);
234 bool created
= false ;
235 CGContextRef cgContext
= NULL
;
236 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
239 wxFAIL_MSG("Unable to retrieve CGContextRef");
242 thisWindow
->MacSetCGContextRef( cgContext
) ;
245 wxMacCGContextStateSaver
sg( cgContext
) ;
246 CGFloat alpha
= (CGFloat
)1.0 ;
248 wxWindow
* iter
= thisWindow
;
251 alpha
*= (CGFloat
)( iter
->GetTransparent()/255.0 ) ;
252 if ( iter
->IsTopLevel() )
255 iter
= iter
->GetParent() ;
258 CGContextSetAlpha( cgContext
, alpha
) ;
260 if ( thisWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
263 HIViewGetBounds( controlRef
, &bounds
);
264 CGContextClearRect( cgContext
, bounds
);
269 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
272 thisWindow
->MacSetCGContextRef( NULL
) ;
276 CGContextRelease( cgContext
) ;
280 DisposeRgn( allocatedRgn
) ;
284 case kEventControlVisibilityChanged
:
285 // we might have two native controls attributed to the same wxWindow instance
286 // eg a scrollview and an embedded textview, make sure we only fire for the 'outer'
287 // control, as otherwise native and wx visibility are different
288 if ( thisWindow
->GetPeer() != NULL
&& thisWindow
->GetPeer()->GetControlRef() == controlRef
)
290 thisWindow
->MacVisibilityChanged() ;
294 case kEventControlEnabledStateChanged
:
295 thisWindow
->MacEnabledStateChanged();
298 case kEventControlHiliteChanged
:
299 thisWindow
->MacHiliteChanged() ;
302 case kEventControlActivate
:
303 case kEventControlDeactivate
:
304 // FIXME: we should have a virtual function for this!
306 if ( thisWindow
->IsKindOf( CLASSINFO( wxTreeCtrl
) ) )
307 thisWindow
->Refresh();
310 if ( thisWindow
->IsKindOf( CLASSINFO( wxListCtrl
) ) )
311 thisWindow
->Refresh();
317 // different handling on OS X
320 case kEventControlFocusPartChanged
:
321 // the event is emulated by wxmac for systems lower than 10.5
323 if ( UMAGetSystemVersion() < 0x1050 )
325 // as it is synthesized here, we have to manually avoid propagation
328 ControlPartCode previousControlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPreviousPart
, typeControlPartCode
);
329 ControlPartCode currentControlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlCurrentPart
, typeControlPartCode
);
331 if ( thisWindow
->MacGetTopLevelWindow() && thisWindow
->GetPeer()->NeedsFocusRect() )
333 thisWindow
->MacInvalidateBorders();
336 if ( currentControlPart
== 0 )
340 if ( thisWindow
->GetCaret() )
341 thisWindow
->GetCaret()->OnKillFocus();
344 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow
));
346 // remove this as soon as posting the synthesized event works properly
347 static bool inKillFocusEvent
= false ;
349 if ( !inKillFocusEvent
)
351 inKillFocusEvent
= true ;
352 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
353 event
.SetEventObject(thisWindow
);
354 event
.SetWindow(targetFocusWindow
);
355 thisWindow
->HandleWindowEvent(event
) ;
356 inKillFocusEvent
= false ;
357 targetFocusWindow
= NULL
;
360 else if ( previousControlPart
== 0 )
363 // panel wants to track the window which was the last to have focus in it
364 wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow
));
365 wxChildFocusEvent
eventFocus((wxWindow
*)thisWindow
);
366 thisWindow
->HandleWindowEvent(eventFocus
);
369 if ( thisWindow
->GetCaret() )
370 thisWindow
->GetCaret()->OnSetFocus();
373 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
374 event
.SetEventObject(thisWindow
);
375 event
.SetWindow(formerFocusWindow
);
376 thisWindow
->HandleWindowEvent(event
) ;
377 formerFocusWindow
= NULL
;
381 case kEventControlSetFocusPart
:
383 Boolean focusEverything
= false ;
384 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
386 // put a breakpoint here to catch focus everything events
388 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
389 if ( controlPart
!= kControlFocusNoPart
)
391 targetFocusWindow
= thisWindow
;
392 wxLogTrace(_T("Focus"), _T("focus to be set(%p)"), wx_static_cast(void*, thisWindow
));
396 formerFocusWindow
= thisWindow
;
397 wxLogTrace(_T("Focus"), _T("focus to be lost(%p)"), wx_static_cast(void*, thisWindow
));
400 ControlPartCode previousControlPart
= 0;
401 verify_noerr( HIViewGetFocusPart(controlRef
, &previousControlPart
));
403 if ( thisWindow
->MacIsUserPane() )
405 if ( controlPart
!= kControlFocusNoPart
)
406 cEvent
.SetParameter
<ControlPartCode
>( kEventParamControlPart
, typeControlPartCode
, 1 ) ;
410 result
= CallNextEventHandler(handler
, event
);
412 if ( UMAGetSystemVersion() < 0x1050 )
414 // set back to 0 if problems arise
416 if ( result
== noErr
)
418 ControlPartCode currentControlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
419 // synthesize the event focus changed event
420 EventRef evRef
= NULL
;
422 OSStatus err
= MacCreateEvent(
423 NULL
, kEventClassControl
, kEventControlFocusPartChanged
, TicksToEventTime( TickCount() ) ,
424 kEventAttributeUserEvent
, &evRef
);
427 wxMacCarbonEvent
iEvent( evRef
) ;
428 iEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, controlRef
);
429 iEvent
.SetParameter
<EventTargetRef
>( kEventParamPostTarget
, typeEventTargetRef
, GetControlEventTarget( controlRef
) );
430 iEvent
.SetParameter
<ControlPartCode
>( kEventParamControlPreviousPart
, typeControlPartCode
, previousControlPart
);
431 iEvent
.SetParameter
<ControlPartCode
>( kEventParamControlCurrentPart
, typeControlPartCode
, currentControlPart
);
434 // TODO test this first, avoid double posts etc...
435 PostEventToQueue( GetMainEventQueue(), evRef
, kEventPriorityHigh
);
437 wxMacWindowControlEventHandler( NULL
, evRef
, data
) ;
439 ReleaseEvent( evRef
) ;
442 // old implementation, to be removed if the new one works
443 if ( controlPart
== kControlFocusNoPart
)
446 if ( thisWindow
->GetCaret() )
447 thisWindow
->GetCaret()->OnKillFocus();
450 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow
));
452 static bool inKillFocusEvent
= false ;
454 if ( !inKillFocusEvent
)
456 inKillFocusEvent
= true ;
457 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
458 event
.SetEventObject(thisWindow
);
459 thisWindow
->HandleWindowEvent(event
) ;
460 inKillFocusEvent
= false ;
465 // panel wants to track the window which was the last to have focus in it
466 wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow
));
467 wxChildFocusEvent
eventFocus((wxWindow
*)thisWindow
);
468 thisWindow
->HandleWindowEvent(eventFocus
);
471 if ( thisWindow
->GetCaret() )
472 thisWindow
->GetCaret()->OnSetFocus();
475 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
476 event
.SetEventObject(thisWindow
);
477 thisWindow
->HandleWindowEvent(event
) ;
484 case kEventControlHit
:
485 result
= thisWindow
->MacControlHit( handler
, event
) ;
488 case kEventControlGetClickActivation
:
490 // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
491 WindowRef owner
= cEvent
.GetParameter
<WindowRef
>(kEventParamWindowRef
);
492 if ( !IsWindowActive(owner
) )
494 cEvent
.SetParameter(kEventParamClickActivation
,(UInt32
) kActivateAndIgnoreClick
) ;
507 static pascal OSStatus
508 wxMacWindowServiceEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
512 OSStatus result
= eventNotHandledErr
;
514 wxMacCarbonEvent
cEvent( event
) ;
516 ControlRef controlRef
;
517 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
518 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
519 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
521 switch ( GetEventKind( event
) )
523 case kEventServiceGetTypes
:
527 textCtrl
->GetSelection( &from
, &to
) ;
529 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
531 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
532 if ( textCtrl
->IsEditable() )
533 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
535 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
536 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
538 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
542 CFArrayAppendValue(copyTypes
, typestring
) ;
544 CFArrayAppendValue(pasteTypes
, typestring
) ;
546 CFRelease( typestring
) ;
554 case kEventServiceCopy
:
559 textCtrl
->GetSelection( &from
, &to
) ;
560 wxString val
= textCtrl
->GetValue() ;
561 val
= val
.Mid( from
, to
- from
) ;
562 PasteboardRef pasteboard
= cEvent
.GetParameter
<PasteboardRef
>( kEventParamPasteboardRef
, typePasteboardRef
);
563 verify_noerr( PasteboardClear( pasteboard
) ) ;
564 PasteboardSynchronize( pasteboard
);
565 // TODO add proper conversion
566 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (const UInt8
*)val
.c_str(), val
.length() );
567 PasteboardPutItemFlavor( pasteboard
, (PasteboardItemID
) 1, CFSTR("com.apple.traditional-mac-plain-text"), data
, 0);
573 case kEventServicePaste
:
576 PasteboardRef pasteboard
= cEvent
.GetParameter
<PasteboardRef
>( kEventParamPasteboardRef
, typePasteboardRef
);
577 PasteboardSynchronize( pasteboard
);
579 verify_noerr( PasteboardGetItemCount( pasteboard
, &itemCount
) );
580 for( UInt32 itemIndex
= 1; itemIndex
<= itemCount
; itemIndex
++ )
582 PasteboardItemID itemID
;
583 if ( PasteboardGetItemIdentifier( pasteboard
, itemIndex
, &itemID
) == noErr
)
585 CFDataRef flavorData
= NULL
;
586 if ( PasteboardCopyItemFlavorData( pasteboard
, itemID
, CFSTR("com.apple.traditional-mac-plain-text"), &flavorData
) == noErr
)
588 CFIndex flavorDataSize
= CFDataGetLength( flavorData
);
589 char *content
= new char[flavorDataSize
+1] ;
590 memcpy( content
, CFDataGetBytePtr( flavorData
), flavorDataSize
);
591 content
[flavorDataSize
]=0;
592 CFRelease( flavorData
);
594 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
596 textCtrl
->WriteText( wxString( content
) ) ;
614 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
616 OSStatus result
= eventNotHandledErr
;
617 wxWindowMac
* focus
= (wxWindowMac
*) data
;
619 wchar_t* uniChars
= NULL
;
620 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
622 UniChar
* charBuf
= NULL
;
623 ByteCount dataSize
= 0 ;
626 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
628 numChars
= dataSize
/ sizeof( UniChar
) + 1;
631 if ( (size_t) numChars
* 2 > sizeof(buf
) )
632 charBuf
= new UniChar
[ numChars
] ;
636 uniChars
= new wchar_t[ numChars
] ;
637 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
638 charBuf
[ numChars
- 1 ] = 0;
639 #if SIZEOF_WCHAR_T == 2
640 uniChars
= (wchar_t*) charBuf
;
641 /* memcpy( uniChars , charBuf , numChars * 2 ) ;*/ // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...)
643 // the resulting string will never have more chars than the utf16 version, so this is safe
644 wxMBConvUTF16 converter
;
645 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
649 switch ( GetEventKind( event
) )
651 case kEventTextInputUpdateActiveInputArea
:
653 // An IME input event may return several characters, but we need to send one char at a time to
655 for (int pos
=0 ; pos
< numChars
; pos
++)
657 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
658 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
659 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
661 UInt32 message
= uniChars
[pos
] < 128 ? (char)uniChars
[pos
] : '?';
663 NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent
664 multiple times to update the active range during inline input, so this handler will often receive
665 uncommited text, which should usually not trigger side effects. It might be a good idea to check the
666 kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h).
667 On the other hand, it can be useful for some applications to react to uncommitted text (for example,
668 to update a status display), as long as it does not disrupt the inline input session. Ideally, wx
669 should add new event types to support advanced text input. For now, I would keep things as they are.
671 However, the code that was being used caused additional problems:
672 UInt32 message = (0 << 8) + ((char)uniChars[pos] );
673 Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline
674 input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji
675 for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB
676 (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D
677 (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress.
678 Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only
679 overlap with Unicode within the (7-bit) ASCII range.
680 But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks
681 for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII
682 characters as they are and replaces the rest with '?', ensuring that update events are triggered.
683 It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but
684 I don't have time to look into that right now.
687 if ( wxTheApp
->MacSendCharEvent(
688 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
693 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
697 case kEventTextInputUnicodeForKeyEvent
:
699 UInt32 keyCode
, modifiers
;
702 unsigned char charCode
;
704 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
705 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
706 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
707 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
708 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
710 UInt32 message
= (keyCode
<< 8) + charCode
;
712 // An IME input event may return several characters, but we need to send one char at a time to
714 for (int pos
=0 ; pos
< numChars
; pos
++)
716 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
717 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
718 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
720 if ( wxTheApp
->MacSendCharEvent(
721 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
726 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
735 if ( charBuf
!= buf
)
741 static pascal OSStatus
742 wxMacWindowCommandEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
746 OSStatus result
= eventNotHandledErr
;
747 wxWindowMac
* focus
= (wxWindowMac
*) data
;
751 wxMacCarbonEvent
cEvent( event
) ;
752 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
754 wxMenuItem
* item
= NULL
;
755 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
756 int id
= wxMacCommandToId( command
.commandID
) ;
760 wxASSERT( itemMenu
!= NULL
) ;
762 switch ( cEvent
.GetKind() )
764 case kEventProcessCommand
:
765 result
= itemMenu
->MacHandleCommandProcess( item
, id
, focus
);
768 case kEventCommandUpdateStatus
:
769 result
= itemMenu
->MacHandleCommandUpdateStatus( item
, id
, focus
);
779 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
781 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
782 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
783 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
784 OSStatus result
= eventNotHandledErr
;
786 switch ( GetEventClass( event
) )
788 case kEventClassCommand
:
789 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
792 case kEventClassControl
:
793 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
796 case kEventClassService
:
797 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
800 case kEventClassTextInput
:
801 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
808 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
813 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
815 // ---------------------------------------------------------------------------
816 // Scrollbar Tracking for all
817 // ---------------------------------------------------------------------------
819 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
820 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
824 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
826 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
829 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
831 // ===========================================================================
833 // ===========================================================================
835 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
837 static MacControlMap wxWinMacControlList
;
839 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
841 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
843 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
846 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
848 // adding NULL ControlRef is (first) surely a result of an error and
849 // (secondly) breaks native event processing
850 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
852 wxWinMacControlList
[inControl
] = control
;
855 void wxRemoveMacControlAssociation(wxWindow
*control
)
857 // iterate over all the elements in the class
858 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
859 // we should go on...
865 MacControlMap::iterator it
;
866 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
868 if ( it
->second
== control
)
870 wxWinMacControlList
.erase(it
);
878 // ----------------------------------------------------------------------------
879 // constructors and such
880 // ----------------------------------------------------------------------------
882 wxWindowMac::wxWindowMac()
887 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
892 const wxString
& name
)
895 Create(parent
, id
, pos
, size
, style
, name
);
898 void wxWindowMac::Init()
902 m_cgContextRef
= NULL
;
904 // as all windows are created with WS_VISIBLE style...
907 m_hScrollBar
= NULL
;
908 m_vScrollBar
= NULL
;
909 m_hScrollBarAlwaysShown
= false;
910 m_vScrollBarAlwaysShown
= false;
912 m_macIsUserPane
= true;
913 m_clipChildren
= false ;
914 m_cachedClippedRectValid
= false ;
917 wxWindowMac::~wxWindowMac()
921 m_isBeingDeleted
= true;
923 MacInvalidateBorders() ;
925 #ifndef __WXUNIVERSAL__
926 // VS: make sure there's no wxFrame with last focus set to us:
927 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
929 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
932 if ( frame
->GetLastFocus() == this )
933 frame
->SetLastFocus((wxWindow
*)NULL
);
939 // destroy children before destroying this window itself
942 // wxRemoveMacControlAssociation( this ) ;
943 // If we delete an item, we should initialize the parent panel,
944 // because it could now be invalid.
945 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
948 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
949 tlw
->SetDefaultItem(NULL
);
952 if ( m_peer
&& m_peer
->Ok() )
954 // in case the callback might be called during destruction
955 wxRemoveMacControlAssociation( this) ;
956 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
957 // we currently are not using this hook
958 // ::SetControlColorProc( *m_peer , NULL ) ;
962 if ( g_MacLastWindow
== this )
963 g_MacLastWindow
= NULL
;
965 #ifndef __WXUNIVERSAL__
966 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
969 if ( frame
->GetLastFocus() == this )
970 frame
->SetLastFocus( NULL
) ;
974 // delete our drop target if we've got one
975 #if wxUSE_DRAG_AND_DROP
976 if ( m_dropTarget
!= NULL
)
986 WXWidget
wxWindowMac::GetHandle() const
988 return (WXWidget
) m_peer
->GetControlRef() ;
991 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
993 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
994 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
995 GetEventTypeCount(eventList
), eventList
, this,
996 (EventHandlerRef
*)&m_macControlEventHandler
);
1000 bool wxWindowMac::Create(wxWindowMac
*parent
,
1005 const wxString
& name
)
1007 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1009 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1012 m_windowVariant
= parent
->GetWindowVariant() ;
1014 if ( m_macIsUserPane
)
1016 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1019 | kControlSupportsEmbedding
1020 | kControlSupportsLiveFeedback
1021 | kControlGetsFocusOnClick
1022 // | kControlHasSpecialBackground
1023 // | kControlSupportsCalcBestRect
1024 | kControlHandlesTracking
1025 | kControlSupportsFocus
1026 | kControlWantsActivate
1027 | kControlWantsIdle
;
1029 m_peer
= new wxMacControl(this) ;
1030 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1031 verify_noerr( err
);
1033 MacPostControlCreate(pos
, size
) ;
1036 #ifndef __WXUNIVERSAL__
1037 // Don't give scrollbars to wxControls unless they ask for them
1038 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1039 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1041 MacCreateScrollBars( style
) ;
1045 wxWindowCreateEvent
event(this);
1046 GetEventHandler()->AddPendingEvent(event
);
1051 void wxWindowMac::MacChildAdded()
1054 m_vScrollBar
->Raise() ;
1056 m_hScrollBar
->Raise() ;
1059 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
1061 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1063 m_peer
->SetReference( (URefCon
) this ) ;
1064 GetParent()->AddChild( this );
1066 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1068 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1069 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1070 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1071 GetParent()->MacChildAdded() ;
1073 // adjust font, controlsize etc
1074 DoSetWindowVariant( m_windowVariant
) ;
1076 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1078 if (!m_macIsUserPane
)
1079 SetInitialSize(size
);
1081 SetCursor( *wxSTANDARD_CURSOR
) ;
1084 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1086 // Don't assert, in case we set the window variant before
1087 // the window is created
1088 // wxASSERT( m_peer->Ok() ) ;
1090 m_windowVariant
= variant
;
1092 if (m_peer
== NULL
|| !m_peer
->Ok())
1096 ThemeFontID themeFont
= kThemeSystemFont
;
1098 // we will get that from the settings later
1099 // and make this NORMAL later, but first
1100 // we have a few calculations that we must fix
1104 case wxWINDOW_VARIANT_NORMAL
:
1105 size
= kControlSizeNormal
;
1106 themeFont
= kThemeSystemFont
;
1109 case wxWINDOW_VARIANT_SMALL
:
1110 size
= kControlSizeSmall
;
1111 themeFont
= kThemeSmallSystemFont
;
1114 case wxWINDOW_VARIANT_MINI
:
1115 // not always defined in the headers
1120 case wxWINDOW_VARIANT_LARGE
:
1121 size
= kControlSizeLarge
;
1122 themeFont
= kThemeSystemFont
;
1126 wxFAIL_MSG(_T("unexpected window variant"));
1130 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1133 font
.MacCreateFromThemeFont( themeFont
) ;
1137 void wxWindowMac::MacUpdateControlFont()
1139 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1140 // do not trigger refreshes upon invisible and possible partly created objects
1141 if ( IsShownOnScreen() )
1145 bool wxWindowMac::SetFont(const wxFont
& font
)
1147 bool retval
= wxWindowBase::SetFont( font
);
1149 MacUpdateControlFont() ;
1154 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1156 bool retval
= wxWindowBase::SetForegroundColour( col
);
1159 MacUpdateControlFont();
1164 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1166 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1169 m_peer
->SetBackgroundColour( col
) ;
1174 bool wxWindowMac::MacCanFocus() const
1176 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1177 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1178 // but the value range is nowhere documented
1179 Boolean keyExistsAndHasValidFormat
;
1180 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1181 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1183 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1189 UInt32 features
= 0 ;
1190 m_peer
->GetFeatures( &features
) ;
1192 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1196 void wxWindowMac::SetFocus()
1198 if ( !AcceptsFocus() )
1201 wxWindow
* former
= FindFocus() ;
1202 if ( former
== this )
1205 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1206 // we can only leave in case of an error
1207 wxLogTrace(_T("Focus"), _T("before wxWindow::SetFocus(%p) %d"), wx_static_cast(void*, this), GetName().c_str());
1208 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1209 if ( err
== errCouldntSetFocus
)
1211 wxLogTrace(_T("Focus"), _T("in wxWindow::SetFocus(%p) errCouldntSetFocus"), wx_static_cast(void*, this));
1214 wxLogTrace(_T("Focus"), _T("after wxWindow::SetFocus(%p)"), wx_static_cast(void*, this));
1216 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1219 void wxWindowMac::DoCaptureMouse()
1221 wxApp::s_captureWindow
= this ;
1224 wxWindow
* wxWindowBase::GetCapture()
1226 return wxApp::s_captureWindow
;
1229 void wxWindowMac::DoReleaseMouse()
1231 wxApp::s_captureWindow
= NULL
;
1234 #if wxUSE_DRAG_AND_DROP
1236 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1238 if ( m_dropTarget
!= NULL
)
1239 delete m_dropTarget
;
1241 m_dropTarget
= pDropTarget
;
1242 if ( m_dropTarget
!= NULL
)
1250 // Old-style File Manager Drag & Drop
1251 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
1256 // Returns the size of the native control. In the case of the toplevel window
1257 // this is the content area root control
1259 void wxWindowMac::MacGetPositionAndSizeFromControl(int& WXUNUSED(x
),
1262 int& WXUNUSED(h
)) const
1264 wxFAIL_MSG( wxT("Not currently supported") ) ;
1267 // From a wx position / size calculate the appropriate size of the native control
1269 bool wxWindowMac::MacGetBoundsForControl(
1273 int& w
, int& h
, bool adjustOrigin
) const
1275 // the desired size, minus the border pixels gives the correct size of the control
1279 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1280 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1281 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1283 x
+= MacGetLeftBorderSize() ;
1284 y
+= MacGetTopBorderSize() ;
1285 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1286 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1289 AdjustForParentClientOrigin( x
, y
) ;
1291 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1292 if ( !GetParent()->IsTopLevel() )
1294 x
-= GetParent()->MacGetLeftBorderSize() ;
1295 y
-= GetParent()->MacGetTopBorderSize() ;
1301 // Get window size (not client size)
1302 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1305 m_peer
->GetRect( &bounds
) ;
1308 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1310 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1313 // get the position of the bounds of this window in client coordinates of its parent
1314 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1317 m_peer
->GetRect( &bounds
) ;
1319 int x1
= bounds
.left
;
1320 int y1
= bounds
.top
;
1322 // get the wx window position from the native one
1323 x1
-= MacGetLeftBorderSize() ;
1324 y1
-= MacGetTopBorderSize() ;
1326 if ( !IsTopLevel() )
1328 wxWindow
*parent
= GetParent();
1331 // we must first adjust it to be in window coordinates of the parent,
1332 // as otherwise it gets lost by the ClientAreaOrigin fix
1333 x1
+= parent
->MacGetLeftBorderSize() ;
1334 y1
+= parent
->MacGetTopBorderSize() ;
1336 // and now to client coordinates
1337 wxPoint
pt(parent
->GetClientAreaOrigin());
1349 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1351 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1352 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1354 Point localwhere
= { 0, 0 } ;
1361 wxMacGlobalToLocal( window
, &localwhere
) ;
1368 MacRootWindowToWindow( x
, y
) ;
1370 wxPoint origin
= GetClientAreaOrigin() ;
1377 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1379 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1380 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1382 wxPoint origin
= GetClientAreaOrigin() ;
1388 MacWindowToRootWindow( x
, y
) ;
1390 Point localwhere
= { 0, 0 };
1396 wxMacLocalToGlobal( window
, &localwhere
) ;
1404 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1406 wxPoint origin
= GetClientAreaOrigin() ;
1412 MacWindowToRootWindow( x
, y
) ;
1415 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1417 MacRootWindowToWindow( x
, y
) ;
1419 wxPoint origin
= GetClientAreaOrigin() ;
1426 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1435 if ( !IsTopLevel() )
1437 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1440 pt
.x
-= MacGetLeftBorderSize() ;
1441 pt
.y
-= MacGetTopBorderSize() ;
1442 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1452 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1461 MacWindowToRootWindow( &x1
, &y1
) ;
1469 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1478 if ( !IsTopLevel() )
1480 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1483 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1484 pt
.x
+= MacGetLeftBorderSize() ;
1485 pt
.y
+= MacGetTopBorderSize() ;
1495 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1504 MacRootWindowToWindow( &x1
, &y1
) ;
1512 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1514 RgnHandle rgn
= NewRgn() ;
1516 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1518 Rect structure
, content
;
1520 GetRegionBounds( rgn
, &content
) ;
1521 m_peer
->GetRect( &structure
) ;
1522 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1524 left
= content
.left
- structure
.left
;
1525 top
= content
.top
- structure
.top
;
1526 right
= structure
.right
- content
.right
;
1527 bottom
= structure
.bottom
- content
.bottom
;
1531 left
= top
= right
= bottom
= 0 ;
1537 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1539 wxSize sizeTotal
= size
;
1541 RgnHandle rgn
= NewRgn() ;
1542 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1544 Rect content
, structure
;
1545 GetRegionBounds( rgn
, &content
) ;
1546 m_peer
->GetRect( &structure
) ;
1548 // structure is in parent coordinates, but we only need width and height, so it's ok
1550 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1551 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1556 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1557 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1562 // Get size *available for subwindows* i.e. excluding menu bar etc.
1563 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1567 RgnHandle rgn
= NewRgn() ;
1569 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1570 GetRegionBounds( rgn
, &content
) ;
1572 m_peer
->GetRect( &content
) ;
1575 ww
= content
.right
- content
.left
;
1576 hh
= content
.bottom
- content
.top
;
1578 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1579 hh
-= m_hScrollBar
->GetSize().y
;
1581 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1582 ww
-= m_vScrollBar
->GetSize().x
;
1590 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1592 if (m_cursor
.IsSameAs(cursor
))
1597 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1602 if ( ! wxWindowBase::SetCursor( cursor
) )
1606 wxASSERT_MSG( m_cursor
.Ok(),
1607 wxT("cursor must be valid after call to the base version"));
1609 wxWindowMac
*mouseWin
= 0 ;
1611 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
1612 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1614 ControlPartCode part
;
1615 ControlRef control
;
1617 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1619 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1623 GetGlobalMouse( &pt
);
1626 ScreenToClient(&x
, &y
);
1630 control
= FindControlUnderMouse( pt
, window
, &part
) ;
1632 mouseWin
= wxFindControlFromMacControl( control
) ;
1636 if ( mouseWin
== this && !wxIsBusy() )
1637 m_cursor
.MacInstall() ;
1643 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1645 #ifndef __WXUNIVERSAL__
1646 menu
->SetInvokingWindow((wxWindow
*)this);
1649 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1651 wxPoint mouse
= wxGetMousePosition();
1657 ClientToScreen( &x
, &y
) ;
1660 menu
->MacBeforeDisplay( true ) ;
1661 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1662 if ( HiWord(menuResult
) != 0 )
1665 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1666 int id
= wxMacCommandToId( macid
);
1667 wxMenuItem
* item
= NULL
;
1669 item
= menu
->FindItem( id
, &realmenu
) ;
1672 if (item
->IsCheckable())
1673 item
->Check( !item
->IsChecked() ) ;
1675 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1679 menu
->MacAfterDisplay( true ) ;
1680 menu
->SetInvokingWindow( NULL
);
1684 // actually this shouldn't be called, because universal is having its own implementation
1690 // ----------------------------------------------------------------------------
1692 // ----------------------------------------------------------------------------
1696 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1698 wxWindowBase::DoSetToolTip(tooltip
);
1701 m_tooltip
->SetWindow(this);
1706 void wxWindowMac::MacInvalidateBorders()
1708 if ( m_peer
== NULL
)
1711 bool vis
= IsShownOnScreen() ;
1715 int outerBorder
= MacGetLeftBorderSize() ;
1716 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
1719 if ( outerBorder
== 0 )
1722 // now we know that we have something to do at all
1724 // as the borders are drawn on the parent we have to properly invalidate all these areas
1725 RgnHandle updateInner
, updateOuter
;
1728 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1729 updateInner
= NewRgn() ;
1730 updateOuter
= NewRgn() ;
1732 m_peer
->GetRect( &rect
) ;
1733 RectRgn( updateInner
, &rect
) ;
1734 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1735 RectRgn( updateOuter
, &rect
) ;
1736 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1738 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1740 DisposeRgn( updateOuter
) ;
1741 DisposeRgn( updateInner
) ;
1744 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1746 // this is never called for a toplevel window, so we know we have a parent
1747 int former_x
, former_y
, former_w
, former_h
;
1749 // Get true coordinates of former position
1750 DoGetPosition( &former_x
, &former_y
) ;
1751 DoGetSize( &former_w
, &former_h
) ;
1753 wxWindow
*parent
= GetParent();
1756 wxPoint
pt(parent
->GetClientAreaOrigin());
1761 int actualWidth
= width
;
1762 int actualHeight
= height
;
1766 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1767 actualWidth
= m_minWidth
;
1768 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1769 actualHeight
= m_minHeight
;
1770 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1771 actualWidth
= m_maxWidth
;
1772 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1773 actualHeight
= m_maxHeight
;
1775 bool doMove
= false, doResize
= false ;
1777 if ( actualX
!= former_x
|| actualY
!= former_y
)
1780 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1783 if ( doMove
|| doResize
)
1785 // as the borders are drawn outside the native control, we adjust now
1787 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1788 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1789 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1792 wxMacRectToNative( &bounds
, &r
) ;
1794 if ( !GetParent()->IsTopLevel() )
1795 wxMacWindowToNative( GetParent() , &r
) ;
1797 MacInvalidateBorders() ;
1799 m_cachedClippedRectValid
= false ;
1800 m_peer
->SetRect( &r
) ;
1802 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1804 MacInvalidateBorders() ;
1806 MacRepositionScrollBars() ;
1809 wxPoint
point(actualX
, actualY
);
1810 wxMoveEvent
event(point
, m_windowId
);
1811 event
.SetEventObject(this);
1812 HandleWindowEvent(event
) ;
1817 MacRepositionScrollBars() ;
1818 wxSize
size(actualWidth
, actualHeight
);
1819 wxSizeEvent
event(size
, m_windowId
);
1820 event
.SetEventObject(this);
1821 HandleWindowEvent(event
);
1826 wxSize
wxWindowMac::DoGetBestSize() const
1828 if ( m_macIsUserPane
|| IsTopLevel() )
1830 return wxWindowBase::DoGetBestSize() ;
1834 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1835 int bestWidth
, bestHeight
;
1837 m_peer
->GetBestRect( &bestsize
) ;
1838 if ( EmptyRect( &bestsize
) )
1843 bestsize
.bottom
= 16 ;
1845 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1847 bestsize
.bottom
= 16 ;
1850 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1852 bestsize
.bottom
= 24 ;
1857 // return wxWindowBase::DoGetBestSize() ;
1861 bestWidth
= bestsize
.right
- bestsize
.left
+ MacGetLeftBorderSize() +
1862 MacGetRightBorderSize();
1863 bestHeight
= bestsize
.bottom
- bestsize
.top
+ MacGetTopBorderSize() +
1864 MacGetBottomBorderSize();
1865 if ( bestHeight
< 10 )
1868 return wxSize(bestWidth
, bestHeight
);
1872 // set the size of the window: if the dimensions are positive, just use them,
1873 // but if any of them is equal to -1, it means that we must find the value for
1874 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1875 // which case -1 is a valid value for x and y)
1877 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1878 // the width/height to best suit our contents, otherwise we reuse the current
1880 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1882 // get the current size and position...
1883 int currentX
, currentY
;
1884 int currentW
, currentH
;
1886 GetPosition(¤tX
, ¤tY
);
1887 GetSize(¤tW
, ¤tH
);
1889 // ... and don't do anything (avoiding flicker) if it's already ok
1890 if ( x
== currentX
&& y
== currentY
&&
1891 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1894 MacRepositionScrollBars() ; // we might have a real position shift
1899 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1901 if ( x
== wxDefaultCoord
)
1903 if ( y
== wxDefaultCoord
)
1907 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1909 wxSize size
= wxDefaultSize
;
1910 if ( width
== wxDefaultCoord
)
1912 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1914 size
= DoGetBestSize();
1919 // just take the current one
1924 if ( height
== wxDefaultCoord
)
1926 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1928 if ( size
.x
== wxDefaultCoord
)
1929 size
= DoGetBestSize();
1930 // else: already called DoGetBestSize() above
1936 // just take the current one
1941 DoMoveWindow( x
, y
, width
, height
);
1944 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1946 RgnHandle rgn
= NewRgn() ;
1948 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1950 GetRegionBounds( rgn
, &content
) ;
1960 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
1963 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1965 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1967 int currentclientwidth
, currentclientheight
;
1968 int currentwidth
, currentheight
;
1970 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1971 GetSize( ¤twidth
, ¤theight
) ;
1973 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1974 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1978 void wxWindowMac::SetLabel(const wxString
& title
)
1982 if ( m_peer
&& m_peer
->Ok() )
1983 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1985 // do not trigger refreshes upon invisible and possible partly created objects
1986 if ( IsShownOnScreen() )
1990 wxString
wxWindowMac::GetLabel() const
1995 bool wxWindowMac::Show(bool show
)
1997 if ( !wxWindowBase::Show(show
) )
2001 m_peer
->SetVisibility( show
, true ) ;
2006 void wxWindowMac::DoEnable(bool enable
)
2008 m_peer
->Enable( enable
) ;
2012 // status change notifications
2015 void wxWindowMac::MacVisibilityChanged()
2019 void wxWindowMac::MacHiliteChanged()
2023 void wxWindowMac::MacEnabledStateChanged()
2025 OnEnabled( m_peer
->IsEnabled() );
2029 // status queries on the inherited window's state
2032 bool wxWindowMac::MacIsReallyEnabled()
2034 return m_peer
->IsEnabled() ;
2037 bool wxWindowMac::MacIsReallyHilited()
2039 return m_peer
->IsActive();
2042 void wxWindowMac::MacFlashInvalidAreas()
2044 #if TARGET_API_MAC_OSX
2045 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2049 int wxWindowMac::GetCharHeight() const
2051 wxClientDC
dc( (wxWindowMac
*)this ) ;
2053 return dc
.GetCharHeight() ;
2056 int wxWindowMac::GetCharWidth() const
2058 wxClientDC
dc( (wxWindowMac
*)this ) ;
2060 return dc
.GetCharWidth() ;
2063 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2064 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2066 const wxFont
*fontToUse
= theFont
;
2070 tempFont
= GetFont();
2071 fontToUse
= &tempFont
;
2074 wxClientDC
dc( (wxWindowMac
*) this ) ;
2075 wxCoord lx
,ly
,ld
,le
;
2076 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2077 if ( externalLeading
)
2078 *externalLeading
= le
;
2088 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2089 * we always intersect with the entire window, not only with the client area
2092 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
2094 if ( m_peer
== NULL
)
2097 if ( !IsShownOnScreen() )
2104 wxMacRectToNative( rect
, &r
) ;
2105 m_peer
->SetNeedsDisplay( &r
) ;
2109 m_peer
->SetNeedsDisplay() ;
2113 void wxWindowMac::DoFreeze()
2115 #if TARGET_API_MAC_OSX
2116 if ( m_peer
&& m_peer
->Ok() )
2117 m_peer
->SetDrawingEnabled( false ) ;
2121 void wxWindowMac::DoThaw()
2123 #if TARGET_API_MAC_OSX
2124 if ( m_peer
&& m_peer
->Ok() )
2126 m_peer
->SetDrawingEnabled( true ) ;
2127 m_peer
->InvalidateWithChildren() ;
2132 wxWindowMac
*wxGetActiveWindow()
2134 // actually this is a windows-only concept
2138 // Coordinates relative to the window
2139 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
2141 // We really don't move the mouse programmatically under Mac.
2144 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2146 if ( MacGetTopLevelWindow() == NULL
)
2149 #if TARGET_API_MAC_OSX
2150 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
2156 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
2158 event
.GetDC()->Clear() ;
2160 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
2162 // don't skip the event here, custom background means that the app
2163 // is drawing it itself in its OnPaint(), so don't draw it at all
2164 // now to avoid flicker
2172 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2177 int wxWindowMac::GetScrollPos(int orient
) const
2179 if ( orient
== wxHORIZONTAL
)
2182 return m_hScrollBar
->GetThumbPosition() ;
2187 return m_vScrollBar
->GetThumbPosition() ;
2193 // This now returns the whole range, not just the number
2194 // of positions that we can scroll.
2195 int wxWindowMac::GetScrollRange(int orient
) const
2197 if ( orient
== wxHORIZONTAL
)
2200 return m_hScrollBar
->GetRange() ;
2205 return m_vScrollBar
->GetRange() ;
2211 int wxWindowMac::GetScrollThumb(int orient
) const
2213 if ( orient
== wxHORIZONTAL
)
2216 return m_hScrollBar
->GetThumbSize() ;
2221 return m_vScrollBar
->GetThumbSize() ;
2227 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
2229 if ( orient
== wxHORIZONTAL
)
2232 m_hScrollBar
->SetThumbPosition( pos
) ;
2237 m_vScrollBar
->SetThumbPosition( pos
) ;
2242 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
2244 bool needVisibilityUpdate
= false;
2246 if ( m_hScrollBarAlwaysShown
!= hflag
)
2248 m_hScrollBarAlwaysShown
= hflag
;
2249 needVisibilityUpdate
= true;
2252 if ( m_vScrollBarAlwaysShown
!= vflag
)
2254 m_vScrollBarAlwaysShown
= vflag
;
2255 needVisibilityUpdate
= true;
2258 if ( needVisibilityUpdate
)
2259 DoUpdateScrollbarVisibility();
2263 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2264 // our own window origin is at leftOrigin/rightOrigin
2267 void wxWindowMac::MacPaintGrowBox()
2272 if ( MacHasScrollBarCorner() )
2276 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
2277 wxASSERT( cgContext
) ;
2279 m_peer
->GetRect( &rect
) ;
2281 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2282 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2283 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2284 CGContextSaveGState( cgContext
);
2286 if ( m_backgroundColour
.Ok() )
2288 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
2292 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
2294 CGContextFillRect( cgContext
, cgrect
);
2295 CGContextRestoreGState( cgContext
);
2299 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
2305 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2307 // back to the surrounding frame rectangle
2308 m_peer
->GetRect( &rect
) ;
2309 InsetRect( &rect
, -1 , -1 ) ;
2312 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2313 rect
.bottom
- rect
.top
) ;
2315 HIThemeFrameDrawInfo info
;
2316 memset( &info
, 0 , sizeof(info
) ) ;
2320 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2321 info
.isFocused
= hasFocus
;
2323 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2324 wxASSERT( cgContext
) ;
2326 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2328 info
.kind
= kHIThemeFrameTextFieldSquare
;
2329 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2331 else if ( HasFlag(wxSIMPLE_BORDER
) )
2333 info
.kind
= kHIThemeFrameListBox
;
2334 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2336 else if ( hasFocus
)
2338 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2340 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
2341 m_peer
->GetRect( &rect
) ;
2342 if ( MacHasScrollBarCorner() )
2344 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
2345 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2346 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2347 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2348 HIThemeGrowBoxDrawInfo info
;
2349 memset( &info
, 0, sizeof(info
) ) ;
2351 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2352 info
.kind
= kHIThemeGrowBoxKindNone
;
2353 // contrary to the docs ...SizeSmall does not work
2354 info
.size
= kHIThemeGrowBoxSizeNormal
;
2355 info
.direction
= 0 ;
2356 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2362 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2364 if ( child
== m_hScrollBar
)
2365 m_hScrollBar
= NULL
;
2366 if ( child
== m_vScrollBar
)
2367 m_vScrollBar
= NULL
;
2369 wxWindowBase::RemoveChild( child
) ;
2372 void wxWindowMac::DoUpdateScrollbarVisibility()
2374 bool triggerSizeEvent
= false;
2378 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
2380 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
2382 m_hScrollBar
->Show( showHScrollBar
);
2383 triggerSizeEvent
= true;
2389 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
2391 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
2393 m_vScrollBar
->Show( showVScrollBar
) ;
2394 triggerSizeEvent
= true;
2398 MacRepositionScrollBars() ;
2399 if ( triggerSizeEvent
)
2401 wxSizeEvent
event(GetSize(), m_windowId
);
2402 event
.SetEventObject(this);
2403 HandleWindowEvent(event
);
2407 // New function that will replace some of the above.
2408 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
2409 int range
, bool refresh
)
2411 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
2412 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
2413 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
2414 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
2416 DoUpdateScrollbarVisibility();
2419 // Does a physical scroll
2420 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2422 if ( dx
== 0 && dy
== 0 )
2425 int width
, height
;
2426 GetClientSize( &width
, &height
) ;
2429 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2430 // area is scrolled, this does not occur if width and height are 2 pixels less,
2431 // TODO: write optimal workaround
2432 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2434 scrollrect
.Intersect( *rect
) ;
2436 if ( m_peer
->GetNeedsDisplay() )
2438 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2439 // in case there is already a pending redraw on that area
2440 // either immediate redraw or full invalidate
2442 // is the better overall solution, as it does not slow down scrolling
2443 m_peer
->SetNeedsDisplay() ;
2445 // this would be the preferred version for fast drawing controls
2446 HIViewRender(m_peer
->GetControlRef()) ;
2450 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2451 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2452 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2455 // this would be the preferred version for fast drawing controls
2456 HIViewRender(m_peer
->GetControlRef()) ;
2462 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2464 child
= node
->GetData();
2467 if (child
== m_vScrollBar
)
2469 if (child
== m_hScrollBar
)
2471 if (child
->IsTopLevel())
2474 child
->GetPosition( &x
, &y
);
2475 child
->GetSize( &w
, &h
);
2478 wxRect
rc( x
, y
, w
, h
);
2479 if (rect
->Intersects( rc
))
2480 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
2484 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
2489 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2491 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2493 wxScrollWinEvent wevent
;
2494 wevent
.SetPosition(event
.GetPosition());
2495 wevent
.SetOrientation(event
.GetOrientation());
2496 wevent
.SetEventObject(this);
2498 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2499 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2500 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2501 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2502 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2503 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2504 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2505 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2506 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2507 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2508 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2509 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2510 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2511 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2512 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2513 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2515 HandleWindowEvent(wevent
);
2519 // Get the window with the focus
2520 wxWindowMac
*wxWindowBase::DoFindFocus()
2522 ControlRef control
;
2523 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2524 return wxFindControlFromMacControl( control
) ;
2527 void wxWindowMac::OnInternalIdle()
2529 // This calls the UI-update mechanism (querying windows for
2530 // menu/toolbar/control state information)
2531 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
2532 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2535 // Raise the window to the top of the Z order
2536 void wxWindowMac::Raise()
2538 m_peer
->SetZOrder( true , NULL
) ;
2541 // Lower the window to the bottom of the Z order
2542 void wxWindowMac::Lower()
2544 m_peer
->SetZOrder( false , NULL
) ;
2547 // static wxWindow *gs_lastWhich = NULL;
2549 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2551 // first trigger a set cursor event
2553 wxPoint clientorigin
= GetClientAreaOrigin() ;
2554 wxSize clientsize
= GetClientSize() ;
2556 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2558 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2560 bool processedEvtSetCursor
= HandleWindowEvent(event
);
2561 if ( processedEvtSetCursor
&& event
.HasCursor() )
2563 cursor
= event
.GetCursor() ;
2567 // the test for processedEvtSetCursor is here to prevent using m_cursor
2568 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2569 // it - this is a way to say that our cursor shouldn't be used for this
2571 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2574 if ( !wxIsBusy() && !GetParent() )
2575 cursor
= *wxSTANDARD_CURSOR
;
2579 cursor
.MacInstall() ;
2582 return cursor
.Ok() ;
2585 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
2589 return m_tooltip
->GetTip() ;
2592 return wxEmptyString
;
2595 void wxWindowMac::ClearBackground()
2601 void wxWindowMac::Update()
2603 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2605 top
->MacPerformUpdates() ;
2608 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
2610 wxNonOwnedWindow
* win
= NULL
;
2611 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2613 win
= wxFindWinFromMacWindow( window
) ;
2618 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2620 MacUpdateClippedRects() ;
2622 return m_cachedClippedClientRect
;
2625 const wxRect
& wxWindowMac::MacGetClippedRect() const
2627 MacUpdateClippedRects() ;
2629 return m_cachedClippedRect
;
2632 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2634 MacUpdateClippedRects() ;
2636 return m_cachedClippedRectWithOuterStructure
;
2639 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2641 static wxRegion emptyrgn
;
2643 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
2645 MacUpdateClippedRects() ;
2646 if ( includeOuterStructures
)
2647 return m_cachedClippedRegionWithOuterStructure
;
2649 return m_cachedClippedRegion
;
2657 void wxWindowMac::MacUpdateClippedRects() const
2659 if ( m_cachedClippedRectValid
)
2662 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2663 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2664 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2665 // to add focus borders everywhere
2667 Rect r
, rIncludingOuterStructures
;
2669 m_peer
->GetRect( &r
) ;
2670 r
.left
-= MacGetLeftBorderSize() ;
2671 r
.top
-= MacGetTopBorderSize() ;
2672 r
.bottom
+= MacGetBottomBorderSize() ;
2673 r
.right
+= MacGetRightBorderSize() ;
2680 rIncludingOuterStructures
= r
;
2681 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2683 wxRect cl
= GetClientRect() ;
2684 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2688 const wxWindow
* child
= this ;
2689 const wxWindow
* parent
= NULL
;
2691 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2693 if ( parent
->MacIsChildOfClientArea(child
) )
2695 size
= parent
->GetClientSize() ;
2696 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2702 // this will be true for scrollbars, toolbars etc.
2703 size
= parent
->GetSize() ;
2704 y
= parent
->MacGetTopBorderSize() ;
2705 x
= parent
->MacGetLeftBorderSize() ;
2706 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2707 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2710 parent
->MacWindowToRootWindow( &x
, &y
) ;
2711 MacRootWindowToWindow( &x
, &y
) ;
2713 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2715 // the wxwindow and client rects will always be clipped
2716 SectRect( &r
, &rparent
, &r
) ;
2717 SectRect( &rClient
, &rparent
, &rClient
) ;
2719 // the structure only at 'hard' borders
2720 if ( parent
->MacClipChildren() ||
2721 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2723 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2729 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2730 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2731 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2732 m_cachedClippedRectWithOuterStructure
= wxRect(
2733 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2734 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2735 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2737 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2738 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2739 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2741 m_cachedClippedRectValid
= true ;
2745 This function must not change the updatergn !
2747 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
2749 bool handled
= false ;
2751 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2752 GetRegionBounds( updatergn
, &updatebounds
) ;
2754 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2756 if ( !EmptyRgn(updatergn
) )
2758 RgnHandle newupdate
= NewRgn() ;
2759 wxSize point
= GetClientSize() ;
2760 wxPoint origin
= GetClientAreaOrigin() ;
2761 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2762 SectRgn( newupdate
, updatergn
, newupdate
) ;
2764 // first send an erase event to the entire update area
2766 // for the toplevel window this really is the entire area
2767 // for all the others only their client area, otherwise they
2768 // might be drawing with full alpha and eg put blue into
2769 // the grow-box area of a scrolled window (scroll sample)
2770 wxDC
* dc
= new wxWindowDC(this);
2772 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
2774 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
2776 wxEraseEvent
eevent( GetId(), dc
);
2777 eevent
.SetEventObject( this );
2778 HandleWindowEvent( eevent
);
2784 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2785 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2786 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
2787 DisposeRgn( newupdate
) ;
2789 if ( !m_updateRegion
.Empty() )
2791 // paint the window itself
2794 event
.SetTimestamp(time
);
2795 event
.SetEventObject(this);
2796 HandleWindowEvent(event
);
2800 // now we cannot rely on having its borders drawn by a window itself, as it does not
2801 // get the updateRgn wide enough to always do so, so we do it from the parent
2802 // this would also be the place to draw any custom backgrounds for native controls
2803 // in Composited windowing
2804 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2808 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2810 child
= node
->GetData();
2813 if (child
== m_vScrollBar
)
2815 if (child
== m_hScrollBar
)
2817 if (child
->IsTopLevel())
2819 if (!child
->IsShown())
2822 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2824 child
->GetPosition( &x
, &y
);
2825 child
->GetSize( &w
, &h
);
2826 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2827 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2828 InsetRect( &childRect
, -10 , -10) ;
2830 if ( RectInRgn( &childRect
, updatergn
) )
2832 // paint custom borders
2833 wxNcPaintEvent
eventNc( child
->GetId() );
2834 eventNc
.SetEventObject( child
);
2835 if ( !child
->HandleWindowEvent( eventNc
) )
2837 child
->MacPaintBorders(0, 0) ;
2847 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2849 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2853 if ( iter
->IsTopLevel() )
2855 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
2857 return toplevel
->MacGetWindowRef();
2859 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
2861 return popupwin
->MacGetWindowRef();
2864 iter
= iter
->GetParent() ;
2870 bool wxWindowMac::MacHasScrollBarCorner() const
2872 /* Returns whether the scroll bars in a wxScrolledWindow should be
2873 * shortened. Scroll bars should be shortened if either:
2875 * - both scroll bars are visible, or
2877 * - there is a resize box in the parent frame's corner and this
2878 * window shares the bottom and right edge with the parent
2882 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2885 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2886 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2888 // Both scroll bars visible
2893 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2895 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
2897 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2900 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2902 // Parent frame has resize handle
2903 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2905 // Note: allow for some wiggle room here as wxMac's
2906 // window rect calculations seem to be imprecise
2907 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2908 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2910 // Parent frame has resize handle and shares
2911 // right bottom corner
2916 // Parent frame has resize handle but doesn't
2917 // share right bottom corner
2923 // Parent frame doesn't have resize handle
2929 // No parent frame found
2934 void wxWindowMac::MacCreateScrollBars( long style
)
2936 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2938 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2940 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2941 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2943 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2946 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2948 GetClientSize( &width
, &height
) ;
2950 wxPoint
vPoint(width
- scrlsize
, 0) ;
2951 wxSize
vSize(scrlsize
, height
- adjust
) ;
2952 wxPoint
hPoint(0, height
- scrlsize
) ;
2953 wxSize
hSize(width
- adjust
, scrlsize
) ;
2955 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2956 if ( style
& wxVSCROLL
)
2958 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2959 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2962 if ( style
& wxHSCROLL
)
2964 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2965 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2969 // because the create does not take into account the client area origin
2970 // we might have a real position shift
2971 MacRepositionScrollBars() ;
2974 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2976 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2981 void wxWindowMac::MacRepositionScrollBars()
2983 if ( !m_hScrollBar
&& !m_vScrollBar
)
2986 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2987 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2989 // get real client area
2991 GetSize( &width
, &height
);
2993 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2994 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2996 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2997 wxSize
vSize( scrlsize
, height
- adjust
) ;
2998 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2999 wxSize
hSize( width
- adjust
, scrlsize
) ;
3002 int x
= 0, y
= 0, w
, h
;
3003 GetSize( &w
, &h
) ;
3005 MacClientToRootWindow( &x
, &y
) ;
3006 MacClientToRootWindow( &w
, &h
) ;
3008 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3010 int totW
= 10000 , totH
= 10000;
3013 if ( iter
->IsTopLevel() )
3015 iter
->GetSize( &totW
, &totH
) ;
3019 iter
= iter
->GetParent() ;
3033 if ( w
- x
>= totW
)
3038 if ( h
- y
>= totH
)
3046 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3048 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3051 bool wxWindowMac::AcceptsFocus() const
3053 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3056 void wxWindowMac::MacSuperChangedPosition()
3058 // only window-absolute structures have to be moved i.e. controls
3060 m_cachedClippedRectValid
= false ;
3063 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3066 child
= node
->GetData();
3067 child
->MacSuperChangedPosition() ;
3069 node
= node
->GetNext();
3073 void wxWindowMac::MacTopLevelWindowChangedPosition()
3075 // only screen-absolute structures have to be moved i.e. glcanvas
3078 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3081 child
= node
->GetData();
3082 child
->MacTopLevelWindowChangedPosition() ;
3084 node
= node
->GetNext();
3088 long wxWindowMac::MacGetLeftBorderSize() const
3095 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3097 // this metric is only the 'outset' outside the simple frame rect
3098 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3101 else if (HasFlag(wxSIMPLE_BORDER
))
3103 // this metric is only the 'outset' outside the simple frame rect
3104 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3111 long wxWindowMac::MacGetRightBorderSize() const
3113 // they are all symmetric in mac themes
3114 return MacGetLeftBorderSize() ;
3117 long wxWindowMac::MacGetTopBorderSize() const
3119 // they are all symmetric in mac themes
3120 return MacGetLeftBorderSize() ;
3123 long wxWindowMac::MacGetBottomBorderSize() const
3125 // they are all symmetric in mac themes
3126 return MacGetLeftBorderSize() ;
3129 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3131 return style
& ~wxBORDER_MASK
;
3134 // Find the wxWindowMac at the current mouse position, returning the mouse
3136 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3138 pt
= wxGetMousePosition();
3139 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3144 // Get the current mouse position.
3145 wxPoint
wxGetMousePosition()
3149 wxGetMousePosition( &x
, &y
);
3151 return wxPoint(x
, y
);
3154 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3156 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3158 // copied from wxGTK : CS
3159 // VZ: shouldn't we move this to base class then?
3161 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3164 // (a) it's a command event and so is propagated to the parent
3165 // (b) under MSW it can be generated from kbd too
3166 // (c) it uses screen coords (because of (a))
3167 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3169 this->ClientToScreen(event
.GetPosition()));
3170 evtCtx
.SetEventObject(this);
3171 if ( ! HandleWindowEvent(evtCtx
) )
3180 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3182 // for native controls: call their native paint method
3183 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
3185 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
3186 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
3187 CallNextEventHandler(
3188 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3189 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3193 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
3194 wxInt16
WXUNUSED(controlpart
),
3195 bool WXUNUSED(mouseStillDown
))
3199 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3203 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3204 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3209 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3211 return eventNotHandledErr
;
3214 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3216 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3217 if ( !wxWindowBase::Reparent(newParent
) )
3220 // copied from MacPostControlCreate
3221 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3223 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3225 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3230 bool wxWindowMac::SetTransparent(wxByte alpha
)
3232 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
3234 if ( alpha
!= m_macAlpha
)
3236 m_macAlpha
= alpha
;
3243 bool wxWindowMac::CanSetTransparent()
3248 wxByte
wxWindowMac::GetTransparent() const
3253 bool wxWindowMac::IsShownOnScreen() const
3255 #if TARGET_API_MAC_OSX
3256 if ( m_peer
&& m_peer
->Ok() )
3258 bool peerVis
= m_peer
->IsVisible();
3259 bool wxVis
= wxWindowBase::IsShownOnScreen();
3260 if( peerVis
!= wxVis
)
3262 // CS : put a breakpoint here to investigate differences
3263 // between native an wx visibilities
3264 // the only place where I've encountered them until now
3265 // are the hiding/showing sequences where the vis-changed event is
3266 // first sent to the innermost control, while wx does things
3267 // from the outmost control
3268 wxVis
= wxWindowBase::IsShownOnScreen();
3272 return m_peer
->IsVisible();
3276 return wxWindowBase::IsShownOnScreen();