diff options
author | George Hazan <ghazan@miranda.im> | 2022-09-26 21:51:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-09-26 21:51:40 +0300 |
commit | 9c87b08dd62901761f3bd41cb13122b79233c75b (patch) | |
tree | 72804ca84e2a2abec1dc9af34d4b63798c243f3d | |
parent | 35f6abcc7f069b3f239215842ec049c716f9b758 (diff) |
MyDetails: crash fix
-rw-r--r-- | plugins/MyDetails/src/data.cpp | 4 | ||||
-rw-r--r-- | plugins/MyDetails/src/data.h | 2 | ||||
-rw-r--r-- | plugins/MyDetails/src/frame.cpp | 51 | ||||
-rw-r--r-- | plugins/MyDetails/src/services.cpp | 44 | ||||
-rw-r--r-- | plugins/MyDetails/src/version.h | 2 |
5 files changed, 52 insertions, 51 deletions
diff --git a/plugins/MyDetails/src/data.cpp b/plugins/MyDetails/src/data.cpp index 21cb1ac189..f6f59da5a1 100644 --- a/plugins/MyDetails/src/data.cpp +++ b/plugins/MyDetails/src/data.cpp @@ -40,6 +40,8 @@ void InitProtocolData() void DeInitProtocolData()
{
+ for (auto &it : protocols)
+ delete it;
protocols.destroy();
}
@@ -335,7 +337,7 @@ wchar_t *Protocol::GetListeningTo() // ProtocolDataArray Class /////////////////////////////////////////////////////////////////////////////
ProtocolArray::ProtocolArray() :
- OBJLIST<Protocol>(10)
+ LIST<Protocol>(10)
{
GetDefaultNick();
GetDefaultAvatar();
diff --git a/plugins/MyDetails/src/data.h b/plugins/MyDetails/src/data.h index d54a40e2d2..627fd599ce 100644 --- a/plugins/MyDetails/src/data.h +++ b/plugins/MyDetails/src/data.h @@ -93,7 +93,7 @@ public: void SetStatusMsg(int aStatus, const wchar_t *message);
};
-struct ProtocolArray : public OBJLIST<Protocol>
+struct ProtocolArray : public LIST<Protocol>
{
wchar_t default_nick[256];
wchar_t default_avatar_file[256];
diff --git a/plugins/MyDetails/src/frame.cpp b/plugins/MyDetails/src/frame.cpp index 80645985c6..fbbbbb34a7 100644 --- a/plugins/MyDetails/src/frame.cpp +++ b/plugins/MyDetails/src/frame.cpp @@ -602,14 +602,14 @@ void CalcRectangles(HWND hwnd) return;
}
- Protocol &proto = protocols[data->protocol_number];
- if (&proto == nullptr) {
+ auto *proto = protocols[data->protocol_number];
+ if (proto == nullptr) {
ReleaseDC(hwnd, hdc);
return;
}
data->recalc_rectangles = false;
- proto.data_changed = false;
+ proto->data_changed = false;
data->draw_proto = false;
data->draw_proto_cycle = false;
@@ -673,12 +673,12 @@ void CalcRectangles(HWND hwnd) text_left = r.left;
// Draw image?
- if (proto.CanGetAvatar()) {
- if (proto.avatar_bmp != nullptr) {
+ if (proto->CanGetAvatar()) {
+ if (proto->avatar_bmp != nullptr) {
data->draw_img = true;
BITMAP bmp;
- if (GetObject(proto.avatar_bmp, sizeof(bmp), &bmp)) {
+ if (GetObject(proto->avatar_bmp, sizeof(bmp), &bmp)) {
// make bounds
RECT rc = r;
@@ -733,9 +733,9 @@ void CalcRectangles(HWND hwnd) data->draw_nick = true;
SelectObject(hdc, hFont[FONT_NICK]);
- data->nick_rect = GetRect(hdc, r, proto.nickname, DEFAULT_NICKNAME, proto, uFormat, next_top, text_left);
+ data->nick_rect = GetRect(hdc, r, proto->nickname, DEFAULT_NICKNAME, *proto, uFormat, next_top, text_left);
- if (proto.nickname[0] != '\0')
+ if (proto->nickname[0] != '\0')
data->nick_tt_hwnd = CreateTooltip(hwnd, data->nick_rect);
next_top = data->nick_rect.bottom + SPACE_TEXT_TEXT;
@@ -758,7 +758,7 @@ void CalcRectangles(HWND hwnd) if (opts.show_protocol_cycle_button)
tmp_r.right -= 2 * ICON_SIZE;
- data->proto_rect = GetRect(hdc, tmp_r, proto.description, L"", proto, uFormat, next_top, tmp_text_left, false, true, false);
+ data->proto_rect = GetRect(hdc, tmp_r, proto->description, L"", *proto, uFormat, next_top, tmp_text_left, false, true, false);
if (opts.show_protocol_cycle_button) {
data->draw_proto_cycle = true;
@@ -800,8 +800,7 @@ void CalcRectangles(HWND hwnd) next_top = max(data->next_proto_rect.bottom, data->proto_rect.bottom) + SPACE_TEXT_TEXT;
}
- else
- next_top = data->proto_rect.bottom + SPACE_TEXT_TEXT;
+ else next_top = data->proto_rect.bottom + SPACE_TEXT_TEXT;
}
// Fits more?
@@ -819,7 +818,7 @@ void CalcRectangles(HWND hwnd) // Text size
RECT r_tmp = r;
- DrawText(hdc, proto.status_name, -1, &r_tmp, DT_CALCRECT | (uFormat & ~DT_END_ELLIPSIS));
+ DrawText(hdc, proto->status_name, -1, &r_tmp, DT_CALCRECT | (uFormat & ~DT_END_ELLIPSIS));
SIZE s;
s.cy = max(r_tmp.bottom - r_tmp.top, ICON_SIZE);
@@ -828,7 +827,7 @@ void CalcRectangles(HWND hwnd) // Status global rect
data->status_rect = GetRect(hdc, r, s, uFormat, next_top, text_left, true, false);
- if (proto.status_name[0] != '\0')
+ if (proto->status_name[0] != '\0')
data->status_tt_hwnd = CreateTooltip(hwnd, data->status_rect);
next_top = data->status_rect.bottom + SPACE_TEXT_TEXT;
@@ -874,14 +873,14 @@ void CalcRectangles(HWND hwnd) text_left = r.left;
// Away msg?
- if (proto.CanGetStatusMsg()) {
+ if (proto->CanGetStatusMsg()) {
data->draw_away_msg = true;
SelectObject(hdc, hFont[FONT_AWAY_MSG]);
- data->away_msg_rect = GetRect(hdc, r, proto.status_message, DEFAULT_STATUS_MESSAGE, proto, uFormat, next_top, text_left);
+ data->away_msg_rect = GetRect(hdc, r, proto->status_message, DEFAULT_STATUS_MESSAGE, *proto, uFormat, next_top, text_left);
- if (proto.status_message[0] != '\0')
+ if (proto->status_message[0] != '\0')
data->away_msg_tt_hwnd = CreateTooltip(hwnd, data->away_msg_rect);
next_top = data->away_msg_rect.bottom + SPACE_TEXT_TEXT;
@@ -895,13 +894,13 @@ void CalcRectangles(HWND hwnd) text_left = r.left;
// Listening to
- if (proto.ListeningToEnabled() && proto.GetStatus() > ID_STATUS_OFFLINE) {
+ if (proto->ListeningToEnabled() && proto->GetStatus() > ID_STATUS_OFFLINE) {
data->draw_listening_to = true;
- if (proto.listening_to[0] == '\0') {
+ if (proto->listening_to[0] == '\0') {
SelectObject(hdc, hFont[FONT_LISTENING_TO]);
- data->listening_to_rect = GetRect(hdc, r, proto.listening_to, DEFAULT_LISTENING_TO, proto, uFormat, next_top, text_left);
+ data->listening_to_rect = GetRect(hdc, r, proto->listening_to, DEFAULT_LISTENING_TO, *proto, uFormat, next_top, text_left);
data->listening_to_text_rect = data->listening_to_rect;
memset(&data->listening_to_icon_rect, 0, sizeof(data->listening_to_icon_rect));
@@ -913,7 +912,7 @@ void CalcRectangles(HWND hwnd) // Text size
RECT r_tmp = r;
- DrawText(hdc, proto.listening_to, -1, &r_tmp, DT_CALCRECT | (uFormat & ~DT_END_ELLIPSIS));
+ DrawText(hdc, proto->listening_to, -1, &r_tmp, DT_CALCRECT | (uFormat & ~DT_END_ELLIPSIS));
SIZE s;
s.cy = max(r_tmp.bottom - r_tmp.top, ICON_SIZE);
@@ -1101,7 +1100,7 @@ void DrawTextWithRect(HDC hdc, const wchar_t *text, const wchar_t *def_text, REC void Draw(HWND hwnd, HDC hdc_orig)
{
MyDetailsFrameData *data = (MyDetailsFrameData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- Protocol *proto = (data) ? &protocols[data->protocol_number] : nullptr;
+ auto *proto = (data) ? protocols[data->protocol_number] : nullptr;
if (proto == nullptr) {
EraseBackground(hwnd, hdc_orig);
@@ -1615,7 +1614,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar return TRUE;
case WM_LBUTTONUP:
- proto = &protocols[data->protocol_number];
+ proto = protocols[data->protocol_number];
if (proto != nullptr) {
POINT p;
p.x = LOWORD(lParam);
@@ -1674,7 +1673,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE;
mii.fType = MFT_STRING;
- mii.dwTypeData = protocols[i].description;
+ mii.dwTypeData = protocols[i]->description;
mii.cch = (int)mir_wstrlen(mii.dwTypeData);
mii.wID = i + 1;
@@ -1697,7 +1696,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar DestroyMenu(menu);
if (ret != 0)
- PluginCommand_ShowProtocol(NULL, (WPARAM)protocols[ret - 1].name);
+ PluginCommand_ShowProtocol(NULL, (WPARAM)protocols[ret-1]->name);
data->showing_menu = false;
}
@@ -1711,7 +1710,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar return Menu_DrawItem(lParam);
case WM_CONTEXTMENU:
- proto = &protocols[data->protocol_number];
+ proto = protocols[data->protocol_number];
if (proto != nullptr) {
POINT p = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ScreenToClient(hwnd, &p);
@@ -2102,7 +2101,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar LPNMHDR lpnmhdr = (LPNMHDR)lParam;
switch (lpnmhdr->code) {
case TTN_GETDISPINFO:
- proto = &protocols[data->protocol_number];
+ proto = protocols[data->protocol_number];
LPNMTTDISPINFO lpttd = (LPNMTTDISPINFO)lpnmhdr;
SendMessage(lpnmhdr->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 300);
diff --git a/plugins/MyDetails/src/services.cpp b/plugins/MyDetails/src/services.cpp index 5493a99508..12f2392850 100644 --- a/plugins/MyDetails/src/services.cpp +++ b/plugins/MyDetails/src/services.cpp @@ -46,11 +46,11 @@ public: // All protos have the same nick?
if (protocols.getCount() > 0) {
- wchar_t *nick = protocols[0].nickname;
+ wchar_t *nick = protocols[0]->nickname;
bool foundDefNick = true;
for (int i = 1; foundDefNick && i < protocols.getCount(); i++) {
- if (mir_wstrcmpi(protocols[i].nickname, nick) != 0) {
+ if (mir_wstrcmpi(protocols[i]->nickname, nick) != 0) {
foundDefNick = false;
break;
}
@@ -65,21 +65,21 @@ public: m_edtNickname.SendMsg(EM_LIMITTEXT, MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, 0);
}
else {
- auto &proto = protocols[m_protonum];
+ if (auto *proto = protocols[m_protonum]) {
+ wchar_t tmp[128];
+ mir_snwprintf(tmp, TranslateT("Set my nickname for %s"), proto->description);
- wchar_t tmp[128];
- mir_snwprintf(tmp, TranslateT("Set my nickname for %s"), proto.description);
+ SetWindowText(m_hwnd, tmp);
- SetWindowText(m_hwnd, tmp);
+ HICON hIcon = (HICON)CallProtoService(proto->name, PS_LOADICON, PLI_PROTOCOL, 0);
+ if (hIcon != nullptr) {
+ SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
+ DestroyIcon(hIcon);
+ }
- HICON hIcon = (HICON)CallProtoService(proto.name, PS_LOADICON, PLI_PROTOCOL, 0);
- if (hIcon != nullptr) {
- SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
- DestroyIcon(hIcon);
+ m_edtNickname.SetText(proto->nickname);
+ m_edtNickname.SendMsg(EM_LIMITTEXT, min(MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, proto->GetNickMaxLength()), 0);
}
-
- m_edtNickname.SetText(proto.nickname);
- m_edtNickname.SendMsg(EM_LIMITTEXT, min(MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, proto.GetNickMaxLength()), 0);
}
return true;
}
@@ -92,7 +92,7 @@ public: if (m_protonum == -1)
protocols.SetNicks(tmp);
else
- protocols[m_protonum].SetNick(tmp);
+ protocols[m_protonum]->SetNick(tmp);
return true;
}
@@ -119,7 +119,7 @@ INT_PTR PluginCommand_SetMyNicknameUI(WPARAM, LPARAM lParam) if (proto_num == -1)
return -1;
- if (!protocols[proto_num].CanSetNick())
+ if (!protocols[proto_num]->CanSetNick())
return -2;
}
@@ -196,14 +196,14 @@ INT_PTR PluginCommand_SetMyAvatarUI(WPARAM, LPARAM lParam) if (proto_num == -1)
return -1;
- if (!protocols[proto_num].CanSetAvatar())
+ if (!protocols[proto_num]->CanSetAvatar())
return -2;
}
if (proto_num == -1)
protocols.SetAvatars(nullptr);
else
- protocols[proto_num].SetAvatar(nullptr);
+ protocols[proto_num]->SetAvatar(nullptr);
return 0;
}
@@ -303,19 +303,19 @@ public: mir_subclassWindow(m_edtStatusMessage.GetHwnd(), StatusMsgEditSubclassProc);
if (m_data->proto_num >= 0) {
- auto &proto = protocols[m_data->proto_num];
+ auto *proto = protocols[m_data->proto_num];
- HICON hIcon = (HICON)CallProtoService(proto.name, PS_LOADICON, PLI_PROTOCOL, 0);
+ HICON hIcon = (HICON)CallProtoService(proto->name, PS_LOADICON, PLI_PROTOCOL, 0);
if (hIcon != nullptr) {
SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
DestroyIcon(hIcon);
}
wchar_t title[256];
- mir_snwprintf(title, TranslateT("Set my status message for %s"), proto.description);
+ mir_snwprintf(title, TranslateT("Set my status message for %s"), proto->description);
SetWindowText(m_hwnd, title);
- m_edtStatusMessage.SetText(proto.GetStatusMsg());
+ m_edtStatusMessage.SetText(proto->GetStatusMsg());
}
else if (m_data->status != 0) {
Window_SetProtoIcon_IcoLib(m_hwnd, nullptr, m_data->status);
@@ -340,7 +340,7 @@ public: m_edtStatusMessage.GetText(tmp, _countof(tmp));
if (m_data->proto_num >= 0)
- protocols[m_data->proto_num].SetStatusMsg(tmp);
+ protocols[m_data->proto_num]->SetStatusMsg(tmp);
else if (m_data->status == 0)
protocols.SetStatusMsgs(tmp);
else
diff --git a/plugins/MyDetails/src/version.h b/plugins/MyDetails/src/version.h index 8a2c9b8369..0deed1a7dd 100644 --- a/plugins/MyDetails/src/version.h +++ b/plugins/MyDetails/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> |