soc.2009.vulture: 6c80539b: Context menus for groups and empty space...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Sat Aug 8 16:06:24 EDT 2009


-----------------------------------------------------------------
Revision: 6c80539b877d576476d5abfe5bd82c5cc697cec0
Ancestor: 22a09446f5090776e2e30b6168b41a3cd0d81489
Author: gdick at soc.pidgin.im
Date: 2009-08-08T14:53:15
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/6c80539b877d576476d5abfe5bd82c5cc697cec0

Modified files:
        vulture/purpleblist.h vulture/purplequeue.c
        vulture/resource.h vulture/vulture-res.rc
        vulture/vultureblist.c vulture/vulturedlg.c

ChangeLog: 

Context menus for groups and empty space.

-------------- next part --------------
============================================================
--- vulture/purpleblist.h	76b62c45b8c961e4ded167979bb30f245a79c6d7
+++ vulture/purpleblist.h	a102a0ab2c8996e6a5055570c0efcde56353f5b4
@@ -39,6 +39,7 @@ typedef struct _VULTURE_JOIN_CHAT_DATA
 	LPTSTR			szAlias;
 	VULTURE_BLIST_NODE	*lpvblistnodeGroup;
 	BOOL			bJoinFieldsOnly;
+	LPTSTR			szInitGroup;
 } VULTURE_JOIN_CHAT_DATA;
 
 
@@ -49,6 +50,7 @@ typedef struct _VULTURE_ADD_BUDDY_DATA
 	LPTSTR			szAlias;
 	VULTURE_BLIST_NODE	*lpvblistnodeGroup;
 	BOOL			bIMFieldsOnly;
+	LPTSTR			szInitGroup;
 } VULTURE_ADD_BUDDY_DATA;
 
 
============================================================
--- vulture/purplequeue.c	13b19a79a65e5e88917e3e36964fafba7e6aed94
+++ vulture/purplequeue.c	03539c890a5b7bb241d33a7a0eb3760588c3abf1
@@ -375,6 +375,9 @@ static void DispatchPurpleCall(PURPLE_CA
 					}
 				}
 			LeaveCriticalSection(&lpvblnstringpair->lpvblistnode->cs);
+
+			VultureBListNodeAddRef(lpvblnstringpair->lpvblistnode);
+			VulturePostUIMessage(VUIMSG_UPDATEBLISTNODE, lpvblnstringpair->lpvblistnode);
 		}
 
 		break;
============================================================
--- vulture/resource.h	153e1cc7ffdc425ec3efb777bdb5972e7b5d6f4b
+++ vulture/resource.h	b3f60211860b0038910dc212efe4b516fffdf262
@@ -66,6 +66,9 @@
 #define IDM_BLIST_CONTEXT_AUTOJOIN	40213
 #define IDM_BLIST_CONTEXT_PROPERTIES	40214
 #define IDM_BLIST_CONTEXT_COLLAPSE	40215
+#define IDM_BLIST_CONTEXT_ADDBUDDY      40216
+#define IDM_BLIST_CONTEXT_ADDCHAT       40217
+#define IDM_BLIST_CONTEXT_ADDGROUP      40218
 
 #define IDM_CONV			1003
 #define IDM_CONV_CONV_CLOSE		40401
============================================================
--- vulture/vulture-res.rc	7585d321ecc9e90b7bb85761470898965ac9fa32
+++ vulture/vulture-res.rc	cc94c74d7b211e3e438bbac44f0e2f4e833a7ebc
@@ -119,6 +119,24 @@ IDM_BLIST_CONTEXT MENUEX
 		MENUITEM "", 0, MFT_SEPARATOR
 		MENUITEM "&Properties", IDM_BLIST_CONTEXT_PROPERTIES, MFT_STRING, MFS_GRAYED
 	}
