From 856ff580fd9d776c331a6b525fa7d73a24d92f64 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Jun 2022 21:26:35 +0300 Subject: UserInfo -> UI classes --- src/core/stduserinfo/res/resource.rc | 80 ++- src/core/stduserinfo/src/contactinfo.cpp | 551 +++++++++-------- src/core/stduserinfo/src/main.cpp | 2 +- src/core/stduserinfo/src/stdafx.h | 4 + src/core/stduserinfo/src/stdinfo.cpp | 727 +++++++++++------------ src/core/stduserinfo/src/userinfo.cpp | 438 ++++++-------- src/core/stduserinfo/stduserinfo.vcxproj | 3 + src/core/stduserinfo/stduserinfo.vcxproj.filters | 5 + 8 files changed, 865 insertions(+), 945 deletions(-) (limited to 'src/core/stduserinfo') diff --git a/src/core/stduserinfo/res/resource.rc b/src/core/stduserinfo/res/resource.rc index 880b1583cc..6ec5cfbd2b 100644 --- a/src/core/stduserinfo/res/resource.rc +++ b/src/core/stduserinfo/res/resource.rc @@ -1,6 +1,6 @@ // Microsoft Visual C++ generated resource script. // -#include "..\..\mir_app\src\resource.h" +#include "..\..\..\mir_app\src\resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// @@ -27,6 +27,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US IDC_HYPERLINKHAND CURSOR "cursor_hyperlink.cur" + ///////////////////////////////////////////////////////////////////////////// // // Dialog @@ -61,7 +62,7 @@ BEGIN END IDD_DETAILS DIALOGEX 0, 0, 318, 210 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +STYLE DS_SETFONT | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME EXSTYLE WS_EX_CONTROLPARENT CAPTION "%s: user details" FONT 8, "MS Shell Dlg", 0, 0, 0x1 @@ -69,10 +70,10 @@ BEGIN CONTROL "View personal user details and more",IDC_HEADERBAR, "MHeaderbarCtrl",0x0,0,0,318,25 CONTROL "",IDC_PAGETREE,"SysTreeView32",TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | TVS_NOTOOLTIPS | TVS_TRACKSELECT | TVS_FULLROWSELECT | TVS_NONEVENHEIGHT | WS_HSCROLL | WS_TABSTOP,3,30,76,176,WS_EX_STATICEDGE - CONTROL "Tab1",IDC_TABS,"SysTabControl32",TCS_HOTTRACK | TCS_MULTILINE | WS_TABSTOP,85,29,228,158 PUSHBUTTON "Update now",IDC_UPDATE,85,191,55,14,WS_DISABLED CTEXT "Updating",IDC_UPDATING,145,194,113,8,SS_NOPREFIX | SS_CENTERIMAGE DEFPUSHBUTTON "OK",IDOK,263,191,50,14 + LTEXT "",IDC_TABS,87,30,225,155,NOT WS_VISIBLE | WS_BORDER END IDD_INFO_SUMMARY DIALOGEX 0, 0, 222, 132 @@ -187,7 +188,6 @@ BEGIN CONTROL "",IDC_WEBPAGE,"Hyperlink",WS_TABSTOP,57,109,160,8 END -#endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // @@ -197,6 +197,26 @@ END #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO BEGIN + IDD_ADDPHONE, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 205 + TOPMARGIN, 5 + BOTTOMMARGIN, 86 + END + + IDD_ADDEMAIL, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 182 + TOPMARGIN, 5 + BOTTOMMARGIN, 37 + END + + IDD_DETAILS, DIALOG + BEGIN + END + IDD_INFO_CONTACT, DIALOG BEGIN LEFTMARGIN, 5 @@ -256,24 +276,7 @@ BEGIN HORZGUIDE, 94 HORZGUIDE, 105 END - - IDD_ADDEMAIL, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 182 - TOPMARGIN, 5 - BOTTOMMARGIN, 37 - END - - IDD_ADDPHONE, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 205 - TOPMARGIN, 5 - BOTTOMMARGIN, 86 - END END - #endif // APSTUDIO_INVOKED @@ -283,22 +286,49 @@ END // TEXTINCLUDE // -1 TEXTINCLUDE +1 TEXTINCLUDE BEGIN - "..\..\mir_app\src\resource.h\0" + "..\\..\\..\\mir_app\\src\\resource.h\0" END -2 TEXTINCLUDE +2 TEXTINCLUDE BEGIN "#include \r\n" "#include \r\n" "\0" END -3 TEXTINCLUDE +3 TEXTINCLUDE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// AFX_DIALOG_LAYOUT +// + +IDD_DETAILS AFX_DIALOG_LAYOUT +BEGIN + 0 +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/src/core/stduserinfo/src/contactinfo.cpp b/src/core/stduserinfo/src/contactinfo.cpp index 8e501e399e..df0895005b 100644 --- a/src/core/stduserinfo/src/contactinfo.cpp +++ b/src/core/stduserinfo/src/contactinfo.cpp @@ -214,23 +214,26 @@ static int IsOverEmail(HWND hwndDlg, wchar_t *szEmail, int cchEmail) return 0; } -#define M_REMAKELISTS (WM_USER+1) -INT_PTR CALLBACK ContactDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CContactPage : public CUserInfoPageDlg { - int i; - RECT rc; - LOGFONT lf; - MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam); + CCtrlListView m_emails, m_phones; + +public: + CContactPage() : + CUserInfoPageDlg(g_plugin, IDD_INFO_CONTACT), + m_emails(this, IDC_EMAILS), + m_phones(this, IDC_PHONES) + { + m_emails.OnCustomDraw = m_phones.OnCustomDraw = Callback(this, &CContactPage::onCustomDraw); + } + bool OnInitDialog() override + { if (hEmailFont) DeleteObject(hEmailFont); + hEmailFont = (HFONT)m_emails.SendMsg(WM_GETFONT, 0, 0); - hEmailFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_EMAILS, WM_GETFONT, 0, 0); + LOGFONT lf; GetObject(hEmailFont, sizeof(lf), &lf); lf.lfUnderline = 1; hEmailFont = CreateFontIndirect(&lf); @@ -238,304 +241,296 @@ INT_PTR CALLBACK ContactDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (hHandCursor == nullptr) hHandCursor = LoadCursor(nullptr, IDC_HAND); - GetClientRect(GetDlgItem(hwndDlg, IDC_EMAILS), &rc); + RECT rc; + GetClientRect(m_emails.GetHwnd(), &rc); rc.right -= GetSystemMetrics(SM_CXVSCROLL); LVCOLUMN lvc; lvc.mask = LVCF_WIDTH; - ListView_SetExtendedListViewStyleEx(GetDlgItem(hwndDlg, IDC_EMAILS), LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - ListView_SetExtendedListViewStyleEx(GetDlgItem(hwndDlg, IDC_PHONES), LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); + m_emails.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); + m_phones.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); lvc.cx = rc.right / 4; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_EMAILS), 0, &lvc); - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PHONES), 0, &lvc); + m_emails.InsertColumn(0, &lvc); + m_phones.InsertColumn(0, &lvc); lvc.cx = rc.right - rc.right / 4 - 40; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_EMAILS), 1, &lvc); + m_emails.InsertColumn(1, &lvc); lvc.cx = rc.right - rc.right / 4 - 90; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PHONES), 1, &lvc); + m_phones.InsertColumn(1, &lvc); lvc.cx = 50; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PHONES), 2, &lvc); + m_phones.InsertColumn(2, &lvc); lvc.cx = 20; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_EMAILS), 2, &lvc); - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_EMAILS), 3, &lvc); - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PHONES), 3, &lvc); - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PHONES), 4, &lvc); - break; - - case M_REMAKELISTS: - if (hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto == nullptr) - break; - - //e-mails - ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_EMAILS)); - - char idstr[33]; - wchar_t idstr2[33]; - DBVARIANT dbv; - - LVITEM lvi; - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.lParam = -1; - lvi.iSubItem = 0; - lvi.iItem = 0; - for (i = -1;; i++) { - if (i == -1) { - if (db_get_ws(hContact, szProto, "e-mail", &dbv)) - continue; - lvi.pszText = TranslateT("Primary"); - } - else { - mir_snprintf(idstr, "e-mail%d", i); - if (db_get_ws(hContact, szProto, idstr, &dbv)) - break; + m_emails.InsertColumn(2, &lvc); + m_emails.InsertColumn(3, &lvc); + m_phones.InsertColumn(3, &lvc); + m_phones.InsertColumn(4, &lvc); + return true; + } - lvi.pszText = idstr2; - mir_snwprintf(idstr2, L"%d", i + 2); - } - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_EMAILS), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_EMAILS), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; + bool OnRefresh() override + { + if (m_hContact == 0) + return false; + + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto == nullptr) + return false; + + // e-mails + m_emails.DeleteAllItems(); + + char idstr[33]; + wchar_t idstr2[33]; + DBVARIANT dbv; + + LVITEM lvi; + lvi.mask = LVIF_TEXT | LVIF_PARAM; + lvi.lParam = -1; + lvi.iSubItem = 0; + lvi.iItem = 0; + for (int i = -1;; i++) { + if (i == -1) { + if (db_get_ws(m_hContact, szProto, "e-mail", &dbv)) + continue; + lvi.pszText = TranslateT("Primary"); } - lvi.iSubItem = 0; - for (i = 0;; i++) { - lvi.lParam = i; - mir_snprintf(idstr, "Mye-mail%d", i); - if (g_plugin.getWString(hContact, idstr, &dbv)) + else { + mir_snprintf(idstr, "e-mail%d", i); + if (db_get_ws(m_hContact, szProto, idstr, &dbv)) break; + lvi.pszText = idstr2; - mir_snwprintf(idstr2, TranslateT("Custom %d"), i + 1); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_EMAILS), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_EMAILS), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; + mir_snwprintf(idstr2, L"%d", i + 2); } - lvi.mask = LVIF_PARAM; - lvi.lParam = -2; - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_EMAILS), &lvi); - //phones - ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_PHONES)); - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.lParam = -1; - lvi.iSubItem = 0; - lvi.iItem = 0; - if (!db_get_ws(hContact, szProto, "Phone", &dbv)) { - lvi.pszText = TranslateT("Primary"); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; - } - if (!db_get_ws(hContact, szProto, "Fax", &dbv)) { - lvi.pszText = TranslateT("Fax"); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; - } - if (!db_get_ws(hContact, szProto, "Cellular", &dbv)) { - lvi.pszText = TranslateT("Mobile"); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); - if (mir_strlen(dbv.pszVal) > 4 && !mir_strcmp(dbv.pszVal + mir_strlen(dbv.pszVal) - 4, " SMS")) { - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 2, L"y"); - dbv.pwszVal[mir_wstrlen(dbv.pwszVal) - 4] = '\0'; - } - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; - } - if (!db_get_ws(hContact, szProto, "CompanyPhone", &dbv)) { - lvi.pszText = TranslateT("Work phone"); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; - } - if (!db_get_ws(hContact, szProto, "CompanyFax", &dbv)) { - lvi.pszText = TranslateT("Work fax"); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; + m_emails.InsertItem(&lvi); + m_emails.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + lvi.iSubItem = 0; + for (int i = 0;; i++) { + lvi.lParam = i; + mir_snprintf(idstr, "Mye-mail%d", i); + if (g_plugin.getWString(m_hContact, idstr, &dbv)) + break; + lvi.pszText = idstr2; + mir_snwprintf(idstr2, TranslateT("Custom %d"), i + 1); + m_emails.InsertItem(&lvi); + m_emails.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + lvi.mask = LVIF_PARAM; + lvi.lParam = -2; + m_emails.InsertItem(&lvi); + + // phones + m_phones.DeleteAllItems(); + + lvi.mask = LVIF_TEXT | LVIF_PARAM; + lvi.lParam = -1; + lvi.iSubItem = 0; + lvi.iItem = 0; + if (!db_get_ws(m_hContact, szProto, "Phone", &dbv)) { + lvi.pszText = TranslateT("Primary"); + m_phones.InsertItem(&lvi); + m_phones.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + if (!db_get_ws(m_hContact, szProto, "Fax", &dbv)) { + lvi.pszText = TranslateT("Fax"); + m_phones.InsertItem(&lvi); + m_phones.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + if (!db_get_ws(m_hContact, szProto, "Cellular", &dbv)) { + lvi.pszText = TranslateT("Mobile"); + m_phones.InsertItem(&lvi); + if (mir_strlen(dbv.pszVal) > 4 && !mir_strcmp(dbv.pszVal + mir_strlen(dbv.pszVal) - 4, " SMS")) { + m_phones.SetItemText(lvi.iItem, 2, L"y"); + dbv.pwszVal[mir_wstrlen(dbv.pwszVal) - 4] = '\0'; } - lvi.iSubItem = 0; - for (i = 0;; i++) { - lvi.lParam = i; - mir_snprintf(idstr, "MyPhone%d", i); - if (g_plugin.getWString(hContact, idstr, &dbv)) - break; - lvi.pszText = idstr2; - mir_snwprintf(idstr2, TranslateT("Custom %d"), i + 1); - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); - if (mir_wstrlen(dbv.pwszVal) > 4 && !mir_wstrcmp(dbv.pwszVal + mir_wstrlen(dbv.pwszVal) - 4, L" SMS")) { - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 2, L"y"); - dbv.pwszVal[mir_wstrlen(dbv.pwszVal) - 4] = '\0'; - } - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PHONES), lvi.iItem, 1, dbv.pwszVal); - db_free(&dbv); - lvi.iItem++; + m_phones.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + if (!db_get_ws(m_hContact, szProto, "CompanyPhone", &dbv)) { + lvi.pszText = TranslateT("Work phone"); + m_phones.InsertItem(&lvi); + m_phones.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + if (!db_get_ws(m_hContact, szProto, "CompanyFax", &dbv)) { + lvi.pszText = TranslateT("Work fax"); + m_phones.InsertItem(&lvi); + m_phones.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; + } + lvi.iSubItem = 0; + for (int i = 0;; i++) { + lvi.lParam = i; + mir_snprintf(idstr, "MyPhone%d", i); + if (g_plugin.getWString(m_hContact, idstr, &dbv)) + break; + lvi.pszText = idstr2; + mir_snwprintf(idstr2, TranslateT("Custom %d"), i + 1); + m_phones.InsertItem(&lvi); + if (mir_wstrlen(dbv.pwszVal) > 4 && !mir_wstrcmp(dbv.pwszVal + mir_wstrlen(dbv.pwszVal) - 4, L" SMS")) { + m_phones.SetItemText(lvi.iItem, 2, L"y"); + dbv.pwszVal[mir_wstrlen(dbv.pwszVal) - 4] = '\0'; } - lvi.mask = LVIF_PARAM; - lvi.lParam = -2; - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PHONES), &lvi); + m_phones.SetItemText(lvi.iItem, 1, dbv.pwszVal); + db_free(&dbv); + lvi.iItem++; } - break; + lvi.mask = LVIF_PARAM; + lvi.lParam = -2; + m_phones.InsertItem(&lvi); + return false; + } - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED) - SendMessage(hwndDlg, M_REMAKELISTS, 0, 0); + void onCustomDraw(CCtrlListView::TEventInfo *ev) + { + NMLVCUSTOMDRAW *nm = ev->nmcd; + switch (nm->nmcd.dwDrawStage) { + case CDDS_PREPAINT: + case CDDS_ITEMPREPAINT: + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW); break; - case IDC_EMAILS: - case IDC_PHONES: - switch (((LPNMHDR)lParam)->code) { - case NM_CUSTOMDRAW: - { - NMLVCUSTOMDRAW *nm = (NMLVCUSTOMDRAW *)lParam; - switch (nm->nmcd.dwDrawStage) { - case CDDS_PREPAINT: - case CDDS_ITEMPREPAINT: - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW); - return TRUE; - - case CDDS_SUBITEM | CDDS_ITEMPREPAINT: - ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc); - if (nm->iSubItem == 1 && nm->nmcd.hdr.idFrom == IDC_EMAILS) { - HFONT hoFont; - wchar_t szText[256] = { 0 }; - ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText)); - hoFont = (HFONT)SelectObject(nm->nmcd.hdc, hEmailFont); - SetTextColor(nm->nmcd.hdc, RGB(0, 0, 255)); - DrawText(nm->nmcd.hdc, szText, -1, &rc, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_TOP); - SelectObject(nm->nmcd.hdc, hoFont); - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); - return TRUE; - } - - HICON hIcon = NULL; - if (nm->nmcd.lItemlParam == -2 && nm->iSubItem - 3 == (nm->nmcd.hdr.idFrom == IDC_PHONES)) - hIcon = Skin_LoadIcon(SKINICON_OTHER_ADDCONTACT); - else if (nm->iSubItem > 1 && nm->nmcd.lItemlParam != -1 && nm->nmcd.lItemlParam != -2) { - static int iconResources[3] = { SKINICON_OTHER_RENAME, SKINICON_OTHER_DELETE }; - if (nm->iSubItem == 2 && nm->nmcd.hdr.idFrom == IDC_PHONES) { - wchar_t szText[2]; - ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText)); - if (szText[0]) hIcon = Skin_LoadIcon(SKINICON_OTHER_SMS); - } - else hIcon = Skin_LoadIcon(iconResources[nm->iSubItem - 3 + (nm->nmcd.hdr.idFrom == IDC_EMAILS)]); - } - else break; - DrawIconEx(nm->nmcd.hdc, (rc.left + rc.right - GetSystemMetrics(SM_CXSMICON)) / 2, (rc.top + rc.bottom - GetSystemMetrics(SM_CYSMICON)) / 2, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); - IcoLib_ReleaseIcon(hIcon, 0); - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); - return TRUE; - } - } + case CDDS_SUBITEM | CDDS_ITEMPREPAINT: + RECT rc; + ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc); + if (nm->iSubItem == 1 && nm->nmcd.hdr.idFrom == IDC_EMAILS) { + HFONT hoFont; + wchar_t szText[256] = { 0 }; + ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText)); + hoFont = (HFONT)SelectObject(nm->nmcd.hdc, hEmailFont); + SetTextColor(nm->nmcd.hdc, RGB(0, 0, 255)); + DrawText(nm->nmcd.hdc, szText, -1, &rc, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_TOP); + SelectObject(nm->nmcd.hdc, hoFont); + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); break; + } - case NM_CLICK: - NMLISTVIEW *nm = (NMLISTVIEW *)lParam; - char *szIdTemplate = (nm->hdr.idFrom == IDC_PHONES) ? "MyPhone%d" : "Mye-mail%d"; - - wchar_t szEmail[256]; - if (IsOverEmail(hwndDlg, szEmail, _countof(szEmail))) { - wchar_t szExec[264]; - mir_snwprintf(szExec, L"mailto:%s", szEmail); - ShellExecute(hwndDlg, L"open", szExec, NULL, NULL, SW_SHOW); - break; + HICON hIcon = NULL; + if (nm->nmcd.lItemlParam == -2 && nm->iSubItem - 3 == (nm->nmcd.hdr.idFrom == IDC_PHONES)) + hIcon = Skin_LoadIcon(SKINICON_OTHER_ADDCONTACT); + else if (nm->iSubItem > 1 && nm->nmcd.lItemlParam != -1 && nm->nmcd.lItemlParam != -2) { + static int iconResources[3] = { SKINICON_OTHER_RENAME, SKINICON_OTHER_DELETE }; + if (nm->iSubItem == 2 && nm->nmcd.hdr.idFrom == IDC_PHONES) { + wchar_t szText[2]; + ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText)); + if (szText[0]) hIcon = Skin_LoadIcon(SKINICON_OTHER_SMS); } - if (nm->iSubItem < 2) - break; - - LVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(GetMessagePos()); - hti.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(nm->hdr.hwndFrom, &hti.pt); - if (ListView_SubItemHitTest(nm->hdr.hwndFrom, &hti) == -1) - break; - - LVITEM lvi; - lvi.mask = LVIF_PARAM; - lvi.iItem = hti.iItem; - lvi.iSubItem = 0; - ListView_GetItem(nm->hdr.hwndFrom, &lvi); - if (lvi.lParam == -1) - break; + else hIcon = Skin_LoadIcon(iconResources[nm->iSubItem - 3 + (nm->nmcd.hdr.idFrom == IDC_EMAILS)]); + } + else break; + DrawIconEx(nm->nmcd.hdc, (rc.left + rc.right - GetSystemMetrics(SM_CXSMICON)) / 2, (rc.top + rc.bottom - GetSystemMetrics(SM_CYSMICON)) / 2, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); + IcoLib_ReleaseIcon(hIcon, 0); + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); + } + } - if (lvi.lParam == -2) { - if (hti.iSubItem - 3 == (nm->hdr.idFrom == IDC_PHONES)) { - // add - char szNewData[256] = "", idstr[33]; - DBVARIANT dbv; - if (IDOK != DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(nm->hdr.idFrom == IDC_PHONES ? IDD_ADDPHONE : IDD_ADDEMAIL), hwndDlg, nm->hdr.idFrom == IDC_PHONES ? EditUserPhoneDlgProc : EditUserEmailDlgProc, (LPARAM)szNewData)) - break; - for (i = 0;; i++) { - mir_snprintf(idstr, szIdTemplate, i); - if (g_plugin.getString(hContact, idstr, &dbv)) break; - db_free(&dbv); - } - g_plugin.setString(hContact, idstr, szNewData); - SendMessage(hwndDlg, M_REMAKELISTS, 0, 0); - } - } - else if (hti.iSubItem - 3 == (nm->hdr.idFrom == IDC_PHONES)) { - // delete - char idstr[33]; - DBVARIANT dbv; - for (i = lvi.lParam;; i++) { - mir_snprintf(idstr, szIdTemplate, i + 1); - if (g_plugin.getString(hContact, idstr, &dbv)) break; - mir_snprintf(idstr, szIdTemplate, i); - g_plugin.setString(hContact, idstr, dbv.pszVal); - db_free(&dbv); - } + void onClick(CCtrlListView::TEventInfo *ev) + { + NMLISTVIEW *nm = ev->nmlv; + char *szIdTemplate = (nm->hdr.idFrom == IDC_PHONES) ? "MyPhone%d" : "Mye-mail%d"; + int i; + + wchar_t szEmail[256]; + if (IsOverEmail(m_hwnd, szEmail, _countof(szEmail))) { + wchar_t szExec[264]; + mir_snwprintf(szExec, L"mailto:%s", szEmail); + ShellExecute(m_hwnd, L"open", szExec, NULL, NULL, SW_SHOW); + return; + } + if (nm->iSubItem < 2) + return; + + LVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(nm->hdr.hwndFrom, &hti.pt); + if (ListView_SubItemHitTest(nm->hdr.hwndFrom, &hti) == -1) + return; + + LVITEM lvi; + lvi.mask = LVIF_PARAM; + lvi.iItem = hti.iItem; + lvi.iSubItem = 0; + ListView_GetItem(nm->hdr.hwndFrom, &lvi); + if (lvi.lParam == -1) + return; + + if (lvi.lParam == -2) { + if (hti.iSubItem - 3 == (nm->hdr.idFrom == IDC_PHONES)) { + // add + char szNewData[256] = "", idstr[33]; + DBVARIANT dbv; + if (IDOK != DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(nm->hdr.idFrom == IDC_PHONES ? IDD_ADDPHONE : IDD_ADDEMAIL), m_hwnd, nm->hdr.idFrom == IDC_PHONES ? EditUserPhoneDlgProc : EditUserEmailDlgProc, (LPARAM)szNewData)) + return; + + for (i = 0;; i++) { mir_snprintf(idstr, szIdTemplate, i); - g_plugin.delSetting(hContact, idstr); - SendMessage(hwndDlg, M_REMAKELISTS, 0, 0); - } - else if (hti.iSubItem - 2 == (nm->hdr.idFrom == IDC_PHONES)) { - // edit - char szText[256], idstr[33]; - DBVARIANT dbv; - mir_snprintf(idstr, szIdTemplate, lvi.lParam); - if (g_plugin.getString(hContact, idstr, &dbv)) break; - mir_strncpy(szText, dbv.pszVal, _countof(szText)); + if (g_plugin.getString(m_hContact, idstr, &dbv)) break; db_free(&dbv); - if (IDOK != DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(nm->hdr.idFrom == IDC_PHONES ? IDD_ADDPHONE : IDD_ADDEMAIL), hwndDlg, nm->hdr.idFrom == IDC_PHONES ? EditUserPhoneDlgProc : EditUserEmailDlgProc, (LPARAM)szText)) - break; - g_plugin.setString(hContact, idstr, szText); - SendMessage(hwndDlg, M_REMAKELISTS, 0, 0); } + g_plugin.setString(m_hContact, idstr, szNewData); + OnRefresh(); } } - break; - - case WM_SETCURSOR: - if (LOWORD(lParam) != HTCLIENT) - break; - - if (GetForegroundWindow() == GetParent(hwndDlg)) { - POINT pt; - GetCursorPos(&pt); - ScreenToClient(hwndDlg, &pt); + else if (hti.iSubItem - 3 == (nm->hdr.idFrom == IDC_PHONES)) { + // delete + char idstr[33]; + DBVARIANT dbv; + for (i = lvi.lParam;; i++) { + mir_snprintf(idstr, szIdTemplate, i + 1); + if (g_plugin.getString(m_hContact, idstr, &dbv)) break; + mir_snprintf(idstr, szIdTemplate, i); + g_plugin.setString(m_hContact, idstr, dbv.pszVal); + db_free(&dbv); + } + mir_snprintf(idstr, szIdTemplate, i); + g_plugin.delSetting(m_hContact, idstr); + OnRefresh(); } - if (IsOverEmail(hwndDlg, nullptr, 0)) { - SetCursor(hHandCursor); - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); - return TRUE; + else if (hti.iSubItem - 2 == (nm->hdr.idFrom == IDC_PHONES)) { + // edit + char szText[256], idstr[33]; + DBVARIANT dbv; + mir_snprintf(idstr, szIdTemplate, lvi.lParam); + if (g_plugin.getString(m_hContact, idstr, &dbv)) + return; + mir_strncpy(szText, dbv.pszVal, _countof(szText)); + db_free(&dbv); + if (IDOK != DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(nm->hdr.idFrom == IDC_PHONES ? IDD_ADDPHONE : IDD_ADDEMAIL), m_hwnd, nm->hdr.idFrom == IDC_PHONES ? EditUserPhoneDlgProc : EditUserEmailDlgProc, (LPARAM)szText)) + return; + g_plugin.setString(m_hContact, idstr, szText); + OnRefresh(); } - break; + } - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - SendMessage(GetParent(hwndDlg), msg, wParam, lParam); - break; + INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override + { + if (msg == WM_SETCURSOR && LOWORD(lParam) == HTCLIENT) { + if (IsOverEmail(m_hwnd, nullptr, 0)) { + SetCursor(hHandCursor); + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, TRUE); + return TRUE; + } } - break; + + return CDlgBase::DlgProc(msg, wParam, lParam); } - return FALSE; +}; + +void InitContactInfo(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.pDialog = new CContactPage(); + uip.szTitle.a = LPGEN("Contact"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/src/core/stduserinfo/src/main.cpp b/src/core/stduserinfo/src/main.cpp index d46195576a..5334c9727f 100644 --- a/src/core/stduserinfo/src/main.cpp +++ b/src/core/stduserinfo/src/main.cpp @@ -41,7 +41,7 @@ PLUGININFOEX pluginInfoEx = { }; CMPlugin::CMPlugin() : - PLUGIN("UserInfo", pluginInfoEx) + PLUGIN(MODULENAME, pluginInfoEx) {} ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/stduserinfo/src/stdafx.h b/src/core/stduserinfo/src/stdafx.h index 43b1528d9a..d5e61f94f5 100644 --- a/src/core/stduserinfo/src/stdafx.h +++ b/src/core/stduserinfo/src/stdafx.h @@ -41,6 +41,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include + #include #include #include @@ -67,6 +69,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../mir_app/src/resource.h" +#define MODULENAME "UserInfo" + struct CMPlugin : public PLUGIN { CMPlugin(); diff --git a/src/core/stduserinfo/src/stdinfo.cpp b/src/core/stduserinfo/src/stdinfo.cpp index 93e1648872..da987d8039 100644 --- a/src/core/stduserinfo/src/stdinfo.cpp +++ b/src/core/stduserinfo/src/stdinfo.cpp @@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -INT_PTR CALLBACK ContactDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); - #define SVS_NORMAL 0 #define SVS_GENDER 1 #define SVS_ZEROISUNSPEC 2 @@ -36,7 +34,7 @@ INT_PTR CALLBACK ContactDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP #define SVS_TIMEZONE 7 #define SVS_MARITAL 8 -static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule, char *szSetting, int special) +static void SetValue(HWND m_hwnd, int idCtrl, MCONTACT hContact, char *szModule, char *szSetting, int special) { char *pstr = nullptr; wchar_t *pwstr = nullptr, wstr[80]; @@ -162,7 +160,7 @@ static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule case DBVT_UTF8: unspecified = (special == SVS_ZEROISUNSPEC && dbv.pszVal[0] == '\0'); if (!unspecified) { - SetDlgItemTextW(hwndDlg, idCtrl, TranslateW(ptrW(mir_utf8decodeW(dbv.pszVal)))); + SetDlgItemTextW(m_hwnd, idCtrl, TranslateW(ptrW(mir_utf8decodeW(dbv.pszVal)))); goto LBL_Exit; } @@ -178,398 +176,362 @@ static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule } if (unspecified) - SetDlgItemText(hwndDlg, idCtrl, TranslateT("")); + SetDlgItemText(m_hwnd, idCtrl, TranslateT("")); else if (pwstr != nullptr) - SetDlgItemText(hwndDlg, idCtrl, pwstr); + SetDlgItemText(m_hwnd, idCtrl, pwstr); else - SetDlgItemTextA(hwndDlg, idCtrl, pstr); + SetDlgItemTextA(m_hwnd, idCtrl, pstr); LBL_Exit: - EnableWindow(GetDlgItem(hwndDlg, idCtrl), !unspecified); + EnableWindow(GetDlgItem(m_hwnd, idCtrl), !unspecified); db_free(&dbv); } -static INT_PTR CALLBACK SummaryDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// +// Summary dlg page + +class CSummaryDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED) { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - if (hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto == nullptr) - break; + CCtrlHyperlink m_email; + +public: + CSummaryDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO_SUMMARY), + m_email(this, IDC_EMAIL) + { + m_email.OnClick = Callback(this, &CSummaryDlg::onClick_Email); + } - SetValue(hwndDlg, IDC_NICK, hContact, szProto, "Nick", 0); - SetValue(hwndDlg, IDC_FIRSTNAME, hContact, szProto, "FirstName", 0); - SetValue(hwndDlg, IDC_LASTNAME, hContact, szProto, "LastName", 0); - SetValue(hwndDlg, IDC_EMAIL, hContact, szProto, "e-mail", 0); - SetValue(hwndDlg, IDC_AGE, hContact, szProto, "Age", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_GENDER, hContact, szProto, "Gender", SVS_GENDER); - SetValue(hwndDlg, IDC_DOBDAY, hContact, szProto, "BirthDay", 0); - SetValue(hwndDlg, IDC_DOBMONTH, hContact, szProto, "BirthMonth", SVS_MONTH); - SetValue(hwndDlg, IDC_DOBYEAR, hContact, szProto, "BirthYear", 0); - SetValue(hwndDlg, IDC_MARITAL, hContact, szProto, "MaritalStatus", SVS_MARITAL); - } - } - break; - } - break; + bool OnRefresh() override + { + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto == nullptr) + return false; + + SetValue(m_hwnd, IDC_NICK, m_hContact, szProto, "Nick", 0); + SetValue(m_hwnd, IDC_FIRSTNAME, m_hContact, szProto, "FirstName", 0); + SetValue(m_hwnd, IDC_LASTNAME, m_hContact, szProto, "LastName", 0); + SetValue(m_hwnd, IDC_EMAIL, m_hContact, szProto, "e-mail", 0); + SetValue(m_hwnd, IDC_AGE, m_hContact, szProto, "Age", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_GENDER, m_hContact, szProto, "Gender", SVS_GENDER); + SetValue(m_hwnd, IDC_DOBDAY, m_hContact, szProto, "BirthDay", 0); + SetValue(m_hwnd, IDC_DOBMONTH, m_hContact, szProto, "BirthMonth", SVS_MONTH); + SetValue(m_hwnd, IDC_DOBYEAR, m_hContact, szProto, "BirthYear", 0); + SetValue(m_hwnd, IDC_MARITAL, m_hContact, szProto, "MaritalStatus", SVS_MARITAL); + return false; + } - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - SendMessage(GetParent(hwndDlg), msg, wParam, lParam); - break; - case IDC_EMAIL: - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_EMAIL))) { - wchar_t szExec[264], szEmail[256]; - GetDlgItemText(hwndDlg, IDC_EMAIL, szEmail, _countof(szEmail)); - mir_snwprintf(szExec, L"mailto:%s", szEmail); - ShellExecute(hwndDlg, L"open", szExec, NULL, NULL, SW_SHOW); - } - break; + void onClick_Email(CCtrlHyperlink *pLink) + { + if (IsWindowEnabled(pLink->GetHwnd())) { + wchar_t szExec[264]; + mir_snwprintf(szExec, L"mailto:%s", ptrW(m_email.GetText()).get()); + ShellExecute(m_hwnd, L"open", szExec, NULL, NULL, SW_SHOW); } - break; } - return FALSE; -} +}; -static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// +// Location dlg page + +class CLocationDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: - - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - TranslateDialogDefault(hwndDlg); - SetTimer(hwndDlg, 1, 1000, nullptr); - - TimeZone_PrepareList(lParam, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB); - SendMessage(hwndDlg, WM_TIMER, 0, 0); - break; - - case WM_TIMER: - { - MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (hContact != NULL) { - wchar_t szTime[80]; - if (printDateTimeByContact(hContact, L"s", szTime, _countof(szTime), TZF_KNOWNONLY)) { - EnableWindow(GetDlgItem(hwndDlg, IDC_LOCALTIME), FALSE); - SetDlgItemText(hwndDlg, IDC_LOCALTIME, TranslateT("")); - } - else { - EnableWindow(GetDlgItem(hwndDlg, IDC_LOCALTIME), TRUE); - SetDlgItemText(hwndDlg, IDC_LOCALTIME, szTime); - } - } - } - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED) { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - if (hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto == nullptr) - break; + CTimer m_timer; + CCtrlCombo cmbTimezone; + +public: + CLocationDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO_LOCATION), + m_timer(this, 1), + cmbTimezone(this, IDC_TIMEZONESELECT) + { + m_timer.OnEvent = Callback(this, &CLocationDlg::onTimer); + + cmbTimezone.OnSelChanged = Callback(this, &CLocationDlg::onSelChange_Timezone); + } - SetValue(hwndDlg, IDC_STREET, hContact, szProto, "Street", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_CITY, hContact, szProto, "City", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_STATE, hContact, szProto, "State", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_ZIP, hContact, szProto, "ZIP", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_COUNTRY, hContact, szProto, "Country", SVS_COUNTRY); - SetValue(hwndDlg, IDC_LANGUAGE1, hContact, szProto, "Language1", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_LANGUAGE2, hContact, szProto, "Language2", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_LANGUAGE3, hContact, szProto, "Language3", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_TIMEZONE, hContact, szProto, "Timezone", SVS_TIMEZONE); - } - } - } - break; + bool OnInitDialog() override + { + m_timer.Start(1000); - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - SendMessage(GetParent(hwndDlg), msg, wParam, lParam); - break; + TimeZone_PrepareList(m_hContact, NULL, cmbTimezone.GetHwnd(), TZF_PLF_CB); + onTimer(0); + return true; + } - case IDC_TIMEZONESELECT: - if (HIWORD(wParam) == CBN_SELCHANGE) { - MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + void onTimer(CTimer *) + { + if (m_hContact == 0) + return; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - TimeZone_StoreListResult(hContact, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB); - } + wchar_t szTime[80]; + if (printDateTimeByContact(m_hContact, L"s", szTime, _countof(szTime), TZF_KNOWNONLY)) { + EnableWindow(GetDlgItem(m_hwnd, IDC_LOCALTIME), FALSE); + SetDlgItemText(m_hwnd, IDC_LOCALTIME, TranslateT("")); + } + else { + EnableWindow(GetDlgItem(m_hwnd, IDC_LOCALTIME), TRUE); + SetDlgItemText(m_hwnd, IDC_LOCALTIME, szTime); } - break; } - return FALSE; -} -static INT_PTR CALLBACK WorkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) + bool OnRefresh() override + { + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto == nullptr) + return false; + + SetValue(m_hwnd, IDC_STREET, m_hContact, szProto, "Street", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_CITY, m_hContact, szProto, "City", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_STATE, m_hContact, szProto, "State", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_ZIP, m_hContact, szProto, "ZIP", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_COUNTRY, m_hContact, szProto, "Country", SVS_COUNTRY); + SetValue(m_hwnd, IDC_LANGUAGE1, m_hContact, szProto, "Language1", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_LANGUAGE2, m_hContact, szProto, "Language2", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_LANGUAGE3, m_hContact, szProto, "Language3", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_TIMEZONE, m_hContact, szProto, "Timezone", SVS_TIMEZONE); + return false; + } + + void onSelChange_Timezone(CCtrlCombo *) + { + TimeZone_StoreListResult(m_hContact, NULL, cmbTimezone.GetHwnd(), TZF_PLF_CB); + } +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Work dlg page + +class CWorkDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED) { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - if (hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto == nullptr) break; - SetValue(hwndDlg, IDC_COMPANY, hContact, szProto, "Company", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_DEPARTMENT, hContact, szProto, "CompanyDepartment", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_POSITION, hContact, szProto, "CompanyPosition", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_STREET, hContact, szProto, "CompanyStreet", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_CITY, hContact, szProto, "CompanyCity", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_STATE, hContact, szProto, "CompanyState", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_ZIP, hContact, szProto, "CompanyZIP", SVS_ZEROISUNSPEC); - SetValue(hwndDlg, IDC_COUNTRY, hContact, szProto, "CompanyCountry", SVS_COUNTRY); - SetValue(hwndDlg, IDC_WEBPAGE, hContact, szProto, "CompanyHomepage", SVS_ZEROISUNSPEC); - } - } - break; - } - break; + CCtrlHyperlink m_url; + +public: + CWorkDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO_WORK), + m_url(this, IDC_WEBPAGE) + { + m_url.OnClick = Callback(this, &CWorkDlg::onClick_Page); + } - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - SendMessage(GetParent(hwndDlg), msg, wParam, lParam); - break; + bool OnRefresh() override + { + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto == nullptr) + return false; + + SetValue(m_hwnd, IDC_COMPANY, m_hContact, szProto, "Company", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_DEPARTMENT, m_hContact, szProto, "CompanyDepartment", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_POSITION, m_hContact, szProto, "CompanyPosition", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_STREET, m_hContact, szProto, "CompanyStreet", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_CITY, m_hContact, szProto, "CompanyCity", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_STATE, m_hContact, szProto, "CompanyState", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_ZIP, m_hContact, szProto, "CompanyZIP", SVS_ZEROISUNSPEC); + SetValue(m_hwnd, IDC_COUNTRY, m_hContact, szProto, "CompanyCountry", SVS_COUNTRY); + SetValue(m_hwnd, IDC_WEBPAGE, m_hContact, szProto, "CompanyHomepage", SVS_ZEROISUNSPEC); + return false; + } - case IDC_WEBPAGE: - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_WEBPAGE))) { - char szPage[256]; - GetDlgItemTextA(hwndDlg, IDC_WEBPAGE, szPage, _countof(szPage)); - Utils_OpenUrl(szPage); - } - } - break; + void onClick_Page(CCtrlHyperlink *pLink) + { + if (IsWindowEnabled(pLink->GetHwnd())) + Utils_OpenUrl(ptrA(pLink->GetTextA())); } - return FALSE; -} +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Work dlg page // Resizes all columns in a listview (report style) // to make all text visible -void ResizeColumns(HWND hwndLV) +void ResizeColumns(CCtrlListView &ctrl) { - int nCol = 0; LVCOLUMN lvCol; - lvCol.mask = LVCF_WIDTH; - while (ListView_GetColumn(hwndLV, nCol++, &lvCol)) - ListView_SetColumnWidth(hwndLV, nCol - 1, LVSCW_AUTOSIZE); + ctrl.SetColumnWidth(0, LVSCW_AUTOSIZE); + ctrl.SetColumnWidth(1, LVSCW_AUTOSIZE); } -static INT_PTR CALLBACK BackgroundDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CBackgroundDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - RECT rc; - GetClientRect(GetDlgItem(hwndDlg, IDC_PAST), &rc); - rc.right -= GetSystemMetrics(SM_CXVSCROLL); - - LVCOLUMN lvc; - lvc.mask = LVCF_WIDTH; - lvc.cx = rc.right / 3; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PAST), 0, &lvc); - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_INTERESTS), 0, &lvc); - - lvc.cx = rc.right - rc.right / 3; - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PAST), 1, &lvc); - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_INTERESTS), 1, &lvc); - } - ListView_SetExtendedListViewStyleEx(GetDlgItem(hwndDlg, IDC_PAST), LVS_EX_LABELTIP, LVS_EX_LABELTIP); - ListView_SetExtendedListViewStyleEx(GetDlgItem(hwndDlg, IDC_INTERESTS), LVS_EX_LABELTIP, LVS_EX_LABELTIP); - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED) { - LVITEM lvi; - char idstr[33]; - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - if (hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto == nullptr) - break; + CCtrlHyperlink m_link; + CCtrlListView m_past, m_interest; + +public: + CBackgroundDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO_BACKGROUND), + m_link(this, IDC_WEBPAGE), + m_past(this, IDC_PAST), + m_interest(this, IDC_INTERESTS) + { + m_link.OnClick = Callback(this, &CBackgroundDlg::onClick_Url); + } - SetValue(hwndDlg, IDC_WEBPAGE, hContact, szProto, "Homepage", SVS_ZEROISUNSPEC); - - // past - ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_PAST)); - lvi.mask = LVIF_TEXT; - lvi.iSubItem = 0; - lvi.iItem = 0; - for (int i = 0;; i++) { - mir_snprintf(idstr, "Past%d", i); - ptrW tszColText(db_get_wsa(hContact, szProto, idstr)); - if (tszColText == NULL) - break; - mir_snprintf(idstr, "Past%dText", i); - ptrW tszText(db_get_wsa(hContact, szProto, idstr)); - if (tszText == NULL) - break; - - lvi.pszText = tszColText; - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PAST), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PAST), lvi.iItem, 1, tszText); - lvi.iItem++; - } + bool OnInitDialog() override + { + RECT rc; + GetClientRect(m_past.GetHwnd(), &rc); + rc.right -= GetSystemMetrics(SM_CXVSCROLL); + + LVCOLUMN lvc; + lvc.mask = LVCF_WIDTH; + lvc.cx = rc.right / 3; + m_past.InsertColumn(0, &lvc); + m_interest.InsertColumn(0, &lvc); + + lvc.cx = rc.right - rc.right / 3; + m_past.InsertColumn(1, &lvc); + m_interest.InsertColumn(1, &lvc); + + m_past.SetExtendedListViewStyleEx(LVS_EX_LABELTIP, LVS_EX_LABELTIP); + m_interest.SetExtendedListViewStyleEx(LVS_EX_LABELTIP, LVS_EX_LABELTIP); + return true; + } - // affiliation - for (int i = 0;; i++) { - mir_snprintf(idstr, "Affiliation%d", i); - ptrW tszColText(db_get_wsa(hContact, szProto, idstr)); - if (tszColText == NULL) - break; - mir_snprintf(idstr, "Affiliation%dText", i); - ptrW tszText(db_get_wsa(hContact, szProto, idstr)); - if (tszText == NULL) - break; - - lvi.pszText = tszColText; - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PAST), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PAST), lvi.iItem, 1, tszText); - lvi.iItem++; - } + bool OnRefresh() override + { + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto == nullptr) + return false; + + SetValue(m_hwnd, IDC_WEBPAGE, m_hContact, szProto, "Homepage", SVS_ZEROISUNSPEC); + + // past + m_past.DeleteAllItems(); + + char idstr[33]; + LVITEM lvi; + lvi.mask = LVIF_TEXT; + lvi.iSubItem = 0; + lvi.iItem = 0; + for (int i = 0;; i++) { + mir_snprintf(idstr, "Past%d", i); + ptrW tszColText(db_get_wsa(m_hContact, szProto, idstr)); + if (tszColText == NULL) + break; + mir_snprintf(idstr, "Past%dText", i); + ptrW tszText(db_get_wsa(m_hContact, szProto, idstr)); + if (tszText == NULL) + break; - ResizeColumns(GetDlgItem(hwndDlg, IDC_PAST)); - - // interests - ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_INTERESTS)); - lvi.mask = LVIF_TEXT; - lvi.iSubItem = 0; - lvi.iItem = 0; - for (int i = 0;; i++) { - mir_snprintf(idstr, "Interest%dCat", i); - ptrW tszColText(db_get_wsa(hContact, szProto, idstr)); - if (tszColText == NULL) - break; - mir_snprintf(idstr, "Interest%dText", i); - ptrW tszText(db_get_wsa(hContact, szProto, idstr)); - if (tszText == NULL) - break; - - lvi.pszText = tszColText; - ListView_InsertItem(GetDlgItem(hwndDlg, IDC_INTERESTS), &lvi); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_INTERESTS), lvi.iItem, 1, tszText); - lvi.iItem++; - } - ResizeColumns(GetDlgItem(hwndDlg, IDC_INTERESTS)); - } - } - break; + lvi.pszText = tszColText; + m_past.InsertItem(&lvi); + m_past.SetItemText(lvi.iItem, 1, tszText); + lvi.iItem++; } - break; - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - SendMessage(GetParent(hwndDlg), msg, wParam, lParam); - break; - case IDC_WEBPAGE: - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_WEBPAGE))) { - char szPage[256]; - GetDlgItemTextA(hwndDlg, IDC_WEBPAGE, szPage, _countof(szPage)); - Utils_OpenUrl(szPage); - } - break; - } - break; - } - return FALSE; -} + // affiliation + for (int i = 0;; i++) { + mir_snprintf(idstr, "Affiliation%d", i); + ptrW tszColText(db_get_wsa(m_hContact, szProto, idstr)); + if (tszColText == NULL) + break; + mir_snprintf(idstr, "Affiliation%dText", i); + ptrW tszText(db_get_wsa(m_hContact, szProto, idstr)); + if (tszText == NULL) + break; -static INT_PTR CALLBACK NotesDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - MCONTACT hContact; - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - HDC hDC = GetDC(hwndDlg); - LOGFONT lf; - lf.lfHeight = -MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72); - ReleaseDC(hwndDlg, hDC); - lf.lfWidth = 0; - lf.lfEscapement = 0; - lf.lfOrientation = 0; - lf.lfWeight = FW_NORMAL; - lf.lfItalic = 0; - lf.lfUnderline = 0; - lf.lfStrikeOut = 0; - lf.lfOutPrecision = OUT_DEFAULT_PRECIS; - lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; - lf.lfQuality = DEFAULT_QUALITY; - lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - mir_wstrcpy(lf.lfFaceName, L"Courier New"); - lf.lfCharSet = DEFAULT_CHARSET; - HFONT hFont = CreateFontIndirect(&lf); - SendDlgItemMessage(hwndDlg, IDC_ABOUT, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); - - ptrW szNotes(g_plugin.getWStringA(lParam, "MyNotes")); - if (szNotes != nullptr) - SetDlgItemText(hwndDlg, IDC_MYNOTES, szNotes); + lvi.pszText = tszColText; + m_past.InsertItem(&lvi); + m_past.SetItemText(lvi.iItem, 1, tszText); + lvi.iItem++; } - SendDlgItemMessage(hwndDlg, IDC_MYNOTES, EM_LIMITTEXT, 2048, 0); - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - switch (((LPNMHDR)lParam)->code) { - case PSN_INFOCHANGED: - hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - if (hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto != NULL) - SetValue(hwndDlg, IDC_ABOUT, hContact, szProto, "About", 0); - } - break; - case PSN_APPLY: - hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - if (GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MYNOTES))) { - wchar_t text[2048]; - GetDlgItemText(hwndDlg, IDC_MYNOTES, text, _countof(text)); - g_plugin.setWString(hContact, "MyNotes", text); - } - else g_plugin.delSetting(hContact, "MyNotes"); + ResizeColumns(m_past); + + // interests + m_interest.DeleteAllItems(); + + lvi.mask = LVIF_TEXT; + lvi.iSubItem = 0; + lvi.iItem = 0; + for (int i = 0;; i++) { + mir_snprintf(idstr, "Interest%dCat", i); + ptrW tszColText(db_get_wsa(m_hContact, szProto, idstr)); + if (tszColText == NULL) break; - } - break; + mir_snprintf(idstr, "Interest%dText", i); + ptrW tszText(db_get_wsa(m_hContact, szProto, idstr)); + if (tszText == NULL) + break; + + lvi.pszText = tszColText; + m_interest.InsertItem(&lvi); + m_interest.SetItemText(lvi.iItem, 1, tszText); + lvi.iItem++; } - break; - - case WM_COMMAND: - if (wParam == MAKEWPARAM(IDC_MYNOTES, EN_CHANGE)) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - else if (LOWORD(wParam) == IDCANCEL) - SendMessage(GetParent(hwndDlg), msg, wParam, lParam); - break; - - case WM_DESTROY: - DeleteObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_ABOUT, WM_GETFONT, 0, 0)); - break; + ResizeColumns(m_interest); + return false; } - return FALSE; -} + + void onClick_Url(CCtrlHyperlink *pLink) + { + if (IsWindowEnabled(pLink->GetHwnd())) + Utils_OpenUrl(ptrA(pLink->GetTextA())); + } +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Notes dlg page + +class CNotesDlg : public CUserInfoPageDlg +{ + CCtrlEdit mynotes; + +public: + CNotesDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO_NOTES), + mynotes(this, IDC_MYNOTES) + { + } + + bool OnInitDialog() override + { + HDC hDC = GetDC(m_hwnd); + LOGFONT lf = {}; + lf.lfHeight = -MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72); + ReleaseDC(m_hwnd, hDC); + lf.lfCharSet = DEFAULT_CHARSET; + lf.lfWeight = FW_NORMAL; + mir_wstrcpy(lf.lfFaceName, L"Courier New"); + HFONT hFont = CreateFontIndirect(&lf); + SendDlgItemMessage(m_hwnd, IDC_ABOUT, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); + + ptrW szNotes(g_plugin.getWStringA(m_hContact, "MyNotes")); + if (szNotes != nullptr) + mynotes.SetText(szNotes); + + mynotes.SetMaxLength(2048); + return true; + } + + bool OnApply() override + { + ptrW wszText(mynotes.GetText()); + if (mir_wstrlen(wszText)) + g_plugin.setWString(m_hContact, "MyNotes", wszText); + else + g_plugin.delSetting(m_hContact, "MyNotes"); + + return true; + } + + void OnDestroy() override + { + DeleteObject((HFONT)SendDlgItemMessage(m_hwnd, IDC_ABOUT, WM_GETFONT, 0, 0)); + } + + bool OnRefresh() override + { + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto != NULL) + SetValue(m_hwnd, IDC_ABOUT, m_hContact, szProto, "About", 0); + return false; + } +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Module entry point + +void InitContactInfo(WPARAM, USERINFOPAGE &uip); int DetailsInit(WPARAM wParam, LPARAM lParam) { @@ -579,41 +541,28 @@ int DetailsInit(WPARAM wParam, LPARAM lParam) if (Proto_GetBaseAccountName(lParam) == nullptr) return 0; - OPTIONSDIALOGPAGE odp = {}; - odp.pfnDlgProc = SummaryDlgProc; - odp.position = -2100000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_SUMMARY); - odp.szTitle.a = LPGEN("Summary"); - g_plugin.addUserInfo(wParam, &odp); - - odp.pfnDlgProc = ContactDlgProc; - odp.position = -1800000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_CONTACT); - odp.szTitle.a = LPGEN("Contact"); - g_plugin.addUserInfo(wParam, &odp); - - odp.pfnDlgProc = LocationDlgProc; - odp.position = -1500000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_LOCATION); - odp.szTitle.a = LPGEN("Location"); - g_plugin.addUserInfo(wParam, &odp); - - odp.pfnDlgProc = WorkDlgProc; - odp.position = -1200000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_WORK); - odp.szTitle.a = LPGEN("Work"); - g_plugin.addUserInfo(wParam, &odp); - - odp.pfnDlgProc = BackgroundDlgProc; - odp.position = -900000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_BACKGROUND); - odp.szTitle.a = LPGEN("Background info"); - g_plugin.addUserInfo(wParam, &odp); - - odp.pfnDlgProc = NotesDlgProc; - odp.position = 0; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_NOTES); - odp.szTitle.a = LPGEN("Notes"); - g_plugin.addUserInfo(wParam, &odp); + USERINFOPAGE uip = {}; + uip.pDialog = new CSummaryDlg(); + uip.szGroup.a = LPGEN("General"); + uip.szTitle.a = LPGEN("Summary"); + g_plugin.addUserInfo(wParam, &uip); + + InitContactInfo(wParam, uip); + + uip.pDialog = new CLocationDlg(); + uip.szTitle.a = LPGEN("Location"); + g_plugin.addUserInfo(wParam, &uip); + + uip.pDialog = new CWorkDlg(); + uip.szTitle.a = LPGEN("Work"); + g_plugin.addUserInfo(wParam, &uip); + + uip.pDialog = new CBackgroundDlg(); + uip.szTitle.a = LPGEN("Background info"); + g_plugin.addUserInfo(wParam, &uip); + + uip.pDialog = new CNotesDlg(); + uip.szTitle.a = LPGEN("Notes"); + g_plugin.addUserInfo(wParam, &uip); return 0; } diff --git a/src/core/stduserinfo/src/userinfo.cpp b/src/core/stduserinfo/src/userinfo.cpp index d66a37574a..ebbd18a6fe 100644 --- a/src/core/stduserinfo/src/userinfo.cpp +++ b/src/core/stduserinfo/src/userinfo.cpp @@ -26,43 +26,40 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define UPDATEANIMFRAMES 20 -int DetailsInit(WPARAM wParam, LPARAM lParam); - -static MWindowList hWindowList = nullptr; -static HANDLE hDetailsInitEvent; - -struct DetailsPageInit -{ - int pageCount; - OPTIONSDIALOGPAGE *odp; -}; - -struct DetailsPageData : public MNonCopyable +struct DetailsPageData : public MNonCopyable, public MZeroedObject { - DLGTEMPLATE *pTemplate; - HINSTANCE hInst; - DLGPROC dlgProc; - LPARAM dlgParam; - HWND hwnd; - HTREEITEM hItem; - HPLUGIN pPlugin; - int changed; - uint32_t dwFlags; - wchar_t *pwszTitle, *pwszTab; + CUserInfoPageDlg *pDialog; + HWND hwnd; + HTREEITEM hItem; + HPLUGIN pPlugin; + int changed; + uint32_t dwFlags; + wchar_t *pwszTitle, *pwszGroup; ~DetailsPageData() { if (hwnd != nullptr) DestroyWindow(hwnd); mir_free(pwszTitle); - mir_free(pwszTab); + mir_free(pwszGroup); } __forceinline wchar_t *getTitle() const { return (dwFlags & ODPF_DONTTRANSLATE) ? pwszTitle : TranslateW_LP(pwszTitle, pPlugin); } + + __forceinline wchar_t* getGroup() const + { return (dwFlags & ODPF_DONTTRANSLATE) ? pwszGroup : TranslateW_LP(pwszGroup, pPlugin); + } }; +///////////////////////////////////////////////////////////////////////////////////////// + +int DetailsInit(WPARAM wParam, LPARAM lParam); + +static MWindowList hWindowList = nullptr; +static HANDLE hDetailsInitEvent; + ///////////////////////////////////////////////////////////////////////////////////////// // User info dialog @@ -80,7 +77,6 @@ static int UserInfoContactDelete(WPARAM wParam, LPARAM) } #define M_PROTOACK (WM_USER+10) -#define M_CHECKONLINE (WM_USER+11) #define M_DLLUNLOAD (WM_USER+12) class CUserInfoDlg : public CDlgBase @@ -88,8 +84,6 @@ class CUserInfoDlg : public CDlgBase MCONTACT m_hContact; HINSTANCE m_hInstIcmp = 0; HFONT m_hBoldFont = 0; - int m_currentPage = -1; - RECT m_rcDisplay, m_rcDisplayTab; int m_updateAnimFrame = 0; wchar_t m_szUpdating[64]; int *m_infosUpdated = 0; @@ -97,130 +91,124 @@ class CUserInfoDlg : public CDlgBase HANDLE m_hProtoAckEvent = 0; HANDLE m_hDllUnloadEvent = 0; - HWND m_tabs; OBJLIST m_pages; + DetailsPageData *m_pCurrent = nullptr; void BuildTree() { ptrW ptszLastTab(g_plugin.getWStringA("LastTab")); - m_currentPage = -1; - - for (int i = 0; i < m_pages.getCount(); i++) { - auto &p = m_pages[i]; - if (i && p.pwszTab && !mir_wstrcmp(m_pages[i - 1].pwszTitle, p.pwszTitle)) { - p.hItem = m_pages[i - 1].hItem; - continue; + m_pCurrent = nullptr; + + std::map parents; + + for (auto &it : m_pages) { + wchar_t *pwszGroup = (it->getGroup() == nullptr) ? TranslateT("General") : it->getGroup(); + + HTREEITEM hParent; + auto p = parents.find(pwszGroup); + if (p == parents.end()) { + TVINSERTSTRUCT tvis = {}; + tvis.hInsertAfter = TVI_LAST; + tvis.item.lParam = (LPARAM)it; + tvis.item.mask = TVIF_TEXT | TVIF_PARAM; + tvis.item.pszText = pwszGroup; + hParent = parents[pwszGroup] = m_tree.InsertItem(&tvis); } + else hParent = p->second; TVINSERTSTRUCT tvis; - tvis.hParent = nullptr; + tvis.hParent = hParent; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_TEXT | TVIF_PARAM; - tvis.item.lParam = (LPARAM)i; - tvis.item.pszText = p.getTitle(); + tvis.item.lParam = (LPARAM)it; + tvis.item.pszText = it->getTitle(); if (ptszLastTab && !mir_wstrcmp(tvis.item.pszText, ptszLastTab)) - m_currentPage = i; - p.hItem = m_tree.InsertItem(&tvis); + m_pCurrent = it; + it->hItem = m_tree.InsertItem(&tvis); } - if (m_currentPage == -1) - m_currentPage = 0; + if (!m_pCurrent) + m_pCurrent = &m_pages[0]; } - void CreateDetailsTabs(DetailsPageData *ppg) + void CheckOnline() { - int sel = 0, pages = 0; - - TCITEM tie; - tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM; - tie.iImage = -1; - TabCtrl_DeleteAllItems(m_tabs); - - for (auto &odp : m_pages) { - if (!odp->pwszTab || mir_wstrcmp(odp->pwszTitle, ppg->pwszTitle)) - continue; - - tie.pszText = TranslateW_LP(odp->pwszTab, odp->pPlugin); - tie.lParam = m_pages.indexOf(&odp); - TabCtrl_InsertItem(m_tabs, pages, &tie); - if (!mir_wstrcmp(odp->pwszTab, ppg->pwszTab)) - sel = pages; - pages++; + if (m_hContact == 0) + return; + + char *szProto = Proto_GetBaseAccountName(m_hContact); + if (szProto == nullptr) + btnUpdate.Disable(); + else { + if (Proto_GetStatus(szProto) < ID_STATUS_ONLINE) + btnUpdate.Disable(); + else + btnUpdate.Enable(!IsWindowVisible(GetDlgItem(m_hwnd, IDC_UPDATING))); } - TabCtrl_SetCurSel(m_tabs, sel); - - LONG style = GetWindowLongPtr(m_tabs, GWL_STYLE); - SetWindowLongPtr(m_tabs, GWL_STYLE, pages > 1 ? style | WS_TABSTOP : style & ~WS_TABSTOP); } void CreateDetailsPageWindow(DetailsPageData *ppg) { - RECT *rc = ppg->pwszTab ? &m_rcDisplayTab : &m_rcDisplay; - ppg->hwnd = CreateDialogIndirectParam(ppg->hInst, ppg->pTemplate, m_hwnd, ppg->dlgProc, (LPARAM)m_hContact); + auto *pDlg = ppg->pDialog; + if (pDlg == nullptr) + return; + + pDlg->SetParent(m_hwnd); + pDlg->SetContact(m_hContact); + pDlg->Create(); + ppg->hwnd = pDlg->GetHwnd(); + ::ThemeDialogBackground(ppg->hwnd); - SetWindowPos(ppg->hwnd, HWND_TOP, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, 0); - SetWindowPos(ppg->hwnd, HWND_TOP, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, 0); - PSHNOTIFY pshn; - pshn.hdr.code = PSN_PARAMCHANGED; - pshn.hdr.hwndFrom = ppg->hwnd; - pshn.hdr.idFrom = 0; - pshn.lParam = (LPARAM)ppg->dlgParam; - SendMessage(ppg->hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); + pDlg->OnRefresh(); + } - pshn.hdr.code = PSN_INFOCHANGED; - pshn.hdr.hwndFrom = ppg->hwnd; - pshn.hdr.idFrom = 0; - pshn.lParam = (LPARAM)m_hContact; - SendMessage(ppg->hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); + void ResizeCurrent() + { + RECT rc; + GetWindowRect(m_place.GetHwnd(), &rc); + + POINT pt = { 0, 0 }; + ClientToScreen(m_hwnd, &pt); + OffsetRect(&rc, -pt.x, -pt.y); + SetWindowPos(m_pCurrent->hwnd, HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0); } - CCtrlBase m_white; + CCtrlBase m_white, m_place; + CCtrlButton btnUpdate; CCtrlTreeView m_tree; CTimer updateTimer; public: - CUserInfoDlg(MCONTACT hContact, int count, OPTIONSDIALOGPAGE *odp) : + CUserInfoDlg(MCONTACT hContact, const LIST &items) : CDlgBase(g_plugin, IDD_DETAILS), m_hContact(hContact), m_pages(1), m_tree(this, IDC_PAGETREE), + m_place(this, IDC_TABS), m_white(this, IDC_WHITERECT), + btnUpdate(this, IDC_UPDATE), updateTimer(this, 1) { + SetMinSize(480, 382); + m_white.UseSystemColors(); m_tree.OnSelChanged = Callback(this, &CUserInfoDlg::onSelChanged_Tree); m_tree.OnSelChanging = Callback(this, &CUserInfoDlg::onSelChanging); - updateTimer.OnEvent = Callback(this, &CUserInfoDlg::onTimer); + btnUpdate.OnClick = Callback(this, &CUserInfoDlg::onClick_Update); - for (int i = 0; i < count; i++, odp++) { - HINSTANCE hInst = odp->pPlugin->getInst(); - if (hInst != nullptr) { - auto *p = new DetailsPageData(); - p->pTemplate = (LPDLGTEMPLATE)LockResource(LoadResource(hInst, FindResourceA(hInst, odp->pszTemplate, MAKEINTRESOURCEA(5)))); - p->dlgProc = odp->pfnDlgProc; - p->dlgParam = odp->dwInitParam; - p->hInst = hInst; - p->dwFlags = odp->flags; - - p->pwszTitle = odp->szTitle.w; - p->pwszTab = odp->szTab.w; - p->pPlugin = odp->pPlugin; - m_pages.insert(p); - } + updateTimer.OnEvent = Callback(this, &CUserInfoDlg::onTimer); - if (odp->szGroup.a != nullptr) - mir_free(odp->szGroup.a); - if ((DWORD_PTR)odp->pszTemplate & 0xFFFF0000) - mir_free((char *)odp->pszTemplate); - } + for (auto odp: items) + m_pages.insert(odp); } bool OnInitDialog() override { Window_SetSkinIcon_IcoLib(m_hwnd, SKINICON_OTHER_USERDETAILS); + Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "main"); m_hProtoAckEvent = HookEventMessage(ME_PROTO_ACK, m_hwnd, M_PROTOACK); m_hDllUnloadEvent = HookEventMessage(ME_SYSTEM_MODULEUNLOAD, m_hwnd, M_DLLUNLOAD); @@ -248,38 +236,15 @@ public: BuildTree(); ////////////////////////////////////////////////////////////////////// - m_tabs = GetDlgItem(m_hwnd, IDC_TABS); - - TCITEM tci; - tci.mask = TCIF_TEXT | TCIF_IMAGE; - tci.iImage = -1; - tci.pszText = L"X"; - TabCtrl_InsertItem(m_tabs, 0, &tci); - - GetWindowRect(m_tabs, &m_rcDisplayTab); - TabCtrl_AdjustRect(m_tabs, FALSE, &m_rcDisplayTab); - - POINT pt = { 0, 0 }; - ClientToScreen(m_hwnd, &pt); - OffsetRect(&m_rcDisplayTab, -pt.x, -pt.y); - - TabCtrl_DeleteAllItems(m_tabs); - - GetWindowRect(m_tabs, &m_rcDisplay); - TabCtrl_AdjustRect(m_tabs, FALSE, &m_rcDisplay); - memset(&pt, 0, sizeof(pt)); - ClientToScreen(m_hwnd, &pt); - OffsetRect(&m_rcDisplay, -pt.x, -pt.y); - - m_tree.SelectItem(m_pages[m_currentPage].hItem); + m_tree.SelectItem(m_pCurrent->hItem); ////////////////////////////////////////////////////////////////////// m_updateAnimFrame = 0; GetDlgItemText(m_hwnd, IDC_UPDATING, m_szUpdating, _countof(m_szUpdating)); - SendMessage(m_hwnd, M_CHECKONLINE, 0, 0); + CheckOnline(); if (!ProtoChainSend(m_hContact, PSS_GETINFO, SGIF_ONOPEN, 0)) { - EnableWindow(GetDlgItem(m_hwnd, IDC_UPDATE), FALSE); + btnUpdate.Disable(); SetTimer(m_hwnd, 1, 100, nullptr); } else ShowWindow(GetDlgItem(m_hwnd, IDC_UPDATING), SW_HIDE); @@ -293,10 +258,10 @@ public: PSHNOTIFY pshn; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)m_hContact; - if (m_currentPage != -1) { + if (m_pCurrent) { pshn.hdr.code = PSN_KILLACTIVE; - pshn.hdr.hwndFrom = m_pages[m_currentPage].hwnd; - if (SendMessage(m_pages[m_currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) + pshn.hdr.hwndFrom = m_pCurrent->hwnd; + if (SendMessage(m_pCurrent->hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) return false; } @@ -307,25 +272,50 @@ public: pshn.hdr.hwndFrom = odp->hwnd; if (SendMessage(odp->hwnd, WM_NOTIFY, 0, (LPARAM)&pshn) == PSNRET_INVALID_NOCHANGEPAGE) { m_tree.Select(odp->hItem, TVGN_CARET); - if (m_currentPage != -1) ShowWindow(m_pages[m_currentPage].hwnd, SW_HIDE); - m_currentPage = m_pages.indexOf(&odp); - ShowWindow(m_pages[m_currentPage].hwnd, SW_SHOW); + if (m_pCurrent) + ShowWindow(m_pCurrent->hwnd, SW_HIDE); + m_pCurrent = odp; + ShowWindow(m_pCurrent->hwnd, SW_SHOW); return false; } } return true; } + int Resizer(UTILRESIZECONTROL *urc) override + { + switch (urc->wId) { + case IDC_TABS: + return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; + + case IDOK: + return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM; + + case IDC_HEADERBAR: + case IDC_WHITERECT: + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; + + case IDC_PAGETREE: + return RD_ANCHORX_LEFT | RD_ANCHORY_HEIGHT; + } + + return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM; + } + void OnDestroy() override { - wchar_t name[128]; - TVITEMEX tvi; - tvi.mask = TVIF_TEXT; - tvi.hItem = m_pages[m_currentPage].hItem; - tvi.pszText = name; - tvi.cchTextMax = _countof(name); - m_tree.GetItem(&tvi); - g_plugin.setWString("LastTab", name); + if (m_pCurrent) { + wchar_t name[128]; + TVITEMEX tvi; + tvi.mask = TVIF_TEXT; + tvi.hItem = m_pCurrent->hItem; + tvi.pszText = name; + tvi.cchTextMax = _countof(name); + m_tree.GetItem(&tvi); + g_plugin.setWString("LastTab", name); + } + + Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "main"); Window_FreeIcon_IcoLib(m_hwnd); SendDlgItemMessage(m_hwnd, IDC_NAME, WM_SETFONT, SendDlgItemMessage(m_hwnd, IDC_WHITERECT, WM_GETFONT, 0, 0), 0); @@ -345,7 +335,8 @@ public: switch (uMsg) { case PSM_CHANGED: - m_pages[m_currentPage].changed = 1; + if (m_pCurrent) + m_pCurrent->changed = 1; return TRUE; case PSM_FORCECHANGED: @@ -359,26 +350,12 @@ public: } break; - case M_CHECKONLINE: - if (m_hContact != NULL) { - char *szProto = Proto_GetBaseAccountName(m_hContact); - if (szProto == nullptr) - EnableWindow(GetDlgItem(m_hwnd, IDC_UPDATE), FALSE); - else { - if (Proto_GetStatus(szProto) < ID_STATUS_ONLINE) - EnableWindow(GetDlgItem(m_hwnd, IDC_UPDATE), FALSE); - else - EnableWindow(GetDlgItem(m_hwnd, IDC_UPDATE), !IsWindowVisible(GetDlgItem(m_hwnd, IDC_UPDATING))); - } - } - break; - case M_DLLUNLOAD: { bool bRemoved = false; HINSTANCE hInst = (HINSTANCE)lParam; for (auto &odp : m_pages.rev_iter()) { - if (odp->hInst == hInst) { + if (odp->pPlugin->getInst() == hInst) { if (!bRemoved) { m_tree.DeleteAllItems(); bRemoved = true; @@ -390,12 +367,13 @@ public: if (bRemoved) BuildTree(); } + break; case M_PROTOACK: { ACKDATA *ack = (ACKDATA *)lParam; if (ack->hContact == NULL && ack->type == ACKTYPE_STATUS) { - SendMessage(m_hwnd, M_CHECKONLINE, 0, 0); + CheckOnline(); break; } if (ack->hContact != m_hContact || ack->type != ACKTYPE_GETINFO) @@ -406,11 +384,13 @@ public: if (!ack->hProcess && !ack->lParam) { ShowWindow(GetDlgItem(m_hwnd, IDC_UPDATING), SW_HIDE); updateTimer.Stop(); - SendMessage(m_hwnd, M_CHECKONLINE, 0, 0); + CheckOnline(); break; - } //if + } + if (m_infosUpdated == nullptr) m_infosUpdated = (int *)mir_calloc(sizeof(int) * (INT_PTR)ack->hProcess); + if (ack->result == ACKRESULT_SUCCESS || ack->result == ACKRESULT_FAILED) m_infosUpdated[ack->lParam] = 1; @@ -422,72 +402,49 @@ public: if (i == (INT_PTR)ack->hProcess) { ShowWindow(GetDlgItem(m_hwnd, IDC_UPDATING), SW_HIDE); updateTimer.Stop(); - SendMessage(m_hwnd, M_CHECKONLINE, 0, 0); + CheckOnline(); } } break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->code) { - case TCN_SELCHANGING: - onSelChanging(0); - break; - - case TCN_SELCHANGE: - if (m_currentPage != -1 && m_pages[m_currentPage].hwnd != NULL) { - ShowWindow(m_pages[m_currentPage].hwnd, SW_HIDE); - - TCITEM tie; - tie.mask = TCIF_PARAM; - TabCtrl_GetItem(m_tabs, TabCtrl_GetCurSel(m_tabs), &tie); - m_currentPage = tie.lParam; - - TVITEMEX tvi; - tvi.hItem = m_tree.GetNextItem(NULL, TVGN_CARET); - tvi.mask = TVIF_PARAM; - tvi.lParam = m_currentPage; - m_tree.SetItem(&tvi); - - if (m_currentPage != -1) { - if (m_pages[m_currentPage].hwnd == NULL) - CreateDetailsPageWindow(&m_pages[m_currentPage]); - ShowWindow(m_pages[m_currentPage].hwnd, SW_SHOWNA); - } - } - break; - } } - return CDlgBase::DlgProc(uMsg, wParam, lParam); + INT_PTR res = CDlgBase::DlgProc(uMsg, wParam, lParam); + + if (uMsg == WM_SIZE && m_pCurrent) + ResizeCurrent(); + + return res; + } void onSelChanging(CCtrlTreeView *) { - if (m_currentPage != -1 && m_pages[m_currentPage].hwnd != NULL) { + if (m_pCurrent && m_pCurrent->hwnd != NULL) { PSHNOTIFY pshn; pshn.hdr.code = PSN_KILLACTIVE; - pshn.hdr.hwndFrom = m_pages[m_currentPage].hwnd; + pshn.hdr.hwndFrom = m_pCurrent->hwnd; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)m_hContact; - if (SendMessage(m_pages[m_currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) + if (SendMessage(m_pCurrent->hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, TRUE); } } void onSelChanged_Tree(CCtrlTreeView::TEventInfo *ev) { - if (m_currentPage != -1 && m_pages[m_currentPage].hwnd != NULL) - ShowWindow(m_pages[m_currentPage].hwnd, SW_HIDE); + if (m_pCurrent && m_pCurrent->hwnd != NULL) + ShowWindow(m_pCurrent->hwnd, SW_HIDE); LPNMTREEVIEW pnmtv = ev->nmtv; TVITEM tvi = pnmtv->itemNew; - m_currentPage = tvi.lParam; + m_pCurrent = (DetailsPageData*)tvi.lParam; + + if (m_pCurrent) { + if (m_pCurrent->hwnd == NULL) + CreateDetailsPageWindow(m_pCurrent); - if (m_currentPage != -1) { - CreateDetailsTabs(&m_pages[m_currentPage]); - if (m_pages[m_currentPage].hwnd == NULL) - CreateDetailsPageWindow(&m_pages[m_currentPage]); - ShowWindow(m_pages[m_currentPage].hwnd, SW_SHOWNA); + ResizeCurrent(); + ShowWindow(m_pCurrent->hwnd, SW_SHOWNA); } } @@ -515,7 +472,7 @@ public: if (m_hContact != NULL) { if (!ProtoChainSend(m_hContact, PSS_GETINFO, 0, 0)) { - EnableWindow(GetDlgItem(m_hwnd, IDC_UPDATE), FALSE); + btnUpdate.Disable(); ShowWindow(GetDlgItem(m_hwnd, IDC_UPDATING), SW_SHOW); updateTimer.Start(100); } @@ -537,62 +494,43 @@ public: static INT_PTR AddDetailsPage(WPARAM wParam, LPARAM lParam) { - OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE *)lParam; - struct DetailsPageInit *opi = (struct DetailsPageInit *)wParam; - - if (odp == nullptr || opi == nullptr) + auto *uip = (USERINFOPAGE*)lParam; + auto *pList = (LIST*)wParam; + if (uip == nullptr || pList == nullptr) return 1; - opi->odp = (OPTIONSDIALOGPAGE *)mir_realloc(opi->odp, sizeof(OPTIONSDIALOGPAGE) * (opi->pageCount + 1)); - OPTIONSDIALOGPAGE *dst = opi->odp + opi->pageCount; - memset(dst, 0, sizeof(OPTIONSDIALOGPAGE)); - dst->pPlugin = odp->pPlugin; - dst->pfnDlgProc = odp->pfnDlgProc; - dst->position = odp->position; - dst->pszTemplate = ((DWORD_PTR)odp->pszTemplate & 0xFFFF0000) ? mir_strdup(odp->pszTemplate) : odp->pszTemplate; - - if (odp->flags & ODPF_UNICODE) { - dst->szTitle.w = (odp->szTitle.w == nullptr) ? nullptr : mir_wstrdup(odp->szTitle.w); - dst->szTab.w = (odp->flags & ODPF_USERINFOTAB) ? mir_wstrdup(odp->szTab.w) : nullptr; + auto *pNew = new DetailsPageData(); + pNew->pPlugin = uip->pPlugin; + pNew->pDialog = uip->pDialog; + + if (uip->flags & ODPF_UNICODE) { + pNew->pwszTitle = (uip->szTitle.w == nullptr) ? nullptr : mir_wstrdup(uip->szTitle.w); + pNew->pwszGroup = (uip->flags & ODPF_USERINFOTAB) ? mir_wstrdup(uip->szGroup.w) : nullptr; } else { - dst->szTitle.w = mir_a2u(odp->szTitle.a); - dst->szTab.w = (odp->flags & ODPF_USERINFOTAB) ? mir_a2u(odp->szTab.a) : nullptr; + pNew->pwszTitle = mir_a2u(uip->szTitle.a); + pNew->pwszGroup = (uip->flags & ODPF_USERINFOTAB) ? mir_a2u(uip->szGroup.a) : nullptr; } - dst->flags = odp->flags; - dst->dwInitParam = odp->dwInitParam; - opi->pageCount++; + pNew->dwFlags = uip->flags; + pList->insert(pNew); return 0; } ///////////////////////////////////////////////////////////////////////////////////////// -static wchar_t *getTab(OPTIONSDIALOGPAGE *p) -{ - return (p->flags & ODPF_DONTTRANSLATE) ? p->szTab.w : TranslateW_LP(p->szTab.w, p->pPlugin); -} - -static wchar_t *getTitle(OPTIONSDIALOGPAGE *p) +static int PageSortProc(const DetailsPageData *item1, const DetailsPageData *item2) { - return (p->flags & ODPF_DONTTRANSLATE) ? p->szTitle.w : TranslateW_LP(p->szTitle.w, p->pPlugin); -} - -static int PageSortProc(OPTIONSDIALOGPAGE *item1, OPTIONSDIALOGPAGE *item2) -{ - int res; - wchar_t *s1 = getTitle(item1), *s2 = getTitle(item2); - if (!mir_wstrcmp(s1, TranslateT("Summary"))) return -1; - if (!mir_wstrcmp(s2, TranslateT("Summary"))) return 1; - if (res = mir_wstrcmp(s1, s2)) return res; - - s1 = getTab(item1), s2 = getTab(item2); + wchar_t *s1 = item1->getGroup(), *s2 = item2->getGroup(); if (s1 && !s2) return -1; if (!s1 && s2) return 1; if (!s1 && !s2) return 0; - if (s1 && !mir_wstrcmp(s1, TranslateT("General"))) return -1; - if (s2 && !mir_wstrcmp(s2, TranslateT("General"))) return 1; + s1 = item1->getTitle(), s2 = item2->getTitle(); + if (!mir_wstrcmp(s1, TranslateT("Summary"))) return -1; + if (!mir_wstrcmp(s2, TranslateT("Summary"))) return 1; + if (int res = mir_wstrcmp(s1, s2)) return res; + return mir_wstrcmp(s1, s2); } @@ -604,17 +542,13 @@ static INT_PTR ShowDetailsDialogCommand(WPARAM hContact, LPARAM) return 0; } - DetailsPageInit opi = {}; - NotifyEventHooks(hDetailsInitEvent, (WPARAM)&opi, hContact); - if (opi.pageCount == 0) + LIST items(1, PageSortProc); + NotifyEventHooks(hDetailsInitEvent, (WPARAM)&items, hContact); + if (items.getCount() == 0) return 0; - qsort(opi.odp, opi.pageCount, sizeof(OPTIONSDIALOGPAGE), (int(*)(const void *, const void *))PageSortProc); - - auto *pDlg = new CUserInfoDlg(hContact, opi.pageCount, opi.odp); + auto *pDlg = new CUserInfoDlg(hContact, items); pDlg->Show(); - - mir_free(opi.odp); return 0; } diff --git a/src/core/stduserinfo/stduserinfo.vcxproj b/src/core/stduserinfo/stduserinfo.vcxproj index 61abde3715..90b5de2fb9 100644 --- a/src/core/stduserinfo/stduserinfo.vcxproj +++ b/src/core/stduserinfo/stduserinfo.vcxproj @@ -40,4 +40,7 @@ + + + \ No newline at end of file diff --git a/src/core/stduserinfo/stduserinfo.vcxproj.filters b/src/core/stduserinfo/stduserinfo.vcxproj.filters index bc7d03c062..21fb202501 100644 --- a/src/core/stduserinfo/stduserinfo.vcxproj.filters +++ b/src/core/stduserinfo/stduserinfo.vcxproj.filters @@ -34,4 +34,9 @@ Resource Files + + + Resource Files + + \ No newline at end of file -- cgit v1.2.3