fphelp.pas 24 KB

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