diff options
Diffstat (limited to 'plugins/NewStory')
-rw-r--r-- | plugins/NewStory/res/resource.rc | 2 | ||||
-rw-r--r-- | plugins/NewStory/src/history.cpp | 4 | ||||
-rw-r--r-- | plugins/NewStory/src/history.h | 1 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 31 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.h | 2 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 139 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 1 | ||||
-rw-r--r-- | plugins/NewStory/src/history_menus.cpp | 5 |
8 files changed, 115 insertions, 70 deletions
diff --git a/plugins/NewStory/res/resource.rc b/plugins/NewStory/res/resource.rc index ae57e7909c..cbae402065 100644 --- a/plugins/NewStory/res/resource.rc +++ b/plugins/NewStory/res/resource.rc @@ -248,7 +248,7 @@ BEGIN MENUITEM "Copy", ID_CONTEXT_COPY MENUITEM SEPARATOR MENUITEM "Edit", ID_CONTEXT_EDIT - MENUITEM "Delete", ID_CONTEXT_DELETE, GRAYED + MENUITEM "Delete", ID_CONTEXT_DELETE MENUITEM SEPARATOR MENUITEM "Select all", ID_CONTEXT_SELECTALL END diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index f2d7a09c61..a1e901ee04 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -602,7 +602,9 @@ public: void onClick_Delete(CCtrlButton *) { - m_histControl.SendMsg(NSM_DELETE, 0, 0); + svcEmptyHistory(m_hContact, 0); + m_histControl.SendMsg(NSM_CLEAR, 0, 0); + UpdateTitle(); TimeTreeBuild(); } diff --git a/plugins/NewStory/src/history.h b/plugins/NewStory/src/history.h index 0dc28180c8..a1293cadff 100644 --- a/plugins/NewStory/src/history.h +++ b/plugins/NewStory/src/history.h @@ -32,6 +32,7 @@ extern MWindowList hNewstoryWindows; void InitHistory(); void InitMenus(); +INT_PTR svcEmptyHistory(WPARAM hContact, LPARAM); INT_PTR svcShowNewstory(WPARAM wParam, LPARAM lParam); INT_PTR svcShowSystemNewstory(WPARAM wParam, LPARAM lParam); diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index ecfc72caa0..07d29edb85 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -262,7 +262,7 @@ bool HistoryArray::addEvent(MCONTACT hContact, MEVENT hEvent, int count) ItemData& HistoryArray::allocateItem() { - if (iLastPageCounter == HIST_BLOCK_SIZE - 1) { + if (iLastPageCounter == HIST_BLOCK_SIZE) { pages.insert(new ItemBlock()); iLastPageCounter = 0; } @@ -290,3 +290,32 @@ int HistoryArray::getCount() const int nPages = pages.getCount(); return (nPages == 0) ? 0 : (nPages - 1) * HIST_BLOCK_SIZE + iLastPageCounter; } + +void HistoryArray::remove(int id) +{ + int pageNo = id / HIST_BLOCK_SIZE; + if (pageNo >= pages.getCount()) + return; + + auto &pPage = pages[pageNo]; + int offset = id % HIST_BLOCK_SIZE; + + ItemData tmp; + memcpy(&tmp, pPage.data + offset, sizeof(ItemData)); + + if (offset != HIST_BLOCK_SIZE - 1) + memmove(&pPage.data[offset], &pPage.data[offset+1], sizeof(ItemData) * (HIST_BLOCK_SIZE - 1 - offset)); + + for (int i = pageNo + 1; i < pages.getCount(); i++) { + auto &prev = pages[i - 1], &curr = pages[i]; + memcpy(&prev.data[HIST_BLOCK_SIZE - 1], curr.data, sizeof(ItemData)); + memmove(&curr.data, &curr.data[1], sizeof(ItemData) * (HIST_BLOCK_SIZE - 1)); + memset(&curr.data[HIST_BLOCK_SIZE - 1], 0, sizeof(ItemData)); + } + + if (iLastPageCounter == 1) { + pages.remove(pages.getCount() - 1); + iLastPageCounter = HIST_BLOCK_SIZE; + } + else iLastPageCounter--; +} diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index 46e075c934..166dd48160 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -139,6 +139,8 @@ public: ItemData* get(int id, bool bLoad = false); ItemData* operator[] (int id) { return get(id, true); } + void remove(int idx); + int FindRel(int id, int dir, Filter filter) { int count = getCount(); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index f9ef9c88a8..5aeb08a8a3 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -5,8 +5,6 @@ HANDLE htuLog = 0; static WNDPROC OldEditWndProc; -wchar_t wszDelete[] = LPGENW("Are you sure to remove all events from history?"); - static LRESULT CALLBACK HistoryEditWndProc(HWND, UINT, WPARAM, LPARAM); ///////////////////////////////////////////////////////////////////////// @@ -71,6 +69,7 @@ struct NewstoryListData : public MZeroedObject break; case ID_CONTEXT_DELETE: + DeleteItems(); break; case ID_CONTEXT_SELECTALL: @@ -137,6 +136,31 @@ struct NewstoryListData : public MZeroedObject SetFocus(hwndEditBox); } + void DeleteItems(void) + { + if (IDYES != MessageBoxW(hwnd, TranslateT("Do you really want to remove selected event(s)?"), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) + return; + + db_set_safety_mode(false); + + int firstSel = -1; + int eventCount = items.getCount(); + for (int i = eventCount - 1; i >= 0; i--) { + auto *p = items.get(i, false); + if (p->hEvent && p->bSelected) { + db_event_delete(p->hEvent); + items.remove(i); + firstSel = i; + } + } + db_set_safety_mode(true); + + if (firstSel != -1) { + SendMessage(hwnd, NSM_SETCARET, firstSel, 0); + SendMessage(hwnd, NSM_SELECTITEMS, firstSel, firstSel); + } + } + void EndEditItem(bool bAccept) { if (hwndEditBox == nullptr) @@ -442,6 +466,7 @@ static LRESULT CALLBACK HistoryEditWndProc(HWND hwnd, UINT msg, WPARAM wParam, L LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { int idx; + POINT pt; NewstoryListData *data = (NewstoryListData *)GetWindowLongPtr(hwnd, 0); switch (msg) { @@ -475,6 +500,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data->redrawTimer.Stop(); data->redrawTimer.Start(100); + InvalidateRect(hwnd, nullptr, FALSE); break; case NSM_GETARRAY: @@ -611,24 +637,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data->pMsgDlg = (CSrmmBaseDialog *)lParam; break; - case NSM_DELETE: - if (IDYES == MessageBoxW(hwnd, TranslateW(wszDelete), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) { - db_set_safety_mode(false); - - int eventCount = data->items.getCount(); - for (int i = eventCount - 1; i >= 0; i--) { - auto *p = data->items.get(i, false); - if (p->hEvent) - db_event_delete(p->hEvent); - } - db_set_safety_mode(true); - - data->items.reset(); - - InvalidateRect(hwnd, 0, FALSE); - } - break; - case NSM_COPY: { CMStringW res; @@ -695,17 +703,21 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM break; case WM_CONTEXTMENU: - { - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - if (pt.x == -1 && pt.y == -1) - GetCursorPos(&pt); + pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + if (pt.x == -1 && pt.y == -1) + GetCursorPos(&pt); - POINT pt2 = pt; - ScreenToClient(hwnd, &pt2); + POINT pt2 = pt; + ScreenToClient(hwnd, &pt2); - int index = data->GetItemFromPixel(pt2.y); - if (index != -1) - data->OnContextMenu(index, pt); + idx = data->GetItemFromPixel(pt2.y); + if (idx != -1) { + if (data->caret != idx) + data->EndEditItem(false); + SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); + SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + + data->OnContextMenu(idx, pt); } break; @@ -786,6 +798,10 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data->EndEditItem(false); break; + case VK_DELETE: + data->DeleteItems(); + break; + case VK_INSERT: case 'C': if (isCtrl) @@ -801,50 +817,47 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM break; case WM_LBUTTONDOWN: - { - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - int item = data->GetItemFromPixel(pt.y); - if (item >= 0) { - if (data->caret != item) - data->EndEditItem(false); + pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + idx = data->GetItemFromPixel(pt.y); + if (idx >= 0) { + if (data->caret != idx) + data->EndEditItem(false); - if (wParam & MK_CONTROL) { - SendMessage(hwnd, NSM_TOGGLEITEMS, item, item); - SendMessage(hwnd, NSM_SETCARET, item, TRUE); - } - else if (wParam & MK_SHIFT) { - SendMessage(hwnd, NSM_SELECTITEMS, data->caret, item); - SendMessage(hwnd, NSM_SETCARET, item, TRUE); + if (wParam & MK_CONTROL) { + SendMessage(hwnd, NSM_TOGGLEITEMS, idx, idx); + SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + } + else if (wParam & MK_SHIFT) { + SendMessage(hwnd, NSM_SELECTITEMS, data->caret, idx); + SendMessage(hwnd, NSM_SETCARET, idx, TRUE); + } + else { + auto *pItem = data->items[idx]; + pt.y -= pItem->savedTop; + if (pItem->isLink(pt)) { + Utils_OpenUrlW(pItem->getWBuf()); + return 0; } - else { - auto *pItem = data->items[item]; - pt.y -= pItem->savedTop; - if (pItem->isLink(pt)) { - Utils_OpenUrlW(pItem->getWBuf()); - return 0; - } - if (data->caret == item) { - data->BeginEditItem(item, true); - return 0; - } - - SendMessage(hwnd, NSM_SELECTITEMS2, item, item); - SendMessage(hwnd, NSM_SETCARET, item, TRUE); + if (data->caret == idx) { + data->BeginEditItem(idx, true); + return 0; } + + SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); + SendMessage(hwnd, NSM_SETCARET, idx, TRUE); } } + SetFocus(hwnd); return 0; case WM_MOUSEMOVE: - { - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - int item = data->GetItemFromPixel(pt.y); - if (item >= 0) { - auto *pItem = data->items[item]; - MTextSendMessage(hwnd, pItem->data, msg, wParam, lParam); - } + pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + idx = data->GetItemFromPixel(pt.y); + if (idx >= 0) { + auto *pItem = data->items[idx]; + MTextSendMessage(hwnd, pItem->data, msg, wParam, lParam); } break; diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index f8e09a7648..9d61c02e35 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -66,7 +66,6 @@ enum // NSM_COPY, - NSM_DELETE, NSM_EXPORT, // diff --git a/plugins/NewStory/src/history_menus.cpp b/plugins/NewStory/src/history_menus.cpp index e69296d589..1a38c1c05b 100644 --- a/plugins/NewStory/src/history_menus.cpp +++ b/plugins/NewStory/src/history_menus.cpp @@ -2,10 +2,9 @@ static HGENMENU hmiHistory, hmiEmpty; -static INT_PTR svcEmptyHistory(WPARAM hContact, LPARAM) +INT_PTR svcEmptyHistory(WPARAM hContact, LPARAM) { - extern wchar_t wszDelete[]; - if (IDYES != MessageBoxW(nullptr, TranslateW(wszDelete), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) + if (IDYES != MessageBoxW(nullptr, TranslateT("Are you sure to remove all events from history?"), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) return 1; DB::ECPTR pCursor(DB::Events(hContact)); |