X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6519b40fe9f5e4706e02497fe01ff71c65079d6..b152d8c56c72577b64de63f4d3b001db5d65f85f:/src/univ/textctrl.cpp diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 17ed256745..ee60b694c5 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -227,7 +227,7 @@ static const size_t PAGE_OVERLAP_IN_LINES = 1; // ---------------------------------------------------------------------------- // the data only used by single line text controls -struct WXDLLEXPORT wxTextSingleLineData +struct wxTextSingleLineData { // the position of the first visible pixel and the first visible column wxCoord m_ofsHorz; @@ -251,7 +251,7 @@ struct WXDLLEXPORT wxTextSingleLineData }; // the data only used by multi line text controls -struct WXDLLEXPORT wxTextMultiLineData +struct wxTextMultiLineData { // the lines of text wxArrayString m_lines; @@ -300,7 +300,7 @@ struct WXDLLEXPORT wxTextMultiLineData }; // the data only used by multi line text controls in line wrap mode -class WXDLLEXPORT wxWrappedLineData +class wxWrappedLineData { // these functions set all our values, so give them access to them friend void wxTextCtrl::LayoutLine(wxTextCoord line, @@ -460,7 +460,7 @@ WX_DECLARE_OBJARRAY(wxWrappedLineData, wxArrayWrappedLinesData); #include "wx/arrimpl.cpp" WX_DEFINE_OBJARRAY(wxArrayWrappedLinesData); -struct WXDLLEXPORT wxTextWrappedData : public wxTextMultiLineData +struct wxTextWrappedData : public wxTextMultiLineData { // the width of the column to the right of the text rect used for the // indicator mark display for the wrapped lines @@ -650,6 +650,7 @@ void wxTextCtrl::Init() m_isModified = false; m_isEditable = true; + m_wrapLines = false; m_posLast = m_curPos = @@ -695,9 +696,18 @@ bool wxTextCtrl::Create(wxWindow *parent, // create data object for normal multiline or for controls with line // wrap as needed if ( style & wxHSCROLL ) + { m_data.mdata = new wxTextMultiLineData; - else + } + else // we must wrap lines if we don't have horizontal scrollbar + { + // NB: we can't rely on HasFlag(wxHSCROLL) as the flags can change + // later and even wxWindow::Create() itself temporarily resets + // wxHSCROLL in wxUniv, so remember that we have a wrapped data + // and not just a multi line data in a separate variable + m_wrapLines = true; m_data.wdata = new wxTextWrappedData; + } } else { @@ -740,7 +750,7 @@ bool wxTextCtrl::Create(wxWindow *parent, RecalcFontMetrics(); SetValue(value); - SetBestSize(size); + SetInitialSize(size); m_isEditable = !(style & wxTE_READONLY); @@ -778,28 +788,27 @@ wxTextCtrl::~wxTextCtrl() // set/get the value // ---------------------------------------------------------------------------- -void wxTextCtrl::ChangeValue(const wxString& value) +void wxTextCtrl::DoSetValue(const wxString& value, int flags) { - if ( IsSingleLine() && (value == GetValue()) ) + if ( value != GetValue() ) { - // nothing changed - return; - } + EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent)); - Replace(0, GetLastPosition(), value); + Replace(0, GetLastPosition(), value); - if ( IsSingleLine() ) + if ( IsSingleLine() ) + { + SetInsertionPoint(0); + } + } + else // nothing changed { - SetInsertionPoint(0); + // still send event for consistency + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(); } } -void wxTextCtrl::SetValue(const wxString& value) -{ - ChangeValue(value); - SendTextUpdatedEvent(); -} - const wxArrayString& wxTextCtrl::GetLines() const { return MData().m_lines; @@ -1257,6 +1266,9 @@ void wxTextCtrl::Replace(wxTextPos from, wxTextPos to, const wxString& text) // now call it to do the rest (not related to refreshing) ClearSelection(); + + if ( EventsAllowed() ) + SendTextUpdatedEvent(); } void wxTextCtrl::Remove(wxTextPos from, wxTextPos to) @@ -1437,8 +1449,12 @@ wxString wxTextCtrl::GetSelectionText() const void wxTextCtrl::SetSelection(wxTextPos from, wxTextPos to) { // selecting till -1 is the same as selecting to the end - if ( to == -1 && from != -1 ) + if ( to == -1 ) { + // and selecting (-1, -1) range is the same as selecting everything, by + // convention + if ( from == -1 ) + from = 0; to = GetLastPosition(); } @@ -1954,7 +1970,7 @@ void wxTextCtrl::ShowPosition(wxTextPos pos) { // finding the last line is easy if each line has exactly // one row - yEnd = yStart + rectText.height / GetLineHeight() - 1; + yEnd = yStart + rectText.height / GetLineHeight(); } if ( yEnd < y ) @@ -2407,7 +2423,7 @@ void wxTextCtrl::UpdateTextRect() WData().m_rowFirstInvalid = 0; // increase timestamp: this means that the lines which had been - // laid out before will be relayd out the next time LayoutLines() + // laid out before will be relaid out the next time LayoutLines() // is called because their timestamp will be smaller than the // current one WData().m_timestamp++; @@ -2431,9 +2447,12 @@ void wxTextCtrl::UpdateLastVisible() { case wxTE_HT_BEYOND: // everything is visible + SData().m_ofsHorz = 0; + + SData().m_colStart = 0; SData().m_colLastVisible = text.length(); - // calc it below + // calculate it below SData().m_posLastVisible = -1; break; @@ -3251,7 +3270,7 @@ bool wxTextCtrl::GetLineAndRow(wxTextCoord row, fine for vertical scrolling as all lines have the same height but is rather ugly for horizontal scrolling if proportional font is used. This is why we manually update and use SData().m_ofsHorz which contains the length of the string - which is hidden beyond the left borde. An important property of text + which is hidden beyond the left border. An important property of text controls using this kind of scrolling is that an entire number of characters is always shown and that parts of characters never appear on display - neither in the leftmost nor rightmost positions. @@ -3266,7 +3285,7 @@ void wxTextCtrl::ShowHorzPosition(wxCoord pos) // pos is the logical position to show - // SData().m_ofsHorz is the fisrt logical position shown + // SData().m_ofsHorz is the first logical position shown if ( pos < SData().m_ofsHorz ) { // scroll backwards @@ -3601,8 +3620,12 @@ void wxTextCtrl::UpdateScrollbars() if ( scrollRangeXOld ) { - x *= scrollRangeX - m_rectText.width / charWidth; - x /= scrollRangeXOld - m_rectText.width / charWidth; + const int w = m_rectText.width / charWidth; + if ( w != scrollRangeXOld ) + { + x *= scrollRangeX - w; + x /= scrollRangeXOld - w; + } Scroll(x, y); } @@ -3735,7 +3758,7 @@ void wxTextCtrl::RefreshTextRange(wxTextPos start, wxTextPos end) { // intermediate line or the last one but we need to refresh it // until the end anyhow - do it - posCount = wxSTRING_MAXLEN; + posCount = wxString::npos; } else // last line { @@ -4179,6 +4202,7 @@ void wxTextCtrl::DoDraw(wxControlRenderer *renderer) // FIXME: is this really a bug in wxMSW? rectTextArea.width--; #endif // __WXMSW__ + dc.DestroyClippingRegion(); dc.SetClippingRegion(rectTextArea); // adjust for scrolling @@ -4286,9 +4310,6 @@ void wxTextCtrl::CreateCaret() { // FIXME use renderer caret = new wxCaret(this, 1, GetLineHeight()); -#ifndef __WXMSW__ - wxCaret::SetBlinkTime(0); -#endif // __WXMSW__ } else {