X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/827fb0e455814783e74a0a211b408e788a386246..4e15d1caa03346c126015019c1fdf093033ef40b:/src/msw/textctrl.cpp diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 4e2171fbfe..66473a3e26 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -30,6 +30,7 @@ #include "wx/textctrl.h" #include "wx/settings.h" #include "wx/brush.h" + #include "wx/dcclient.h" #include "wx/utils.h" #include "wx/intl.h" #include "wx/log.h" @@ -63,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__) @@ -426,7 +423,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; @@ -1108,7 +1105,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) ) { @@ -1780,8 +1777,19 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* msg) // fall through case 0: - if ( IsMultiLine() && vkey == VK_RETURN ) - return false; + switch ( vkey ) + { + case VK_RETURN: + // This one is only special for multi line controls. + if ( !IsMultiLine() ) + break; + // fall through + + case VK_DELETE: + case VK_HOME: + case VK_END: + return false; + } // fall through case 2: break; @@ -2043,7 +2051,7 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) WXHBRUSH wxTextCtrl::MSWControlColor(WXHDC hDC, WXHWND hWnd) { - if ( !IsEnabled() && !HasFlag(wxTE_MULTILINE) ) + if ( !IsThisEnabled() && !HasFlag(wxTE_MULTILINE) ) return MSWControlColorDisabled(hDC); return wxTextCtrlBase::MSWControlColor(hDC, hWnd); @@ -2094,22 +2102,61 @@ 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 - // 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; + // Text controls without border are special and have the same height as + // static labels (they also have the same appearance when they're disable + // and are often used as a sort of copyable to the clipboard label so it's + // important that they have the same height as the normal labels to not + // 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); } @@ -2377,9 +2424,7 @@ bool wxTextCtrl::SetForegroundColour(const wxColour& colour) if ( IsRich() ) { // change the colour of everything - CHARFORMAT cf; - wxZeroMemory(cf); - cf.cbSize = sizeof(cf); + WinStruct cf; cf.dwMask = CFM_COLOR; cf.crTextColor = wxColourToRGB(colour); ::SendMessage(GetHwnd(), EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); @@ -2721,7 +2766,10 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) LOGFONT lf; - lf.lfHeight = cf.yHeight; + // Convert the height from the units of 1/20th of the point in which + // CHARFORMAT stores it to pixel-based units used by LOGFONT. + const wxCoord ppi = wxClientDC(this).GetPPI().y; + lf.lfHeight = -MulDiv(cf.yHeight/20, ppi, 72); lf.lfWidth = 0; lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset? lf.lfClipPrecision = 0;