summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src/psp_profile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/UserInfoEx/src/psp_profile.cpp')
-rw-r--r--plugins/UserInfoEx/src/psp_profile.cpp610
1 files changed, 280 insertions, 330 deletions
diff --git a/plugins/UserInfoEx/src/psp_profile.cpp b/plugins/UserInfoEx/src/psp_profile.cpp
index 38ee787e90..78acc56f4d 100644
--- a/plugins/UserInfoEx/src/psp_profile.cpp
+++ b/plugins/UserInfoEx/src/psp_profile.cpp
@@ -198,13 +198,12 @@ static void ProfileList_Clear(HWND hList)
**/
static int ProfileList_EndLabelEdit(LPLISTCTRL pList, uint8_t bSave)
{
- HWND hEdit;
-
// check if labeledit is enabled
- if (!PtrIsValid(pList) || !pList->hList || !pList->labelEdit.hEdit)
+ if (!pList->hList || !pList->labelEdit.hEdit)
return 1;
+
// set hEdit NULL to indicate the endlabeledit call and prevent other calls
- hEdit = pList->labelEdit.hEdit;
+ HWND hEdit = pList->labelEdit.hEdit;
pList->labelEdit.hEdit = nullptr;
if (bSave != FALSE && pList->labelEdit.pItem) {
@@ -257,11 +256,6 @@ static int ProfileList_EndLabelEdit(LPLISTCTRL pList, uint8_t bSave)
return 0;
}
-static int ProfileList_EndLabelEdit(HWND hList, uint8_t bSave)
-{
- return ProfileList_EndLabelEdit((LPLISTCTRL)GetUserData(hList), bSave);
-}
-
/**
* name: ProfileList_BeginLabelEdit
* desc: create an edit control to edit the label of the selected item
@@ -272,16 +266,10 @@ static int ProfileList_EndLabelEdit(HWND hList, uint8_t bSave)
**/
static HWND ProfileList_BeginLabelEdit(LPLISTCTRL pList, int iItem, int iSubItem)
{
- LVITEM lvi;
- LPLCITEM pItem;
- MCONTACT m_hContact;
- RECT rcList;
-
- if (!PtrIsValid(pList))
- return nullptr;
if (pList->labelEdit.hEdit)
ProfileList_EndLabelEdit(pList, FALSE);
+ LVITEM lvi;
lvi.mask = LVIF_PARAM | LVIF_STATE;
lvi.stateMask = 0xFFFFFFFF;
lvi.iItem = iItem;
@@ -290,12 +278,13 @@ static HWND ProfileList_BeginLabelEdit(LPLISTCTRL pList, int iItem, int iSubItem
if (!ListView_GetItem(pList->hList, &lvi))
return nullptr;
- pItem = (LPLCITEM)lvi.lParam;
+ LPLCITEM pItem = (LPLCITEM)lvi.lParam;
- PSGetContact(GetParent(pList->hList), m_hContact);
+ MCONTACT hContact;
+ PSGetContact(GetParent(pList->hList), hContact);
// do not edit deviders or protocol based contact information
- if (!(lvi.state & LVIS_SELECTED) || !PtrIsValid(pItem) || (m_hContact && (pItem->wFlags & CTRLF_HASPROTO)))
+ if (!(lvi.state & LVIS_SELECTED) || !PtrIsValid(pItem) || (hContact && (pItem->wFlags & CTRLF_HASPROTO)))
return nullptr;
ListView_EnsureVisible(pList->hList, iItem, FALSE);
@@ -307,6 +296,8 @@ static HWND ProfileList_BeginLabelEdit(LPLISTCTRL pList, int iItem, int iSubItem
ListView_GetSubItemRect(pList->hList, iItem, 1, LVIR_BOUNDS, &rc2);
pList->labelEdit.rcCombo.right = rc2.left;
}
+
+ RECT rcList;
GetClientRect(pList->hList, &rcList);
pList->labelEdit.rcCombo.right = min(pList->labelEdit.rcCombo.right, rcList.right);
pList->labelEdit.rcCombo.left = max(pList->labelEdit.rcCombo.left, rcList.left);
@@ -358,19 +349,6 @@ static HWND ProfileList_BeginLabelEdit(LPLISTCTRL pList, int iItem, int iSubItem
}
/**
- * name: ProfileList_BeginLabelEdit
- * desc: create an edit control to edit the label of the selected item
- * param: hList - handle to listview control
- * iItem - item index
- * iSubItem - subitem (column) index
- * return: handle to the edit control
- **/
-static HWND ProfileList_BeginLabelEdit(HWND hList, int iItem, int iSubItem)
-{
- return ProfileList_BeginLabelEdit((LPLISTCTRL)GetUserData(hList), iItem, iSubItem);
-}
-
-/**
* name: ProfileList_GetInsertIndex
* desc: finds index to add the new item to and adds an devider if necessary
* param: hList - handle to listcontrol to search for the index in
@@ -412,148 +390,6 @@ static int ProfileList_GetInsertIndex(HWND hList, LPTSTR pszGroup)
}
/**
- * name: ProfileList_AddNewItem
- * desc: Ask's user for a type and adds new item to the list view
- * param: pList - pointer to the listview's data structure
- * pszList - database settings string, that identifies this category
- *
- * return: TRUE or FALSE
- **/
-static uint8_t ProfileList_AddNewItem(HWND hDlg, LPLISTCTRL pList, const PROFILEENTRY *pEntry)
-{
- LPLCITEM pItem;
- LVITEM lvi;
- MCONTACT m_hContact;
-
- if (PtrIsValid(pList) && (pItem = (LPLCITEM)mir_alloc(sizeof(LCITEM)))) {
- PSGetContact(hDlg, m_hContact);
- pItem->nType = CTRL_LIST_ITEM;
- pItem->wFlags = m_hContact ? CTRLF_HASCUSTOM : 0;
- pItem->iListItem = 0;
- pItem->pszText[0] = nullptr;
- pItem->pszText[1] = nullptr;
- // get category list
- pEntry->GetList((WPARAM)&pItem->idstrListCount, (LPARAM)&pItem->idstrList);
-
- lvi.mask = LVIF_PARAM | LVIF_STATE;
- lvi.stateMask = 0xFFFFFFFF;
- lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
- lvi.iItem = ProfileList_GetInsertIndex(pList->hList, pEntry->szGroup);
- lvi.iSubItem = 0;
- lvi.lParam = (LPARAM)pItem;
- if ((lvi.iItem = ListView_InsertItem(pList->hList, &lvi)) >= 0) {
- ProfileList_BeginLabelEdit(pList, lvi.iItem, 0);
- return TRUE;
- }
- mir_free(pItem);
- MsgErr(hDlg, LPGENW("Sorry, but there is a problem with adding a new item of type \"%s\""), pEntry->szGroup);
- }
- return FALSE;
-}
-
-/**
- * name: ProfileList_AddItemlistFromDB
- * desc: reads an zero based indexed szList from the database of hContacts pszModule and fills a hList
- * 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
- * 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
- * wFlags - flags to set for a new allocated item
- *
- * return number of added rows or -1 if listview's changed flag is set
- **/
-static int ProfileList_AddItemlistFromDB(
- LPLISTCTRL pList,
- int &iItem,
- LPIDSTRLIST idList,
- UINT nList,
- MCONTACT m_hContact,
- LPCSTR pszModule,
- LPCSTR szCatFormat,
- LPCSTR szValFormat,
- uint16_t wFlags)
-{
- DBVARIANT dbvVal, dbvCat;
- LPLCITEM pItem;
- LVITEM lvi;
- UINT i, j = 0;
- CHAR pszSetting[MAXSETTING];
-
- lvi.iSubItem = 0;
- lvi.mask = LVIF_PARAM;
-
- for (i = 0, lvi.iItem = iItem; ; i++) {
- // read the setting from db
- mir_snprintf(pszSetting, szValFormat, i);
- if (DB::Setting::GetWString(m_hContact, pszModule, pszSetting, &dbvVal))
- break;
- if (dbvVal.type != DBVT_WCHAR)
- continue;
- mir_snprintf(pszSetting, szCatFormat, i);
- DB::Setting::GetAString(m_hContact, pszModule, pszSetting, &dbvCat);
- // create the itemobject
- if (!(pItem = (LPLCITEM)mir_alloc(sizeof(LCITEM)))) {
- db_free(&dbvCat);
- db_free(&dbvVal);
- break;
- }
- // fill item struct
- pItem->nType = CTRL_LIST_ITEM;
- pItem->idstrList = idList;
- pItem->idstrListCount = nList;
- pItem->iListItem = 0;
- pItem->pszText[0] = nullptr;
- pItem->pszText[1] = dbvVal.pwszVal;
- pItem->wFlags = wFlags;
- lvi.lParam = (LPARAM)pItem;
-
- // get id-str-list-item for the category string
- if (idList != nullptr) {
- for (j = 0; j < nList; j++) {
- switch (dbvCat.type) {
- case DBVT_BYTE:
- if (dbvCat.bVal != (uint8_t)idList[j].nID)
- continue;
- break;
- case DBVT_WORD:
- if (dbvCat.wVal != (uint16_t)idList[j].nID)
- continue;
- break;
- case DBVT_DWORD:
- if (dbvCat.dVal != (uint32_t)idList[j].nID)
- continue;
- break;
- case DBVT_ASCIIZ:
- if (mir_strcmp(dbvCat.pszVal, idList[j].pszText))
- continue;
- break;
- }
- pItem->iListItem = j;
- break;
- }
- }
- // item not found in the predefined category list?
- if ((idList == nullptr || j == nList) && dbvCat.type == DBVT_ASCIIZ) {
- pItem->pszText[0] = mir_a2u(dbvCat.pszVal);
- db_free(&dbvCat);
- }
- if ((lvi.iItem = ListView_InsertItem(pList->hList, &lvi)) < 0) {
- mir_free(pItem);
- db_free(&dbvCat);
- db_free(&dbvVal);
- break;
- }
- lvi.iItem++;
- dbvCat.type = dbvVal.type = DBVT_DELETED;
- }
- iItem = lvi.iItem;
- return i;
-}
-
-/**
* name: ProfileList_DropdownProc
* desc: procedure to catch messages for a listbox control for my own combobox
* param: hwnd - handle to the listview control's window
@@ -613,7 +449,7 @@ static LRESULT CALLBACK ProfileList_DropdownProc(HWND hwnd, UINT msg, WPARAM wPa
else
pList->labelEdit.dropDown.iItem = -1;
- ProfileList_EndLabelEdit(pList->hList, TRUE);
+ ProfileList_EndLabelEdit(pList, TRUE);
return 0;
}
case WM_KILLFOCUS:
@@ -654,24 +490,20 @@ static LRESULT CALLBACK ProfileList_LabelEditProc(HWND hwnd, UINT msg, WPARAM wP
SendMessage(pList->hList, WM_COMMAND, MAKEWPARAM(BTN_EDIT, BN_CLICKED), (LPARAM)pList->labelEdit.hBtn);
return 0;
case VK_RETURN:
- {
- uint8_t bEditNext;
- int iItem;
-
- if (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_WANTRETURN && !(GetKeyState(VK_CONTROL) & 0x8000))
- break;
- if (PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd))) {
- bEditNext = !pList->labelEdit.iSubItem && !ProfileList_GetItemText(pList->hList, pList->labelEdit.iItem, 1, nullptr, NULL);
- iItem = pList->labelEdit.iItem;
- ProfileList_EndLabelEdit(pList->hList, TRUE);
- if (bEditNext) ProfileList_BeginLabelEdit(pList->hList, pList->labelEdit.iItem, 1);
- }
- return 0;
+ if (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_WANTRETURN && !(GetKeyState(VK_CONTROL) & 0x8000))
+ break;
+
+ if (PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd))) {
+ bool bEditNext = !pList->labelEdit.iSubItem && !ProfileList_GetItemText(pList->hList, pList->labelEdit.iItem, 1, nullptr, NULL);
+ ProfileList_EndLabelEdit(pList, TRUE);
+ if (bEditNext)
+ ProfileList_BeginLabelEdit(pList, pList->labelEdit.iItem, 1);
}
+ return 0;
+
case VK_TAB:
if (PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd))) {
LVITEM lvi;
-
lvi.mask = LVIF_STATE;
lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
lvi.iItem = pList->labelEdit.iItem;
@@ -679,11 +511,9 @@ static LRESULT CALLBACK ProfileList_LabelEditProc(HWND hwnd, UINT msg, WPARAM wP
if (!pList->labelEdit.iSubItem) {
lvi.iSubItem = 1;
lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
- ProfileList_EndLabelEdit(pList->hList, TRUE);
+ ProfileList_EndLabelEdit(pList, TRUE);
}
else {
- UINT iSubItem = 0;
-
lvi.iSubItem = 0;
lvi.state = 0;
@@ -694,11 +524,10 @@ static LRESULT CALLBACK ProfileList_LabelEditProc(HWND hwnd, UINT msg, WPARAM wP
return 0;
// search for next valid list item (skip deviders)
- lvi.iSubItem = iSubItem;
+ lvi.iSubItem = 0;
lvi.mask = LVIF_PARAM;
do {
lvi.iItem++;
-
if (lvi.iItem == -1 || !ListView_GetItem(pList->hList, &lvi))
return 0;
}
@@ -710,26 +539,27 @@ static LRESULT CALLBACK ProfileList_LabelEditProc(HWND hwnd, UINT msg, WPARAM wP
if (!ListView_SetItem(pList->hList, &lvi))
return 0;
}
- ProfileList_BeginLabelEdit(pList->hList, lvi.iItem, lvi.iSubItem);
+ ProfileList_BeginLabelEdit(pList, lvi.iItem, lvi.iSubItem);
return 0;
}
return 1;
}
break;
+
case WM_GETDLGCODE:
return DLGC_WANTALLKEYS | mir_callNextSubclass(hwnd, ProfileList_LabelEditProc, msg, wParam, lParam);
+
case WM_KILLFOCUS:
- {
- HWND hwndFocus = GetFocus();
+ HWND hwndFocus = GetFocus();
- if (PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd))
- && hwndFocus != pList->labelEdit.dropDown.hDrop
- && hwndFocus != pList->labelEdit.hEdit
- && hwndFocus != pList->labelEdit.hBtn)
- ProfileList_EndLabelEdit(pList, hwndFocus == pList->hList);
- return 0;
- }
+ if (PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd))
+ && hwndFocus != pList->labelEdit.dropDown.hDrop
+ && hwndFocus != pList->labelEdit.hEdit
+ && hwndFocus != pList->labelEdit.hBtn)
+ ProfileList_EndLabelEdit(pList, hwndFocus == pList->hList);
+ return 0;
}
+
return mir_callNextSubclass(hwnd, ProfileList_LabelEditProc, msg, wParam, lParam);
}
@@ -744,7 +574,7 @@ static LRESULT CALLBACK ProfileList_LabelEditProc(HWND hwnd, UINT msg, WPARAM wP
**/
static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- LPLISTCTRL pList;
+ LPLISTCTRL pList = (LPLISTCTRL)GetUserData(hwnd);
LVHITTESTINFO hi;
switch (msg) {
@@ -758,13 +588,13 @@ static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wPa
nCurSel = ListView_GetSelectionMark(hwnd);
if (nCurSel == -1)
break;
- ProfileList_BeginLabelEdit(hwnd, nCurSel, 0);
+ ProfileList_BeginLabelEdit(pList, nCurSel, 0);
return 0;
case VK_F3:
nCurSel = ListView_GetSelectionMark(hwnd);
if (nCurSel == -1)
break;
- ProfileList_BeginLabelEdit(hwnd, nCurSel, 1);
+ ProfileList_BeginLabelEdit(pList, nCurSel, 1);
return 0;
case VK_UP:
case VK_DOWN:
@@ -796,10 +626,11 @@ static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wPa
ListView_SetSelectionMark(hwnd, lvi.iItem);
return 0;
}
- break;
}
+ break;
+
case WM_MOUSEMOVE:
- if (PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd))) {
+ if (PtrIsValid(pList)) {
RECT rchWnd, rcItem;
SIZE textSize;
@@ -872,13 +703,12 @@ static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wPa
}
return 0;
- // begin label edit
- case WM_LBUTTONDBLCLK:
+ case WM_LBUTTONDBLCLK: // begin label edit
{
hi.pt.x = GET_X_LPARAM(lParam);
hi.pt.y = GET_Y_LPARAM(lParam);
if (ListView_SubItemHitTest(hwnd, &hi))
- ProfileList_BeginLabelEdit(hwnd, hi.iItem, hi.iSubItem);
+ ProfileList_BeginLabelEdit(pList, hi.iItem, hi.iSubItem);
return TRUE;
}
@@ -902,75 +732,72 @@ static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wPa
switch (LOWORD(wParam)) {
// show dropdown menu for category list
case BTN_EDIT:
- {
- int i;
- wchar_t szEdit[MAX_PATH];
-
- if (!PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd)))
- break;
- GetWindowText(pList->labelEdit.hEdit, szEdit, _countof(szEdit));
-
- // need to create the dropdown list?
- if (pList->labelEdit.dropDown.hDrop == nullptr) {
- const int listHeight = 120;
- RECT rc, rcList;
- int add;
-
- // dropdown rect
- GetClientRect(pList->hList, &rcList);
- rc.left = pList->labelEdit.rcCombo.left;
- rc.right = pList->labelEdit.rcCombo.right + pList->labelEdit.rcCombo.bottom - pList->labelEdit.rcCombo.top;
-
- if (rcList.bottom < pList->labelEdit.rcCombo.bottom + listHeight) {
- rc.bottom = pList->labelEdit.rcCombo.bottom - 7; // don't ask me why!
- rc.top = rc.bottom - listHeight;
- }
- else {
- rc.top = pList->labelEdit.rcCombo.bottom;
- rc.bottom = rc.top + listHeight;
- }
+ int i;
+ wchar_t szEdit[MAX_PATH];
- pList->labelEdit.dropDown.hDrop = CreateWindowEx(0, L"LISTBOX", nullptr,
- WS_CHILD | WS_BORDER | WS_VSCROLL | LBS_COMBOBOX | LBS_HASSTRINGS,
- rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
- hwnd, nullptr, g_plugin.getInst(), nullptr);
- if (!pList->labelEdit.dropDown.hDrop)
- return FALSE;
- SetUserData(pList->labelEdit.dropDown.hDrop, pList);
- mir_subclassWindow(pList->labelEdit.dropDown.hDrop, ProfileList_DropdownProc);
- SetWindowLongPtr(pList->labelEdit.dropDown.hDrop, GWLP_ID, LIST_DROPDOWN);
- SendMessage(pList->labelEdit.dropDown.hDrop, WM_SETFONT, (WPARAM)SendMessage(GetParent(pList->hList), WM_GETFONT, 0, 0), 0);
-
- // add items
- for (i = 0; i < pList->labelEdit.pItem->idstrListCount; i++) {
- add = ListBox_AddString(pList->labelEdit.dropDown.hDrop, pList->labelEdit.pItem->idstrList[i].ptszTranslated);
- ListBox_SetItemData(pList->labelEdit.dropDown.hDrop, add, pList->labelEdit.pItem->idstrList + i);
- if (!mir_wstrcmp(szEdit, pList->labelEdit.pItem->idstrList[i].ptszTranslated))
- ListBox_SetCurSel(pList->labelEdit.dropDown.hDrop, add);
- }
+ if (!PtrIsValid(pList = (LPLISTCTRL)GetUserData(hwnd)))
+ break;
+ GetWindowText(pList->labelEdit.hEdit, szEdit, _countof(szEdit));
+
+ // need to create the dropdown list?
+ if (pList->labelEdit.dropDown.hDrop == nullptr) {
+ const int listHeight = 120;
+ RECT rc, rcList;
+ int add;
+
+ // dropdown rect
+ GetClientRect(pList->hList, &rcList);
+ rc.left = pList->labelEdit.rcCombo.left;
+ rc.right = pList->labelEdit.rcCombo.right + pList->labelEdit.rcCombo.bottom - pList->labelEdit.rcCombo.top;
+
+ if (rcList.bottom < pList->labelEdit.rcCombo.bottom + listHeight) {
+ rc.bottom = pList->labelEdit.rcCombo.bottom - 7; // don't ask me why!
+ rc.top = rc.bottom - listHeight;
}
else {
- LPIDSTRLIST lpidList;
-
- i = 0;
- while (PtrIsValid(lpidList = (LPIDSTRLIST)ListBox_GetItemData(pList->labelEdit.dropDown.hDrop, i))) {
- if (!mir_wstrcmp(szEdit, lpidList->ptszTranslated)) {
- ListBox_SetCurSel(pList->labelEdit.dropDown.hDrop, i);
- break;
- }
- i++;
- }
- if (i == pList->labelEdit.pItem->idstrListCount)
- ListBox_SetCurSel(pList->labelEdit.dropDown.hDrop, -1);
+ rc.top = pList->labelEdit.rcCombo.bottom;
+ rc.bottom = rc.top + listHeight;
}
- if (IsWindowVisible(pList->labelEdit.dropDown.hDrop)) {
- SetFocus(pList->labelEdit.hEdit);
+
+ pList->labelEdit.dropDown.hDrop = CreateWindowEx(0, L"LISTBOX", nullptr,
+ WS_CHILD | WS_BORDER | WS_VSCROLL | LBS_COMBOBOX | LBS_HASSTRINGS,
+ rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
+ hwnd, nullptr, g_plugin.getInst(), nullptr);
+ if (!pList->labelEdit.dropDown.hDrop)
+ return FALSE;
+ SetUserData(pList->labelEdit.dropDown.hDrop, pList);
+ mir_subclassWindow(pList->labelEdit.dropDown.hDrop, ProfileList_DropdownProc);
+ SetWindowLongPtr(pList->labelEdit.dropDown.hDrop, GWLP_ID, LIST_DROPDOWN);
+ SendMessage(pList->labelEdit.dropDown.hDrop, WM_SETFONT, (WPARAM)SendMessage(GetParent(pList->hList), WM_GETFONT, 0, 0), 0);
+
+ // add items
+ for (i = 0; i < pList->labelEdit.pItem->idstrListCount; i++) {
+ add = ListBox_AddString(pList->labelEdit.dropDown.hDrop, pList->labelEdit.pItem->idstrList[i].ptszTranslated);
+ ListBox_SetItemData(pList->labelEdit.dropDown.hDrop, add, pList->labelEdit.pItem->idstrList + i);
+ if (!mir_wstrcmp(szEdit, pList->labelEdit.pItem->idstrList[i].ptszTranslated))
+ ListBox_SetCurSel(pList->labelEdit.dropDown.hDrop, add);
}
- else {
- ShowWindow(pList->labelEdit.dropDown.hDrop, SW_SHOW);
- //SetFocus(pList->labelEdit.dropDown.hDrop);
+ }
+ else {
+ LPIDSTRLIST lpidList;
+
+ i = 0;
+ while (PtrIsValid(lpidList = (LPIDSTRLIST)ListBox_GetItemData(pList->labelEdit.dropDown.hDrop, i))) {
+ if (!mir_wstrcmp(szEdit, lpidList->ptszTranslated)) {
+ ListBox_SetCurSel(pList->labelEdit.dropDown.hDrop, i);
+ break;
+ }
+ i++;
}
- break;
+ if (i == pList->labelEdit.pItem->idstrListCount)
+ ListBox_SetCurSel(pList->labelEdit.dropDown.hDrop, -1);
+ }
+ if (IsWindowVisible(pList->labelEdit.dropDown.hDrop)) {
+ SetFocus(pList->labelEdit.hEdit);
+ }
+ else {
+ ShowWindow(pList->labelEdit.dropDown.hDrop, SW_SHOW);
+ //SetFocus(pList->labelEdit.dropDown.hDrop);
}
}
break;
@@ -1017,61 +844,187 @@ static LRESULT CALLBACK ProfileList_SubclassProc(HWND hwnd, UINT msg, WPARAM wPa
* return: 0 or 1
**/
-struct PSPContactProfileDlg : public PSPBaseDlg
+class PSPContactProfileDlg : public PSPBaseDlg
{
+ CCtrlListView m_list;
+
+ /**
+ * name: ProfileList_AddItemlistFromDB
+ * desc: reads an zero based indexed szList from the database of hContacts pszModule and fills a hList
+ * param: 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
+ * 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
+ * wFlags - flags to set for a new allocated item
+ *
+ * return number of added rows or -1 if listview's changed flag is set
+ **/
+
+ int ProfileList_AddItemlistFromDB(
+ int &iItem,
+ LPIDSTRLIST idList,
+ int nList,
+ MCONTACT hContact,
+ LPCSTR pszModule,
+ LPCSTR szCatFormat,
+ LPCSTR szValFormat,
+ uint16_t wFlags)
+ {
+ DBVARIANT dbvVal, dbvCat;
+ CHAR pszSetting[MAXSETTING];
+
+ LVITEM lvi;
+ lvi.iSubItem = 0;
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = iItem;
+
+ int i;
+ for (i = 0; ; i++) {
+ // read the setting from db
+ mir_snprintf(pszSetting, szValFormat, i);
+ if (DB::Setting::GetWString(hContact, pszModule, pszSetting, &dbvVal))
+ break;
+ if (dbvVal.type != DBVT_WCHAR)
+ continue;
+ mir_snprintf(pszSetting, szCatFormat, i);
+ DB::Setting::GetAString(hContact, pszModule, pszSetting, &dbvCat);
+
+ // create the item object
+ LPLCITEM pItem = (LPLCITEM)mir_alloc(sizeof(LCITEM));
+ pItem->nType = CTRL_LIST_ITEM;
+ pItem->idstrList = idList;
+ pItem->idstrListCount = nList;
+ pItem->iListItem = 0;
+ pItem->pszText[0] = nullptr;
+ pItem->pszText[1] = dbvVal.pwszVal;
+ pItem->wFlags = wFlags;
+ lvi.lParam = (LPARAM)pItem;
+
+ // get id-str-list-item for the category string
+ int j = 0;
+ if (idList != nullptr) {
+ for (j = 0; j < nList; j++) {
+ switch (dbvCat.type) {
+ case DBVT_BYTE:
+ if (dbvCat.bVal != (uint8_t)idList[j].nID)
+ continue;
+ break;
+ case DBVT_WORD:
+ if (dbvCat.wVal != (uint16_t)idList[j].nID)
+ continue;
+ break;
+ case DBVT_DWORD:
+ if (dbvCat.dVal != (uint32_t)idList[j].nID)
+ continue;
+ break;
+ case DBVT_ASCIIZ:
+ if (mir_strcmp(dbvCat.pszVal, idList[j].pszText))
+ continue;
+ break;
+ }
+ pItem->iListItem = j;
+ break;
+ }
+ }
+ // item not found in the predefined category list?
+ if ((idList == nullptr || j == nList) && dbvCat.type == DBVT_ASCIIZ) {
+ pItem->pszText[0] = mir_a2u(dbvCat.pszVal);
+ db_free(&dbvCat);
+ }
+ if ((lvi.iItem = m_list.InsertItem(&lvi)) < 0) {
+ mir_free(pItem);
+ db_free(&dbvCat);
+ db_free(&dbvVal);
+ break;
+ }
+ lvi.iItem++;
+ dbvCat.type = dbvVal.type = DBVT_DELETED;
+ }
+ iItem = lvi.iItem;
+ return i;
+ }
+
+ bool ProfileList_AddNewItem(const PROFILEENTRY *pEntry)
+ {
+ LPLCITEM pItem = (LPLCITEM)mir_alloc(sizeof(LCITEM));
+ pItem->nType = CTRL_LIST_ITEM;
+ pItem->wFlags = m_hContact ? CTRLF_HASCUSTOM : 0;
+ pItem->iListItem = 0;
+ pItem->pszText[0] = nullptr;
+ pItem->pszText[1] = nullptr;
+ // get category list
+ pEntry->GetList((WPARAM)&pItem->idstrListCount, (LPARAM)&pItem->idstrList);
+
+ LVITEM lvi;
+ lvi.mask = LVIF_PARAM | LVIF_STATE;
+ lvi.stateMask = 0xFFFFFFFF;
+ lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
+ lvi.iItem = ProfileList_GetInsertIndex(m_list.GetHwnd(), pEntry->szGroup);
+ lvi.iSubItem = 0;
+ lvi.lParam = (LPARAM)pItem;
+ if ((lvi.iItem = m_list.InsertItem(&lvi)) >= 0) {
+ ProfileList_BeginLabelEdit(pList, lvi.iItem, 0);
+ return true;
+ }
+
+ mir_free(pItem);
+ MsgErr(m_hwnd, LPGENW("Sorry, but there is a problem with adding a new item of type \"%s\""), pEntry->szGroup);
+ return false;
+ }
+
+public:
PSPContactProfileDlg() :
- PSPBaseDlg(IDD_CONTACT_PROFILE)
- {}
+ PSPBaseDlg(IDD_CONTACT_PROFILE),
+ m_list(this, LIST_PROFILE)
+ {
+ pList = (LPLISTCTRL)mir_calloc(sizeof(LISTCTRL));
+ }
- HWND hList;
LPLISTCTRL pList;
bool OnInitDialog() override
{
- LVCOLUMN lvc;
- RECT rc;
- LOGFONT lf;
- HFONT hFont;
-
- hList = GetDlgItem(m_hwnd, LIST_PROFILE);
- if (!hList || !(pList = (LPLISTCTRL)mir_calloc(sizeof(LISTCTRL))))
- return FALSE;
-
Ctrl_InitTextColours();
// init info structure
- pList->hList = hList;
+ pList->hList = m_list.GetHwnd();
pList->nType = CTRL_LIST_PROFILE;
memset(&pList->labelEdit, 0, sizeof(pList->labelEdit));
- SetUserData(hList, pList);
+ SetUserData(m_list.GetHwnd(), pList);
// set new window procedure
- mir_subclassWindow(hList, ProfileList_SubclassProc);
+ mir_subclassWindow(m_list.GetHwnd(), ProfileList_SubclassProc);
// remove static edge in aero mode
if (IsAeroMode())
- SetWindowLongPtr(hList, GWL_EXSTYLE, GetWindowLongPtr(hList, GWL_EXSTYLE) & ~WS_EX_STATICEDGE);
+ SetWindowLongPtr(m_list.GetHwnd(), GWL_EXSTYLE, GetWindowLongPtr(m_list.GetHwnd(), GWL_EXSTYLE) & ~WS_EX_STATICEDGE);
// insert columns into the listboxes
- ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);
+ m_list.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT);
+ HFONT hFont;
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->hFont = (HFONT)m_list.SendMsg(WM_GETFONT, 0, 0);
pList->wFlags |= LVF_EDITLABEL;
+
+ LOGFONT lf;
GetObject(pList->hFont, sizeof(lf), &lf);
lf.lfHeight -= 6;
hFont = CreateFontIndirect(&lf);
- SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0);
+ m_list.SendMsg(WM_SETFONT, (WPARAM)hFont, 0);
- GetClientRect(hList, &rc);
+ RECT rc;
+ GetClientRect(m_list.GetHwnd(), &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);
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_list.GetHwnd(), 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);
@@ -1081,18 +1034,19 @@ struct PSPContactProfileDlg : public PSPBaseDlg
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;
+ ti.hwnd = m_list.GetHwnd();
+ ti.uId = (UINT_PTR)m_list.GetHwnd();
SendMessage(pList->hTip, TTM_ADDTOOL, NULL, (LPARAM)&ti);
SendMessage(pList->hTip, TTM_ACTIVATE, FALSE, (LPARAM)&ti);
}
// insert columns into the listboxes
+ LVCOLUMN lvc;
lvc.mask = LVCF_WIDTH;
lvc.cx = rc.right / 8 * 3;
- ListView_InsertColumn(hList, 0, &lvc);
+ m_list.InsertColumn(0, &lvc);
lvc.cx = rc.right / 8 * 5;
- ListView_InsertColumn(hList, 1, &lvc);
+ m_list.InsertColumn(1, &lvc);
return true;
}
@@ -1116,7 +1070,7 @@ struct PSPContactProfileDlg : public PSPBaseDlg
lvi.pszText = szGroup;
lvi.cchTextMax = _countof(szGroup);
- for (iItem = lvi.iItem = lvi.iSubItem = 0; ListView_GetItem(hList, &lvi); lvi.iItem++) {
+ for (iItem = lvi.iItem = lvi.iSubItem = 0; m_list.GetItem(&lvi); lvi.iItem++) {
if (!PtrIsValid(pItem = (LPLCITEM)lvi.lParam)) {
// delete reluctant items
if (iFmt < _countof(pFmt)) {
@@ -1153,7 +1107,7 @@ struct PSPContactProfileDlg : public PSPBaseDlg
// redraw the item if required
if (pItem->wFlags & CTRLF_CHANGED) {
pItem->wFlags &= ~CTRLF_CHANGED;
- ListView_RedrawItems(hList, lvi.iItem, lvi.iItem);
+ m_list.RedrawItems(lvi.iItem, lvi.iItem);
}
iItem++;
}
@@ -1172,20 +1126,18 @@ struct PSPContactProfileDlg : public PSPBaseDlg
bool OnRefresh() override
{
- LPCSTR pszProto;
- uint8_t msgResult = 0;
- LPIDSTRLIST idList;
- UINT nList;
- uint8_t i;
int iItem = 0, iGrp = 0, numProtoItems, numUserItems;
+ LPCSTR pszProto;
if (!(pList->wFlags & CTRLF_CHANGED) && PSGetBaseProto(m_hwnd, pszProto) && *pszProto != 0) {
- ProfileList_Clear(hList);
+ ProfileList_Clear(m_list.GetHwnd());
// insert the past information
- for (i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
+ int nList;
+ LPIDSTRLIST idList;
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)
+ if ((numProtoItems = ProfileList_AddItemlistFromDB(iItem, idList, nList, m_hContact, pszProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASPROTO)) < 0)
return false;
// scan all basic protocols for the subcontacts
@@ -1195,7 +1147,7 @@ struct PSPContactProfileDlg : public PSPBaseDlg
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)
+ if ((numProtoItems += ProfileList_AddItemlistFromDB(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
@@ -1207,17 +1159,16 @@ struct PSPContactProfileDlg : public PSPBaseDlg
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)
+ if ((numProtoItems += ProfileList_AddItemlistFromDB(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, m_hContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASCUSTOM)) < 0)
+ if ((numUserItems = ProfileList_AddItemlistFromDB(iItem, idList, nList, m_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);
+ ProfileList_AddGroup(m_list.GetHwnd(), pFmt[i].szGroup, iGrp);
iGrp = ++iItem;
}
}
@@ -1242,7 +1193,7 @@ struct PSPContactProfileDlg : public PSPBaseDlg
// 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);
+ ProfileList_EndLabelEdit(pList, TRUE);
break;
}
break;
@@ -1306,8 +1257,8 @@ struct PSPContactProfileDlg : public PSPBaseDlg
return 0;
case LVN_GETDISPINFO:
- if (pList->labelEdit.iTopIndex != ListView_GetTopIndex(hList))
- ProfileList_EndLabelEdit(((LPNMHDR)lParam)->hwndFrom, FALSE);
+ if (pList->labelEdit.iTopIndex != m_list.GetTopIndex())
+ ProfileList_EndLabelEdit(pList, FALSE);
break;
case NM_CUSTOMDRAW:
@@ -1389,28 +1340,27 @@ struct PSPContactProfileDlg : public PSPBaseDlg
case WM_COMMAND:
switch (LOWORD(wParam)) {
case BTN_ADD_intEREST:
- return ProfileList_AddNewItem(m_hwnd, (LPLISTCTRL)GetUserData(hList), &pFmt[2]);
+ return ProfileList_AddNewItem(&pFmt[2]);
case BTN_ADD_AFFLIATION:
- return ProfileList_AddNewItem(m_hwnd, (LPLISTCTRL)GetUserData(hList), &pFmt[1]);
+ return ProfileList_AddNewItem(&pFmt[1]);
case BTN_ADD_PAST:
- return ProfileList_AddNewItem(m_hwnd, (LPLISTCTRL)GetUserData(hList), &pFmt[0]);
+ return ProfileList_AddNewItem(&pFmt[0]);
case BTN_EDIT_CAT:
- ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 0);
+ ProfileList_BeginLabelEdit(pList, m_list.GetSelectionMark(), 0);
break;
case BTN_EDIT_VAL:
- ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 1);
+ ProfileList_BeginLabelEdit(pList, m_list.GetSelectionMark(), 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);
+ int iItem = m_list.GetSelectionMark();
+ ProfileList_DeleteItem(m_list.GetHwnd(), iItem);
- if (PtrIsValid(pList))
- pList->wFlags |= CTRLF_CHANGED;
+ 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);
+ if (!ProfileList_GetItemData(m_list.GetHwnd(), iItem--) && !ProfileList_GetItemData(m_list.GetHwnd(), iItem))
+ m_list.DeleteItem(iItem);
}
break;
}