fphelp.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Help routines for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPHelp;
  12. {$ifdef cpullvm}
  13. {$modeswitch nestedprocvars}
  14. {$endif}
  15. {$H-}
  16. interface
  17. uses
  18. Drivers,
  19. FVConsts,
  20. WHelp,WHlpView,WHTML,
  21. WEditor,WCEdit,
  22. WViews,WHTMLScn,
  23. FPViews;
  24. type
  25. PIDEStatusLine = ^TIDEStatusLine;
  26. TIDEStatusLine = object(TAdvancedStatusLine)
  27. function Hint(AHelpCtx: Word): String; virtual;
  28. procedure HandleEvent(var Event: TEvent); virtual;
  29. end;
  30. PFPHTMLFileLinkScanner = ^TFPHTMLFileLinkScanner;
  31. TFPHTMLFileLinkScanner = object(THTMLFileLinkScanner)
  32. function CheckURL(const URL: string): boolean; virtual;
  33. function CheckText(const Text: string): boolean; virtual;
  34. procedure ProcessDoc(Doc: PHTMLLinkScanFile); virtual;
  35. end;
  36. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  37. procedure HelpIndex(Keyword: string);
  38. procedure HelpTopicSearch(Editor: PEditor);
  39. procedure HelpTopic(const S: string);
  40. procedure CloseHelpWindows;
  41. procedure HelpDebugInfos;
  42. procedure InitHelpSystem;
  43. procedure DoneHelpSystem;
  44. procedure InitHelpFiles;
  45. procedure DoneHelpFiles;
  46. procedure CheckHelpSystem;
  47. procedure PushStatus(S: string);
  48. procedure SetStatus(S: string);
  49. procedure ClearStatus;
  50. procedure PopStatus;
  51. const
  52. HelpWindow : PFPHelpWindow = nil;
  53. HelpInited : boolean = false;
  54. implementation
  55. uses Objects,Views,App,MsgBox,
  56. WUtils,WOAHelp,WHTMLHlp,WNGHelp,WOS2Help,WVPHelp,WWinHelp,
  57. FPConst,FPVars,FPUtils;
  58. const
  59. MaxStatusLevel = 10;
  60. {$if MaxViewWidth < 256}
  61. var StatusStack : array[0..MaxStatusLevel] of string[MaxViewWidth];
  62. {$else}
  63. var StatusStack : array[0..MaxStatusLevel] of string[255{MaxViewWidth}];
  64. {$endif}
  65. const
  66. StatusStackPtr : integer = 0;
  67. {$ifdef useresstrings}
  68. resourcestring
  69. {$else}
  70. const
  71. {$endif}
  72. dialog_help = 'Help';
  73. msg_modalhelpnotimplemented = 'Sorry, modal help not yet implemented.';
  74. { Help messages }
  75. msg_indexingfile = 'Indexing file %s';
  76. msg_loadinghelpfiles = 'Loading help files...';
  77. msg_loadinghelpfile = 'Loading help file...';
  78. msg_buildinghelpindex = 'Building Help Index...';
  79. msg_locatingtopic = 'Locating topic...';
  80. msg_failedtoloadhelpfile = 'Failed to load help file %s';
  81. { Menu hints }
  82. hint_systemmenu = 'System menu';
  83. hint_update = 'Refresh and redraw display';
  84. hint_about = 'Show version and copyright information';
  85. hint_filemenu = 'File management commands (Open, New, Save, etc.)';
  86. hint_filenew = 'Create a new file in a new edit window';
  87. hint_filenewfromtemplate='Create a new file using a code template';
  88. hint_fileopen = 'Locate and open a file in an edit window';
  89. hint_filesave = 'Save the file in the active edit window';
  90. hint_filesaveas = 'Save the current file under a different name, directory or drive';
  91. hint_filesaveall = 'Save all modified files';
  92. hint_print = 'Print current file';
  93. hint_printersetup = 'Setup printer output device';
  94. hint_changedir = 'Choose a new default directory';
  95. hint_dosshell = 'Temporarily exit to shell';
  96. hint_exit = 'Exit the IDE';
  97. hint_openrecentfile = 'Open ';
  98. hint_editmenu = 'Clipboard editing commands';
  99. hint_editundo = 'Undo the previous editor operation';
  100. hint_editredo = 'Redo the previously undone editor operation';
  101. hint_editcut = 'Remove the selected text and put it in the clipboard';
  102. hint_editcopy = 'Copy the selected text in the clipboard';
  103. hint_editpaste = 'Insert selected text from the clipboard at the cursor position';
  104. {$ifdef HASAMIGA}
  105. {$ifdef AROS}
  106. hint_editcopywin = 'Copy the selected text in AROS clipboard';
  107. hint_editpastewin = 'Insert selected text from AROS clipboard at the cursor position';
  108. {$else}
  109. hint_editcopywin = 'Copy the selected text to the system clipboard';
  110. hint_editpastewin = 'Insert selected text from the system clipboard at the cursor position';
  111. {$endif}
  112. {$else}
  113. hint_editcopywin = 'Copy the selected text in windows clipboard';
  114. hint_editpastewin = 'Insert selected text from windows clipboard at the cursor position';
  115. {$endif}
  116. hint_editclear = 'Delete the selected text';
  117. hint_editselectall = 'Select the whole text';
  118. hint_editunselect = 'Unselect everything';
  119. hint_showclipboard = 'Open then clipboard window';
  120. hint_commentsel = 'Insert line comment in front of each selected line';
  121. hint_uncommentsel = 'Remove line comment (if any) from beginning of every selected line';
  122. hint_searchmenu = 'Text and symbols search commands';
  123. hint_searchfind = 'Search for text';
  124. hint_searchreplace = 'Search for text and replace it with new text';
  125. hint_replaceagain = 'Repeat the last Replace command (%s with %s)';
  126. hint_searchagain = 'Repeat the last Search command (%s)';
  127. hint_gotoline = 'Move the cursor to a specified line number';
  128. hint_objects = 'Open a browser displaying all objects in the program';
  129. hint_modules = 'Open a browser displaying all modules of the program';
  130. hint_globals = 'Open a browser displaying all global symbols in the program';
  131. hint_symbol = 'Open a browser a current word (not yet scope sensitive)';
  132. hint_runmenu = 'Execution and parameters';
  133. hint_run = 'Run the current program';
  134. hint_rundir = 'Set directory that will be used as current working directory at execution';
  135. hint_runparameters = 'Set command-line parameters passed to program at execution';
  136. hint_resetprogram = 'Reset Program';
  137. hint_rununtilcursor = 'Go on until Cursor position';
  138. hint_rununtilreturn = 'Go on until end of current function';
  139. hint_userscreen = 'Switch to the full-screen user output';
  140. hint_compilemenu = 'Compile, build & make';
  141. hint_compile = 'Compile the current source file';
  142. hint_make = 'Rebuild source file and all other files that have been modified';
  143. hint_build = 'Rebuild program and all available source files';
  144. hint_target = 'Select target platform to compile for';
  145. hint_primaryfile = 'Define the file that is the focus of Make and Build';
  146. hint_clearprimaryfile = 'Clear the file previously set to Primary';
  147. hint_information = 'Show compiler messages and program information';
  148. hint_showmessages = 'Show compiler messages window';
  149. hint_debugmenu = 'Debug Program';
  150. hint_togglebreakpoint = 'Toggles Breakpoint';
  151. hint_createnewbreakpoint = 'Create a new breakpoint';
  152. hint_editbreakpoint = 'Edit focused breakpoint';
  153. hint_deletebreakpoint = 'Delete focused breakpoint';
  154. hint_opengdbwindow = 'Open direct window to GDB';
  155. hint_addwatch = 'Add a new expression to watch';
  156. hint_watches = 'Open the Watches Window';
  157. hint_callstack = 'Show call stack';
  158. hint_editbreakpoints = 'Edit breakpoints';
  159. hint_toolsmenu = 'User installed tools';
  160. hint_calculator = 'Show calculator';
  161. hint_grep = 'Run grep';
  162. hint_gotosource = 'Edit source';
  163. hint_registers = 'Open the Registers Window';
  164. hint_fpuregisters = 'Open the FPU Registers Window';
  165. hint_vectorregisters = 'Open the Vector Registers Window';
  166. hint_messageswindow = 'Open the message window';
  167. hint_gotonextmsg = 'Jumps to the next message in the Message Window';
  168. hint_gotoprevmsg = 'Jumps to the previous message in the Message Window';
  169. hint_usertool = 'User installed tool';
  170. hint_asciitable = 'Show ASCII table';
  171. hint_optionsmenu = 'Setting for compiler, editor, mouse, etc.';
  172. hint_switchesmode = 'Select settings for normal, debug or release version';
  173. hint_compiler = 'Set default compiler directives and conditional defines';
  174. hint_memorysizes = 'Set default stack and heap sizes for generated programs';
  175. hint_linkeroptions = 'Set linker options';
  176. hint_debugoptions = 'Set debug information options';
  177. hint_remotedialog = 'Set remote protocol parameters';
  178. hint_transferremote = 'Transfer executable to remote target';
  179. hint_directories = 'Set paths for units, include, object and generated files';
  180. hint_browser = 'Specify global browser settings';
  181. hint_reloadmodifiedfile= 'Reload file modified on disk';
  182. hint_tools = 'Create or change tools';
  183. hint_environmentmenu = 'Specify environment settins';
  184. hint_preferences = 'Specify preferences settings';
  185. hint_editoroptions = 'Specify default editor settings';
  186. hint_codecomplete = 'Specify CodeComplete keywords';
  187. hint_codetemplates = 'Specify CodeTemplates';
  188. hint_mouseoptions = 'Specify mouse settings';
  189. hint_desktopoptions = 'Specify desktop settings';
  190. hint_startup = 'Permanently change default startup options';
  191. hint_colors = 'Customize IDE colors for windows, menus, editors, etc.';
  192. hint_openini = 'Load a previously saved options file';
  193. hint_saveini = 'Save all the changes made in the options menu';
  194. hint_saveasini = 'Save all the changes made under a different name';
  195. hint_windowmenu = 'Windows management commands';
  196. hint_tile = 'Arrange windows on desktop by tiling';
  197. hint_cascade = 'Arrange windows on desktop by cascading';
  198. hint_stepped = 'Arrange windows on desktop by stepping';
  199. hint_closeall = 'Close all windows on the desktop';
  200. hint_resize = 'Change the size/postion of the active window';
  201. hint_zoom = 'Enlarge or restore the size of the active window';
  202. hint_next = 'Make the next window active';
  203. hint_prev = 'Make the previous window active';
  204. hint_hide = 'Hide the current window';
  205. hint_closewindow = 'Close the active window';
  206. hint_windowlist = 'Show a list of all open windows';
  207. hint_userscreenwindow = 'Show contents of user screen in a window';
  208. hint_helpmenu = 'Get online help';
  209. hint_helpcontents = 'Show table of contents for Online Help';
  210. hint_helpindex = 'Show index for Online Help';
  211. hint_helptopicsearch = 'Display help on the word at cursor';
  212. hint_helpprevtopic = 'Redisplay the last-viewed Online Help screen';
  213. hint_helphowtouse = 'How to use Online Help';
  214. hint_helpfiles = 'Install or remove installed help files';
  215. hint_openatcursor = 'Attempt to open the file indicated by the word at cursor';
  216. hint_browseatcursor = 'Attempt to browse the symbol at cursor';
  217. hint_editoroptionscur = 'Specify editor settings';
  218. hint_rawgdbwindow = 'Raw GDB communication window';
  219. hint_disassemblywindow = 'Show mixed Assembly/Source window';
  220. hint_allbreakpoints = 'All current breakpoints';
  221. procedure TIDEStatusLine.HandleEvent(var Event: TEvent);
  222. begin
  223. case Event.What of
  224. evBroadcast :
  225. case Event.Command of
  226. cmUpdate : Update;
  227. end;
  228. end;
  229. inherited HandleEvent(Event);
  230. end;
  231. function TIDEStatusLine.Hint(AHelpCtx: Word): String;
  232. var S: string;
  233. begin
  234. case AHelpCtx of
  235. hcNoContext : S:='';
  236. hcDragging : S:='';
  237. hcSourceWindow : S:='';
  238. hcHelpWindow : S:='';
  239. hcCalcWindow : S:='';
  240. hcInfoWindow : S:='';
  241. hcClipboardWindow:S:='';
  242. hcBrowserWindow : S:='';
  243. hcMessagesWindow: S:='';
  244. hcCompilerMessagesWindow: S:='';
  245. hcASCIITableWindow: S:='';
  246. hcGDBWindow : S:=hint_rawgdbwindow;
  247. hcDisassemblyWindow : S:=hint_disassemblywindow;
  248. hcBreakpointListWindow : S:=hint_allbreakpoints;
  249. hcSystemMenu : S:=hint_systemmenu;
  250. hcUpdate : S:=hint_update;
  251. hcAbout : S:=hint_about;
  252. hcFileMenu : S:=hint_filemenu;
  253. hcNew : S:=hint_filenew;
  254. hcNewFromTemplate:S:=hint_filenewfromtemplate;
  255. hcOpen : S:=hint_fileopen;
  256. hcSave : S:=hint_filesave;
  257. hcSaveAs : S:=hint_filesaveas;
  258. hcSaveAll : S:=hint_filesaveall;
  259. hcPrint : S:=hint_print;
  260. hcPrinterSetup : S:=hint_printersetup;
  261. hcChangeDir : S:=hint_changedir;
  262. hcDOSShell : S:=hint_dosshell;
  263. hcQuit : S:=hint_exit;
  264. hcRecentFileBase..hcRecentFileBase+10
  265. : S:=hint_openrecentfile+RecentFiles[AHelpCtx-hcRecentFileBase].FileName;
  266. hcEditMenu : S:=hint_editmenu;
  267. hcUndo : S:=hint_editundo;
  268. hcRedo : S:=hint_editredo;
  269. hcCut : S:=hint_editcut;
  270. hcCopy : S:=hint_editcopy;
  271. hcPaste : S:=hint_editpaste;
  272. hcSelectAll : S:=hint_editselectall;
  273. hcUnselect : S:=hint_editunselect;
  274. hcCopyWin : S:=hint_editcopywin;
  275. hcPasteWin : S:=hint_editpastewin;
  276. hcClear : S:=hint_editclear;
  277. hcShowClipboard : S:=hint_showclipboard;
  278. hcCommentSel : S:=hint_commentsel;
  279. hcUnCommentSel : S:=hint_uncommentsel;
  280. hcSearchMenu : S:=hint_searchmenu;
  281. hcFind : S:=hint_searchfind;
  282. hcReplace : S:=hint_searchreplace;
  283. hcSearchAgain : begin
  284. if (FindFlags and ffDoReplace)<>0 then
  285. s:=formatstrstr2(hint_replaceagain,findstr,WEditor.replacestr)
  286. else
  287. s:=formatstrstr(hint_searchagain,findstr);
  288. end;
  289. hcGotoLine : S:=hint_gotoline;
  290. hcObjects : S:=hint_objects;
  291. hcModules : S:=hint_modules;
  292. hcGlobals : S:=hint_globals;
  293. hcSymbol : S:=hint_symbol;
  294. hcRunMenu : S:=hint_runmenu;
  295. hcRun : S:=hint_run;
  296. hcRunDir : S:=hint_rundir;
  297. hcParameters : S:=hint_runparameters;
  298. hcResetDebugger : S:=hint_resetprogram;
  299. hcContToCursor : S:=hint_rununtilcursor;
  300. hcUntilReturn : S:=hint_rununtilreturn;
  301. hcUserScreen : S:=hint_userscreen;
  302. hcCompileMenu : S:=hint_compilemenu;
  303. hcCompile : S:=hint_compile;
  304. hcMake : S:=hint_make;
  305. hcBuild : S:=hint_build;
  306. hcTarget : S:=hint_target;
  307. hcPrimaryFile : S:=hint_primaryfile;
  308. hcClearPrimary : S:=hint_clearprimaryfile;
  309. hcCompilerMessages:S:=hint_showmessages;
  310. hcDebugMenu : S:=hint_debugmenu;
  311. hcToggleBreakpoint : S:=hint_togglebreakpoint;
  312. hcNewBreakpoint : S:=hint_createnewbreakpoint;
  313. hcEditBreakpoint : S:=hint_editbreakpoint;
  314. hcDeleteBreakpoint : S:=hint_deletebreakpoint;
  315. hcOpenGDBWindow : S:=hint_opengdbwindow;
  316. hcAddWatch : S:=hint_addwatch;
  317. hcWatchesWindow : S:=hint_watches;
  318. hcStackWindow : S:=hint_callstack;
  319. hcBreakpointList : S:=hint_editbreakpoints;
  320. hcToolsMenu : S:=hint_toolsmenu;
  321. hcCalculator : S:=hint_calculator;
  322. hcGrep : S:=hint_grep;
  323. hcMsgGotoSource : S:=hint_gotosource;
  324. hcRegistersWindow : S:=hint_registers;
  325. hcFPURegisters : S:=hint_FPURegisters;
  326. hcVectorRegisters : S:=hint_VectorRegisters;
  327. hcToolsMessages : S:=hint_messageswindow;
  328. hcToolsMsgNext : S:=hint_gotonextmsg;
  329. hcToolsMsgPrev : S:=hint_gotoprevmsg;
  330. hcToolsBase..
  331. hcToolsBase+MaxToolCount
  332. : S:=hint_usertool;
  333. hcASCIITable : S:=hint_asciitable;
  334. hcOptionsMenu : S:=hint_optionsmenu;
  335. hcSwitchesMode : S:=hint_switchesmode;
  336. hcCompiler,
  337. hcCompilerNoAltX : S:=hint_compiler;
  338. hcMemorySizes : S:=hint_memorysizes;
  339. hcLinker : S:=hint_linkeroptions;
  340. hcDebugger : S:=hint_debugoptions;
  341. hcDirectories : S:=hint_directories;
  342. hcBrowser,
  343. hcBrowserOptions: S:=hint_browser;
  344. hcTools : S:=hint_tools;
  345. hcRemoteDialog : S:=hint_remotedialog;
  346. hcTransferRemote: S:=hint_transferremote;
  347. hcDoReload : S:=hint_reloadmodifiedfile;
  348. hcEnvironmentMenu:S:=hint_environmentmenu;
  349. hcPreferences : S:=hint_preferences;
  350. hcEditor : S:=hint_editoroptions;
  351. hcCodeCompleteOptions:S:=hint_codecomplete;
  352. hcCodeTemplateOptions:S:=hint_codetemplates;
  353. hcMouse : S:=hint_mouseoptions;
  354. hcDesktopOptions: S:=hint_desktopoptions;
  355. hcStartup : S:=hint_startup;
  356. hcColors : S:=hint_colors;
  357. hcOpenINI : S:=hint_openini;
  358. hcSaveINI : S:=hint_saveini;
  359. hcSaveAsINI : S:=hint_saveasini;
  360. hcWindowMenu : S:=hint_windowmenu;
  361. hcTile : S:=hint_tile;
  362. hcCascade : S:=hint_cascade;
  363. hcStepped : S:=hint_stepped;
  364. hcCloseAll : S:=hint_closeall;
  365. hcResize : S:=hint_resize;
  366. hcZoom : S:=hint_zoom;
  367. hcNext : S:=hint_next;
  368. hcPrev : S:=hint_prev;
  369. hcHide : S:=hint_hide;
  370. hcClose : S:=hint_closewindow;
  371. hcWindowList : S:=hint_windowlist;
  372. hcUserScreenWindow:S:=hint_userscreenwindow;
  373. hcHelpMenu : S:=hint_helpmenu;
  374. hcHelpContents : S:=hint_helpcontents;
  375. hcHelpIndex : S:=hint_helpindex;
  376. hcHelpTopicSearch:S:=hint_helptopicsearch;
  377. hcHelpPrevTopic : S:=hint_helpprevtopic;
  378. hcHelpUsingHelp : S:=hint_helphowtouse;
  379. hcHelpFiles : S:=hint_helpfiles;
  380. hcOpenAtCursor : S:=hint_openatcursor;
  381. hcBrowseAtCursor: S:=hint_browseatcursor;
  382. hcEditorOptions : S:=hint_editoroptionscur;
  383. else S:='???';
  384. end;
  385. Hint:=S;
  386. end;
  387. procedure TFPHTMLFileLinkScanner.ProcessDoc(Doc: PHTMLLinkScanFile);
  388. begin
  389. PushStatus(FormatStrStr(msg_indexingfile,Doc^.GetDocumentURL));
  390. inherited ProcessDoc(Doc);
  391. PopStatus;
  392. end;
  393. function TFPHTMLFileLinkScanner.CheckURL(const URL: string): boolean;
  394. var OK: boolean;
  395. const HTTPPrefix = 'http:';
  396. FTPPrefix = 'ftp:';
  397. begin
  398. OK:=inherited CheckURL(URL);
  399. if OK then OK:=DirAndNameOf(URL)<>'';
  400. if OK then OK:=CompareText(copy(ExtOf(URL),1,4),'.HTM')=0;
  401. if OK then OK:=CompareText(copy(URL,1,length(HTTPPrefix)),HTTPPrefix)<>0;
  402. if OK then OK:=CompareText(copy(URL,1,length(FTPPrefix)),FTPPrefix)<>0;
  403. CheckURL:=OK;
  404. end;
  405. function TFPHTMLFileLinkScanner.CheckText(const Text: string): boolean;
  406. var OK: boolean;
  407. i : sw_integer;
  408. S: string;
  409. begin
  410. S:=Trim(Text);
  411. OK:=(S<>'') and (S[1]<>'[') and (S[1]<>',');
  412. { remove all Indexes }
  413. if s[1] in ['0'..'9'] then
  414. begin
  415. i:=1;
  416. while (i<length(s)) and (s[i] in ['0'..'9']) do
  417. inc(i);
  418. if (i<length(s)) and (s[i] in [' ',#9,'.']) then
  419. OK:=false;
  420. end;
  421. CheckText:=OK;
  422. end;
  423. procedure InitHelpSystem;
  424. procedure AddHelpFile(HelpFile,Param: string);
  425. begin
  426. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  427. if HelpFacility^.AddFile(HelpFile,Param)=nil then
  428. ErrorBox(FormatStrStr(msg_failedtoloadhelpfile,HelpFile),nil);
  429. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile);{$ENDIF}
  430. end;
  431. var I,P: sw_integer;
  432. S: string;
  433. Param: string;
  434. begin
  435. New(HelpFacility, Init);
  436. WOAHelp.RegisterHelpType;
  437. WNGHelp.RegisterHelpType;
  438. WOS2Help.RegisterHelpType;
  439. WWinHelp.RegisterHelpType;
  440. WVPHelp.RegisterHelpType;
  441. WHTMLHlp.RegisterHelpType; // Also registers chm and html index (.htx)
  442. PushStatus(msg_LoadingHelpFiles);
  443. for I:=0 to HelpFiles^.Count-1 do
  444. begin
  445. S:=HelpFiles^.At(I)^; Param:='';
  446. P:=Pos('|',S);
  447. if P>0 then
  448. begin Param:=copy(S,P+1,High(S)); S:=copy(S,1,P-1); end;
  449. AddHelpFile(S,Param);
  450. end;
  451. PopStatus;
  452. end;
  453. procedure CheckHelpSystem;
  454. begin
  455. if HelpInited then Exit;
  456. InitHelpSystem;
  457. HelpInited:=true;
  458. end;
  459. procedure DoneHelpSystem;
  460. begin
  461. if assigned(HelpFacility) then
  462. begin
  463. Dispose(HelpFacility, Done);
  464. HelpFacility:=nil;
  465. end;
  466. HelpInited:=false;
  467. end;
  468. procedure HelpCreateWindow;
  469. var R: TRect;
  470. begin
  471. CheckHelpSystem;
  472. if HelpWindow=nil then
  473. begin
  474. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  475. New(HelpWindow, Init(R, dialog_help, 0, 0, SearchFreeWindowNo));
  476. if HelpWindow<>nil then
  477. begin
  478. HelpWindow^.Hide;
  479. Desktop^.Insert(HelpWindow);
  480. end;
  481. end;
  482. end;
  483. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  484. begin
  485. if Modal then
  486. begin MessageBox(msg_modalhelpnotimplemented,nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  487. HelpCreateWindow;
  488. with HelpWindow^ do
  489. begin
  490. HelpWindow^.ShowTopic(FileID,Context);
  491. if GetState(sfVisible)=false then Show;
  492. MakeFirst;
  493. end;
  494. Message(Application,evCommand,cmUpdate,nil);
  495. end;
  496. procedure HelpTopicSearch(Editor: PEditor);
  497. var S: string;
  498. begin
  499. if Editor=nil then S:='' else
  500. S:=GetEditorCurWord(Editor,[]);
  501. HelpTopic(S);
  502. end;
  503. procedure HelpTopic(const S: string);
  504. var FileID: word;
  505. Ctx : THelpCtx;
  506. var Found: boolean;
  507. begin
  508. CheckHelpSystem;
  509. PushStatus(msg_LocatingTopic);
  510. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  511. PopStatus;
  512. if Found then
  513. Help(FileID,Ctx,false)
  514. else
  515. HelpIndex(S);
  516. end;
  517. procedure HelpIndex(Keyword: string);
  518. begin
  519. HelpCreateWindow;
  520. with HelpWindow^ do
  521. begin
  522. PushStatus(msg_BuildingHelpIndex);
  523. HelpWindow^.ShowIndex;
  524. if Keyword<>'' then
  525. HelpWindow^.HelpView^.Lookup(Keyword);
  526. PopStatus;
  527. if GetState(sfVisible)=false then Show;
  528. MakeFirst;
  529. end;
  530. Message(Application,evCommand,cmUpdate,nil);
  531. end;
  532. procedure HelpDebugInfos;
  533. begin
  534. HelpCreateWindow;
  535. HelpWindow^.ShowDebugInfos;
  536. end;
  537. procedure PushStatus(S: string);
  538. begin
  539. if StatusLine=nil then
  540. Exit;
  541. If StatusStackPtr<=MaxStatusLevel then
  542. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  543. else
  544. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  545. SetStatus(S);
  546. Inc(StatusStackPtr);
  547. end;
  548. procedure PopStatus;
  549. begin
  550. if StatusLine=nil then
  551. Exit;
  552. Dec(StatusStackPtr);
  553. If StatusStackPtr<=MaxStatusLevel then
  554. SetStatus(StatusStack[StatusStackPtr])
  555. else
  556. SetStatus(StatusStack[MaxStatusLevel]);
  557. end;
  558. procedure SetStatus(S: string);
  559. begin
  560. if StatusLine=nil then
  561. Exit;
  562. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  563. end;
  564. procedure ClearStatus;
  565. begin
  566. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  567. end;
  568. function FPHTMLGetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  569. var OK: boolean;
  570. S: string;
  571. begin
  572. Color:=0;
  573. OK:=(ord(Section) in [1..length(CHTMLSectionAttrs)]);
  574. if OK then
  575. begin
  576. S:=#0;
  577. S:=copy(CHTMLSectionAttrs,ord(Section),1);
  578. if Assigned(Application)=false then Color:=0 else
  579. Color:=Application^.GetColor(ord(S[1]));
  580. if (Color and $0f) = ((Color and $f0) shr 4) then { same color ? }
  581. OK:=false;
  582. end;
  583. FPHTMLGetSectionColor:=OK;
  584. end;
  585. function FPNGGetAttrColor(Attr: AnsiChar; var Color: byte): boolean;
  586. var OK: boolean;
  587. begin
  588. OK:=false;
  589. case Attr of
  590. 'A' : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  591. 'B' : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  592. 'b' : OK:=FPHTMLGetSectionColor(hsHeading5,Color);
  593. 'U' : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  594. 'N' : OK:=FPHTMLGetSectionColor(hsHeading4,Color);
  595. {$ifdef DEBUGMSG}
  596. else ErrorBox('Unknown attr encountered : "'+Attr+'"',nil);
  597. {$endif}
  598. end;
  599. FPNGGetAttrColor:=OK;
  600. end;
  601. function FPINFGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  602. var OK: boolean;
  603. begin
  604. OK:=false;
  605. case TextColor of
  606. 1 : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  607. 2 : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  608. 3 : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  609. end;
  610. FPINFGetAttrColor:=OK;
  611. end;
  612. procedure InitHelpFiles;
  613. begin
  614. HTMLGetSectionColor:={$ifdef FPC}@{$endif}FPHTMLGetSectionColor;
  615. NGGetAttrColor:={$ifdef FPC}@{$endif}FPNGGetAttrColor;
  616. INFGetAttrColor:={$ifdef FPC}@{$endif}FPINFGetAttrColor;
  617. New(HelpFiles, Init(10,10));
  618. end;
  619. procedure DoneHelpFiles;
  620. begin
  621. if assigned(HelpFiles) then
  622. Dispose(HelpFiles, Done);
  623. end;
  624. procedure CloseHelpWindows;
  625. procedure CloseIfHelpWindow(P: PView);
  626. begin
  627. if P^.HelpCtx=hcHelpWindow then
  628. begin
  629. Message(P,evCommand,cmClose,nil);
  630. {Dispose(P, Done); help windows are only hidden on close so we've
  631. to destroy them manually
  632. but this was wrong as it was not correctly
  633. resetting the corresponding pointer in whelp unit PM }
  634. end;
  635. end;
  636. begin
  637. Desktop^.ForEach(TCallbackProcParam(@CloseIfHelpWindow));
  638. end;
  639. END.