wxTextCtrl cursor position Topic is solved
wxTextCtrl cursor position
I have a wxTextCtrl when enter is hit I Clear() the text and need to set the cursor position back to the start, how can I do that?
You type a few words, enter is hit, the function to handle enter is called, in there I copy the text, use it, then call
the wxTextCtrls Clear(), the text clears but the cursor stays on the second line where enter placed it. Now if I were to start typing again, Im typing on the second line, I want the cursor to go back to the top left of the text ctrl.
the wxTextCtrls Clear(), the text clears but the cursor stays on the second line where enter placed it. Now if I were to start typing again, Im typing on the second line, I want the cursor to go back to the top left of the text ctrl.
-
- Super wx Problem Solver
- Posts: 401
- Joined: Wed Sep 21, 2005 8:17 am
- Location: Rostov-on-Don, Southern Russia
Swoop wrote:You type a few words, enter is hit, the function to handle enter is called, in there I copy the text, use it, then call
the wxTextCtrls Clear(), the text clears but the cursor stays on the second line where enter placed it. Now if I were to start typing again, Im typing on the second line, I want the cursor to go back to the top left of the text ctrl.
Code: Select all
m_textCtrl->SetFocus();
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
This kinda sounds like a bug, the cursor should probably not stay at a position where there is no text anymoreSwoop wrote:You type a few words, enter is hit, the function to handle enter is called, in there I copy the text, use it, then call
the wxTextCtrls Clear(), the text clears but the cursor stays on the second line where enter placed it. Now if I were to start typing again, Im typing on the second line, I want the cursor to go back to the top left of the text ctrl.
"Keyboard not detected. Press F1 to continue"
-- Windows
-- Windows
I had the same problem.
@Swoop, try this;
@Swoop, try this;
Code: Select all
void TextCtrl::OnEnter(wxRichTextEvent& event)
{
Clear();
MoveToParagraphStart();
event.Skip();
}
wxWidgets 2.8.10 & WX_TRUNK
Ubuntu 9.10
GCC 4.4
Ubuntu 9.10
GCC 4.4
-
- Super wx Problem Solver
- Posts: 401
- Joined: Wed Sep 21, 2005 8:17 am
- Location: Rostov-on-Don, Southern Russia
wxTextCtrl hasn't MoveToParagraphStart() member.Ridmix wrote:I had the same problem.
@Swoop, try this;
Code: Select all
void TextCtrl::OnEnter(wxRichTextEvent& event) { Clear(); MoveToParagraphStart(); event.Skip(); }
There is MoveToParagraphStart() in wxRichTextCtrl only.
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
-
- Super wx Problem Solver
- Posts: 401
- Joined: Wed Sep 21, 2005 8:17 am
- Location: Rostov-on-Don, Southern Russia
If I get right, the problem is double action when you push Enter key.
The first action - m_textCtrl1->Clear(); and simultaneously goes the second one - pushing Enter key removes cursor on next line (this native action in windows textcontrol).
So, it takes to convert the question: "How to disable the second action i.e. removing cursor (or caret?) on next line when you push Enter-key ?
The first action - m_textCtrl1->Clear(); and simultaneously goes the second one - pushing Enter key removes cursor on next line (this native action in windows textcontrol).
So, it takes to convert the question: "How to disable the second action i.e. removing cursor (or caret?) on next line when you push Enter-key ?
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
Thanks for the suggestions.
m_textCtrl->SetFocus(); is a no go
wxTextCtrl::SetInsertionPoint(long pos) is a no go
event.Skip(); is a no go
I cant believe something so simply has no methods to accomplish this. Clear erases all 'X' chars before the cursor, yet the cursor remains at 'X' chars position, usually to accomplish this you would have to hold space to push the cursor to this position. It seems like a bug, whats keeping the cursor at the same position once the text before it is erased?
m_textCtrl->SetFocus(); is a no go
wxTextCtrl::SetInsertionPoint(long pos) is a no go
event.Skip(); is a no go
I cant believe something so simply has no methods to accomplish this. Clear erases all 'X' chars before the cursor, yet the cursor remains at 'X' chars position, usually to accomplish this you would have to hold space to push the cursor to this position. It seems like a bug, whats keeping the cursor at the same position once the text before it is erased?
Hi,
Can you demonstrate this problem in e.g. the 'text' sample (that comes with the wx source) or, failing that, create and post the code of a minimal compilable sample, so that we can try this at home?
Regards,
David
I can't believe nobody else has noticed it before. Which platform/wx version are you using?I cant believe something so simply has no methods to accomplish this.
Can you demonstrate this problem in e.g. the 'text' sample (that comes with the wx source) or, failing that, create and post the code of a minimal compilable sample, so that we can try this at home?
Regards,
David
I was running 2.8.10 when I made the original post, then I changed to 2.8.11, same thing. Im on Windows XP x64.
My example doesnt derive from wxTextCtrl, I call clear in OnTextEnter() { ctrl->Clear(); }
I reproduced it using the text sample, in text.cpp starting at line 807
My example doesnt derive from wxTextCtrl, I call clear in OnTextEnter() { ctrl->Clear(); }
I reproduced it using the text sample, in text.cpp starting at line 807
Code: Select all
void MyTextCtrl::OnTextEnter(wxCommandEvent& event)
{
if ( !ms_logText )
return;
MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
const wxChar *data = (const wxChar *)(win->GetClientData());
if ( data )
{
wxLogMessage(_T("Enter pressed in control '%s'"), data);
}
else
{
wxLogMessage(_T("Enter pressed in some control"));
}
win->Clear(); // I added this, the text clears, the
// cursor sits, just like in mine
}
Huh?My example doesnt derive from wxTextCtrl
Hmm. The only textctrl instance in the sample that includes the wxTE_PROCESS_ENTER style-flag is a single-line textctrl, so I'm not sure how you managed to demonstrate the problem.I reproduced it using the text sample, in text.cpp starting at line 807
Adding wxTE_PROCESS_ENTER to several other textctrls, so that MyTextCtrl::OnTextEnter is called, does clear those textctrls, and the cursor is then correctly placed at the beginning of the control.
That's on wxGTK-2.8.11, so maybe you've found a MSWin issue.
Well Im more confused then before now, I checked those text controls, MyTextCtrl from the sample has an event table entry for OnTextEnter(), but it doesnt seem to use the flag wxTE_PROCESS_ENTER for the multiline ctrls that go down the middle column of that sample window, yet I break inside OnTextEnter() for those multi line ctrls and it does fire, I clear like I said in the last post, the cursor stays, I guess its a bug, what else is new.