+
+	POPUP "Group"
+	{
+		MENUITEM "Add &buddy...", IDM_BLIST_CONTEXT_ADDBUDDY, MFT_STRING
+		MENUITEM "Add &chat...", IDM_BLIST_CONTEXT_ADDCHAT, MFT_STRING
+		MENUITEM "", 0, MFT_SEPARATOR
+		MENUITEM "&Rename", IDM_BLIST_CONTEXT_ALIAS, MFT_STRING
+		MENUITEM "&Delete", IDM_BLIST_CONTEXT_REMOVE, MFT_STRING
+		MENUITEM "", 0, MFT_SEPARATOR
+		CONTEXT_CUSTOMICON
+	}
+
+	POPUP "Empty Space"
+	{
+		MENUITEM "Add &buddy...", IDM_BLIST_CONTEXT_ADDBUDDY, MFT_STRING
+		MENUITEM "Add &chat...", IDM_BLIST_CONTEXT_ADDCHAT, MFT_STRING
+		MENUITEM "Add &group...", IDM_BLIST_CONTEXT_ADDGROUP, MFT_STRING
+	}
 }
 
 
============================================================
--- vulture/vultureblist.c	250d5a788290fbaa2ba53caa0db8633042eb30d0
+++ vulture/vultureblist.c	17b209f4e93b1fc419912330ed7daee01203cd51
@@ -65,6 +65,9 @@ static void InvalidateBListNodeIconCache
 static void DrawBListNodeExtra(LPNMTVCUSTOMDRAW lpnmtvcdraw);
 static HBITMAP GetBListNodeIcon(VULTURE_BLIST_NODE *lpvblistnode);
 static void InvalidateBListNodeIconCache(VULTURE_BLIST_NODE *lpvblistnode);
+static void RequestAddChat(HWND hwndParent, LPTSTR szAlias, LPTSTR szInitGroup);
+static void RequestAddBuddy(HWND hwndParent, LPTSTR szUsername, LPTSTR szAlias, LPTSTR szInitGroup);
+static void RequestAddGroup(HWND hwndParent);
 
 
 #define BLIST_MARGIN		6
@@ -78,6 +81,8 @@ enum CONTEXT_MENU_INDICES
 	CMI_CONTACT_COMPOSITE,
 	CMI_CONTACT_BASIC,
 	CMI_CHAT,
+	CMI_GROUP,
+	CMI_EMPTYSPACE,
 };
 
 
@@ -217,58 +222,15 @@ static LRESULT CALLBACK MainWndProc(HWND
 			return 0;
 
 		case IDM_BLIST_BUDDIES_ADDBUDDY:
-			{
-				VULTURE_ADD_BUDDY_DATA vabd;
-
-				vabd.bIMFieldsOnly = FALSE;
-
-				if(VultureAddBuddyDlg(hwnd, &vabd))
-				{
-					VultureSingleSyncPurpleCall(PC_ADDBUDDY, &vabd);
-
-					if(vabd.lpvblistnodeGroup)
-						VultureBListNodeRelease(vabd.lpvblistnodeGroup);
-
-					ProcHeapFree(vabd.szUsername);
-					if(vabd.szAlias)
-						ProcHeapFree(vabd.szAlias);
-				}
-			}
-
+			RequestAddBuddy(hwnd, NULL, NULL, NULL);
 			return 0;
 
 		case IDM_BLIST_BUDDIES_ADDCHAT:
-			{
-				VULTURE_JOIN_CHAT_DATA vjcd;
-
-				vjcd.bJoinFieldsOnly = FALSE;
-
-				if(VultureJoinChatDlg(hwnd, &vjcd))
-				{
-					VultureSingleSyncPurpleCall(PC_ADDCHAT, &vjcd);
-
-					if(vjcd.lpvblistnodeGroup)
-						VultureBListNodeRelease(vjcd.lpvblistnodeGroup);
-
-					if(vjcd.szAlias)
-						ProcHeapFree(vjcd.szAlias);
-				}
-			}
-
+			RequestAddChat(hwnd, NULL, NULL);
 			return 0;
 
 		case IDM_BLIST_BUDDIES_ADDGROUP:
-			{
-				LPTSTR szGroup;
-
-				if((szGroup = VultureAddGroupDlg(hwnd)))
-				{
-					VultureSingleSyncPurpleCall(PC_ADDGROUP, szGroup);
-
-					ProcHeapFree(szGroup);
-				}
-			}
-
+			RequestAddGroup(hwnd);
 			return 0;
 
 		case IDM_BLIST_BUDDIES_CLOSE:
@@ -675,17 +637,22 @@ static INT_PTR CALLBACK BuddyListDlgProc
 				case NM_RCLICK:
 					{
 						TVITEM tvitem;
+						HMENU hmenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_BLIST_CONTEXT));
+						HMENU hmenuSubmenu = NULL;
+						GList *lpglistVMA = NULL;
+						VULTURE_MAKE_CONTEXT_MENU vmcm;
+						VULTURE_BLIST_NODE *lpvblistnode = NULL;
+						TVHITTESTINFO tvhti;
+						DWORD dwMouse;
 
