X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f11220943f14b4bb5190db0dfd0054304f5015c..bd9396d52dc2118f2f527ecea55271e79a893ed4:/src/msw/textctrl.cpp?ds=sidebyside diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 5643da7ebc..bfb35eaa50 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -39,12 +39,9 @@ #include #if wxUSE_IOSTREAMH -#include +# include #else -#include -# ifdef _MSC_VER - using namespace std; -# endif +# include #endif #include @@ -98,7 +95,6 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_fileName = ""; SetName(name); SetValidator(validator); if (parent) parent->AddChild(this); @@ -125,6 +121,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; } @@ -312,7 +311,7 @@ void wxTextCtrl::SetValue(const wxString& value) SetWindowText((HWND) GetHWND(), (const char *)value); } -void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags) +void wxTextCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -454,6 +453,7 @@ long wxTextCtrl::GetLastPosition() const void wxTextCtrl::Replace(long from, long to, const wxString& value) { +#if wxUSE_CLIPBOARD HWND hWnd = (HWND) GetHWND(); long fromChar = from; long toChar = to; @@ -471,6 +471,9 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value) // Paste into edit control SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L); +#else + wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0."); +#endif } void wxTextCtrl::Remove(long from, long to) @@ -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(), ""); } @@ -700,11 +708,6 @@ void wxTextCtrl::ShowPosition(long pos) int linesToScroll = specifiedLineLineNo - currentLineLineNo; -/* - wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n", - currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll); -*/ - if (linesToScroll != 0) (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELPARAM(linesToScroll, 0)); } @@ -809,7 +812,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,15 +877,15 @@ int wxTextCtrl::underflow() wxTextCtrl& wxTextCtrl::operator<<(const wxString& s) { - WriteText(s); - return *this; + AppendText(s); + return *this; } wxTextCtrl& wxTextCtrl::operator<<(float f) { wxString str; str.Printf("%.2f", f); - WriteText(str); + AppendText(str); return *this; } @@ -890,7 +893,7 @@ wxTextCtrl& wxTextCtrl::operator<<(double d) { wxString str; str.Printf("%.2f", d); - WriteText(str); + AppendText(str); return *this; } @@ -898,7 +901,7 @@ wxTextCtrl& wxTextCtrl::operator<<(int i) { wxString str; str.Printf("%d", i); - WriteText(str); + AppendText(str); return *this; } @@ -906,7 +909,7 @@ wxTextCtrl& wxTextCtrl::operator<<(long i) { wxString str; str.Printf("%ld", i); - WriteText(str); + AppendText(str); return *this; } @@ -916,7 +919,7 @@ wxTextCtrl& wxTextCtrl::operator<<(const char c) buf[0] = c; buf[1] = 0; - WriteText(buf); + AppendText(buf); return *this; } @@ -962,38 +965,53 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) case '\\': { char c = (char)event.KeyCode(); - *this << c; + WriteText(c); } break; case WXK_RETURN: + { +/* Oh yes it will, because we also specify DLGC_WANTCHARS 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; } + break; } // don't just call event.Skip() because this will cause TABs and ENTERs // be passed upwards and we don't always want this - instead process it // right here Default(); +// event.Skip(); } long wxTextCtrl::MSWGetDlgCode()