From eec361608fde60d63fe4511e26e3b95c7f72be13 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 5 Jun 2016 16:11:08 +0000 Subject: - fix for #1059; - direct unsafe work with icons replaces with Window_SetIcon_IcoLib / Window_SetSkinIcon_IcoLib; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@16917 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MyDetails/src/services.cpp | 178 +++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 88 deletions(-) (limited to 'plugins/MyDetails/src/services.cpp') diff --git a/plugins/MyDetails/src/services.cpp b/plugins/MyDetails/src/services.cpp index f4e3d4f616..16fcf7eb93 100644 --- a/plugins/MyDetails/src/services.cpp +++ b/plugins/MyDetails/src/services.cpp @@ -38,72 +38,72 @@ static INT_PTR CALLBACK DlgProcSetNickname(HWND hwndDlg, UINT msg, WPARAM wParam return TRUE; case WMU_SETDATA: - { - int proto_num = (int)wParam; + { + int proto_num = (int)wParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, proto_num); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, proto_num); - if (proto_num == -1) { - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadIcon(SKINICON_OTHER_MIRANDA)); + if (proto_num == -1) { + Window_SetSkinIcon_IcoLib(hwndDlg, SKINICON_OTHER_MIRANDA); - // All protos have the same nick? - if (protocols->GetSize() > 0) { - TCHAR *nick = protocols->Get(0)->nickname; + // All protos have the same nick? + if (protocols->GetSize() > 0) { + TCHAR *nick = protocols->Get(0)->nickname; - bool foundDefNick = true; - for (int i = 1; foundDefNick && i < protocols->GetSize(); i++) { - if (mir_tstrcmpi(protocols->Get(i)->nickname, nick) != 0) { - foundDefNick = false; - break; + bool foundDefNick = true; + for (int i = 1; foundDefNick && i < protocols->GetSize(); i++) { + if (mir_tstrcmpi(protocols->Get(i)->nickname, nick) != 0) { + foundDefNick = false; + break; + } } + + if (foundDefNick) + if (mir_tstrcmpi(protocols->default_nick, nick) != 0) + mir_tstrcpy(protocols->default_nick, nick); } - if (foundDefNick) - if (mir_tstrcmpi(protocols->default_nick, nick) != 0) - mir_tstrcpy(protocols->default_nick, nick); + SetDlgItemText(hwndDlg, IDC_NICKNAME, protocols->default_nick); + SendDlgItemMessage(hwndDlg, IDC_NICKNAME, EM_LIMITTEXT, MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, 0); } + else { + Protocol *proto = protocols->Get(proto_num); - SetDlgItemText(hwndDlg, IDC_NICKNAME, protocols->default_nick); - SendDlgItemMessage(hwndDlg, IDC_NICKNAME, EM_LIMITTEXT, MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, 0); - } - else { - Protocol *proto = protocols->Get(proto_num); + TCHAR tmp[128]; + mir_sntprintf(tmp, TranslateT("Set my nickname for %s"), proto->description); - TCHAR tmp[128]; - mir_sntprintf(tmp, TranslateT("Set my nickname for %s"), proto->description); + SetWindowText(hwndDlg, tmp); - SetWindowText(hwndDlg, tmp); + HICON hIcon = (HICON)CallProtoService(proto->name, PS_LOADICON, PLI_PROTOCOL, 0); + if (hIcon != NULL) { + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); + DestroyIcon(hIcon); + } - HICON hIcon = (HICON)CallProtoService(proto->name, PS_LOADICON, PLI_PROTOCOL, 0); - if (hIcon != NULL) { - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); - DestroyIcon(hIcon); + SetDlgItemText(hwndDlg, IDC_NICKNAME, proto->nickname); + SendDlgItemMessage(hwndDlg, IDC_NICKNAME, EM_LIMITTEXT, + min(MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, proto->GetNickMaxLength()), 0); } - SetDlgItemText(hwndDlg, IDC_NICKNAME, proto->nickname); - SendDlgItemMessage(hwndDlg, IDC_NICKNAME, EM_LIMITTEXT, - min(MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE, proto->GetNickMaxLength()), 0); + return TRUE; } - return TRUE; - } - case WM_COMMAND: switch (wParam) { case IDOK: - { - TCHAR tmp[MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE]; - GetDlgItemText(hwndDlg, IDC_NICKNAME, tmp, _countof(tmp)); + { + TCHAR tmp[MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE]; + GetDlgItemText(hwndDlg, IDC_NICKNAME, tmp, _countof(tmp)); - LONG_PTR proto_num = GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (proto_num == -1) - protocols->SetNicks(tmp); - else - protocols->Get(proto_num)->SetNick(tmp); + LONG_PTR proto_num = GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + if (proto_num == -1) + protocols->SetNicks(tmp); + else + protocols->Get(proto_num)->SetNick(tmp); - DestroyWindow(hwndDlg); - break; - } + DestroyWindow(hwndDlg); + break; + } case IDCANCEL: DestroyWindow(hwndDlg); break; @@ -300,7 +300,8 @@ static LRESULT CALLBACK StatusMsgEditSubclassProc(HWND hwnd, UINT msg, WPARAM wP return mir_callNextSubclass(hwnd, StatusMsgEditSubclassProc, msg, wParam, lParam); } -struct SetStatusMessageData { +struct SetStatusMessageData +{ int status; int proto_num; }; @@ -315,64 +316,64 @@ static INT_PTR CALLBACK DlgProcSetStatusMessage(HWND hwndDlg, UINT msg, WPARAM w return TRUE; case WMU_SETDATA: - { - SetStatusMessageData *data = (SetStatusMessageData *)malloc(sizeof(SetStatusMessageData)); - data->status = (int)wParam; - data->proto_num = (int)lParam; + { + SetStatusMessageData *data = (SetStatusMessageData *)malloc(sizeof(SetStatusMessageData)); + data->status = (int)wParam; + data->proto_num = (int)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)data); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)data); - if (data->proto_num >= 0) { - Protocol *proto = protocols->Get(data->proto_num); + if (data->proto_num >= 0) { + Protocol *proto = protocols->Get(data->proto_num); - HICON hIcon = (HICON)CallProtoService(proto->name, PS_LOADICON, PLI_PROTOCOL, 0); - if (hIcon != NULL) { - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); - DestroyIcon(hIcon); - } + HICON hIcon = (HICON)CallProtoService(proto->name, PS_LOADICON, PLI_PROTOCOL, 0); + if (hIcon != NULL) { + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); + DestroyIcon(hIcon); + } - TCHAR title[256]; - mir_sntprintf(title, TranslateT("Set my status message for %s"), proto->description); - SetWindowText(hwndDlg, title); + TCHAR title[256]; + mir_sntprintf(title, TranslateT("Set my status message for %s"), proto->description); + SetWindowText(hwndDlg, title); - SetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, proto->GetStatusMsg()); - } - else if (data->status != 0) { - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadProtoIcon(NULL, data->status)); + SetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, proto->GetStatusMsg()); + } + else if (data->status != 0) { + Window_SetProtoIcon_IcoLib(hwndDlg, NULL, data->status); - TCHAR title[256]; - mir_sntprintf(title, TranslateT("Set my status message for %s"), pcli->pfnGetStatusModeDescription(data->status, 0)); - SetWindowText(hwndDlg, title); + TCHAR title[256]; + mir_sntprintf(title, TranslateT("Set my status message for %s"), pcli->pfnGetStatusModeDescription(data->status, 0)); + SetWindowText(hwndDlg, title); - SetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, protocols->GetDefaultStatusMsg(data->status)); - } - else { - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadIcon(SKINICON_OTHER_MIRANDA)); + SetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, protocols->GetDefaultStatusMsg(data->status)); + } + else { + Window_SetSkinIcon_IcoLib(hwndDlg, SKINICON_OTHER_MIRANDA); - SetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, protocols->GetDefaultStatusMsg()); + SetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, protocols->GetDefaultStatusMsg()); + } } - return TRUE; - } + case WM_COMMAND: switch (wParam) { case IDOK: - { - TCHAR tmp[MS_MYDETAILS_GETMYSTATUSMESSAGE_BUFFER_SIZE]; - GetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, tmp, _countof(tmp)); + { + TCHAR tmp[MS_MYDETAILS_GETMYSTATUSMESSAGE_BUFFER_SIZE]; + GetDlgItemText(hwndDlg, IDC_STATUSMESSAGE, tmp, _countof(tmp)); - SetStatusMessageData *data = (SetStatusMessageData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + SetStatusMessageData *data = (SetStatusMessageData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (data->proto_num >= 0) - protocols->Get(data->proto_num)->SetStatusMsg(tmp); - else if (data->status == 0) - protocols->SetStatusMsgs(tmp); - else - protocols->SetStatusMsgs(data->status, tmp); + if (data->proto_num >= 0) + protocols->Get(data->proto_num)->SetStatusMsg(tmp); + else if (data->status == 0) + protocols->SetStatusMsgs(tmp); + else + protocols->SetStatusMsgs(data->status, tmp); - DestroyWindow(hwndDlg); - } - break; + DestroyWindow(hwndDlg); + } + break; case IDCANCEL: DestroyWindow(hwndDlg); @@ -388,6 +389,7 @@ static INT_PTR CALLBACK DlgProcSetStatusMessage(HWND hwndDlg, UINT msg, WPARAM w SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_STATUSMESSAGE), GWLP_WNDPROC, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_STATUSMESSAGE), GWLP_USERDATA)); free((SetStatusMessageData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); + Window_FreeIcon_IcoLib(hwndDlg); InterlockedExchange(&status_msg_dialog_open, 0); break; } -- cgit v1.2.3