-						tvitem.hItem = TreeView_GetDropHilight(lpnmhdr->hwndFrom);
-						if(!tvitem.hItem) tvitem.hItem = TreeView_GetSelection(lpnmhdr->hwndFrom);
+						dwMouse = GetMessagePos();
+						tvhti.pt.x = (short)(dwMouse & 0xFFFF);
+						tvhti.pt.y = (short)(dwMouse >> 16);
+						ScreenToClient(lpnmhdr->hwndFrom, &tvhti.pt);
+						SendMessage(lpnmhdr->hwndFrom, TVM_HITTEST, 0, (LPARAM)&tvhti);
 
-						if(tvitem.hItem)
+						if((tvitem.hItem = tvhti.hItem))
 						{
-							VULTURE_BLIST_NODE *lpvblistnode;
-							HMENU hmenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_BLIST_CONTEXT));
-							HMENU hmenuSubmenu = NULL;
-							GList *lpglistVMA = NULL;
-							VULTURE_MAKE_CONTEXT_MENU vmcm;
 
 							/* Really select this node. */
 							TreeView_SelectItem(lpnmhdr->hwndFrom, tvitem.hItem);
@@ -721,6 +688,10 @@ static INT_PTR CALLBACK BuddyListDlgProc
 									hmenuSubmenu = GetSubMenu(hmenu, CMI_CHAT);
 									break;
 
+								case PURPLE_BLIST_GROUP_NODE:
+									hmenuSubmenu = GetSubMenu(hmenu, CMI_GROUP);
+									break;
+
 								default:
 									vmcm.bExtraItems = FALSE;
 									break;
@@ -732,16 +703,24 @@ static INT_PTR CALLBACK BuddyListDlgProc
 							vmcm.lplpglistVMA = &lpglistVMA;
 
 							VultureSingleSyncPurpleCall(PC_MAKECONTEXTMENU, &vmcm);
+						}
+						else
+						{
+							TreeView_SelectItem(lpnmhdr->hwndFrom, NULL);
+							hmenuSubmenu = GetSubMenu(hmenu, CMI_EMPTYSPACE);
+						}
 
