Windows NT 4.0 source code leak
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.

375 lines
9.2 KiB

4 years ago
  1. /************************************************************************
  2. * *
  3. * MSGVIEW.CPP *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1995 *
  6. * All Rights reserved. *
  7. * *
  8. ************************************************************************/
  9. #include "stdafx.h"
  10. #include "resource.h"
  11. #include "hcwdoc.h"
  12. #include "..\common\waitcur.h"
  13. #include "tabstop.h"
  14. #include "mainfrm.h"
  15. #include "msgview.h"
  16. #include "pageset.h"
  17. #include "mapread.h"
  18. #include "msgopt.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. CMsgView* pMsgView;
  24. IMPLEMENT_DYNCREATE(CMsgView, CLogView)
  25. BEGIN_MESSAGE_MAP(CMsgView, CLogView)
  26. ON_COMMAND(IDM_CLEAR_BUFFER, OnClearBuffer)
  27. ON_COMMAND(IDM_MSG_OPTIONS, OnMsgOptions)
  28. END_MESSAGE_MAP()
  29. static PSTR pszWhMsg;
  30. const char txtWhSharedMem[] = "whshare";
  31. extern int m_cbLogMax;
  32. extern CLogView* plogview;
  33. extern CLogView* poldlogview;
  34. static void STDCALL ReplaceStrings(PSTR pszCur, PCSTR pszOrg, PCSTR pszNew);
  35. typedef struct {
  36. PCSTR pszShort;
  37. PCSTR pszExpanded;
  38. } MSG_PAIR;
  39. MSG_PAIR msgpair[] = {
  40. { "AA(", "AddAccelerator(", },
  41. { "AI(", "AppendItem(", },
  42. { "AL(", "ALink(", },
  43. { "AN(", "Annotate(", },
  44. { "CB(", "CreateButton(", },
  45. { "CBB(", "ChangeButtonBinding(", },
  46. { "CE(", "ChangeEnable(", },
  47. { "CI(", "CheckItem(", },
  48. { "CIB(", "ChangeItemBinding(", },
  49. { "CS(", "CloseSecondarys(", },
  50. { "CT(", "CopyTopic(", },
  51. { "CW(", "CloseWindow(", },
  52. { "DB(", "DisableButton(", },
  53. { "DEB(", "DestroyButton(", },
  54. { "DI(", "DisableItem(", },
  55. { "EB(", "EnableButton(", },
  56. { "EF(", "ExecFile(", },
  57. { "EI(", "EnableItem(", },
  58. { "EP(", "ExecProgram(", },
  59. { "FD(", "Finder(", },
  60. { "FE(", "FileExist(", },
  61. { "FH(", "FlushMessageQueue(", },
  62. { "FO(", "FileOpen(", },
  63. { "IB(", "IsBook(", },
  64. { "IE(", "IfThenElse(", },
  65. { "IF(", "IfElse(", },
  66. { "JC(", "JumpContext(", },
  67. { "JI(", "JumpId(", },
  68. { "JK(", "JumpKeyword(", },
  69. { "JW(", "JumpWindow(", },
  70. { "KL(", "KLink(", },
  71. { "MU(", "Menu(", },
  72. { "NS(", "NoShow(", },
  73. { "PC(", "PopupContext(", },
  74. { "PI(", "PopupId(", },
  75. { "RA(", "RemoveAccelerator(", },
  76. { "RR(", "RegisterRoutine(", },
  77. { "SE(", "ShellExecute(", },
  78. { "SF(", "ShowFolder(", },
  79. { "SH(", "ShortCut(", },
  80. { "SPC(", "SetPopupColor(", },
  81. { "SW(", "ShowInWindow(", },
  82. { "TC(", "TCard(", },
  83. { "UI(", "UncheckItem(", },
  84. { NULL, NULL, },
  85. };
  86. static const char txtShowApi[] = "ShowApi";
  87. static const char txtShowTopicInfo[] = "ShowTopicInfo";
  88. static const char txtShowMacros[] = "ShowMacros";
  89. static const char txtShowExpanded[] = "ShowExpanded";
  90. BOOL g_fShowApi;
  91. BOOL g_fShowTopicInfo;
  92. BOOL g_fShowMacros;
  93. BOOL g_fShowExpanded;
  94. void CMsgView::Initialize()
  95. {
  96. g_fShowApi = AfxGetApp()->GetProfileInt(txtSettingsSection,
  97. txtShowApi, TRUE);
  98. g_fShowTopicInfo = AfxGetApp()->GetProfileInt(txtSettingsSection,
  99. txtShowTopicInfo, TRUE);
  100. g_fShowMacros = AfxGetApp()->GetProfileInt(txtSettingsSection,
  101. txtShowMacros, TRUE);
  102. g_fShowExpanded = AfxGetApp()->GetProfileInt(txtSettingsSection,
  103. txtShowExpanded, TRUE);
  104. }
  105. void CMsgView::Terminate()
  106. {
  107. AfxGetApp()->WriteProfileInt(txtSettingsSection, txtShowApi, g_fShowApi);
  108. AfxGetApp()->WriteProfileInt(txtSettingsSection, txtShowTopicInfo, g_fShowTopicInfo);
  109. AfxGetApp()->WriteProfileInt(txtSettingsSection, txtShowMacros, g_fShowMacros);
  110. AfxGetApp()->WriteProfileInt(txtSettingsSection, txtShowExpanded, g_fShowExpanded);
  111. }
  112. CMsgView::CMsgView()
  113. {
  114. pMsgView = this;
  115. /*
  116. * Because we are derived from CLogView, the CLogView constructor has
  117. * already been called, resulting in plogview being set to this view.
  118. * We now restore it to what it was before this class was constructed.
  119. */
  120. plogview = poldlogview;
  121. if (!hfMsgShare) {
  122. hfMsgShare = CreateFileMapping((HANDLE) -1, NULL, PAGE_READWRITE, 0, 4096,
  123. txtWhSharedMem);
  124. ConfirmOrDie(hfMsgShare);
  125. pszWhMsg = (PSTR) MapViewOfFile(hfMsgShare, FILE_MAP_READ | FILE_MAP_WRITE,
  126. 0, 0, 0);
  127. }
  128. ASSERT(pszWhMsg);
  129. pszMsg = pszWhMsg;
  130. fMacroArriving = FALSE;
  131. fSupressNextMsg = FALSE;
  132. strcpy(pszMsg, GetStringResource(IDS_MSG_VIEW_PROMPT));
  133. ::PostMessage(APP_WINDOW, WMP_WH_MSG, 0, 0);
  134. }
  135. CMsgView::~CMsgView()
  136. {
  137. pMsgView = NULL;
  138. }
  139. void CMsgView::OnWinHelpMsg(void)
  140. {
  141. if (fSupressNextMsg) {
  142. fSupressNextMsg--;
  143. return;
  144. }
  145. if (!g_fShowApi && nstrsubcmp(pszMsg, "HELP_")) {
  146. if ( nstrsubcmp(pszMsg, "HELP_KEY") ||
  147. nstrsubcmp(pszMsg, "HELP_MULTIKEY") ||
  148. nstrsubcmp(pszMsg, "HELP_PARTIALKEY"))
  149. fSupressNextMsg = 3;
  150. else if (nstrsubcmp(pszMsg, "HELP_COMMAND"))
  151. fSupressNextMsg = 3;
  152. else if (nstrsubcmp(pszMsg, "HELP_SETWINPOS"))
  153. fSupressNextMsg = 1;
  154. return;
  155. }
  156. if (!g_fShowTopicInfo && isdigit(*pszMsg))
  157. return;
  158. if (nstrsubcmp(pszMsg, "M:")) {
  159. // Macros get sent in 3 messages: "M:", "macro", "\r\n"
  160. if (!g_fShowMacros) {
  161. fSupressNextMsg = 2;
  162. return;
  163. }
  164. else {
  165. ReplaceStrings(pszMsg, "M:", " ");
  166. fMacroArriving = TRUE;
  167. }
  168. }
  169. else if (fMacroArriving) {
  170. fMacroArriving = FALSE;
  171. // ignore WinHelp variables (processed as macros)
  172. if ( nstrisubcmp(pszMsg, "hwndContext") ||
  173. nstrisubcmp(pszMsg, "hwndApp") ||
  174. nstrisubcmp(pszMsg, "qchPath") ||
  175. nstrisubcmp(pszMsg, "qError") ||
  176. nstrisubcmp(pszMsg, "lTopicNo") ||
  177. nstrisubcmp(pszMsg, "hfs") ||
  178. nstrisubcmp(pszMsg, "coForeground") ||
  179. nstrisubcmp(pszMsg, "coBackground"))
  180. return;
  181. if (!g_fShowExpanded)
  182. goto ShowIt;
  183. PSTR pszDst = pszMsg;
  184. for (;;) {
  185. if (*pszDst == '\"')
  186. pszDst++;
  187. for (int i = 0; msgpair[i].pszShort; i++) {
  188. if (nstrisubcmp(pszDst, msgpair[i].pszShort)) {
  189. ReplaceStrings(pszDst, msgpair[i].pszShort, msgpair[i].pszExpanded);
  190. if (nstrsubcmp(pszDst, "IfThenElse(") || nstrsubcmp(pszDst, "IfElse(")) {
  191. i = -1;
  192. pszDst = FirstNonSpace(strchr(pszDst, '(') + 1);
  193. continue;
  194. }
  195. break;
  196. }
  197. }
  198. if ((pszDst = strstr(pszDst, ");"))) {
  199. PSTR pszAfter = FirstNonSpace(pszDst + 2);
  200. if (*pszAfter) {
  201. ReplaceStrings(pszDst, ");", ");\r\n ");
  202. pszDst = FirstNonSpace(pszDst + 8);
  203. continue;
  204. }
  205. else
  206. break;
  207. }
  208. else if ((pszDst = strstr(pszMsg, ",\""))) {
  209. ReplaceStrings(pszDst, ",\"", ", \"");
  210. pszDst += 3;
  211. continue;
  212. }
  213. else
  214. break;
  215. }
  216. // Make the macros a bit more readable
  217. while ((pszDst = strstr(pszMsg, "\",\"")))
  218. ReplaceStrings(pszDst, "\",\"", "\", \"");
  219. }
  220. else if (fSupressNextMsg) {
  221. fSupressNextMsg = FALSE;
  222. return;
  223. }
  224. else if (nstrsubcmp(pszMsg, "HELP_CONTEXT") ||
  225. nstrsubcmp(pszMsg, "HELP_CONTEXTPOPUP"))
  226. ConvertHelpCommand();
  227. ShowIt:
  228. EnableWindow(FALSE);
  229. // Place the insertion point after the last character in the edit control.
  230. GetEditCtrl().SetSel(-1, -1, TRUE);
  231. // Get the current selection, which is the amount of text in the edit control.
  232. int nStart;
  233. int nEnd;
  234. GetEditCtrl().GetSel(nStart, nEnd);
  235. // If near max add an overflow message, otherwise add the string.
  236. if (nStart + lstrlen(pszMsg) + 256 >= m_cbLogMax) {
  237. GetEditCtrl().ReplaceSel(GetStringResource(IDS_LOG_OVERFLOW));
  238. }
  239. else
  240. GetEditCtrl().ReplaceSel(pszMsg);
  241. SetModifiedFlag(FALSE); // set file as unmodified
  242. EnableWindow(TRUE);
  243. }
  244. void CMsgView::OnClearBuffer(void)
  245. {
  246. GetEditCtrl().SetSel(0, -1);
  247. GetEditCtrl().Clear();
  248. SetModifiedFlag(FALSE); // set file as unmodified
  249. }
  250. void CMsgView::OnMsgOptions(void)
  251. {
  252. CMsgOpt msgopt;
  253. msgopt.DoModal();
  254. }
  255. void CMsgView::ConvertHelpCommand(void)
  256. {
  257. PSTR pszDigit = strchr(pszMsg, ':');
  258. ASSERT(pszDigit);
  259. pszDigit++;
  260. char chWindowChar = 0;
  261. PSTR pszHelpFile = strstr(pszMsg, "--");
  262. ASSERT(pszHelpFile);
  263. pszHelpFile += 3;
  264. PSTR pszWindow = StrChrDBCS(pszHelpFile, '>');
  265. if (!pszWindow)
  266. pszWindow = StrChrDBCS(pszHelpFile, '\r');
  267. if (pszWindow) {
  268. chWindowChar = *pszWindow;
  269. *pszWindow = '\0';
  270. }
  271. CReadMapFile mapread(pszHelpFile);
  272. if (pszWindow)
  273. *pszWindow = chWindowChar;
  274. if (!mapread.m_ptblMap)
  275. return; // no project file, or no [MAP] section
  276. char szNum[20];
  277. PSTR pszRest;
  278. GetArg(szNum, FirstNonSpace(pszDigit));
  279. strtol(FirstNonSpace(pszDigit), &pszRest, 0);
  280. int pos;
  281. if ((pos = mapread.m_ptblMap->IsPrimaryStringInTable(szNum))) {
  282. CStr cszSave(pszRest);
  283. int posAlias;
  284. BOOL fAliased = mapread.m_ptblAlias && (posAlias =
  285. mapread.m_ptblAlias->IsStringInTable(mapread.m_ptblMap->GetPointer(pos + 1)));
  286. wsprintf(pszDigit, " %s%s%s (%s)%s",
  287. mapread.m_ptblMap->GetPointer(pos + 1),
  288. fAliased ? ">" : "",
  289. fAliased ? mapread.m_ptblAlias->GetPointer(posAlias + 1) : "",
  290. szNum, cszSave.psz);
  291. }
  292. }
  293. /***************************************************************************
  294. FUNCTION: ReplaceStrings
  295. PURPOSE: Replace one string with another in a string
  296. PARAMETERS:
  297. pszCur -- pointer to the buffer
  298. pszOrg -- original string to be replaced
  299. pszNew -- string to replace with
  300. RETURNS:
  301. COMMENTS:
  302. This will move the buffer to make room for the new string
  303. MODIFICATION DATES:
  304. 08-Mar-1995 [ralphw]
  305. ***************************************************************************/
  306. static void STDCALL ReplaceStrings(PSTR pszCur, PCSTR pszOrg, PCSTR pszNew)
  307. {
  308. ASSERT(nstrisubcmp(pszCur, pszOrg));
  309. MoveMemory(pszCur + strlen(pszNew) - strlen(pszOrg), pszCur,
  310. strlen(pszCur) + 1);
  311. while (*pszNew)
  312. *pszCur++ = *pszNew++;
  313. }