m_peer = wxWidgetImpl::CreateTextControl( this, GetParent(), GetId(), str, pos, size, style, GetExtraStyle() );
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() ;
wxTextWidgetImpl* wxTextCtrl::GetTextPeer() const
{
- return dynamic_cast<wxTextWidgetImpl*> (m_peer);
+ return dynamic_cast<wxTextWidgetImpl*> (m_peer);
}
void wxTextCtrl::MacSuperChangedPosition()
bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
{
- GetTextPeer()->SetStyle( start , end , style ) ;
+ if (GetTextPeer())
+ GetTextPeer()->SetStyle( start , end , style ) ;
return true ;
}
wxSize wxTextCtrl::DoGetBestSize() const
{
+ if (GetTextPeer())
+ {
+ wxSize size = GetTextPeer()->GetBestSize();
+ if (size.x > 0 && size.y > 0)
+ return size;
+ }
+
int wText, hText;
// these are the numbers from the HIG:
return wxSize(wText, hText);
}
+bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
+{
+ return GetTextPeer()->GetStyle(position, style);
+}
+
// ----------------------------------------------------------------------------
// Undo/redo
// ----------------------------------------------------------------------------
return ;
}
- if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB &&
+ if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) &&
!( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
// && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
)
// allow navigation and deletion
GetSelection( &from, &to );
if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength &&
- key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && key != WXK_UP && key != WXK_DOWN &&
- key != WXK_BACK && key != WXK_DELETE && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) &&
+ !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) &&
+ !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) &&
from == to )
{
// eat it, we don't want to add more than allowed # of characters
m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All"));
}
- if (m_privateContextMenu != NULL)
- PopupMenu(m_privateContextMenu);
+ PopupMenu(m_privateContextMenu);
#endif
}
// implementation base class
// ----------------------------------------------------------------------------
+bool wxTextWidgetImpl::GetStyle(long WXUNUSED(position),
+ wxTextAttr& WXUNUSED(style))
+{
+ return false;
+}
+
void wxTextWidgetImpl::SetStyle(long WXUNUSED(start),
long WXUNUSED(end),
const wxTextAttr& WXUNUSED(style))
int wxTextWidgetImpl::GetNumberOfLines() const
{
- ItemCount lines = 0 ;
wxString content = GetStringValue() ;
- lines = 1;
+ ItemCount lines = 1;
for (size_t i = 0; i < content.length() ; i++)
{
+#if wxOSX_USE_COCOA
+ if (content[i] == '\n')
+#else
if (content[i] == '\r')
+#endif
lines++;
}