-							if(hmenuSubmenu)
-							{
-								POINT ptMouse;
-								int iCmd;
+						if(hmenuSubmenu)
+						{
+							POINT ptMouse;
+							int iCmd;
 
-								GetCursorPos(&ptMouse);
-								iCmd = TrackPopupMenu(hmenuSubmenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, ptMouse.x, ptMouse.y, 0, hwndDlg, NULL);
+							GetCursorPos(&ptMouse);
+							iCmd = TrackPopupMenu(hmenuSubmenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, ptMouse.x, ptMouse.y, 0, hwndDlg, NULL);
 
-								if(iCmd != 0)
+							if(iCmd != 0)
+							{
+								if(lpvblistnode)
 								{
 									switch(lpvblistnode->nodetype)
 									{
@@ -752,30 +731,36 @@ static INT_PTR CALLBACK BuddyListDlgProc
 									case PURPLE_BLIST_CHAT_NODE:
 										RunChatMenuCmd(lpnmhdr->hwndFrom, lpvblistnode, hmenuSubmenu, iCmd);
 										break;
+									case PURPLE_BLIST_GROUP_NODE:
+										RunCommonMenuCmd(lpnmhdr->hwndFrom, lpvblistnode, hmenuSubmenu, iCmd);
+										break;
 									default:
 										break;
 									}
 								}
+								else
+									RunCommonMenuCmd(lpnmhdr->hwndFrom, NULL, hmenuSubmenu, iCmd);
 							}
+						}
 
+						if(lpvblistnode)
 							VultureBListNodeRelease(lpvblistnode);
 
-							/* Destroy menu. This will also destroy our modifications. */
-							DestroyMenu(hmenu);
+						/* Destroy menu. This will also destroy our modifications. */
+						DestroyMenu(hmenu);
 
-							/* Clean up any extra data we might have as a result of
-							 * having modified the menu.
-							 */
-							g_list_foreach(lpglistVMA, (GFunc)g_free, NULL);
-							g_list_free(lpglistVMA);
+						/* Clean up any extra data we might have as a result of
+						 * having modified the menu.
+						 */
+						g_list_foreach(lpglistVMA, (GFunc)g_free, NULL);
+						g_list_free(lpglistVMA);
 
-							/* Prevent spurious right-click messages being sent
-							 * elsewhere.
-							 */
-							SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
+						/* Prevent spurious right-click messages being sent
+						 * elsewhere.
+						 */
+						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
 
-							return TRUE;
-						}
+						return TRUE;
 					}
 
 					break;
