now cache GetCharWidth() too (and not only height)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8856 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-11-28 17:19:11 +00:00
parent be18e65726
commit 8c27f612e5
2 changed files with 22 additions and 11 deletions

View File

@@ -394,8 +394,11 @@ protected:
return m_heightLine;
}
// recalc the line height (to call when the font changes)
void RecalcLineHeight();
// get the average char width
wxCoord GetAverageWidth() const { return m_widthAvg; }
// recalc the line height and char width (to call when the font changes)
void RecalcFontMetrics();
// event handlers
void OnIdle(wxIdleEvent& event);
@@ -461,6 +464,9 @@ private:
// the height of one line (cached value of GetCharHeight)
wxCoord m_heightLine;
// and the average char width (cached value of GetCharWidth)
wxCoord m_widthAvg;
// we have some data which depends on the kind of control (single or multi
// line)
union

View File

@@ -392,7 +392,8 @@ void wxTextCtrl::Init()
m_curCol =
m_curRow = 0;
m_heightLine = -1;
m_heightLine =
m_widthAvg = -1;
// init wxScrollHelper
SetWindow(this);
@@ -463,7 +464,7 @@ bool wxTextCtrl::Create(wxWindow *parent,
_T("wxTE_PASSWORD can't be used with multiline ctrls") );
}
RecalcLineHeight();
RecalcFontMetrics();
SetValue(value);
SetBestSize(size);
@@ -1520,8 +1521,8 @@ void wxTextCtrl::ShowPosition(wxTextPos pos)
// (i.e. the current character)
// make xStart the first visible pixel (and not position)
int wChar = GetCharWidth();
xStart *= GetCharWidth();
int wChar = GetAverageWidth();
xStart *= wChar;
if ( x < xStart )
{
@@ -1859,7 +1860,7 @@ wxSize wxTextCtrl::DoGetBestClientSize() const
wxCoord w, h;
GetTextExtent(GetTextToShow(GetLineText(0)), &w, &h);
int wChar = GetCharWidth(),
int wChar = GetAverageWidth(),
hChar = GetLineHeight();
int widthMin = wxMax(10*wChar, 100);
@@ -2180,7 +2181,10 @@ wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line,
// we use the first character of the line instead of (average)
// GetCharWidth(): it is common to have lines of dashes, for example,
// and this should give us much better approximation in such case
//
// OPT: maybe using (cache) m_widthAvg would be still faster? profile!
dc.GetTextExtent(line[0], &width, NULL);
col = x / width;
if ( col < 0 )
{
@@ -2712,9 +2716,10 @@ void wxTextCtrl::UpdateMaxWidth(wxTextCoord line)
MData().m_updateScrollbarX = MData().m_widthMax != widthMaxOld;
}
void wxTextCtrl::RecalcLineHeight()
void wxTextCtrl::RecalcFontMetrics()
{
m_heightLine = GetCharHeight();
m_widthAvg = GetCharWidth();
}
void wxTextCtrl::RecalcMaxWidth()
@@ -2770,7 +2775,7 @@ void wxTextCtrl::UpdateScrollbars()
bool showScrollbarX;
if ( !WrapLines() )
{
charWidth = GetCharWidth();
charWidth = GetAverageWidth();
maxWidth = GetMaxWidth();
showScrollbarX = maxWidth > size.x;
}
@@ -3326,7 +3331,7 @@ bool wxTextCtrl::SetFont(const wxFont& font)
// update geometry parameters
UpdateTextRect();
UpdateScrollbars();
RecalcLineHeight();
RecalcFontMetrics();
RecalcMaxWidth();
Refresh();