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.

371 lines
9.2 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // help.c - help functions
  24. ////
  25. #include "winlocal.h"
  26. #include <stdlib.h>
  27. #include "help.h"
  28. #include "mem.h"
  29. #include "str.h"
  30. #include "trace.h"
  31. ////
  32. // private definitions
  33. ////
  34. // help control struct
  35. //
  36. typedef struct HELP
  37. {
  38. DWORD dwVersion;
  39. HINSTANCE hInst;
  40. HTASK hTask;
  41. HWND hwndFrame;
  42. TCHAR szHelpFile[_MAX_PATH];
  43. UINT idContents;
  44. } HELP, FAR *LPHELP;
  45. // helper functions
  46. //
  47. static LPHELP HelpGetPtr(HHELP hHelp);
  48. static HHELP HelpGetHandle(LPHELP lpHelp);
  49. static int HelpQuit(HHELP hHelp);
  50. ////
  51. // public functions
  52. ////
  53. // HelpInit - initialize help engine
  54. // <dwVersion> (i) must be HELP_VERSION
  55. // <hInst> (i) instance handle of calling module
  56. // <hwndFrame> (i) frame window of the calling program
  57. // <lpszHelpFile> (i) help file to display
  58. // return handle (NULL if error)
  59. //
  60. HHELP DLLEXPORT WINAPI HelpInit(DWORD dwVersion, HINSTANCE hInst, HWND hwndFrame, LPCTSTR lpszHelpFile)
  61. {
  62. BOOL fSuccess = TRUE;
  63. LPHELP lpHelp = NULL;
  64. if (dwVersion != HELP_VERSION)
  65. fSuccess = TraceFALSE(NULL);
  66. else if (hInst == NULL)
  67. fSuccess = TraceFALSE(NULL);
  68. else if (hwndFrame == NULL)
  69. fSuccess = TraceFALSE(NULL);
  70. else if (lpszHelpFile == NULL)
  71. fSuccess = TraceFALSE(NULL);
  72. else if ((lpHelp = (LPHELP) MemAlloc(NULL, sizeof(HELP), 0)) == NULL)
  73. fSuccess = TraceFALSE(NULL);
  74. else
  75. {
  76. lpHelp->dwVersion = dwVersion;
  77. lpHelp->hInst = hInst;
  78. lpHelp->hTask = GetCurrentTask();
  79. lpHelp->hwndFrame = hwndFrame;
  80. StrNCpy(lpHelp->szHelpFile, lpszHelpFile, SIZEOFARRAY(lpHelp->szHelpFile));
  81. lpHelp->idContents = 0;
  82. }
  83. if (!fSuccess)
  84. {
  85. HelpTerm(HelpGetHandle(lpHelp));
  86. lpHelp = NULL;
  87. }
  88. return fSuccess ? HelpGetHandle(lpHelp) : NULL;
  89. }
  90. // HelpTerm - shut down help engine
  91. // <hHelp> (i) handle returned by HelpInit
  92. // return 0 if success
  93. //
  94. int DLLEXPORT WINAPI HelpTerm(HHELP hHelp)
  95. {
  96. BOOL fSuccess = TRUE;
  97. LPHELP lpHelp;
  98. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  99. fSuccess = TraceFALSE(NULL);
  100. else if (HelpQuit(hHelp) != 0)
  101. fSuccess = TraceFALSE(NULL);
  102. else if ((lpHelp = MemFree(NULL, lpHelp)) != NULL)
  103. fSuccess = TraceFALSE(NULL);
  104. return fSuccess ? 0 : -1;
  105. }
  106. // HelpGetHelpFile - get help file name
  107. // <hHelp> (i) handle returned by HelpInit
  108. // <lpszHelpFile> (o) buffer to hold help file name
  109. // <sizHelpFile> (i) size of buffer
  110. // NULL do not copy; return static pointer instead
  111. // return pointer to help file name (NULL if error)
  112. //
  113. LPTSTR DLLEXPORT WINAPI HelpGetHelpFile(HHELP hHelp, LPTSTR lpszHelpFile, int sizHelpFile)
  114. {
  115. BOOL fSuccess = TRUE;
  116. LPHELP lpHelp;
  117. if ((lpHelp = (LPHELP) hHelp) == NULL)
  118. fSuccess = TraceFALSE(NULL);
  119. {
  120. // copy file name if destination buffer specified
  121. //
  122. if (lpszHelpFile != NULL)
  123. StrNCpy(lpszHelpFile, lpHelp->szHelpFile, sizHelpFile);
  124. // otherwise just point to static copy of file name
  125. //
  126. else
  127. lpszHelpFile = lpHelp->szHelpFile;
  128. }
  129. return fSuccess ? lpszHelpFile : NULL;
  130. }
  131. // HelpContents - display Help contents topic
  132. // <hHelp> (i) handle returned by HelpInit
  133. // return 0 if success
  134. //
  135. int DLLEXPORT WINAPI HelpContents(HHELP hHelp)
  136. {
  137. BOOL fSuccess = TRUE;
  138. LPHELP lpHelp;
  139. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  140. fSuccess = TraceFALSE(NULL);
  141. // use the default contents topic if no other has been set
  142. //
  143. else if (lpHelp->idContents == 0 &&
  144. !WinHelp(lpHelp->hwndFrame,
  145. lpHelp->szHelpFile, HELP_CONTENTS, 0L))
  146. fSuccess = TraceFALSE(NULL);
  147. // display the current contents topic
  148. //
  149. else if (lpHelp->idContents != 0
  150. && HelpContext(hHelp, lpHelp->idContents) != 0)
  151. fSuccess = TraceFALSE(NULL);
  152. return fSuccess ? 0 : -1;
  153. }
  154. // HelpOnHelp - display Help topic on using help
  155. // <hHelp> (i) handle returned by HelpInit
  156. // return 0 if success
  157. //
  158. int DLLEXPORT WINAPI HelpOnHelp(HHELP hHelp)
  159. {
  160. BOOL fSuccess = TRUE;
  161. LPHELP lpHelp;
  162. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  163. fSuccess = TraceFALSE(NULL);
  164. else if (!WinHelp(lpHelp->hwndFrame, lpHelp->szHelpFile,
  165. HELP_HELPONHELP, 0L))
  166. fSuccess = TraceFALSE(NULL);
  167. return fSuccess ? 0 : -1;
  168. }
  169. // HelpContext - display Help topic corresponding to specified context id
  170. // <hHelp> (i) handle returned by HelpInit
  171. // <idContext> (i) id of the topic to display
  172. // return 0 if success
  173. //
  174. int DLLEXPORT WINAPI HelpContext(HHELP hHelp, UINT idContext)
  175. {
  176. BOOL fSuccess = TRUE;
  177. #if 0
  178. TCHAR szKeyword[128];
  179. if (LoadString(lpHelp->hInst, idContext, szKeyword, SIZEOFARRAY(szKeyword)) <= 0)
  180. fSuccess = TraceFALSE(NULL);
  181. else if (HelpKeyword(hHelp, szKeyword) != 0)
  182. fSuccess = TraceFALSE(NULL);
  183. #else
  184. LPHELP lpHelp;
  185. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  186. fSuccess = TraceFALSE(NULL);
  187. else if (!WinHelp(lpHelp->hwndFrame, lpHelp->szHelpFile,
  188. HELP_CONTEXT, (DWORD) idContext))
  189. fSuccess = TraceFALSE(NULL);
  190. #endif
  191. return fSuccess ? 0 : -1;
  192. }
  193. // HelpKeyword - display Help topic corresponding to specified keyword
  194. // <hHelp> (i) handle returned by HelpInit
  195. // <lpszKeyword> (i) keyword of the topic to display
  196. // return 0 id success
  197. //
  198. int DLLEXPORT WINAPI HelpKeyword(HHELP hHelp, LPCTSTR lpszKeyword)
  199. {
  200. BOOL fSuccess = TRUE;
  201. LPHELP lpHelp;
  202. TCHAR szCommand[128];
  203. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  204. fSuccess = TraceFALSE(NULL);
  205. #if 0
  206. else if (!WinHelp(lpHelp->hwndFrame, lpHelp->szHelpFile,
  207. HELP_KEY, (DWORD) lpszKeyword))
  208. fSuccess = TraceFALSE(NULL);
  209. #else
  210. //
  211. // We should verify the lpHelp pointer
  212. //
  213. if( lpHelp )
  214. {
  215. if (wsprintf(szCommand, TEXT("JumpID(\"%s\", \"%s\")"),
  216. (LPTSTR) lpHelp->szHelpFile, (LPTSTR) lpszKeyword) <= 0)
  217. fSuccess = TraceFALSE(NULL);
  218. else if (!WinHelp(lpHelp->hwndFrame, lpHelp->szHelpFile,
  219. HELP_FORCEFILE, 0L))
  220. fSuccess = TraceFALSE(NULL);
  221. else if (!WinHelp(lpHelp->hwndFrame, lpHelp->szHelpFile,
  222. HELP_COMMAND, (DWORD_PTR) szCommand))
  223. fSuccess = TraceFALSE(NULL);
  224. }
  225. #endif
  226. return fSuccess ? 0 : -1;
  227. }
  228. // HelpGetContentsId - get Help contents topic id
  229. // <hHelp> (i) handle returned by HelpInit
  230. // return id of the current contents topic (0 if default, -1 if error)
  231. //
  232. int DLLEXPORT WINAPI HelpGetContentsId(HHELP hHelp)
  233. {
  234. BOOL fSuccess = TRUE;
  235. LPHELP lpHelp;
  236. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  237. fSuccess = TraceFALSE(NULL);
  238. return fSuccess ? lpHelp->idContents : -1;
  239. }
  240. // HelpSetContentsId - set Help contents topic id
  241. // <hHelp> (i) handle returned by HelpInit
  242. // <idContents> (i) new id of the contents topic
  243. // 0 set to default contents id
  244. // return 0 if success
  245. //
  246. int DLLEXPORT WINAPI HelpSetContentsId(HHELP hHelp, UINT idContents)
  247. {
  248. BOOL fSuccess = TRUE;
  249. LPHELP lpHelp;
  250. if ((lpHelp = HelpGetPtr(hHelp)) == NULL)
  251. fSuccess = TraceFALSE(NULL);
  252. else
  253. lpHelp->idContents = idContents;
  254. return fSuccess ? 0 : -1;
  255. }
  256. ////
  257. // helper functions
  258. ////
  259. // HelpGetPtr - verify that help handle is valid,
  260. // <hHelp> (i) handle returned by HelpInit
  261. // return corresponding help pointer (NULL if error)
  262. //
  263. static LPHELP HelpGetPtr(HHELP hHelp)
  264. {
  265. BOOL fSuccess = TRUE;
  266. LPHELP lpHelp;
  267. if ((lpHelp = (LPHELP) hHelp) == NULL)
  268. fSuccess = TraceFALSE(NULL);
  269. else if (IsBadWritePtr(lpHelp, sizeof(HELP)))
  270. fSuccess = TraceFALSE(NULL);
  271. #ifdef CHECKTASK
  272. // make sure current task owns the help handle
  273. //
  274. else if (lpHelp->hTask != GetCurrentTask())
  275. fSuccess = TraceFALSE(NULL);
  276. #endif
  277. return fSuccess ? lpHelp : NULL;
  278. }
  279. // HelpGetHandle - verify that help pointer is valid,
  280. // <lpHelp> (i) pointer to HELP struct
  281. // return corresponding help handle (NULL if error)
  282. //
  283. static HHELP HelpGetHandle(LPHELP lpHelp)
  284. {
  285. BOOL fSuccess = TRUE;
  286. HHELP hHelp;
  287. if ((hHelp = (HHELP) lpHelp) == NULL)
  288. fSuccess = TraceFALSE(NULL);
  289. return fSuccess ? hHelp : NULL;
  290. }
  291. // HelpQuit - close Help application if no other app needs it
  292. // <hHelp> (i) handle returned by HelpInit
  293. // return 0 if success
  294. //
  295. static int HelpQuit(HHELP hHelp)
  296. {
  297. BOOL fSuccess = TRUE;
  298. LPHELP lpHelp;
  299. if ((lpHelp = (LPHELP) hHelp) == NULL)
  300. fSuccess = TraceFALSE(NULL);
  301. else if (!WinHelp(lpHelp->hwndFrame, lpHelp->szHelpFile,
  302. HELP_QUIT, 0L))
  303. fSuccess = TraceFALSE(NULL);
  304. return fSuccess ? 0 : -1;
  305. }