X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c6b938377211da1987c8b6e44134fb0f32c84df..43c42c18d36c703a88b1b7b697bac27fe5608eca:/src/msw/textctrl.cpp diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 4f02fbaf85..36cd9dee90 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -64,10 +64,6 @@ #if wxUSE_RICHEDIT -#if wxUSE_INKEDIT -#include "wx/dynlib.h" -#endif - // old mingw32 has richedit stuff directly in windows.h and doesn't have // richedit.h at all #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) @@ -78,6 +74,11 @@ #include "wx/msw/missing.h" +// FIXME-VC6: This seems to be only missing from VC6 headers. +#ifndef SPI_GETCARETWIDTH + #define SPI_GETCARETWIDTH 0x2006 +#endif + #if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT // dummy value used for m_dropTarget, different from any valid pointer value @@ -427,7 +428,7 @@ bool wxTextCtrl::MSWCreateText(const wxString& value, // implementation detail m_updatesCount = -2; - if ( !MSWCreateControl(windowClass.wx_str(), msStyle, pos, size, valueWin) ) + if ( !MSWCreateControl(windowClass.t_str(), msStyle, pos, size, valueWin) ) return false; m_updatesCount = -1; @@ -498,7 +499,37 @@ bool wxTextCtrl::MSWCreateText(const wxString& value, SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE| SWP_FRAMECHANGED); -#endif + + if ( IsSingleLine() ) + { + // If we don't set the margins explicitly, their size depends on the + // control initial size, see #2438. So explicitly set them to something + // consistent. And for this we have 2 candidates: EC_USEFONTINFO (which + // sets the left margin to 3 pixels, at least under Windows 7) or 0. We + // use the former because it looks like it was meant to be used as the + // default (what else would it be there for?) and 0 looks bad in + // classic mode, i.e. without themes. Also, the margin can be reset to + // 0 easily by calling SetMargins() explicitly but setting it to the + // default value is not currently supported. + // + // Finally, notice that EC_USEFONTINFO is used differently for plain + // and rich text controls. + WPARAM wParam; + LPARAM lParam; + if ( IsRich() ) + { + wParam = EC_USEFONTINFO; + lParam = 0; + } + else // plain EDIT, EC_USEFONTINFO is used in lParam with them. + { + wParam = EC_LEFTMARGIN | EC_RIGHTMARGIN; + lParam = MAKELPARAM(EC_USEFONTINFO, EC_USEFONTINFO); + } + + ::SendMessage(GetHwnd(), EM_SETMARGINS, wParam, lParam); + } +#endif // !__WXWINCE__ return true; } @@ -992,7 +1023,7 @@ wxTextCtrl::StreamOut(wxFontEncoding encoding, bool selectionOnly) const EDITSTREAM eds; wxZeroMemory(eds); - eds.dwCookie = (DWORD)&data; + eds.dwCookie = (DWORD_PTR)&data; eds.pfnCallback = wxRichEditStreamOut; ::SendMessage @@ -1109,7 +1140,7 @@ void wxTextCtrl::DoWriteText(const wxString& value, int flags) ::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT, // EM_REPLACESEL takes 1 to indicate the operation should be redoable - selectionOnly ? 1 : 0, (LPARAM)valueDos.wx_str()); + selectionOnly ? 1 : 0, wxMSW_CONV_LPARAM(valueDos)); if ( !ucf.GotUpdate() && (flags & SetValue_SendEvent) ) { @@ -1832,7 +1863,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) { case WXK_RETURN: { - wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); InitCommandEvent(event); event.SetString(GetValue()); if ( HandleWindowEvent(event) ) @@ -2035,7 +2066,7 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) // the text size limit has been hit -- try to increase it if ( !AdjustSpaceLimit() ) { - wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, m_windowId); + wxCommandEvent event(wxEVT_TEXT_MAXLEN, m_windowId); InitCommandEvent(event); event.SetString(GetValue()); ProcessCommand(event); @@ -2106,18 +2137,42 @@ bool wxTextCtrl::AcceptsFocusFromKeyboard() const } wxSize wxTextCtrl::DoGetBestSize() const +{ + return DoGetSizeFromTextSize( DEFAULT_ITEM_WIDTH ); +} + +wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const { int cx, cy; wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); - int wText = DEFAULT_ITEM_WIDTH; + DWORD wText = 1; + ::SystemParametersInfo(SPI_GETCARETWIDTH, 0, &wText, 0); + wText += xlen; int hText = cy; if ( m_windowStyle & wxTE_MULTILINE ) { - hText *= wxMax(wxMin(GetNumberOfLines(), 10), 2); + // add space for vertical scrollbar + if ( !(m_windowStyle & wxTE_NO_VSCROLL) ) + wText += ::GetSystemMetrics(SM_CXVSCROLL); + + if ( ylen <= 0 ) + { + hText *= wxMax(wxMin(GetNumberOfLines(), 10), 2); + // add space for horizontal scrollbar + if ( m_windowStyle & wxHSCROLL ) + hText += ::GetSystemMetrics(SM_CYHSCROLL); + } + } + // for single line control cy (height + external leading) is ok + else + { + // Add the margins we have previously set + wxPoint marg( GetMargins() ); + wText += wxMax(0, marg.x); + hText += wxMax(0, marg.y); } - //else: for single line control everything is ok // Text controls without border are special and have the same height as // static labels (they also have the same appearance when they're disable @@ -2126,11 +2181,18 @@ wxSize wxTextCtrl::DoGetBestSize() const // stand out). if ( !HasFlag(wxBORDER_NONE) ) { + wText += 9; // borders and inner margins + // we have to add the adjustments for the control height only once, not // once per line, so do it after multiplication above hText += EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) - cy; } + // Perhaps the user wants something different from CharHeight, or ylen + // is used as the height of a multiline text. + if ( ylen > 0 ) + hText += ylen - GetCharHeight(); + return wxSize(wText, hText); }