- if (horizontalScrollBarVisible) {
- if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar
- int sbMax = stc->GetScrollRange(wxHORIZONTAL);
- int sbThumb = stc->GetScrollThumb(wxHORIZONTAL);
- if ((sbMax != H_SCROLL_MAX) || (sbThumb != H_SCROLL_STEP)) {
- stc->SetScrollbar(wxHORIZONTAL, 0, H_SCROLL_STEP, H_SCROLL_MAX);
- modified = true;
+ // Check the horizontal scrollbar
+ PRectangle rcText = GetTextRectangle();
+ int horizEnd = scrollWidth;
+ if (horizEnd < 0)
+ horizEnd = 0;
+ if (!horizontalScrollBarVisible || (wrapState != eWrapNone))
+ horizEnd = 0;
+ int pageWidth = rcText.Width();
+
+ if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar
+ int sbMax = stc->GetScrollRange(wxHORIZONTAL);
+ int sbThumb = stc->GetScrollThumb(wxHORIZONTAL);
+ int sbPos = stc->GetScrollPos(wxHORIZONTAL);
+ if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
+ stc->SetScrollbar(wxHORIZONTAL, 0, pageWidth, horizEnd);
+ modified = true;
+ if (scrollWidth < pageWidth) {
+ HorizontalScrollTo(0);