fphelp.pas 24 KB

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