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 --- plugins/AVS/src/options.cpp | 467 ++++++------- plugins/BuddyExpectator/src/options.cpp | 92 +-- plugins/ExternalAPI/m_userinfoex.h | 1 - plugins/FavContacts/src/stdafx.h | 2 +- plugins/FingerprintNG/src/stdafx.h | 1 + plugins/HTTPServer/src/Glob.h | 2 +- plugins/NewXstatusNotify/src/indsnd.cpp | 456 ++++++------- plugins/QuickContacts/src/stdafx.h | 1 + plugins/Scriver/src/stdafx.h | 1 + plugins/SeenPlugin/src/stdafx.h | 1 + plugins/SeenPlugin/src/userinfo.cpp | 56 +- plugins/TabSRMM/src/stdafx.h | 1 + plugins/UserInfoEx/src/classMAnnivDate.cpp | 2 +- plugins/UserInfoEx/src/classPsTree.cpp | 28 +- plugins/UserInfoEx/src/classPsTreeItem.cpp | 115 +--- plugins/UserInfoEx/src/ctrl_combo.cpp | 2 +- plugins/UserInfoEx/src/ctrl_contact.cpp | 8 +- plugins/UserInfoEx/src/ctrl_edit.cpp | 2 +- plugins/UserInfoEx/src/dlg_propsheet.cpp | 92 +-- plugins/UserInfoEx/src/dlg_propsheet.h | 78 +-- .../UserInfoEx/src/ex_import/dlg_ExImModules.cpp | 2 +- plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp | 2 +- plugins/UserInfoEx/src/mir_db.h | 13 +- plugins/UserInfoEx/src/psp_about.cpp | 133 ++-- plugins/UserInfoEx/src/psp_anniversary.cpp | 311 ++++----- plugins/UserInfoEx/src/psp_base.cpp | 114 ++-- plugins/UserInfoEx/src/psp_base.h | 43 +- plugins/UserInfoEx/src/psp_company.cpp | 66 +- plugins/UserInfoEx/src/psp_contact.cpp | 467 ++++++------- plugins/UserInfoEx/src/psp_general.cpp | 236 +++---- plugins/UserInfoEx/src/psp_origin.cpp | 201 +++--- plugins/UserInfoEx/src/psp_profile.cpp | 743 +++++++++++---------- plugins/UserInfoEx/src/stdafx.h | 16 +- 33 files changed, 1774 insertions(+), 1981 deletions(-) (limited to 'plugins') diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index ef355a951d..7ab9d4d379 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -732,154 +732,173 @@ int OptInit(WPARAM wParam, LPARAM) } ///////////////////////////////////////////////////////////////////////////////////////// +// User info dialog -static INT_PTR CALLBACK DlgProcAvatarUserInfo(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class AvatarUserInfoDlg : public CUserInfoPageDlg { - WindowData *dat = (WindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - MCONTACT hContact = (dat) ? dat->hContact : INVALID_CONTACT_ID; + HANDLE hHook = nullptr; - switch (msg) { - case WM_INITDIALOG: - dat = new WindowData(hContact = lParam, hwndDlg); - { - HWND protopic = GetDlgItem(hwndDlg, IDC_PROTOPIC); - SendMessage(protopic, AVATAR_SETCONTACT, 0, (LPARAM)hContact); - SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW)); - SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("Contact has no avatar")); - SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, (LPARAM)FALSE); - SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE); - } + CCtrlCheck chkTransparent; + CCtrlButton btnHide, btnChange, btnDefaults, btnProtect, btnReset, btnDelete; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - TranslateDialogDefault(hwndDlg); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_HIDEAVATAR, Contact_IsHidden(hContact) ? BST_CHECKED : BST_UNCHECKED); + void ReloadAvatar() + { + SaveTransparentData(m_hwnd, m_hContact, IsDlgButtonChecked(m_hwnd, IDC_PROTECTAVATAR)); + ChangeAvatar(m_hContact, true); + } - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), 0); - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2)); + INT_PTR OnChangeAvatar(UINT, WPARAM, LPARAM) + { + InvalidateRect(GetDlgItem(m_hwnd, IDC_PROTOPIC), nullptr, TRUE); + return 0; + } - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), 0); - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); + UI_MESSAGE_MAP(AvatarUserInfoDlg, CUserInfoPageDlg); + UI_MESSAGE(DM_AVATARCHANGED, OnChangeAvatar); + UI_MESSAGE_MAP_END(); + +public: + AvatarUserInfoDlg() : + CUserInfoPageDlg(g_plugin, IDD_USER_AVATAR), + btnHide(this, IDC_HIDEAVATAR), + btnReset(this, IDC_RESET), + btnChange(this, IDC_CHANGE), + btnDelete(this, IDC_DELETE), + btnProtect(this, IDC_PROTECTAVATAR), + btnDefaults(this, ID_USE_DEFAULTS), + chkTransparent(this, IDC_MAKETRANSPBKG) + { + btnHide.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Hide); + btnReset.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Reset); + btnChange.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Change); + btnDelete.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Delete); + btnProtect.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Protect); + btnDefaults.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_UseDefaults); + + chkTransparent.OnChange = Callback(this, &AvatarUserInfoDlg::onChange_Transparent); + } - LoadTransparentData(hwndDlg, GetContactThatHaveTheAvatar(hContact)); - break; + bool OnInitDialog() override + { + hHook = HookEventMessage(ME_AV_AVATARCHANGED, m_hwnd, DM_AVATARCHANGED); - case WM_COMMAND: - switch (LOWORD(wParam)) { - case ID_USE_DEFAULTS: - hContact = GetContactThatHaveTheAvatar(hContact); + HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC); + SendMessage(protopic, AVATAR_SETCONTACT, 0, m_hContact); + SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW)); + SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("Contact has no avatar")); + SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, (LPARAM)FALSE); + SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE); - db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); - db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); - db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); + SendMessage(m_hwnd, DM_SETAVATARNAME, 0, 0); + CheckDlgButton(m_hwnd, IDC_PROTECTAVATAR, db_get_b(m_hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_HIDEAVATAR, Contact_IsHidden(m_hContact) ? BST_CHECKED : BST_UNCHECKED); - LoadTransparentData(hwndDlg, hContact); + SendDlgItemMessage(m_hwnd, IDC_BKG_NUM_POINTS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS), 0); + SendDlgItemMessage(m_hwnd, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2)); - SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0); - break; + SendDlgItemMessage(m_hwnd, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE), 0); + SendDlgItemMessage(m_hwnd, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); - case IDC_CHANGE: - SetAvatar(hContact, 0); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); - break; + LoadTransparentData(m_hwnd, GetContactThatHaveTheAvatar(m_hContact)); + return true; + } - case IDC_HIDEAVATAR: - { - bool hidden = IsDlgButtonChecked(hwndDlg, IDC_HIDEAVATAR) != 0; - SetAvatarAttribute(hContact, AVS_HIDEONCLIST, hidden); - if (hidden != Contact_IsHidden(hContact)) - Contact_Hide(hContact, hidden); - } - break; + void OnDestroy() override + { + UnhookEvent(hHook); + } - case IDC_PROTECTAVATAR: - { - BOOL locked = IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR); - SaveTransparentData(hwndDlg, hContact, locked); - ProtectAvatar(hContact, locked ? 1 : 0); - } - break; + void onClick_UseDefaults(CCtrlButton *) + { + m_hContact = GetContactThatHaveTheAvatar(m_hContact); - case IDC_BKG_NUM_POINTS: - case IDC_BKG_COLOR_DIFFERENCE: - if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) - break; + db_unset(m_hContact, "ContactPhoto", "MakeTransparentBkg"); + db_unset(m_hContact, "ContactPhoto", "TranspBkgNumPoints"); + db_unset(m_hContact, "ContactPhoto", "TranspBkgColorDiff"); - case IDC_MAKETRANSPBKG: - { - BOOL enable = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), enable); - } - SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0); - break; - case IDC_RESET: - ProtectAvatar(hContact, 0); - if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { - DBVARIANT dbv = { 0 }; - if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.pwszVal); - db_free(&dbv); - } - } - db_unset(hContact, "ContactPhoto", "Locked"); - db_unset(hContact, "ContactPhoto", "Backup"); - db_unset(hContact, "ContactPhoto", "RFile"); - db_unset(hContact, "ContactPhoto", "File"); - db_unset(hContact, "ContactPhoto", "Format"); - { - char *szProto = Proto_GetBaseAccountName(hContact); - db_unset(hContact, szProto, "AvatarHash"); - DeleteAvatarFromCache(hContact, FALSE); + LoadTransparentData(m_hwnd, m_hContact); + ReloadAvatar(); + } - QueueAdd(hContact); - } - break; + void onClick_Change(CCtrlButton *) + { + SetAvatar(m_hContact, 0); + SendMessage(m_hwnd, DM_SETAVATARNAME, 0, 0); + CheckDlgButton(m_hwnd, IDC_PROTECTAVATAR, db_get_b(m_hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); + } - case IDC_DELETE: - ProtectAvatar(hContact, 0); - if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { - DBVARIANT dbv = { 0 }; - if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.pwszVal); - db_free(&dbv); - } + void onClick_Hide(CCtrlButton *) + { + bool hidden = IsDlgButtonChecked(m_hwnd, IDC_HIDEAVATAR) != 0; + SetAvatarAttribute(m_hContact, AVS_HIDEONCLIST, hidden); + if (hidden != Contact_IsHidden(m_hContact)) + Contact_Hide(m_hContact, hidden); + } + + void onClick_Protect(CCtrlButton *) + { + BOOL locked = IsDlgButtonChecked(m_hwnd, IDC_PROTECTAVATAR); + SaveTransparentData(m_hwnd, m_hContact, locked); + ProtectAvatar(m_hContact, locked ? 1 : 0); + } + + void onChange_Transparent(CCtrlCheck *) + { + BOOL enable = IsDlgButtonChecked(m_hwnd, IDC_MAKETRANSPBKG); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS_L), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS_SPIN), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE_L), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE_SPIN), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE), enable); + ReloadAvatar(); + } + + void onClick_Reset(CCtrlButton *) + { + ProtectAvatar(m_hContact, 0); + if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { + DBVARIANT dbv = { 0 }; + if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) { + DeleteFile(dbv.pwszVal); + db_free(&dbv); } - db_unset(hContact, "ContactPhoto", "Locked"); - db_unset(hContact, "ContactPhoto", "Backup"); - db_unset(hContact, "ContactPhoto", "RFile"); - db_unset(hContact, "ContactPhoto", "File"); - db_unset(hContact, "ContactPhoto", "Format"); - DeleteAvatarFromCache(hContact, FALSE); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - break; } - break; + db_unset(m_hContact, "ContactPhoto", "Locked"); + db_unset(m_hContact, "ContactPhoto", "Backup"); + db_unset(m_hContact, "ContactPhoto", "RFile"); + db_unset(m_hContact, "ContactPhoto", "File"); + db_unset(m_hContact, "ContactPhoto", "Format"); - case DM_REALODAVATAR: - SaveTransparentData(hwndDlg, hContact, IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR)); - ChangeAvatar(hContact, true); - break; + char *szProto = Proto_GetBaseAccountName(m_hContact); + db_unset(m_hContact, szProto, "AvatarHash"); + DeleteAvatarFromCache(m_hContact, FALSE); - case DM_AVATARCHANGED: - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; + QueueAdd(m_hContact); + } - case WM_NCDESTROY: - delete dat; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - break; + void onClick_Delete(CCtrlButton *) + { + ProtectAvatar(m_hContact, 0); + if (MessageBoxW(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { + DBVARIANT dbv = { 0 }; + if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) { + DeleteFile(dbv.pwszVal); + db_free(&dbv); + } + } + db_unset(m_hContact, "ContactPhoto", "Locked"); + db_unset(m_hContact, "ContactPhoto", "Backup"); + db_unset(m_hContact, "ContactPhoto", "RFile"); + db_unset(m_hContact, "ContactPhoto", "File"); + db_unset(m_hContact, "ContactPhoto", "Format"); + DeleteAvatarFromCache(m_hContact, FALSE); + SendMessage(m_hwnd, DM_SETAVATARNAME, 0, 0); } - return FALSE; -} +}; ///////////////////////////////////////////////////////////////////////////////////////// +// Protocol avatar dialog static char* GetSelectedProtocol(HWND hwndDlg) { @@ -982,143 +1001,145 @@ static void EnableDisableProtocols(HWND hwndDlg, BOOL init) } } -static INT_PTR CALLBACK DlgProcAvatarProtoInfo(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class AvatarProtoInfoDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - HWND protopic = GetDlgItem(hwndDlg, IDC_PROTOPIC); - SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW)); - SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("No avatar")); - SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE); - - HWND hwndList = GetDlgItem(hwndDlg, IDC_PROTOCOLS); - ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_SUBITEMIMAGES); + CCtrlCheck chkPerProto; + CCtrlButton btnChange, btnDelete; + CCtrlListView protocols; + +public: + AvatarProtoInfoDlg() : + CUserInfoPageDlg(g_plugin, IDD_PROTO_AVATARS), + protocols(this, IDC_PROTOCOLS), + btnChange(this, IDC_CHANGE), + btnDelete(this, IDC_DELETE), + chkPerProto(this, IDC_PER_PROTO) + { + btnChange.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Change); + btnDelete.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Delete); - HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0); - ListView_SetImageList(hwndList, hIml, LVSIL_SMALL); + chkPerProto.OnChange = Callback(this, &AvatarProtoInfoDlg::onChange_PerProto); + } - LVCOLUMN lvc = { 0 }; - lvc.mask = LVCF_FMT; - lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT; - ListView_InsertColumn(hwndList, 0, &lvc); + bool OnInitDialog() override + { + HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC); + SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW)); + SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("No avatar")); + SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE); - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; - item.iItem = 1000; + protocols.SetExtendedListViewStyleEx(0, LVS_EX_SUBITEMIMAGES); - // List protocols - int num = 0; - for (auto &it : Accounts()) { - if (!ProtoServiceExists(it->szModuleName, PS_GETMYAVATAR)) - continue; + HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0); + protocols.SetImageList(hIml, LVSIL_SMALL); - if (!Proto_IsAvatarsEnabled(it->szModuleName)) - continue; + LVCOLUMN lvc = { 0 }; + lvc.mask = LVCF_FMT; + lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT; + protocols.InsertColumn(0, &lvc); - ImageList_AddIcon(hIml, Skin_LoadProtoIcon(it->szModuleName, ID_STATUS_ONLINE)); - item.pszText = it->tszAccountName; - item.iImage = num; - item.lParam = (LPARAM)it->szModuleName; + LVITEM item = { 0 }; + item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; + item.iItem = 1000; - ListView_InsertItem(hwndList, &item); - num++; - } + // List protocols + int num = 0; + for (auto &it : Accounts()) { + if (!ProtoServiceExists(it->szModuleName, PS_GETMYAVATAR)) + continue; - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE); - ListView_Arrange(hwndList, LVA_ALIGNLEFT | LVA_ALIGNTOP); + if (!Proto_IsAvatarsEnabled(it->szModuleName)) + continue; - // Check if should show per protocol avatars - CheckDlgButton(hwndDlg, IDC_PER_PROTO, g_plugin.getByte("PerProtocolUserAvatars", 1) ? BST_CHECKED : BST_UNCHECKED); - EnableDisableProtocols(hwndDlg, TRUE); + ImageList_AddIcon(hIml, Skin_LoadProtoIcon(it->szModuleName, ID_STATUS_ONLINE)); + item.pszText = it->tszAccountName; + item.iImage = num; + item.lParam = (LPARAM)it->szModuleName; + protocols.InsertItem(&item); + num++; } - break; - case WM_NOTIFY: - { - LPNMHDR nm = (LPNMHDR)lParam; - switch (nm->idFrom) { - case IDC_PROTOCOLS: - switch (nm->code) { - case LVN_ITEMCHANGED: - LPNMLISTVIEW li = (LPNMLISTVIEW)nm; - if (li->uNewState & LVIS_SELECTED) { - SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam); - EnableDisableControls(hwndDlg, (char*)li->lParam); - } - } - break; + protocols.SetColumnWidth(0, LVSCW_AUTOSIZE); + protocols.Arrange(LVA_ALIGNLEFT | LVA_ALIGNTOP); - case IDC_PROTOPIC: - if (nm->code == NM_AVATAR_CHANGED) { - EnableDisableControls(hwndDlg, GetSelectedProtocol(hwndDlg)); - break; - } - } + // Check if should show per protocol avatars + CheckDlgButton(m_hwnd, IDC_PER_PROTO, g_plugin.getByte("PerProtocolUserAvatars", 1) ? BST_CHECKED : BST_UNCHECKED); + EnableDisableProtocols(m_hwnd, TRUE); + return true; + } + + void onItemChanged_List(CCtrlListView::TEventInfo *ev) + { + LPNMLISTVIEW li = ev->nmlv; + if (li->uNewState & LVIS_SELECTED) { + SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam); + EnableDisableControls(m_hwnd, (char*)li->lParam); } - break; + } - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_CHANGE: - if (BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_PER_PROTO)) - SetMyAvatar(NULL, NULL); - else { - char *proto = GetSelectedProtocol(hwndDlg); - if (proto != nullptr) - SetMyAvatar((WPARAM)proto, NULL); - } - break; + INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override + { + if (msg == WM_NOTIFY) { + LPNMHDR hdr = (LPNMHDR)lParam; + if (hdr->idFrom == IDC_PROTOPIC && hdr->code == NM_AVATAR_CHANGED) + EnableDisableControls(m_hwnd, GetSelectedProtocol(m_hwnd)); + } + return CDlgBase::DlgProc(msg, wParam, lParam); + } - case IDC_DELETE: - if (BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_PER_PROTO)) { - if (MessageBox(hwndDlg, TranslateT("Are you sure you want to remove your avatar?"), TranslateT("Global avatar"), MB_YESNO) == IDYES) - SetMyAvatar(NULL, (LPARAM)L""); - } - else { - char *proto = GetSelectedProtocol(hwndDlg); - if (proto == nullptr) - break; + void onClick_Change(CCtrlButton *) + { + if (BST_UNCHECKED == IsDlgButtonChecked(m_hwnd, IDC_PER_PROTO)) + SetMyAvatar(NULL, NULL); + else { + char *proto = GetSelectedProtocol(m_hwnd); + if (proto != nullptr) + SetMyAvatar((WPARAM)proto, NULL); + } + } + void onClick_Delete(CCtrlButton *) + { + if (BST_UNCHECKED == IsDlgButtonChecked(m_hwnd, IDC_PER_PROTO)) { + if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), TranslateT("Global avatar"), MB_YESNO) == IDYES) + SetMyAvatar(NULL, (LPARAM)L""); + } + else { + if (char *proto = GetSelectedProtocol(m_hwnd)) { char description[256]; CallProtoService(proto, PS_GETNAME, _countof(description), (LPARAM)description); wchar_t *descr = mir_a2u(description); - if (MessageBox(hwndDlg, TranslateT("Are you sure you want to remove your avatar?"), descr, MB_YESNO) == IDYES) + if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), descr, MB_YESNO) == IDYES) SetMyAvatar((WPARAM)proto, (LPARAM)L""); mir_free(descr); } - break; - - case IDC_PER_PROTO: - g_plugin.setByte("PerProtocolUserAvatars", IsDlgButtonChecked(hwndDlg, IDC_PER_PROTO) ? 1 : 0); - EnableDisableProtocols(hwndDlg, FALSE); - break; } - break; } - return FALSE; -} + + void onChange_PerProto(CCtrlCheck*) + { + g_plugin.setByte("PerProtocolUserAvatars", IsDlgButtonChecked(m_hwnd, IDC_PER_PROTO) ? 1 : 0); + EnableDisableProtocols(m_hwnd, FALSE); + } +}; int OnDetailsInit(WPARAM wParam, LPARAM hContact) { - OPTIONSDIALOGPAGE odp = {}; - odp.szTitle.a = LPGEN("Avatar"); + USERINFOPAGE uip = {}; + uip.szTitle.a = LPGEN("Avatar"); if (hContact == NULL) { // User dialog - odp.pfnDlgProc = DlgProcAvatarProtoInfo; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROTO_AVATARS); - g_plugin.addUserInfo(wParam, &odp); + uip.pDialog = new AvatarProtoInfoDlg(); + g_plugin.addUserInfo(wParam, &uip); } else { char *szProto = Proto_GetBaseAccountName(hContact); if (szProto == nullptr || g_plugin.getByte(szProto, 1)) { // Contact dialog - odp.pfnDlgProc = DlgProcAvatarUserInfo; - odp.position = -2000000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_USER_AVATAR); - g_plugin.addUserInfo(wParam, &odp); + uip.position = -2000000000; + uip.pDialog = new AvatarUserInfoDlg(); + g_plugin.addUserInfo(wParam, &uip); } } return 0; diff --git a/plugins/BuddyExpectator/src/options.cpp b/plugins/BuddyExpectator/src/options.cpp index 06e1e9560a..07bcdc9562 100644 --- a/plugins/BuddyExpectator/src/options.cpp +++ b/plugins/BuddyExpectator/src/options.cpp @@ -439,88 +439,66 @@ int OptionsInit(WPARAM wParam, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// // UserInfo initalization -INT_PTR CALLBACK UserinfoDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) +struct UserinfoDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: + UserinfoDlg() : + CUserInfoPageDlg(g_plugin, IDD_USERINFO) + {} + + bool OnInitDialog() override { time_t tmpTime; wchar_t tmpBuf[51] = { 0 }; - tmpTime = getLastSeen((MCONTACT)lparam); + tmpTime = getLastSeen(m_hContact); if (tmpTime == -1) - SetDlgItemText(hdlg, IDC_EDIT_LASTSEEN, TranslateT("not detected")); + SetDlgItemTextW(m_hwnd, IDC_EDIT_LASTSEEN, TranslateT("not detected")); else { wcsftime(tmpBuf, 50, L"%#x, %#X", gmtime(&tmpTime)); - SetDlgItemText(hdlg, IDC_EDIT_LASTSEEN, tmpBuf); + SetDlgItemTextW(m_hwnd, IDC_EDIT_LASTSEEN, tmpBuf); } - tmpTime = getLastInputMsg((MCONTACT)lparam); + tmpTime = getLastInputMsg(m_hContact); if (tmpTime == -1) - SetDlgItemText(hdlg, IDC_EDIT_LASTINPUT, TranslateT("not found")); + SetDlgItemTextW(m_hwnd, IDC_EDIT_LASTINPUT, TranslateT("not found")); else { wcsftime(tmpBuf, 50, L"%#x, %#X", gmtime(&tmpTime)); - SetDlgItemText(hdlg, IDC_EDIT_LASTINPUT, tmpBuf); + SetDlgItemTextW(m_hwnd, IDC_EDIT_LASTINPUT, tmpBuf); } - unsigned int AbsencePeriod = g_plugin.getDword(lparam, "iAbsencePeriod", options.iAbsencePeriod); + unsigned int AbsencePeriod = g_plugin.getDword(m_hContact, "iAbsencePeriod", options.iAbsencePeriod); - SendDlgItemMessage(hdlg, IDC_SPINABSENCE, UDM_SETRANGE, 0, MAKELONG(999, 1)); - SetDlgItemInt(hdlg, IDC_EDITABSENCE, AbsencePeriod, FALSE); + SendDlgItemMessage(m_hwnd, IDC_SPINABSENCE, UDM_SETRANGE, 0, MAKELONG(999, 1)); + SetDlgItemInt(m_hwnd, IDC_EDITABSENCE, AbsencePeriod, FALSE); - if (isContactGoneFor((MCONTACT)lparam, options.iAbsencePeriod2)) - SetDlgItemText(hdlg, IDC_EDIT_WILLNOTICE, TranslateT("This contact has been absent for an extended period of time.")); + if (isContactGoneFor(m_hContact, options.iAbsencePeriod2)) + SetDlgItemText(m_hwnd, IDC_EDIT_WILLNOTICE, TranslateT("This contact has been absent for an extended period of time.")); else - SetDlgItemText(hdlg, IDC_EDIT_WILLNOTICE, L""); + SetDlgItemText(m_hwnd, IDC_EDIT_WILLNOTICE, L""); - CheckDlgButton(hdlg, IDC_CHECK_MISSYOU, g_plugin.getByte(lparam, "MissYou") ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_NOTIFYALWAYS, g_plugin.getByte(lparam, "MissYouNotifyAlways") ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_NEVERHIDE, g_plugin.getByte(lparam, "NeverHide") ? BST_CHECKED : BST_UNCHECKED); - - TranslateDialogDefault(hdlg); - return TRUE; + CheckDlgButton(m_hwnd, IDC_CHECK_MISSYOU, g_plugin.getByte(m_hContact, "MissYou") ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_CHECK_NOTIFYALWAYS, g_plugin.getByte(m_hContact, "MissYouNotifyAlways") ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_CHECK_NEVERHIDE, g_plugin.getByte(m_hContact, "NeverHide") ? BST_CHECKED : BST_UNCHECKED); + return true; } - case WM_NOTIFY: - switch (((LPNMHDR)lparam)->idFrom) - { - case 0: - switch (((LPNMHDR)lparam)->code) - { - case (PSN_APPLY) : - { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lparam)->lParam; - if (hContact) - { - g_plugin.setDword(hContact, "iAbsencePeriod", GetDlgItemInt(hdlg, IDC_EDITABSENCE, nullptr, FALSE)); - g_plugin.setByte(hContact, "MissYou", (IsDlgButtonChecked(hdlg, IDC_CHECK_MISSYOU) == BST_CHECKED) ? 1 : 0); - g_plugin.setByte(hContact, "MissYouNotifyAlways", (IsDlgButtonChecked(hdlg, IDC_CHECK_NOTIFYALWAYS) == BST_CHECKED) ? 1 : 0); - g_plugin.setByte(hContact, "NeverHide", (IsDlgButtonChecked(hdlg, IDC_CHECK_NEVERHIDE) == BST_CHECKED) ? 1 : 0); - } - break; - } - } - break; + bool OnApply() override + { + if (m_hContact) { + g_plugin.setDword(m_hContact, "iAbsencePeriod", GetDlgItemInt(m_hwnd, IDC_EDITABSENCE, nullptr, FALSE)); + g_plugin.setByte(m_hContact, "MissYou", (IsDlgButtonChecked(m_hwnd, IDC_CHECK_MISSYOU) == BST_CHECKED) ? 1 : 0); + g_plugin.setByte(m_hContact, "MissYouNotifyAlways", (IsDlgButtonChecked(m_hwnd, IDC_CHECK_NOTIFYALWAYS) == BST_CHECKED) ? 1 : 0); + g_plugin.setByte(m_hContact, "NeverHide", (IsDlgButtonChecked(m_hwnd, IDC_CHECK_NEVERHIDE) == BST_CHECKED) ? 1 : 0); } - break; - - case WM_COMMAND: - if (wparam == MAKEWPARAM(IDC_EDITABSENCE, EN_CHANGE)) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - else if (LOWORD(wparam) == IDCANCEL) - SendMessage(GetParent(hdlg), msg, wparam, lparam); - break; + return true; } +}; - return FALSE; -} - -int UserinfoInit(WPARAM wparam, LPARAM lparam) +int UserinfoInit(WPARAM wparam, LPARAM hContact) { - if (lparam > 0) { - OPTIONSDIALOGPAGE uip = { sizeof(uip) }; - uip.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO); + if (hContact > 0) { + USERINFOPAGE uip = {}; uip.szTitle.a = LPGEN("Buddy Expectator"); - uip.pfnDlgProc = UserinfoDlgProc; + uip.pDialog = new UserinfoDlg(); g_plugin.addUserInfo(wparam, &uip); } return 0; diff --git a/plugins/ExternalAPI/m_userinfoex.h b/plugins/ExternalAPI/m_userinfoex.h index 1e263085c5..973c06f3c2 100644 --- a/plugins/ExternalAPI/m_userinfoex.h +++ b/plugins/ExternalAPI/m_userinfoex.h @@ -44,7 +44,6 @@ called this message. Because UserinfoEx now looks for changes in the settings of shown inforamtion up to date. */ #define PSP_CHANGED 2 -#define PSN_ICONCHANGED 2000 /* PSM_GETBOLDFONT v0.1.0.3+ wParam=NULL diff --git a/plugins/FavContacts/src/stdafx.h b/plugins/FavContacts/src/stdafx.h index afe031f56b..ace1a328cf 100644 --- a/plugins/FavContacts/src/stdafx.h +++ b/plugins/FavContacts/src/stdafx.h @@ -39,7 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include -#include +#include #include #include #include diff --git a/plugins/FingerprintNG/src/stdafx.h b/plugins/FingerprintNG/src/stdafx.h index f2a48ade19..6a62fb57e8 100644 --- a/plugins/FingerprintNG/src/stdafx.h +++ b/plugins/FingerprintNG/src/stdafx.h @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include #include diff --git a/plugins/HTTPServer/src/Glob.h b/plugins/HTTPServer/src/Glob.h index 15d5636943..d312715361 100644 --- a/plugins/HTTPServer/src/Glob.h +++ b/plugins/HTTPServer/src/Glob.h @@ -31,7 +31,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/plugins/NewXstatusNotify/src/indsnd.cpp b/plugins/NewXstatusNotify/src/indsnd.cpp index 2cbf75bd2d..d99edfa59a 100644 --- a/plugins/NewXstatusNotify/src/indsnd.cpp +++ b/plugins/NewXstatusNotify/src/indsnd.cpp @@ -21,44 +21,7 @@ #include "stdafx.h" -void PreviewSound(HWND hList) -{ - wchar_t buff[MAX_PATH], stzSoundPath[MAX_PATH]; - - LVITEM lvi = { 0 }; - lvi.mask = LVIF_PARAM; - lvi.iItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED); - ListView_GetItem(hList, &lvi); - - int hlpStatus = lvi.lParam; - - ListView_GetItemText(hList, lvi.iItem, 1, buff, _countof(buff)); - if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND))) { - if (hlpStatus < ID_STATUS_MIN) - Skin_PlaySound(StatusListEx[hlpStatus].lpzSkinSoundName); - else - Skin_PlaySound(StatusList[Index(hlpStatus)].lpzSkinSoundName); - } - else { - PathToAbsoluteW(buff, stzSoundPath); - Skin_PlaySoundFile(stzSoundPath); - } -} - -BOOL RemoveSoundFromList(HWND hList) -{ - int iSel = ListView_GetSelectionMark(hList); - if (iSel != -1) { - iSel = -1; - while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1) - ListView_SetItemText(hList, iSel, 1, TranslateW(DEFAULT_SOUND)); - return TRUE; - } - - return FALSE; -} - -wchar_t *SelectSound(HWND hwndDlg, wchar_t *buff, size_t bufflen) +wchar_t* SelectSound(HWND hwndDlg, wchar_t *buff, size_t bufflen) { OPENFILENAME ofn = { 0 }; @@ -102,186 +65,6 @@ HIMAGELIST GetStatusIconsImgList(char *szProto) return hList; } -INT_PTR CALLBACK DlgProcSoundUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static MCONTACT hContact = NULL; - HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - hContact = lParam; - char *szProto = Proto_GetBaseAccountName(hContact); - - ListView_SetImageList(hList, GetStatusIconsImgList(szProto), LVSIL_SMALL); - ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - - RECT rc = { 0 }; - GetClientRect(hList, &rc); - - LV_COLUMN lvc = { 0 }; - lvc.mask = LVCF_WIDTH | LVCF_TEXT; - lvc.cx = STATUS_COLUMN; - lvc.pszText = TranslateT("Status"); - ListView_InsertColumn(hList, 0, &lvc); - - lvc.cx = rc.right - STATUS_COLUMN - GetSystemMetrics(SM_CXVSCROLL); - lvc.pszText = TranslateT("Sound file"); - ListView_InsertColumn(hList, 1, &lvc); - - if (szProto) { - DBVARIANT dbv; - wchar_t buff[MAX_PATH]; - - for (int i = ID_STATUS_MAX; i >= ID_STATUS_MIN; i--) { - int flags = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_2, 0); - if (flags == 0) - flags = PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT; - - if ((flags & Proto_Status2Flag(i)) || i == ID_STATUS_OFFLINE) { - LV_ITEM lvi = { 0 }; - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; - lvi.iItem = 0; - lvi.iSubItem = 0; - lvi.iImage = Index(i); - lvi.lParam = (LPARAM)i; - lvi.pszText = TranslateW(StatusList[Index(i)].lpzSkinSoundDesc); - lvi.iItem = ListView_InsertItem(hList, &lvi); - - if (!g_plugin.getWString(hContact, StatusList[Index(i)].lpzSkinSoundName, &dbv)) { - mir_wstrcpy(buff, dbv.pwszVal); - db_free(&dbv); - } - else mir_wstrcpy(buff, TranslateW(DEFAULT_SOUND)); - - ListView_SetItemText(hList, lvi.iItem, 1, buff); - } - } - - for (int i = 0; i <= ID_STATUSEX_MAX; i++) { - LV_ITEM lvi = { 0 }; - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; - lvi.iItem = 0; - lvi.iSubItem = 0; - lvi.iImage = Index(ID_STATUS_MAX) + 1; // additional icon - lvi.lParam = (LPARAM)i; - lvi.pszText = TranslateW(StatusListEx[i].lpzSkinSoundDesc); - lvi.iItem = ListView_InsertItem(hList, &lvi); - - if (!g_plugin.getWString(hContact, StatusList[i].lpzSkinSoundName, &dbv)) { - wcsncpy(buff, dbv.pwszVal, _countof(buff)-1); - db_free(&dbv); - } - else wcsncpy(buff, TranslateW(DEFAULT_SOUND), _countof(buff)-1); - - ListView_SetItemText(hList, lvi.iItem, 1, buff); - } - } - - CheckDlgButton(hwndDlg, IDC_CHECK_NOTIFYSOUNDS, g_plugin.getByte(hContact, "EnableSounds", 1) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHECK_NOTIFYPOPUPS, g_plugin.getByte(hContact, "EnablePopups", 1) ? BST_CHECKED : BST_UNCHECKED); - - ShowWindow(GetDlgItem(hwndDlg, IDC_INDSNDLIST), opt.UseIndSnd ? SW_SHOW : SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_TEXT_ENABLE_IS), opt.UseIndSnd ? SW_HIDE : SW_SHOW); - ShowWindow(GetDlgItem(hwndDlg, IDC_CHANGE), opt.UseIndSnd ? SW_SHOW : SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), opt.UseIndSnd ? SW_SHOW : SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_DELETE), opt.UseIndSnd ? SW_SHOW : SW_HIDE); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_PREVIEW: - if (ListView_GetSelectionMark(hList) != -1) - PreviewSound(hList); - break; - case IDC_CHANGE: - { - int iSel = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_INDSNDLIST), -1, LVNI_SELECTED); - if (iSel != -1) { - wchar_t stzFilePath[MAX_PATH]; - if (SelectSound(hwndDlg, stzFilePath, MAX_PATH - 1) != nullptr) { - iSel = -1; - while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1) - ListView_SetItemText(hList, iSel, 1, stzFilePath); - - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - } - } - break; - case IDC_DELETE: - if (ListView_GetSelectionMark(hList) != -1) - if (RemoveSoundFromList(GetDlgItem(hwndDlg, IDC_INDSNDLIST))) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - case IDC_CHECK_NOTIFYSOUNDS: - g_plugin.setByte(hContact, "EnableSounds", IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOTIFYSOUNDS) ? 1 : 0); - break; - case IDC_CHECK_NOTIFYPOPUPS: - g_plugin.setByte(hContact, "EnablePopups", IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOTIFYPOPUPS) ? 1 : 0); - break; - } - break; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->code == PSN_APPLY) { - wchar_t buff[MAX_PATH]; - - LVITEM lvi = { 0 }; - lvi.mask = LVIF_PARAM; - //Cycle through the list reading the text associated to each status. - for (lvi.iItem = ListView_GetItemCount(hList) - 1; lvi.iItem >= 0; lvi.iItem--) { - ListView_GetItem(hList, &lvi); - ListView_GetItemText(hList, lvi.iItem, 1, buff, _countof(buff)); - - if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND))) { - if (lvi.lParam < ID_STATUS_MIN) - g_plugin.delSetting(hContact, StatusListEx[lvi.lParam].lpzSkinSoundName); - else - g_plugin.delSetting(hContact, StatusList[Index(lvi.lParam)].lpzSkinSoundName); - } - else { - wchar_t stzSoundPath[MAX_PATH] = { 0 }; - PathToRelativeW(buff, stzSoundPath); - if (lvi.lParam < ID_STATUS_MIN) - g_plugin.setWString(hContact, StatusListEx[lvi.lParam].lpzSkinSoundName, stzSoundPath); - else - g_plugin.setWString(hContact, StatusList[Index(lvi.lParam)].lpzSkinSoundName, stzSoundPath); - } - } - - return TRUE; - } - - int hlpControlID = (int)wParam; - switch (hlpControlID) { - case IDC_INDSNDLIST: - if (((LPNMHDR)lParam)->code == NM_DBLCLK) { - wchar_t stzFilePath[MAX_PATH]; - if (SelectSound(hwndDlg, stzFilePath, MAX_PATH - 1) != nullptr) { - int iSel = -1; - while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1) - ListView_SetItemText(hList, iSel, 1, stzFilePath); - - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - return TRUE; - } - else if (((LPNMHDR)lParam)->code == LVN_KEYDOWN) { - LPNMLVKEYDOWN pnkd = (LPNMLVKEYDOWN)lParam; - if (pnkd->wVKey == VK_DELETE) - RemoveSoundFromList(GetDlgItem(hwndDlg, IDC_INDSNDLIST)); - } - - break; - } - break; - } - return FALSE; -} - void ResetListOptions(HWND hwndList) { SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | CLS_SHOWHIDDEN); @@ -592,15 +375,240 @@ INT_PTR CALLBACK DlgProcFiltering(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam) return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// +// User info dialog + +class SoundUIPageDlg : public CUserInfoPageDlg +{ + CCtrlCheck chkSounds, chkPopups; + CCtrlButton btnPreview, btnChange, btnDelete; + CCtrlListView m_list; + + void PreviewSound() + { + LVITEM lvi = { 0 }; + lvi.mask = LVIF_PARAM; + lvi.iItem = m_list.GetNextItem(-1, LVNI_SELECTED); + m_list.GetItem(&lvi); + + int hlpStatus = lvi.lParam; + + wchar_t buff[MAX_PATH], stzSoundPath[MAX_PATH]; + m_list.GetItemText(lvi.iItem, 1, buff, _countof(buff)); + if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND))) { + if (hlpStatus < ID_STATUS_MIN) + Skin_PlaySound(StatusListEx[hlpStatus].lpzSkinSoundName); + else + Skin_PlaySound(StatusList[Index(hlpStatus)].lpzSkinSoundName); + } + else { + PathToAbsoluteW(buff, stzSoundPath); + Skin_PlaySoundFile(stzSoundPath); + } + } + + BOOL RemoveSoundFromList() + { + int iSel = m_list.GetSelectionMark(); + if (iSel != -1) { + iSel = -1; + while ((iSel = m_list.GetNextItem(iSel, LVNI_SELECTED)) != -1) + m_list.SetItemText(iSel, 1, TranslateW(DEFAULT_SOUND)); + return TRUE; + } + + return FALSE; + } + +public: + SoundUIPageDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO_SOUNDS), + m_list(this, IDC_INDSNDLIST), + chkPopups(this, IDC_CHECK_NOTIFYPOPUPS), + chkSounds(this, IDC_CHECK_NOTIFYSOUNDS), + btnChange(this, IDC_CHANGE), + btnDelete(this, IDC_DELETE), + btnPreview(this, IDC_PREVIEW) + { + m_list.OnDoubleClick = Callback(this, &SoundUIPageDlg::onDblClick_List); + + chkPopups.OnChange = Callback(this, &SoundUIPageDlg::onChange_Popups); + chkSounds.OnChange = Callback(this, &SoundUIPageDlg::onChange_Sounds); + + btnChange.OnClick = Callback(this, &SoundUIPageDlg::onClick_Change); + btnDelete.OnClick = Callback(this, &SoundUIPageDlg::onClick_Delete); + btnPreview.OnClick = Callback(this, &SoundUIPageDlg::onClick_Preview); + } + + bool OnInitDialog() override + { + char *szProto = Proto_GetBaseAccountName(m_hContact); + + m_list.SetImageList(GetStatusIconsImgList(szProto), LVSIL_SMALL); + m_list.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); + + RECT rc = { 0 }; + GetClientRect(m_list.GetHwnd(), &rc); + + LV_COLUMN lvc = { 0 }; + lvc.mask = LVCF_WIDTH | LVCF_TEXT; + lvc.cx = STATUS_COLUMN; + lvc.pszText = TranslateT("Status"); + m_list.InsertColumn(0, &lvc); + + lvc.cx = rc.right - STATUS_COLUMN - GetSystemMetrics(SM_CXVSCROLL); + lvc.pszText = TranslateT("Sound file"); + m_list.InsertColumn(1, &lvc); + + if (szProto) { + DBVARIANT dbv; + wchar_t buff[MAX_PATH]; + + for (int i = ID_STATUS_MAX; i >= ID_STATUS_MIN; i--) { + int flags = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_2, 0); + if (flags == 0) + flags = PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT; + + if ((flags & Proto_Status2Flag(i)) || i == ID_STATUS_OFFLINE) { + LV_ITEM lvi = { 0 }; + lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; + lvi.iItem = 0; + lvi.iSubItem = 0; + lvi.iImage = Index(i); + lvi.lParam = (LPARAM)i; + lvi.pszText = TranslateW(StatusList[Index(i)].lpzSkinSoundDesc); + lvi.iItem = m_list.InsertItem(&lvi); + + if (!g_plugin.getWString(m_hContact, StatusList[Index(i)].lpzSkinSoundName, &dbv)) { + mir_wstrcpy(buff, dbv.pwszVal); + db_free(&dbv); + } + else mir_wstrcpy(buff, TranslateW(DEFAULT_SOUND)); + + m_list.SetItemText(lvi.iItem, 1, buff); + } + } + + for (int i = 0; i <= ID_STATUSEX_MAX; i++) { + LV_ITEM lvi = { 0 }; + lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; + lvi.iItem = 0; + lvi.iSubItem = 0; + lvi.iImage = Index(ID_STATUS_MAX) + 1; // additional icon + lvi.lParam = (LPARAM)i; + lvi.pszText = TranslateW(StatusListEx[i].lpzSkinSoundDesc); + lvi.iItem = m_list.InsertItem(&lvi); + + if (!g_plugin.getWString(m_hContact, StatusList[i].lpzSkinSoundName, &dbv)) { + wcsncpy(buff, dbv.pwszVal, _countof(buff) - 1); + db_free(&dbv); + } + else wcsncpy(buff, TranslateW(DEFAULT_SOUND), _countof(buff) - 1); + + m_list.SetItemText(lvi.iItem, 1, buff); + } + } + + chkSounds.SetState(g_plugin.getByte(m_hContact, "EnableSounds", 1)); + chkPopups.SetState(g_plugin.getByte(m_hContact, "EnablePopups", 1)); + + ShowWindow(GetDlgItem(m_hwnd, IDC_INDSNDLIST), opt.UseIndSnd ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(m_hwnd, IDC_TEXT_ENABLE_IS), opt.UseIndSnd ? SW_HIDE : SW_SHOW); + ShowWindow(GetDlgItem(m_hwnd, IDC_CHANGE), opt.UseIndSnd ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(m_hwnd, IDC_PREVIEW), opt.UseIndSnd ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(m_hwnd, IDC_DELETE), opt.UseIndSnd ? SW_SHOW : SW_HIDE); + return true; + } + + bool OnApply() override + { + wchar_t buff[MAX_PATH]; + + LVITEM lvi = { 0 }; + lvi.mask = LVIF_PARAM; + //Cycle through the list reading the text associated to each status. + for (lvi.iItem = m_list.GetItemCount() - 1; lvi.iItem >= 0; lvi.iItem--) { + m_list.GetItem(&lvi); + m_list.GetItemText(lvi.iItem, 1, buff, _countof(buff)); + + if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND))) { + if (lvi.lParam < ID_STATUS_MIN) + g_plugin.delSetting(m_hContact, StatusListEx[lvi.lParam].lpzSkinSoundName); + else + g_plugin.delSetting(m_hContact, StatusList[Index(lvi.lParam)].lpzSkinSoundName); + } + else { + wchar_t stzSoundPath[MAX_PATH] = { 0 }; + PathToRelativeW(buff, stzSoundPath); + if (lvi.lParam < ID_STATUS_MIN) + g_plugin.setWString(m_hContact, StatusListEx[lvi.lParam].lpzSkinSoundName, stzSoundPath); + else + g_plugin.setWString(m_hContact, StatusList[Index(lvi.lParam)].lpzSkinSoundName, stzSoundPath); + } + } + + return true; + } + + void onClick_Preview(CCtrlButton*) + { + if (m_list.GetSelectionMark() != -1) + PreviewSound(); + } + + void onClick_Change(CCtrlButton*) + { + int iSel = m_list.GetNextItem(-1, LVNI_SELECTED); + if (iSel != -1) { + wchar_t stzFilePath[MAX_PATH]; + if (SelectSound(m_hwnd, stzFilePath, MAX_PATH - 1) != nullptr) { + iSel = -1; + while ((iSel = m_list.GetNextItem(iSel, LVNI_SELECTED)) != -1) + m_list.SetItemText(iSel, 1, stzFilePath); + + NotifyChange(); + } + } + } + + void onClick_Delete(CCtrlButton*) + { + if (m_list.GetSelectionMark() != -1) + if (RemoveSoundFromList()) + NotifyChange(); + } + + void onChange_Popups(CCtrlCheck*) + { + g_plugin.setByte(m_hContact, "EnableSounds", chkPopups.GetState()); + } + + void onChange_Sounds(CCtrlCheck*) + { + g_plugin.setByte(m_hContact, "EnablePopups", chkSounds.GetState()); + } + + void onDblClick_List(CCtrlListView::TEventInfo*) + { + wchar_t stzFilePath[MAX_PATH]; + if (SelectSound(m_hwnd, stzFilePath, MAX_PATH - 1) != nullptr) { + int iSel = -1; + while ((iSel = m_list.GetNextItem(iSel, LVNI_SELECTED)) != -1) + m_list.SetItemText(iSel, 1, stzFilePath); + + SendMessage(GetParent(m_hwnd), PSM_CHANGED, 0, 0); + } + } +}; + int UserInfoInitialise(WPARAM wParam, LPARAM lParam) { if (lParam) { - OPTIONSDIALOGPAGE odp = {}; - odp.position = 100000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_SOUNDS); - odp.szTitle.a = LPGEN("Status Notify"); - odp.pfnDlgProc = DlgProcSoundUIPage; - g_plugin.addUserInfo(wParam, &odp); + USERINFOPAGE uip = {}; + uip.position = 100000000; + uip.szTitle.a = LPGEN("Status Notify"); + uip.pDialog = new SoundUIPageDlg(); + g_plugin.addUserInfo(wParam, &uip); } return 0; } diff --git a/plugins/QuickContacts/src/stdafx.h b/plugins/QuickContacts/src/stdafx.h index 3f40173ac1..1d5b42e5f5 100644 --- a/plugins/QuickContacts/src/stdafx.h +++ b/plugins/QuickContacts/src/stdafx.h @@ -29,6 +29,7 @@ Boston, MA 02111-1307, USA. #include #include #include +#include #include #include #include diff --git a/plugins/Scriver/src/stdafx.h b/plugins/Scriver/src/stdafx.h index 1f72d10d64..778229d2ca 100644 --- a/plugins/Scriver/src/stdafx.h +++ b/plugins/Scriver/src/stdafx.h @@ -49,6 +49,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include #include diff --git a/plugins/SeenPlugin/src/stdafx.h b/plugins/SeenPlugin/src/stdafx.h index c636358661..9172cce71d 100644 --- a/plugins/SeenPlugin/src/stdafx.h +++ b/plugins/SeenPlugin/src/stdafx.h @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include #include diff --git a/plugins/SeenPlugin/src/userinfo.cpp b/plugins/SeenPlugin/src/userinfo.cpp index 2f2966d25a..1a323a5e11 100644 --- a/plugins/SeenPlugin/src/userinfo.cpp +++ b/plugins/SeenPlugin/src/userinfo.cpp @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -LRESULT CALLBACK EditProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) +static LRESULT CALLBACK EditProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_SETCURSOR: @@ -30,47 +30,43 @@ LRESULT CALLBACK EditProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) return mir_callNextSubclass(hdlg, EditProc, msg, wparam, lparam); } -INT_PTR CALLBACK UserinfoDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) +struct UserinfoDlg : public CUserInfoPageDlg { - switch (msg) { - case WM_INITDIALOG: - mir_subclassWindow(GetDlgItem(hdlg, IDC_INFOTEXT), EditProc); - WindowList_Add(g_pUserInfo, hdlg, lparam); - SendMessage(hdlg, WM_REFRESH_UI, lparam, 0); - break; - - case WM_REFRESH_UI: - { - ptrW szout(g_plugin.getWStringA("UserStamp")); - CMStringW str = ParseString((szout != NULL) ? szout : DEFAULT_USERSTAMP, wparam); - SetDlgItemText(hdlg, IDC_INFOTEXT, str); + UserinfoDlg() : + CUserInfoPageDlg(g_plugin, IDD_USERINFO) + {} - if (!mir_wstrcmp(str, TranslateT(""))) - EnableWindow(GetDlgItem(hdlg, IDC_INFOTEXT), FALSE); - } - break; + bool OnInitDialog() override + { + mir_subclassWindow(GetDlgItem(m_hwnd, IDC_INFOTEXT), EditProc); + WindowList_Add(g_pUserInfo, m_hwnd, m_hContact); + return true; + } - case WM_COMMAND: - if (HIWORD(wparam) == EN_SETFOCUS) - SetFocus(GetParent(hdlg)); - break; + bool OnRefresh() override + { + ptrW szout(g_plugin.getWStringA("UserStamp")); + CMStringW str = ParseString((szout != NULL) ? szout : DEFAULT_USERSTAMP, m_hContact); + SetDlgItemText(m_hwnd, IDC_INFOTEXT, str); - case WM_DESTROY: - WindowList_Remove(g_pUserInfo, hdlg); - break; + if (!mir_wstrcmp(str, TranslateT(""))) + EnableWindow(GetDlgItem(m_hwnd, IDC_INFOTEXT), FALSE); + return false; } - return 0; -} + void OnDestroy() override + { + WindowList_Remove(g_pUserInfo, m_hwnd); + } +}; int UserinfoInit(WPARAM wparam, LPARAM hContact) { char *szProto = Proto_GetBaseAccountName(hContact); if (IsWatchedProtocol(szProto) && !db_get_b(hContact, szProto, "ChatRoom", false)) { - OPTIONSDIALOGPAGE uip = { sizeof(uip) }; - uip.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO); + USERINFOPAGE uip = {}; uip.szTitle.a = LPGEN("Last seen"); - uip.pfnDlgProc = UserinfoDlgProc; + uip.pDialog = new UserinfoDlg(); g_plugin.addUserInfo(wparam, &uip); } return 0; diff --git a/plugins/TabSRMM/src/stdafx.h b/plugins/TabSRMM/src/stdafx.h index 41f5fede3a..8c95d3a86c 100644 --- a/plugins/TabSRMM/src/stdafx.h +++ b/plugins/TabSRMM/src/stdafx.h @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include diff --git a/plugins/UserInfoEx/src/classMAnnivDate.cpp b/plugins/UserInfoEx/src/classMAnnivDate.cpp index b1c4a8f9ee..940ddcda6c 100644 --- a/plugins/UserInfoEx/src/classMAnnivDate.cpp +++ b/plugins/UserInfoEx/src/classMAnnivDate.cpp @@ -588,7 +588,7 @@ int MAnnivDate::DBGetAnniversaryDate(MCONTACT hContact, uint16_t iIndex) // read description mir_snprintf(szStamp, "Anniv%dDesc", iIndex); DBVARIANT dbv; - if (!DB::Setting::GetTString(hContact, USERINFO, szStamp, &dbv)) { + if (!DB::Setting::GetWString(hContact, USERINFO, szStamp, &dbv)) { _strDesc = dbv.pwszVal; db_free(&dbv); } diff --git a/plugins/UserInfoEx/src/classPsTree.cpp b/plugins/UserInfoEx/src/classPsTree.cpp index f4b55fa027..ac023b5b83 100644 --- a/plugins/UserInfoEx/src/classPsTree.cpp +++ b/plugins/UserInfoEx/src/classPsTree.cpp @@ -115,12 +115,12 @@ int CPsTree::AddDummyItem(LPCSTR pszGroup) psh._pszProto = _pPs->pszProto; psh._hImages = _hImages; - OPTIONSDIALOGPAGE odp = {}; - odp.flags = ODPF_UNICODE; - odp.szTitle.w = mir_utf8decodeW(pszGroup); + USERINFOPAGE uip = {}; + uip.flags = ODPF_UNICODE; + uip.szTitle.w = mir_utf8decodeW(pszGroup); auto *p = new CPsTreeItem(); - p->Create(&psh, &odp); + p->Create(&psh, &uip); _pages.insert(p); return _pages.indexOf(&p); @@ -810,21 +810,17 @@ void CPsTree::OnIconsChanged() uint8_t CPsTree::OnInfoChanged() { - PSHNOTIFY pshn; uint8_t bChanged = 0; - pshn.hdr.idFrom = 0; - pshn.hdr.code = PSN_INFOCHANGED; for (auto &it : _pages) { - pshn.hdr.hwndFrom = it->Wnd(); - if (pshn.hdr.hwndFrom != nullptr) { - pshn.lParam = (LPARAM)it->hContact(); - SendMessage(pshn.hdr.hwndFrom, WM_NOTIFY, 0, (LPARAM)&pshn); - if (PSP_CHANGED == GetWindowLongPtr(pshn.hdr.hwndFrom, DWLP_MSGRESULT)) - bChanged |= 1; - else - it->RemoveFlags(PSPF_CHANGED); - } + if (it->Wnd() == nullptr) + continue; + + it->Dialog()->SetContact(it->hContact()); + if (it->Dialog()->OnRefresh()) + bChanged |= 1; + else + it->RemoveFlags(PSPF_CHANGED); } return bChanged; } diff --git a/plugins/UserInfoEx/src/classPsTreeItem.cpp b/plugins/UserInfoEx/src/classPsTreeItem.cpp index 12d3ceef79..914e80da31 100644 --- a/plugins/UserInfoEx/src/classPsTreeItem.cpp +++ b/plugins/UserInfoEx/src/classPsTreeItem.cpp @@ -44,18 +44,7 @@ BOOL CALLBACK BoldGroupTitlesEnumChildren(HWND hWnd, LPARAM lParam) * odp - optiondialogpage structure with the info about the item to add * return: nothing **/ -CPsTreeItem::CPsTreeItem() : _idDlg(NULL), _pTemplate(nullptr), _hInst(nullptr), _pfnDlgProc(nullptr), _hWnd(nullptr), _dwFlags(NULL), - _hItem(nullptr), // handle to the treeview item - _iParent(-1), // index to the parent item - _iImage(-1), // index of treeview item's image - _bState(NULL), // initial state of this treeitem - _pszName(nullptr), // original name, given by plugin (not customized) - _ptszLabel(nullptr), - _pszProto(nullptr), - _pszPrefix(nullptr), - _hContact(NULL), - _iPosition(0), - _initParam(0) +CPsTreeItem::CPsTreeItem() { } @@ -245,7 +234,7 @@ int CPsTreeItem::ItemLabel(const uint8_t bReadDBValue) mir_free(_ptszLabel); // try to get custom label from database - if (!bReadDBValue || DB::Setting::GetTString(0, MODULENAME, GlobalPropertyKey(SET_ITEM_LABEL), &dbv) || (_ptszLabel = dbv.pwszVal) == nullptr) { + if (!bReadDBValue || DB::Setting::GetWString(0, MODULENAME, GlobalPropertyKey(SET_ITEM_LABEL), &dbv) || (_ptszLabel = dbv.pwszVal) == nullptr) { // extract the name LPSTR pszName = mir_strrchr(_pszName, '\\'); if (pszName && pszName[1]) @@ -294,14 +283,14 @@ HICON CPsTreeItem::ProtoIcon() * class: CPsTreeItem * desc: load the icon, add to icolib if required and add to imagelist of treeview * params: hIml - treeview's imagelist to add the icon to - * odp - pointer to OPTIONSDIALOGPAGE providing the information about the icon to load + * odp - pointer to USERINFOPAGE providing the information about the icon to load * hDefaultIcon - default icon to use * return: nothing **/ -int CPsTreeItem::Icon(HIMAGELIST hIml, OPTIONSDIALOGPAGE *odp, uint8_t bInitIconsOnly) +int CPsTreeItem::Icon(HIMAGELIST hIml, USERINFOPAGE *uip, uint8_t bInitIconsOnly) { // check parameter - if (!_pszName || !odp) + if (!_pszName || !uip) return 1; // load the icon if no icolib is installed or creating the required settingname failed @@ -320,16 +309,16 @@ int CPsTreeItem::Icon(HIMAGELIST hIml, OPTIONSDIALOGPAGE *odp, uint8_t bInitIcon sid.section.w = pwszSection; // the item to insert brings along an icon? - if (odp->flags & ODPF_ICON) { + if (uip->flags & ODPF_ICON) { // is it uinfoex item? - if (odp->pPlugin == &g_plugin) { + if (uip->pPlugin == &g_plugin) { // the pszGroup holds the iconfile for items added by uinfoex - sid.defaultFile.w = odp->szGroup.w; + sid.defaultFile.w = uip->szGroup.w; // icon library exists? if (sid.defaultFile.w) - sid.iDefaultIndex = odp->dwInitParam; + sid.iDefaultIndex = uip->dwInitParam; // no valid icon library else { bNeedFree = true; @@ -374,20 +363,20 @@ int CPsTreeItem::Icon(HIMAGELIST hIml, OPTIONSDIALOGPAGE *odp, uint8_t bInitIcon * class: CPsTreeItem * desc: inits the treeitem's attributes * params: pPsh - pointer to the property page's header structure - * odp - OPTIONSDIALOGPAGE structure with the information about the page to add + * odp - USERINFOPAGE structure with the information about the page to add * return: 0 on success, 1 on failure **/ -int CPsTreeItem::Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp) +int CPsTreeItem::Create(CPsHdr* pPsh, USERINFOPAGE *uip) { int err; wchar_t szTitle[ MAXSETTING ]; // check parameter - if (pPsh && odp && PtrIsValid(odp->pPlugin)) { + if (pPsh && uip && PtrIsValid(uip->pPlugin)) { // instance value - _hInst = odp->pPlugin->getInst(); - _dwFlags = odp->flags; - _initParam = odp->dwInitParam; + _hInst = uip->pPlugin->getInst(); + _dwFlags = uip->flags; + _initParam = uip->dwInitParam; // init page owning contact _hContact = pPsh->_hContact; @@ -398,15 +387,15 @@ int CPsTreeItem::Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp) if (pPsh->_dwFlags & PSF_PROTOPAGESONLY) { if (_dwFlags & ODPF_USERINFOTAB) - mir_snwprintf(szTitle, L"%s %d\\%s", odp->szTitle.w, pPsh->_nSubContact+1, odp->szTab.w); + mir_snwprintf(szTitle, L"%s %d\\%s", uip->szTitle.w, pPsh->_nSubContact+1, uip->szGroup.w); else - mir_snwprintf(szTitle, L"%s %d", odp->szTitle.w, pPsh->_nSubContact+1); + mir_snwprintf(szTitle, L"%s %d", uip->szTitle.w, pPsh->_nSubContact+1); } else { if (_dwFlags & ODPF_USERINFOTAB) - mir_snwprintf(szTitle, L"%s\\%s", odp->szTitle.w, odp->szTab.w); + mir_snwprintf(szTitle, L"%s\\%s", uip->szTitle.w, uip->szGroup.w); else - mir_wstrcpy(szTitle, odp->szTitle.w); + mir_wstrcpy(szTitle, uip->szTitle.w); } // set the unique utf8 encoded name for the item if (err = Name(szTitle, (_dwFlags & ODPF_UNICODE) == ODPF_UNICODE)) @@ -415,9 +404,10 @@ int CPsTreeItem::Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp) // read label from database or create it else if (err = ItemLabel(TRUE)) MsgErr(nullptr, LPGENW("Creating the label for a page failed with %d and error code %d"), err, GetLastError()); + else { // load icon for the item - Icon(pPsh->_hImages, odp, (pPsh->_dwFlags & PSTVF_INITICONS) == PSTVF_INITICONS); + Icon(pPsh->_hImages, uip, (pPsh->_dwFlags & PSTVF_INITICONS) == PSTVF_INITICONS); // the rest is not needed if only icons are loaded if (pPsh->_dwFlags & PSTVF_INITICONS) @@ -425,33 +415,16 @@ int CPsTreeItem::Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp) // load custom order if (!(pPsh->_dwFlags & PSTVF_SORTTREE)) { - _iPosition = (int)g_plugin.getByte(PropertyKey(SET_ITEM_POS), odp->position); + _iPosition = g_plugin.getByte(PropertyKey(SET_ITEM_POS), uip->position); if ((_iPosition < 0) || (_iPosition > 0x800000A)) _iPosition = 0; } // read visibility state - _bState = g_plugin.getByte(PropertyKey(SET_ITEM_STATE), DBTVIS_EXPANDED); + _bState = g_plugin.getByte(PropertyKey(SET_ITEM_STATE), DBTVIS_EXPANDED); - // error for no longer supported dialog template type - if (((UINT_PTR)odp->pszTemplate & 0xFFFF0000)) - MsgErr(nullptr, LPGENW("The dialog template type is no longer supported")); - else { - // fetch dialog resource id - _idDlg = (INT_PTR)odp->pszTemplate; - // dialog procedure - _pfnDlgProc = odp->pfnDlgProc; - - // is dummy item? - if (!_idDlg && !_pfnDlgProc) - return 0; - - if (_idDlg && _pfnDlgProc) { - // lock the property pages dialog resource - _pTemplate = (DLGTEMPLATE*)LockResource(LoadResource(_hInst, FindResource(_hInst, (LPCTSTR)(UINT_PTR)_idDlg, RT_DIALOG))); - if (_pTemplate) - return 0; - } - } + // fetch dialog + _pDialog = uip->pDialog; + return 0; } } return 1; @@ -501,20 +474,15 @@ uint16_t CPsTreeItem::DBSaveItemState(LPCSTR pszGroup, int iItemPosition, UINT i **/ HWND CPsTreeItem::CreateWnd(LPPS pPs) { - if (pPs && !_hWnd && _pTemplate && _pfnDlgProc) { - _hWnd = CreateDialogIndirectParam(_hInst, _pTemplate, pPs->hDlg, _pfnDlgProc, (LPARAM)_hContact); + if (pPs && !_hWnd && _pDialog) { + _pDialog->SetParent(pPs->hDlg); + _pDialog->SetContact(_hContact); + _pDialog->Create(); + _hWnd = _pDialog->GetHwnd(); if (_hWnd != nullptr) { - PSHNOTIFY pshn; - pshn.hdr.code = PSN_PARAMCHANGED; - pshn.hdr.hwndFrom = _hWnd; - pshn.hdr.idFrom = 0; - pshn.lParam = (LPARAM)_initParam; - SendMessage(_hWnd, WM_NOTIFY, 0, (LPARAM)&pshn); - // force child window (mainly for AIM property page) SetWindowLongPtr(_hWnd, GWL_STYLE, (GetWindowLongPtr(_hWnd, GWL_STYLE) & ~(WS_POPUP|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME)) | WS_CHILD); SetWindowLongPtr(_hWnd, GWL_EXSTYLE, GetWindowLongPtr(_hWnd, GWL_EXSTYLE) & ~(WS_EX_APPWINDOW|WS_EX_STATICEDGE|WS_EX_CLIENTEDGE)); - SetParent(_hWnd, pPs->hDlg); // move dialog into the display area SetWindowPos(_hWnd, HWND_TOP, @@ -547,15 +515,8 @@ HWND CPsTreeItem::CreateWnd(LPPS pPs) **/ void CPsTreeItem::OnInfoChanged() { - if (_hWnd) { - PSHNOTIFY pshn; - pshn.hdr.code = PSN_INFOCHANGED; - pshn.hdr.hwndFrom = _hWnd; - pshn.hdr.idFrom = 0; - pshn.lParam = (LPARAM)_hContact; - if (PSP_CHANGED != SendMessage(_hWnd, WM_NOTIFY, 0, (LPARAM)&pshn)) - _dwFlags &= ~PSPF_CHANGED; - } + if (_hWnd) + _pDialog->OnRefresh(); } /** @@ -567,13 +528,9 @@ void CPsTreeItem::OnInfoChanged() **/ void CPsTreeItem::OnPageIconsChanged() { - if (_hWnd) { - PSHNOTIFY pshn; - pshn.hdr.code = PSN_ICONCHANGED; - pshn.hdr.hwndFrom = _hWnd; - pshn.hdr.idFrom = 0; - pshn.lParam = (LPARAM)_hContact; - SendMessage(_hWnd, WM_NOTIFY, 0, (LPARAM)&pshn); + if (_hWnd && _initParam) { + auto *pDlg = (PSPBaseDlg *)_pDialog; + pDlg->OnIconsChanged(); } } diff --git a/plugins/UserInfoEx/src/ctrl_combo.cpp b/plugins/UserInfoEx/src/ctrl_combo.cpp index 81d82220f0..512371116a 100644 --- a/plugins/UserInfoEx/src/ctrl_combo.cpp +++ b/plugins/UserInfoEx/src/ctrl_combo.cpp @@ -149,7 +149,7 @@ BOOL CCombo::OnInfoChanged(MCONTACT hContact, LPCSTR pszProto) int iVal = CB_ERR; _Flags.B.hasCustom = _Flags.B.hasProto = _Flags.B.hasMeta = false; - _Flags.W |= DB::Setting::GetTStringCtrl(hContact, USERINFO, USERINFO, pszProto, _pszSetting, &dbv); + _Flags.W |= DB::Setting::GetWStringCtrl(hContact, USERINFO, USERINFO, pszProto, _pszSetting, &dbv); EnableWindow(_hwnd, !hContact || _Flags.B.hasCustom || !g_plugin.getByte(SET_PROPSHEET_PCBIREADONLY, 0)); if (_Flags.B.hasCustom || _Flags.B.hasProto || _Flags.B.hasMeta) { diff --git a/plugins/UserInfoEx/src/ctrl_contact.cpp b/plugins/UserInfoEx/src/ctrl_contact.cpp index 66c153a110..7ce07cdb30 100644 --- a/plugins/UserInfoEx/src/ctrl_contact.cpp +++ b/plugins/UserInfoEx/src/ctrl_contact.cpp @@ -1292,7 +1292,7 @@ int CtrlContactAddItemFromDB( cbi.pszVal = nullptr; cbi.dwID = mir_hashstr(szSettingVal); - cbi.wFlags = CBEXIF_CATREADONLY | DB::Setting::GetTStringCtrl(hContact, pszModule, pszModule, pszProto, szSettingVal, &dbv); + cbi.wFlags = CBEXIF_CATREADONLY | DB::Setting::GetWStringCtrl(hContact, pszModule, pszModule, pszProto, szSettingVal, &dbv); if (dbv.type >= DBVT_WCHAR) { // no value read from database if (cbi.wFlags == CBEXIF_CATREADONLY) @@ -1352,7 +1352,7 @@ int CtrlContactAddMyItemsFromDB( for (i = 0; SUCCEEDED(mir_snprintf(pszSetting, szFormatVal, i)) && - (cbi.wFlags = DB::Setting::GetTStringCtrl(hContact, pszModule, pszModule, pszProto, pszSetting, &dbv)); + (cbi.wFlags = DB::Setting::GetWStringCtrl(hContact, pszModule, pszModule, pszProto, pszSetting, &dbv)); i++) { // read value cbi.dwID = mir_hashstr(pszSetting); @@ -1363,12 +1363,12 @@ int CtrlContactAddMyItemsFromDB( // read category if (SUCCEEDED(mir_snprintf(pszSetting, szFormatCat, i))) { if (cbi.wFlags & CTRLF_HASCUSTOM) { - if (DB::Setting::GetTString(hContact, pszModule, pszSetting, &dbv)) + if (DB::Setting::GetWString(hContact, pszModule, pszSetting, &dbv)) dbv.type = DBVT_DELETED; } else if (cbi.wFlags & CTRLF_HASPROTO) { - if (DB::Setting::GetTString(hContact, pszProto, pszSetting, &dbv)) + if (DB::Setting::GetWString(hContact, pszProto, pszSetting, &dbv)) dbv.type = DBVT_DELETED; } diff --git a/plugins/UserInfoEx/src/ctrl_edit.cpp b/plugins/UserInfoEx/src/ctrl_edit.cpp index fb3b5d9e83..99d8f22b75 100644 --- a/plugins/UserInfoEx/src/ctrl_edit.cpp +++ b/plugins/UserInfoEx/src/ctrl_edit.cpp @@ -111,7 +111,7 @@ BOOL CEditCtrl::OnInfoChanged(MCONTACT hContact, LPCSTR pszProto) wchar_t szText[64]; _Flags.B.hasCustom = _Flags.B.hasProto = _Flags.B.hasMeta = false; - _Flags.W |= DB::Setting::GetTStringCtrl(hContact, _pszModule, _pszModule, pszProto, _pszSetting, &dbv); + _Flags.W |= DB::Setting::GetWStringCtrl(hContact, _pszModule, _pszModule, pszProto, _pszSetting, &dbv); EnableWindow(_hwnd, !hContact || _Flags.B.hasCustom || !g_plugin.getByte(SET_PROPSHEET_PCBIREADONLY, 0)); diff --git a/plugins/UserInfoEx/src/dlg_propsheet.cpp b/plugins/UserInfoEx/src/dlg_propsheet.cpp index 24fb405c45..e254162217 100644 --- a/plugins/UserInfoEx/src/dlg_propsheet.cpp +++ b/plugins/UserInfoEx/src/dlg_propsheet.cpp @@ -304,18 +304,18 @@ static INT_PTR ShowDialog(WPARAM wParam, LPARAM) static INT_PTR AddPage(WPARAM wParam, LPARAM lParam) { CPsHdr *pPsh = (CPsHdr *)wParam; - OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE *)lParam; + USERINFOPAGE *uip = (USERINFOPAGE*)lParam; // check size of the handled structures - if (pPsh == nullptr || odp == nullptr) + if (pPsh == nullptr || uip == nullptr) return 1; // try to check whether the flag member is initialized or not - odp->flags = odp->flags > (ODPF_UNICODE | ODPF_BOLDGROUPS | ODPF_ICON | PSPF_PROTOPREPENDED) ? 0 : odp->flags; + uip->flags = uip->flags > (ODPF_UNICODE | ODPF_BOLDGROUPS | ODPF_ICON | PSPF_PROTOPREPENDED) ? 0 : uip->flags; if (pPsh->_dwFlags & (PSF_PROTOPAGESONLY | PSF_PROTOPAGESONLY_INIT)) { - uint8_t bIsUnicode = (odp->flags & ODPF_UNICODE) == ODPF_UNICODE; - wchar_t *ptszTitle = bIsUnicode ? mir_wstrdup(odp->szTitle.w) : mir_a2u(odp->szTitle.a); + uint8_t bIsUnicode = (uip->flags & ODPF_UNICODE) == ODPF_UNICODE; + wchar_t *ptszTitle = bIsUnicode ? mir_wstrdup(uip->szTitle.w) : mir_a2u(uip->szTitle.a); // avoid adding pages for a meta subcontact, which have been added for a metacontact. if (pPsh->_dwFlags & PSF_PROTOPAGESONLY) { @@ -334,7 +334,7 @@ static INT_PTR AddPage(WPARAM wParam, LPARAM lParam) // create the new tree item CPsTreeItem *pNew = new CPsTreeItem(); if (pNew) { - if (pNew->Create(pPsh, odp)) { + if (pNew->Create(pPsh, uip)) { MIR_DELETE(pNew); return 1; } @@ -384,79 +384,23 @@ static int InitDetails(WPARAM wParam, LPARAM lParam) if (!(pPsh->_dwFlags & PSF_PROTOPAGESONLY)) { uint8_t bChangeDetailsEnabled = myGlobals.CanChangeDetails && g_plugin.getByte(SET_PROPSHEET_CHANGEMYDETAILS, FALSE); if (lParam || bChangeDetailsEnabled) { - OPTIONSDIALOGPAGE odp = {}; - odp.flags = ODPF_ICON | ODPF_UNICODE; - odp.szGroup.w = IcoLib_GetDefaultIconFileName(); - odp.pPlugin = &g_plugin; + USERINFOPAGE uip = {}; + uip.flags = ODPF_ICON | ODPF_UNICODE; + uip.szGroup.w = IcoLib_GetDefaultIconFileName(); + uip.pPlugin = &g_plugin; if (lParam) { // ignore common pages for weather contacts if (!pPsh->_pszProto || _stricmp(pPsh->_pszProto, "weather")) { - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_GENERAL); - odp.position = 0x8000000; - odp.pfnDlgProc = PSPProcGeneral; - odp.dwInitParam = ICONINDEX(IDI_TREE_GENERAL); - odp.szTitle.w = LPGENW("General"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ADDRESS); - odp.position = 0x8000001; - odp.pfnDlgProc = PSPProcContactHome; - odp.dwInitParam = ICONINDEX(IDI_TREE_ADDRESS); - odp.szTitle.w = LPGENW("General") L"\\" LPGENW("Contact (private)"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ORIGIN); - odp.position = 0x8000002; - odp.pfnDlgProc = PSPProcOrigin; - odp.dwInitParam = ICONINDEX(IDI_TREE_ADVANCED); - odp.szTitle.w = LPGENW("General") L"\\" LPGENW("Origin"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ANNIVERSARY); - odp.position = 0x8000003; - odp.pfnDlgProc = PSPProcAnniversary; - odp.dwInitParam = ICONINDEX(IDI_BIRTHDAY); - odp.szTitle.w = LPGENW("General") L"\\" LPGENW("Anniversaries"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_COMPANY); - odp.position = 0x8000004; - odp.pfnDlgProc = PSPProcCompany; - odp.dwInitParam = ICONINDEX(IDI_TREE_COMPANY); - odp.szTitle.w = LPGENW("Work"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ADDRESS); - odp.position = 0x8000005; - odp.pfnDlgProc = PSPProcContactWork; - odp.dwInitParam = ICONINDEX(IDI_TREE_ADDRESS); - odp.szTitle.w = LPGENW("Work") L"\\" LPGENW("Contact (work)"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ABOUT); - odp.position = 0x8000006; - odp.pfnDlgProc = PSPProcAbout; - odp.dwInitParam = ICONINDEX(IDI_TREE_ABOUT); - odp.szTitle.w = LPGENW("About"); - AddPage(wParam, (LPARAM)&odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_PROFILE); - odp.position = 0x8000007; - odp.pfnDlgProc = PSPProcContactProfile; - odp.dwInitParam = ICONINDEX(IDI_TREE_PROFILE); - odp.szTitle.w = LPGENW("About") L"\\" LPGENW("Profile"); - AddPage(wParam, (LPARAM)&odp); - - odp.szTitle.w = LPGENW("About") L"\\" LPGENW("Notes"); + InitGeneralDlg(wParam, uip); + InitContactDlg(wParam, uip); + InitOriginDlg(wParam, uip); + InitAnniversaryDlg(wParam, uip); + InitCompanyDlg(wParam, uip); + InitOriginDlg(wParam, uip, false); + InitProfileDlg(wParam, uip); } - else odp.szTitle.w = LPGENW("Notes"); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ABOUT); - odp.position = 0x8000008; - odp.pfnDlgProc = PSPProcMyNotes; - odp.dwInitParam = ICONINDEX(IDI_TREE_NOTES); - AddPage(wParam, (LPARAM)&odp); + else InitOriginDlg(wParam, uip, true); } } } diff --git a/plugins/UserInfoEx/src/dlg_propsheet.h b/plugins/UserInfoEx/src/dlg_propsheet.h index d8aea78665..615c98102b 100644 --- a/plugins/UserInfoEx/src/dlg_propsheet.h +++ b/plugins/UserInfoEx/src/dlg_propsheet.h @@ -32,28 +32,27 @@ class CPsTree; class CPsTreeItem { - int _idDlg; // resource id of the property page - LPDLGTEMPLATE _pTemplate; // locked template for the property page - HINSTANCE _hInst; // instance handle of the owning plugin dll - DLGPROC _pfnDlgProc; // dialog procedure for the property page - HWND _hWnd; // window handle for the property page if shown jet - uint32_t _dwFlags; // some flags - int _iPosition; // initiating position if custom (used for sorting) - LPARAM _initParam; - MCONTACT _hContact; // contact the page is accociated with (may be a meta subcontact if details dialog is shown for a meta contact) - LPCSTR _pszProto; // protocol the page is accociated with (is the contact's protocol if _hContact is not NULL) - LPCSTR _pszPrefix; // pointer to the dialog owning contact's protocol - - HTREEITEM _hItem; // handle to the treeview item if visible (NULL if this item is hidden) - int _iParent; // index of the owning tree item - int _iImage; // index of treeview item's image - uint8_t _bState; // initial state of this treeitem - LPSTR _pszName; // original name, given by plugin (not customized) - LPTSTR _ptszLabel; // string to setting in db holding information about this treeitem + int _idDlg = 0; // resource id of the property page + HINSTANCE _hInst = 0; // instance handle of the owning plugin dll + CUserInfoPageDlg *_pDialog = 0; // pointer to a page dialog + HWND _hWnd = 0; // window handle for the property page if shown jet + uint32_t _dwFlags = 0; // some flags + int _iPosition = 0; // initiating position if custom (used for sorting) + MCONTACT _hContact = 0; // contact the page is accociated with (may be a meta subcontact if details dialog is shown for a meta contact) + LPCSTR _pszProto = 0; // protocol the page is accociated with (is the contact's protocol if _hContact is not NULL) + LPCSTR _pszPrefix = 0; // pointer to the dialog owning contact's protocol + INT_PTR _initParam = 0; + + HTREEITEM _hItem = 0; // handle to the treeview item if visible (NULL if this item is hidden) + int _iParent = -1; // index of the owning tree item + int _iImage = -1; // index of treeview item's image + uint8_t _bState = 0; // initial state of this treeitem + LPSTR _pszName = 0; // original name, given by plugin (not customized) + LPTSTR _ptszLabel= 0; // string to setting in db holding information about this treeitem LPCSTR GlobalName(); - int Icon(HIMAGELIST hIml, OPTIONSDIALOGPAGE *odp, uint8_t bInitIconsOnly); + int Icon(HIMAGELIST hIml, USERINFOPAGE *uip, uint8_t bInitIconsOnly); int ItemLabel(const uint8_t bReadDBValue); int Name(LPTSTR pszTitle, const uint8_t bIsUnicode); HICON ProtoIcon(); @@ -62,30 +61,31 @@ public: CPsTreeItem(); ~CPsTreeItem(); - int Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp); + int Create(CPsHdr* pPsh, USERINFOPAGE *uip); void Rename(const LPTSTR pszLabel); - __inline LPSTR Name() const { return _pszName; }; - __inline LPCSTR Proto() const { return _pszProto; }; - __inline LPTSTR Label() const { return _ptszLabel; }; - __inline MCONTACT hContact() const { return _hContact; }; + __inline LPSTR Name() const { return _pszName; } + __inline LPCSTR Proto() const { return _pszProto; } + __inline LPTSTR Label() const { return _ptszLabel; } + __inline MCONTACT hContact() const { return _hContact; } - __inline HWND Wnd() const { return _hWnd; }; - __inline int DlgId() const { return _idDlg; }; - __inline HINSTANCE Inst() const { return _hInst; }; + __inline HWND Wnd() const { return _hWnd; } + __inline int DlgId() const { return _idDlg; } + __inline HINSTANCE Inst() const { return _hInst; } + __inline CUserInfoPageDlg* Dialog() const { return _pDialog; } - __inline int Image() const { return _iImage; }; - __inline int Pos() const { return _iPosition; }; - __inline uint8_t State() const { return _bState; }; - __inline HTREEITEM Hti() const { return _hItem; }; - __inline void Hti(HTREEITEM hti) { _hItem = hti; }; - __inline int Parent() const { return _iParent; }; - __inline void Parent(const int iParent) { _iParent = iParent; }; + __inline int Image() const { return _iImage; } + __inline int Pos() const { return _iPosition; } + __inline uint8_t State() const { return _bState; } + __inline HTREEITEM Hti() const { return _hItem; } + __inline void Hti(HTREEITEM hti) { _hItem = hti; } + __inline int Parent() const { return _iParent; } + __inline void Parent(const int iParent) { _iParent = iParent; } - __inline uint32_t Flags() const { return _dwFlags; }; - __inline void Flags(uint32_t dwFlags) { _dwFlags = dwFlags; }; - __inline void AddFlags(uint32_t dwFlags) { _dwFlags |= dwFlags; }; - __inline void RemoveFlags(uint32_t dwFlags) { _dwFlags &= ~dwFlags; }; + __inline uint32_t Flags() const { return _dwFlags; } + __inline void Flags(uint32_t dwFlags) { _dwFlags = dwFlags; } + __inline void AddFlags(uint32_t dwFlags) { _dwFlags |= dwFlags; } + __inline void RemoveFlags(uint32_t dwFlags) { _dwFlags &= ~dwFlags; } uint8_t HasName(const LPCSTR pszName) const; @@ -246,7 +246,7 @@ struct TPropSheet { // dialogs owner MCONTACT hContact; - CHAR pszProto[MAXMODULELABELLENGTH]; + char pszProto[MAXMODULELABELLENGTH]; HANDLE hProtoAckEvent; // eventhook for protocol acks HANDLE hSettingChanged; // eventhook searching for changed contact information diff --git a/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp b/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp index 666fd84b78..773edbab63 100644 --- a/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp +++ b/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp @@ -282,7 +282,7 @@ INT_PTR CALLBACK SelectModulesToExport_DlgProc(HWND hDlg, UINT uMsg, WPARAM wPar case EXIM_GROUP: break; case EXIM_SUBGROUP: - if (mir_wstrncmp(pDat->ExImContact->ptszName, DB::Setting::GetTString(hContact, "CList", "Group"), mir_wstrlen(pDat->ExImContact->ptszName))) { + if (mir_wstrncmp(pDat->ExImContact->ptszName, DB::Setting::GetWString(hContact, "CList", "Group"), mir_wstrlen(pDat->ExImContact->ptszName))) { continue; } break; diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp index 1d008719ad..f4ea0a1e10 100644 --- a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp +++ b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp @@ -152,7 +152,7 @@ int CFileXml::Export(lpExImParam ExImContact, const wchar_t *pszFileName) // dont export meta subcontacts by default and // export only contact with selectet group name if (!db_mc_isSub(hContact) && - mir_wstrncmp(ExImContact->ptszName, DB::Setting::GetTString(hContact, "CList", "Group"), mir_wstrlen(ExImContact->ptszName)) == 0) { + mir_wstrncmp(ExImContact->ptszName, DB::Setting::GetWString(hContact, "CList", "Group"), mir_wstrlen(ExImContact->ptszName)) == 0) { if (vContact.fromDB(hContact)) { vContact.Export(xmlfile, &Modules); } diff --git a/plugins/UserInfoEx/src/mir_db.h b/plugins/UserInfoEx/src/mir_db.h index e00052a450..bfb3faf468 100644 --- a/plugins/UserInfoEx/src/mir_db.h +++ b/plugins/UserInfoEx/src/mir_db.h @@ -29,12 +29,12 @@ namespace DB { **/ namespace Contact { - uint32_t WhenAdded(uint32_t dwUIN, LPCSTR szBaseProto); + uint32_t WhenAdded(uint32_t dwUIN, LPCSTR szBaseProto); } /* namespace Contact */ namespace Module { - bool IsMeta(LPCSTR pszModule); - bool IsMetaAndScan(LPCSTR pszModule); + bool IsMeta(LPCSTR pszModule); + bool IsMetaAndScan(LPCSTR pszModule); } /* namespace Module */ @@ -43,7 +43,7 @@ namespace Module { **/ namespace Setting { - uint8_t Get(MCONTACT hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const uint8_t nType); + uint8_t Get(MCONTACT hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const uint8_t nType); static FORCEINLINE uint8_t GetAsIs(MCONTACT hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) { return Get(hContact, pszModule, pszSetting, dbv, 0); } static FORCEINLINE uint8_t GetAString(MCONTACT hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) @@ -77,11 +77,6 @@ namespace Setting { static FORCEINLINE uint16_t GetUStringCtrl(MCONTACT hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_UTF8); } - #define GetTString GetWString - #define GetTStringEx GetWStringEx - #define GetTStringCtrl GetWStringCtrl - #define WriteTString WriteWString - /** * misc operations **/ diff --git a/plugins/UserInfoEx/src/psp_about.cpp b/plugins/UserInfoEx/src/psp_about.cpp index bacc975bd2..05b14573a0 100644 --- a/plugins/UserInfoEx/src/psp_about.cpp +++ b/plugins/UserInfoEx/src/psp_about.cpp @@ -21,83 +21,84 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -/** - * Dialog procedure for the about/nodes information propertysheetpage - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -INT_PTR CALLBACK PSPProcEdit(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, const CHAR *pszSetting) +struct PSPEditDlg : public PSPBaseDlg { - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) { - HFONT hBoldFont; - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); - - if (!mir_strcmp(pszSetting, SET_CONTACT_MYNOTES)) - SetDlgItemText(hDlg, IDC_PAGETITLE, LPGENW("My notes:")); - else - SetDlgItemText(hDlg, IDC_PAGETITLE, LPGENW("About:")); - - TranslateDialogDefault(hDlg); - - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_ABOUT, pszSetting, DBVT_WCHAR)); - - // remove static edge in aero mode - if (IsAeroMode()) - SetWindowLongPtr(GetDlgItem(hDlg, EDIT_ABOUT), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hDlg, EDIT_ABOUT), GWL_EXSTYLE) & ~WS_EX_STATICEDGE); - - SendDlgItemMessage(hDlg, EDIT_ABOUT, EM_SETEVENTMASK, 0, /*ENM_KEYEVENTS | */ENM_LINK | ENM_CHANGE); - SendDlgItemMessage(hDlg, EDIT_ABOUT, EM_AUTOURLDETECT, TRUE, NULL); - if (!lParam) SendDlgItemMessage(hDlg, EDIT_ABOUT, EM_LIMITTEXT, 1024, NULL); - } - } - break; - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->idFrom) - { + const char *m_szSetting; + + PSPEditDlg(const char *szSetting) : + PSPBaseDlg(IDD_CONTACT_ABOUT), + m_szSetting(szSetting) + {} + + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); + + if (!mir_strcmp(m_szSetting, SET_CONTACT_MYNOTES)) + SetDlgItemText(m_hwnd, IDC_PAGETITLE, TranslateT("My notes:")); + else + SetDlgItemText(m_hwnd, IDC_PAGETITLE, TranslateT("About:")); + + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ABOUT, m_szSetting, DBVT_WCHAR)); + + // remove static edge in aero mode + if (IsAeroMode()) + SetWindowLongPtr(GetDlgItem(m_hwnd, EDIT_ABOUT), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(m_hwnd, EDIT_ABOUT), GWL_EXSTYLE) & ~WS_EX_STATICEDGE); + + SendDlgItemMessage(m_hwnd, EDIT_ABOUT, EM_SETEVENTMASK, 0, /*ENM_KEYEVENTS | */ENM_LINK | ENM_CHANGE); + SendDlgItemMessage(m_hwnd, EDIT_ABOUT, EM_AUTOURLDETECT, TRUE, NULL); + if (!m_hContact) + SendDlgItemMessage(m_hwnd, EDIT_ABOUT, EM_LIMITTEXT, 1024, NULL); + return true; + } + + INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + switch (uMsg) { + case WM_NOTIFY: // notification handler for richedit control + switch (((LPNMHDR)lParam)->idFrom) { case EDIT_ABOUT: - { - switch (((LPNMHDR)lParam)->code) { - - // notification handler for a link within the richedit control - case EN_LINK: - return CEditCtrl::GetObj(((LPNMHDR)lParam)->hwndFrom)->LinkNotificationHandler((ENLINK *)lParam); - } + // notification handler for a link within the richedit control + switch (((LPNMHDR)lParam)->code) { + case EN_LINK: + return CEditCtrl::GetObj(((LPNMHDR)lParam)->hwndFrom)->LinkNotificationHandler((ENLINK *)lParam); } return FALSE; } - } - break; + break; - case WM_COMMAND: - { + case WM_COMMAND: switch (LOWORD(wParam)) { case EDIT_ABOUT: - { - if (HIWORD(wParam) == EN_CHANGE) - { - CBaseCtrl *pResult; - - pResult = CBaseCtrl::GetObj((HWND)lParam); - if (PtrIsValid(pResult) && (pResult->_cbSize == sizeof(CBaseCtrl))) - pResult->OnChangedByUser(HIWORD(wParam)); - } + if (HIWORD(wParam) == EN_CHANGE) { + CBaseCtrl *pResult = CBaseCtrl::GetObj((HWND)lParam); + if (PtrIsValid(pResult) && (pResult->_cbSize == sizeof(CBaseCtrl))) + pResult->OnChangedByUser(HIWORD(wParam)); } } + return FALSE; } - return FALSE; + + return PSPBaseDlg::DlgProc(uMsg, wParam, lParam); } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); +}; + +void InitOriginDlg(WPARAM wParam, USERINFOPAGE &uip, bool bReadOnly) +{ + if (!bReadOnly) { + uip.position = 0x8000006; + uip.pDialog = new PSPEditDlg(SET_CONTACT_ABOUT); + uip.dwInitParam = ICONINDEX(IDI_TREE_ABOUT); + uip.szTitle.w = LPGENW("About"); + g_plugin.addUserInfo(wParam, &uip); + + uip.szTitle.w = LPGENW("About") L"\\" LPGENW("Notes"); + } + else uip.szTitle.w = LPGENW("Notes"); + + uip.position = 0x8000008; + uip.pDialog = new PSPEditDlg(SET_CONTACT_MYNOTES); + uip.dwInitParam = ICONINDEX(IDI_TREE_NOTES); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/psp_anniversary.cpp b/plugins/UserInfoEx/src/psp_anniversary.cpp index a185512b59..5e929ace4e 100644 --- a/plugins/UserInfoEx/src/psp_anniversary.cpp +++ b/plugins/UserInfoEx/src/psp_anniversary.cpp @@ -21,19 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -/** - * Dialog procedure for the anniversary add/edit dialog - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND m_hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - MAnnivDate *pDlgEditAnniv = (MAnnivDate *)GetUserData(hDlg); + MAnnivDate *pDlgEditAnniv = (MAnnivDate *)GetUserData(m_hwnd); switch (uMsg) { case WM_INITDIALOG: @@ -41,23 +31,23 @@ static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND hDlg, UINT uMsg, WPARAM w if (!PtrIsValid(pDlgEditAnniv)) break; - SetUserData(hDlg, lParam); + SetUserData(m_hwnd, lParam); // set icons if (g_plugin.getByte(SET_ICONS_BUTTONS, 1)) { - SendDlgItemMessage(hDlg, IDOK, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_BTN_OK)); - SendDlgItemMessage(hDlg, IDCANCEL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_BTN_CLOSE)); + SendDlgItemMessage(m_hwnd, IDOK, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_BTN_OK)); + SendDlgItemMessage(m_hwnd, IDCANCEL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_BTN_CLOSE)); } - SendDlgItemMessage(hDlg, IDC_HEADERBAR, WM_SETICON, 0, (LPARAM)g_plugin.getIcon(IDI_ANNIVERSARY, true)); + SendDlgItemMessage(m_hwnd, IDC_HEADERBAR, WM_SETICON, 0, (LPARAM)g_plugin.getIcon(IDI_ANNIVERSARY, true)); // translate controls - SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL); - SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL); - TranslateDialogDefault(hDlg); + SendDlgItemMessage(m_hwnd, IDOK, BUTTONTRANSLATE, NULL, NULL); + SendDlgItemMessage(m_hwnd, IDCANCEL, BUTTONTRANSLATE, NULL, NULL); + TranslateDialogDefault(m_hwnd); // init controls - EnableWindow(GetDlgItem(hDlg, EDIT_CATEGORY), pDlgEditAnniv->Id() != ANID_BIRTHDAY); - SetDlgItemText(hDlg, EDIT_CATEGORY, pDlgEditAnniv->Description()); + EnableWindow(GetDlgItem(m_hwnd, EDIT_CATEGORY), pDlgEditAnniv->Id() != ANID_BIRTHDAY); + SetDlgItemText(m_hwnd, EDIT_CATEGORY, pDlgEditAnniv->Description()); return TRUE; case WM_CTLCOLORSTATIC: @@ -68,13 +58,13 @@ static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND hDlg, UINT uMsg, WPARAM w switch (LOWORD(wParam)) { case EDIT_CATEGORY: if (HIWORD(wParam) == EN_UPDATE) - EnableWindow(GetDlgItem(hDlg, IDOK), GetWindowTextLength((HWND)lParam) > 0); + EnableWindow(GetDlgItem(m_hwnd, IDOK), GetWindowTextLength((HWND)lParam) > 0); break; case IDOK: { // read new description - HWND hEdit = GetDlgItem(hDlg, EDIT_CATEGORY); + HWND hEdit = GetDlgItem(m_hwnd, EDIT_CATEGORY); int len = Edit_GetTextLength(hEdit); LPTSTR pszText; @@ -82,7 +72,7 @@ static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND hDlg, UINT uMsg, WPARAM w || (pszText = (LPTSTR)_alloca((len + 1) * sizeof(wchar_t))) == nullptr || !Edit_GetText(hEdit, pszText, len + 1)) { - MsgErr(hDlg, LPGENW("Please enter a valid description first!")); + MsgErr(m_hwnd, LPGENW("Please enter a valid description first!")); break; } @@ -94,167 +84,162 @@ static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND hDlg, UINT uMsg, WPARAM w __fallthrough; case IDCANCEL: - return EndDialog(hDlg, LOWORD(wParam)); + return EndDialog(m_hwnd, LOWORD(wParam)); } } return FALSE; } -/** -* Dialog procedure for the anniversary propertysheetpage -* -* @param hDlg - handle to the dialog window -* @param uMsg - the message to handle -* @param wParam - parameter -* @param lParam - parameter -* -* @return different values -**/ - -INT_PTR CALLBACK PSPProcAnniversary(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// + +struct PSPAnniversaryDlg : public PSPBaseDlg { - CAnnivEditCtrl *pDateCtrl = CAnnivEditCtrl::GetObj(hDlg, EDIT_ANNIVERSARY_DATE); + PSPAnniversaryDlg() : + PSPBaseDlg(IDD_CONTACT_ANNIVERSARY) + {} - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) { - HFONT hBoldFont; - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); - TranslateDialogDefault(hDlg); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_AGE, SET_CONTACT_AGE, DBVT_BYTE)); + m_ctrlList->insert(CAnnivEditCtrl::CreateObj(m_hwnd, EDIT_ANNIVERSARY_DATE, nullptr)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_AGE, SET_CONTACT_AGE, DBVT_BYTE)); - pCtrlList->insert(CAnnivEditCtrl::CreateObj(hDlg, EDIT_ANNIVERSARY_DATE, nullptr)); + // hContact == NULL or reminder disabled + CAnnivEditCtrl::GetObj(m_hwnd, EDIT_ANNIVERSARY_DATE)->EnableReminderCtrl(m_hContact != NULL); - // hContact == NULL or reminder disabled - CAnnivEditCtrl::GetObj(hDlg, EDIT_ANNIVERSARY_DATE)->EnableReminderCtrl(lParam != NULL); + SendDlgItemMessage(m_hwnd, EDIT_AGE, EM_LIMITTEXT, 3, 0); + SendDlgItemMessage(m_hwnd, SPIN_AGE, UDM_SETRANGE32, 0, 200); + return true; + } - SendDlgItemMessage(hDlg, EDIT_AGE, EM_LIMITTEXT, 3, 0); - SendDlgItemMessage(hDlg, SPIN_AGE, UDM_SETRANGE32, 0, 200); - } - } - break; + void OnIconsChanged() override + { + const ICONCTRL idIcon[] = { + { IDI_BIRTHDAY, STM_SETIMAGE, ICO_BIRTHDAY }, + { IDI_BTN_ADD, BM_SETIMAGE, BTN_ADD }, + { IDI_BTN_DELETE, BM_SETIMAGE, BTN_DELETE } + }; + IcoLib_SetCtrlIcons(m_hwnd, idIcon, _countof(idIcon)); + } - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: + INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + CAnnivEditCtrl *pDateCtrl = CAnnivEditCtrl::GetObj(m_hwnd, EDIT_ANNIVERSARY_DATE); + + switch(LOWORD(wParam)) { + case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { - case PSN_ICONCHANGED: - { - const ICONCTRL idIcon[] = { - { IDI_BIRTHDAY, STM_SETIMAGE, ICO_BIRTHDAY }, - { IDI_BTN_ADD, BM_SETIMAGE, BTN_ADD }, - { IDI_BTN_DELETE, BM_SETIMAGE, BTN_DELETE } - }; - IcoLib_SetCtrlIcons(hDlg, idIcon, _countof(idIcon)); + case EDIT_ANNIVERSARY_DATE: + if (!PspIsLocked(m_hwnd) && PtrIsValid(pDateCtrl)) { + LPNMHDR lpNmhdr = (LPNMHDR)lParam; + switch (lpNmhdr->code) { + case DTN_DATETIMECHANGE: + pDateCtrl->OnDateChanged((LPNMDATETIMECHANGE)lParam); + break; + case DTN_DROPDOWN: + HWND hMonthCal = DateTime_GetMonthCal(lpNmhdr->hwndFrom); + SetWindowLongPtr(hMonthCal, GWL_STYLE, GetWindowLongPtr(hMonthCal, GWL_STYLE) | MCS_WEEKNUMBERS); + InvalidateRect(hMonthCal, nullptr, TRUE); + } } return FALSE; } - break; /* case 0 */ - - case EDIT_ANNIVERSARY_DATE: - if (!PspIsLocked(hDlg) && PtrIsValid(pDateCtrl)) { - LPNMHDR lpNmhdr = (LPNMHDR)lParam; - switch (lpNmhdr->code) { - case DTN_DATETIMECHANGE: - pDateCtrl->OnDateChanged((LPNMDATETIMECHANGE)lParam); - break; - case DTN_DROPDOWN: - HWND hMonthCal = DateTime_GetMonthCal(lpNmhdr->hwndFrom); - SetWindowLongPtr(hMonthCal, GWL_STYLE, GetWindowLongPtr(hMonthCal, GWL_STYLE) | MCS_WEEKNUMBERS); - InvalidateRect(hMonthCal, nullptr, TRUE); + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case EDIT_REMIND: + if (!PspIsLocked(m_hwnd) && HIWORD(wParam) == EN_UPDATE) + if (PtrIsValid(pDateCtrl)) + pDateCtrl->OnRemindEditChanged(); + return FALSE; + + /** + * name: BTN_MENU + * desc: the button to dropdown the list to show all items is pressed + **/ + case BTN_MENU: + if (HIWORD(wParam) == BN_CLICKED) { + if (PtrIsValid(pDateCtrl)) + pDateCtrl->OnMenuPopup(); } - } - return FALSE; - } - break; + return FALSE; - case WM_COMMAND: - switch (LOWORD(wParam)) { - case EDIT_REMIND: - if (!PspIsLocked(hDlg) && HIWORD(wParam) == EN_UPDATE) - if (PtrIsValid(pDateCtrl)) - pDateCtrl->OnRemindEditChanged(); - return FALSE; - - /** - * name: BTN_MENU - * desc: the button to dropdown the list to show all items is pressed - **/ - case BTN_MENU: - if (HIWORD(wParam) == BN_CLICKED) { - if (PtrIsValid(pDateCtrl)) - pDateCtrl->OnMenuPopup(); - } - return FALSE; - - /** - * name: BTN_ADD - * desc: creates a new dialog to add a new anniversary - **/ - case BTN_ADD: - if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) { - MAnnivDate Date; - if (IDOK == DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ANNIVERSARY_EDITOR), hDlg, DlgProc_AnniversaryEditor, (LPARAM)&Date)) { - SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL); - if (!pDateCtrl->AddDate(Date)) - pDateCtrl->SetCurSel(pDateCtrl->NumDates() - 1); + /** + * name: BTN_ADD + * desc: creates a new dialog to add a new anniversary + **/ + case BTN_ADD: + if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) { + MAnnivDate Date; + if (IDOK == DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ANNIVERSARY_EDITOR), m_hwnd, DlgProc_AnniversaryEditor, (LPARAM)&Date)) { + SendMessage(GetParent(m_hwnd), PSM_CHANGED, NULL, NULL); + if (!pDateCtrl->AddDate(Date)) + pDateCtrl->SetCurSel(pDateCtrl->NumDates() - 1); + } } - } - return FALSE; - - /** - * name: BTN_EDIT - * desc: edit the currently selected anniversary - **/ - case BTN_EDIT: - if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) { - MAnnivDate *pDate = pDateCtrl->Current(); - if (!pDate) - MsgErr(hDlg, LPGENW("No valid date selected for editing!")); - else if ( - IDOK == DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ANNIVERSARY_EDITOR), hDlg, DlgProc_AnniversaryEditor, (LPARAM)pDate) && - (pDate->Flags() & (MAnnivDate::MADF_CHANGED | MAnnivDate::MADF_REMINDER_CHANGED))) - { - SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL); - pDateCtrl->SetCurSel(pDateCtrl->CurrentIndex()); + return FALSE; + + /** + * name: BTN_EDIT + * desc: edit the currently selected anniversary + **/ + case BTN_EDIT: + if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) { + MAnnivDate *pDate = pDateCtrl->Current(); + if (!pDate) + MsgErr(m_hwnd, LPGENW("No valid date selected for editing!")); + else if ( + IDOK == DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ANNIVERSARY_EDITOR), m_hwnd, DlgProc_AnniversaryEditor, (LPARAM)pDate) && + (pDate->Flags() & (MAnnivDate::MADF_CHANGED | MAnnivDate::MADF_REMINDER_CHANGED))) + { + SendMessage(GetParent(m_hwnd), PSM_CHANGED, NULL, NULL); + pDateCtrl->SetCurSel(pDateCtrl->CurrentIndex()); + } } - } - return FALSE; - - /** - * name: BTN_DELETE - * desc: user wants to delete an anniversary - **/ - case BTN_DELETE: - if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) { - MAnnivDate *pCurrent = pDateCtrl->Current(); - if (pCurrent) { - int rc = MsgBox(hDlg, MB_YESNO | MB_ICON_QUESTION | MB_NOPOPUP, LPGENW("Delete"), nullptr, - LPGENW("Do you really want to delete the %s?"), pCurrent->Description()); - - if (rc == IDYES) - pDateCtrl->DeleteDate(pDateCtrl->CurrentIndex()); + return FALSE; + + /** + * name: BTN_DELETE + * desc: user wants to delete an anniversary + **/ + case BTN_DELETE: + if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) { + MAnnivDate *pCurrent = pDateCtrl->Current(); + if (pCurrent) { + int rc = MsgBox(m_hwnd, MB_YESNO | MB_ICON_QUESTION | MB_NOPOPUP, LPGENW("Delete"), nullptr, + LPGENW("Do you really want to delete the %s?"), pCurrent->Description()); + + if (rc == IDYES) + pDateCtrl->DeleteDate(pDateCtrl->CurrentIndex()); + } } + return FALSE; + + /** + * name: CHECK_REMIND + * desc: state of reminder checkbox is changed + **/ + case RADIO_REMIND1: + case RADIO_REMIND2: + case RADIO_REMIND3: + if (PtrIsValid(pDateCtrl) && HIWORD(wParam) == BN_CLICKED) + pDateCtrl->OnReminderChecked(); + return FALSE; } - return FALSE; - - /** - * name: CHECK_REMIND - * desc: state of reminder checkbox is changed - **/ - case RADIO_REMIND1: - case RADIO_REMIND2: - case RADIO_REMIND3: - if (PtrIsValid(pDateCtrl) && HIWORD(wParam) == BN_CLICKED) - pDateCtrl->OnReminderChecked(); - return FALSE; - } /* switch (LOWORD(wParam)) */ - break; + } + + return PSPBaseDlg::DlgProc(uMsg, wParam, lParam); } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); +}; + +void InitAnniversaryDlg(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.position = 0x8000003; + uip.pDialog = new PSPAnniversaryDlg(); + uip.dwInitParam = ICONINDEX(IDI_BIRTHDAY); + uip.szTitle.w = LPGENW("General") L"\\" LPGENW("Anniversaries"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/psp_base.cpp b/plugins/UserInfoEx/src/psp_base.cpp index d8d07bd9ea..0737807bcc 100644 --- a/plugins/UserInfoEx/src/psp_base.cpp +++ b/plugins/UserInfoEx/src/psp_base.cpp @@ -29,64 +29,76 @@ void UpDate_CountryIcon(HWND hCtrl, int countryID) IcoLib_ReleaseIcon(hOld); } +PSPBaseDlg::PSPBaseDlg(int idDialog) : + CUserInfoPageDlg(g_plugin, idDialog), + m_ctrlList(nullptr) +{ +} + +bool PSPBaseDlg::OnInitDialog() +{ + m_ctrlList = CCtrlList::CreateObj(m_hwnd); + + HFONT hBoldFont; + PSGetBoldFont(m_hwnd, hBoldFont); + SendDlgItemMessage(m_hwnd, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); + return true; +} + +void PSPBaseDlg::OnDestroy() +{ + m_ctrlList->Release(); +} + // Default dialog procedure, which handles common functions -INT_PTR CALLBACK PSPBaseProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR PSPBaseDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { - CCtrlList *pCtrlList; - - pCtrlList = CCtrlList::GetObj(hDlg); - if (PtrIsValid(pCtrlList)) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - - // set propertysheet page's background white in aero mode - case WM_CTLCOLORSTATIC: - case WM_CTLCOLORDLG: - if (IsAeroMode()) - return (INT_PTR)GetStockBrush(WHITE_BRUSH); - break; + switch (uMsg) { + // set propertysheet page's background white in aero mode + case WM_CTLCOLORSTATIC: + case WM_CTLCOLORDLG: + if (IsAeroMode()) + return (INT_PTR)GetStockBrush(WHITE_BRUSH); + break; + + // Set text color of edit boxes according to the source of information they display. + case WM_CTLCOLOREDIT: + if (m_ctrlList) + return m_ctrlList->OnSetTextColour((HWND)lParam, (HDC)wParam); + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->idFrom) { + case 0: + MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; + LPSTR pszProto; + + switch (((LPNMHDR)lParam)->code) { + case PSN_RESET: + m_ctrlList->OnReset(); + break; - // Set text color of edit boxes according to the source of information they display. - case WM_CTLCOLOREDIT: - return pCtrlList->OnSetTextColour((HWND)lParam, (HDC)wParam); - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - LPSTR pszProto; - - switch (((LPNMHDR)lParam)->code) { - case PSN_RESET: - pCtrlList->OnReset(); - break; - - case PSN_INFOCHANGED: - if (PSGetBaseProto(hDlg, pszProto) && *pszProto) { - BOOL bChanged = (GetWindowLongPtr(hDlg, DWLP_MSGRESULT)&PSP_CHANGED) | pCtrlList->OnInfoChanged(hContact, pszProto); - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bChanged ? PSP_CHANGED : 0); - } - break; - - case PSN_APPLY: - if (PSGetBaseProto(hDlg, pszProto) && *pszProto) - pCtrlList->OnApply(hContact, pszProto); - break; + case PSN_INFOCHANGED: + if (PSGetBaseProto(m_hwnd, pszProto) && *pszProto) { + BOOL bChanged = (GetWindowLongPtr(m_hwnd, DWLP_MSGRESULT)&PSP_CHANGED) | m_ctrlList->OnInfoChanged(hContact, pszProto); + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, bChanged ? PSP_CHANGED : 0); } break; - } - break; - case WM_COMMAND: - if (!PspIsLocked(hDlg)) - pCtrlList->OnChangedByUser(LOWORD(wParam), HIWORD(wParam)); + case PSN_APPLY: + if (PSGetBaseProto(m_hwnd, pszProto) && *pszProto) + m_ctrlList->OnApply(hContact, pszProto); + break; + } break; - - case WM_DESTROY: - // destroy all control objects and the list - pCtrlList->Release(); } + break; + + case WM_COMMAND: + if (m_ctrlList && !PspIsLocked(m_hwnd)) + m_ctrlList->OnChangedByUser(LOWORD(wParam), HIWORD(wParam)); + break; } - return 0; + + return CUserInfoPageDlg::DlgProc(uMsg, wParam, lParam); } diff --git a/plugins/UserInfoEx/src/psp_base.h b/plugins/UserInfoEx/src/psp_base.h index 6f8702b99f..55c4529120 100644 --- a/plugins/UserInfoEx/src/psp_base.h +++ b/plugins/UserInfoEx/src/psp_base.h @@ -22,20 +22,35 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _UI_PSP_BASE_INCLUDE_ #define _UI_PSP_BASE_INCLUDE_ -INT_PTR CALLBACK PSPBaseProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - -INT_PTR CALLBACK PSPProcAnniversary(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcCompany(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcContactHome(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcContactProfile(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcContactWork(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcGeneral(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcOrigin(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK PSPProcEdit(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, const CHAR* pszSetting); -static FORCEINLINE INT_PTR CALLBACK PSPProcMyNotes(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ return PSPProcEdit(hDlg, uMsg, wParam, lParam, SET_CONTACT_MYNOTES); } -static FORCEINLINE INT_PTR CALLBACK PSPProcAbout(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ return PSPProcEdit(hDlg, uMsg, wParam, lParam, SET_CONTACT_ABOUT); } +///////////////////////////////////////////////////////////////////////////////////////// +// Base page dialog class + +class PSPBaseDlg : public CUserInfoPageDlg +{ + friend class CPsTreeItem; + +protected: + CCtrlList *m_ctrlList; + + PSPBaseDlg(int idDialog); + + virtual void OnIconsChanged() {} + + bool OnInitDialog() override; + void OnDestroy() override; + + INT_PTR DlgProc(UINT uMsg, WPARAM, LPARAM) override; +}; + +///////////////////////////////////////////////////////////////////////////////////////// + +void InitGeneralDlg(WPARAM wParam, USERINFOPAGE &uip); +void InitContactDlg(WPARAM wParam, USERINFOPAGE &uip); +void InitOriginDlg(WPARAM wParam, USERINFOPAGE &uip); +void InitCompanyDlg(WPARAM wParam, USERINFOPAGE &uip); +void InitAnniversaryDlg(WPARAM wParam, USERINFOPAGE &uip); +void InitOriginDlg(WPARAM wParam, USERINFOPAGE &uip, bool bReadOnly); +void InitProfileDlg(WPARAM wParam, USERINFOPAGE &uip); void UpDate_CountryIcon(HWND hCtrl, int countryID); diff --git a/plugins/UserInfoEx/src/psp_company.cpp b/plugins/UserInfoEx/src/psp_company.cpp index 06328e885f..d55e01db2b 100644 --- a/plugins/UserInfoEx/src/psp_company.cpp +++ b/plugins/UserInfoEx/src/psp_company.cpp @@ -21,42 +21,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -/** - * Dialog procedure for the company contact information propertysheetpage - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -INT_PTR CALLBACK PSPProcCompany(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +struct PSPCompanyDlg : public PSPBaseDlg { - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) { - LPIDSTRLIST pList; - UINT nList; - HFONT hBoldFont; - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); - - TranslateDialogDefault(hDlg); - - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_COMPANY, SET_CONTACT_COMPANY, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_DEPARTMENT, SET_CONTACT_COMPANY_DEPARTMENT, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_OFFICE, SET_CONTACT_COMPANY_OFFICE, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_POSITION, SET_CONTACT_COMPANY_POSITION, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_SUPERIOR, SET_CONTACT_COMPANY_SUPERIOR, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_ASSISTENT, SET_CONTACT_COMPANY_ASSISTENT, DBVT_WCHAR)); - - GetOccupationList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_OCCUPATION, SET_CONTACT_COMPANY_OCCUPATION, DBVT_WORD, pList, nList)); - } - } + PSPCompanyDlg() : + PSPBaseDlg(IDD_CONTACT_COMPANY) + {} + + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); + + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_COMPANY, SET_CONTACT_COMPANY, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_DEPARTMENT, SET_CONTACT_COMPANY_DEPARTMENT, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_OFFICE, SET_CONTACT_COMPANY_OFFICE, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_POSITION, SET_CONTACT_COMPANY_POSITION, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_SUPERIOR, SET_CONTACT_COMPANY_SUPERIOR, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ASSISTENT, SET_CONTACT_COMPANY_ASSISTENT, DBVT_WCHAR)); + + UINT nList; + LPIDSTRLIST pList; + GetOccupationList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_OCCUPATION, SET_CONTACT_COMPANY_OCCUPATION, DBVT_WORD, pList, nList)); + return true; } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); +}; + +void InitCompanyDlg(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.position = 0x8000004; + uip.pDialog = new PSPCompanyDlg(); + uip.dwInitParam = ICONINDEX(IDI_TREE_COMPANY); + uip.szTitle.w = LPGENW("Work"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/psp_contact.cpp b/plugins/UserInfoEx/src/psp_contact.cpp index f4e8b4ef65..5088972e12 100644 --- a/plugins/UserInfoEx/src/psp_contact.cpp +++ b/plugins/UserInfoEx/src/psp_contact.cpp @@ -21,291 +21,260 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -/** - * Dialog procedure for the home contact information propertysheetpage - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -INT_PTR CALLBACK PSPProcContactHome(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// +// Home contact info + +struct PSPContactHomeDlg : public PSPBaseDlg { - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) { - wchar_t szAddr[MAX_PATH]; - LPIDSTRLIST pList; - UINT nList; - - HFONT hBoldFont; - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); - - mir_snwprintf(szAddr, L"%s (%s)", TranslateT("Address"), TranslateT("home")); - SetDlgItemText(hDlg, IDC_PAGETITLE, szAddr); - SendDlgItemMessage(hDlg, BTN_GOTO, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR); - TranslateDialogDefault(hDlg); - - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_STREET, SET_CONTACT_STREET, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_CITY, SET_CONTACT_CITY, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_ZIP, SET_CONTACT_ZIP, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_STATE, SET_CONTACT_STATE, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_HOMEPAGE, SET_CONTACT_HOMEPAGE, DBVT_WCHAR)); - - GetCountryList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_COUNTRY, SET_CONTACT_COUNTRY, DBVT_WORD, pList, nList)); + PSPContactHomeDlg() : + PSPBaseDlg(IDD_CONTACT_ADDRESS) + {} + + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); + + wchar_t szAddr[MAX_PATH]; + mir_snwprintf(szAddr, L"%s (%s)", TranslateT("Address"), TranslateT("home")); + SetDlgItemText(m_hwnd, IDC_PAGETITLE, szAddr); + + SendDlgItemMessage(m_hwnd, BTN_GOTO, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR); + + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STREET, SET_CONTACT_STREET, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_CITY, SET_CONTACT_CITY, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ZIP, SET_CONTACT_ZIP, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STATE, SET_CONTACT_STATE, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_HOMEPAGE, SET_CONTACT_HOMEPAGE, DBVT_WCHAR)); + + UINT nList; + LPIDSTRLIST pList; + GetCountryList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_COUNTRY, SET_CONTACT_COUNTRY, DBVT_WORD, pList, nList)); + return true; + } - break; - } - } - return FALSE; - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - LPCSTR pszProto; - HWND hCtrl; - - switch (((LPNMHDR)lParam)->code) { - case PSN_INFOCHANGED: - { - uint8_t bChanged = 0; - - if (!PSGetBaseProto(hDlg, pszProto) || *pszProto == 0) - break; - - // phone numbers - hCtrl = GetDlgItem(hDlg, EDIT_PHONE); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_PHONE, TranslateT(SET_CONTACT_PHONE), hContact, USERINFO, pszProto, SET_CONTACT_PHONE); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_FAX, TranslateT(SET_CONTACT_FAX), hContact, USERINFO, pszProto, SET_CONTACT_FAX); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_CELLULAR, TranslateT(SET_CONTACT_CELLULAR), hContact, USERINFO, pszProto, SET_CONTACT_CELLULAR); - bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_CUSTOMPHONE, 0, hContact, USERINFO, pszProto, SET_CONTACT_MYPHONE_CAT, SET_CONTACT_MYPHONE_VAL); - SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); - - // emails - hCtrl = GetDlgItem(hDlg, EDIT_EMAIL); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Primary e-mail"), hContact, USERINFO, pszProto, SET_CONTACT_EMAIL); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Secondary e-mail"), hContact, USERINFO, pszProto, SET_CONTACT_EMAIL0); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Tertiary e-mail"), hContact, USERINFO, pszProto, SET_CONTACT_EMAIL1); - bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_EMAIL, 0, hContact, USERINFO, pszProto, SET_CONTACT_MYEMAIL_CAT, SET_CONTACT_MYEMAIL_VAL); - SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bChanged ? PSP_CHANGED : 0); - } - break; - - case PSN_APPLY: - { - if (!PSGetBaseProto(hDlg, pszProto) || *pszProto == 0) - break; - - hCtrl = GetDlgItem(hDlg, EDIT_PHONE); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_PHONE); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_FAX); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_CELLULAR); - CtrlContactWriteMyItemsToDB(hCtrl, 3, hContact, USERINFO, pszProto, SET_CONTACT_MYPHONE_CAT, SET_CONTACT_MYPHONE_VAL); - SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); - - hCtrl = GetDlgItem(hDlg, EDIT_EMAIL); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_EMAIL); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_EMAIL0); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_EMAIL1); - CtrlContactWriteMyItemsToDB(hCtrl, 3, hContact, USERINFO, pszProto, SET_CONTACT_MYEMAIL_CAT, SET_CONTACT_MYEMAIL_VAL); - SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); - } - break; - - case PSN_ICONCHANGED: - { - HICON hIcon = g_plugin.getIcon(IDI_BTN_GOTO); - SendDlgItemMessage(hDlg, BTN_GOTO, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); - SetDlgItemText(hDlg, BTN_GOTO, hIcon ? L"" : L"->"); - - hIcon = g_plugin.getIcon(IDI_TREE_ADDRESS); - SendDlgItemMessage(hDlg, ICO_ADDRESS, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); - ShowWindow(GetDlgItem(hDlg, ICO_ADDRESS), hIcon ? SW_SHOW : SW_HIDE); - - SendDlgItemMessage(hDlg, EDIT_PHONE, WM_SETICON, NULL, NULL); - SendDlgItemMessage(hDlg, EDIT_EMAIL, WM_SETICON, NULL, NULL); - } - break; - } - } - } - } - break; + bool OnRefresh() override + { + LPCSTR pszProto; + if (!PSGetBaseProto(m_hwnd, pszProto) || *pszProto == 0) + return false; + + uint8_t bChanged = 0; + + // phone numbers + HWND hCtrl = GetDlgItem(m_hwnd, EDIT_PHONE); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_PHONE, TranslateT(SET_CONTACT_PHONE), m_hContact, USERINFO, pszProto, SET_CONTACT_PHONE); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_FAX, TranslateT(SET_CONTACT_FAX), m_hContact, USERINFO, pszProto, SET_CONTACT_FAX); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_CELLULAR, TranslateT(SET_CONTACT_CELLULAR), m_hContact, USERINFO, pszProto, SET_CONTACT_CELLULAR); + bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_CUSTOMPHONE, 0, m_hContact, USERINFO, pszProto, SET_CONTACT_MYPHONE_CAT, SET_CONTACT_MYPHONE_VAL); + SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); + + // emails + hCtrl = GetDlgItem(m_hwnd, EDIT_EMAIL); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Primary e-mail"), m_hContact, USERINFO, pszProto, SET_CONTACT_EMAIL); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Secondary e-mail"), m_hContact, USERINFO, pszProto, SET_CONTACT_EMAIL0); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Tertiary e-mail"), m_hContact, USERINFO, pszProto, SET_CONTACT_EMAIL1); + bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_EMAIL, 0, m_hContact, USERINFO, pszProto, SET_CONTACT_MYEMAIL_CAT, SET_CONTACT_MYEMAIL_VAL); + SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); + return bChanged != 0; + } - case WM_COMMAND: - { + bool OnApply() override + { + LPCSTR pszProto; + if (!PSGetBaseProto(m_hwnd, pszProto) || *pszProto == 0) + return false; + + HWND hCtrl = GetDlgItem(m_hwnd, EDIT_PHONE); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_PHONE); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_FAX); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_CELLULAR); + CtrlContactWriteMyItemsToDB(hCtrl, 3, m_hContact, USERINFO, pszProto, SET_CONTACT_MYPHONE_CAT, SET_CONTACT_MYPHONE_VAL); + SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); + + hCtrl = GetDlgItem(m_hwnd, EDIT_EMAIL); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_EMAIL); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_EMAIL0); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_EMAIL1); + CtrlContactWriteMyItemsToDB(hCtrl, 3, m_hContact, USERINFO, pszProto, SET_CONTACT_MYEMAIL_CAT, SET_CONTACT_MYEMAIL_VAL); + SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); + return true; + } + + void OnIconsChanged() override + { + HICON hIcon = g_plugin.getIcon(IDI_BTN_GOTO); + SendDlgItemMessage(m_hwnd, BTN_GOTO, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetDlgItemText(m_hwnd, BTN_GOTO, hIcon ? L"" : L"->"); + + hIcon = g_plugin.getIcon(IDI_TREE_ADDRESS); + SendDlgItemMessage(m_hwnd, ICO_ADDRESS, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + ShowWindow(GetDlgItem(m_hwnd, ICO_ADDRESS), hIcon ? SW_SHOW : SW_HIDE); + + SendDlgItemMessage(m_hwnd, EDIT_PHONE, WM_SETICON, NULL, NULL); + SendDlgItemMessage(m_hwnd, EDIT_EMAIL, WM_SETICON, NULL, NULL); + } + + INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + if (uMsg == WM_COMMAND) { switch (LOWORD(wParam)) { case EDIT_HOMEPAGE: if (HIWORD(wParam) == EN_UPDATE) - EnableWindow(GetDlgItem(hDlg, BTN_GOTO), GetWindowTextLength((HWND)lParam) > 0); + EnableWindow(GetDlgItem(m_hwnd, BTN_GOTO), GetWindowTextLength((HWND)lParam) > 0); break; case BTN_GOTO: - CEditCtrl::GetObj(hDlg, EDIT_HOMEPAGE)->OpenUrl(); + CEditCtrl::GetObj(m_hwnd, EDIT_HOMEPAGE)->OpenUrl(); break; case EDIT_COUNTRY: if (HIWORD(wParam) == CBN_SELCHANGE) { LPIDSTRLIST pd = (LPIDSTRLIST)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); - UpDate_CountryIcon(GetDlgItem(hDlg, ICO_COUNTRY), pd->nID); + UpDate_CountryIcon(GetDlgItem(m_hwnd, ICO_COUNTRY), pd->nID); } break; } } + + return PSPBaseDlg::DlgProc(uMsg, wParam, lParam); } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); -} +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Work contact info -/** - * Dialog procedure for the company's contact information propertysheetpage - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -INT_PTR CALLBACK PSPProcContactWork(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +struct PSPContactWorkDlg : public PSPBaseDlg { - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) - { - wchar_t szAddr[MAX_PATH]; - LPIDSTRLIST pList; - UINT nList; - - HFONT hBoldFont; - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); - - mir_snwprintf(szAddr, L"%s (%s)", TranslateT("Address and contact"), TranslateT("company")); - SetDlgItemText(hDlg, IDC_PAGETITLE, szAddr); - SendDlgItemMessage(hDlg, BTN_GOTO, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR); - TranslateDialogDefault(hDlg); - - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_STREET, SET_CONTACT_COMPANY_STREET, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_CITY, SET_CONTACT_COMPANY_CITY, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_ZIP, SET_CONTACT_COMPANY_ZIP, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_STATE, SET_CONTACT_COMPANY_STATE, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_HOMEPAGE, SET_CONTACT_COMPANY_HOMEPAGE, DBVT_WCHAR)); - - GetCountryList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_COUNTRY, SET_CONTACT_COMPANY_COUNTRY, DBVT_WORD, pList, nList)); - } - } - break; - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - LPCSTR pszProto; - HWND hCtrl; - - switch (((LPNMHDR)lParam)->code) { - case PSN_INFOCHANGED: - { - uint8_t bChanged = 0; - - if (!PSGetBaseProto(hDlg, pszProto) || *pszProto == 0) - break; - - // phone numbers - hCtrl = GetDlgItem(hDlg, EDIT_PHONE); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_PHONE, TranslateT(SET_CONTACT_PHONE), hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_PHONE); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_FAX, TranslateT(SET_CONTACT_FAX), hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_FAX); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_CELLULAR, TranslateT(SET_CONTACT_CELLULAR), hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_CELLULAR); - bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_CUSTOMPHONE, 0, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYPHONE_CAT, SET_CONTACT_COMPANY_MYPHONE_VAL); - SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); - - // emails - hCtrl = GetDlgItem(hDlg, EDIT_EMAIL); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Primary e-mail"), hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Secondary e-mail"), hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL0); - bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Tertiary e-mail"), hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL1); - bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_EMAIL, 0, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYEMAIL_CAT, SET_CONTACT_COMPANY_MYEMAIL_VAL); - SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bChanged ? PSP_CHANGED : 0); - } - break; - - case PSN_APPLY: - { - if (!PSGetBaseProto(hDlg, pszProto) || *pszProto == 0) - break; - - hCtrl = GetDlgItem(hDlg, EDIT_PHONE); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_PHONE); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_FAX); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_CELLULAR); - CtrlContactWriteMyItemsToDB(hCtrl, 3, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYPHONE_CAT, SET_CONTACT_COMPANY_MYPHONE_VAL); - SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); - - hCtrl = GetDlgItem(hDlg, EDIT_EMAIL); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL0); - CtrlContactWriteItemToDB(hCtrl, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL1); - CtrlContactWriteMyItemsToDB(hCtrl, 3, hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYEMAIL_CAT, SET_CONTACT_COMPANY_MYEMAIL_VAL); - SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); - } - break; - - case PSN_ICONCHANGED: - { - HICON hIcon = g_plugin.getIcon(IDI_BTN_GOTO); - SendDlgItemMessage(hDlg, BTN_GOTO, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); - SetDlgItemText(hDlg, BTN_GOTO, hIcon ? L"" : L"->"); - - hIcon = g_plugin.getIcon(IDI_TREE_ADDRESS); - SendDlgItemMessage(hDlg, ICO_ADDRESS, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); - ShowWindow(GetDlgItem(hDlg, ICO_ADDRESS), hIcon ? SW_SHOW : SW_HIDE); - - SendDlgItemMessage(hDlg, EDIT_PHONE, WM_SETICON, NULL, NULL); - SendDlgItemMessage(hDlg, EDIT_EMAIL, WM_SETICON, NULL, NULL); - } - break; - } - } - } - } - break; + PSPContactWorkDlg() : + PSPBaseDlg(IDD_CONTACT_ADDRESS) + {} + + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); + + wchar_t szAddr[MAX_PATH]; + mir_snwprintf(szAddr, L"%s (%s)", TranslateT("Address and contact"), TranslateT("company")); + SetDlgItemText(m_hwnd, IDC_PAGETITLE, szAddr); + SendDlgItemMessage(m_hwnd, BTN_GOTO, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR); + TranslateDialogDefault(m_hwnd); + + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STREET, SET_CONTACT_COMPANY_STREET, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_CITY, SET_CONTACT_COMPANY_CITY, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ZIP, SET_CONTACT_COMPANY_ZIP, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STATE, SET_CONTACT_COMPANY_STATE, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_HOMEPAGE, SET_CONTACT_COMPANY_HOMEPAGE, DBVT_WCHAR)); + + UINT nList; + LPIDSTRLIST pList; + GetCountryList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_COUNTRY, SET_CONTACT_COMPANY_COUNTRY, DBVT_WORD, pList, nList)); + return true; + } + + bool OnApply() override + { + LPCSTR pszProto; + if (!PSGetBaseProto(m_hwnd, pszProto) || *pszProto == 0) + return false; + + HWND hCtrl = GetDlgItem(m_hwnd, EDIT_PHONE); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_PHONE); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_FAX); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_CELLULAR); + CtrlContactWriteMyItemsToDB(hCtrl, 3, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYPHONE_CAT, SET_CONTACT_COMPANY_MYPHONE_VAL); + SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); + + hCtrl = GetDlgItem(m_hwnd, EDIT_EMAIL); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL0); + CtrlContactWriteItemToDB(hCtrl, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL1); + CtrlContactWriteMyItemsToDB(hCtrl, 3, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYEMAIL_CAT, SET_CONTACT_COMPANY_MYEMAIL_VAL); + SendMessage(hCtrl, CBEXM_RESETCHANGED, NULL, NULL); + return true; + } - case WM_COMMAND: - { + bool OnRefresh() override + { + LPCSTR pszProto; + if (!PSGetBaseProto(m_hwnd, pszProto) || *pszProto == 0) + return false; + + uint8_t bChanged = 0; + + // phone numbers + HWND hCtrl = GetDlgItem(m_hwnd, EDIT_PHONE); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_PHONE, TranslateT(SET_CONTACT_PHONE), m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_PHONE); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_FAX, TranslateT(SET_CONTACT_FAX), m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_FAX); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_CELLULAR, TranslateT(SET_CONTACT_CELLULAR), m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_CELLULAR); + bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_CUSTOMPHONE, 0, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYPHONE_CAT, SET_CONTACT_COMPANY_MYPHONE_VAL); + SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); + + // emails + hCtrl = GetDlgItem(m_hwnd, EDIT_EMAIL); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Primary e-mail"), m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Secondary e-mail"), m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL0); + bChanged |= CtrlContactAddItemFromDB(hCtrl, IDI_BTN_EMAIL, TranslateT("Tertiary e-mail"), m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_EMAIL1); + bChanged |= CtrlContactAddMyItemsFromDB(hCtrl, IDI_BTN_EMAIL, 0, m_hContact, USERINFO, pszProto, SET_CONTACT_COMPANY_MYEMAIL_CAT, SET_CONTACT_COMPANY_MYEMAIL_VAL); + SendMessage(hCtrl, CBEXM_SETCURSEL, (WPARAM)-1, TRUE); + return bChanged != 0; + } + + void OnIconsChanged() override + { + HICON hIcon = g_plugin.getIcon(IDI_BTN_GOTO); + SendDlgItemMessage(m_hwnd, BTN_GOTO, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetDlgItemText(m_hwnd, BTN_GOTO, hIcon ? L"" : L"->"); + + hIcon = g_plugin.getIcon(IDI_TREE_ADDRESS); + SendDlgItemMessage(m_hwnd, ICO_ADDRESS, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + ShowWindow(GetDlgItem(m_hwnd, ICO_ADDRESS), hIcon ? SW_SHOW : SW_HIDE); + + SendDlgItemMessage(m_hwnd, EDIT_PHONE, WM_SETICON, NULL, NULL); + SendDlgItemMessage(m_hwnd, EDIT_EMAIL, WM_SETICON, NULL, NULL); + } + + INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + if (uMsg == WM_COMMAND) { switch (LOWORD(wParam)) { case EDIT_HOMEPAGE: if (HIWORD(wParam) == EN_UPDATE) - EnableWindow(GetDlgItem(hDlg, BTN_GOTO), GetWindowTextLength((HWND)lParam) > 0); + EnableWindow(GetDlgItem(m_hwnd, BTN_GOTO), GetWindowTextLength((HWND)lParam) > 0); break; case BTN_GOTO: - CEditCtrl::GetObj(hDlg, EDIT_HOMEPAGE)->OpenUrl(); + CEditCtrl::GetObj(m_hwnd, EDIT_HOMEPAGE)->OpenUrl(); break; case EDIT_COUNTRY: if (HIWORD(wParam) == CBN_SELCHANGE) { LPIDSTRLIST pd = (LPIDSTRLIST)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); - UpDate_CountryIcon(GetDlgItem(hDlg, ICO_COUNTRY), pd->nID); + UpDate_CountryIcon(GetDlgItem(m_hwnd, ICO_COUNTRY), pd->nID); } break; } } + + return PSPBaseDlg::DlgProc(uMsg, wParam, lParam); } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Module entry point + +void InitContactDlg(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.position = 0x8000001; + uip.pDialog = new PSPContactHomeDlg(); + uip.dwInitParam = ICONINDEX(IDI_TREE_ADDRESS); + uip.szTitle.w = LPGENW("General") L"\\" LPGENW("Contact (private)"); + g_plugin.addUserInfo(wParam, &uip); + + uip.position = 0x8000005; + uip.pDialog = new PSPContactWorkDlg(); + uip.dwInitParam = ICONINDEX(IDI_TREE_ADDRESS); + uip.szTitle.w = LPGENW("Work") L"\\" LPGENW("Contact (work)"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/psp_general.cpp b/plugins/UserInfoEx/src/psp_general.cpp index 05c8d229fd..44c8576d85 100644 --- a/plugins/UserInfoEx/src/psp_general.cpp +++ b/plugins/UserInfoEx/src/psp_general.cpp @@ -21,162 +21,96 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -/** - * Dialog procedure for the contact information propertysheetpage - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -INT_PTR CALLBACK PSPProcGeneral(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +struct PSPGeneralDlg : public PSPBaseDlg { - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) { - LPIDSTRLIST pList; - UINT nList; - HFONT hBoldFont; - - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); - TranslateDialogDefault(hDlg); - - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_TITLE, SET_CONTACT_TITLE, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_FIRSTNAME, SET_CONTACT_FIRSTNAME, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_SECONDNAME, SET_CONTACT_SECONDNAME, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_LASTNAME, SET_CONTACT_LASTNAME, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_NICK, SET_CONTACT_NICK, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_DISPLAYNAME, "CList", SET_CONTACT_MYHANDLE, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_PARTNER, SET_CONTACT_PARTNER, DBVT_WCHAR)); - - GetNamePrefixList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_PREFIX, SET_CONTACT_PREFIX, DBVT_BYTE, pList, nList)); - - // marital groupbox - GetMaritalList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_MARITAL, SET_CONTACT_MARITAL, DBVT_BYTE, pList, nList)); - - GetLanguageList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_LANG1, SET_CONTACT_LANG1, DBVT_WCHAR, pList, nList)); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_LANG2, SET_CONTACT_LANG2, DBVT_WCHAR, pList, nList)); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_LANG3, SET_CONTACT_LANG3, DBVT_WCHAR, pList, nList)); - } - } - break; - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - char* pszProto; - - switch (((LPNMHDR)lParam)->code) { - case PSN_INFOCHANGED: - { - uint8_t bEnable; - DBVARIANT dbv; - CCtrlFlags Flags; - - if (PSGetBaseProto(hDlg, pszProto) && *pszProto) { - Flags.W = DB::Setting::GetTStringCtrl(hContact, USERINFO, USERINFO, pszProto, SET_CONTACT_GENDER, &dbv); - if (Flags.B.hasCustom || Flags.B.hasProto || Flags.B.hasMeta) { - if (dbv.type == DBVT_BYTE) { - CheckDlgButton(hDlg, RADIO_FEMALE, (dbv.bVal == 'F') ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, RADIO_MALE, (dbv.bVal == 'M') ? BST_CHECKED : BST_UNCHECKED); - - bEnable = !hContact || Flags.B.hasCustom || !g_plugin.getByte(SET_PROPSHEET_PCBIREADONLY, 0); - EnableWindow(GetDlgItem(hDlg, RADIO_FEMALE), bEnable); - EnableWindow(GetDlgItem(hDlg, RADIO_MALE), bEnable); - } - else - db_free(&dbv); - } - } - } - break; - - case PSN_APPLY: - { - if (!PSGetBaseProto(hDlg, pszProto) || *pszProto == 0) - break; - - // gender - { - uint8_t gender - = IsDlgButtonChecked(hDlg, RADIO_FEMALE) - ? 'F' - : IsDlgButtonChecked(hDlg, RADIO_MALE) - ? 'M' - : 0; - - if (gender) - db_set_b(hContact, hContact ? USERINFO : pszProto, SET_CONTACT_GENDER, gender); - else - db_unset(hContact, hContact ? USERINFO : pszProto, SET_CONTACT_GENDER); - } - } - break; - - case PSN_ICONCHANGED: - { - const ICONCTRL idIcon[] = { - { IDI_FEMALE, STM_SETIMAGE, ICO_FEMALE }, - { IDI_MALE, STM_SETIMAGE, ICO_MALE }, - { IDI_MARITAL, STM_SETIMAGE, ICO_MARITAL }, - }; - IcoLib_SetCtrlIcons(hDlg, idIcon, _countof(idIcon)); - } - } - } - } - } - break; - - case WM_COMMAND: - { - MCONTACT hContact; - LPCSTR pszProto; - - switch (LOWORD(wParam)) { - case RADIO_FEMALE: - { - if (!PspIsLocked(hDlg) && HIWORD(wParam) == BN_CLICKED) { - DBVARIANT dbv; - - PSGetContact(hDlg, hContact); - PSGetBaseProto(hDlg, pszProto); - - if (!DB::Setting::GetAsIsCtrl(hContact, USERINFO, USERINFO, pszProto, SET_CONTACT_GENDER, &dbv) - || dbv.type != DBVT_BYTE - || (dbv.bVal != 'F' && SendMessage((HWND)lParam, BM_GETCHECK, NULL, NULL))) - SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL); - } - } - break; - - case RADIO_MALE: - { - if (!PspIsLocked(hDlg) && HIWORD(wParam) == BN_CLICKED) { - DBVARIANT dbv; + PSPGeneralDlg() : + PSPBaseDlg(IDD_CONTACT_GENERAL) + { + } - PSGetContact(hDlg, hContact); - PSGetBaseProto(hDlg, pszProto); + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); + + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_TITLE, SET_CONTACT_TITLE, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_FIRSTNAME, SET_CONTACT_FIRSTNAME, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_SECONDNAME, SET_CONTACT_SECONDNAME, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_LASTNAME, SET_CONTACT_LASTNAME, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_NICK, SET_CONTACT_NICK, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_DISPLAYNAME, "CList", SET_CONTACT_MYHANDLE, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_PARTNER, SET_CONTACT_PARTNER, DBVT_WCHAR)); + + UINT nList; + LPIDSTRLIST pList; + GetNamePrefixList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_PREFIX, SET_CONTACT_PREFIX, DBVT_BYTE, pList, nList)); + + // marital groupbox + GetMaritalList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_MARITAL, SET_CONTACT_MARITAL, DBVT_BYTE, pList, nList)); + + GetLanguageList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_LANG1, SET_CONTACT_LANG1, DBVT_WCHAR, pList, nList)); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_LANG2, SET_CONTACT_LANG2, DBVT_WCHAR, pList, nList)); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_LANG3, SET_CONTACT_LANG3, DBVT_WCHAR, pList, nList)); + return true; + } - if (!DB::Setting::GetAsIsCtrl(hContact, USERINFO, USERINFO, pszProto, SET_CONTACT_GENDER, &dbv) - || dbv.type != DBVT_BYTE - || (dbv.bVal != 'M' && SendMessage((HWND)lParam, BM_GETCHECK, NULL, NULL))) - SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL); - } + bool OnRefresh() override + { + char *pszProto; + if (PSGetBaseProto(m_hwnd, pszProto) && *pszProto) { + DBVARIANT dbv; + CCtrlFlags Flags; + Flags.W = DB::Setting::GetWStringCtrl(m_hContact, USERINFO, USERINFO, pszProto, SET_CONTACT_GENDER, &dbv); + if (Flags.B.hasCustom || Flags.B.hasProto || Flags.B.hasMeta) { + if (dbv.type == DBVT_BYTE) { + CheckDlgButton(m_hwnd, RADIO_FEMALE, (dbv.bVal == 'F') ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, RADIO_MALE, (dbv.bVal == 'M') ? BST_CHECKED : BST_UNCHECKED); + + bool bEnable = !m_hContact || Flags.B.hasCustom || !g_plugin.getByte(SET_PROPSHEET_PCBIREADONLY, 0); + EnableWindow(GetDlgItem(m_hwnd, RADIO_FEMALE), bEnable); + EnableWindow(GetDlgItem(m_hwnd, RADIO_MALE), bEnable); } + else db_free(&dbv); } } + return false; + } + + bool OnApply() override + { + char *pszProto; + if (!PSGetBaseProto(m_hwnd, pszProto) || *pszProto == 0) + return false; + + // gender + uint8_t gender = IsDlgButtonChecked(m_hwnd, RADIO_FEMALE) ? 'F' : + IsDlgButtonChecked(m_hwnd, RADIO_MALE) ? 'M' : 0; + + if (gender) + db_set_b(m_hContact, m_hContact ? USERINFO : pszProto, SET_CONTACT_GENDER, gender); + else + db_unset(m_hContact, m_hContact ? USERINFO : pszProto, SET_CONTACT_GENDER); + return true; } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); + + void OnIconsChanged() override + { + const ICONCTRL idIcon[] = { + { IDI_FEMALE, STM_SETIMAGE, ICO_FEMALE }, + { IDI_MALE, STM_SETIMAGE, ICO_MALE }, + { IDI_MARITAL, STM_SETIMAGE, ICO_MARITAL }, + }; + IcoLib_SetCtrlIcons(m_hwnd, idIcon, _countof(idIcon)); + } +}; + +void InitGeneralDlg(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.position = 0x8000000; + uip.pDialog = new PSPGeneralDlg(); + uip.dwInitParam = ICONINDEX(IDI_TREE_GENERAL); + uip.szTitle.w = LPGENW("General"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/psp_origin.cpp b/plugins/UserInfoEx/src/psp_origin.cpp index c10d4c0fc0..78b85cc707 100644 --- a/plugins/UserInfoEx/src/psp_origin.cpp +++ b/plugins/UserInfoEx/src/psp_origin.cpp @@ -21,126 +21,109 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -/** - * This is the dialog procedure for the advanced contact information propertysheetpage. - * - * @param hDlg - handle to the dialog window - * @param uMsg - the message to handle - * @param wParam - parameter - * @param lParam - parameter - * - * @return different values - **/ -INT_PTR CALLBACK PSPProcOrigin(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +class PSPOriginDlg : public PSPBaseDlg { - switch (uMsg) { - case WM_INITDIALOG: - { - CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg); - if (pCtrlList) { - LPIDSTRLIST pList; - UINT nList; - - HFONT hBoldFont; - PSGetBoldFont(hDlg, hBoldFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0); - - TranslateDialogDefault(hDlg); - SetTimer(hDlg, 1, 5000, nullptr); - - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_STREET, SET_CONTACT_ORIGIN_STREET, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_ZIP, SET_CONTACT_ORIGIN_ZIP, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_CITY, SET_CONTACT_ORIGIN_CITY, DBVT_WCHAR)); - pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_STATE, SET_CONTACT_ORIGIN_STATE, DBVT_WCHAR)); - - GetCountryList(&nList, &pList); - pCtrlList->insert(CCombo::CreateObj(hDlg, EDIT_COUNTRY, SET_CONTACT_ORIGIN_COUNTRY, DBVT_WORD, pList, nList)); - - pCtrlList->insert(CTzCombo::CreateObj(hDlg, EDIT_TIMEZONE, nullptr)); - } + CTimer timer; + +public: + PSPOriginDlg() : + PSPBaseDlg(IDD_CONTACT_ORIGIN), + timer(this, 1) + { + timer.OnEvent = Callback(this, &PSPOriginDlg::onTimer); + } + + bool OnInitDialog() override + { + PSPBaseDlg::OnInitDialog(); + + timer.Start(5000); + + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STREET, SET_CONTACT_ORIGIN_STREET, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ZIP, SET_CONTACT_ORIGIN_ZIP, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_CITY, SET_CONTACT_ORIGIN_CITY, DBVT_WCHAR)); + m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STATE, SET_CONTACT_ORIGIN_STATE, DBVT_WCHAR)); + + UINT nList; + LPIDSTRLIST pList; + GetCountryList(&nList, &pList); + m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_COUNTRY, SET_CONTACT_ORIGIN_COUNTRY, DBVT_WORD, pList, nList)); + + m_ctrlList->insert(CTzCombo::CreateObj(m_hwnd, EDIT_TIMEZONE, nullptr)); + return true; + } + + bool OnRefresh() override + { + LPCSTR pszProto; + if (!PSGetBaseProto(m_hwnd, pszProto) || *pszProto == 0) + return false; + + if (!m_hContact) + return false; + + MTime mt; + if (mt.DBGetStamp(m_hContact, USERINFO, SET_CONTACT_ADDEDTIME) && strstr(pszProto, "ICQ")) { + uint32_t dwStamp; + + dwStamp = DB::Contact::WhenAdded(db_get_dw(m_hContact, pszProto, "UIN", 0), pszProto); + if (dwStamp > 0) + mt.FromStampAsUTC(dwStamp); } - break; - - case WM_NOTIFY: - { - switch (((LPNMHDR) lParam)->idFrom) { - case 0: - { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - LPCSTR pszProto; - - switch (((LPNMHDR) lParam)->code) { - case PSN_INFOCHANGED: - { - if (!PSGetBaseProto(hDlg, pszProto) || *pszProto == 0) - break; - - if (hContact) { - MTime mt; - - if (mt.DBGetStamp(hContact, USERINFO, SET_CONTACT_ADDEDTIME) && strstr(pszProto, "ICQ")) { - uint32_t dwStamp; - - dwStamp = DB::Contact::WhenAdded(db_get_dw(hContact, pszProto, "UIN", 0), pszProto); - if (dwStamp > 0) - mt.FromStampAsUTC(dwStamp); - } - if (mt.IsValid()) { - wchar_t szTime[MAX_PATH]; - LPTSTR ptr; - - mt.UTCToLocal(); - mt.DateFormatLong(szTime, _countof(szTime)); - - mir_wstrcat(szTime, L" - "); - ptr = szTime + mir_wstrlen(szTime); - mt.TimeFormat(ptr, _countof(szTime) - (ptr - szTime)); - SetDlgItemText(hDlg, TXT_DATEADDED, szTime); - } - } - - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0); - } - break; - - case PSN_ICONCHANGED: - { - const ICONCTRL idIcon[] = { - { IDI_TREE_ADDRESS, STM_SETIMAGE, ICO_ADDRESS }, - { IDI_CLOCK, STM_SETIMAGE, ICO_CLOCK }, - }; - - IcoLib_SetCtrlIcons(hDlg, idIcon, _countof(idIcon)); - } - } - } - } /* switch (((LPNMHDR)lParam)->idFrom) */ + if (mt.IsValid()) { + wchar_t szTime[MAX_PATH]; + LPTSTR ptr; + + mt.UTCToLocal(); + mt.DateFormatLong(szTime, _countof(szTime)); + + mir_wstrcat(szTime, L" - "); + ptr = szTime + mir_wstrlen(szTime); + mt.TimeFormat(ptr, _countof(szTime) - (ptr - szTime)); + SetDlgItemText(m_hwnd, TXT_DATEADDED, szTime); } - break; + return false; + } + + void OnIconsChanged() override + { + const ICONCTRL idIcon[] = { + { IDI_TREE_ADDRESS, STM_SETIMAGE, ICO_ADDRESS }, + { IDI_CLOCK, STM_SETIMAGE, ICO_CLOCK }, + }; + + IcoLib_SetCtrlIcons(m_hwnd, idIcon, _countof(idIcon)); + } - case WM_COMMAND: - { + void onTimer(CTimer *) + { + wchar_t szTime[32]; + CTzCombo::GetObj(m_hwnd, EDIT_TIMEZONE)->GetTime(szTime, _countof(szTime)); + SetDlgItemText(m_hwnd, TXT_TIME, szTime); + } + + INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + if (uMsg == WM_COMMAND) { switch (LOWORD(wParam)) { case EDIT_COUNTRY: if (HIWORD(wParam) == CBN_SELCHANGE) { LPIDSTRLIST pd = (LPIDSTRLIST)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); - UpDate_CountryIcon(GetDlgItem(hDlg, ICO_COUNTRY), pd->nID); + UpDate_CountryIcon(GetDlgItem(m_hwnd, ICO_COUNTRY), pd->nID); } break; } } - break; - - case WM_TIMER: - { - wchar_t szTime[32]; - CTzCombo::GetObj(hDlg, EDIT_TIMEZONE)->GetTime(szTime, _countof(szTime)); - SetDlgItemText(hDlg, TXT_TIME, szTime); - break; - } - - case WM_DESTROY: - KillTimer(hDlg, 1); + + return PSPBaseDlg::DlgProc(uMsg, wParam, lParam); } - return PSPBaseProc(hDlg, uMsg, wParam, lParam); +}; + +void InitOriginDlg(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.position = 0x8000002; + uip.pDialog = new PSPOriginDlg(); + uip.dwInitParam = ICONINDEX(IDI_TREE_ADVANCED); + uip.szTitle.w = LPGENW("General") L"\\" LPGENW("Origin"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/psp_profile.cpp b/plugins/UserInfoEx/src/psp_profile.cpp index 9101d41d13..38ee787e90 100644 --- a/plugins/UserInfoEx/src/psp_profile.cpp +++ b/plugins/UserInfoEx/src/psp_profile.cpp @@ -274,7 +274,7 @@ static HWND ProfileList_BeginLabelEdit(LPLISTCTRL pList, int iItem, int iSubItem { LVITEM lvi; LPLCITEM pItem; - MCONTACT hContact; + MCONTACT m_hContact; RECT rcList; if (!PtrIsValid(pList)) @@ -292,10 +292,10 @@ static HWND ProfileList_BeginLabelEdit(LPLISTCTRL pList, int iItem, int iSubItem pItem = (LPLCITEM)lvi.lParam; - PSGetContact(GetParent(pList->hList), hContact); + PSGetContact(GetParent(pList->hList), m_hContact); // do not edit deviders or protocol based contact information - if (!(lvi.state & LVIS_SELECTED) || !PtrIsValid(pItem) || (hContact && (pItem->wFlags & CTRLF_HASPROTO))) + if (!(lvi.state & LVIS_SELECTED) || !PtrIsValid(pItem) || (m_hContact && (pItem->wFlags & CTRLF_HASPROTO))) return nullptr; ListView_EnsureVisible(pList->hList, iItem, FALSE); @@ -423,12 +423,12 @@ static uint8_t ProfileList_AddNewItem(HWND hDlg, LPLISTCTRL pList, const PROFILE { LPLCITEM pItem; LVITEM lvi; - MCONTACT hContact; + MCONTACT m_hContact; if (PtrIsValid(pList) && (pItem = (LPLCITEM)mir_alloc(sizeof(LCITEM)))) { - PSGetContact(hDlg, hContact); + PSGetContact(hDlg, m_hContact); pItem->nType = CTRL_LIST_ITEM; - pItem->wFlags = hContact ? CTRLF_HASCUSTOM : 0; + pItem->wFlags = m_hContact ? CTRLF_HASCUSTOM : 0; pItem->iListItem = 0; pItem->pszText[0] = nullptr; pItem->pszText[1] = nullptr; @@ -457,7 +457,7 @@ static uint8_t ProfileList_AddNewItem(HWND hDlg, LPLISTCTRL pList, const PROFILE * param: hList - HANDLE to the list to fill with two columns * iItem - index of new listviewitem * iImage - image to draw from a imagelist associated with the listview - * hContact - handle to the contact, whose information are read + * m_hContact - handle to the contact, whose information are read * pszModule - the module the information are stored in * szCatFormat - name of a database setting that holds the categorytext * szValFormat - name of a database setting that holds the valuetext @@ -470,7 +470,7 @@ static int ProfileList_AddItemlistFromDB( int &iItem, LPIDSTRLIST idList, UINT nList, - MCONTACT hContact, + MCONTACT m_hContact, LPCSTR pszModule, LPCSTR szCatFormat, LPCSTR szValFormat, @@ -488,12 +488,12 @@ static int ProfileList_AddItemlistFromDB( for (i = 0, lvi.iItem = iItem; ; i++) { // read the setting from db mir_snprintf(pszSetting, szValFormat, i); - if (DB::Setting::GetTString(hContact, pszModule, pszSetting, &dbvVal)) + if (DB::Setting::GetWString(m_hContact, pszModule, pszSetting, &dbvVal)) break; if (dbvVal.type != DBVT_WCHAR) continue; mir_snprintf(pszSetting, szCatFormat, i); - DB::Setting::GetAString(hContact, pszModule, pszSetting, &dbvCat); + DB::Setting::GetAString(m_hContact, pszModule, pszSetting, &dbvCat); // create the itemobject if (!(pItem = (LPLCITEM)mir_alloc(sizeof(LCITEM)))) { db_free(&dbvCat); @@ -1016,359 +1016,352 @@ static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wPa * * return: 0 or 1 **/ -INT_PTR CALLBACK PSPProcContactProfile(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) + +struct PSPContactProfileDlg : public PSPBaseDlg { - HWND hList = GetDlgItem(hDlg, LIST_PROFILE); + PSPContactProfileDlg() : + PSPBaseDlg(IDD_CONTACT_PROFILE) + {} + + HWND hList; LPLISTCTRL pList; - LVHITTESTINFO hi; - switch (uMsg) { - case WM_INITDIALOG: - { - LVCOLUMN lvc; - RECT rc; - LOGFONT lf; - HFONT hFont; - TOOLINFO ti; + bool OnInitDialog() override + { + LVCOLUMN lvc; + RECT rc; + LOGFONT lf; + HFONT hFont; - if (!hList || !(pList = (LPLISTCTRL)mir_alloc(sizeof(LISTCTRL)))) - return FALSE; - memset(pList, 0, sizeof(LISTCTRL)); + hList = GetDlgItem(m_hwnd, LIST_PROFILE); + if (!hList || !(pList = (LPLISTCTRL)mir_calloc(sizeof(LISTCTRL)))) + return FALSE; + + Ctrl_InitTextColours(); - TranslateDialogDefault(hDlg); - Ctrl_InitTextColours(); + // init info structure + pList->hList = hList; + pList->nType = CTRL_LIST_PROFILE; + memset(&pList->labelEdit, 0, sizeof(pList->labelEdit)); + SetUserData(hList, pList); - // init info structure - pList->hList = hList; - pList->nType = CTRL_LIST_PROFILE; - memset(&pList->labelEdit, 0, sizeof(pList->labelEdit)); - SetUserData(hList, pList); + // set new window procedure + mir_subclassWindow(hList, ProfileList_SubclassProc); - // set new window procedure - mir_subclassWindow(hList, ProfileList_SubclassProc); + // remove static edge in aero mode + if (IsAeroMode()) + SetWindowLongPtr(hList, GWL_EXSTYLE, GetWindowLongPtr(hList, GWL_EXSTYLE) & ~WS_EX_STATICEDGE); - // remove static edge in aero mode - if (IsAeroMode()) - SetWindowLongPtr(hList, GWL_EXSTYLE, GetWindowLongPtr(hList, GWL_EXSTYLE) & ~WS_EX_STATICEDGE); - - // insert columns into the listboxes - ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT); - - - PSGetBoldFont(hDlg, hFont); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hFont, 0); - - // set listfont - pList->hFont = (HFONT)SendMessage(hList, WM_GETFONT, 0, 0); - pList->wFlags |= LVF_EDITLABEL; - GetObject(pList->hFont, sizeof(lf), &lf); - lf.lfHeight -= 6; - hFont = CreateFontIndirect(&lf); - SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0); - - GetClientRect(hList, &rc); - rc.right -= GetSystemMetrics(SM_CXVSCROLL); - - // initiate the tooltips - pList->hTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr, WS_POPUP | TTS_BALLOON | TTS_NOPREFIX | TTS_ALWAYSTIP, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hList, nullptr, g_plugin.getInst(), nullptr); - if (pList->hTip) { - SetWindowPos(pList->hTip, HWND_TOPMOST, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - - memset(&ti, 0, sizeof(TOOLINFO)); - ti.cbSize = sizeof(TOOLINFO); - ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT; - ti.hinst = g_plugin.getInst(); - ti.hwnd = hList; - ti.uId = (UINT_PTR)hList; - SendMessage(pList->hTip, TTM_ADDTOOL, NULL, (LPARAM)&ti); - SendMessage(pList->hTip, TTM_ACTIVATE, FALSE, (LPARAM)&ti); - } + // insert columns into the listboxes + ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT); - // insert columns into the listboxes - lvc.mask = LVCF_WIDTH; - lvc.cx = rc.right / 8 * 3; - ListView_InsertColumn(hList, 0, &lvc); - lvc.cx = rc.right / 8 * 5; - ListView_InsertColumn(hList, 1, &lvc); - return TRUE; + PSGetBoldFont(m_hwnd, hFont); + SendDlgItemMessage(m_hwnd, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hFont, 0); + + // set listfont + pList->hFont = (HFONT)SendMessage(hList, WM_GETFONT, 0, 0); + pList->wFlags |= LVF_EDITLABEL; + GetObject(pList->hFont, sizeof(lf), &lf); + lf.lfHeight -= 6; + hFont = CreateFontIndirect(&lf); + SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0); + + GetClientRect(hList, &rc); + rc.right -= GetSystemMetrics(SM_CXVSCROLL); + + // initiate the tooltips + pList->hTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr, WS_POPUP | TTS_BALLOON | TTS_NOPREFIX | TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hList, nullptr, g_plugin.getInst(), nullptr); + if (pList->hTip) { + SetWindowPos(pList->hTip, HWND_TOPMOST, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + + TOOLINFO ti; + memset(&ti, 0, sizeof(TOOLINFO)); + ti.cbSize = sizeof(TOOLINFO); + ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT; + ti.hinst = g_plugin.getInst(); + ti.hwnd = hList; + ti.uId = (UINT_PTR)hList; + SendMessage(pList->hTip, TTM_ADDTOOL, NULL, (LPARAM)&ti); + SendMessage(pList->hTip, TTM_ACTIVATE, FALSE, (LPARAM)&ti); } - case WM_CTLCOLORSTATIC: - case WM_CTLCOLORDLG: - if (IsAeroMode()) - return (INT_PTR)GetStockBrush(WHITE_BRUSH); - break; + // insert columns into the listboxes + lvc.mask = LVCF_WIDTH; + lvc.cx = rc.right / 8 * 3; + ListView_InsertColumn(hList, 0, &lvc); + lvc.cx = rc.right / 8 * 5; + ListView_InsertColumn(hList, 1, &lvc); + return true; + } - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - { - MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - LPCSTR pszProto; + bool OnApply() override + { + if (pList->wFlags & CTRLF_CHANGED) { + uint8_t iFmt = -1; + wchar_t szGroup[MAX_PATH]; + CHAR pszSetting[MAXSETTING]; + LPLCITEM pItem; + int iItem; + LPSTR pszModule = USERINFO; - if (!PtrIsValid(pList = (LPLISTCTRL)GetUserData(hList))) - break; + if (!m_hContact) + PSGetBaseProto(m_hwnd, pszModule); - // some account data may have changed so reread database - switch (((LPNMHDR)lParam)->code) { - case PSN_INFOCHANGED: - { - uint8_t msgResult = 0; - LPIDSTRLIST idList; - UINT nList; - uint8_t i; - int iItem = 0, iGrp = 0, numProtoItems, numUserItems; - - if (!(pList->wFlags & CTRLF_CHANGED) && PSGetBaseProto(hDlg, pszProto) && *pszProto != 0) { - ProfileList_Clear(hList); - - // insert the past information - for (i = 0; i < 3; i++) { - pFmt[i].GetList((WPARAM)&nList, (LPARAM)&idList); - if ((numProtoItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hContact, pszProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASPROTO)) < 0) - return FALSE; - - // scan all basic protocols for the subcontacts - if (DB::Module::IsMetaAndScan(pszProto)) { - int iDefault = db_mc_getDefaultNum(hContact); - MCONTACT hSubContact, hDefContact; - LPCSTR pszSubBaseProto; - - if ((hDefContact = db_mc_getSub(hContact, iDefault)) && (pszSubBaseProto = Proto_GetBaseAccountName(hDefContact))) { - if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hDefContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA | CTRLF_HASPROTO)) < 0) - return FALSE; - - // copy the missing settings from the other subcontacts - int numSubs = db_mc_getSubCount(hContact); - for (int j = 0; j < numSubs; j++) { - if (j == iDefault) - continue; - if (!(hSubContact = db_mc_getSub(hContact, j))) - continue; - if (!(pszSubBaseProto = Proto_GetBaseAccountName(hSubContact))) - continue; - if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA | CTRLF_HASPROTO)) < 0) - return FALSE; - //if ((numUserItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA | CTRLF_HASPROTO)) < 0) - // return FALSE; - } - } - } - if ((numUserItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASCUSTOM)) < 0) - return FALSE; - if (numUserItems || numProtoItems) { - msgResult = PSP_CHANGED; - ProfileList_AddGroup(hList, pFmt[i].szGroup, iGrp); - iGrp = ++iItem; - } - } - } - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, msgResult); - break; - } - // user swiches to another propertysheetpage - case PSN_KILLACTIVE: - ProfileList_EndLabelEdit(hList, TRUE); - break; - // user selected to apply settings to the database - case PSN_APPLY: - if (pList->wFlags & CTRLF_CHANGED) { - uint8_t iFmt = -1; - int iItem; - LVITEM lvi; - wchar_t szGroup[MAX_PATH]; - CHAR pszSetting[MAXSETTING]; - LPLCITEM pItem; - LPSTR pszModule = USERINFO; - - if (!hContact) - PSGetBaseProto(hDlg, pszModule); + *szGroup = 0; + LVITEM lvi; + lvi.mask = LVIF_TEXT | LVIF_PARAM; + lvi.pszText = szGroup; + lvi.cchTextMax = _countof(szGroup); + + for (iItem = lvi.iItem = lvi.iSubItem = 0; ListView_GetItem(hList, &lvi); lvi.iItem++) { + if (!PtrIsValid(pItem = (LPLCITEM)lvi.lParam)) { + // delete reluctant items + if (iFmt < _countof(pFmt)) { + DB::Setting::DeleteArray(m_hContact, pszModule, pFmt[iFmt].szCatFmt, iItem); + DB::Setting::DeleteArray(m_hContact, pszModule, pFmt[iFmt].szValFmt, iItem); + } + // find information about the group + for (iFmt = 0; iFmt < _countof(pFmt); iFmt++) { + if (!mir_wstrcmp(szGroup, pFmt[iFmt].szGroup)) + break; + } + // indicate, no group was found. should not happen!! + if (iFmt == _countof(pFmt)) { *szGroup = 0; - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.pszText = szGroup; - lvi.cchTextMax = _countof(szGroup); - - for (iItem = lvi.iItem = lvi.iSubItem = 0; ListView_GetItem(hList, &lvi); lvi.iItem++) { - if (!PtrIsValid(pItem = (LPLCITEM)lvi.lParam)) { - // delete reluctant items - if (iFmt < _countof(pFmt)) { - DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szCatFmt, iItem); - DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szValFmt, iItem); - } - // find information about the group - for (iFmt = 0; iFmt < _countof(pFmt); iFmt++) { - if (!mir_wstrcmp(szGroup, pFmt[iFmt].szGroup)) - break; - } - // indicate, no group was found. should not happen!! - if (iFmt == _countof(pFmt)) { - *szGroup = 0; - iFmt = -1; - } - iItem = 0; - } - else if (iFmt >= 0 && iFmt < _countof(pFmt)) { - // save value - if (!pItem->pszText[1] || !*pItem->pszText[1]) - continue; - if (!(pItem->wFlags & (CTRLF_HASPROTO|CTRLF_HASMETA))) { - mir_snprintf(pszSetting, pFmt[iFmt].szValFmt, iItem); - db_set_ws(hContact, pszModule, pszSetting, pItem->pszText[1]); - // save category - mir_snprintf(pszSetting, pFmt[iFmt].szCatFmt, iItem); - if (pItem->idstrList && pItem->iListItem > 0 && pItem->iListItem < pItem->idstrListCount) - db_set_s(hContact, pszModule, pszSetting, (LPSTR)pItem->idstrList[pItem->iListItem].pszText); - else if (pItem->pszText[0] && *pItem->pszText[0]) - db_set_ws(hContact, pszModule, pszSetting, (LPTSTR)pItem->pszText[0]); - else - db_unset(hContact, pszModule, pszSetting); - // redraw the item if required - if (pItem->wFlags & CTRLF_CHANGED) { - pItem->wFlags &= ~CTRLF_CHANGED; - ListView_RedrawItems(hList, lvi.iItem, lvi.iItem); - } - iItem++; - } - } - } - // delete reluctant items - if (iFmt >= 0 && iFmt < _countof(pFmt)) { - DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szCatFmt, iItem); - DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szValFmt, iItem); + iFmt = -1; + } + iItem = 0; + } + else if (iFmt >= 0 && iFmt < _countof(pFmt)) { + // save value + if (!pItem->pszText[1] || !*pItem->pszText[1]) + continue; + if (!(pItem->wFlags & (CTRLF_HASPROTO|CTRLF_HASMETA))) { + mir_snprintf(pszSetting, pFmt[iFmt].szValFmt, iItem); + db_set_ws(m_hContact, pszModule, pszSetting, pItem->pszText[1]); + // save category + mir_snprintf(pszSetting, pFmt[iFmt].szCatFmt, iItem); + if (pItem->idstrList && pItem->iListItem > 0 && pItem->iListItem < pItem->idstrListCount) + db_set_s(m_hContact, pszModule, pszSetting, (LPSTR)pItem->idstrList[pItem->iListItem].pszText); + else if (pItem->pszText[0] && *pItem->pszText[0]) + db_set_ws(m_hContact, pszModule, pszSetting, (LPTSTR)pItem->pszText[0]); + else + db_unset(m_hContact, pszModule, pszSetting); + // redraw the item if required + if (pItem->wFlags & CTRLF_CHANGED) { + pItem->wFlags &= ~CTRLF_CHANGED; + ListView_RedrawItems(hList, lvi.iItem, lvi.iItem); } - - pList->wFlags &= ~CTRLF_CHANGED; + iItem++; } } } - break; + // delete reluctant items + if (iFmt >= 0 && iFmt < _countof(pFmt)) { + DB::Setting::DeleteArray(m_hContact, pszModule, pFmt[iFmt].szCatFmt, iItem); + DB::Setting::DeleteArray(m_hContact, pszModule, pFmt[iFmt].szValFmt, iItem); + } - // handle notification messages from the list control - case LIST_PROFILE: - pList = (LPLISTCTRL)GetUserData(((LPNMHDR)lParam)->hwndFrom); + pList->wFlags &= ~CTRLF_CHANGED; + } + return true; + } - switch (((LPNMHDR)lParam)->code) { - case NM_RCLICK: - { - HMENU hMenu = CreatePopupMenu(); - MCONTACT hContact; - LPLCITEM pItem; - POINT pt; - - if (!hMenu) - return 1; - PSGetContact(hDlg, hContact); - GetCursorPos(&pt); - hi.pt = pt; - ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hi.pt); - ListView_SubItemHitTest(((LPNMHDR)lParam)->hwndFrom, &hi); - pItem = ProfileList_GetItemData(((LPNMHDR)lParam)->hwndFrom, hi.iItem); - - // insert menuitems - MENUITEMINFO mii = { 0 }; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_ID|MIIM_STRING; - // insert "Add" Menuitem - mii.wID = BTN_ADD_intEREST; - mii.dwTypeData = TranslateT("Add interest"); - InsertMenuItem(hMenu, 0, TRUE, &mii); - mii.wID = BTN_ADD_AFFLIATION; - mii.dwTypeData = TranslateT("Add affiliation"); - InsertMenuItem(hMenu, 1, TRUE, &mii); - mii.wID = BTN_ADD_PAST; - mii.dwTypeData = TranslateT("Add past"); - InsertMenuItem(hMenu, 2, TRUE, &mii); - - if (hi.iItem != -1 && PtrIsValid(pItem) && !(hContact && (pItem->wFlags & CTRLF_HASPROTO))) { - // insert separator - mii.fMask = MIIM_FTYPE; - mii.fType = MFT_SEPARATOR; - InsertMenuItem(hMenu, 3, TRUE, &mii); - // insert "Delete" Menuitem - mii.fMask = MIIM_ID | MIIM_STRING; - mii.wID = BTN_EDIT_CAT; - mii.dwTypeData = TranslateT("Edit category"); - InsertMenuItem(hMenu, 4, TRUE, &mii); - mii.wID = BTN_EDIT_VAL; - mii.dwTypeData = TranslateT("Edit value"); - InsertMenuItem(hMenu, 5, TRUE, &mii); - mii.fMask = MIIM_FTYPE; - mii.fType = MFT_SEPARATOR; - InsertMenuItem(hMenu, 6, TRUE, &mii); - // insert "Delete" Menuitem - mii.fMask = MIIM_ID | MIIM_STRING; - mii.wID = BTN_DEL; - mii.dwTypeData = TranslateT("Delete"); - InsertMenuItem(hMenu, 7, TRUE, &mii); + bool OnRefresh() override + { + LPCSTR pszProto; + uint8_t msgResult = 0; + LPIDSTRLIST idList; + UINT nList; + uint8_t i; + int iItem = 0, iGrp = 0, numProtoItems, numUserItems; + + if (!(pList->wFlags & CTRLF_CHANGED) && PSGetBaseProto(m_hwnd, pszProto) && *pszProto != 0) { + ProfileList_Clear(hList); + + // insert the past information + for (i = 0; i < 3; i++) { + pFmt[i].GetList((WPARAM)&nList, (LPARAM)&idList); + if ((numProtoItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, m_hContact, pszProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASPROTO)) < 0) + return false; + + // scan all basic protocols for the subcontacts + if (DB::Module::IsMetaAndScan(pszProto)) { + int iDefault = db_mc_getDefaultNum(m_hContact); + MCONTACT hSubContact, hDefContact; + LPCSTR pszSubBaseProto; + + if ((hDefContact = db_mc_getSub(m_hContact, iDefault)) && (pszSubBaseProto = Proto_GetBaseAccountName(hDefContact))) { + if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hDefContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA | CTRLF_HASPROTO)) < 0) + return false; + + // copy the missing settings from the other subcontacts + int numSubs = db_mc_getSubCount(m_hContact); + for (int j = 0; j < numSubs; j++) { + if (j == iDefault) + continue; + if (!(hSubContact = db_mc_getSub(m_hContact, j))) + continue; + if (!(pszSubBaseProto = Proto_GetBaseAccountName(hSubContact))) + continue; + if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA | CTRLF_HASPROTO)) < 0) + return false; + } } - TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hDlg, nullptr); - DestroyMenu(hMenu); } - return 0; + if ((numUserItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, m_hContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASCUSTOM)) < 0) + return false; - case LVN_GETDISPINFO: - if (pList->labelEdit.iTopIndex != ListView_GetTopIndex(hList)) - ProfileList_EndLabelEdit(((LPNMHDR)lParam)->hwndFrom, FALSE); + if (numUserItems || numProtoItems) { + msgResult = PSP_CHANGED; + ProfileList_AddGroup(hList, pFmt[i].szGroup, iGrp); + iGrp = ++iItem; + } + } + } + return false; + } + + INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override + { + LVHITTESTINFO hi; + + switch (uMsg) { + case WM_CTLCOLORSTATIC: + case WM_CTLCOLORDLG: + if (IsAeroMode()) + return (INT_PTR)GetStockBrush(WHITE_BRUSH); + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->idFrom) { + case 0: + // some account data may have changed so reread database + switch (((LPNMHDR)lParam)->code) { + case PSN_KILLACTIVE: // user swiches to another propertysheetpage + ProfileList_EndLabelEdit(hList, TRUE); + break; + } break; - case NM_CUSTOMDRAW: - { - LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)lParam; - LPLCITEM pItem = (LPLCITEM)cd->nmcd.lItemlParam; - RECT rc; - - switch (cd->nmcd.dwDrawStage) { - case CDDS_PREPAINT: - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW); - return TRUE; - - case CDDS_ITEMPREPAINT: - ListView_GetItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, &rc, LVIR_BOUNDS); - if (!PtrIsValid(pItem)) { - HFONT hBold, hFont; - wchar_t szText[MAX_PATH]; - - PSGetBoldFont(hDlg, hBold); - hFont = (HFONT)SelectObject(cd->nmcd.hdc, hBold); - SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW)); - ProfileList_GetItemText(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, 0, szText, MAX_PATH); - rc.left += 6; - DrawText(cd->nmcd.hdc, TranslateW(szText), -1, &rc, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER); - - rc.bottom -= 2; - rc.top = rc.bottom - 1; - rc.left -= 6; - DrawEdge(cd->nmcd.hdc, &rc, BDR_SUNKENOUTER, BF_RECT); - - SelectObject(cd->nmcd.hdc, hFont); - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); - return TRUE; - } - // draw selected item - if ((cd->nmcd.uItemState & CDIS_SELECTED) || (pList->labelEdit.iItem == (int)cd->nmcd.dwItemSpec)) { - SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT)); - } - // draw background of unselected item - else { - SetTextColor(cd->nmcd.hdc, - (pItem->wFlags & CTRLF_CHANGED) - ? clrChanged : (pItem->wFlags & CTRLF_HASMETA) - ? clrMeta : ((pItem->wFlags & (CTRLF_HASCUSTOM)) && (pItem->wFlags & CTRLF_HASPROTO)) - ? clrBoth : (pItem->wFlags & CTRLF_HASCUSTOM) - ? clrCustom : clrNormal); - FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW)); + // handle notification messages from the list control + case LIST_PROFILE: + switch (((LPNMHDR)lParam)->code) { + case NM_RCLICK: + { + HMENU hMenu = CreatePopupMenu(); + if (!hMenu) + return 1; + + POINT pt; + GetCursorPos(&pt); + hi.pt = pt; + ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hi.pt); + ListView_SubItemHitTest(((LPNMHDR)lParam)->hwndFrom, &hi); + LPLCITEM pItem = ProfileList_GetItemData(((LPNMHDR)lParam)->hwndFrom, hi.iItem); + + // insert menuitems + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_ID|MIIM_STRING; + // insert "Add" Menuitem + mii.wID = BTN_ADD_intEREST; + mii.dwTypeData = TranslateT("Add interest"); + InsertMenuItem(hMenu, 0, TRUE, &mii); + mii.wID = BTN_ADD_AFFLIATION; + mii.dwTypeData = TranslateT("Add affiliation"); + InsertMenuItem(hMenu, 1, TRUE, &mii); + mii.wID = BTN_ADD_PAST; + mii.dwTypeData = TranslateT("Add past"); + InsertMenuItem(hMenu, 2, TRUE, &mii); + + if (hi.iItem != -1 && PtrIsValid(pItem) && !(m_hContact && (pItem->wFlags & CTRLF_HASPROTO))) { + // insert separator + mii.fMask = MIIM_FTYPE; + mii.fType = MFT_SEPARATOR; + InsertMenuItem(hMenu, 3, TRUE, &mii); + // insert "Delete" Menuitem + mii.fMask = MIIM_ID | MIIM_STRING; + mii.wID = BTN_EDIT_CAT; + mii.dwTypeData = TranslateT("Edit category"); + InsertMenuItem(hMenu, 4, TRUE, &mii); + mii.wID = BTN_EDIT_VAL; + mii.dwTypeData = TranslateT("Edit value"); + InsertMenuItem(hMenu, 5, TRUE, &mii); + mii.fMask = MIIM_FTYPE; + mii.fType = MFT_SEPARATOR; + InsertMenuItem(hMenu, 6, TRUE, &mii); + // insert "Delete" Menuitem + mii.fMask = MIIM_ID | MIIM_STRING; + mii.wID = BTN_DEL; + mii.dwTypeData = TranslateT("Delete"); + InsertMenuItem(hMenu, 7, TRUE, &mii); } - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT | CDRF_NOTIFYSUBITEMDRAW); - return TRUE; + TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, m_hwnd, nullptr); + DestroyMenu(hMenu); + } + return 0; - case CDDS_SUBITEM | CDDS_ITEMPREPAINT: - { -// HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, pList->hFont); + case LVN_GETDISPINFO: + if (pList->labelEdit.iTopIndex != ListView_GetTopIndex(hList)) + ProfileList_EndLabelEdit(((LPNMHDR)lParam)->hwndFrom, FALSE); + break; + + case NM_CUSTOMDRAW: + { + LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)lParam; + LPLCITEM pItem = (LPLCITEM)cd->nmcd.lItemlParam; + RECT rc; + switch (cd->nmcd.dwDrawStage) { + case CDDS_PREPAINT: + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW); + return TRUE; + + case CDDS_ITEMPREPAINT: + ListView_GetItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, &rc, LVIR_BOUNDS); + if (!PtrIsValid(pItem)) { + HFONT hBold, hFont; + wchar_t szText[MAX_PATH]; + + PSGetBoldFont(m_hwnd, hBold); + hFont = (HFONT)SelectObject(cd->nmcd.hdc, hBold); + SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW)); + ProfileList_GetItemText(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, 0, szText, MAX_PATH); + rc.left += 6; + DrawText(cd->nmcd.hdc, TranslateW(szText), -1, &rc, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER); + + rc.bottom -= 2; + rc.top = rc.bottom - 1; + rc.left -= 6; + DrawEdge(cd->nmcd.hdc, &rc, BDR_SUNKENOUTER, BF_RECT); + + SelectObject(cd->nmcd.hdc, hFont); + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); + return TRUE; + } + // draw selected item + if ((cd->nmcd.uItemState & CDIS_SELECTED) || (pList->labelEdit.iItem == (int)cd->nmcd.dwItemSpec)) { + SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT)); + } + // draw background of unselected item + else { + SetTextColor(cd->nmcd.hdc, + (pItem->wFlags & CTRLF_CHANGED) + ? clrChanged : (pItem->wFlags & CTRLF_HASMETA) + ? clrMeta : ((pItem->wFlags & (CTRLF_HASCUSTOM)) && (pItem->wFlags & CTRLF_HASPROTO)) + ? clrBoth : (pItem->wFlags & CTRLF_HASCUSTOM) + ? clrCustom : clrNormal); + FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW)); + } + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_NEWFONT | CDRF_NOTIFYSUBITEMDRAW); + return TRUE; + + case CDDS_SUBITEM | CDDS_ITEMPREPAINT: ListView_GetSubItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, cd->iSubItem, LVIR_BOUNDS, &rc); if (cd->iSubItem == 0) { RECT rc2; @@ -1383,47 +1376,55 @@ INT_PTR CALLBACK PSPProcContactProfile(HWND hDlg, UINT uMsg, WPARAM wParam, LPAR ? pItem->idstrList[pItem->iListItem].ptszTranslated : TranslateT(""), -1, &rc, DT_END_ELLIPSIS | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER); - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); return TRUE; - } - } /* switch (cd->nmcd.dwDrawStage) */ - break; - } /* case NM_CUSTOMDRAW: */ - } /* (((LPNMHDR)lParam)->code) */ - break; - } - break; /* case WM_NOTIFY: */ - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case BTN_ADD_intEREST: - return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[2]); - case BTN_ADD_AFFLIATION: - return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[1]); - case BTN_ADD_PAST: - return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[0]); - case BTN_EDIT_CAT: - ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 0); - break; - case BTN_EDIT_VAL: - ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 1); - break; - case BTN_DEL: - if (IDYES == MsgBox(hDlg, MB_YESNO | MB_ICON_QUESTION, LPGENW("Question"), LPGENW("Delete an entry"), LPGENW("Do you really want to delete this entry?"))) { - int iItem = ListView_GetSelectionMark(hList); - pList = (LPLISTCTRL)GetUserData(hList); - - ProfileList_DeleteItem(hList, iItem); - if (PtrIsValid(pList)) - pList->wFlags |= CTRLF_CHANGED; - SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL); - // check if to delete any devider - if (!ProfileList_GetItemData(hList, iItem--) && !ProfileList_GetItemData(hList, iItem)) - ListView_DeleteItem(hList, iItem); + } /* switch (cd->nmcd.dwDrawStage) */ + break; + } /* case NM_CUSTOMDRAW: */ + } /* (((LPNMHDR)lParam)->code) */ + break; + } + break; /* case WM_NOTIFY: */ + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case BTN_ADD_intEREST: + return ProfileList_AddNewItem(m_hwnd, (LPLISTCTRL)GetUserData(hList), &pFmt[2]); + case BTN_ADD_AFFLIATION: + return ProfileList_AddNewItem(m_hwnd, (LPLISTCTRL)GetUserData(hList), &pFmt[1]); + case BTN_ADD_PAST: + return ProfileList_AddNewItem(m_hwnd, (LPLISTCTRL)GetUserData(hList), &pFmt[0]); + case BTN_EDIT_CAT: + ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 0); + break; + case BTN_EDIT_VAL: + ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 1); + break; + case BTN_DEL: + if (IDYES == MsgBox(m_hwnd, MB_YESNO | MB_ICON_QUESTION, LPGENW("Question"), LPGENW("Delete an entry"), LPGENW("Do you really want to delete this entry?"))) { + int iItem = ListView_GetSelectionMark(hList); + ProfileList_DeleteItem(hList, iItem); + + if (PtrIsValid(pList)) + pList->wFlags |= CTRLF_CHANGED; + SendMessage(GetParent(m_hwnd), PSM_CHANGED, NULL, NULL); + // check if to delete any devider + if (!ProfileList_GetItemData(hList, iItem--) && !ProfileList_GetItemData(hList, iItem)) + ListView_DeleteItem(hList, iItem); + } + break; } break; } - break; + return FALSE; } - return FALSE; +}; + +void InitProfileDlg(WPARAM wParam, USERINFOPAGE &uip) +{ + uip.position = 0x8000007; + uip.pDialog = new PSPContactProfileDlg(); + uip.dwInitParam = ICONINDEX(IDI_TREE_PROFILE); + uip.szTitle.w = LPGENW("About") L"\\" LPGENW("Profile"); + g_plugin.addUserInfo(wParam, &uip); } diff --git a/plugins/UserInfoEx/src/stdafx.h b/plugins/UserInfoEx/src/stdafx.h index cafc703717..2d71b7698a 100644 --- a/plugins/UserInfoEx/src/stdafx.h +++ b/plugins/UserInfoEx/src/stdafx.h @@ -103,6 +103,14 @@ using namespace std; #define GetUserData(p) GetWindowLongPtr((p), GWLP_USERDATA) #define SetUserData(p, l) SetWindowLongPtr((p), GWLP_USERDATA, (LONG_PTR) (l)) +struct CMPlugin : public PLUGIN +{ + CMPlugin(); + + int Load() override; + int Unload() override; +}; + #include "resource.h" #include "version.h" #include "../IconPacks/default/src/icons.h" @@ -150,14 +158,6 @@ using namespace std; * UserInfoEx global variables ***********************************************************************************************************/ -struct CMPlugin : public PLUGIN -{ - CMPlugin(); - - int Load() override; - int Unload() override; -}; - typedef struct _MGLOBAL { uint8_t CanChangeDetails : 1; // is service to upload own contact information for icq present? -- cgit v1.2.3