[NEW_FEATURE] Doc map: Processing text wrapping situation (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@874 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2012-03-04 18:04:36 +00:00
parent d6f66b1d73
commit da8fdbb86a
5 changed files with 149 additions and 22 deletions

View File

@ -2777,6 +2777,7 @@ int Notepad_plus::switchEditViewTo(int gid)
}
if (!viewVisible(gid))
return currentView(); //cannot activate invisible view
int oldView = currentView();
int newView = otherView();
@ -2792,6 +2793,11 @@ int Notepad_plus::switchEditViewTo(int gid)
_pEditView->beSwitched();
_pEditView->getFocus(); //set the focus
if (_pDocMap)
{
_pDocMap->initWrapMap();
}
notifyBufferActivated(_pEditView->getCurrentBufferID(), currentView());
return oldView;
}
@ -2941,7 +2947,6 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode)
bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
{
//scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED
Buffer * pBuf = MainFileManager->getBufferByID(id);
bool reload = pBuf->getNeedReload();
if (reload)
@ -2968,6 +2973,7 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
{
performPostReload(whichOne);
}
notifyBufferActivated(id, whichOne);
//scnN.nmhdr.code = NPPN_DOCSWITCHINGIN; //superseeded by NPPN_BUFFERACTIVATED
@ -4763,10 +4769,15 @@ void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int
void Notepad_plus::launchDocMap()
{
if (!(NppParameters::getInstance())->isTransparentAvailable())
{
::MessageBox(NULL, TEXT("It seems you still use a prehistoric system, This feature works only on a modern system, sorry."), TEXT(""), MB_OK);
return;
}
if (!_pDocMap)
{
_pDocMap = new DocumentMap();
_pDocMap->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), &_pEditView);
tTbData data = {0};
@ -4783,7 +4794,20 @@ void Notepad_plus::launchDocMap()
// In the case of Notepad++ internal function, it'll be the command ID which triggers this dialog
data.dlgID = IDM_VIEW_DOC_MAP;
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
_pDocMap->setMainEditorWrap(_pEditView->isWrap());
}
else
{
// Disable wrap text
if (!_pDocMap->isVisible())
{
_pDocMap->setMainEditorWrap(_pEditView->isWrap());
}
}
//_mainEditView.wrap(false);
//_subEditView.wrap(false);
_pDocMap->display();
}

View File

@ -22,6 +22,7 @@
#include "TaskListDlg.h"
#include "clipboardFormats.h"
#include "VerticalFileSwitcher.h"
#include "documentMap.h"
void Notepad_plus::macroPlayback(Macro macro)
{
@ -1146,6 +1147,8 @@ void Notepad_plus::command(int id)
}
case IDM_VIEW_WRAP:
{
//if (_pDocMap && !_pDocMap->isVisible())
{
bool isWraped = !_pEditView->isWrap();
_mainEditView.wrap(isWraped);
@ -1155,6 +1158,7 @@ void Notepad_plus::command(int id)
ScintillaViewParams & svp1 = (ScintillaViewParams &)(NppParameters::getInstance())->getSVP();
svp1._doWrap = isWraped;
}
break;
}
case IDM_VIEW_WRAP_SYMBOL:

View File

