Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

956 lines
30 KiB

  1. // baprop.cpp
  2. // WAB & Messenger integration to OE
  3. // Created 06/23/98 by YST
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "pch.hxx"
  7. #include "msoert.h"
  8. #include "hotlinks.h"
  9. #include "shlwapi.h"
  10. #include "badata.h"
  11. #include "baprop.h"
  12. #include "bllist.h"
  13. #include "baui.h"
  14. #include "shlwapip.h"
  15. // #include "demand.h"
  16. // #include "mailnews.h"
  17. // #include "menuutil.h"
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[]=__FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23. #define MAX_SUMMARY_ID 13
  24. #define Msgr_Index 0
  25. extern ULONG MsgrPropTags[];
  26. extern ULONG PR_MSGR_DEF_ID;
  27. // static WCHAR szDefault[CCHMAX_STRINGRES]; // TEXT(" (default)");
  28. // static WCHAR szPending[CCHMAX_STRINGRES]; // TEXT(" (Pending...)");
  29. const LPWSTR szDomainSeparator = L"@";
  30. const LPWSTR szSMTP = L"SMTP";
  31. #define PROP_ERROR(prop) (PROP_TYPE(prop.ulPropTag) == PT_ERROR)
  32. static int nDefault = -1;
  33. static HFONT hBold = NULL;
  34. static HFONT hNormal = NULL;
  35. static CMsgrList *s_pMsgrList = NULL;
  36. static SizedSPropTagArray(1, pTagProp)=
  37. {
  38. 1,
  39. {
  40. PR_EMAIL_ADDRESS,
  41. }
  42. };
  43. ///$$/////////////////////////////////////////////////////////////////////////
  44. //
  45. // AddCBEmailItem - Adds an email address to the personal tab list view
  46. //
  47. // lpszAddrType can be NULL in which case a default one of type SMTP will be used
  48. //
  49. //////////////////////////////////////////////////////////////////////////////
  50. void AddCBEmailItem(HWND hWndCB,
  51. LPWSTR lpwszEmailAddress,
  52. BOOL fDefault,
  53. LPWSTR lpwszPendName)
  54. {
  55. WCHAR szBuf[CCHMAX_STRINGRES];
  56. WCHAR szTmp[CCHMAX_STRINGRES];
  57. LV_ITEMW lvi = {0};
  58. UINT nSim = 0;
  59. int index = -1;
  60. StrCpyNW(szTmp, lpwszEmailAddress, ARRAYSIZE(szTmp));
  61. // TCHAR *pch = StrStr(CharUpper(szTmp), szHotMail);
  62. // if(pch != NULL)
  63. nSim = lstrlenW(szTmp); //(UINT) (pch - szTmp + 1);
  64. Assert(nSim < CCHMAX_STRINGRES);
  65. if(nSim > 0)
  66. {
  67. if(nSim > ((UINT) (CCHMAX_STRINGRES - 2)))
  68. {
  69. nSim = CCHMAX_STRINGRES - 2;
  70. StrCpyNW(szBuf, lpwszEmailAddress, nSim);
  71. szBuf[nSim] = L'\0';
  72. }
  73. else
  74. StrCpyNW(szBuf, szTmp, ARRAYSIZE(szBuf));
  75. if(fDefault)
  76. {
  77. if(s_pMsgrList)
  78. {
  79. #ifdef LATER
  80. if(s_pMsgrList->FindAndDeleteUser(lpwszEmailAddress, FALSE /*fDelete*/) == S_OK)
  81. StrCatBuff(szBuf, szDefault, ARRAYSIZE(szBuf));
  82. else if(!lstrcmpiW(lpwszPendName, lpwszEmailAddress))
  83. StrCatBuff(szBuf, szPending, ARRAYSIZE(szBuf));
  84. #endif //LATER
  85. }
  86. }
  87. lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
  88. lvi.iImage = IMAGE_EMPTY;
  89. lvi.pszText = szBuf;
  90. lvi.cchTextMax = 256; //nSim;
  91. lvi.iItem = ListView_GetItemCount(hWndCB);
  92. lvi.iSubItem = 0;
  93. lvi.lParam = fDefault;
  94. index = ListView_InsertItem(hWndCB, &lvi);
  95. if(fDefault)
  96. nDefault = index;
  97. }
  98. return;
  99. }
  100. #ifdef LATER
  101. const static HELPMAP g_rgCtxWabExt[] =
  102. {
  103. {IDC_MSGR_ID_EDIT, IDH_WAB_ONLINE_ADDNEW},
  104. {IDC_MSGR_ADD, IDH_WAB_ONLINE_ADD},
  105. {IDC_MSGR_BUTTON_SETDEFAULT, IDH_WAB_ONLINE_SETAS},
  106. {IDC_SEND_INSTANT_MESSAGE, IDH_WAB_ONLINE_SENDIM},
  107. {IDC_USER_NAME, IDH_WAB_ONLINE_LIST},
  108. {idcStatic1, IDH_NEWS_COMM_GROUPBOX},
  109. {idcStatic2, IDH_NEWS_COMM_GROUPBOX},
  110. {idcStatic3, IDH_NEWS_COMM_GROUPBOX},
  111. {idcStatic4, IDH_NEWS_COMM_GROUPBOX},
  112. {idcStatic5, IDH_NEWS_COMM_GROUPBOX},
  113. {idcStatic6, IDH_NEWS_COMM_GROUPBOX},
  114. {idcStatic7, IDH_NEWS_COMM_GROUPBOX},
  115. {0, 0}
  116. };
  117. #endif
  118. INT_PTR CALLBACK WabExtDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  119. {
  120. #ifdef LATER
  121. LPWABEXTDISPLAY lpWED = (LPWABEXTDISPLAY) GetWindowLongPtr(hDlg, DWLP_USER);
  122. DWORD dwError = 0;
  123. HIMAGELIST himl = NULL;
  124. switch (msg)
  125. {
  126. case WM_INITDIALOG:
  127. {
  128. PROPSHEETPAGE * pps = (PROPSHEETPAGE *) lParam;
  129. LPWABEXTDISPLAY * lppWED = (LPWABEXTDISPLAY *) pps->lParam;
  130. SetWindowLongPtr(hDlg,DWLP_USER,lParam);
  131. // Add two columns to the listview
  132. LVCOLUMN lvc;
  133. RECT rc;
  134. HWND ctlList = GetDlgItem(hDlg, IDC_USER_NAME);
  135. s_pMsgrList = OE_OpenMsgrList();
  136. // one column
  137. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  138. lvc.fmt = LVCFMT_LEFT;
  139. lvc.iSubItem = 0;
  140. GetWindowRect(ctlList,&rc);
  141. lvc.cx = rc.right - rc.left - 20; //TBD
  142. ListView_InsertColumn(ctlList, 0, &lvc);
  143. if(lppWED)
  144. {
  145. SetWindowLongPtr(hDlg,DWLP_USER,(LPARAM)*lppWED);
  146. lpWED = *lppWED;
  147. }
  148. InitFonts();
  149. AthLoadString(idsBADefault, szDefault, ARRAYSIZE(szDefault));
  150. AthLoadString(idsBADispStatus, szPending, ARRAYSIZE(szPending));
  151. // ListView_SetExtendedListViewStyle(ctlList, LVS_EX_FULLROWSELECT);
  152. himl = ImageList_LoadImage(g_hLocRes, MAKEINTRESOURCE(idbAddrBookHot), 18, 0,
  153. RGB(255, 0, 255), IMAGE_BITMAP,
  154. LR_LOADMAP3DCOLORS | LR_CREATEDIBSECTION);
  155. ListView_SetImageList(ctlList, himl, LVSIL_SMALL);
  156. AddAccountsToList(hDlg, lpWED);
  157. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_ADD),FALSE);
  158. }
  159. break;
  160. case WM_CONTEXTMENU:
  161. case WM_HELP:
  162. return OnContextHelp(hDlg, msg, wParam, lParam, g_rgCtxWabExt);
  163. break;
  164. case WM_COMMAND:
  165. {
  166. switch(HIWORD(wParam)) // Notification code
  167. {
  168. case EN_CHANGE:
  169. {
  170. if(LOWORD(wParam) == IDC_MSGR_ID_EDIT)
  171. {
  172. if(GetWindowTextLength(GetDlgItem(hDlg, IDC_MSGR_ID_EDIT)) > 0)
  173. {
  174. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_ADD),TRUE);
  175. SendMessage(GetParent(hDlg), DM_SETDEFID, IDC_MSGR_ADD, 0);
  176. }
  177. else
  178. {
  179. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_ADD),FALSE);
  180. SendMessage(GetParent(hDlg), DM_SETDEFID, IDOK, 0);
  181. }
  182. }
  183. break;
  184. }
  185. }
  186. switch(LOWORD(wParam)) // commands
  187. {
  188. case IDC_MSGR_BUTTON_SETDEFAULT:
  189. SetAsDefault(hDlg, lpWED);
  190. break;
  191. case IDC_MSGR_ADD:
  192. AddMsgrId(hDlg, lpWED);
  193. break;
  194. case IDC_SEND_INSTANT_MESSAGE:
  195. WabSendIMsg(hDlg, lpWED);
  196. break;
  197. default:
  198. break;
  199. }
  200. }
  201. break;
  202. case WM_NOTIFY:
  203. {
  204. switch (((NMHDR FAR *) lParam)->code)
  205. {
  206. case PSN_APPLY:
  207. ::SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  208. DeleteFonts();
  209. if(s_pMsgrList)
  210. OE_CloseMsgrList(s_pMsgrList);
  211. break;
  212. case PSN_SETACTIVE:
  213. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_USER_NAME));
  214. AddAccountsToList(hDlg, lpWED);
  215. break;
  216. case PSN_KILLACTIVE:
  217. AddMsgrId(hDlg, lpWED);
  218. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  219. return 1;
  220. break;
  221. case PSN_RESET:
  222. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  223. DeleteFonts();
  224. if(s_pMsgrList)
  225. OE_CloseMsgrList(s_pMsgrList);
  226. break;
  227. case LVN_ITEMCHANGED:
  228. {
  229. int nItem = ListView_GetNextItem(::GetDlgItem(hDlg, IDC_USER_NAME), -1, LVIS_SELECTED);
  230. if((nItem != nDefault) && (nItem > -1))
  231. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_BUTTON_SETDEFAULT),TRUE);
  232. else
  233. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_BUTTON_SETDEFAULT),FALSE);
  234. if(WabIsItemOnline(hDlg, nItem))
  235. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),TRUE);
  236. else
  237. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),FALSE);
  238. }
  239. break;
  240. case NM_CUSTOMDRAW:
  241. switch(wParam)
  242. {
  243. case IDC_USER_NAME:
  244. {
  245. NMCUSTOMDRAW *pnmcd=(NMCUSTOMDRAW*)lParam;
  246. NM_LISTVIEW * pNm = (NM_LISTVIEW *)lParam;
  247. if(pnmcd->dwDrawStage==CDDS_PREPAINT)
  248. {
  249. SetLastError(0);
  250. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW | CDRF_DODEFAULT);
  251. dwError = GetLastError();
  252. return TRUE;
  253. }
  254. else if(pnmcd->dwDrawStage==CDDS_ITEMPREPAINT)
  255. {
  256. if(pnmcd->lItemlParam)
  257. {
  258. SelectObject(((NMLVCUSTOMDRAW*)lParam)->nmcd.hdc, hBold);
  259. SetLastError(0);
  260. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  261. dwError = GetLastError();
  262. return TRUE;
  263. }
  264. else
  265. {
  266. SelectObject(((NMLVCUSTOMDRAW*)lParam)->nmcd.hdc, hNormal);
  267. SetLastError(0);
  268. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  269. dwError = GetLastError();
  270. return TRUE;
  271. }
  272. }
  273. SetLastError(0);
  274. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_DODEFAULT);
  275. dwError = GetLastError();
  276. return TRUE;
  277. }
  278. break;
  279. default:
  280. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_DODEFAULT);
  281. return TRUE;
  282. break;
  283. }
  284. break;
  285. }
  286. }
  287. break;
  288. }
  289. #endif
  290. return FALSE;
  291. }
  292. void AddAccountsToList(HWND hDlg, LPWABEXTDISPLAY lpWED, LPWSTR lpwszPendName)
  293. {
  294. #ifdef LATER
  295. // LPWABEXTDISPLAY lpWED = (LPWABEXTDISPLAY) GetWindowLongPtr(hDlg, DWLP_USER);
  296. ULONG ulcPropCount = 0;
  297. LPSPropValue lpPropArray = NULL;
  298. ULONG i = 0;
  299. LPSPropValue lpPropEmail = NULL;
  300. LPSPropValue lpPropAddrType = NULL;
  301. LPSPropValue lpPropMVEmail = NULL;
  302. LPSPropValue lpPropMVAddrType = NULL;
  303. LPSPropValue lpPropDefaultIndex = NULL;
  304. LPSPropValue lpMsgrDevId = NULL;
  305. HWND ctlList = GetDlgItem(hDlg, IDC_USER_NAME);
  306. Assert(ctlList);
  307. Assert(PR_MSGR_DEF_ID);
  308. nDefault = -1;
  309. if(!lpWED)
  310. {
  311. Assert(FALSE);
  312. return;
  313. }
  314. if(!HR_FAILED(lpWED->lpPropObj->GetProps(NULL, 0,
  315. &ulcPropCount,
  316. &lpPropArray)))
  317. {
  318. if(ulcPropCount && lpPropArray)
  319. {
  320. for(i = 0; i < ulcPropCount; i++)
  321. {
  322. switch(lpPropArray[i].ulPropTag)
  323. {
  324. case PR_EMAIL_ADDRESS:
  325. lpPropEmail = &(lpPropArray[i]);
  326. break;
  327. case PR_ADDRTYPE:
  328. lpPropAddrType = &(lpPropArray[i]);
  329. break;
  330. case PR_CONTACT_EMAIL_ADDRESSES:
  331. lpPropMVEmail = &(lpPropArray[i]);
  332. break;
  333. case PR_CONTACT_ADDRTYPES:
  334. lpPropMVAddrType = &(lpPropArray[i]);
  335. break;
  336. case PR_CONTACT_DEFAULT_ADDRESS_INDEX:
  337. lpPropDefaultIndex = &(lpPropArray[i]);
  338. break;
  339. default:
  340. if(lpPropArray[i].ulPropTag == PR_MSGR_DEF_ID)
  341. lpMsgrDevId = &(lpPropArray[i]);
  342. break;
  343. }
  344. }
  345. if(!lpPropEmail && !lpPropMVEmail)
  346. goto Error;
  347. if(lpPropMVEmail)
  348. {
  349. // we have a multiple emails
  350. //Assume, if this is present, so is MVAddrType, and defaultindex
  351. for(i = 0; i < lpPropMVEmail->Value.MVszW.cValues; i++)
  352. {
  353. AddCBEmailItem(ctlList,
  354. lpPropMVEmail->Value.MVszW.lppszW[i],
  355. (lpMsgrDevId ?
  356. ((!lstrcmpiW(lpPropMVEmail->Value.MVszW.lppszW[i], lpMsgrDevId->Value.lpszW)) ? TRUE : FALSE) : FALSE), lpwszPendName);
  357. }
  358. }
  359. else
  360. {
  361. // we dont have multi-valued props yet - lets use the
  362. // single valued ones and tag a change so that the record is
  363. // updated ...
  364. AddCBEmailItem(ctlList,
  365. lpPropEmail->Value.lpszW,
  366. (lpMsgrDevId ?
  367. ((!lstrcmpiW(lpPropEmail->Value.lpszW, lpMsgrDevId->Value.lpszW)) ? TRUE : FALSE) : FALSE), lwpszPendName);
  368. }
  369. }
  370. }
  371. Error:
  372. if(nDefault == -1)
  373. {
  374. if(ListView_GetItemCount(ctlList) > 0) // We have as min 1 item
  375. {
  376. // Select default item
  377. ListView_SetItemState(ctlList, 0,
  378. LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  379. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_BUTTON_SETDEFAULT),TRUE);
  380. // Enable "SendInstant Message only when contact is Online
  381. if(WabIsItemOnline(hDlg, 0))
  382. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),TRUE);
  383. else
  384. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),FALSE);
  385. }
  386. else
  387. {
  388. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),FALSE);
  389. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_BUTTON_SETDEFAULT),FALSE);
  390. }
  391. }
  392. else
  393. {
  394. // Select default item
  395. ListView_SetItemState(ctlList, nDefault,
  396. LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  397. EnableWindow(GetDlgItem(hDlg,IDC_MSGR_BUTTON_SETDEFAULT),FALSE);
  398. // Enable "SendInstant Message only when contact is Online
  399. if(WabIsItemOnline(hDlg, nDefault))
  400. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),TRUE);
  401. else
  402. EnableWindow(GetDlgItem(hDlg,IDC_SEND_INSTANT_MESSAGE),FALSE);
  403. }
  404. if(lpPropArray)
  405. lpWED->lpWABObject->FreeBuffer(lpPropArray);
  406. #endif
  407. return;
  408. }
  409. // Set selected email address as default for Messenger
  410. void SetAsDefault(HWND hDlg, LPWABEXTDISPLAY lpWED)
  411. {
  412. #ifdef LATER
  413. HWND ctlList = ::GetDlgItem(hDlg, IDC_USER_NAME);
  414. TCHAR szName[CCHMAX_STRINGRES];
  415. Assert(ctlList);
  416. int iItem = ListView_GetNextItem(ctlList, -1, LVIS_SELECTED);
  417. if(iItem == -1)
  418. return;
  419. ListView_GetItemText(ctlList, iItem, 0,szName, CCHMAX_STRINGRES - 1);
  420. if(StrStr(CharUpper(szName), CharUpper(szDefault))) // already default
  421. return;
  422. SetDefaultID(szName, hDlg, lpWED);
  423. #endif
  424. }
  425. // Add Messanger ID to list
  426. #define NOT_FOUND ((ULONG) -1)
  427. void AddMsgrId(HWND hDlg, LPWABEXTDISPLAY lpWED)
  428. {
  429. #ifdef LATER
  430. HWND hwndEdit = ::GetDlgItem(hDlg, IDC_MSGR_ID_EDIT);
  431. LPSPropValue lpPropArray = NULL;
  432. ULONG ulcPropCount = 0;
  433. ULONG i = 0;
  434. ULONG nMVEmailAddress = NOT_FOUND, nMVAddrTypes = NOT_FOUND, nEmailAddress = NOT_FOUND;
  435. ULONG nAddrType = NOT_FOUND, nDefaultIndex = NOT_FOUND;
  436. TCHAR szName[CCHMAX_STRINGRES];
  437. HRESULT hr = S_OK;
  438. if(!::GetWindowText(hwndEdit, szName, CCHMAX_STRINGRES - 1))
  439. return;
  440. TCHAR *pch = NULL;
  441. if(!AsciiTrimSpaces(szName))
  442. {
  443. AthMessageBoxW(hDlg, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsBAErrExtChars),
  444. NULL, MB_OK | MB_ICONSTOP);
  445. ::SetWindowText(hwndEdit, "");
  446. ::SetFocus(hwndEdit);
  447. return;
  448. }
  449. int nLen = lstrlen(szName);
  450. if(nLen <= 0)
  451. goto exi;
  452. nLen = lstrlen(szSMTP);
  453. if(nLen <= 0)
  454. goto exi;
  455. // Create a return prop array to pass back to the WAB
  456. if(HR_FAILED(lpWED->lpPropObj->GetProps(NULL, 0,
  457. &ulcPropCount,
  458. &lpPropArray)))
  459. return;
  460. if(ulcPropCount && lpPropArray)
  461. {
  462. for(i = 0; i < ulcPropCount; i++)
  463. {
  464. switch(lpPropArray[i].ulPropTag)
  465. {
  466. case PR_EMAIL_ADDRESS:
  467. nEmailAddress = i;
  468. break;
  469. case PR_ADDRTYPE:
  470. nAddrType = i;
  471. break;
  472. case PR_CONTACT_EMAIL_ADDRESSES:
  473. nMVEmailAddress = i;
  474. break;
  475. case PR_CONTACT_ADDRTYPES:
  476. nMVAddrTypes = i;
  477. break;
  478. case PR_CONTACT_DEFAULT_ADDRESS_INDEX:
  479. nDefaultIndex = i;
  480. break;
  481. }
  482. }
  483. // if no e-mail address, just add the given prop as e-mail address and in mv e-mail addresses
  484. if(nEmailAddress == NOT_FOUND)
  485. {
  486. SPropValue spv[5];
  487. spv[0].ulPropTag = PR_EMAIL_ADDRESS;
  488. spv[0].Value.lpszW = szName;
  489. spv[1].ulPropTag = PR_ADDRTYPE;
  490. spv[1].Value.lpszW = szSMTP;
  491. spv[2].ulPropTag = PR_CONTACT_EMAIL_ADDRESSES;
  492. spv[2].Value.MVszW.cValues = 1;
  493. spv[2].Value.MVszW.lppszW = (WCHAR **) LocalAlloc(LMEM_ZEROINIT, sizeof(LPTSTR));
  494. if(spv[2].Value.MVszW.lppszW)
  495. spv[2].Value.MVszW.lppszW[0] = szName;
  496. spv[3].ulPropTag = PR_CONTACT_ADDRTYPES;
  497. spv[3].Value.MVszW.cValues = 1;
  498. spv[3].Value.MVszW.lppszW = (WCHAR **) LocalAlloc(LMEM_ZEROINIT, sizeof(LPTSTR));
  499. if(spv[3].Value.MVszW.lppszW)
  500. spv[3].Value.MVszW.lppszW[0] = szSMTP;
  501. spv[4].ulPropTag = PR_CONTACT_DEFAULT_ADDRESS_INDEX;
  502. spv[4].Value.l = 0;
  503. hr = lpWED->lpPropObj->SetProps(5, (LPSPropValue)&spv, NULL);
  504. if(spv[2].Value.MVszW.lppszW)
  505. LocalFree(spv[2].Value.MVszW.lppszW);
  506. if(spv[3].Value.MVszW.lppszW)
  507. LocalFree(spv[3].Value.MVszW.lppszW);
  508. }
  509. else if(nMVEmailAddress == NOT_FOUND)
  510. {
  511. // we have an e-mail address but no contact-email-addresses
  512. // so we will need to create the contact e-mail addresses
  513. SPropValue spv[3];
  514. spv[0].ulPropTag = PR_CONTACT_EMAIL_ADDRESSES;
  515. spv[0].Value.MVszW.cValues = 2;
  516. spv[0].Value.MVszW.lppszW = (WCHAR **) LocalAlloc(LMEM_ZEROINIT, sizeof(LPTSTR)*2);
  517. if(spv[0].Value.MVszW.lppszW)
  518. {
  519. spv[0].Value.MVszW.lppszW[0] = lpPropArray[nEmailAddress].Value.lpszW;
  520. spv[0].Value.MVszW.lppszW[1] = szName;
  521. }
  522. spv[1].ulPropTag = PR_CONTACT_ADDRTYPES;
  523. spv[1].Value.MVszW.cValues = 2;
  524. spv[1].Value.MVszW.lppszW = (WCHAR **) LocalAlloc(LMEM_ZEROINIT, sizeof(LPTSTR)*2);
  525. if(spv[1].Value.MVszW.lppszW)
  526. {
  527. spv[1].Value.MVszW.lppszW[0] = (nAddrType == NOT_FOUND) ? (LPTSTR)szSMTP : lpPropArray[nAddrType].Value.lpszW;
  528. spv[1].Value.MVszW.lppszW[1] = szSMTP;
  529. }
  530. spv[2].ulPropTag = PR_CONTACT_DEFAULT_ADDRESS_INDEX;
  531. spv[2].Value.l = 0;
  532. hr = lpWED->lpPropObj->SetProps(3, (LPSPropValue)&spv, NULL);
  533. if(spv[0].Value.MVszW.lppszW)
  534. LocalFree(spv[0].Value.MVszW.lppszW);
  535. if(spv[1].Value.MVszW.lppszW)
  536. LocalFree(spv[1].Value.MVszW.lppszW);
  537. }
  538. else
  539. {
  540. // tag on the new props to the end of the existing contact_address_types
  541. if(HR_FAILED(hr = AddPropToMVPString(lpWED, lpPropArray,ulcPropCount, nMVEmailAddress, szName)))
  542. goto exi;
  543. if(HR_FAILED(hr = AddPropToMVPString(lpWED, lpPropArray, ulcPropCount, nMVAddrTypes, szSMTP)))
  544. goto exi;
  545. hr = lpWED->lpPropObj->SetProps(ulcPropCount, lpPropArray, NULL);
  546. }
  547. // Set this new data on the object
  548. //
  549. if(SUCCEEDED(hr))
  550. {
  551. lpWED->fDataChanged = TRUE;
  552. if(nDefault == -1)
  553. SetDefaultID(szName, hDlg, lpWED);
  554. else
  555. {
  556. // just refresh list, which will add buddy.6
  557. ListView_DeleteAllItems(::GetDlgItem(hDlg, IDC_USER_NAME));
  558. AddAccountsToList(hDlg, lpWED);
  559. }
  560. ::SetWindowText(hwndEdit, "");
  561. }
  562. }
  563. exi:
  564. if(lpPropArray)
  565. lpWED->lpWABObject->FreeBuffer(lpPropArray);
  566. #endif
  567. }
  568. //Set default ID in WAB
  569. void SetDefaultID(TCHAR *szName, HWND hDlg, LPWABEXTDISPLAY lpWED)
  570. {
  571. #ifdef LATER
  572. ULONG ulcPropCount = 0;
  573. LPSPropValue lpPropArray = NULL;
  574. SCODE sc = 0;
  575. if(s_pMsgrList)
  576. {
  577. s_pMsgrList->AddUser(szName); // Always ignore result
  578. }
  579. else
  580. return;
  581. // Create a return prop array to pass back to the WAB
  582. int nLen = lstrlen(szName);
  583. sc = lpWED->lpWABObject->AllocateBuffer(sizeof(SPropValue),
  584. (LPVOID *)&lpPropArray);
  585. if (sc!=S_OK)
  586. goto out;
  587. if(nLen)
  588. {
  589. lpPropArray[Msgr_Index].ulPropTag = MsgrPropTags[Msgr_Index];
  590. sc = lpWED->lpWABObject->AllocateMore(nLen+1, lpPropArray,
  591. (LPVOID *)&(lpPropArray[Msgr_Index].Value.lpszW));
  592. if (sc!=S_OK)
  593. goto out;
  594. StrCpyN(lpPropArray[Msgr_Index].Value.lpszW, szName, nLen +1);
  595. }
  596. // Set this new data on the object
  597. //
  598. if(HR_FAILED(lpWED->lpPropObj->SetProps( 1, lpPropArray, NULL)))
  599. goto out;
  600. lpWED->fDataChanged = TRUE;
  601. ListView_DeleteAllItems(::GetDlgItem(hDlg, IDC_USER_NAME));
  602. AddAccountsToList(hDlg, lpWED, szName);
  603. out:
  604. if(lpPropArray)
  605. lpWED->lpWABObject->FreeBuffer(lpPropArray);
  606. #endif
  607. }
  608. //$$//////////////////////////////////////////////////////////////////////////////
  609. //
  610. // TrimSpaces - strips a string of leading and trailing blanks
  611. //
  612. // szBuf - pointer to buffer containing the string we want to strip spaces off.
  613. // Also, check that characters are ASCII
  614. //
  615. ////////////////////////////////////////////////////////////////////////////////
  616. BOOL AsciiTrimSpaces(TCHAR * szBuf)
  617. {
  618. register LPTSTR lpTemp = szBuf;
  619. DWORD cch = lstrlen(szBuf)+1;
  620. if(!szBuf || !lstrlen(szBuf))
  621. return FALSE;
  622. // Trim leading spaces
  623. while (IEIsSpace(lpTemp)) {
  624. lpTemp = CharNext(lpTemp);
  625. }
  626. if (lpTemp != szBuf) {
  627. // Leading spaces to trim
  628. StrCpyN(szBuf, lpTemp, cch);
  629. lpTemp = szBuf;
  630. }
  631. if (*lpTemp == '\0') {
  632. // empty string
  633. return(TRUE);
  634. }
  635. // Move to the end
  636. lpTemp += lstrlen(lpTemp);
  637. lpTemp--;
  638. // Walk backwards, triming spaces
  639. while (IEIsSpace(lpTemp) && lpTemp > szBuf) {
  640. *lpTemp = '\0';
  641. lpTemp = CharPrev(szBuf, lpTemp);
  642. }
  643. lpTemp = szBuf;
  644. while (*lpTemp)
  645. {
  646. // Internet addresses only allow pure ASCII. No high bits!
  647. if (*lpTemp & 0x80)
  648. return(FALSE);
  649. lpTemp++;
  650. }
  651. return(TRUE);
  652. }
  653. /***************************************************************************
  654. Name : AddPropToMVPString
  655. Purpose : Add a property to a multi-valued binary property in a prop array
  656. Parameters: lpaProps -> array of properties
  657. cProps = number of props in lpaProps
  658. uPropTag = property tag for MVP
  659. index = index in lpaProps of MVP
  660. lpszNew -> new data string
  661. Returns : HRESULT
  662. Comment : Find the size of the existing MVP
  663. Add in the size of the new entry
  664. allocate new space
  665. copy old to new
  666. free old
  667. copy new entry
  668. point prop array lpszW to the new space
  669. increment cValues
  670. Note: The new MVP memory is AllocMore'd onto the lpaProps
  671. allocation. We will unlink the pointer to the old MVP array,
  672. but this will be cleaned up when the prop array is freed.
  673. ***************************************************************************/
  674. HRESULT AddPropToMVPString(
  675. LPWABEXTDISPLAY lpWED,
  676. LPSPropValue lpaProps,
  677. DWORD cProps,
  678. DWORD index,
  679. LPWSTR lpszNew) {
  680. #ifdef UNICODE
  681. SWStringArray UNALIGNED * lprgszOld = NULL; // old SString array
  682. #else
  683. SWStringArray UNALIGNED * lprgszOld = NULL; // old SString array
  684. #endif
  685. LPWSTR *lppszNew = NULL; // new prop array
  686. LPWSTR *lppszOld = NULL; // old prop array
  687. ULONG cbMVP = 0;
  688. ULONG cExisting = 0;
  689. LPBYTE lpNewTemp = NULL;
  690. HRESULT hResult = hrSuccess;
  691. SCODE sc = SUCCESS_SUCCESS;
  692. ULONG i = 0;
  693. ULONG cchNew;
  694. if (lpszNew) {
  695. cchNew = lstrlenW(lpszNew) + 1;
  696. } else {
  697. cchNew = 0;
  698. }
  699. // Find the size of any existing MVP entries
  700. if (PROP_ERROR(lpaProps[index])) {
  701. // Un-ERROR the property tag
  702. lpaProps[index].ulPropTag = PROP_TAG(PT_MV_TSTRING, PROP_ID(lpaProps[index].ulPropTag));
  703. } else {
  704. // point to the structure in the prop array.
  705. lprgszOld = &(lpaProps[index].Value.MVszW);
  706. lppszOld = lprgszOld->lppszW;
  707. cExisting = lprgszOld->cValues;
  708. cbMVP = cExisting * sizeof(LPTSTR);
  709. }
  710. // cbMVP now contains the current size of the MVP
  711. cbMVP += sizeof(LPWSTR); // room in the MVP for another string pointer
  712. // Allocate room for new MVP array
  713. if (sc = lpWED->lpWABObject->AllocateMore(cbMVP, lpaProps, (LPVOID *)&lppszNew)) {
  714. DebugTrace("AddPropToMVPString allocation (%u) failed %x\n", cbMVP, sc);
  715. hResult = ResultFromScode(sc);
  716. return(hResult);
  717. }
  718. // If there are properties there already, copy them to our new MVP
  719. for (i = 0; i < cExisting; i++) {
  720. // Copy this property value to the MVP
  721. lppszNew[i] = lppszOld[i];
  722. }
  723. // Add the new property value
  724. // Allocate room for it
  725. if (cchNew) {
  726. if (sc = lpWED->lpWABObject->AllocateMore(cchNew * sizeof(WCHAR), lpaProps, (LPVOID *)&(lppszNew[i]))) {
  727. DebugTrace("AddPropToMVPBin allocation (%u) failed %x\n", cchNew * sizeof(WCHAR), sc);
  728. hResult = ResultFromScode(sc);
  729. return(hResult);
  730. }
  731. StrCpyNW(lppszNew[i], lpszNew, cchNew);
  732. lpaProps[index].Value.MVszW.lppszW= lppszNew;
  733. lpaProps[index].Value.MVszW.cValues = cExisting + 1;
  734. } else {
  735. lppszNew[i] = NULL;
  736. }
  737. return(hResult);
  738. }
  739. // this function check if selected item is online
  740. BOOL WabIsItemOnline(HWND hDlg, int nItem)
  741. {
  742. #ifdef LATER
  743. TCHAR szName[CCHMAX_STRINGRES];
  744. TCHAR *pch = NULL;
  745. if(nItem < 0)
  746. return(FALSE);
  747. HWND ctlList = ::GetDlgItem(hDlg, IDC_USER_NAME);
  748. Assert(ctlList);
  749. ListView_GetItemText(ctlList, nItem, 0,szName, CCHMAX_STRINGRES - 1);
  750. // Remove "(default)"
  751. pch = StrStr(szName, szDefault);
  752. if(pch != NULL)
  753. szName[pch - szName] = '\0';
  754. if(s_pMsgrList)
  755. {
  756. return(s_pMsgrList->IsContactOnline(szName, s_pMsgrList->GetFirstMsgrItem()));
  757. }
  758. #endif
  759. return(FALSE);
  760. }
  761. // Send instant message to selected item
  762. void WabSendIMsg(HWND hDlg, LPWABEXTDISPLAY lpWED)
  763. {
  764. #ifdef LATER
  765. TCHAR szName[CCHMAX_STRINGRES];
  766. TCHAR *pch = NULL;
  767. HWND ctlList = ::GetDlgItem(hDlg, IDC_USER_NAME);
  768. Assert(ctlList);
  769. int iItem = ListView_GetNextItem(ctlList, -1, LVIS_SELECTED);
  770. if(iItem == -1)
  771. return;
  772. ListView_GetItemText(ctlList, iItem, 0,szName, CCHMAX_STRINGRES - 1);
  773. // Remove "(default)"
  774. pch = StrStr(szName, szDefault);
  775. if(pch != NULL)
  776. szName[pch - szName] = '\0';
  777. if(s_pMsgrList)
  778. {
  779. s_pMsgrList->SendInstMessage(szName);
  780. }
  781. #endif
  782. }
  783. BOOL InitFonts(void)
  784. {
  785. LOGFONT lf;
  786. // Create the font
  787. if(SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0))
  788. {
  789. if(!hNormal)
  790. hNormal = CreateFontIndirect(&lf);
  791. lf.lfWeight = (lf.lfWeight < 700) ? 700 : 1000;
  792. if(!hBold)
  793. hBold = CreateFontIndirect(&lf);
  794. }
  795. return(TRUE);
  796. }
  797. void DeleteFonts(void)
  798. {
  799. if(hNormal)
  800. {
  801. DeleteObject(hNormal);
  802. hNormal = NULL;
  803. }
  804. if(hBold)
  805. {
  806. DeleteObject(hBold);
  807. hBold = NULL;
  808. }
  809. }