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.

336 lines
7.3 KiB

  1. // File: rtoolbar.cpp
  2. #include "precomp.h"
  3. #include "resource.h"
  4. #include "CallingBar.h"
  5. #include "RToolbar.h"
  6. #include "conf.h"
  7. #include "ConfRoom.h"
  8. #include "richaddr.h"
  9. #include "dlgAcd.h"
  10. #include "callto.h"
  11. #include "topwindow.h"
  12. #include "roomlist.h"
  13. #define ReleaseIt(pUnk) if (NULL != (pUnk)) { (pUnk)->Release(); (pUnk) = NULL; }
  14. const static int CCH_MAX_NAME = 256;
  15. // BUGBUG georgep: Hard-coded colors for the edit control
  16. static const COLORREF EditBack = RGB(-1 , -1 , -1 );
  17. static const COLORREF EditFore = RGB(0, 55, 55);
  18. void CCallingBar::SetEditFont(BOOL bUnderline, BOOL bForce)
  19. {
  20. // BUGBUG georgep: For now, we will never underline; We'll probably need to
  21. // change this some time in the future
  22. bUnderline = FALSE;
  23. if (!bForce && ((bUnderline&&m_bUnderline) || (!bUnderline&&!m_bUnderline)))
  24. {
  25. return;
  26. }
  27. m_bUnderline = bUnderline;
  28. LOGFONT lf;
  29. {
  30. HDC hdc = GetDC(NULL);
  31. lf.lfHeight = -MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
  32. ReleaseDC(NULL, hdc);
  33. }
  34. lf.lfWidth = 0;
  35. lf.lfEscapement = 0;
  36. lf.lfOrientation = 0;
  37. lf.lfWeight = FW_NORMAL;
  38. lf.lfItalic = FALSE;
  39. lf.lfUnderline = (BYTE)bUnderline;
  40. lf.lfStrikeOut = FALSE;
  41. lf.lfCharSet = DEFAULT_CHARSET;
  42. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  43. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  44. lf.lfQuality = DEFAULT_QUALITY;
  45. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
  46. lf.lfFaceName[0] = '\0';
  47. m_pEdit->SetFont(CreateFontIndirect(&lf));
  48. }
  49. void CCallingBar::ClearAddr(RichAddressInfo **ppAddr)
  50. {
  51. if (NULL != *ppAddr)
  52. {
  53. m_pConfRoom->FreeAddress(ppAddr);
  54. *ppAddr = NULL;
  55. }
  56. }
  57. void CCallingBar::ClearCombo()
  58. {
  59. if (NULL == m_pEdit)
  60. {
  61. return;
  62. }
  63. // Clear the combo
  64. while (0 < m_pEdit->GetNumItems())
  65. {
  66. RichAddressInfo *pAddr = reinterpret_cast<RichAddressInfo*>(m_pEdit->GetUserData(0));
  67. ClearAddr(&pAddr);
  68. m_pEdit->RemoveItem(0);
  69. }
  70. }
  71. void CCallingBar::OnNewAddress(RichAddressInfo *pAddr)
  72. {
  73. if (NULL != pAddr)
  74. {
  75. m_pEdit->SetSelectedIndex(-1);
  76. m_pEdit->SetText(pAddr->szName);
  77. SetEditFont(TRUE);
  78. ClearAddr(&m_pAddr);
  79. m_pAddr = pAddr;
  80. }
  81. }
  82. CCallingBar::CCallingBar() : m_pAddr(NULL), m_pEdit(NULL), m_bUnderline(FALSE), m_pAccel(NULL)
  83. {
  84. }
  85. BOOL CCallingBar::Create(CGenWindow *pParent, CConfRoom *pConfRoom)
  86. {
  87. m_pConfRoom = pConfRoom;
  88. // Create the toolbar
  89. if (!CToolbar::Create(pParent->GetWindow()))
  90. {
  91. return(FALSE);
  92. }
  93. CCallingBar *pDial = this;
  94. pDial->m_nAlignment = Center;
  95. // Add the directory button
  96. static const Buttons callButtons[] =
  97. {
  98. { IDB_DIAL , CBitmapButton::Disabled+1, 1, ID_TB_NEW_CALL, IDS_TT_TB_NEW_CALL, },
  99. } ;
  100. // Create the text control
  101. CComboBox *pEdit = new CComboBox();
  102. m_pEdit = pEdit;
  103. if (NULL != pEdit)
  104. {
  105. if (pEdit->Create(pDial->GetWindow(), 200, CBS_AUTOHSCROLL|CBS_DROPDOWN, g_szEmpty, this))
  106. {
  107. pEdit->SetTooltip(RES2T(IDS_TT_ADDRESS_BAR));
  108. // Set the colors and the font
  109. pEdit->SetColors(CreateSolidBrush(EditBack), EditBack, EditFore);
  110. SetEditFont(FALSE, TRUE);
  111. ::SendMessage( *pEdit, CB_LIMITTEXT, CCallto::s_iMaxAddressLength, 0 );
  112. }
  113. }
  114. // Add the call button on the right
  115. AddButtons(pDial, callButtons, 1);
  116. // I want the second button on the right, and the ComboBox in the
  117. // middle
  118. pDial->m_uRightIndex = 1;
  119. pDial->m_bHasCenterChild = TRUE;
  120. m_pAccel = new CTranslateAccelTable(GetWindow(),
  121. ::LoadAccelerators(GetInstanceHandle(), MAKEINTRESOURCE(IDR_CALL)));
  122. if (NULL != m_pAccel)
  123. {
  124. AddTranslateAccelerator(m_pAccel);
  125. }
  126. return(TRUE);
  127. }
  128. void CCallingBar::OnTextChange(CComboBox *pEdit)
  129. {
  130. ClearAddr(&m_pAddr);
  131. SetEditFont(FALSE);
  132. }
  133. void CCallingBar::OnFocusChange(CComboBox *pEdit, BOOL bSet)
  134. {
  135. if (!bSet)
  136. {
  137. RichAddressInfo *pAddr = NULL;
  138. int index = m_pEdit->GetSelectedIndex();
  139. if (0 <= index)
  140. {
  141. LPARAM lpAddr = m_pEdit->GetUserData(index);
  142. if (static_cast<LPARAM>(-1) != lpAddr && 0 != lpAddr)
  143. {
  144. // There are cases where the combo thinks we have a selection,
  145. // but there is no associated address
  146. pAddr = reinterpret_cast<RichAddressInfo*>(lpAddr);
  147. // I need to make a copy so I won't delete twice
  148. RichAddressInfo *pCopy = NULL;
  149. m_pConfRoom->CopyAddress(pAddr, &pCopy);
  150. OnNewAddress(pCopy);
  151. }
  152. }
  153. }
  154. if (bSet)
  155. {
  156. // Only clear this on setfocus, to avoid some weirdness when the focus is
  157. // lost while the list is dropped down.
  158. ClearCombo();
  159. IEnumRichAddressInfo *pEnum;
  160. if (SUCCEEDED(m_pConfRoom->GetRecentAddresses(&pEnum)))
  161. {
  162. for (long index=0; ; ++index)
  163. {
  164. RichAddressInfo *pAddr;
  165. if (S_OK != pEnum->GetAddress(index, &pAddr))
  166. {
  167. break;
  168. }
  169. m_pEdit->AddText(pAddr->szName, reinterpret_cast<LPARAM>(pAddr));
  170. }
  171. pEnum->Release();
  172. }
  173. }
  174. }
  175. void CCallingBar::OnSelectionChange(CComboBox *pCombo)
  176. {
  177. }
  178. CCallingBar::~CCallingBar()
  179. {
  180. ClearAddr(&m_pAddr);
  181. ReleaseIt(m_pEdit);
  182. }
  183. LRESULT CCallingBar::ProcessMessage(HWND hwnd, UINT uCmd, WPARAM wParam, LPARAM lParam)
  184. {
  185. switch (uCmd)
  186. {
  187. case WM_DESTROY:
  188. if (NULL != m_pAccel)
  189. {
  190. RemoveTranslateAccelerator(m_pAccel);
  191. m_pAccel->Release();
  192. m_pAccel = NULL;
  193. }
  194. ClearCombo();
  195. break;
  196. case WM_SETFOCUS:
  197. if (NULL != m_pEdit)
  198. {
  199. ::SetFocus(m_pEdit->GetWindow());
  200. }
  201. break;
  202. default:
  203. break;
  204. }
  205. return(CToolbar::ProcessMessage(hwnd, uCmd, wParam, lParam));
  206. }
  207. void CCallingBar::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  208. {
  209. switch (id)
  210. {
  211. case ID_TB_NEW_CALL:
  212. {
  213. // Make sure all the fields are updated correctly
  214. OnFocusChange(m_pEdit, FALSE);
  215. TCHAR szEdit[CCH_MAX_NAME];
  216. int szEditLen = m_pEdit->GetText(szEdit, ARRAY_ELEMENTS(szEdit));
  217. if( szEditLen > 0 )
  218. {
  219. szEditLen = TrimSz( szEdit );
  220. }
  221. if( (m_pAddr != NULL) || (szEditLen > 0) )
  222. {
  223. const TCHAR * pszCallto;
  224. const TCHAR * pszDisplayName;
  225. NM_ADDR_TYPE nmAddressType;
  226. if( hasValidUserInfo( m_pAddr ) )
  227. {
  228. pszCallto = m_pAddr->rgDwStr[ 0 ].psz;
  229. pszDisplayName = m_pAddr->szName;
  230. nmAddressType = static_cast<NM_ADDR_TYPE>(m_pAddr->rgDwStr[ 0 ].dw);
  231. }
  232. else
  233. {
  234. pszCallto = szEdit;
  235. pszDisplayName = szEdit;
  236. nmAddressType = bCanCallAsPhoneNumber( pszCallto )? NM_ADDR_ALIAS_E164: NM_ADDR_UNKNOWN;
  237. }
  238. g_pCCallto->Callto( pszCallto, // pointer to the callto url to try to place the call with...
  239. pszDisplayName, // pointer to the display name to use...
  240. nmAddressType, // callto type to resolve this callto as...
  241. true, // the pszCallto parameter is to be interpreted as a pre-unescaped addressing component vs a full callto...
  242. NULL, // security preference, NULL for none. must be "compatible" with secure param if present...
  243. true, // whether or not save in mru...
  244. true, // whether or not to perform user interaction on errors...
  245. GetWindow(), // if bUIEnabled is true this is the window to parent error/status windows to...
  246. NULL ); // out pointer to INmCall * to receive INmCall * generated by placing call...
  247. }
  248. else
  249. {
  250. CDlgAcd::newCall( GetWindow(), m_pConfRoom );
  251. }
  252. break;
  253. }
  254. case ID_TB_DIRECTORY:
  255. // Let the parent handle this command
  256. default:
  257. FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, CToolbar::ProcessMessage);
  258. }
  259. }
  260. int CCallingBar::GetText(LPTSTR szText, int nLen)
  261. {
  262. if (NULL != m_pEdit)
  263. {
  264. return(m_pEdit->GetText(szText, nLen));
  265. }
  266. szText[0] = '\0';
  267. return(0);
  268. }
  269. void CCallingBar::SetText(LPCTSTR szText)
  270. {
  271. if (NULL != m_pEdit)
  272. {
  273. m_pEdit->SetText(szText);
  274. }
  275. }
  276.