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.

460 lines
12 KiB

  1. // Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. //
  3. // mlink.c
  4. // Remote Access Common Dialog APIs
  5. // Multi-link configuration dialogs
  6. //
  7. // 01/23/96 Steve Cobb
  8. #include "rasdlgp.h"
  9. //----------------------------------------------------------------------------
  10. // Help maps
  11. //----------------------------------------------------------------------------
  12. static DWORD g_adwDmHelp[] =
  13. {
  14. CID_DM_ST_Explain, HID_DM_ST_Explain,
  15. CID_DM_ST_Dial, HID_DM_LB_DialPercent,
  16. CID_DM_LB_DialPercent, HID_DM_LB_DialPercent,
  17. CID_DM_ST_DialOrMore, HID_DM_LB_DialTime,
  18. CID_DM_LB_DialTime, HID_DM_LB_DialTime,
  19. CID_DM_ST_HangUp, HID_DM_LB_HangUpPercent,
  20. CID_DM_LB_HangUpPercent, HID_DM_LB_HangUpPercent,
  21. CID_DM_ST_HangUpOrLess, HID_DM_LB_HangUpTime,
  22. CID_DM_LB_HangUpTime, HID_DM_LB_HangUpTime,
  23. 0, 0
  24. };
  25. //-----------------------------------------------------------------------------
  26. // Local datatypes
  27. //-----------------------------------------------------------------------------
  28. // Multi-link dialing dialog context block.
  29. //
  30. typedef struct
  31. _DMINFO
  32. {
  33. // Stub API argument.
  34. //
  35. PBENTRY* pEntry;
  36. // Handle of this dialog and some of it's controls.
  37. //
  38. HWND hwndDlg;
  39. HWND hwndLbDialPercents;
  40. HWND hwndLbDialTimes;
  41. HWND hwndLbHangUpPercents;
  42. HWND hwndLbHangUpTimes;
  43. }
  44. DMINFO;
  45. //----------------------------------------------------------------------------
  46. // Local prototypes (alphabetically)
  47. //----------------------------------------------------------------------------
  48. BOOL
  49. DmCommand(
  50. IN HWND hwnd,
  51. IN WORD wNotification,
  52. IN WORD wId,
  53. IN HWND hwndCtrl );
  54. INT_PTR CALLBACK
  55. DmDlgProc(
  56. IN HWND hwnd,
  57. IN UINT unMsg,
  58. IN WPARAM wparam,
  59. IN LPARAM lparam );
  60. BOOL
  61. DmInit(
  62. IN HWND hwndDlg,
  63. IN PBENTRY* pEntry );
  64. VOID
  65. DmSave(
  66. IN DMINFO* pInfo );
  67. VOID
  68. DmTerm(
  69. IN HWND hwndDlg );
  70. //----------------------------------------------------------------------------
  71. // Multi-link dialing dialog
  72. // Listed alphabetically following stub API and dialog proc
  73. //----------------------------------------------------------------------------
  74. BOOL
  75. MultiLinkDialingDlg(
  76. IN HWND hwndOwner,
  77. OUT PBENTRY* pEntry )
  78. // Popup the Multi-link dialing dialog. 'HwndOwner' is the owner of the
  79. // dialog. 'PEntry' is a phonebook entry to edit.
  80. //
  81. // Returns true if user pressed OK and succeeded, false if user pressed
  82. // Cancel or encountered an error.
  83. {
  84. INT_PTR nStatus;
  85. TRACE( "MultiLinkConfigureDlg" );
  86. nStatus =
  87. DialogBoxParam(
  88. g_hinstDll,
  89. MAKEINTRESOURCE( DID_DM_DialingMultipleLines ),
  90. hwndOwner,
  91. DmDlgProc,
  92. (LPARAM )pEntry );
  93. if (nStatus == -1)
  94. {
  95. ErrorDlg( hwndOwner, SID_OP_LoadDlg, ERROR_UNKNOWN, NULL );
  96. nStatus = FALSE;
  97. }
  98. return (nStatus) ? TRUE : FALSE;
  99. }
  100. INT_PTR CALLBACK
  101. DmDlgProc(
  102. IN HWND hwnd,
  103. IN UINT unMsg,
  104. IN WPARAM wparam,
  105. IN LPARAM lparam )
  106. // DialogProc callback for the Multi-Link dialing dialog. Parameters and
  107. // return value are as described for standard windows 'DialogProc's.
  108. //
  109. {
  110. #if 0
  111. TRACE4( "DmDlgProc(h=$%x,m=$%x,w=$%x,l=$%x)",
  112. (DWORD )hwnd, (DWORD )unMsg, (DWORD )wparam, (DWORD )lparam );
  113. #endif
  114. switch (unMsg)
  115. {
  116. case WM_INITDIALOG:
  117. {
  118. return DmInit( hwnd, (PBENTRY* )lparam );
  119. }
  120. case WM_HELP:
  121. case WM_CONTEXTMENU:
  122. {
  123. ContextHelp( g_adwDmHelp, hwnd, unMsg, wparam, lparam );
  124. break;
  125. }
  126. case WM_COMMAND:
  127. {
  128. return DmCommand(
  129. hwnd, HIWORD( wparam ), LOWORD( wparam ), (HWND )lparam );
  130. }
  131. case WM_DESTROY:
  132. {
  133. DmTerm( hwnd );
  134. break;
  135. }
  136. }
  137. return FALSE;
  138. }
  139. BOOL
  140. DmCommand(
  141. IN HWND hwnd,
  142. IN WORD wNotification,
  143. IN WORD wId,
  144. IN HWND hwndCtrl )
  145. // Called on WM_COMMAND. 'Hwnd' is the dialog window. 'WNotification' is
  146. // the notification code of the command. 'wId' is the control/menu
  147. // identifier of the command. 'HwndCtrl' is the control window handle of
  148. // the command.
  149. //
  150. // Returns true if processed message, false otherwise.
  151. //
  152. {
  153. DWORD dwErr;
  154. TRACE3( "DmCommand(n=%d,i=%d,c=$%x)",
  155. (DWORD )wNotification, (DWORD )wId, (ULONG_PTR )hwndCtrl );
  156. switch (wId)
  157. {
  158. case IDOK:
  159. {
  160. DMINFO* pInfo;
  161. pInfo = (DMINFO* )GetWindowLongPtr( hwnd, DWLP_USER );
  162. ASSERT( pInfo );
  163. DmSave( pInfo );
  164. EndDialog( hwnd, TRUE );
  165. return TRUE;
  166. }
  167. case IDCANCEL:
  168. {
  169. TRACE( "Cancel pressed" );
  170. EndDialog( hwnd, FALSE );
  171. return TRUE;
  172. }
  173. }
  174. return FALSE;
  175. }
  176. BOOL
  177. DmInit(
  178. IN HWND hwndDlg,
  179. IN PBENTRY* pEntry )
  180. // Called on WM_INITDIALOG. 'hwndDlg' is the handle of the owning window.
  181. // 'PEntry' is the caller's stub API argument.
  182. //
  183. // Return false if focus was set, true otherwise, i.e. as defined for
  184. // WM_INITDIALOG.
  185. //
  186. {
  187. DWORD dwErr;
  188. DMINFO* pInfo;
  189. TRACE( "DmInit" );
  190. // Allocate the dialog context block. Initialize minimally for proper
  191. // cleanup, then attach to the dialog window.
  192. //
  193. {
  194. pInfo = Malloc( sizeof(*pInfo) );
  195. if (!pInfo)
  196. {
  197. ErrorDlg( hwndDlg, SID_OP_LoadDlg, ERROR_NOT_ENOUGH_MEMORY, NULL );
  198. EndDialog( hwndDlg, FALSE );
  199. return TRUE;
  200. }
  201. ZeroMemory( pInfo, sizeof(*pInfo) );
  202. pInfo->pEntry = pEntry;
  203. pInfo->hwndDlg = hwndDlg;
  204. SetWindowLongPtr( hwndDlg, DWLP_USER, (ULONG_PTR )pInfo );
  205. TRACE( "Context set" );
  206. }
  207. pInfo->hwndLbDialPercents = GetDlgItem( hwndDlg, CID_DM_LB_DialPercent );
  208. ASSERT( pInfo->hwndLbDialPercents );
  209. pInfo->hwndLbDialTimes = GetDlgItem( hwndDlg, CID_DM_LB_DialTime );
  210. ASSERT( pInfo->hwndLbDialTimes );
  211. pInfo->hwndLbHangUpPercents = GetDlgItem( hwndDlg, CID_DM_LB_HangUpPercent );
  212. ASSERT( pInfo->hwndLbHangUpPercents );
  213. pInfo->hwndLbHangUpTimes = GetDlgItem( hwndDlg, CID_DM_LB_HangUpTime );
  214. ASSERT( pInfo->hwndLbHangUpTimes );
  215. // Initialize the drop lists contents and selections.
  216. //
  217. {
  218. INT i;
  219. INT iSel;
  220. DWORD* pdwPercent;
  221. LBTABLEITEM* pItem;
  222. static LBTABLEITEM aTimes[] =
  223. {
  224. SID_Time3s, 3,
  225. SID_Time5s, 5,
  226. SID_Time10s, 10,
  227. SID_Time30s, 30,
  228. SID_Time1m, 60,
  229. SID_Time2m, 120,
  230. SID_Time5m, 300,
  231. SID_Time10m, 600,
  232. SID_Time30m, 1800,
  233. SID_Time1h, 3600,
  234. 0, 0
  235. };
  236. static DWORD aDialPercents[] =
  237. {
  238. 1, 5, 10, 25, 50, 75, 90, 95, 100, 0xFFFFFFFF
  239. };
  240. static DWORD aHangUpPercents[] =
  241. {
  242. 0, 5, 10, 25, 50, 75, 90, 95, 99, 0xFFFFFFFF
  243. };
  244. // Initialize the Dial Percents list and set the selection.
  245. //
  246. iSel = -1;
  247. for (pdwPercent = aDialPercents, i = 0;
  248. *pdwPercent != 0xFFFFFFFF;
  249. ++pdwPercent, ++i)
  250. {
  251. TCHAR achPercent[ 12 ];
  252. wsprintf( achPercent, TEXT("%d%%"), *pdwPercent );
  253. ComboBox_AddItem( pInfo->hwndLbDialPercents, achPercent,
  254. (VOID* )UlongToPtr(*pdwPercent));
  255. if (iSel < 0 && pEntry->dwDialPercent <= *pdwPercent)
  256. {
  257. iSel = i;
  258. ComboBox_SetCurSel( pInfo->hwndLbDialPercents, iSel );
  259. }
  260. }
  261. if (iSel < 0)
  262. {
  263. ComboBox_SetCurSel( pInfo->hwndLbDialPercents, i - 1 );
  264. }
  265. // Initialize the Hang Up Percents list and set the selection.
  266. //
  267. iSel = -1;
  268. for (pdwPercent = aHangUpPercents, i = 0;
  269. *pdwPercent != 0xFFFFFFFF;
  270. ++pdwPercent, ++i)
  271. {
  272. TCHAR achPercent[ 12 ];
  273. wsprintf( achPercent, TEXT("%d%%"), *pdwPercent );
  274. ComboBox_AddItem( pInfo->hwndLbHangUpPercents, achPercent,
  275. (VOID* )UlongToPtr(*pdwPercent));
  276. if (iSel < 0 && pEntry->dwHangUpPercent <= *pdwPercent)
  277. {
  278. iSel = i;
  279. ComboBox_SetCurSel( pInfo->hwndLbHangUpPercents, iSel );
  280. }
  281. }
  282. if (iSel < 0)
  283. {
  284. ComboBox_SetCurSel( pInfo->hwndLbHangUpPercents, i - 1 );
  285. }
  286. // Initialize the Dial times list.
  287. //
  288. iSel = -1;
  289. for (pItem = aTimes, i = 0;
  290. pItem->sidItem;
  291. ++pItem, ++i )
  292. {
  293. ComboBox_AddItemFromId( g_hinstDll, pInfo->hwndLbDialTimes,
  294. pItem->sidItem, (VOID* )UlongToPtr(pItem->dwData));
  295. if (iSel < 0 && pEntry->dwDialSeconds <= pItem->dwData)
  296. {
  297. iSel = i;
  298. ComboBox_SetCurSel( pInfo->hwndLbDialTimes, iSel );
  299. }
  300. }
  301. if (iSel < 0)
  302. {
  303. ComboBox_SetCurSel( pInfo->hwndLbDialTimes, i - 1 );
  304. }
  305. // Initialize the Hang Up times list.
  306. //
  307. iSel = -1;
  308. for (pItem = aTimes, i = 0;
  309. pItem->sidItem;
  310. ++pItem, ++i )
  311. {
  312. ComboBox_AddItemFromId( g_hinstDll, pInfo->hwndLbHangUpTimes,
  313. pItem->sidItem, (VOID* )UlongToPtr(pItem->dwData));
  314. if (iSel < 0 && pEntry->dwHangUpSeconds <= pItem->dwData)
  315. {
  316. iSel = i;
  317. ComboBox_SetCurSel( pInfo->hwndLbHangUpTimes, iSel );
  318. }
  319. }
  320. if (iSel < 0)
  321. {
  322. ComboBox_SetCurSel( pInfo->hwndLbDialTimes, i - 1 );
  323. }
  324. }
  325. // Center dialog on the owner window.
  326. //
  327. CenterWindow( hwndDlg, GetParent( hwndDlg ) );
  328. // Add context help button to title bar. Dlgedit.exe doesn't currently
  329. // support this at resource edit time. When that's fixed set
  330. // DS_CONTEXTHELP there and remove this call.
  331. //
  332. AddContextHelpButton( hwndDlg );
  333. return TRUE;
  334. }
  335. VOID
  336. DmSave(
  337. IN DMINFO* pInfo )
  338. // Save the current dialog state in the stub API entry buffer. 'PInfo' is
  339. // the dialog context.
  340. //
  341. {
  342. INT iSel;
  343. TRACE( "DmSave" );
  344. iSel = ComboBox_GetCurSel( pInfo->hwndLbDialPercents );
  345. ASSERT( iSel >= 0 );
  346. pInfo->pEntry->dwDialPercent =
  347. PtrToUlong( ComboBox_GetItemDataPtr( pInfo->hwndLbDialPercents, iSel ) );
  348. iSel = ComboBox_GetCurSel( pInfo->hwndLbDialTimes );
  349. ASSERT( iSel >= 0 );
  350. pInfo->pEntry->dwDialSeconds =
  351. PtrToUlong( ComboBox_GetItemDataPtr( pInfo->hwndLbDialTimes, iSel ) );
  352. iSel = ComboBox_GetCurSel( pInfo->hwndLbHangUpPercents );
  353. ASSERT( iSel >= 0 );
  354. pInfo->pEntry->dwHangUpPercent =
  355. PtrToUlong( ComboBox_GetItemDataPtr( pInfo->hwndLbHangUpPercents, iSel ) );
  356. iSel = ComboBox_GetCurSel( pInfo->hwndLbHangUpTimes );
  357. ASSERT( iSel >= 0 );
  358. pInfo->pEntry->dwHangUpSeconds =
  359. PtrToUlong( ComboBox_GetItemDataPtr( pInfo->hwndLbHangUpTimes, iSel ) );
  360. pInfo->pEntry->fDirty = TRUE;
  361. }
  362. VOID
  363. DmTerm(
  364. IN HWND hwndDlg )
  365. /* Dialog termination. Releases the context block. 'HwndDlg' is the
  366. ** handle of a dialog.
  367. */
  368. {
  369. DMINFO* pInfo;
  370. TRACE( "DmTerm" );
  371. pInfo = (DMINFO* )GetWindowLongPtr( hwndDlg, DWLP_USER );
  372. if (pInfo)
  373. {
  374. Free( pInfo );
  375. TRACE( "Context freed" );
  376. }
  377. }