#define MAC_SCROLLBAR_SIZE 15
#define MAC_SMALL_SCROLLBAR_SIZE 11
-#ifndef __DARWIN__
-#include <Windows.h>
-#include <ToolUtils.h>
-#include <MacTextEditor.h>
-#endif
-
-#if TARGET_API_MAC_OSX
-#ifndef __HIVIEW__
- #include <HIToolbox/HIView.h>
-#endif
-#endif
-
#include <string.h>
#ifdef __WXUNIVERSAL__
BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
EVT_NC_PAINT(wxWindowMac::OnNcPaint)
EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
-#if TARGET_API_MAC_OSX
EVT_PAINT(wxWindowMac::OnPaint)
-#endif
- EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
- EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
END_EVENT_TABLE()
{ kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
{ kEventClassControl , kEventControlDraw } ,
-#if TARGET_API_MAC_OSX
+
{ kEventClassControl , kEventControlVisibilityChanged } ,
{ kEventClassControl , kEventControlEnabledStateChanged } ,
{ kEventClassControl , kEventControlHiliteChanged } ,
{ kEventClassControl , kEventControlActivate } ,
{ kEventClassControl , kEventControlDeactivate } ,
-#endif
+
{ kEventClassControl , kEventControlSetFocusPart } ,
+ { kEventClassControl , kEventControlFocusPartChanged } ,
{ kEventClassService , kEventServiceGetTypes },
{ kEventClassService , kEventServiceCopy },
switch ( GetEventKind( event ) )
{
-#if TARGET_API_MAC_OSX
case kEventControlDraw :
{
RgnHandle updateRgn = NULL ;
if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
{
- updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
+ HIShapeGetAsQDRgn( visRegion.GetWXHRGN(), updateRgn );
}
else
{
}
}
- Rect rgnBounds ;
- GetRegionBounds( updateRgn , &rgnBounds ) ;
-
#if wxMAC_DEBUG_REDRAW
if ( thisWindow->MacIsUserPane() )
{
#endif
{
-#if wxMAC_USE_CORE_GRAPHICS
bool created = false ;
CGContextRef cgContext = NULL ;
OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
- wxASSERT_MSG( err == noErr , wxT("Unable to retrieve CGContextRef") ) ;
+ if ( err != noErr )
+ {
+ wxFAIL_MSG("Unable to retrieve CGContextRef");
+ }
+
thisWindow->MacSetCGContextRef( cgContext ) ;
{
wxMacCGContextStateSaver sg( cgContext ) ;
- float alpha = 1.0 ;
+ CGFloat alpha = (CGFloat)1.0 ;
{
wxWindow* iter = thisWindow ;
while ( iter )
{
- alpha *= (float) iter->GetTransparent()/255.0 ;
+ alpha *= (CGFloat)( iter->GetTransparent()/255.0 ) ;
if ( iter->IsTopLevel() )
iter = NULL ;
else
}
-#endif
+
if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
result = noErr ;
-#if wxMAC_USE_CORE_GRAPHICS
thisWindow->MacSetCGContextRef( NULL ) ;
}
if ( created )
CGContextRelease( cgContext ) ;
-#endif
}
if ( allocatedRgn )
break ;
case kEventControlVisibilityChanged :
- thisWindow->MacVisibilityChanged() ;
+ // we might have two native controls attributed to the same wxWindow instance
+ // eg a scrollview and an embedded textview, make sure we only fire for the 'outer'
+ // control, as otherwise native and wx visibility are different
+ if ( thisWindow->GetPeer() != NULL && thisWindow->GetPeer()->GetControlRef() == controlRef )
+ {
+ thisWindow->MacVisibilityChanged() ;
+ }
break ;
case kEventControlEnabledStateChanged :
- thisWindow->MacEnabledStateChanged() ;
+ thisWindow->MacEnabledStateChanged();
break ;
case kEventControlHiliteChanged :
thisWindow->Refresh();
#endif
break ;
-#endif // TARGET_API_MAC_OSX
- // we emulate this event under Carbon CFM
- case kEventControlSetFocusPart :
+ //
+ // focus handling
+ // different handling on OS X
+ //
+
+ case kEventControlFocusPartChanged :
+ // the event is emulated by wxmac for systems lower than 10.5
{
- Boolean focusEverything = false ;
- ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+ ControlPartCode previousControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPreviousPart , typeControlPartCode );
+ ControlPartCode currentControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlCurrentPart , typeControlPartCode );
- if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
+ if ( thisWindow->MacGetTopLevelWindow() && thisWindow->GetPeer()->NeedsFocusRect() )
{
+ thisWindow->MacInvalidateBorders();
}
- if ( thisWindow->MacIsUserPane() )
- result = noErr ;
-
- if ( controlPart == kControlFocusNoPart )
+ if ( currentControlPart == 0 )
{
+ // kill focus
#if wxUSE_CARET
if ( thisWindow->GetCaret() )
thisWindow->GetCaret()->OnKillFocus();
#endif
+ wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
+
+ // remove this as soon as posting the synthesized event works properly
static bool inKillFocusEvent = false ;
if ( !inKillFocusEvent )
inKillFocusEvent = true ;
wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
event.SetEventObject(thisWindow);
- thisWindow->GetEventHandler()->ProcessEvent(event) ;
+ thisWindow->HandleWindowEvent(event) ;
inKillFocusEvent = false ;
}
}
- else
+ else if ( previousControlPart == 0 )
{
+ // set focus
// panel wants to track the window which was the last to have focus in it
- wxChildFocusEvent eventFocus(thisWindow);
- thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
+ wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
+ wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+ thisWindow->HandleWindowEvent(eventFocus);
#if wxUSE_CARET
if ( thisWindow->GetCaret() )
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
event.SetEventObject(thisWindow);
- thisWindow->GetEventHandler()->ProcessEvent(event) ;
+ thisWindow->HandleWindowEvent(event) ;
+ }
+ }
+ break;
+ case kEventControlSetFocusPart :
+ {
+#ifdef __WXMAC_OSX__
+ Boolean focusEverything = false ;
+ if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
+ {
+ // put a breakpoint here to catch focus everything events
+ }
+#endif
+ ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+
+ ControlPartCode previousControlPart = 0;
+ verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart));
+
+ if ( thisWindow->MacIsUserPane() )
+ {
+ if ( controlPart != kControlFocusNoPart )
+ cEvent.SetParameter<ControlPartCode>( kEventParamControlPart, typeControlPartCode, 1 ) ;
+ result = noErr ;
+ }
+ else
+ result = CallNextEventHandler(handler, event);
+
+ if ( UMAGetSystemVersion() < 0x1050 )
+ {
+// set back to 0 if problems arise
+#if 1
+ ControlPartCode currentControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+ // synthesize the event focus changed event
+ EventRef evRef = NULL ;
+
+ OSStatus err = MacCreateEvent(
+ NULL , kEventClassControl , kEventControlFocusPartChanged , TicksToEventTime( TickCount() ) ,
+ kEventAttributeUserEvent , &evRef );
+ verify_noerr( err );
+
+ wxMacCarbonEvent iEvent( evRef ) ;
+ iEvent.SetParameter<ControlRef>( kEventParamDirectObject , controlRef ) ;
+ iEvent.SetParameter<ControlPartCode>( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ) ;
+ iEvent.SetParameter<ControlPartCode>( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ) ;
+
+#if 0
+ // TODO test this first, avoid double posts etc...
+ PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh );
+#else
+ wxMacWindowControlEventHandler( NULL , evRef , data ) ;
+#endif
+ ReleaseEvent( evRef ) ;
+#else
+ // old implementation, to be removed if the new one works
+ if ( controlPart == kControlFocusNoPart )
+ {
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnKillFocus();
+#endif
+
+ wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
+
+ static bool inKillFocusEvent = false ;
+
+ if ( !inKillFocusEvent )
+ {
+ inKillFocusEvent = true ;
+ wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ inKillFocusEvent = false ;
+ }
+ }
+ else
+ {
+ // panel wants to track the window which was the last to have focus in it
+ wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
+ wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+ thisWindow->HandleWindowEvent(eventFocus);
+
+ #if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnSetFocus();
+ #endif
+
+ wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+#endif
}
}
break ;
case kEventControlGetClickActivation :
{
- // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
+ // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
WindowRef owner = cEvent.GetParameter<WindowRef>(kEventParamWindowRef);
if ( !IsWindowActive(owner) )
{
charBuf[ numChars - 1 ] = 0;
#if SIZEOF_WCHAR_T == 2
uniChars = (wchar_t*) charBuf ;
-/* 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...)
+/* 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...)
#else
// the resulting string will never have more chars than the utf16 version, so this is safe
wxMBConvUTF16 converter ;
UInt32 message = uniChars[pos] < 128 ? (char)uniChars[pos] : '?';
/*
- NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent
- multiple times to update the active range during inline input, so this handler will often receive
- uncommited text, which should usually not trigger side effects. It might be a good idea to check the
- kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h).
- On the other hand, it can be useful for some applications to react to uncommitted text (for example,
- to update a status display), as long as it does not disrupt the inline input session. Ideally, wx
- should add new event types to support advanced text input. For now, I would keep things as they are.
-
- However, the code that was being used caused additional problems:
+ NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent
+ multiple times to update the active range during inline input, so this handler will often receive
+ uncommited text, which should usually not trigger side effects. It might be a good idea to check the
+ kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h).
+ On the other hand, it can be useful for some applications to react to uncommitted text (for example,
+ to update a status display), as long as it does not disrupt the inline input session. Ideally, wx
+ should add new event types to support advanced text input. For now, I would keep things as they are.
+
+ However, the code that was being used caused additional problems:
UInt32 message = (0 << 8) + ((char)uniChars[pos] );
- Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline
- input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji
- for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB
- (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D
- (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress.
- Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only
- overlap with Unicode within the (7-bit) ASCII range.
- But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks
- for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII
- characters as they are and replaces the rest with '?', ensuring that update events are triggered.
- It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but
- I don't have time to look into that right now.
- -- CL
+ Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline
+ input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji
+ for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB
+ (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D
+ (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress.
+ Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only
+ overlap with Unicode within the (7-bit) ASCII range.
+ But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks
+ for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII
+ characters as they are and replaces the rest with '?', ensuring that update events are triggered.
+ It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but
+ I don't have time to look into that right now.
+ -- CL
*/
if ( wxTheApp->MacSendCharEvent(
focus , message , 0 , when , 0 , 0 , uniChars[pos] ) )
DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
-#if !TARGET_API_MAC_OSX
-
-// ---------------------------------------------------------------------------
-// UserPane events for non OSX builds
-// ---------------------------------------------------------------------------
-
-static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- win->MacControlUserPaneDrawProc(part) ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ;
-
-static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
- else
- return kControlNoPart ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ;
-
-static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
- else
- return kControlNoPart ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ;
-
-static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- win->MacControlUserPaneIdleProc() ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ;
-
-static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
- else
- return kControlNoPart ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ;
-
-static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- win->MacControlUserPaneActivateProc(activating) ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ;
-
-static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- return win->MacControlUserPaneFocusProc(action) ;
- else
- return kControlNoPart ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ;
-
-static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
-{
- wxWindow * win = wxFindControlFromMacControl(control) ;
- if ( win )
- win->MacControlUserPaneBackgroundProc(info) ;
-}
-wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ;
-
-void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
-{
- int x = 0 , y = 0;
- RgnHandle rgn = NewRgn() ;
- GetClip( rgn ) ;
- MacWindowToRootWindow( &x, &y ) ;
- OffsetRgn( rgn , -x , -y ) ;
- wxMacWindowStateSaver sv( this ) ;
- SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ;
- MacDoRedraw( rgn , 0 ) ;
- DisposeRgn( rgn ) ;
-}
-
-wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
-{
- return kControlNoPart ;
-}
-
-wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
-{
- return kControlNoPart ;
-}
-
-void wxWindowMac::MacControlUserPaneIdleProc()
-{
-}
-
-wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
-{
- return kControlNoPart ;
-}
-
-void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
-{
-}
-
-wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
-{
- if ( AcceptsFocus() )
- return 1 ;
- else
- return kControlNoPart ;
-}
-
-void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
-{
-}
-
-#endif
-
// ---------------------------------------------------------------------------
// Scrollbar Tracking for all
// ---------------------------------------------------------------------------
void wxWindowMac::Init()
{
m_peer = NULL ;
- m_frozenness = 0 ;
m_macAlpha = 255 ;
-
-#if wxMAC_USE_CORE_GRAPHICS
m_cgContextRef = NULL ;
-#endif
// as all windows are created with WS_VISIBLE style...
m_isShown = true;
m_hScrollBarAlwaysShown = false;
m_vScrollBarAlwaysShown = false;
- m_macBackgroundBrush = wxNullBrush ;
-
m_macIsUserPane = true;
m_clipChildren = false ;
m_cachedClippedRectValid = false ;
-
- // we need a valid font for the encodings
- wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
wxWindowMac::~wxWindowMac()
InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&m_macControlEventHandler);
-
-#if !TARGET_API_MAC_OSX
- if ( (ControlRef) control == m_peer->GetControlRef() )
- {
- m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ;
- m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ;
- m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ;
- m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ;
- m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ;
- m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ;
- m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ;
- m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ;
- }
-#endif
}
// Constructor
m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
wxFont font ;
- font.MacCreateThemeFont( themeFont ) ;
+ font.MacCreateFromThemeFont( themeFont ) ;
SetFont( font ) ;
}
{
m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
// do not trigger refreshes upon invisible and possible partly created objects
- if ( MacIsReallyShown() )
+ if ( IsShownOnScreen() )
Refresh() ;
}
if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
return false ;
- wxBrush brush ;
- wxColour newCol(GetBackgroundColour());
-
- if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) )
- brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
- else if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
- brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
- else
- brush.SetColour( newCol ) ;
-
- MacSetBackgroundBrush( brush ) ;
- MacUpdateControlFont() ;
+ m_peer->SetBackgroundColour( col ) ;
return true ;
}
-void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
-{
- m_macBackgroundBrush = brush ;
- m_peer->SetBackground( brush ) ;
-}
-
bool wxWindowMac::MacCanFocus() const
{
// TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
return ;
SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() );
-
-#if !TARGET_API_MAC_OSX
- // emulate carbon events when running under CarbonLib where they are not natively available
- if ( former )
- {
- EventRef evRef = NULL ;
-
- err = MacCreateEvent(
- NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
- kEventAttributeUserEvent , &evRef );
- verify_noerr( err );
-
- wxMacCarbonEvent cEvent( evRef ) ;
- cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
- cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
-
- wxMacWindowEventHandler( NULL , evRef , former ) ;
- ReleaseEvent( evRef ) ;
- }
-
- // send new focus event
- {
- EventRef evRef = NULL ;
-
- err = MacCreateEvent(
- NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
- kEventAttributeUserEvent , &evRef );
- verify_noerr( err );
-
- wxMacCarbonEvent cEvent( evRef ) ;
- cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
- cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
-
- wxMacWindowEventHandler( NULL , evRef , this ) ;
- ReleaseEvent( evRef ) ;
- }
-#endif
}
void wxWindowMac::DoCaptureMouse()
pt.h = hiPoint.x;
pt.v = hiPoint.y;
#else
- CGrafPtr savePort ;
- Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
-
- // TODO: If we ever get a GetCurrentEvent... replacement
- // for the mouse position, use it...
-
-
- GetMouse( &pt ) ;
+ GetGlobalMouse( &pt );
+ int x = pt.h;
+ int y = pt.v;
+ ScreenToClient(&x, &y);
+ pt.h = x;
+ pt.v = y;
#endif
control = FindControlUnderMouse( pt , window , &part ) ;
if ( control )
mouseWin = wxFindControlFromMacControl( control ) ;
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
- if ( swapped )
- QDSwapPort( savePort , NULL ) ;
-#endif
}
if ( mouseWin == this && !wxIsBusy() )
if ( m_peer == NULL )
return ;
- bool vis = MacIsReallyShown() ;
+ bool vis = IsShownOnScreen() ;
if ( !vis )
return ;
int outerBorder = MacGetLeftBorderSize() ;
- if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
+ if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ )
outerBorder += 4 ;
if ( outerBorder == 0 )
wxPoint point(actualX, actualY);
wxMoveEvent event(point, m_windowId);
event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event) ;
+ HandleWindowEvent(event) ;
}
if ( doResize )
wxSize size(actualWidth, actualHeight);
wxSizeEvent event(size, m_windowId);
event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event);
+ HandleWindowEvent(event);
}
}
}
m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ;
// do not trigger refreshes upon invisible and possible partly created objects
- if ( MacIsReallyShown() )
+ if ( IsShownOnScreen() )
Refresh() ;
}
bool wxWindowMac::Show(bool show)
{
- bool former = MacIsReallyShown() ;
if ( !wxWindowBase::Show(show) )
return false;
- // TODO: use visibilityChanged Carbon Event for OSX
if ( m_peer )
m_peer->SetVisibility( show , true ) ;
- if ( former != MacIsReallyShown() )
- MacPropagateVisibilityChanged() ;
-
return true;
}
m_peer->Enable( enable ) ;
}
-//
-// status change propagations (will be not necessary for OSX later )
-//
-
-void wxWindowMac::MacPropagateVisibilityChanged()
-{
-#if !TARGET_API_MAC_OSX
- MacVisibilityChanged() ;
-
- wxWindowMac *child;
- wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
- while ( node )
- {
- child = node->GetData();
- if ( child->IsShown() )
- child->MacPropagateVisibilityChanged() ;
-
- node = node->GetNext();
- }
-#endif
-}
-
-void wxWindowMac::OnEnabled(bool WXUNUSED(enabled))
-{
-#if !TARGET_API_MAC_OSX
- MacEnabledStateChanged() ;
-#endif
-}
-
-void wxWindowMac::MacPropagateHiliteChanged()
-{
-#if !TARGET_API_MAC_OSX
- MacHiliteChanged() ;
-
- wxWindowMac *child;
- wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
- while ( node )
- {
- child = node->GetData();
- if (child /* && child->IsEnabled() */)
- child->MacPropagateHiliteChanged() ;
-
- node = node->GetNext();
- }
-#endif
-}
-
//
// status change notifications
//
void wxWindowMac::MacEnabledStateChanged()
{
+ OnEnabled( m_peer->IsEnabled() );
}
//
// status queries on the inherited window's state
//
-bool wxWindowMac::MacIsReallyShown()
-{
- // only under OSX the visibility of the TLW is taken into account
- if ( m_isBeingDeleted )
- return false ;
-
-#if TARGET_API_MAC_OSX
- if ( m_peer && m_peer->Ok() )
- return m_peer->IsVisible();
-#endif
-
- wxWindow* win = this ;
- while ( win->IsShown() )
- {
- if ( win->IsTopLevel() )
- return true ;
-
- win = win->GetParent() ;
- if ( win == NULL )
- return true ;
- }
-
- return false ;
-}
-
bool wxWindowMac::MacIsReallyEnabled()
{
return m_peer->IsEnabled() ;
if ( m_peer == NULL )
return ;
- if ( !MacIsReallyShown() )
+ if ( !IsShownOnScreen() )
return ;
if ( rect )
}
}
-void wxWindowMac::Freeze()
+void wxWindowMac::DoFreeze()
{
#if TARGET_API_MAC_OSX
- if ( !m_frozenness++ )
- {
- if ( m_peer && m_peer->Ok() )
- m_peer->SetDrawingEnabled( false ) ;
- }
+ if ( m_peer && m_peer->Ok() )
+ m_peer->SetDrawingEnabled( false ) ;
#endif
}
-void wxWindowMac::Thaw()
+void wxWindowMac::DoThaw()
{
#if TARGET_API_MAC_OSX
- wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") );
-
- if ( !--m_frozenness )
+ if ( m_peer && m_peer->Ok() )
{
- if ( m_peer && m_peer->Ok() )
- {
- m_peer->SetDrawingEnabled( true ) ;
- m_peer->InvalidateWithChildren() ;
- }
+ m_peer->SetDrawingEnabled( true ) ;
+ m_peer->InvalidateWithChildren() ;
}
#endif
}
-bool wxWindowMac::IsFrozen() const
-{
- return m_frozenness != 0;
-}
-
wxWindowMac *wxGetActiveWindow()
{
// actually this is a windows-only concept
{
if ( MacGetTopLevelWindow() == NULL )
return ;
-
+/*
#if TARGET_API_MAC_OSX
- if ( !m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT
- || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
+ if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
{
- event.Skip() ;
}
else
#endif
+*/
+ if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR )
{
event.GetDC()->Clear() ;
}
+ else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM )
+ {
+ // don't skip the event here, custom background means that the app
+ // is drawing it itself in its OnPaint(), so don't draw it at all
+ // now to avoid flicker
+ }
+ else
+ {
+ event.Skip() ;
+ }
}
void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
if ( IsTopLevel() )
return ;
-#if wxMAC_USE_CORE_GRAPHICS
if ( MacHasScrollBarCorner() )
{
Rect rect ;
CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
wxASSERT( cgContext ) ;
-
+
m_peer->GetRect( &rect ) ;
int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
CGContextSaveGState( cgContext );
-
- if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT )
+
+ if ( m_backgroundColour.Ok() )
{
- wxMacCoreGraphicsColour bkgnd( m_macBackgroundBrush ) ;
- bkgnd.Apply( cgContext );
+ CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() );
}
else
{
- CGContextSetRGBFillColor( cgContext, 1.0, 1.0 , 1.0 , 1.0 );
+ CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 );
}
CGContextFillRect( cgContext, cgrect );
CGContextRestoreGState( cgContext );
}
-#endif
}
void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
m_peer->GetRect( &rect ) ;
InsetRect( &rect, -1 , -1 ) ;
-#if wxMAC_USE_CORE_GRAPHICS
{
CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
rect.bottom - rect.top ) ;
}
#endif
}
- #else
- {
- wxTopLevelWindowMac* top = MacGetTopLevelWindow();
- if ( top )
- {
- wxPoint pt(0, 0) ;
- wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
- OffsetRect( &rect , pt.x , pt.y ) ;
- }
-
- if ( HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
- DrawThemeEditTextFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
- else if ( HasFlag(wxSIMPLE_BORDER) )
- DrawThemeListBoxFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
-
- if ( hasFocus )
- DrawThemeFocusRect( &rect , true ) ;
- // TODO REMOVE
- /*
- if ( hasBothScrollbars ) // hasBothScrollbars is not declared
- {
- // GetThemeStandaloneGrowBoxBounds
- // DrawThemeStandaloneNoGrowBox
- }
- */
- }
-#endif
}
void wxWindowMac::RemoveChild( wxWindowBase *child )
{
wxSizeEvent event(GetSize(), m_windowId);
event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event);
+ HandleWindowEvent(event);
}
}
else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
- GetEventHandler()->ProcessEvent(wevent);
+ HandleWindowEvent(wevent);
}
}
return wxFindControlFromMacControl( control ) ;
}
-void wxWindowMac::OnSetFocus( wxFocusEvent& event )
-{
- // panel wants to track the window which was the last to have focus in it,
- // so we want to set ourselves as the window which last had focus
- //
- // notice that it's also important to do it upwards the tree because
- // otherwise when the top level panel gets focus, it won't set it back to
- // us, but to some other sibling
-
- // CS: don't know if this is still needed:
- //wxChildFocusEvent eventFocus(this);
- //(void)GetEventHandler()->ProcessEvent(eventFocus);
-
- if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
- {
-#if wxMAC_USE_CORE_GRAPHICS
- GetParent()->Refresh() ;
-#else
- wxMacWindowStateSaver sv( this ) ;
- Rect rect ;
-
- m_peer->GetRect( &rect ) ;
- // auf den umgebenden Rahmen zurチᅡ゚ck
- InsetRect( &rect, -1 , -1 ) ;
-
- wxTopLevelWindowMac* top = MacGetTopLevelWindow();
- if ( top )
- {
- wxPoint pt(0, 0) ;
- wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
- rect.left += pt.x ;
- rect.right += pt.x ;
- rect.top += pt.y ;
- rect.bottom += pt.y ;
- }
-
- bool bIsFocusEvent = (event.GetEventType() == wxEVT_SET_FOCUS);
- DrawThemeFocusRect( &rect , bIsFocusEvent ) ;
- if ( !bIsFocusEvent )
- {
- // as this erases part of the frame we have to redraw borders
- // and because our z-ordering is not always correct (staticboxes)
- // we have to invalidate things, we cannot simple redraw
- MacInvalidateBorders() ;
- }
-#endif
- }
-
- event.Skip();
-}
-
void wxWindowMac::OnInternalIdle()
{
// This calls the UI-update mechanism (querying windows for
// menu/toolbar/control state information)
- if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
+ if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
}
{
wxSetCursorEvent event( pt.x , pt.y );
- bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
+ bool processedEvtSetCursor = HandleWindowEvent(event);
if ( processedEvtSetCursor && event.HasCursor() )
{
cursor = event.GetCursor() ;
void wxWindowMac::Update()
{
-#if TARGET_API_MAC_OSX
wxTopLevelWindowMac* top = MacGetTopLevelWindow();
if (top)
top->MacPerformUpdates() ;
-#else
- ::Draw1Control( m_peer->GetControlRef() ) ;
-#endif
}
wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
{
static wxRegion emptyrgn ;
- if ( !m_isBeingDeleted && MacIsReallyShown() /*m_peer->IsVisible() */ )
+ if ( !m_isBeingDeleted && IsShownOnScreen() )
{
MacUpdateClippedRects() ;
if ( includeOuterStructures )
/*
This function must not change the updatergn !
*/
-bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
+bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
{
bool handled = false ;
Rect updatebounds ;
// the grow-box area of a scrolled window (scroll sample)
wxDC* dc = new wxWindowDC(this);
if ( IsTopLevel() )
- dc->SetClippingRegion(wxRegion(updatergn));
+ dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn)));
else
- dc->SetClippingRegion(wxRegion(newupdate));
+ dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate)));
wxEraseEvent eevent( GetId(), dc );
eevent.SetEventObject( this );
- GetEventHandler()->ProcessEvent( eevent );
+ HandleWindowEvent( eevent );
delete dc ;
}
// calculate a client-origin version of the update rgn and set m_updateRegion to that
OffsetRgn( newupdate , -origin.x , -origin.y ) ;
- m_updateRegion = newupdate ;
+ m_updateRegion = wxRegion(HIShapeCreateWithQDRgn(newupdate)) ;
DisposeRgn( newupdate ) ;
if ( !m_updateRegion.Empty() )
wxPaintEvent event;
event.SetTimestamp(time);
event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event);
+ HandleWindowEvent(event);
handled = true ;
}
// paint custom borders
wxNcPaintEvent eventNc( child->GetId() );
eventNc.SetEventObject( child );
- if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
+ if ( !child->HandleWindowEvent( eventNc ) )
{
-#if wxMAC_USE_CORE_GRAPHICS
child->MacPaintBorders(0, 0) ;
-#else
- {
- wxWindowDC dc(this) ;
- dc.SetClippingRegion(wxRegion(updatergn));
- wxMacPortSetter helper(&dc) ;
- child->MacPaintBorders(0, 0) ;
- }
-#endif
}
}
}
wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
this->GetId(),
this->ClientToScreen(event.GetPosition()));
- if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
+ evtCtx.SetEventObject(this);
+ if ( ! HandleWindowEvent(evtCtx) )
event.Skip() ;
}
else
bool wxWindowMac::SetTransparent(wxByte alpha)
{
-#if wxMAC_USE_CORE_GRAPHICS
SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
if ( alpha != m_macAlpha )
Refresh() ;
}
return true ;
-#else
- return false ;
-#endif
}
bool wxWindowMac::CanSetTransparent()
{
-#if wxMAC_USE_CORE_GRAPHICS
return true ;
-#else
- return false ;
-#endif
}
wxByte wxWindowMac::GetTransparent() const
{
return m_macAlpha ;
}
+
+bool wxWindowMac::IsShownOnScreen() const
+{
+#if TARGET_API_MAC_OSX
+ if ( m_peer && m_peer->Ok() )
+ {
+ bool peerVis = m_peer->IsVisible();
+ bool wxVis = wxWindowBase::IsShownOnScreen();
+ if( peerVis != wxVis )
+ {
+ // CS : put a breakpoint here to investigate differences
+ // between native an wx visibilities
+ // the only place where I've encountered them until now
+ // are the hiding/showing sequences where the vis-changed event is
+ // first sent to the innermost control, while wx does things
+ // from the outmost control
+ wxVis = wxWindowBase::IsShownOnScreen();
+ return wxVis;
+ }
+
+ return m_peer->IsVisible();
+ }
+#endif
+
+ return wxWindowBase::IsShownOnScreen();
+}