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.

459 lines
12 KiB

  1. /* File: D:\WACKER\tdll\sessmenu.c (Created: 30-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 9 $
  7. * $Date: 4/22/02 1:26p $
  8. */
  9. // #define DEBUGSTR 1
  10. #include <windows.h>
  11. #pragma hdrstop
  12. #include <time.h> // goes with cnct.h
  13. #include "stdtyp.h"
  14. #include "session.h"
  15. #include "emu\emu.h"
  16. #include "term.h"
  17. #include "print.h"
  18. #include <term\res.h>
  19. #include <tdll\assert.h>
  20. #include "capture.h"
  21. #include "globals.h"
  22. #include "xfer_msc.h"
  23. #include "cnct.h"
  24. #if defined(INCL_NAG_SCREEN)
  25. #include "nagdlg.h"
  26. #include "register.h"
  27. #endif
  28. static void MenuItemCheck(const HMENU hMenu, const UINT uID, BOOL fChecked);
  29. static void MenuItemEnable(const HMENU hMenu, const UINT uID, BOOL fEnable);
  30. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  31. * FUNCTION:
  32. * sessInitMenuPopupEdit
  33. *
  34. * DESCRIPTION:
  35. * Initializes edit menu just before display.
  36. *
  37. * ARGUMENTS:
  38. * hSession - external session handle
  39. * hMenu - edit popup menu handle
  40. *
  41. * RETURNS:
  42. * void
  43. *
  44. */
  45. void sessInitMenuPopupCall(const HSESSION hSession, const HMENU hMenu)
  46. {
  47. BOOL fCheck = FALSE;
  48. HCNCT hCnct = (HCNCT)0;
  49. int iRet = CNCT_STATUS_FALSE;
  50. // Enable disconnect option only if we are connected.
  51. //
  52. hCnct = sessQueryCnctHdl(hSession);
  53. if (hCnct)
  54. iRet = cnctQueryStatus(hCnct);
  55. //
  56. // Check to see if we are currently connected or connecting.
  57. // Added the check for connecting status. REV: 03/23/2001
  58. //
  59. fCheck = (iRet == CNCT_STATUS_TRUE ||
  60. iRet == CNCT_STATUS_CONNECTING);
  61. MenuItemEnable(hMenu, IDM_ACTIONS_HANGUP, fCheck);
  62. #ifdef INCL_CALL_ANSWERING
  63. // Enable "Wait for a Call" if we are not connected and not waiting.
  64. // Added check for "Connecting" and "Disconnecting" states as well.
  65. // REV: 03/23/2001
  66. //
  67. fCheck = (iRet != CNCT_STATUS_TRUE &&
  68. iRet != CNCT_STATUS_CONNECTING &&
  69. iRet != CNCT_STATUS_DISCONNECTING &&
  70. iRet != CNCT_STATUS_ANSWERING);
  71. MenuItemEnable(hMenu, IDM_ACTIONS_WAIT_FOR_CALL, fCheck);
  72. // Enable "Stop Waiting" if we are waiting for a call.
  73. //
  74. fCheck = (iRet == CNCT_STATUS_ANSWERING);
  75. MenuItemEnable(hMenu, IDM_ACTIONS_STOP_WAITING, fCheck);
  76. //Disable "Call" if we are waiting for a call - mpt 09-08-99
  77. //
  78. fCheck = (iRet == CNCT_STATUS_TRUE ||
  79. iRet == CNCT_STATUS_CONNECTING ||
  80. iRet == CNCT_STATUS_ANSWERING);
  81. #endif
  82. //
  83. // Moved enabling/disabling the "Call" button after the check
  84. // for Waiting for calls so that we set the correct state when
  85. // we are waiting for calls. REV: 08/16/2001
  86. //
  87. MenuItemEnable(hMenu, IDM_ACTIONS_DIAL, !fCheck);
  88. return;
  89. }
  90. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  91. * FUNCTION:
  92. * sessInitMenuPopupEdit
  93. *
  94. * DESCRIPTION:
  95. * Initializes edit menu just before display.
  96. *
  97. * ARGUMENTS:
  98. * hSession - external session handle
  99. * hMenu - edit popup menu handle
  100. *
  101. * RETURNS:
  102. * void
  103. *
  104. */
  105. void sessInitMenuPopupEdit(const HSESSION hSession, const HMENU hMenu)
  106. {
  107. BOOL fCheck = FALSE, f;
  108. HCNCT hCnct = (HCNCT)0;
  109. int iRet = 0;
  110. // Don't enable the copy menu item unless we have something to copy.
  111. //
  112. if (SendMessage(sessQueryHwndTerminal(hSession), WM_TERM_Q_MARKED, 0, 0))
  113. fCheck = TRUE;
  114. MenuItemEnable(hMenu, IDM_COPY, fCheck);
  115. // Enable Paste to Host if there is something on the clipboard and
  116. // we are connected.
  117. //
  118. hCnct = sessQueryCnctHdl(hSession);
  119. if (hCnct)
  120. iRet = cnctQueryStatus(hCnct);
  121. fCheck = IsClipboardFormatAvailable(CF_TEXT);
  122. f = fCheck && (iRet == CNCT_STATUS_TRUE);
  123. MenuItemEnable(hMenu, IDM_PASTE, f);
  124. DbgOutStr("Enable IDM_PASTE %d %d %d\r\n", f, fCheck, iRet == CNCT_STATUS_TRUE, 0,0);
  125. return;
  126. }
  127. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  128. * FUNCTION:
  129. * sessInitMenuPopupView
  130. *
  131. * DESCRIPTION:
  132. * Initializes view menu just before display.
  133. *
  134. * ARGUMENTS:
  135. * hSession - external session handle
  136. * hMenu - view popup menu handle
  137. *
  138. * RETURNS:
  139. * void
  140. *
  141. */
  142. void sessInitMenuPopupView(const HSESSION hSession, const HMENU hMenu)
  143. {
  144. BOOL f;
  145. #if defined(TESTMENU) && !defined(NDEBUG)
  146. const HWND hwndTerm = sessQueryHwndTerminal(hSession);
  147. #endif
  148. const HWND hwndToolbar = sessQueryHwndToolbar(hSession);
  149. const HWND hwndStatusbar = sessQueryHwndStatusbar(hSession);
  150. #if defined(TESTMENU) && !defined(NDEBUG)
  151. f = (BOOL)SendMessage(hwndTerm, WM_TERM_Q_BEZEL, 0, 0);
  152. MenuItemCheck(hMenu, IDM_TEST_BEZEL, f);
  153. #endif
  154. f = IsWindow(hwndToolbar) && sessQueryToolbarVisible(hSession);
  155. MenuItemCheck(hMenu, IDM_VIEW_TOOLBAR, f);
  156. f = IsWindow(hwndStatusbar) && sessQueryStatusbarVisible(hSession);
  157. MenuItemCheck(hMenu, IDM_VIEW_STATUS, f);
  158. return;
  159. }
  160. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  161. * FUNCTION:
  162. * sessInitMenuPopupActions
  163. *
  164. * DESCRIPTION:
  165. * This function gets called when the Actions menu is about to be displayed
  166. * so that any last minute changes can be made.
  167. *
  168. * PARAMETERS:
  169. * hSession - external session handle
  170. * hMenu - view popup menu handle
  171. *
  172. * RETURNS:
  173. * void
  174. *
  175. */
  176. #define TRANSFER_CAPTURE_OFFSET 2
  177. void sessInitMenuPopupTransfer(const HSESSION hSession, const HMENU hMenu)
  178. {
  179. int nMode;
  180. BOOL f;
  181. VOID *pData;
  182. MENUITEMINFO stM;
  183. TCHAR acMessage[64];
  184. HMENU hSubMenu;
  185. pData = (VOID *)0;
  186. xfrQueryDataPointer(sessQueryXferHdl(hSession), &pData);
  187. /*
  188. * A NULL pointer means no transfer in progress, a non-NULL pointer
  189. * means that someone is transferring.
  190. */
  191. f = (pData == (VOID *)0);
  192. MenuItemEnable(hMenu, IDM_ACTIONS_SEND, f);
  193. MenuItemEnable(hMenu, IDM_ACTIONS_RCV, f);
  194. /*
  195. * This section is for the Capture Menu. It is more of a pain.
  196. */
  197. nMode = cpfGetCaptureState(sessQueryCaptureFileHdl(hSession));
  198. if (nMode == CPF_CAPTURE_OFF)
  199. {
  200. /* Set things so that they can get to the dialog box */
  201. LoadString(glblQueryDllHinst(),
  202. IDS_CPF_CAP_OFF,
  203. acMessage,
  204. sizeof(acMessage) / sizeof(TCHAR));
  205. memset(&stM, 0, sizeof(MENUITEMINFO));
  206. stM.cbSize = sizeof(MENUITEMINFO);
  207. stM.fMask = MIIM_ID | MIIM_TYPE | MIIM_SUBMENU;
  208. stM.wID = IDM_ACTIONS_CAP;
  209. stM.fType = MFT_STRING;
  210. stM.hSubMenu = (HMENU)0;
  211. stM.dwTypeData = (LPTSTR)acMessage;
  212. DbgOutStr("Setting Capture to start dialog\r\n", 0,0,0,0,0);
  213. SetMenuItemInfo(hMenu,
  214. TRANSFER_CAPTURE_OFFSET,
  215. TRUE, /* By Position */
  216. &stM);
  217. }
  218. else
  219. {
  220. LoadString(glblQueryDllHinst(),
  221. IDS_CPF_CAP_ON,
  222. acMessage,
  223. sizeof(acMessage) / sizeof(TCHAR));
  224. hSubMenu = cpfGetCaptureMenu(sessQueryCaptureFileHdl(hSession));
  225. memset(&stM, 0, sizeof(MENUITEMINFO));
  226. stM.cbSize = sizeof(MENUITEMINFO);
  227. stM.fMask = MIIM_TYPE | MIIM_SUBMENU;
  228. stM.hSubMenu = hSubMenu;
  229. stM.dwTypeData = (LPTSTR)acMessage;
  230. /* Set up the cascade for the alternative choices */
  231. switch (nMode)
  232. {
  233. default:
  234. case CPF_CAPTURE_ON:
  235. /* Disable RESUME, enable PAUSE */
  236. MenuItemEnable(hSubMenu, IDM_CAPTURE_RESUME, FALSE);
  237. MenuItemEnable(hSubMenu, IDM_CAPTURE_PAUSE, TRUE);
  238. break;
  239. case CPF_CAPTURE_PAUSE:
  240. /* Disable PAUSE, enable RESUME */
  241. MenuItemEnable(hSubMenu, IDM_CAPTURE_RESUME, TRUE);
  242. MenuItemEnable(hSubMenu, IDM_CAPTURE_PAUSE, FALSE);
  243. break;
  244. }
  245. DbgOutStr("Setting Capture to cascade menu\r\n", 0,0,0,0,0);
  246. SetMenuItemInfo(hMenu,
  247. TRANSFER_CAPTURE_OFFSET,
  248. TRUE, /* By Position */
  249. &stM);
  250. }
  251. // Display setup for Printer Echo option.
  252. MenuItemEnable(hMenu, IDM_ACTIONS_PRINT, TRUE);
  253. f = printQueryStatus(emuQueryPrintEchoHdl(sessQueryEmuHdl(hSession)));
  254. MenuItemCheck(hMenu, IDM_ACTIONS_PRINT, f);
  255. }
  256. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  257. * FUNCTION:
  258. * sessInitMenuPopupView
  259. *
  260. * DESCRIPTION:
  261. * Initializes view menu just before display.
  262. *
  263. * ARGUMENTS:
  264. * hSession - external session handle
  265. * hMenu - view popup menu handle
  266. *
  267. * RETURNS:
  268. * void
  269. *
  270. */
  271. void sessInitMenuPopupHelp(const HSESSION hSession, const HMENU hMenu)
  272. {
  273. #if defined(INCL_NAG_SCREEN)
  274. if ( !IsEval() )
  275. {
  276. MenuItemEnable(hMenu, IDM_PURCHASE_INFO, FALSE);
  277. MenuItemEnable(hMenu, IDM_REG_CODE, FALSE);
  278. }
  279. // If they are already registered take this menu item off
  280. //
  281. #ifndef NT_VERSION
  282. if (IsRegisteredUser())
  283. {
  284. DeleteMenu(hMenu, IDM_REGISTER, MF_BYCOMMAND);
  285. }
  286. #endif
  287. #endif
  288. return;
  289. }
  290. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  291. * FUNCTION:
  292. * MenuItemCheck
  293. *
  294. * DESCRIPTION:
  295. * Once again the menu functions have changed. Checking and unchecking
  296. * menu items is a bit more complicated so I wrote a function to handle
  297. * it. Other common menu operations should be handled this way. - mrw
  298. *
  299. * ARGUMENTS:
  300. * hMenu - handle of menu
  301. * uID - id of menu item (position not supported)
  302. * fChecked- TRUE if item is to be checked
  303. *
  304. * RETURNS:
  305. * void
  306. *
  307. */
  308. static void MenuItemCheck(const HMENU hMenu, const UINT uID, BOOL fChecked)
  309. {
  310. MENUITEMINFO mii;
  311. memset(&mii, 0, sizeof(MENUITEMINFO));
  312. mii.cbSize = sizeof(MENUITEMINFO);
  313. mii.fMask = MIIM_STATE;
  314. mii.fState = (fChecked) ? MFS_CHECKED : MFS_UNCHECKED;
  315. mii.wID = uID;
  316. SetMenuItemInfo(hMenu, uID, FALSE, &mii);
  317. return;
  318. }
  319. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  320. * FUNCTION:
  321. *
  322. * DESCRIPTION:
  323. * Please see the previous function.
  324. *
  325. * ARGUEMENTS:
  326. * Please see the previous function.
  327. *
  328. * RETURNS:
  329. * Nothing.
  330. */
  331. static void MenuItemEnable(const HMENU hMenu, const UINT uID, BOOL fEnable)
  332. {
  333. MENUITEMINFO mii;
  334. memset(&mii, 0, sizeof(MENUITEMINFO));
  335. mii.cbSize = sizeof(MENUITEMINFO);
  336. mii.fMask = MIIM_STATE;
  337. mii.fState = (fEnable) ? (MFS_ENABLED) : (MFS_DISABLED | MFS_GRAYED);
  338. mii.wID = uID;
  339. SetMenuItemInfo(hMenu, uID, FALSE, &mii);
  340. return;
  341. }
  342. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  343. * FUNCTION:
  344. * HandleContextMenu
  345. *
  346. * DESCRIPTION:
  347. * Load and display the context menu.
  348. *
  349. * ARGUMENTS:
  350. * hwnd - session window handle.
  351. * point - where the user clicked.
  352. *
  353. * RETURNS:
  354. * void.
  355. *
  356. */
  357. void HandleContextMenu(HWND hwnd, POINT point)
  358. {
  359. const HSESSION hSession = (HSESSION)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  360. HMENU hMenu;
  361. HMENU hMenuTrackPopup;
  362. BOOL fCheck = FALSE, f;
  363. HCNCT hCnct = (HCNCT)0;
  364. int iRet = 0;
  365. hMenu = LoadMenu(glblQueryDllHinst() , "SessionContextMenu");
  366. if (!hMenu)
  367. return;
  368. // Don't enable the copy menu item unless we have something to copy.
  369. //
  370. if (SendMessage(sessQueryHwndTerminal(hSession), WM_TERM_Q_MARKED, 0, 0))
  371. fCheck = TRUE;
  372. // Enable - 'Copy' menu item
  373. //
  374. MenuItemEnable(hMenu, IDM_CONTEXT_COPY, fCheck);
  375. // Enable - 'Paste to Host' menu item
  376. //
  377. hCnct = sessQueryCnctHdl(hSession);
  378. if (hCnct)
  379. iRet = cnctQueryStatus(hCnct);
  380. fCheck = IsClipboardFormatAvailable(CF_TEXT);
  381. f = fCheck && (iRet == CNCT_STATUS_TRUE);
  382. MenuItemEnable(hMenu, IDM_CONTEXT_PASTE, f);
  383. /* --- Snap doesn't make sense when we're maximized - mrw --- */
  384. if (IsZoomed(hwnd))
  385. MenuItemEnable(hMenu, IDM_CONTEXT_SNAP, FALSE);
  386. /* --- Normal context menu stuff --- */
  387. hMenuTrackPopup = GetSubMenu(hMenu, 0);
  388. ClientToScreen(hwnd, (LPPOINT)&point);
  389. TrackPopupMenu(hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL);
  390. DestroyMenu(hMenu);
  391. }