[UPDATE] line numbers margin width is changed dynamically according to the needed space (but keeping at least 3 digits).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@450 f5eea248-9336-0410-98b8-ebc06183d4e3
pull/343/head^2
yniq 2009-04-13 08:35:56 +00:00
parent 6ed92acab2
commit 1175b82052
3 changed files with 39 additions and 25 deletions

View File

@ -2600,7 +2600,6 @@ BOOL Notepad_plus::notify(SCNotification *notification)
break;
case SCN_ZOOM:
notifyView->setLineNumberWidth(notifyView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER));
break;
case SCN_MACRORECORD:
@ -2609,6 +2608,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case SCN_PAINTED:
{
notifyView->updateLineNumberWidth();
if (_syncInfo.doSync())
doSynScorll(HWND(notification->nmhdr.hwndFrom));

View File

@ -32,8 +32,6 @@ const int ScintillaEditView::_SC_MARGE_SYBOLE = 1;
const int ScintillaEditView::_SC_MARGE_FOLDER = 2;
const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3;
const int ScintillaEditView::_MARGE_LINENUMBER_NB_CHIFFRE = 5;
WNDPROC ScintillaEditView::_scintillaDefaultProc = NULL;
/*
SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree
@ -1394,9 +1392,6 @@ void ScintillaEditView::activateBuffer(BufferID buffer)
itoa(numLines, numLineStr, 10);
int nbDigit = strlen(numLineStr);
if (increaseMaxNbDigit(nbDigit))
setLineNumberWidth(hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER));
runMarkers(true, 0, true, false);
return; //all done
}

View File

@ -149,7 +149,7 @@ class ScintillaEditView : public Window
public:
ScintillaEditView()
: Window(), _pScintillaFunc(NULL),_pScintillaPtr(NULL),
_folderStyle(FOLDER_STYLE_BOX), _maxNbDigit(_MARGE_LINENUMBER_NB_CHIFFRE), _wrapRestoreNeeded(false)
_folderStyle(FOLDER_STYLE_BOX), _lineNumbersShown(false), _wrapRestoreNeeded(false)
{
++_refCount;
};
@ -247,11 +247,9 @@ public:
static const int _SC_MARGE_FOLDER;
static const int _SC_MARGE_MODIFMARKER;
static const int _MARGE_LINENUMBER_NB_CHIFFRE;
void showMargin(int whichMarge, bool willBeShowed = true) {
if (whichMarge == _SC_MARGE_LINENUMBER)
setLineNumberWidth(willBeShowed);
showLineNumbersMargin(willBeShowed);
else
{
int width = 3;
@ -380,11 +378,41 @@ public:
void setLineIndent(int line, int indent) const;
void setLineNumberWidth(bool willBeShowed = true) {
// The 4 here allows for spacing: 1 poxel on left and 3 on right.
int pixelWidth = int((willBeShowed)?(8 + _maxNbDigit * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8")):0);
execute(SCI_SETMARGINWIDTHN, 0, pixelWidth);
};
void showLineNumbersMargin(bool show){
if (show == _lineNumbersShown) return;
_lineNumbersShown = show;
if (show)
{
updateLineNumberWidth();
}
else
{
execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, 0);
}
}
void updateLineNumberWidth() {
if (_lineNumbersShown)
{
int linesVisible = (int) execute(SCI_LINESONSCREEN);
if (linesVisible)
{
int firstVisibleLineVis = (int) execute(SCI_GETFIRSTVISIBLELINE);
int lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1;
int i = 0;
while (lastVisibleLineVis)
{
lastVisibleLineVis /= 10;
i++;
}
i = max(i, 3);
{
int pixelWidth = int(8 + i * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8"));
execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth);
}
}
}
};
void setCurrentLineHiLiting(bool isHiliting, COLORREF bgColor) const {
execute(SCI_SETCARETLINEVISIBLE, isHiliting);
@ -448,15 +476,6 @@ public:
void foldCurrentPos(bool mode);
int getCodepage() const {return _codepage;};
bool increaseMaxNbDigit(int newValue) {
if (newValue > _maxNbDigit)
{
_maxNbDigit = newValue;
return true;
}
return false;
};
NppParameters * getParameter() {
return _pParameter;
};
@ -579,7 +598,7 @@ protected:
int _codepage;
int _oemCodepage;
int _maxNbDigit; // For Line Number Marge
bool _lineNumbersShown;
bool _wrapRestoreNeeded;