@@ -1160,8 +1145,6 @@ static BOOL RunCommonMenuCmd(HWND hwndBu
  */
 static BOOL RunCommonMenuCmd(HWND hwndBuddies, VULTURE_BLIST_NODE *lpvblistnode, HMENU hmenu, int iCmd)
 {
-	UNREFERENCED_PARAMETER(hmenu);
-
 	switch(iCmd)
 	{
 	case IDM_BLIST_CONTEXT_ACTIVATE:
@@ -1213,6 +1196,38 @@ static BOOL RunCommonMenuCmd(HWND hwndBu
 			VultureSingleSyncPurpleCall(PC_SETCUSTOMICON, &vblnstringpairNewIcon);
 		}
 
+		return TRUE;
+
+	case IDM_BLIST_CONTEXT_ADDBUDDY:
+	case IDM_BLIST_CONTEXT_ADDCHAT:
+		{
+			LPTSTR szGroup = NULL;
+
+			if(lpvblistnode)
+			{
+				EnterCriticalSection(&lpvblistnode->cs);
+				{
+					if(lpvblistnode->nodetype == PURPLE_BLIST_GROUP_NODE && lpvblistnode->szNodeText)
+						szGroup = _tcsdup(lpvblistnode->szNodeText);
+				}
+				LeaveCriticalSection(&lpvblistnode->cs);
+			}
+
+			if(iCmd == IDM_BLIST_CONTEXT_ADDBUDDY)
+				RequestAddBuddy(g_hwndMain, NULL, NULL, szGroup);
+			else
+				RequestAddChat(g_hwndMain, NULL, szGroup);
+
+			if(szGroup)
+				free(szGroup);
+		}
+
+		return TRUE;
+
+	case IDM_BLIST_CONTEXT_ADDGROUP:
+		RequestAddGroup(g_hwndMain);
+		return TRUE;
+
 	default:
 		/* Not a static command that we recongise; might be a dynamic
 		 * command.
@@ -1299,6 +1314,7 @@ static void UpdateBListNode(HWND hwndBli
 static void UpdateBListNode(HWND hwndBlistTree, VULTURE_BLIST_NODE *lpvbn)
 {
 	TVITEMEX tvitemex;
+	HBITMAP hbmIcon;
 
 	if(lpvbn->hti)
 	{
@@ -1340,12 +1356,13 @@ static void UpdateBListNode(HWND hwndBli
 	}
 
 	/* Set height. */
+	hbmIcon = GetBListNodeIcon(lpvbn);
 	EnterCriticalSection(&lpvbn->cs);
 	{
 		tvitemex.mask = TVIF_HANDLE | TVIF_INTEGRAL;
 		tvitemex.hItem = lpvbn->hti;
 		tvitemex.iIntegral =
-			((lpvbn->nodetype == PURPLE_BLIST_CONTACT_NODE && lpvbn->bExpanded) || lpvbn->nodetype == PURPLE_BLIST_GROUP_NODE) ?
+			(!hbmIcon && ((lpvbn->nodetype == PURPLE_BLIST_CONTACT_NODE && lpvbn->bExpanded) || lpvbn->nodetype == PURPLE_BLIST_GROUP_NODE)) ?
 			1 :
 			2;
 	}
@@ -1536,3 +1553,80 @@ static void InvalidateBListNodeIconCache
 		lpvblistnode->ui.bIconCacheValid = FALSE;
 	}
 }
+
+
+/**
+ * Shows the "Add Chat" UI and adds the chat if confirmed.
+ *
+ * @param	hwndParent	Parent window handle for dialogue.
+ * @param	szAlias		Initial alias. May be NULL.
+ * @param	szInitGroup	Initial group name. May be NULL.
+ */
+static void RequestAddChat(HWND hwndParent, LPTSTR szAlias, LPTSTR szInitGroup)
+{
+	VULTURE_JOIN_CHAT_DATA vjcd;
+
+	vjcd.bJoinFieldsOnly = FALSE;
+	vjcd.szAlias = szAlias;
+	vjcd.szInitGroup = szInitGroup;
+
+	if(VultureJoinChatDlg(hwndParent, &vjcd))
+	{
+		VultureSingleSyncPurpleCall(PC_ADDCHAT, &vjcd);
+
+		if(vjcd.lpvblistnodeGroup)
+			VultureBListNodeRelease(vjcd.lpvblistnodeGroup);
+
+		if(vjcd.szAlias)
+			ProcHeapFree(vjcd.szAlias);
+	}
+}
+
+
+/**
+ * Shows the "Add Buddy" UI and adds the buddy if confirmed.
+ *
+ * @param	hwndParent	Parent window handle for dialogue.
+ * @param	szUsername	Initial username. May be NULL.
+ * @param	szAlias		Initial alias. May be NULL.
+ * @param	szInitGroup	Initial group name. May be NULL.
+ */
+static void RequestAddBuddy(HWND hwndParent, LPTSTR szUsername, LPTSTR szAlias, LPTSTR szInitGroup)
+{
+	VULTURE_ADD_BUDDY_DATA vabd;
+
+	vabd.bIMFieldsOnly = FALSE;
+	vabd.szAlias = szAlias;
+	vabd.szInitGroup = szInitGroup;
+	vabd.szUsername = szUsername;
+
+	if(VultureAddBuddyDlg(hwndParent, &vabd))
+	{
+		VultureSingleSyncPurpleCall(PC_ADDBUDDY, &vabd);
+
+		if(vabd.lpvblistnodeGroup)
+			VultureBListNodeRelease(vabd.lpvblistnodeGroup);
+
+		ProcHeapFree(vabd.szUsername);
+		if(vabd.szAlias)
+			ProcHeapFree(vabd.szAlias);
+	}
+}
+
+
+/**
+ * Shows the "Add Group" UI and adds the group if confirmed.
+ *
+ * @param	hwndParent	Parent window handle for dialogue.
+ */
+static void RequestAddGroup(HWND hwndParent)
+{
+	LPTSTR szGroup;
+
+	if((szGroup = VultureAddGroupDlg(hwndParent)))
+	{
+		VultureSingleSyncPurpleCall(PC_ADDGROUP, szGroup);
+
+		ProcHeapFree(szGroup);
+	}
+}
============================================================
--- vulture/vulturedlg.c	1c4c19b6dffeed35a510fa52f1de19bce04e9b88
+++ vulture/vulturedlg.c	a3d87d6092bcf986ecb65d21e25ab0b53210ddd4
@@ -159,13 +159,25 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 
 			if(!lpvjcd->bJoinFieldsOnly)
 			{
+				if(lpvjcd->szAlias)
+					SetDlgItemText(hwndDlg, IDC_EDIT_ALIAS, lpvjcd->szAlias);
+
 				/* Get all groups. */
 				VultureSingleSyncPurpleCall(PC_GETGROUPS, &s_lpglistGroups);
 
-				/* Populate combo and select first item. */
+				/* Populate combo and select appropriate item. */
 				PopulateGroupsCombo(GetDlgItem(hwndDlg, IDC_CBEX_GROUP), s_lpglistGroups);
+
 				if(SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_GETCOUNT, 0, 0) > 0)
-					SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_SETCURSEL, 0, 0);
+				{
+					/* Maybe override this with given group. */
+					if(lpvjcd->szInitGroup)
+					{
+						LRESULT lIndex = SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_FINDSTRINGEXACT, -1, (LPARAM)lpvjcd->szInitGroup);
+						if(lIndex != CB_ERR)
+							SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_SETCURSEL, lIndex, 0);
+					}
+				}
 			}
 
 			AutoEnableJoinDlgOKButton(hwndDlg, s_lpglistFields);
