X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..73fb82f3f3c1e722ad874d487c85249f6e866fbf:/src/msw/textctrl.cpp diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 1bf2931792..3def23203d 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -72,18 +72,18 @@ wxTextCtrl::wxTextCtrl(void) :streambuf() #endif { - fileName = ""; + m_fileName = ""; m_isRich = FALSE; } -bool wxTextCtrl::Create(wxWindow *parent, const wxWindowID id, +bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& value, const wxPoint& pos, - const wxSize& size, const long style, + const wxSize& size, long style, const wxValidator& validator, const wxString& name) { - fileName = ""; + m_fileName = ""; SetName(name); SetValidator(validator); if (parent) parent->AddChild(this); @@ -171,7 +171,7 @@ bool wxTextCtrl::Create(wxWindow *parent, const wxWindowID id, HWND edit = CreateWindowEx(exStyle, windowClass, NULL, msStyle, 0, 0, 0, 0, (HWND) ((wxWindow*)parent)->GetHWND(), (HMENU)m_windowId, - m_globalHandle ? (HANDLE) m_globalHandle : wxGetInstance(), NULL); + m_globalHandle ? (HINSTANCE) m_globalHandle : wxGetInstance(), NULL); #if CTL3D if ( want3D ) @@ -300,7 +300,7 @@ void wxTextCtrl::SetValue(const wxString& value) SetWindowText((HWND) GetHWND(), (const char *)value); } -void wxTextCtrl::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags) { int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -314,6 +314,8 @@ void wxTextCtrl::SetSize(const int x, const int y, const int width, const int he if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) y1 = currentY; + AdjustForParentClientOrigin(x1, y1, sizeFlags); + int cx; // button font dimensions int cy; @@ -345,15 +347,6 @@ void wxTextCtrl::SetSize(const int x, const int y, const int width, const int he MoveWindow((HWND) GetHWND(), (int)control_x, (int)control_y, (int)control_width, (int)control_height, TRUE); -/* -#if WXWIN_COMPATIBILITY - GetEventHandler()->OldOnSize(width, height); -#else - wxSizeEvent event(wxSize(width, height), m_windowId); - event.eventObject = this; - GetEventHandler()->ProcessEvent(event); -#endif -*/ } // Clipboard operations @@ -375,13 +368,13 @@ void wxTextCtrl::Paste(void) SendMessage(hWnd, WM_PASTE, 0, 0L); } -void wxTextCtrl::SetEditable(const bool editable) +void wxTextCtrl::SetEditable(bool editable) { HWND hWnd = (HWND) GetHWND(); SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L); } -void wxTextCtrl::SetInsertionPoint(const long pos) +void wxTextCtrl::SetInsertionPoint(long pos) { HWND hWnd = (HWND) GetHWND(); #ifdef __WIN32__ @@ -447,7 +440,7 @@ long wxTextCtrl::GetLastPosition(void) const return (long)(charIndex + lineLength); } -void wxTextCtrl::Replace(const long from, const long to, const wxString& value) +void wxTextCtrl::Replace(long from, long to, const wxString& value) { HWND hWnd = (HWND) GetHWND(); long fromChar = from; @@ -462,13 +455,13 @@ void wxTextCtrl::Replace(const long from, const long to, const wxString& value) SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0); // Now replace with 'value', by pasting. - wxSetClipboardData(wxCF_TEXT, (wxObject *) (const char *)value, 0, 0); + wxSetClipboardData(wxDF_TEXT, (wxObject *) (const char *)value, 0, 0); // Paste into edit control SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L); } -void wxTextCtrl::Remove(const long from, const long to) +void wxTextCtrl::Remove(long from, long to) { HWND hWnd = (HWND) GetHWND(); long fromChar = from; @@ -483,7 +476,7 @@ void wxTextCtrl::Remove(const long from, const long to) SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0); } -void wxTextCtrl::SetSelection(const long from, const long to) +void wxTextCtrl::SetSelection(long from, long to) { HWND hWnd = (HWND) GetHWND(); long fromChar = from; @@ -511,7 +504,7 @@ bool wxTextCtrl::LoadFile(const wxString& file) if (!FileExists(WXSTRINGCAST file)) return FALSE; - fileName = file; + m_fileName = file; Clear(); @@ -560,14 +553,14 @@ bool wxTextCtrl::LoadFile(const wxString& file) // Returns TRUE if succeeds. bool wxTextCtrl::SaveFile(const wxString& file) { - wxString theFile; - if (file == "") - theFile = fileName; - if (file == "") + wxString theFile(file); + if (theFile == "") + theFile = m_fileName; + if (theFile == "") return FALSE; - fileName = theFile; + m_fileName = theFile; - ofstream output(WXSTRINGCAST file); + ofstream output((char*) (const char*) theFile); if (output.bad()) return FALSE; @@ -641,7 +634,7 @@ int wxTextCtrl::GetNumberOfLines(void) const return (int)SendMessage((HWND) GetHWND(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0); } -long wxTextCtrl::XYToPosition(const long x, const long y) const +long wxTextCtrl::XYToPosition(long x, long y) const { HWND hWnd = (HWND) GetHWND(); @@ -650,7 +643,7 @@ long wxTextCtrl::XYToPosition(const long x, const long y) const return (long)(x + charIndex); } -void wxTextCtrl::PositionToXY(const long pos, long *x, long *y) const +void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const { HWND hWnd = (HWND) GetHWND(); @@ -663,7 +656,7 @@ void wxTextCtrl::PositionToXY(const long pos, long *x, long *y) const *y = (long)lineNo; } -void wxTextCtrl::ShowPosition(const long pos) +void wxTextCtrl::ShowPosition(long pos) { HWND hWnd = (HWND) GetHWND(); @@ -693,7 +686,7 @@ void wxTextCtrl::ShowPosition(const long pos) (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELPARAM(linesToScroll, 0)); } -int wxTextCtrl::GetLineLength(const long lineNo) const +int wxTextCtrl::GetLineLength(long lineNo) const { long charIndex = XYToPosition(0, lineNo); HWND hWnd = (HWND) GetHWND(); @@ -701,7 +694,7 @@ int wxTextCtrl::GetLineLength(const long lineNo) const return len; } -wxString wxTextCtrl::GetLineText(const long lineNo) const +wxString wxTextCtrl::GetLineText(long lineNo) const { HWND hWnd = (HWND) GetHWND(); *(WORD *)wxBuffer = 512; @@ -853,50 +846,49 @@ wxTextCtrl& wxTextCtrl::operator<<(const wxString& s) return *this; } -wxTextCtrl& wxTextCtrl::operator<<(const float f) +wxTextCtrl& wxTextCtrl::operator<<(float f) { - static char buf[100]; - sprintf(buf, "%.2f", f); - WriteText(buf); - return *this; + wxString str; + str.Printf("%.2f", f); + WriteText(str); + return *this; } -wxTextCtrl& wxTextCtrl::operator<<(const double d) +wxTextCtrl& wxTextCtrl::operator<<(double d) { - static char buf[100]; - sprintf(buf, "%.2f", d); - WriteText(buf); - return *this; + wxString str; + str.Printf("%.2f", d); + WriteText(str); + return *this; } -wxTextCtrl& wxTextCtrl::operator<<(const int i) +wxTextCtrl& wxTextCtrl::operator<<(int i) { - static char buf[100]; - sprintf(buf, "%i", i); - WriteText(buf); - return *this; + wxString str; + str.Printf("%d", i); + WriteText(str); + return *this; } -wxTextCtrl& wxTextCtrl::operator<<(const long i) +wxTextCtrl& wxTextCtrl::operator<<(long i) { - static char buf[100]; - sprintf(buf, "%ld", i); - WriteText(buf); - return *this; + wxString str; + str.Printf("%ld", i); + WriteText(str); + return *this; } wxTextCtrl& wxTextCtrl::operator<<(const char c) { - char buf[2]; + char buf[2]; - buf[0] = c; - buf[1] = 0; - WriteText(buf); - return *this; + buf[0] = c; + buf[1] = 0; + WriteText(buf); + return *this; } - -WXHBRUSH wxTextCtrl::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, +WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { #if CTL3D @@ -930,44 +922,31 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject( this ); - if ( !GetEventHandler()->ProcessEvent(event) ) - event.Skip(); + if ( GetEventHandler()->ProcessEvent(event) ) + return; } - else - event.Skip(); + else if ( event.KeyCode() == WXK_TAB ) { + wxNavigationKeyEvent event; + event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100)); + event.SetWindowChange(FALSE); + event.SetEventObject(this); + + if ( GetEventHandler()->ProcessEvent(event) ) + return; + } + + event.Skip(); } -long wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +long wxTextCtrl::MSWGetDlgCode() { - switch (nMsg) - { -/* - case WM_GETDLGCODE: - { - if (GetWindowStyleFlag() & wxPROCESS_ENTER) - return DLGC_WANTALLKEYS; - break; - } -*/ -/* - case WM_CHAR: // Always an ASCII character - { - if (wParam == VK_RETURN) - { - wxCommandEvent event(wxEVENT_TYPE_TEXT_ENTER_COMMAND); - event.commandString = ((wxTextCtrl *)item)->GetValue(); - event.eventObject = item; - item->ProcessCommand(event); - return FALSE; - } - break; - } -*/ - default: - break; - } + long lRc = DLGC_WANTCHARS | DLGC_WANTARROWS; + if ( m_windowStyle & wxPROCESS_ENTER ) + lRc |= DLGC_WANTMESSAGE; + else if ( m_windowStyle & wxTE_MULTILINE ) + lRc |= DLGC_WANTMESSAGE; - return wxWindow::MSWWindowProc(nMsg, wParam, lParam); + return lRc; } void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) @@ -991,7 +970,7 @@ void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) // wxWindow::OnEraseBackground(event); } -bool wxTextCtrl::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) +bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { /* // Debugging @@ -1027,51 +1006,49 @@ bool wxTextCtrl::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) break; } */ - WXTYPE eventTyp = 0; switch (param) { case EN_SETFOCUS: - eventTyp = wxEVENT_TYPE_SET_FOCUS; - break; case EN_KILLFOCUS: - eventTyp = wxEVENT_TYPE_KILL_FOCUS; + { + wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS + : wxEVT_SET_FOCUS, + m_windowId); + event.SetEventObject( this ); + ProcessEvent(event); + } break; - case EN_UPDATE: - break; + case EN_CHANGE: - eventTyp = wxEVENT_TYPE_TEXT_COMMAND; + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + wxString val(GetValue()); + if ( !val.IsNull() ) + event.m_commandString = WXSTRINGCAST val; + event.SetEventObject( this ); + ProcessCommand(event); + } break; + + // the other notification messages are not processed + case EN_UPDATE: case EN_ERRSPACE: - break; case EN_MAXTEXT: - break; case EN_HSCROLL: - break; case EN_VSCROLL: - break; default: - break; + return FALSE; } - if (eventTyp != 0) - { - wxCommandEvent event(eventTyp, m_windowId); - wxString val(GetValue()); - if ( !val.IsNull() ) - event.m_commandString = WXSTRINGCAST val; - event.SetEventObject( this ); - ProcessCommand(event); - return TRUE; - } - else - return FALSE; + // processed + return TRUE; } // For Rich Edit controls. Do we need it? #if 0 #if defined(__WIN95__) -bool wxTextCtrl::MSWNotify(const WXWPARAM wParam, const WXLPARAM lParam) +bool wxTextCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam) { wxCommandEvent event(0, m_windowId); int eventType = 0;