summaryrefslogtreecommitdiff
path: root/plugins/NewStory
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-03-30 19:42:10 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-03-30 19:42:10 +0300
commit4c0d70f527b2d1382a5d1d9c625eaf8537a25d6d (patch)
tree3e694ead31c8509d64d2c4fc15376710d3513106 /plugins/NewStory
parent11d58880ebb4346c5a188fdb0e6ab78cc8d31db1 (diff)
NewStory: code cleaning
Diffstat (limited to 'plugins/NewStory')
-rw-r--r--plugins/NewStory/src/history_array.cpp13
-rw-r--r--plugins/NewStory/src/history_array.h25
-rw-r--r--plugins/NewStory/src/history_control.cpp238
3 files changed, 124 insertions, 152 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 00854aef19..378847f142 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -46,7 +46,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode)
mir_snprintf(atext, 512, ("%s requested authorization"), dbe.pBlob + 8);
}
else {
- mir_snprintf(atext, 512, ("%d requested authorization"), *(DWORD*)(dbe.pBlob));
+ mir_snprintf(atext, 512, ("%d requested authorization"), *(DWORD *)(dbe.pBlob));
}
aLength = lstrlenA(atext);
break;
@@ -60,7 +60,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode)
mir_snprintf(atext, 512, ("%s added you to the contact list"), dbe.pBlob + 8);
}
else {
- mir_snprintf(atext, 512, ("%d added you to the contact list"), *(DWORD*)(dbe.pBlob));
+ mir_snprintf(atext, 512, ("%d added you to the contact list"), *(DWORD *)(dbe.pBlob));
}
aLength = lstrlenA(atext);
break;
@@ -68,15 +68,15 @@ bool HistoryArray::ItemData::load(EventLoadMode mode)
}
if (atext && !wtext) {
- #ifdef UNICODE
+#ifdef UNICODE
int bufSize = MultiByteToWideChar(CP_ACP, 0, atext, aLength + 1, 0, 0);
wtext = new WCHAR[bufSize + 1];
MultiByteToWideChar(CP_ACP, 0, atext, aLength + 1, wtext, bufSize);
wtext_del = true;
- #else
+#else
this->wtext = 0;
wtext_del = false;
- #endif
+#endif
}
else
if (!atext && wtext) {
@@ -110,7 +110,6 @@ HistoryArray::ItemData::~ItemData()
// Array
HistoryArray::HistoryArray()
{
- head = tail = 0;
}
HistoryArray::~HistoryArray()
@@ -164,7 +163,7 @@ bool HistoryArray::addHistory(MCONTACT hContact, EventLoadMode)
tail->items[i].hEvent = hEvent;
++i;
- hEvent = db_event_next(hEvent, 0);
+ hEvent = db_event_next(hEvent, hContact);
}
return true;
}
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index e9b92142cf..955e63b1b5 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -32,22 +32,23 @@ class HistoryArray
public:
struct ItemData
{
- BYTE flags;
+ BYTE flags = 0;
- MCONTACT hContact;
- MEVENT hEvent;
+ MCONTACT hContact = 0;
+ MEVENT hEvent = 0;
- bool dbeOk;
+ bool dbeOk = false;
DBEVENTINFO dbe;
- bool atext_del, wtext_del;
- char *atext;
- WCHAR *wtext;
+ bool atext_del = false, wtext_del = false;
+ char *atext = 0;
+ WCHAR *wtext = 0;
- HANDLE data;
+ HANDLE data = 0;
- ItemData() : flags(0), hContact(0), hEvent(0), atext(0), wtext(0), atext_del(false), wtext_del(false), data(0), dbeOk(false) {}
+ ItemData() { memset(&dbe, 0, sizeof(dbe)); }
~ItemData();
+
bool load(EventLoadMode mode);
inline bool loadInline(EventLoadMode mode)
{
@@ -169,9 +170,9 @@ public:
};
private:
- ItemBlock *head, *tail;
- ItemBlock *preBlock;
- int preIndex;
+ ItemBlock *head = 0, *tail = 0;
+ ItemBlock *preBlock = 0;
+ int preIndex = 0;
bool allocateBlock(int count);
public:
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index afb1cd890a..315c9b39bd 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -101,28 +101,22 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
switch (msg) {
case WM_CREATE:
- {
- data = new NewstoryListData;
- SetWindowLongPtr(hwnd, 0, (LONG_PTR)data);
- RecalcScrollBar(hwnd, data);
- break;
- }
+ data = new NewstoryListData;
+ SetWindowLongPtr(hwnd, 0, (LONG_PTR)data);
+ RecalcScrollBar(hwnd, data);
+ break;
case WM_USER:
- {
- data->items.addHistory((MCONTACT)wParam);
- RecalcScrollBar(hwnd, data);
- data->scrollTopItem = data->items.getCount();
- FixScrollPosition(hwnd, data);
- InvalidateRect(hwnd, 0, FALSE);
- break;
- }
+ data->items.addHistory((MCONTACT)wParam);
+ RecalcScrollBar(hwnd, data);
+ data->scrollTopItem = data->items.getCount();
+ FixScrollPosition(hwnd, data);
+ InvalidateRect(hwnd, 0, FALSE);
+ break;
// History list control messages
case NSM_GETCOUNT:
- {
- return data->items.getCount();
- }
+ return data->items.getCount();
case NSM_SELECTITEMS:
{
@@ -198,10 +192,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
case NSM_ENSUREVISIBLE:
- {
- EnsureVisible(hwnd, data, wParam);
- return 0;
- }
+ EnsureVisible(hwnd, data, wParam);
+ return 0;
case NSM_GETITEMFROMPIXEL:
{
@@ -266,7 +258,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int eventCount = data->items.getCount();
for (int i = 0; i < eventCount; i++) {
HistoryArray::ItemData *item = data->items.get(i, ELM_NOTHING);
- if (item->flags&HIF_SELECTED) {
+ if (item->flags & HIF_SELECTED) {
buf = TplFormatString(TPL_COPY_MESSAGE, item->hContact, item);
res = appendString(res, buf);
free(buf);
@@ -366,99 +358,82 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
EndPaint(hwnd, &ps);
- break;
}
+ break;
case WM_SETFOCUS:
- {
- return 0;
- }
+ return 0;
case WM_GETDLGCODE:
- {
- if (lParam) {
- MSG *msg2 = (MSG *)lParam;
- if (msg2->message == WM_KEYDOWN) {
- if (msg2->wParam == VK_TAB)
- return 0;
- if (msg2->wParam == VK_ESCAPE && !data->hwndEditBox)
- return 0;
- }
- else
- if (msg2->message == WM_CHAR) {
- if (msg2->wParam == '\t')
- return 0;
- if (msg2->wParam == 27 && !data->hwndEditBox)
- return 0;
- }
+ if (lParam) {
+ MSG *msg2 = (MSG *)lParam;
+ if (msg2->message == WM_KEYDOWN) {
+ if (msg2->wParam == VK_TAB)
+ return 0;
+ if (msg2->wParam == VK_ESCAPE && !data->hwndEditBox)
+ return 0;
+ }
+ else if (msg2->message == WM_CHAR) {
+ if (msg2->wParam == '\t')
+ return 0;
+ if (msg2->wParam == 27 && !data->hwndEditBox)
+ return 0;
}
- return DLGC_WANTMESSAGE;
}
-
+ return DLGC_WANTMESSAGE;
case WM_KEYDOWN:
{
switch (wParam) {
case VK_UP:
- {
- SendMessage(hwnd, NSM_SELECTITEMS2, data->caret - 1, data->caret - 1);
- SendMessage(hwnd, NSM_SETCARET, data->caret - 1, TRUE);
- break;
- }
+ SendMessage(hwnd, NSM_SELECTITEMS2, data->caret - 1, data->caret - 1);
+ SendMessage(hwnd, NSM_SETCARET, data->caret - 1, TRUE);
+ break;
+
case VK_DOWN:
- {
- SendMessage(hwnd, NSM_SELECTITEMS2, data->caret + 1, data->caret + 1);
- SendMessage(hwnd, NSM_SETCARET, data->caret + 1, TRUE);
- break;
- }
+ SendMessage(hwnd, NSM_SELECTITEMS2, data->caret + 1, data->caret + 1);
+ SendMessage(hwnd, NSM_SETCARET, data->caret + 1, TRUE);
+ break;
+
case VK_PRIOR:
- {
- break;
- }
+ break;
+
case VK_NEXT:
- {
- break;
- }
+ break;
+
case VK_HOME:
- {
- break;
- }
+ break;
+
case VK_END:
- {
- break;
- }
+ break;
+
case VK_F2:
- {
- BeginEditItem(hwnd, data, data->caret);
- break;
- }
+ BeginEditItem(hwnd, data, data->caret);
+ break;
}
break;
}
case WM_SYSCHAR:
case WM_CHAR:
- {
- if (wParam == 27) {
- if (data->hwndEditBox)
- EndEditItem(hwnd, data);
+ if (wParam == 27) {
+ if (data->hwndEditBox)
+ EndEditItem(hwnd, data);
+ }
+ else {
+ char ch = MapVirtualKey((lParam >> 16) & 0xff, 1);
+ if (((ch == 'C') || (ch == VK_INSERT)) && (GetKeyState(VK_CONTROL) & 0x80)) {
+ PostMessage(hwnd, NSM_COPY, 0, 0);
}
- else {
- char ch = MapVirtualKey((lParam >> 16) & 0xff, 1);
- if (((ch == 'C') || (ch == VK_INSERT)) && (GetKeyState(VK_CONTROL) & 0x80)) {
- PostMessage(hwnd, NSM_COPY, 0, 0);
- }
- else
- if ((ch == 'A') && (GetKeyState(VK_CONTROL) & 0x80)) {
- SendMessage(hwnd, NSM_SELECTITEMS, 0, data->items.getCount());
- // } else
- // if (ch == VK_ESCAPE)
- // {
- // PostMessage(GetParent(hwnd), WM_CLOSE, 0, 0);
- }
+ else if ((ch == 'A') && (GetKeyState(VK_CONTROL) & 0x80)) {
+ SendMessage(hwnd, NSM_SELECTITEMS, 0, data->items.getCount());
+ // } else
+ // if (ch == VK_ESCAPE)
+ // {
+ // PostMessage(GetParent(hwnd), WM_CLOSE, 0, 0);
}
- break;
}
+ break;
case WM_LBUTTONDOWN:
{
@@ -486,9 +461,9 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
}
}
- SetFocus(hwnd);
- return 0;
}
+ SetFocus(hwnd);
+ return 0;
case WM_MOUSEWHEEL:
{
@@ -550,8 +525,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
data->scrollTopPixel = -pos % AVERAGE_ITEM_HEIGHT * itemHeight / AVERAGE_ITEM_HEIGHT;
}
FixScrollPosition(hwnd, data);
- break;
}
+ break;
default:
return 0;
@@ -563,11 +538,9 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
case WM_DESTROY:
- {
- delete data;
- SetWindowLongPtr(hwnd, 0, 0);
- break;
- }
+ delete data;
+ SetWindowLongPtr(hwnd, 0, 0);
+ break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
@@ -581,31 +554,30 @@ static void ScrollListBy(HWND hwnd, NewstoryListData *data, int scrollItems, int
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;
- }
+ 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;
+ }
- if (data->scrollTopPixel > 0) {
- data->scrollTopPixel = 0;
- }
+ 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);
- }
- }
}
+ 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);
+ }
+ }
+ }
+
FixScrollPosition(hwnd, data);
}
@@ -710,14 +682,14 @@ static void BeginEditItem(HWND hwnd, NewstoryListData *data, int index)
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;
+ 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;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
break;
case EVENTTYPE_STATUSCHANGE:
@@ -740,8 +712,8 @@ static void BeginEditItem(HWND hwnd, NewstoryListData *data, int index)
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;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
break;
}
@@ -782,12 +754,12 @@ static int LayoutItem(HWND hwnd, HistoryArray *items, int index)
switch (item->dbe.eventType) {
case EVENTTYPE_MESSAGE:
tpl = TPL_MESSAGE;
- fontid = !(item->dbe.flags&DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INMSG : FONT_OUTMSG;
break;
case EVENTTYPE_FILE:
tpl = TPL_FILE;
- fontid = !(item->dbe.flags&DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
break;
case EVENTTYPE_STATUSCHANGE:
@@ -807,7 +779,7 @@ static int LayoutItem(HWND hwnd, HistoryArray *items, int index)
default:
tpl = TPL_OTHER;
- fontid = !(item->dbe.flags&DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
break;
}
@@ -841,14 +813,14 @@ static int PaintItem(HDC hdc, HistoryArray *items, int index, int top, int width
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;
+ 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_FILE;
- fontid = !(item->dbe.flags&DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
- colorid = !(item->dbe.flags&DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INFILE : FONT_OUTFILE;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INFILE : COLOR_OUTFILE;
break;
case EVENTTYPE_STATUSCHANGE:
@@ -871,8 +843,8 @@ static int PaintItem(HDC hdc, HistoryArray *items, int index, int top, int width
default:
tpl = TPL_OTHER;
- fontid = !(item->dbe.flags&DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
- colorid = !(item->dbe.flags&DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
+ fontid = !(item->dbe.flags & DBEF_SENT) ? FONT_INOTHER : FONT_OUTOTHER;
+ colorid = !(item->dbe.flags & DBEF_SENT) ? COLOR_INOTHER : COLOR_OUTOTHER;
break;
}
clText = fonts[fontid].cl;