diff options
Diffstat (limited to 'plugins/NewStory/src')
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 41 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 101 | ||||
-rw-r--r-- | plugins/NewStory/src/version.h | 2 |
3 files changed, 86 insertions, 58 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 7c55e309e9..33724bdff5 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -76,29 +76,30 @@ void ItemData::load(bool bFullLoad) return; dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob + 1); - if (db_event_get(hEvent, &dbe)) - return; - - bLoaded = true; + mir_ptr<BYTE> pData((BYTE *)mir_calloc(dbe.cbBlob + 1)); + dbe.pBlob = pData; + if (!db_event_get(hEvent, &dbe)) { + bLoaded = true; - switch (dbe.eventType) { - case EVENTTYPE_MESSAGE: - if (!(dbe.flags & DBEF_SENT)) { - if (!dbe.markedRead()) - db_event_markRead(hContact, hEvent); - g_clistApi.pfnRemoveEvent(hContact, hEvent); - } - __fallthrough; + switch (dbe.eventType) { + case EVENTTYPE_MESSAGE: + if (!(dbe.flags & DBEF_SENT)) { + if (!dbe.markedRead()) + db_event_markRead(hContact, hEvent); + g_clistApi.pfnRemoveEvent(hContact, hEvent); + } + __fallthrough; - case EVENTTYPE_STATUSCHANGE: - wtext = mir_utf8decodeW((char *)dbe.pBlob); - break; + case EVENTTYPE_STATUSCHANGE: + wtext = mir_utf8decodeW((char *)dbe.pBlob); + break; - default: - wtext = DbEvent_GetTextW(&dbe, CP_ACP); - break; + default: + wtext = DbEvent_GetTextW(&dbe, CP_ACP); + break; + } } + dbe.pBlob = nullptr; } bool ItemData::isGrouped() const @@ -115,8 +116,6 @@ bool ItemData::isGrouped() const ItemData::~ItemData() { - if (bLoaded) - mir_free(dbe.pBlob); mir_free(wtext); if (data) MTextDestroy(data); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 76b8b9b2f0..ef997f829a 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -67,7 +67,7 @@ struct NewstoryListData : public MZeroedObject break; case ID_CONTEXT_EDIT: - BeginEditItem(index); + BeginEditItem(index, false); break; case ID_CONTEXT_DELETE: @@ -96,10 +96,10 @@ struct NewstoryListData : public MZeroedObject InvalidateRect(hwnd, 0, FALSE); } - void BeginEditItem(int index) + void BeginEditItem(int index, bool bReadOnly) { if (hwndEditBox) - EndEditItem(); + EndEditItem(false); if (scrollTopItem > index) return; @@ -111,30 +111,58 @@ struct NewstoryListData : public MZeroedObject int idx = scrollTopItem; int itemHeight = LayoutItem(idx); while (top < height) { - if (idx == index) { - ItemData *item = items[index]; - - int fontid, colorid; - item->getFontColor(fontid, colorid); - - ptrW text(TplFormatString(item->getCopyTemplate(), item->hContact, item)); - hwndEditBox = CreateWindow(L"EDIT", text, WS_CHILD | WS_BORDER | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL, 0, top, rc.right - rc.left, itemHeight, hwnd, NULL, g_plugin.getInst(), NULL); - OldEditWndProc = (WNDPROC)SetWindowLongPtr(hwndEditBox, GWLP_WNDPROC, (LONG_PTR)HistoryEditWndProc); - SendMessage(hwndEditBox, WM_SETFONT, (WPARAM)g_fontTable[fontid].hfnt, 0); - SendMessage(hwndEditBox, EM_SETMARGINS, EC_RIGHTMARGIN, 100); - SendMessage(hwndEditBox, EM_SETSEL, 0, (LPARAM)(-1)); - ShowWindow(hwndEditBox, SW_SHOW); - SetFocus(hwndEditBox); + if (idx == index) break; - } + top += itemHeight; idx++; itemHeight = LayoutItem(idx); } + + ItemData *item = items[index]; + int fontid, colorid; + item->getFontColor(fontid, colorid); + + DWORD dwStyle = WS_CHILD | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL; + if (bReadOnly) + dwStyle |= ES_READONLY; + + hwndEditBox = CreateWindow(L"EDIT", item->getWBuf(), dwStyle, 0, top, rc.right - rc.left, itemHeight, hwnd, NULL, g_plugin.getInst(), NULL); + SetWindowLongPtrW(hwndEditBox, GWLP_USERDATA, (LPARAM)item); + OldEditWndProc = (WNDPROC)SetWindowLongPtr(hwndEditBox, GWLP_WNDPROC, (LONG_PTR)HistoryEditWndProc); + SendMessage(hwndEditBox, WM_SETFONT, (WPARAM)g_fontTable[fontid].hfnt, 0); + SendMessage(hwndEditBox, EM_SETMARGINS, EC_RIGHTMARGIN, 100); + SendMessage(hwndEditBox, EM_SETSEL, 0, (LPARAM)(-1)); + ShowWindow(hwndEditBox, SW_SHOW); + SetFocus(hwndEditBox); } - void EndEditItem() + void EndEditItem(bool bAccept) { + if (hwndEditBox == nullptr) + return; + + if (bAccept) { + if ((GetWindowLong(hwndEditBox, GWL_STYLE) & ES_READONLY) == 0) { + auto *pItem = (ItemData *)GetWindowLongPtrW(hwndEditBox, GWLP_USERDATA); + + int iTextLen = GetWindowTextLengthW(hwndEditBox); + replaceStrW(pItem->wtext, (wchar_t *)mir_alloc((iTextLen + 1) * sizeof(wchar_t))); + GetWindowTextW(hwndEditBox, pItem->wtext, iTextLen); + pItem->wtext[iTextLen] = 0; + + if (pItem->hContact && pItem->hEvent) { + ptrA szUtf(mir_utf8encodeW(pItem->wtext)); + pItem->dbe.cbBlob = mir_strlen(szUtf) + 1; + pItem->dbe.pBlob = (BYTE *)szUtf.get(); + db_event_edit(pItem->hContact, pItem->hEvent, &pItem->dbe); + } + + MTextDestroy(pItem->data); pItem->data = 0; + pItem->checkCreate(hwnd); + } + } + DestroyWindow(hwndEditBox); hwndEditBox = 0; } @@ -175,7 +203,7 @@ struct NewstoryListData : public MZeroedObject void FixScrollPosition() { - EndEditItem(); + EndEditItem(false); RECT rc; GetWindowRect(hwnd, &rc); @@ -378,8 +406,11 @@ static LRESULT CALLBACK HistoryEditWndProc(HWND hwnd, UINT msg, WPARAM wParam, L switch (msg) { case WM_KEYDOWN: switch (wParam) { + case VK_RETURN: + pData->EndEditItem(true); + return 0; case VK_ESCAPE: - pData->EndEditItem(); + pData->EndEditItem(false); return 0; } break; @@ -395,7 +426,7 @@ static LRESULT CALLBACK HistoryEditWndProc(HWND hwnd, UINT msg, WPARAM wParam, L return DLGC_WANTMESSAGE; case WM_KILLFOCUS: - pData->EndEditItem(); + pData->EndEditItem(false); return 0; } @@ -451,7 +482,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case NSM_SELECTITEMS: { - int start = min(data->items.getCount() - 1, wParam); + int start = min(data->items.getCount() - 1, (int)wParam); int end = min(data->items.getCount() - 1, max(0, lParam)); if (start > end) std::swap(start, end); @@ -467,7 +498,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case NSM_TOGGLEITEMS: { - int start = min(data->items.getCount() - 1, wParam); + int start = min(data->items.getCount() - 1, (int)wParam); int end = min(data->items.getCount() - 1, max(0, lParam)); if (start > end) std::swap(start, end); @@ -483,7 +514,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case NSM_SELECTITEMS2: { - int start = min(data->items.getCount() - 1, wParam); + int start = min(data->items.getCount() - 1, (int)wParam); int end = min(data->items.getCount() - 1, max(0, lParam)); if (start > end) std::swap(start, end); @@ -503,13 +534,11 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case NSM_DESELECTITEMS: { - int start = min(data->items.getCount() - 1, wParam); + int start = min(data->items.getCount() - 1, (int)wParam); int end = min(data->items.getCount() - 1, max(0, lParam)); - if (start > end) { - start ^= end; - end ^= start; - start ^= end; - } + if (start > end) + std::swap(start, end); + for (int i = start; i <= end; ++i) { auto *p = data->items.get(i, false); p->bSelected = false; @@ -527,7 +556,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return data->GetItemFromPixel(lParam); case NSM_SETCARET: - if (wParam < data->items.getCount()) { + if ((int)wParam < data->items.getCount()) { data->caret = wParam; if (lParam) SendMessage(hwnd, NSM_ENSUREVISIBLE, data->caret, 0); @@ -746,12 +775,12 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM break; case VK_F2: - data->BeginEditItem(data->caret); + data->BeginEditItem(data->caret, false); break; case VK_ESCAPE: if (data->hwndEditBox) - data->EndEditItem(); + data->EndEditItem(false); break; case VK_INSERT: @@ -774,7 +803,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM int item = data->GetItemFromPixel(pt.y); if (item >= 0) { if (data->caret != item) - data->EndEditItem(); + data->EndEditItem(false); if (wParam & MK_CONTROL) { SendMessage(hwnd, NSM_TOGGLEITEMS, item, item); @@ -793,7 +822,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } if (data->caret == item) { - data->BeginEditItem(item); + data->BeginEditItem(item, true); return 0; } diff --git a/plugins/NewStory/src/version.h b/plugins/NewStory/src/version.h index 82b5d5505a..688ed2c8d7 100644 --- a/plugins/NewStory/src/version.h +++ b/plugins/NewStory/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include <stdver.h> |