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/mac/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
:
384 Boolean focusEverything
= false ;
385 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
387 // put a breakpoint here to catch focus everything events
390 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
391 if ( controlPart
!= kControlFocusNoPart
)
393 targetFocusWindow
= thisWindow
;
394 wxLogTrace(_T("Focus"), _T("focus to be set(%p)"), wx_static_cast(void*, thisWindow
));
398 formerFocusWindow
= thisWindow
;
399 wxLogTrace(_T("Focus"), _T("focus to be lost(%p)"), wx_static_cast(void*, thisWindow
));
402 ControlPartCode previousControlPart
= 0;
403 verify_noerr( HIViewGetFocusPart(controlRef
, &previousControlPart
));
405 if ( thisWindow
->MacIsUserPane() )
407 if ( controlPart
!= kControlFocusNoPart
)
408 cEvent
.SetParameter
<ControlPartCode
>( kEventParamControlPart
, typeControlPartCode
, 1 ) ;
412 result
= CallNextEventHandler(handler
, event
);
414 if ( UMAGetSystemVersion() < 0x1050 )
416 // set back to 0 if problems arise
418 if ( result
== noErr
)
420 ControlPartCode currentControlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
421 // synthesize the event focus changed event
422 EventRef evRef
= NULL
;
424 OSStatus err
= MacCreateEvent(
425 NULL
, kEventClassControl
, kEventControlFocusPartChanged
, TicksToEventTime( TickCount() ) ,
426 kEventAttributeUserEvent
, &evRef
);
429 wxMacCarbonEvent
iEvent( evRef
) ;
430 iEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, controlRef
);
431 iEvent
.SetParameter
<EventTargetRef
>( kEventParamPostTarget
, typeEventTargetRef
, GetControlEventTarget( controlRef
) );
432 iEvent
.SetParameter
<ControlPartCode
>( kEventParamControlPreviousPart
, typeControlPartCode
, previousControlPart
);
433 iEvent
.SetParameter
<ControlPartCode
>( kEventParamControlCurrentPart
, typeControlPartCode
, currentControlPart
);
436 // TODO test this first, avoid double posts etc...
437 PostEventToQueue( GetMainEventQueue(), evRef
, kEventPriorityHigh
);
439 wxMacWindowControlEventHandler( NULL
, evRef
, data
) ;
441 ReleaseEvent( evRef
) ;
444 // old implementation, to be removed if the new one works
445 if ( controlPart
== kControlFocusNoPart
)
448 if ( thisWindow
->GetCaret() )
449 thisWindow
->GetCaret()->OnKillFocus();
452 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow
));
454 static bool inKillFocusEvent
= false ;
456 if ( !inKillFocusEvent
)
458 inKillFocusEvent
= true ;
459 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
460 event
.SetEventObject(thisWindow
);
461 thisWindow
->HandleWindowEvent(event
) ;
462 inKillFocusEvent
= false ;
467 // panel wants to track the window which was the last to have focus in it
468 wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow
));
469 wxChildFocusEvent
eventFocus((wxWindow
*)thisWindow
);
470 thisWindow
->HandleWindowEvent(eventFocus
);
473 if ( thisWindow
->GetCaret() )
474 thisWindow
->GetCaret()->OnSetFocus();
477 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
478 event
.SetEventObject(thisWindow
);
479 thisWindow
->HandleWindowEvent(event
) ;
486 case kEventControlHit
:
487 result
= thisWindow
->MacControlHit( handler
, event
) ;
490 case kEventControlGetClickActivation
:
492 // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
493 WindowRef owner
= cEvent
.GetParameter
<WindowRef
>(kEventParamWindowRef
);
494 if ( !IsWindowActive(owner
) )
496 cEvent
.SetParameter(kEventParamClickActivation
,(UInt32
) kActivateAndIgnoreClick
) ;
509 static pascal OSStatus
510 wxMacWindowServiceEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
514 OSStatus result
= eventNotHandledErr
;
516 wxMacCarbonEvent
cEvent( event
) ;
518 ControlRef controlRef
;
519 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
520 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
521 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
523 switch ( GetEventKind( event
) )
525 case kEventServiceGetTypes
:
529 textCtrl
->GetSelection( &from
, &to
) ;
531 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
533 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
534 if ( textCtrl
->IsEditable() )
535 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
537 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
538 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
540 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
544 CFArrayAppendValue(copyTypes
, typestring
) ;
546 CFArrayAppendValue(pasteTypes
, typestring
) ;
548 CFRelease( typestring
) ;
556 case kEventServiceCopy
:
561 textCtrl
->GetSelection( &from
, &to
) ;
562 wxString val
= textCtrl
->GetValue() ;
563 val
= val
.Mid( from
, to
- from
) ;
564 PasteboardRef pasteboard
= cEvent
.GetParameter
<PasteboardRef
>( kEventParamPasteboardRef
, typePasteboardRef
);
565 verify_noerr( PasteboardClear( pasteboard
) ) ;
566 PasteboardSynchronize( pasteboard
);
567 // TODO add proper conversion
568 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (const UInt8
*)val
.c_str(), val
.length() );
569 PasteboardPutItemFlavor( pasteboard
, (PasteboardItemID
) 1, CFSTR("com.apple.traditional-mac-plain-text"), data
, 0);
575 case kEventServicePaste
:
578 PasteboardRef pasteboard
= cEvent
.GetParameter
<PasteboardRef
>( kEventParamPasteboardRef
, typePasteboardRef
);
579 PasteboardSynchronize( pasteboard
);
581 verify_noerr( PasteboardGetItemCount( pasteboard
, &itemCount
) );
582 for( UInt32 itemIndex
= 1; itemIndex
<= itemCount
; itemIndex
++ )
584 PasteboardItemID itemID
;
585 if ( PasteboardGetItemIdentifier( pasteboard
, itemIndex
, &itemID
) == noErr
)
587 CFDataRef flavorData
= NULL
;
588 if ( PasteboardCopyItemFlavorData( pasteboard
, itemID
, CFSTR("com.apple.traditional-mac-plain-text"), &flavorData
) == noErr
)
590 CFIndex flavorDataSize
= CFDataGetLength( flavorData
);
591 char *content
= new char[flavorDataSize
+1] ;
592 memcpy( content
, CFDataGetBytePtr( flavorData
), flavorDataSize
);
593 content
[flavorDataSize
]=0;
594 CFRelease( flavorData
);
596 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
598 textCtrl
->WriteText( wxString( content
) ) ;
616 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
618 OSStatus result
= eventNotHandledErr
;
619 wxWindowMac
* focus
= (wxWindowMac
*) data
;
621 wchar_t* uniChars
= NULL
;
622 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
624 UniChar
* charBuf
= NULL
;
625 ByteCount dataSize
= 0 ;
628 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
630 numChars
= dataSize
/ sizeof( UniChar
) + 1;
633 if ( (size_t) numChars
* 2 > sizeof(buf
) )
634 charBuf
= new UniChar
[ numChars
] ;
638 uniChars
= new wchar_t[ numChars
] ;
639 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
640 charBuf
[ numChars
- 1 ] = 0;
641 #if SIZEOF_WCHAR_T == 2
642 uniChars
= (wchar_t*) charBuf
;
643 /* 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...)
645 // the resulting string will never have more chars than the utf16 version, so this is safe
646 wxMBConvUTF16 converter
;
647 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
651 switch ( GetEventKind( event
) )
653 case kEventTextInputUpdateActiveInputArea
:
655 // An IME input event may return several characters, but we need to send one char at a time to
657 for (int pos
=0 ; pos
< numChars
; pos
++)
659 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
660 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
661 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
663 UInt32 message
= uniChars
[pos
] < 128 ? (char)uniChars
[pos
] : '?';
665 NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent
666 multiple times to update the active range during inline input, so this handler will often receive
667 uncommited text, which should usually not trigger side effects. It might be a good idea to check the
668 kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h).
669 On the other hand, it can be useful for some applications to react to uncommitted text (for example,
670 to update a status display), as long as it does not disrupt the inline input session. Ideally, wx
671 should add new event types to support advanced text input. For now, I would keep things as they are.
673 However, the code that was being used caused additional problems:
674 UInt32 message = (0 << 8) + ((char)uniChars[pos] );
675 Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline
676 input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji
677 for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB
678 (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D
679 (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress.
680 Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only
681 overlap with Unicode within the (7-bit) ASCII range.
682 But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks
683 for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII
684 characters as they are and replaces the rest with '?', ensuring that update events are triggered.
685 It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but
686 I don't have time to look into that right now.
689 if ( wxTheApp
->MacSendCharEvent(
690 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
695 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
699 case kEventTextInputUnicodeForKeyEvent
:
701 UInt32 keyCode
, modifiers
;
704 unsigned char charCode
;
706 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
707 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
708 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
709 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
710 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
712 UInt32 message
= (keyCode
<< 8) + charCode
;
714 // An IME input event may return several characters, but we need to send one char at a time to
716 for (int pos
=0 ; pos
< numChars
; pos
++)
718 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
719 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
720 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
722 if ( wxTheApp
->MacSendCharEvent(
723 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
728 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
737 if ( charBuf
!= buf
)
743 static pascal OSStatus
744 wxMacWindowCommandEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
748 OSStatus result
= eventNotHandledErr
;
749 wxWindowMac
* focus
= (wxWindowMac
*) data
;
753 wxMacCarbonEvent
cEvent( event
) ;
754 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
756 wxMenuItem
* item
= NULL
;
757 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
758 int id
= wxMacCommandToId( command
.commandID
) ;
762 wxASSERT( itemMenu
!= NULL
) ;
764 switch ( cEvent
.GetKind() )
766 case kEventProcessCommand
:
767 result
= itemMenu
->MacHandleCommandProcess( item
, id
, focus
);
770 case kEventCommandUpdateStatus
:
771 result
= itemMenu
->MacHandleCommandUpdateStatus( item
, id
, focus
);
781 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
783 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
784 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
785 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
786 OSStatus result
= eventNotHandledErr
;
788 switch ( GetEventClass( event
) )
790 case kEventClassCommand
:
791 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
794 case kEventClassControl
:
795 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
798 case kEventClassService
:
799 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
802 case kEventClassTextInput
:
803 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
810 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
815 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
817 // ---------------------------------------------------------------------------
818 // Scrollbar Tracking for all
819 // ---------------------------------------------------------------------------
821 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
822 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
826 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
828 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
831 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
833 // ===========================================================================
835 // ===========================================================================
837 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
839 static MacControlMap wxWinMacControlList
;
841 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
843 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
845 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
848 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
850 // adding NULL ControlRef is (first) surely a result of an error and
851 // (secondly) breaks native event processing
852 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
854 wxWinMacControlList
[inControl
] = control
;
857 void wxRemoveMacControlAssociation(wxWindow
*control
)
859 // iterate over all the elements in the class
860 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
861 // we should go on...
867 MacControlMap::iterator it
;
868 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
870 if ( it
->second
== control
)
872 wxWinMacControlList
.erase(it
);
880 // ----------------------------------------------------------------------------
881 // constructors and such
882 // ----------------------------------------------------------------------------
884 wxWindowMac::wxWindowMac()
889 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
894 const wxString
& name
)
897 Create(parent
, id
, pos
, size
, style
, name
);
900 void wxWindowMac::Init()
904 m_cgContextRef
= NULL
;
906 // as all windows are created with WS_VISIBLE style...
909 m_hScrollBar
= NULL
;
910 m_vScrollBar
= NULL
;
911 m_hScrollBarAlwaysShown
= false;
912 m_vScrollBarAlwaysShown
= false;
914 m_macIsUserPane
= true;
915 m_clipChildren
= false ;
916 m_cachedClippedRectValid
= false ;
919 wxWindowMac::~wxWindowMac()
923 m_isBeingDeleted
= true;
925 MacInvalidateBorders() ;
927 #ifndef __WXUNIVERSAL__
928 // VS: make sure there's no wxFrame with last focus set to us:
929 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
931 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
934 if ( frame
->GetLastFocus() == this )
935 frame
->SetLastFocus((wxWindow
*)NULL
);
941 // destroy children before destroying this window itself
944 // wxRemoveMacControlAssociation( this ) ;
945 // If we delete an item, we should initialize the parent panel,
946 // because it could now be invalid.
947 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
950 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
951 tlw
->SetDefaultItem(NULL
);
954 if ( m_peer
&& m_peer
->Ok() )
956 // in case the callback might be called during destruction
957 wxRemoveMacControlAssociation( this) ;
958 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
959 // we currently are not using this hook
960 // ::SetControlColorProc( *m_peer , NULL ) ;
964 if ( g_MacLastWindow
== this )
965 g_MacLastWindow
= NULL
;
967 #ifndef __WXUNIVERSAL__
968 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
971 if ( frame
->GetLastFocus() == this )
972 frame
->SetLastFocus( NULL
) ;
976 // delete our drop target if we've got one
977 #if wxUSE_DRAG_AND_DROP
978 if ( m_dropTarget
!= NULL
)
988 WXWidget
wxWindowMac::GetHandle() const
990 return (WXWidget
) m_peer
->GetControlRef() ;
993 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
995 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
996 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
997 GetEventTypeCount(eventList
), eventList
, this,
998 (EventHandlerRef
*)&m_macControlEventHandler
);
1002 bool wxWindowMac::Create(wxWindowMac
*parent
,
1007 const wxString
& name
)
1009 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1011 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1014 m_windowVariant
= parent
->GetWindowVariant() ;
1016 if ( m_macIsUserPane
)
1018 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1021 | kControlSupportsEmbedding
1022 | kControlSupportsLiveFeedback
1023 | kControlGetsFocusOnClick
1024 // | kControlHasSpecialBackground
1025 // | kControlSupportsCalcBestRect
1026 | kControlHandlesTracking
1027 | kControlSupportsFocus
1028 | kControlWantsActivate
1029 | kControlWantsIdle
;
1031 m_peer
= new wxMacControl(this) ;
1032 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1033 verify_noerr( err
);
1035 MacPostControlCreate(pos
, size
) ;
1038 #ifndef __WXUNIVERSAL__
1039 // Don't give scrollbars to wxControls unless they ask for them
1040 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1041 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1043 MacCreateScrollBars( style
) ;
1047 wxWindowCreateEvent
event(this);
1048 GetEventHandler()->AddPendingEvent(event
);
1053 void wxWindowMac::MacChildAdded()
1056 m_vScrollBar
->Raise() ;
1058 m_hScrollBar
->Raise() ;
1061 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
1063 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1065 m_peer
->SetReference( (URefCon
) this ) ;
1066 GetParent()->AddChild( this );
1068 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1070 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1071 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1072 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1073 GetParent()->MacChildAdded() ;
1075 // adjust font, controlsize etc
1076 DoSetWindowVariant( m_windowVariant
) ;
1078 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1080 if (!m_macIsUserPane
)
1081 SetInitialSize(size
);
1083 SetCursor( *wxSTANDARD_CURSOR
) ;
1086 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1088 // Don't assert, in case we set the window variant before
1089 // the window is created
1090 // wxASSERT( m_peer->Ok() ) ;
1092 m_windowVariant
= variant
;
1094 if (m_peer
== NULL
|| !m_peer
->Ok())
1098 ThemeFontID themeFont
= kThemeSystemFont
;
1100 // we will get that from the settings later
1101 // and make this NORMAL later, but first
1102 // we have a few calculations that we must fix
1106 case wxWINDOW_VARIANT_NORMAL
:
1107 size
= kControlSizeNormal
;
1108 themeFont
= kThemeSystemFont
;
1111 case wxWINDOW_VARIANT_SMALL
:
1112 size
= kControlSizeSmall
;
1113 themeFont
= kThemeSmallSystemFont
;
1116 case wxWINDOW_VARIANT_MINI
:
1117 // not always defined in the headers
1122 case wxWINDOW_VARIANT_LARGE
:
1123 size
= kControlSizeLarge
;
1124 themeFont
= kThemeSystemFont
;
1128 wxFAIL_MSG(_T("unexpected window variant"));
1132 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1135 font
.MacCreateFromThemeFont( themeFont
) ;
1139 void wxWindowMac::MacUpdateControlFont()
1141 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1142 // do not trigger refreshes upon invisible and possible partly created objects
1143 if ( IsShownOnScreen() )
1147 bool wxWindowMac::SetFont(const wxFont
& font
)
1149 bool retval
= wxWindowBase::SetFont( font
);
1151 MacUpdateControlFont() ;
1156 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1158 bool retval
= wxWindowBase::SetForegroundColour( col
);
1161 MacUpdateControlFont();
1166 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1168 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1171 m_peer
->SetBackgroundColour( col
) ;
1176 bool wxWindowMac::MacCanFocus() const
1178 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1179 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1180 // but the value range is nowhere documented
1181 Boolean keyExistsAndHasValidFormat
;
1182 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1183 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1185 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1191 UInt32 features
= 0 ;
1192 m_peer
->GetFeatures( &features
) ;
1194 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1198 void wxWindowMac::SetFocus()
1200 if ( !AcceptsFocus() )
1203 wxWindow
* former
= FindFocus() ;
1204 if ( former
== this )
1207 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1208 // we can only leave in case of an error
1209 wxLogTrace(_T("Focus"), _T("before wxWindow::SetFocus(%p) %d"), wx_static_cast(void*, this), GetName().c_str());
1210 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1211 if ( err
== errCouldntSetFocus
)
1213 wxLogTrace(_T("Focus"), _T("in wxWindow::SetFocus(%p) errCouldntSetFocus"), wx_static_cast(void*, this));
1216 wxLogTrace(_T("Focus"), _T("after wxWindow::SetFocus(%p)"), wx_static_cast(void*, this));
1218 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1221 void wxWindowMac::DoCaptureMouse()
1223 wxApp::s_captureWindow
= this ;
1226 wxWindow
* wxWindowBase::GetCapture()
1228 return wxApp::s_captureWindow
;
1231 void wxWindowMac::DoReleaseMouse()
1233 wxApp::s_captureWindow
= NULL
;
1236 #if wxUSE_DRAG_AND_DROP
1238 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1240 if ( m_dropTarget
!= NULL
)
1241 delete m_dropTarget
;
1243 m_dropTarget
= pDropTarget
;
1244 if ( m_dropTarget
!= NULL
)
1252 // Old-style File Manager Drag & Drop
1253 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
1258 // Returns the size of the native control. In the case of the toplevel window
1259 // this is the content area root control
1261 void wxWindowMac::MacGetPositionAndSizeFromControl(int& WXUNUSED(x
),
1264 int& WXUNUSED(h
)) const
1266 wxFAIL_MSG( wxT("Not currently supported") ) ;
1269 // From a wx position / size calculate the appropriate size of the native control
1271 bool wxWindowMac::MacGetBoundsForControl(
1275 int& w
, int& h
, bool adjustOrigin
) const
1277 // the desired size, minus the border pixels gives the correct size of the control
1281 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1282 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1283 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1285 x
+= MacGetLeftBorderSize() ;
1286 y
+= MacGetTopBorderSize() ;
1287 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1288 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1291 AdjustForParentClientOrigin( x
, y
) ;
1293 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1294 if ( !GetParent()->IsTopLevel() )
1296 x
-= GetParent()->MacGetLeftBorderSize() ;
1297 y
-= GetParent()->MacGetTopBorderSize() ;
1303 // Get window size (not client size)
1304 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1307 m_peer
->GetRect( &bounds
) ;
1310 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1312 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1315 // get the position of the bounds of this window in client coordinates of its parent
1316 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1319 m_peer
->GetRect( &bounds
) ;
1321 int x1
= bounds
.left
;
1322 int y1
= bounds
.top
;
1324 // get the wx window position from the native one
1325 x1
-= MacGetLeftBorderSize() ;
1326 y1
-= MacGetTopBorderSize() ;
1328 if ( !IsTopLevel() )
1330 wxWindow
*parent
= GetParent();
1333 // we must first adjust it to be in window coordinates of the parent,
1334 // as otherwise it gets lost by the ClientAreaOrigin fix
1335 x1
+= parent
->MacGetLeftBorderSize() ;
1336 y1
+= parent
->MacGetTopBorderSize() ;
1338 // and now to client coordinates
1339 wxPoint
pt(parent
->GetClientAreaOrigin());
1351 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1353 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1354 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1356 Point localwhere
= { 0, 0 } ;
1363 wxMacGlobalToLocal( window
, &localwhere
) ;
1370 MacRootWindowToWindow( x
, y
) ;
1372 wxPoint origin
= GetClientAreaOrigin() ;
1379 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1381 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1382 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1384 wxPoint origin
= GetClientAreaOrigin() ;
1390 MacWindowToRootWindow( x
, y
) ;
1392 Point localwhere
= { 0, 0 };
1398 wxMacLocalToGlobal( window
, &localwhere
) ;
1406 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1408 wxPoint origin
= GetClientAreaOrigin() ;
1414 MacWindowToRootWindow( x
, y
) ;
1417 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1419 MacRootWindowToWindow( x
, y
) ;
1421 wxPoint origin
= GetClientAreaOrigin() ;
1428 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1437 if ( !IsTopLevel() )
1439 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1442 pt
.x
-= MacGetLeftBorderSize() ;
1443 pt
.y
-= MacGetTopBorderSize() ;
1444 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1454 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1463 MacWindowToRootWindow( &x1
, &y1
) ;
1471 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1480 if ( !IsTopLevel() )
1482 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1485 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1486 pt
.x
+= MacGetLeftBorderSize() ;
1487 pt
.y
+= MacGetTopBorderSize() ;
1497 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1506 MacRootWindowToWindow( &x1
, &y1
) ;
1514 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1516 RgnHandle rgn
= NewRgn() ;
1518 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1520 Rect structure
, content
;
1522 GetRegionBounds( rgn
, &content
) ;
1523 m_peer
->GetRect( &structure
) ;
1524 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1526 left
= content
.left
- structure
.left
;
1527 top
= content
.top
- structure
.top
;
1528 right
= structure
.right
- content
.right
;
1529 bottom
= structure
.bottom
- content
.bottom
;
1533 left
= top
= right
= bottom
= 0 ;
1539 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1541 wxSize sizeTotal
= size
;
1543 RgnHandle rgn
= NewRgn() ;
1544 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1546 Rect content
, structure
;
1547 GetRegionBounds( rgn
, &content
) ;
1548 m_peer
->GetRect( &structure
) ;
1550 // structure is in parent coordinates, but we only need width and height, so it's ok
1552 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1553 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1558 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1559 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1564 // Get size *available for subwindows* i.e. excluding menu bar etc.
1565 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1569 RgnHandle rgn
= NewRgn() ;
1571 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1572 GetRegionBounds( rgn
, &content
) ;
1574 m_peer
->GetRect( &content
) ;
1577 ww
= content
.right
- content
.left
;
1578 hh
= content
.bottom
- content
.top
;
1580 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1581 hh
-= m_hScrollBar
->GetSize().y
;
1583 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1584 ww
-= m_vScrollBar
->GetSize().x
;
1592 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1594 if (m_cursor
.IsSameAs(cursor
))
1599 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1604 if ( ! wxWindowBase::SetCursor( cursor
) )
1608 wxASSERT_MSG( m_cursor
.Ok(),
1609 wxT("cursor must be valid after call to the base version"));
1611 wxWindowMac
*mouseWin
= 0 ;
1613 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
1614 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1616 ControlPartCode part
;
1617 ControlRef control
;
1619 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1621 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
1625 GetGlobalMouse( &pt
);
1628 ScreenToClient(&x
, &y
);
1632 control
= FindControlUnderMouse( pt
, window
, &part
) ;
1634 mouseWin
= wxFindControlFromMacControl( control
) ;
1638 if ( mouseWin
== this && !wxIsBusy() )
1639 m_cursor
.MacInstall() ;
1645 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1647 #ifndef __WXUNIVERSAL__
1648 menu
->SetInvokingWindow((wxWindow
*)this);
1651 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1653 wxPoint mouse
= wxGetMousePosition();
1659 ClientToScreen( &x
, &y
) ;
1662 menu
->MacBeforeDisplay( true ) ;
1663 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1664 if ( HiWord(menuResult
) != 0 )
1667 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1668 int id
= wxMacCommandToId( macid
);
1669 wxMenuItem
* item
= NULL
;
1671 item
= menu
->FindItem( id
, &realmenu
) ;
1674 if (item
->IsCheckable())
1675 item
->Check( !item
->IsChecked() ) ;
1677 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1681 menu
->MacAfterDisplay( true ) ;
1682 menu
->SetInvokingWindow( NULL
);
1686 // actually this shouldn't be called, because universal is having its own implementation
1692 // ----------------------------------------------------------------------------
1694 // ----------------------------------------------------------------------------
1698 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1700 wxWindowBase::DoSetToolTip(tooltip
);
1703 m_tooltip
->SetWindow(this);
1708 void wxWindowMac::MacInvalidateBorders()
1710 if ( m_peer
== NULL
)
1713 bool vis
= IsShownOnScreen() ;
1717 int outerBorder
= MacGetLeftBorderSize() ;
1718 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
1721 if ( outerBorder
== 0 )
1724 // now we know that we have something to do at all
1726 // as the borders are drawn on the parent we have to properly invalidate all these areas
1727 RgnHandle updateInner
, updateOuter
;
1730 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1731 updateInner
= NewRgn() ;
1732 updateOuter
= NewRgn() ;
1734 m_peer
->GetRect( &rect
) ;
1735 RectRgn( updateInner
, &rect
) ;
1736 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1737 RectRgn( updateOuter
, &rect
) ;
1738 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1740 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1742 DisposeRgn( updateOuter
) ;
1743 DisposeRgn( updateInner
) ;
1746 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1748 // this is never called for a toplevel window, so we know we have a parent
1749 int former_x
, former_y
, former_w
, former_h
;
1751 // Get true coordinates of former position
1752 DoGetPosition( &former_x
, &former_y
) ;
1753 DoGetSize( &former_w
, &former_h
) ;
1755 wxWindow
*parent
= GetParent();
1758 wxPoint
pt(parent
->GetClientAreaOrigin());
1763 int actualWidth
= width
;
1764 int actualHeight
= height
;
1768 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1769 actualWidth
= m_minWidth
;
1770 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1771 actualHeight
= m_minHeight
;
1772 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1773 actualWidth
= m_maxWidth
;
1774 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1775 actualHeight
= m_maxHeight
;
1777 bool doMove
= false, doResize
= false ;
1779 if ( actualX
!= former_x
|| actualY
!= former_y
)
1782 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1785 if ( doMove
|| doResize
)
1787 // as the borders are drawn outside the native control, we adjust now
1789 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1790 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1791 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1794 wxMacRectToNative( &bounds
, &r
) ;
1796 if ( !GetParent()->IsTopLevel() )
1797 wxMacWindowToNative( GetParent() , &r
) ;
1799 MacInvalidateBorders() ;
1801 m_cachedClippedRectValid
= false ;
1802 m_peer
->SetRect( &r
) ;
1804 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1806 MacInvalidateBorders() ;
1808 MacRepositionScrollBars() ;
1811 wxPoint
point(actualX
, actualY
);
1812 wxMoveEvent
event(point
, m_windowId
);
1813 event
.SetEventObject(this);
1814 HandleWindowEvent(event
) ;
1819 MacRepositionScrollBars() ;
1820 wxSize
size(actualWidth
, actualHeight
);
1821 wxSizeEvent
event(size
, m_windowId
);
1822 event
.SetEventObject(this);
1823 HandleWindowEvent(event
);
1828 wxSize
wxWindowMac::DoGetBestSize() const
1830 if ( m_macIsUserPane
|| IsTopLevel() )
1831 return wxWindowBase::DoGetBestSize() ;
1833 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1834 int bestWidth
, bestHeight
;
1836 m_peer
->GetBestRect( &bestsize
) ;
1837 if ( EmptyRect( &bestsize
) )
1842 bestsize
.bottom
= 16 ;
1844 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1846 bestsize
.bottom
= 16 ;
1849 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1851 bestsize
.bottom
= 24 ;
1856 // return wxWindowBase::DoGetBestSize() ;
1860 bestWidth
= bestsize
.right
- bestsize
.left
;
1861 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1862 if ( bestHeight
< 10 )
1865 return wxSize(bestWidth
, bestHeight
);
1868 // set the size of the window: if the dimensions are positive, just use them,
1869 // but if any of them is equal to -1, it means that we must find the value for
1870 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1871 // which case -1 is a valid value for x and y)
1873 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1874 // the width/height to best suit our contents, otherwise we reuse the current
1876 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1878 // get the current size and position...
1879 int currentX
, currentY
;
1880 int currentW
, currentH
;
1882 GetPosition(¤tX
, ¤tY
);
1883 GetSize(¤tW
, ¤tH
);
1885 // ... and don't do anything (avoiding flicker) if it's already ok
1886 if ( x
== currentX
&& y
== currentY
&&
1887 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1890 MacRepositionScrollBars() ; // we might have a real position shift
1895 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1897 if ( x
== wxDefaultCoord
)
1899 if ( y
== wxDefaultCoord
)
1903 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1905 wxSize size
= wxDefaultSize
;
1906 if ( width
== wxDefaultCoord
)
1908 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1910 size
= DoGetBestSize();
1915 // just take the current one
1920 if ( height
== wxDefaultCoord
)
1922 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1924 if ( size
.x
== wxDefaultCoord
)
1925 size
= DoGetBestSize();
1926 // else: already called DoGetBestSize() above
1932 // just take the current one
1937 DoMoveWindow( x
, y
, width
, height
);
1940 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1942 RgnHandle rgn
= NewRgn() ;
1944 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1946 GetRegionBounds( rgn
, &content
) ;
1956 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
1959 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1961 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1963 int currentclientwidth
, currentclientheight
;
1964 int currentwidth
, currentheight
;
1966 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1967 GetSize( ¤twidth
, ¤theight
) ;
1969 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1970 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1974 void wxWindowMac::SetLabel(const wxString
& title
)
1978 if ( m_peer
&& m_peer
->Ok() )
1979 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1981 // do not trigger refreshes upon invisible and possible partly created objects
1982 if ( IsShownOnScreen() )
1986 wxString
wxWindowMac::GetLabel() const
1991 bool wxWindowMac::Show(bool show
)
1993 if ( !wxWindowBase::Show(show
) )
1997 m_peer
->SetVisibility( show
, true ) ;
2002 void wxWindowMac::DoEnable(bool enable
)
2004 m_peer
->Enable( enable
) ;
2008 // status change notifications
2011 void wxWindowMac::MacVisibilityChanged()
2015 void wxWindowMac::MacHiliteChanged()
2019 void wxWindowMac::MacEnabledStateChanged()
2021 OnEnabled( m_peer
->IsEnabled() );
2025 // status queries on the inherited window's state
2028 bool wxWindowMac::MacIsReallyEnabled()
2030 return m_peer
->IsEnabled() ;
2033 bool wxWindowMac::MacIsReallyHilited()
2035 return m_peer
->IsActive();
2038 void wxWindowMac::MacFlashInvalidAreas()
2040 #if TARGET_API_MAC_OSX
2041 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2045 int wxWindowMac::GetCharHeight() const
2047 wxClientDC
dc( (wxWindowMac
*)this ) ;
2049 return dc
.GetCharHeight() ;
2052 int wxWindowMac::GetCharWidth() const
2054 wxClientDC
dc( (wxWindowMac
*)this ) ;
2056 return dc
.GetCharWidth() ;
2059 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2060 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2062 const wxFont
*fontToUse
= theFont
;
2064 fontToUse
= &m_font
;
2066 wxClientDC
dc( (wxWindowMac
*) this ) ;
2067 wxCoord lx
,ly
,ld
,le
;
2068 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2069 if ( externalLeading
)
2070 *externalLeading
= le
;
2080 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2081 * we always intersect with the entire window, not only with the client area
2084 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
2086 if ( m_peer
== NULL
)
2089 if ( !IsShownOnScreen() )
2096 wxMacRectToNative( rect
, &r
) ;
2097 m_peer
->SetNeedsDisplay( &r
) ;
2101 m_peer
->SetNeedsDisplay() ;
2105 void wxWindowMac::DoFreeze()
2107 #if TARGET_API_MAC_OSX
2108 if ( m_peer
&& m_peer
->Ok() )
2109 m_peer
->SetDrawingEnabled( false ) ;
2113 void wxWindowMac::DoThaw()
2115 #if TARGET_API_MAC_OSX
2116 if ( m_peer
&& m_peer
->Ok() )
2118 m_peer
->SetDrawingEnabled( true ) ;
2119 m_peer
->InvalidateWithChildren() ;
2124 wxWindowMac
*wxGetActiveWindow()
2126 // actually this is a windows-only concept
2130 // Coordinates relative to the window
2131 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
2133 // We really don't move the mouse programmatically under Mac.
2136 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2138 if ( MacGetTopLevelWindow() == NULL
)
2141 #if TARGET_API_MAC_OSX
2142 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
2148 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
2150 event
.GetDC()->Clear() ;
2152 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
2154 // don't skip the event here, custom background means that the app
2155 // is drawing it itself in its OnPaint(), so don't draw it at all
2156 // now to avoid flicker
2164 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2169 int wxWindowMac::GetScrollPos(int orient
) const
2171 if ( orient
== wxHORIZONTAL
)
2174 return m_hScrollBar
->GetThumbPosition() ;
2179 return m_vScrollBar
->GetThumbPosition() ;
2185 // This now returns the whole range, not just the number
2186 // of positions that we can scroll.
2187 int wxWindowMac::GetScrollRange(int orient
) const
2189 if ( orient
== wxHORIZONTAL
)
2192 return m_hScrollBar
->GetRange() ;
2197 return m_vScrollBar
->GetRange() ;
2203 int wxWindowMac::GetScrollThumb(int orient
) const
2205 if ( orient
== wxHORIZONTAL
)
2208 return m_hScrollBar
->GetThumbSize() ;
2213 return m_vScrollBar
->GetThumbSize() ;
2219 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
2221 if ( orient
== wxHORIZONTAL
)
2224 m_hScrollBar
->SetThumbPosition( pos
) ;
2229 m_vScrollBar
->SetThumbPosition( pos
) ;
2234 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
2236 bool needVisibilityUpdate
= false;
2238 if ( m_hScrollBarAlwaysShown
!= hflag
)
2240 m_hScrollBarAlwaysShown
= hflag
;
2241 needVisibilityUpdate
= true;
2244 if ( m_vScrollBarAlwaysShown
!= vflag
)
2246 m_vScrollBarAlwaysShown
= vflag
;
2247 needVisibilityUpdate
= true;
2250 if ( needVisibilityUpdate
)
2251 DoUpdateScrollbarVisibility();
2255 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2256 // our own window origin is at leftOrigin/rightOrigin
2259 void wxWindowMac::MacPaintGrowBox()
2264 if ( MacHasScrollBarCorner() )
2268 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
2269 wxASSERT( cgContext
) ;
2271 m_peer
->GetRect( &rect
) ;
2273 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2274 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2275 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2276 CGContextSaveGState( cgContext
);
2278 if ( m_backgroundColour
.Ok() )
2280 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
2284 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
2286 CGContextFillRect( cgContext
, cgrect
);
2287 CGContextRestoreGState( cgContext
);
2291 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
2297 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2299 // back to the surrounding frame rectangle
2300 m_peer
->GetRect( &rect
) ;
2301 InsetRect( &rect
, -1 , -1 ) ;
2304 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2305 rect
.bottom
- rect
.top
) ;
2307 HIThemeFrameDrawInfo info
;
2308 memset( &info
, 0 , sizeof(info
) ) ;
2312 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2313 info
.isFocused
= hasFocus
;
2315 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2316 wxASSERT( cgContext
) ;
2318 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2320 info
.kind
= kHIThemeFrameTextFieldSquare
;
2321 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2323 else if ( HasFlag(wxSIMPLE_BORDER
) )
2325 info
.kind
= kHIThemeFrameListBox
;
2326 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2328 else if ( hasFocus
)
2330 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2332 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
2333 m_peer
->GetRect( &rect
) ;
2334 if ( MacHasScrollBarCorner() )
2336 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
2337 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2338 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2339 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2340 HIThemeGrowBoxDrawInfo info
;
2341 memset( &info
, 0, sizeof(info
) ) ;
2343 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2344 info
.kind
= kHIThemeGrowBoxKindNone
;
2345 // contrary to the docs ...SizeSmall does not work
2346 info
.size
= kHIThemeGrowBoxSizeNormal
;
2347 info
.direction
= 0 ;
2348 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2354 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2356 if ( child
== m_hScrollBar
)
2357 m_hScrollBar
= NULL
;
2358 if ( child
== m_vScrollBar
)
2359 m_vScrollBar
= NULL
;
2361 wxWindowBase::RemoveChild( child
) ;
2364 void wxWindowMac::DoUpdateScrollbarVisibility()
2366 bool triggerSizeEvent
= false;
2370 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
2372 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
2374 m_hScrollBar
->Show( showHScrollBar
);
2375 triggerSizeEvent
= true;
2381 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
2383 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
2385 m_vScrollBar
->Show( showVScrollBar
) ;
2386 triggerSizeEvent
= true;
2390 MacRepositionScrollBars() ;
2391 if ( triggerSizeEvent
)
2393 wxSizeEvent
event(GetSize(), m_windowId
);
2394 event
.SetEventObject(this);
2395 HandleWindowEvent(event
);
2399 // New function that will replace some of the above.
2400 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
2401 int range
, bool refresh
)
2403 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
2404 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
2405 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
2406 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
2408 DoUpdateScrollbarVisibility();
2411 // Does a physical scroll
2412 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2414 if ( dx
== 0 && dy
== 0 )
2417 int width
, height
;
2418 GetClientSize( &width
, &height
) ;
2421 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2422 // area is scrolled, this does not occur if width and height are 2 pixels less,
2423 // TODO: write optimal workaround
2424 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2426 scrollrect
.Intersect( *rect
) ;
2428 if ( m_peer
->GetNeedsDisplay() )
2430 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2431 // in case there is already a pending redraw on that area
2432 // either immediate redraw or full invalidate
2434 // is the better overall solution, as it does not slow down scrolling
2435 m_peer
->SetNeedsDisplay() ;
2437 // this would be the preferred version for fast drawing controls
2438 HIViewRender(m_peer
->GetControlRef()) ;
2442 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2443 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2444 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2447 // this would be the preferred version for fast drawing controls
2448 HIViewRender(m_peer
->GetControlRef()) ;
2454 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2456 child
= node
->GetData();
2459 if (child
== m_vScrollBar
)
2461 if (child
== m_hScrollBar
)
2463 if (child
->IsTopLevel())
2466 child
->GetPosition( &x
, &y
);
2467 child
->GetSize( &w
, &h
);
2470 wxRect
rc( x
, y
, w
, h
);
2471 if (rect
->Intersects( rc
))
2472 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
2476 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
2481 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2483 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2485 wxScrollWinEvent wevent
;
2486 wevent
.SetPosition(event
.GetPosition());
2487 wevent
.SetOrientation(event
.GetOrientation());
2488 wevent
.SetEventObject(this);
2490 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2491 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2492 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2493 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2494 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2495 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2496 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2497 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2498 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2499 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2500 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2501 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2502 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2503 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2504 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2505 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2507 HandleWindowEvent(wevent
);
2511 // Get the window with the focus
2512 wxWindowMac
*wxWindowBase::DoFindFocus()
2514 ControlRef control
;
2515 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2516 return wxFindControlFromMacControl( control
) ;
2519 void wxWindowMac::OnInternalIdle()
2521 // This calls the UI-update mechanism (querying windows for
2522 // menu/toolbar/control state information)
2523 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
2524 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2527 // Raise the window to the top of the Z order
2528 void wxWindowMac::Raise()
2530 m_peer
->SetZOrder( true , NULL
) ;
2533 // Lower the window to the bottom of the Z order
2534 void wxWindowMac::Lower()
2536 m_peer
->SetZOrder( false , NULL
) ;
2539 // static wxWindow *gs_lastWhich = NULL;
2541 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2543 // first trigger a set cursor event
2545 wxPoint clientorigin
= GetClientAreaOrigin() ;
2546 wxSize clientsize
= GetClientSize() ;
2548 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2550 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2552 bool processedEvtSetCursor
= HandleWindowEvent(event
);
2553 if ( processedEvtSetCursor
&& event
.HasCursor() )
2555 cursor
= event
.GetCursor() ;
2559 // the test for processedEvtSetCursor is here to prevent using m_cursor
2560 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2561 // it - this is a way to say that our cursor shouldn't be used for this
2563 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2566 if ( !wxIsBusy() && !GetParent() )
2567 cursor
= *wxSTANDARD_CURSOR
;
2571 cursor
.MacInstall() ;
2574 return cursor
.Ok() ;
2577 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
2581 return m_tooltip
->GetTip() ;
2584 return wxEmptyString
;
2587 void wxWindowMac::ClearBackground()
2593 void wxWindowMac::Update()
2595 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2597 top
->MacPerformUpdates() ;
2600 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
2602 wxNonOwnedWindow
* win
= NULL
;
2603 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2605 win
= wxFindWinFromMacWindow( window
) ;
2610 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2612 MacUpdateClippedRects() ;
2614 return m_cachedClippedClientRect
;
2617 const wxRect
& wxWindowMac::MacGetClippedRect() const
2619 MacUpdateClippedRects() ;
2621 return m_cachedClippedRect
;
2624 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2626 MacUpdateClippedRects() ;
2628 return m_cachedClippedRectWithOuterStructure
;
2631 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2633 static wxRegion emptyrgn
;
2635 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
2637 MacUpdateClippedRects() ;
2638 if ( includeOuterStructures
)
2639 return m_cachedClippedRegionWithOuterStructure
;
2641 return m_cachedClippedRegion
;
2649 void wxWindowMac::MacUpdateClippedRects() const
2651 if ( m_cachedClippedRectValid
)
2654 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2655 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2656 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2657 // to add focus borders everywhere
2659 Rect r
, rIncludingOuterStructures
;
2661 m_peer
->GetRect( &r
) ;
2662 r
.left
-= MacGetLeftBorderSize() ;
2663 r
.top
-= MacGetTopBorderSize() ;
2664 r
.bottom
+= MacGetBottomBorderSize() ;
2665 r
.right
+= MacGetRightBorderSize() ;
2672 rIncludingOuterStructures
= r
;
2673 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2675 wxRect cl
= GetClientRect() ;
2676 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2680 const wxWindow
* child
= this ;
2681 const wxWindow
* parent
= NULL
;
2683 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2685 if ( parent
->MacIsChildOfClientArea(child
) )
2687 size
= parent
->GetClientSize() ;
2688 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2694 // this will be true for scrollbars, toolbars etc.
2695 size
= parent
->GetSize() ;
2696 y
= parent
->MacGetTopBorderSize() ;
2697 x
= parent
->MacGetLeftBorderSize() ;
2698 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2699 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2702 parent
->MacWindowToRootWindow( &x
, &y
) ;
2703 MacRootWindowToWindow( &x
, &y
) ;
2705 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2707 // the wxwindow and client rects will always be clipped
2708 SectRect( &r
, &rparent
, &r
) ;
2709 SectRect( &rClient
, &rparent
, &rClient
) ;
2711 // the structure only at 'hard' borders
2712 if ( parent
->MacClipChildren() ||
2713 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2715 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2721 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2722 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2723 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2724 m_cachedClippedRectWithOuterStructure
= wxRect(
2725 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2726 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2727 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2729 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2730 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2731 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2733 m_cachedClippedRectValid
= true ;
2737 This function must not change the updatergn !
2739 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
2741 bool handled
= false ;
2743 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2744 GetRegionBounds( updatergn
, &updatebounds
) ;
2746 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2748 if ( !EmptyRgn(updatergn
) )
2750 RgnHandle newupdate
= NewRgn() ;
2751 wxSize point
= GetClientSize() ;
2752 wxPoint origin
= GetClientAreaOrigin() ;
2753 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2754 SectRgn( newupdate
, updatergn
, newupdate
) ;
2756 // first send an erase event to the entire update area
2758 // for the toplevel window this really is the entire area
2759 // for all the others only their client area, otherwise they
2760 // might be drawing with full alpha and eg put blue into
2761 // the grow-box area of a scrolled window (scroll sample)
2762 wxDC
* dc
= new wxWindowDC(this);
2764 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
2766 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
2768 wxEraseEvent
eevent( GetId(), dc
);
2769 eevent
.SetEventObject( this );
2770 HandleWindowEvent( eevent
);
2776 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2777 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2778 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
2779 DisposeRgn( newupdate
) ;
2781 if ( !m_updateRegion
.Empty() )
2783 // paint the window itself
2786 event
.SetTimestamp(time
);
2787 event
.SetEventObject(this);
2788 HandleWindowEvent(event
);
2792 // now we cannot rely on having its borders drawn by a window itself, as it does not
2793 // get the updateRgn wide enough to always do so, so we do it from the parent
2794 // this would also be the place to draw any custom backgrounds for native controls
2795 // in Composited windowing
2796 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2800 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2802 child
= node
->GetData();
2805 if (child
== m_vScrollBar
)
2807 if (child
== m_hScrollBar
)
2809 if (child
->IsTopLevel())
2811 if (!child
->IsShown())
2814 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2816 child
->GetPosition( &x
, &y
);
2817 child
->GetSize( &w
, &h
);
2818 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2819 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2820 InsetRect( &childRect
, -10 , -10) ;
2822 if ( RectInRgn( &childRect
, updatergn
) )
2824 // paint custom borders
2825 wxNcPaintEvent
eventNc( child
->GetId() );
2826 eventNc
.SetEventObject( child
);
2827 if ( !child
->HandleWindowEvent( eventNc
) )
2829 child
->MacPaintBorders(0, 0) ;
2839 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2841 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2845 if ( iter
->IsTopLevel() )
2847 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
2849 return toplevel
->MacGetWindowRef();
2851 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
2853 return popupwin
->MacGetWindowRef();
2856 iter
= iter
->GetParent() ;
2862 bool wxWindowMac::MacHasScrollBarCorner() const
2864 /* Returns whether the scroll bars in a wxScrolledWindow should be
2865 * shortened. Scroll bars should be shortened if either:
2867 * - both scroll bars are visible, or
2869 * - there is a resize box in the parent frame's corner and this
2870 * window shares the bottom and right edge with the parent
2874 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2877 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2878 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2880 // Both scroll bars visible
2885 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2887 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
2889 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2892 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2894 // Parent frame has resize handle
2895 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2897 // Note: allow for some wiggle room here as wxMac's
2898 // window rect calculations seem to be imprecise
2899 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2900 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2902 // Parent frame has resize handle and shares
2903 // right bottom corner
2908 // Parent frame has resize handle but doesn't
2909 // share right bottom corner
2915 // Parent frame doesn't have resize handle
2921 // No parent frame found
2926 void wxWindowMac::MacCreateScrollBars( long style
)
2928 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2930 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2932 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2933 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2935 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2938 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2940 GetClientSize( &width
, &height
) ;
2942 wxPoint
vPoint(width
- scrlsize
, 0) ;
2943 wxSize
vSize(scrlsize
, height
- adjust
) ;
2944 wxPoint
hPoint(0, height
- scrlsize
) ;
2945 wxSize
hSize(width
- adjust
, scrlsize
) ;
2947 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2948 if ( style
& wxVSCROLL
)
2950 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2951 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2954 if ( style
& wxHSCROLL
)
2956 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2957 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2961 // because the create does not take into account the client area origin
2962 // we might have a real position shift
2963 MacRepositionScrollBars() ;
2966 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2968 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2973 void wxWindowMac::MacRepositionScrollBars()
2975 if ( !m_hScrollBar
&& !m_vScrollBar
)
2978 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2979 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2981 // get real client area
2983 GetSize( &width
, &height
);
2985 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2986 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2988 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2989 wxSize
vSize( scrlsize
, height
- adjust
) ;
2990 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2991 wxSize
hSize( width
- adjust
, scrlsize
) ;
2994 int x
= 0, y
= 0, w
, h
;
2995 GetSize( &w
, &h
) ;
2997 MacClientToRootWindow( &x
, &y
) ;
2998 MacClientToRootWindow( &w
, &h
) ;
3000 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3002 int totW
= 10000 , totH
= 10000;
3005 if ( iter
->IsTopLevel() )
3007 iter
->GetSize( &totW
, &totH
) ;
3011 iter
= iter
->GetParent() ;
3025 if ( w
- x
>= totW
)
3030 if ( h
- y
>= totH
)
3038 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3040 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3043 bool wxWindowMac::AcceptsFocus() const
3045 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3048 void wxWindowMac::MacSuperChangedPosition()
3050 // only window-absolute structures have to be moved i.e. controls
3052 m_cachedClippedRectValid
= false ;
3055 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3058 child
= node
->GetData();
3059 child
->MacSuperChangedPosition() ;
3061 node
= node
->GetNext();
3065 void wxWindowMac::MacTopLevelWindowChangedPosition()
3067 // only screen-absolute structures have to be moved i.e. glcanvas
3070 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3073 child
= node
->GetData();
3074 child
->MacTopLevelWindowChangedPosition() ;
3076 node
= node
->GetNext();
3080 long wxWindowMac::MacGetLeftBorderSize() const
3087 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3089 // this metric is only the 'outset' outside the simple frame rect
3090 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3093 else if (HasFlag(wxSIMPLE_BORDER
))
3095 // this metric is only the 'outset' outside the simple frame rect
3096 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3103 long wxWindowMac::MacGetRightBorderSize() const
3105 // they are all symmetric in mac themes
3106 return MacGetLeftBorderSize() ;
3109 long wxWindowMac::MacGetTopBorderSize() const
3111 // they are all symmetric in mac themes
3112 return MacGetLeftBorderSize() ;
3115 long wxWindowMac::MacGetBottomBorderSize() const
3117 // they are all symmetric in mac themes
3118 return MacGetLeftBorderSize() ;
3121 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3123 return style
& ~wxBORDER_MASK
;
3126 // Find the wxWindowMac at the current mouse position, returning the mouse
3128 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3130 pt
= wxGetMousePosition();
3131 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3136 // Get the current mouse position.
3137 wxPoint
wxGetMousePosition()
3141 wxGetMousePosition( &x
, &y
);
3143 return wxPoint(x
, y
);
3146 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3148 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3150 // copied from wxGTK : CS
3151 // VZ: shouldn't we move this to base class then?
3153 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3156 // (a) it's a command event and so is propagated to the parent
3157 // (b) under MSW it can be generated from kbd too
3158 // (c) it uses screen coords (because of (a))
3159 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3161 this->ClientToScreen(event
.GetPosition()));
3162 evtCtx
.SetEventObject(this);
3163 if ( ! HandleWindowEvent(evtCtx
) )
3172 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3174 // for native controls: call their native paint method
3175 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
3177 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
3178 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
3179 CallNextEventHandler(
3180 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3181 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3185 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
3186 wxInt16
WXUNUSED(controlpart
),
3187 bool WXUNUSED(mouseStillDown
))
3191 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3195 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3196 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3201 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3203 return eventNotHandledErr
;
3206 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3208 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3209 if ( !wxWindowBase::Reparent(newParent
) )
3212 // copied from MacPostControlCreate
3213 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3215 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3217 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3222 bool wxWindowMac::SetTransparent(wxByte alpha
)
3224 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
3226 if ( alpha
!= m_macAlpha
)
3228 m_macAlpha
= alpha
;
3235 bool wxWindowMac::CanSetTransparent()
3240 wxByte
wxWindowMac::GetTransparent() const
3245 bool wxWindowMac::IsShownOnScreen() const
3247 #if TARGET_API_MAC_OSX
3248 if ( m_peer
&& m_peer
->Ok() )
3250 bool peerVis
= m_peer
->IsVisible();
3251 bool wxVis
= wxWindowBase::IsShownOnScreen();
3252 if( peerVis
!= wxVis
)
3254 // CS : put a breakpoint here to investigate differences
3255 // between native an wx visibilities
3256 // the only place where I've encountered them until now
3257 // are the hiding/showing sequences where the vis-changed event is
3258 // first sent to the innermost control, while wx does things
3259 // from the outmost control
3260 wxVis
= wxWindowBase::IsShownOnScreen();
3264 return m_peer
->IsVisible();
3268 return wxWindowBase::IsShownOnScreen();