From 3c7977ecba695788052732e0b9c8a52e82b1ea41 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 11 Sep 2009 00:22:40 +0000 Subject: [PATCH] [BUG_FIXED] Fix tooltip crash issue. [NEW_FEATURE] Add selected lines moving up/down capacity. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@533 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 95 +++++++++++-------- .../ScitillaComponent/ScintillaEditView.cpp | 58 +++++++---- .../src/ScitillaComponent/ScintillaEditView.h | 26 +---- 3 files changed, 100 insertions(+), 79 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index f530082d..e0eda7b1 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2647,47 +2647,66 @@ BOOL Notepad_plus::notify(SCNotification *notification) } case TTN_GETDISPINFO: - { - LPTOOLTIPTEXT lpttt; + { + try { + LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)notification; - lpttt = (LPTOOLTIPTEXT)notification; + //Joce's fix + lpttt->hinst = NULL; - //Joce's fix - lpttt->hinst = NULL; + POINT p; + ::GetCursorPos(&p); + ::ScreenToClient(_hSelf, &p); + HWND hWin = ::RealChildWindowFromPoint(_hSelf, p); + const int tipMaxLen = 1024; + static TCHAR toolTip[tipMaxLen]; + static TCHAR mainDocTip[tipMaxLen]; + static TCHAR subDocTip[tipMaxLen]; + toolTip[0] = mainDocTip[0] = subDocTip[0] = '\0'; - POINT p; - ::GetCursorPos(&p); - ::ScreenToClient(_hSelf, &p); - HWND hWin = ::RealChildWindowFromPoint(_hSelf, p); - const int tipMaxLen = 1024; - /*static */TCHAR tip[tipMaxLen]; - tip[0] = '\0'; - generic_string tipTmp(TEXT("")); - int id = int(lpttt->hdr.idFrom); + generic_string tipTmp(TEXT("")); + int id = int(lpttt->hdr.idFrom); - if (hWin == _rebarTop.getHSelf()) - { - getNameStrFromCmd(id, tipTmp); + if (hWin == _rebarTop.getHSelf()) + { + getNameStrFromCmd(id, tipTmp); + if (tipTmp.length() >= tipMaxLen) + return FALSE; + lstrcpy(toolTip, tipTmp.c_str()); + lpttt->lpszText = toolTip; + return TRUE; + } + else if (hWin == _mainDocTab.getHSelf()) + { + BufferID idd = _mainDocTab.getBufferByIndex(id); + Buffer * buf = MainFileManager->getBufferByID(idd); + tipTmp = buf->getFullPathName(); + + if (tipTmp.length() >= tipMaxLen) + return FALSE; + lstrcpy(mainDocTip, tipTmp.c_str()); + lpttt->lpszText = mainDocTip; + return TRUE; + } + else if (hWin == _subDocTab.getHSelf()) + { + BufferID idd = _subDocTab.getBufferByIndex(id); + Buffer * buf = MainFileManager->getBufferByID(idd); + tipTmp = buf->getFullPathName(); + + if (tipTmp.length() >= tipMaxLen) + return FALSE; + lstrcpy(subDocTip, tipTmp.c_str()); + lpttt->lpszText = subDocTip; + return TRUE; + } + else + { + return FALSE; + } + } catch (...) { + //printStr(TEXT("ToolTip crash is catched!")); } - else if (hWin == _mainDocTab.getHSelf()) - { - BufferID idd = _mainDocTab.getBufferByIndex(id); - Buffer * buf = MainFileManager->getBufferByID(idd); - tipTmp = buf->getFullPathName(); - } - else if (hWin == _subDocTab.getHSelf()) - { - BufferID idd = _subDocTab.getBufferByIndex(id); - Buffer * buf = MainFileManager->getBufferByID(idd); - tipTmp = buf->getFullPathName(); - } - else - break; - - if (tipTmp.length() < tipMaxLen) - lstrcpy(tip, tipTmp.c_str()); - - lpttt->lpszText = tip; } break; @@ -3805,11 +3824,11 @@ void Notepad_plus::command(int id) break; case IDM_EDIT_LINE_UP: - _pEditView->currentLineUp(); + _pEditView->currentLinesUp(); break; case IDM_EDIT_LINE_DOWN: - _pEditView->currentLineDown(); + _pEditView->currentLinesDown(); break; case IDM_EDIT_UPPERCASE: diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index a6dca73a..62f2de60 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -2065,6 +2065,33 @@ void ScintillaEditView::setMultiSelections(const ColumnModeInfos & cmi) } } +void ScintillaEditView::currentLineUp() const +{ + int currentLine = getCurrentLineNumber(); + if (currentLine != 0) + { + execute(SCI_BEGINUNDOACTION); + currentLine--; + execute(SCI_LINETRANSPOSE); + execute(SCI_GOTOLINE, currentLine); + execute(SCI_ENDUNDOACTION); + } +} + +void ScintillaEditView::currentLineDown() const +{ + int currentLine = getCurrentLineNumber(); + if (currentLine != (execute(SCI_GETLINECOUNT) - 1)) + { + execute(SCI_BEGINUNDOACTION); + currentLine++; + execute(SCI_GOTOLINE, currentLine); + execute(SCI_LINETRANSPOSE); + execute(SCI_ENDUNDOACTION); + } +} + + pair ScintillaEditView::getSelectionLinesRange() const { pair range(-1, -1); @@ -2086,6 +2113,7 @@ void ScintillaEditView::currentLinesUp() const if ((lineRange.first == -1 || lineRange.first == 0)) return; + bool noSel = lineRange.first == lineRange.second; int nbSelLines = lineRange.second - lineRange.first + 1; int line2swap = lineRange.first - 1; @@ -2099,48 +2127,42 @@ void ScintillaEditView::currentLinesUp() const for (int i = 0 ; i < nbSelLines ; i++) { - /* - execute(SCI_GOTOLINE, line2swap); - execute(SCI_LINETRANSPOSE); - - line2swap++; - */ currentLineDown(); } execute(SCI_ENDUNDOACTION); execute(SCI_SETSELECTIONSTART, posStart - nbChar); - execute(SCI_SETSELECTIONEND, posEnd - nbChar); + execute(SCI_SETSELECTIONEND, noSel?posStart - nbChar:posEnd - nbChar); } void ScintillaEditView::currentLinesDown() const { pair lineRange = getSelectionLinesRange(); - if ((lineRange.first == -1 || lineRange.first == 0)) + + if ((lineRange.first == -1 || lineRange.second >= execute(SCI_LINEFROMPOSITION, getCurrentDocLen()))) return; + bool noSel = lineRange.first == lineRange.second; int nbSelLines = lineRange.second - lineRange.first + 1; - int line2swap = lineRange.first - 1; + int line2swap = lineRange.second + 1; int nbChar = execute(SCI_LINELENGTH, line2swap); + int posStart = execute(SCI_POSITIONFROMLINE, lineRange.first); + int posEnd = execute(SCI_GETLINEENDPOSITION, lineRange.second); + execute(SCI_BEGINUNDOACTION); execute(SCI_GOTOLINE, line2swap); for (int i = 0 ; i < nbSelLines ; i++) { - /* - execute(SCI_GOTOLINE, line2swap); - execute(SCI_LINETRANSPOSE); - - line2swap++; - */ - currentLineDown(); + currentLineUp(); } execute(SCI_ENDUNDOACTION); - execute(SCI_SETSELECTIONSTART, lineRange.first - nbChar); - execute(SCI_SETSELECTIONEND, lineRange.second - nbChar); + execute(SCI_SETSELECTIONSTART, posStart + nbChar); + execute(SCI_SETSELECTIONEND, noSel?posStart + nbChar:posEnd + nbChar); + } void ScintillaEditView::convertSelectedTextTo(bool Case) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index ba13df4e..2e935bbb 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -468,33 +468,13 @@ public: void expand(int &line, bool doExpand, bool force = false, int visLevels = 0, int level = -1); - void currentLineUp() const { - int currentLine = getCurrentLineNumber(); - if (currentLine != 0) - { - execute(SCI_BEGINUNDOACTION); - currentLine--; - execute(SCI_LINETRANSPOSE); - execute(SCI_GOTOLINE, currentLine); - execute(SCI_ENDUNDOACTION); - } - }; + void currentLineUp() const; + void currentLineDown() const; + pair getSelectionLinesRange() const; void currentLinesUp() const; void currentLinesDown() const; - void currentLineDown() const { - int currentLine = getCurrentLineNumber(); - if (currentLine != (execute(SCI_GETLINECOUNT) - 1)) - { - execute(SCI_BEGINUNDOACTION); - currentLine++; - execute(SCI_GOTOLINE, currentLine); - execute(SCI_LINETRANSPOSE); - execute(SCI_ENDUNDOACTION); - } - }; - void convertSelectedTextTo(bool Case); void setMultiSelections(const ColumnModeInfos & cmi);