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.

339 lines
7.7 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. USES_RES2T
  108. pEdit->SetTooltip(RES2T(IDS_TT_ADDRESS_BAR));
  109. // pEdit->SetWindowtext(RES2T(IDS_TT_ADDRESS_BAR));
  110. // Set the colors and the font
  111. pEdit->SetColors(CreateSolidBrush(EditBack), EditBack, EditFore);
  112. SetEditFont(FALSE, TRUE);
  113. ::SendMessage( *pEdit, CB_LIMITTEXT, CCallto::s_iMaxAddressLength, 0 );
  114. }
  115. }
  116. // Add the call button on the right
  117. AddButtons(pDial, callButtons, 1);
  118. // I want the second button on the right, and the ComboBox in the
  119. // middle
  120. pDial->m_uRightIndex = 1;
  121. pDial->m_bHasCenterChild = TRUE;
  122. m_pAccel = new CTranslateAccelTable(GetWindow(),
  123. ::LoadAccelerators(GetInstanceHandle(), MAKEINTRESOURCE(IDR_CALL)));
  124. if (NULL != m_pAccel)
  125. {
  126. AddTranslateAccelerator(m_pAccel);
  127. }
  128. return(TRUE);
  129. }
  130. void CCallingBar::OnTextChange(CComboBox *pEdit)
  131. {
  132. ClearAddr(&m_pAddr);
  133. SetEditFont(FALSE);
  134. }
  135. void CCallingBar::OnFocusChange(CComboBox *pEdit, BOOL bSet)
  136. {
  137. if (!bSet)
  138. {
  139. RichAddressInfo *pAddr = NULL;
  140. int index = m_pEdit->GetSelectedIndex();
  141. if (0 <= index)
  142. {
  143. LPARAM lpAddr = m_pEdit->GetUserData(index);
  144. if (static_cast<LPARAM>(-1) != lpAddr && 0 != lpAddr)
  145. {
  146. // There are cases where the combo thinks we have a selection,
  147. // but there is no associated address
  148. pAddr = reinterpret_cast<RichAddressInfo*>(lpAddr);
  149. // I need to make a copy so I won't delete twice
  150. RichAddressInfo *pCopy = NULL;
  151. m_pConfRoom->CopyAddress(pAddr, &pCopy);
  152. OnNewAddress(pCopy);
  153. }
  154. }
  155. }
  156. if (bSet)
  157. {
  158. // Only clear this on setfocus, to avoid some weirdness when the focus is
  159. // lost while the list is dropped down.
  160. ClearCombo();
  161. IEnumRichAddressInfo *pEnum;
  162. if (SUCCEEDED(m_pConfRoom->GetRecentAddresses(&pEnum)))
  163. {
  164. for (long index=0; ; ++index)
  165. {
  166. RichAddressInfo *pAddr;
  167. if (S_OK != pEnum->GetAddress(index, &pAddr))
  168. {
  169. break;
  170. }
  171. m_pEdit->AddText(pAddr->szName, reinterpret_cast<LPARAM>(pAddr));
  172. }
  173. pEnum->Release();
  174. }
  175. }
  176. }
  177. void CCallingBar::OnSelectionChange(CComboBox *pCombo)
  178. {
  179. }
  180. CCallingBar::~CCallingBar()
  181. {
  182. ClearAddr(&m_pAddr);
  183. ReleaseIt(m_pEdit);
  184. }
  185. LRESULT CCallingBar::ProcessMessage(HWND hwnd, UINT uCmd, WPARAM wParam, LPARAM lParam)
  186. {
  187. switch (uCmd)
  188. {
  189. case WM_DESTROY:
  190. if (NULL != m_pAccel)
  191. {
  192. RemoveTranslateAccelerator(m_pAccel);
  193. m_pAccel->Release();
  194. m_pAccel = NULL;
  195. }
  196. ClearCombo();
  197. break;
  198. case WM_SETFOCUS:
  199. if (NULL != m_pEdit)
  200. {
  201. ::SetFocus(m_pEdit->GetWindow());
  202. }
  203. break;
  204. default:
  205. break;
  206. }
  207. return(CToolbar::ProcessMessage(hwnd, uCmd, wParam, lParam));
  208. }
  209. void CCallingBar::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  210. {
  211. switch (id)
  212. {
  213. case ID_TB_NEW_CALL:
  214. {
  215. // Make sure all the fields are updated correctly
  216. OnFocusChange(m_pEdit, FALSE);
  217. TCHAR szEdit[CCH_MAX_NAME];
  218. int szEditLen = m_pEdit->GetText(szEdit, ARRAY_ELEMENTS(szEdit));
  219. if( szEditLen > 0 )
  220. {
  221. szEditLen = TrimSz( szEdit );
  222. }
  223. if( (m_pAddr != NULL) || (szEditLen > 0) )
  224. {
  225. const TCHAR * pszCallto;
  226. const TCHAR * pszDisplayName;
  227. NM_ADDR_TYPE nmAddressType;
  228. if( hasValidUserInfo( m_pAddr ) )
  229. {
  230. pszCallto = m_pAddr->rgDwStr[ 0 ].psz;
  231. pszDisplayName = m_pAddr->szName;
  232. nmAddressType = static_cast<NM_ADDR_TYPE>(m_pAddr->rgDwStr[ 0 ].dw);
  233. }
  234. else
  235. {
  236. pszCallto = szEdit;
  237. pszDisplayName = szEdit;
  238. nmAddressType = bCanCallAsPhoneNumber( pszCallto )? NM_ADDR_ALIAS_E164: NM_ADDR_UNKNOWN;
  239. }
  240. g_pCCallto->Callto( pszCallto, // pointer to the callto url to try to place the call with...
  241. pszDisplayName, // pointer to the display name to use...
  242. nmAddressType, // callto type to resolve this callto as...
  243. true, // the pszCallto parameter is to be interpreted as a pre-unescaped addressing component vs a full callto...
  244. NULL, // security preference, NULL for none. must be "compatible" with secure param if present...
  245. true, // whether or not save in mru...
  246. true, // whether or not to perform user interaction on errors...
  247. GetWindow(), // if bUIEnabled is true this is the window to parent error/status windows to...
  248. NULL ); // out pointer to INmCall * to receive INmCall * generated by placing call...
  249. }
  250. else
  251. {
  252. CDlgAcd::newCall( GetWindow(), m_pConfRoom );
  253. }
  254. break;
  255. }
  256. case ID_TB_DIRECTORY:
  257. // Let the parent handle this command
  258. default:
  259. FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, CToolbar::ProcessMessage);
  260. }
  261. }
  262. int CCallingBar::GetText(LPTSTR szText, int nLen)
  263. {
  264. if (NULL != m_pEdit)
  265. {
  266. return(m_pEdit->GetText(szText, nLen));
  267. }
  268. szText[0] = '\0';
  269. return(0);
  270. }
  271. void CCallingBar::SetText(LPCTSTR szText)
  272. {
  273. if (NULL != m_pEdit)
  274. {
  275. m_pEdit->SetText(szText);
  276. }
  277. }
  278.