@ -38,11 +38,111 @@ void DocumentMap::reloadMap()
// folding
_pScintillaEditView->syncFoldStateWith((*_ppEditView)->getCurrentFoldStates());
// Wrapping
//wrapMap();
scrollMap();
}
}
void DocumentMap::initWrapMap()
{
if (_pScintillaEditView && _ppEditView)
{
RECT rect;
getClientRect(rect);
::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, rect.right - rect.left, rect.bottom-rect.top, TRUE);
_pScintillaEditView->wrap(false);
_pScintillaEditView->redraw(true);
}
}
void DocumentMap::wrapMap()
{
RECT rect;
getClientRect(rect);
//::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, rect.right - rect.left, rect.bottom-rect.top, TRUE);
//_pScintillaEditView->wrap(false);
//_pScintillaEditView->redraw();
if ((*_ppEditView)->isWrap())
{
// get model line N from current document
/*
for each docline
nbline = SCI_WRAPCOUNT(int docLine)
if (nbline == 1)
if maxNbChar < nbChar(docline)
pLine = docLine
maxChar = nbChar(docline)
return pLine
*/
int maxChar = 0;
int nbWrappedDocLine = 0;
int pLine = -1;
int nbDocLine = (*_ppEditView)->execute(SCI_GETLINECOUNT);
for (int i = 0; i < nbDocLine; i++)
{
int nbWrapLine = (*_ppEditView)->execute(SCI_WRAPCOUNT, i);
if (nbWrapLine == 1)
{
int charCount = (*_ppEditView)->execute(SCI_LINELENGTH, i);
if (charCount > maxChar)
{
maxChar = charCount;
pLine = i;
}
}
else
{
nbWrappedDocLine++;
}
}
if (pLine == -1 || !nbWrappedDocLine)
return;
// get Xlength1 (Xend - Xbegin) from current document line N
int posBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, pLine);
int posEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, pLine);
int xBegin = (*_ppEditView)->execute(SCI_POINTXFROMPOSITION, 0, posBegin);
int xEnd = (*_ppEditView)->execute(SCI_POINTXFROMPOSITION, 0, posEnd);
int Xlength1 = xEnd - xBegin;
// get Xlength2 (Xend - Xbegin) from map line N
int xBegin2 = _pScintillaEditView->execute(SCI_POINTXFROMPOSITION, 0, posBegin);
int xEnd2 = _pScintillaEditView->execute(SCI_POINTXFROMPOSITION, 0, posEnd);
int Xlength2 = xEnd2 - xBegin2;
// get current scintilla width W1
RECT editorRect;
(*_ppEditView)->getClientRect(editorRect);
int marginWidths = 0;
for (int m = 0; m < 4; m++)
{
marginWidths += (*_ppEditView)->execute(SCI_GETMARGINWIDTHN, m);
}
int w1 = editorRect.right - editorRect.left - marginWidths;
// resize map width W2 according W1, Xlength1 and Xlength2
int w2 = (w1 * Xlength2)/Xlength1;
::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, w2, rect.bottom-rect.top, TRUE);
_pScintillaEditView->wrap(true);
// sync wrapping indent mode
_pScintillaEditView->execute(SCI_SETWRAPINDENTMODE, (*_ppEditView)->execute(SCI_GETWRAPINDENTMODE));
}
}
void DocumentMap::scrollMap()
{
if (_pScintillaEditView && _ppEditView)
@ -188,6 +288,7 @@ BOOL CALLBACK DocumentMap::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
/*
if (_pScintillaEditView->isWrap())
{
int mapStringWidth = _pScintillaEditView->execute(SCI_TEXTWIDTH, 0, (LPARAM)"aiueolW");
@ -200,7 +301,7 @@ BOOL CALLBACK DocumentMap::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
{
::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, width , height, TRUE);
}
*/
if (_vzDlg.isCreated())
{
POINT pt = {0,0};
@ -303,17 +404,6 @@ BOOL CALLBACK DocumentMap::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
}
scrollMap();
/*
int newHigher = newPosY - (currentHeight / 2);
int newLower = newPosY + (currentHeight / 2);
if (newHigher < 0)
{
newHigher = 0;
newLower = currentHeight;
}
*/
}
return TRUE;

View File

@ -102,10 +102,18 @@ public:
//void wrapScintilla(bool doWrap);
void reloadMap();
void wrapMap();
void initWrapMap();
void scrollMap();
void scrollMap(bool direction, moveMode whichMode);
void doMove();
void fold(int line, bool foldOrNot);
void setMainEditorWrap(bool isWrap) {
_isMainEditorWrap = isWrap;
};
bool isMainEditorWrap() const {
return _isMainEditorWrap;
};
protected:
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -115,6 +123,7 @@ private:
ScintillaEditView *_pScintillaEditView;
//HWND _glassHandle;
ViewZoneDlg _vzDlg;
bool _isMainEditorWrap;
};

View File

@ -325,7 +325,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="false"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel;..\src\WinControls\FindCharsInRange;..\src\WinControls\ClipboardHistory;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\ProjectPanel"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel;..\src\WinControls\FindCharsInRange;..\src\WinControls\ClipboardHistory;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\ProjectPanel;..\src\WinControls\DocumentMap"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS=1"
StringPooling="true"
ExceptionHandling="2"