mlink.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 32k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //****************************************************************************
  2. //
  3. //  Module:     RNAUI.DLL
  4. //  File:       connent.c
  5. //  Content:    This file contain all the functions that handle the connection
  6. //              entry dialog boxes.
  7. //  History:
  8. //      Wed 17-Mar-1993 07:45:27  -by-  Viroon  Touranachun [viroont]
  9. //
  10. //  Copyright (c) Microsoft Corporation 1991-1994
  11. //
  12. //****************************************************************************
  13. #include "rnaui.h"
  14. #include "connent.h"
  15. #include "mlink.h"
  16. #include "rnahelp.h"
  17. extern char g_szProfile[];
  18. #ifdef MULTILINK_ENABLED
  19. //****************************************************************************
  20. // BOOL CALLBACK _export MLDlgProc (HWND, UINT, WPARAM, LPARAM)
  21. //
  22. // This function displays the modal connection entry setting dialog box.
  23. //
  24. // History:
  25. //  Wed 17-Mar-1993 07:52:16  -by-  Viroon  Touranachun [viroont]
  26. // Created.
  27. //****************************************************************************
  28. BOOL    CALLBACK _export MLDlgProc (HWND    hWnd,
  29.                                     UINT    message,
  30.                                     WPARAM  wParam,
  31.                                     LPARAM  lParam)
  32. {
  33.   PCONNENTDLG pConnEntDlg;
  34.   switch (message)
  35.   {
  36.     case WM_INITDIALOG:
  37.       // Remember the pointer to the Connection Entry structure
  38. #ifdef MULTILINK_PROP_PAGE
  39.       pConnEntDlg = (PCONNENTDLG)(((LPPROPSHEETPAGE)lParam)->lParam);
  40.       SetWindowLong(hWnd, DWL_USER, (LONG)pConnEntDlg);
  41. #else
  42.       pConnEntDlg   = (LPCONNENTDLG)lParam;
  43.       SetWindowLong(hWnd, DWL_USER, (LONG)(LPCONNENTDLG)pConnEntDlg);
  44. #endif
  45.       // Initialize the appearance of the dialog box
  46.       return (InitMLDlg(hWnd));
  47.     case WM_DESTROY:
  48.       DeInitMLDlg(hWnd);
  49.       break;
  50.     case WM_NOTIFY:
  51.     {
  52.       NMHDR FAR *lpnm;
  53.       lpnm = (NMHDR FAR *)lParam;
  54.       switch(lpnm->code)
  55.       {
  56. #ifdef MULTILINK_PROP_PAGE
  57.         case PSN_KILLACTIVE:
  58.           //
  59.           // Validate the connection information
  60.           //
  61.           SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)IsInvalidMLEntry(hWnd));
  62.           return TRUE;
  63.         case PSN_APPLY:
  64.             //
  65.             // The property sheet information is permanently applied
  66.             //
  67.             pConnEntDlg = (PCONNENTDLG)GetWindowLong(hWnd, DWL_USER);
  68.             //
  69.             // Update the multilink info
  70.             //
  71.             TRACE_MSG(TF_ALWAYS, "Getting updated multilink settings");
  72.             GetMLSetting(hWnd);
  73.             //
  74.             // Save the multilink info
  75.             //
  76.             TRACE_MSG(TF_ALWAYS, "Saving updated multilink settings");
  77.             SaveSubConnList(pConnEntDlg);
  78.             return FALSE;
  79. #endif
  80.         case LVN_ITEMCHANGED:
  81.         {
  82.           NM_LISTVIEW *lpnmLV = (NM_LISTVIEW *)lpnm;
  83.           if ((lpnmLV->uChanged & LVIF_STATE) &&
  84.               (lpnmLV->uNewState & LVIS_SELECTED))
  85.           {
  86.             HWND    hLV;
  87.             char    szIndex[MAXNAME+1];
  88.             hLV = GetDlgItem(hWnd, IDC_ML_LIST);
  89.             ListView_GetItemText(hLV, lpnmLV->iItem, 0, szIndex,
  90.                                  sizeof(szIndex));
  91.             SetWindowText(GetDlgItem(hWnd, IDC_ML_SEL), szIndex);
  92.           };
  93.           break;
  94.         };
  95.         case NM_DBLCLK:
  96.         {
  97.           if (lpnm->idFrom == IDC_ML_LIST)
  98.           {
  99.             PostMessage(hWnd, WM_COMMAND, IDC_ML_EDIT,
  100.                         (LPARAM)GetDlgItem(hWnd, IDC_ML_EDIT));
  101.           };
  102.           break;
  103.         };
  104.         default:
  105.           break;
  106.       };
  107.       break;
  108.     }
  109.     case WM_COMMAND:
  110.     {
  111.       // Determine the end-user action
  112.       switch (GET_WM_COMMAND_ID(wParam, lParam))
  113.       {
  114.         case IDC_ML_ENABLE:
  115.         case IDC_ML_DISABLE:
  116.           AdjustMLControls(hWnd);
  117.           break;
  118.         case IDC_ML_ADD:
  119.           AddMLItem(hWnd);
  120.           break;
  121.         case IDC_ML_EDIT:
  122.           EditMLItem(hWnd, GET_WM_COMMAND_ID(wParam, lParam));
  123.           break;
  124.         case IDC_ML_DEL:
  125.           RemoveMLItem(hWnd, GET_WM_COMMAND_ID(wParam, lParam));
  126.           break;
  127.         case IDOK:
  128.           //
  129.           // Validate the connection information
  130.           //
  131.           if (IsInvalidMLEntry(hWnd))
  132.           {
  133.             return TRUE;
  134.           };
  135.           //
  136.           // The property sheet information is permanently applied
  137.           //
  138.           GetMLSetting(hWnd);
  139.         case IDCANCEL:
  140.           EndDialog( hWnd, GET_WM_COMMAND_ID(wParam, lParam));
  141.           break;
  142.         default:
  143.           break;
  144.       };
  145.       break;
  146.     }
  147.     case WM_HELP:
  148.     case WM_CONTEXTMENU:
  149.       ContextHelp(gaSubEntry, message, wParam, lParam);
  150.       break;
  151.     default:
  152.       break;
  153.   }
  154.   return FALSE;
  155. }
  156. //****************************************************************************
  157. // BOOL NEAR PASCAL InitMLDlg (HWND hWnd)
  158. //
  159. // This function initializes the controls on the multilink page.
  160. //
  161. // History:
  162. //  Fri 09-Feb-1996 08:06:06  -by-  Viroon  Touranachun [viroont]
  163. // Created.
  164. //****************************************************************************
  165. BOOL NEAR PASCAL InitMLDlg (HWND hWnd)
  166. {
  167.   PCONNENTDLG  pConnEntDlg;
  168.   LPSTR        szEntryName;
  169.   PMLINFO      pmli;
  170.   // Get the phonebook entry name
  171.   //
  172.   pConnEntDlg = (PCONNENTDLG)GetWindowLong(hWnd, DWL_USER);
  173.   szEntryName = pConnEntDlg->pConnEntry->pszEntry;
  174.   pmli = pConnEntDlg->pmli;
  175.   // Enable/disable multilink
  176.   //
  177.   CheckDlgButton(hWnd, pmli->fEnabled ? IDC_ML_ENABLE : IDC_ML_DISABLE, TRUE);
  178.   // Initialize the device list
  179.   //
  180.   InitMLList(hWnd, szEntryName, pmli);
  181.   // Adjust the dialog appearance
  182.   //
  183.   AdjustMLControls(hWnd);
  184.   return TRUE;
  185. }
  186. //****************************************************************************
  187. // void NEAR PASCAL DeinitMLDlg (HWND hWnd)
  188. //
  189. // This function deinitializes the controls on the multilink page.
  190. //
  191. // History:
  192. //  Fri 09-Feb-1996 08:06:06  -by-  Viroon  Touranachun [viroont]
  193. // Created.
  194. //****************************************************************************
  195. void NEAR PASCAL DeInitMLDlg (HWND hWnd)
  196. {
  197.   // Free resources allocated for the multilink list
  198.   //
  199.   DeinitMLList(hWnd);
  200.   return;
  201. }
  202. //****************************************************************************
  203. // BOOL NEAR PASCAL IsInvalidMLEntry(HWND hWnd)
  204. //
  205. // This function validates the information on the multilink page.
  206. //
  207. // History:
  208. //  Fri 09-Feb-1996 08:06:06  -by-  Viroon  Touranachun [viroont]
  209. // Created.
  210. //****************************************************************************
  211. BOOL NEAR PASCAL IsInvalidMLEntry(HWND hWnd)
  212. {
  213.   return FALSE;
  214. }
  215. //****************************************************************************
  216. // void NEAR PASCAL InitMLList (HWND hDlg, LPSTR szEntryName, PMLINFO pmli)
  217. //
  218. // This function initializes the multilink list.
  219. //
  220. // History:
  221. //  Mon 12-Feb-1996 08:33:20  -by-  Viroon  Touranachun [viroont]
  222. // Created.
  223. //****************************************************************************
  224. void NEAR PASCAL InitMLList (HWND hDlg, LPSTR szEntryName, PMLINFO pmli)
  225. {
  226.   HWND         hwnd, hwndFrame;
  227.   UINT         id;
  228.   char         szText[MAXNAME+1];
  229.   // Check whether we have the control
  230.   //
  231.   hwndFrame = GetDlgItem(hDlg, IDC_ML_FRAME);
  232.   if ((hwnd = GetDlgItem(hDlg, IDC_ML_LIST)) == NULL)
  233.   {
  234.     RECT         rectFrame;
  235.     POINT        ptOrgFrame;
  236.     SIZE         sizeFrame;
  237.     LV_COLUMN    col;
  238.     // Create the listview control for the multilink list
  239.     //
  240.     GetWindowRect(hwndFrame, &rectFrame);
  241.     sizeFrame.cx = rectFrame.right - rectFrame.left;
  242.     sizeFrame.cy = rectFrame.bottom - rectFrame.top;
  243.     ptOrgFrame   = *(POINT *)((RECT *)&rectFrame);
  244.     ScreenToClient(hDlg, &ptOrgFrame);
  245.     hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
  246.                   WC_LISTVIEW,
  247.                   NULL,
  248.        WS_CHILD |
  249.                   WS_VISIBLE |
  250.                   WS_TABSTOP |
  251.                   LVS_REPORT |
  252.   //LVS_ALWAYSSEL |
  253.                   LVS_SINGLESEL,
  254.        ptOrgFrame.x, ptOrgFrame.y,
  255.                   sizeFrame.cx, sizeFrame.cy,
  256.                   hDlg,
  257.                   (HMENU)(IDC_ML_LIST),
  258.                   ghInstance,
  259.                   NULL);
  260.     SetWindowPos(hwnd, GetDlgItem(hDlg, IDC_ML_SEL_TXT), 0, 0, 0, 0,
  261.                  SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  262.     // Add the header to the list
  263.     //
  264.     col.mask        = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  265.     col.fmt         = LVCFMT_LEFT;
  266.     col.pszText     = szText;
  267.     col.cchTextMax  = 0;
  268.     for ( id = 0; id < MAX_USER_COLS; id++ )
  269.     {
  270.         //
  271.         // Add a virtual column that will be joined to the first column
  272.         // to make it appear slightly larger than the others
  273.         //
  274.         col.cx          = (id?1:2) * (sizeFrame.cx/(MAX_USER_COLS+1)) - 1;
  275.         //  
  276.         // Set the column text and its id
  277.         //
  278.         LoadString (ghInstance, id-ML_COL_BASE+IDS_ML_COL_BASE, szText,
  279.                   sizeof(szText));
  280.         col.iSubItem = id - 1;
  281.         ListView_InsertColumn(hwnd, id, &col);
  282.     }
  283.   }
  284.   else
  285.   {
  286.     // Clean up the user list
  287.     //
  288.     DeinitMLList(hDlg);
  289.   };
  290.   // If there is a sub-entry, get the sub-entry
  291.   //
  292.   if (pmli->cSubEntries != 0)
  293.   {
  294.     LV_ITEM      item;
  295.     int          iItem;
  296.     BOOL         fSelected;
  297.     DWORD        iSubEntry, iIndex;
  298.     char         szDeviceName[MAXNAME+1];
  299.     PSUBCONNENTRY psce, psceNew;
  300.     // Prepare the name item
  301.     //
  302.     item.mask     = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
  303.     item.iItem    = 32000;
  304.     item.iSubItem = 0;
  305.     item.state    = 0;
  306.     item.pszText  = szDeviceName;
  307.     fSelected = FALSE;
  308.     // Initialize each multilink info
  309.     //
  310.     psce = (PSUBCONNENTRY)(pmli+1);
  311.     for (iSubEntry = 0, iIndex = 1; iSubEntry < pmli->cSubEntries; iSubEntry++)
  312.     {
  313.       // Allocate the multilink data
  314.       //
  315.       if ((psceNew = (PSUBCONNENTRY)LocalAlloc(LMEM_FIXED, sizeof(*psce)))
  316.           != NULL)
  317.       {
  318.         // Record the information
  319.         //
  320.         *psceNew = *psce;
  321.         // Add this multilink into the list
  322.         //
  323.         lstrcpyn (szDeviceName, psceNew->szDeviceName, MAXNAME);
  324.         
  325.         item.lParam  = (LPARAM)psceNew;
  326.         iItem   = ListView_InsertItem(hwnd, &item);
  327.         ListView_SetItemText(hwnd, iItem, ML_COL_PHONE,  psceNew->szLocal);
  328.         iIndex++;
  329.         // Promote as the selected user
  330.         //
  331.         if (!fSelected)
  332.         {
  333.           SetWindowText(GetDlgItem(hDlg, IDC_ML_SEL), item.pszText);
  334.           fSelected = TRUE;
  335.         }
  336.       }
  337.       psce++;
  338.     };
  339.   };
  340.   return;
  341. }
  342. //****************************************************************************
  343. // void NEAR PASCAL DeinitMLList (HWND hDlg)
  344. //
  345. // This function deinitializes the multilink list.
  346. //
  347. // History:
  348. //  Mon 12-Feb-1996 09:05:30  -by-  Viroon  Touranachun [viroont]
  349. // Created.
  350. //****************************************************************************
  351. void NEAR PASCAL DeinitMLList (HWND hDlg)
  352. {
  353.   HWND      hwnd;
  354.   LV_ITEM   item;
  355.   DWORD     i, cEntries;
  356.   if ((hwnd = GetDlgItem(hDlg, IDC_ML_LIST)) != NULL)
  357.   {
  358.     // Remove the data
  359.     //
  360.     cEntries = ListView_GetItemCount(hwnd);
  361.     item.mask       = LVIF_PARAM;
  362.     item.iSubItem   = 0;
  363.     item.cchTextMax = 0;
  364.     for (i = 0; i < cEntries; i++)
  365.     {
  366.       item.iItem   = i;
  367.       ListView_GetItem(hwnd, &item);
  368.       LocalFree((HLOCAL)item.lParam);
  369.     };
  370.     // Clean up the user list
  371.     //
  372.     ListView_DeleteAllItems(hwnd);
  373.   };
  374.   return;
  375. }
  376. //****************************************************************************
  377. // DWORD NEAR PASCAL GetMLSetting (HWND hWnd)
  378. //
  379. // This function gets the information on the multilink page.
  380. //
  381. // History:
  382. //  Fri 09-Feb-1996 08:06:06  -by-  Viroon  Touranachun [viroont]
  383. // Created.
  384. //****************************************************************************
  385. DWORD NEAR PASCAL GetMLSetting (HWND hWnd)
  386. {
  387.   PCONNENTDLG   pConnEntDlg;
  388.   LPSTR         szEntryName;
  389.   PMLINFO       pmli;
  390.   PSUBCONNENTRY psce, psceNew;
  391.   DWORD         iSubEntry;
  392.   HWND          hLV;
  393.   UINT          cSubEntries;
  394.   LV_ITEM       item;
  395.   // Get the phonebook entry
  396.   //
  397.   pConnEntDlg = (PCONNENTDLG)GetWindowLong(hWnd, DWL_USER);
  398.   szEntryName = pConnEntDlg->pConnEntry->pszEntry;
  399.   // Get the multilink list control
  400.   //
  401.   hLV = GetDlgItem(hWnd, IDC_ML_LIST);
  402.   // Get the item count
  403.   //
  404.   cSubEntries = ListView_GetItemCount(hLV);
  405.   // Allocate the buffer for the multilink info
  406.   //
  407.   if ((pmli = (PMLINFO)LocalAlloc(LPTR, sizeof(MLINFO)+
  408.                                         (cSubEntries*sizeof(SUBCONNENTRY))))
  409.       != NULL)
  410.   {
  411.     psce = (PSUBCONNENTRY)(pmli+1);
  412.     // Enable/disable the multilink and clear the old information
  413.     //
  414.     pmli->fEnabled    = IsDlgButtonChecked(hWnd, IDC_ML_ENABLE);
  415.     pmli->cSubEntries = cSubEntries;
  416.     // Save one item at a time
  417.     //
  418.     item.mask       = LVIF_PARAM;
  419.     item.iSubItem   = 0;
  420.     item.cchTextMax = 0;
  421.     item.pszText    = NULL;
  422.     for (iSubEntry = 0; iSubEntry < cSubEntries; iSubEntry++)
  423.     {
  424.       // Get the multilink info
  425.       //
  426.       item.iItem   = iSubEntry;
  427.       ListView_GetItem(hLV, &item);
  428.       // Save it
  429.       //
  430.       psceNew = (PSUBCONNENTRY)item.lParam;
  431.       *psce   = *psceNew;
  432.       psce++;
  433.     };
  434.     // Replace the old info with the new one;
  435.     //
  436.     LocalFree (pConnEntDlg->pmli);
  437.     pConnEntDlg->pmli = pmli;
  438.   };
  439.   return ERROR_SUCCESS;
  440. }
  441. //****************************************************************************
  442. // void NEAR PASCAL AdjustMLControls(HWND hWnd)
  443. //
  444. // This function adjusts the controls on the multilink page.
  445. //
  446. // History:
  447. //  Fri 09-Feb-1996 08:06:06  -by-  Viroon  Touranachun [viroont]
  448. // Created.
  449. //****************************************************************************
  450. void NEAR PASCAL AdjustMLControls(HWND hDlg)
  451. {
  452.   PCONNENTDLG   pConnEntDlg;
  453.   HWND  hLV;
  454.   BOOL  fUserCtrl, fEnabled;
  455.   DWORD cEntries;
  456.   pConnEntDlg = (PCONNENTDLG)GetWindowLong(hDlg, DWL_USER);
  457.   // Is multilink enabled?
  458.   //
  459.   fEnabled = IsDlgButtonChecked(hDlg, IDC_ML_ENABLE);
  460.   // Adjust the multilink list
  461.   //
  462.   hLV    = GetDlgItem(hDlg, IDC_ML_LIST);
  463.   cEntries = ListView_GetItemCount(hLV);
  464.   ShowWindow(hLV, fEnabled ? SW_SHOW : SW_HIDE);
  465.   ShowWindow(GetDlgItem(hDlg, IDC_ML_FRAME),
  466.              fEnabled ? SW_HIDE : SW_SHOW);
  467.   EnableWindow(GetDlgItem(hDlg, IDC_ML_SEL), fEnabled);
  468.   EnableWindow(GetDlgItem(hDlg, IDC_ML_ADD),
  469.                (fEnabled & (cEntries < pConnEntDlg->cmlChannel) ? TRUE : FALSE));
  470.   // Selction dependent controls
  471.   //
  472.   fUserCtrl = (fEnabled && (cEntries != 0));
  473.   EnableWindow(GetDlgItem(hDlg, IDC_ML_DEL), fUserCtrl);
  474.   EnableWindow(GetDlgItem(hDlg, IDC_ML_EDIT), fUserCtrl);
  475.   EnableWindow(GetDlgItem(hDlg, IDC_ML_SEL_TXT), fUserCtrl);
  476.   if (fUserCtrl)
  477.   {
  478.     char    szDeviceName[MAXNAME+1];
  479.     LV_FINDINFO lvfi;
  480.     int     iItem;
  481.     // Hilite the selected multilink
  482.     //
  483.     GetDlgItemText(hDlg, IDC_ML_SEL, szDeviceName, sizeof(szDeviceName));
  484.     lvfi.flags = LVFI_STRING;
  485.     lvfi.psz   = szDeviceName;
  486.     iItem = ListView_FindItem(hLV, 0, &lvfi);
  487.     ListView_EnsureVisible(hLV, iItem, FALSE);
  488.     ListView_SetItemState(hLV, iItem, LVIS_FOCUSED | LVIS_SELECTED,
  489.                           LVIS_FOCUSED | LVIS_SELECTED);
  490.   };
  491.   return;
  492. }
  493. //****************************************************************************
  494. // DWORD NEAR PASCAL AddMLItem (HWND)
  495. //
  496. // This function adds a new multilink item to the list.
  497. //
  498. // History:
  499. //  Mon 12-Feb-1996 09:52:50  -by-  Viroon  Touranachun [viroont]
  500. // Created.
  501. //****************************************************************************
  502. DWORD NEAR PASCAL AddMLItem (HWND hDlg)
  503. {
  504.   PCONNENTDLG   pConnEntDlg;
  505.   PDEVICEINFO   pdi;
  506.   HWND          hLV;
  507.   LV_ITEM       item;
  508.   int           iItem;
  509.   char          szDeviceName[MAXNAME+1], szTmp[MAXNAME+1];
  510.   PSUBCONNENTRY psce;
  511.   pConnEntDlg = (PCONNENTDLG)GetWindowLong(hDlg, DWL_USER);
  512.   pdi = &pConnEntDlg->pConnEntry->pDevConfig->di;
  513.   // Allocate a multilink record
  514.   //
  515.   if ((psce = (PSUBCONNENTRY)LocalAlloc(LPTR, sizeof(*psce))) == NULL)
  516.     return ERROR_OUTOFMEMORY;
  517.   // Initialize a default information
  518.   //
  519.   psce->dwSize = sizeof(*psce);
  520.   lstrcpyn(psce->szDeviceName, pdi->szDeviceName, sizeof(psce->szDeviceName));
  521.   lstrcpyn(psce->szDeviceType, pdi->szDeviceType, sizeof(psce->szDeviceType));
  522.   lstrcpyn(psce->szLocal, pConnEntDlg->pConnEntry->pn.szLocal,
  523.            sizeof(psce->szLocal));
  524.   // Get the new information
  525.   //
  526.   if (!DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_EDIT_MLI), hDlg,
  527.                       EditMLInfoDlg, (LPARAM)psce))
  528.   {
  529.     LocalFree((HLOCAL)psce);
  530.     return ERROR_CANCELLED;
  531.   };
  532.   // Add the new multilink item
  533.   //
  534.   hLV = GetDlgItem(hDlg, IDC_ML_LIST);
  535.   item.mask     = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
  536.   item.iItem    = 32000;
  537.   item.iSubItem = 0;
  538.   item.state    = 0;
  539.   item.lParam   = (LPARAM)psce;
  540.   item.pszText  = szDeviceName;
  541.   lstrcpyn (szDeviceName, psce->szDeviceName, MAXNAME);
  542.   iItem         = ListView_InsertItem(hLV, &item);
  543.   // Display the information
  544.   //
  545.   ListView_SetItemText(hLV, iItem, ML_COL_PHONE,  psce->szLocal);
  546.   // May need to set a default user
  547.   //
  548.   if (GetDlgItemText(hDlg, IDC_ML_SEL, szTmp, sizeof(szTmp)) == 0)
  549.   {
  550.     SetDlgItemText(hDlg, IDC_ML_SEL, szDeviceName);
  551.   }
  552.   // Adjust the dialog appearance
  553.   //
  554.   AdjustMLControls(hDlg);
  555.   if (!IsWindowEnabled(GetDlgItem(hDlg, IDC_ML_ADD)))
  556.   {
  557.     SetFocus(GetDlgItem(hDlg, IDC_ML_DEL));
  558.   };
  559.   return ERROR_SUCCESS;
  560. }
  561. //****************************************************************************
  562. // BOOL NEAR PASCAL RemoveMLItem (HWND, UINT)
  563. //
  564. // This function removes a multilink sub connection.
  565. //
  566. // History:
  567. //  Created
  568. //          25-Jul-1996           -by-  Bruce Johnson (bjohnson)
  569. //****************************************************************************
  570. BOOL NEAR PASCAL RemoveMLItem (HWND hDlg, UINT id)
  571. {
  572.     HWND        hLV;
  573.     char        szDeviceName[MAXNAME+1];
  574.     int         iSelect, iLast;
  575.     LV_FINDINFO lvfi;
  576.     LV_ITEM     item;
  577.     BOOL        bUpdated;
  578.     LPSTR       pszSelected;
  579.     // Get the selected line
  580.     //
  581.     GetDlgItemText(hDlg, IDC_ML_SEL, szDeviceName, sizeof(szDeviceName));
  582.     // Get the selected multilink info
  583.     //
  584.     hLV = GetDlgItem(hDlg, IDC_ML_LIST);
  585.     lvfi.flags = LVFI_STRING;
  586.     lvfi.psz   = szDeviceName;
  587.     iSelect = ListView_FindItem(hLV, -1, &lvfi);
  588.     //
  589.     // If the selected item was not found, just return.
  590.     //
  591.     if (iSelect == -1) {
  592.         return FALSE;
  593.     }            
  594.     bUpdated = TRUE;
  595.     // Remove the selected line
  596.     //
  597.     item.mask       = LVIF_PARAM;
  598.     item.iSubItem   = 0;
  599.     item.cchTextMax = 0;
  600.     item.iItem      = iSelect;
  601.     ListView_GetItem(hLV, &item);
  602.     LocalFree((HLOCAL)item.lParam);
  603.     ListView_DeleteItem(hLV, iSelect);
  604.     //
  605.     // Determine the number of lines left in the list
  606.     //
  607.     if ((iLast = ListView_GetItemCount(hLV)) > 0)
  608.     {
  609.       //  
  610.       // Select the first line as the default line
  611.       //
  612.       ListView_GetItemText(hLV, 0, 0, szDeviceName, sizeof(szDeviceName));
  613.       pszSelected = szDeviceName;
  614.       AdjustMLControls(hDlg);
  615.     }
  616.     else
  617.     {
  618.       // No user left in the list, adjust some controls
  619.       //
  620.       AdjustMLControls(hDlg);
  621.       SetFocus(GetDlgItem(hDlg, IDC_ML_ADD));
  622.       pszSelected = (LPSTR)c_szNull;
  623.     }
  624.     SetDlgItemText(hDlg, IDC_ML_SEL, pszSelected);
  625.   return bUpdated;
  626. }
  627. //****************************************************************************
  628. // BOOL NEAR PASCAL EditMLItem (HWND, UINT)
  629. //
  630. // This function modifies the multilink info.
  631. //
  632. // History:
  633. //  Created.
  634. //  Mon 12-Feb-1996 09:27:03  -by-  Viroon  Touranachun [viroont]
  635. //  Updated
  636. //      25-Jul-1996               -by-  Bruce Johnson (bjohnson)
  637. //****************************************************************************
  638. BOOL NEAR PASCAL EditMLItem (HWND hDlg, UINT id)
  639. {
  640.   HWND        hLV;
  641.   char        szDeviceName[MAXNAME+1];
  642.   int         iSelect;
  643.   LV_FINDINFO lvfi;
  644.   LV_ITEM     item;
  645.   BOOL        bUpdated;
  646.   // Get the selected line
  647.   //
  648.   GetDlgItemText(hDlg, IDC_ML_SEL, szDeviceName, sizeof(szDeviceName));
  649.   // Get the selected multilink info
  650.   //
  651.   hLV = GetDlgItem(hDlg, IDC_ML_LIST);
  652.   lvfi.flags = LVFI_STRING;
  653.   lvfi.psz   = szDeviceName;
  654.   iSelect = ListView_FindItem(hLV, -1, &lvfi);
  655.   //
  656.   // If the selected item was not found, just return.
  657.   //
  658.   if (iSelect == -1) {
  659.       return FALSE;
  660.   }            
  661.   // Modify the user access
  662.   //
  663.   item.iItem    = iSelect;
  664.   item.iSubItem = 0;
  665.   item.mask     = LVIF_PARAM;
  666.   ListView_GetItem(hLV, &item);
  667.   // Show the edit dialog
  668.   //
  669.   bUpdated  = DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_EDIT_MLI), hDlg,
  670.                              EditMLInfoDlg, item.lParam);
  671.   // Update the multilink information
  672.   //
  673.   if (bUpdated)
  674.   {
  675.     PSUBCONNENTRY psce;
  676.     psce          = (PSUBCONNENTRY)item.lParam;
  677.     item.mask     = LVIF_TEXT;
  678.     // Update the device name
  679.     //
  680.     item.pszText  = psce->szDeviceName;
  681.     ListView_SetItem(hLV, &item);
  682.     // Update the selected device name
  683.     //
  684.     SetDlgItemText(hDlg, IDC_ML_SEL, psce->szDeviceName);
  685.     // Update the phone number
  686.     //
  687.     item.iSubItem = ML_COL_PHONE;
  688.     item.pszText  = psce->szLocal;
  689.     ListView_SetItem(hLV, &item);
  690.   };
  691.   return bUpdated;
  692. }
  693. //************************************************************************
  694. // BOOL CALLBACK _export EditMLInfoDlg (HWND, UINT, WPARAM, LPARAM)
  695. //
  696. // This function displays the multilink info dialog box.
  697. //
  698. // History:
  699. //   Mon 12-Feb-1996 12:33:27  -by-  Viroon  Touranachun [viroont]
  700. //************************************************************************
  701. BOOL CALLBACK _export EditMLInfoDlg(HWND hDlg, UINT message, WPARAM wParam,
  702.                                     LPARAM lParam)
  703. {
  704.   switch(message)
  705.   {
  706.     case WM_INITDIALOG:
  707.       //
  708.       // Init the dialog appearance
  709.       //
  710.       SetWindowLong(hDlg, DWL_USER, (LONG) lParam);
  711.       // Initialize default information and controls
  712.       //
  713.       return (InitEditML(hDlg));
  714.     case WM_DESTROY:
  715.       //
  716.       // Deinitialize dialog box
  717.       //
  718.       DeinitEditML(hDlg);
  719.       break;
  720.     case WM_COMMAND:
  721.       //
  722.       // Respond to the dialog termination
  723.       //
  724.       switch(GET_WM_COMMAND_ID(wParam, lParam))
  725.       {
  726.         case IDC_ML_DEVICE:
  727.           //
  728.           // Adjust the dialog appearance
  729.           //
  730.           if (GET_WM_COMMAND_CMD(wParam, lParam)==CBN_SELCHANGE)
  731.           {
  732.             AdjustMLDeviceList(hDlg);
  733.           };
  734.           return TRUE;
  735.         case IDOK:
  736.           //
  737.           // Save the current information
  738.           //
  739.           if (SaveEditMLInfo(hDlg) != ERROR_SUCCESS)
  740.             break;
  741.         //*****************************************************************
  742.         // Fall through !!! Fall through !!! Fall through !!!
  743.         //*****************************************************************
  744.         //
  745.         case IDCANCEL:
  746.           EndDialog( hDlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
  747.           break;
  748.       }
  749.       break;
  750.     case WM_RASDIALEVENT:
  751.     {
  752.       switch (lParam)
  753.       {
  754.         case RNA_ADD_DEVICE:
  755.         case RNA_DEL_DEVICE:
  756.           ModifyMLDeviceList(hDlg, lParam);
  757.           break;
  758.         case RNA_SHUTDOWN:
  759.           EndDialog( hDlg, FALSE );
  760.           break;
  761.       }
  762.       break;
  763.     }
  764.     case WM_HELP:
  765.     case WM_CONTEXTMENU:
  766.       ContextHelp(gaEditSub, message, wParam, lParam);
  767.       break;
  768.     default:
  769.       break;
  770.   }
  771.   return FALSE;
  772. }
  773. //****************************************************************************
  774. // BOOL NEAR PASCAL InitEditML (HWND hDlg)
  775. //
  776. // This function initializes the multilink info editor.
  777. //
  778. // History:
  779. //  Mon 12-Feb-1996 09:27:03  -by-  Viroon  Touranachun [viroont]
  780. // Created.
  781. //****************************************************************************
  782. BOOL NEAR PASCAL InitEditML (HWND hDlg)
  783. {
  784.   PSUBCONNENTRY psce;
  785.   HWND          hCtrl;
  786.   int           nIndex;
  787.   // Get multilink info
  788.   //
  789.   psce = (PSUBCONNENTRY)GetWindowLong(hDlg, DWL_USER);
  790.   // Fill-up the device list
  791.   //
  792.   hCtrl = GetDlgItem(hDlg, IDC_ML_DEVICE);
  793.   InitDeviceList(hCtrl);
  794.   // Try to find the selected device
  795.   //
  796.   if ((nIndex = ComboBox_FindStringExact(hCtrl, -1,
  797.                 psce->szDeviceName)) == CB_ERR)
  798.   {
  799.     // We have a device that is not installed, add to the list
  800.     //
  801.     nIndex = ComboBox_AddString(hCtrl, psce->szDeviceName);
  802.   };
  803.   // Select a default device
  804.   //
  805.   ComboBox_SetCurSel(hCtrl, nIndex);
  806.   ComboBox_SetItemData(hCtrl, nIndex, (DWORD)psce->szDeviceType);
  807.   // Initialize the phone number
  808.   //
  809.   hCtrl = GetDlgItem(hDlg, IDC_ML_PHONE);
  810.   Edit_LimitText(hCtrl, sizeof(psce->szLocal)-1);
  811.   Edit_SetText(hCtrl, psce->szLocal);
  812.   // Register device change notification
  813.   //
  814.   RnaEngineRequest(RA_REG_DEVCHG, (DWORD)hDlg);
  815.   return TRUE;
  816. }
  817. //****************************************************************************
  818. // void NEAR PASCAL DeinitEditML (HWND hDlg)
  819. //
  820. // This function deinitializes the multilink info editor.
  821. //
  822. // History:
  823. //  Mon 12-Feb-1996 09:27:03  -by-  Viroon  Touranachun [viroont]
  824. // Created.
  825. //****************************************************************************
  826. void NEAR PASCAL DeinitEditML(HWND hDlg)
  827. {
  828.   // Register device change notification
  829.   //
  830.   RnaEngineRequest(RA_DEREG_DEVCHG, (DWORD)hDlg);
  831.   return;
  832. }
  833. //****************************************************************************
  834. // void NEAR PASCAL AdjustMLDeviceList(HWND hDlg)
  835. //
  836. // This function adjusts the appearance of the device list in the ML editor.
  837. //
  838. // History:
  839. //  Mon 12-Feb-1996 09:27:03  -by-  Viroon  Touranachun [viroont]
  840. // Created.
  841. //****************************************************************************
  842. void NEAR PASCAL AdjustMLDeviceList(HWND hDlg)
  843. {
  844.   HWND          hCtrl;
  845.   int           iSelect;
  846.   hCtrl = GetDlgItem(hDlg, IDC_ML_DEVICE);
  847.   iSelect = ComboBox_GetCurSel(hCtrl);
  848.   // If we do not know the device type yet, get the device type
  849.   //
  850.   if ((LPSTR)ComboBox_GetItemData(hCtrl, iSelect) == NULL)
  851.   {
  852.     DEVICEINFO di;
  853.     LPCSTR     pszDeviceType;
  854.     // Get the device information
  855.     //
  856.     di.dwVersion = sizeof(di);
  857.     ComboBox_GetText(hCtrl, di.szDeviceName, sizeof(di.szDeviceName));
  858.     RnaGetDeviceInfo(di.szDeviceName, &di);
  859.     // Remember the device type
  860.     //
  861.     if (!lstrcmpi(di.szDeviceType, szISDNDevice))
  862.     {
  863.       pszDeviceType = szISDNDevice;
  864.     }
  865.     else
  866.     {
  867.       if (!lstrcmpi(di.szDeviceType, szModemDevice))
  868.       {
  869.         pszDeviceType = szModemDevice;
  870.       }
  871.       else
  872.       {
  873.         pszDeviceType = szUnknownDevice;
  874.       };
  875.     };
  876.     ComboBox_SetItemData(hCtrl, iSelect, (DWORD)pszDeviceType);
  877.   };
  878.   return;
  879. }
  880. //****************************************************************************
  881. // DWORD NEAR PASCAL SaveEditMLInfo (HWND hDlg)
  882. //
  883. // This function saves the modified multilink information.
  884. //
  885. // History:
  886. //  Mon 12-Feb-1996 09:27:03  -by-  Viroon  Touranachun [viroont]
  887. // Created.
  888. //****************************************************************************
  889. DWORD NEAR PASCAL SaveEditMLInfo (HWND hDlg)
  890. {
  891.   PSUBCONNENTRY psce;
  892.   HWND          hCtrl;
  893.   int           iSelect;
  894.   LPSTR         pszDeviceType;
  895.   PHONENUM      pn;
  896.   // Get multilink info
  897.   //
  898.   psce = (PSUBCONNENTRY)GetWindowLong(hDlg, DWL_USER);
  899.   // Get the phone number
  900.   //
  901.   ZeroMemory(&pn, sizeof(pn));
  902.   Edit_GetText(GetDlgItem(hDlg, IDC_ML_PHONE), pn.szLocal, sizeof(pn.szLocal));
  903.   if (!ValidateEntry(hDlg, (LPBYTE)&pn, IDC_ML_PHONE, IDS_ERR_INVALID_PHONE))
  904.     return ERROR_INVALID_PARAMETER;
  905.   lstrcpyn(psce->szLocal, pn.szLocal, sizeof(psce->szLocal));
  906.   // Get the device information
  907.   //
  908.   hCtrl = GetDlgItem(hDlg, IDC_ML_DEVICE);
  909.   ComboBox_GetText(hCtrl, psce->szDeviceName, sizeof(psce->szDeviceName));
  910.   iSelect = ComboBox_GetCurSel(hCtrl);
  911.   pszDeviceType = (LPSTR)ComboBox_GetItemData(hCtrl, iSelect);
  912.   if (pszDeviceType != psce->szDeviceType)
  913.   {
  914.     lstrcpyn(psce->szDeviceType, pszDeviceType, sizeof(psce->szDeviceType));
  915.   };
  916.   return ERROR_SUCCESS;
  917. }
  918. //****************************************************************************
  919. // void NEAR PASCAL ModifyMLDeviceList (HWND, DWORD)
  920. //
  921. // This function adds or removes a device in the device list.
  922. //
  923. // History:
  924. //  Mon 01-Mar-1993 13:51:30  -by-  Viroon  Touranachun [viroont]
  925. // Created.
  926. //****************************************************************************
  927. void NEAR PASCAL ModifyMLDeviceList (HWND hwnd, DWORD dwCommand)
  928. {
  929.   HWND  hLB;
  930.   DWORD cbSize;
  931.   DWORD cEntries;
  932.   LPSTR pPortList, pNext;
  933.   int   nIndex;
  934.   UINT  i;
  935.   hLB = GetDlgItem(hwnd, IDC_ML_DEVICE);
  936.   // Get the buffer size
  937.   cbSize = 0;
  938.   if (RnaEnumDevices(NULL, &cbSize, &cEntries) != ERROR_BUFFER_TOO_SMALL)
  939.     return;
  940.   // Allocate the buffer for the device list
  941.   if ((pPortList = (LPSTR)LocalAlloc(LMEM_FIXED, (UINT)cbSize)) != NULL)
  942.   {
  943.     // Enumerate the device list
  944.     cEntries = 0;
  945.     if (RnaEnumDevices((LPBYTE)pPortList, &cbSize, &cEntries) == SUCCESS)
  946.     {
  947.       // Determine the requested action
  948.       //
  949.       if (dwCommand == RNA_ADD_DEVICE)
  950.       {
  951.         // For each device in the list
  952.         for (i = 0, pNext = pPortList; i < (UINT)cEntries; i++, pNext += (lstrlen(pNext)+1))
  953.         {
  954.           // Check the device type
  955.           //
  956.           if (!IsValidDevice(pNext))
  957.             continue;
  958.           // Check if it is already in the list
  959.           if ((nIndex = ComboBox_FindStringExact(hLB, 0, pNext)) == CB_ERR)
  960.           {
  961.             // Add the device to the list box
  962.             nIndex = ComboBox_AddString(hLB, pNext);
  963.             ComboBox_SetItemData(hLB, nIndex, NULL);
  964.             // This maybe the only device in the list
  965.             //
  966.             if (ComboBox_GetCount(hLB) == 1)
  967.             {
  968.               ComboBox_SetCurSel(hLB, nIndex);
  969.               AdjustMLDeviceList(hwnd);
  970.             };
  971.             break;
  972.           };
  973.         };
  974.       }
  975.       else
  976.       {
  977.         DWORD i, j, cDevices;
  978.         char  szDeviceName[RAS_MaxDeviceName+1];
  979.         // For each item in the device list
  980.         cDevices = ComboBox_GetCount(hLB);
  981.         for (i = 0; i < cDevices; i++)
  982.         {
  983.           // Get the device name
  984.           //
  985.           ComboBox_GetLBText(hLB, i, szDeviceName);
  986.           // Check whether it is in the current list
  987.           //
  988.           for (j = 0, pNext = pPortList; j < (UINT)cEntries; j++, pNext += (lstrlen(pNext)+1))
  989.           {
  990.             // Check the device type
  991.             //
  992.             if (!IsValidDevice(pNext))
  993.               continue;
  994.             if (!lstrcmpi(pNext, szDeviceName))
  995.               break;
  996.           };
  997.           if (j == cEntries)
  998.           {
  999.             // We remove it only if it was not selected before
  1000.             // A (previously) selected device has a device type associated with it
  1001.             //
  1002.             if ((LPSTR)ComboBox_GetItemData(hLB, i) == NULL)
  1003.             {
  1004.               // Remove it from the list
  1005.               //
  1006.               ComboBox_DeleteString(hLB, i);
  1007.             };
  1008.             break;
  1009.           };
  1010.         };
  1011.       };
  1012.     };
  1013.     // Free the buffer
  1014.     LocalFree((HLOCAL)pPortList);
  1015.   };
  1016.   return;
  1017. }
  1018. #endif // MULTILINK_ENABLED