Set initial wxTextCtrl text earlier in wxOSX

This reverts the changes of 63bcc669d8 (fixing setting initial value
under osx_cocoa for single line text controls, 2009-10-01) and fixes the
problem which this commit probably tried to fix in a different way,
using the same approach as in 98f5315405 (Don't set initial label in
wxNativeWindow on OS X, 2016-04-29) as the real root of the problem was
that the text set in CreateTextControl() was overwritten later when the
label was set from SetPeer().

This change means that the text is now set correctly before SetPeer()
calls SetInitialSize() call, which makes it possible to set the correct
initial size based on the initial text, as will be done in later
commits.

It also makes Cocoa port more consistent with iOS one, as a nice side
effect.
This commit is contained in:
Vadim Zeitlin 2020-06-08 15:29:42 +02:00
parent de2fba540b
commit 41f4b1716d
3 changed files with 15 additions and 9 deletions

View File

@ -32,6 +32,12 @@ public :
virtual ~wxNSTextBase() { }
virtual bool ShouldHandleKeyNavigation(const wxKeyEvent &event) const wxOVERRIDE;
virtual void SetInitialLabel(const wxString& WXUNUSED(title), wxFontEncoding WXUNUSED(encoding)) wxOVERRIDE
{
// Don't do anything here, text controls don't have any label and
// setting it would overwrite the string value set when creating it.
}
};
// implementation exposed, so that search control can pull it

View File

@ -1556,7 +1556,7 @@ void wxNSTextFieldControl::SetJustification()
wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
wxWindowMac* WXUNUSED(parent),
wxWindowID WXUNUSED(id),
const wxString& WXUNUSED(str),
const wxString& str,
const wxPoint& pos,
const wxSize& size,
long style,
@ -1569,8 +1569,11 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
{
wxNSTextScrollView* v = nil;
v = [[wxNSTextScrollView alloc] initWithFrame:r];
c = new wxNSTextViewControl( wxpeer, v, style );
wxNSTextViewControl* t = new wxNSTextViewControl( wxpeer, v, style );
c = t;
c->SetNeedsFocusRect( true );
t->SetStringValue(str);
}
else
{
@ -1593,7 +1596,8 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
[cell setWraps:NO];
[cell setScrollable:YES];
c = new wxNSTextFieldControl( wxpeer, wxpeer, v );
wxNSTextFieldControl* t = new wxNSTextFieldControl( wxpeer, wxpeer, v );
c = t;
if ( (style & wxNO_BORDER) || (style & wxSIMPLE_BORDER) )
{
@ -1608,6 +1612,8 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
// use native border
c->SetNeedsFrame(false);
}
t->SetStringValue(str);
}
return c;

View File

@ -105,12 +105,6 @@ bool wxTextCtrl::Create( wxWindow *parent,
MacPostControlCreate(pos, size) ;
#if wxOSX_USE_COCOA
// under carbon everything can already be set before the MacPostControlCreate embedding takes place
// but under cocoa for single line textfields this only works after everything has been set up
GetTextPeer()->SetStringValue(str);
#endif
// only now the embedding is correct and we can do a positioning update
MacSuperChangedPosition() ;