whlpview.pas 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Help display objects
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit WHlpView;
  13. interface
  14. uses
  15. Objects,Drivers,Views,
  16. FVConsts,
  17. WEditor,WCEdit,
  18. WUtils,WHelp;
  19. type
  20. TEditor = TCodeEditor;
  21. PEditor = PCodeEditor;
  22. const
  23. cmPrevTopic = 90;
  24. HistorySize = 30;
  25. CHelpViewer = #33#34#35#36;
  26. CHelpFrame = #37#37#38#38#39;
  27. cmHelpFilesChanged = 57340;
  28. type
  29. PHelpLink = ^THelpLink;
  30. THelpLink = record
  31. Bounds : TRect;
  32. FileID : longint;
  33. Context : THelpCtx;
  34. end;
  35. PHelpColorArea = ^THelpColorArea;
  36. THelpColorArea = record
  37. Color : byte;
  38. Bounds : TRect;
  39. AttrMask : byte;
  40. end;
  41. PHelpKeyword = ^THelpKeyword;
  42. THelpKeyword = record
  43. KWord : PString;
  44. Index : sw_integer;
  45. end;
  46. PLinkCollection = ^TLinkCollection;
  47. TLinkCollection = object(TCollection)
  48. procedure FreeItem(Item: Pointer); virtual;
  49. end;
  50. PColorAreaCollection = ^TColorAreaCollection;
  51. TColorAreaCollection = object(TCollection)
  52. procedure FreeItem(Item: Pointer); virtual;
  53. end;
  54. PKeywordCollection = ^TKeywordCollection;
  55. TKeywordCollection = object({TSorted}TCollection)
  56. function At(Index: sw_Integer): PHelpKeyword;
  57. procedure FreeItem(Item: Pointer); virtual;
  58. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  59. end;
  60. { TSearchRelation = (srEqual,srGreater,srLess,srGreatEqu,srLessEqu);
  61. PAdvancedStringCollection = ^TAdvancedStringCollection;
  62. TAdvancedStringCollection = object(TStringCollection)
  63. function SearchItem(Key: pointer; Rel: TSearchRelation; var Index: integer): boolean; virtual;
  64. end;}
  65. PNamedMark = ^TNamedMark;
  66. TNamedMark = object(TObject)
  67. constructor Init(const AName: string; AX, AY: integer);
  68. function GetName: string;
  69. destructor Done; virtual;
  70. private
  71. Name: PString;
  72. Pos: TPoint;
  73. end;
  74. PNamedMarkCollection = ^TNamedMarkCollection;
  75. TNamedMarkCollection = object(TSortedCollection)
  76. function At(Index: sw_Integer): PNamedMark;
  77. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  78. function SearchMark(const Name: string): PNamedMark;
  79. function GetMarkPos(const Name: string; var P: TPoint): boolean;
  80. procedure Add(const Name: string; P: TPoint);
  81. end;
  82. PLinePosCollection = ^TLinePosCollection;
  83. TLinePosCollection = object(TNoDisposeCollection)
  84. function At(Index: sw_Integer): sw_integer;
  85. procedure Insert (Item: ptrint);virtual;
  86. end;
  87. PHelpTopic = ^THelpTopic;
  88. THelpTopic = object(TObject)
  89. Topic: PTopic;
  90. Lines: PUnsortedStringCollection;
  91. LinesPos: PLinePosCollection;
  92. Links: PLinkCollection;
  93. NamedMarks: PNamedMarkCollection;
  94. ColorAreas: PColorAreaCollection;
  95. public
  96. constructor Init(ATopic: PTopic);
  97. procedure SetParams(AMargin, AWidth: sw_integer); virtual;
  98. function GetLineCount: sw_integer; virtual;
  99. function GetLineText(Line: sw_integer): string; virtual;
  100. function GetLinkCount: sw_integer; virtual;
  101. procedure GetLinkBounds(Index: sw_integer; var R: TRect); virtual;
  102. function GetLinkFileID(Index: sw_integer): word; virtual;
  103. function GetLinkContext(Index: sw_integer): THelpCtx; virtual;
  104. function GetColorAreaCount: sw_integer; virtual;
  105. procedure GetColorAreaBounds(Index: sw_integer; var R: TRect); virtual;
  106. function GetColorAreaColor(Index: sw_integer): word; virtual;
  107. function GetColorAreaMask(Index: sw_integer): word; virtual;
  108. destructor Done; virtual;
  109. private
  110. Width,Margin: sw_integer;
  111. { StockItem: boolean;}
  112. procedure ReBuild;
  113. end;
  114. THelpHistoryEntry = record
  115. Context_ : THelpCtx;
  116. Delta_ : TPoint;
  117. CurPos_ : TPoint;
  118. CurLink_ : sw_integer;
  119. FileID_ : word;
  120. end;
  121. PHelpViewer = ^THelpViewer;
  122. THelpViewer = object(TEditor)
  123. Margin: sw_integer;
  124. HelpTopic: PHelpTopic;
  125. CurLink: sw_integer;
  126. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  127. procedure ChangeBounds(var Bounds: TRect); virtual;
  128. procedure Draw; virtual;
  129. procedure HandleEvent(var Event: TEvent); virtual;
  130. procedure SetCurPtr(X,Y: sw_integer); virtual;
  131. function GetLineCount: sw_integer; virtual;
  132. function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  133. function GetLineText(Line: sw_integer): string; virtual;
  134. function GetDisplayText(I: sw_integer): string; virtual;
  135. function GetLinkCount: sw_integer; virtual;
  136. procedure GetLinkBounds(Index: sw_integer; var R: TRect); virtual;
  137. function GetLinkFileID(Index: sw_integer): word; virtual;
  138. function GetLinkContext(Index: sw_integer): THelpCtx; virtual;
  139. function GetLinkTarget(Index: sw_integer): string; virtual;
  140. function GetLinkText(Index: sw_integer): string; virtual;
  141. function GetColorAreaCount: sw_integer; virtual;
  142. procedure GetColorAreaBounds(Index: sw_integer; var R: TRect); virtual;
  143. function GetColorAreaColor(Index: sw_integer): word; virtual;
  144. function GetColorAreaMask(Index: sw_integer): word; virtual;
  145. procedure SelectNextLink(ANext: boolean); virtual;
  146. procedure SwitchToIndex; virtual;
  147. procedure SwitchToTopic(SourceFileID: word; Context: THelpCtx); virtual;
  148. procedure SetTopic(Topic: PTopic); virtual;
  149. procedure SetCurLink(Link: sw_integer); virtual;
  150. procedure SelectLink(Index: sw_integer); virtual;
  151. procedure PrevTopic; virtual;
  152. procedure RenderTopic; virtual;
  153. procedure Lookup(S: string); virtual;
  154. function GetPalette: PPalette; virtual;
  155. constructor Load(var S: TStream);
  156. procedure Store(var S: TStream);
  157. destructor Done; virtual;
  158. private
  159. History : array[0..HistorySize] of THelpHistoryEntry;
  160. HistoryPtr : integer;
  161. WordList : PKeywordCollection;
  162. Lookupword : string;
  163. InLookUp : boolean;
  164. IndexTopic : PTopic;
  165. IndexHelpTopic: PHelpTopic;
  166. function LinkContainsPoint(var R: TRect; var P: TPoint): boolean;
  167. procedure ISwitchToTopic(SourceFileID: word; Context: THelpCtx; RecordInHistory: boolean);
  168. procedure ISwitchToTopicPtr(P: PTopic; RecordInHistory: boolean);
  169. procedure BuildTopicWordList;
  170. end;
  171. PHelpFrame = ^THelpFrame;
  172. THelpFrame = object(TFrame)
  173. function GetPalette: PPalette; virtual;
  174. end;
  175. PHelpWindow = ^THelpWindow;
  176. THelpWindow = object(TWindow)
  177. HSB,VSB : PScrollBar;
  178. HelpView: PHelpViewer;
  179. HideOnClose: boolean;
  180. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word; AContext: THelpCtx; ANumber: Integer);
  181. procedure InitFrame; virtual;
  182. procedure InitScrollBars; virtual;
  183. procedure InitHelpView; virtual;
  184. procedure ShowIndex; virtual;
  185. procedure ShowTopic(SourceFileID: word; Context: THelpCtx); virtual;
  186. procedure HandleEvent(var Event: TEvent); virtual;
  187. procedure Close; virtual;
  188. function GetPalette: PPalette; virtual; { needs to be overriden }
  189. end;
  190. implementation
  191. uses
  192. Video,
  193. WConsts;
  194. const CommentColor = Blue;
  195. function NewLink(FileID: longint; Topic: THelpCtx; StartP, EndP: TPoint): PHelpLink;
  196. var P: PHelpLink;
  197. begin
  198. New(P); FillChar(P^, SizeOf(P^), 0);
  199. P^.FileID:=FileID;
  200. P^.Context:=Topic; P^.Bounds.A:=StartP; P^.Bounds.B:=EndP;
  201. NewLink:=P;
  202. end;
  203. procedure DisposeLink(P: PHelpLink);
  204. begin
  205. if P<>nil then Dispose(P);
  206. end;
  207. function NewColorArea(Color, AttrMask: byte; StartP, EndP: TPoint): PHelpColorArea;
  208. var P: PHelpColorArea;
  209. begin
  210. New(P); FillChar(P^, SizeOf(P^), 0);
  211. P^.Color:=Color; P^.AttrMask:=AttrMask;
  212. P^.Bounds.A:=StartP; P^.Bounds.B:=EndP;
  213. NewColorArea:=P;
  214. end;
  215. procedure DisposeColorArea(P: PHelpColorArea);
  216. begin
  217. if P<>nil then Dispose(P);
  218. end;
  219. function NewKeyword(Index: sw_integer; KWord: string): PHelpKeyword;
  220. var P: PHelpKeyword;
  221. begin
  222. New(P); FillChar(P^, SizeOf(P^), 0);
  223. P^.Index:=Index; P^.KWord:=NewStr(KWord);
  224. NewKeyword:=P;
  225. end;
  226. procedure DisposeKeyword(P: PHelpKeyword);
  227. begin
  228. if P<>nil then
  229. begin
  230. if P^.KWord<>nil then DisposeStr(P^.KWord);
  231. Dispose(P);
  232. end;
  233. end;
  234. procedure TLinkCollection.FreeItem(Item: Pointer);
  235. begin
  236. if Item<>nil then DisposeLink(Item);
  237. end;
  238. procedure TColorAreaCollection.FreeItem(Item: Pointer);
  239. begin
  240. if Item<>nil then DisposeColorArea(Item);
  241. end;
  242. function TKeywordCollection.At(Index: sw_Integer): PHelpKeyword;
  243. begin
  244. At:=inherited At(Index);
  245. end;
  246. procedure TKeywordCollection.FreeItem(Item: Pointer);
  247. begin
  248. if Item<>nil then DisposeKeyword(Item);
  249. end;
  250. function TKeywordCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  251. var R: sw_integer;
  252. K1: PHelpKeyword absolute Key1;
  253. K2: PHelpKeyword absolute Key2;
  254. S1,S2: string;
  255. begin
  256. S1:=UpcaseStr(K1^.KWord^); S2:=UpcaseStr(K2^.KWord^);
  257. if S1<S2 then R:=-1 else
  258. if S1>S2 then R:=1 else
  259. R:=0;
  260. Compare:=R;
  261. end;
  262. {function TAdvancedStringCollection.SearchItem(Key: pointer; Rel: TSearchRelation; var Index: sw_integer): boolean;
  263. var
  264. L, H, I, C: sw_Integer;
  265. const resSmaller = -1; resEqual = 0; resGreater = 1;
  266. begin
  267. Index:=-1;
  268. case Rel of
  269. srEqual :
  270. while (L <= H) and (Index=-1) do
  271. begin
  272. I := (L + H) shr 1;
  273. C := Compare(KeyOf(Items^[I]), Key);
  274. if C = resSmaller then L := I + 1 else
  275. begin
  276. H := I - 1;
  277. if C = resEqual then
  278. begin
  279. if not Duplicates then L := I;
  280. Index := L;
  281. end;
  282. end;
  283. end;
  284. srGreater :
  285. begin
  286. end;
  287. srLess :
  288. ;
  289. srGreatEqu :
  290. ;
  291. srLessEqu :
  292. ;
  293. else Exit;
  294. end;
  295. Search:=Index<>-1;
  296. end;}
  297. constructor TNamedMark.Init(const AName: string; AX, AY: integer);
  298. begin
  299. inherited Init;
  300. Name:=NewStr(AName);
  301. Pos.X:=AX; Pos.Y:=AY;
  302. end;
  303. function TNamedMark.GetName: string;
  304. begin
  305. GetName:=GetStr(Name);
  306. end;
  307. destructor TNamedMark.Done;
  308. begin
  309. if Assigned(Name) then DisposeStr(Name); Name:=nil;
  310. inherited Done;
  311. end;
  312. function TNamedMarkCollection.At(Index: sw_Integer): PNamedMark;
  313. begin
  314. At:=inherited At(Index);
  315. end;
  316. function TNamedMarkCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  317. var K1: PNamedMark absolute Key1;
  318. K2: PNamedMark absolute Key2;
  319. R: integer;
  320. N1,N2: string;
  321. begin
  322. N1:=UpcaseStr(K1^.GetName); N2:=UpcaseStr(K2^.GetName);
  323. if N1<N2 then R:=-1 else
  324. if N1>N2 then R:= 1 else
  325. R:=0;
  326. Compare:=R;
  327. end;
  328. function TNamedMarkCollection.SearchMark(const Name: string): PNamedMark;
  329. var M,P: PNamedMark;
  330. I: sw_integer;
  331. begin
  332. New(M, Init(Name,0,0));
  333. if Search(M,I)=false then P:=nil else
  334. P:=At(I);
  335. Dispose(M, Done);
  336. SearchMark:=P;
  337. end;
  338. function TNamedMarkCollection.GetMarkPos(const Name: string; var P: TPoint): boolean;
  339. var M: PNamedMark;
  340. begin
  341. M:=SearchMark(Name);
  342. if Assigned(M) then
  343. P:=M^.Pos;
  344. GetMarkPos:=Assigned(M);
  345. end;
  346. procedure TNamedMarkCollection.Add(const Name: string; P: TPoint);
  347. begin
  348. Insert(New(PNamedMark, Init(Name, P.X, P.Y)));
  349. end;
  350. function TLinePosCollection.At(Index: sw_Integer): sw_integer;
  351. begin
  352. at := longint (inherited at(Index));
  353. end;
  354. procedure TLinePosCollection.Insert (Item: ptrint);
  355. begin
  356. Inherited Insert(pointer(Item));
  357. end;
  358. constructor THelpTopic.Init(ATopic: PTopic);
  359. begin
  360. inherited Init;
  361. Topic:=ATopic;
  362. New(Lines, Init(100,100));
  363. New(LinesPos, Init(100,100));
  364. New(Links, Init(50,50));
  365. New(ColorAreas, Init(50,50));
  366. New(NamedMarks, Init(10,10));
  367. end;
  368. procedure THelpTopic.SetParams(AMargin, AWidth: sw_integer);
  369. begin
  370. if Width<>AWidth then
  371. begin
  372. Width:=AWidth; Margin:=AMargin;
  373. ReBuild;
  374. end;
  375. end;
  376. procedure THelpTopic.ReBuild;
  377. var TextPos,LinePos,LinkNo,NamedMarkNo: sw_word;
  378. Line,CurWord: string;
  379. C: char;
  380. InLink,InCodeArea,InColorArea,InImage: boolean;
  381. LinkStart,LinkEnd,CodeAreaStart,CodeAreaEnd: TPoint;
  382. ColorAreaStart,ColorAreaEnd: TPoint;
  383. ColorAreaType: (atText,atFull);
  384. CurPos: TPoint;
  385. ZeroLevel: sw_integer;
  386. LineStart,NextLineStart: sw_integer;
  387. LineAlign : (laLeft,laCenter,laRight);
  388. FirstLink,LastLink: sw_integer;
  389. AreaColor: word;
  390. NextByte: (nbNormal,nbAreaColor,nbDirect);
  391. procedure ClearLine;
  392. begin
  393. Line:='';
  394. end;
  395. procedure AddWord(TheWord: string); forward;
  396. procedure NextLine;
  397. var P: sw_integer;
  398. I,Delta: sw_integer;
  399. begin
  400. Line:=CharStr(' ',Margin)+Line;
  401. if not InImage then
  402. repeat
  403. P:=Pos(#255,Line);
  404. if P>0 then
  405. Line[P]:=#32;
  406. until P=0;
  407. if Not InImage then
  408. while copy(Line,length(Line),1)=' ' do
  409. Delete(Line,length(Line),1);
  410. Delta:=0;
  411. if Line<>'' then
  412. case LineAlign of
  413. laLeft : ;
  414. laCenter : if Margin+length(Line)+Margin<Width then
  415. begin
  416. Delta:=(Width-(Margin+length(Line)+Margin)) div 2;
  417. Line:=CharStr(' ',Delta)+Line;
  418. end;
  419. laRight : if Margin+length(Line)+Margin<Width then
  420. begin
  421. Delta:=Width-(Margin+length(Line)+Margin);
  422. Line:=CharStr(' ',Delta)+Line;
  423. end;
  424. end;
  425. if (Delta>0) and (FirstLink<>LastLink) then
  426. for I:=FirstLink to LastLink-1 do
  427. with PHelpLink(Links^.At(I))^ do
  428. Bounds.Move(Delta,0);
  429. if Line='' then Line:=' ';
  430. Lines^.Insert(NewStr(Line));
  431. LinesPos^.Insert(LinePos);
  432. ClearLine;
  433. LineStart:=NextLineStart;
  434. CurPos.X:=Margin+LineStart; Line:=CharStr(#255,LineStart); Inc(CurPos.Y);
  435. if InLink then LinkStart:=CurPos;
  436. FirstLink:=LastLink;
  437. LinePos:=TextPos;
  438. end;
  439. procedure FlushLine;
  440. var W: string;
  441. begin
  442. if CurWord<>'' then begin W:=CurWord; CurWord:=''; AddWord(W); end;
  443. NextLine;
  444. end;
  445. procedure AddWord(TheWord: string);
  446. var W: string;
  447. begin
  448. W:=TheWord;
  449. while (length(W)>0) and (W[length(W)] in [' ',#255]) do
  450. Delete(W,length(W),1);
  451. if (copy(Line+TheWord,1,1)<>' ') then
  452. if (Line<>'') and (Margin+length(Line)+length(W)+Margin>Width) and
  453. not InImage then
  454. NextLine;
  455. Line:=Line+TheWord;
  456. CurPos.X:=Margin+length(Line);
  457. end;
  458. procedure CheckZeroLevel;
  459. begin
  460. if ZeroLevel<>0 then
  461. begin
  462. if CurWord<>'' then AddWord(CurWord+' ');
  463. CurWord:='';
  464. ZeroLevel:=0;
  465. end;
  466. end;
  467. procedure EndColorArea;
  468. var Mask: word;
  469. begin
  470. if ColorAreaType=atText then Mask:=$f0 else Mask:=$00;
  471. if CurWord<>'' then AddWord(CurWord); CurWord:='';
  472. ColorAreaEnd:=CurPos; Dec(ColorAreaEnd.X);
  473. ColorAreas^.Insert(NewColorArea(AreaColor,Mask,ColorAreaStart,ColorAreaEnd));
  474. InColorArea:=false; AreaColor:=0;
  475. end;
  476. begin
  477. Lines^.FreeAll; LinesPos^.FreeAll;
  478. Links^.FreeAll; NamedMarks^.FreeAll; ColorAreas^.FreeAll;
  479. if Topic=nil then Lines^.Insert(NewStr(msg_nohelpavailabelforthistopic)) else
  480. begin
  481. LineStart:=0; NextLineStart:=0;
  482. TextPos:=0; ClearLine; CurWord:=''; Line:='';
  483. CurPos.X:=Margin+LineStart; CurPos.Y:=0; LinkNo:=0;
  484. NamedMarkNo:=0; LinePos:=0;
  485. InLink:=false; InCodeArea:=false; InColorArea:=false;
  486. InImage:=false;
  487. ZeroLevel:=0;
  488. LineAlign:=laLeft;
  489. FirstLink:=0; LastLink:=0; NextByte:=nbNormal;
  490. while (TextPos<Topic^.TextSize) or InImage do
  491. begin
  492. C:=chr(PByteArray(Topic^.Text)^[TextPos]);
  493. case NextByte of
  494. nbAreaColor :
  495. begin
  496. AreaColor:=ord(C);
  497. NextByte:=nbNormal;
  498. end;
  499. nbDirect :
  500. begin
  501. NextByte:=nbNormal;
  502. CurWord:=CurWord+C;
  503. end;
  504. nbNormal :
  505. begin
  506. case C of
  507. hscLineBreak :
  508. {if ZeroLevel=0 then ZeroLevel:=1 else
  509. begin FlushLine; FlushLine; ZeroLevel:=0; end;}
  510. if InLink then CurWord:=CurWord+' ' else
  511. begin
  512. NextLineStart:=0;
  513. FlushLine;
  514. LineStart:=0;
  515. LineAlign:=laLeft;
  516. end;
  517. #1 : {Break};
  518. hscLink :
  519. begin
  520. CheckZeroLevel;
  521. if InLink=false then
  522. begin LinkStart:=CurPos; InLink:=true; end else
  523. begin
  524. if CurWord<>'' then AddWord(CurWord); CurWord:='';
  525. LinkEnd:=CurPos; Dec(LinkEnd.X);
  526. if Topic^.Links<>nil then
  527. begin
  528. if LinkNo<Topic^.LinkCount then
  529. begin
  530. Inc(LastLink);
  531. Links^.Insert(NewLink(Topic^.Links^[LinkNo].FileID,
  532. Topic^.Links^[LinkNo].Context,LinkStart,LinkEnd));
  533. end;
  534. Inc(LinkNo);
  535. end;
  536. InLink:=false;
  537. end;
  538. end;
  539. hscLineStart :
  540. begin
  541. NextLineStart:=length(Line)+length(CurWord);
  542. { LineStart:=LineStart+(NextLineStart-LineStart);}
  543. end;
  544. hscCode :
  545. begin
  546. if InCodeArea=false then
  547. CodeAreaStart:=CurPos else
  548. begin
  549. if CurWord<>'' then AddWord(CurWord); CurWord:='';
  550. CodeAreaEnd:=CurPos; Dec(CodeAreaEnd.X);
  551. ColorAreas^.Insert(NewColorArea(CommentColor,$f0,CodeAreaStart,CodeAreaEnd));
  552. end;
  553. InCodeArea:=not InCodeArea;
  554. end;
  555. hscCenter :
  556. LineAlign:=laCenter;
  557. hscRight :
  558. LineAlign:=laRight{was laCenter, typo error ? PM };
  559. hscNamedMark :
  560. begin
  561. if NamedMarkNo<Topic^.NamedMarks^.Count then
  562. NamedMarks^.Add(GetStr(Topic^.NamedMarks^.At(NamedMarkNo)),CurPos);
  563. Inc(NamedMarkNo);
  564. end;
  565. hscTextAttr,hscTextColor :
  566. begin
  567. if InColorArea then
  568. EndColorArea;
  569. if C=hscTextAttr then
  570. ColorAreaType:=atFull
  571. else
  572. ColorAreaType:=atText;
  573. NextByte:=nbAreaColor;
  574. ColorAreaStart:=CurPos;
  575. InColorArea:=true;
  576. end;
  577. hscDirect :
  578. NextByte:=nbDirect;
  579. hscInImage :
  580. begin
  581. InImage := not InImage;
  582. end;
  583. hscNormText :
  584. begin
  585. if InColorArea then
  586. EndColorArea;
  587. end;
  588. #32: if InLink then CurWord:=CurWord+C else
  589. begin CheckZeroLevel; AddWord(CurWord+C); CurWord:=''; end;
  590. else begin CheckZeroLevel; CurWord:=CurWord+C; end;
  591. end;
  592. end;
  593. end;
  594. CurPos.X:=Margin+length(Line)+length(CurWord);
  595. Inc(TextPos);
  596. end;
  597. if (Line<>'') or (CurWord<>'') then FlushLine;
  598. end;
  599. end;
  600. function THelpTopic.GetLineCount: sw_integer;
  601. begin
  602. GetLineCount:=Lines^.Count;
  603. end;
  604. function THelpTopic.GetLineText(Line: sw_integer): string;
  605. var S: string;
  606. begin
  607. if Line<GetLineCount then S:=PString(Lines^.At(Line))^ else S:='';
  608. GetLineText:=S;
  609. end;
  610. function THelpTopic.GetLinkCount: sw_integer;
  611. begin
  612. GetLinkCount:=Links^.Count;
  613. end;
  614. procedure THelpTopic.GetLinkBounds(Index: sw_integer; var R: TRect);
  615. var P: PHelpLink;
  616. begin
  617. P:=Links^.At(Index);
  618. R:=P^.Bounds;
  619. end;
  620. function THelpTopic.GetLinkFileID(Index: sw_integer): word;
  621. var P: PHelpLink;
  622. begin
  623. P:=Links^.At(Index);
  624. GetLinkFileID:=P^.FileID;
  625. end;
  626. function THelpTopic.GetLinkContext(Index: sw_integer): THelpCtx;
  627. var P: PHelpLink;
  628. begin
  629. P:=Links^.At(Index);
  630. GetLinkContext:=P^.Context;
  631. end;
  632. function THelpTopic.GetColorAreaCount: sw_integer;
  633. begin
  634. GetColorAreaCount:=ColorAreas^.Count;
  635. end;
  636. procedure THelpTopic.GetColorAreaBounds(Index: sw_integer; var R: TRect);
  637. var P: PHelpColorArea;
  638. begin
  639. P:=ColorAreas^.At(Index);
  640. R:=P^.Bounds;
  641. end;
  642. function THelpTopic.GetColorAreaColor(Index: sw_integer): word;
  643. var P: PHelpColorArea;
  644. begin
  645. P:=ColorAreas^.At(Index);
  646. GetColorAreaColor:=P^.Color;
  647. end;
  648. function THelpTopic.GetColorAreaMask(Index: sw_integer): word;
  649. var P: PHelpColorArea;
  650. begin
  651. P:=ColorAreas^.At(Index);
  652. GetColorAreaMask:=P^.AttrMask;
  653. end;
  654. destructor THelpTopic.Done;
  655. begin
  656. inherited Done;
  657. Dispose(Lines, Done);
  658. Dispose(LinesPos, Done);
  659. Dispose(Links, Done);
  660. Dispose(ColorAreas, Done);
  661. Dispose(NamedMarks, Done);
  662. if (Topic<>nil) then DisposeTopic(Topic);
  663. end;
  664. constructor THelpViewer.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  665. begin
  666. inherited Init(Bounds, AHScrollBar, AVScrollBar, nil, nil);
  667. Flags:=efInsertMode or efPersistentBlocks;
  668. ReadOnly:=true;
  669. New(WordList, Init(50,50));
  670. Margin:=1; CurLink:=-1;
  671. end;
  672. procedure THelpViewer.ChangeBounds(var Bounds: TRect);
  673. var
  674. LinePos,NewLineIndex,I : longint;
  675. ymin, ymax : sw_integer;
  676. prop : real;
  677. begin
  678. if Owner<>nil then Owner^.Lock;
  679. ymin:=Delta.Y;
  680. ymax:=ymin+Size.Y;
  681. if ymax>ymin then
  682. prop:=(CurPos.Y-ymin)/(ymax-ymin)
  683. else
  684. prop:=0;
  685. inherited ChangeBounds(Bounds);
  686. if (HelpTopic<>nil) and (HelpTopic^.Topic<>nil) and
  687. (HelpTopic^.Topic^.FileID<>0) then
  688. Begin
  689. LinePos:=HelpTopic^.LinesPos^.At(CurPos.Y)+CurPos.X;
  690. RenderTopic;
  691. NewLineIndex:=-1;
  692. For i:=0 to HelpTopic^.LinesPos^.Count-1 do
  693. if LinePos<HelpTopic^.LinesPos^.At(i) then
  694. begin
  695. NewLineIndex:=i-1;
  696. break;
  697. end;
  698. if NewLineIndex>=0 then
  699. Begin
  700. ymin:=NewLineIndex - trunc(prop * Size.Y);
  701. if ymin<0 then
  702. ymin:=0;
  703. ScrollTo(0,ymin);
  704. SetCurPtr(LinePos-HelpTopic^.LinesPos^.At(NewLineIndex),NewLineIndex);
  705. End;
  706. End;
  707. if Owner<>nil then Owner^.UnLock;
  708. end;
  709. procedure THelpViewer.RenderTopic;
  710. begin
  711. if HelpTopic<>nil then
  712. HelpTopic^.SetParams(Margin,Size.X);
  713. SetLimit(255,GetLineCount);
  714. DrawView;
  715. end;
  716. function THelpViewer.LinkContainsPoint(var R: TRect; var P: TPoint): boolean;
  717. var OK: boolean;
  718. begin
  719. if (R.A.Y=R.B.Y) then
  720. OK:= (P.Y=R.A.Y) and (R.A.X<=P.X) and (P.X<=R.B.X) else
  721. OK:=
  722. ( (R.A.Y=P.Y) and (R.A.X<=P.X) ) or
  723. ( (R.A.Y<P.Y) and (P.Y<R.B.Y) ) or
  724. ( (R.B.Y=P.Y) and (P.X<=R.B.X) );
  725. LinkContainsPoint:=OK;
  726. end;
  727. procedure THelpViewer.SetCurPtr(X,Y: sw_integer);
  728. var OldCurLink,I: sw_integer;
  729. OldPos,P: TPoint;
  730. R: TRect;
  731. begin
  732. OldPos:=CurPos;
  733. OldCurLink:=CurLink;
  734. inherited SetCurPtr(X,Y);
  735. CurLink:=-1;
  736. P:=CurPos;
  737. for I:=0 to GetLinkCount-1 do
  738. begin
  739. GetLinkBounds(I,R);
  740. if LinkContainsPoint(R,P) then
  741. begin CurLink:=I; Break; end;
  742. end;
  743. if OldCurLink<>CurLink then DrawView;
  744. if ((OldPos.X<>CurPos.X) or (OldPos.Y<>CurPos.Y)) and (InLookup=false) then
  745. Lookup('');
  746. end;
  747. function THelpViewer.GetLineCount: sw_integer;
  748. var Count: sw_integer;
  749. begin
  750. if HelpTopic=nil then Count:=0 else Count:=HelpTopic^.GetLineCount;
  751. GetLineCount:=Count;
  752. end;
  753. function THelpViewer.GetLine(LineNo: sw_integer): PCustomLine;
  754. begin
  755. {Abstract; used in wcedit unit ! }
  756. GetLine:=nil;
  757. end;
  758. function THelpViewer.GetDisplayText(I: sw_integer): string;
  759. begin
  760. GetDisplayText:=ExtractTabs(GetLineText(I),DefaultTabSize);
  761. end;
  762. function THelpViewer.GetLineText(Line: sw_integer): string;
  763. var S: string;
  764. begin
  765. if HelpTopic=nil then S:='' else S:=HelpTopic^.GetLineText(Line);
  766. GetLineText:=S;
  767. end;
  768. function THelpViewer.GetLinkCount: sw_integer;
  769. var Count: sw_integer;
  770. begin
  771. if HelpTopic=nil then Count:=0 else Count:=HelpTopic^.GetLinkCount;
  772. GetLinkCount:=Count;
  773. end;
  774. procedure THelpViewer.GetLinkBounds(Index: sw_integer; var R: TRect);
  775. begin
  776. HelpTopic^.GetLinkBounds(Index,R);
  777. end;
  778. function THelpViewer.GetLinkFileID(Index: sw_integer): word;
  779. begin
  780. GetLinkFileID:=HelpTopic^.GetLinkFileID(Index);
  781. end;
  782. function THelpViewer.GetLinkContext(Index: sw_integer): THelpCtx;
  783. begin
  784. GetLinkContext:=HelpTopic^.GetLinkContext(Index);
  785. end;
  786. function THelpViewer.GetLinkTarget(Index: sw_integer): string;
  787. begin
  788. GetLinkTarget:='';
  789. end;
  790. function THelpViewer.GetLinkText(Index: sw_integer): string;
  791. var S: string;
  792. R: TRect;
  793. Y,StartX,EndX: sw_integer;
  794. begin
  795. S:=''; GetLinkBounds(Index,R);
  796. Y:=R.A.Y;
  797. while (Y<=R.B.Y) do
  798. begin
  799. if Y=R.A.Y then StartX:=R.A.X else StartX:=Margin;
  800. if Y=R.B.Y then EndX:=R.B.X else EndX:=High(S);
  801. S:=S+copy(GetLineText(Y),StartX+1,EndX-StartX+1);
  802. Inc(Y);
  803. end;
  804. GetLinkText:=S;
  805. end;
  806. function THelpViewer.GetColorAreaCount: sw_integer;
  807. var Count: sw_integer;
  808. begin
  809. if HelpTopic=nil then Count:=0 else Count:=HelpTopic^.GetColorAreaCount;
  810. GetColorAreaCount:=Count;
  811. end;
  812. procedure THelpViewer.GetColorAreaBounds(Index: sw_integer; var R: TRect);
  813. begin
  814. HelpTopic^.GetColorAreaBounds(Index,R);
  815. end;
  816. function THelpViewer.GetColorAreaColor(Index: sw_integer): word;
  817. begin
  818. GetColorAreaColor:=HelpTopic^.GetColorAreaColor(Index);
  819. end;
  820. function THelpViewer.GetColorAreaMask(Index: sw_integer): word;
  821. begin
  822. GetColorAreaMask:=HelpTopic^.GetColorAreaMask(Index);
  823. end;
  824. procedure THelpViewer.SelectNextLink(ANext: boolean);
  825. var I,Link: sw_integer;
  826. R: TRect;
  827. begin
  828. if HelpTopic=nil then Exit;
  829. Link:=CurLink;
  830. if Link<>-1 then
  831. begin
  832. if ANext then
  833. begin Inc(Link); if Link>=GetLinkCount then Link:=0; end else
  834. begin Dec(Link); if Link=-1 then Link:=GetLinkCount-1; end;
  835. end else
  836. for I:=0 to GetLinkCount-1 do
  837. begin
  838. GetLinkBounds(I,R);
  839. if (R.A.Y>CurPos.Y) or
  840. (R.A.Y=CurPos.Y) and (R.A.X>CurPos.X) then
  841. begin Link:=I; Break; end;
  842. end;
  843. if (Link=-1) and (GetLinkCount>0) then
  844. if ANext then Link:=0
  845. else Link:=GetLinkCount-1;
  846. SetCurLink(Link);
  847. end;
  848. procedure THelpViewer.SetCurLink(Link: sw_integer);
  849. var R: TRect;
  850. begin
  851. if Link<>-1 then
  852. begin
  853. GetLinkBounds(Link,R);
  854. SetCurPtr(R.A.X,R.A.Y);
  855. TrackCursor(true);
  856. {St:=GetLinkTarget(Link);
  857. If St<>'' then
  858. SetTitle('Help '+St);}
  859. end;
  860. end;
  861. procedure THelpViewer.SwitchToIndex;
  862. begin
  863. if IndexTopic=nil then
  864. IndexTopic:=HelpFacility^.BuildIndexTopic;
  865. ISwitchToTopicPtr(IndexTopic,true);
  866. end;
  867. procedure THelpViewer.SwitchToTopic(SourceFileID: word; Context: THelpCtx);
  868. begin
  869. ISwitchToTopic(SourceFileID,Context,true);
  870. end;
  871. procedure THelpViewer.ISwitchToTopic(SourceFileID: word; Context: THelpCtx; RecordInHistory: boolean);
  872. var P: PTopic;
  873. begin
  874. if HelpFacility=nil then P:=nil else
  875. if (SourceFileID=0) and (Context=0) and (HelpTopic<>nil) then
  876. P:=IndexTopic else
  877. P:=HelpFacility^.LoadTopic(SourceFileID, Context);
  878. ISwitchToTopicPtr(P,RecordInHistory);
  879. end;
  880. procedure THelpViewer.ISwitchToTopicPtr(P: PTopic; RecordInHistory: boolean);
  881. var HistoryFull: boolean;
  882. begin
  883. if (P<>nil) and RecordInHistory and (HelpTopic<>nil) then
  884. begin
  885. HistoryFull:=HistoryPtr>=HistorySize;
  886. if HistoryFull then
  887. Move(History[1],History[0],SizeOf(History)-SizeOf(History[0]));
  888. with History[HistoryPtr] do
  889. begin
  890. {SourceTopic_:=SourceTopic; }Context_:=HelpTopic^.Topic^.HelpCtx;
  891. FileID_:=HelpTopic^.Topic^.FileID;
  892. Delta_:=Delta; CurPos_:=CurPos; CurLink_:=CurLink;
  893. end;
  894. if HistoryFull=false then Inc(HistoryPtr);
  895. end;
  896. if Owner<>nil then Owner^.Lock;
  897. SetTopic(P);
  898. DrawView;
  899. if Owner<>nil then Owner^.UnLock;
  900. end;
  901. procedure THelpViewer.PrevTopic;
  902. begin
  903. if HistoryPtr>0 then
  904. begin
  905. if Owner<>nil then Owner^.Lock;
  906. Dec(HistoryPtr);
  907. with History[HistoryPtr] do
  908. begin
  909. ISwitchToTopic(FileID_,Context_,false);
  910. ScrollTo(Delta_.X,Delta_.Y);
  911. SetCurPtr(CurPos_.X,CurPos_.Y);
  912. TrackCursor(false);
  913. if CurLink<>CurLink_ then SetCurLink(CurLink_);
  914. end;
  915. DrawView;
  916. if Owner<>nil then Owner^.UnLock;
  917. end;
  918. end;
  919. procedure THelpViewer.SetTopic(Topic: PTopic);
  920. var Bookmark: string;
  921. P: TPoint;
  922. begin
  923. CurLink:=-1;
  924. if (HelpTopic=nil) or (Topic<>HelpTopic^.Topic) then
  925. begin
  926. if (HelpTopic<>nil) and (HelpTopic<>IndexHelpTopic) then
  927. Dispose(HelpTopic, Done);
  928. HelpTopic:=nil;
  929. if Topic<>nil then
  930. begin
  931. if (Topic=IndexTopic) and (IndexHelpTopic<>nil) then
  932. HelpTopic:=IndexHelpTopic else
  933. New(HelpTopic, Init(Topic));
  934. if Topic=IndexTopic then
  935. IndexHelpTopic:=HelpTopic;
  936. end;
  937. end;
  938. if Owner<>nil then Owner^.Lock;
  939. SetCurPtr(0,0); TrackCursor(false);
  940. RenderTopic;
  941. BuildTopicWordList;
  942. Lookup('');
  943. if Assigned(Topic) then
  944. if Topic^.StartNamedMark>0 then
  945. if Topic^.NamedMarks^.Count>=Topic^.StartNamedMark then
  946. begin
  947. Bookmark:=GetStr(Topic^.NamedMarks^.At(Topic^.StartNamedMark-1));
  948. if HelpTopic^.NamedMarks^.GetMarkPos(Bookmark,P) then
  949. begin
  950. SetCurPtr(P.X,P.Y);
  951. ScrollTo(0,Max(0,P.Y-1));
  952. end;
  953. end;
  954. SetSelection(CurPos,CurPos);
  955. DrawView;
  956. if Owner<>nil then Owner^.UnLock;
  957. end;
  958. procedure THelpViewer.BuildTopicWordList;
  959. var I: sw_integer;
  960. begin
  961. WordList^.FreeAll;
  962. for I:=0 to GetLinkCount-1 do
  963. WordList^.Insert(NewKeyword(I,Trim(GetLinkText(I))));
  964. end;
  965. procedure THelpViewer.Lookup(S: string);
  966. var Index, I: Sw_integer;
  967. W: string;
  968. OldLookup: string;
  969. R: TRect;
  970. P: PHelpKeyword;
  971. begin
  972. InLookup:=true;
  973. OldLookup:=LookupWord;
  974. S:=UpcaseStr(S);
  975. Index:=-1;
  976. I:=0; {J:=0;
  977. while (J<GetLinkCount) do
  978. begin
  979. GetLinkBounds(J,R);
  980. if (R.A.Y<CurPos.Y) or ((R.A.Y=CurPos.Y) and (R.B.X<CurPos.X))
  981. then Inc(J) else
  982. begin I:=J; Break; end;
  983. end;}
  984. if S='' then LookupWord:='' else
  985. begin
  986. while (Index=-1) and (I<WordList^.Count) do
  987. begin
  988. P:=WordList^.At(I);
  989. if P^.KWord<>nil then
  990. begin
  991. W:=UpcaseStr(Trim(P^.KWord^));
  992. if copy(W,1,length(S))=S then Index:=I;
  993. end;
  994. { if W>S then Break else}
  995. Inc(I);
  996. end;
  997. if Index<>-1 then
  998. begin
  999. W:=Trim(WordList^.At(Index)^.KWord^);
  1000. LookupWord:=copy(W,1,length(S));
  1001. end;
  1002. end;
  1003. if LookupWord<>OldLookup then
  1004. begin
  1005. if Index=-1 then SetCurLink(CurLink) else
  1006. begin
  1007. if Owner<>nil then Owner^.Lock;
  1008. P:=WordList^.At(Index);
  1009. S:=GetLinkText(P^.Index);
  1010. I:=Pos(LookupWord,S); if I=0 then I:=1;
  1011. GetLinkBounds(P^.Index,R);
  1012. SetCurPtr(R.A.X+(I-1)+length(Lookupword),R.A.Y);
  1013. CurLink:=P^.Index; DrawView;
  1014. TrackCursor(true);
  1015. if Owner<>nil then Owner^.UnLock;
  1016. end;
  1017. end;
  1018. InLookup:=false;
  1019. end;
  1020. procedure THelpViewer.SelectLink(Index: sw_integer);
  1021. var ID: word;
  1022. Ctx: THelpCtx;
  1023. begin
  1024. if Index=-1 then Exit;
  1025. if HelpTopic=nil then begin ID:=0; Ctx:=0; end else
  1026. begin
  1027. ID:=GetLinkFileID(Index);
  1028. Ctx:=GetLinkContext(Index);
  1029. end;
  1030. SwitchToTopic(ID,Ctx);
  1031. end;
  1032. procedure THelpViewer.HandleEvent(var Event: TEvent);
  1033. var DontClear: boolean;
  1034. procedure GetMousePos(var P: TPoint);
  1035. begin
  1036. MakeLocal(Event.Where,P);
  1037. Inc(P.X,Delta.X); Inc(P.Y,Delta.Y);
  1038. end;
  1039. begin
  1040. case Event.What of
  1041. evMouseDown :
  1042. if MouseInView(Event.Where) then
  1043. if (Event.Buttons=mbLeftButton) and (Event.Double) then
  1044. begin
  1045. inherited HandleEvent(Event);
  1046. if CurLink<>-1 then
  1047. SelectLink(CurLink);
  1048. end;
  1049. evBroadcast :
  1050. case Event.Command of
  1051. cmHelpFilesChanged :
  1052. begin
  1053. if HelpTopic=IndexHelpTopic then HelpTopic:=nil;
  1054. IndexTopic:=nil;
  1055. if IndexHelpTopic<>nil then Dispose(IndexHelpTopic, Done);
  1056. IndexHelpTopic:=nil;
  1057. end;
  1058. end;
  1059. evCommand :
  1060. begin
  1061. DontClear:=false;
  1062. case Event.Command of
  1063. cmPrevTopic :
  1064. PrevTopic;
  1065. else DontClear:=true;
  1066. end;
  1067. if DontClear=false then ClearEvent(Event);
  1068. end;
  1069. evKeyDown :
  1070. begin
  1071. DontClear:=false;
  1072. case Event.KeyCode of
  1073. kbTab :
  1074. SelectNextLink(true);
  1075. kbShiftTab :
  1076. begin NoSelect:=true; SelectNextLink(false); NoSelect:=false; end;
  1077. kbEnter :
  1078. if CurLink<>-1 then
  1079. SelectLink(CurLink);
  1080. kbBack,kbDel :
  1081. if Length(LookupWord)>0 then
  1082. Lookup(Copy(LookupWord,1,Length(LookupWord)-1));
  1083. else
  1084. case Event.CharCode of
  1085. #32..#255 :
  1086. begin NoSelect:=true; Lookup(LookupWord+Event.CharCode); NoSelect:=false; end;
  1087. else DontClear:=true;
  1088. end;
  1089. end;
  1090. TrackCursor(false);
  1091. if DontClear=false then ClearEvent(Event);
  1092. end;
  1093. end;
  1094. inherited HandleEvent(Event);
  1095. end;
  1096. procedure THelpViewer.Draw;
  1097. var NormalColor, LinkColor,
  1098. SelectColor, SelectionColor: word;
  1099. B: TDrawBuffer;
  1100. DX,DY,X,Y,I,MinX,MaxX,ScreenX: sw_integer;
  1101. LastLinkDrawn,LastColorAreaDrawn: sw_integer;
  1102. S: string;
  1103. R: TRect;
  1104. SelR : TRect;
  1105. C,Mask: word;
  1106. CurP: TPoint;
  1107. ANDSB,ORSB: word;
  1108. begin
  1109. if ELockFlag>0 then
  1110. begin
  1111. DrawCalled:=true;
  1112. Exit;
  1113. end;
  1114. DrawCalled:=false;
  1115. NormalColor:=GetColor(1); LinkColor:=GetColor(2);
  1116. SelectColor:=GetColor(3); SelectionColor:=GetColor(4);
  1117. SelR.A:=SelStart; SelR.B:=SelEnd;
  1118. LastLinkDrawn:=0; LastColorAreaDrawn:=0;
  1119. for DY:=0 to Size.Y-1 do
  1120. begin
  1121. Y:=Delta.Y+DY;
  1122. MoveChar(B,' ',NormalColor,Size.X);
  1123. if Y<GetLineCount then
  1124. begin
  1125. S:=copy(GetLineText(Y),Delta.X+1,High(S));
  1126. S:=copy(S,1,MaxViewWidth);
  1127. MoveStr(B,S,NormalColor);
  1128. for I:=LastColorAreaDrawn to GetColorAreaCount-1 do
  1129. begin
  1130. GetColorAreaBounds(I,R);
  1131. if R.A.Y>Y then Break;
  1132. LastColorAreaDrawn:=I;
  1133. if Y=R.B.Y then MaxX:=R.B.X else MaxX:=(length(S)+Delta.X-1);
  1134. if Y=R.A.Y then MinX:=R.A.X else MinX:=0;
  1135. if (R.A.Y<=Y) and (Y<=R.B.Y) then
  1136. begin
  1137. C:=GetColorAreaColor(I);
  1138. Mask:=GetColorAreaMask(I);
  1139. for DX:=MinX to MaxX do
  1140. begin
  1141. X:=DX;
  1142. ScreenX:=X-(Delta.X);
  1143. if (ScreenX>=0) and (ScreenX<=High(B)) then
  1144. begin
  1145. { CurP.X:=X; CurP.Y:=Y;
  1146. if LinkAreaContainsPoint(R,CurP) then}
  1147. (* B[ScreenX]:=(B[ScreenX] and $f0ff) or (C shl 8);*)
  1148. ANDSB:=(Mask shl 8)+$ff;
  1149. ORSB:=(C shl 8);
  1150. B[ScreenX]:=(B[ScreenX] and ANDSB) or ORSB;
  1151. end;
  1152. end;
  1153. end;
  1154. end;
  1155. for I:=LastLinkDrawn to GetLinkCount-1 do
  1156. begin
  1157. GetLinkBounds(I,R);
  1158. if R.A.Y>Y then Break;
  1159. LastLinkDrawn:=I;
  1160. if Y=R.B.Y then MaxX:=R.B.X else MaxX:=(length(S)-1);
  1161. if Y=R.A.Y then MinX:=R.A.X else MinX:=0;
  1162. if (R.A.Y<=Y) and (Y<=R.B.Y) then
  1163. for DX:=MinX to MaxX do
  1164. begin
  1165. X:=DX;
  1166. ScreenX:=X-(Delta.X);
  1167. if (ScreenX>=0) and (ScreenX<=High(B)) then
  1168. begin
  1169. CurP.X:=X; CurP.Y:=Y;
  1170. if LinkContainsPoint(R,CurP) then
  1171. if I=CurLink then C:=SelectColor else C:=LinkColor;
  1172. B[ScreenX]:=(B[ScreenX] and $ff) or (C shl 8);
  1173. end;
  1174. end;
  1175. end;
  1176. if ((SelR.A.X<>SelR.B.X) or (SelR.A.Y<>SelR.B.Y)) and (SelR.A.Y<=Y) and (Y<=SelR.B.Y) then
  1177. begin
  1178. if Y=SelR.A.Y then MinX:=SelR.A.X else MinX:=0;
  1179. if Y=SelR.B.Y then MaxX:=SelR.B.X-1 else MaxX:=High(string);
  1180. for DX:=MinX to MaxX do
  1181. begin
  1182. X:=DX;
  1183. ScreenX:=X-(Delta.X);
  1184. if (ScreenX>=0) and (ScreenX<High(B)) then
  1185. B[ScreenX]:=(B[ScreenX] and $0fff) or ((SelectionColor and $f0) shl 8);
  1186. end;
  1187. end;
  1188. end;
  1189. WriteLine(0,DY,Size.X,1,B);
  1190. end;
  1191. DrawCursor;
  1192. end;
  1193. function THelpViewer.GetPalette: PPalette;
  1194. const P: string[length(CHelpViewer)] = CHelpViewer;
  1195. begin
  1196. GetPalette:=@P;
  1197. end;
  1198. constructor THelpViewer.Load(var S: TStream);
  1199. begin
  1200. inherited Load(S);
  1201. end;
  1202. procedure THelpViewer.Store(var S: TStream);
  1203. begin
  1204. inherited Store(S);
  1205. end;
  1206. destructor THelpViewer.Done;
  1207. begin
  1208. if (HelpTopic<>nil) and (HelpTopic<>IndexHelpTopic) then
  1209. Dispose(HelpTopic, Done);
  1210. HelpTopic:=nil;
  1211. if IndexHelpTopic<>nil then
  1212. Dispose(IndexHelpTopic, Done);
  1213. IndexHelpTopic:=nil;
  1214. inherited Done;
  1215. if assigned(WordList) then
  1216. Dispose(WordList, Done);
  1217. end;
  1218. function THelpFrame.GetPalette: PPalette;
  1219. const P: string[length(CHelpFrame)] = CHelpFrame;
  1220. begin
  1221. GetPalette:=@P;
  1222. end;
  1223. constructor THelpWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word; AContext: THelpCtx; ANumber: Integer);
  1224. begin
  1225. inherited Init(Bounds, ATitle, ANumber);
  1226. InitScrollBars;
  1227. if Assigned(HSB) then Insert(HSB);
  1228. if Assigned(VSB) then Insert(VSB);
  1229. InitHelpView;
  1230. if Assigned(HelpView) then
  1231. begin
  1232. if (ASourceFileID<>0) or (AContext<>0) then
  1233. ShowTopic(ASourceFileID, AContext);
  1234. Insert(HelpView);
  1235. end;
  1236. end;
  1237. procedure THelpWindow.InitScrollBars;
  1238. var R: TRect;
  1239. begin
  1240. GetExtent(R); R.Grow(0,-1); R.A.X:=R.B.X-1;
  1241. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1242. GetExtent(R); R.Grow(-1,0); R.A.Y:=R.B.Y-1;
  1243. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1244. end;
  1245. procedure THelpWindow.InitHelpView;
  1246. var R: TRect;
  1247. begin
  1248. GetExtent(R); R.Grow(-1,-1);
  1249. New(HelpView, Init(R, HSB, VSB));
  1250. HelpView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1251. end;
  1252. procedure THelpWindow.InitFrame;
  1253. var R: TRect;
  1254. begin
  1255. GetExtent(R);
  1256. Frame:=New(PHelpFrame, Init(R));
  1257. end;
  1258. procedure THelpWindow.ShowIndex;
  1259. begin
  1260. HelpView^.SwitchToIndex;
  1261. end;
  1262. procedure THelpWindow.ShowTopic(SourceFileID: word; Context: THelpCtx);
  1263. begin
  1264. HelpView^.SwitchToTopic(SourceFileID, Context);
  1265. end;
  1266. procedure THelpWindow.HandleEvent(var Event: TEvent);
  1267. begin
  1268. case Event.What of
  1269. evKeyDown :
  1270. case Event.KeyCode of
  1271. kbEsc :
  1272. begin
  1273. Event.What:=evCommand; Event.Command:=cmClose;
  1274. end;
  1275. end;
  1276. end;
  1277. inherited HandleEvent(Event);
  1278. end;
  1279. procedure THelpWindow.Close;
  1280. begin
  1281. if HideOnClose then Hide else inherited Close;
  1282. end;
  1283. function THelpWindow.GetPalette: PPalette;
  1284. begin
  1285. GetPalette:=nil;
  1286. end;
  1287. END.
  1288. {
  1289. $Log$
  1290. Revision 1.12 2004-12-19 13:55:42 florian
  1291. * x86_64 compilation fixed
  1292. Revision 1.11 2004/11/08 20:28:29 peter
  1293. * Breakpoints are now deleted when removed from source, disabling is
  1294. still possible from the breakpoint list
  1295. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  1296. FV and 1.9.x compilers
  1297. * Run directory added to Run menu
  1298. * Useless programinfo window removed
  1299. Revision 1.10 2003/01/18 01:36:23 pierre
  1300. * fix web bug 1649
  1301. Revision 1.9 2002/09/07 15:40:49 peter
  1302. * old logs removed and tabs fixed
  1303. Revision 1.8 2002/03/25 14:37:45 pierre
  1304. +handle hscDirect
  1305. Revision 1.7 2002/03/20 17:10:04 pierre
  1306. * avoid to cut a part of an image
  1307. Revision 1.6 2002/03/20 11:15:51 pierre
  1308. * possible fix for the IDE prerelease crash
  1309. }