fphelp.pas 24 KB

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