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.

1066 lines
26 KiB

  1. /* File: D:\WACKER\tdll\sessutil.c (Created: 30-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 9 $
  7. * $Date: 7/08/02 6:48p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <time.h>
  12. #include "features.h"
  13. #include "stdtyp.h"
  14. #include "sf.h"
  15. #include "mc.h"
  16. #include "term.h"
  17. #include "cnct.h"
  18. #include "print.h"
  19. #include "assert.h"
  20. #include "capture.h"
  21. #include "globals.h"
  22. #include "sess_ids.h"
  23. #include "load_res.h"
  24. #include "open_msc.h"
  25. #include "xfer_msc.h"
  26. #include "file_msc.h"
  27. #include "backscrl.h"
  28. #include "cloop.h"
  29. #include "com.h"
  30. #include <term\res.h>
  31. #include "session.h"
  32. #include "session.hh"
  33. #include "errorbox.h"
  34. #include <emu\emu.h>
  35. #include "tdll.h"
  36. #include "htchar.h"
  37. #include "misc.h"
  38. #ifdef INCL_NAG_SCREEN
  39. #include "nagdlg.h"
  40. #endif
  41. STATIC_FUNC void sessPreventOverlap(const HSESSION hSession, BOOL fIsToolbar);
  42. STATIC_FUNC int sessCountMenuLines(HWND hwnd);
  43. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  44. * FUNCTION:
  45. * sessSnapToTermWindow
  46. *
  47. * DESCRIPTION:
  48. * Sizes the session window so that the terminal is full size (usually
  49. * 80 x 24).
  50. *
  51. * ARGUMENTS:
  52. * hwnd - session window handle
  53. *
  54. * RETURNS:
  55. * void
  56. *
  57. */
  58. void sessSnapToTermWindow(const HWND hwnd)
  59. {
  60. RECT rc;
  61. RECT rc2;
  62. LONG lw;
  63. LONG lh;
  64. LONG l2w;
  65. LONG l2h;
  66. const HSESSION hSession = (HSESSION)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  67. /* --- Doesn't make much sense to snap when we're maximized - mrw --- */
  68. if (IsZoomed(hwnd))
  69. return;
  70. if (sessComputeSnapSize(hSession, &rc))
  71. {
  72. // Make sure we don't go beyond size of screen
  73. // mrw,1/20/95
  74. //
  75. if (SystemParametersInfo(SPI_GETWORKAREA, sizeof(LPRECT), &rc2, 0))
  76. {
  77. lw = rc.right - rc.left;
  78. lh = rc.bottom - rc.top;
  79. l2w = rc2.right - rc2.left;
  80. l2h = rc2.bottom - rc2.top;
  81. GetWindowRect(hwnd, &rc);
  82. // When we first start-up we move the window off screen.
  83. // If we're off screen, we don't do any screen bounds
  84. // checking.
  85. //
  86. if (rc.top > rc2.bottom)
  87. {
  88. SetWindowPos(hwnd, 0, 0, 0, lw, lh, SWP_NOMOVE);
  89. }
  90. else
  91. {
  92. // Calculate new size in desktop coordinates.
  93. //
  94. rc.right = rc.left + lw;
  95. rc.bottom = rc.top + lh;
  96. // Check if too wide
  97. //
  98. if (lw > l2w)
  99. {
  100. rc.left = rc2.left;
  101. rc.right = rc2.right;
  102. }
  103. // Check if to high
  104. //
  105. if (lh > l2h)
  106. {
  107. rc.top = rc2.top;
  108. rc.bottom = rc2.bottom;
  109. }
  110. // Check if we're off to the right
  111. //
  112. if (rc.right > rc2.right)
  113. {
  114. lw = rc.right - rc2.right;
  115. rc.right -= lw;
  116. rc.left -= lw;
  117. }
  118. // Check if we're off the bottom
  119. //
  120. if (rc.bottom > rc2.bottom)
  121. {
  122. lh = rc.bottom - rc2.bottom;
  123. rc.bottom -= lh;
  124. rc.top -= lh;
  125. }
  126. SetWindowPos(hwnd, 0, rc.left, rc.top,
  127. rc.right-rc.left, rc.bottom-rc.top, 0);
  128. }
  129. }
  130. }
  131. return;
  132. }
  133. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  134. * FUNCTION:
  135. * sessSetMinMaxInfo
  136. *
  137. * DESCRIPTION:
  138. * Calculates the max horizontal size for the session and sets that
  139. * value in the mmi structure. If the window is being maximized, then
  140. * we just return. Later, we'll have flags to control autosnapping so
  141. * this function will change. Also some minimum tracking size is set.
  142. *
  143. * ARGUMENTS:
  144. * hSession - public session handle.
  145. * pmmi - pointer to MINMAXINFO structure
  146. *
  147. * RETURNS:
  148. * void
  149. *
  150. */
  151. void sessSetMinMaxInfo(const HSESSION hSession, const PMINMAXINFO pmmi)
  152. {
  153. RECT rc;
  154. HWND hwndStatusbar, hwndToolbar, hwndSess;
  155. NONCLIENTMETRICS stNCM;
  156. int i, iLineCnt = 0;
  157. /* --- Believe it or not, this gets called before WM_CREATE --- */
  158. if (hSession == (HSESSION)0)
  159. return;
  160. hwndSess = sessQueryHwnd(hSession);
  161. if (IsZoomed(hwndSess))
  162. return;
  163. #if 0 // removed on a trial basis - mrw
  164. if (sessComputeSnapSize(hSession, &rc))
  165. pmmi->ptMaxTrackSize.x = (rc.right - rc.left);
  166. #endif
  167. /* --- Set the minimum height for the session --- */
  168. memset(&rc, 0, sizeof(RECT));
  169. hwndStatusbar = sessQueryHwndStatusbar(hSession);
  170. if (IsWindow(hwndStatusbar) && IsWindowVisible(hwndStatusbar))
  171. {
  172. GetWindowRect(hwndStatusbar, &rc);
  173. pmmi->ptMinTrackSize.y += (rc.bottom - rc.top);
  174. }
  175. memset(&rc, 0, sizeof(RECT));
  176. hwndToolbar = sessQueryHwndToolbar(hSession);
  177. if (IsWindow(hwndToolbar) && IsWindowVisible(hwndToolbar))
  178. {
  179. GetWindowRect(hwndToolbar, &rc);
  180. pmmi->ptMinTrackSize.y += (rc.bottom - rc.top);
  181. }
  182. // Menus take up at least one iMenuHeight...
  183. //
  184. stNCM.cbSize = sizeof(NONCLIENTMETRICS);
  185. if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
  186. sizeof(NONCLIENTMETRICS), &stNCM, 0) == TRUE)
  187. {
  188. pmmi->ptMinTrackSize.y += (stNCM.iMenuHeight - 1);
  189. // And if they take up more than that then adjust for it.
  190. //
  191. iLineCnt = sessCountMenuLines(hwndSess);
  192. for (i = 1; i < iLineCnt; i++)
  193. pmmi->ptMinTrackSize.y += (stNCM.iMenuHeight);
  194. DbgOutStr("%i, %i ", stNCM.iMenuHeight, iLineCnt, 0, 0, 0);
  195. }
  196. return;
  197. }
  198. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  199. * FUNCTION:
  200. * sessCountMenuLines
  201. *
  202. * DESCRIPTION:
  203. * Counts the lines a menu associated with a window is taking up.
  204. *
  205. * ARGUMENTS:
  206. * hwnd - the window handle.
  207. *
  208. * RETURNS:
  209. * How many lines a menu is taking up.
  210. *
  211. */
  212. STATIC_FUNC int sessCountMenuLines(HWND hwnd)
  213. {
  214. int i, iLineCnt = 0, iRemembered = 0;
  215. HMENU hMenu;
  216. RECT rc;
  217. hMenu = GetMenu(hwnd);
  218. memset(&rc, 0, sizeof(RECT));
  219. for (i = 0; i < GetMenuItemCount(hMenu); i++)
  220. {
  221. GetMenuItemRect(hwnd, hMenu, (UINT)i, &rc);
  222. if ((int)rc.bottom > iRemembered)
  223. {
  224. iRemembered = (int)rc.bottom;
  225. iLineCnt++;
  226. }
  227. }
  228. return (iLineCnt);
  229. }
  230. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  231. * FUNCTION:
  232. * sessComputeSnapSize
  233. *
  234. * DESCRIPTION:
  235. * Computes the minimum size of the session window that will display
  236. * the entire terminal screen.
  237. *
  238. * ARGUMENTS:
  239. * hSession - public session handle
  240. * prc - pointer to rectangle that contains minimum size
  241. *
  242. * RETURNS:
  243. * TRUE if success, FALSE contains worthless data
  244. *
  245. */
  246. BOOL sessComputeSnapSize(const HSESSION hSession, const LPRECT prc)
  247. {
  248. RECT rcTmp;
  249. const HWND hwndTerm = sessQueryHwndTerminal(hSession);
  250. const HWND hwndToolbar = sessQueryHwndToolbar(hSession);
  251. const HWND hwndStatusbar = sessQueryHwndStatusbar(hSession);
  252. const HWND hwndSidebar = sessQuerySidebarHwnd(hSession);
  253. if (IsWindow(hwndTerm) == FALSE)
  254. return FALSE;
  255. /* --- Ask terminal for it's snapped size --- */
  256. SendMessage(hwndTerm, WM_TERM_Q_SNAP, 0, (LPARAM)prc);
  257. /* --- Compute the client window height --- */
  258. if (IsWindow(hwndToolbar) && sessQueryToolbarVisible(hSession))
  259. {
  260. GetWindowRect(hwndToolbar, &rcTmp);
  261. prc->top -= (rcTmp.bottom - rcTmp.top);
  262. }
  263. if (IsWindow(hwndStatusbar) && sessQueryStatusbarVisible(hSession))
  264. {
  265. GetWindowRect(hwndStatusbar, &rcTmp);
  266. prc->bottom += (rcTmp.bottom - rcTmp.top);
  267. }
  268. if (IsWindow(hwndSidebar) && IsWindowVisible(hwndSidebar))
  269. {
  270. GetWindowRect(hwndSidebar, &rcTmp);
  271. prc->right += (rcTmp.right - rcTmp.left);
  272. }
  273. /* --- Compute the necessary frame size --- */
  274. if (AdjustWindowRectEx(prc, WS_OVERLAPPEDWINDOW, TRUE, WS_EX_WINDOWEDGE))
  275. return TRUE;
  276. return FALSE;
  277. }
  278. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  279. * FUNCTION:
  280. * NotifyClient
  281. *
  282. * DESCRIPTION:
  283. * Called from the engine thread primarily, this function notifies the
  284. * main thread of some event in the engine, such as new data for the
  285. * terminal to display.
  286. *
  287. * ARGUMENTS:
  288. * hSession - external session handle
  289. * nEvent - event that occured
  290. * lExtra - extra data to pass
  291. *
  292. * RETURNS:
  293. * void
  294. *
  295. */
  296. void NotifyClient(const HSESSION hSession, const NOTIFICATION nEvent,
  297. const long lExtra)
  298. {
  299. const HHSESSION hhSess = (HHSESSION)hSession;
  300. PostMessage(hhSess->hwndSess, WM_SESS_NOTIFY, (WPARAM)nEvent, lExtra);
  301. return;
  302. }
  303. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  304. * FUNCTION:
  305. *
  306. * DESCRIPTION:
  307. *
  308. * ARGUMENTS:
  309. *
  310. * RETURNS:
  311. *
  312. */
  313. void sessInitializeIcons(HSESSION hSession)
  314. {
  315. const HHSESSION hhSess = VerifySessionHandle(hSession);
  316. hhSess->nIconId = IDI_PROG;
  317. hhSess->hIcon = extLoadIcon(MAKEINTRESOURCE(IDI_PROG));
  318. //hhSess->hIcon = LoadIcon(glblQueryDllHinst(),
  319. // MAKEINTRESOURCE(IDI_PROG));
  320. //hhSess->hLittleIcon = LoadIcon(glblQueryDllHinst(),
  321. // MAKEINTRESOURCE(IDI_PROG + IDI_PROG_ICON_CNT));
  322. }
  323. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  324. * FUNCTION:
  325. *
  326. * DESCRIPTION:
  327. *
  328. * ARGUMENTS:
  329. *
  330. * RETURNS:
  331. *
  332. */
  333. void sessLoadIcons(HSESSION hSession)
  334. {
  335. const HHSESSION hhSess = VerifySessionHandle(hSession);
  336. long lSize;
  337. lSize = sizeof(hhSess->nIconId);
  338. sfGetSessionItem(hhSess->hSysFile, SFID_ICON_DEFAULT, &lSize,
  339. &hhSess->nIconId);
  340. hhSess->hIcon = extLoadIcon(MAKEINTRESOURCE(hhSess->nIconId));
  341. //hhSess->hIcon = LoadIcon(glblQueryDllHinst(),
  342. // MAKEINTRESOURCE(hhSess->nIconId));
  343. //hhSess->hLittleIcon = LoadIcon(glblQueryDllHinst(),
  344. // MAKEINTRESOURCE(hhSess->nIconId+IDI_PROG_ICON_CNT));
  345. }
  346. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  347. * FUNCTION:
  348. *
  349. * DESCRIPTION:
  350. *
  351. * ARGUMENTS:
  352. *
  353. * RETURNS:
  354. *
  355. */
  356. void sessSaveIcons(HSESSION hSession)
  357. {
  358. const HHSESSION hhSess = VerifySessionHandle(hSession);
  359. sfPutSessionItem(hhSess->hSysFile, SFID_ICON_DEFAULT,
  360. sizeof(hhSess->nIconId), &hhSess->nIconId);
  361. return;
  362. }
  363. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  364. * FUNCTION:
  365. * sessSetSuspend
  366. *
  367. * DESCRIPTION:
  368. * We need to block the flow of data going into the emulators which is
  369. * done by suspending the CLoop. Suspending is done for several reasons.
  370. * User presses the scroll lock key. User has pressed left mouse button
  371. * down in preparation for marking (note: user could just let up mouse
  372. * without marking so its a separate reason). User is marking or has
  373. * marked text.
  374. *
  375. * ARGUMENTS:
  376. * hSession - public session handle
  377. * iReason - which event has called this routine
  378. *
  379. * RETURNS:
  380. * void
  381. *
  382. */
  383. void sessSetSuspend(const HSESSION hSession, const int iReason)
  384. {
  385. const HHSESSION hhSession = VerifySessionHandle(hSession);
  386. switch (iReason)
  387. {
  388. case SUSPEND_SCRLCK:
  389. hhSession->fSuspendScrlLck = TRUE;
  390. break;
  391. case SUSPEND_TERMINAL_MARKING:
  392. hhSession->fSuspendTermMarking = TRUE;
  393. break;
  394. case SUSPEND_TERMINAL_LBTNDN:
  395. hhSession->fSuspendTermLBtnDn = TRUE;
  396. break;
  397. case SUSPEND_TERMINAL_COPY:
  398. hhSession->fSuspendTermCopy = TRUE;
  399. break;
  400. default:
  401. assert(FALSE);
  402. return;
  403. }
  404. CLoopRcvControl(sessQueryCLoopHdl(hSession), CLOOP_SUSPEND,
  405. CLOOP_RB_SCRLOCK);
  406. return;
  407. }
  408. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  409. * FUNCTION:
  410. * sessClearSuspend
  411. *
  412. * DESCRIPTION:
  413. * Clearing suspends is essentially the opposite of setting execept that
  414. * we do not resume cloop processing until all flags are FALSE. Sets
  415. * and clears are not cumulative which is what I first wanted to do but
  416. * particularly in the area's of scroll lock keys and text marking the
  417. * events are not always toggled (ie. might get many marks but only one
  418. * unmark). Also, event can be easily added although none come to mind.
  419. *
  420. * ARGUMENTS:
  421. * hSession - public session handle
  422. * iReason - which event has called this routine
  423. *
  424. * RETURNS:
  425. * void
  426. *
  427. */
  428. void sessClearSuspend(const HSESSION hSession, const int iReason)
  429. {
  430. const HHSESSION hhSession = VerifySessionHandle(hSession);
  431. switch (iReason)
  432. {
  433. case SUSPEND_SCRLCK:
  434. hhSession->fSuspendScrlLck = FALSE;
  435. break;
  436. case SUSPEND_TERMINAL_MARKING:
  437. hhSession->fSuspendTermMarking = FALSE;
  438. break;
  439. case SUSPEND_TERMINAL_LBTNDN:
  440. hhSession->fSuspendTermLBtnDn = FALSE;
  441. break;
  442. case SUSPEND_TERMINAL_COPY:
  443. hhSession->fSuspendTermCopy = FALSE;
  444. break;
  445. default:
  446. assert(FALSE);
  447. return;
  448. }
  449. if (!hhSession->fSuspendScrlLck && !hhSession->fSuspendTermMarking
  450. && !hhSession->fSuspendTermLBtnDn && !hhSession->fSuspendTermCopy)
  451. {
  452. CLoopRcvControl(sessQueryCLoopHdl(hSession), CLOOP_RESUME,
  453. CLOOP_RB_SCRLOCK);
  454. }
  455. return;
  456. }
  457. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  458. * FUNCTION:
  459. * IsSessionSuspended
  460. *
  461. * DESCRIPTION:
  462. * Checks if the session is suspended. Suspends occur
  463. * whenever the user is marking text, holds the mouse button down, or
  464. * presses the scroll lock key.
  465. *
  466. * ARGUMENTS:
  467. * hSession - public session handle
  468. *
  469. * RETURNS:
  470. * TRUE if were suspended.
  471. *
  472. */
  473. BOOL IsSessionSuspended(const HSESSION hSession)
  474. {
  475. const HHSESSION hhSess = VerifySessionHandle(hSession);
  476. return (hhSess->fSuspendScrlLck || hhSess->fSuspendTermMarking ||
  477. hhSess->fSuspendTermLBtnDn || hhSess->fSuspendTermCopy);
  478. }
  479. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  480. * FUNCTION:
  481. * sessQueryToolbarVisible
  482. *
  483. * DESCRIPTION:
  484. * This function returns the expected visibility state of the Toolbar.
  485. *
  486. * ARGUMENTS:
  487. * hSession -- the session handle
  488. *
  489. * RETURNS:
  490. * The expected visibility state of the Toolbar.
  491. *
  492. */
  493. BOOL sessQueryToolbarVisible(const HSESSION hSession)
  494. {
  495. const HHSESSION hhSession = VerifySessionHandle(hSession);
  496. return hhSession->fToolbarVisible;
  497. }
  498. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  499. * FUNCTION:
  500. * sessSetToolbarVisible
  501. *
  502. * DESCRIPTION:
  503. * This function changes the expected visibility state of the Toolbar.
  504. * It does not change the actual visibility of the Toolbar.
  505. *
  506. * ARGUMENTS:
  507. * hSession -- the session handle
  508. * fVisible -- indicates visibility as TRUE or FALSE
  509. *
  510. * RETURNS:
  511. * The previous visibility state of the Toolbar.
  512. *
  513. */
  514. BOOL sessSetToolbarVisible(const HSESSION hSession, const BOOL fVisible)
  515. {
  516. const HHSESSION hhSession = VerifySessionHandle(hSession);
  517. BOOL bRet = TRUE;
  518. bRet = hhSession->fToolbarVisible;
  519. hhSession->fToolbarVisible = (fVisible != FALSE);
  520. if (fVisible)
  521. sessPreventOverlap(hSession, TRUE);
  522. ShowWindow(hhSession->hwndToolbar, (fVisible) ? SW_SHOW : SW_HIDE);
  523. return bRet;
  524. }
  525. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  526. * FUNCTION:
  527. * sessQueryStatusbarVisible
  528. *
  529. * DESCRIPTION:
  530. * This function returns the expected visibility state of the Statusbar.
  531. *
  532. * ARGUMENTS:
  533. * hSession -- the session handle
  534. *
  535. * RETURNS:
  536. * The expected visibility state of the Statusbar.
  537. *
  538. */
  539. BOOL sessQueryStatusbarVisible(const HSESSION hSession)
  540. {
  541. const HHSESSION hhSession = VerifySessionHandle(hSession);
  542. return hhSession->fStatusbarVisible;
  543. }
  544. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  545. * FUNCTION:
  546. * sessSetStatusbarVisible
  547. *
  548. * DESCRIPTION:
  549. * This function changes the expected visibility state of the Statusbar.
  550. * It does not change the actual visibility of the Statusbar.
  551. *
  552. * ARGUMENTS:
  553. * hSession -- the session handle
  554. * fVisible -- indicates visibility as TRUE or FALSE
  555. *
  556. * RETURNS:
  557. * The previous visibility state of the Statusbar.
  558. *
  559. */
  560. BOOL sessSetStatusbarVisible(const HSESSION hSession, const BOOL fVisible)
  561. {
  562. const HHSESSION hhSession = VerifySessionHandle(hSession);
  563. BOOL bRet = TRUE;
  564. bRet = hhSession->fStatusbarVisible;
  565. hhSession->fStatusbarVisible = (fVisible != FALSE);
  566. if (fVisible)
  567. sessPreventOverlap(hSession, FALSE);
  568. ShowWindow(hhSession->hwndStatusbar, (fVisible) ? SW_SHOW : SW_HIDE);
  569. return bRet;
  570. }
  571. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  572. * FUNCTION:
  573. * sessCmdLnDial
  574. *
  575. * DESCRIPTION:
  576. * Everytime we open a session, we call this function to attempt to
  577. * dial.
  578. *
  579. *
  580. * ARGUMENTS:
  581. * hSession - public session handle
  582. *
  583. * RETURNS:
  584. * void
  585. *
  586. */
  587. void sessCmdLnDial(const HSESSION hSession)
  588. {
  589. const HHSESSION hhSession = VerifySessionHandle(hSession);
  590. switch (hhSession->iCmdLnDial)
  591. {
  592. case CMDLN_DIAL_DIAL:
  593. cnctConnect(sessQueryCnctHdl(hSession), 0);
  594. break;
  595. case CMDLN_DIAL_NEW:
  596. cnctConnect(sessQueryCnctHdl(hSession), CNCT_NEW);
  597. break;
  598. case CMDLN_DIAL_WINSOCK:
  599. cnctConnect(sessQueryCnctHdl(hSession), CNCT_WINSOCK);
  600. break;
  601. case CMDLN_DIAL_OPEN:
  602. default:
  603. break;
  604. }
  605. return;
  606. }
  607. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  608. * FUNCTION:
  609. * sessUpdateAppTitle
  610. *
  611. * DESCRIPTION:
  612. *
  613. * ARGUMENTS:
  614. * hwnd - app window.
  615. *
  616. * RETURNS:
  617. * void.
  618. *
  619. */
  620. void sessUpdateAppTitle(const HSESSION hSession)
  621. {
  622. HWND hwnd = sessQueryHwnd(hSession);
  623. TCHAR acTitle[256], acName[256], acNewTitle[256];
  624. #ifdef INCL_NAG_SCREEN
  625. TCHAR acUnregistered[256];
  626. #endif
  627. LPTSTR pNewTitle;
  628. int iSize;
  629. TCHAR *pszSeperator = TEXT(" - ");
  630. BOOL bEval = FALSE;
  631. TCHAR_Fill(acNewTitle, TEXT('\0'), sizeof(acNewTitle) / sizeof(TCHAR));
  632. TCHAR_Fill(acTitle, TEXT('\0'), sizeof(acTitle) / sizeof(TCHAR));
  633. sessQueryName(hSession, acName, sizeof(acName));
  634. if (sessIsSessNameDefault(acName))
  635. {
  636. LoadString(glblQueryDllHinst(), IDS_GNRL_NEW_CNCT, acName,
  637. sizeof(acName) / sizeof(TCHAR));
  638. }
  639. StrCharCopyN(acNewTitle, acName, sizeof(acTitle) / sizeof(TCHAR));
  640. LoadString(glblQueryDllHinst(), IDS_GNRL_APPNAME, acTitle,
  641. sizeof(acTitle) / sizeof(TCHAR));
  642. #ifdef INCL_NAG_SCREEN
  643. if ( IsEval() )
  644. {
  645. bEval = TRUE;
  646. LoadString(glblQueryDllHinst(), IDS_GNRL_UNREGISTERED, acUnregistered,
  647. sizeof(acUnregistered) / sizeof(TCHAR));
  648. }
  649. #endif
  650. iSize = StrCharGetByteCount(acNewTitle);
  651. iSize += StrCharGetByteCount(pszSeperator);
  652. iSize += StrCharGetByteCount(acTitle);
  653. #ifdef INCL_NAG_SCREEN
  654. if ( bEval )
  655. {
  656. iSize += StrCharGetByteCount(acUnregistered);
  657. }
  658. #endif
  659. iSize += sizeof(TCHAR);
  660. pNewTitle = malloc(iSize);
  661. if (pNewTitle)
  662. {
  663. StrCharCopyN(pNewTitle, acNewTitle, iSize);
  664. StrCharCat(pNewTitle, pszSeperator);
  665. StrCharCat(pNewTitle, acTitle);
  666. #ifdef INCL_NAG_SCREEN
  667. if ( bEval )
  668. {
  669. StrCharCat(pNewTitle, acUnregistered);
  670. }
  671. #endif
  672. SetWindowText(hwnd, pNewTitle);
  673. free(pNewTitle);
  674. pNewTitle = NULL;
  675. }
  676. else
  677. {
  678. SetWindowText(hwnd, acNewTitle);
  679. }
  680. }
  681. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  682. * FUNCTION:
  683. * sessDisconnectToContinue
  684. *
  685. * DESCRIPTION:
  686. * If connecterd, ask the user if he wants to disconnect and continue with
  687. * whatever he set out to perform, such as close the app, open a new session,
  688. * create a new connection, etc.
  689. *
  690. * ARGUMENTS:
  691. * hSession - the Session handle.
  692. * hwnd - the session window.
  693. *
  694. * RETURNS:
  695. * TRUE - if the user wants to disconnect and go on with his request.
  696. * FALSE - if he changes his mind.
  697. *
  698. */
  699. BOOL sessDisconnectToContinue(const HSESSION hSession, HWND hwnd)
  700. {
  701. HCNCT hCnct = (HCNCT)0;
  702. int iRet = 0;
  703. TCHAR ach[256], achTitle[100];
  704. hCnct = sessQueryCnctHdl(hSession);
  705. if (hCnct)
  706. iRet = cnctQueryStatus(hCnct);
  707. if (iRet == CNCT_STATUS_TRUE)
  708. {
  709. LoadString(glblQueryDllHinst(), IDS_GNRL_CNFRM_DCNCT,
  710. ach, sizeof(ach) / sizeof(TCHAR));
  711. LoadString(glblQueryDllHinst(), IDS_MB_TITLE_WARN, achTitle,
  712. sizeof(achTitle) / sizeof(TCHAR));
  713. if ((iRet = TimedMessageBox(hwnd, ach, achTitle,
  714. MB_YESNO | MB_ICONEXCLAMATION, 0)) == IDYES)
  715. {
  716. if (SendMessageTimeout(hwnd, WM_COMMAND, IDM_ACTIONS_HANGUP, 0L,
  717. SMTO_ABORTIFHUNG, 1000, NULL) == 0)
  718. {
  719. PostMessage(hwnd, WM_COMMAND, IDM_ACTIONS_HANGUP, 0L);
  720. }
  721. }
  722. else
  723. return FALSE;
  724. }
  725. return TRUE;
  726. }
  727. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  728. * FUNCTION:
  729. * sessSizeAndShow
  730. *
  731. * DESCRIPTION:
  732. * Called only once from the InitInstance() this function will size
  733. * the window via snap and insure it lands on the desktop. This
  734. * function is called via a posted message because it was found that
  735. * the session was not fully initialized after returning from the
  736. * CreateWindow call.
  737. *
  738. * ARGUMENTS:
  739. * hwnd - session window.
  740. * nCmdShow - Show command passed from WinMain()
  741. *
  742. * RETURNS:
  743. * void
  744. *
  745. */
  746. void sessSizeAndShow(const HWND hwnd, const int nCmdShow)
  747. {
  748. HSESSION hSession = (HSESSION)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  749. const HWND hwndBanner = glblQueryHwndBanner();
  750. WINDOWPLACEMENT stWP;
  751. RECT rc, rc2, rc3;
  752. int cx, cy;
  753. int xWA, yWA, cxWA, cyWA;
  754. int iWidth = 0, iHeight = 0;
  755. // Size session window...
  756. //
  757. if (!sessQueryIsNewSession(hSession))
  758. {
  759. // Size and position the session window according to the
  760. // remembered values, if no values were remembered, i.e., an old
  761. // session, then treat it as a default session.
  762. //
  763. memset(&rc, 0, sizeof(RECT));
  764. sessQueryWindowRect(hSession, &rc);
  765. iWidth = rc.right - rc.left;
  766. iHeight = rc.bottom - rc.top;
  767. if (iWidth != 0 && iHeight != 0)
  768. {
  769. stWP.length = sizeof(WINDOWPLACEMENT);
  770. stWP.flags = 0;
  771. stWP.showCmd = (UINT)sessQueryWindowShowCmd(hSession);
  772. memmove(&stWP.rcNormalPosition, &rc, sizeof(RECT));
  773. SetWindowPlacement(hwnd, &stWP);
  774. UpdateWindow(hwnd);
  775. if (IsWindow(hwndBanner))
  776. PostMessage(hwndBanner, WM_CLOSE, 0, 0);
  777. return;
  778. }
  779. }
  780. // Well, were back to our windows tricks. The toolbar height
  781. // has changed with the introduction of the larger bitmaps (from
  782. // 16x16 to 22x24). On program startup, the toolbar window reports
  783. // a default size which is not the correct size since the new bitmaps
  784. // will force it to be larger. This doesn't happen however, until
  785. // the window is displayed. So we display the window off screen,
  786. // do the resizing, then move it back on screen.
  787. GetWindowRect(hwnd, &rc);
  788. SetWindowPos(hwnd, 0, 20000, 20000, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  789. ShowWindow(hwnd, nCmdShow);
  790. UpdateWindow(hwnd);
  791. // Size to terminal window for a default session, i.e., the user
  792. // did not specify a session name on the command line.
  793. //
  794. sessSnapToTermWindow(hwnd);
  795. // Get new window size but keep original origin
  796. //
  797. GetWindowRect(hwnd, &rc2);
  798. rc.right = rc.left + (rc2.right - rc2.left);
  799. rc.bottom = rc.top + (rc2.bottom - rc2.top);
  800. // Until the SPI parameters are defined
  801. //
  802. if (SystemParametersInfo(SPI_GETWORKAREA, sizeof(LPRECT), &rc3, 0) == TRUE)
  803. {
  804. xWA = rc3.left;
  805. yWA = rc3.top;
  806. cxWA = rc3.right - rc3.left;
  807. cyWA = rc3.bottom - rc3.top;
  808. }
  809. else
  810. {
  811. xWA = 0;
  812. yWA = 0;
  813. cxWA = GetSystemMetrics(SM_CXSCREEN);
  814. cyWA = GetSystemMetrics(SM_CYSCREEN);
  815. }
  816. cx = rc.left;
  817. cy = rc.top;
  818. if (rc.right > (xWA + cxWA))
  819. cx = max(xWA, rc.left - (rc.right - (xWA + cxWA)));
  820. if (rc.bottom > (yWA + cyWA))
  821. cy = max(yWA, rc.top - (rc.bottom - (yWA + cyWA)));
  822. // Move window back to either its original or adjusted position.
  823. //
  824. SetWindowPos(hwnd, 0, cx, cy, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  825. UpdateWindow(hwnd);
  826. if (IsWindow(hwndBanner))
  827. PostMessage(hwndBanner, WM_CLOSE, 0, 0);
  828. return;
  829. }
  830. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  831. * FUNCTION:
  832. * sessPreventOverlap
  833. *
  834. * DESCRIPTION:
  835. * The main purpose for existance of this function is to prevent the toolbar
  836. * window and the status window overlapping each other. That is accomplished
  837. * by sizing the session window to be big enough to display both of the
  838. * windows comfortably.
  839. *
  840. * ARGUMENTS:
  841. * hSession - the session handle.
  842. * fIsToolbar - TRUE if we showing the toolbar window, FALSE otherwise.
  843. *
  844. * RETURNS:
  845. * void.
  846. *
  847. */
  848. STATIC_FUNC void sessPreventOverlap(const HSESSION hSession, BOOL fIsToolbar)
  849. {
  850. const HHSESSION hhSession = VerifySessionHandle(hSession);
  851. RECT rcSess, rcTool, rcStat;
  852. if ((fIsToolbar) ? hhSession->fStatusbarVisible :
  853. hhSession->fToolbarVisible)
  854. {
  855. GetWindowRect(hhSession->hwndSess, &rcSess);
  856. GetWindowRect(hhSession->hwndToolbar, &rcTool);
  857. GetWindowRect(hhSession->hwndStatusbar, &rcStat);
  858. if (rcTool.bottom > rcStat.top)
  859. {
  860. SetWindowPos(hhSession->hwndSess, 0,
  861. 0, 0, rcSess.right - rcSess.left,
  862. (rcSess.bottom - rcSess.top) + (rcTool.bottom - rcStat.top),
  863. SWP_NOMOVE | SWP_NOZORDER);
  864. }
  865. }
  866. }
  867. #if defined(DEADWOOD)
  868. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  869. * FUNCTION:
  870. * DoBeeper
  871. *
  872. * DESCRIPTION:
  873. * Produces three audible beeps in sequence
  874. *
  875. * ARGUMENTS:
  876. * dw - required by CreateThread()
  877. *
  878. * RETURNS:
  879. * DWORD - required by CreateThread
  880. *
  881. */
  882. DWORD WINAPI DoBeeper(DWORD dw)
  883. {
  884. //mpt:06-04-98 changed to use windows sounds
  885. MessageBeep(MB_ICONEXCLAMATION);
  886. #if 0
  887. int i;
  888. for (i = 0 ; i < 3 ; ++i)
  889. {
  890. MessageBeep((unsigned)-1);
  891. Sleep(300);
  892. }
  893. #endif
  894. return 0;
  895. }
  896. #endif // defined(DEADWOOD)
  897. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  898. * FUNCTION:
  899. * sessBeeper
  900. *
  901. * DESCRIPTION:
  902. * Launches thread to do beeps if session setting is on. Seems silly
  903. * to launch a thread to do something like this but it really is the
  904. * simplist and most direct way. - mrw
  905. *
  906. * ARGUMENTS:
  907. * hSession - public session handle
  908. *
  909. * RETURNS:
  910. * void
  911. *
  912. */
  913. void sessBeeper(const HSESSION hSession)
  914. {
  915. if (sessQuerySound(hSession))
  916. {
  917. #if defined(DEADWOOD)
  918. DWORD dwID;
  919. if (CreateThread(0, 100, (LPTHREAD_START_ROUTINE)DoBeeper, 0, 0,
  920. &dwID) == 0)
  921. #else // defined(DEADWOOD)
  922. if(mscMessageBeep(MB_ICONEXCLAMATION) == FALSE)
  923. #endif // defined(DEADWOOD)
  924. {
  925. DbgShowLastError();
  926. }
  927. }
  928. return;
  929. }