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.

348 lines
8.3 KiB

  1. // File: sdialdlg.cpp
  2. //
  3. // Speed Dials (Friends)
  4. #include "precomp.h"
  5. #include "resource.h"
  6. #include "sdialdlg.h"
  7. #include "call.h"
  8. #include "cmd.h"
  9. #include "ConfUtil.h"
  10. #include "help_ids.h"
  11. extern BOOL FCreateSpeedDial(LPCTSTR pcszName, LPCTSTR pcszAddress,
  12. NM_ADDR_TYPE addrType = NM_ADDR_UNKNOWN, DWORD dwCallFlags = CRPCF_DEFAULT,
  13. LPCTSTR pcszRemoteConfName = NULL, LPCTSTR pcszPassword = NULL,
  14. LPCTSTR pcszPathPrefix = NULL);
  15. static const DWORD _rgHelpIdsSpeedDial[] = {
  16. IDC_STATIC_SPEED_DIAL_INSTRUCTIONS, IDH_STATIC_SPEED_DIAL_INSTRUCTIONS,
  17. IDC_CSD_SD_INFO_GROUP, IDH_CSD_SD_INFO_GROUP,
  18. IDC_STATIC_ADDRESS, IDH_CSD_ADDRESS_EDIT,
  19. IDC_CSD_ADDRESS_EDIT, IDH_CSD_ADDRESS_EDIT,
  20. IDC_STATIC_CALLUSING, IDH_CSD_CALL_USING_COMBO,
  21. IDC_CSD_CALL_USING_COMBO, IDH_CSD_CALL_USING_COMBO,
  22. IDC_CSD_CREATE_GROUPBOX, IDH_CSD_CREATE_GROUPBOX,
  23. IDC_CSD_SPEEDDIAL_LIST_RADIO, IDH_CSD_SPEEDDIAL_LIST_RADIO,
  24. IDC_CSD_SAVE_DESKTOP_RADIO, IDH_CSD_SAVE_DESKTOP_RADIO,
  25. 0, 0 // terminator
  26. };
  27. CSpeedDialDlg::CSpeedDialDlg(HWND hwndParent, NM_ADDR_TYPE addrType) :
  28. m_hwndParent (hwndParent),
  29. m_pszAddress (NULL),
  30. m_addrType (addrType),
  31. m_hwnd (NULL)
  32. {
  33. DBGENTRY(CSpeedDialDlg::CSpeedDialDlg);
  34. }
  35. CSpeedDialDlg::~CSpeedDialDlg()
  36. {
  37. DBGENTRY(CSpeedDialDlg::~CSpeedDialDlg);
  38. // Free all strings
  39. delete m_pszAddress;
  40. }
  41. /****************************************************************************
  42. *
  43. * CLASS: CSpeedDialDlg
  44. *
  45. * MEMBER: DoModal()
  46. *
  47. * PURPOSE: Brings up the modal dialog box
  48. *
  49. ****************************************************************************/
  50. INT_PTR CSpeedDialDlg::DoModal(LPCTSTR pcszAddress)
  51. {
  52. DBGENTRY(CSpeedDialDlg::DoModal);
  53. if (NULL != pcszAddress)
  54. {
  55. ASSERT(NULL == m_pszAddress);
  56. m_pszAddress = PszAlloc(pcszAddress);
  57. }
  58. INT_PTR nRet = DialogBoxParam( ::GetInstanceHandle(),
  59. MAKEINTRESOURCE(IDD_CREATE_SPEED_DIAL),
  60. m_hwndParent,
  61. CSpeedDialDlg::SpeedDialDlgProc,
  62. (LPARAM) this);
  63. DebugExitINT_PTR(CSpeedDialDlg::DoModal, nRet);
  64. return nRet;
  65. }
  66. /****************************************************************************
  67. *
  68. * CLASS: CSpeedDialDlg
  69. *
  70. * MEMBER: SpeedDialDlgProc()
  71. *
  72. * PURPOSE: Dialog Proc - handles all messages
  73. *
  74. ****************************************************************************/
  75. INT_PTR CALLBACK CSpeedDialDlg::SpeedDialDlgProc( HWND hDlg,
  76. UINT uMsg,
  77. WPARAM wParam,
  78. LPARAM lParam)
  79. {
  80. BOOL bMsgHandled = FALSE;
  81. ASSERT(IS_VALID_HANDLE(hDlg, WND));
  82. switch (uMsg)
  83. {
  84. case WM_INITDIALOG:
  85. {
  86. if (NULL != lParam)
  87. {
  88. ((CSpeedDialDlg*) lParam)->m_hwnd = hDlg;
  89. ::SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  90. bMsgHandled = ((CSpeedDialDlg*) lParam)->OnInitDialog();
  91. }
  92. break;
  93. }
  94. default:
  95. {
  96. CSpeedDialDlg* psdd = (CSpeedDialDlg*) ::GetWindowLongPtr(hDlg,
  97. DWLP_USER);
  98. if (NULL != psdd)
  99. {
  100. bMsgHandled = psdd->ProcessMessage(uMsg, wParam, lParam);
  101. }
  102. }
  103. }
  104. return bMsgHandled;
  105. }
  106. BOOL CSpeedDialDlg::AddAddressType(NM_ADDR_TYPE addrType, LPCTSTR lpcszDispName)
  107. {
  108. int index = (int)::SendDlgItemMessage(m_hwnd, IDC_CSD_CALL_USING_COMBO,
  109. CB_ADDSTRING, 0, (LPARAM) lpcszDispName);
  110. if (CB_ERR == index)
  111. return FALSE;
  112. // Set the item data:
  113. ::SendDlgItemMessage(m_hwnd, IDC_CSD_CALL_USING_COMBO,
  114. CB_SETITEMDATA, index,addrType);
  115. if (addrType == m_addrType)
  116. {
  117. // Select the transport:
  118. ::SendDlgItemMessage(m_hwnd, IDC_CSD_CALL_USING_COMBO,
  119. CB_SETCURSEL, index, 0);
  120. }
  121. return TRUE;
  122. }
  123. BOOL CSpeedDialDlg::AddAddressType(NM_ADDR_TYPE addrType, UINT uStringID)
  124. {
  125. TCHAR sz[MAX_PATH];
  126. if (!FLoadString(uStringID, sz, CCHMAX(sz)))
  127. return FALSE;
  128. return AddAddressType(addrType, sz);
  129. }
  130. BOOL CSpeedDialDlg::OnInitDialog(void)
  131. {
  132. ::CheckDlgButton(m_hwnd, IDC_CSD_SPEEDDIAL_LIST_RADIO, BST_CHECKED);
  133. // Fill in the "Call Using" list:
  134. AddAddressType(NM_ADDR_IP, IDS_ACD_CT_IP);
  135. AddAddressType(NM_ADDR_ULS, IDS_ACD_CT_ILS);
  136. if (FH323GatewayEnabled())
  137. {
  138. AddAddressType(NM_ADDR_H323_GATEWAY, IDS_GATEWAY_DISPLAY_NAME);
  139. }
  140. int iSelected = (int)::SendDlgItemMessage(m_hwnd,
  141. IDC_CSD_CALL_USING_COMBO, CB_GETCURSEL, 0, 0);
  142. if (CB_ERR == iSelected)
  143. {
  144. // The transport that we wanted to select was not available, so
  145. // we will select the first one that we added to the list:
  146. ::SendDlgItemMessage(m_hwnd,
  147. IDC_CSD_CALL_USING_COMBO, CB_SETCURSEL, 0, 0);
  148. m_addrType = (NM_ADDR_TYPE) ::SendDlgItemMessage(m_hwnd,
  149. IDC_CSD_CALL_USING_COMBO, CB_GETITEMDATA, 0, 0);
  150. }
  151. if (!FEmptySz(m_pszAddress))
  152. {
  153. ::SetDlgItemText(m_hwnd, IDC_CSD_ADDRESS_EDIT, m_pszAddress);
  154. }
  155. else if (NM_ADDR_ULS == m_addrType)
  156. {
  157. RegEntry re(ISAPI_CLIENT_KEY, HKEY_CURRENT_USER);
  158. ::SetDlgItemText(m_hwnd, IDC_CSD_ADDRESS_EDIT,
  159. re.GetString(REGVAL_ULS_RES_NAME));
  160. }
  161. Edit_LimitText(GetDlgItem(m_hwnd, IDC_CSD_ADDRESS_EDIT), CCHMAXSZ_ADDRESS - 1);
  162. RefreshOkButton();
  163. return TRUE;
  164. }
  165. /****************************************************************************
  166. *
  167. * CLASS: CSpeedDialDlg
  168. *
  169. * MEMBER: ProcessMessage()
  170. *
  171. * PURPOSE: processes all messages except WM_INITDIALOG
  172. *
  173. ****************************************************************************/
  174. BOOL CSpeedDialDlg::ProcessMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  175. {
  176. BOOL bRet = FALSE;
  177. ASSERT(m_hwnd);
  178. switch (uMsg)
  179. {
  180. case WM_COMMAND:
  181. {
  182. switch (LOWORD(wParam))
  183. {
  184. case IDOK:
  185. {
  186. bRet = OnOk();
  187. break;
  188. }
  189. case IDCANCEL:
  190. {
  191. ::EndDialog(m_hwnd, LOWORD(wParam));
  192. bRet = TRUE;
  193. break;
  194. }
  195. case IDC_CSD_ADDRESS_EDIT:
  196. {
  197. if (EN_CHANGE == HIWORD(wParam))
  198. {
  199. RefreshOkButton();
  200. }
  201. break;
  202. }
  203. }
  204. break;
  205. case WM_CONTEXTMENU:
  206. DoHelpWhatsThis(wParam, _rgHelpIdsSpeedDial);
  207. break;
  208. case WM_HELP:
  209. DoHelp(lParam, _rgHelpIdsSpeedDial);
  210. break;
  211. }
  212. }
  213. return bRet;
  214. }
  215. NM_ADDR_TYPE CSpeedDialDlg::GetCurAddrType(void)
  216. {
  217. int iIndex = (int)::SendDlgItemMessage(m_hwnd, IDC_CSD_CALL_USING_COMBO,
  218. CB_GETCURSEL, 0, 0);
  219. if (CB_ERR == iIndex)
  220. return NM_ADDR_UNKNOWN;
  221. return (NM_ADDR_TYPE) ::SendDlgItemMessage(m_hwnd,
  222. IDC_CSD_CALL_USING_COMBO, CB_GETITEMDATA, iIndex, 0);
  223. }
  224. BOOL CSpeedDialDlg::OnOk(void)
  225. {
  226. m_addrType = GetCurAddrType();
  227. BOOL fSaveDesktop = (BST_CHECKED == ::IsDlgButtonChecked(m_hwnd,
  228. IDC_CSD_SAVE_DESKTOP_RADIO));
  229. TCHAR szBuf[MAX_PATH];
  230. if (0 != ::GetDlgItemText( m_hwnd,
  231. IDC_CSD_ADDRESS_EDIT,
  232. szBuf,
  233. ARRAY_ELEMENTS(szBuf)))
  234. {
  235. // Copy address into the address:
  236. delete m_pszAddress;
  237. m_pszAddress = PszAlloc(szBuf);
  238. }
  239. ::EndDialog(m_hwnd, IDOK);
  240. TRACE_OUT(("Creating Speed Dial:"));
  241. TRACE_OUT(("\tTransport ID: %d", GetAddrType()));
  242. TRACE_OUT(("\tAddress: \"%s\"", GetAddress()));
  243. TRACE_OUT(("\tSaveDesktop: %s", ::GetBOOLString(fSaveDesktop)));
  244. NM_ADDR_TYPE addrType = GetAddrType();
  245. DWORD crpcf = (NM_ADDR_H323_GATEWAY == addrType) ?
  246. (CRPCF_AUDIO | CRPCF_VIDEO) : CRPCF_DEFAULT;
  247. if (fSaveDesktop)
  248. {
  249. // Save on desktop
  250. BOOL fSavedOk = FALSE;
  251. LPITEMIDLIST pidl = NULL;
  252. TCHAR szPathPrefix[MAX_PATH];
  253. szPathPrefix[0] = _T('\0');
  254. if (NMGetSpecialFolderPath(NULL, szPathPrefix, CSIDL_DESKTOP, TRUE))
  255. {
  256. fSavedOk = ::FCreateSpeedDial(
  257. GetAddress(), // pcszName
  258. GetAddress(), // pcszAddress
  259. addrType, // addrType
  260. crpcf, // dwCallFlags
  261. NULL, // pcszRemoteConfName
  262. NULL, // pcszPassword
  263. szPathPrefix); // pcszPathPrefix
  264. }
  265. else
  266. {
  267. ERROR_OUT(("NMGetSpecialFolderPath failed!"));
  268. }
  269. ::ConfMsgBox( m_hwnd, (LPCTSTR) (fSavedOk ?
  270. (UINT_PTR)IDS_SPEED_DIAL_SAVED_ON_DESKTOP :
  271. (UINT_PTR)IDS_SPEED_DIAL_SAVE_ERROR));
  272. }
  273. else
  274. {
  275. ::FCreateSpeedDial(
  276. GetAddress(), // pcszName
  277. GetAddress(), // pcszAddress
  278. addrType, // addrType
  279. crpcf, // dwCallFlags
  280. NULL, // pcszRemoteConfName
  281. NULL, // pcszPassword
  282. NULL); // pcszPathPrefix
  283. }
  284. return TRUE;
  285. }
  286. VOID CSpeedDialDlg::RefreshOkButton()
  287. {
  288. ::EnableWindow( GetDlgItem(m_hwnd, IDOK),
  289. 0 != ::GetWindowTextLength(::GetDlgItem(m_hwnd, IDC_CSD_ADDRESS_EDIT)));
  290. }
  291.