summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src/psp_profile.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-06-09 21:26:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-06-09 21:30:54 +0300
commit856ff580fd9d776c331a6b525fa7d73a24d92f64 (patch)
tree42c4912b0b9c406c15783af3fc6e8c4857b09de1 /plugins/UserInfoEx/src/psp_profile.cpp
parent68c2dea66f3e368cc1437f7890c8e62907890fcd (diff)
UserInfo -> UI classes
Diffstat (limited to 'plugins/UserInfoEx/src/psp_profile.cpp')
-rw-r--r--plugins/UserInfoEx/src/psp_profile.cpp743
1 files changed, 372 insertions, 371 deletions
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("<empty>"),
-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);
}