fphelp.pas 24 KB

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