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.

367 lines
9.8 KiB

  1. //******************************************************************************
  2. // File: \wacker\TDLL\Key_sdlg.c Created: 6/5/98 By: Dwayne M. Newsome
  3. //
  4. // Copyright 1998 by Hilgraeve Inc. --- Monroe, MI
  5. // All rights reserved
  6. //
  7. // Description:
  8. // This file is the key summary dialog procedure. Its purpose is to display
  9. // a list of defined key macros and allow for the creation, modification and
  10. // deletion of key macros.
  11. //
  12. // $Revision: 6 $
  13. // $Date: 2/25/02 1:17p $
  14. // $Id: key_sdlg.c 1.1 1998/06/11 12:03:53 dmn Exp $
  15. //
  16. //******************************************************************************
  17. #include <windows.h>
  18. #pragma hdrstop
  19. #include "stdtyp.h"
  20. #include "mc.h"
  21. #ifdef INCL_KEY_MACROS
  22. #include <term\res.h>
  23. #include "tdll.h"
  24. #include "errorbox.h"
  25. #include "globals.h"
  26. #include "misc.h"
  27. #include "hlptable.h"
  28. #include "keyutil.h"
  29. #if !defined(DlgParseCmd)
  30. #define DlgParseCmd(i,n,c,w,l) i=LOWORD(w);n=HIWORD(w);c=(HWND)l;
  31. #endif
  32. #define IDC_LB_KEYS_KEYLIST 101
  33. #define IDC_PB_KEYS_MODIFY 102
  34. #define IDC_PB_KEYS_NEW 103
  35. #define IDC_PB_KEYS_DELETE 104
  36. //
  37. // helper functions
  38. //
  39. static void setButtonState( HWND hDlg );
  40. static int getSelectedMacro( HWND hDlg, keyMacro * pMacro );
  41. //******************************************************************************
  42. // FUNCTION:
  43. // KeySummaryDlg
  44. //
  45. // DESCRIPTION:
  46. // This is the dialog proc for the key summary dialog.
  47. //
  48. // ARGUMENTS: Standard Windows dialog manager
  49. //
  50. // RETURNS: Standard Windows dialog manager
  51. //
  52. //
  53. BOOL CALLBACK KeySummaryDlg(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  54. {
  55. HWND hwndChild;
  56. HWND listBox;
  57. INT nId;
  58. INT nNtfy;
  59. INT iTabStop;
  60. int iRet = 0;
  61. int lCurSelected;
  62. TCHAR errorMsg[256];
  63. TCHAR errorMsgFmt[256];
  64. TCHAR msgTitle[100];
  65. TCHAR keyName[35];
  66. keyMacro * pKeyMacro;
  67. static DWORD aHlpTable[] = {IDC_LB_KEYS_KEYLIST , IDH_LB_KEYS_KEYLIST,
  68. IDC_PB_KEYS_MODIFY , IDH_PB_KEYS_MODIFY,
  69. IDC_PB_KEYS_NEW , IDH_PB_KEYS_NEW,
  70. IDC_PB_KEYS_DELETE , IDH_PB_KEYS_DELETE,
  71. IDCANCEL, IDH_CANCEL,
  72. IDOK, IDH_OK,
  73. 0, 0};
  74. //
  75. // process messages
  76. //
  77. switch (wMsg)
  78. {
  79. case WM_INITDIALOG:
  80. {
  81. pKeyMacro = keysCreateKeyMacro();
  82. pKeyMacro->hSession = (HSESSION) lPar;
  83. if ( pKeyMacro == 0 )
  84. {
  85. EndDialog(hDlg, FALSE);
  86. }
  87. SetWindowLongPtr( hDlg, DWLP_USER, (LONG_PTR)pKeyMacro );
  88. mscCenterWindowOnWindow( hDlg, GetParent(hDlg) );
  89. iTabStop = 85;
  90. listBox = GetDlgItem( hDlg, IDC_LB_KEYS_KEYLIST );
  91. SendMessage( listBox, LB_SETTABSTOPS, (WPARAM)1, (LPARAM)&iTabStop );
  92. keysLoadSummaryList( listBox );
  93. SendMessage( listBox, LB_SETCURSEL, 0, 0 );
  94. setButtonState( hDlg );
  95. break;
  96. }
  97. case WM_DESTROY:
  98. pKeyMacro = (keyMacro *)GetWindowLongPtr(hDlg, DWLP_USER);
  99. free(pKeyMacro);
  100. pKeyMacro = 0;
  101. break;
  102. case WM_CONTEXTMENU:
  103. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  104. break;
  105. case WM_HELP:
  106. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  107. break;
  108. case WM_COMMAND:
  109. DlgParseCmd(nId, nNtfy, hwndChild, wPar, lPar);
  110. switch (nId)
  111. {
  112. case IDOK:
  113. EndDialog(hDlg, TRUE);
  114. break;
  115. case IDCANCEL:
  116. EndDialog(hDlg, FALSE);
  117. break;
  118. case IDC_PB_KEYS_MODIFY:
  119. pKeyMacro = (keyMacro *)GetWindowLongPtr(hDlg, DWLP_USER);
  120. getSelectedMacro( hDlg, pKeyMacro );
  121. pKeyMacro->editMode = KEYS_EDIT_MODE_EDIT;
  122. if ( DoDialog(glblQueryDllHinst(), MAKEINTRESOURCE(IDD_KEYDLG),
  123. hDlg, KeyDlg, (LPARAM)pKeyMacro ))
  124. {
  125. listBox = GetDlgItem( hDlg, IDC_LB_KEYS_KEYLIST );
  126. keysLoadSummaryList( listBox );
  127. SendMessage( listBox, LB_SETCURSEL, 0, 0 );
  128. setButtonState( hDlg );
  129. }
  130. break;
  131. case IDC_PB_KEYS_NEW:
  132. pKeyMacro = (keyMacro *)GetWindowLongPtr(hDlg, DWLP_USER);
  133. keysResetKeyMacro( pKeyMacro );
  134. pKeyMacro->editMode = KEYS_EDIT_MODE_INSERT;
  135. if ( DoDialog(glblQueryDllHinst(), MAKEINTRESOURCE(IDD_KEYDLG),
  136. hDlg, KeyDlg, (LPARAM)pKeyMacro ))
  137. {
  138. listBox = GetDlgItem( hDlg, IDC_LB_KEYS_KEYLIST );
  139. keysLoadSummaryList( listBox );
  140. SendMessage( listBox, LB_SETCURSEL, 0, 0 );
  141. setButtonState( hDlg );
  142. }
  143. break;
  144. case IDC_PB_KEYS_DELETE:
  145. {
  146. LoadString(glblQueryDllHinst(), IDS_DELETE_KEY_MACRO,
  147. errorMsgFmt, sizeof(errorMsgFmt) / sizeof(TCHAR));
  148. LoadString(glblQueryDllHinst(), IDS_MB_TITLE_WARN, msgTitle,
  149. sizeof(msgTitle) / sizeof(TCHAR));
  150. pKeyMacro = (keyMacro *)GetWindowLongPtr(hDlg, DWLP_USER);
  151. listBox = GetDlgItem( hDlg, IDC_LB_KEYS_KEYLIST );
  152. lCurSelected = SendMessage( listBox, LB_GETCURSEL, 0, 0 );
  153. getSelectedMacro( hDlg, pKeyMacro );
  154. keysGetDisplayString( &pKeyMacro->keyName, 1, keyName, sizeof(keyName) );
  155. wsprintf( errorMsg, errorMsgFmt, keyName );
  156. if ((iRet = TimedMessageBox(hDlg, errorMsg, msgTitle,
  157. MB_YESNO | MB_ICONEXCLAMATION, 0)) == IDYES)
  158. {
  159. keysRemoveMacro( pKeyMacro );
  160. keysLoadSummaryList( listBox );
  161. if ( lCurSelected > 0 )
  162. {
  163. lCurSelected--;
  164. }
  165. SendMessage( listBox, LB_SETCURSEL, lCurSelected, 0 );
  166. setButtonState( hDlg );
  167. }
  168. break;
  169. }
  170. case IDC_LB_KEYS_KEYLIST:
  171. {
  172. switch ( nNtfy )
  173. {
  174. case LBN_SELCHANGE:
  175. setButtonState( hDlg );
  176. break;
  177. case LBN_DBLCLK:
  178. pKeyMacro = (keyMacro *)GetWindowLongPtr(hDlg, DWLP_USER);
  179. getSelectedMacro( hDlg, pKeyMacro );
  180. pKeyMacro->editMode = KEYS_EDIT_MODE_EDIT;
  181. DoDialog( glblQueryDllHinst(),
  182. MAKEINTRESOURCE(IDD_KEYDLG),
  183. hDlg,
  184. KeyDlg,
  185. (LPARAM)pKeyMacro );
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191. default:
  192. return FALSE;
  193. }
  194. break;
  195. default:
  196. return FALSE;
  197. }
  198. return TRUE;
  199. }
  200. //******************************************************************************
  201. // Method:
  202. // getSelectedMacro
  203. //
  204. // Description:
  205. // Gets the definition of the selected macro from the macro summary list box.
  206. //
  207. // Arguments:
  208. // hDlg - Handle to the key macro summary dialog
  209. // pMacro - Pointer to the keyMacro structure to fill
  210. //
  211. // Returns:
  212. // 0 if an error occured, non zero if the key is retrieved.
  213. //
  214. // Throws:
  215. // None
  216. //
  217. // Author: Dwayne M. Newsome, 6/5/98
  218. //
  219. //
  220. int getSelectedMacro( HWND hDlg, keyMacro * pMacro )
  221. {
  222. HWND listBox;
  223. int lCurSelected;
  224. int lSelectedMacro;
  225. listBox = GetDlgItem( hDlg, IDC_LB_KEYS_KEYLIST );
  226. lCurSelected = SendMessage( listBox, LB_GETCURSEL, 0, 0 );
  227. if ( lCurSelected == LB_ERR )
  228. {
  229. return 0;
  230. }
  231. lSelectedMacro = SendMessage( listBox, LB_GETITEMDATA, lCurSelected, 0 );
  232. if ( lSelectedMacro == LB_ERR )
  233. {
  234. return 0;
  235. }
  236. return keysGetMacro( lSelectedMacro, pMacro );
  237. }
  238. //******************************************************************************
  239. // Method:
  240. // setButtonState
  241. //
  242. // Description:
  243. // Sets the states of the new, modify and delete buttons.
  244. //
  245. // Arguments:
  246. // HWND hDlg
  247. //
  248. // Returns:
  249. // void
  250. //
  251. // Throws:
  252. // None
  253. //
  254. // Author: Dwayne M. Newsome, 6/4/98
  255. //
  256. //
  257. void setButtonState( HWND hDlg )
  258. {
  259. BOOL fEnable = FALSE;
  260. int nCount;
  261. HWND listBox;
  262. HWND modifyButton;
  263. HWND deleteButton;
  264. HWND newButton;
  265. listBox = GetDlgItem( hDlg, IDC_LB_KEYS_KEYLIST );
  266. nCount = SendMessage( listBox, LB_GETCOUNT, 0, 0 );
  267. if (nCount > 0)
  268. {
  269. EnableWindow(listBox, TRUE);
  270. fEnable = SendMessage( listBox, LB_GETCURSEL, 0, 0 ) != LB_ERR;
  271. //
  272. // do not allow more than keysMaxMacro keys macros to be defined
  273. //
  274. newButton = GetDlgItem( hDlg, IDC_PB_KEYS_NEW );
  275. if (nCount >= KEYS_MAX_MACROS)
  276. {
  277. EnableWindow( newButton, FALSE );
  278. }
  279. else
  280. {
  281. EnableWindow( newButton, TRUE );
  282. }
  283. }
  284. modifyButton = GetDlgItem( hDlg, IDC_PB_KEYS_MODIFY );
  285. deleteButton = GetDlgItem( hDlg, IDC_PB_KEYS_DELETE );
  286. EnableWindow( modifyButton, fEnable );
  287. EnableWindow( deleteButton, fEnable );
  288. if ( nCount <= 0 )
  289. {
  290. EnableWindow(listBox, FALSE);
  291. newButton = GetDlgItem( hDlg, IDC_PB_KEYS_NEW );
  292. SetFocus( newButton );
  293. }
  294. return;
  295. }
  296. #endif