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.

3082 lines
92 KiB

  1. // baui.cpp : Implementation of CMsgrAb
  2. // Messenger integration to OE
  3. // Created 04/20/98 by YST
  4. #include "pch.hxx"
  5. #include "bactrl.h"
  6. #include "baprop.h"
  7. #include "baui.h"
  8. #include "mimeutil.h"
  9. #include "menuutil.h"
  10. #include "fldbar.h"
  11. #include "bllist.h"
  12. #include "inpobj.h"
  13. #include "note.h"
  14. #include "dllmain.h"
  15. #include <wabapi.h>
  16. #include "shlwapip.h"
  17. #include "statnery.h"
  18. #include "secutil.h"
  19. #include "util.h"
  20. // Load resource string once
  21. #define RESSTRMAX 64
  22. static const int BA_SortOrder[] =
  23. {
  24. MSTATEOE_ONLINE,
  25. MSTATEOE_BE_RIGHT_BACK,
  26. MSTATEOE_OUT_TO_LUNCH,
  27. MSTATEOE_IDLE,
  28. MSTATEOE_AWAY,
  29. MSTATEOE_ON_THE_PHONE,
  30. MSTATEOE_BUSY,
  31. MSTATEOE_INVISIBLE,
  32. MSTATEOE_OFFLINE,
  33. MSTATEOE_UNKNOWN
  34. };
  35. static CAddressBookData * st_pAddrBook = NULL;
  36. // {BA9EE970-87A0-11d1-9ACF-00A0C91F9C8B}
  37. // IMPLEMENT_OLECREATE(CMfcExt, "WABSamplePropExtSheet", 0xba9ee970, 0x87a0, 0x11d1, 0x9a, 0xcf, 0x0, 0xa0, 0xc9, 0x1f, 0x9c, 0x8b);
  38. HRESULT CreateMsgrAbCtrl(IMsgrAb **ppMsgrAb)
  39. {
  40. HRESULT hr;
  41. IUnknown *pUnknown;
  42. TraceCall("CreateMessageList");
  43. // Get the class factory for the MessageList object
  44. IClassFactory *pFactory = NULL;
  45. hr = _Module.GetClassObject(CLSID_MsgrAb, IID_IClassFactory,
  46. (LPVOID *) &pFactory);
  47. // If we got the factory, then get an object pointer from it
  48. if (SUCCEEDED(hr))
  49. {
  50. hr = pFactory->CreateInstance(NULL, IID_IUnknown,
  51. (LPVOID *) &pUnknown);
  52. if (SUCCEEDED(hr))
  53. {
  54. hr = pUnknown->QueryInterface(IID_IMsgrAb, (LPVOID *) ppMsgrAb);
  55. pUnknown->Release();
  56. }
  57. pFactory->Release();
  58. }
  59. return (hr);
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CMsgrAb
  63. CMsgrAb::CMsgrAb():m_ctlList(_T("SysListView32"), this, 1),
  64. m_ctlViewTip(TOOLTIPS_CLASS, this, 2)
  65. {
  66. m_bWindowOnly = TRUE;
  67. m_pDataObject = 0;
  68. m_cf = 0;
  69. m_pObjSite = NULL;
  70. m_hwndParent = NULL;
  71. m_pFolderBar = NULL;
  72. m_nSortType = (int) DwGetOption(OPT_BASORT);
  73. m_pCMsgrList = NULL;
  74. m_fViewTip = TRUE;
  75. m_fViewTipVisible = FALSE;
  76. m_fTrackSet = FALSE;
  77. m_iItemTip = -1;
  78. m_iSubItemTip = -1;
  79. m_himl = NULL;
  80. m_ptToolTip.x = -1;
  81. m_ptToolTip.y = -1;
  82. m_fLogged = FALSE;
  83. m_dwFontCacheCookie = 0;
  84. m_nChCount = 0;
  85. m_lpWED = NULL;
  86. m_lpWEDContext = NULL;
  87. m_lpPropObj = NULL;
  88. m_szOnline = NULL;
  89. // m_szInvisible = NULL;
  90. m_szBusy = NULL;
  91. m_szBack = NULL;
  92. m_szAway = NULL;
  93. m_szOnPhone = NULL;
  94. m_szLunch = NULL;
  95. m_szOffline = NULL;
  96. m_szIdle = NULL;
  97. m_szEmptyList = NULL;
  98. m_fNoRemove = FALSE;
  99. m_delItem = 0;
  100. // Initialize the applicaiton
  101. g_pInstance->DllAddRef();
  102. // Raid-32933: OE: MSIMN.EXE doesn't always exit
  103. // g_pInstance->CoIncrementInit();
  104. }
  105. CMsgrAb::~CMsgrAb()
  106. {
  107. // unregister from Msgr list
  108. if(m_pCMsgrList)
  109. {
  110. m_pCMsgrList->UnRegisterUIWnd(m_hWnd);
  111. OE_CloseMsgrList(m_pCMsgrList);
  112. }
  113. SafeRelease(m_pObjSite);
  114. SafeMemFree(m_szOnline);
  115. // SafeMemFree(m_szInvisible);
  116. SafeMemFree(m_szBusy);
  117. SafeMemFree(m_szBack);
  118. SafeMemFree(m_szAway);
  119. SafeMemFree(m_szOnPhone);
  120. SafeMemFree(m_szLunch);
  121. SafeMemFree(m_szOffline);
  122. SafeMemFree(m_szIdle);
  123. SafeMemFree(m_szEmptyList);
  124. // Raid-32933: OE: MSIMN.EXE doesn't always exit
  125. // g_pInstance->CoDecrementInit();
  126. g_pInstance->DllRelease();
  127. }
  128. LRESULT CMsgrAb::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  129. {
  130. SetDwOption(OPT_BASORT, m_nSortType, 0, 0);
  131. if(m_delItem != 0)
  132. m_fNoRemove = TRUE;
  133. // else
  134. // m_fNoRemove = FALSE;
  135. m_delItem = ListView_GetItemCount(m_ctlList);
  136. if (IsWindow(m_ctlViewTip))
  137. {
  138. m_ctlViewTip.SendMessage(TTM_POP, 0, 0);
  139. m_ctlViewTip.DestroyWindow();
  140. }
  141. if (m_dwFontCacheCookie && g_lpIFontCache)
  142. {
  143. IConnectionPoint *pConnection = NULL;
  144. if (SUCCEEDED(g_lpIFontCache->QueryInterface(IID_IConnectionPoint, (LPVOID *) &pConnection)))
  145. {
  146. pConnection->Unadvise(m_dwFontCacheCookie);
  147. pConnection->Release();
  148. }
  149. }
  150. m_cAddrBook.Unadvise();
  151. RevokeDragDrop(m_hWnd);
  152. if (m_himl != NULL)
  153. ImageList_Destroy(m_himl);
  154. return 0;
  155. }
  156. HRESULT CMsgrAb::OnDraw(ATL_DRAWINFO& di)
  157. {
  158. RECT& rc = *(RECT*)di.prcBounds;
  159. #if 0
  160. int patGray[4];
  161. HBITMAP hbm;
  162. HBRUSH hbr;
  163. COLORREF cFg;
  164. COLORREF cBkg;
  165. // Initialize the pattern
  166. patGray[0] = 0x005500AA;
  167. patGray[1] = 0x005500AA;
  168. patGray[2] = 0x005500AA;
  169. patGray[3] = 0x005500AA;
  170. // Create a bitmap from the pattern
  171. hbm = CreateBitmap(8, 8, 1, 1, (LPSTR)patGray);
  172. if ((HBITMAP) NULL != hbm)
  173. {
  174. hbr = CreatePatternBrush(hbm);
  175. if (hbr)
  176. {
  177. // Select the right colors into the DC
  178. cFg = SetTextColor(di.hdcDraw, GetSysColor(COLOR_3DFACE));
  179. cBkg = SetBkColor(di.hdcDraw, RGB(255, 255, 255));
  180. // Fill the rectangle
  181. FillRect(di.hdcDraw, &rc, hbr);
  182. SetTextColor(di.hdcDraw, cFg);
  183. SetBkColor(di.hdcDraw, cBkg);
  184. DeleteObject(hbr);
  185. }
  186. DeleteObject(hbm);
  187. }
  188. #endif
  189. // Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  190. return S_OK;
  191. }
  192. LRESULT CMsgrAb::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  193. {
  194. // Define a bogus rectangle for the controls. They will get resized in
  195. // our size handler.
  196. RECT rcPos = {0, 0, 100, 100};
  197. TCHAR sz[CCHMAX_STRINGRES];
  198. // Create the various controls
  199. m_ctlList.Create(m_hWnd, rcPos, _T("Outlook Express Address Book ListView"),
  200. WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
  201. LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS /* | LVS_SORTASCENDING*/, 0);
  202. ListView_SetExtendedListViewStyleEx(m_ctlList, LVS_EX_INFOTIP | LVS_EX_LABELTIP, LVS_EX_INFOTIP | LVS_EX_LABELTIP);
  203. // Image List
  204. Assert(m_himl == NULL);
  205. m_himl = ImageList_LoadImage(g_hLocRes, MAKEINTRESOURCE(idbAddrBookHot), 16, 0,
  206. RGB(255, 0, 255), IMAGE_BITMAP,
  207. LR_LOADMAP3DCOLORS | LR_CREATEDIBSECTION);
  208. ListView_SetImageList(m_ctlList, m_himl, LVSIL_SMALL);
  209. LVCOLUMN lvc;
  210. lvc.mask = LVCF_SUBITEM;
  211. lvc.iSubItem = 0;
  212. ListView_InsertColumn(m_ctlList, 0, &lvc);
  213. m_ctlList.SendMessage(WM_SETFONT, NULL, 0);
  214. SetListViewFont(m_ctlList, GetListViewCharset(), TRUE);
  215. if (g_lpIFontCache)
  216. {
  217. IConnectionPoint *pConnection = NULL;
  218. if (SUCCEEDED(g_lpIFontCache->QueryInterface(IID_IConnectionPoint, (LPVOID *) &pConnection)))
  219. {
  220. pConnection->Advise((IUnknown *)(IFontCacheNotify *) this, &m_dwFontCacheCookie);
  221. pConnection->Release();
  222. }
  223. }
  224. // Msgr Initialization
  225. m_pCMsgrList = OE_OpenMsgrList();
  226. // Register our control for Msgr list
  227. if(m_pCMsgrList)
  228. {
  229. m_pCMsgrList->RegisterUIWnd(m_hWnd);
  230. if(m_pCMsgrList->IsLocalOnline())
  231. {
  232. m_fLogged = TRUE;
  233. FillMsgrList();
  234. }
  235. }
  236. // Initialize the address book object too
  237. HRESULT hr = m_cAddrBook.OpenWabFile();
  238. if(hr == S_OK)
  239. m_cAddrBook.LoadWabContents(m_ctlList, this);
  240. st_pAddrBook = &m_cAddrBook;
  241. // Sort and Select the first item
  242. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  243. ListView_SetItemState(m_ctlList, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  244. // Add the tooltip
  245. // Load Tooltip strings
  246. if(AthLoadString(idsBAOnline, sz, ARRAYSIZE(sz)))
  247. {
  248. if(MemAlloc((LPVOID *) &m_szOnline, lstrlen(sz) + 1))
  249. StrCpyN(m_szOnline, sz, lstrlen(sz) + 1);
  250. }
  251. /* if(AthLoadString(idsBAInvisible, sz, ARRAYSIZE(sz)))
  252. {
  253. if(MemAlloc((LPVOID *) &m_szInvisible, lstrlen(sz) + 1))
  254. StrCpyN(m_szInvisible, sz, lstrlen(sz) + 1);
  255. }*/
  256. if(AthLoadString(idsBABusy, sz, ARRAYSIZE(sz)))
  257. {
  258. if(MemAlloc((LPVOID *) &m_szBusy, lstrlen(sz) + 1))
  259. StrCpyN(m_szBusy, sz, lstrlen(sz) + 1);
  260. }
  261. if(AthLoadString(idsBABack, sz, ARRAYSIZE(sz)))
  262. {
  263. if(MemAlloc((LPVOID *) &m_szBack, lstrlen(sz) + 1))
  264. StrCpyN(m_szBack, sz, lstrlen(sz) + 1);
  265. }
  266. if(AthLoadString(idsBAAway, sz, ARRAYSIZE(sz)))
  267. {
  268. if(MemAlloc((LPVOID *) &m_szAway, lstrlen(sz) + 1))
  269. StrCpyN(m_szAway, sz, lstrlen(sz) + 1);
  270. }
  271. if(AthLoadString(idsBAOnPhone, sz, ARRAYSIZE(sz)))
  272. {
  273. if(MemAlloc((LPVOID *) &m_szOnPhone, lstrlen(sz) + 1))
  274. StrCpyN(m_szOnPhone, sz, lstrlen(sz) + 1);
  275. }
  276. if(AthLoadString(idsBALunch, sz, ARRAYSIZE(sz)))
  277. {
  278. if(MemAlloc((LPVOID *) &m_szLunch, lstrlen(sz) + 1))
  279. StrCpyN(m_szLunch, sz, lstrlen(sz) + 1);
  280. }
  281. if(AthLoadString(idsBAOffline, sz, ARRAYSIZE(sz)))
  282. {
  283. if(MemAlloc((LPVOID *) &m_szOffline, lstrlen(sz) + 1))
  284. StrCpyN(m_szOffline, sz,lstrlen(sz) + 1);
  285. }
  286. if(AthLoadString(idsBAIdle, sz, ARRAYSIZE(sz)))
  287. {
  288. if(MemAlloc((LPVOID *) &m_szIdle, lstrlen(sz) + 1))
  289. StrCpyN(m_szIdle, sz, lstrlen(sz) + 1);
  290. }
  291. if(AthLoadString(idsMsgrEmptyList, sz, ARRAYSIZE(sz)))
  292. {
  293. if(MemAlloc((LPVOID *) &m_szEmptyList, lstrlen(sz) + 1))
  294. StrCpyN(m_szEmptyList, sz, lstrlen(sz) + 1);
  295. }
  296. // Create the ListView tooltip
  297. if (m_fViewTip)
  298. {
  299. TOOLINFO ti = {0};
  300. m_ctlViewTip.Create(m_hWnd, rcPos, NULL, TTS_NOPREFIX);
  301. // Add the tool
  302. ti.cbSize = sizeof(TOOLINFO);
  303. ti.uFlags = TTF_IDISHWND | TTF_TRANSPARENT | TTF_TRACK | TTF_ABSOLUTE;
  304. ti.hwnd = m_hWnd;
  305. ti.uId = (UINT_PTR)(HWND) m_ctlList;
  306. ti.lpszText = _TEXT(""); // LPSTR_TEXTCALLBACK;
  307. ti.lParam = 0;
  308. m_ctlViewTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti);
  309. m_ctlViewTip.SendMessage(TTM_SETDELAYTIME, TTDT_INITIAL, (LPARAM) 500);
  310. // m_ctlViewTip.SendMessage(TTM_SETTIPBKCOLOR, GetSysColor(COLOR_WINDOW), 0);
  311. // m_ctlViewTip.SendMessage(TTM_SETTIPTEXTCOLOR, GetSysColor(COLOR_WINDOWTEXT), 0);
  312. }
  313. m_ctlList.SetFocus();
  314. // Register ourselves as a drop target
  315. RegisterDragDrop(m_hWnd, (IDropTarget *) this);
  316. // Update the size of the listview columns
  317. _AutosizeColumns();
  318. if(ListView_GetItemCount(m_ctlList) > 0)
  319. m_cEmptyList.Hide();
  320. else
  321. m_cEmptyList.Show(m_ctlList, (LPTSTR) m_szEmptyList);
  322. // Finished
  323. return (0);
  324. }
  325. LRESULT CMsgrAb::OnSetFocus(UINT nMsg , WPARAM wParam , LPARAM lParam , BOOL& bHandled )
  326. {
  327. CComControlBase::OnSetFocus(nMsg, wParam, lParam, bHandled);
  328. m_ctlList.SetFocus();
  329. if (m_pObjSite)
  330. {
  331. m_pObjSite->OnFocusChangeIS((IInputObject*) this, TRUE);
  332. }
  333. return 0;
  334. }
  335. LRESULT CMsgrAb::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  336. {
  337. RECT rc;
  338. DWORD width = LOWORD(lParam);
  339. DWORD height = HIWORD(lParam);
  340. // Position the listview to fill the entire area
  341. RECT rcList;
  342. rcList.left = 0;
  343. rcList.top = 0;
  344. rcList.right = width;
  345. rcList.bottom = height;
  346. m_ctlList.SetWindowPos(NULL, &rcList, SWP_NOACTIVATE | SWP_NOZORDER);
  347. // Update the size of the listview columns
  348. _AutosizeColumns();
  349. return (0);
  350. }
  351. void CMsgrAb::_AutosizeColumns(void)
  352. {
  353. RECT rcList;
  354. m_ctlList.GetClientRect(&rcList);
  355. ListView_SetColumnWidth(m_ctlList, 0, rcList.right - 5);
  356. }
  357. //
  358. // FUNCTION: CMessageList::OnPreFontChange()
  359. //
  360. // PURPOSE: Get's hit by the Font Cache before it changes the fonts we're
  361. // using. In response we tell the ListView to dump any custom
  362. // font's it's using.
  363. //
  364. STDMETHODIMP CMsgrAb::OnPreFontChange(void)
  365. {
  366. m_ctlList.SendMessage(WM_SETFONT, 0, 0);
  367. return (S_OK);
  368. }
  369. //
  370. // FUNCTION: CMessageList::OnPostFontChange()
  371. //
  372. // PURPOSE: Get's hit by the Font Cache after it updates the font's we're
  373. // using. In response, we set the new font for the current charset.
  374. //
  375. STDMETHODIMP CMsgrAb::OnPostFontChange(void)
  376. {
  377. SetListViewFont(m_ctlList, GetListViewCharset(), TRUE);
  378. return (S_OK);
  379. }
  380. LRESULT CMsgrAb::CmdSetOnline(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  381. {
  382. if(g_dwHideMessenger == BL_NOTINST)
  383. return(InstallMessenger(m_hWnd));
  384. LPMABENTRY pEntry = GetSelectedEntry();
  385. if(!pEntry || (pEntry->tag == LPARAM_MENTRY) || !m_pCMsgrList)
  386. return S_FALSE;
  387. // m_cAddrBook.SetDefaultMsgrID(pEntry->lpSB, pEntry->pchWABID);
  388. if(PromptToGoOnline() == S_OK)
  389. m_pCMsgrList->AddUser(pEntry->pchWABID);
  390. return S_OK;
  391. }
  392. LRESULT CMsgrAb::CmdNewOnlineContact(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  393. {
  394. if(g_dwHideMessenger == BL_NOTINST)
  395. return(InstallMessenger(m_hWnd));
  396. else if(m_pCMsgrList)
  397. {
  398. if(PromptToGoOnline() == S_OK)
  399. m_pCMsgrList->NewOnlineContact();
  400. }
  401. return S_OK;
  402. }
  403. LRESULT CMsgrAb::CmdNewContact(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  404. {
  405. // Tell the WAB to bring up it's new contact UI
  406. m_cAddrBook.NewContact(m_hWnd);
  407. return (0);
  408. }
  409. LRESULT CMsgrAb::NewInstantMessage(LPMABENTRY pEntry)
  410. {
  411. if(((INT_PTR) pEntry) == -1)
  412. return(m_pCMsgrList->SendInstMessage(NULL));
  413. else if(m_pCMsgrList)
  414. {
  415. if(PromptToGoOnline() == S_OK)
  416. return(m_pCMsgrList->SendInstMessage(pEntry->lpMsgrInfo->pchID));
  417. }
  418. return(S_OK);
  419. }
  420. LRESULT CMsgrAb::CmdNewEmaile(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  421. {
  422. LPMIMEMESSAGE pMessage = 0;
  423. LVITEM lvi;
  424. LPMIMEADDRESSTABLEW pAddrTableW = NULL;
  425. LPMIMEADDRESSTABLE pAddrTableA = NULL;
  426. LPMABENTRY pEntry;
  427. BOOL fModal;
  428. BOOL fMail;
  429. FOLDERID folderID;
  430. IUnknown *pUnkPump;
  431. INIT_MSGSITE_STRUCT initStruct = {0};
  432. DWORD dwCreateFlags = 0;
  433. // Create a new message
  434. if (FAILED(HrCreateMessage(&pMessage)))
  435. return (0);
  436. // Get the address table from the message
  437. if (FAILED(pMessage->GetAddressTable(&pAddrTableA)))
  438. goto exit;
  439. if (FAILED(pAddrTableA->QueryInterface(IID_IMimeAddressTableW, (LPVOID*)&pAddrTableW)))
  440. goto exit;
  441. // Loop through the selected items
  442. lvi.mask = LVIF_PARAM;
  443. lvi.iItem = -1;
  444. lvi.iSubItem = 0;
  445. while (-1 != (lvi.iItem = ListView_GetNextItem(m_ctlList, lvi.iItem, LVIS_SELECTED)))
  446. {
  447. // We need to get the entry ID from the item
  448. ListView_GetItem(m_ctlList, &lvi);
  449. // Tell the data source to add this person to the message
  450. pEntry = (LPMABENTRY) lvi.lParam;
  451. Assert(pEntry);
  452. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_ABENTRY)
  453. m_cAddrBook.AddRecipient(pAddrTableW, pEntry->lpSB, FALSE);
  454. else if(pEntry->tag == LPARAM_ABGRPENTRY)
  455. m_cAddrBook.AddRecipient(pAddrTableW, pEntry->lpSB, TRUE);
  456. else if(pEntry->tag == LPARAM_MENTRY)
  457. {
  458. Assert(pEntry->lpMsgrInfo);
  459. pAddrTableA->Append(IAT_TO, IET_DECODED, pEntry->lpMsgrInfo->pchID, NULL , NULL);
  460. }
  461. else
  462. Assert(FALSE);
  463. }
  464. fModal = FALSE;
  465. fMail = TRUE;
  466. folderID = FOLDERID_INVALID;
  467. pUnkPump = NULL;
  468. if (DwGetOption(OPT_MAIL_USESTATIONERY))
  469. {
  470. WCHAR wszFile[MAX_PATH];
  471. *wszFile = 0;
  472. if (SUCCEEDED(GetDefaultStationeryName(TRUE, wszFile)) &&
  473. SUCCEEDED(HrNewStationery(m_hwndParent, 0, wszFile, fModal, fMail, folderID,
  474. FALSE, NSS_DEFAULT, pUnkPump, pMessage)))
  475. {
  476. goto exit;
  477. }
  478. }
  479. // If HrNewStationery fails, go ahead and try opening a blank note without stationery.
  480. initStruct.dwInitType = OEMSIT_MSG;
  481. initStruct.folderID = FOLDERID_INVALID;
  482. initStruct.pMsg = pMessage;
  483. CreateAndShowNote(OENA_COMPOSE, dwCreateFlags, &initStruct, m_hwndParent, pUnkPump);
  484. exit:
  485. ReleaseObj(pMessage);
  486. ReleaseObj(pAddrTableA);
  487. ReleaseObj(pAddrTableW);
  488. return (0);
  489. }
  490. LRESULT CMsgrAb::CmdNewIMsg(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  491. {
  492. return(CmdNewMessage(wNotifyCode, ID_SEND_INSTANT_MESSAGE, hWndCtl, bHandled));
  493. }
  494. LRESULT CMsgrAb::CmdNewMessage(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  495. {
  496. LVITEM lvi;
  497. LPMABENTRY pEntry;
  498. pEntry = GetEntryForSendInstMsg();
  499. if(wID == ID_SEND_INSTANT_MESSAGE)
  500. {
  501. if(g_dwHideMessenger == BL_NOTINST)
  502. return(InstallMessenger(m_hWnd));
  503. if(pEntry)
  504. return(NewInstantMessage(pEntry));
  505. else
  506. {
  507. Assert(FALSE);
  508. return(-1);
  509. }
  510. }
  511. else if((((INT_PTR) pEntry) != -1) && pEntry)
  512. return(NewInstantMessage(pEntry));
  513. else
  514. return(CmdNewEmaile(wNotifyCode, wID, hWndCtl, bHandled));
  515. }
  516. LRESULT CMsgrAb::NotifyDeleteItem(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  517. {
  518. NMLISTVIEW *pnmlv = (NMLISTVIEW *) pnmh;
  519. LVITEM lvi;
  520. lvi.mask = LVIF_PARAM;
  521. lvi.iItem = pnmlv->iItem;
  522. lvi.iSubItem = 0;
  523. ListView_GetItem(m_ctlList, &lvi);
  524. LPMABENTRY pEntry = (LPMABENTRY) lvi.lParam;
  525. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_ABENTRY || pEntry->tag == LPARAM_ABGRPENTRY)
  526. m_cAddrBook.FreeListViewItem(pEntry->lpSB);
  527. RemoveBlabEntry(pEntry);
  528. if(m_delItem > 0)
  529. m_delItem--;
  530. else
  531. Assert(FALSE);
  532. return (0);
  533. }
  534. LRESULT CMsgrAb::NotifyItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  535. {
  536. ULONG uChanged;
  537. NMLISTVIEW *pnmlv = (NMLISTVIEW *) pnmh;
  538. if (pnmlv->uChanged & LVIF_STATE)
  539. {
  540. uChanged = pnmlv->uNewState ^ pnmlv->uOldState;
  541. if (uChanged & LVIS_SELECTED)
  542. _EnableCommands();
  543. }
  544. return (0);
  545. }
  546. // Sort compare
  547. int CALLBACK BA_Sort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  548. {
  549. LPMABENTRY pEntry1 = (LPMABENTRY) lParam1;
  550. LPMABENTRY pEntry2 = (LPMABENTRY) lParam2;
  551. TCHAR pchName1[MAXNAME];
  552. TCHAR pchName2[MAXNAME];
  553. int nIndex1 = 0;
  554. int nIndex2 = 0 ;
  555. if(!(pEntry1->lpMsgrInfo))
  556. {
  557. nIndex1 = sizeof(BA_SortOrder)/sizeof(int);
  558. if(pEntry1->tag == LPARAM_ABGRPENTRY)
  559. nIndex1++;
  560. }
  561. else
  562. {
  563. while((pEntry1->lpMsgrInfo) && (BA_SortOrder[nIndex1] != pEntry1->lpMsgrInfo->nStatus) && (BA_SortOrder[nIndex1] != MSTATEOE_UNKNOWN))
  564. nIndex1++;
  565. }
  566. if(!(pEntry2->lpMsgrInfo))
  567. {
  568. nIndex2 = sizeof(BA_SortOrder)/sizeof(int);
  569. if(pEntry2->tag == LPARAM_ABGRPENTRY)
  570. nIndex2++;
  571. }
  572. else
  573. {
  574. while((BA_SortOrder[nIndex2] != pEntry2->lpMsgrInfo->nStatus) && (BA_SortOrder[nIndex2] != MSTATEOE_UNKNOWN))
  575. nIndex2++;
  576. }
  577. if(pEntry1->tag == LPARAM_MENTRY) // if no AB entry
  578. StrCpyN(pchName1, pEntry1->lpMsgrInfo->pchMsgrName, ARRAYSIZE(pchName1));
  579. else
  580. StrCpyN(pchName1, pEntry1->pchWABName, ARRAYSIZE(pchName1));
  581. // st_pAddrBook->GetDisplayName(pEntry1->lpSB, pchName1);
  582. pchName1[MAXNAME - 1] = _T('\0');
  583. if(pEntry2->tag == LPARAM_MENTRY) // if no AB entry
  584. StrCpyN(pchName2, pEntry2->lpMsgrInfo->pchMsgrName, ARRAYSIZE(pchName2));
  585. else
  586. StrCpyN(pchName2, pEntry2->pchWABName, ARRAYSIZE(pchName2));
  587. // st_pAddrBook->GetDisplayName(pEntry2->lpSB, pchName2);
  588. pchName2[MAXNAME - 1] = _T('\0');
  589. switch(lParamSort)
  590. {
  591. case BASORT_NAME_ACSEND:
  592. return(lstrcmpi(pchName1, pchName2));
  593. case BASORT_NAME_DESCEND:
  594. return(lstrcmpi(pchName2, pchName1));
  595. default:
  596. if((pEntry1->lpMsgrInfo) && (pEntry2->lpMsgrInfo) && (pEntry1->lpMsgrInfo->nStatus == pEntry2->lpMsgrInfo->nStatus))
  597. {
  598. if(lParamSort == BASORT_STATUS_ACSEND)
  599. return(lstrcmpi(pchName1, pchName2));
  600. else
  601. return(lstrcmpi(pchName2, pchName1));
  602. }
  603. else
  604. {
  605. if(lParamSort == BASORT_STATUS_ACSEND)
  606. return(nIndex1 - nIndex2);
  607. else
  608. return(nIndex2 - nIndex1);
  609. }
  610. }
  611. Assert(FALSE);
  612. return(0);
  613. }
  614. void CMsgrAb::_EnableCommands(void)
  615. {
  616. if(g_pBrowser)
  617. g_pBrowser->UpdateToolbar();
  618. }
  619. LRESULT CMsgrAb::NotifyItemActivate(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  620. {
  621. return (SendMessage(WM_COMMAND, ID_SEND_INSTANT_MESSAGE2, 0));
  622. }
  623. // GETDISPLAYINFO notification message
  624. LRESULT CMsgrAb::NotifyGetDisplayInfo(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  625. {
  626. LV_DISPINFO * plvdi = (LV_DISPINFO *)pnmh;
  627. LRESULT hr;
  628. if(plvdi->item.lParam)
  629. {
  630. LPMABENTRY pEntry = (LPMABENTRY) plvdi->item.lParam;
  631. LPMABENTRY pFindEntry = NULL;
  632. if (plvdi->item.mask & LVIF_IMAGE)
  633. {
  634. if((hr = SetUserIcon(pEntry, (pEntry->lpMsgrInfo ? pEntry->lpMsgrInfo->nStatus : MSTATEOE_OFFLINE), &(plvdi->item.iImage) ) ) != S_OK)
  635. return(hr);
  636. }
  637. if (plvdi->item.mask & LVIF_TEXT)
  638. {
  639. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_ABENTRY || pEntry->tag == LPARAM_ABGRPENTRY)
  640. {
  641. // if((hr = m_cAddrBook.GetDisplayName(pEntry->lpSB, plvdi->item.pszText)) != S_OK)
  642. // return(hr);
  643. Assert(pEntry->pchWABName);
  644. StrCpyN(plvdi->item.pszText, pEntry->pchWABName, plvdi->item.cchTextMax - 1);
  645. plvdi->item.pszText[plvdi->item.cchTextMax - 1] = '\0';
  646. }
  647. else if(pEntry->tag == LPARAM_MENTRY)
  648. {
  649. if((pEntry->lpMsgrInfo->nStatus == MSTATEOE_ONLINE) && lstrcmpi(pEntry->lpMsgrInfo->pchMsgrName, pEntry->lpMsgrInfo->pchID))
  650. {
  651. StrCpyN(plvdi->item.pszText, pEntry->lpMsgrInfo->pchMsgrName, plvdi->item.cchTextMax - 1);
  652. plvdi->item.pszText[plvdi->item.cchTextMax - 1] = '\0';
  653. // Don't need redraw now, do it later
  654. hr = MAPI_E_COLLISION; // m_cAddrBook.AutoAddContact(pEntry->lpMsgrInfo->pchMsgrName, pEntry->lpMsgrInfo->pchID);
  655. if(hr == MAPI_E_COLLISION) // already have a contact in AB
  656. {
  657. int Index = -1;
  658. TCHAR *pchID = NULL;
  659. if(MemAlloc((LPVOID *) &pchID, lstrlen(pEntry->lpMsgrInfo->pchID) + 1))
  660. {
  661. StrCpyN(pchID, pEntry->lpMsgrInfo->pchID, lstrlen(pEntry->lpMsgrInfo->pchID) + 1);
  662. do
  663. {
  664. pFindEntry = FindUserEmail(pchID, &Index, FALSE);
  665. }while((pFindEntry != NULL) && (pFindEntry->tag == LPARAM_MENTRY));
  666. if(pFindEntry != NULL)
  667. {
  668. hr = m_cAddrBook.SetDefaultMsgrID(pFindEntry->lpSB, pchID);
  669. if(hr == S_OK)
  670. _ReloadListview();
  671. }
  672. MemFree(pchID);
  673. }
  674. }
  675. //if we not found...
  676. if(hr != S_OK)
  677. {
  678. hr = m_cAddrBook.AutoAddContact(pEntry->lpMsgrInfo->pchMsgrName, pEntry->lpMsgrInfo->pchID);
  679. if(hr == S_OK)
  680. _ReloadListview();
  681. }
  682. }
  683. else
  684. {
  685. StrCpyN(plvdi->item.pszText, pEntry->lpMsgrInfo->pchMsgrName, plvdi->item.cchTextMax - 1);
  686. plvdi->item.pszText[plvdi->item.cchTextMax - 1] = '\0';
  687. // plvdi->item.pszText = pEntry->lpMsgrInfo->pchMsgrName;
  688. }
  689. }
  690. else // Unknown tag
  691. Assert(FALSE);
  692. }
  693. }
  694. return S_OK;
  695. }
  696. LRESULT CMsgrAb::NotifyGetInfoTip(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  697. {
  698. NMLVGETINFOTIP *plvgit = (NMLVGETINFOTIP *) pnmh;
  699. TCHAR szText[CCHMAX_STRINGRES + MAXNAME + 1] = _T("");
  700. TCHAR szName[MAXNAME];
  701. LVITEM lvi;
  702. lvi.mask = LVIF_PARAM;
  703. lvi.iItem = plvgit->iItem;
  704. lvi.iSubItem = plvgit->iSubItem;
  705. ListView_GetItem(m_ctlList, &lvi);
  706. LPMABENTRY pEntry = (LPMABENTRY) lvi.lParam;
  707. #ifdef NEED
  708. if (pEntry->lpMsgrInfo != NULL)
  709. {
  710. StrCpyN(plvgit->pszText, pEntry->lpMsgrInfo->pchMsgrName, plvgit->cchTextMax);
  711. StrCatBuff(plvgit->pszText, m_szLeftBr, plvgit->cchTextMax);
  712. StrCatBuff(plvgit->pszText, pEntry->lpMsgrInfo->pchID, plvgit->cchTextMax);
  713. StrCatBuff(plvgit->pszText, m_szRightBr, plvgit->cchTextMax);
  714. LPCWSTR szStatus;
  715. switch(pEntry->lpMsgrInfo->nStatus)
  716. {
  717. case BIMSTATE_ONLINE:
  718. szStatus = m_szOnline;
  719. break;
  720. case BIMSTATE_BUSY:
  721. szStatus = m_szBusy;
  722. break;
  723. case BIMSTATE_BE_RIGHT_BACK:
  724. szStatus = m_szBack;
  725. break;
  726. case BIMSTATE_IDLE:
  727. szStatus = m_szIdle;
  728. break;
  729. case BIMSTATE_AWAY:
  730. szStatus = m_szAway;
  731. break;
  732. case BIMSTATE_ON_THE_PHONE:
  733. szStatus = m_szOnPhone;
  734. break;
  735. case BIMSTATE_OUT_TO_LUNCH:
  736. szStatus = m_szLunch;
  737. break;
  738. default:
  739. szStatus = m_szOffline;
  740. break;
  741. }
  742. StrCatBuff(plvgit->pszText, szStatus, plvgit->cchTextMax);
  743. }
  744. #endif
  745. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_ABENTRY || pEntry->tag == LPARAM_ABGRPENTRY)
  746. {
  747. Assert(pEntry->pchWABName != NULL);
  748. StrCpyN(szName, pEntry->pchWABName, ARRAYSIZE(szName));
  749. szName[MAXNAME - 1] = _T('\0');
  750. }
  751. else if(pEntry->tag == LPARAM_MENTRY)
  752. {
  753. StrCpyN(szName, pEntry->lpMsgrInfo->pchMsgrName, ARRAYSIZE(szName));
  754. szName[MAXNAME - 1] = _T('\0');
  755. }
  756. else
  757. Assert(FALSE);
  758. StrCpyN(szText, szName, ARRAYSIZE(szText));
  759. if(pEntry->lpMsgrInfo)
  760. {
  761. switch(pEntry->lpMsgrInfo->nStatus)
  762. {
  763. case MSTATEOE_ONLINE:
  764. StrCatBuff(szText, m_szOnline, ARRAYSIZE(szText));
  765. break;
  766. case MSTATEOE_BUSY:
  767. StrCatBuff(szText, m_szBusy, ARRAYSIZE(szText));
  768. break;
  769. case MSTATEOE_BE_RIGHT_BACK:
  770. StrCatBuff(szText, m_szBack, ARRAYSIZE(szText));
  771. break;
  772. case MSTATEOE_IDLE:
  773. StrCatBuff(szText, m_szIdle, ARRAYSIZE(szText));
  774. break;
  775. case MSTATEOE_AWAY:
  776. StrCatBuff(szText, m_szAway, ARRAYSIZE(szText));
  777. break;
  778. case MSTATEOE_ON_THE_PHONE:
  779. StrCatBuff(szText, m_szOnPhone, ARRAYSIZE(szText));
  780. break;
  781. case MSTATEOE_OUT_TO_LUNCH:
  782. StrCatBuff(szText, m_szLunch, ARRAYSIZE(szText));
  783. break;
  784. default:
  785. StrCatBuff(szText, m_szOffline, ARRAYSIZE(szText));
  786. break;
  787. }
  788. StrCpyN(plvgit->pszText, szText, plvgit->cchTextMax);
  789. }
  790. else if (plvgit->dwFlags & LVGIT_UNFOLDED)
  791. {
  792. // If this is not a messenger item and the text
  793. // isn't truncated do not display a tooltip.
  794. plvgit->pszText[0] = L'\0';
  795. }
  796. return 0;
  797. }
  798. LRESULT CMsgrAb::SetUserIcon(LPMABENTRY pEntry, int nStatus, int * pImage)
  799. {
  800. switch(pEntry->tag)
  801. {
  802. case LPARAM_MENTRY:
  803. case LPARAM_MABENTRY:
  804. {
  805. switch(nStatus)
  806. {
  807. case MSTATEOE_ONLINE:
  808. *pImage = IMAGE_ONLINE;
  809. break;
  810. case MSTATEOE_INVISIBLE:
  811. *pImage = IMAGE_STOPSIGN;
  812. break;
  813. case MSTATEOE_BUSY:
  814. *pImage = IMAGE_STOPSIGN;
  815. break;
  816. case MSTATEOE_BE_RIGHT_BACK:
  817. *pImage = IMAGE_CLOCKSIGN; // IMAGE_BE_RIGHT_BACK;
  818. break;
  819. case MSTATEOE_IDLE:
  820. *pImage = IMAGE_CLOCKSIGN; // IMAGE_IDLE;
  821. break;
  822. case MSTATEOE_AWAY:
  823. *pImage = IMAGE_CLOCKSIGN; // IMAGE_AWAY;
  824. break;
  825. case MSTATEOE_ON_THE_PHONE:
  826. *pImage = IMAGE_STOPSIGN; // IMAGE_ON_THE_PHONE;
  827. break;
  828. case MSTATEOE_OUT_TO_LUNCH:
  829. *pImage = IMAGE_CLOCKSIGN; // IMAGE_OUT_TO_LUNCH;
  830. break;
  831. default:
  832. *pImage = IMAGE_OFFLINE;
  833. break;
  834. }
  835. }
  836. break;
  837. case LPARAM_ABGRPENTRY:
  838. // WAB group
  839. *pImage = IMAGE_DISTRIBUTION_LIST;
  840. break;
  841. default:
  842. // Not a buddy...
  843. if(pEntry->fCertificate)
  844. *pImage = IMAGE_CERT;
  845. else
  846. *pImage = IMAGE_NEW_MESSAGE;
  847. break;
  848. }
  849. return(S_OK);
  850. }
  851. // Return MAB entry for first selected item
  852. LPMABENTRY CMsgrAb::GetSelectedEntry()
  853. {
  854. LVITEM lvi;
  855. // Get the focused item
  856. lvi.iItem = ListView_GetNextItem(m_ctlList, -1, LVNI_SELECTED | LVNI_FOCUSED);
  857. // Get the lParam for that item
  858. if (lvi.iItem != -1)
  859. {
  860. lvi.iSubItem = 0;
  861. lvi.mask = LVIF_PARAM;
  862. if(ListView_GetItem(m_ctlList, &lvi))
  863. return((LPMABENTRY) lvi.lParam);
  864. }
  865. return(NULL); // unscucces
  866. }
  867. /*
  868. LRESULT CMsgrAb::CmdMsgrOptions(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  869. {
  870. return(m_pCMsgrList->LaunchOptionsUI()); // (MOPTDLG_GENERAL_PAGE);
  871. }
  872. */
  873. // Exec for Properties command
  874. LRESULT CMsgrAb::CmdProperties(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  875. {
  876. LPMABENTRY pEntry = GetSelectedEntry();
  877. if(pEntry)
  878. {
  879. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_ABENTRY || pEntry->tag == LPARAM_ABGRPENTRY)
  880. m_cAddrBook.ShowDetails(m_hWnd, pEntry->lpSB);
  881. }
  882. return (0);
  883. }
  884. // Check entry for possibility to send Instant message
  885. LPMABENTRY CMsgrAb::GetEntryForSendInstMsg(LPMABENTRY pEntry)
  886. {
  887. if(ListView_GetSelectedCount(m_ctlList) == 1)
  888. {
  889. if(!pEntry) // if we don'y have pEntry yet then get it
  890. pEntry = GetSelectedEntry();
  891. if(pEntry && (pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_MENTRY) &&
  892. (pEntry->lpMsgrInfo->nStatus != MSTATEOE_OFFLINE) && (pEntry->lpMsgrInfo->nStatus != MSTATEOE_INVISIBLE) &&
  893. !(m_pCMsgrList->IsLocalName(pEntry->lpMsgrInfo->pchID)))
  894. return(pEntry);
  895. }
  896. if(m_pCMsgrList)
  897. {
  898. if(m_pCMsgrList->IsLocalOnline() && (m_pCMsgrList->GetCount() > 0))
  899. return(NULL); // should be /*return((LPMABENTRY) -1);*/ - temporary disabled (YST)
  900. }
  901. return(NULL);
  902. }
  903. // Display right-mouse click (context) menu
  904. LRESULT CMsgrAb::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  905. {
  906. LPMABENTRY pEntry;
  907. HMENU hPopup = 0;
  908. HWND hwndHeader;
  909. int id = 0;
  910. POINT pt = { (int)(short) LOWORD(lParam), (int)(short) HIWORD(lParam) };
  911. int n = -1;
  912. // Figure out if this came from the keyboard or not
  913. if (lParam == -1)
  914. {
  915. Assert((HWND) wParam == m_ctlList);
  916. int i = ListView_GetFirstSel(m_ctlList);
  917. if (i == -1)
  918. return (0);
  919. ListView_GetItemPosition(m_ctlList, i, &pt);
  920. m_ctlList.ClientToScreen(&pt);
  921. }
  922. LVHITTESTINFO lvhti;
  923. lvhti.pt = pt;
  924. m_ctlList.ScreenToClient(&lvhti.pt);
  925. ListView_HitTest(m_ctlList, &lvhti);
  926. if (lvhti.iItem == -1)
  927. return (0);
  928. // Load the context menu
  929. hPopup = LoadPopupMenu(IDR_BA_POPUP);
  930. if (!hPopup)
  931. goto exit;
  932. pEntry = GetSelectedEntry();
  933. pEntry = GetEntryForSendInstMsg(pEntry);
  934. if((pEntry == NULL) && (g_dwHideMessenger != BL_NOTINST))
  935. SetMenuDefaultItem(hPopup, ID_SEND_MESSAGE, FALSE);
  936. else if((g_dwHideMessenger == BL_NOTINST) || (((INT_PTR) pEntry) == -1))
  937. SetMenuDefaultItem(hPopup, ID_SEND_MESSAGE, FALSE);
  938. else
  939. SetMenuDefaultItem(hPopup, ID_SEND_INSTANT_MESSAGE, FALSE);
  940. if ((g_dwHideMessenger == BL_HIDE) || (g_dwHideMessenger == BL_DISABLE))
  941. {
  942. DeleteMenu(hPopup, ID_SEND_INSTANT_MESSAGE, MF_BYCOMMAND);
  943. DeleteMenu(hPopup, ID_SET_ONLINE_CONTACT, MF_BYCOMMAND);
  944. DeleteMenu(hPopup, ID_NEW_ONLINE_CONTACT, MF_BYCOMMAND);
  945. }
  946. MenuUtil_EnablePopupMenu(hPopup, this);
  947. TrackPopupMenuEx(hPopup, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  948. pt.x, pt.y, m_hWnd, NULL);
  949. exit:
  950. if (hPopup)
  951. DestroyMenu(hPopup);
  952. return (0);
  953. }
  954. //
  955. // FUNCTION: CMsgrAb::DragEnter()
  956. //
  957. // PURPOSE: This get's called when the user starts dragging an object
  958. // over our target area.
  959. //
  960. // PARAMETERS:
  961. // <in> pDataObject - Pointer to the data object being dragged
  962. // <in> grfKeyState - Pointer to the current key states
  963. // <in> pt - Point in screen coordinates of the mouse
  964. // <out> pdwEffect - Where we return whether this is a valid place for
  965. // pDataObject to be dropped and if so what type of
  966. // drop.
  967. //
  968. // RETURN VALUE:
  969. // S_OK - The function succeeded.
  970. //
  971. STDMETHODIMP CMsgrAb::DragEnter(IDataObject* pDataObject, DWORD grfKeyState,
  972. POINTL pt, DWORD* pdwEffect)
  973. {
  974. IEnumFORMATETC *pEnum;
  975. FORMATETC fe;
  976. ULONG celtFetched;
  977. // Verify we got this
  978. if (!pDataObject)
  979. return (S_OK);
  980. // Init
  981. ZeroMemory(&fe, sizeof(FORMATETC));
  982. // Set the default return value to be failure
  983. *pdwEffect = DROPEFFECT_NONE;
  984. // Get the FORMATETC enumerator for this data object
  985. if (SUCCEEDED(pDataObject->EnumFormatEtc(DATADIR_GET, &pEnum)))
  986. {
  987. // Walk through the data types to see if we can find the ones we're
  988. // interested in.
  989. pEnum->Reset();
  990. while (S_OK == pEnum->Next(1, &fe, &celtFetched))
  991. {
  992. Assert(celtFetched == 1);
  993. // The only format we care about is CF_INETMSG
  994. if ((fe.cfFormat == CF_INETMSG) /*|| (fe.cfFormat == CF_OEMESSAGES)*/)
  995. {
  996. *pdwEffect = DROPEFFECT_COPY;
  997. break;
  998. }
  999. }
  1000. pEnum->Release();
  1001. }
  1002. // We we're going to allow the drop, then keep a copy of the data object
  1003. if (*pdwEffect != DROPEFFECT_NONE)
  1004. {
  1005. m_pDataObject = pDataObject;
  1006. m_pDataObject->AddRef();
  1007. m_cf = fe.cfFormat;
  1008. m_fRight = (grfKeyState & MK_RBUTTON);
  1009. }
  1010. return (S_OK);
  1011. }
  1012. //
  1013. // FUNCTION: CMsgrAb::DragOver()
  1014. //
  1015. // PURPOSE: This is called as the user drags an object over our target.
  1016. // If we allow this object to be dropped on us, then we will have
  1017. // a pointer in m_pDataObject.
  1018. //
  1019. // PARAMETERS:
  1020. // <in> grfKeyState - Pointer to the current key states
  1021. // <in> pt - Point in screen coordinates of the mouse
  1022. // <out> pdwEffect - Where we return whether this is a valid place for
  1023. // pDataObject to be dropped and if so what type of
  1024. // drop.
  1025. //
  1026. // RETURN VALUE:
  1027. // S_OK - The function succeeded.
  1028. //
  1029. STDMETHODIMP CMsgrAb::DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
  1030. {
  1031. // If we didn't cache a data object in IDropTarget::DragEnter(), we
  1032. // blow this off.
  1033. if (NULL == m_pDataObject)
  1034. {
  1035. *pdwEffect = DROPEFFECT_NONE;
  1036. return (S_OK);
  1037. }
  1038. // We always do a copy
  1039. *pdwEffect = DROPEFFECT_COPY;
  1040. return (S_OK);
  1041. }
  1042. //
  1043. // FUNCTION: CMsgrAb::DragLeave()
  1044. //
  1045. // PURPOSE: Allows us to release any stored data we have from a successful
  1046. // DragEnter()
  1047. //
  1048. // RETURN VALUE:
  1049. // S_OK - Everything is groovy
  1050. //
  1051. STDMETHODIMP CMsgrAb::DragLeave(void)
  1052. {
  1053. // Free everything up at this point.
  1054. if (NULL != m_pDataObject)
  1055. {
  1056. m_pDataObject->Release();
  1057. m_pDataObject = 0;
  1058. m_cf = 0;
  1059. }
  1060. return (S_OK);
  1061. }
  1062. //
  1063. // FUNCTION: CMsgrAb::Drop()
  1064. //
  1065. // PURPOSE: The user has let go of the object over our target. If we
  1066. // can accept this object we will already have the pDataObject
  1067. // stored in m_pDataObject.
  1068. //
  1069. // PARAMETERS:
  1070. // <in> pDataObject - Pointer to the data object being dragged
  1071. // <in> grfKeyState - Pointer to the current key states
  1072. // <in> pt - Point in screen coordinates of the mouse
  1073. // <out> pdwEffect - Where we return whether this is a valid place for
  1074. // pDataObject to be dropped and if so what type of
  1075. // drop.
  1076. //
  1077. // RETURN VALUE:
  1078. // S_OK - Everything worked OK
  1079. //
  1080. STDMETHODIMP CMsgrAb::Drop(IDataObject* pDataObject, DWORD grfKeyState,
  1081. POINTL pt, DWORD* pdwEffect)
  1082. {
  1083. HRESULT hr = S_OK;
  1084. FORMATETC fe;
  1085. STGMEDIUM stm;
  1086. IMimeMessage *pMessage = 0;
  1087. // Get the stream from the DataObject
  1088. ZeroMemory(&stm, sizeof(STGMEDIUM));
  1089. SETDefFormatEtc(fe, CF_INETMSG, TYMED_ISTREAM);
  1090. if (FAILED(hr = pDataObject->GetData(&fe, &stm)))
  1091. goto exit;
  1092. // Create a new message object
  1093. if (FAILED(hr = HrCreateMessage(&pMessage)))
  1094. goto exit;
  1095. // Load the message from the stream
  1096. if (FAILED(hr = pMessage->Load(stm.pstm)))
  1097. goto exit;
  1098. // If this was a right-drag, then we bring up a context menu etc.
  1099. if (m_fRight)
  1100. _DoDropMenu(pt, pMessage);
  1101. else
  1102. _DoDropMessage(pMessage);
  1103. exit:
  1104. ReleaseStgMedium(&stm);
  1105. SafeRelease(pMessage);
  1106. m_pDataObject->Release();
  1107. m_pDataObject = 0;
  1108. m_cf = 0;
  1109. return (hr);
  1110. }
  1111. HRESULT CMsgrAb::_DoDropMessage(LPMIMEMESSAGE pMessage)
  1112. {
  1113. HRESULT hr;
  1114. ADDRESSLIST addrList = { 0 };
  1115. ULONG i;
  1116. SECSTATE secState = {0};
  1117. BOOL fSignTrusted = FALSE;
  1118. if(FAILED(hr = HandleSecurity(m_hWnd, pMessage)))
  1119. return hr;
  1120. if (IsSecure(pMessage) && SUCCEEDED(HrGetSecurityState(pMessage, &secState, NULL)))
  1121. {
  1122. fSignTrusted = !!IsSignTrusted(&secState);
  1123. CleanupSECSTATE(&secState);
  1124. }
  1125. // Get the address list from the message
  1126. hr = pMessage->GetAddressTypes(IAT_FROM | IAT_SENDER, IAP_FRIENDLYW | IAP_EMAIL | IAP_ADRTYPE, &addrList);
  1127. if (FAILED(hr))
  1128. goto exit;
  1129. // Loop through the addresses
  1130. for (i = 0; i < addrList.cAdrs; i++)
  1131. {
  1132. m_cAddrBook.AddAddress(addrList.prgAdr[i].pszFriendlyW, addrList.prgAdr[i].pszEmail);
  1133. #ifdef DEAD
  1134. TCHAR *pch = StrStr(CharUpper(addrList.prgAdr[i].pszEmail), szHotMail);
  1135. if((pch != NULL) && m_pCMsgrList)
  1136. m_pCMsgrList->AddUser(addrList.prgAdr[i].pszEmail);
  1137. #endif // DEAD
  1138. }
  1139. if(fSignTrusted)
  1140. {
  1141. FILETIME ftNull = {0};
  1142. HrAddSenderCertToWab(NULL, pMessage, NULL, NULL, NULL, ftNull, WFF_CREATE);
  1143. }
  1144. #ifdef NEEDED
  1145. // Reload the table
  1146. _ReloadListview();
  1147. #endif
  1148. exit:
  1149. return (S_OK);
  1150. }
  1151. HRESULT CMsgrAb::_DoDropMenu(POINTL pt, LPMIMEMESSAGE pMessage)
  1152. {
  1153. HRESULT hr;
  1154. ADDRESSLIST addrList = { 0 };
  1155. ULONG i;
  1156. HMENU hPopup = 0, hSubMenu = 0;
  1157. UINT id = 0;
  1158. BOOL fReload = FALSE;
  1159. SECSTATE secState = {0};
  1160. BOOL fSignTrusted = FALSE;
  1161. // Get the address list from the message
  1162. if(FAILED(hr = HandleSecurity(m_hWnd, pMessage)))
  1163. return hr;
  1164. if (IsSecure(pMessage) && SUCCEEDED(HrGetSecurityState(pMessage, &secState, NULL)))
  1165. {
  1166. fSignTrusted = !!IsSignTrusted(&secState);
  1167. CleanupSECSTATE(&secState);
  1168. }
  1169. hr = pMessage->GetAddressTypes(IAT_KNOWN, IAP_FRIENDLYW | IAP_EMAIL | IAP_ADRTYPE, &addrList);
  1170. if (FAILED(hr))
  1171. goto exit;
  1172. // Load the context menu
  1173. hPopup = LoadPopupMenu(IDR_BA_DRAGDROP_POPUP);
  1174. if (!hPopup)
  1175. goto exit;
  1176. // Bold the "Save All" item
  1177. MENUITEMINFO mii;
  1178. mii.cbSize = sizeof(mii);
  1179. mii.fMask = MIIM_STATE;
  1180. if (GetMenuItemInfo(hPopup, ID_SAVE_ALL, FALSE, &mii))
  1181. {
  1182. mii.fState |= MFS_DEFAULT;
  1183. SetMenuItemInfo(hPopup, ID_SAVE_ALL, FALSE, &mii);
  1184. }
  1185. // Create the "Save >" item
  1186. hSubMenu = CreatePopupMenu();
  1187. // Loop through the addresses
  1188. for (i = 0; i < addrList.cAdrs; i++)
  1189. {
  1190. AppendMenuWrapW(hSubMenu, MF_STRING | MF_ENABLED, ID_SAVE_ADDRESS_FIRST + i, addrList.prgAdr[i].pszFriendlyW);
  1191. }
  1192. mii.fMask = MIIM_SUBMENU;
  1193. mii.hSubMenu = hSubMenu;
  1194. SetMenuItemInfo(hPopup, ID_SAVE, FALSE, &mii);
  1195. id = TrackPopupMenuEx(hPopup, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  1196. pt.x, pt.y, m_hWnd, NULL);
  1197. if (id == ID_SAVE_ALL_ADDRESSES)
  1198. {
  1199. for (i = 0; i < addrList.cAdrs; i++)
  1200. {
  1201. m_cAddrBook.AddAddress(addrList.prgAdr[i].pszFriendlyW, addrList.prgAdr[i].pszEmail);
  1202. }
  1203. fReload = TRUE;
  1204. }
  1205. else if (id >= ID_SAVE_ADDRESS_FIRST && id < ID_SAVE_ADDRESS_LAST)
  1206. {
  1207. m_cAddrBook.AddAddress(addrList.prgAdr[id - ID_SAVE_ADDRESS_FIRST].pszFriendlyW,
  1208. addrList.prgAdr[id - ID_SAVE_ADDRESS_FIRST].pszEmail);
  1209. fReload = TRUE;
  1210. }
  1211. if(fSignTrusted)
  1212. {
  1213. FILETIME ftNull = {0};
  1214. HrAddSenderCertToWab(NULL, pMessage, NULL, NULL, NULL, ftNull, WFF_CREATE);
  1215. }
  1216. if (fReload)
  1217. {
  1218. // Reload the table
  1219. _ReloadListview();
  1220. }
  1221. exit:
  1222. if (hSubMenu)
  1223. DestroyMenu(hSubMenu);
  1224. if (hPopup)
  1225. DestroyMenu(hPopup);
  1226. return (S_OK);
  1227. }
  1228. LRESULT CMsgrAb::CmdDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1229. {
  1230. LVITEM lvi;
  1231. ENTRYLIST rList;
  1232. ULONG cValues;
  1233. SBinary UNALIGNED *pEntryId;
  1234. HRESULT hr = S_OK;
  1235. BOOL fConfirm = TRUE;
  1236. TCHAR szText[CCHMAX_STRINGRES + MAXNAME];
  1237. TCHAR szBuff[CCHMAX_STRINGRES];
  1238. if(m_delItem > 0)
  1239. {
  1240. MessageBeep(MB_OK);
  1241. return(S_OK);
  1242. }
  1243. if(m_fNoRemove)
  1244. m_fNoRemove = FALSE;
  1245. lvi.mask = LVIF_PARAM;
  1246. lvi.iSubItem = 0;
  1247. lvi.iItem = -1;
  1248. // Figure out how many items are selected
  1249. cValues = ListView_GetSelectedCount(m_ctlList);
  1250. m_delItem = cValues;
  1251. if (cValues != 1)
  1252. {
  1253. // Remove only Msgr entry
  1254. AthLoadString(idsBADelMultiple, szBuff, ARRAYSIZE(szBuff));
  1255. wnsprintf(szText, ARRAYSIZE(szText), szBuff, cValues);
  1256. if(IDNO == AthMessageBox(m_hWnd, MAKEINTRESOURCE(idsAthena), szText,
  1257. NULL, MB_YESNO | MB_ICONEXCLAMATION))
  1258. return (0);
  1259. else if(m_fNoRemove)
  1260. goto ErrBeep;
  1261. else
  1262. fConfirm = FALSE;
  1263. // Assert(FALSE);
  1264. // return (0);
  1265. }
  1266. while(cValues > 0)
  1267. {
  1268. lvi.iItem = ListView_GetNextItem(m_ctlList, lvi.iItem, LVNI_SELECTED);
  1269. if(lvi.iItem < 0)
  1270. {
  1271. ErrBeep:
  1272. MessageBeep(MB_OK);
  1273. return(S_OK);
  1274. }
  1275. // Get the item from the ListView
  1276. if(ListView_GetItem(m_ctlList, &lvi) == FALSE)
  1277. goto ErrBeep;
  1278. // Check buddy state
  1279. LPMABENTRY pEntry = (LPMABENTRY) lvi.lParam;
  1280. if(pEntry->tag == LPARAM_MENTRY)
  1281. {
  1282. if(m_pCMsgrList->IsLocalOnline())
  1283. {
  1284. // Remove only Msgr entry
  1285. if(fConfirm)
  1286. {
  1287. AthLoadString(idsBADelBLEntry, szBuff, ARRAYSIZE(szBuff));
  1288. wnsprintf(szText, ARRAYSIZE(szText), szBuff, pEntry->lpMsgrInfo->pchMsgrName);
  1289. if(IDNO == AthMessageBox(m_hWnd, MAKEINTRESOURCE(idsAthena), szText,
  1290. NULL, MB_YESNO | MB_ICONEXCLAMATION))
  1291. {
  1292. m_delItem = 0;
  1293. return (0);
  1294. }
  1295. else if(m_fNoRemove)
  1296. goto ErrBeep;
  1297. }
  1298. if(pEntry->lpMsgrInfo)
  1299. {
  1300. m_delItem--;
  1301. hr = m_pCMsgrList->FindAndDeleteUser(pEntry->lpMsgrInfo->pchID, TRUE /* fDelete*/);
  1302. }
  1303. else
  1304. {
  1305. m_delItem = 0;
  1306. return(S_OK);
  1307. }
  1308. }
  1309. else
  1310. goto ErrBeep;
  1311. }
  1312. else if(pEntry->tag == LPARAM_MABENTRY)
  1313. {
  1314. int nID = IDNO;
  1315. if(fConfirm)
  1316. {
  1317. AthLoadString(idsBADelBLABEntry, szBuff, ARRAYSIZE(szBuff));
  1318. wnsprintf(szText, ARRAYSIZE(szText), szBuff, pEntry->pchWABName);
  1319. nID = AthMessageBox(m_hWnd, MAKEINTRESOURCE(idsAthena), szText,
  1320. NULL, MB_YESNOCANCEL | MB_ICONEXCLAMATION);
  1321. }
  1322. if(((nID == IDYES) || !fConfirm) && !m_fNoRemove)
  1323. {
  1324. if(m_pCMsgrList->IsLocalOnline())
  1325. {
  1326. // Remove only Msgr & AB entry
  1327. if(pEntry->lpMsgrInfo)
  1328. hr = m_pCMsgrList->FindAndDeleteUser(pEntry->lpMsgrInfo->pchID, TRUE /* fDelete*/);
  1329. else
  1330. {
  1331. m_delItem = 0;
  1332. return(S_OK);
  1333. }
  1334. // Allocate a structure big enough for all of 'em
  1335. if (MemAlloc((LPVOID *) &(rList.lpbin), sizeof(SBinary)))
  1336. {
  1337. rList.cValues = 0;
  1338. pEntryId = rList.lpbin;
  1339. *pEntryId = *(pEntry->lpSB);
  1340. pEntryId++;
  1341. rList.cValues = 1;
  1342. // Tell the WAB to delete 'em
  1343. m_nChCount++; // increase count of our notification messages from WAB
  1344. m_cAddrBook.DeleteItems(&rList);
  1345. // Free our array
  1346. MemFree(rList.lpbin);
  1347. }
  1348. // m_delItem++;
  1349. ListView_DeleteItem(m_ctlList, lvi.iItem);
  1350. lvi.iItem--;
  1351. ListView_SetItemState(m_ctlList, ((lvi.iItem >= 0) ? lvi.iItem : 0), LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  1352. }
  1353. else
  1354. MessageBeep(MB_OK);
  1355. }
  1356. else if((nID == IDNO) && !m_fNoRemove)
  1357. {
  1358. // Remove only Msgr entry
  1359. m_delItem--;
  1360. hr = m_pCMsgrList->FindAndDeleteUser(pEntry->lpMsgrInfo->pchID, TRUE /* fDelete*/);
  1361. }
  1362. else
  1363. {
  1364. // Remove nothing
  1365. m_delItem--;
  1366. hr = S_OK;
  1367. }
  1368. }
  1369. else
  1370. {
  1371. // remove AN entry (group or contact)
  1372. if(fConfirm)
  1373. {
  1374. AthLoadString(idsBADelABEntry, szBuff, ARRAYSIZE(szBuff));
  1375. wnsprintf(szText, ARRAYSIZE(szText), szBuff, pEntry->pchWABName);
  1376. if(IDNO == AthMessageBox(m_hWnd, MAKEINTRESOURCE(idsAthena), szText,
  1377. NULL, MB_YESNO | MB_ICONEXCLAMATION))
  1378. {
  1379. m_delItem = 0;
  1380. return(0);
  1381. }
  1382. else if(m_fNoRemove)
  1383. goto ErrBeep;
  1384. }
  1385. // Allocate a structure big enough for all of 'em
  1386. if(pEntry->lpSB)
  1387. {
  1388. if (MemAlloc((LPVOID *) &(rList.lpbin), sizeof(SBinary)))
  1389. {
  1390. rList.cValues = 0;
  1391. pEntryId = rList.lpbin;
  1392. *pEntryId = *(pEntry->lpSB);
  1393. pEntryId++;
  1394. rList.cValues = 1;
  1395. // Tell the WAB to delete 'em
  1396. m_nChCount++; // increase count of our notification messages from WAB
  1397. m_cAddrBook.DeleteItems(&rList);
  1398. // Free our array
  1399. MemFree(rList.lpbin);
  1400. }
  1401. }
  1402. // m_delItem++;
  1403. ListView_DeleteItem(m_ctlList, lvi.iItem);
  1404. lvi.iItem--;
  1405. }
  1406. cValues--;
  1407. }
  1408. if(ListView_GetItemCount(m_ctlList) > 0)
  1409. {
  1410. m_cEmptyList.Hide();
  1411. ListView_SetItemState(m_ctlList, ((lvi.iItem >= 0) ? lvi.iItem : 0), LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  1412. }
  1413. else
  1414. m_cEmptyList.Show(m_ctlList, (LPTSTR) m_szEmptyList);
  1415. return (hr);
  1416. }
  1417. STDMETHODIMP CMsgrAb::get_InstMsg(BOOL * pVal)
  1418. {
  1419. *pVal = (GetEntryForSendInstMsg() != NULL);
  1420. return S_OK;
  1421. }
  1422. /* STDMETHODIMP CMsgrAb::put_InstMsg(BOOL newVal)
  1423. {
  1424. return S_OK;
  1425. } */
  1426. STDMETHODIMP CMsgrAb::HasFocusIO()
  1427. {
  1428. if (GetFocus() == m_ctlList)
  1429. return S_OK;
  1430. else
  1431. return S_FALSE;
  1432. }
  1433. STDMETHODIMP CMsgrAb::TranslateAcceleratorIO(LPMSG lpMsg)
  1434. {
  1435. #if 0
  1436. if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_DELETE)
  1437. {
  1438. SendMessage(WM_COMMAND, ID_DELETE_CONTACT, 0);
  1439. return (S_OK);
  1440. }
  1441. #endif
  1442. return (S_FALSE);
  1443. }
  1444. STDMETHODIMP CMsgrAb::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
  1445. {
  1446. if (!m_pObjSite)
  1447. return E_FAIL;
  1448. if (!IsWindow(m_hWnd))
  1449. {
  1450. IOleWindow *pOleWnd;
  1451. if (SUCCEEDED(m_pObjSite->QueryInterface(IID_IOleWindow, (LPVOID*)&pOleWnd)))
  1452. {
  1453. if(SUCCEEDED(pOleWnd->GetWindow(&m_hwndParent)))
  1454. {
  1455. //Will be resized by parent
  1456. RECT rect = {0};
  1457. m_hWnd = CreateControlWindow(m_hwndParent, rect);
  1458. if (!m_hWnd)
  1459. return E_FAIL;
  1460. }
  1461. }
  1462. pOleWnd->Release();
  1463. }
  1464. if (fActivate)
  1465. {
  1466. m_ctlList.SetFocus();
  1467. }
  1468. m_pObjSite->OnFocusChangeIS((IInputObject*) this, fActivate);
  1469. return (S_OK);
  1470. }
  1471. STDMETHODIMP CMsgrAb::SetSite(IUnknown *punksite)
  1472. {
  1473. //If we already have a site, we release it
  1474. SafeRelease(m_pObjSite);
  1475. IInputObjectSite *pObjSite;
  1476. if ((punksite) && (SUCCEEDED(punksite->QueryInterface(IID_IInputObjectSite, (LPVOID*)&pObjSite))))
  1477. {
  1478. m_pObjSite = pObjSite;
  1479. return S_OK;
  1480. }
  1481. return E_FAIL;
  1482. }
  1483. STDMETHODIMP CMsgrAb::GetSite(REFIID riid, LPVOID *ppvSite)
  1484. {
  1485. return E_NOTIMPL;
  1486. }
  1487. HRESULT CMsgrAb::RegisterFlyOut(CFolderBar *pFolderBar)
  1488. {
  1489. Assert(m_pFolderBar == NULL);
  1490. m_pFolderBar = pFolderBar;
  1491. m_pFolderBar->AddRef();
  1492. return S_OK;
  1493. }
  1494. HRESULT CMsgrAb::RevokeFlyOut(void)
  1495. {
  1496. if (m_pFolderBar)
  1497. {
  1498. m_pFolderBar->Release();
  1499. m_pFolderBar = NULL;
  1500. }
  1501. return S_OK;
  1502. }
  1503. void CMsgrAb::_ReloadListview(void)
  1504. {
  1505. // Turn off redrawing
  1506. if(m_delItem != 0)
  1507. m_fNoRemove = TRUE;
  1508. // else
  1509. // m_fNoRemove = FALSE;
  1510. m_delItem = ListView_GetItemCount(m_ctlList);
  1511. SetWindowRedraw(m_ctlList, FALSE);
  1512. int index = ListView_GetNextItem(m_ctlList, -1, LVIS_SELECTED | LVIS_FOCUSED);
  1513. if(index == -1)
  1514. index = 0;
  1515. // Delete everything and reload
  1516. SideAssert(ListView_DeleteAllItems(m_ctlList));
  1517. FillMsgrList(); // User list reload
  1518. m_cAddrBook.LoadWabContents(m_ctlList, this);
  1519. ListView_SetItemState(m_ctlList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  1520. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  1521. ListView_EnsureVisible(m_ctlList, index, FALSE);
  1522. SetWindowRedraw(m_ctlList, TRUE);
  1523. // Invalidate(TRUE); //
  1524. if(ListView_GetItemCount(m_ctlList) > 0)
  1525. m_cEmptyList.Hide();
  1526. else
  1527. m_cEmptyList.Show(m_ctlList, (LPTSTR) m_szEmptyList);
  1528. UpdateWindow(/*m_ctlList*/);
  1529. return;
  1530. }
  1531. ULONG STDMETHODCALLTYPE CMsgrAb::OnNotify(ULONG cNotif, LPNOTIFICATION pNotifications)
  1532. {
  1533. // Well something changed in WAB, but we don't know what. We should reload.
  1534. // Sometimes these changes from us and we should ignore it.
  1535. if(m_nChCount > 0)
  1536. m_nChCount--;
  1537. else
  1538. _ReloadListview();
  1539. return (0);
  1540. }
  1541. LRESULT CMsgrAb::CmdFind(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1542. {
  1543. m_cAddrBook.Find(m_hWnd);
  1544. return (0);
  1545. }
  1546. LRESULT CMsgrAb::CmdNewGroup(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1547. {
  1548. m_cAddrBook.NewGroup(m_hWnd);
  1549. return (0);
  1550. }
  1551. LRESULT CMsgrAb::CmdMsgrAb(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1552. {
  1553. m_cAddrBook.AddressBook(m_hWnd);
  1554. return (0);
  1555. }
  1556. void CMsgrAb::AddMsgrListItem(LPMINFO lpMsgrInfo)
  1557. {
  1558. LV_ITEM lvItem;
  1559. m_cEmptyList.Hide(); // m,ust be sure that empty mesage is hide
  1560. lvItem.iItem = ListView_GetItemCount(m_ctlList);
  1561. lvItem.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
  1562. lvItem.lParam = (LPARAM) AddBlabEntry(LPARAM_MENTRY, NULL, lpMsgrInfo, NULL, NULL, FALSE);
  1563. lvItem.iSubItem = 0;
  1564. lvItem.pszText = LPSTR_TEXTCALLBACK;
  1565. lvItem.iImage = I_IMAGECALLBACK;
  1566. // SetUserIcon(LPARAM_MENTRY, lpMsgrInfo->nStatus, &(lvItem.iImage));
  1567. ListView_InsertItem(m_ctlList, &lvItem);
  1568. return;
  1569. }
  1570. HRESULT CMsgrAb::FillMsgrList()
  1571. {
  1572. LPMINFO pEntry = NULL;
  1573. if(!m_pCMsgrList)
  1574. {
  1575. // Assert(FALSE); // Possible situation. See Bug 31262
  1576. return(S_OK);
  1577. }
  1578. pEntry = m_pCMsgrList->GetFirstMsgrItem();
  1579. while(pEntry)
  1580. {
  1581. AddMsgrListItem(pEntry);
  1582. pEntry = m_pCMsgrList->GetNextMsgrItem(pEntry);
  1583. }
  1584. return S_OK;
  1585. }
  1586. // Add BLAB table entry
  1587. LPMABENTRY CMsgrAb::AddBlabEntry(MABENUM tag, LPSBinary lpSB, LPMINFO lpMsgrInfo, TCHAR *pchMail, TCHAR *pchDisplayName, BOOL fCert)
  1588. {
  1589. TCHAR szName[MAXNAME];
  1590. LPMABENTRY pEntry = NULL;
  1591. TCHAR *pchName = NULL;
  1592. if (!MemAlloc((LPVOID *) &pEntry, sizeof(mabEntry)))
  1593. return(NULL);
  1594. pEntry->tag = tag;
  1595. pEntry->lpSB = lpSB;
  1596. pEntry->pchWABName = NULL;
  1597. pEntry->pchWABID = NULL;
  1598. pEntry->fCertificate = fCert;
  1599. if(lpSB != NULL)
  1600. {
  1601. if(!pchDisplayName)
  1602. {
  1603. m_cAddrBook.GetDisplayName(pEntry->lpSB, szName, MAXNAME);
  1604. pchName = szName;
  1605. }
  1606. else
  1607. pchName = pchDisplayName;
  1608. if (!MemAlloc((LPVOID *) &(pEntry->pchWABName), lstrlen(pchName) + 1 ))
  1609. {
  1610. MemFree(pEntry);
  1611. return(NULL);
  1612. }
  1613. StrCpyN(pEntry->pchWABName, pchName, lstrlen(pchName) + 1);
  1614. if(pchMail != NULL)
  1615. {
  1616. if (MemAlloc((LPVOID *) &(pEntry->pchWABID), lstrlen(pchMail) + 1 ))
  1617. StrCpyN(pEntry->pchWABID, pchMail, lstrlen(pchMail) + 1);
  1618. }
  1619. }
  1620. if(lpMsgrInfo && MemAlloc((LPVOID *) &(pEntry->lpMsgrInfo), sizeof(struct _tag_OEMsgrInfo)))
  1621. {
  1622. pEntry->lpMsgrInfo->nStatus = lpMsgrInfo->nStatus;
  1623. pEntry->lpMsgrInfo->pPrev = NULL;
  1624. pEntry->lpMsgrInfo->pNext = NULL;
  1625. if(MemAlloc((LPVOID *) &(pEntry->lpMsgrInfo->pchMsgrName), lstrlen(lpMsgrInfo->pchMsgrName) + 1))
  1626. StrCpyN(pEntry->lpMsgrInfo->pchMsgrName, lpMsgrInfo->pchMsgrName, lstrlen(lpMsgrInfo->pchMsgrName) + 1);
  1627. else
  1628. pEntry->lpMsgrInfo->pchMsgrName = NULL;
  1629. if(MemAlloc((LPVOID *) &(pEntry->lpMsgrInfo->pchID), lstrlen(lpMsgrInfo->pchID) + 1))
  1630. StrCpyN(pEntry->lpMsgrInfo->pchID, lpMsgrInfo->pchID, lstrlen(lpMsgrInfo->pchID) + 1);
  1631. else
  1632. pEntry->lpMsgrInfo->pchID = NULL;
  1633. }
  1634. else
  1635. pEntry->lpMsgrInfo = NULL;
  1636. return(pEntry);
  1637. }
  1638. void CMsgrAb::RemoveMsgrInfo(LPMINFO lpMsgrInfo)
  1639. {
  1640. SafeMemFree(lpMsgrInfo->pchMsgrName);
  1641. SafeMemFree(lpMsgrInfo->pchID);
  1642. SafeMemFree(lpMsgrInfo);
  1643. }
  1644. // Remove BLAB table entry
  1645. void CMsgrAb::RemoveBlabEntry(LPMABENTRY lpEntry)
  1646. {
  1647. if(lpEntry == NULL)
  1648. return;
  1649. if(lpEntry->pchWABName)
  1650. MemFree(lpEntry->pchWABName);
  1651. if(lpEntry->pchWABID)
  1652. MemFree(lpEntry->pchWABID);
  1653. if(lpEntry->lpMsgrInfo)
  1654. {
  1655. RemoveMsgrInfo(lpEntry->lpMsgrInfo);
  1656. lpEntry->lpMsgrInfo = NULL;
  1657. }
  1658. MemFree(lpEntry);
  1659. lpEntry = NULL;
  1660. return;
  1661. }
  1662. // This function check buddy and if we have AB entry then set LPARAM_MABENTRY tag
  1663. void CMsgrAb::CheckAndAddAbEntry(LPSBinary lpSB, TCHAR *pchEmail, TCHAR *pchDisplayName, DWORD nFlag)
  1664. {
  1665. TCHAR szName[MAXNAME];
  1666. LPMABENTRY pEntry = NULL;
  1667. LV_ITEM lvItem;
  1668. lvItem.iItem = ListView_GetItemCount(m_ctlList);
  1669. lvItem.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
  1670. lvItem.iSubItem = 0;
  1671. lvItem.pszText = LPSTR_TEXTCALLBACK;
  1672. lvItem.iImage = I_IMAGECALLBACK;
  1673. m_cEmptyList.Hide(); // m,ust be sure that empty mesage is hide
  1674. if(!(nFlag & MAB_BUDDY))
  1675. {
  1676. lvItem.lParam = (LPARAM) AddBlabEntry((nFlag & MAB_GROUP) ? LPARAM_ABGRPENTRY : LPARAM_ABENTRY, lpSB, NULL, pchEmail,
  1677. pchDisplayName, (nFlag & MAB_CERT));
  1678. // SetUserIcon(LPARAM_ABGRPENTRY, 0, &(lvItem.iImage));
  1679. ListView_InsertItem(m_ctlList, &lvItem);
  1680. return;
  1681. }
  1682. if(pchEmail)
  1683. pEntry = FindUserEmail(pchEmail, NULL, TRUE);
  1684. if(pEntry) // buddy found
  1685. {
  1686. // if we already linked this budyy to AN entry, add new list item)
  1687. if(pEntry->tag == LPARAM_MABENTRY)
  1688. {
  1689. lvItem.lParam = (LPARAM) AddBlabEntry(LPARAM_MABENTRY, lpSB, pEntry->lpMsgrInfo, pchEmail, pchDisplayName, (nFlag & MAB_CERT));
  1690. // SetUserIcon(LPARAM_MABENTRY, pEntry->lpMsgrInfo->nStatus, &(lvItem.iImage));
  1691. ListView_InsertItem(m_ctlList, &lvItem);
  1692. }
  1693. else if(pEntry->tag == LPARAM_MENTRY) // buddy was not linked to AB entry
  1694. {
  1695. pEntry->tag = LPARAM_MABENTRY;
  1696. pEntry->lpSB = lpSB;
  1697. Assert(lpSB);
  1698. m_cAddrBook.GetDisplayName(pEntry->lpSB, szName, MAXNAME);
  1699. pEntry->pchWABName = NULL;
  1700. pEntry->pchWABID = NULL;
  1701. if (MemAlloc((LPVOID *) &(pEntry->pchWABName), lstrlen(szName) + 1 ))
  1702. StrCpyN(pEntry->pchWABName, szName, lstrlen(szName) + 1);
  1703. if(MemAlloc((LPVOID *) &(pEntry->pchWABID), lstrlen(pchEmail) + 1 ))
  1704. StrCpyN(pEntry->pchWABID, pchEmail, lstrlen(pchEmail) + 1);
  1705. }
  1706. else
  1707. Assert(FALSE); // something strange
  1708. }
  1709. else // buddy not found, simple AB entry
  1710. {
  1711. lvItem.lParam = (LPARAM) AddBlabEntry(LPARAM_ABENTRY, lpSB, NULL, pchEmail, pchDisplayName, (nFlag & MAB_CERT));
  1712. // SetUserIcon(LPARAM_ABENTRY, 0, &(lvItem.iImage));
  1713. ListView_InsertItem(m_ctlList, &lvItem);
  1714. }
  1715. }
  1716. LPMABENTRY CMsgrAb::FindUserEmail(TCHAR *pchEmail, int *pIndex, BOOL fMsgrOnly)
  1717. {
  1718. LPMABENTRY pEntry = NULL;
  1719. LVITEM lvi;
  1720. lvi.mask = LVIF_PARAM;
  1721. if(pIndex != NULL)
  1722. lvi.iItem = *pIndex;
  1723. else
  1724. lvi.iItem = -1;
  1725. lvi.iSubItem = 0;
  1726. while((lvi.iItem = ListView_GetNextItem(m_ctlList, lvi.iItem, LVNI_ALL)) != -1)
  1727. {
  1728. ListView_GetItem(m_ctlList, &lvi);
  1729. pEntry = (LPMABENTRY) lvi.lParam;
  1730. if(pEntry)
  1731. {
  1732. if(fMsgrOnly)
  1733. {
  1734. if(pEntry->lpMsgrInfo)
  1735. {
  1736. if((pEntry->lpMsgrInfo)->pchID)
  1737. {
  1738. if(!lstrcmpi((pEntry->lpMsgrInfo)->pchID, pchEmail))
  1739. {
  1740. if(pIndex != NULL)
  1741. *pIndex = lvi.iItem;
  1742. return(pEntry);
  1743. }
  1744. }
  1745. }
  1746. }
  1747. else
  1748. {
  1749. if(pEntry->pchWABID)
  1750. {
  1751. if(!lstrcmpi(pEntry->pchWABID, pchEmail))
  1752. {
  1753. if(pIndex != NULL)
  1754. *pIndex = lvi.iItem;
  1755. return(pEntry);
  1756. }
  1757. }
  1758. if(pEntry->lpSB)
  1759. {
  1760. if(m_cAddrBook.CheckEmailAddr(pEntry->lpSB, pchEmail))
  1761. {
  1762. if(pIndex != NULL)
  1763. *pIndex = lvi.iItem;
  1764. return(pEntry);
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. return(NULL);
  1771. }
  1772. // messenger want shutown. release messenger object
  1773. HRESULT CMsgrAb::OnMsgrShutDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1774. {
  1775. if(m_pCMsgrList)
  1776. {
  1777. m_pCMsgrList->UnRegisterUIWnd(m_hWnd);
  1778. OE_CloseMsgrList(m_pCMsgrList);
  1779. m_pCMsgrList = NULL;
  1780. }
  1781. _ReloadListview();
  1782. return(S_OK);
  1783. }
  1784. // Set new buddy status (online/ofline/etc. and redraw list view entry)
  1785. HRESULT CMsgrAb::OnUserStateChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1786. {
  1787. HRESULT hr = S_OK;
  1788. LPMABENTRY pEntry = NULL;
  1789. int index = -1;
  1790. while((pEntry = FindUserEmail((LPSTR) lParam, &index, TRUE)) != NULL)
  1791. {
  1792. pEntry->lpMsgrInfo->nStatus = (int) wParam;
  1793. #ifdef NEEDED
  1794. // Check that buddy is in WAB
  1795. if((pEntry->tag == LPARAM_MENTRY) && (pEntry->lpMsgrInfo->nStatus != MSTATEOE_OFFLINE) &&
  1796. (pEntry->lpMsgrInfo->nStatus != MSTATEOE_UNKNOWN) && (pEntry->lpMsgrInfo->nStatus != MSTATEOE_INVISIBLE))
  1797. {
  1798. // Add new contact to WAB, if we know ID and Display Name
  1799. if(pEntry->lpMsgrInfo->pchID && pEntry->lpMsgrInfo->pchMsgrName && lstrcmpi(pEntry->lpMsgrInfo->pchID, pEntry->lpMsgrInfo->pchMsgrName))
  1800. {
  1801. hr = m_cAddrBook.AutoAddContact(pEntry->lpMsgrInfo->pchMsgrName, pEntry->lpMsgrInfo->pchID); // Don't need redraw now, do it later
  1802. // _ReloadListview();
  1803. return(hr);
  1804. }
  1805. }
  1806. #endif
  1807. ListView_RedrawItems(m_ctlList, index, index+1);
  1808. }
  1809. // if(index < 0)
  1810. // Assert(index > -1);
  1811. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  1812. return(hr);
  1813. }
  1814. // Message: buddy was removed
  1815. HRESULT CMsgrAb::OnUserRemoved(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1816. {
  1817. HRESULT hr = S_OK;
  1818. int index = -1;
  1819. LPMABENTRY pEntry = NULL;
  1820. while((pEntry = FindUserEmail((LPSTR) lParam, &index, TRUE)) != NULL)
  1821. {
  1822. // Not removed yet
  1823. if(pEntry->tag == LPARAM_MABENTRY)
  1824. {
  1825. Assert(pEntry->lpMsgrInfo);
  1826. if(pEntry->lpMsgrInfo)
  1827. {
  1828. RemoveMsgrInfo(pEntry->lpMsgrInfo);
  1829. pEntry->lpMsgrInfo = NULL;
  1830. }
  1831. pEntry->tag = LPARAM_ABENTRY;
  1832. ListView_RedrawItems(m_ctlList, index, index+1);
  1833. }
  1834. else if(pEntry->tag == LPARAM_MENTRY)
  1835. {
  1836. int index1 = ListView_GetNextItem(m_ctlList, -1, LVIS_SELECTED | LVIS_FOCUSED);
  1837. m_delItem++;
  1838. ListView_DeleteItem(m_ctlList, index);
  1839. if(index == index1)
  1840. {
  1841. index1--;
  1842. ListView_SetItemState(m_ctlList, ((index1 >= 0) ? index1 : 0), LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  1843. }
  1844. }
  1845. else
  1846. index++;
  1847. }
  1848. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  1849. if(ListView_GetItemCount(m_ctlList) > 0)
  1850. m_cEmptyList.Hide();
  1851. else
  1852. m_cEmptyList.Show(m_ctlList, (LPTSTR) m_szEmptyList);
  1853. return(hr);
  1854. }
  1855. // Event User was added => add buddy to our list.
  1856. HRESULT CMsgrAb::OnUserAdded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1857. {
  1858. LPMINFO pItem = (LPMINFO) lParam;
  1859. AddMsgrListItem(pItem);
  1860. #ifdef NEEDED
  1861. TCHAR szText[CCHMAX_STRINGRES + RESSTRMAX];
  1862. TCHAR szBuff[CCHMAX_STRINGRES];
  1863. AthLoadString(idsBAAddedUser, szBuff, ARRAYSIZE(szBuff));
  1864. wnsprintf(szText, ARRAYSIZE(szText), szBuff, pItem->pchMsgrName ? pItem->pchMsgrName : pItem->pchID);
  1865. if(IDYES == AthMessageBox(m_hWnd, MAKEINTRESOURCE(idsAthena), szText,
  1866. NULL, MB_YESNO | MB_ICONEXCLAMATION))
  1867. m_cAddrBook.AddContact(m_hWnd, pItem->pchMsgrName, pItem->pchID);
  1868. else // just update list
  1869. #endif //NEEDED
  1870. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  1871. return(S_OK);
  1872. }
  1873. HRESULT CMsgrAb::OnUserNameChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1874. {
  1875. HRESULT hr = S_OK;
  1876. #ifdef NEEDED
  1877. LPMINFO pItem = (LPMINFO) lParam;
  1878. LPMABENTRY pEntry = NULL;
  1879. int index = -1;
  1880. while((pEntry = FindUserEmail(pItem->pchID, &index, TRUE)) != NULL)
  1881. {
  1882. if((pEntry->tag == LPARAM_MENTRY) && lstrcmpi(pItem->pchID, pItem->pchMsgrName))
  1883. {
  1884. hr = m_cAddrBook.AutoAddContact(pItem->pchMsgrName, pItem->pchID);
  1885. // _ReloadListview();
  1886. }
  1887. ListView_RedrawItems(m_ctlList, index, index+1);
  1888. }
  1889. #endif
  1890. _ReloadListview();
  1891. return(hr);
  1892. }
  1893. HRESULT CMsgrAb::OnUserLogoffEvent(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1894. {
  1895. if(!m_fLogged)
  1896. return S_OK;
  1897. else
  1898. m_fLogged = FALSE;
  1899. SetWindowRedraw(m_ctlList, FALSE);
  1900. int index = ListView_GetNextItem(m_ctlList, -1, LVIS_SELECTED | LVIS_FOCUSED);
  1901. // Delete everything and reload
  1902. if(m_delItem != 0)
  1903. m_fNoRemove = TRUE;
  1904. // else
  1905. // m_fNoRemove = FALSE;
  1906. m_delItem = ListView_GetItemCount(m_ctlList);
  1907. ListView_DeleteAllItems(m_ctlList);
  1908. // FillMsgrList(); // User list reload
  1909. m_cAddrBook.LoadWabContents(m_ctlList, this);
  1910. ListView_SetItemState(m_ctlList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  1911. SetWindowRedraw(m_ctlList, TRUE);
  1912. if(ListView_GetItemCount(m_ctlList) > 0)
  1913. m_cEmptyList.Hide();
  1914. else
  1915. m_cEmptyList.Show(m_ctlList, (LPTSTR) m_szEmptyList);
  1916. UpdateWindow(/*m_ctlList*/);
  1917. return S_OK;
  1918. }
  1919. HRESULT CMsgrAb::OnUserLogResultEvent(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1920. {
  1921. if(SUCCEEDED(lParam))
  1922. {
  1923. _ReloadListview();
  1924. m_fLogged = TRUE;
  1925. }
  1926. return S_OK;
  1927. }
  1928. LRESULT CMsgrAb::NotifySetFocus(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1929. {
  1930. UnkOnFocusChangeIS(m_pObjSite, (IInputObject*) this, TRUE);
  1931. return (0);
  1932. }
  1933. HRESULT STDMETHODCALLTYPE CMsgrAb::QueryStatus(const GUID *pguidCmdGroup,
  1934. ULONG cCmds, OLECMD *prgCmds,
  1935. OLECMDTEXT *pCmdText)
  1936. {
  1937. int nEnable;
  1938. HRESULT hr;
  1939. DWORD cSelected = ListView_GetSelectedCount(m_ctlList);
  1940. UINT id;
  1941. MSTATEOE State;
  1942. // Loop through all the commands in the array
  1943. for ( ; cCmds > 0; cCmds--, prgCmds++)
  1944. {
  1945. // Only look at commands that don't have OLECMDF_SUPPORTED;
  1946. if (prgCmds->cmdf == 0)
  1947. {
  1948. switch (prgCmds->cmdID)
  1949. {
  1950. // These commands are enabled if and only if one item is selected
  1951. case ID_DELETE_CONTACT:
  1952. if (cSelected > 0)
  1953. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1954. break;
  1955. case ID_SEND_MESSAGE:
  1956. case ID_FIND_PEOPLE:
  1957. case ID_ADDRESS_BOOK:
  1958. #ifdef GEORGEH
  1959. case ID_NEW_MSG_DEFAULT:
  1960. #endif
  1961. if(HasFocusIO() == S_OK)
  1962. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1963. break;
  1964. case ID_SEND_INSTANT_MESSAGE2:
  1965. {
  1966. if(g_dwHideMessenger == BL_NOTINST)
  1967. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1968. else if (cSelected == 1)
  1969. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1970. else
  1971. prgCmds->cmdf = OLECMDF_SUPPORTED;
  1972. break;
  1973. }
  1974. case ID_SORT_BY_STATUS:
  1975. if((g_dwHideMessenger & BL_NOTINST) || (g_dwHideMessenger & BL_HIDE))
  1976. {
  1977. prgCmds->cmdf = OLECMDF_SUPPORTED;
  1978. break;
  1979. }
  1980. else if(ListView_GetItemCount(m_ctlList) > 1)
  1981. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1982. else
  1983. prgCmds->cmdf = OLECMDF_SUPPORTED;
  1984. if((m_nSortType == BASORT_STATUS_ACSEND) || (m_nSortType == BASORT_STATUS_DESCEND))
  1985. prgCmds->cmdf |= OLECMDF_NINCHED;
  1986. break;
  1987. case ID_SORT_BY_NAME:
  1988. if((g_dwHideMessenger & BL_NOTINST) || (g_dwHideMessenger & BL_HIDE))
  1989. {
  1990. prgCmds->cmdf = OLECMDF_SUPPORTED;
  1991. break;
  1992. }
  1993. else if(ListView_GetItemCount(m_ctlList) > 1)
  1994. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1995. else
  1996. prgCmds->cmdf = OLECMDF_SUPPORTED;
  1997. if((m_nSortType == BASORT_NAME_ACSEND) || (m_nSortType == BASORT_NAME_DESCEND))
  1998. prgCmds->cmdf |= OLECMDF_NINCHED;
  1999. break;
  2000. // These commands are always enabled
  2001. case ID_POPUP_NEW_ACCOUNT:
  2002. case ID_NEW_HOTMAIL_ACCOUNT:
  2003. case ID_NEW_ATT_ACCOUNT:
  2004. case ID_NEW_CONTACT:
  2005. case ID_POPUP_MESSENGER:
  2006. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  2007. break;
  2008. case ID_SET_ONLINE_CONTACT:
  2009. {
  2010. if(cSelected != 1)
  2011. {
  2012. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2013. break;
  2014. }
  2015. LPMABENTRY pEntry = GetSelectedEntry();
  2016. if(!pEntry && m_pCMsgrList)
  2017. {
  2018. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2019. break;
  2020. }
  2021. else if(pEntry && pEntry->tag != LPARAM_ABENTRY)
  2022. {
  2023. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2024. break;
  2025. }
  2026. }
  2027. case ID_NEW_ONLINE_CONTACT:
  2028. if(m_pCMsgrList)
  2029. {
  2030. if(m_pCMsgrList->IsLocalOnline())
  2031. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  2032. else
  2033. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2034. }
  2035. else if(g_dwHideMessenger == BL_NOTINST)
  2036. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  2037. else
  2038. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2039. break;
  2040. // Properties is only enabled if the input focus is in the
  2041. // list view. Otherwise, we don't mark it as supported at all.
  2042. case ID_PROPERTIES:
  2043. {
  2044. LPMABENTRY pEntry = GetSelectedEntry();
  2045. if(pEntry && pEntry->tag != LPARAM_MENTRY)
  2046. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  2047. else
  2048. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2049. break;
  2050. }
  2051. case ID_MESSENGER_OPTIONS:
  2052. if (!m_pCMsgrList)
  2053. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2054. else
  2055. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  2056. break;
  2057. // These depend on whether
  2058. case ID_LOGIN_MESSENGER:
  2059. case ID_LOGOFF_MESSENGER:
  2060. case ID_MESSENGER_ONLINE:
  2061. case ID_MESSENGER_INVISIBLE:
  2062. case ID_MESSENGER_BUSY:
  2063. case ID_MESSENGER_BACK:
  2064. case ID_MESSENGER_AWAY:
  2065. case ID_MESSENGER_ON_PHONE:
  2066. case ID_MESSENGER_LUNCH:
  2067. case ID_POPUP_MESSENGER_STATUS:
  2068. {
  2069. // If messenger isn't installed, then none of these commands will
  2070. // be enabled.
  2071. if (!m_pCMsgrList)
  2072. {
  2073. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2074. break;
  2075. }
  2076. if (FAILED(m_pCMsgrList->GetLocalState(&State)))
  2077. State = MSTATEOE_UNKNOWN;
  2078. // Convert the online state to a command ID
  2079. switch (State)
  2080. {
  2081. case MSTATEOE_ONLINE:
  2082. case MSTATEOE_IDLE:
  2083. id = ID_MESSENGER_ONLINE;
  2084. break;
  2085. case MSTATEOE_INVISIBLE:
  2086. id = ID_MESSENGER_INVISIBLE;
  2087. break;
  2088. case MSTATEOE_BUSY:
  2089. id = ID_MESSENGER_BUSY;
  2090. break;
  2091. case MSTATEOE_BE_RIGHT_BACK:
  2092. id = ID_MESSENGER_BACK;
  2093. break;
  2094. case MSTATEOE_AWAY:
  2095. id = ID_MESSENGER_AWAY;
  2096. break;
  2097. case MSTATEOE_ON_THE_PHONE:
  2098. id = ID_MESSENGER_ON_PHONE;
  2099. break;
  2100. case MSTATEOE_OUT_TO_LUNCH:
  2101. id = ID_MESSENGER_LUNCH;
  2102. break;
  2103. default:
  2104. id = 0xffff;
  2105. }
  2106. // Logon is handled a bit seperatly
  2107. if (prgCmds->cmdID == ID_LOGIN_MESSENGER)
  2108. {
  2109. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2110. if (id == 0xffff)
  2111. prgCmds->cmdf |= OLECMDF_ENABLED;
  2112. }
  2113. else if (prgCmds->cmdID == ID_LOGOFF_MESSENGER)
  2114. {
  2115. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2116. if (id != 0xffff)
  2117. prgCmds->cmdf |= OLECMDF_ENABLED;
  2118. }
  2119. else
  2120. {
  2121. // For all other commands, if we in a known state
  2122. // then the command is enabled.
  2123. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2124. if (id != 0xffff)
  2125. prgCmds->cmdf = OLECMDF_ENABLED;
  2126. // If the command is the same as our state, it should be checked
  2127. if (id == prgCmds->cmdID)
  2128. prgCmds->cmdf |= OLECMDF_NINCHED;
  2129. }
  2130. }
  2131. break;
  2132. case ID_SEND_INSTANT_MESSAGE:
  2133. {
  2134. if (GetEntryForSendInstMsg() || (g_dwHideMessenger == BL_NOTINST))
  2135. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  2136. else
  2137. prgCmds->cmdf = OLECMDF_SUPPORTED;
  2138. break;
  2139. }
  2140. }
  2141. }
  2142. }
  2143. return S_OK;
  2144. }
  2145. HRESULT STDMETHODCALLTYPE CMsgrAb::Exec(const GUID *pguidCmdGroup,
  2146. DWORD nCmdID,
  2147. DWORD nCmdExecOpt,
  2148. VARIANTARG *pvaIn,
  2149. VARIANTARG *pvaOut)
  2150. {
  2151. HRESULT hr = OLECMDERR_E_NOTSUPPORTED;
  2152. BOOL bHandled = 0;
  2153. MSTATEOE State = MSTATEOE_UNKNOWN;
  2154. switch (nCmdID)
  2155. {
  2156. case ID_SEND_INSTANT_MESSAGE2:
  2157. CmdNewMessage(HIWORD(nCmdID), ID_SEND_INSTANT_MESSAGE2, m_ctlList, bHandled);
  2158. hr = S_OK;
  2159. break;
  2160. case ID_DELETE_CONTACT:
  2161. hr = (HRESULT) CmdDelete(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2162. break;
  2163. case ID_NEW_CONTACT:
  2164. // if(HasFocusIO() == S_OK)
  2165. CmdNewContact(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2166. hr = S_OK;
  2167. break;
  2168. case ID_SET_ONLINE_CONTACT:
  2169. CmdSetOnline(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2170. hr = S_OK;
  2171. break;
  2172. case ID_NEW_ONLINE_CONTACT:
  2173. CmdNewOnlineContact(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2174. hr = S_OK;
  2175. break;
  2176. case ID_PROPERTIES:
  2177. {
  2178. // Only if we have focus
  2179. if (m_ctlList == GetFocus())
  2180. {
  2181. CmdProperties(0, 0, m_ctlList, bHandled);
  2182. hr = S_OK;
  2183. }
  2184. break;
  2185. }
  2186. #ifdef GEORGEH
  2187. case ID_NEW_MSG_DEFAULT:
  2188. if(HasFocusIO() == S_OK)
  2189. hr = CmdNewMessage(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2190. break;
  2191. #endif // GEORGEH
  2192. case ID_SEND_MESSAGE:
  2193. if(HasFocusIO() == S_OK)
  2194. hr = (HRESULT) CmdNewEmaile(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2195. break;
  2196. case ID_SEND_INSTANT_MESSAGE:
  2197. // Assert(m_pCMsgrList);
  2198. CmdNewIMsg(HIWORD(nCmdID), LOWORD(nCmdID), m_ctlList, bHandled);
  2199. hr = S_OK;
  2200. break;
  2201. case ID_MESSENGER_OPTIONS:
  2202. hr = m_pCMsgrList->LaunchOptionsUI(); //CmdMsgrOptions();
  2203. break;
  2204. case ID_MESSENGER_ONLINE:
  2205. Assert(m_pCMsgrList);
  2206. hr = m_pCMsgrList->SetLocalState(MSTATEOE_ONLINE);
  2207. break;
  2208. case ID_MESSENGER_INVISIBLE:
  2209. Assert(m_pCMsgrList);
  2210. hr = m_pCMsgrList->SetLocalState(MSTATEOE_INVISIBLE);
  2211. break;
  2212. case ID_MESSENGER_BUSY:
  2213. Assert(m_pCMsgrList);
  2214. hr = m_pCMsgrList->SetLocalState(MSTATEOE_BUSY);
  2215. break;
  2216. case ID_MESSENGER_BACK:
  2217. Assert(m_pCMsgrList);
  2218. hr = m_pCMsgrList->SetLocalState(MSTATEOE_BE_RIGHT_BACK);
  2219. break;
  2220. case ID_MESSENGER_AWAY:
  2221. Assert(m_pCMsgrList);
  2222. hr = m_pCMsgrList->SetLocalState(MSTATEOE_AWAY);
  2223. break;
  2224. case ID_MESSENGER_ON_PHONE:
  2225. Assert(m_pCMsgrList);
  2226. hr = m_pCMsgrList->SetLocalState(MSTATEOE_ON_THE_PHONE);
  2227. break;
  2228. case ID_MESSENGER_LUNCH:
  2229. Assert(m_pCMsgrList);
  2230. hr = m_pCMsgrList->SetLocalState(MSTATEOE_OUT_TO_LUNCH);
  2231. break;
  2232. case ID_LOGIN_MESSENGER:
  2233. Assert(m_pCMsgrList);
  2234. if(!m_pCMsgrList->IsLocalOnline())
  2235. {
  2236. if(PromptToGoOnline() == S_OK)
  2237. m_pCMsgrList->UserLogon();
  2238. }
  2239. hr = S_OK;
  2240. break;
  2241. case ID_LOGOFF_MESSENGER:
  2242. Assert(m_pCMsgrList);
  2243. if(m_pCMsgrList->IsLocalOnline())
  2244. {
  2245. m_pCMsgrList->UserLogoff();
  2246. }
  2247. hr = S_OK;
  2248. break;
  2249. case ID_SORT_BY_NAME:
  2250. m_nSortType = BASORT_NAME_ACSEND;
  2251. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  2252. break;
  2253. case ID_SORT_BY_STATUS:
  2254. m_nSortType = BASORT_STATUS_ACSEND;
  2255. ListView_SortItems(m_ctlList, BA_Sort, m_nSortType);
  2256. break;
  2257. default:
  2258. break;
  2259. }
  2260. return hr;
  2261. }
  2262. #ifdef OLDTIPS
  2263. //
  2264. // FUNCTION: CMsgrAb::OnListMouseEvent()
  2265. //
  2266. // PURPOSE: Whenever we get our first mouse event in a series, we call
  2267. // TrackMouseEvent() so we know when the mouse leaves the ListView.
  2268. //
  2269. HRESULT CMsgrAb::OnListMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  2270. {
  2271. // If we have the view tooltip, then we track all mouse events
  2272. if (!m_fTrackSet && m_fViewTip && (uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST))
  2273. {
  2274. TRACKMOUSEEVENT tme;
  2275. tme.cbSize = sizeof(tme);
  2276. tme.hwndTrack = m_ctlList;
  2277. tme.dwFlags = TME_LEAVE;
  2278. tme.dwHoverTime = 1000;
  2279. if (_TrackMouseEvent(&tme))
  2280. m_fTrackSet = TRUE;
  2281. }
  2282. bHandled = FALSE;
  2283. return (0);
  2284. }
  2285. //
  2286. // FUNCTION: CMsgrAb::OnListMouseMove()
  2287. //
  2288. // PURPOSE: If the ListView tooltips are turned on, we need to relay mouse
  2289. // move messages to the tooltip control and update our cached
  2290. // information about what the mouse is over.
  2291. //
  2292. HRESULT CMsgrAb::OnListMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  2293. {
  2294. LVHITTESTINFO lvhti;
  2295. // If we're displaying view tips, then we need to figure out if the mouse is
  2296. // over the same item or not.
  2297. if (m_fViewTip && m_ctlViewTip)
  2298. _UpdateViewTip(LOWORD(lParam), HIWORD(lParam));
  2299. bHandled = FALSE;
  2300. return (0);
  2301. }
  2302. //
  2303. // FUNCTION: HRESULT CMsgrAb::OnListMouseLeave()
  2304. //
  2305. // PURPOSE: When the mouse leaves the ListView window, we need to make
  2306. // sure we hide the tooltip.
  2307. //
  2308. HRESULT CMsgrAb::OnListMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  2309. {
  2310. TOOLINFO ti = {0};
  2311. if (m_fViewTip && m_ctlViewTip)
  2312. {
  2313. ti.cbSize = sizeof(TOOLINFO);
  2314. ti.hwnd = m_hWnd;
  2315. ti.uId = (UINT_PTR)(HWND) m_ctlList;
  2316. // Hide the tooltip
  2317. m_ctlViewTip.SendMessage(TTM_TRACKACTIVATE, FALSE, (LPARAM) &ti);
  2318. m_fViewTipVisible = FALSE;
  2319. // Reset our item / subitem
  2320. m_iItemTip = -1;
  2321. m_iSubItemTip = -1;
  2322. // Tracking is no longer set
  2323. m_fTrackSet = FALSE;
  2324. }
  2325. bHandled = FALSE;
  2326. return (0);
  2327. }
  2328. // UpdateViewTip - update expand string in list view
  2329. // ported from msglist.cpp
  2330. BOOL CMsgrAb::_UpdateViewTip(int x, int y)
  2331. {
  2332. LVHITTESTINFO lvhti = {0};
  2333. TOOLINFO ti = {0};
  2334. FNTSYSTYPE fntType;
  2335. RECT rc;
  2336. MESSAGEINFO rInfo;
  2337. COLUMN_ID idColumn;
  2338. TCHAR szText[CCHMAX_STRINGRES + MAXNAME + 1] = _T("");
  2339. TCHAR szName[MAXNAME];
  2340. POINT pt;
  2341. LVITEM lvi;
  2342. ti.cbSize = sizeof(TOOLINFO);
  2343. ti.uFlags = TTF_IDISHWND | TTF_TRANSPARENT | TTF_TRACK | TTF_ABSOLUTE;
  2344. ti.hwnd = m_hWnd;
  2345. ti.uId = (UINT_PTR)(HWND) m_ctlList;
  2346. // Get the item and subitem the mouse is currently over
  2347. lvhti.pt.x = x;
  2348. lvhti.pt.y = y;
  2349. ListView_SubItemHitTest(m_ctlList, &lvhti);
  2350. // If the item doesn't exist, then the above call returns the item -1. If
  2351. // we encounter -1, we break the loop and return FALSE.
  2352. if (-1 == lvhti.iItem || !_IsItemTruncated(lvhti.iItem, lvhti.iSubItem) || !::IsChild(GetForegroundWindow(), m_ctlList))
  2353. {
  2354. // Hide the tip
  2355. if (m_fViewTipVisible)
  2356. {
  2357. m_ctlViewTip.SendMessage(TTM_TRACKACTIVATE, FALSE, (LPARAM) &ti);
  2358. m_fViewTipVisible = FALSE;
  2359. }
  2360. // Reset the item / subitem
  2361. m_iItemTip = -1;
  2362. m_iSubItemTip = -1;
  2363. return (FALSE);
  2364. }
  2365. // If the newly found item & subitem is different from what we're already
  2366. // set up to show, then update the tooltip
  2367. if (m_iItemTip != lvhti.iItem || m_iSubItemTip != lvhti.iSubItem)
  2368. {
  2369. // Update our cached item / subitem
  2370. m_iItemTip = lvhti.iItem;
  2371. m_iSubItemTip = lvhti.iSubItem;
  2372. // Figure out if this column has an image
  2373. lvi.mask = LVIF_PARAM;
  2374. lvi.iItem = m_iItemTip;
  2375. lvi.iSubItem = 0;
  2376. ListView_GetItem(m_ctlList, &lvi);
  2377. LPMABENTRY pEntry = (LPMABENTRY) lvi.lParam;
  2378. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_ABENTRY || pEntry->tag == LPARAM_ABGRPENTRY)
  2379. {
  2380. Assert(pEntry->pchWABName != NULL);
  2381. StrCpyN(szName, pEntry->pchWABName, ARRAYSIZE(szName));
  2382. szName[MAXNAME - 1] = _T('\0');
  2383. }
  2384. else if(pEntry->tag == LPARAM_MENTRY)
  2385. {
  2386. StrCpyN(szName, pEntry->lpMsgrInfo->pchMsgrName, ARRAYSIZE(szName));
  2387. szName[MAXNAME - 1] = _T('\0');
  2388. }
  2389. else
  2390. Assert(FALSE);
  2391. StrCpyN(szText, szName, ARRAYSIZE(szText));
  2392. if(pEntry->lpMsgrInfo)
  2393. {
  2394. switch(pEntry->lpMsgrInfo->nStatus)
  2395. {
  2396. case MSTATEOE_ONLINE:
  2397. StrCatBuff(szText, m_szOnline, ARRAYSIZE(szText));
  2398. break;
  2399. case MSTATEOE_BUSY:
  2400. StrCatBuff(szText, m_szBusy, ARRAYSIZE(szText));
  2401. break;
  2402. case MSTATEOE_BE_RIGHT_BACK:
  2403. StrCatBuff(szText, m_szBack, ARRAYSIZE(szText));
  2404. break;
  2405. case MSTATEOE_IDLE:
  2406. StrCatBuff(szText, m_szIdle, ARRAYSIZE(szText));
  2407. break;
  2408. case MSTATEOE_AWAY:
  2409. StrCatBuff(szText, m_szAway, ARRAYSIZE(szText));
  2410. break;
  2411. case MSTATEOE_ON_THE_PHONE:
  2412. StrCatBuff(szText, m_szOnPhone, ARRAYSIZE(szText));
  2413. break;
  2414. case MSTATEOE_OUT_TO_LUNCH:
  2415. StrCatBuff(szText, m_szLunch, ARRAYSIZE(szText));
  2416. break;
  2417. default:
  2418. StrCatBuff(szText, m_szOffline, ARRAYSIZE(szText));
  2419. break;
  2420. }
  2421. }
  2422. ti.lpszText = szText;
  2423. m_ctlViewTip.SendMessage(TTM_UPDATETIPTEXT, 0, (LPARAM) &ti);
  2424. // Figure out where to place the tip
  2425. ListView_GetSubItemRect(m_ctlList, m_iItemTip, m_iSubItemTip, LVIR_LABEL, &rc);
  2426. m_ctlList.ClientToScreen(&rc);
  2427. // Update the tooltip
  2428. m_ctlViewTip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM) &ti);
  2429. m_fViewTipVisible = TRUE;
  2430. // Do some voodoo to line up the tooltip
  2431. pt.x = rc.left;
  2432. pt.y = rc.top;
  2433. // Update the tooltip position
  2434. m_ctlViewTip.SendMessage(TTM_TRACKPOSITION, 0, MAKELPARAM(pt.x, pt.y));
  2435. // Update the tooltip
  2436. m_ctlViewTip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM) &ti);
  2437. m_fViewTipVisible = TRUE;
  2438. return (TRUE);
  2439. }
  2440. return (FALSE);
  2441. }
  2442. BOOL CMsgrAb::_IsItemTruncated(int iItem, int iSubItem)
  2443. {
  2444. HDC hdc = NULL;
  2445. SIZE size={0};
  2446. BOOL bRet = TRUE;
  2447. LVITEM lvi;
  2448. TCHAR szText[256] = _T("");
  2449. int cxEdge;
  2450. BOOL fBold;
  2451. RECT rcText;
  2452. int cxWidth;
  2453. LPMABENTRY pEntry = NULL;
  2454. HFONT hf = NULL;;
  2455. // Get the text of the specified item
  2456. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  2457. lvi.iItem = iItem;
  2458. lvi.iSubItem = iSubItem;
  2459. lvi.pszText = szText;
  2460. lvi.cchTextMax = ARRAYSIZE(szText);
  2461. ListView_GetItem(m_ctlList, &lvi);
  2462. // If there's no text, it's not truncated, eh?
  2463. if (0 == *szText)
  2464. return (FALSE);
  2465. // if Msgr entry then always expend
  2466. pEntry = (LPMABENTRY) lvi.lParam;
  2467. if(pEntry->tag == LPARAM_MABENTRY || pEntry->tag == LPARAM_MENTRY)
  2468. return(TRUE);
  2469. // ListView uses this for padding
  2470. cxEdge = GetSystemMetrics(SM_CXEDGE);
  2471. // Get the sub item rect from the ListView
  2472. ListView_GetSubItemRect(m_ctlList, iItem, iSubItem, LVIR_LABEL, &rcText);
  2473. // Figure out the width
  2474. cxWidth = rcText.right - rcText.left;
  2475. cxWidth -= (6 * cxEdge);
  2476. // Figure out the width of the string
  2477. hdc = m_ctlList.GetDC();
  2478. if(hdc)
  2479. {
  2480. hf = SelectFont(hdc, HGetCharSetFont(FNT_SYS_ICON, GetListViewCharset()));
  2481. if(hf)
  2482. {
  2483. GetTextExtentPoint(hdc, szText, lstrlen(szText), &size);
  2484. SelectFont(hdc, hf);
  2485. }
  2486. m_ctlList.ReleaseDC(hdc);
  2487. }
  2488. return (cxWidth < size.cx);
  2489. }
  2490. #endif // OLDTIPS
  2491. STDMETHODIMP CMsgrAb::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  2492. {
  2493. TCHAR sz[CCHMAX_STRINGRES];
  2494. if(m_lpWED->fReadOnly)
  2495. return NOERROR;
  2496. PROPSHEETPAGE psp;
  2497. // hinstApp = g_hInst;
  2498. psp.dwSize = sizeof(psp); // no extra data
  2499. psp.dwFlags = PSP_USEREFPARENT | PSP_USETITLE ;
  2500. psp.hInstance = g_hLocRes;
  2501. psp.lParam = (LPARAM) &(m_lpWED);
  2502. psp.pcRefParent = (UINT *)&(m_cRefThisDll);
  2503. psp.pszTemplate = MAKEINTRESOURCE(iddWabExt);
  2504. psp.pfnDlgProc = WabExtDlgProc;
  2505. psp.pszTitle = AthLoadString(idsWABExtTitle, sz, ARRAYSIZE(sz)); // Title for your tab AthLoadString(idsWABExtTitle, sz, ARRAYSIZE(sz))
  2506. m_hPage1 = ::CreatePropertySheetPage(&psp);
  2507. if (m_hPage1)
  2508. {
  2509. if (!lpfnAddPage(m_hPage1, lParam))
  2510. ::DestroyPropertySheetPage(m_hPage1);
  2511. }
  2512. return NOERROR;
  2513. }
  2514. STDMETHODIMP CMsgrAb::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
  2515. {
  2516. Assert(FALSE);
  2517. return E_NOTIMPL;
  2518. }
  2519. STDMETHODIMP CMsgrAb::Initialize(LPWABEXTDISPLAY lpWABExtDisplay)
  2520. {
  2521. if (lpWABExtDisplay == NULL)
  2522. {
  2523. TRACE("CMsgrAb::Initialize() no data object");
  2524. return E_FAIL;
  2525. }
  2526. if(st_pAddrBook == NULL)
  2527. {
  2528. TRACE("CMsgrAb::Initialize() - run from not OE - no st_pAddrbook");
  2529. return E_FAIL;
  2530. }
  2531. if(!m_pCMsgrList)
  2532. {
  2533. m_pCMsgrList = OE_OpenMsgrList();
  2534. if(!m_pCMsgrList)
  2535. {
  2536. TRACE("CMsgrAb::Initialize() - Messeneger not installed");
  2537. return E_FAIL;
  2538. }
  2539. OE_CloseMsgrList(m_pCMsgrList);
  2540. m_pCMsgrList = NULL;
  2541. }
  2542. // However if this is a context menu extension, we need to hang
  2543. // onto the propobj till such time as InvokeCommand is called ..
  2544. // At this point just AddRef the propobj - this will ensure that the
  2545. // data in the lpAdrList remains valid till we release the propobj..
  2546. // When we get another ContextMenu initiation, we can release the
  2547. // older cached propobj - if we dont get another initiation, we
  2548. // release the cached object at shutdown time
  2549. if(lpWABExtDisplay->ulFlags & WAB_CONTEXT_ADRLIST) // this means a IContextMenu operation is occuring
  2550. {
  2551. if(m_lpPropObj)
  2552. {
  2553. m_lpPropObj->Release();
  2554. m_lpPropObj = NULL;
  2555. }
  2556. m_lpPropObj = lpWABExtDisplay->lpPropObj;
  2557. m_lpPropObj->AddRef();
  2558. m_lpWEDContext = lpWABExtDisplay;
  2559. }
  2560. else
  2561. {
  2562. // For property sheet extensions, the lpWABExtDisplay will
  2563. // exist for the life of the property sheets ..
  2564. m_lpWED = lpWABExtDisplay;
  2565. }
  2566. return S_OK;
  2567. }
  2568. HRESULT CMsgrAb::PromptToGoOnline()
  2569. {
  2570. HRESULT hr;
  2571. if (g_pConMan->IsGlobalOffline())
  2572. {
  2573. if (IDYES == AthMessageBoxW(m_hwndParent, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsErrWorkingOffline),
  2574. 0, MB_YESNO | MB_ICONEXCLAMATION ))
  2575. {
  2576. g_pConMan->SetGlobalOffline(FALSE);
  2577. hr = S_OK;
  2578. }
  2579. else
  2580. {
  2581. hr = S_FALSE;
  2582. }
  2583. }
  2584. else
  2585. hr = S_OK;
  2586. return hr;
  2587. }