fphelp.pas 24 KB

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