@@ -223,9 +235,18 @@ static INT_PTR CALLBACK JoinChatDlgProc(
 					/* Get the selected group. */
 					cbexitem.mask = CBEIF_LPARAM;
 					cbexitem.iItem = SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_GETCURSEL, 0, 0);
-					SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
-					lpvjcd->lpvblistnodeGroup = (VULTURE_BLIST_NODE*)cbexitem.lParam;
+					
+					if(cbexitem.iItem != CB_ERR)
+					{
+						SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
+						lpvjcd->lpvblistnodeGroup = (VULTURE_BLIST_NODE*)cbexitem.lParam;
 
+						if(lpvjcd->lpvblistnodeGroup)
+							VultureBListNodeAddRef(lpvjcd->lpvblistnodeGroup);
+					}
+					else
+						lpvjcd->lpvblistnodeGroup = NULL;
+
 					if(lpvjcd->lpvblistnodeGroup)
 						VultureBListNodeAddRef(lpvjcd->lpvblistnodeGroup);
 
@@ -577,16 +598,16 @@ static INT_PTR CALLBACK AddBuddyDlgProc(
 {
 	static GList *s_lpglistAccounts = NULL;
 	static GList *s_lpglistGroups = NULL;
-	static VULTURE_ADD_BUDDY_DATA *s_lpvabd = NULL;
 
 	switch(uiMsg)
 	{
 	case WM_INITDIALOG:
 		{
 			VULTURE_GET_ACCOUNTS vgetaccounts;
+			VULTURE_ADD_BUDDY_DATA *lpvabd = (VULTURE_ADD_BUDDY_DATA*)lParam;
 
 			/* We return stuff here. */
-			s_lpvabd = (VULTURE_ADD_BUDDY_DATA*)lParam;
+			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
 
 			/* Get online accounts. */
 			vgetaccounts.bOnlineOnly = TRUE;
@@ -598,15 +619,31 @@ static INT_PTR CALLBACK AddBuddyDlgProc(
 			if(SendDlgItemMessage(hwndDlg, IDC_CBEX_ACCOUNTS, CB_GETCOUNT, 0, 0) > 0)
 				SendDlgItemMessage(hwndDlg, IDC_CBEX_ACCOUNTS, CB_SETCURSEL, 0, 0);
 
-			if(!s_lpvabd->bIMFieldsOnly)
+			/* Initial value. */
+			if(lpvabd->szUsername)
+				SetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, lpvabd->szUsername);
+
+			if(!lpvabd->bIMFieldsOnly)
 			{
+				if(lpvabd->szAlias)
+					SetDlgItemText(hwndDlg, IDC_EDIT_ALIAS, lpvabd->szAlias);
+
 				/* Get all groups. */
 				VultureSingleSyncPurpleCall(PC_GETGROUPS, &s_lpglistGroups);
 
-				/* Populate combo and select first item. */
+				/* Populate combo and select appropriate item. */
 				PopulateGroupsCombo(GetDlgItem(hwndDlg, IDC_CBEX_GROUP), s_lpglistGroups);
+
 				if(SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_GETCOUNT, 0, 0) > 0)
-					SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_SETCURSEL, 0, 0);
+				{
+					/* Maybe override this with given group. */
+					if(lpvabd->szInitGroup)
+					{
+						LRESULT lIndex = SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_FINDSTRINGEXACT, -1, (LPARAM)lpvabd->szInitGroup);
+						if(lIndex != CB_ERR)
+							SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_SETCURSEL, lIndex, 0);
+					}
+				}
 			}
 
 			AutoEnableBuddyDlgOKButton(hwndDlg);
