Source code of Windows XP (NT5)
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.

213 lines
5.3 KiB

  1. // File: redial.cpp
  2. #include <precomp.h>
  3. #include "resource.h"
  4. // from confroom.cpp
  5. VOID PlaceCall(LPCTSTR pcszName, LPCTSTR pcszAddress, NM_ADDR_TYPE addrType);
  6. /* B U I L D R E D I A L L I S T M E N U */
  7. /*-------------------------------------------------------------------------
  8. %%Function: BuildRedialListMenu
  9. -------------------------------------------------------------------------*/
  10. BOOL BuildRedialListMenu(HMENU hPopupMenu, RegEntry * pRe)
  11. {
  12. ASSERT(NULL != hPopupMenu);
  13. MENUITEMINFO mmi;
  14. InitStruct(&mmi);
  15. mmi.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
  16. mmi.wID = ID_FIRST_REDIAL_ITEM;
  17. mmi.fType = MFT_STRING;
  18. int cItem = pRe->GetNumber(REGVAL_MRU_COUNT, 0);
  19. if (0 == cItem)
  20. {
  21. // Insert a "stub" item
  22. TCHAR szMenuText[MAX_PATH];
  23. if (FLoadString(IDS_REDIAL_EMPTY, szMenuText, CCHMAX(szMenuText)))
  24. {
  25. mmi.fState = MFS_DISABLED;
  26. mmi.dwTypeData = szMenuText;
  27. mmi.cch = lstrlen(mmi.dwTypeData);
  28. InsertMenuItem(hPopupMenu, 0, TRUE, &mmi);;
  29. }
  30. }
  31. else
  32. {
  33. mmi.fState = MFS_ENABLED;
  34. for (int iItem = 0; iItem < cItem; iItem++)
  35. {
  36. TCHAR szKey[MAX_PATH];
  37. wsprintf(szKey, TEXT("%s%d"), REGVAL_NAME_MRU_PREFIX, iItem);
  38. mmi.dwTypeData = (LPTSTR) pRe->GetString(szKey);
  39. mmi.cch = lstrlen(mmi.dwTypeData);
  40. InsertMenuItem(hPopupMenu, iItem, TRUE, &mmi);;
  41. mmi.wID++;
  42. }
  43. }
  44. return TRUE;
  45. }
  46. /* D I S P L A Y R E D I A L L I S T P O P U P */
  47. /*-------------------------------------------------------------------------
  48. %%Function: DisplayRedialListPopup
  49. -------------------------------------------------------------------------*/
  50. int DisplayRedialListPopup(HMENU hPopupMenu, RECT const *rc)
  51. {
  52. TPMPARAMS tpm;
  53. tpm.cbSize = sizeof(tpm);
  54. tpm.rcExclude = *rc;
  55. // Popup the menu (making sure it doesn't cover the button)
  56. int id = ::TrackPopupMenuEx(hPopupMenu,
  57. TPM_VERTICAL | TPM_TOPALIGN | TPM_RETURNCMD,
  58. tpm.rcExclude.left, tpm.rcExclude.bottom,
  59. ::GetMainWindow(), &tpm);
  60. return (0 == id) ? -1 : id -= ID_FIRST_REDIAL_ITEM;
  61. }
  62. /* D O T B R E D I A L L I S T */
  63. /*-------------------------------------------------------------------------
  64. %%Function: DoTbRedialList
  65. -------------------------------------------------------------------------*/
  66. VOID DoTbRedialList(HWND hwndRedial, RECT const *prcExclude)
  67. {
  68. RECT rcExclude;
  69. ASSERT(NULL != hwndRedial);
  70. if (NULL == prcExclude)
  71. {
  72. GetClientRect(hwndRedial, &rcExclude);
  73. }
  74. else
  75. {
  76. rcExclude = *prcExclude;
  77. }
  78. ::MapWindowPoints(hwndRedial, NULL, (LPPOINT)&rcExclude, 2);
  79. HMENU hPopupMenu = CreatePopupMenu();
  80. if (NULL == hPopupMenu)
  81. return;
  82. RegEntry re(DLGCALL_MRU_KEY, HKEY_CURRENT_USER);
  83. if (BuildRedialListMenu(hPopupMenu, &re))
  84. {
  85. int iItem = DisplayRedialListPopup(hPopupMenu, &rcExclude);
  86. if (-1 != iItem)
  87. {
  88. TCHAR szKey[MAX_PATH];
  89. wsprintf(szKey, TEXT("%s%d"), REGVAL_DLGCALL_ADDR_MRU_PREFIX, iItem);
  90. TCHAR szAddress[CCHMAXSZ_ADDRESS];
  91. lstrcpyn(szAddress, re.GetString(szKey), CCHMAX(szAddress));
  92. if (!FEmptySz(szAddress))
  93. {
  94. wsprintf(szKey, TEXT("%s%d"), REGVAL_DLGCALL_TYPE_MRU_PREFIX, iItem);
  95. NM_ADDR_TYPE addrType = (NM_ADDR_TYPE) re.GetNumber(szKey);
  96. wsprintf(szKey, TEXT("%s%d"), REGVAL_DLGCALL_NAME_MRU_PREFIX, iItem);
  97. PlaceCall(re.GetString(szKey), szAddress, addrType);
  98. }
  99. }
  100. }
  101. ::DestroyMenu(hPopupMenu);
  102. }
  103. VOID DoTbRedialList(HWND hwndToolbar, UINT uCmd)
  104. {
  105. RECT rcShow;
  106. // Determine which toolbar button was pressed:
  107. int nIndex = SendMessage(hwndToolbar, TB_COMMANDTOINDEX, uCmd, 0);
  108. // Get it's position
  109. ::SendMessage(hwndToolbar, TB_GETITEMRECT, nIndex, (LPARAM) &rcShow);
  110. DoTbRedialList(hwndToolbar, &rcShow);
  111. }
  112. /* G E T R E D I A L H E L P T E X T */
  113. /*-------------------------------------------------------------------------
  114. %%Function: GetRedialHelpText
  115. -------------------------------------------------------------------------*/
  116. VOID GetRedialHelpText(LPTSTR psz, int cchMax, int id)
  117. {
  118. TCHAR szKey[MAX_PATH];
  119. TCHAR szName[CCHMAXSZ_NAME];
  120. TCHAR szAddress[CCHMAXSZ_ADDRESS];
  121. TCHAR szUsing[MAX_PATH];
  122. TCHAR szFormat[MAX_PATH];
  123. SetEmptySz(psz);
  124. RegEntry re(DLGCALL_MRU_KEY, HKEY_CURRENT_USER);
  125. wsprintf(szKey, TEXT("%s%d"), REGVAL_DLGCALL_NAME_MRU_PREFIX, id);
  126. lstrcpyn(szName, re.GetString(szKey), CCHMAX(szName));
  127. if (FEmptySz(szName))
  128. return;
  129. if (!FLoadString(IDS_REDIAL_FORMAT, szFormat, CCHMAX(szFormat)))
  130. return;
  131. wsprintf(szKey, TEXT("%s%d"), REGVAL_DLGCALL_TYPE_MRU_PREFIX, id);
  132. int idsUsing;
  133. switch (re.GetNumber(szKey))
  134. {
  135. case NM_ADDR_IP:
  136. case NM_ADDR_MACHINENAME:
  137. idsUsing = IDS_CALLUSING_IP;
  138. break;
  139. case NM_ADDR_H323_GATEWAY:
  140. idsUsing = IDS_CALLUSING_PHONE;
  141. break;
  142. case NM_ADDR_ULS:
  143. idsUsing = IDS_CALLUSING_ILS;
  144. break;
  145. case NM_ADDR_ALIAS_ID:
  146. case NM_ADDR_ALIAS_E164:
  147. idsUsing = IDS_CALLUSING_GK;
  148. break;
  149. default:
  150. idsUsing = 0;
  151. break;
  152. }
  153. if (0 == idsUsing)
  154. {
  155. SetEmptySz(szUsing);
  156. }
  157. else if (!FLoadString(idsUsing, szUsing, CCHMAX(szUsing)))
  158. {
  159. return;
  160. }
  161. wsprintf(szKey, TEXT("%s%d"), REGVAL_DLGCALL_ADDR_MRU_PREFIX, id);
  162. lstrcpyn(szAddress, re.GetString(szKey), CCHMAX(szAddress));
  163. if ((lstrlen(szAddress) + lstrlen(szFormat) + lstrlen(szUsing) + lstrlen(szName)) > cchMax)
  164. {
  165. // Just display the address if it won't fit
  166. lstrcpyn(psz, szAddress, cchMax);
  167. return;
  168. }
  169. wsprintf(psz, szFormat, szName, szUsing, szAddress);
  170. ASSERT(lstrlen(psz) < cchMax);
  171. }