From: Vadim Zeitlin Date: Wed, 27 Jan 1999 18:46:07 +0000 (+0000) Subject: GTK asserts disappeared - but surprizngly, SetInsertionPoint() still doesn't X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d59051dd0a4cbb3b51dfcc89025eb19a4671a912 GTK asserts disappeared - but surprizngly, SetInsertionPoint() still doesn't seem to work for multiline controls. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1501 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index fe99c4266e..686dc1bab4 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -80,6 +80,8 @@ class MyPanel: public wxPanel void OnSpinUpdate( wxSpinEvent &event ); void OnPasteFromClipboard( wxCommandEvent &event ); void OnCopyToClipboard( wxCommandEvent &event ); + void OnMoveToEndOfText( wxCommandEvent &event ); + void OnMoveToEndOfEntry( wxCommandEvent &event ); wxListBox *m_listbox; wxChoice *m_choice; @@ -91,6 +93,7 @@ class MyPanel: public wxPanel wxSpinButton *m_spinbutton; wxTextCtrl *m_spintext; wxTextCtrl *m_multitext; + wxTextCtrl *m_textentry; wxCheckBox *m_checkbox; wxTextCtrl *m_text; @@ -118,7 +121,7 @@ class MyFrame: public wxFrame // main() //---------------------------------------------------------------------- -IMPLEMENT_APP (MyApp) +IMPLEMENT_APP(MyApp) //---------------------------------------------------------------------- // MyApp @@ -192,6 +195,8 @@ const int ID_COMBO_ENABLE = 147; const int ID_TEXT = 150; const int ID_PASTE_TEXT = 151; const int ID_COPY_TEXT = 152; +const int ID_MOVE_END_ENTRY = 153; +const int ID_MOVE_END_ZONE = 154; const int ID_RADIOBOX = 160; const int ID_RADIOBOX_SEL_NUM = 161; @@ -248,6 +253,8 @@ BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard) EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard) + EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText) + EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry) END_EVENT_TABLE() MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : @@ -386,15 +393,21 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : panel = new wxPanel(m_notebook); // panel->SetBackgroundColour("cadet blue"); // panel->SetForegroundColour("blue"); - wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28)); - (*tc) << " More text."; -// tc->SetBackgroundColour("wheat"); + m_textentry = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28)); + (*m_textentry) << " More text."; +// m_textentry->SetBackgroundColour("wheat"); m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE ); (*m_multitext) << " More text."; // m_multitext->SetBackgroundColour("wheat"); - (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) ); - (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,80), wxSize(110,30) ); - (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,140), wxSize(110,30) ); + (void)new wxStaticBox( panel, -1, "Move cursor to the end of:", + wxPoint(345, 0), wxSize(160, 100) ); + (void)new wxButton(panel, ID_MOVE_END_ENTRY, "Text entry", + wxPoint(370, 20), wxSize(110, 30)); + (void)new wxButton(panel, ID_MOVE_END_ZONE, "Text zone", + wxPoint(370, 60), wxSize(110, 30)); + (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,120), wxSize(160,100) ); + (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,140), wxSize(110,30) ); + (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,180), wxSize(110,30) ); m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text); wxString choices2[] = @@ -533,6 +546,18 @@ void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) ) #endif } +void MyPanel::OnMoveToEndOfText( wxCommandEvent &event ) +{ + m_multitext->SetInsertionPointEnd(); + m_multitext->SetFocus(); +} + +void MyPanel::OnMoveToEndOfEntry( wxCommandEvent &event ) +{ + m_textentry->SetInsertionPointEnd(); + m_textentry->SetFocus(); +} + void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) { int x = 0; diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 29bda2592d..f165c20805 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -435,7 +435,7 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const { wxString text = GetValue(); - if( pos >= text.Len() ) + if( pos >= (long)text.Len() ) return FALSE; *x=1; // Col 1 @@ -519,18 +519,20 @@ void wxTextCtrl::SetInsertionPoint( long pos ) { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); - int tmp = (int) pos; if (m_windowStyle & wxTE_MULTILINE) - gtk_text_set_point( GTK_TEXT(m_text), tmp ); + gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); else - gtk_entry_set_position( GTK_ENTRY(m_text), tmp ); + gtk_entry_set_position( GTK_ENTRY(m_text), (int)pos ); } void wxTextCtrl::SetInsertionPointEnd() { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); - SetInsertionPoint(-1); + if (m_windowStyle & wxTE_MULTILINE) + SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text))); + else + gtk_entry_set_position( GTK_ENTRY(m_text), -1 ); } void wxTextCtrl::SetEditable( bool editable ) diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 29bda2592d..f165c20805 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -435,7 +435,7 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const { wxString text = GetValue(); - if( pos >= text.Len() ) + if( pos >= (long)text.Len() ) return FALSE; *x=1; // Col 1 @@ -519,18 +519,20 @@ void wxTextCtrl::SetInsertionPoint( long pos ) { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); - int tmp = (int) pos; if (m_windowStyle & wxTE_MULTILINE) - gtk_text_set_point( GTK_TEXT(m_text), tmp ); + gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); else - gtk_entry_set_position( GTK_ENTRY(m_text), tmp ); + gtk_entry_set_position( GTK_ENTRY(m_text), (int)pos ); } void wxTextCtrl::SetInsertionPointEnd() { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); - SetInsertionPoint(-1); + if (m_windowStyle & wxTE_MULTILINE) + SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text))); + else + gtk_entry_set_position( GTK_ENTRY(m_text), -1 ); } void wxTextCtrl::SetEditable( bool editable )