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
;
2066 tempFont
= GetFont();
2067 fontToUse
= &tempFont
;
2070 wxClientDC
dc( (wxWindowMac
*) this ) ;
2071 wxCoord lx
,ly
,ld
,le
;
2072 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2073 if ( externalLeading
)
2074 *externalLeading
= le
;
2084 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2085 * we always intersect with the entire window, not only with the client area
2088 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
2090 if ( m_peer
== NULL
)
2093 if ( !IsShownOnScreen() )
2100 wxMacRectToNative( rect
, &r
) ;
2101 m_peer
->SetNeedsDisplay( &r
) ;
2105 m_peer
->SetNeedsDisplay() ;
2109 void wxWindowMac::DoFreeze()
2111 #if TARGET_API_MAC_OSX
2112 if ( m_peer
&& m_peer
->Ok() )
2113 m_peer
->SetDrawingEnabled( false ) ;
2117 void wxWindowMac::DoThaw()
2119 #if TARGET_API_MAC_OSX
2120 if ( m_peer
&& m_peer
->Ok() )
2122 m_peer
->SetDrawingEnabled( true ) ;
2123 m_peer
->InvalidateWithChildren() ;
2128 wxWindowMac
*wxGetActiveWindow()
2130 // actually this is a windows-only concept
2134 // Coordinates relative to the window
2135 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
2137 // We really don't move the mouse programmatically under Mac.
2140 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2142 if ( MacGetTopLevelWindow() == NULL
)
2145 #if TARGET_API_MAC_OSX
2146 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
2152 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
2154 event
.GetDC()->Clear() ;
2156 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
2158 // don't skip the event here, custom background means that the app
2159 // is drawing it itself in its OnPaint(), so don't draw it at all
2160 // now to avoid flicker
2168 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2173 int wxWindowMac::GetScrollPos(int orient
) const
2175 if ( orient
== wxHORIZONTAL
)
2178 return m_hScrollBar
->GetThumbPosition() ;
2183 return m_vScrollBar
->GetThumbPosition() ;
2189 // This now returns the whole range, not just the number
2190 // of positions that we can scroll.
2191 int wxWindowMac::GetScrollRange(int orient
) const
2193 if ( orient
== wxHORIZONTAL
)
2196 return m_hScrollBar
->GetRange() ;
2201 return m_vScrollBar
->GetRange() ;
2207 int wxWindowMac::GetScrollThumb(int orient
) const
2209 if ( orient
== wxHORIZONTAL
)
2212 return m_hScrollBar
->GetThumbSize() ;
2217 return m_vScrollBar
->GetThumbSize() ;
2223 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
2225 if ( orient
== wxHORIZONTAL
)
2228 m_hScrollBar
->SetThumbPosition( pos
) ;
2233 m_vScrollBar
->SetThumbPosition( pos
) ;
2238 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
2240 bool needVisibilityUpdate
= false;
2242 if ( m_hScrollBarAlwaysShown
!= hflag
)
2244 m_hScrollBarAlwaysShown
= hflag
;
2245 needVisibilityUpdate
= true;
2248 if ( m_vScrollBarAlwaysShown
!= vflag
)
2250 m_vScrollBarAlwaysShown
= vflag
;
2251 needVisibilityUpdate
= true;
2254 if ( needVisibilityUpdate
)
2255 DoUpdateScrollbarVisibility();
2259 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2260 // our own window origin is at leftOrigin/rightOrigin
2263 void wxWindowMac::MacPaintGrowBox()
2268 if ( MacHasScrollBarCorner() )
2272 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
2273 wxASSERT( cgContext
) ;
2275 m_peer
->GetRect( &rect
) ;
2277 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2278 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2279 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2280 CGContextSaveGState( cgContext
);
2282 if ( m_backgroundColour
.Ok() )
2284 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
2288 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
2290 CGContextFillRect( cgContext
, cgrect
);
2291 CGContextRestoreGState( cgContext
);
2295 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
2301 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2303 // back to the surrounding frame rectangle
2304 m_peer
->GetRect( &rect
) ;
2305 InsetRect( &rect
, -1 , -1 ) ;
2308 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2309 rect
.bottom
- rect
.top
) ;
2311 HIThemeFrameDrawInfo info
;
2312 memset( &info
, 0 , sizeof(info
) ) ;
2316 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2317 info
.isFocused
= hasFocus
;
2319 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2320 wxASSERT( cgContext
) ;
2322 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2324 info
.kind
= kHIThemeFrameTextFieldSquare
;
2325 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2327 else if ( HasFlag(wxSIMPLE_BORDER
) )
2329 info
.kind
= kHIThemeFrameListBox
;
2330 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2332 else if ( hasFocus
)
2334 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2336 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
2337 m_peer
->GetRect( &rect
) ;
2338 if ( MacHasScrollBarCorner() )
2340 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
2341 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2342 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2343 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2344 HIThemeGrowBoxDrawInfo info
;
2345 memset( &info
, 0, sizeof(info
) ) ;
2347 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2348 info
.kind
= kHIThemeGrowBoxKindNone
;
2349 // contrary to the docs ...SizeSmall does not work
2350 info
.size
= kHIThemeGrowBoxSizeNormal
;
2351 info
.direction
= 0 ;
2352 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2358 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2360 if ( child
== m_hScrollBar
)
2361 m_hScrollBar
= NULL
;
2362 if ( child
== m_vScrollBar
)
2363 m_vScrollBar
= NULL
;
2365 wxWindowBase::RemoveChild( child
) ;
2368 void wxWindowMac::DoUpdateScrollbarVisibility()
2370 bool triggerSizeEvent
= false;
2374 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
2376 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
2378 m_hScrollBar
->Show( showHScrollBar
);
2379 triggerSizeEvent
= true;
2385 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
2387 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
2389 m_vScrollBar
->Show( showVScrollBar
) ;
2390 triggerSizeEvent
= true;
2394 MacRepositionScrollBars() ;
2395 if ( triggerSizeEvent
)
2397 wxSizeEvent
event(GetSize(), m_windowId
);
2398 event
.SetEventObject(this);
2399 HandleWindowEvent(event
);
2403 // New function that will replace some of the above.
2404 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
2405 int range
, bool refresh
)
2407 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
2408 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
2409 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
2410 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
2412 DoUpdateScrollbarVisibility();
2415 // Does a physical scroll
2416 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2418 if ( dx
== 0 && dy
== 0 )
2421 int width
, height
;
2422 GetClientSize( &width
, &height
) ;
2425 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2426 // area is scrolled, this does not occur if width and height are 2 pixels less,
2427 // TODO: write optimal workaround
2428 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2430 scrollrect
.Intersect( *rect
) ;
2432 if ( m_peer
->GetNeedsDisplay() )
2434 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2435 // in case there is already a pending redraw on that area
2436 // either immediate redraw or full invalidate
2438 // is the better overall solution, as it does not slow down scrolling
2439 m_peer
->SetNeedsDisplay() ;
2441 // this would be the preferred version for fast drawing controls
2442 HIViewRender(m_peer
->GetControlRef()) ;
2446 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2447 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2448 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2451 // this would be the preferred version for fast drawing controls
2452 HIViewRender(m_peer
->GetControlRef()) ;
2458 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2460 child
= node
->GetData();
2463 if (child
== m_vScrollBar
)
2465 if (child
== m_hScrollBar
)
2467 if (child
->IsTopLevel())
2470 child
->GetPosition( &x
, &y
);
2471 child
->GetSize( &w
, &h
);
2474 wxRect
rc( x
, y
, w
, h
);
2475 if (rect
->Intersects( rc
))
2476 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
2480 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
2485 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2487 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2489 wxScrollWinEvent wevent
;
2490 wevent
.SetPosition(event
.GetPosition());
2491 wevent
.SetOrientation(event
.GetOrientation());
2492 wevent
.SetEventObject(this);
2494 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2495 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2496 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2497 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2498 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2499 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2500 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2501 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2502 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2503 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2504 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2505 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2506 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2507 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2508 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2509 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2511 HandleWindowEvent(wevent
);
2515 // Get the window with the focus
2516 wxWindowMac
*wxWindowBase::DoFindFocus()
2518 ControlRef control
;
2519 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2520 return wxFindControlFromMacControl( control
) ;
2523 void wxWindowMac::OnInternalIdle()
2525 // This calls the UI-update mechanism (querying windows for
2526 // menu/toolbar/control state information)
2527 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
2528 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2531 // Raise the window to the top of the Z order
2532 void wxWindowMac::Raise()
2534 m_peer
->SetZOrder( true , NULL
) ;
2537 // Lower the window to the bottom of the Z order
2538 void wxWindowMac::Lower()
2540 m_peer
->SetZOrder( false , NULL
) ;
2543 // static wxWindow *gs_lastWhich = NULL;
2545 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2547 // first trigger a set cursor event
2549 wxPoint clientorigin
= GetClientAreaOrigin() ;
2550 wxSize clientsize
= GetClientSize() ;
2552 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2554 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2556 bool processedEvtSetCursor
= HandleWindowEvent(event
);
2557 if ( processedEvtSetCursor
&& event
.HasCursor() )
2559 cursor
= event
.GetCursor() ;
2563 // the test for processedEvtSetCursor is here to prevent using m_cursor
2564 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2565 // it - this is a way to say that our cursor shouldn't be used for this
2567 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2570 if ( !wxIsBusy() && !GetParent() )
2571 cursor
= *wxSTANDARD_CURSOR
;
2575 cursor
.MacInstall() ;
2578 return cursor
.Ok() ;
2581 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
2585 return m_tooltip
->GetTip() ;
2588 return wxEmptyString
;
2591 void wxWindowMac::ClearBackground()
2597 void wxWindowMac::Update()
2599 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2601 top
->MacPerformUpdates() ;
2604 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
2606 wxNonOwnedWindow
* win
= NULL
;
2607 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2609 win
= wxFindWinFromMacWindow( window
) ;
2614 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2616 MacUpdateClippedRects() ;
2618 return m_cachedClippedClientRect
;
2621 const wxRect
& wxWindowMac::MacGetClippedRect() const
2623 MacUpdateClippedRects() ;
2625 return m_cachedClippedRect
;
2628 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2630 MacUpdateClippedRects() ;
2632 return m_cachedClippedRectWithOuterStructure
;
2635 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2637 static wxRegion emptyrgn
;
2639 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
2641 MacUpdateClippedRects() ;
2642 if ( includeOuterStructures
)
2643 return m_cachedClippedRegionWithOuterStructure
;
2645 return m_cachedClippedRegion
;
2653 void wxWindowMac::MacUpdateClippedRects() const
2655 if ( m_cachedClippedRectValid
)
2658 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2659 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2660 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2661 // to add focus borders everywhere
2663 Rect r
, rIncludingOuterStructures
;
2665 m_peer
->GetRect( &r
) ;
2666 r
.left
-= MacGetLeftBorderSize() ;
2667 r
.top
-= MacGetTopBorderSize() ;
2668 r
.bottom
+= MacGetBottomBorderSize() ;
2669 r
.right
+= MacGetRightBorderSize() ;
2676 rIncludingOuterStructures
= r
;
2677 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2679 wxRect cl
= GetClientRect() ;
2680 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2684 const wxWindow
* child
= this ;
2685 const wxWindow
* parent
= NULL
;
2687 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2689 if ( parent
->MacIsChildOfClientArea(child
) )
2691 size
= parent
->GetClientSize() ;
2692 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2698 // this will be true for scrollbars, toolbars etc.
2699 size
= parent
->GetSize() ;
2700 y
= parent
->MacGetTopBorderSize() ;
2701 x
= parent
->MacGetLeftBorderSize() ;
2702 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2703 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2706 parent
->MacWindowToRootWindow( &x
, &y
) ;
2707 MacRootWindowToWindow( &x
, &y
) ;
2709 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2711 // the wxwindow and client rects will always be clipped
2712 SectRect( &r
, &rparent
, &r
) ;
2713 SectRect( &rClient
, &rparent
, &rClient
) ;
2715 // the structure only at 'hard' borders
2716 if ( parent
->MacClipChildren() ||
2717 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2719 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2725 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2726 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2727 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2728 m_cachedClippedRectWithOuterStructure
= wxRect(
2729 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2730 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2731 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2733 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2734 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2735 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2737 m_cachedClippedRectValid
= true ;
2741 This function must not change the updatergn !
2743 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
2745 bool handled
= false ;
2747 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2748 GetRegionBounds( updatergn
, &updatebounds
) ;
2750 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2752 if ( !EmptyRgn(updatergn
) )
2754 RgnHandle newupdate
= NewRgn() ;
2755 wxSize point
= GetClientSize() ;
2756 wxPoint origin
= GetClientAreaOrigin() ;
2757 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2758 SectRgn( newupdate
, updatergn
, newupdate
) ;
2760 // first send an erase event to the entire update area
2762 // for the toplevel window this really is the entire area
2763 // for all the others only their client area, otherwise they
2764 // might be drawing with full alpha and eg put blue into
2765 // the grow-box area of a scrolled window (scroll sample)
2766 wxDC
* dc
= new wxWindowDC(this);
2768 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
2770 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
2772 wxEraseEvent
eevent( GetId(), dc
);
2773 eevent
.SetEventObject( this );
2774 HandleWindowEvent( eevent
);
2780 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2781 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2782 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
2783 DisposeRgn( newupdate
) ;
2785 if ( !m_updateRegion
.Empty() )
2787 // paint the window itself
2790 event
.SetTimestamp(time
);
2791 event
.SetEventObject(this);
2792 HandleWindowEvent(event
);
2796 // now we cannot rely on having its borders drawn by a window itself, as it does not
2797 // get the updateRgn wide enough to always do so, so we do it from the parent
2798 // this would also be the place to draw any custom backgrounds for native controls
2799 // in Composited windowing
2800 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2804 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2806 child
= node
->GetData();
2809 if (child
== m_vScrollBar
)
2811 if (child
== m_hScrollBar
)
2813 if (child
->IsTopLevel())
2815 if (!child
->IsShown())
2818 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2820 child
->GetPosition( &x
, &y
);
2821 child
->GetSize( &w
, &h
);
2822 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2823 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2824 InsetRect( &childRect
, -10 , -10) ;
2826 if ( RectInRgn( &childRect
, updatergn
) )
2828 // paint custom borders
2829 wxNcPaintEvent
eventNc( child
->GetId() );
2830 eventNc
.SetEventObject( child
);
2831 if ( !child
->HandleWindowEvent( eventNc
) )
2833 child
->MacPaintBorders(0, 0) ;
2843 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2845 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2849 if ( iter
->IsTopLevel() )
2851 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
2853 return toplevel
->MacGetWindowRef();
2855 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
2857 return popupwin
->MacGetWindowRef();
2860 iter
= iter
->GetParent() ;
2866 bool wxWindowMac::MacHasScrollBarCorner() const
2868 /* Returns whether the scroll bars in a wxScrolledWindow should be
2869 * shortened. Scroll bars should be shortened if either:
2871 * - both scroll bars are visible, or
2873 * - there is a resize box in the parent frame's corner and this
2874 * window shares the bottom and right edge with the parent
2878 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2881 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2882 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2884 // Both scroll bars visible
2889 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2891 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
2893 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2896 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2898 // Parent frame has resize handle
2899 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2901 // Note: allow for some wiggle room here as wxMac's
2902 // window rect calculations seem to be imprecise
2903 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2904 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2906 // Parent frame has resize handle and shares
2907 // right bottom corner
2912 // Parent frame has resize handle but doesn't
2913 // share right bottom corner
2919 // Parent frame doesn't have resize handle
2925 // No parent frame found
2930 void wxWindowMac::MacCreateScrollBars( long style
)
2932 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2934 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2936 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2937 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2939 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2942 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2944 GetClientSize( &width
, &height
) ;
2946 wxPoint
vPoint(width
- scrlsize
, 0) ;
2947 wxSize
vSize(scrlsize
, height
- adjust
) ;
2948 wxPoint
hPoint(0, height
- scrlsize
) ;
2949 wxSize
hSize(width
- adjust
, scrlsize
) ;
2951 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2952 if ( style
& wxVSCROLL
)
2954 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2955 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2958 if ( style
& wxHSCROLL
)
2960 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2961 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2965 // because the create does not take into account the client area origin
2966 // we might have a real position shift
2967 MacRepositionScrollBars() ;
2970 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2972 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2977 void wxWindowMac::MacRepositionScrollBars()
2979 if ( !m_hScrollBar
&& !m_vScrollBar
)
2982 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2983 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2985 // get real client area
2987 GetSize( &width
, &height
);
2989 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2990 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2992 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2993 wxSize
vSize( scrlsize
, height
- adjust
) ;
2994 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2995 wxSize
hSize( width
- adjust
, scrlsize
) ;
2998 int x
= 0, y
= 0, w
, h
;
2999 GetSize( &w
, &h
) ;
3001 MacClientToRootWindow( &x
, &y
) ;
3002 MacClientToRootWindow( &w
, &h
) ;
3004 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3006 int totW
= 10000 , totH
= 10000;
3009 if ( iter
->IsTopLevel() )
3011 iter
->GetSize( &totW
, &totH
) ;
3015 iter
= iter
->GetParent() ;
3029 if ( w
- x
>= totW
)
3034 if ( h
- y
>= totH
)
3042 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3044 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3047 bool wxWindowMac::AcceptsFocus() const
3049 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3052 void wxWindowMac::MacSuperChangedPosition()
3054 // only window-absolute structures have to be moved i.e. controls
3056 m_cachedClippedRectValid
= false ;
3059 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3062 child
= node
->GetData();
3063 child
->MacSuperChangedPosition() ;
3065 node
= node
->GetNext();
3069 void wxWindowMac::MacTopLevelWindowChangedPosition()
3071 // only screen-absolute structures have to be moved i.e. glcanvas
3074 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3077 child
= node
->GetData();
3078 child
->MacTopLevelWindowChangedPosition() ;
3080 node
= node
->GetNext();
3084 long wxWindowMac::MacGetLeftBorderSize() const
3091 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3093 // this metric is only the 'outset' outside the simple frame rect
3094 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3097 else if (HasFlag(wxSIMPLE_BORDER
))
3099 // this metric is only the 'outset' outside the simple frame rect
3100 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3107 long wxWindowMac::MacGetRightBorderSize() const
3109 // they are all symmetric in mac themes
3110 return MacGetLeftBorderSize() ;
3113 long wxWindowMac::MacGetTopBorderSize() const
3115 // they are all symmetric in mac themes
3116 return MacGetLeftBorderSize() ;
3119 long wxWindowMac::MacGetBottomBorderSize() const
3121 // they are all symmetric in mac themes
3122 return MacGetLeftBorderSize() ;
3125 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3127 return style
& ~wxBORDER_MASK
;
3130 // Find the wxWindowMac at the current mouse position, returning the mouse
3132 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3134 pt
= wxGetMousePosition();
3135 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3140 // Get the current mouse position.
3141 wxPoint
wxGetMousePosition()
3145 wxGetMousePosition( &x
, &y
);
3147 return wxPoint(x
, y
);
3150 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3152 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3154 // copied from wxGTK : CS
3155 // VZ: shouldn't we move this to base class then?
3157 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3160 // (a) it's a command event and so is propagated to the parent
3161 // (b) under MSW it can be generated from kbd too
3162 // (c) it uses screen coords (because of (a))
3163 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3165 this->ClientToScreen(event
.GetPosition()));
3166 evtCtx
.SetEventObject(this);
3167 if ( ! HandleWindowEvent(evtCtx
) )
3176 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3178 // for native controls: call their native paint method
3179 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
3181 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
3182 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
3183 CallNextEventHandler(
3184 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3185 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3189 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
3190 wxInt16
WXUNUSED(controlpart
),
3191 bool WXUNUSED(mouseStillDown
))
3195 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3199 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3200 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3205 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3207 return eventNotHandledErr
;
3210 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3212 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3213 if ( !wxWindowBase::Reparent(newParent
) )
3216 // copied from MacPostControlCreate
3217 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3219 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3221 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3226 bool wxWindowMac::SetTransparent(wxByte alpha
)
3228 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
3230 if ( alpha
!= m_macAlpha
)
3232 m_macAlpha
= alpha
;
3239 bool wxWindowMac::CanSetTransparent()
3244 wxByte
wxWindowMac::GetTransparent() const
3249 bool wxWindowMac::IsShownOnScreen() const
3251 #if TARGET_API_MAC_OSX
3252 if ( m_peer
&& m_peer
->Ok() )
3254 bool peerVis
= m_peer
->IsVisible();
3255 bool wxVis
= wxWindowBase::IsShownOnScreen();
3256 if( peerVis
!= wxVis
)
3258 // CS : put a breakpoint here to investigate differences
3259 // between native an wx visibilities
3260 // the only place where I've encountered them until now
3261 // are the hiding/showing sequences where the vis-changed event is
3262 // first sent to the innermost control, while wx does things
3263 // from the outmost control
3264 wxVis
= wxWindowBase::IsShownOnScreen();
3268 return m_peer
->IsVisible();
3272 return wxWindowBase::IsShownOnScreen();