From edfa987f4ea81cd5bb7d54b1b0b3592f36e010ca Mon Sep 17 00:00:00 2001 From: Christian Grasser Date: Mon, 8 Jun 2015 12:11:10 +0200 Subject: [PATCH] x64 issue, replace int for bufferid by bufferid itself, otherwise x64 crashes as bufferid aka buffer * differs from int under x64 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 4 ++-- PowerEditor/src/Notepad_plus.cpp | 6 ++--- PowerEditor/src/NppCommands.cpp | 2 +- PowerEditor/src/NppIO.cpp | 14 +++++------ .../VerticalFileSwitcher.cpp | 6 ++--- .../VerticalFileSwitcher.h | 8 +++---- .../VerticalFileSwitcherListView.cpp | 24 +++++++++---------- .../VerticalFileSwitcherListView.h | 21 +++++++++------- 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index dc2912a3..39c5d75c 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -228,13 +228,13 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // allocate fullFilePath with the return values + 1, then call it again to get full path file name #define NPPM_GETBUFFERIDFROMPOS (NPPMSG + 59) - // INT NPPM_GETBUFFERIDFROMPOS(INT index, INT iView) + // LRESULT NPPM_GETBUFFERIDFROMPOS(INT index, INT iView) // wParam: Position of document // lParam: View to use, 0 = Main, 1 = Secondary // Returns 0 if invalid #define NPPM_GETCURRENTBUFFERID (NPPMSG + 60) - // INT NPPM_GETCURRENTBUFFERID(0, 0) + // LRESULT NPPM_GETCURRENTBUFFERID(0, 0) // Returns active Buffer #define NPPM_RELOADBUFFERID (NPPMSG + 61) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 3a0d078c..a9484bb7 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3197,7 +3197,7 @@ void Notepad_plus::loadBufferIntoView(BufferID id, int whichOne, bool dontClose) activateBuffer(id, whichOne); //activate. DocTab already activated but not a problem MainFileManager->closeBuffer(idToClose, viewToOpen); //delete the buffer if (_pFileSwitcherPanel) - _pFileSwitcherPanel->closeItem((int)idToClose, whichOne); + _pFileSwitcherPanel->closeItem(idToClose, whichOne); } else { @@ -4730,7 +4730,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) } if (_pFileSwitcherPanel) - _pFileSwitcherPanel->setItemIconStatus((int)buffer); + _pFileSwitcherPanel->setItemIconStatus(buffer); if (!mainActive && !subActive) { @@ -4830,7 +4830,7 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) if (_pFileSwitcherPanel) { - _pFileSwitcherPanel->activateItem((int)bufid, currentView()); + _pFileSwitcherPanel->activateItem(bufid, currentView()); } if (_pDocMap && (!_pDocMap->isClosed()) && _pDocMap->isVisible()) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index d15c671b..778e0b01 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -101,7 +101,7 @@ void Notepad_plus::command(int id) if (id == IDM_FILESWITCHER_FILESCLOSEOTHERS) { // Get current buffer and its view - _pFileSwitcherPanel->activateItem(int(_pEditView->getCurrentBufferID()), currentView()); + _pFileSwitcherPanel->activateItem(_pEditView->getCurrentBufferID(), currentView()); } } break; diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 9fcc33a7..affb0656 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -244,7 +244,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe scnN.nmhdr.code = NPPN_FILEOPENED; _pluginsManager.notify(&scnN); if (_pFileSwitcherPanel) - _pFileSwitcherPanel->newItem((int)buf, currentView()); + _pFileSwitcherPanel->newItem(buf, currentView()); } else { @@ -449,14 +449,14 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup) //Do all the works bool isBufRemoved = removeBufferFromView(id, whichOne); - int hiddenBufferID = -1; + BufferID hiddenBufferID = BUFFER_INVALID; if (nrDocs == 1 && canHideView(whichOne)) { //close the view if both visible hideView(whichOne); // if the current activated buffer is in this view, // then get buffer ID to remove the entry from File Switcher Pannel - hiddenBufferID = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETBUFFERIDFROMPOS, 0, whichOne); + hiddenBufferID = reinterpret_cast(::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETBUFFERIDFROMPOS, 0, whichOne)); } // Notify plugins that current file is closed @@ -466,15 +466,15 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup) _pluginsManager.notify(&scnN); // The document could be clonned. - // if the same buffer ID is not found then remove the entry from File Switcher Pannel + // if the same buffer ID is not found then remove the entry from File Switcher Panel if (_pFileSwitcherPanel) { //int posInfo = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETPOSFROMBUFFERID, (WPARAM)id ,0); - _pFileSwitcherPanel->closeItem((int)id, whichOne); + _pFileSwitcherPanel->closeItem(id, whichOne); - if (hiddenBufferID != -1) - _pFileSwitcherPanel->closeItem((int)hiddenBufferID, whichOne); + if (hiddenBufferID != BUFFER_INVALID) + _pFileSwitcherPanel->closeItem(hiddenBufferID, whichOne); } } command(IDM_VIEW_REFRESHTABAR); diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 658648ad..32bce546 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -205,15 +205,15 @@ BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPA void VerticalFileSwitcher::activateDoc(TaskLstFnStatus *tlfs) const { int view = tlfs->_iView; - int bufferID = (int)tlfs->_bufID; + BufferID bufferID = static_cast(tlfs->_bufID); int currentView = ::SendMessage(_hParent, NPPM_GETCURRENTVIEW, 0, 0); - int currentBufID = ::SendMessage(_hParent, NPPM_GETCURRENTBUFFERID, 0, 0); + BufferID currentBufID = reinterpret_cast(::SendMessage(_hParent, NPPM_GETCURRENTBUFFERID, 0, 0)); if (bufferID == currentBufID && view == currentView) return; - int docPosInfo = ::SendMessage(_hParent, NPPM_GETPOSFROMBUFFERID, bufferID, view); + int docPosInfo = ::SendMessage(_hParent, NPPM_GETPOSFROMBUFFERID, (WPARAM)bufferID, view); int view2set = docPosInfo >> 30; int index2Switch = (docPosInfo << 2) >> 2 ; diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h index 0276cd00..fa827d3f 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h @@ -55,19 +55,19 @@ public: //Activate document in scintilla by using the internal index void activateDoc(TaskLstFnStatus *tlfs) const; - int newItem(int bufferID, int iView){ + int newItem(BufferID bufferID, int iView){ return _fileListView.newItem(bufferID, iView); }; - int closeItem(int bufferID, int iView){ + int closeItem(BufferID bufferID, int iView){ return _fileListView.closeItem(bufferID, iView); }; - void activateItem(int bufferID, int iView) { + void activateItem(BufferID bufferID, int iView) { _fileListView.activateItem(bufferID, iView); }; - void setItemIconStatus(int bufferID) { + void setItemIconStatus(BufferID bufferID) { _fileListView.setItemIconStatus(bufferID) ; }; diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp index 304b65cc..1f8dbec2 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp @@ -157,11 +157,11 @@ void VerticalFileSwitcherListView::reload() initList(); } -int VerticalFileSwitcherListView::getBufferInfoFromIndex(int index, int & view) const +BufferID VerticalFileSwitcherListView::getBufferInfoFromIndex(int index, int & view) const { int nbItem = ListView_GetItemCount(_hSelf); if (index < 0 || index >= nbItem) - return -1; + return BUFFER_INVALID; LVITEM item; item.mask = LVIF_PARAM; @@ -170,10 +170,10 @@ int VerticalFileSwitcherListView::getBufferInfoFromIndex(int index, int & view) TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam; view = tlfs->_iView; - return int(tlfs->_bufID); + return static_cast(tlfs->_bufID); } -int VerticalFileSwitcherListView::newItem(int bufferID, int iView) +int VerticalFileSwitcherListView::newItem(BufferID bufferID, int iView) { int i = find(bufferID, iView); if (i == -1) @@ -183,7 +183,7 @@ int VerticalFileSwitcherListView::newItem(int bufferID, int iView) return i; } -void VerticalFileSwitcherListView::setItemIconStatus(int bufferID) +void VerticalFileSwitcherListView::setItemIconStatus(BufferID bufferID) { Buffer *buf = (Buffer *)bufferID; @@ -207,7 +207,7 @@ void VerticalFileSwitcherListView::setItemIconStatus(int bufferID) item.iItem = i; ListView_GetItem(_hSelf, &item); TaskLstFnStatus *tlfs = (TaskLstFnStatus *)(item.lParam); - if (int(tlfs->_bufID) == bufferID) + if (tlfs->_bufID == bufferID) { item.mask = LVIF_TEXT | LVIF_IMAGE; ListView_SetItem(_hSelf, &item); @@ -236,7 +236,7 @@ generic_string VerticalFileSwitcherListView::getFullFilePath(size_t i) const return tlfs->_fn; } -int VerticalFileSwitcherListView::closeItem(int bufferID, int iView) +int VerticalFileSwitcherListView::closeItem(BufferID bufferID, int iView) { int i = find(bufferID, iView); if (i != -1) @@ -244,7 +244,7 @@ int VerticalFileSwitcherListView::closeItem(int bufferID, int iView) return i; } -void VerticalFileSwitcherListView::activateItem(int bufferID, int iView) +void VerticalFileSwitcherListView::activateItem(BufferID bufferID, int iView) { // Clean all selection int nbItem = ListView_GetItemCount(_hSelf); @@ -255,7 +255,7 @@ void VerticalFileSwitcherListView::activateItem(int bufferID, int iView) ListView_SetItemState(_hSelf, i, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); } -int VerticalFileSwitcherListView::add(int bufferID, int iView) +int VerticalFileSwitcherListView::add(BufferID bufferID, int iView) { int index = ListView_GetItemCount(_hSelf); Buffer *buf = (Buffer *)bufferID; @@ -311,7 +311,7 @@ void VerticalFileSwitcherListView::removeAll() } } -int VerticalFileSwitcherListView::find(int bufferID, int iView) const +int VerticalFileSwitcherListView::find(BufferID bufferID, int iView) const { LVITEM item; bool found = false; @@ -323,7 +323,7 @@ int VerticalFileSwitcherListView::find(int bufferID, int iView) const item.iItem = i; ListView_GetItem(_hSelf, &item); TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam; - if (int(tlfs->_bufID) == bufferID && tlfs->_iView == iView) + if (tlfs->_bufID == bufferID && tlfs->_iView == iView) { found = true; break; @@ -374,7 +374,7 @@ std::vector VerticalFileSwitcherListView::getSelectedFiles(boo ListView_GetItem(_hSelf, &item); TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam; - files.push_back(SwitcherFileInfo(int(tlfs->_bufID), tlfs->_iView)); + files.push_back(SwitcherFileInfo(static_cast(tlfs->_bufID), tlfs->_iView)); } } diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h index 8d48cfc6..6877feec 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h @@ -32,13 +32,16 @@ #include "window.h" #include "TaskListDlg.h" +class Buffer; +typedef Buffer * BufferID; //each buffer has unique ID by which it can be retrieved + #define SORT_DIRECTION_UP 0 #define SORT_DIRECTION_DOWN 1 struct SwitcherFileInfo { - int _bufID; + BufferID _bufID; int _iView; - SwitcherFileInfo(int buf, int view): _bufID(buf), _iView(view){}; + SwitcherFileInfo(BufferID buf, int view) : _bufID(buf), _iView(view){}; }; class VerticalFileSwitcherListView : public Window @@ -50,14 +53,14 @@ public: virtual void init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst); virtual void destroy(); void initList(); - int getBufferInfoFromIndex(int index, int & view) const; + BufferID getBufferInfoFromIndex(int index, int & view) const; void setBgColour(int i) { ListView_SetItemState(_hSelf, i, LVIS_SELECTED|LVIS_FOCUSED, 0xFF); } - int newItem(int bufferID, int iView); - int closeItem(int bufferID, int iView); - void activateItem(int bufferID, int iView); - void setItemIconStatus(int bufferID); + int newItem(BufferID bufferID, int iView); + int closeItem(BufferID bufferID, int iView); + void activateItem(BufferID bufferID, int iView); + void setItemIconStatus(BufferID bufferID); generic_string getFullFilePath(size_t i) const; void insertColumn(const TCHAR *name, int width, int index); @@ -92,8 +95,8 @@ protected: return (((VerticalFileSwitcherListView *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(hwnd, Message, wParam, lParam)); }; - int find(int bufferID, int iView) const; - int add(int bufferID, int iView); + int find(BufferID bufferID, int iView) const; + int add(BufferID bufferID, int iView); void remove(int index); void removeAll(); };