fpsymbol.pas 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Symbol browse support 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. {$i globdir.inc}
  12. unit FPSymbol;
  13. interface
  14. uses Objects,Drivers,Views,Menus,Dialogs,
  15. {$ifdef HASOUTLINE}
  16. Outline,
  17. {$endif HASOUTLINE}
  18. BrowCol,
  19. WViews,
  20. FPViews;
  21. const
  22. { Browser tab constants }
  23. btScope = 0;
  24. btReferences = 1;
  25. btInheritance = 2;
  26. btMemInfo = 3;
  27. btUnitInfo = 4;
  28. btBreakWatch = 7;
  29. {Symbol Flags}
  30. bfUnits = $00000001;
  31. bfLabels = $00000002;
  32. bfConstants = $00000004;
  33. bfTypes = $00000008;
  34. bfVariables = $00000010;
  35. bfProcedures = $00000020;
  36. bfInherited = $00000040;
  37. {Display Flags}
  38. bfQualifiedSymbols = $40000000;
  39. bfSortAlways = $80000000;
  40. const
  41. DefaultSymbolFlags : longint = bfUnits or
  42. bfLabels or bfConstants or bfTypes or bfVariables or bfProcedures;
  43. DefaultDispayFlags : longint = (bfQualifiedSymbols) shr 30;
  44. { Note: default browser flags will be created with formula:
  45. BrowserFlags:=DefaultDispayFlags shl 30 or DefaultSymbolFlags;
  46. }
  47. DefaultBrowserSub : longint = 0;
  48. DefaultBrowserPane : longint = 0;
  49. type
  50. PBrowserWindow = ^TBrowserWindow;
  51. PGDBValueCollection = ^TGDBValueCollection;
  52. PGDBValue = ^TGDBValue;
  53. TGDBValue = Object(TObject)
  54. constructor Init(Const AExpr : String;ASym : PSymbol);
  55. procedure GetValue;
  56. function GetText : String;
  57. destructor Done;virtual;
  58. private
  59. expr : Pstring;
  60. St : Pstring;
  61. S : PSymbol;
  62. GDBI : longint;
  63. end;
  64. TGDBValueCollection = Object(TCollection)
  65. function At(Index: sw_Integer): PGDBValue;
  66. end;
  67. PFilteredSym = ^TFilteredSym;
  68. TFilteredSym = Object(TObject)
  69. constructor Init(AItemSym:Sw_Integer;ASym : PSymbol);
  70. function GetText:String;
  71. destructor Done;virtual;
  72. private
  73. Sym:PSymbol;
  74. ItemSym : Sw_Integer;
  75. end;
  76. PFilteredSymCollection=^TFilteredSymCollection;
  77. TFilteredSymCollection = Object(TCollection)
  78. function At(Index: sw_Integer): PFilteredSym;
  79. end;
  80. PSymbolView = ^TSymbolView;
  81. TSymbolView = object(THSListBox)
  82. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  83. destructor Done;virtual;
  84. procedure HandleEvent(var Event: TEvent); virtual;
  85. procedure SetState(AState: Word; Enable: Boolean); virtual;
  86. function GotoItem(Item: sw_integer): boolean; virtual;
  87. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  88. function GetPalette: PPalette; virtual;
  89. function GetLocalMenu: PMenu; virtual;
  90. procedure ClearHighlights;
  91. procedure AutoTrackSource; virtual;
  92. procedure Browse; virtual;
  93. procedure GotoSource; virtual;
  94. procedure TrackSource; virtual;
  95. procedure OptionsDlg; virtual;
  96. private
  97. MyBW : PBrowserWindow;
  98. function TrackReference(R: PReference; AutoTrack: boolean): boolean; virtual;
  99. function GotoReference(R: PReference): boolean; virtual;
  100. end;
  101. PSymbolScopeView = ^TSymbolScopeView;
  102. TSymbolScopeView = object(TSymbolView)
  103. constructor Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  104. destructor Done; virtual;
  105. procedure SetGDBCol;
  106. procedure FilterSymbols(AFilter:boolean);
  107. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  108. procedure HandleEvent(var Event: TEvent); virtual;
  109. procedure Draw; virtual;
  110. procedure LookUp(S: string); virtual;
  111. function GotoItem(Item: sw_integer): boolean; virtual;
  112. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  113. private
  114. FilteredSym: PFilteredSymCollection;
  115. Symbols: PSymbolCollection;
  116. SymbolsValue : PGDBValueCollection;
  117. LookupStr: string;
  118. end;
  119. PSymbolReferenceView = ^TSymbolReferenceView;
  120. TSymbolReferenceView = object(TSymbolView)
  121. constructor Init(var Bounds: TRect; AReferences: PReferenceCollection; AHScrollBar, AVScrollBar: PScrollBar);
  122. destructor Done; virtual;
  123. procedure HandleEvent(var Event: TEvent); virtual;
  124. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  125. procedure SelectItem(Item: Sw_Integer); virtual;
  126. function GotoItem(Item: sw_integer): boolean; virtual;
  127. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  128. procedure Browse; virtual;
  129. private
  130. References: PReferenceCollection;
  131. end;
  132. PSymbolMemInfoView = ^TSymbolMemInfoView;
  133. TSymbolMemInfoView = object(TStaticText)
  134. constructor Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  135. destructor Done; virtual;
  136. procedure GetText(var S: String); virtual;
  137. function GetPalette: PPalette; virtual;
  138. private
  139. MemInfo: PSymbolMemInfo;
  140. MyBW : PBrowserWindow;
  141. end;
  142. PSymbolMemoView = ^TSymbolMemoView;
  143. TSymbolMemoView = object(TFPMemo)
  144. function GetPalette: PPalette; virtual;
  145. end;
  146. PSymbolInheritanceView = ^TSymbolInheritanceView;
  147. {$ifdef HASOUTLINE}
  148. TSymbolInheritanceView = object(TLocalMenuOutlineViewer)
  149. {$else notHASOUTLINE}
  150. TSymbolInheritanceView = object(TLocalMenuListBox)
  151. {$endif HASOUTLINE}
  152. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  153. destructor Done; virtual;
  154. function GetRoot: Pointer; virtual;
  155. function HasChildren(Node: Pointer): Boolean; virtual;
  156. function GetChild(Node: Pointer; I: sw_Integer): Pointer; virtual;
  157. function GetNumChildren(Node: Pointer): sw_Integer; virtual;
  158. function GetNumChildrenExposed(Node: Pointer) : sw_Integer; virtual;
  159. procedure Adjust(Node: Pointer; Expand: Boolean); virtual;
  160. function IsExpanded(Node: Pointer): Boolean; virtual;
  161. {$ifdef HASOUTLINE}
  162. function GetText(Node: Pointer): String; virtual;
  163. {$else not HASOUTLINE}
  164. procedure ExpandAll(Node: Pointer);
  165. function GetNode(I : sw_Integer) : Pointer; virtual;
  166. function GetLineNode(Item : sw_Integer) : Pointer; virtual;
  167. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  168. {$endif HASOUTLINE}
  169. procedure NodeSelected(P: pointer); virtual;
  170. procedure Selected(I: sw_Integer); virtual;
  171. procedure HandleEvent(var Event: TEvent); virtual;
  172. function GetPalette: PPalette; virtual;
  173. function GetLocalMenu: PMenu; virtual;
  174. function SaveToFile(const AFileName: string): boolean; virtual;
  175. function SaveAs: Boolean; virtual;
  176. private
  177. Root : PObjectSymbol;
  178. MyBW : PBrowserWindow;
  179. end;
  180. PBrowserTabItem = ^TBrowserTabItem;
  181. TBrowserTabItem = record
  182. Sign : AnsiChar;
  183. Link : PView;
  184. Next : PBrowserTabItem;
  185. end;
  186. PBrowserTab = ^TBrowserTab;
  187. TBrowserTab = object(TView)
  188. Items: PBrowserTabItem;
  189. constructor Init(var Bounds: TRect; AItems: PBrowserTabItem);
  190. function GetItemCount: sw_integer; virtual;
  191. function GetItem(Index: sw_integer): PBrowserTabItem; virtual;
  192. procedure SetParams(AFlags: word; ACurrent: Sw_integer); virtual;
  193. procedure SelectItem(Index: Sw_integer); virtual;
  194. procedure Draw; virtual;
  195. function GetPalette: PPalette; virtual;
  196. procedure HandleEvent(var Event: TEvent); virtual;
  197. destructor Done; virtual;
  198. private
  199. Flags : word;
  200. Current : Sw_integer;
  201. end;
  202. PUnitInfoPanel = ^TUnitInfoPanel;
  203. TUnitInfoPanel = object(TPanel)
  204. InOwnerCall: boolean;
  205. procedure HandleEvent(var Event: TEvent); virtual;
  206. end;
  207. TBrowserWindow = object(TFPWindow)
  208. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  209. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  210. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemInfo);
  211. procedure HandleEvent(var Event: TEvent); virtual;
  212. procedure SetState(AState: Word; Enable: Boolean); virtual;
  213. procedure Close; virtual;
  214. procedure SelectTab(BrowserTab: Sw_integer); virtual;
  215. function GetPalette: PPalette; virtual;
  216. function Disassemble : boolean;
  217. function GetFlags: longint; virtual;
  218. procedure SetFlags(AFlags: longint); virtual;
  219. destructor Done;virtual;
  220. private
  221. BrowserFlags : Longint;
  222. PageTab : PBrowserTab;
  223. ST : PStaticText;
  224. Sym : PSymbol;
  225. ScopeView : PSymbolScopeView;
  226. ReferenceView : PSymbolReferenceView;
  227. InheritanceView: PSymbolInheritanceView;
  228. MemInfoView : PSymbolMemInfoView;
  229. UnitInfoText : PSymbolMemoView;
  230. UnitInfoUsed : PSymbolScopeView;
  231. UnitInfoDependent : PSymbolScopeView;
  232. UnitInfo : PUnitInfoPanel;
  233. Prefix : PString;
  234. IsValid : boolean;
  235. DebuggerValue : PGDBValue;
  236. end;
  237. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  238. ParentBrowser : PBrowserWindow;
  239. Symbols: PSymbolCollection; References: PReferenceCollection;
  240. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo);
  241. function IsSymbolInfoAvailable: boolean;
  242. procedure OpenOneSymbolBrowser(Name : String);
  243. procedure CloseAllBrowsers;
  244. procedure RemoveBrowsersCollection;
  245. const
  246. GlobalsCollection : PSortedCollection = nil;
  247. ProcedureCollection : PSortedCollection = nil;
  248. ModulesCollection : PSortedCollection = nil;
  249. implementation
  250. uses App,Strings,Stddlg,
  251. FVConsts,
  252. {$ifdef BROWSERCOL}
  253. symconst,
  254. {$endif BROWSERCOL}
  255. WUtils,WEditor,WConsts,
  256. FPConst,FPUtils,FPVars,{$ifndef FPDEBUG}FPDebug{$endif},FPIDE;
  257. {$ifdef USERESSTRINGS}
  258. resourcestring
  259. {$else}
  260. const
  261. {$endif}
  262. msg_symbolnotfound = #3'Symbol %s not found';
  263. msg_nobrowserinfoavailable = 'No Browser info available';
  264. msg_cantfindfile = 'Can''t find %s';
  265. menu_local_gotosource = '~G~oto source';
  266. menu_local_tracksource = '~T~rack source';
  267. menu_local_options = '~O~ptions...';
  268. menu_local_clear = '~C~lear';
  269. menu_local_saveas = 'Save ~a~s';
  270. { Symbol view local menu items }
  271. menu_symlocal_browse = '~B~rowse';
  272. menu_symlocal_gotosource = '~G~oto source';
  273. menu_symlocal_tracksource = '~T~rack source';
  274. menu_symlocal_saveas = 'Save ~a~s';
  275. menu_symlocal_options = '~O~ptions...';
  276. { Symbol browser meminfo page }
  277. msg_sizeinmemory = 'Size in memory';
  278. msg_sizeonstack = 'Size on stack';
  279. msg_usedfirstin = 'Used first in';
  280. msg_mainsource = 'Main source';
  281. msg_sourcefiles = 'Source files';
  282. dialog_browse = 'Browse: %s';
  283. const { Symbol browser tabs }
  284. { must be AnsiChar constants (so cannot be resourcestring)}
  285. label_browsertab_scope = 'S';
  286. label_browsertab_reference = 'R';
  287. label_browsertab_inheritance = 'I';
  288. label_browsertab_memory = 'M';
  289. label_browsertab_unit = 'U';
  290. procedure CloseAllBrowsers;
  291. procedure SendCloseIfBrowser(P: PView);
  292. begin
  293. if assigned(P) and
  294. ((TypeOf(P^)=TypeOf(TBrowserWindow)) or
  295. (TypeOf(P^)=TypeOf(TSymbolView)) or
  296. (TypeOf(P^)=TypeOf(TSymbolScopeView)) or
  297. (TypeOf(P^)=TypeOf(TSymbolReferenceView)) or
  298. (TypeOf(P^)=TypeOf(TSymbolMemInfoView)) or
  299. (TypeOf(P^)=TypeOf(TSymbolInheritanceView)) or
  300. (TypeOf(P^)=TypeOf(TSymbolMemoView))) then
  301. Message(P,evCommand,cmClose,nil);
  302. end;
  303. begin
  304. Desktop^.ForEach(TCallbackProcParam(@SendCloseIfBrowser));
  305. end;
  306. procedure RemoveBrowsersCollection;
  307. begin
  308. if assigned(GlobalsCollection) then
  309. begin
  310. GlobalsCollection^.deleteAll;
  311. Dispose(GlobalsCollection,done);
  312. GlobalsCollection:=nil;
  313. end;
  314. if assigned(ProcedureCollection) then
  315. begin
  316. ProcedureCollection^.deleteAll;
  317. Dispose(ProcedureCollection,done);
  318. ProcedureCollection:=nil;
  319. end;
  320. if assigned(ModulesCollection) then
  321. begin
  322. ModulesCollection^.deleteAll;
  323. Dispose(ModulesCollection,done);
  324. ModulesCollection:=nil;
  325. end;
  326. end;
  327. function NewBrowserTabItem(ASign: AnsiChar; ALink: PView; ANext: PBrowserTabItem): PBrowserTabItem;
  328. var P: PBrowserTabItem;
  329. begin
  330. New(P); FillChar(P^,SizeOf(P^),0);
  331. with P^ do begin Sign:=ASign; Link:=ALink; Next:=ANext; end;
  332. NewBrowserTabItem:=P;
  333. end;
  334. procedure DisposeBrowserTabItem(P: PBrowserTabItem);
  335. begin
  336. if P<>nil then Dispose(P);
  337. end;
  338. procedure DisposeBrowserTabList(P: PBrowserTabItem);
  339. begin
  340. if P<>nil then
  341. begin
  342. if P^.Next<>nil then DisposeBrowserTabList(P^.Next);
  343. DisposeBrowserTabItem(P);
  344. end;
  345. end;
  346. function IsSymbolInfoAvailable: boolean;
  347. begin
  348. IsSymbolInfoAvailable:=BrowCol.Modules<>nil;
  349. end;
  350. procedure OpenOneSymbolBrowser(Name : String);
  351. var Index : sw_integer;
  352. PS,S : PSymbol;
  353. Anc : PObjectSymbol;
  354. P : Pstring;
  355. Symbols: PSymbolCollection;
  356. function Search(P : PSymbol) : boolean;
  357. begin
  358. Search:=UpcaseStr(P^.Items^.LookUp(Name,Index))=Name;
  359. end;
  360. begin
  361. Name:=UpcaseStr(Name);
  362. If BrowCol.Modules<>nil then
  363. begin
  364. PS:=BrowCol.Modules^.FirstThat(TCallbackFunBoolParam(@Search));
  365. If assigned(PS) then
  366. begin
  367. S:=PS^.Items^.At(Index);
  368. Symbols:=S^.Items;
  369. if (not assigned(symbols) or (symbols^.count=0)) and
  370. assigned(S^.Ancestor) then
  371. Symbols:=S^.Ancestor^.Items;
  372. if (S^.Flags and (sfObject or sfClass))=0 then
  373. Anc:=nil
  374. else if S^.Ancestor=nil then
  375. Anc:=ObjectTree
  376. else
  377. Anc:=SearchObjectForSymbol(S^.Ancestor);
  378. OpenSymbolBrowser(0,20,
  379. PS^.Items^.At(Index)^.GetName,
  380. PS^.Items^.At(Index)^.GetText,
  381. PS^.Items^.At(Index),nil,
  382. Symbols,PS^.Items^.At(Index)^.References,Anc,PS^.MemInfo);
  383. end
  384. else
  385. begin
  386. P:=@Name;
  387. ErrorBox(msg_symbolnotfound,@P);
  388. end;
  389. end
  390. else
  391. ErrorBox(msg_nobrowserinfoavailable,nil);
  392. end;
  393. (*procedure ReadBrowseLog(FileName: string);
  394. var f: text;
  395. IOOK,EndOfFile: boolean;
  396. Line: string;
  397. procedure NextLine;
  398. begin
  399. readln(f,Line);
  400. EndOfFile:=Eof(f);
  401. end;
  402. var Level: integer;
  403. procedure ProcessSymTable(Indent: integer; Owner: PSymbolCollection);
  404. var IndentS,S,Source: string;
  405. Sym: PSymbol;
  406. Ref: PSymbolReference;
  407. P: byte;
  408. PX: TPoint;
  409. PS: PString;
  410. PCount: integer;
  411. Params: array[0..30] of PString;
  412. Typ: tsymtyp;
  413. ExitBack: boolean;
  414. begin
  415. Inc(Level);
  416. IndentS:=CharStr(' ',Indent); ExitBack:=false;
  417. Sym:=nil;
  418. repeat
  419. if copy(Line,1,length(IndentS))<>IndentS then ExitBack:=true else
  420. if copy(Line,Indent+1,3)='***' then
  421. { new symbol }
  422. begin
  423. S:=copy(Line,Indent+1+3,255);
  424. P:=Pos('***',S); if P=0 then P:=length(S)+1;
  425. S:=Trim(copy(S,1,P-1));
  426. if (copy(S,1,1)='_') and (Pos('$$',S)>0) then
  427. begin
  428. repeat
  429. P:=Pos('$$',S);
  430. if P>0 then Delete(S,1,P+1);
  431. until P=0;
  432. P:=Pos('$',S);
  433. Delete(S,1,P);
  434. PCount:=0;
  435. repeat
  436. P:=Pos('$',S); if P=0 then P:=length(S)+1;
  437. Params[PCount]:=TypeNames^.Add(copy(S,1,P-1));
  438. Inc(PCount);
  439. Delete(S,1,P);
  440. until S='';
  441. Sym^.Typ:=procsym;
  442. Sym^.SetParams(PCount,@Params);
  443. end
  444. else
  445. New(Sym, Init(S, varsym, 0, nil));
  446. Owner^.Insert(Sym);
  447. NextLine;
  448. end else
  449. if copy(Line,Indent+1,3)='---' then
  450. { child symtable }
  451. begin
  452. S:=Trim(copy(Line,Indent+1+12,255));
  453. if Level=1 then Typ:=unitsym else
  454. Typ:=typesym;
  455. if (Sym<>nil) and (Sym^.GetName=S) then
  456. else
  457. begin
  458. New(Sym, Init(S, Typ, 0, nil));
  459. Owner^.Insert(Sym);
  460. end;
  461. Sym^.Typ:=Typ;
  462. NextLine;
  463. New(Sym^.Items, Init(0,50));
  464. ProcessSymTable(Indent+2,Sym^.Items);
  465. end else
  466. { if Sym<>nil then}
  467. if copy(Line,Indent+1,1)=' ' then
  468. { reference }
  469. begin
  470. S:=copy(Line,Indent+1+2,255);
  471. P:=Pos('(',S); if P=0 then P:=length(S)+1;
  472. Source:=Trim(copy(S,1,P-1)); Delete(S,1,P);
  473. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  474. PX.Y:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  475. P:=Pos(')',S); if P=0 then P:=length(S)+1;
  476. PX.X:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  477. PS:=ModuleNames^.Add(Source);
  478. New(Ref, Init(PS, PX));
  479. if Sym^.References=nil then
  480. New(Sym^.References, Init(10,50));
  481. Sym^.References^.Insert(Ref);
  482. end;
  483. if ExitBack=false then
  484. NextLine;
  485. until EndOfFile or ExitBack;
  486. Dec(Level);
  487. end;
  488. begin
  489. DoneSymbolBrowser;
  490. InitSymbolBrowser;
  491. {$I-}
  492. Assign(f,FileName);
  493. Reset(f);
  494. Level:=0;
  495. NextLine;
  496. while (IOResult=0) and (EndOfFile=false) do
  497. ProcessSymTable(0,Modules);
  498. Close(f);
  499. EatIO;
  500. {$I+}
  501. end;*)
  502. {****************************************************************************
  503. TGDBValue
  504. ****************************************************************************}
  505. constructor TGDBValue.Init(Const AExpr : String;ASym : PSymbol);
  506. begin
  507. St := nil;
  508. S := ASym;
  509. Expr:=NewStr(AExpr);
  510. GDBI:=-1;
  511. end;
  512. destructor TGDBValue.Done;
  513. begin
  514. If Assigned(St) then
  515. begin
  516. DisposeStr(St);
  517. st:=nil;
  518. end;
  519. If Assigned(Expr) then
  520. begin
  521. DisposeStr(Expr);
  522. Expr:=nil;
  523. end;
  524. end;
  525. procedure TGDBValue.GetValue;
  526. var
  527. p : PAnsiChar;
  528. begin
  529. {$ifdef BROWSERCOL}
  530. {$ifndef NODEBUG}
  531. if not assigned(Debugger) then
  532. exit;
  533. if not Debugger^.IsRunning then
  534. exit;
  535. if (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) or (GDBI=Debugger^.RunCount) then
  536. exit;
  537. If Assigned(St) then
  538. DisposeStr(St);
  539. if assigned(Expr) then
  540. begin
  541. { avoid infinite recursion here }
  542. GDBI:=Debugger^.RunCount;
  543. p:=Debugger^.GetValue(Expr^);
  544. St:=NewStr(GetPChar(p));
  545. if assigned(p) then
  546. StrDispose(p);
  547. end;
  548. {$endif ndef NODEBUG}
  549. {$endif BROWSERCOL}
  550. end;
  551. function TGDBValue.GetText : String;
  552. begin
  553. GetValue;
  554. if assigned(St) then
  555. GetText:=S^.GetText+' = '+GetStr(St)
  556. else
  557. GetText:=S^.GetText;
  558. end;
  559. {****************************************************************************
  560. TGDBValueCollection
  561. ****************************************************************************}
  562. function TGDBValueCollection.At(Index: sw_Integer): PGDBValue;
  563. begin
  564. At:= Inherited At(Index);
  565. end;
  566. {****************************************************************************
  567. TFilteredSym
  568. ****************************************************************************}
  569. constructor TFilteredSym.Init(AItemSym:Sw_Integer;ASym : PSymbol);
  570. begin
  571. inherited Init;
  572. ItemSym:=AItemSym;
  573. Sym:=ASym;
  574. end;
  575. function TFilteredSym.GetText:String;
  576. begin
  577. GetText:=Sym^.GetText;
  578. end;
  579. destructor TFilteredSym.Done;
  580. begin
  581. inherited Done;
  582. end;
  583. {****************************************************************************
  584. TFilteredSymCollection
  585. ****************************************************************************}
  586. function TFilteredSymCollection.At(Index: sw_Integer): PFilteredSym;
  587. begin
  588. At:= Inherited At(Index);
  589. end;
  590. {****************************************************************************
  591. TSymbolView
  592. ****************************************************************************}
  593. constructor TSymbolView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  594. begin
  595. inherited Init(Bounds,1,AHScrollBar,AVScrollBar);
  596. {HScrollBar:=AHScrollBar;}
  597. MyBW:=nil;
  598. if assigned(HScrollBar) then
  599. begin
  600. HScrollBar^.SetRange(1,80);
  601. end;
  602. Options:=Options or (ofSelectable+ofTopSelect);
  603. EventMask:=EventMask or evBroadcast;
  604. end;
  605. procedure TSymbolView.ClearHighlights;
  606. begin
  607. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  608. end;
  609. procedure TSymbolView.AutoTrackSource;
  610. begin
  611. if Range>0 then
  612. TrackSource;
  613. end;
  614. procedure TSymbolView.OptionsDlg;
  615. begin
  616. if MyBW<> nil then
  617. Message(@IDEApp, evCommand, cmBrowserOptions, MyBW); { Send message }
  618. end;
  619. destructor TSymbolView.Done;
  620. begin
  621. EventMask:=EventMask and not evBroadcast;
  622. Inherited Done;
  623. end;
  624. procedure TSymbolView.SetState(AState: Word; Enable: Boolean);
  625. var OState: longint;
  626. begin
  627. OState:=State;
  628. inherited SetState(AState,Enable);
  629. if ((OState xor State) and sfFocused)<>0 then
  630. if GetState(sfFocused) then
  631. begin
  632. if (MiscOptions and moAutoTrackSource)<>0 then
  633. AutoTrackSource;
  634. end
  635. else
  636. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  637. end;
  638. procedure TSymbolView.Browse;
  639. begin
  640. SelectItem(Focused);
  641. end;
  642. procedure TSymbolView.GotoSource;
  643. begin
  644. if GotoItem(Focused) then
  645. PutCommand(Owner,evCommand,cmClose,nil);
  646. end;
  647. procedure TSymbolView.TrackSource;
  648. begin
  649. TrackItem(Focused,false);
  650. end;
  651. procedure TSymbolView.HandleEvent(var Event: TEvent);
  652. var DontClear: boolean;
  653. begin
  654. case Event.What of
  655. evKeyDown :
  656. begin
  657. DontClear:=false;
  658. case Event.KeyCode of
  659. kbEnter :
  660. Browse;
  661. kbCtrlEnter :
  662. GotoSource;
  663. kbSpaceBar :
  664. TrackSource;
  665. kbRight,kbLeft :
  666. if HScrollBar<>nil then
  667. HScrollBar^.HandleEvent(Event);
  668. else DontClear:=true;
  669. end;
  670. if DontClear=false then ClearEvent(Event);
  671. end;
  672. evMouseDown :
  673. begin
  674. if Event.double then
  675. begin
  676. Browse;
  677. ClearEvent(Event);
  678. end;
  679. end;
  680. evCommand :
  681. begin
  682. DontClear:=false;
  683. case Event.Command of
  684. cmSymBrowse :
  685. Browse;
  686. cmSymGotoSource :
  687. GotoSource;
  688. cmSymTrackSource :
  689. TrackSource;
  690. cmSymSaveAs,cmSaveAs :
  691. SaveAs;
  692. cmSymOptions :
  693. OptionsDlg;
  694. else DontClear:=true;
  695. end;
  696. if DontClear=false then ClearEvent(Event);
  697. end;
  698. evBroadcast :
  699. case Event.Command of
  700. cmListFocusChanged :
  701. if Event.InfoPtr=@Self then
  702. if (MiscOptions and moAutoTrackSource)<>0 then
  703. if GetState(sfFocused) then
  704. AutoTrackSource;
  705. end;
  706. end;
  707. inherited HandleEvent(Event);
  708. end;
  709. function TSymbolView.GetPalette: PPalette;
  710. const
  711. P: string[length(CBrowserListBox)] = CBrowserListBox;
  712. begin
  713. GetPalette:=@P;
  714. end;
  715. function TSymbolView.GetLocalMenu: PMenu;
  716. begin
  717. GetLocalMenu:=NewMenu(
  718. NewItem(menu_symlocal_browse,'',kbNoKey,cmSymBrowse,hcSymBrowse,
  719. NewItem(menu_symlocal_gotosource,'',kbNoKey,cmSymGotoSource,hcSymGotoSource,
  720. NewItem(menu_symlocal_tracksource,'',kbNoKey,cmSymTrackSource,hcSymTrackSource,
  721. NewLine(
  722. NewItem(menu_symlocal_saveas,'',kbNoKey,cmSymSaveAs,hcSymSaveAs,
  723. NewItem(menu_symlocal_options,'',kbNoKey,cmSymOptions,hcSymOptions,
  724. nil)))))));
  725. end;
  726. function TSymbolView.GotoItem(Item: sw_integer): boolean;
  727. begin
  728. SelectItem(Item);
  729. GotoItem:=true;
  730. end;
  731. function TSymbolView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  732. begin
  733. SelectItem(Item);
  734. TrackItem:=true;
  735. end;
  736. function LastBrowserWindow: PBrowserWindow;
  737. var BW: PBrowserWindow;
  738. procedure IsBW(P: PView);
  739. begin
  740. if (P^.HelpCtx=hcBrowserWindow) then
  741. BW:=pointer(P);
  742. end;
  743. begin
  744. BW:=nil;
  745. Desktop^.ForEach(TCallbackProcParam(@IsBW));
  746. LastBrowserWindow:=BW;
  747. end;
  748. function TSymbolView.TrackReference(R: PReference; AutoTrack: boolean): boolean;
  749. var W: PSourceWindow;
  750. BW: PBrowserWindow;
  751. P: TPoint;
  752. begin
  753. ClearHighlights;
  754. Desktop^.Lock;
  755. P.X:=R^.Position.X-1; P.Y:=R^.Position.Y-1;
  756. if AutoTrack then
  757. W:=SearchOnDesktop(R^.GetFileName,false)
  758. else
  759. W:=TryToOpenFile(nil,R^.GetFileName,P.X,P.Y,true);
  760. if not assigned(W) then
  761. begin
  762. Desktop^.Unlock;
  763. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  764. begin
  765. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  766. if Assigned(W) then
  767. W^.Select;
  768. end;
  769. Desktop^.Lock;
  770. end;
  771. if W<>nil then
  772. begin
  773. BW:=LastBrowserWindow;
  774. if BW=nil then
  775. W^.Select
  776. else
  777. begin
  778. Desktop^.Delete(W);
  779. Desktop^.InsertBefore(W,BW^.NextView);
  780. end;
  781. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,P.Y);
  782. end;
  783. Desktop^.UnLock;
  784. if Assigned(W)=false then
  785. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  786. TrackReference:=W<>nil;
  787. end;
  788. function TSymbolView.GotoReference(R: PReference): boolean;
  789. var W: PSourceWindow;
  790. begin
  791. Desktop^.Lock;
  792. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  793. if Assigned(W) then
  794. W^.Select
  795. else
  796. begin
  797. Desktop^.Unlock;
  798. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  799. begin
  800. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  801. if Assigned(W) then
  802. W^.Select;
  803. end;
  804. Desktop^.Lock;
  805. end;
  806. Desktop^.UnLock;
  807. if Assigned(W)=false then
  808. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  809. GotoReference:=W<>nil;
  810. end;
  811. {****************************************************************************
  812. TSymbolScopeView
  813. ****************************************************************************}
  814. constructor TSymbolScopeView.Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  815. begin
  816. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  817. Symbols:=ASymbols;
  818. New(SymbolsValue,Init(50,50));
  819. New(FilteredSym,Init(50,50));
  820. FilterSymbols(false); {select all}
  821. NewList(FilteredSym);
  822. SetRange(FilteredSym^.Count);
  823. end;
  824. destructor TSymbolScopeView.Done;
  825. begin
  826. {if assigned(Symbols) then
  827. begin
  828. the elements belong to other lists
  829. Symbols^.DeleteAll;
  830. dispose(Symbols,done);
  831. end;}
  832. if Assigned(SymbolsValue) then
  833. begin
  834. Dispose(SymbolsValue,Done);
  835. SymbolsValue:=nil;
  836. end;
  837. if Assigned(FilteredSym) then
  838. begin
  839. Dispose(FilteredSym,Done);
  840. FilteredSym:=nil;
  841. end;
  842. Inherited Done;
  843. end;
  844. procedure TSymbolScopeView.HandleEvent(var Event: TEvent);
  845. var OldFocus: sw_integer;
  846. begin
  847. case Event.What of
  848. evKeyDown :
  849. case Event.KeyCode of
  850. kbBack :
  851. begin
  852. LookUp(copy(LookUpStr,1,length(LookUpStr)-1));
  853. ClearEvent(Event);
  854. end;
  855. else
  856. if Event.CharCode in[#33..#255] then
  857. begin
  858. LookUp(LookUpStr+Event.CharCode);
  859. ClearEvent(Event);
  860. end;
  861. end;
  862. end;
  863. OldFocus:=Focused;
  864. inherited HandleEvent(Event);
  865. if OldFocus<>Focused then
  866. Lookup('');
  867. end;
  868. procedure TSymbolScopeView.Draw;
  869. var DeltaX: sw_integer;
  870. begin
  871. inherited Draw;
  872. if Assigned(HScrollBar)=false then DeltaX:=0 else
  873. DeltaX:=HScrollBar^.Value-HScrollBar^.Min;
  874. SetCursor(2+SymbolTypLen+length(LookUpStr)-DeltaX,Focused-TopItem);
  875. end;
  876. procedure TSymbolScopeView.LookUp(S: string);
  877. var LookUpS : String;
  878. function GetFilteredLookUpIdx(Item:Sw_Integer):Sw_Integer;
  879. var I, Count : Sw_Integer;
  880. F : PFilteredSym;
  881. UpS,LeftS : String;
  882. begin
  883. GetFilteredLookUpIdx:=-1;
  884. Count:=FilteredSym^.Count;
  885. if Count > 0 then
  886. for I:=0 to Count-1 do
  887. begin
  888. F:=FilteredSym^.At(I);
  889. if F^.ItemSym = Item then {perfect match}
  890. begin
  891. GetFilteredLookUpIdx:=I;
  892. break;
  893. end;
  894. if F^.ItemSym > Item then { test next item if perfect match is missing}
  895. begin
  896. LeftS:=UpcaseStr(F^.Sym^.GetName);
  897. UpS:=UpcaseStr(LookUpS);
  898. if copy(LeftS,1,length(UpS))=UpS then {perfect match}
  899. GetFilteredLookUpIdx:=I;
  900. break; {all you get is one second chance, it wont be any better from here}
  901. end;
  902. end;
  903. end;
  904. var Idx,Slength,I: Sw_integer;
  905. NS: string;
  906. begin
  907. NS:=LookUpStr;
  908. Slength:=Length(S);
  909. LookUpS:=S;
  910. if (Symbols=nil) or (S='') then NS:='' else
  911. begin
  912. S:=Symbols^.LookUp(S,Idx);
  913. if Idx<>-1 then
  914. begin
  915. { Have found, but get filtered list index first
  916. Some entries might be missing if need then look up agin }
  917. Idx:=GetFilteredLookUpIdx(Idx);
  918. if Idx<>-1 then
  919. begin
  920. NS:=S;
  921. FocusItem(Idx);
  922. end;
  923. end;
  924. end;
  925. LookUpStr:=Copy(NS,1,Slength);
  926. SetState(sfCursorVis,LookUpStr<>'');
  927. DrawView;
  928. end;
  929. function TSymbolScopeView.GotoItem(Item: sw_integer): boolean;
  930. var S: PSymbol;
  931. OK: boolean;
  932. F : PFilteredSym;
  933. begin
  934. OK:=Range>0;
  935. if OK then
  936. begin
  937. F:=List^.At(Item);
  938. S:=F^.Sym;
  939. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  940. if OK then
  941. OK:=GotoReference(S^.References^.At(0));
  942. end;
  943. GotoItem:=OK;
  944. end;
  945. function TSymbolScopeView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  946. var S: PSymbol;
  947. OK: boolean;
  948. F: PFilteredSym;
  949. begin
  950. OK:=Range>0;
  951. if OK then
  952. begin
  953. F:=List^.At(Item);
  954. S:=F^.Sym;
  955. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  956. if OK then
  957. OK:=TrackReference(S^.References^.At(0),AutoTrack);
  958. end;
  959. TrackItem:=OK;
  960. end;
  961. procedure TSymbolScopeView.SetGDBCol;
  962. var S : PSymbol;
  963. I : sw_integer;
  964. begin
  965. if assigned(MyBW) and (SymbolsValue^.Count=0) then
  966. begin
  967. For i:=0 to Symbols^.Count-1 do
  968. begin
  969. S:=Symbols^.At(I);
  970. SymbolsValue^.Insert(New(PGDBValue,Init(GetStr(MyBW^.Prefix)+S^.GetName,S)));
  971. end;
  972. end;
  973. end;
  974. procedure TSymbolScopeView.FilterSymbols(AFilter:boolean);
  975. var S : PSymbol;
  976. I : sw_integer;
  977. Flags : Longint;
  978. bUni, bLab, bcon, btyp, bvar, bprc, binh: boolean;
  979. begin
  980. Flags:=0;
  981. if assigned(MyBW) then
  982. Flags:=MyBW^.GetFlags;
  983. bUni:=(Flags and bfUnits)<>0;
  984. bLab:=(Flags and bfLabels)<>0;
  985. bCon:=(Flags and bfConstants)<>0;
  986. bTyp:=(Flags and bfTypes)<>0;
  987. bVar:=(Flags and bfVariables)<>0;
  988. bPrc:=(Flags and bfProcedures)<>0;
  989. bInh:=(Flags and bfInherited)<>0;
  990. FilteredSym^.FreeAll;
  991. if Symbols^.Count = 0 then exit;
  992. For i:=0 to Symbols^.Count-1 do
  993. begin
  994. S:=Symbols^.At(I);
  995. if AFilter then begin
  996. {---------- only selected ones ----------}
  997. case S^.typ of
  998. labelsym: if not bLab then continue;
  999. namespacesym,staticvarsym,localvarsym,paravarsym,
  1000. fieldvarsym,absolutevarsym,programparasym: if not bVar then continue;
  1001. procsym,propertysym,syssym : if not bPrc then continue;
  1002. typesym : if not bTyp then continue;
  1003. constsym,enumsym : if not bCon then continue;
  1004. unitsym : if not bUni then continue;
  1005. errorsym,macrosym,undefinedsym: ; {accepted anyway}
  1006. end;
  1007. end;
  1008. FilteredSym^.Insert(New(PFilteredSym,Init(I,S)));
  1009. end;
  1010. end;
  1011. function TSymbolScopeView.GetText(Item,MaxLen: Sw_Integer): String;
  1012. var S1: string;
  1013. S : PSymbol;
  1014. SG : PGDBValue;
  1015. F : PFilteredSym;
  1016. begin
  1017. F:=FilteredSym^.At(Item);
  1018. Item:=F^.ItemSym;
  1019. S:=Symbols^.At(Item);
  1020. if Assigned(SymbolsValue) and (SymbolsValue^.Count>Item) then
  1021. SG:=SymbolsValue^.At(Item)
  1022. else
  1023. SG:=nil;
  1024. if assigned(SG) then
  1025. S1:=SG^.getText
  1026. else
  1027. S1:=S^.GetText;
  1028. GetText:=copy(S1,1,MaxLen);
  1029. end;
  1030. {****************************************************************************
  1031. TSymbolReferenceView
  1032. ****************************************************************************}
  1033. constructor TSymbolReferenceView.Init(var Bounds: TRect; AReferences: PReferenceCollection;
  1034. AHScrollBar, AVScrollBar: PScrollBar);
  1035. begin
  1036. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  1037. References:=AReferences;
  1038. NewList(AReferences);
  1039. SetRange(References^.Count);
  1040. end;
  1041. destructor TSymbolReferenceView.Done;
  1042. begin
  1043. Inherited Done;
  1044. end;
  1045. procedure TSymbolReferenceView.HandleEvent(var Event: TEvent);
  1046. var OldFocus: sw_integer;
  1047. DontClear: boolean;
  1048. begin
  1049. OldFocus:=Focused;
  1050. case Event.What of
  1051. evKeyDown :
  1052. begin
  1053. DontClear:=false;
  1054. case Event.KeyCode of
  1055. kbEnter :
  1056. TrackItem(Focused,false);
  1057. kbCtrlEnter :
  1058. GotoItem(Focused);
  1059. else DontClear:=true;
  1060. end;
  1061. if DontClear=false then ClearEvent(Event);
  1062. end;
  1063. end;
  1064. inherited HandleEvent(Event);
  1065. if OldFocus<>Focused then
  1066. if (MiscOptions and moAutoTrackSource)=0 then
  1067. ClearHighlights;
  1068. end;
  1069. procedure TSymbolReferenceView.Browse;
  1070. begin
  1071. { do nothing here }
  1072. end;
  1073. function TSymbolReferenceView.GetText(Item,MaxLen: Sw_Integer): String;
  1074. var S: string;
  1075. P: PReference;
  1076. begin
  1077. P:=References^.At(Item);
  1078. S:=P^.GetFileName+'('+IntToStr(P^.Position.Y)+','+IntToStr(P^.Position.X)+')';
  1079. GetText:=copy(S,1,MaxLen);
  1080. end;
  1081. function TSymbolReferenceView.GotoItem(Item: sw_integer): boolean;
  1082. var OK: boolean;
  1083. begin
  1084. OK:=Range>0;
  1085. if OK then
  1086. OK:=GotoReference(List^.At(Item));
  1087. GotoItem:=OK;
  1088. end;
  1089. function TSymbolReferenceView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  1090. var OK: boolean;
  1091. begin
  1092. OK:=Range>0;
  1093. if OK then
  1094. OK:=TrackReference(List^.At(Item),AutoTrack);
  1095. TrackItem:=OK;
  1096. end;
  1097. procedure TSymbolReferenceView.SelectItem(Item: Sw_Integer);
  1098. begin
  1099. GotoItem(Item);
  1100. end;
  1101. constructor TSymbolMemInfoView.Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  1102. begin
  1103. inherited Init(Bounds,'');
  1104. Options:=Options or (ofSelectable+ofTopSelect);
  1105. MemInfo:=AMemInfo;
  1106. MyBW:=nil;
  1107. end;
  1108. destructor TSymbolMemInfoView.Done;
  1109. begin
  1110. { if assigned(MemInfo) then
  1111. dispose(MemInfo);}
  1112. Inherited Done;
  1113. end;
  1114. procedure TSymbolMemInfoView.GetText(var S: String);
  1115. function SizeStr(Size: longint): string;
  1116. var S: string[40];
  1117. begin
  1118. S:=IntToStrL(Size,7);
  1119. S:=S+' byte';
  1120. if Size>1 then S:=S+'s';
  1121. if Size=-1 then
  1122. SizeStr:='variable'
  1123. else
  1124. SizeStr:=S;
  1125. end;
  1126. function AddrStr(Addr: longint): string;
  1127. { Warning this is endian specific code !! (PM) }
  1128. type TLongint = record LoW,HiW: word; end;
  1129. begin
  1130. with TLongint(Addr) do
  1131. AddrStr:='$'+hexstr(HiW,4)+hexstr(LoW,4);
  1132. end;
  1133. begin
  1134. ClearFormatParams;
  1135. AddFormatParamStr(msg_sizeinmemory);
  1136. AddFormatParamStr(msg_sizeonstack);
  1137. S:=
  1138. FormatStrF(
  1139. #13+
  1140. { ' Memory location: '+AddrStr(MemInfo^.Addr)+#13+
  1141. ' Local address: '+AddrStr(MemInfo^.LocalAddr)+#13+}
  1142. { ??? internal linker ??? }
  1143. '%18s: '+SizeStr(MemInfo^.Size)+#13+
  1144. '%18s: '+SizeStr(MemInfo^.PushSize)+#13+
  1145. '',
  1146. FormatParams);
  1147. end;
  1148. function TSymbolMemInfoView.GetPalette: PPalette;
  1149. begin
  1150. GetPalette:=inherited GetPalette;
  1151. end;
  1152. function TSymbolMemoView.GetPalette: PPalette;
  1153. const P: string[length(CFPSymbolMemo)] = CFPSymbolMemo;
  1154. begin
  1155. GetPalette:=@P;
  1156. end;
  1157. {****************************************************************************
  1158. TSymbolInheritanceView
  1159. ****************************************************************************}
  1160. constructor TSymbolInheritanceView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  1161. begin
  1162. {$ifdef HASOUTLINE}
  1163. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  1164. {$else not HASOUTLINE}
  1165. inherited Init(Bounds,1,AVScrollBar);
  1166. HScrollBar:=AHScrollBar;
  1167. {$endif not HASOUTLINE}
  1168. Options:=Options or (ofSelectable+ofTopSelect);
  1169. Root:=ARoot;
  1170. MyBW:=nil;
  1171. ExpandAll(Root);
  1172. {$ifdef HASOUTLINE}
  1173. Update;
  1174. {$else not HASOUTLINE}
  1175. SetRange(GetNumChildrenExposed(Root));
  1176. {$endif not HASOUTLINE}
  1177. end;
  1178. destructor TSymbolInheritanceView.Done;
  1179. begin
  1180. { do not dispose,
  1181. belongs to a symbolcollection (PM)
  1182. if assigned(Root) then
  1183. dispose(Root,done); }
  1184. Inherited Done;
  1185. end;
  1186. function TSymbolInheritanceView.GetRoot: Pointer;
  1187. begin
  1188. GetRoot:=Root;
  1189. end;
  1190. function TSymbolInheritanceView.HasChildren(Node: Pointer): Boolean;
  1191. begin
  1192. HasChildren:=GetNumChildren(Node)>0;
  1193. end;
  1194. function TSymbolInheritanceView.GetChild(Node: Pointer; I: sw_Integer): Pointer;
  1195. begin
  1196. GetChild:=PObjectSymbol(Node)^.GetDescendant(I);
  1197. end;
  1198. function TSymbolInheritanceView.GetNumChildren(Node: Pointer): sw_Integer;
  1199. begin
  1200. GetNumChildren:=PObjectSymbol(Node)^.GetDescendantCount;
  1201. end;
  1202. function TSymbolInheritanceView.GetNumChildrenExposed(Node: Pointer) : sw_Integer;
  1203. var
  1204. Nb : integer;
  1205. P : PObjectSymbol;
  1206. Procedure AddCount(P : PObjectSymbol);
  1207. var
  1208. i,count : integer;
  1209. D : PObjectSymbol;
  1210. begin
  1211. if not assigned(P) then
  1212. exit;
  1213. Count:=P^.GetDescendantCount;
  1214. Inc(Nb,Count);
  1215. for I:=0 to Count-1 do
  1216. begin
  1217. D:=P^.GetDescendant(I);
  1218. AddCount(D);
  1219. end;
  1220. end;
  1221. begin
  1222. Nb:=0;
  1223. AddCount(Node);
  1224. GetNumChildrenExposed:=Nb;
  1225. end;
  1226. procedure TSymbolInheritanceView.Adjust(Node: Pointer; Expand: Boolean);
  1227. begin
  1228. PObjectSymbol(Node)^.Expanded:=Expand;
  1229. end;
  1230. function TSymbolInheritanceView.IsExpanded(Node: Pointer): Boolean;
  1231. begin
  1232. IsExpanded:=PObjectSymbol(Node)^.Expanded;
  1233. end;
  1234. procedure TSymbolInheritanceView.HandleEvent(var Event: TEvent);
  1235. var DontClear: boolean;
  1236. {$ifndef HASOUTLINE}
  1237. P: TPoint;
  1238. {$endif HASOUTLINE}
  1239. begin
  1240. case Event.What of
  1241. evKeyDown :
  1242. begin
  1243. DontClear:=false;
  1244. case Event.KeyCode of
  1245. {$ifndef HASOUTLINE}
  1246. kbEnter:
  1247. NodeSelected(GetLineNode(Cursor.Y-Origin.Y));
  1248. {$endif HASOUTLINE}
  1249. kbLeft,kbRight,
  1250. kbCtrlLeft,kbCtrlRight :
  1251. if Assigned(HScrollBar) then
  1252. HScrollBar^.HandleEvent(Event)
  1253. else
  1254. DontClear:=true;
  1255. else DontClear:=true;
  1256. end;
  1257. if DontClear=false then ClearEvent(Event);
  1258. end;
  1259. evMouseDown :
  1260. begin
  1261. {$ifndef HASOUTLINE}
  1262. MakeLocal(Event.Where,P);
  1263. SetCursor(P.X,P.Y);
  1264. {$endif HASOUTLINE}
  1265. if Event.double then
  1266. begin
  1267. Message(@Self,evKeyDown,kbEnter,nil);
  1268. ClearEvent(Event);
  1269. end;
  1270. end;
  1271. evCommand :
  1272. begin
  1273. DontClear:=false;
  1274. case Event.Command of
  1275. cmSymBrowse :
  1276. Message(@Self,evKeyDown,kbEnter,nil);
  1277. cmSymSaveAs,cmSaveAs :
  1278. SaveAs;
  1279. else DontClear:=true;
  1280. end;
  1281. if DontClear=false then ClearEvent(Event);
  1282. end;
  1283. end;
  1284. inherited HandleEvent(Event);
  1285. end;
  1286. function TSymbolInheritanceView.GetPalette: PPalette;
  1287. const P: string[length(CBrowserOutline)] = CBrowserOutline;
  1288. begin
  1289. GetPalette:=@P;
  1290. end;
  1291. function TSymbolInheritanceView.GetLocalMenu: PMenu;
  1292. begin
  1293. GetLocalMenu:=NewMenu(
  1294. NewItem(menu_symlocal_browse,'',kbNoKey,cmSymBrowse,hcSymBrowse,
  1295. NewLine(
  1296. NewItem(menu_symlocal_saveas,'',kbNoKey,cmSymSaveAs,hcSymSaveAs,
  1297. nil))));
  1298. end;
  1299. function TSymbolInheritanceView.SaveToFile(const AFileName: string): boolean;
  1300. var OK: boolean;
  1301. S: PBufStream;
  1302. st : string;
  1303. P : PObjectSymbol;
  1304. procedure WriteSymbolTree(P:PObjectSymbol;Depth:Sw_Integer);
  1305. var
  1306. Q : PObjectSymbol;
  1307. Nc,Des,Count : integer;
  1308. Space : String;
  1309. begin
  1310. if not assigned(P) then
  1311. exit;
  1312. Des:=0;
  1313. Count:=GetNumChildren{Exposed}(P);
  1314. if Count=0 then exit;
  1315. SetLength(Space,Depth*2);
  1316. for nc:=1 to Length(Space) do Space[nc]:=' ';
  1317. While Count>Des do
  1318. begin
  1319. if not ok then exit;
  1320. Q:=P^.GetDescendant(Des);
  1321. st:=GetText(Q);
  1322. S^.Write(Space[1],Length(Space));
  1323. if not OK then exit;
  1324. S^.Write(St[1],length(St));
  1325. OK:=(S^.Status=stOK);
  1326. if not OK then exit;
  1327. S^.Write(EOL[1],length(EOL));
  1328. OK:=(S^.Status=stOK);
  1329. if not OK then exit;
  1330. if Ok then
  1331. WriteSymbolTree(Q,Depth+1);
  1332. Inc(Des);
  1333. end;
  1334. end;
  1335. begin
  1336. New(S, Init(AFileName,stCreate,4096));
  1337. OK:=Assigned(S) and (S^.Status=stOK);
  1338. if OK then
  1339. begin
  1340. P:=Root;
  1341. st:=GetText(P);
  1342. S^.Write(St[1],length(St));
  1343. OK:=(S^.Status=stOK);
  1344. if OK then
  1345. begin
  1346. S^.Write(EOL[1],length(EOL));
  1347. OK:=(S^.Status=stOK);
  1348. if OK then
  1349. WriteSymbolTree(P,1);
  1350. end;
  1351. end;
  1352. if Assigned(S) then Dispose(S, Done);
  1353. SaveToFile:=OK;
  1354. end;
  1355. function TSymbolInheritanceView.SaveAs: Boolean;
  1356. var
  1357. DefExt,Title,Filename : string;
  1358. Re : word;
  1359. begin
  1360. SaveAs := False;
  1361. Filename:='list.txt';
  1362. DefExt:='*.txt';
  1363. Title:='Save content';
  1364. Re:=Application^.ExecuteDialog(New(PFPFileDialog, Init(DefExt,
  1365. Title, label_name, fdOkButton, FileId)), @FileName);
  1366. if Re <> cmCancel then
  1367. SaveAs := SaveToFile(FileName);
  1368. end;
  1369. {$ifdef HASOUTLINE}
  1370. function TSymbolInheritanceView.GetText(Node: Pointer): String;
  1371. begin
  1372. GetText:=PObjectSymbol(Node)^.GetName;
  1373. end;
  1374. {$else not HASOUTLINE}
  1375. function TSymbolInheritanceView.GetNode(I : sw_Integer) : Pointer;
  1376. var
  1377. P : PObjectSymbol;
  1378. begin
  1379. P:=Root;
  1380. If Assigned(P) then
  1381. P:=P^.GetDescendant(I);
  1382. GetNode:=Pointer(P);
  1383. end;
  1384. procedure TSymbolInheritanceView.ExpandAll(Node: Pointer);
  1385. var
  1386. i : integer;
  1387. P : Pointer;
  1388. begin
  1389. Adjust(Node,true);
  1390. For i:=0 to GetNumChildren(Node)-1 do
  1391. begin
  1392. P:=GetChild(Node,I);
  1393. if Assigned(P) then
  1394. ExpandAll(P);
  1395. end;
  1396. end;
  1397. function TSymbolInheritanceView.GetLineNode(Item : sw_Integer) : Pointer;
  1398. var
  1399. P : PObjectSymbol;
  1400. NT: Integer;
  1401. procedure FindSymbol(var P:PObjectSymbol);
  1402. var
  1403. Q : PObjectSymbol;
  1404. Nc,Des : integer;
  1405. begin
  1406. if not assigned(P) then
  1407. exit;
  1408. Des:=0;
  1409. While (NT<Item) and (Des<GetNumChildren(P)) do
  1410. begin
  1411. Q:=P^.GetDescendant(Des);
  1412. Inc(NT);
  1413. if NT=Item then
  1414. begin
  1415. P:=Q;
  1416. exit;
  1417. end;
  1418. Nc:=GetNumChildrenExposed(Q);
  1419. If NT+Nc<Item then
  1420. Inc(NT,Nc)
  1421. else
  1422. begin
  1423. FindSymbol(Q);
  1424. P:=Q;
  1425. exit;
  1426. end;
  1427. Inc(Des);
  1428. end;
  1429. end;
  1430. begin
  1431. P:=Root;
  1432. NT:=0;
  1433. FindSymbol(P);
  1434. GetLineNode:=P;
  1435. end;
  1436. function TSymbolInheritanceView.GetText(Item,MaxLen: Sw_Integer): String;
  1437. var
  1438. P,Ans : PObjectSymbol;
  1439. NC,NT,NumParents : Integer;
  1440. S : String;
  1441. procedure FindSymbol(var P:PObjectSymbol);
  1442. var
  1443. Q : PObjectSymbol;
  1444. Des : integer;
  1445. begin
  1446. if not assigned(P) then
  1447. exit;
  1448. Des:=0;
  1449. While (NT<Item) and (Des<GetNumChildren(P)) do
  1450. begin
  1451. Q:=P^.GetDescendant(Des);
  1452. Inc(NT);
  1453. if NT=Item then
  1454. begin
  1455. P:=Q;
  1456. exit;
  1457. end;
  1458. Nc:=GetNumChildrenExposed(Q);
  1459. If NT+Nc<Item then
  1460. Inc(NT,Nc)
  1461. else
  1462. begin
  1463. FindSymbol(Q);
  1464. P:=Q;
  1465. exit;
  1466. end;
  1467. Inc(Des);
  1468. end;
  1469. end;
  1470. begin
  1471. P:=Root;
  1472. NT:=0;
  1473. FindSymbol(P);
  1474. if assigned(P) then
  1475. begin
  1476. S:=P^.GetName;
  1477. Ans:=P^.Parent;
  1478. NumParents:=0;
  1479. While Assigned(Ans) do
  1480. begin
  1481. Inc(NumParents);
  1482. Ans:=Ans^.Parent;
  1483. end;
  1484. S:=CharStr('-',NumParents)+S;
  1485. GetText:=Copy(S,1,MaxLen);
  1486. end
  1487. else
  1488. GetText:='';
  1489. end;
  1490. {$endif HASOUTLINE}
  1491. procedure TSymbolInheritanceView.Selected(I: sw_Integer);
  1492. var P: pointer;
  1493. begin
  1494. P:=GetNode(I);
  1495. NodeSelected(P);
  1496. end;
  1497. procedure TSymbolInheritanceView.NodeSelected(P: pointer);
  1498. var
  1499. S: PSymbol;
  1500. St : String;
  1501. Anc: PObjectSymbol;
  1502. begin
  1503. if P=nil then Exit;
  1504. S:=PObjectSymbol(P)^.Symbol;
  1505. { this happens for the top objects view (PM) }
  1506. if S=nil then exit;
  1507. st:=S^.GetName;
  1508. if S^.Ancestor=nil then
  1509. Anc:=ObjectTree
  1510. else
  1511. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1512. OpenSymbolBrowser(Origin.X-1,
  1513. {$ifdef HASOUTLINE}
  1514. FOC-Delta.Y+1,
  1515. {$else not HASOUTLINE}
  1516. Origin.Y+1,
  1517. {$endif not HASOUTLINE}
  1518. st,
  1519. S^.GetText,S,nil,
  1520. S^.Items,S^.References,Anc,S^.MemInfo);
  1521. end;
  1522. {****************************************************************************
  1523. TBrowserTab
  1524. ****************************************************************************}
  1525. constructor TBrowserTab.Init(var Bounds: TRect; AItems: PBrowserTabItem);
  1526. begin
  1527. inherited Init(Bounds);
  1528. Options:=Options or ofPreProcess;
  1529. Items:=AItems;
  1530. SetParams(0,0);
  1531. end;
  1532. procedure TBrowserTab.SetParams(AFlags: word; ACurrent: Sw_integer);
  1533. begin
  1534. Flags:=AFlags;
  1535. SelectItem(ACurrent);
  1536. end;
  1537. procedure TBrowserTab.SelectItem(Index: Sw_integer);
  1538. var P: PBrowserTabItem;
  1539. begin
  1540. Current:=Index;
  1541. P:=GetItem(Current);
  1542. if (P<>nil) and (P^.Link<>nil) then
  1543. P^.Link^.Focus;
  1544. DrawView;
  1545. end;
  1546. function TBrowserTab.GetItemCount: sw_integer;
  1547. var Count: integer;
  1548. P: PBrowserTabItem;
  1549. begin
  1550. Count:=0; P:=Items;
  1551. while (P<>nil) do
  1552. begin
  1553. Inc(Count);
  1554. P:=P^.Next;
  1555. end;
  1556. GetItemCount:=Count;
  1557. end;
  1558. function TBrowserTab.GetItem(Index: sw_integer): PBrowserTabItem;
  1559. var Counter: integer;
  1560. P: PBrowserTabItem;
  1561. begin
  1562. P:=Items;
  1563. Counter:=0;
  1564. while (P<>nil) and (Counter<Index) do
  1565. begin
  1566. P:=P^.Next;
  1567. Inc(Counter);
  1568. end;
  1569. GetItem:=P;
  1570. end;
  1571. procedure TBrowserTab.Draw;
  1572. var B: TDrawBuffer;
  1573. SelColor, NormColor, C: word;
  1574. I,CurX,Count: Sw_integer;
  1575. function Names(Idx: integer): AnsiChar;
  1576. begin
  1577. Names:=GetItem(Idx)^.Sign;
  1578. end;
  1579. begin
  1580. NormColor:=GetColor(1); SelColor:=GetColor(2);
  1581. MoveChar(B,#196{-},SelColor,Size.X);
  1582. CurX:=0; Count:=0;
  1583. for I:=0 to GetItemCount-1 do
  1584. if (Flags and (1 shl I))<>0 then
  1585. begin
  1586. Inc(Count);
  1587. if Current=I then C:=SelColor
  1588. else C:=NormColor;
  1589. if Count=1 then MoveChar(B[CurX],#180,SelColor,1)
  1590. else MoveChar(B[CurX],#179,SelColor,1);
  1591. MoveCStr(B[CurX+1],' '+Names(I)+' ',C);
  1592. Inc(CurX,4);
  1593. end;
  1594. if Count>0 then
  1595. MoveChar(B[CurX],#195,SelColor,1);
  1596. WriteLine(0,0,Size.X,Size.Y,B);
  1597. end;
  1598. procedure TBrowserTab.HandleEvent(var Event: TEvent);
  1599. var I,Idx: integer;
  1600. DontClear: boolean;
  1601. P: TPoint;
  1602. function GetItemForCoord(X: integer): integer;
  1603. var I,CurX,Idx: integer;
  1604. begin
  1605. CurX:=0; Idx:=-1;
  1606. for I:=0 to GetItemCount-1 do
  1607. if (Flags and (1 shl I))<>0 then
  1608. begin
  1609. if (CurX+1<=X) and (X<=CurX+3) then
  1610. begin Idx:=I; Break; end;
  1611. Inc(CurX,4);
  1612. end;
  1613. GetItemForCoord:=Idx;
  1614. end;
  1615. begin
  1616. case Event.What of
  1617. evMouseDown :
  1618. if MouseInView(Event.Where) then
  1619. begin
  1620. repeat
  1621. MakeLocal(Event.Where,P);
  1622. Idx:=GetItemForCoord(P.X);
  1623. if Idx<>-1 then
  1624. SelectItem(Idx);
  1625. until not MouseEvent(Event, evMouseMove);
  1626. ClearEvent(Event);
  1627. end;
  1628. evKeyDown :
  1629. begin
  1630. DontClear:=false; Idx:=-1;
  1631. for I:=0 to GetItemCount-1 do
  1632. if (GetCtrlCode(GetItem(I)^.Sign)=Event.KeyCode){ or
  1633. (GetItem(I)^.Sign=UpCase(Event.CharCode))} then
  1634. if (Flags and (1 shl I))<>0 then
  1635. begin
  1636. Idx:=I;
  1637. Break;
  1638. end;
  1639. if Idx=-1 then
  1640. DontClear:=true
  1641. else
  1642. SelectItem(Idx);
  1643. if DontClear=false then ClearEvent(Event);
  1644. end;
  1645. end;
  1646. inherited HandleEvent(Event);
  1647. end;
  1648. function TBrowserTab.GetPalette: PPalette;
  1649. const P: string[length(CBrowserTab)] = CBrowserTab;
  1650. begin
  1651. GetPalette:=@P;
  1652. end;
  1653. destructor TBrowserTab.Done;
  1654. begin
  1655. if Items<>nil then DisposeBrowserTabList(Items);
  1656. inherited Done;
  1657. end;
  1658. procedure TUnitInfoPanel.HandleEvent(var Event: TEvent);
  1659. begin
  1660. if (Event.What=evBroadcast) and (Event.Command=cmListItemSelected) and
  1661. (InOwnerCall=false) then
  1662. begin
  1663. InOwnerCall:=true;
  1664. if Assigned(Owner) then
  1665. Owner^.HandleEvent(Event);
  1666. InOwnerCall:=false;
  1667. end;
  1668. inherited HandleEvent(Event);
  1669. end;
  1670. constructor TBrowserWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  1671. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  1672. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemINfo);
  1673. var R,R2,R3: TRect;
  1674. HSB,VSB: PScrollBar;
  1675. CST: PColorStaticText;
  1676. I: sw_integer;
  1677. function CreateVSB(R: TRect): PScrollBar;
  1678. var R2: TRect;
  1679. SB: PScrollBar;
  1680. begin
  1681. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  1682. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1683. CreateVSB:=SB;
  1684. end;
  1685. function CreateHSB(R: TRect): PScrollBar;
  1686. var R2: TRect;
  1687. SB: PScrollBar;
  1688. begin
  1689. R2.Copy(R); R2.Move(0,1); R2.A.Y:=R2.B.Y-1;
  1690. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1691. CreateHSB:=SB;
  1692. end;
  1693. begin
  1694. inherited Init(Bounds, FormatStrStr(dialog_browse,ATitle), ANumber);
  1695. HelpCtx:=hcBrowserWindow;
  1696. Sym:=ASym;
  1697. Prefix:=NewStr(APrefix);
  1698. BrowserFlags:=DefaultDispayFlags shl 30 or DefaultSymbolFlags;
  1699. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  1700. {$ifndef NODEBUG}
  1701. if {assigned(Debugger) and Debugger^.IsRunning and}
  1702. assigned(Sym) and (Sym^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) then
  1703. begin
  1704. New(DebuggerValue,Init(ATitle,Sym));
  1705. New(ST, Init(R, ' '+DebuggerValue^.GetText));
  1706. end
  1707. else
  1708. {$endif NODEBUG}
  1709. begin
  1710. New(ST, Init(R, ' '+AName));
  1711. DebuggerValue:=nil;
  1712. end;
  1713. ST^.GrowMode:=gfGrowHiX;
  1714. Insert(ST);
  1715. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);
  1716. if assigned(ASymbols) and (ASymbols^.Count>0) then
  1717. begin
  1718. HSB:=CreateHSB(R);
  1719. Insert(HSB);
  1720. VSB:=CreateVSB(R);
  1721. Insert(VSB);
  1722. New(ScopeView, Init(R, ASymbols, HSB, VSB));
  1723. ScopeView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1724. Insert(ScopeView);
  1725. ScopeView^.MyBW:=@Self;
  1726. ScopeView^.SetGDBCol;
  1727. ScopeView^.FilterSymbols(true);
  1728. ScopeView^.SetRange(ScopeView^.FilteredSym^.Count);
  1729. end;
  1730. if assigned(AReferences) and (AReferences^.Count>0) then
  1731. begin
  1732. HSB:=CreateHSB(R);
  1733. Insert(HSB);
  1734. VSB:=CreateVSB(R);
  1735. Insert(VSB);
  1736. New(ReferenceView, Init(R, AReferences, HSB, VSB));
  1737. ReferenceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1738. Insert(ReferenceView);
  1739. ReferenceView^.MyBW:=@Self;
  1740. end;
  1741. if assigned(AInheritance) then
  1742. begin
  1743. HSB:=CreateHSB(R);
  1744. Insert(HSB);
  1745. VSB:=CreateVSB(R);
  1746. Insert(VSB);
  1747. New(InheritanceView, Init(R, HSB,VSB, AInheritance));
  1748. InheritanceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1749. Insert(InheritanceView);
  1750. InheritanceView^.MyBW:=@Self;
  1751. end;
  1752. if assigned(AMemInfo) then
  1753. begin
  1754. New(MemInfoView, Init(R, AMemInfo));
  1755. MemInfoView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1756. Insert(MemInfoView);
  1757. MemInfoView^.MyBW:=@Self;
  1758. end;
  1759. if Assigned(Asym) and (TypeOf(ASym^)=TypeOf(TModuleSymbol)) then
  1760. with PModuleSymbol(Sym)^ do
  1761. begin
  1762. New(UnitInfo, Init(R));
  1763. UnitInfo^.GetExtent(R3);
  1764. R2.Copy(R3);
  1765. R2.B.Y:=R2.A.Y+3;
  1766. if (Assigned(UsedUnits) or Assigned(DependentUnits))=false then
  1767. R2.B.Y:=R3.B.Y;
  1768. HSB:=CreateHSB(R2); {UnitInfo^.Insert(HSB); HSB:=nil;}
  1769. VSB:=CreateVSB(R2);
  1770. {UnitInfo^.Insert(VSB);
  1771. VSB will be owned by UnitInfoText PM }
  1772. New(UnitInfoText, Init(R2,HSB,VSB, nil));
  1773. with UnitInfoText^ do
  1774. begin
  1775. GrowMode:=gfGrowHiX;
  1776. if Assigned(LoadedFrom) then
  1777. begin
  1778. AddLine(FormatStrStr2('%s : %s',msg_usedfirstin,GetStr(LoadedFrom)));
  1779. AddLine(FormatStrStr('%s : ',msg_mainsource));
  1780. AddLine(FormatStrStr(' %s',GetStr(MainSource)));
  1781. if Assigned(SourceFiles) and (SourceFiles^.Count>1) then
  1782. begin
  1783. AddLine(FormatStrStr('%s : ',msg_sourcefiles));
  1784. for I:=0 to SourceFiles^.Count-1 do
  1785. AddLine(FormatStrStr(' %s',GetStr(SourceFiles^.At(I))));
  1786. end;
  1787. end;
  1788. end;
  1789. UnitInfo^.Insert(UnitInfoText);
  1790. if Assigned(UsedUnits) then
  1791. begin
  1792. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  1793. New(CST, Init(R2,#180' Used units '#195+CharStr(#196,255),ColorIndex(12),false));
  1794. CST^.GrowMode:=gfGrowHiX;
  1795. UnitInfo^.Insert(CST);
  1796. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+4;
  1797. if Assigned(DependentUnits)=false then R2.B.Y:=R3.B.Y;
  1798. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  1799. HSB:=nil;
  1800. VSB:=CreateVSB(R2);
  1801. {UnitInfo^.Insert(VSB); this created crashes,
  1802. that were difficult to findout PM }
  1803. New(UnitInfoUsed, Init(R2,UsedUnits,HSB,VSB));
  1804. UnitInfoUsed^.GrowMode:=gfGrowHiY+gfGrowHiX;
  1805. UnitInfoUsed^.MyBW:=@Self;
  1806. UnitInfo^.Insert(UnitInfoUsed);
  1807. end;
  1808. if Assigned(DependentUnits) then
  1809. begin
  1810. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  1811. New(CST, Init(R2,#180' Dependent units '#195+CharStr(#196,255),ColorIndex(12),false));
  1812. CST^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1813. UnitInfo^.Insert(CST);
  1814. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R3.B.Y;
  1815. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  1816. HSB:=nil;
  1817. VSB:=CreateVSB(R2);
  1818. { UnitInfo^.Insert(VSB); this created crashes,
  1819. that were difficult to findout PM }
  1820. New(UnitInfoDependent, Init(R2,DependentUnits,HSB,VSB));
  1821. UnitInfoDependent^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1822. UnitInfoDependent^.MyBW:=@Self;
  1823. UnitInfo^.Insert(UnitInfoDependent);
  1824. end;
  1825. if Assigned(UnitInfoText) then
  1826. UnitInfoText^.Select;
  1827. Insert(UnitInfo);
  1828. end;
  1829. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.B.Y:=R.A.Y+1;
  1830. New(PageTab, Init(R,
  1831. NewBrowserTabItem(label_browsertab_scope,ScopeView,
  1832. NewBrowserTabItem(label_browsertab_reference,ReferenceView,
  1833. NewBrowserTabItem(label_browsertab_inheritance,InheritanceView,
  1834. NewBrowserTabItem(label_browsertab_memory,MemInfoView,
  1835. NewBrowserTabItem(label_browsertab_unit,UnitInfo,
  1836. nil)))))));
  1837. PageTab^.GrowMode:=gfGrowHiX;
  1838. Insert(PageTab);
  1839. if assigned(ScopeView) {Scope assinged and chosen to be selected by default}
  1840. and ((DefaultBrowserPane=0) or not assigned(ReferenceView)) then
  1841. SelectTab(btScope)
  1842. else if assigned(ReferenceView) then
  1843. SelectTab(btReferences)
  1844. else if assigned(MemInfoView) then
  1845. SelectTab(btMemInfo)
  1846. else
  1847. if assigned(InheritanceView) then
  1848. SelectTab(btInheritance);
  1849. end;
  1850. destructor TBrowserWindow.Done;
  1851. begin
  1852. { UnitInfoText needs to be removed first
  1853. to avoid crashes within the UnitInfo destructor PM }
  1854. if Assigned(UnitInfoText) then
  1855. begin
  1856. UnitInfo^.Delete(UnitInfoText);
  1857. Dispose(UnitInfoText,Done);
  1858. UnitInfoText:=nil;
  1859. end;
  1860. if assigned(DebuggerValue) then
  1861. begin
  1862. Dispose(DebuggerValue,Done);
  1863. DebuggerValue:=nil;
  1864. end;
  1865. if assigned(Prefix) then
  1866. begin
  1867. DisposeStr(Prefix);
  1868. Prefix:=nil;
  1869. end;
  1870. inherited Done;
  1871. end;
  1872. procedure TBrowserWindow.HandleEvent(var Event: TEvent);
  1873. var DontClear: boolean;
  1874. S: PSymbol;
  1875. Symbols: PSymbolCollection;
  1876. Anc: PObjectSymbol;
  1877. P: TPoint;
  1878. begin
  1879. case Event.What of
  1880. evBroadcast :
  1881. case Event.Command of
  1882. cmDebuggerStopped :
  1883. begin
  1884. if Assigned(DebuggerValue) and
  1885. (DebuggerValue^.GDBI<>PtrInt(Event.InfoPtr)) then
  1886. begin
  1887. If Assigned(ST^.Text) then
  1888. DisposeStr(ST^.Text);
  1889. ST^.Text:=NewStr(DebuggerValue^.GetText);
  1890. ST^.DrawView;
  1891. end;
  1892. end;
  1893. cmSearchWindow :
  1894. ClearEvent(Event);
  1895. cmListItemSelected :
  1896. begin
  1897. S:=nil;
  1898. if (Event.InfoPtr=ScopeView) then
  1899. begin
  1900. S:=ScopeView^.FilteredSym^.At(ScopeView^.Focused)^.Sym;
  1901. MakeGlobal(ScopeView^.Origin,P);
  1902. Desktop^.MakeLocal(P,P); Inc(P.Y,ScopeView^.Focused-ScopeView^.TopItem);
  1903. Inc(P.Y);
  1904. end;
  1905. if (Event.InfoPtr=UnitInfoUsed) then
  1906. begin
  1907. S:=UnitInfoUsed^.Symbols^.At(UnitInfoUsed^.Focused);
  1908. MakeGlobal(UnitInfoUsed^.Origin,P);
  1909. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoUsed^.Focused-UnitInfoUsed^.TopItem);
  1910. Inc(P.Y);
  1911. end;
  1912. if (Event.InfoPtr=UnitInfoDependent) then
  1913. begin
  1914. S:=UnitInfoDependent^.Symbols^.At(UnitInfoDependent^.Focused);
  1915. MakeGlobal(UnitInfoDependent^.Origin,P);
  1916. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoDependent^.Focused-UnitInfoDependent^.TopItem);
  1917. Inc(P.Y);
  1918. end;
  1919. if Assigned(S) then
  1920. begin
  1921. if S^.Ancestor=nil then Anc:=nil else
  1922. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1923. Symbols:=S^.Items;
  1924. if (not assigned(Symbols) or (symbols^.count=0)) then
  1925. if assigned(S^.Ancestor) then
  1926. Symbols:=S^.Ancestor^.Items;
  1927. if (S^.GetReferenceCount>0) or (assigned(Symbols) and (Symbols^.Count>0)) or (Anc<>nil) then
  1928. OpenSymbolBrowser(Origin.X-1,P.Y,
  1929. S^.GetName,
  1930. ScopeView^.GetText(ScopeView^.Focused,255),
  1931. S,@self,
  1932. Symbols,S^.References,Anc,S^.MemInfo);
  1933. ClearEvent(Event);
  1934. end;
  1935. end;
  1936. end;
  1937. { evCommand :
  1938. begin
  1939. DontClear:=false;
  1940. case Event.Command of
  1941. cmGotoSymbol :
  1942. if Event.InfoPtr=ScopeView then
  1943. if ReferenceView<>nil then
  1944. if ReferenceView^.Range>0 then
  1945. ReferenceView^.GotoItem(0);
  1946. cmTrackSymbol :
  1947. if Event.InfoPtr=ScopeView then
  1948. if (ScopeView<>nil) and (ScopeView^.Range>0) then
  1949. begin
  1950. S:=ScopeView^.At(ScopeView^.Focused);
  1951. if (S^.References<>nil) and (S^.References^.Count>0) then
  1952. TrackItem(S^.References^.At(0));
  1953. else DontClear:=true;
  1954. end;
  1955. if DontClear=false then ClearEvent(Event);
  1956. end;}
  1957. evKeyDown :
  1958. begin
  1959. DontClear:=false;
  1960. case Event.KeyCode of
  1961. kbEsc :
  1962. Close;
  1963. kbAltI :
  1964. If not Disassemble then
  1965. DontClear:=true;
  1966. else DontClear:=true;
  1967. end;
  1968. if DontClear=false then ClearEvent(Event);
  1969. end;
  1970. end;
  1971. inherited HandleEvent(Event);
  1972. end;
  1973. function TBrowserWindow.Disassemble : boolean;
  1974. begin
  1975. Disassemble:=false;
  1976. if not assigned(sym) or (sym^.typ<>procsym) then
  1977. exit;
  1978. { We need to load exefile }
  1979. {$ifndef NODEBUG}
  1980. InitGDBWindow;
  1981. if not assigned(Debugger) then
  1982. begin
  1983. new(Debugger,Init);
  1984. if assigned(Debugger) then
  1985. Debugger^.SetExe(ExeFile);
  1986. end;
  1987. if not assigned(Debugger) or not Debugger^.HasExe then
  1988. exit;
  1989. { goto source/assembly mixture }
  1990. InitDisassemblyWindow;
  1991. DisassemblyWindow^.LoadFunction(Sym^.GetName);
  1992. DisassemblyWindow^.SelectInDebugSession;
  1993. Disassemble:=true;
  1994. {$else NODEBUG}
  1995. NoDebugger;
  1996. {$endif NODEBUG}
  1997. end;
  1998. function TBrowserWindow.GetFlags: longint;
  1999. begin
  2000. GetFlags:=BrowserFlags;
  2001. end;
  2002. procedure TBrowserWindow.SetFlags(AFlags: longint);
  2003. begin
  2004. BrowserFlags:=AFlags;
  2005. if assigned(ScopeView) then
  2006. begin
  2007. ScopeView^.FilterSymbols(true);
  2008. ScopeView^.SetRange(ScopeView^.FilteredSym^.Count);
  2009. ScopeView^.DrawView;
  2010. end;
  2011. end;
  2012. procedure TBrowserWindow.SetState(AState: Word; Enable: Boolean);
  2013. var OldState: word;
  2014. begin
  2015. OldState:=State;
  2016. inherited SetState(AState,Enable);
  2017. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  2018. SetCmdState([cmSaveAs],Enable);
  2019. { if ((State xor OldState) and sfActive)<>0 then
  2020. if GetState(sfActive)=false then
  2021. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);}
  2022. end;
  2023. procedure TBrowserWindow.Close;
  2024. begin
  2025. inherited Close;
  2026. end;
  2027. procedure TBrowserWindow.SelectTab(BrowserTab: Sw_integer);
  2028. var Tabs: Sw_integer;
  2029. {$ifndef NODEBUG}
  2030. PB : PBreakpoint;
  2031. {$endif}
  2032. PS :PString;
  2033. l : longint;
  2034. begin
  2035. case BrowserTab of
  2036. btScope :
  2037. if assigned(ScopeView) then
  2038. ScopeView^.Select;
  2039. btReferences :
  2040. if assigned(ReferenceView) then
  2041. ReferenceView^.Select;
  2042. btMemInfo:
  2043. if assigned(MemInfoView) then
  2044. MemInfoView^.Select;
  2045. {$ifndef NODEBUG}
  2046. btBreakWatch :
  2047. begin
  2048. if Assigned(Sym) then
  2049. begin
  2050. if Pos('proc',Sym^.GetText)>0 then
  2051. { insert function breakpoint }
  2052. begin
  2053. { make it visible }
  2054. PS:=Sym^.Name;
  2055. l:=Length(PS^);
  2056. If PS^[l]='*' then
  2057. begin
  2058. PB:=BreakpointsCollection^.GetType(bt_function,copy(GetStr(PS),1,l-1));
  2059. If Assigned(PB) then
  2060. BreakpointsCollection^.Delete(PB);
  2061. Sym^.Name:=NewStr(copy(GetStr(PS),1,l-1));
  2062. DrawView;
  2063. DisposeStr(PS);
  2064. end
  2065. else
  2066. begin
  2067. Sym^.Name:=NewStr(GetStr(PS)+'*');
  2068. DrawView;
  2069. New(PB,init_function(GetStr(PS)));
  2070. DisposeStr(PS);
  2071. BreakpointsCollection^.Insert(PB);
  2072. BreakpointsCollection^.Update;
  2073. end;
  2074. end
  2075. else if pos('var',Sym^.GetText)>0 then
  2076. { insert watch point }
  2077. begin
  2078. { make it visible }
  2079. PS:=Sym^.Name;
  2080. l:=Length(PS^);
  2081. If PS^[l]='*' then
  2082. begin
  2083. PB:=BreakpointsCollection^.GetType(bt_awatch,copy(PS^,1,l-1));
  2084. If Assigned(PB) then
  2085. BreakpointsCollection^.Delete(PB);
  2086. Sym^.Name:=NewStr(copy(PS^,1,l-1));
  2087. DrawView;
  2088. DisposeStr(PS);
  2089. end
  2090. else
  2091. begin
  2092. Sym^.Name:=NewStr(GetStr(PS)+'*');
  2093. DrawView;
  2094. New(PB,init_type(bt_awatch,GetStr(PS)));
  2095. DisposeStr(PS);
  2096. BreakpointsCollection^.Insert(PB);
  2097. BreakpointsCollection^.Update;
  2098. end;
  2099. end;
  2100. end;
  2101. end;
  2102. {$endif NODEBUG}
  2103. end;
  2104. Tabs:=0;
  2105. if assigned(ScopeView) then
  2106. Tabs:=Tabs or (1 shl btScope);
  2107. if assigned(ReferenceView) then
  2108. Tabs:=Tabs or (1 shl btReferences);
  2109. if assigned(InheritanceView) then
  2110. Tabs:=Tabs or (1 shl btInheritance);
  2111. if assigned(MemInfoView) then
  2112. Tabs:=Tabs or (1 shl btMemInfo);
  2113. {$ifndef NODEBUG}
  2114. if Assigned(Sym) then
  2115. if (Pos('proc',Sym^.GetText)>0) or (Pos('var',Sym^.GetText)>0) then
  2116. Tabs:=Tabs or (1 shl btBreakWatch);
  2117. {$endif NODEBUG}
  2118. if assigned(UnitInfo) then
  2119. Tabs:=Tabs or (1 shl btUnitInfo);
  2120. if PageTab<>nil then PageTab^.SetParams(Tabs,BrowserTab);
  2121. end;
  2122. function TBrowserWindow.GetPalette: PPalette;
  2123. const S: string[length(CBrowserWindow)] = CBrowserWindow;
  2124. begin
  2125. GetPalette:=@S;
  2126. end;
  2127. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  2128. ParentBrowser : PBrowserWindow;
  2129. Symbols: PSymbolCollection; References: PReferenceCollection;
  2130. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo);
  2131. var R: TRect;
  2132. PB : PBrowserWindow;
  2133. St,st2 : string;
  2134. begin
  2135. if X=0 then X:=Desktop^.Size.X-35;
  2136. R.A.X:=X; R.A.Y:=Y;
  2137. R.B.X:=R.A.X+35; R.B.Y:=R.A.Y+15;
  2138. while (R.B.Y>Desktop^.Size.Y) do R.Move(0,-1);
  2139. if assigned(ParentBrowser) and assigned(ParentBrowser^.Prefix) and
  2140. assigned(ParentBrowser^.sym) and
  2141. (ParentBrowser^.sym^.typ<>unitsym)
  2142. then
  2143. begin
  2144. st:=GetStr(ParentBrowser^.Prefix)+' '+Name;
  2145. end
  2146. else
  2147. st:=Name;
  2148. st2:=st;
  2149. if assigned(S) and ((S^.Flags and sfPointer)<>0) then
  2150. begin
  2151. st:=st+'^';
  2152. if assigned(S^.Ancestor) and
  2153. ((S^.Ancestor^.Flags and sfRecord)<>0) then
  2154. st:=st+'.';
  2155. end
  2156. else if assigned(S) and ((S^.Flags and sfRecord)<>0) then
  2157. st:=st+'.';
  2158. PB:=New(PBrowserWindow, Init(R,
  2159. st2,SearchFreeWindowNo,S,Line,st,
  2160. Symbols,References,Inheritance,MemInfo));
  2161. if (assigned(S) and (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym])) or
  2162. (assigned(ParentBrowser) and ParentBrowser^.IsValid) then
  2163. PB^.IsValid:=true;
  2164. Desktop^.Insert(PB);
  2165. end;
  2166. END.