summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-05-01 12:11:28 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-05-01 12:11:28 +0300
commit99c07e02823f266fe0a29a846146f8b297a8d657 (patch)
tree4108de4edbce78995100dc23463005c1471c8528
parentd4c5fb26501ed5dbe44793139146495755f7be2b (diff)
code cleaning
-rw-r--r--plugins/NewStory/src/history_control.cpp751
1 files changed, 371 insertions, 380 deletions
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index e33d901ba3..0cd1aa776e 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -1,14 +1,23 @@
#include "stdafx.h"
+#define AVERAGE_ITEM_HEIGHT 100
+
HANDLE htuLog = 0;
+static WNDPROC OldEditWndProc;
static wchar_t wszDelete[] = LPGENW("Are you sure to remove all events from history?");
+static LRESULT CALLBACK HistoryEditWndProc(HWND, UINT, WPARAM, LPARAM);
+
/////////////////////////////////////////////////////////////////////////
// Control utilities, types and constants
struct NewstoryListData : public MZeroedObject
{
+ NewstoryListData(HWND _1) :
+ hwnd(_1)
+ {}
+
HistoryArray items;
int scrollTopItem; // topmost item
@@ -21,424 +30,407 @@ struct NewstoryListData : public MZeroedObject
RECT rcLastPaint;
bool repaint;
+ HWND hwnd;
HWND hwndEditBox;
-};
-#define AVERAGE_ITEM_HEIGHT 100
+ void BeginEditItem(int index)
+ {
+ if (hwndEditBox)
+ EndEditItem();
-static void ScrollListBy(HWND hwnd, NewstoryListData *data, int scrollItems, int scrollPixels);
-static void EnsureVisible(HWND hwnd, NewstoryListData *data, int item);
-static void FixScrollPosition(HWND hwnd, NewstoryListData *data);
-static void RecalcScrollBar(HWND hwnd, NewstoryListData *data);
-static void BeginEditItem(HWND hwnd, NewstoryListData *data, int index);
-static void EndEditItem(HWND hwnd, NewstoryListData *data);
-static int LayoutItem(HWND hwnd, HistoryArray *items, int index);
-static int PaintItem(HDC hdc, HistoryArray *items, int index, int top, int width);
+ if (scrollTopItem > index)
+ return;
-// Edit box
-static WNDPROC OldEditWndProc;
-static LRESULT CALLBACK HistoryEditWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_KEYDOWN:
- switch (wParam) {
- case VK_ESCAPE:
- {
- EndEditItem(GetParent(hwnd), (NewstoryListData *)GetWindowLongPtr(GetParent(hwnd), 0));
- return 0;
- }
- }
- break;
+ RECT rc; GetClientRect(hwnd, &rc);
+ int height = rc.bottom - rc.top;
- case WM_GETDLGCODE:
- if (lParam) {
- MSG *msg2 = (MSG *)lParam;
- if (msg2->message == WM_KEYDOWN && msg2->wParam == VK_TAB)
- return 0;
- if (msg2->message == WM_CHAR && msg2->wParam == '\t')
- return 0;
- }
- return DLGC_WANTMESSAGE;
+ int top = scrollTopPixel;
+ int idx = scrollTopItem;
+ int itemHeight = LayoutItem(idx);
+ while (top < height) {
+ if (idx == index) {
+ ItemData *item = items.get(index, ItemData::ELM_DATA);
+
+ int tpl;
+ int fontid;
+ int colorid;
+ switch (item->dbe.eventType) {
+ case EVENTTYPE_MESSAGE:
+ tpl = TPL_COPY_MESSAGE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INMSG : COLOR_OUTMSG;
+ break;
- case WM_KILLFOCUS:
- EndEditItem(GetParent(hwnd), (NewstoryListData *)GetWindowLong(GetParent(hwnd), 0));
- return 0;
- }
+ case EVENTTYPE_FILE:
+ tpl = TPL_COPY_FILE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
+ break;
- return CallWindowProc(OldEditWndProc, hwnd, msg, wParam, lParam);
-}
+ case EVENTTYPE_STATUSCHANGE:
+ tpl = TPL_COPY_SIGN;
+ fontid = FONT_STATUS;
+ colorid = COLOR_STATUS;
+ break;
-/////////////////////////////////////////////////////////////////////////
-// Utilities
+ case EVENTTYPE_AUTHREQUEST:
+ tpl = TPL_COPY_AUTH;
+ fontid = FONT_INOTHER;
+ colorid = COLOR_INOTHER;
+ break;
-static void ScrollListBy(HWND hwnd, NewstoryListData *data, int scrollItems, int scrollPixels)
-{
- if (scrollItems) {
- data->scrollTopItem += scrollItems;
- data->scrollTopPixel = 0;
- }
- else if (scrollPixels) {
- data->scrollTopPixel += scrollPixels;
- if (data->scrollTopPixel > 0) {
- while ((data->scrollTopPixel > 0) && data->scrollTopItem) {
- data->scrollTopItem--;
- int itemHeight = LayoutItem(hwnd, &data->items, data->scrollTopItem);
- data->scrollTopPixel -= itemHeight;
- }
+ case EVENTTYPE_ADDED:
+ tpl = TPL_COPY_ADDED;
+ fontid = FONT_INOTHER;
+ colorid = COLOR_INOTHER;
+ break;
- if (data->scrollTopPixel > 0) {
- data->scrollTopPixel = 0;
- }
- }
- else if (data->scrollTopPixel < 0) {
- int maxItem = data->items.getCount();
- int itemHeight = LayoutItem(hwnd, &data->items, data->scrollTopItem);
- while ((-data->scrollTopPixel > itemHeight) && (data->scrollTopItem < maxItem)) {
- data->scrollTopPixel += itemHeight;
- data->scrollTopItem++;
- itemHeight = LayoutItem(hwnd, &data->items, data->scrollTopItem);
- }
- }
- }
+ case EVENTTYPE_JABBER_PRESENCE:
+ tpl = TPL_COPY_PRESENCE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ break;
- FixScrollPosition(hwnd, data);
-}
+ default:
+ tpl = TPL_COPY_OTHER;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ break;
+ }
-static void EnsureVisible(HWND hwnd, NewstoryListData *data, int item)
-{
- if (data->scrollTopItem >= item) {
- data->scrollTopItem = item;
- data->scrollTopPixel = 0;
- }
- else {
- RECT rc; GetClientRect(hwnd, &rc);
- int height = rc.bottom - rc.top;
- int top = data->scrollTopPixel;
- int idx = data->scrollTopItem;
- int itemHeight = LayoutItem(hwnd, &data->items, idx);
- bool found = false;
- while (top < height) {
- if (idx == item) {
- itemHeight = LayoutItem(hwnd, &data->items, idx);
- if (top + itemHeight > height)
- ScrollListBy(hwnd, data, 0, height - top - itemHeight);
- found = true;
+ ptrW text(TplFormatString(tpl, 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);
break;
}
top += itemHeight;
idx++;
- itemHeight = LayoutItem(hwnd, &data->items, idx);
- }
- if (!found) {
- data->scrollTopItem = item;
- data->scrollTopPixel = 0;
+ itemHeight = LayoutItem(idx);
}
}
- FixScrollPosition(hwnd, data);
-}
-static void FixScrollPosition(HWND hwnd, NewstoryListData *data)
-{
- EndEditItem(hwnd, data);
-
- RECT rc;
- GetWindowRect(hwnd, &rc);
- int windowHeight = rc.bottom - rc.top;
-
- if (windowHeight != data->cachedWindowHeight) {
- int maxTopItem = 0;
- int tmp = 0;
- for (maxTopItem = data->items.getCount(); (maxTopItem > 0) && (tmp < windowHeight); maxTopItem--)
- tmp += LayoutItem(hwnd, &data->items, maxTopItem - 1);
- data->cachedMaxTopItem = maxTopItem;
- data->cachedWindowHeight = windowHeight;
- data->cachedMaxTopPixel = (windowHeight < tmp) ? windowHeight - tmp : 0;
+ void EndEditItem()
+ {
+ DestroyWindow(hwndEditBox);
+ hwndEditBox = 0;
}
- if (data->scrollTopItem < 0)
- data->scrollTopItem = 0;
-
- if ((data->scrollTopItem > data->cachedMaxTopItem) ||
- ((data->scrollTopItem == data->cachedMaxTopItem) && (data->scrollTopPixel < data->cachedMaxTopPixel))) {
- data->scrollTopItem = data->cachedMaxTopItem;
- data->scrollTopPixel = data->cachedMaxTopPixel;
+ void EnsureVisible(int item)
+ {
+ if (scrollTopItem >= item) {
+ scrollTopItem = item;
+ scrollTopPixel = 0;
+ }
+ else {
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ int height = rc.bottom - rc.top;
+ int top = scrollTopPixel;
+ int idx = scrollTopItem;
+ int itemHeight = LayoutItem(idx);
+ bool found = false;
+ while (top < height) {
+ if (idx == item) {
+ itemHeight = LayoutItem(idx);
+ if (top + itemHeight > height)
+ ScrollListBy(0, height - top - itemHeight);
+ found = true;
+ break;
+ }
+ top += itemHeight;
+ idx++;
+ itemHeight = LayoutItem(idx);
+ }
+ if (!found) {
+ scrollTopItem = item;
+ scrollTopPixel = 0;
+ }
+ }
+ FixScrollPosition();
}
-
- RecalcScrollBar(hwnd, data);
-}
-
-static void RecalcScrollBar(HWND hwnd, NewstoryListData *data)
-{
- SCROLLINFO si = { 0 };
- RECT clRect;
- GetClientRect(hwnd, &clRect);
- si.cbSize = sizeof(si);
- si.fMask = SIF_ALL;
- si.nMin = 0;
- si.nMax = data->items.getCount() * AVERAGE_ITEM_HEIGHT;
- si.nPage = clRect.bottom;
- si.nPos = data->scrollTopItem * AVERAGE_ITEM_HEIGHT;
- SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
-}
-
-static void BeginEditItem(HWND hwnd, NewstoryListData *data, int index)
-{
- if (data->hwndEditBox)
- EndEditItem(hwnd, data);
-
- if (data->scrollTopItem > index)
- return;
-
- RECT rc; GetClientRect(hwnd, &rc);
- int height = rc.bottom - rc.top;
-
- int top = data->scrollTopPixel;
- int idx = data->scrollTopItem;
- int itemHeight = LayoutItem(hwnd, &data->items, idx);
- while (top < height) {
- if (idx == index) {
- ItemData *item = data->items.get(index, ItemData::ELM_DATA);
-
- int tpl;
- int fontid;
- int colorid;
- switch (item->dbe.eventType) {
- case EVENTTYPE_MESSAGE:
- tpl = TPL_COPY_MESSAGE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INMSG : COLOR_OUTMSG;
- break;
- case EVENTTYPE_FILE:
- tpl = TPL_COPY_FILE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
- break;
+ void FixScrollPosition()
+ {
+ EndEditItem();
+
+ RECT rc;
+ GetWindowRect(hwnd, &rc);
+ int windowHeight = rc.bottom - rc.top;
+
+ if (windowHeight != cachedWindowHeight) {
+ int maxTopItem = 0;
+ int tmp = 0;
+ for (maxTopItem = items.getCount(); (maxTopItem > 0) && (tmp < windowHeight); maxTopItem--)
+ tmp += LayoutItem(maxTopItem - 1);
+ cachedMaxTopItem = maxTopItem;
+ cachedWindowHeight = windowHeight;
+ cachedMaxTopPixel = (windowHeight < tmp) ? windowHeight - tmp : 0;
+ }
- case EVENTTYPE_STATUSCHANGE:
- tpl = TPL_COPY_SIGN;
- fontid = FONT_STATUS;
- colorid = COLOR_STATUS;
- break;
+ if (scrollTopItem < 0)
+ scrollTopItem = 0;
- case EVENTTYPE_AUTHREQUEST:
- tpl = TPL_COPY_AUTH;
- fontid = FONT_INOTHER;
- colorid = COLOR_INOTHER;
- break;
+ if ((scrollTopItem > cachedMaxTopItem) ||
+ ((scrollTopItem == cachedMaxTopItem) && (scrollTopPixel < cachedMaxTopPixel))) {
+ scrollTopItem = cachedMaxTopItem;
+ scrollTopPixel = cachedMaxTopPixel;
+ }
- case EVENTTYPE_ADDED:
- tpl = TPL_COPY_ADDED;
- fontid = FONT_INOTHER;
- colorid = COLOR_INOTHER;
- break;
+ RecalcScrollBar();
+ }
- case EVENTTYPE_JABBER_PRESENCE:
- tpl = TPL_COPY_PRESENCE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
- break;
+ int LayoutItem(int index)
+ {
+ HDC hdc = GetDC(hwnd);
+ RECT rc; GetClientRect(hwnd, &rc);
+ int width = rc.right - rc.left;
- default:
- tpl = TPL_COPY_OTHER;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
- break;
- }
+ ItemData *item = items.get(index, ItemData::ELM_DATA);
+ if (!item) {
+ DeleteDC(hdc);
+ return 0;
+ }
- ptrW text(TplFormatString(tpl, item->hContact, item));
- data->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(data->hwndEditBox, GWLP_WNDPROC, (LONG_PTR)HistoryEditWndProc);
- SendMessage(data->hwndEditBox, WM_SETFONT, (WPARAM)g_fontTable[fontid].hfnt, 0);
- SendMessage(data->hwndEditBox, EM_SETMARGINS, EC_RIGHTMARGIN, 100);
- SendMessage(data->hwndEditBox, EM_SETSEL, 0, (LPARAM)(-1));
- ShowWindow(data->hwndEditBox, SW_SHOW);
- SetFocus(data->hwndEditBox);
+ int tpl;
+ int fontid;
+ switch (item->dbe.eventType) {
+ case EVENTTYPE_MESSAGE:
+ tpl = TPL_MESSAGE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
break;
- }
- top += itemHeight;
- idx++;
- itemHeight = LayoutItem(hwnd, &data->items, idx);
- }
-}
-static void EndEditItem(HWND, NewstoryListData *data)
-{
- DestroyWindow(data->hwndEditBox);
- data->hwndEditBox = 0;
-}
+ case EVENTTYPE_FILE:
+ tpl = TPL_FILE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ break;
-static int LayoutItem(HWND hwnd, HistoryArray *items, int index)
-{
- HDC hdc = GetDC(hwnd);
- RECT rc; GetClientRect(hwnd, &rc);
- int width = rc.right - rc.left;
+ case EVENTTYPE_STATUSCHANGE:
+ tpl = TPL_SIGN;
+ fontid = FONT_STATUS;
+ break;
- ItemData *item = items->get(index, ItemData::ELM_DATA);
- if (!item) {
- DeleteDC(hdc);
- return 0;
- }
+ case EVENTTYPE_AUTHREQUEST:
+ tpl = TPL_AUTH;
+ fontid = FONT_INOTHER;
+ break;
- int tpl;
- int fontid;
- switch (item->dbe.eventType) {
- case EVENTTYPE_MESSAGE:
- tpl = TPL_MESSAGE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
- break;
+ case EVENTTYPE_ADDED:
+ tpl = TPL_ADDED;
+ fontid = FONT_INOTHER;
+ break;
- case EVENTTYPE_FILE:
- tpl = TPL_FILE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
- break;
+ case EVENTTYPE_JABBER_PRESENCE:
+ tpl = TPL_PRESENCE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ break;
- case EVENTTYPE_STATUSCHANGE:
- tpl = TPL_SIGN;
- fontid = FONT_STATUS;
- break;
+ default:
+ tpl = TPL_OTHER;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ break;
+ }
- case EVENTTYPE_AUTHREQUEST:
- tpl = TPL_AUTH;
- fontid = FONT_INOTHER;
- break;
+ HFONT hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
+ if (!item->data)
+ item->data = MTextCreateW(htuLog, ptrW(TplFormatString(tpl, item->hContact, item)));
- case EVENTTYPE_ADDED:
- tpl = TPL_ADDED;
- fontid = FONT_INOTHER;
- break;
+ SIZE sz;
+ sz.cx = width - 6;
+ MTextMeasure(hdc, &sz, (HANDLE)item->data);
- case EVENTTYPE_JABBER_PRESENCE:
- tpl = TPL_PRESENCE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- break;
+ SelectObject(hdc, hfnt);
- default:
- tpl = TPL_OTHER;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- break;
+ ReleaseDC(hwnd, hdc);
+ return sz.cy + 5;
}
- HFONT hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
- if (!item->data)
- item->data = MTextCreateW(htuLog, ptrW(TplFormatString(tpl, item->hContact, item)));
-
- SIZE sz;
- sz.cx = width - 6;
- MTextMeasure(hdc, &sz, (HANDLE)item->data);
-
- SelectObject(hdc, hfnt);
+ int PaintItem(HDC hdc, int index, int top, int width)
+ {
+ ItemData *item = items.get(index, ItemData::ELM_DATA);
+
+ // LOGFONT lfText;
+ COLORREF clText, clBack, clLine;
+ int tpl;
+ int fontid;
+ int colorid;
+ switch (item->dbe.eventType) {
+ case EVENTTYPE_MESSAGE:
+ tpl = TPL_MESSAGE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INMSG : COLOR_OUTMSG;
+ break;
- ReleaseDC(hwnd, hdc);
- return sz.cy + 5;
-}
+ case EVENTTYPE_FILE:
+ tpl = TPL_FILE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
+ break;
-static int PaintItem(HDC hdc, HistoryArray *items, int index, int top, int width)
-{
- if (!items)
- return 0;
-
- ItemData *item = items->get(index, ItemData::ELM_DATA);
-
- // LOGFONT lfText;
- COLORREF clText, clBack, clLine;
- int tpl;
- int fontid;
- int colorid;
- switch (item->dbe.eventType) {
- case EVENTTYPE_MESSAGE:
- tpl = TPL_MESSAGE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INMSG : COLOR_OUTMSG;
- break;
+ case EVENTTYPE_STATUSCHANGE:
+ tpl = TPL_SIGN;
+ fontid = FONT_STATUS;
+ colorid = COLOR_STATUS;
+ break;
- case EVENTTYPE_FILE:
- tpl = TPL_FILE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
- break;
+ case EVENTTYPE_AUTHREQUEST:
+ tpl = TPL_AUTH;
+ fontid = FONT_INOTHER;
+ colorid = COLOR_INOTHER;
+ break;
- case EVENTTYPE_STATUSCHANGE:
- tpl = TPL_SIGN;
- fontid = FONT_STATUS;
- colorid = COLOR_STATUS;
- break;
+ case EVENTTYPE_ADDED:
+ tpl = TPL_ADDED;
+ fontid = FONT_INOTHER;
+ colorid = COLOR_INOTHER;
+ break;
- case EVENTTYPE_AUTHREQUEST:
- tpl = TPL_AUTH;
- fontid = FONT_INOTHER;
- colorid = COLOR_INOTHER;
- break;
+ case EVENTTYPE_JABBER_PRESENCE:
+ tpl = TPL_PRESENCE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ break;
- case EVENTTYPE_ADDED:
- tpl = TPL_ADDED;
- fontid = FONT_INOTHER;
- colorid = COLOR_INOTHER;
- break;
+ default:
+ tpl = TPL_OTHER;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ break;
+ }
+ clText = g_fontTable[fontid].cl;
+ if (item->flags & HIF_SELECTED) {
+ MTextSendMessage(0, item->data, EM_SETSEL, 0, -1);
+ clText = g_colorTable[COLOR_SELTEXT].cl;
+ clLine = GetSysColor(COLOR_HIGHLIGHTTEXT);
+ clBack = GetSysColor(COLOR_HIGHLIGHT);
+ }
+ else {
+ MTextSendMessage(0, item->data, EM_SETSEL, 0, 0);
+ clLine = g_colorTable[COLOR_SELECTED].cl;
+ clBack = g_colorTable[colorid].cl;
+ }
- case EVENTTYPE_JABBER_PRESENCE:
- tpl = TPL_PRESENCE;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
- break;
+ if (!item->data) {
+ item->data = MTextCreateW(htuLog, ptrW(TplFormatString(tpl, item->hContact, item)));
+ if (!item->data)
+ return 0;
+ }
- default:
- tpl = TPL_OTHER;
- fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
- break;
- }
- clText = g_fontTable[fontid].cl;
- if (item->flags & HIF_SELECTED) {
- MTextSendMessage(0, item->data, EM_SETSEL, 0, -1);
- clText = g_colorTable[COLOR_SELTEXT].cl;
- clLine = GetSysColor(COLOR_HIGHLIGHTTEXT);
- clBack = GetSysColor(COLOR_HIGHLIGHT);
- }
- else {
- MTextSendMessage(0, item->data, EM_SETSEL, 0, 0);
- clLine = g_colorTable[COLOR_SELECTED].cl;
- clBack = g_colorTable[colorid].cl;
+ SIZE sz;
+ sz.cx = width - 6;
+ HFONT hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
+ MTextMeasure(hdc, &sz, (HANDLE)item->data);
+ SelectObject(hdc, hfnt);
+ int height = sz.cy + 5;
+
+ RECT rc;
+ SetRect(&rc, 0, top, width, top + height);
+
+ HBRUSH hbr;
+ hbr = CreateSolidBrush(clBack);
+ FillRect(hdc, &rc, hbr);
+
+ SetTextColor(hdc, clText);
+ SetBkMode(hdc, TRANSPARENT);
+
+ POINT pos;
+ pos.x = 3;
+ pos.y = top + 2;
+ hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
+ MTextDisplay(hdc, pos, sz, (HANDLE)item->data);
+ SelectObject(hdc, hfnt);
+
+ DeleteObject(hbr);
+
+ HPEN hpn = (HPEN)SelectObject(hdc, CreatePen(PS_SOLID, 1, clLine));
+ MoveToEx(hdc, rc.left, rc.bottom - 1, 0);
+ LineTo(hdc, rc.right, rc.bottom - 1);
+ DeleteObject(SelectObject(hdc, hpn));
+ return height;
}
- if (!item->data) {
- item->data = MTextCreateW(htuLog, ptrW(TplFormatString(tpl, item->hContact, item)));
- if (!item->data)
- return 0;
+ void RecalcScrollBar()
+ {
+ SCROLLINFO si = { 0 };
+ RECT clRect;
+ GetClientRect(hwnd, &clRect);
+ si.cbSize = sizeof(si);
+ si.fMask = SIF_ALL;
+ si.nMin = 0;
+ si.nMax = items.getCount() * AVERAGE_ITEM_HEIGHT;
+ si.nPage = clRect.bottom;
+ si.nPos = scrollTopItem * AVERAGE_ITEM_HEIGHT;
+ SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
}
- SIZE sz;
- sz.cx = width - 6;
- HFONT hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
- MTextMeasure(hdc, &sz, (HANDLE)item->data);
- SelectObject(hdc, hfnt);
- int height = sz.cy + 5;
+ void ScrollListBy(int scrollItems, int scrollPixels)
+ {
+ if (scrollItems) {
+ scrollTopItem += scrollItems;
+ scrollTopPixel = 0;
+ }
+ else if (scrollPixels) {
+ scrollTopPixel += scrollPixels;
+ if (scrollTopPixel > 0) {
+ while ((scrollTopPixel > 0) && scrollTopItem) {
+ scrollTopItem--;
+ int itemHeight = LayoutItem(scrollTopItem);
+ scrollTopPixel -= itemHeight;
+ }
- RECT rc;
- SetRect(&rc, 0, top, width, top + height);
+ if (scrollTopPixel > 0) {
+ scrollTopPixel = 0;
+ }
+ }
+ else if (scrollTopPixel < 0) {
+ int maxItem = items.getCount();
+ int itemHeight = LayoutItem(scrollTopItem);
+ while ((-scrollTopPixel > itemHeight) && (scrollTopItem < maxItem)) {
+ scrollTopPixel += itemHeight;
+ scrollTopItem++;
+ itemHeight = LayoutItem(scrollTopItem);
+ }
+ }
+ }
- HBRUSH hbr;
- hbr = CreateSolidBrush(clBack);
- FillRect(hdc, &rc, hbr);
+ FixScrollPosition();
+ }
+};
- SetTextColor(hdc, clText);
- SetBkMode(hdc, TRANSPARENT);
+// Edit box
+static LRESULT CALLBACK HistoryEditWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ auto *pData = (NewstoryListData *)GetWindowLongPtr(GetParent(hwnd), 0);
- POINT pos;
- pos.x = 3;
- pos.y = top + 2;
- hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
- MTextDisplay(hdc, pos, sz, (HANDLE)item->data);
- SelectObject(hdc, hfnt);
+ switch (msg) {
+ case WM_KEYDOWN:
+ switch (wParam) {
+ case VK_ESCAPE:
+ pData->EndEditItem();
+ return 0;
+ }
+ break;
- DeleteObject(hbr);
+ case WM_GETDLGCODE:
+ if (lParam) {
+ MSG *msg2 = (MSG *)lParam;
+ if (msg2->message == WM_KEYDOWN && msg2->wParam == VK_TAB)
+ return 0;
+ if (msg2->message == WM_CHAR && msg2->wParam == '\t')
+ return 0;
+ }
+ return DLGC_WANTMESSAGE;
- HPEN hpn = (HPEN)SelectObject(hdc, CreatePen(PS_SOLID, 1, clLine));
- MoveToEx(hdc, rc.left, rc.bottom - 1, 0);
- LineTo(hdc, rc.right, rc.bottom - 1);
- DeleteObject(SelectObject(hdc, hpn));
+ case WM_KILLFOCUS:
+ pData->EndEditItem();
+ return 0;
+ }
- return height;
+ return CallWindowProc(OldEditWndProc, hwnd, msg, wParam, lParam);
}
/////////////////////////////////////////////////////////////////////////
@@ -450,9 +442,9 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
switch (msg) {
case WM_CREATE:
- data = new NewstoryListData;
+ data = new NewstoryListData(hwnd);
SetWindowLongPtr(hwnd, 0, (LONG_PTR)data);
- RecalcScrollBar(hwnd, data);
+ data->RecalcScrollBar();
break;
// History list control messages
@@ -463,17 +455,17 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
p->hFirstEVent = db_event_first(p->hContact);
data->items.addEvent(p->hContact, p->hFirstEVent, p->eventCount);
}
- RecalcScrollBar(hwnd, data);
+ data->RecalcScrollBar();
data->scrollTopItem = data->items.getCount();
- FixScrollPosition(hwnd, data);
+ data->FixScrollPosition();
InvalidateRect(hwnd, 0, FALSE);
break;
case NSM_ADDCHATEVENT:
data->items.addChatEvent((SESSION_INFO *)wParam, (LOGINFO*)lParam);
- RecalcScrollBar(hwnd, data);
+ data->RecalcScrollBar();
data->scrollTopItem = data->items.getCount();
- FixScrollPosition(hwnd, data);
+ data->FixScrollPosition();
InvalidateRect(hwnd, 0, FALSE);
break;
@@ -551,7 +543,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
case NSM_ENSUREVISIBLE:
- EnsureVisible(hwnd, data, wParam);
+ data->EnsureVisible(wParam);
return 0;
case NSM_GETITEMFROMPIXEL:
@@ -562,14 +554,14 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int count = data->items.getCount();
int current = data->scrollTopItem;
int top = data->scrollTopPixel;
- int bottom = top + LayoutItem(hwnd, &data->items, current);
+ int bottom = top + data->LayoutItem(current);
while (top <= height) {
if ((lParam >= top) && (lParam <= bottom))
return current;
if (++current >= count)
return -1;
top = bottom;
- bottom = top + LayoutItem(hwnd, &data->items, current);
+ bottom = top + data->LayoutItem(current);
}
return -1;
}
@@ -726,7 +718,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int top = data->scrollTopPixel;
int idx = data->scrollTopItem;
while ((top < height) && (idx < data->items.getCount()))
- top += PaintItem(hdc, &data->items, idx++, top, width);
+ top += data->PaintItem(hdc, idx++, top, width);
if (top <= height) {
RECT rc2;
@@ -799,7 +791,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
break;
case VK_F2:
- BeginEditItem(hwnd, data, data->caret);
+ data->BeginEditItem(data->caret);
break;
}
break;
@@ -809,7 +801,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
case WM_CHAR:
if (wParam == 27) {
if (data->hwndEditBox)
- EndEditItem(hwnd, data);
+ data->EndEditItem();
}
else {
char ch = MapVirtualKey((lParam >> 16) & 0xff, 1);
@@ -831,7 +823,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int item = SendMessage(hwnd, NSM_GETITEMFROMPIXEL, LOWORD(lParam), HIWORD(lParam));
if (item >= 0) {
if (data->caret != item)
- EndEditItem(hwnd, data);
+ data->EndEditItem();
if (wParam & MK_CONTROL) {
SendMessage(hwnd, NSM_TOGGLEITEMS, item, item);
@@ -842,9 +834,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
SendMessage(hwnd, NSM_SETCARET, item, TRUE);
}
else {
- if (data->caret == item) {
- BeginEditItem(hwnd, data, item);
- }
+ if (data->caret == item)
+ data->BeginEditItem(item);
else {
SendMessage(hwnd, NSM_SELECTITEMS2, item, item);
SendMessage(hwnd, NSM_SETCARET, item, TRUE);
@@ -863,7 +854,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
UINT scrollLines;
if (!SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, FALSE))
scrollLines = 3;
- ScrollListBy(hwnd, data, 0, (short)HIWORD(wParam) * 10 * (signed)scrollLines / WHEEL_DELTA);
+ data->ScrollListBy(0, (short)HIWORD(wParam) * 10 * (signed)scrollLines / WHEEL_DELTA);
if ((s_scrollTopItem != data->scrollTopItem) || (s_scrollTopPixel != data->scrollTopPixel))
InvalidateRect(hwnd, 0, FALSE);
@@ -877,16 +868,16 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
switch (LOWORD(wParam)) {
case SB_LINEUP:
- ScrollListBy(hwnd, data, 0, 10);
+ data->ScrollListBy(0, 10);
break;
case SB_LINEDOWN:
- ScrollListBy(hwnd, data, 0, -10);
+ data->ScrollListBy(0, -10);
break;
case SB_PAGEUP:
- ScrollListBy(hwnd, data, -10, 0);
+ data->ScrollListBy(-10, 0);
break;
case SB_PAGEDOWN:
- ScrollListBy(hwnd, data, 10, 0);
+ data->ScrollListBy(10, 0);
break;
case SB_BOTTOM:
data->scrollTopItem = data->items.getCount() - 1;
@@ -910,10 +901,10 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
else {
data->scrollTopItem = pos / AVERAGE_ITEM_HEIGHT;
- int itemHeight = LayoutItem(hwnd, &data->items, data->scrollTopItem);
+ int itemHeight = data->LayoutItem(data->scrollTopItem);
data->scrollTopPixel = -pos % AVERAGE_ITEM_HEIGHT * itemHeight / AVERAGE_ITEM_HEIGHT;
}
- FixScrollPosition(hwnd, data);
+ data->FixScrollPosition();
}
break;