Neil Hodgson wrote:
> Snow:
>
>> OK, good point. I've attached a revised patch that adds a field
>> Editor::currentPageWidth. This is updated in Paint(); and Idle() calls
>> SetScrollBars() when currentPageWidth != scrollWidth.
>
> This change makes the scroll width too variable I think: it will
> extend the scroll range when painting a wide line, but may also,
> sometimes, shrink the scroll range when moving to a narrow portion of
> the file. It should really only act to widen the range automatically.
Well, that was the intended behaviour. It mirrors how many of the
editors/IDEs that I use work. This gives the user a visual indication of
how wide the page is. If the scrollbar doesn't change width according to
the page width, you have to scroll to see how much is off the edge of
the screen.
See below for my proposed solution.
> I don't think that all interactions between scrollWidth and
> currentPageWidth are well defined: currentPageWidth should have a
> defined invalid setting, probably 0 so that setting it is a signal
> rather than a state.
currentPageWidth is the width of the page that is visible. scrollWidth
is the width of the scrollbar. If they aren't equal then scrollWidth is
set to currentPageWidth and the scrollbars updated. What else is there
to be defined?
I can make 0 an invalid setting, but what do you want it to do?
> For clients that call SCI_SETSCROLLWIDTH, it should be possible to
> enable / disable the automatic sizing mechanism.
>
> The use of SIF_DISABLENOSCROLL means that there is always a visible
> scroll bar even when not needed which decreases the amount of text
> visible and will make Scintilla less useful for those using it for
> small entry boxes.
I've change SCI_SETHSCROLLBAR so it takes a bitmap instead of a bool.
Possible values are:
SC_HSCROLL_NEVER 0 // Never show the h-scrollbar
SC_HSCROLL_SHOW 1 // Show the h-scrollbar
SC_HSCROLL_AUTOHIDE 2 // Hide the h-scrollbar if not needed.
SC_HSCROLL_AUTOGROW 4 // Increase the h-scroll size if required.
SC_HSCROLL_AUTOSIZE 8 // Increase/decrease the h-scroll size if required.
SC_HSCROLL_SHOW on its own means a fixed-size h-scrollbar.
SC_HSCROLL_AUTOHIDE | SC_HSCROLL_SHOW will only show the scrollbar if
needed.
One combination that shouldn't be used is SC_HSCROLL_AUTOSIZE and
SC_HSCROLL_AUTOHIDE. If the last line on the page is the only one long
enough to need a scrollbar then the scrollbar is added. But the
h-scrollbar covers the last line of the page, so there is now no need
for the h-scrollbar. So it is auto-hidden. But now it is needed
again...this causes the h-scrollbar to flicker on and off.
> The workaround double call to ShowScrollBar looks like covering up
> a problem that may be more tightly definable.
This turned out to be a problem in notepad2, not Scintilla. I've fixed
it there instead.
Note: I've changed Scintilla.iface, but my version of Python doesn't
like the autogen script, so I haven't tested it.
--
Snow
diff -r -u scin-base/include/Scintilla.h scin-scroll/include/Scintilla.h
--- scin-base/include/Scintilla.h 2006-02-25 23:58:22.000000000 +0000
+++ scin-scroll/include/Scintilla.h 2006-04-09 17:38:14.000000000 +0100
@@ -691,6 +691,12 @@
#define SCN_AUTOCSELECTION 2022
//--Autogenerated -- end of section automatically generated from
Scintilla.iface
+#define SC_HSCROLL_NEVER 0
+#define SC_HSCROLL_SHOW 1
+#define SC_HSCROLL_AUTOHIDE 2
+#define SC_HSCROLL_AUTOGROW 4
+#define SC_HSCROLL_AUTOSIZE 8
+
// These structures are defined to be exactly the same shape as the Win32
// CHARRANGE, TEXTRANGE, FINDTEXTEX, FORMATRANGE, and NMHDR structs.
// So older code that treats Scintilla as a RichEdit will work.
diff -r -u scin-base/include/Scintilla.iface scin-scroll/include/Scintilla.iface
--- scin-base/include/Scintilla.iface 2006-04-09 17:12:48.000000000 +0100
+++ scin-scroll/include/Scintilla.iface 2006-04-09 17:39:40.000000000 +0100
@@ -654,11 +654,19 @@
# Retrieve the column number of a position, taking tab width into account.
get int GetColumn=2129(position pos,)
-# Show or hide the horizontal scroll bar.
-set void SetHScrollBar=2130(bool show,)
+enu HorzScrollBehaviour=SC_HSCROLL_
+val SC_HSCROLL_NEVER=0
+val SC_HSCROLL_SHOW=1
+val SC_HSCROLL_AUTOHIDE=2
+val SC_HSCROLL_AUTOGROW=4
+val SC_HSCROLL_AUTOSIZE=8
+
+# Set the horizontal scrollbar's behaviour using one of the SC_HSCROLL_*
+# constants.
+set void SetHScrollBar=2130(int show,)
-# Is the horizontal scroll bar visible?
-get bool GetHScrollBar=2131(,)
+# Get the horizontal scrollbar's behavior.
+get int GetHScrollBar=2131(,)
# Show or hide indentation guides.
set void SetIndentationGuides=2132(bool show,)
diff -r -u scin-base/src/Editor.cxx scin-scroll/src/Editor.cxx
--- scin-base/src/Editor.cxx 2006-03-14 10:11:08.000000000 +0000
+++ scin-scroll/src/Editor.cxx 2006-04-09 18:11:12.000000000 +0100
@@ -384,8 +384,9 @@
xOffset = 0;
xCaretMargin = 50;
- horizontalScrollBarVisible = true;
- scrollWidth = 2000;
+ horizontalScrollBarVisible = SC_HSCROLL_AUTOSIZE;
+ scrollWidth = 1;
+ currentPageWidth = scrollWidth;
verticalScrollBarVisible = true;
endAtLastLine = true;
caretSticky = false;
@@ -1446,7 +1447,7 @@
xOffset = xOffsetNew;
if (xOffsetNew > 0) {
PRectangle rcText = GetTextRectangle();
- if (horizontalScrollBarVisible == true &&
+ if (horizontalScrollBarVisible !=
SC_HSCROLL_NEVER &&
rcText.Width() + xOffset > scrollWidth)
{
scrollWidth = xOffset + rcText.Width();
SetScrollBars();
@@ -2831,6 +2832,8 @@
rcTextArea.right -= vs.rightMarginWidth;
surfaceWindow->SetClip(rcTextArea);
+ int textAreaWidth = rcTextArea.right - rcTextArea.left - 1;
+ int dispScrollWidth = textAreaWidth;
// Loop on visible lines
//double durLayout = 0.0;
//double durPaint = 0.0;
@@ -2875,6 +2878,9 @@
ll->containsCaret = false;
}
+ int lineLength =
ll->positions[ll->numCharsInLine];
+ dispScrollWidth = lineLength > dispScrollWidth
? lineLength : dispScrollWidth;
+
GetHotSpotRange(ll->hsStart, ll->hsEnd);
PRectangle rcLine = rcClient;
@@ -3017,6 +3023,27 @@
//if (durPaint < 0.00000001)
// durPaint = 0.00000001;
+ // If we are scrolled too far right for this page,
+ // make the scrollbars bigger.
+ if (dispScrollWidth < xOffset + textAreaWidth) {
+ dispScrollWidth = xOffset + textAreaWidth;
+ }
+
+ // If the needed width is bigger increase it, if the needed width is
more than 50
+ // smaller and we have painted the whole screen decrease it.
+ if (horizontalScrollBarVisible & SC_HSCROLL_AUTOSIZE) {
+ if (dispScrollWidth > scrollWidth ||
+ (scrollWidth - dispScrollWidth > 50 &&
rcClient.Height() == rcArea.Height())) {
+ currentPageWidth = dispScrollWidth;
+ SetIdle(true);
+ }
+ } else if (horizontalScrollBarVisible & SC_HSCROLL_AUTOGROW) {
+ if(dispScrollWidth > scrollWidth) {
+ currentPageWidth = dispScrollWidth;
+ SetIdle(true);
+ }
+ }
+
// Right column limit indicator
PRectangle rcBeyondEOF = rcClient;
rcBeyondEOF.left = vs.fixedColumnWidth;
@@ -5400,6 +5427,12 @@
wrappingDone = true;
}
+ if ((horizontalScrollBarVisible & (SC_HSCROLL_AUTOGROW |
SC_HSCROLL_AUTOSIZE)) &&
+ currentPageWidth != scrollWidth) {
+ scrollWidth = currentPageWidth;
+ SetScrollBars();
+ }
+
// Add more idle things to do here, but make sure idleDone is
// set correctly before the function returns. returning
// false will stop calling this idle funtion until SetIdle() is
@@ -6435,8 +6468,8 @@
return pdoc->FindColumn(wParam, lParam);
case SCI_SETHSCROLLBAR :
- if (horizontalScrollBarVisible != (wParam != 0)) {
- horizontalScrollBarVisible = wParam != 0;
+ if (horizontalScrollBarVisible != static_cast<int>(wParam)) {
+ horizontalScrollBarVisible = wParam;
SetScrollBars();
ReconfigureScrollBars();
}
diff -r -u scin-base/src/Editor.h scin-scroll/src/Editor.h
--- scin-base/src/Editor.h 2005-12-09 21:22:10.000000000 +0000
+++ scin-scroll/src/Editor.h 2006-04-09 17:47:50.000000000 +0100
@@ -216,8 +216,9 @@
int xOffset; ///< Horizontal scrolled amount in pixels
int xCaretMargin; ///< Ensure this many pixels visible on both
sides of caret
- bool horizontalScrollBarVisible;
+ int horizontalScrollBarVisible;
int scrollWidth;
+ int currentPageWidth;
bool verticalScrollBarVisible;
bool endAtLastLine;
bool caretSticky;
diff -r -u scin-base/win32/ScintillaWin.cxx scin-scroll/win32/ScintillaWin.cxx
--- scin-base/win32/ScintillaWin.cxx 2006-02-25 23:58:22.000000000 +0000
+++ scin-scroll/win32/ScintillaWin.cxx 2006-04-09 18:02:48.000000000 +0100
@@ -1105,16 +1105,17 @@
int horizEndPreferred = scrollWidth;
if (horizEndPreferred < 0)
horizEndPreferred = 0;
- if (!horizontalScrollBarVisible || (wrapState != eWrapNone))
+ if (horizontalScrollBarVisible == SC_HSCROLL_NEVER || (wrapState !=
eWrapNone))
horizEndPreferred = 0;
unsigned int pageWidth = rcText.Width();
- sci.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(SB_HORZ, &sci);
if ((sci.nMin != 0) ||
(sci.nMax != horizEndPreferred) ||
(sci.nPage != pageWidth) ||
(sci.nPos != 0)) {
sci.fMask = SIF_PAGE | SIF_RANGE;
+ if (horizEndPreferred != 0 && (horizontalScrollBarVisible &
SC_HSCROLL_AUTOHIDE) == 0)
+ sci.fMask |= SIF_DISABLENOSCROLL;
sci.nMin = 0;
sci.nMax = horizEndPreferred;
sci.nPage = pageWidth;
@@ -1124,7 +1125,7 @@
modified = true;
if (scrollWidth < static_cast<int>(pageWidth)) {
HorizontalScrollTo(0);
- }
+ }
}
return modified;
}
_______________________________________________
Scintilla-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scintilla-interest