fpsymbol.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Symbol browse support routines for the IDE
  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 FPSymbol;
  13. interface
  14. uses Objects,Drivers,Views,Dialogs,
  15. BrowCol,
  16. FPViews;
  17. const
  18. { Browser tab constants }
  19. btScope = 0;
  20. btReferences = 1;
  21. btInheritance = 2;
  22. btBreakWatch = 3;
  23. type
  24. PSymbolView = ^TSymbolView;
  25. TSymbolView = object(TListBox)
  26. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  27. procedure HandleEvent(var Event: TEvent); virtual;
  28. procedure GotoItem(Item: sw_integer); virtual;
  29. procedure TrackItem(Item: sw_integer); virtual;
  30. function GetPalette: PPalette; virtual;
  31. private
  32. function TrackReference(R: PReference): boolean; virtual;
  33. function GotoReference(R: PReference): boolean; virtual;
  34. end;
  35. PSymbolScopeView = ^TSymbolScopeView;
  36. TSymbolScopeView = object(TSymbolView)
  37. constructor Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  38. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  39. procedure HandleEvent(var Event: TEvent); virtual;
  40. procedure Draw; virtual;
  41. procedure LookUp(S: string); virtual;
  42. procedure GotoItem(Item: sw_integer); virtual;
  43. procedure TrackItem(Item: sw_integer); virtual;
  44. private
  45. Symbols: PSymbolCollection;
  46. LookupStr: string;
  47. end;
  48. PSymbolReferenceView = ^TSymbolReferenceView;
  49. TSymbolReferenceView = object(TSymbolView)
  50. constructor Init(var Bounds: TRect; AReferences: PReferenceCollection; AHScrollBar, AVScrollBar: PScrollBar);
  51. procedure HandleEvent(var Event: TEvent); virtual;
  52. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  53. procedure SelectItem(Item: Sw_Integer); virtual;
  54. procedure GotoItem(Item: sw_integer); virtual;
  55. procedure TrackItem(Item: sw_integer); virtual;
  56. private
  57. References: PReferenceCollection;
  58. end;
  59. PBrowserTabItem = ^TBrowserTabItem;
  60. TBrowserTabItem = record
  61. Sign : char;
  62. Link : PView;
  63. Next : PBrowserTabItem;
  64. end;
  65. PBrowserTab = ^TBrowserTab;
  66. TBrowserTab = object(TView)
  67. Items: PBrowserTabItem;
  68. constructor Init(var Bounds: TRect; AItems: PBrowserTabItem);
  69. function GetItemCount: sw_integer; virtual;
  70. function GetItem(Index: sw_integer): PBrowserTabItem; virtual;
  71. procedure SetParams(AFlags: word; ACurrent: Sw_integer); virtual;
  72. procedure SelectItem(Index: Sw_integer); virtual;
  73. procedure Draw; virtual;
  74. function GetPalette: PPalette; virtual;
  75. procedure HandleEvent(var Event: TEvent); virtual;
  76. destructor Done; virtual;
  77. private
  78. Flags : word;
  79. Current : Sw_integer;
  80. end;
  81. PBrowserWindow = ^TBrowserWindow;
  82. TBrowserWindow = object(TFPWindow)
  83. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  84. const AName: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection);
  85. procedure HandleEvent(var Event: TEvent); virtual;
  86. procedure SetState(AState: Word; Enable: Boolean); virtual;
  87. procedure Close; virtual;
  88. procedure SelectTab(BrowserTab: Sw_integer); virtual;
  89. function GetPalette: PPalette; virtual;
  90. private
  91. PageTab : PBrowserTab;
  92. Sym : PSymbol;
  93. ScopeView : PSymbolScopeView;
  94. ReferenceView : PSymbolReferenceView;
  95. end;
  96. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  97. Symbols: PSymbolCollection; References: PReferenceCollection);
  98. function IsSymbolInfoAvailable: boolean;
  99. procedure OpenOneSymbolBrowser(Name : String);
  100. implementation
  101. uses Commands,App,
  102. WEditor,WViews,
  103. FPConst,FPUtils,FPVars,FPDebug;
  104. function NewBrowserTabItem(ASign: char; ALink: PView; ANext: PBrowserTabItem): PBrowserTabItem;
  105. var P: PBrowserTabItem;
  106. begin
  107. New(P); FillChar(P^,SizeOf(P^),0);
  108. with P^ do begin Sign:=ASign; Link:=ALink; Next:=ANext; end;
  109. NewBrowserTabItem:=P;
  110. end;
  111. procedure DisposeBrowserTabItem(P: PBrowserTabItem);
  112. begin
  113. if P<>nil then Dispose(P);
  114. end;
  115. procedure DisposeBrowserTabList(P: PBrowserTabItem);
  116. begin
  117. if P<>nil then
  118. begin
  119. if P^.Next<>nil then DisposeBrowserTabList(P^.Next);
  120. DisposeBrowserTabItem(P);
  121. end;
  122. end;
  123. function IsSymbolInfoAvailable: boolean;
  124. begin
  125. IsSymbolInfoAvailable:=BrowCol.Modules<>nil;
  126. end;
  127. procedure OpenOneSymbolBrowser(Name : String);
  128. var Index : sw_integer;
  129. PS : PSymbol;
  130. P : Pstring;
  131. function Search(P : PSymbol) : boolean;
  132. begin
  133. Search:=UpcaseStr(P^.Items^.LookUp(Name,Index))=Name;
  134. end;
  135. begin
  136. Name:=UpcaseStr(Name);
  137. If BrowCol.Modules<>nil then
  138. begin
  139. PS:=BrowCol.Modules^.FirstThat(@Search);
  140. If assigned(PS) then
  141. OpenSymbolBrowser(0,20,
  142. PS^.Items^.At(Index)^.GetName,'',PS^.Items^.At(Index),
  143. PS^.Items^.At(Index)^.Items,PS^.Items^.At(Index)^.References)
  144. else
  145. begin
  146. P:=@Name;
  147. ErrorBox(#3'Symbol %s not found',@P);
  148. end;
  149. end
  150. else
  151. ErrorBox('No Browser info available',nil);
  152. end;
  153. (*procedure ReadBrowseLog(FileName: string);
  154. var f: text;
  155. IOOK,EndOfFile: boolean;
  156. Line: string;
  157. procedure NextLine;
  158. begin
  159. readln(f,Line);
  160. EndOfFile:=Eof(f);
  161. end;
  162. var Level: integer;
  163. procedure ProcessSymTable(Indent: integer; Owner: PSymbolCollection);
  164. var IndentS,S,Source: string;
  165. Sym: PSymbol;
  166. Ref: PSymbolReference;
  167. P: byte;
  168. PX: TPoint;
  169. PS: PString;
  170. PCount: integer;
  171. Params: array[0..30] of PString;
  172. Typ: tsymtyp;
  173. ExitBack: boolean;
  174. begin
  175. Inc(Level);
  176. IndentS:=CharStr(' ',Indent); ExitBack:=false;
  177. Sym:=nil;
  178. repeat
  179. if copy(Line,1,length(IndentS))<>IndentS then ExitBack:=true else
  180. if copy(Line,Indent+1,3)='***' then
  181. { new symbol }
  182. begin
  183. S:=copy(Line,Indent+1+3,255);
  184. P:=Pos('***',S); if P=0 then P:=length(S)+1;
  185. S:=Trim(copy(S,1,P-1));
  186. if (copy(S,1,1)='_') and (Pos('$$',S)>0) then
  187. begin
  188. repeat
  189. P:=Pos('$$',S);
  190. if P>0 then Delete(S,1,P+1);
  191. until P=0;
  192. P:=Pos('$',S);
  193. Delete(S,1,P);
  194. PCount:=0;
  195. repeat
  196. P:=Pos('$',S); if P=0 then P:=length(S)+1;
  197. Params[PCount]:=TypeNames^.Add(copy(S,1,P-1));
  198. Inc(PCount);
  199. Delete(S,1,P);
  200. until S='';
  201. Sym^.Typ:=procsym;
  202. Sym^.SetParams(PCount,@Params);
  203. end
  204. else
  205. New(Sym, Init(S, varsym, 0, nil));
  206. Owner^.Insert(Sym);
  207. NextLine;
  208. end else
  209. if copy(Line,Indent+1,3)='---' then
  210. { child symtable }
  211. begin
  212. S:=Trim(copy(Line,Indent+1+12,255));
  213. if Level=1 then Typ:=unitsym else
  214. Typ:=typesym;
  215. if (Sym<>nil) and (Sym^.GetName=S) then
  216. else
  217. begin
  218. New(Sym, Init(S, Typ, 0, nil));
  219. Owner^.Insert(Sym);
  220. end;
  221. Sym^.Typ:=Typ;
  222. NextLine;
  223. New(Sym^.Items, Init(0,50));
  224. ProcessSymTable(Indent+2,Sym^.Items);
  225. end else
  226. { if Sym<>nil then}
  227. if copy(Line,Indent+1,1)=' ' then
  228. { reference }
  229. begin
  230. S:=copy(Line,Indent+1+2,255);
  231. P:=Pos('(',S); if P=0 then P:=length(S)+1;
  232. Source:=Trim(copy(S,1,P-1)); Delete(S,1,P);
  233. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  234. PX.Y:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  235. P:=Pos(')',S); if P=0 then P:=length(S)+1;
  236. PX.X:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  237. PS:=ModuleNames^.Add(Source);
  238. New(Ref, Init(PS, PX));
  239. if Sym^.References=nil then
  240. New(Sym^.References, Init(10,50));
  241. Sym^.References^.Insert(Ref);
  242. end;
  243. if ExitBack=false then
  244. NextLine;
  245. until EndOfFile or ExitBack;
  246. Dec(Level);
  247. end;
  248. begin
  249. DoneSymbolBrowser;
  250. InitSymbolBrowser;
  251. {$I-}
  252. Assign(f,FileName);
  253. Reset(f);
  254. Level:=0;
  255. NextLine;
  256. while (IOResult=0) and (EndOfFile=false) do
  257. ProcessSymTable(0,Modules);
  258. Close(f);
  259. EatIO;
  260. {$I+}
  261. end;*)
  262. {****************************************************************************
  263. TSymbolView
  264. ****************************************************************************}
  265. constructor TSymbolView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  266. begin
  267. inherited Init(Bounds,1,AVScrollBar);
  268. HScrollBar:=AHScrollBar;
  269. if assigned(HScrollBar) then
  270. HScrollBar^.SetRange(1,80);
  271. Options:=Options or (ofSelectable+ofTopSelect);
  272. end;
  273. procedure TSymbolView.HandleEvent(var Event: TEvent);
  274. var DontClear: boolean;
  275. begin
  276. case Event.What of
  277. evKeyDown :
  278. begin
  279. DontClear:=false;
  280. case Event.KeyCode of
  281. kbEnter :
  282. GotoItem(Focused);
  283. kbSpaceBar :
  284. TrackItem(Focused);
  285. kbRight,kbLeft :
  286. if HScrollBar<>nil then
  287. HScrollBar^.HandleEvent(Event);
  288. else DontClear:=true;
  289. end;
  290. if DontClear=false then ClearEvent(Event);
  291. end;
  292. evMouseDown :
  293. if Event.double then
  294. GotoItem(Focused);
  295. end;
  296. inherited HandleEvent(Event);
  297. end;
  298. function TSymbolView.GetPalette: PPalette;
  299. const
  300. P: string[length(CBrowserListBox)] = CBrowserListBox;
  301. begin
  302. GetPalette:=@P;
  303. end;
  304. procedure TSymbolView.GotoItem(Item: sw_integer);
  305. begin
  306. SelectItem(Item);
  307. end;
  308. procedure TSymbolView.TrackItem(Item: sw_integer);
  309. begin
  310. SelectItem(Item);
  311. end;
  312. function LastBrowserWindow: PBrowserWindow;
  313. var BW: PBrowserWindow;
  314. procedure IsBW(P: PView); {$ifndef FPC}far;{$endif}
  315. begin
  316. if (P^.HelpCtx=hcBrowserWindow) then
  317. BW:=pointer(P);
  318. end;
  319. begin
  320. BW:=nil;
  321. Desktop^.ForEach(@IsBW);
  322. LastBrowserWindow:=BW;
  323. end;
  324. function TSymbolView.TrackReference(R: PReference): boolean;
  325. var W: PSourceWindow;
  326. BW: PBrowserWindow;
  327. P: TPoint;
  328. begin
  329. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  330. Desktop^.Lock;
  331. P.X:=R^.Position.X-1; P.Y:=R^.Position.Y-1;
  332. W:=TryToOpenFile(nil,R^.GetFileName,P.X,P.Y,true);
  333. if W<>nil then
  334. begin
  335. BW:=LastBrowserWindow;
  336. if BW=nil then
  337. W^.Select
  338. else
  339. begin
  340. Desktop^.Delete(W);
  341. Desktop^.InsertBefore(W,BW^.NextView);
  342. end;
  343. W^.Editor^.SetHighlightRow(P.Y);
  344. end;
  345. Desktop^.UnLock;
  346. TrackReference:=W<>nil;
  347. end;
  348. function TSymbolView.GotoReference(R: PReference): boolean;
  349. var W: PSourceWindow;
  350. begin
  351. Desktop^.Lock;
  352. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  353. if W<>nil then W^.Select;
  354. Desktop^.UnLock;
  355. GotoReference:=W<>nil;
  356. end;
  357. {****************************************************************************
  358. TSymbolScopeView
  359. ****************************************************************************}
  360. constructor TSymbolScopeView.Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  361. begin
  362. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  363. Symbols:=ASymbols;
  364. NewList(ASymbols);
  365. SetRange(Symbols^.Count);
  366. end;
  367. procedure TSymbolScopeView.HandleEvent(var Event: TEvent);
  368. var OldFocus: sw_integer;
  369. begin
  370. case Event.What of
  371. evKeyDown :
  372. case Event.KeyCode of
  373. kbBack :
  374. begin
  375. LookUp(copy(LookUpStr,1,length(LookUpStr)-1));
  376. ClearEvent(Event);
  377. end;
  378. else
  379. if Event.CharCode in[#33..#255] then
  380. begin
  381. LookUp(LookUpStr+Event.CharCode);
  382. ClearEvent(Event);
  383. end;
  384. end;
  385. end;
  386. OldFocus:=Focused;
  387. inherited HandleEvent(Event);
  388. if OldFocus<>Focused then
  389. Lookup('');
  390. end;
  391. procedure TSymbolScopeView.Draw;
  392. begin
  393. inherited Draw;
  394. SetCursor(2+SymbolTypLen+length(LookUpStr),Focused-TopItem);
  395. end;
  396. procedure TSymbolScopeView.LookUp(S: string);
  397. var Idx: Sw_integer;
  398. NS: string;
  399. begin
  400. NS:=LookUpStr;
  401. if (Symbols=nil) or (S='') then NS:='' else
  402. begin
  403. S:=Symbols^.LookUp(S,Idx);
  404. if Idx<>-1 then
  405. begin
  406. NS:=S;
  407. FocusItem(Idx);
  408. end;
  409. end;
  410. LookUpStr:=NS;
  411. SetState(sfCursorVis,LookUpStr<>'');
  412. DrawView;
  413. end;
  414. procedure TSymbolScopeView.GotoItem(Item: sw_integer);
  415. begin
  416. SelectItem(Item);
  417. end;
  418. procedure TSymbolScopeView.TrackItem(Item: sw_integer);
  419. var S: PSymbol;
  420. begin
  421. if Range=0 then Exit;
  422. S:=List^.At(Focused);
  423. if (S^.References<>nil) and (S^.References^.Count>0) then
  424. TrackReference(S^.References^.At(0));
  425. end;
  426. function TSymbolScopeView.GetText(Item,MaxLen: Sw_Integer): String;
  427. var S: string;
  428. begin
  429. S:=Symbols^.At(Item)^.GetText;
  430. GetText:=copy(S,1,MaxLen);
  431. end;
  432. {****************************************************************************
  433. TSymbolReferenceView
  434. ****************************************************************************}
  435. constructor TSymbolReferenceView.Init(var Bounds: TRect; AReferences: PReferenceCollection;
  436. AHScrollBar, AVScrollBar: PScrollBar);
  437. begin
  438. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  439. References:=AReferences;
  440. NewList(AReferences);
  441. SetRange(References^.Count);
  442. end;
  443. procedure TSymbolReferenceView.HandleEvent(var Event: TEvent);
  444. var OldFocus: sw_integer;
  445. begin
  446. OldFocus:=Focused;
  447. inherited HandleEvent(Event);
  448. if OldFocus<>Focused then
  449. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  450. end;
  451. function TSymbolReferenceView.GetText(Item,MaxLen: Sw_Integer): String;
  452. var S: string;
  453. P: PReference;
  454. begin
  455. P:=References^.At(Item);
  456. S:=P^.GetFileName+'('+IntToStr(P^.Position.Y)+','+IntToStr(P^.Position.X)+')';
  457. GetText:=copy(S,1,MaxLen);
  458. end;
  459. procedure TSymbolReferenceView.GotoItem(Item: sw_integer);
  460. begin
  461. if Range=0 then Exit;
  462. GotoReference(List^.At(Item));
  463. end;
  464. procedure TSymbolReferenceView.TrackItem(Item: sw_integer);
  465. begin
  466. if Range=0 then Exit;
  467. TrackReference(List^.At(Item));
  468. end;
  469. procedure TSymbolReferenceView.SelectItem(Item: Sw_Integer);
  470. begin
  471. GotoItem(Item);
  472. end;
  473. {****************************************************************************
  474. TBrowserTab
  475. ****************************************************************************}
  476. constructor TBrowserTab.Init(var Bounds: TRect; AItems: PBrowserTabItem);
  477. begin
  478. inherited Init(Bounds);
  479. Options:=Options or ofPreProcess;
  480. Items:=AItems;
  481. SetParams(0,0);
  482. end;
  483. procedure TBrowserTab.SetParams(AFlags: word; ACurrent: Sw_integer);
  484. begin
  485. Flags:=AFlags;
  486. SelectItem(ACurrent);
  487. end;
  488. procedure TBrowserTab.SelectItem(Index: Sw_integer);
  489. var P: PBrowserTabItem;
  490. begin
  491. Current:=Index;
  492. P:=GetItem(Current);
  493. if (P<>nil) and (P^.Link<>nil) then
  494. P^.Link^.Focus;
  495. DrawView;
  496. end;
  497. function TBrowserTab.GetItemCount: sw_integer;
  498. var Count: integer;
  499. P: PBrowserTabItem;
  500. begin
  501. Count:=0; P:=Items;
  502. while (P<>nil) do
  503. begin
  504. Inc(Count);
  505. P:=P^.Next;
  506. end;
  507. GetItemCount:=Count;
  508. end;
  509. function TBrowserTab.GetItem(Index: sw_integer): PBrowserTabItem;
  510. var Counter: integer;
  511. P: PBrowserTabItem;
  512. begin
  513. P:=Items; Counter:=0;
  514. while (P<>nil) and (Counter<Index) do
  515. begin
  516. P:=P^.Next;
  517. Inc(Counter);
  518. end;
  519. GetItem:=P;
  520. end;
  521. procedure TBrowserTab.Draw;
  522. var B: TDrawBuffer;
  523. SelColor, NormColor, C: word;
  524. I,CurX,Count: Sw_integer;
  525. function Names(Idx: integer): char;
  526. begin
  527. Names:=GetItem(Idx)^.Sign;
  528. end;
  529. begin
  530. NormColor:=GetColor(1); SelColor:=GetColor(2);
  531. MoveChar(B,'Ä',SelColor,Size.X);
  532. CurX:=0; Count:=0;
  533. for I:=0 to GetItemCount-1 do
  534. if (Flags and (1 shl I))<>0 then
  535. begin
  536. Inc(Count);
  537. if Current=I then C:=SelColor
  538. else C:=NormColor;
  539. if Count=1 then MoveChar(B[CurX],'´',SelColor,1)
  540. else MoveChar(B[CurX],'³',SelColor,1);
  541. MoveCStr(B[CurX+1],' '+Names(I)+' ',C);
  542. Inc(CurX,4);
  543. end;
  544. if Count>0 then
  545. MoveChar(B[CurX],'Ã',SelColor,1);
  546. WriteLine(0,0,Size.X,Size.Y,B);
  547. end;
  548. procedure TBrowserTab.HandleEvent(var Event: TEvent);
  549. var I,Idx: integer;
  550. DontClear: boolean;
  551. P: TPoint;
  552. function GetItemForCoord(X: integer): integer;
  553. var I,CurX,Idx: integer;
  554. begin
  555. CurX:=0; Idx:=-1;
  556. for I:=0 to GetItemCount-1 do
  557. if (Flags and (1 shl I))<>0 then
  558. begin
  559. if (CurX+1<=X) and (X<=CurX+3) then
  560. begin Idx:=I; Break; end;
  561. Inc(CurX,4);
  562. end;
  563. GetItemForCoord:=Idx;
  564. end;
  565. begin
  566. case Event.What of
  567. evMouseDown :
  568. if MouseInView(Event.Where) then
  569. begin
  570. repeat
  571. MakeLocal(Event.Where,P);
  572. Idx:=GetItemForCoord(P.X);
  573. if Idx<>-1 then
  574. SelectItem(Idx);
  575. until not MouseEvent(Event, evMouseMove);
  576. ClearEvent(Event);
  577. end;
  578. evKeyDown :
  579. begin
  580. DontClear:=false; Idx:=-1;
  581. for I:=0 to GetItemCount-1 do
  582. if Upcase(GetCtrlChar(Event.KeyCode))=Upcase(GetItem(I)^.Sign) then
  583. begin
  584. Idx:=I;
  585. Break;
  586. end;
  587. if Idx=-1 then
  588. DontClear:=true
  589. else
  590. SelectItem(Idx);
  591. if DontClear=false then ClearEvent(Event);
  592. end;
  593. end;
  594. inherited HandleEvent(Event);
  595. end;
  596. function TBrowserTab.GetPalette: PPalette;
  597. const P: string[length(CBrowserTab)] = CBrowserTab;
  598. begin
  599. GetPalette:=@P;
  600. end;
  601. destructor TBrowserTab.Done;
  602. begin
  603. inherited Done;
  604. if Items<>nil then DisposeBrowserTabList(Items);
  605. end;
  606. constructor TBrowserWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  607. const AName: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection);
  608. var R: TRect;
  609. ST: PStaticText;
  610. HSB,VSB: PScrollBar;
  611. function CreateVSB(R: TRect): PScrollBar;
  612. var R2: TRect;
  613. SB: PScrollBar;
  614. begin
  615. Sym:=ASym;
  616. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  617. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  618. CreateVSB:=SB;
  619. end;
  620. function CreateHSB(R: TRect): PScrollBar;
  621. var R2: TRect;
  622. SB: PScrollBar;
  623. begin
  624. R2.Copy(R); R2.Move(0,1); R2.A.Y:=R2.B.Y-1;
  625. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  626. CreateHSB:=SB;
  627. end;
  628. begin
  629. inherited Init(Bounds, ATitle, ANumber);
  630. HelpCtx:=hcBrowserWindow;
  631. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  632. New(ST, Init(R, ' '+AName)); ST^.GrowMode:=gfGrowHiX;
  633. Insert(ST);
  634. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);
  635. if assigned(ASymbols) and (ASymbols^.Count>0) then
  636. begin
  637. HSB:=CreateHSB(R); Insert(HSB);
  638. VSB:=CreateVSB(R); Insert(VSB);
  639. New(ScopeView, Init(R, ASymbols, HSB, VSB));
  640. ScopeView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  641. Insert(ScopeView);
  642. end;
  643. if assigned(AReferences) and (AReferences^.Count>0) then
  644. begin
  645. HSB:=CreateHSB(R); Insert(HSB);
  646. VSB:=CreateVSB(R); Insert(VSB);
  647. New(ReferenceView, Init(R, AReferences, HSB, VSB));
  648. ReferenceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  649. Insert(ReferenceView);
  650. end;
  651. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.B.Y:=R.A.Y+1;
  652. New(PageTab, Init(R,
  653. NewBrowserTabItem('S',ScopeView,
  654. NewBrowserTabItem('R',ReferenceView,
  655. nil))
  656. ));
  657. PageTab^.GrowMode:=gfGrowHiX;
  658. Insert(PageTab);
  659. if assigned(ScopeView) then
  660. SelectTab(btScope)
  661. else
  662. if assigned(ReferenceView) then
  663. SelectTab(btReferences);
  664. end;
  665. procedure TBrowserWindow.HandleEvent(var Event: TEvent);
  666. var DontClear: boolean;
  667. S: PSymbol;
  668. P: TPoint;
  669. begin
  670. case Event.What of
  671. evBroadcast :
  672. case Event.Command of
  673. cmSearchWindow :
  674. ClearEvent(Event);
  675. cmListItemSelected :
  676. if Event.InfoPtr=ScopeView then
  677. begin
  678. S:=ScopeView^.Symbols^.At(ScopeView^.Focused);
  679. MakeGlobal(ScopeView^.Origin,P);
  680. Desktop^.MakeLocal(P,P); Inc(P.Y,ScopeView^.Focused-ScopeView^.TopItem);
  681. Inc(P.Y);
  682. if (S^.GetReferenceCount>0) or (S^.GetItemCount>0) then
  683. OpenSymbolBrowser(Origin.X-1,P.Y,
  684. S^.GetName,
  685. ScopeView^.GetText(ScopeView^.Focused,255),S,
  686. S^.Items,S^.References);
  687. end;
  688. end;
  689. { evCommand :
  690. begin
  691. DontClear:=false;
  692. case Event.Command of
  693. cmGotoSymbol :
  694. if Event.InfoPtr=ScopeView then
  695. if ReferenceView<>nil then
  696. if ReferenceView^.Range>0 then
  697. ReferenceView^.GotoItem(0);
  698. cmTrackSymbol :
  699. if Event.InfoPtr=ScopeView then
  700. if (ScopeView<>nil) and (ScopeView^.Range>0) then
  701. begin
  702. S:=ScopeView^.At(ScopeView^.Focused);
  703. if (S^.References<>nil) and (S^.References^.Count>0) then
  704. TrackItem(S^.References^.At(0));
  705. else DontClear:=true;
  706. end;
  707. if DontClear=false then ClearEvent(Event);
  708. end;}
  709. evKeyDown :
  710. begin
  711. DontClear:=false;
  712. case Event.KeyCode of
  713. kbEsc :
  714. Close;
  715. else DontClear:=true;
  716. end;
  717. if DontClear=false then ClearEvent(Event);
  718. end;
  719. end;
  720. inherited HandleEvent(Event);
  721. end;
  722. procedure TBrowserWindow.SetState(AState: Word; Enable: Boolean);
  723. var OldState: word;
  724. begin
  725. OldState:=State;
  726. inherited SetState(AState,Enable);
  727. if ((State xor OldState) and sfActive)<>0 then
  728. if GetState(sfActive)=false then
  729. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  730. end;
  731. procedure TBrowserWindow.Close;
  732. begin
  733. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  734. inherited Close;
  735. end;
  736. procedure TBrowserWindow.SelectTab(BrowserTab: Sw_integer);
  737. var Tabs: Sw_integer;
  738. { PB : PBreakpoint;
  739. PS :PString;
  740. l : longint; }
  741. begin
  742. (* case BrowserTab of
  743. btScope :
  744. if assigned(ScopeView) then
  745. ScopeView^.Select;
  746. btReferences :
  747. if assigned(ReferenceView) then
  748. ReferenceView^.Select;
  749. btBreakWatch :
  750. begin
  751. if Assigned(Sym) then
  752. begin
  753. if Pos('proc',Sym^.GetText)>0 then
  754. { insert function breakpoint }
  755. begin
  756. { make it visible }
  757. PS:=Sym^.Name;
  758. l:=Length(PS^);
  759. If PS^[l]='*' then
  760. begin
  761. PB:=BreakpointCollection^.GetType(bt_function,copy(GetStr(PS),1,l-1));
  762. If Assigned(PB) then
  763. BreakpointCollection^.Delete(PB);
  764. Sym^.Name:=NewStr(copy(GetStr(PS),1,l-1));
  765. DrawView;
  766. DisposeStr(PS);
  767. end
  768. else
  769. begin
  770. Sym^.Name:=NewStr(GetStr(PS)+'*');
  771. DrawView;
  772. New(PB,init_function(GetStr(PS)));
  773. DisposeStr(PS);
  774. BreakpointCollection^.Insert(PB);
  775. BreakpointCollection^.Update;
  776. end;
  777. end
  778. else if pos('var',Sym^.GetText)>0 then
  779. { insert watch point }
  780. begin
  781. { make it visible }
  782. PS:=Sym^.Name;
  783. l:=Length(PS^);
  784. If PS^[l]='*' then
  785. begin
  786. PB:=BreakpointCollection^.GetType(bt_awatch,copy(PS^,1,l-1));
  787. If Assigned(PB) then
  788. BreakpointCollection^.Delete(PB);
  789. Sym^.Name:=NewStr(copy(PS^,1,l-1));
  790. DrawView;
  791. DisposeStr(PS);
  792. end
  793. else
  794. begin
  795. Sym^.Name:=NewStr(GetStr(PS)+'*');
  796. DrawView;
  797. New(PB,init_type(bt_awatch,GetStr(PS)));
  798. DisposeStr(PS);
  799. BreakpointCollection^.Insert(PB);
  800. BreakpointCollection^.Update;
  801. end;
  802. end;
  803. end;
  804. end;
  805. end;*)
  806. Tabs:=0;
  807. if assigned(ScopeView) then
  808. Tabs:=Tabs or (1 shl btScope);
  809. if assigned(ReferenceView) then
  810. Tabs:=Tabs or (1 shl btReferences);
  811. if Assigned(Sym) then
  812. if (Pos('proc',Sym^.GetText)>0) or (Pos('var',Sym^.GetText)>0) then
  813. Tabs:=Tabs or (1 shl btBreakWatch);
  814. if PageTab<>nil then PageTab^.SetParams(Tabs,BrowserTab);
  815. end;
  816. function TBrowserWindow.GetPalette: PPalette;
  817. const S: string[length(CBrowserWindow)] = CBrowserWindow;
  818. begin
  819. GetPalette:=@S;
  820. end;
  821. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  822. Symbols: PSymbolCollection; References: PReferenceCollection);
  823. var R: TRect;
  824. begin
  825. if X=0 then X:=Desktop^.Size.X-35;
  826. R.A.X:=X; R.A.Y:=Y;
  827. R.B.X:=R.A.X+35; R.B.Y:=R.A.Y+15;
  828. while (R.B.Y>Desktop^.Size.Y) do R.Move(0,-1);
  829. Desktop^.Insert(New(PBrowserWindow, Init(R,
  830. 'Browse: '+Name,SearchFreeWindowNo,S,Line,Symbols,References)));
  831. end;
  832. END.
  833. {
  834. $Log$
  835. Revision 1.13 1999-03-16 00:44:44 peter
  836. * forgotten in last commit :(
  837. Revision 1.12 1999/03/01 15:42:02 peter
  838. + Added dummy entries for functions not yet implemented
  839. * MenuBar didn't update itself automatically on command-set changes
  840. * Fixed Debugging/Profiling options dialog
  841. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  842. set
  843. * efBackSpaceUnindents works correctly
  844. + 'Messages' window implemented
  845. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  846. + Added TP message-filter support (for ex. you can call GREP thru
  847. GREP2MSG and view the result in the messages window - just like in TP)
  848. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  849. so topic search didn't work...
  850. * In FPHELP.PAS there were still context-variables defined as word instead
  851. of THelpCtx
  852. * StdStatusKeys() was missing from the statusdef for help windows
  853. + Topic-title for index-table can be specified when adding a HTML-files
  854. Revision 1.11 1999/02/22 11:51:38 peter
  855. * browser updates from gabor
  856. Revision 1.9 1999/02/18 13:44:34 peter
  857. * search fixed
  858. + backward search
  859. * help fixes
  860. * browser updates
  861. Revision 1.7 1999/02/16 12:44:20 pierre
  862. * DoubleClick works now
  863. Revision 1.6 1999/02/10 09:44:59 pierre
  864. + added B tab for functions and vars for break/watch
  865. TBrowserWindow also stores the symbol itself for break/watchpoints
  866. Revision 1.5 1999/02/04 17:53:47 pierre
  867. + OpenOneSymbolBrowser
  868. Revision 1.4 1999/02/04 13:16:14 pierre
  869. + column info added
  870. Revision 1.3 1999/01/21 11:54:23 peter
  871. + tools menu
  872. + speedsearch in symbolbrowser
  873. * working run command
  874. Revision 1.2 1999/01/14 21:42:24 peter
  875. * source tracking from Gabor
  876. Revision 1.1 1999/01/12 14:29:40 peter
  877. + Implemented still missing 'switch' entries in Options menu
  878. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  879. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  880. ASCII chars and inserted directly in the text.
  881. + Added symbol browser
  882. * splitted fp.pas to fpide.pas
  883. Revision 1.0 1999/01/09 11:49:41 gabor
  884. Original implementation
  885. }