moving more things to common API between carbon and cocoa, adapting WidthDefault etc, removing dependencies from wxClientDC from text measuring ops on wxWindow
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -452,12 +452,7 @@ public :
|
|||||||
|
|
||||||
virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
|
virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
|
||||||
|
|
||||||
void InstallEventHandler()
|
void InstallEventHandler( WXWidget control = NULL );
|
||||||
{
|
|
||||||
MacInstallEventHandler( m_controlRef, m_wxPeer );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MacInstallEventHandler( ControlRef control, wxWindowMac* wxPeer );
|
|
||||||
protected :
|
protected :
|
||||||
WXEVENTHANDLERREF m_macControlEventHandler ;
|
WXEVENTHANDLERREF m_macControlEventHandler ;
|
||||||
ControlRef m_controlRef;
|
ControlRef m_controlRef;
|
||||||
|
@@ -236,6 +236,15 @@ public :
|
|||||||
// state changing logic is required from the outside
|
// state changing logic is required from the outside
|
||||||
virtual bool ButtonClickDidStateChange() = 0;
|
virtual bool ButtonClickDidStateChange() = 0;
|
||||||
|
|
||||||
|
// static methods for associating native controls and their implementations
|
||||||
|
|
||||||
|
static wxWidgetImpl*
|
||||||
|
FindFromWXWidget(WXWidget control);
|
||||||
|
|
||||||
|
static void RemoveAssociations( wxWidgetImpl* impl);
|
||||||
|
|
||||||
|
static void Associate( WXWidget control, wxWidgetImpl *impl );
|
||||||
|
|
||||||
// static creation methods, must be implemented by all toolkits
|
// static creation methods, must be implemented by all toolkits
|
||||||
|
|
||||||
static wxWidgetImplType* CreateUserPane( wxWindowMac* wxpeer,
|
static wxWidgetImplType* CreateUserPane( wxWindowMac* wxpeer,
|
||||||
|
@@ -2227,7 +2227,7 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer,
|
|||||||
{
|
{
|
||||||
HIViewAddSubview( m_scrollView , m_textView ) ;
|
HIViewAddSubview( m_scrollView , m_textView ) ;
|
||||||
m_controlRef = m_scrollView ;
|
m_controlRef = m_scrollView ;
|
||||||
wxMacControl::MacInstallEventHandler( m_textView, wxPeer ) ;
|
InstallEventHandler( (WXWidget) m_textView ) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -79,50 +79,6 @@
|
|||||||
#define wxMAC_DEBUG_REDRAW 0
|
#define wxMAC_DEBUG_REDRAW 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
WX_DECLARE_HASH_MAP(WXWidget, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
|
|
||||||
|
|
||||||
static MacControlMap wxWinMacControlList;
|
|
||||||
|
|
||||||
wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl )
|
|
||||||
{
|
|
||||||
MacControlMap::iterator node = wxWinMacControlList.find(inControl);
|
|
||||||
|
|
||||||
return (node == wxWinMacControlList.end()) ? NULL : node->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxAssociateWindowWithWXWidget(WXWidget inControl, wxWindow *control)
|
|
||||||
{
|
|
||||||
// adding NULL ControlRef is (first) surely a result of an error and
|
|
||||||
// (secondly) breaks native event processing
|
|
||||||
wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WindowRef to window list") );
|
|
||||||
|
|
||||||
wxWinMacControlList[inControl] = control;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxRemoveWXWidgetAssociation(wxWindow *control)
|
|
||||||
{
|
|
||||||
// iterate over all the elements in the class
|
|
||||||
// is the iterator stable ? as we might have two associations pointing to the same wxWindow
|
|
||||||
// we should go on...
|
|
||||||
|
|
||||||
bool found = true ;
|
|
||||||
while ( found )
|
|
||||||
{
|
|
||||||
found = false ;
|
|
||||||
MacControlMap::iterator it;
|
|
||||||
for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
|
|
||||||
{
|
|
||||||
if ( it->second == control )
|
|
||||||
{
|
|
||||||
wxWinMacControlList.erase(it);
|
|
||||||
found = true ;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Carbon Events
|
// Carbon Events
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -842,11 +798,11 @@ wxWidgetImplType* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxMacControl::MacInstallEventHandler( ControlRef control, wxWindowMac* wxPeer )
|
void wxMacControl::InstallEventHandler( WXWidget control )
|
||||||
{
|
{
|
||||||
wxAssociateWindowWithWXWidget( (WXWidget) control , wxPeer ) ;
|
wxWidgetImpl::Associate( control ? control : (WXWidget) m_controlRef , this ) ;
|
||||||
::InstallControlEventHandler( control , GetwxMacWindowEventHandlerUPP(),
|
::InstallControlEventHandler( control ? (ControlRef) control : m_controlRef , GetwxMacWindowEventHandlerUPP(),
|
||||||
GetEventTypeCount(eventList), eventList, wxPeer, NULL);
|
GetEventTypeCount(eventList), eventList, GetWXPeer(), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS( wxMacControl , wxWidgetImpl )
|
IMPLEMENT_DYNAMIC_CLASS( wxMacControl , wxWidgetImpl )
|
||||||
@@ -869,7 +825,7 @@ wxMacControl::~wxMacControl()
|
|||||||
wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") );
|
wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") );
|
||||||
wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
|
wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
|
||||||
|
|
||||||
wxRemoveWXWidgetAssociation( m_wxPeer) ;
|
wxWidgetImpl::RemoveAssociations( this ) ;
|
||||||
// we cannot check the ref count here anymore, as autorelease objects might delete their refs later
|
// we cannot check the ref count here anymore, as autorelease objects might delete their refs later
|
||||||
// we can have situations when being embedded, where the control gets deleted behind our back, so only
|
// we can have situations when being embedded, where the control gets deleted behind our back, so only
|
||||||
// CFRelease if we are safe
|
// CFRelease if we are safe
|
||||||
|
@@ -61,6 +61,8 @@
|
|||||||
#include "wx/dnd.h"
|
#include "wx/dnd.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/graphics.h"
|
||||||
|
|
||||||
#if wxOSX_USE_CARBON
|
#if wxOSX_USE_CARBON
|
||||||
#include "wx/osx/uma.h"
|
#include "wx/osx/uma.h"
|
||||||
#else
|
#else
|
||||||
@@ -292,7 +294,8 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSiz
|
|||||||
|
|
||||||
m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
|
m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
|
||||||
|
|
||||||
if (!m_macIsUserPane)
|
// for controls we want to use best size for wxDefaultSize params )
|
||||||
|
if ( !m_macIsUserPane )
|
||||||
SetInitialSize(size);
|
SetInitialSize(size);
|
||||||
|
|
||||||
SetCursor( *wxSTANDARD_CURSOR ) ;
|
SetCursor( *wxSTANDARD_CURSOR ) ;
|
||||||
@@ -384,8 +387,8 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
|
|||||||
|
|
||||||
void wxWindowMac::MacUpdateControlFont()
|
void wxWindowMac::MacUpdateControlFont()
|
||||||
{
|
{
|
||||||
|
if ( m_peer )
|
||||||
m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
|
m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
|
||||||
|
|
||||||
// do not trigger refreshes upon invisible and possible partly created objects
|
// do not trigger refreshes upon invisible and possible partly created objects
|
||||||
if ( IsShownOnScreen() )
|
if ( IsShownOnScreen() )
|
||||||
@@ -483,9 +486,8 @@ bool wxWindowMac::MacGetBoundsForControl(
|
|||||||
x = (int)pos.x;
|
x = (int)pos.x;
|
||||||
y = (int)pos.y;
|
y = (int)pos.y;
|
||||||
|
|
||||||
// TODO: the default calls may be used as soon as PostCreateControl Is moved here
|
w = WidthDefault( size.x );
|
||||||
w = wxMax(size.x, 0) ; // WidthDefault( size.x );
|
h = HeightDefault( size.y );
|
||||||
h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ;
|
|
||||||
|
|
||||||
x += MacGetLeftBorderSize() ;
|
x += MacGetLeftBorderSize() ;
|
||||||
y += MacGetTopBorderSize() ;
|
y += MacGetTopBorderSize() ;
|
||||||
@@ -1134,19 +1136,21 @@ bool wxWindowMac::MacIsReallyHilited()
|
|||||||
|
|
||||||
int wxWindowMac::GetCharHeight() const
|
int wxWindowMac::GetCharHeight() const
|
||||||
{
|
{
|
||||||
wxClientDC dc( (wxWindow*)this ) ;
|
wxCoord height;
|
||||||
|
GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
|
||||||
|
|
||||||
return dc.GetCharHeight() ;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxWindowMac::GetCharWidth() const
|
int wxWindowMac::GetCharWidth() const
|
||||||
{
|
{
|
||||||
wxClientDC dc( (wxWindow*)this ) ;
|
wxCoord width;
|
||||||
|
GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
|
||||||
|
|
||||||
return dc.GetCharWidth() ;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
|
void wxWindowMac::GetTextExtent(const wxString& str, int *x, int *y,
|
||||||
int *descent, int *externalLeading, const wxFont *theFont ) const
|
int *descent, int *externalLeading, const wxFont *theFont ) const
|
||||||
{
|
{
|
||||||
const wxFont *fontToUse = theFont;
|
const wxFont *fontToUse = theFont;
|
||||||
@@ -1157,17 +1161,22 @@ void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
|
|||||||
fontToUse = &tempFont;
|
fontToUse = &tempFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxClientDC dc( (wxWindow*) this ) ;
|
wxGraphicsContext* ctx = wxGraphicsContext::Create();
|
||||||
wxCoord lx,ly,ld,le ;
|
ctx->SetFont( *fontToUse, *wxBLACK );
|
||||||
dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
|
|
||||||
|
wxDouble h , d , e , w;
|
||||||
|
ctx->GetTextExtent( str, &w, &h, &d, &e );
|
||||||
|
|
||||||
|
delete ctx;
|
||||||
|
|
||||||
if ( externalLeading )
|
if ( externalLeading )
|
||||||
*externalLeading = le ;
|
*externalLeading = (wxCoord)(e+0.5);
|
||||||
if ( descent )
|
if ( descent )
|
||||||
*descent = ld ;
|
*descent = (wxCoord)(d+0.5);
|
||||||
if ( x )
|
if ( x )
|
||||||
*x = lx ;
|
*x = (wxCoord)(w+0.5);
|
||||||
if ( y )
|
if ( y )
|
||||||
*y = ly ;
|
*y = (wxCoord)(h+0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1861,9 +1870,9 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
|
|||||||
// the grow-box area of a scrolled window (scroll sample)
|
// the grow-box area of a scrolled window (scroll sample)
|
||||||
wxDC* dc = new wxWindowDC(this);
|
wxDC* dc = new wxWindowDC(this);
|
||||||
if ( IsTopLevel() )
|
if ( IsTopLevel() )
|
||||||
dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn)));
|
dc->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn)));
|
||||||
else
|
else
|
||||||
dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate)));
|
dc->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate)));
|
||||||
|
|
||||||
wxEraseEvent eevent( GetId(), dc );
|
wxEraseEvent eevent( GetId(), dc );
|
||||||
eevent.SetEventObject( this );
|
eevent.SetEventObject( this );
|
||||||
@@ -2325,6 +2334,58 @@ bool wxWindowMac::IsShownOnScreen() const
|
|||||||
// wxWidgetImpl
|
// wxWidgetImpl
|
||||||
//
|
//
|
||||||
|
|
||||||
|
WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap);
|
||||||
|
|
||||||
|
static MacControlMap wxWinMacControlList;
|
||||||
|
|
||||||
|
wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl )
|
||||||
|
{
|
||||||
|
wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl );
|
||||||
|
if ( impl )
|
||||||
|
return impl->GetWXPeer();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl )
|
||||||
|
{
|
||||||
|
MacControlMap::iterator node = wxWinMacControlList.find(inControl);
|
||||||
|
|
||||||
|
return (node == wxWinMacControlList.end()) ? NULL : node->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl)
|
||||||
|
{
|
||||||
|
// adding NULL ControlRef is (first) surely a result of an error and
|
||||||
|
// (secondly) breaks native event processing
|
||||||
|
wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") );
|
||||||
|
|
||||||
|
wxWinMacControlList[inControl] = impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl)
|
||||||
|
{
|
||||||
|
// iterate over all the elements in the class
|
||||||
|
// is the iterator stable ? as we might have two associations pointing to the same wxWindow
|
||||||
|
// we should go on...
|
||||||
|
|
||||||
|
bool found = true ;
|
||||||
|
while ( found )
|
||||||
|
{
|
||||||
|
found = false ;
|
||||||
|
MacControlMap::iterator it;
|
||||||
|
for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
|
||||||
|
{
|
||||||
|
if ( it->second == impl )
|
||||||
|
{
|
||||||
|
wxWinMacControlList.erase(it);
|
||||||
|
found = true ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
|
IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
|
||||||
|
|
||||||
wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl )
|
wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl )
|
||||||
|
Reference in New Issue
Block a user