@@ -628,37 +665,44 @@ static INT_PTR CALLBACK AddBuddyDlgProc(
 			{
 				COMBOBOXEXITEM cbexitem;
 				int cch;
+				VULTURE_ADD_BUDDY_DATA *lpvabd = (VULTURE_ADD_BUDDY_DATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
 
 				/* Get the selected account. */
 				cbexitem.mask = CBEIF_LPARAM;
 				cbexitem.iItem = SendDlgItemMessage(hwndDlg, IDC_CBEX_ACCOUNTS, CB_GETCURSEL, 0, 0);
 				SendDlgItemMessage(hwndDlg, IDC_CBEX_ACCOUNTS, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
-				s_lpvabd->lppac = ((VULTURE_ACCOUNT*)cbexitem.lParam)->lppac;
+				lpvabd->lppac = ((VULTURE_ACCOUNT*)cbexitem.lParam)->lppac;
 
 				/* Get username. */
 				cch = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_EDIT_USERNAME)) + 1;
-				s_lpvabd->szUsername = ProcHeapAlloc(cch * sizeof(TCHAR));
-				GetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, s_lpvabd->szUsername, cch);
+				lpvabd->szUsername = ProcHeapAlloc(cch * sizeof(TCHAR));
+				GetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, lpvabd->szUsername, cch);
 
-				if(!s_lpvabd->bIMFieldsOnly)
+				if(!lpvabd->bIMFieldsOnly)
 				{
 					/* Get the selected group. */
 					cbexitem.mask = CBEIF_LPARAM;
 					cbexitem.iItem = SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CB_GETCURSEL, 0, 0);
-					SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
-					s_lpvabd->lpvblistnodeGroup = (VULTURE_BLIST_NODE*)cbexitem.lParam;
 
-					if(s_lpvabd->lpvblistnodeGroup)
-						VultureBListNodeAddRef(s_lpvabd->lpvblistnodeGroup);
+					if(cbexitem.iItem != CB_ERR)
+					{
+						SendDlgItemMessage(hwndDlg, IDC_CBEX_GROUP, CBEM_GETITEM, 0, (LPARAM)&cbexitem);
+						lpvabd->lpvblistnodeGroup = (VULTURE_BLIST_NODE*)cbexitem.lParam;
 
+						if(lpvabd->lpvblistnodeGroup)
+							VultureBListNodeAddRef(lpvabd->lpvblistnodeGroup);
+					}
+					else
+						lpvabd->lpvblistnodeGroup = NULL;
+
 					cch = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_EDIT_ALIAS)) + 1;
 					if(cch > 1)
 					{
-						s_lpvabd->szAlias = ProcHeapAlloc(cch * sizeof(TCHAR));
-						GetDlgItemText(hwndDlg, IDC_EDIT_ALIAS, s_lpvabd->szAlias, cch);
+						lpvabd->szAlias = ProcHeapAlloc(cch * sizeof(TCHAR));
+						GetDlgItemText(hwndDlg, IDC_EDIT_ALIAS, lpvabd->szAlias, cch);
 					}
 					else
-						s_lpvabd->szAlias = NULL;
+						lpvabd->szAlias = NULL;
 				}
 
 				EndDialog(hwndDlg, TRUE);


More information about the Commits mailing list