[ENHANCE] Enhance the horizontal scroll feature.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@82 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
50ad915434
commit
c7188766c8
|
@ -555,24 +555,6 @@ bool Notepad_plus::doOpen(const char *fileName, bool isReadOnly)
|
|||
if (_pEditView->increaseMaxNbDigit(nbDigit))
|
||||
_pEditView->setLineNumberWidth(_pEditView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER));
|
||||
|
||||
int maxLen = 0;
|
||||
int maxPixel = 0;
|
||||
int pixel = int(_pEditView->execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P"));
|
||||
|
||||
for( int i = 0 ; i < numLines ; i++ )
|
||||
{
|
||||
int len = _pEditView->getLineLength(i);
|
||||
if (maxLen < len)
|
||||
{
|
||||
maxLen = len;
|
||||
maxPixel = pixel * maxLen;
|
||||
}
|
||||
}
|
||||
|
||||
int currentWidth = int(_pEditView->execute(SCI_GETSCROLLWIDTH));
|
||||
if (currentWidth < maxPixel)
|
||||
_pEditView->execute(SCI_SETSCROLLWIDTH, maxPixel);
|
||||
|
||||
// Then replace the caret to the begining
|
||||
_pEditView->execute(SCI_GOTOPOS, 0);
|
||||
//dynamicCheckMenuAndTB();
|
||||
|
@ -1237,7 +1219,7 @@ void Notepad_plus::checkClipboard()
|
|||
enableCommand(IDM_EDIT_UPPERCASE, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_LOWERCASE, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_BLOCK_COMMENT, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_BLOCK_COMMENT_SET, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_BLOCK_COMMENT_SET, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_BLOCK_UNCOMMENT, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_STREAM_COMMENT, hasSelection, MENU);
|
||||
}
|
||||
|
@ -1896,7 +1878,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||
|
||||
case SCN_UPDATEUI:
|
||||
braceMatch();
|
||||
|
||||
_pEditView->recalcHorizontalScrollbar();
|
||||
// To update the line and the col status
|
||||
updateStatusBar();
|
||||
break;
|
||||
|
@ -2775,15 +2757,15 @@ void Notepad_plus::command(int id)
|
|||
break;
|
||||
|
||||
case IDM_EDIT_BLOCK_COMMENT:
|
||||
doBlockComment(cm_toggle);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_BLOCK_COMMENT_SET:
|
||||
doBlockComment(cm_comment);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_BLOCK_UNCOMMENT:
|
||||
doBlockComment(cm_uncomment);
|
||||
doBlockComment(cm_toggle);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_BLOCK_COMMENT_SET:
|
||||
doBlockComment(cm_comment);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_BLOCK_UNCOMMENT:
|
||||
doBlockComment(cm_uncomment);
|
||||
break;
|
||||
|
||||
case IDM_EDIT_STREAM_COMMENT:
|
||||
|
@ -3803,7 +3785,7 @@ void Notepad_plus::command(int id)
|
|||
case IDM_EDIT_UPPERCASE:
|
||||
case IDM_EDIT_LOWERCASE:
|
||||
case IDM_EDIT_BLOCK_COMMENT:
|
||||
case IDM_EDIT_BLOCK_COMMENT_SET:
|
||||
case IDM_EDIT_BLOCK_COMMENT_SET:
|
||||
case IDM_EDIT_BLOCK_UNCOMMENT:
|
||||
case IDM_EDIT_STREAM_COMMENT:
|
||||
case IDM_EDIT_TRIMTRAILING:
|
||||
|
|
|
@ -149,6 +149,17 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
|
|||
::SendMessage(_hParent, Message, wParam, lParam);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//Have to perform the scroll first, because the first/last line do not get updated untill after the scroll has been parsed
|
||||
LRESULT scrollResult = ::CallWindowProc(_scintillaDefaultProc, hwnd, Message, wParam, lParam);
|
||||
recalcHorizontalScrollbar();
|
||||
return scrollResult;
|
||||
break;
|
||||
}
|
||||
case WM_VSCROLL :
|
||||
{
|
||||
if (LOWORD(wParam) == SB_ENDSCROLL)
|
||||
recalcHorizontalScrollbar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1624,4 +1635,33 @@ void ScintillaEditView::columnReplace(const ColumnModeInfo & cmi, const char ch)
|
|||
execute(SCI_SETTARGETEND, cmi[i].second);
|
||||
execute(SCI_REPLACETARGET, -1, (LPARAM)str.c_str());
|
||||
}
|
||||
}
|
||||
//This method recalculates the horizontal scrollbar based
|
||||
//on the current visible text and styler.
|
||||
void ScintillaEditView::recalcHorizontalScrollbar() {
|
||||
int curOffset = execute(SCI_GETXOFFSET);
|
||||
int maxPixel = 0, curLen;
|
||||
int numLines = int(execute(SCI_GETLINECOUNT));
|
||||
int startLine = execute(SCI_GETFIRSTVISIBLELINE);
|
||||
int endLine = startLine + execute(SCI_LINESONSCREEN);
|
||||
if ( endLine >= (execute(SCI_GETLINECOUNT) - 1) )
|
||||
endLine--;
|
||||
long beginPosition, endPosition;
|
||||
|
||||
for( int i = startLine ; i <= endLine ; i++ ) { //for all _visible_ lines
|
||||
endPosition = execute(SCI_GETLINEENDPOSITION, i); //get character position from begin
|
||||
beginPosition = execute(SCI_POSITIONFROMLINE, i); //and end of line
|
||||
curLen = execute(SCI_POINTXFROMPOSITION, 0, endPosition) - //Then let Scintilla get pixel width with
|
||||
execute(SCI_POINTXFROMPOSITION, 0, beginPosition); //current styler
|
||||
if (maxPixel < curLen) { //If its the largest line yet
|
||||
maxPixel = curLen; //Use that length
|
||||
}
|
||||
}
|
||||
|
||||
if (maxPixel == 0)
|
||||
maxPixel++; //make sure maxPixel is valid
|
||||
|
||||
int currentLength = execute(SCI_GETSCROLLWIDTH); //Get current scrollbar size
|
||||
if (currentLength != maxPixel) //And if it is not the same
|
||||
execute(SCI_SETSCROLLWIDTH, maxPixel); //update it
|
||||
}
|
|
@ -582,6 +582,7 @@ public:
|
|||
void columnReplace(const ColumnModeInfo & cmi, const char ch);
|
||||
void columnReplace(ColumnModeInfo & cmi, int initial, int incr, unsigned char format);
|
||||
|
||||
void ScintillaEditView::recalcHorizontalScrollbar();
|
||||
protected:
|
||||
static HINSTANCE _hLib;
|
||||
static int _refCount;
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
#define IDM_EDIT_CLEARREADONLY (IDM_EDIT+33)
|
||||
#define IDM_EDIT_COLUMNMODE (IDM_EDIT+34)
|
||||
#define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT+35)
|
||||
#define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT+35)
|
||||
#define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT+36)
|
||||
|
||||
#define IDM_EDIT_AUTOCOMPLETE (50000+0)
|
||||
|
|
|
@ -1884,6 +1884,7 @@ void ScintillaWin::ScrollMessage(WPARAM wParam) {
|
|||
}
|
||||
|
||||
void ScintillaWin::HorizontalScrollMessage(WPARAM wParam) {
|
||||
SCROLLINFO si;
|
||||
int xPos = xOffset;
|
||||
PRectangle rcText = GetTextRectangle();
|
||||
int pageWidth = rcText.Width() * 2 / 3;
|
||||
|
@ -1910,10 +1911,16 @@ void ScintillaWin::HorizontalScrollMessage(WPARAM wParam) {
|
|||
xPos = scrollWidth;
|
||||
break;
|
||||
case SB_THUMBPOSITION:
|
||||
xPos = HiWord(wParam);
|
||||
break;
|
||||
//xPos = HiWord(wParam);
|
||||
//break;
|
||||
case SB_THUMBTRACK:
|
||||
xPos = HiWord(wParam);
|
||||
si.cbSize = sizeof(si);
|
||||
si.fMask = SIF_TRACKPOS;
|
||||
if (!GetScrollInfo(SB_HORZ, &si))
|
||||
break;
|
||||
//Do NOT use wParam, its 16 bit and not enough for very long lines. Its still possible to overflow the 32 bit but you have to try harder =]
|
||||
//xPos = HiWord(wParam);
|
||||
xPos = si.nTrackPos;
|
||||
break;
|
||||
}
|
||||
HorizontalScrollTo(xPos);
|
||||
|
|
Loading…
Reference in New Issue