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.

595 lines
17 KiB

  1. /* File: \WACKER\TDLL\new_cnct.c (Created: 2-Feb-1994)
  2. *
  3. * Copyright 1990,1995 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 11 $
  7. * $Date: 5/15/02 4:31p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <commctrl.h>
  12. extern BOOL WINAPI SetWindowStyle(HWND hwnd, DWORD style, BOOL fExtended);
  13. int gnrlPickIconDlg(HWND hDlg);
  14. #include <term\res.h>
  15. #include "stdtyp.h"
  16. #include "session.h"
  17. #include "mc.h"
  18. #include "globals.h"
  19. #include "misc.h"
  20. #include "tdll.h"
  21. #include "htchar.h"
  22. #include "errorbox.h"
  23. #include "assert.h"
  24. #include "hlptable.h"
  25. #if !defined(DlgParseCmd)
  26. #define DlgParseCmd(i,n,c,w,l) i=LOWORD(w);n=HIWORD(w);c=(HWND)l;
  27. #endif
  28. struct stSaveDlgStuff
  29. {
  30. /*
  31. * Put in whatever else you might need to access later
  32. */
  33. HSESSION hSession;
  34. TCHAR achSessName[FNAME_LEN];
  35. };
  36. typedef struct stSaveDlgStuff SDS;
  37. #define IDC_IC_ICON 101
  38. #define IDC_TF_NAME 102
  39. #define IDC_LB_NAME 105
  40. #define IDC_EF_NAME 106
  41. #define IDC_TF_ICON 107
  42. #define IDC_LB_LIST 108
  43. #define IDC_PB_BROWSE 109
  44. #define NC_CUT1 103
  45. #define NC_CUT2 110
  46. // Design change - 4/14/94: Don't show Wackers New Connection icon
  47. // in selection list. - mrw
  48. //
  49. #define ICON_COUNT 16
  50. BOOL NCD_WM_DRAWITEM(LPDRAWITEMSTRUCT pD);
  51. BOOL NCD_WM_COMPAREITEM(LPCOMPAREITEMSTRUCT pC);
  52. BOOL NCD_WM_DELETEITEM(LPDELETEITEMSTRUCT pD);
  53. BOOL NCD_WM_MEASUREITEM(LPMEASUREITEMSTRUCT pM);
  54. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55. * FUNCTION: NewConnectionDlg
  56. *
  57. * DESCRIPTION: Dialog manager stub
  58. *
  59. * ARGUMENTS: Standard Windows dialog manager
  60. *
  61. * RETURNS: Standard Windows dialog manager
  62. *
  63. */
  64. INT_PTR CALLBACK NewConnectionDlg(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  65. {
  66. HWND hwndChild;
  67. INT nId;
  68. INT nNtfy, fBad;
  69. SDS *pS;
  70. int nLoop;
  71. HWND hwnd;
  72. BOOL fRc;
  73. DWORD dwMaxComponentLength;
  74. DWORD dwFileSystemFlags;
  75. HICON hIcon;
  76. int nSelected;
  77. int cy;
  78. RECT rc;
  79. static fLongNamesSupported;
  80. static DWORD aHlpTable[] = { IDC_EF_NAME, IDH_TERM_NEWCONN_NAME,
  81. IDC_LB_NAME, IDH_TERM_NEWCONN_NAME,
  82. //IDC_TF_NAME, IDH_TERM_NEWCONN_NAME,
  83. IDC_TF_ICON, IDH_TERM_NEWCONN_ICON,
  84. IDC_LB_LIST, IDH_TERM_NEWCONN_ICON,
  85. //IDC_IC_ICON, IDH_TERM_NEWCONN_ICON,
  86. IDCANCEL, IDH_CANCEL,
  87. IDOK, IDH_OK,
  88. 0, 0};
  89. //
  90. // MSDN docs state these are all reserved device names. REV: 5/14/2002
  91. //
  92. static const TCHAR *apszBadNames[] =
  93. {
  94. "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
  95. "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
  96. "EPT", "NUL", "PRN", "CLOCK$", "CON", "AUX", NULL
  97. };
  98. static const TCHAR *apszBadNTNames[] =
  99. {
  100. "MAILSLOT", "PIPE", "UNC", NULL
  101. };
  102. TCHAR ach[FNAME_LEN];
  103. switch (wMsg)
  104. {
  105. case WM_INITDIALOG:
  106. pS = (SDS *)malloc(sizeof(SDS));
  107. // Set no matter what so we can always free
  108. //
  109. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pS);
  110. if (pS == (SDS *)0)
  111. {
  112. /* TODO: decide if we need to display an error here */
  113. EndDialog(hDlg, FALSE);
  114. break;
  115. }
  116. pS->hSession = (HSESSION)lPar;
  117. mscCenterWindowOnWindow(hDlg, GetParent(hDlg));
  118. // Determine whether long filenames are supported. JRJ 12/94
  119. fRc = GetVolumeInformation(NULL, // pointer to root dir path buffer
  120. NULL, // pointer to volume name buffer
  121. 0, // length of volume name buffer
  122. NULL, // pointer to volume serial number buffer
  123. &dwMaxComponentLength, // the prize - what I'm after
  124. &dwFileSystemFlags, // ptr to file system flag DWORD
  125. NULL, // pointer to file system name buffer
  126. 0); // length of file system name buffer
  127. if(dwMaxComponentLength == 255)
  128. {
  129. // There is support for long file names.
  130. // Allow a max name lenght of 249. That's 255 minus the
  131. // extension length (3), minus the smallest path length,
  132. // (i.e. C:\) also (3).
  133. //
  134. SendDlgItemMessage(hDlg, IDC_EF_NAME, EM_SETLIMITTEXT, 249, 0);
  135. fLongNamesSupported = TRUE;
  136. }
  137. else
  138. {
  139. // There IS NOT support for long file names. Limit to eight.
  140. SendDlgItemMessage(hDlg, IDC_EF_NAME, EM_SETLIMITTEXT, 8, 0);
  141. fLongNamesSupported = FALSE;
  142. }
  143. // This dialog may also be called to change the session icon,
  144. // so display the name and icon if we already have one.
  145. //
  146. sessQueryName(pS->hSession, ach, sizeof(ach)/sizeof(TCHAR));
  147. StrCharCopyN(pS->achSessName, ach, sizeof(pS->achSessName)/sizeof(TCHAR));
  148. if (!sessIsSessNameDefault(ach))
  149. {
  150. SetDlgItemText(hDlg, IDC_EF_NAME, ach);
  151. mscModifyToFit(GetDlgItem(hDlg, IDC_TF_NAME), ach, SS_WORDELLIPSIS);
  152. SetDlgItemText(hDlg, IDC_TF_NAME, ach);
  153. }
  154. else if (ach[0] != TEXT('\0'))
  155. {
  156. SetDlgItemText(hDlg, IDC_TF_NAME, ach);
  157. // Set the new connection icon ID, if it's a new connection.
  158. // --jcm 2/23/95.
  159. //
  160. sessSetIconID(pS->hSession, IDI_PROG);
  161. }
  162. hIcon = sessQueryIcon(pS->hSession);
  163. if (hIcon != (HICON)0)
  164. SendDlgItemMessage(hDlg, IDC_IC_ICON, STM_SETICON,
  165. (WPARAM)hIcon, 0);
  166. /* Fiddle with the list box */
  167. hwnd = GetDlgItem(hDlg, IDC_LB_LIST);
  168. SendMessage(hwnd,
  169. LB_SETCOLUMNWIDTH,
  170. GetSystemMetrics(SM_CXICON) + 12,
  171. 0L);
  172. /* compute the height of the listbox based on icon dimensions */
  173. GetClientRect(hwnd, &rc);
  174. cy = GetSystemMetrics(SM_CYICON);
  175. cy += GetSystemMetrics(SM_CYHSCROLL);
  176. cy += GetSystemMetrics(SM_CYEDGE) * 3;
  177. SetWindowPos(hwnd,
  178. NULL,
  179. 0, 0,
  180. rc.right, cy,
  181. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  182. /* It's an owner drawn list box, just set the ICON ids for later */
  183. nSelected = FALSE;
  184. for (nLoop = 0; nLoop < ICON_COUNT; nLoop += 1)
  185. {
  186. SendMessage(hwnd,
  187. LB_INSERTSTRING,
  188. nLoop,
  189. (LPARAM)"Hilgraeve is Great !!!");
  190. // Design change - 4/14/94: Don't show Wackers New Connection
  191. // icon in selection list. - mrw
  192. //
  193. SendMessage(hwnd,
  194. LB_SETITEMDATA,
  195. nLoop,
  196. nLoop + IDI_PROG1);
  197. if (sessQueryIconID(pS->hSession) == (IDI_PROG1 + nLoop))
  198. {
  199. SendMessage(hwnd,
  200. LB_SETCURSEL,
  201. nLoop, 0L);
  202. nSelected = TRUE;
  203. }
  204. }
  205. if (!nSelected)
  206. {
  207. SendMessage(hwnd,
  208. LB_SETCURSEL,
  209. 0, 0L);
  210. }
  211. break;
  212. case WM_DRAWITEM:
  213. if (wPar == IDC_LB_LIST)
  214. return NCD_WM_DRAWITEM((LPDRAWITEMSTRUCT)lPar);
  215. break;
  216. case WM_COMPAREITEM:
  217. if (wPar == IDC_LB_LIST)
  218. return NCD_WM_COMPAREITEM((LPCOMPAREITEMSTRUCT)lPar);
  219. break;
  220. case WM_DELETEITEM:
  221. if (wPar == IDC_LB_LIST)
  222. return NCD_WM_DELETEITEM((LPDELETEITEMSTRUCT)lPar);
  223. break;
  224. case WM_MEASUREITEM:
  225. if (wPar == IDC_LB_LIST)
  226. return NCD_WM_MEASUREITEM((LPMEASUREITEMSTRUCT)lPar);
  227. break;
  228. case WM_CONTEXTMENU:
  229. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  230. break;
  231. case WM_HELP:
  232. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  233. break;
  234. case WM_DESTROY:
  235. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  236. if (pS)
  237. {
  238. free(pS);
  239. pS = NULL;
  240. }
  241. break;
  242. case WM_COMMAND:
  243. /*
  244. * Did we plan to put a macro in here to do the parsing ?
  245. */
  246. DlgParseCmd(nId, nNtfy, hwndChild, wPar, lPar);
  247. switch (nId)
  248. {
  249. case IDOK:
  250. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  251. fBad = FALSE;
  252. // Set session name and icon.
  253. //
  254. ach[0] = TEXT('\0');
  255. nSelected = GetDlgItemText(hDlg, IDC_EF_NAME, ach, sizeof(ach) / sizeof(TCHAR));
  256. if (ach[0] == TEXT('\0'))
  257. {
  258. TCHAR msg[MAX_PATH];
  259. LoadString(glblQueryDllHinst(),
  260. IDS_GNRL_NEED_SESSION_NAME, msg,
  261. sizeof(msg)/sizeof(TCHAR));
  262. TimedMessageBox(hDlg, msg, NULL,
  263. MB_OK | MB_ICONHAND, 0);
  264. SetFocus(GetDlgItem(hDlg, IDC_EF_NAME));
  265. fBad = TRUE;
  266. }
  267. else
  268. {
  269. TCHAR ach2[MAX_PATH];
  270. TCHAR invalid_chars[MAX_PATH];
  271. LoadString(glblQueryDllHinst(),
  272. IDS_GNRL_INVALID_FILE_CHARS, invalid_chars,
  273. sizeof(invalid_chars)/sizeof(TCHAR));
  274. if (StrCharPBrk(ach, invalid_chars) != NULL)
  275. {
  276. TCHAR msg[MAX_PATH];
  277. LoadString(glblQueryDllHinst(),
  278. IDS_GNRL_INVALID_CHARS, ach2,
  279. sizeof(ach2)/sizeof(TCHAR));
  280. wsprintf(msg, ach2, invalid_chars);
  281. TimedMessageBox(hDlg, msg, NULL,
  282. MB_OK | MB_ICONHAND, 0);
  283. SetFocus(GetDlgItem(hDlg, IDC_EF_NAME));
  284. fBad = TRUE;
  285. }
  286. if (fBad)
  287. break;
  288. TCHAR_Trim(ach);
  289. // Check the name against known device names.
  290. //
  291. fBad = FALSE;
  292. for(nLoop = 0; apszBadNames[nLoop] != NULL; nLoop++)
  293. {
  294. if (StrCharCmpi(apszBadNames[nLoop], ach) == 0)
  295. {
  296. LoadString(glblQueryDllHinst(),IDS_GNRL_INVALID_NAME,
  297. ach2, sizeof(ach2) / sizeof(TCHAR));
  298. wsprintf(ach, ach2, invalid_chars);
  299. TimedMessageBox(hDlg, ach, NULL,
  300. MB_OK | MB_ICONHAND, 0);
  301. SetFocus(GetDlgItem(hDlg, IDC_EF_NAME));
  302. fBad = TRUE;
  303. break;
  304. }
  305. } //for(nLoop = 0; apszBadNames[nLoop] != NULL; nLoop++)
  306. if (!fBad && IsNT())
  307. {
  308. for(nLoop = 0; apszBadNTNames[nLoop] != NULL; nLoop++)
  309. {
  310. if (StrCharCmpi(apszBadNTNames[nLoop], ach) == 0)
  311. {
  312. LoadString(glblQueryDllHinst(),IDS_GNRL_INVALID_NAME,
  313. ach2, sizeof(ach2) / sizeof(TCHAR));
  314. wsprintf(ach, ach2, invalid_chars);
  315. TimedMessageBox(hDlg, ach, NULL,
  316. MB_OK | MB_ICONHAND, 0);
  317. SetFocus(GetDlgItem(hDlg, IDC_EF_NAME));
  318. fBad = TRUE;
  319. break;
  320. }
  321. } //for(nLoop = 0; apszBadNTNames[nLoop] != NULL; nLoop++)
  322. }
  323. if (fBad)
  324. {
  325. break;
  326. }
  327. sessSetName(pS->hSession, ach);
  328. sessUpdateAppTitle(pS->hSession);
  329. /*
  330. * Check and see if a new Icon has been selected
  331. */
  332. hwnd = GetDlgItem(hDlg, IDC_LB_LIST);
  333. assert(hwnd);
  334. if (hwnd)
  335. {
  336. /* Get the ICON from the list box */
  337. nLoop = (int)SendMessage(hwnd, LB_GETCURSEL, 0, 0L);
  338. if (nLoop == LB_ERR)
  339. nLoop = 0;
  340. nLoop = (int)SendMessage(hwnd, LB_GETITEMDATA, nLoop, 0);
  341. sessSetIconID(pS->hSession, nLoop);
  342. PostMessage(sessQueryHwnd(pS->hSession), WM_SETICON,
  343. (WPARAM)TRUE, (LPARAM)sessQueryIcon(pS->hSession));
  344. } // (hwnd)
  345. EndDialog(hDlg, TRUE);
  346. break;
  347. case IDCANCEL:
  348. pS = (SDS *)GetWindowLongPtr(hDlg, DWLP_USER);
  349. sessQueryName(pS->hSession, ach, sizeof(ach)/sizeof(TCHAR));
  350. if (!sessIsSessNameDefault(ach))
  351. {
  352. sessSetName(pS->hSession, pS->achSessName);
  353. }
  354. EndDialog(hDlg, FALSE);
  355. break;
  356. default:
  357. return FALSE;
  358. } // if (ach[0] == TEXT('\0'))
  359. } // switch(nId)
  360. break; // WM_COMMAND
  361. default:
  362. return FALSE;
  363. } //switch (wMsg)
  364. return TRUE;
  365. }
  366. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  367. * FUNCTION:
  368. * NCD_WM_DRAWITEM
  369. *
  370. * DESCRIPTION:
  371. * This function is called when the owner drawn list box used to display
  372. * ICONs sends its parent a WM_DRAWITEM message.
  373. *
  374. * ARGUMENTS:
  375. * pD -- pointer to the draw structure
  376. *
  377. * RETURNS:
  378. *
  379. */
  380. BOOL NCD_WM_DRAWITEM(LPDRAWITEMSTRUCT pD)
  381. {
  382. int x, y;
  383. HICON hicon;
  384. #if(WINVER >= 0x0500)
  385. DWORD dwOldLayout;
  386. #endif
  387. //hicon = LoadIcon(glblQueryDllHinst(), MAKEINTRESOURCE(pD->itemData));
  388. hicon = extLoadIcon(MAKEINTRESOURCE(pD->itemData));
  389. if (hicon == (HICON)0)
  390. return FALSE;
  391. if (pD->itemState & ODS_SELECTED)
  392. SetBkColor(pD->hDC, GetSysColor(COLOR_HIGHLIGHT));
  393. else
  394. SetBkColor(pD->hDC, GetSysColor(COLOR_WINDOW));
  395. /* repaint the selection state */
  396. ExtTextOut(pD->hDC, 0, 0, ETO_OPAQUE, &pD->rcItem, NULL, 0, NULL);
  397. x = (pD->rcItem.left + pD->rcItem.right - GetSystemMetrics(SM_CXICON)) / 2;
  398. y = (pD->rcItem.top + pD->rcItem.bottom - GetSystemMetrics(SM_CYICON)) / 2;
  399. #if(WINVER >= 0x0500)
  400. /* Bug #345406 : Don't mirror the icon. */
  401. dwOldLayout = GetLayout(pD->hDC);
  402. if (dwOldLayout && dwOldLayout != GDI_ERROR)
  403. {
  404. SetLayout(pD->hDC, dwOldLayout | LAYOUT_BITMAPORIENTATIONPRESERVED);
  405. }
  406. #endif
  407. DrawIcon(pD->hDC, x, y, hicon);
  408. #if(WINVER >= 0x0500)
  409. if (dwOldLayout && dwOldLayout != GDI_ERROR)
  410. {
  411. SetLayout(pD->hDC, dwOldLayout);
  412. }
  413. #endif
  414. /* if it has the focus, draw the focus */
  415. if (pD->itemState & ODS_FOCUS)
  416. DrawFocusRect(pD->hDC, &pD->rcItem);
  417. return TRUE;
  418. }
  419. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  420. * FUNCTION:
  421. * NCD_WM_COMPAREITEM
  422. *
  423. * DESCRIPTION:
  424. * This function is called when the owner drawn list box used to display
  425. * ICONs sends its parent a WM_COMPAREITEM message.
  426. *
  427. * ARGUMENTS:
  428. * pC -- pointer to the structure to fill in.
  429. *
  430. * RETURNS:
  431. * ZERO -- they all compare the same.
  432. *
  433. */
  434. BOOL NCD_WM_COMPAREITEM(LPCOMPAREITEMSTRUCT pC)
  435. {
  436. return 0;
  437. }
  438. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  439. * FUNCTION:
  440. * NCD_WM_DELETEITEM
  441. *
  442. * DESCRIPTION:
  443. * This function is called when the owner drawn list box used to display
  444. * ICONs sends its parent a WM_DELETEITEM message.
  445. *
  446. * ARGUMENTS:
  447. * pD -- pointer to the structure to fill in.
  448. *
  449. * RETURNS:
  450. * TRUE;
  451. *
  452. */
  453. BOOL NCD_WM_DELETEITEM(LPDELETEITEMSTRUCT pD)
  454. {
  455. return TRUE;
  456. }
  457. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  458. * FUNCTION:
  459. * NCD_WM_MEASUREITEM
  460. *
  461. * DESCRIPTION:
  462. * This function is called when the owner drawn list box used to display
  463. * ICONs sends its parent a WM_MEASUREITEM message. It fills in the
  464. * structure and returns.
  465. *
  466. * ARGUMENTS:
  467. * pM -- pointer to the structure to fill in.
  468. *
  469. * RETURNS:
  470. * TRUE.
  471. *
  472. */
  473. BOOL NCD_WM_MEASUREITEM(LPMEASUREITEMSTRUCT pM)
  474. {
  475. pM->itemWidth = GetSystemMetrics(SM_CXICON);
  476. pM->itemWidth += 12;
  477. pM->itemHeight = GetSystemMetrics(SM_CYICON);
  478. pM->itemHeight += 4;
  479. return TRUE;
  480. }
  481. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  482. * FUNCTION:
  483. * DisplayError
  484. *
  485. * DESCRIPTION:
  486. * Displays and error message.
  487. *
  488. * ARGUMENTS:
  489. * hwnd - dialog box handle
  490. * idText - id of text
  491. * idTitle - id of title
  492. *
  493. * RETURNS:
  494. *
  495. * AUTHOR: Mike Ward, 19-Jan-1995
  496. */
  497. static void DisplayError(const HWND hwnd, const int idText, const int idTitle)
  498. {
  499. }