From 79eba94cba0578e05b11ac26ebbb5906e865ae19 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 31 Aug 2009 00:27:35 +0000 Subject: [PATCH] [ADAPTATION] Make existing Column mode operations work with Scintilla 2.01 (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@528 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../installer/nativeLang/hungarian.xml | 33 +- .../installer/nativeLang/hungarianA.xml | 33 +- PowerEditor/installer/nativeLang/kazakh.xml | 168 +-- .../MISC/PluginsManager/Notepad_plus_msgs.h | 2 +- PowerEditor/src/Notepad_plus.cpp | 4 +- .../ScitillaComponent/ScintillaEditView.cpp | 340 +++-- .../src/ScitillaComponent/ScintillaEditView.h | 36 +- .../src/ScitillaComponent/columnEditor.cpp | 225 +++- .../visual.net/notepadPlus.vc.7.0.vcproj | 1091 ----------------- 9 files changed, 542 insertions(+), 1390 deletions(-) delete mode 100644 PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj diff --git a/PowerEditor/installer/nativeLang/hungarian.xml b/PowerEditor/installer/nativeLang/hungarian.xml index 491008cb0..603c36b99 100644 --- a/PowerEditor/installer/nativeLang/hungarian.xml +++ b/PowerEditor/installer/nativeLang/hungarian.xml @@ -1,4 +1,6 @@ + + @@ -75,7 +77,7 @@ - + @@ -88,7 +90,7 @@ - + @@ -100,7 +102,7 @@ - + @@ -123,7 +125,7 @@ - + @@ -149,9 +151,9 @@ - + - + @@ -166,7 +168,7 @@ - + @@ -234,7 +236,6 @@ - @@ -258,14 +259,13 @@ - + - @@ -383,11 +383,6 @@ - - - - - @@ -404,7 +399,7 @@ - + @@ -425,10 +420,13 @@ - + + + + @@ -456,6 +454,7 @@ + diff --git a/PowerEditor/installer/nativeLang/hungarianA.xml b/PowerEditor/installer/nativeLang/hungarianA.xml index b3f6282ad..dd86aa98b 100644 --- a/PowerEditor/installer/nativeLang/hungarianA.xml +++ b/PowerEditor/installer/nativeLang/hungarianA.xml @@ -1,4 +1,6 @@ + + @@ -75,7 +77,7 @@ - + @@ -88,7 +90,7 @@ - + @@ -100,7 +102,7 @@ - + @@ -123,7 +125,7 @@ - + @@ -149,9 +151,9 @@ - + - + @@ -166,7 +168,7 @@ - + @@ -234,7 +236,6 @@ - @@ -258,14 +259,13 @@ - + - @@ -383,11 +383,6 @@ - - - - - @@ -404,7 +399,7 @@ - + @@ -425,10 +420,13 @@ - + + + + @@ -456,6 +454,7 @@ + diff --git a/PowerEditor/installer/nativeLang/kazakh.xml b/PowerEditor/installer/nativeLang/kazakh.xml index 370b07c31..e189be8f2 100644 --- a/PowerEditor/installer/nativeLang/kazakh.xml +++ b/PowerEditor/installer/nativeLang/kazakh.xml @@ -10,11 +10,11 @@ - + - + @@ -24,8 +24,8 @@ - - + + @@ -49,9 +49,9 @@ - + - + @@ -75,7 +75,7 @@ - + @@ -87,8 +87,9 @@ - - + + + @@ -96,7 +97,7 @@ - + @@ -110,18 +111,18 @@ - + - + - + - + - - + + - + @@ -157,49 +158,49 @@ - + + - + - - + + - + - - + + - + - - + - - - - - + + + + + - - + + - + @@ -209,13 +210,13 @@ - + - - + + @@ -226,21 +227,21 @@ - - - - + + + + - + - - + + - + @@ -248,9 +249,9 @@ - + - + @@ -263,8 +264,8 @@ - - + + @@ -276,6 +277,9 @@ + @@ -316,24 +320,24 @@ - - + + - - - - + + + + - - - - + + + + @@ -350,21 +354,22 @@ - + - + - + - + - - + + + @@ -398,9 +403,9 @@ - - - + + + @@ -429,7 +434,7 @@ - + @@ -441,6 +446,8 @@ + + @@ -455,7 +462,7 @@ - + @@ -473,11 +480,10 @@ - + - - - + + @@ -490,11 +496,11 @@ - - - - - + + + + + @@ -521,7 +527,7 @@ - + diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 49725fdec..1bd65d6f3 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -380,7 +380,7 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILESAVED (NPPN_FIRST + 8) // To notify plugins that the current file is just saved - //scnNotification->nmhdr.code = NPPN_FILECLOSED; + //scnNotification->nmhdr.code = NPPN_FILESAVED; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 7b094a69c..87713e110 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1926,7 +1926,8 @@ void Notepad_plus::enableCommand(int cmdID, bool doEnable, int which) const void Notepad_plus::checkClipboard() { - bool hasSelection = _pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND); + + bool hasSelection = (_pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND)) || (_pEditView->execute(SCI_GETSELECTIONS) > 0); bool canPaste = (_pEditView->execute(SCI_CANPASTE) != 0); enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR); enableCommand(IDM_EDIT_COPY, hasSelection, MENU | TOOLBAR); @@ -7133,6 +7134,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _subEditView.execute(SCI_SETMULTIPLESELECTION, true); _mainEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); _subEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); + _mainEditView.execute(SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION); _subEditView.execute(SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index d46484ca8..97314731f 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -261,38 +261,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa { switch (Message) { - /* - case WM_CHAR : - { - if (execute(SCI_SELECTIONISRECTANGLE) && !(::GetKeyState(VK_LCONTROL) & 0x80000000)) - { - if (wParam != VK_ESCAPE) - { - execute(SCI_BEGINUNDOACTION); - - ColumnModeInfo colInfos = getColumnModeSelectInfo(); - generic_string str(1, (TCHAR)wParam); - columnReplace(colInfos, str.c_str()); - - int selStart = execute(SCI_GETSELECTIONSTART)+1; - int selEnd = execute(SCI_GETSELECTIONEND); - execute(SCI_SETSELECTIONSTART, selStart); - execute(SCI_SETSELECTIONEND, selEnd); - - execute(SCI_ENDUNDOACTION); - execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1].second); - } - else - { - int pos = execute(SCI_GETSELECTIONSTART); - execute(SCI_SETSEL, pos, pos); - } - return TRUE; - } - break; - } - */ - case WM_MOUSEHWHEEL : { ::CallWindowProc(_scintillaDefaultProc, hwnd, WM_HSCROLL, ((short)HIWORD(wParam) > 0)?SB_LINERIGHT:SB_LINELEFT, NULL); @@ -2077,85 +2045,109 @@ const char * ScintillaEditView::getCompleteKeywordList(std::basic_string & return kwl.c_str(); } +void ScintillaEditView::setMultiSelections(const ColumnModeInfos & cmi) +{ + for (size_t i = 0 ; i < cmi.size() ; i++) + { + if (cmi[i].isValid()) + { + int selStart = cmi[i]._direction == L2R?cmi[i]._selLpos:cmi[i]._selRpos; + int selEnd = cmi[i]._direction == L2R?cmi[i]._selRpos:cmi[i]._selLpos; + execute(SCI_SETSELECTIONNSTART, i, selStart); + execute(SCI_SETSELECTIONNEND, i, selEnd); + } + //if (cmi[i].hasVirtualSpace()) + //{ + if (cmi[i]._nbVirtualAnchorSpc) + execute(SCI_SETSELECTIONNANCHORVIRTUALSPACE, i, cmi[i]._nbVirtualAnchorSpc); + if (cmi[i]._nbVirtualCaretSpc) + execute(SCI_SETSELECTIONNCARETVIRTUALSPACE, i, cmi[i]._nbVirtualCaretSpc); + //} + } +} void ScintillaEditView::convertSelectedTextTo(bool Case) { - unsigned int codepage = _codepage; - UniMode um = getCurrentBuffer()->getUnicodeMode(); - if (um != uni8Bit) - codepage = CP_UTF8; + unsigned int codepage = _codepage; + UniMode um = getCurrentBuffer()->getUnicodeMode(); + if (um != uni8Bit) + codepage = CP_UTF8; - if (execute(SCI_SELECTIONISRECTANGLE)) - { - execute(SCI_BEGINUNDOACTION); + if (execute(SCI_GETSELECTIONS) > 1) // Multi-Selection || Column mode + { + execute(SCI_BEGINUNDOACTION); + + //int selStart = execute(SCI_GETSELECTIONSTART); + //int selEnd = execute(SCI_GETSELECTIONEND); + + ColumnModeInfos cmi = getColumnModeSelectInfo(); + + for (size_t i = 0 ; i < cmi.size() ; i++) + { + const int len = cmi[i]._selRpos - cmi[i]._selLpos; + char *srcStr = new char[len+1]; + wchar_t *destStr = new wchar_t[len+1]; - int selStart = execute(SCI_GETSELECTIONSTART); - int selEnd = execute(SCI_GETSELECTIONEND); + int start = cmi[i]._selLpos; + int end = cmi[i]._selRpos; + getText(srcStr, start, end); + + int nbChar = ::MultiByteToWideChar(codepage, 0, srcStr, len, destStr, len); + + for (int j = 0 ; j < nbChar ; j++) + { + if (Case == UPPERCASE) + destStr[j] = (wchar_t)::CharUpperW((LPWSTR)destStr[j]); + else + destStr[j] = (wchar_t)::CharLowerW((LPWSTR)destStr[j]); + } + ::WideCharToMultiByte(codepage, 0, destStr, len, srcStr, len, NULL, NULL); + + execute(SCI_SETTARGETSTART, start); + execute(SCI_SETTARGETEND, end); + execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)srcStr); - ColumnModeInfo cmi = getColumnModeSelectInfo(); - const int len = cmi[0].second - cmi[0].first; - char *srcStr = new char[len+1]; - wchar_t *destStr = new wchar_t[len+3]; - for (size_t i = 0 ; i < cmi.size() ; i++) - { - int start = cmi[i].first; - int end = cmi[i].second; - getText(srcStr, start, end); + delete [] srcStr; + delete [] destStr; + } - int nbChar = ::MultiByteToWideChar(codepage, 0, srcStr, len, destStr, len); + setMultiSelections(cmi); + + //execute(SCI_SETSELECTIONSTART, selStart); + //execute(SCI_SETSELECTIONEND, selEnd); + + execute(SCI_ENDUNDOACTION); + return; + } - for (int j = 0 ; j < nbChar ; j++) - { - if (Case == UPPERCASE) - destStr[j] = (wchar_t)::CharUpperW((LPWSTR)destStr[j]); - else - destStr[j] = (wchar_t)::CharLowerW((LPWSTR)destStr[j]); - } - ::WideCharToMultiByte(codepage, 0, destStr, len, srcStr, len, NULL, NULL); - - execute(SCI_SETTARGETSTART, start); - execute(SCI_SETTARGETEND, end); - execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)srcStr); - } - - delete [] srcStr; - delete [] destStr; - - execute(SCI_SETSELECTIONSTART, selStart); - execute(SCI_SETSELECTIONEND, selEnd); - - execute(SCI_ENDUNDOACTION); - return; - } - - size_t selectionStart = execute(SCI_GETSELECTIONSTART); - size_t selectionEnd = execute(SCI_GETSELECTIONEND); + size_t selectionStart = execute(SCI_GETSELECTIONSTART); + size_t selectionEnd = execute(SCI_GETSELECTIONEND); - int strSize = ((selectionEnd > selectionStart)?(selectionEnd - selectionStart):(selectionStart - selectionEnd))+1; - if (strSize) - { - char *selectedStr = new char[strSize+1]; - int strWSize = strSize * 2; - wchar_t *selectedStrW = new wchar_t[strWSize+3]; + int strSize = ((selectionEnd > selectionStart)?(selectionEnd - selectionStart):(selectionStart - selectionEnd))+1; + if (strSize) + { + char *selectedStr = new char[strSize+1]; + int strWSize = strSize * 2; + wchar_t *selectedStrW = new wchar_t[strWSize+3]; - execute(SCI_GETSELTEXT, 0, (LPARAM)selectedStr); + execute(SCI_GETSELTEXT, 0, (LPARAM)selectedStr); - int nbChar = ::MultiByteToWideChar(codepage, 0, selectedStr, strSize, selectedStrW, strWSize); + int nbChar = ::MultiByteToWideChar(codepage, 0, selectedStr, strSize, selectedStrW, strWSize); - for (int i = 0 ; i < nbChar ; i++) - { - if (Case == UPPERCASE) - selectedStrW[i] = (WCHAR)::CharUpperW((LPWSTR)selectedStrW[i]); - else - selectedStrW[i] = (WCHAR)::CharLowerW((LPWSTR)selectedStrW[i]); - } - ::WideCharToMultiByte(codepage, 0, selectedStrW, strWSize, selectedStr, strSize, NULL, NULL); + for (int i = 0 ; i < nbChar ; i++) + { + if (Case == UPPERCASE) + selectedStrW[i] = (WCHAR)::CharUpperW((LPWSTR)selectedStrW[i]); + else + selectedStrW[i] = (WCHAR)::CharLowerW((LPWSTR)selectedStrW[i]); + } + ::WideCharToMultiByte(codepage, 0, selectedStrW, strWSize, selectedStr, strSize, NULL, NULL); - execute(SCI_REPLACESEL, strSize, (LPARAM)selectedStr); - execute(SCI_SETSEL, selectionStart, selectionEnd); - delete [] selectedStr; - delete [] selectedStrW; - } + execute(SCI_REPLACESEL, strSize, (LPARAM)selectedStr); + execute(SCI_SETSEL, selectionStart, selectionEnd); + delete [] selectedStr; + delete [] selectedStrW; + } } @@ -2228,85 +2220,88 @@ TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, boo return str; } -ColumnModeInfo ScintillaEditView::getColumnModeSelectInfo() +ColumnModeInfos ScintillaEditView::getColumnModeSelectInfo() { - ColumnModeInfo columnModeInfo; - if (execute(SCI_SELECTIONISRECTANGLE)) + ColumnModeInfos columnModeInfos; + if (execute(SCI_GETSELECTIONS) > 1) // Multi-Selection || Column mode { - int selStartAbsPos = execute(SCI_GETSELECTIONSTART); - int selEndAbsPos = execute(SCI_GETSELECTIONEND); + int nbSel = execute(SCI_GETSELECTIONS); - int startCol = execute(SCI_GETCOLUMN, selStartAbsPos); - int endCol = execute(SCI_GETCOLUMN, selEndAbsPos); - - int startLine = execute(SCI_LINEFROMPOSITION, selStartAbsPos); - int endLine = execute(SCI_LINEFROMPOSITION, selEndAbsPos); - - if (endCol < startCol)// another way of selection + for (int i = 0 ; i < nbSel ; i++) { - int tmp = startCol; - startCol = endCol; - endCol = tmp; - - selStartAbsPos = execute(SCI_FINDCOLUMN, startLine, startCol); - selEndAbsPos = execute(SCI_FINDCOLUMN, endLine, endCol); - } - - bool zeroCharSelMode = true; - for (int i = startLine ; i <= endLine ; i++) - { - int absPosSelStartPerLine = execute(SCI_FINDCOLUMN, i, startCol); - int absPosSelEndPerLine = execute(SCI_FINDCOLUMN, i, endCol); - - if (absPosSelStartPerLine != absPosSelEndPerLine) - { - zeroCharSelMode = false; - } - columnModeInfo.push_back(pair(absPosSelStartPerLine, absPosSelEndPerLine)); - } - - if (!zeroCharSelMode) - { - for (int i = columnModeInfo.size() - 1 ; i >= 0 ; i--) + int absPosSelStartPerLine = execute(SCI_GETSELECTIONNANCHOR, i); + int absPosSelEndPerLine = execute(SCI_GETSELECTIONNCARET, i); + int nbVirtualAnchorSpc = execute(SCI_GETSELECTIONNANCHORVIRTUALSPACE, i); + int nbVirtualCaretSpc = execute(SCI_GETSELECTIONNCARETVIRTUALSPACE, i); + + if (absPosSelStartPerLine == absPosSelEndPerLine && execute(SCI_SELECTIONISRECTANGLE)) { - ColumnModeInfo::iterator it = columnModeInfo.begin() + i; - if (it->first == it->second) - columnModeInfo.erase(it); + bool dir = nbVirtualAnchorSpc absPosSelEndPerLine) + columnModeInfos.push_back(ColumnModeInfo(absPosSelEndPerLine, absPosSelStartPerLine, i, R2L, nbVirtualAnchorSpc, nbVirtualCaretSpc)); + else + columnModeInfos.push_back(ColumnModeInfo(absPosSelStartPerLine, absPosSelEndPerLine, i, L2R, nbVirtualAnchorSpc, nbVirtualCaretSpc)); } } - return columnModeInfo; + return columnModeInfos; } -void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, const TCHAR *str) +void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const TCHAR *str) { - //for (int i = (int)cmi.size() - 1 ; i >= 0 ; i--) int totalDiff = 0; for (size_t i = 0 ; i < cmi.size() ; i++) { - int len2beReplace = cmi[i].second - cmi[i].first; - int diff = lstrlen(str) - len2beReplace; + if (cmi[i].isValid()) + { + int len2beReplace = cmi[i]._selRpos - cmi[i]._selLpos; + int diff = lstrlen(str) - len2beReplace; - cmi[i].first += totalDiff; - cmi[i].second += totalDiff; + cmi[i]._selLpos += totalDiff; + cmi[i]._selRpos += totalDiff; + bool hasVirtualSpc = cmi[i]._nbVirtualAnchorSpc > 0; - execute(SCI_SETTARGETSTART, cmi[i].first); - execute(SCI_SETTARGETEND, cmi[i].second); + if (hasVirtualSpc) // if virtual space is present, then insert space + { + for (int j = 0, k = cmi[i]._selLpos; j < cmi[i]._nbVirtualCaretSpc ; j++, k++) + { + execute(SCI_INSERTTEXT, k, (LPARAM)" "); + } + cmi[i]._selLpos += cmi[i]._nbVirtualAnchorSpc; + cmi[i]._selRpos += cmi[i]._nbVirtualCaretSpc; + } + + execute(SCI_SETTARGETSTART, cmi[i]._selLpos); + execute(SCI_SETTARGETEND, cmi[i]._selRpos); + #ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - unsigned int cp = execute(SCI_GETCODEPAGE); - const char *strA = wmc->wchar2char(str, cp); - execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)strA); + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *strA = wmc->wchar2char(str, cp); + execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)strA); #else - execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)str); + execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)str); #endif - totalDiff += diff; - cmi[i].second += diff; + + if (hasVirtualSpc) + { + totalDiff += cmi[i]._nbVirtualAnchorSpc + lstrlen(str); + + // Now there's no more virtual space + cmi[i]._nbVirtualAnchorSpc = 0; + cmi[i]._nbVirtualCaretSpc = 0; + } + else + { + totalDiff += diff; + } + cmi[i]._selRpos += diff; + } } } - -void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, int initial, int incr, UCHAR format) +void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int incr, UCHAR format) { // 0000 00 00 : Dec BASE_10 // 0000 00 01 : Hex BASE_16 @@ -2341,27 +2336,30 @@ void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, int initial, int inc int totalDiff = 0; for (size_t i = 0 ; i < cmi.size() ; i++) { - int len2beReplace = cmi[i].second - cmi[i].first; - int diff = nb - len2beReplace; + if (cmi[i].isValid()) + { + int len2beReplace = cmi[i]._selRpos - cmi[i]._selLpos; + int diff = nb - len2beReplace; - cmi[i].first += totalDiff; - cmi[i].second += totalDiff; + cmi[i]._selLpos += totalDiff; + cmi[i]._selRpos += totalDiff; - int2str(str, stringSize, initial, base, nb, isZeroLeading); - - execute(SCI_SETTARGETSTART, cmi[i].first); - execute(SCI_SETTARGETEND, cmi[i].second); + int2str(str, stringSize, initial, base, nb, isZeroLeading); + + execute(SCI_SETTARGETSTART, cmi[i]._selLpos); + execute(SCI_SETTARGETEND, cmi[i]._selRpos); #ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - unsigned int cp = execute(SCI_GETCODEPAGE); - const char *strA = wmc->wchar2char(str, cp); - execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)strA); + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *strA = wmc->wchar2char(str, cp); + execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)strA); #else - execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)str); + execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)str); #endif - initial += incr; - totalDiff += diff; - cmi[i].second += diff; + initial += incr; + totalDiff += diff; + cmi[i]._selRpos += diff; + } } } diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index ec0cd0b7d..5b579ff32 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -92,7 +92,7 @@ const bool fold_collapse = false; const bool UPPERCASE = true; const bool LOWERCASE = false; -typedef vector > ColumnModeInfo; + const UCHAR MASK_FORMAT = 0x03; const UCHAR MASK_ZERO_LEADING = 0x04; const UCHAR BASE_10 = 0x00; // Dec @@ -116,6 +116,33 @@ TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, boo typedef LRESULT (WINAPI *CallWindowProcFunc) (WNDPROC,HWND,UINT,WPARAM,LPARAM); +const bool L2R = true; +const bool R2L = false; + +struct ColumnModeInfo { + int _selLpos; + int _selRpos; + int _order; // 0 based index + bool _direction; // L2R or R2L + int _nbVirtualCaretSpc; + int _nbVirtualAnchorSpc; + + ColumnModeInfo() : _selLpos(0), _selRpos(0), _order(-1), _direction(L2R), _nbVirtualAnchorSpc(0), _nbVirtualCaretSpc(0){}; + ColumnModeInfo(int lPos, int rPos, int order, bool dir = L2R, int vAnchorNbSpc = 0, int vCaretNbSpc = 0) + : _selLpos(lPos), _selRpos(rPos), _order(order), _direction(dir), _nbVirtualAnchorSpc(vAnchorNbSpc), _nbVirtualCaretSpc(vCaretNbSpc){}; + + bool isValid() const { + return (_order >= 0 && _selLpos >= 0 && _selRpos >= 0 && _selLpos <= _selRpos); + }; +/* + bool hasVirtualSpace() const { + return (_nbVirtualCaretSpc >= 0 && _nbVirtualAnchorSpc >= 0); + }; + */ +}; + +typedef vector ColumnModeInfos; + struct LanguageName { const TCHAR * lexerName; const TCHAR * shortName; @@ -446,6 +473,7 @@ public: }; void convertSelectedTextTo(bool Case); + void setMultiSelections(const ColumnModeInfos & cmi); void convertSelectedTextToLowerCase() { // if system is w2k or xp @@ -472,10 +500,10 @@ public: return _pParameter; }; - ColumnModeInfo getColumnModeSelectInfo(); + ColumnModeInfos getColumnModeSelectInfo(); - void columnReplace(ColumnModeInfo & cmi, const TCHAR *str); - void columnReplace(ColumnModeInfo & cmi, int initial, int incr, UCHAR format); + void columnReplace(ColumnModeInfos & cmi, const TCHAR *str); + void columnReplace(ColumnModeInfos & cmi, int initial, int incr, UCHAR format); void foldChanged(int line, int levelNow, int levelPrev); void clearIndicator(int indicatorNumber) { diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.cpp b/PowerEditor/src/ScitillaComponent/columnEditor.cpp index 41643ddfb..fb889e323 100644 --- a/PowerEditor/src/ScitillaComponent/columnEditor.cpp +++ b/PowerEditor/src/ScitillaComponent/columnEditor.cpp @@ -19,6 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "columnEditor.h" +/* BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) { switch (message) @@ -63,9 +64,9 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE)) { - ColumnModeInfo colInfos = (*_ppEditView)->getColumnModeSelectInfo(); + ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo(); (*_ppEditView)->columnReplace(colInfos, str); - (*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1].second); + (*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1]._selRpos); } else { @@ -120,9 +121,9 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE)) { - ColumnModeInfo colInfos = (*_ppEditView)->getColumnModeSelectInfo(); + ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo(); (*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format); - (*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1].second); + (*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1]._selRpos); } else { @@ -170,9 +171,219 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) (*_ppEditView)->getGenericText(line, lineBegin, lineEnd); generic_string s2r(line); - /* - Calcule generic_string - */ + + //Calcule generic_string + int2str(str, stringSize, initialNumber, base, nb, isZeroLeading); + initialNumber += increaseNumber; + + if (lineEndCol < cursorCol) + { + generic_string s_space(cursorCol - lineEndCol, ' '); + s2r.append(s_space); + s2r.append(str); + } + else + { + int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol); + int posRelative2Start = posAbs2Start - lineBegin; + s2r.insert(posRelative2Start, str); + } + + (*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd); + } + delete [] line; + } + } + (*_ppEditView)->execute(SCI_ENDUNDOACTION); + (*_ppEditView)->getFocus(); + return TRUE; + } + case IDC_COL_TEXT_RADIO : + case IDC_COL_NUM_RADIO : + { + switchTo((wParam == IDC_COL_TEXT_RADIO)? activeText : activeNumeric); + return TRUE; + } + + default : + { + switch (HIWORD(wParam)) + { + case EN_SETFOCUS : + case BN_SETFOCUS : + //updateLinesNumbers(); + return TRUE; + default : + return TRUE; + } + break; + } + } + } + + default : + return FALSE; + } + //return FALSE; +} +*/ + + +BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) +{ + switch (message) + { + case WM_INITDIALOG : + { + switchTo(activeText); + ::SendDlgItemMessage(_hSelf, IDC_COL_DEC_RADIO, BM_SETCHECK, TRUE, 0); + goToCenter(); + + NppParameters *pNppParam = NppParameters::getInstance(); + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + { + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + redraw(); + } + return TRUE; + } + case WM_COMMAND : + { + switch (wParam) + { + case IDCANCEL : // Close + display(false); + return TRUE; + + case IDOK : + { + (*_ppEditView)->execute(SCI_BEGINUNDOACTION); + + const int stringSize = 1024; + TCHAR str[stringSize]; + + bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0)); + + if (isTextMode) + { + ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_EDIT, WM_GETTEXT, stringSize, (LPARAM)str); + + display(false); + + if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE)) + { + ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo(); + (*_ppEditView)->columnReplace(colInfos, str); + (*_ppEditView)->setMultiSelections(colInfos); + } + else + { + int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS); + int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos); + int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos); + int endPos = (*_ppEditView)->execute(SCI_GETLENGTH); + int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos); + + int lineAllocatedLen = 1024; + TCHAR *line = new TCHAR[lineAllocatedLen]; + + for (int i = cursorLine ; i <= endLine ; i++) + { + int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i); + int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i); + + int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd); + int lineLen = lineEnd - lineBegin + 1; + + if (lineLen > lineAllocatedLen) + { + delete [] line; + line = new TCHAR[lineLen]; + } + (*_ppEditView)->getGenericText(line, lineBegin, lineEnd); + generic_string s2r(line); + + if (lineEndCol < cursorCol) + { + generic_string s_space(cursorCol - lineEndCol, ' '); + s2r.append(s_space); + s2r.append(str); + } + else + { + int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol); + int posRelative2Start = posAbs2Start - lineBegin; + s2r.insert(posRelative2Start, str); + } + (*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd); + } + delete [] line; + } + } + else + { + int initialNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INITNUM_EDIT, NULL, TRUE); + int increaseNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INCREASENUM_EDIT, NULL, TRUE); + UCHAR format = getFormat(); + display(false); + + if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE)) + { + ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo(); + (*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format); + //(*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1]._selRpos); + (*_ppEditView)->setMultiSelections(colInfos); + } + else + { + int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS); + int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos); + int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos); + int endPos = (*_ppEditView)->execute(SCI_GETLENGTH); + int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos); + + int lineAllocatedLen = 1024; + TCHAR *line = new TCHAR[lineAllocatedLen]; + + + UCHAR f = format & MASK_FORMAT; + bool isZeroLeading = (MASK_ZERO_LEADING & format) != 0; + + int base = 10; + if (f == BASE_16) + base = 16; + else if (f == BASE_08) + base = 8; + else if (f == BASE_02) + base = 2; + + int nbLine = endLine - cursorLine + 1; + int endNumber = initialNumber + increaseNumber * (nbLine - 1); + int nbEnd = getNbDigits(endNumber, base); + int nbInit = getNbDigits(initialNumber, base); + int nb = max(nbInit, nbEnd); + + + for (int i = cursorLine ; i <= endLine ; i++) + { + int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i); + int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i); + + int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd); + int lineLen = lineEnd - lineBegin + 1; + + if (lineLen > lineAllocatedLen) + { + delete [] line; + line = new TCHAR[lineLen]; + } + (*_ppEditView)->getGenericText(line, lineBegin, lineEnd); + generic_string s2r(line); + + // + // Calcule generic_string + // int2str(str, stringSize, initialNumber, base, nb, isZeroLeading); initialNumber += increaseNumber; diff --git a/PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj b/PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj deleted file mode 100644 index f5b75359e..000000000 --- a/PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj +++ /dev/null @@ -1,1091 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -