1. Harm's patch for AppendText()
2. Kbd processing seems to work (dlg navigation keys, wxTE_PROCESS_TAB &c) 3. controls sample updated to use AppendText() and test kbd navigation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1571 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -123,6 +123,7 @@ public:
|
||||
virtual bool LoadFile(const wxString& file);
|
||||
virtual bool SaveFile(const wxString& file);
|
||||
virtual void WriteText(const wxString& text);
|
||||
virtual void AppendText(const wxString& text);
|
||||
virtual void DiscardEdits();
|
||||
virtual bool IsModified() const;
|
||||
|
||||
|
@@ -63,7 +63,7 @@ public:
|
||||
const wxPoint &pos, const wxSize &size, int style = 0)
|
||||
: wxTextCtrl(parent, id, value, pos, size, style) { }
|
||||
|
||||
void OnChar(wxKeyEvent& event);
|
||||
void OnKeyDown(wxKeyEvent& event);
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
@@ -125,6 +125,7 @@ class MyFrame: public wxFrame
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnIdle( wxIdleEvent& event );
|
||||
void OnSize( wxSizeEvent& event );
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
@@ -176,10 +177,10 @@ bool MyApp::OnInit(void)
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
|
||||
EVT_CHAR(MyTextCtrl::OnChar)
|
||||
EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
void MyTextCtrl::OnChar(wxKeyEvent& event)
|
||||
void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
|
||||
{
|
||||
switch ( event.KeyCode() )
|
||||
{
|
||||
@@ -314,7 +315,8 @@ BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
||||
EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
|
||||
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
||||
: m_notebook(NULL), m_text(NULL),
|
||||
wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
|
||||
{
|
||||
// SetBackgroundColour("cadet blue");
|
||||
@@ -432,7 +434,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
|
||||
panel = new wxPanel(m_notebook);
|
||||
m_textentry = new MyTextCtrl( panel, -1, "Write text here.", wxPoint(10,10), wxSize(320,28),
|
||||
wxTE_PROCESS_ENTER);
|
||||
(*m_textentry) << " More text.";
|
||||
(*m_textentry) << " More text."; // this text is appended
|
||||
m_textentry->SetInsertionPoint(0);
|
||||
m_textentry->WriteText("Less text."); // this text is prepended
|
||||
|
||||
m_multitext = new MyTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,70),
|
||||
wxTE_MULTILINE );
|
||||
(*m_multitext) << " More text.\nPress function keys to test different \nwxTextCtrl functions.";
|
||||
@@ -608,16 +613,16 @@ void MyPanel::OnPageChanged( wxNotebookEvent &event )
|
||||
|
||||
void MyPanel::OnListBox( wxCommandEvent &event )
|
||||
{
|
||||
m_text->WriteText( "ListBox selection string is: " );
|
||||
m_text->WriteText( event.GetString() );
|
||||
m_text->WriteText( "\n" );
|
||||
m_text->AppendText( "ListBox selection string is: " );
|
||||
m_text->AppendText( event.GetString() );
|
||||
m_text->AppendText( "\n" );
|
||||
}
|
||||
|
||||
void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
|
||||
{
|
||||
m_text->WriteText( "ListBox double click string is: " );
|
||||
m_text->WriteText( event.GetString() );
|
||||
m_text->WriteText( "\n" );
|
||||
m_text->AppendText( "ListBox double click string is: " );
|
||||
m_text->AppendText( event.GetString() );
|
||||
m_text->AppendText( "\n" );
|
||||
}
|
||||
|
||||
void MyPanel::OnListBoxButtons( wxCommandEvent &event )
|
||||
@@ -626,7 +631,7 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event )
|
||||
{
|
||||
case ID_LISTBOX_ENABLE:
|
||||
{
|
||||
m_text->WriteText("Checkbox clicked.\n");
|
||||
m_text->AppendText("Checkbox clicked.\n");
|
||||
wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
|
||||
if (event.GetInt())
|
||||
cb->SetToolTip( "Click to enable listbox" );
|
||||
@@ -672,9 +677,9 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event )
|
||||
|
||||
void MyPanel::OnChoice( wxCommandEvent &event )
|
||||
{
|
||||
m_text->WriteText( "Choice selection string is: " );
|
||||
m_text->WriteText( event.GetString() );
|
||||
m_text->WriteText( "\n" );
|
||||
m_text->AppendText( "Choice selection string is: " );
|
||||
m_text->AppendText( event.GetString() );
|
||||
m_text->AppendText( "\n" );
|
||||
}
|
||||
|
||||
void MyPanel::OnChoiceButtons( wxCommandEvent &event )
|
||||
@@ -722,9 +727,9 @@ void MyPanel::OnChoiceButtons( wxCommandEvent &event )
|
||||
|
||||
void MyPanel::OnCombo( wxCommandEvent &event )
|
||||
{
|
||||
m_text->WriteText( "ComboBox selection string is: " );
|
||||
m_text->WriteText( event.GetString() );
|
||||
m_text->WriteText( "\n" );
|
||||
m_text->AppendText( "ComboBox selection string is: " );
|
||||
m_text->AppendText( event.GetString() );
|
||||
m_text->AppendText( "\n" );
|
||||
}
|
||||
|
||||
void MyPanel::OnComboButtons( wxCommandEvent &event )
|
||||
@@ -772,9 +777,9 @@ void MyPanel::OnComboButtons( wxCommandEvent &event )
|
||||
|
||||
void MyPanel::OnRadio( wxCommandEvent &event )
|
||||
{
|
||||
m_text->WriteText( "RadioBox selection string is: " );
|
||||
m_text->WriteText( event.GetString() );
|
||||
m_text->WriteText( "\n" );
|
||||
m_text->AppendText( "RadioBox selection string is: " );
|
||||
m_text->AppendText( event.GetString() );
|
||||
m_text->AppendText( "\n" );
|
||||
}
|
||||
|
||||
void MyPanel::OnRadioButtons( wxCommandEvent &event )
|
||||
@@ -834,13 +839,14 @@ MyPanel::~MyPanel()
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
|
||||
EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
|
||||
EVT_SIZE(MyFrame::OnSize)
|
||||
EVT_IDLE(MyFrame::OnIdle)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
||||
: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
|
||||
{
|
||||
CreateStatusBar();
|
||||
CreateStatusBar(2);
|
||||
|
||||
(void)new MyPanel( this, 10, 10, 300, 100 );
|
||||
}
|
||||
@@ -856,6 +862,15 @@ void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
|
||||
dialog.ShowModal();
|
||||
}
|
||||
|
||||
void MyFrame::OnSize( wxSizeEvent& event )
|
||||
{
|
||||
wxString msg;
|
||||
msg.Printf("%dx%d", event.GetSize().x, event.GetSize().y);
|
||||
SetStatusText(msg, 1);
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
||||
{
|
||||
// track the window which has the focus in the status bar
|
||||
|
@@ -125,6 +125,9 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
|
||||
if (m_windowStyle & wxTE_MULTILINE)
|
||||
{
|
||||
wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
|
||||
"wxTE_PROCESS_ENTER style is ignored for multiline controls" );
|
||||
|
||||
msStyle |= ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL ; // WS_BORDER
|
||||
m_windowStyle |= wxTE_PROCESS_ENTER;
|
||||
}
|
||||
@@ -630,9 +633,14 @@ void wxTextCtrl::WriteText(const wxString& text)
|
||||
delete[] newtext;
|
||||
}
|
||||
|
||||
void wxTextCtrl::AppendText(const wxString& text)
|
||||
{
|
||||
SetInsertionPointEnd();
|
||||
WriteText(text);
|
||||
}
|
||||
|
||||
void wxTextCtrl::Clear()
|
||||
{
|
||||
// SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
|
||||
SetWindowText((HWND) GetHWND(), "");
|
||||
}
|
||||
|
||||
@@ -809,7 +817,7 @@ int wxTextCtrl::overflow(int c)
|
||||
txt[plen] = (char)c; // append c
|
||||
txt[plen+xtra] = '\0'; // append '\0' or overwrite c
|
||||
// If the put area already contained \0, output will be truncated there
|
||||
WriteText(txt);
|
||||
AppendText(txt);
|
||||
delete[] txt;
|
||||
}
|
||||
|
||||
@@ -874,7 +882,7 @@ int wxTextCtrl::underflow()
|
||||
|
||||
wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
|
||||
{
|
||||
WriteText(s);
|
||||
AppendText(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -882,7 +890,7 @@ wxTextCtrl& wxTextCtrl::operator<<(float f)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf("%.2f", f);
|
||||
WriteText(str);
|
||||
AppendText(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -890,7 +898,7 @@ wxTextCtrl& wxTextCtrl::operator<<(double d)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf("%.2f", d);
|
||||
WriteText(str);
|
||||
AppendText(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -898,7 +906,7 @@ wxTextCtrl& wxTextCtrl::operator<<(int i)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf("%d", i);
|
||||
WriteText(str);
|
||||
AppendText(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -906,7 +914,7 @@ wxTextCtrl& wxTextCtrl::operator<<(long i)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf("%ld", i);
|
||||
WriteText(str);
|
||||
AppendText(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -916,7 +924,7 @@ wxTextCtrl& wxTextCtrl::operator<<(const char c)
|
||||
|
||||
buf[0] = c;
|
||||
buf[1] = 0;
|
||||
WriteText(buf);
|
||||
AppendText(buf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -969,23 +977,32 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
|
||||
case WXK_RETURN:
|
||||
wxASSERT_MSG( m_windowStyle & wxTE_PROCESS_ENTER,
|
||||
"this text ctrl should never receive return" );
|
||||
if ( m_windowStyle & wxTE_MULTILINE == 0 )
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
|
||||
event.SetEventObject( this );
|
||||
if ( GetEventHandler()->ProcessEvent(event) )
|
||||
return;
|
||||
}
|
||||
//else: multiline controls need Enter for themselves
|
||||
|
||||
break;
|
||||
|
||||
case WXK_TAB:
|
||||
// only produce navigation event if we don't process TAB ourself
|
||||
if ( !(m_windowStyle & wxTE_PROCESS_TAB) )
|
||||
// only produce navigation event if we don't process TAB ourself or
|
||||
// if it's a Shift-Tab keypress (we assume nobody will ever need
|
||||
// this key combo for himself)
|
||||
//
|
||||
// NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
|
||||
// handled by Windows
|
||||
if ( event.ShiftDown() || !(m_windowStyle & wxTE_PROCESS_TAB) )
|
||||
{
|
||||
wxNavigationKeyEvent event;
|
||||
event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100));
|
||||
event.SetWindowChange(FALSE);
|
||||
event.SetEventObject(this);
|
||||
wxNavigationKeyEvent eventNav;
|
||||
eventNav.SetDirection(!event.ShiftDown());
|
||||
eventNav.SetWindowChange(FALSE);
|
||||
eventNav.SetEventObject(this);
|
||||
|
||||
if ( GetEventHandler()->ProcessEvent(event) )
|
||||
if ( GetEventHandler()->ProcessEvent(eventNav) )
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -1201,7 +1201,6 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
MSWOnKeyDown((WORD) wParam, lParam);
|
||||
@@ -1224,7 +1223,6 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
|
||||
return Default();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case WM_KEYUP:
|
||||
{
|
||||
@@ -1933,7 +1931,7 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
|
||||
bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
|
||||
|
||||
// WM_GETDLGCODE: if the control wants it for itself, don't process it
|
||||
// (except for Ctrl-Tab combination which is always processed)
|
||||
// (except for Ctrl-Tab/Enter combinations which are always processed)
|
||||
LONG lDlgCode = 0;
|
||||
if ( bProcess && !bCtrlDown ) {
|
||||
lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
|
||||
@@ -1973,11 +1971,20 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
|
||||
if ( !GetDefaultItem() ) {
|
||||
// but if there is not it makes sense to make it work
|
||||
// like a TAB
|
||||
|
||||
if ( bCtrlDown || (lDlgCode & DLGC_WANTMESSAGE == 0) )
|
||||
{
|
||||
// nothing to do - all variables are already set
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// control wants to process Enter itself, don't
|
||||
// call IsDialogMessage() which would interpret
|
||||
// it
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
//else: fall through and don't process the message
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user