diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-10 12:02:31 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-10 12:02:31 +0300 |
commit | 3187428bb2f7b929e31ebf64b1e21d9c0fbc4f2b (patch) | |
tree | fa1704b43d0a1c5b3c7b67f1e4f9f8142f39d0be /plugins | |
parent | 258cb3c6a167d7f3ca125de2d7ba70ea2ef65a63 (diff) |
NewStory: memory leak fix + small quirks fixed
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/NewStory/src/fonts.cpp | 16 | ||||
-rw-r--r-- | plugins/NewStory/src/fonts.h | 3 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 25 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 2 | ||||
-rw-r--r-- | plugins/NewStory/src/history_log.cpp | 6 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 34 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.h | 9 |
7 files changed, 61 insertions, 34 deletions
diff --git a/plugins/NewStory/src/fonts.cpp b/plugins/NewStory/src/fonts.cpp index b054cf542d..c805a9a072 100644 --- a/plugins/NewStory/src/fonts.cpp +++ b/plugins/NewStory/src/fonts.cpp @@ -2,30 +2,30 @@ MyColourID g_colorTable[COLOR_COUNT] = { + { LPGEN("Incoming name"), "ColorNickIn", RGB(0xc8, 0x3f, 0x6b) }, + { LPGEN("Outgoing name"), "ColorNickOut", RGB(0x08, 0x60, 0xbd) }, + { LPGEN("Incoming messages"), "ColorMsgIn", RGB(0xd6, 0xf5, 0xc0) }, { LPGEN("Outgoing messages"), "ColorMsgOut", RGB(0xf5, 0xe7, 0xd8) }, - + { LPGEN("Incoming files"), "ColorFileIn", RGB(0xe3, 0xee, 0x9b) }, { LPGEN("Outgoing files"), "ColorFileOut", RGB(0xe3, 0xee, 0x9b) }, - + { LPGEN("Status changes"), "ColorStatus", RGB(0xf0, 0xf0, 0xf0) }, - + { LPGEN("Other incoming events"), "ColorIn", RGB(0xff, 0xff, 0xff) }, { LPGEN("Other outgoing events"), "ColorOut", RGB(0xff, 0xff, 0xff) }, - + { LPGEN("Selected item's text"), "ColorSelTxt", RGB(0xff, 0xff, 0xff) }, { LPGEN("Selected item's background"), "ColorSel", GetSysColor(COLOR_HIGHLIGHT) }, { LPGEN("Selected item's frame"), "ColorSelFrm", GetSysColor(COLOR_HIGHLIGHTTEXT) }, - + { LPGEN("Grid background"), "Background", RGB(0xff, 0xff, 0xff) }, { LPGEN("Separator"), "Separator", RGB(0x60, 0x60, 0x60) }, }; MyFontID g_fontTable[FONT_COUNT] = { - { LPGEN("Incoming name"), "FontNickIn", RGB(0xc8, 0x3f, 0x6b) }, - { LPGEN("Outgoing name"), "FontNickOut", RGB(0x08, 0x60, 0xbd) }, - { LPGEN("Incoming messages"), "FontMsgIn" }, { LPGEN("Outgoing messages"), "FontMsgOut" }, diff --git a/plugins/NewStory/src/fonts.h b/plugins/NewStory/src/fonts.h index 6707639d16..55875643c6 100644 --- a/plugins/NewStory/src/fonts.h +++ b/plugins/NewStory/src/fonts.h @@ -5,6 +5,7 @@ enum { + COLOR_INNICK, COLOR_OUTNICK, COLOR_INMSG, COLOR_OUTMSG, COLOR_INFILE, COLOR_OUTFILE, COLOR_STATUS, @@ -26,8 +27,6 @@ extern MyColourID g_colorTable[COLOR_COUNT]; enum { - FONT_INNICK, - FONT_OUTNICK, FONT_INMSG, FONT_OUTMSG, FONT_INFILE, diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 5da6bc1a02..329b333920 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -73,6 +73,11 @@ void NewstoryListData::OnTimer(CTimer *pTimer) { pTimer->Stop(); + if (bScrollBottom) { + bScrollBottom = false; + EnsureVisible(totalCount - 1); + } + InvalidateRect(hwnd, 0, FALSE); } @@ -251,10 +256,9 @@ void NewstoryListData::FixScrollPosition() int windowHeight = rc.bottom - rc.top; if (windowHeight != cachedWindowHeight || cachedMaxTopItem != scrollTopItem) { - int maxTopItem = 0; - int tmp = 0; - for (maxTopItem = totalCount; (maxTopItem > 0) && (tmp < windowHeight); maxTopItem--) - tmp += GetItemHeight(maxTopItem - 1); + int maxTopItem = totalCount, tmp = 0; + while (maxTopItem > 0 && tmp < windowHeight) + tmp += GetItemHeight(--maxTopItem); cachedMaxTopItem = maxTopItem; cachedWindowHeight = windowHeight; cachedMaxTopPixel = (windowHeight < tmp) ? windowHeight - tmp : 0; @@ -537,15 +541,18 @@ void NewstoryListData::PageDown() void NewstoryListData::ScrollTop() { - SetPos(0); + EnsureVisible(0); + ScheduleDraw(); } void NewstoryListData::ScrollBottom() { - if (totalCount) - SetPos(totalCount - 1); -} + if (!totalCount) + return; + bScrollBottom = true; + ScheduleDraw(); +} ///////////////////////////////////////////////////////////////////////////////////////// // Edit box window procedure @@ -614,7 +621,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VSCROLL); break; - // History list control messages + // History list control messages case NSM_ADDEVENTS: if (auto *p = (ADDEVENTS *)wParam) { data->items.addEvent(p->hContact, p->hFirstEVent, p->eventCount); diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 9cd9e9d782..2e1e6901f6 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -80,7 +80,7 @@ struct NewstoryListData : public MZeroedObject RECT rcLastPaint; - bool bWasShift, bSortAscending, hasData; + bool bWasShift, bSortAscending, hasData, bScrollBottom; HWND hwnd; HWND hwndEditBox; diff --git a/plugins/NewStory/src/history_log.cpp b/plugins/NewStory/src/history_log.cpp index 8c9775706b..7b85321202 100644 --- a/plugins/NewStory/src/history_log.cpp +++ b/plugins/NewStory/src/history_log.cpp @@ -12,7 +12,11 @@ public: void Attach() override { - m_hwnd = ::CreateWindow(_T(NEWSTORYLIST_CLASS), L"NewStory", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 0, 0, 300, 150, m_pDlg.GetHwnd(), 0, m_pDlg.GetInst(), 0); + RECT rc; + GetClientRect(GetDlgItem(m_pDlg.GetHwnd(), IDC_SRMM_LOG), &rc); + + m_hwnd = ::CreateWindowW(_T(NEWSTORYLIST_CLASS), L"NewStory", WS_VISIBLE | WS_CHILD | WS_TABSTOP, + 0, 0, rc.left - rc.right, rc.bottom - rc.top, m_pDlg.GetHwnd(), 0, m_pDlg.GetInst(), 0); SendMessage(m_hwnd, NSM_SET_SRMM, 0, (LPARAM)&m_pDlg); } diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 451342034e..87c3faf9de 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -150,11 +150,11 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, ItemData *item) if (item->dbe.flags & DBEF_SENT) { char *proto = Proto_GetBaseAccountName(item->hContact); ptrW nick(Contact::GetInfo(CNF_DISPLAY, 0, proto)); - vars->SetVar('N', nick, false); + vars->SetNick(nick, false); } else { wchar_t *nick = (item->wszNick) ? item->wszNick : Clist_GetContactDisplayName(item->hContact, 0); - vars->SetVar('N', nick, false); + vars->SetNick(nick, true); } // %I: Icon @@ -200,10 +200,9 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, ItemData *item) if (!TimeZone_GetSystemTime(nullptr, item->dbe.timestamp, &st, 0)) { int iLocale = Langpack_GetDefaultLocale(); - CMStringW tmp; - GetDateFormatW(iLocale, 0, &st, L"dd.MM.yyyy, ", buf, _countof(buf)); tmp += buf; - GetTimeFormatW(iLocale, 0, &st, L"HH:mm", buf, _countof(buf)); tmp += buf; - vars->SetVar('t', tmp, true); + GetDateFormatW(iLocale, 0, &st, L"dd.MM.yyyy, ", buf, _countof(buf)); + GetTimeFormatW(iLocale, 0, &st, L"HH:mm", buf + 12, _countof(buf)); + vars->SetVar('t', buf, true); // %h: hour (24 hour format, 0-23) GetTimeFormatW(iLocale, 0, &st, L"HH", buf, _countof(buf)); @@ -295,6 +294,29 @@ void vfOther(int, TemplateVars *vars, MCONTACT, ItemData *item) ///////////////////////////////////////////////////////////////////////////////////////// +void TemplateVars::SetNick(wchar_t *v, bool bIncoming) +{ + CMStringW wszNick(FORMAT, L"[color=%d]%s[/color]", g_colorTable[(bIncoming) ? COLOR_INNICK : COLOR_OUTNICK].cl, v); + + auto &V = vars['N']; + if (V.del) + mir_free(V.val); + V.val = wszNick.Detach(); + V.del = true; +} + +void TemplateVars::SetVar(uint8_t id, wchar_t *v, bool d) +{ + auto &V = vars[id]; + if (V.del) + mir_free(V.val); + + V.val = (d) ? mir_wstrdup(v) : v; + V.del = d; +} + +///////////////////////////////////////////////////////////////////////////////////////// + HICON TemplateInfo::getIcon() const { return (iIcon < 0) ? Skin_LoadIcon(-iIcon) : g_plugin.getIcon(iIcon); diff --git a/plugins/NewStory/src/templates.h b/plugins/NewStory/src/templates.h index a2564940c4..7cee810fb1 100644 --- a/plugins/NewStory/src/templates.h +++ b/plugins/NewStory/src/templates.h @@ -19,13 +19,8 @@ struct TemplateVars return vars[id].val; } - __forceinline void SetVar(uint8_t id, const wchar_t *v, bool d) { - auto &V = vars[id]; - if (V.val && V.del) - mir_free(V.val); - V.val = mir_wstrdup(v); - V.del = d; - } + void SetNick(wchar_t *v, bool bIncoming); + void SetVar(uint8_t id, wchar_t *v, bool d); }; typedef void (*VarFunc)(int mode, TemplateVars *vars, MCONTACT hContact, ItemData *item); |