fpsymbol.pas 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041
  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. {Shell of TSymbol used to filter inherited and to display qualified symbols }
  68. PHollowSymbol = ^THollowSymbol;
  69. THollowSymbol = object(TSymbol)
  70. Sym : PSymbol; { orginal symbol, need for unit info save}
  71. Parent : PSymbol; { to get object name from }
  72. NeedPrefix : Boolean; { GetName will add object prefix if needed }
  73. constructor Init(ASymbol,AParent:PSymbol);
  74. function GetName: string; virtual;
  75. destructor Done; virtual;
  76. end;
  77. PHollowSymbolCollection=^THollowSymbolCollection;
  78. THollowSymbolCollection = Object(TSortedSymbolCollection)
  79. function At(Index: Sw_Integer): PHollowSymbol;
  80. end;
  81. PFilteredSym = ^TFilteredSym;
  82. TFilteredSym = Object(TObject)
  83. constructor Init(AItemSym:Sw_Integer;ASym : PSymbol);
  84. function GetText:String;
  85. destructor Done;virtual;
  86. private
  87. Sym:PSymbol;
  88. ItemSym : Sw_Integer;
  89. end;
  90. PFilteredSymCollection=^TFilteredSymCollection;
  91. TFilteredSymCollection = Object(TCollection)
  92. function At(Index: sw_Integer): PFilteredSym;
  93. end;
  94. PSymbolView = ^TSymbolView;
  95. TSymbolView = object(THSListBox)
  96. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  97. destructor Done;virtual;
  98. procedure HandleEvent(var Event: TEvent); virtual;
  99. procedure SetState(AState: Word; Enable: Boolean); virtual;
  100. function GotoItem(Item: sw_integer): boolean; virtual;
  101. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  102. function GetPalette: PPalette; virtual;
  103. function GetLocalMenu: PMenu; virtual;
  104. procedure ClearHighlights;
  105. procedure AutoTrackSource; virtual;
  106. procedure Browse; virtual;
  107. procedure GotoSource; virtual;
  108. procedure TrackSource; virtual;
  109. procedure OptionsDlg; virtual;
  110. private
  111. MyBW : PBrowserWindow;
  112. function TrackReference(R: PReference; AutoTrack: boolean): boolean; virtual;
  113. function GotoReference(R: PReference): boolean; virtual;
  114. end;
  115. PSymbolScopeView = ^TSymbolScopeView;
  116. TSymbolScopeView = object(TSymbolView)
  117. constructor Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  118. destructor Done; virtual;
  119. procedure SetGDBCol;
  120. procedure FilterSymbols(AFilter:boolean);
  121. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  122. procedure HandleEvent(var Event: TEvent); virtual;
  123. procedure Draw; virtual;
  124. procedure LookUp(S: string); virtual;
  125. function GotoItem(Item: sw_integer): boolean; virtual;
  126. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  127. private
  128. Inh : Boolean; {filter for inheritance is possible}
  129. ObjSymbol : PSymbol;
  130. OrgSymbols: PSymbolCollection;
  131. FilteredSym: PFilteredSymCollection;
  132. Symbols : PHollowSymbolCollection;
  133. SymbolsValue : PGDBValueCollection;
  134. LookupStr: string;
  135. procedure CopyOrgSymbols;
  136. procedure PullInInheritance;
  137. end;
  138. PSymbolReferenceView = ^TSymbolReferenceView;
  139. TSymbolReferenceView = object(TSymbolView)
  140. constructor Init(var Bounds: TRect; AReferences: PReferenceCollection; AHScrollBar, AVScrollBar: PScrollBar);
  141. destructor Done; virtual;
  142. procedure HandleEvent(var Event: TEvent); virtual;
  143. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  144. procedure SelectItem(Item: Sw_Integer); virtual;
  145. function GotoItem(Item: sw_integer): boolean; virtual;
  146. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  147. procedure Browse; virtual;
  148. private
  149. References: PReferenceCollection;
  150. end;
  151. PSymbolMemInfoView = ^TSymbolMemInfoView;
  152. TSymbolMemInfoView = object(TStaticText)
  153. constructor Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  154. destructor Done; virtual;
  155. procedure GetText(var S: String); virtual;
  156. function GetPalette: PPalette; virtual;
  157. private
  158. MemInfo: PSymbolMemInfo;
  159. MyBW : PBrowserWindow;
  160. end;
  161. PSymbolMemoView = ^TSymbolMemoView;
  162. TSymbolMemoView = object(TFPMemo)
  163. function GetPalette: PPalette; virtual;
  164. end;
  165. PSymbolInheritanceView = ^TSymbolInheritanceView;
  166. {$ifdef HASOUTLINE}
  167. TSymbolInheritanceView = object(TLocalMenuOutlineViewer)
  168. {$else notHASOUTLINE}
  169. TSymbolInheritanceView = object(TLocalMenuListBox)
  170. {$endif HASOUTLINE}
  171. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  172. destructor Done; virtual;
  173. function GetRoot: Pointer; virtual;
  174. function HasChildren(Node: Pointer): Boolean; virtual;
  175. function GetChild(Node: Pointer; I: sw_Integer): Pointer; virtual;
  176. function GetNumChildren(Node: Pointer): sw_Integer; virtual;
  177. function GetNumChildrenExposed(Node: Pointer) : sw_Integer; virtual;
  178. procedure Adjust(Node: Pointer; Expand: Boolean); virtual;
  179. function IsExpanded(Node: Pointer): Boolean; virtual;
  180. function NodeCountToFoc(aFoc:Sw_Integer):Sw_Integer;
  181. {$ifdef HASOUTLINE}
  182. function GetText(Node: Pointer): String; virtual;
  183. {$else not HASOUTLINE}
  184. procedure ExpandAll(Node: Pointer);
  185. function GetNode(I : sw_Integer) : Pointer; virtual;
  186. function GetLineNode(Item : sw_Integer) : Pointer; virtual;
  187. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  188. {$endif HASOUTLINE}
  189. procedure NodeSelected(P: pointer); virtual;
  190. procedure Selected(I: sw_Integer); virtual;
  191. procedure HandleEvent(var Event: TEvent); virtual;
  192. function GetPalette: PPalette; virtual;
  193. function GetLocalMenu: PMenu; virtual;
  194. function SaveToFile(const AFileName: string): boolean; virtual;
  195. function SaveAs: Boolean; virtual;
  196. private
  197. Root : PObjectSymbol;
  198. MyBW : PBrowserWindow;
  199. end;
  200. PBrowserTabItem = ^TBrowserTabItem;
  201. TBrowserTabItem = record
  202. Sign : AnsiChar;
  203. Link : PView;
  204. Next : PBrowserTabItem;
  205. end;
  206. PBrowserTab = ^TBrowserTab;
  207. TBrowserTab = object(TView)
  208. Items: PBrowserTabItem;
  209. constructor Init(var Bounds: TRect; AItems: PBrowserTabItem);
  210. function GetItemCount: sw_integer; virtual;
  211. function GetItem(Index: sw_integer): PBrowserTabItem; virtual;
  212. procedure SetParams(AFlags: word; ACurrent: Sw_integer); virtual;
  213. procedure SelectItem(Index: Sw_integer); virtual;
  214. procedure Draw; virtual;
  215. function GetPalette: PPalette; virtual;
  216. procedure HandleEvent(var Event: TEvent); virtual;
  217. destructor Done; virtual;
  218. private
  219. Flags : word;
  220. Current : Sw_integer;
  221. end;
  222. PUnitInfoPanel = ^TUnitInfoPanel;
  223. TUnitInfoPanel = object(TPanel)
  224. InOwnerCall: boolean;
  225. UnitInfoUsed: PSymbolScopeView;
  226. UnitInfoDependent: PSymbolScopeView;
  227. UsedVSB: PScrollBar;
  228. DependVSB: PScrollBar;
  229. UsedCST: PColorStaticText;
  230. DependCST: PColorStaticText;
  231. procedure SetState(AState: Word; Enable: Boolean); virtual;
  232. procedure HandleEvent(var Event: TEvent); virtual;
  233. end;
  234. PBrowserLinkedCollection=^TBrowserLinkedCollection;
  235. PBrowserLinked = ^TBrowserLinked;
  236. TBrowserWindow = object(TFPWindow)
  237. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  238. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  239. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemInfo);
  240. procedure HandleEvent(var Event: TEvent); virtual;
  241. {procedure SetState(AState: Word; Enable: Boolean); virtual;}
  242. procedure UpdateCommands; Virtual;
  243. procedure Close; virtual;
  244. procedure SelectTab(BrowserTab: Sw_integer); virtual;
  245. function GetPalette: PPalette; virtual;
  246. function Disassemble : boolean;
  247. function GetFlags: longint; virtual;
  248. procedure SetFlags(AFlags: longint); virtual;
  249. procedure SizeLimits (Var Min, Max: TPoint); Virtual;
  250. procedure OnResize; Virtual; { called on window resize event }
  251. destructor Done;virtual;
  252. private
  253. BrowserFlags : Longint;
  254. PrevSize : TPoint;
  255. PageTab : PBrowserTab;
  256. ST : PStaticText;
  257. Sym : PSymbol;
  258. ScopeView : PSymbolScopeView;
  259. ReferenceView : PSymbolReferenceView;
  260. InheritanceView: PSymbolInheritanceView;
  261. MemInfoView : PSymbolMemInfoView;
  262. UnitInfoText : PSymbolMemoView;
  263. UnitInfoUsed : PSymbolScopeView;
  264. UnitInfoDependent : PSymbolScopeView;
  265. UnitInfo : PUnitInfoPanel;
  266. Prefix : PString;
  267. IsValid : boolean;
  268. DebuggerValue : PGDBValue;
  269. BrowserLinked : PBrowserLinked;
  270. end;
  271. { Tree to go to previous browser windows }
  272. { Holds all parametrs to recreate closed previous window if needed to be}
  273. TBrowserLinked = Object(TObject)
  274. BrowserWindow : PBrowserWindow;
  275. Previous : PBrowserLinked;
  276. Branches : PBrowserLinkedCollection;
  277. Origin, Size : TPoint;
  278. Title: TTitleStr;
  279. Number: Sw_Integer;
  280. Name : String;
  281. Prefix: string;
  282. Sym : PSymbol;
  283. Symbols: PSymbolCollection;
  284. References: PReferenceCollection;
  285. Inheritance: PObjectSymbol;
  286. MemInfo: PSymbolMemInfo;
  287. BrowserFlags : Longint;
  288. Tab : sw_integer;
  289. ScopeTop : sw_integer;
  290. ScopeFocused:sw_integer;
  291. ReferenceTop : sw_integer;
  292. ReferenceFocused:sw_integer;
  293. InheritanceTop : sw_integer;
  294. InheritanceFocused : sw_integer;
  295. UnitInfoUsedTop : sw_integer;
  296. UnitInfoUsedFocused:sw_integer;
  297. UnitInfoDependentTop : sw_integer;
  298. UnitInfoDependentFocused:sw_integer;
  299. constructor Init(ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  300. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  301. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemInfo);
  302. procedure InsertWindow(BW : PBrowserWindow);
  303. procedure PreviousWindow; { activate previous window }
  304. procedure CreateNewWindow;
  305. procedure LeaveTree; { cut itself from tree }
  306. destructor Done;virtual;
  307. end;
  308. TBrowserLinkedCollection = Object(TCollection)
  309. function At(Index: sw_Integer): PBrowserLinked;
  310. end;
  311. function OpenSymbolBrowser(X,Y,W,H: Sw_integer;const Name,Line: string;S : PSymbol;
  312. ParentBrowser : PBrowserWindow;
  313. Symbols: PSymbolCollection; References: PReferenceCollection;
  314. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo):PBrowserWindow;
  315. function IsSymbolInfoAvailable: boolean;
  316. procedure OpenOneSymbolBrowser(Name : String);
  317. procedure CloseAllBrowsers;
  318. procedure RemoveBrowsersCollection;
  319. const
  320. GlobalsCollection : PSortedCollection = nil;
  321. ProcedureCollection : PSortedCollection = nil;
  322. ModulesCollection : PSortedCollection = nil;
  323. var BrowserRoot : PBrowserLinked;
  324. implementation
  325. uses App,Strings,Stddlg,Keyboard,
  326. FVConsts,
  327. {$ifdef BROWSERCOL}
  328. symconst,
  329. {$endif BROWSERCOL}
  330. WUtils,WEditor,WConsts,
  331. FPConst,FPUtils,FPVars,{$ifndef FPDEBUG}FPDebug{$endif},FPIDE;
  332. {$ifdef USERESSTRINGS}
  333. resourcestring
  334. {$else}
  335. const
  336. {$endif}
  337. msg_symbolnotfound = #3'Symbol %s not found';
  338. msg_nobrowserinfoavailable = 'No Browser info available';
  339. msg_cantfindfile = 'Can''t find %s';
  340. menu_local_gotosource = '~G~oto source';
  341. menu_local_tracksource = '~T~rack source';
  342. menu_local_options = '~O~ptions...';
  343. menu_local_clear = '~C~lear';
  344. menu_local_saveas = 'Save ~a~s';
  345. { Symbol view local menu items }
  346. menu_symlocal_browse = '~B~rowse';
  347. menu_symlocal_previous = '~P~revious';
  348. menu_symlocal_gotosource = '~G~oto source';
  349. menu_symlocal_tracksource = '~T~rack source';
  350. menu_symlocal_saveas = 'Save ~a~s';
  351. menu_symlocal_options = '~O~ptions...';
  352. { Symbol browser meminfo page }
  353. msg_sizeinmemory = 'Size in memory';
  354. msg_sizeonstack = 'Size on stack';
  355. msg_usedfirstin = 'Used first in';
  356. msg_mainsource = 'Main source';
  357. msg_sourcefiles = 'Source files';
  358. dialog_browse = 'Browse: %s';
  359. const { Symbol browser tabs }
  360. { must be AnsiChar constants (so cannot be resourcestring)}
  361. label_browsertab_scope = 'S';
  362. label_browsertab_reference = 'R';
  363. label_browsertab_inheritance = 'I';
  364. label_browsertab_memory = 'M';
  365. label_browsertab_unit = 'U';
  366. function ReplaceCurrent:longint;
  367. var K:TKeyEvent;
  368. ShiftState : byte;
  369. begin
  370. K:=PollShiftStateEvent;
  371. ShiftState:=GetKeyEventShiftState(K);
  372. if (ShiftState and kbShift)=0 then
  373. ReplaceCurrent:=1
  374. else
  375. ReplaceCurrent:=0; { Reverse replace current }
  376. end;
  377. procedure CloseAllBrowsers;
  378. procedure SendCloseIfBrowser(P: PView);
  379. begin
  380. if assigned(P) and
  381. ((TypeOf(P^)=TypeOf(TBrowserWindow)) or
  382. (TypeOf(P^)=TypeOf(TSymbolView)) or
  383. (TypeOf(P^)=TypeOf(TSymbolScopeView)) or
  384. (TypeOf(P^)=TypeOf(TSymbolReferenceView)) or
  385. (TypeOf(P^)=TypeOf(TSymbolMemInfoView)) or
  386. (TypeOf(P^)=TypeOf(TSymbolInheritanceView)) or
  387. (TypeOf(P^)=TypeOf(TSymbolMemoView))) then
  388. Message(P,evCommand,cmClose,nil);
  389. end;
  390. begin
  391. Desktop^.ForEach(TCallbackProcParam(@SendCloseIfBrowser));
  392. end;
  393. procedure RemoveBrowsersCollection;
  394. begin
  395. if assigned(GlobalsCollection) then
  396. begin
  397. GlobalsCollection^.deleteAll;
  398. Dispose(GlobalsCollection,done);
  399. GlobalsCollection:=nil;
  400. end;
  401. if assigned(ProcedureCollection) then
  402. begin
  403. ProcedureCollection^.deleteAll;
  404. Dispose(ProcedureCollection,done);
  405. ProcedureCollection:=nil;
  406. end;
  407. if assigned(ModulesCollection) then
  408. begin
  409. ModulesCollection^.deleteAll;
  410. Dispose(ModulesCollection,done);
  411. ModulesCollection:=nil;
  412. end;
  413. end;
  414. function NewBrowserTabItem(ASign: AnsiChar; ALink: PView; ANext: PBrowserTabItem): PBrowserTabItem;
  415. var P: PBrowserTabItem;
  416. begin
  417. New(P); FillChar(P^,SizeOf(P^),0);
  418. with P^ do begin Sign:=ASign; Link:=ALink; Next:=ANext; end;
  419. NewBrowserTabItem:=P;
  420. end;
  421. procedure DisposeBrowserTabItem(P: PBrowserTabItem);
  422. begin
  423. if P<>nil then Dispose(P);
  424. end;
  425. procedure DisposeBrowserTabList(P: PBrowserTabItem);
  426. begin
  427. if P<>nil then
  428. begin
  429. if P^.Next<>nil then DisposeBrowserTabList(P^.Next);
  430. DisposeBrowserTabItem(P);
  431. end;
  432. end;
  433. function IsSymbolInfoAvailable: boolean;
  434. begin
  435. IsSymbolInfoAvailable:=BrowCol.Modules<>nil;
  436. end;
  437. procedure OpenOneSymbolBrowser(Name : String);
  438. var Index : sw_integer;
  439. PS,S,MS : PSymbol;
  440. Anc : PObjectSymbol;
  441. P : Pstring;
  442. Symbols: PSymbolCollection;
  443. PB : PBrowserWindow;
  444. function Search(P : PSymbol) : boolean;
  445. begin
  446. Search:=UpcaseStr(P^.Items^.LookUp(Name,Index))=Name;
  447. end;
  448. function SearchModule(P : PSymbol) : boolean;
  449. begin
  450. SearchModule:=UpcaseStr(P^.Name^)=Name;
  451. end;
  452. begin
  453. Name:=UpcaseStr(Name);
  454. If BrowCol.Modules<>nil then
  455. begin
  456. PS:=BrowCol.Modules^.FirstThat(TCallbackFunBoolParam(@Search));
  457. MS:=BrowCol.Modules^.FirstThat(TCallbackFunBoolParam(@SearchModule));
  458. If assigned(PS) then
  459. begin
  460. S:=PS^.Items^.At(Index);
  461. Symbols:=S^.Items;
  462. if (not assigned(symbols) or (symbols^.count=0)) and
  463. assigned(S^.Ancestor) then
  464. Symbols:=S^.Ancestor^.Items;
  465. if (S^.Flags and (sfObject or sfClass))=0 then
  466. Anc:=nil
  467. else if S^.Ancestor=nil then
  468. Anc:=ObjectTree
  469. else
  470. Anc:=SearchObjectForSymbol(S^.Ancestor);
  471. PB:=OpenSymbolBrowser(0,20,0,0,
  472. PS^.Items^.At(Index)^.GetName,
  473. PS^.Items^.At(Index)^.GetText,
  474. PS^.Items^.At(Index),nil,
  475. Symbols,PS^.Items^.At(Index)^.References,Anc,PS^.MemInfo);
  476. BrowserRoot^.InsertWindow(PB);
  477. end
  478. else If assigned(MS) then
  479. begin
  480. Symbols:=MS^.Items;
  481. PB:=OpenSymbolBrowser(0,20,0,0,
  482. MS^.GetName,
  483. MS^.GetText,
  484. MS,nil,
  485. Symbols,MS^.References,nil,nil);
  486. BrowserRoot^.InsertWindow(PB);
  487. end
  488. else
  489. begin
  490. P:=@Name;
  491. ErrorBox(msg_symbolnotfound,@P);
  492. end;
  493. end
  494. else
  495. ErrorBox(msg_nobrowserinfoavailable,nil);
  496. end;
  497. (*procedure ReadBrowseLog(FileName: string);
  498. var f: text;
  499. IOOK,EndOfFile: boolean;
  500. Line: string;
  501. procedure NextLine;
  502. begin
  503. readln(f,Line);
  504. EndOfFile:=Eof(f);
  505. end;
  506. var Level: integer;
  507. procedure ProcessSymTable(Indent: integer; Owner: PSymbolCollection);
  508. var IndentS,S,Source: string;
  509. Sym: PSymbol;
  510. Ref: PSymbolReference;
  511. P: byte;
  512. PX: TPoint;
  513. PS: PString;
  514. PCount: integer;
  515. Params: array[0..30] of PString;
  516. Typ: tsymtyp;
  517. ExitBack: boolean;
  518. begin
  519. Inc(Level);
  520. IndentS:=CharStr(' ',Indent); ExitBack:=false;
  521. Sym:=nil;
  522. repeat
  523. if copy(Line,1,length(IndentS))<>IndentS then ExitBack:=true else
  524. if copy(Line,Indent+1,3)='***' then
  525. { new symbol }
  526. begin
  527. S:=copy(Line,Indent+1+3,255);
  528. P:=Pos('***',S); if P=0 then P:=length(S)+1;
  529. S:=Trim(copy(S,1,P-1));
  530. if (copy(S,1,1)='_') and (Pos('$$',S)>0) then
  531. begin
  532. repeat
  533. P:=Pos('$$',S);
  534. if P>0 then Delete(S,1,P+1);
  535. until P=0;
  536. P:=Pos('$',S);
  537. Delete(S,1,P);
  538. PCount:=0;
  539. repeat
  540. P:=Pos('$',S); if P=0 then P:=length(S)+1;
  541. Params[PCount]:=TypeNames^.Add(copy(S,1,P-1));
  542. Inc(PCount);
  543. Delete(S,1,P);
  544. until S='';
  545. Sym^.Typ:=procsym;
  546. Sym^.SetParams(PCount,@Params);
  547. end
  548. else
  549. New(Sym, Init(S, varsym, 0, nil));
  550. Owner^.Insert(Sym);
  551. NextLine;
  552. end else
  553. if copy(Line,Indent+1,3)='---' then
  554. { child symtable }
  555. begin
  556. S:=Trim(copy(Line,Indent+1+12,255));
  557. if Level=1 then Typ:=unitsym else
  558. Typ:=typesym;
  559. if (Sym<>nil) and (Sym^.GetName=S) then
  560. else
  561. begin
  562. New(Sym, Init(S, Typ, 0, nil));
  563. Owner^.Insert(Sym);
  564. end;
  565. Sym^.Typ:=Typ;
  566. NextLine;
  567. New(Sym^.Items, Init(0,50));
  568. ProcessSymTable(Indent+2,Sym^.Items);
  569. end else
  570. { if Sym<>nil then}
  571. if copy(Line,Indent+1,1)=' ' then
  572. { reference }
  573. begin
  574. S:=copy(Line,Indent+1+2,255);
  575. P:=Pos('(',S); if P=0 then P:=length(S)+1;
  576. Source:=Trim(copy(S,1,P-1)); Delete(S,1,P);
  577. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  578. PX.Y:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  579. P:=Pos(')',S); if P=0 then P:=length(S)+1;
  580. PX.X:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  581. PS:=ModuleNames^.Add(Source);
  582. New(Ref, Init(PS, PX));
  583. if Sym^.References=nil then
  584. New(Sym^.References, Init(10,50));
  585. Sym^.References^.Insert(Ref);
  586. end;
  587. if ExitBack=false then
  588. NextLine;
  589. until EndOfFile or ExitBack;
  590. Dec(Level);
  591. end;
  592. begin
  593. DoneSymbolBrowser;
  594. InitSymbolBrowser;
  595. {$I-}
  596. Assign(f,FileName);
  597. Reset(f);
  598. Level:=0;
  599. NextLine;
  600. while (IOResult=0) and (EndOfFile=false) do
  601. ProcessSymTable(0,Modules);
  602. Close(f);
  603. EatIO;
  604. {$I+}
  605. end;*)
  606. {****************************************************************************
  607. TGDBValue
  608. ****************************************************************************}
  609. constructor TGDBValue.Init(Const AExpr : String;ASym : PSymbol);
  610. begin
  611. St := nil;
  612. S := ASym;
  613. Expr:=NewStr(AExpr);
  614. GDBI:=-1;
  615. end;
  616. destructor TGDBValue.Done;
  617. begin
  618. If Assigned(St) then
  619. begin
  620. DisposeStr(St);
  621. st:=nil;
  622. end;
  623. If Assigned(Expr) then
  624. begin
  625. DisposeStr(Expr);
  626. Expr:=nil;
  627. end;
  628. end;
  629. procedure TGDBValue.GetValue;
  630. var
  631. p : PAnsiChar;
  632. begin
  633. {$ifdef BROWSERCOL}
  634. {$ifndef NODEBUG}
  635. if not assigned(Debugger) then
  636. exit;
  637. if not Debugger^.IsRunning then
  638. exit;
  639. if (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) or (GDBI=Debugger^.RunCount) then
  640. exit;
  641. If Assigned(St) then
  642. DisposeStr(St);
  643. if assigned(Expr) then
  644. begin
  645. { avoid infinite recursion here }
  646. GDBI:=Debugger^.RunCount;
  647. p:=Debugger^.GetValue(Expr^);
  648. St:=NewStr(GetPChar(p));
  649. if assigned(p) then
  650. StrDispose(p);
  651. end;
  652. {$endif ndef NODEBUG}
  653. {$endif BROWSERCOL}
  654. end;
  655. function TGDBValue.GetText : String;
  656. begin
  657. GetValue;
  658. if assigned(St) then
  659. GetText:=S^.GetText+' = '+GetStr(St)
  660. else
  661. GetText:=S^.GetText;
  662. end;
  663. {****************************************************************************
  664. TGDBValueCollection
  665. ****************************************************************************}
  666. function TGDBValueCollection.At(Index: sw_Integer): PGDBValue;
  667. begin
  668. At:= Inherited At(Index);
  669. end;
  670. {****************************************************************************
  671. THollowSymbol
  672. ****************************************************************************}
  673. constructor THollowSymbol.init(ASymbol,AParent:PSymbol);
  674. begin
  675. TObject.Init;
  676. Name := ASymbol^.Name;
  677. Typ := ASymbol^.Typ;
  678. varoptions := ASymbol^.varoptions;
  679. varspez := ASymbol^.varspez;
  680. Params := ASymbol^.Params;
  681. References := ASymbol^.References;
  682. Items := ASymbol^.Items;
  683. DType := ASymbol^.DType;
  684. VType := ASymbol^.VType;
  685. TypeID := ASymbol^.TypeID;
  686. RelatedTypeID := ASymbol^.RelatedTypeID;
  687. DebuggerCount := ASymbol^.DebuggerCount;
  688. Ancestor := ASymbol^.Ancestor;
  689. Flags := ASymbol^.Flags;
  690. MemInfo := ASymbol^.MemInfo;
  691. Sym := ASymbol;
  692. Parent := AParent;
  693. NeedPrefix := false;
  694. end;
  695. function THollowSymbol.GetName: string;
  696. begin
  697. if (not NeedPrefix) or (not assigned(Parent)) then
  698. GetName:=inherited GetName
  699. else
  700. GetName:=Parent^.Name^+'.'+inherited GetName;
  701. end;
  702. destructor THollowSymbol.done;
  703. begin
  704. { Skip TSymbol.Done because we do not own any of actual pointers here }
  705. TObject.Done;
  706. end;
  707. {****************************************************************************
  708. THollowSymbolCollection
  709. ****************************************************************************}
  710. function THollowSymbolCollection.At(Index: Sw_Integer): PHollowSymbol;
  711. begin
  712. At:=TCollection.At(Index);
  713. end;
  714. {****************************************************************************
  715. TFilteredSym
  716. ****************************************************************************}
  717. constructor TFilteredSym.Init(AItemSym:Sw_Integer;ASym : PSymbol);
  718. begin
  719. inherited Init;
  720. ItemSym:=AItemSym;
  721. Sym:=ASym;
  722. end;
  723. function TFilteredSym.GetText:String;
  724. begin
  725. GetText:=Sym^.GetText;
  726. end;
  727. destructor TFilteredSym.Done;
  728. begin
  729. inherited Done;
  730. end;
  731. {****************************************************************************
  732. TFilteredSymCollection
  733. ****************************************************************************}
  734. function TFilteredSymCollection.At(Index: sw_Integer): PFilteredSym;
  735. begin
  736. At:= Inherited At(Index);
  737. end;
  738. {****************************************************************************
  739. TSymbolView
  740. ****************************************************************************}
  741. constructor TSymbolView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  742. begin
  743. inherited Init(Bounds,1,AHScrollBar,AVScrollBar);
  744. {HScrollBar:=AHScrollBar;}
  745. MyBW:=nil;
  746. if assigned(HScrollBar) then
  747. begin
  748. HScrollBar^.SetRange(1,80);
  749. end;
  750. Options:=Options or (ofSelectable+ofTopSelect);
  751. EventMask:=EventMask or evBroadcast;
  752. end;
  753. procedure TSymbolView.ClearHighlights;
  754. begin
  755. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  756. end;
  757. procedure TSymbolView.AutoTrackSource;
  758. begin
  759. if Range>0 then
  760. TrackSource;
  761. end;
  762. procedure TSymbolView.OptionsDlg;
  763. begin
  764. if MyBW<> nil then
  765. Message(@IDEApp, evCommand, cmBrowserOptions, MyBW); { Send message }
  766. end;
  767. destructor TSymbolView.Done;
  768. begin
  769. EventMask:=EventMask and not evBroadcast;
  770. Inherited Done;
  771. end;
  772. procedure TSymbolView.SetState(AState: Word; Enable: Boolean);
  773. var OState: longint;
  774. begin
  775. OState:=State;
  776. inherited SetState(AState,Enable);
  777. if ((OState xor State) and sfFocused)<>0 then
  778. if GetState(sfFocused) then
  779. begin
  780. if (MiscOptions and moAutoTrackSource)<>0 then
  781. AutoTrackSource;
  782. end
  783. else
  784. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  785. end;
  786. procedure TSymbolView.Browse;
  787. begin
  788. SelectItem(Focused);
  789. end;
  790. procedure TSymbolView.GotoSource;
  791. begin
  792. if GotoItem(Focused) then
  793. PutCommand(Owner,evCommand,cmClose,nil);
  794. end;
  795. procedure TSymbolView.TrackSource;
  796. begin
  797. TrackItem(Focused,false);
  798. end;
  799. procedure TSymbolView.HandleEvent(var Event: TEvent);
  800. var DontClear: boolean;
  801. begin
  802. case Event.What of
  803. evKeyDown :
  804. begin
  805. DontClear:=false;
  806. case Event.KeyCode of
  807. kbEnter :
  808. Browse;
  809. kbCtrlEnter,kbCtrlG :
  810. GotoSource;
  811. kbSpaceBar,kbCtrlT :
  812. TrackSource;
  813. kbCtrlP :
  814. Message(MyBW,evCommand,cmSymPrevious,nil);
  815. kbF2 :
  816. SaveAs;
  817. kbCtrlO :
  818. OptionsDlg;
  819. kbRight,kbLeft :
  820. if HScrollBar<>nil then
  821. HScrollBar^.HandleEvent(Event);
  822. kbTab:
  823. Message(Owner,evBroadcast,cmSymTabKeyPress,@Self);
  824. else DontClear:=true;
  825. end;
  826. if DontClear=false then ClearEvent(Event);
  827. end;
  828. evMouseDown :
  829. begin
  830. if Event.double then
  831. begin
  832. Browse;
  833. ClearEvent(Event);
  834. end;
  835. end;
  836. evCommand :
  837. begin
  838. DontClear:=false;
  839. case Event.Command of
  840. cmSymBrowse :
  841. Browse;
  842. cmSymPrevious :
  843. Message(MyBW,evCommand,cmSymPrevious,nil);
  844. cmSymGotoSource :
  845. GotoSource;
  846. cmSymTrackSource :
  847. TrackSource;
  848. cmSymSaveAs,cmSaveAs :
  849. SaveAs;
  850. cmSymOptions :
  851. OptionsDlg;
  852. else DontClear:=true;
  853. end;
  854. if DontClear=false then ClearEvent(Event);
  855. end;
  856. evBroadcast :
  857. case Event.Command of
  858. cmListFocusChanged :
  859. if Event.InfoPtr=@Self then
  860. if (MiscOptions and moAutoTrackSource)<>0 then
  861. if GetState(sfFocused) then
  862. AutoTrackSource;
  863. end;
  864. end;
  865. inherited HandleEvent(Event);
  866. end;
  867. function TSymbolView.GetPalette: PPalette;
  868. const
  869. P: string[length(CBrowserListBox)] = CBrowserListBox;
  870. begin
  871. GetPalette:=@P;
  872. end;
  873. function TSymbolView.GetLocalMenu: PMenu;
  874. begin
  875. GetLocalMenu:=NewMenu(
  876. NewItem(menu_symlocal_browse,'',kbNoKey,cmSymBrowse,hcSymBrowse,
  877. NewItem(menu_symlocal_previous,'Ctrl+P',kbCtrlP,cmSymPrevious,hcSymPrevious,
  878. NewItem(menu_symlocal_gotosource,'Ctrl+G',kbCtrlG,cmSymGotoSource,hcSymGotoSource,
  879. NewItem(menu_symlocal_tracksource,'Ctrl+T',kbCtrlT,cmSymTrackSource,hcSymTrackSource,
  880. NewLine(
  881. NewItem(menu_symlocal_saveas,'F2',kbF2,cmSymSaveAs,hcSymSaveAs,
  882. NewItem(menu_symlocal_options,'Ctrl+O',kbCtrlO,cmSymOptions,hcSymOptions,
  883. nil))))))));
  884. end;
  885. function TSymbolView.GotoItem(Item: sw_integer): boolean;
  886. begin
  887. SelectItem(Item);
  888. GotoItem:=true;
  889. end;
  890. function TSymbolView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  891. begin
  892. SelectItem(Item);
  893. TrackItem:=true;
  894. end;
  895. function LastBrowserWindow: PBrowserWindow;
  896. var BW: PBrowserWindow;
  897. procedure IsBW(P: PView);
  898. begin
  899. if (P^.HelpCtx=hcBrowserWindow) then
  900. BW:=pointer(P);
  901. end;
  902. begin
  903. BW:=nil;
  904. Desktop^.ForEach(TCallbackProcParam(@IsBW));
  905. LastBrowserWindow:=BW;
  906. end;
  907. function TSymbolView.TrackReference(R: PReference; AutoTrack: boolean): boolean;
  908. var W: PSourceWindow;
  909. BW: PBrowserWindow;
  910. P: TPoint;
  911. begin
  912. ClearHighlights;
  913. Desktop^.Lock;
  914. P.X:=R^.Position.X-1; P.Y:=R^.Position.Y-1;
  915. if AutoTrack then
  916. W:=SearchOnDesktop(R^.GetFileName,false)
  917. else
  918. W:=TryToOpenFile(nil,R^.GetFileName,P.X,P.Y,true);
  919. if not assigned(W) then
  920. begin
  921. Desktop^.Unlock;
  922. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  923. begin
  924. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  925. if Assigned(W) then
  926. W^.Select;
  927. end;
  928. Desktop^.Lock;
  929. end;
  930. if W<>nil then
  931. begin
  932. BW:=LastBrowserWindow;
  933. if BW=nil then
  934. W^.Select
  935. else
  936. begin
  937. Desktop^.Delete(W);
  938. Desktop^.InsertBefore(W,BW^.NextView);
  939. end;
  940. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,P.Y);
  941. end;
  942. Desktop^.UnLock;
  943. if Assigned(W)=false then
  944. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  945. TrackReference:=W<>nil;
  946. end;
  947. function TSymbolView.GotoReference(R: PReference): boolean;
  948. var W: PSourceWindow;
  949. begin
  950. Desktop^.Lock;
  951. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  952. if Assigned(W) then
  953. W^.Select
  954. else
  955. begin
  956. Desktop^.Unlock;
  957. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  958. begin
  959. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  960. if Assigned(W) then
  961. W^.Select;
  962. end;
  963. Desktop^.Lock;
  964. end;
  965. Desktop^.UnLock;
  966. if Assigned(W)=false then
  967. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  968. GotoReference:=W<>nil;
  969. end;
  970. {****************************************************************************
  971. TSymbolScopeView
  972. ****************************************************************************}
  973. constructor TSymbolScopeView.Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  974. begin
  975. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  976. OrgSymbols:=ASymbols;
  977. Inh:=false; { use inheritance filter (set to true only if view object or class) }
  978. ObjSymbol:=nil;
  979. New(SymbolsValue,Init(50,50));
  980. New(FilteredSym,Init(50,50));
  981. New(Symbols,Init(50,50));
  982. CopyOrgSymbols;
  983. FilterSymbols(false); {select all}
  984. NewList(FilteredSym);
  985. SetRange(FilteredSym^.Count);
  986. end;
  987. destructor TSymbolScopeView.Done;
  988. begin
  989. if assigned(Symbols) then
  990. begin
  991. dispose(Symbols,done);
  992. Symbols:=nil;
  993. end;
  994. if Assigned(SymbolsValue) then
  995. begin
  996. Dispose(SymbolsValue,Done);
  997. SymbolsValue:=nil;
  998. end;
  999. if Assigned(FilteredSym) then
  1000. begin
  1001. Dispose(FilteredSym,Done);
  1002. FilteredSym:=nil;
  1003. end;
  1004. Inherited Done;
  1005. end;
  1006. procedure TSymbolScopeView.HandleEvent(var Event: TEvent);
  1007. var OldFocus: sw_integer;
  1008. begin
  1009. case Event.What of
  1010. evKeyDown :
  1011. case Event.KeyCode of
  1012. kbBack :
  1013. begin
  1014. LookUp(copy(LookUpStr,1,length(LookUpStr)-1));
  1015. ClearEvent(Event);
  1016. end;
  1017. else
  1018. if Event.CharCode in[#33..#255] then
  1019. begin
  1020. LookUp(LookUpStr+Event.CharCode);
  1021. ClearEvent(Event);
  1022. end;
  1023. end;
  1024. end;
  1025. OldFocus:=Focused;
  1026. inherited HandleEvent(Event);
  1027. if OldFocus<>Focused then
  1028. Lookup('');
  1029. end;
  1030. procedure TSymbolScopeView.Draw;
  1031. var DeltaX: sw_integer;
  1032. begin
  1033. inherited Draw;
  1034. if Assigned(HScrollBar)=false then DeltaX:=0 else
  1035. DeltaX:=HScrollBar^.Value-HScrollBar^.Min;
  1036. SetCursor(2+SymbolTypLen+length(LookUpStr)-DeltaX,Focused-TopItem);
  1037. end;
  1038. procedure TSymbolScopeView.LookUp(S: string);
  1039. var LookUpS : String;
  1040. function GetFilteredLookUpIdx(Item:Sw_Integer):Sw_Integer;
  1041. var I, Count : Sw_Integer;
  1042. F : PFilteredSym;
  1043. UpS,LeftS : String;
  1044. begin
  1045. GetFilteredLookUpIdx:=-1;
  1046. Count:=FilteredSym^.Count;
  1047. if Count > 0 then
  1048. for I:=0 to Count-1 do
  1049. begin
  1050. F:=FilteredSym^.At(I);
  1051. if F^.ItemSym = Item then {perfect match}
  1052. begin
  1053. GetFilteredLookUpIdx:=I;
  1054. break;
  1055. end;
  1056. if F^.ItemSym > Item then { test next item if perfect match is missing}
  1057. begin
  1058. LeftS:=UpcaseStr(F^.Sym^.GetName);
  1059. UpS:=UpcaseStr(LookUpS);
  1060. if copy(LeftS,1,length(UpS))=UpS then {perfect match}
  1061. GetFilteredLookUpIdx:=I;
  1062. break; {all you get is one second chance, it wont be any better from here}
  1063. end;
  1064. end;
  1065. end;
  1066. var Idx,Slength,I: Sw_integer;
  1067. NS: string;
  1068. begin
  1069. NS:=LookUpStr;
  1070. Slength:=Length(S);
  1071. LookUpS:=S;
  1072. if (Symbols=nil) or (S='') then NS:='' else
  1073. begin
  1074. S:=Symbols^.LookUp(S,Idx);
  1075. if Idx<>-1 then
  1076. begin
  1077. { Have found, but get filtered list index first
  1078. Some entries might be missing if need then look up agin }
  1079. Idx:=GetFilteredLookUpIdx(Idx);
  1080. if Idx<>-1 then
  1081. begin
  1082. NS:=S;
  1083. FocusItem(Idx);
  1084. end;
  1085. end;
  1086. end;
  1087. LookUpStr:=Copy(NS,1,Slength);
  1088. SetState(sfCursorVis,LookUpStr<>'');
  1089. DrawView;
  1090. end;
  1091. function TSymbolScopeView.GotoItem(Item: sw_integer): boolean;
  1092. var S: PSymbol;
  1093. OK: boolean;
  1094. F : PFilteredSym;
  1095. begin
  1096. OK:=Range>0;
  1097. if OK then
  1098. begin
  1099. F:=List^.At(Item);
  1100. S:=F^.Sym;
  1101. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  1102. if OK then
  1103. OK:=GotoReference(S^.References^.At(0));
  1104. end;
  1105. GotoItem:=OK;
  1106. end;
  1107. function TSymbolScopeView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  1108. var S: PSymbol;
  1109. OK: boolean;
  1110. F: PFilteredSym;
  1111. begin
  1112. OK:=Range>0;
  1113. if OK then
  1114. begin
  1115. F:=List^.At(Item);
  1116. S:=F^.Sym;
  1117. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  1118. if OK then
  1119. OK:=TrackReference(S^.References^.At(0),AutoTrack);
  1120. end;
  1121. TrackItem:=OK;
  1122. end;
  1123. procedure TSymbolScopeView.SetGDBCol;
  1124. var S : PSymbol;
  1125. I : sw_integer;
  1126. begin
  1127. if assigned(MyBW) and (SymbolsValue^.Count=0) then
  1128. begin
  1129. For i:=0 to Symbols^.Count-1 do
  1130. begin
  1131. S:=Symbols^.At(I);
  1132. SymbolsValue^.Insert(New(PGDBValue,Init(GetStr(MyBW^.Prefix)+S^.GetName,S)));
  1133. end;
  1134. end;
  1135. end;
  1136. procedure TSymbolScopeView.CopyOrgSymbols;
  1137. var S : PSymbol;
  1138. I : sw_integer;
  1139. begin
  1140. Symbols^.FreeAll;
  1141. if OrgSymbols^.Count>0 then
  1142. For i:=0 to OrgSymbols^.Count-1 do
  1143. begin
  1144. S:=OrgSymbols^.At(I);
  1145. Symbols^.Insert(new(PHollowSymbol,Init(S,nil)));
  1146. end;
  1147. end;
  1148. procedure TSymbolScopeView.PullInInheritance; {adds to the list inherited procedures and fields}
  1149. var S : PSymbol;
  1150. O : PObjectSymbol;
  1151. InhSymbols : PSymbolCollection;
  1152. I : sw_integer;
  1153. function LookFor (Collection, AItems : PSymbolCollection):PSymbol;
  1154. var I : sw_integer;
  1155. S : PSymbol;
  1156. R : PSymbol;
  1157. begin
  1158. R:=nil;
  1159. for i:=0 to Collection^.count-1 do
  1160. begin
  1161. S:=Collection^.At(I);
  1162. if assigned(S) and assigned(S^.Items) then
  1163. begin
  1164. if S^.Items = AItems then
  1165. begin
  1166. R:=S; break;
  1167. end;
  1168. R:=LookFor(S^.Items,AItems);
  1169. if R<>nil then break;
  1170. end;
  1171. end;
  1172. LookFor:=R;
  1173. end;
  1174. begin
  1175. S:=LookFor(Modules,OrgSymbols); { find the owner of OrgSymbols }
  1176. if assigned(S) then
  1177. begin
  1178. ObjSymbol:=S;
  1179. For i:=0 to Symbols^.Count-1 do
  1180. Symbols^.At(I)^.Parent:=S;
  1181. SymbolsValue^.FreeAll;
  1182. O:=SearchObjectForSymbol(S);
  1183. if assigned(O) then
  1184. while assigned(O^.Parent) do
  1185. begin
  1186. O:=O^.Parent;
  1187. S:=O^.Symbol;
  1188. if assigned(S) then
  1189. begin
  1190. {-- add inherited symbols --}
  1191. InhSymbols:=S^.Items;
  1192. if InhSymbols^.Count>0 then
  1193. For i:=0 to InhSymbols^.Count-1 do
  1194. Symbols^.Insert(new(PHollowSymbol,Init(InhSymbols^.At(I),S)));
  1195. end;
  1196. end;
  1197. end;
  1198. end;
  1199. procedure TSymbolScopeView.FilterSymbols(AFilter:boolean);
  1200. var S : PHollowSymbol;
  1201. I : sw_integer;
  1202. Flags : Longint;
  1203. bUni, bLab, bCon, bTyp, bVar, bPrc, bInh, bQua: boolean;
  1204. begin
  1205. Flags:=0;
  1206. if assigned(MyBW) then
  1207. Flags:=MyBW^.GetFlags;
  1208. bUni:=(Flags and bfUnits)<>0;
  1209. bLab:=(Flags and bfLabels)<>0;
  1210. bCon:=(Flags and bfConstants)<>0;
  1211. bTyp:=(Flags and bfTypes)<>0;
  1212. bVar:=(Flags and bfVariables)<>0;
  1213. bPrc:=(Flags and bfProcedures)<>0;
  1214. bInh:=(Flags and bfInherited)<>0;
  1215. bQua:=(Flags and bfQualifiedSymbols)<>0;
  1216. FilteredSym^.FreeAll;
  1217. if Symbols^.Count = 0 then exit;
  1218. For i:=0 to Symbols^.Count-1 do
  1219. begin
  1220. S:=Symbols^.At(I);
  1221. if AFilter then begin
  1222. {---------- only selected ones ----------}
  1223. S^.NeedPrefix:=bQua;
  1224. if Inh then { we are in object scope view }
  1225. if not bInh then { Inherite checkbox is not selected }
  1226. if S^.Parent <> ObjSymbol then continue;
  1227. case S^.typ of
  1228. labelsym: if not bLab then continue;
  1229. namespacesym,staticvarsym,localvarsym,paravarsym,
  1230. fieldvarsym,absolutevarsym,programparasym,
  1231. propertysym: if not bVar then continue;
  1232. procsym,syssym : if not bPrc then continue;
  1233. typesym : if not bTyp then continue;
  1234. constsym,enumsym : if not bCon then continue;
  1235. unitsym : if not bUni then continue;
  1236. errorsym,macrosym,undefinedsym: ; {accepted anyway}
  1237. end;
  1238. end;
  1239. FilteredSym^.Insert(New(PFilteredSym,Init(I,S)));
  1240. end;
  1241. end;
  1242. function TSymbolScopeView.GetText(Item,MaxLen: Sw_Integer): String;
  1243. var S1: string;
  1244. S : PSymbol;
  1245. SG : PGDBValue;
  1246. F : PFilteredSym;
  1247. begin
  1248. F:=FilteredSym^.At(Item);
  1249. Item:=F^.ItemSym;
  1250. S:=Symbols^.At(Item);
  1251. //S:=F^.Sym;
  1252. if Assigned(SymbolsValue) and (SymbolsValue^.Count>Item) then
  1253. SG:=SymbolsValue^.At(Item)
  1254. else
  1255. SG:=nil;
  1256. if assigned(SG) then
  1257. S1:=SG^.getText
  1258. else
  1259. S1:=S^.GetText;
  1260. GetText:=copy(S1,1,MaxLen);
  1261. end;
  1262. {****************************************************************************
  1263. TSymbolReferenceView
  1264. ****************************************************************************}
  1265. constructor TSymbolReferenceView.Init(var Bounds: TRect; AReferences: PReferenceCollection;
  1266. AHScrollBar, AVScrollBar: PScrollBar);
  1267. begin
  1268. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  1269. References:=AReferences;
  1270. NewList(AReferences);
  1271. SetRange(References^.Count);
  1272. end;
  1273. destructor TSymbolReferenceView.Done;
  1274. begin
  1275. Inherited Done;
  1276. end;
  1277. procedure TSymbolReferenceView.HandleEvent(var Event: TEvent);
  1278. var OldFocus: sw_integer;
  1279. DontClear: boolean;
  1280. begin
  1281. OldFocus:=Focused;
  1282. case Event.What of
  1283. evKeyDown :
  1284. begin
  1285. DontClear:=false;
  1286. case Event.KeyCode of
  1287. kbEnter :
  1288. TrackItem(Focused,false);
  1289. kbCtrlEnter :
  1290. GotoItem(Focused);
  1291. else DontClear:=true;
  1292. end;
  1293. if DontClear=false then ClearEvent(Event);
  1294. end;
  1295. end;
  1296. inherited HandleEvent(Event);
  1297. if OldFocus<>Focused then
  1298. if (MiscOptions and moAutoTrackSource)=0 then
  1299. ClearHighlights;
  1300. end;
  1301. procedure TSymbolReferenceView.Browse;
  1302. begin
  1303. { do nothing here }
  1304. end;
  1305. function TSymbolReferenceView.GetText(Item,MaxLen: Sw_Integer): String;
  1306. var S: string;
  1307. P: PReference;
  1308. begin
  1309. P:=References^.At(Item);
  1310. S:=P^.GetFileName+'('+IntToStr(P^.Position.Y)+','+IntToStr(P^.Position.X)+')';
  1311. GetText:=copy(S,1,MaxLen);
  1312. end;
  1313. function TSymbolReferenceView.GotoItem(Item: sw_integer): boolean;
  1314. var OK: boolean;
  1315. begin
  1316. OK:=Range>0;
  1317. if OK then
  1318. OK:=GotoReference(List^.At(Item));
  1319. GotoItem:=OK;
  1320. end;
  1321. function TSymbolReferenceView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  1322. var OK: boolean;
  1323. begin
  1324. OK:=Range>0;
  1325. if OK then
  1326. OK:=TrackReference(List^.At(Item),AutoTrack);
  1327. TrackItem:=OK;
  1328. end;
  1329. procedure TSymbolReferenceView.SelectItem(Item: Sw_Integer);
  1330. begin
  1331. GotoItem(Item);
  1332. end;
  1333. constructor TSymbolMemInfoView.Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  1334. begin
  1335. inherited Init(Bounds,'');
  1336. Options:=Options or (ofSelectable+ofTopSelect);
  1337. MemInfo:=AMemInfo;
  1338. MyBW:=nil;
  1339. end;
  1340. destructor TSymbolMemInfoView.Done;
  1341. begin
  1342. { if assigned(MemInfo) then
  1343. dispose(MemInfo);}
  1344. Inherited Done;
  1345. end;
  1346. procedure TSymbolMemInfoView.GetText(var S: String);
  1347. function SizeStr(Size: longint): string;
  1348. var S: string[40];
  1349. begin
  1350. S:=IntToStrL(Size,7);
  1351. S:=S+' byte';
  1352. if Size>1 then S:=S+'s';
  1353. if Size=-1 then
  1354. SizeStr:='variable'
  1355. else
  1356. SizeStr:=S;
  1357. end;
  1358. function AddrStr(Addr: longint): string;
  1359. { Warning this is endian specific code !! (PM) }
  1360. type TLongint = record LoW,HiW: word; end;
  1361. begin
  1362. with TLongint(Addr) do
  1363. AddrStr:='$'+hexstr(HiW,4)+hexstr(LoW,4);
  1364. end;
  1365. begin
  1366. ClearFormatParams;
  1367. AddFormatParamStr(msg_sizeinmemory);
  1368. AddFormatParamStr(msg_sizeonstack);
  1369. S:=
  1370. FormatStrF(
  1371. #13+
  1372. { ' Memory location: '+AddrStr(MemInfo^.Addr)+#13+
  1373. ' Local address: '+AddrStr(MemInfo^.LocalAddr)+#13+}
  1374. { ??? internal linker ??? }
  1375. '%18s: '+SizeStr(MemInfo^.Size)+#13+
  1376. '%18s: '+SizeStr(MemInfo^.PushSize)+#13+
  1377. '',
  1378. FormatParams);
  1379. end;
  1380. function TSymbolMemInfoView.GetPalette: PPalette;
  1381. begin
  1382. GetPalette:=inherited GetPalette;
  1383. end;
  1384. function TSymbolMemoView.GetPalette: PPalette;
  1385. const P: string[length(CFPSymbolMemo)] = CFPSymbolMemo;
  1386. begin
  1387. GetPalette:=@P;
  1388. end;
  1389. {****************************************************************************
  1390. TSymbolInheritanceView
  1391. ****************************************************************************}
  1392. constructor TSymbolInheritanceView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  1393. begin
  1394. {$ifdef HASOUTLINE}
  1395. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  1396. {$else not HASOUTLINE}
  1397. inherited Init(Bounds,1,AVScrollBar);
  1398. HScrollBar:=AHScrollBar;
  1399. {$endif not HASOUTLINE}
  1400. Options:=Options or (ofSelectable+ofTopSelect);
  1401. Root:=ARoot;
  1402. MyBW:=nil;
  1403. ExpandAll(Root);
  1404. {$ifdef HASOUTLINE}
  1405. Update;
  1406. {$else not HASOUTLINE}
  1407. SetRange(GetNumChildrenExposed(Root));
  1408. {$endif not HASOUTLINE}
  1409. end;
  1410. destructor TSymbolInheritanceView.Done;
  1411. begin
  1412. { do not dispose,
  1413. belongs to a symbolcollection (PM)
  1414. if assigned(Root) then
  1415. dispose(Root,done); }
  1416. Inherited Done;
  1417. end;
  1418. function TSymbolInheritanceView.GetRoot: Pointer;
  1419. begin
  1420. GetRoot:=Root;
  1421. end;
  1422. function TSymbolInheritanceView.HasChildren(Node: Pointer): Boolean;
  1423. begin
  1424. HasChildren:=GetNumChildren(Node)>0;
  1425. end;
  1426. function TSymbolInheritanceView.GetChild(Node: Pointer; I: sw_Integer): Pointer;
  1427. begin
  1428. GetChild:=PObjectSymbol(Node)^.GetDescendant(I);
  1429. end;
  1430. function TSymbolInheritanceView.GetNumChildren(Node: Pointer): sw_Integer;
  1431. begin
  1432. GetNumChildren:=PObjectSymbol(Node)^.GetDescendantCount;
  1433. end;
  1434. function TSymbolInheritanceView.GetNumChildrenExposed(Node: Pointer) : sw_Integer;
  1435. var
  1436. Nb : integer;
  1437. P : PObjectSymbol;
  1438. Procedure AddCount(P : PObjectSymbol);
  1439. var
  1440. i,count : integer;
  1441. D : PObjectSymbol;
  1442. begin
  1443. if not assigned(P) then
  1444. exit;
  1445. Count:=P^.GetDescendantCount;
  1446. Inc(Nb,Count);
  1447. for I:=0 to Count-1 do
  1448. begin
  1449. D:=P^.GetDescendant(I);
  1450. AddCount(D);
  1451. end;
  1452. end;
  1453. begin
  1454. Nb:=0;
  1455. AddCount(Node);
  1456. GetNumChildrenExposed:=Nb;
  1457. end;
  1458. procedure TSymbolInheritanceView.Adjust(Node: Pointer; Expand: Boolean);
  1459. begin
  1460. PObjectSymbol(Node)^.Expanded:=Expand;
  1461. end;
  1462. function TSymbolInheritanceView.IsExpanded(Node: Pointer): Boolean;
  1463. begin
  1464. IsExpanded:=PObjectSymbol(Node)^.Expanded;
  1465. end;
  1466. procedure TSymbolInheritanceView.HandleEvent(var Event: TEvent);
  1467. var DontClear: boolean;
  1468. {$ifndef HASOUTLINE}
  1469. P: TPoint;
  1470. {$endif HASOUTLINE}
  1471. begin
  1472. case Event.What of
  1473. evKeyDown :
  1474. begin
  1475. DontClear:=false;
  1476. case Event.KeyCode of
  1477. {$ifndef HASOUTLINE}
  1478. kbEnter:
  1479. NodeSelected(GetLineNode(Cursor.Y-Origin.Y));
  1480. {$endif HASOUTLINE}
  1481. kbLeft,kbRight,
  1482. kbCtrlLeft,kbCtrlRight :
  1483. if Assigned(HScrollBar) then
  1484. HScrollBar^.HandleEvent(Event)
  1485. else
  1486. DontClear:=true;
  1487. kbCtrlP :
  1488. Message(MyBw,evCommand,cmSymPrevious,nil);
  1489. kbF2: SaveAs;
  1490. else DontClear:=true;
  1491. end;
  1492. if DontClear=false then ClearEvent(Event);
  1493. end;
  1494. evMouseDown :
  1495. begin
  1496. {$ifndef HASOUTLINE}
  1497. MakeLocal(Event.Where,P);
  1498. SetCursor(P.X,P.Y);
  1499. {$endif HASOUTLINE}
  1500. if Event.double then
  1501. begin
  1502. Message(@Self,evKeyDown,kbEnter,nil);
  1503. ClearEvent(Event);
  1504. end;
  1505. end;
  1506. evCommand :
  1507. begin
  1508. DontClear:=false;
  1509. case Event.Command of
  1510. cmSymBrowse :
  1511. Message(@Self,evKeyDown,kbEnter,nil);
  1512. cmSymPrevious :
  1513. Message(MyBw,evCommand,cmSymPrevious,nil);
  1514. cmSymSaveAs,cmSaveAs :
  1515. SaveAs;
  1516. else DontClear:=true;
  1517. end;
  1518. if DontClear=false then ClearEvent(Event);
  1519. end;
  1520. end;
  1521. inherited HandleEvent(Event);
  1522. end;
  1523. function TSymbolInheritanceView.GetPalette: PPalette;
  1524. const P: string[length(CBrowserOutline)] = CBrowserOutline;
  1525. begin
  1526. GetPalette:=@P;
  1527. end;
  1528. function TSymbolInheritanceView.GetLocalMenu: PMenu;
  1529. begin
  1530. GetLocalMenu:=NewMenu(
  1531. NewItem(menu_symlocal_browse,'',kbNoKey,cmSymBrowse,hcSymBrowse,
  1532. NewItem(menu_symlocal_previous,'Ctrl+P',kbCtrlP,cmSymPrevious,hcSymPrevious,
  1533. NewLine(
  1534. NewItem(menu_symlocal_saveas,'F2',kbF2,cmSymSaveAs,hcSymSaveAs,
  1535. nil)))));
  1536. end;
  1537. function TSymbolInheritanceView.NodeCountToFoc(aFoc:Sw_Integer):Sw_Integer;
  1538. var P : PObjectSymbol;
  1539. Exp: Sw_Integer;
  1540. ExpandedFoc, NormalFoc : Sw_integer;
  1541. procedure CountSymbolTree(P:PObjectSymbol;Depth:Sw_Integer);
  1542. var
  1543. Q : PObjectSymbol;
  1544. Des,Count : integer;
  1545. begin
  1546. if not assigned(P) then
  1547. exit;
  1548. Count:=GetNumChildren{Exposed}(P);
  1549. if Count=0 then exit;
  1550. Des:=0;
  1551. if not IsExpanded(P) then
  1552. Inc(Exp);
  1553. While Count>Des do
  1554. begin
  1555. Q:=P^.GetDescendant(Des);
  1556. If aFoc=NormalFoc then break; { exit if reached focused node }
  1557. if Exp=0 then Inc(NormalFoc);
  1558. Inc(ExpandedFoc);
  1559. CountSymbolTree(Q,Depth+1);
  1560. Inc(Des);
  1561. end;
  1562. if not IsExpanded(P) then
  1563. Dec(Exp);
  1564. end;
  1565. begin
  1566. P:=Root;
  1567. Exp:=0;
  1568. ExpandedFoc:=0;
  1569. NormalFoc:=0;
  1570. CountSymbolTree(P,1);
  1571. NodeCountToFoc:=ExpandedFoc;
  1572. end;
  1573. function TSymbolInheritanceView.SaveToFile(const AFileName: string): boolean;
  1574. var OK: boolean;
  1575. S: PBufStream;
  1576. st : string;
  1577. P : PObjectSymbol;
  1578. procedure WriteSymbolTree(P:PObjectSymbol;Depth:Sw_Integer;grph:string);
  1579. var
  1580. Q : PObjectSymbol;
  1581. Des,Count : integer;
  1582. Space : String;
  1583. begin
  1584. if not assigned(P) then
  1585. exit;
  1586. Des:=0;
  1587. Count:=GetNumChildren{Exposed}(P);
  1588. if Count=0 then exit;
  1589. While Count>Des do
  1590. begin
  1591. if not ok then exit;
  1592. Q:=P^.GetDescendant(Des);
  1593. st:=Q^.GetName;
  1594. if (Des+1)=Count then
  1595. Space:=grph+#32#192#196#196
  1596. else Space:=grph+#32#195#196#196;
  1597. S^.Write(Space[1],Length(Space));
  1598. if not OK then exit;
  1599. S^.Write(St[1],length(St));
  1600. OK:=(S^.Status=stOK);
  1601. if not OK then exit;
  1602. S^.Write(EOL[1],length(EOL));
  1603. OK:=(S^.Status=stOK);
  1604. if not OK then exit;
  1605. if Ok then
  1606. begin
  1607. if (Des+1)=Count then
  1608. Space:=grph+' ' else Space:=grph+' '#179' ';
  1609. WriteSymbolTree(Q,Depth+1,Space);
  1610. end;
  1611. Inc(Des);
  1612. end;
  1613. end;
  1614. begin
  1615. New(S, Init(AFileName,stCreate,4096));
  1616. OK:=Assigned(S) and (S^.Status=stOK);
  1617. if OK then
  1618. begin
  1619. P:=Root;
  1620. st:=#32#192#196#196+P^.GetName;
  1621. S^.Write(St[1],length(St));
  1622. OK:=(S^.Status=stOK);
  1623. if OK then
  1624. begin
  1625. S^.Write(EOL[1],length(EOL));
  1626. OK:=(S^.Status=stOK);
  1627. if OK then
  1628. WriteSymbolTree(P,1,' ');
  1629. end;
  1630. end;
  1631. if Assigned(S) then Dispose(S, Done);
  1632. SaveToFile:=OK;
  1633. end;
  1634. function TSymbolInheritanceView.SaveAs: Boolean;
  1635. var
  1636. DefExt,Title,Filename : string;
  1637. Re : word;
  1638. begin
  1639. SaveAs := False;
  1640. Filename:='list.txt';
  1641. DefExt:='*.txt';
  1642. Title:='Save content';
  1643. Re:=Application^.ExecuteDialog(New(PFPFileDialog, Init(DefExt,
  1644. Title, label_name, fdOkButton, FileId)), @FileName);
  1645. if Re <> cmCancel then
  1646. SaveAs := SaveToFile(FileName);
  1647. end;
  1648. {$ifdef HASOUTLINE}
  1649. function TSymbolInheritanceView.GetText(Node: Pointer): String;
  1650. begin
  1651. GetText:=PObjectSymbol(Node)^.GetName;
  1652. end;
  1653. {$else not HASOUTLINE}
  1654. function TSymbolInheritanceView.GetNode(I : sw_Integer) : Pointer;
  1655. var
  1656. P : PObjectSymbol;
  1657. begin
  1658. P:=Root;
  1659. If Assigned(P) then
  1660. P:=P^.GetDescendant(I);
  1661. GetNode:=Pointer(P);
  1662. end;
  1663. procedure TSymbolInheritanceView.ExpandAll(Node: Pointer);
  1664. var
  1665. i : integer;
  1666. P : Pointer;
  1667. begin
  1668. Adjust(Node,true);
  1669. For i:=0 to GetNumChildren(Node)-1 do
  1670. begin
  1671. P:=GetChild(Node,I);
  1672. if Assigned(P) then
  1673. ExpandAll(P);
  1674. end;
  1675. end;
  1676. function TSymbolInheritanceView.GetLineNode(Item : sw_Integer) : Pointer;
  1677. var
  1678. P : PObjectSymbol;
  1679. NT: Integer;
  1680. procedure FindSymbol(var P:PObjectSymbol);
  1681. var
  1682. Q : PObjectSymbol;
  1683. Nc,Des : integer;
  1684. begin
  1685. if not assigned(P) then
  1686. exit;
  1687. Des:=0;
  1688. While (NT<Item) and (Des<GetNumChildren(P)) do
  1689. begin
  1690. Q:=P^.GetDescendant(Des);
  1691. Inc(NT);
  1692. if NT=Item then
  1693. begin
  1694. P:=Q;
  1695. exit;
  1696. end;
  1697. Nc:=GetNumChildrenExposed(Q);
  1698. If NT+Nc<Item then
  1699. Inc(NT,Nc)
  1700. else
  1701. begin
  1702. FindSymbol(Q);
  1703. P:=Q;
  1704. exit;
  1705. end;
  1706. Inc(Des);
  1707. end;
  1708. end;
  1709. begin
  1710. P:=Root;
  1711. NT:=0;
  1712. FindSymbol(P);
  1713. GetLineNode:=P;
  1714. end;
  1715. function TSymbolInheritanceView.GetText(Item,MaxLen: Sw_Integer): String;
  1716. var
  1717. P,Ans : PObjectSymbol;
  1718. NC,NT,NumParents : Integer;
  1719. S : String;
  1720. procedure FindSymbol(var P:PObjectSymbol);
  1721. var
  1722. Q : PObjectSymbol;
  1723. Des : integer;
  1724. begin
  1725. if not assigned(P) then
  1726. exit;
  1727. Des:=0;
  1728. While (NT<Item) and (Des<GetNumChildren(P)) do
  1729. begin
  1730. Q:=P^.GetDescendant(Des);
  1731. Inc(NT);
  1732. if NT=Item then
  1733. begin
  1734. P:=Q;
  1735. exit;
  1736. end;
  1737. Nc:=GetNumChildrenExposed(Q);
  1738. If NT+Nc<Item then
  1739. Inc(NT,Nc)
  1740. else
  1741. begin
  1742. FindSymbol(Q);
  1743. P:=Q;
  1744. exit;
  1745. end;
  1746. Inc(Des);
  1747. end;
  1748. end;
  1749. begin
  1750. P:=Root;
  1751. NT:=0;
  1752. FindSymbol(P);
  1753. if assigned(P) then
  1754. begin
  1755. S:=P^.GetName;
  1756. Ans:=P^.Parent;
  1757. NumParents:=0;
  1758. While Assigned(Ans) do
  1759. begin
  1760. Inc(NumParents);
  1761. Ans:=Ans^.Parent;
  1762. end;
  1763. S:=CharStr('-',NumParents)+S;
  1764. GetText:=Copy(S,1,MaxLen);
  1765. end
  1766. else
  1767. GetText:='';
  1768. end;
  1769. {$endif HASOUTLINE}
  1770. procedure TSymbolInheritanceView.Selected(I: sw_Integer);
  1771. var P: pointer;
  1772. begin
  1773. P:=GetNode(I);
  1774. NodeSelected(P);
  1775. end;
  1776. procedure TSymbolInheritanceView.NodeSelected(P: pointer);
  1777. var
  1778. S: PSymbol;
  1779. St : String;
  1780. Anc: PObjectSymbol;
  1781. R, WH :TPoint;
  1782. begin
  1783. if P=nil then Exit;
  1784. S:=PObjectSymbol(P)^.Symbol;
  1785. { this happens for the top objects view (PM) }
  1786. if S=nil then exit;
  1787. R.X:=MyBw^.Origin.X-1;WH.X:=0;WH.Y:=0;
  1788. {$ifdef HASOUTLINE}
  1789. R.Y:=FOC-Delta.Y+1;
  1790. {$else not HASOUTLINE}
  1791. R.Y:=MyBw^.Origin.Y+1;
  1792. {$endif not HASOUTLINE}
  1793. if DefaultBrowserSub = ReplaceCurrent then begin
  1794. R.X:=MyBw^.Origin.X;R.Y:=MyBw^.Origin.Y;
  1795. WH.X:=Size.X;WH.Y:=Size.Y;
  1796. end;
  1797. st:=S^.GetName;
  1798. if S^.Ancestor=nil then
  1799. Anc:=ObjectTree
  1800. else
  1801. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1802. OpenSymbolBrowser(R.X,R.Y,WH.X,WH.Y,
  1803. st,
  1804. S^.GetText,S,MyBw,
  1805. S^.Items,S^.References,Anc,S^.MemInfo);
  1806. if DefaultBrowserSub = ReplaceCurrent then
  1807. Message(MyBw,evCommand,cmClose,nil);
  1808. end;
  1809. {****************************************************************************
  1810. TBrowserTab
  1811. ****************************************************************************}
  1812. constructor TBrowserTab.Init(var Bounds: TRect; AItems: PBrowserTabItem);
  1813. begin
  1814. inherited Init(Bounds);
  1815. Options:=Options or ofPreProcess;
  1816. Items:=AItems;
  1817. SetParams(0,0);
  1818. end;
  1819. procedure TBrowserTab.SetParams(AFlags: word; ACurrent: Sw_integer);
  1820. begin
  1821. Flags:=AFlags;
  1822. SelectItem(ACurrent);
  1823. end;
  1824. procedure TBrowserTab.SelectItem(Index: Sw_integer);
  1825. var P: PBrowserTabItem;
  1826. PrevTab:Sw_Integer;
  1827. begin
  1828. PrevTab:=Current;
  1829. Current:=Index;
  1830. if PrevTab<>Current then
  1831. begin
  1832. P:=GetItem(PrevTab);
  1833. if (P<>nil) and (P^.Link<>nil) then
  1834. P^.Link^.SetState(sfVisible,False);
  1835. end;
  1836. P:=GetItem(Current);
  1837. if (P<>nil) and (P^.Link<>nil) then
  1838. begin
  1839. P^.Link^.SetState(sfVisible,True);
  1840. P^.Link^.Focus;
  1841. end;
  1842. DrawView;
  1843. end;
  1844. function TBrowserTab.GetItemCount: sw_integer;
  1845. var Count: integer;
  1846. P: PBrowserTabItem;
  1847. begin
  1848. Count:=0; P:=Items;
  1849. while (P<>nil) do
  1850. begin
  1851. Inc(Count);
  1852. P:=P^.Next;
  1853. end;
  1854. GetItemCount:=Count;
  1855. end;
  1856. function TBrowserTab.GetItem(Index: sw_integer): PBrowserTabItem;
  1857. var Counter: integer;
  1858. P: PBrowserTabItem;
  1859. begin
  1860. P:=Items;
  1861. Counter:=0;
  1862. while (P<>nil) and (Counter<Index) do
  1863. begin
  1864. P:=P^.Next;
  1865. Inc(Counter);
  1866. end;
  1867. GetItem:=P;
  1868. end;
  1869. procedure TBrowserTab.Draw;
  1870. var B: TDrawBuffer;
  1871. SelColor, NormColor, C: word;
  1872. I,CurX,Count: Sw_integer;
  1873. function Names(Idx: integer): AnsiChar;
  1874. begin
  1875. Names:=GetItem(Idx)^.Sign;
  1876. end;
  1877. begin
  1878. NormColor:=GetColor(1); SelColor:=GetColor(2);
  1879. MoveChar(B,#196{-},SelColor,Size.X);
  1880. CurX:=0; Count:=0;
  1881. for I:=0 to GetItemCount-1 do
  1882. if (Flags and (1 shl I))<>0 then
  1883. begin
  1884. Inc(Count);
  1885. if Current=I then C:=SelColor
  1886. else C:=NormColor;
  1887. if Count=1 then MoveChar(B[CurX],#180,SelColor,1)
  1888. else MoveChar(B[CurX],#179,SelColor,1);
  1889. MoveCStr(B[CurX+1],' '+Names(I)+' ',C);
  1890. Inc(CurX,4);
  1891. end;
  1892. if Count>0 then
  1893. MoveChar(B[CurX],#195,SelColor,1);
  1894. WriteLine(0,0,Size.X,Size.Y,B);
  1895. end;
  1896. procedure TBrowserTab.HandleEvent(var Event: TEvent);
  1897. var I,Idx: integer;
  1898. DontClear: boolean;
  1899. P: TPoint;
  1900. function GetItemForCoord(X: integer): integer;
  1901. var I,CurX,Idx: integer;
  1902. begin
  1903. CurX:=0; Idx:=-1;
  1904. for I:=0 to GetItemCount-1 do
  1905. if (Flags and (1 shl I))<>0 then
  1906. begin
  1907. if (CurX+1<=X) and (X<=CurX+3) then
  1908. begin Idx:=I; Break; end;
  1909. Inc(CurX,4);
  1910. end;
  1911. GetItemForCoord:=Idx;
  1912. end;
  1913. begin
  1914. case Event.What of
  1915. evMouseDown :
  1916. if MouseInView(Event.Where) then
  1917. begin
  1918. repeat
  1919. MakeLocal(Event.Where,P);
  1920. Idx:=GetItemForCoord(P.X);
  1921. if Idx<>-1 then
  1922. SelectItem(Idx);
  1923. until not MouseEvent(Event, evMouseMove);
  1924. ClearEvent(Event);
  1925. end;
  1926. evKeyDown :
  1927. begin
  1928. DontClear:=false; Idx:=-1;
  1929. for I:=0 to GetItemCount-1 do
  1930. if (GetCtrlCode(GetItem(I)^.Sign)=Event.KeyCode){ or
  1931. (GetItem(I)^.Sign=UpCase(Event.CharCode))} then
  1932. if (Flags and (1 shl I))<>0 then
  1933. begin
  1934. Idx:=I;
  1935. Break;
  1936. end;
  1937. if Idx=-1 then
  1938. DontClear:=true
  1939. else
  1940. SelectItem(Idx);
  1941. if DontClear=false then ClearEvent(Event);
  1942. end;
  1943. end;
  1944. inherited HandleEvent(Event);
  1945. end;
  1946. function TBrowserTab.GetPalette: PPalette;
  1947. const P: string[length(CBrowserTab)] = CBrowserTab;
  1948. begin
  1949. GetPalette:=@P;
  1950. end;
  1951. destructor TBrowserTab.Done;
  1952. begin
  1953. if Items<>nil then DisposeBrowserTabList(Items);
  1954. inherited Done;
  1955. end;
  1956. procedure TUnitInfoPanel.SetState(AState: Word; Enable: Boolean);
  1957. var OState: longint;
  1958. begin
  1959. OState:=State;
  1960. inherited SetState(AState,Enable);
  1961. if ((OState xor State) and sfVisible)<>0 then
  1962. begin
  1963. if GetState(sfVisible) then
  1964. begin
  1965. { even they are visible already
  1966. we need to make them visible for focus to work }
  1967. if assigned(UnitInfoUsed) then
  1968. UnitInfoUsed^.SetState(sfVisible,true);
  1969. if assigned(UnitInfoDependent) then
  1970. UnitInfoDependent^.SetState(sfVisible,true);
  1971. end;
  1972. end;
  1973. end;
  1974. procedure TUnitInfoPanel.HandleEvent(var Event: TEvent);
  1975. begin
  1976. if (Event.What=evBroadcast) and (Event.Command=cmListItemSelected) and
  1977. (InOwnerCall=false) then
  1978. begin
  1979. InOwnerCall:=true;
  1980. if Assigned(Owner) then
  1981. Owner^.HandleEvent(Event);
  1982. InOwnerCall:=false;
  1983. end else
  1984. if (Event.What=evBroadcast) and (Event.Command=cmSymTabKeyPress) then
  1985. begin
  1986. if Event.InfoPtr = UnitInfoUsed then
  1987. if assigned(UnitInfoDependent) then
  1988. UnitInfoDependent^.Focus;
  1989. if Event.InfoPtr = UnitInfoDependent then
  1990. if assigned(UnitInfoUsed) then
  1991. UnitInfoUsed^.Focus;
  1992. ClearEvent(Event);
  1993. end;
  1994. inherited HandleEvent(Event);
  1995. end;
  1996. constructor TBrowserWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  1997. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  1998. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemINfo);
  1999. var R,R2,R3: TRect;
  2000. HSB,VSB: PScrollBar;
  2001. CST: PColorStaticText;
  2002. I: sw_integer;
  2003. function CreateVSB(R: TRect): PScrollBar;
  2004. var R2: TRect;
  2005. SB: PScrollBar;
  2006. begin
  2007. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  2008. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  2009. CreateVSB:=SB;
  2010. end;
  2011. function CreateHSB(R: TRect): PScrollBar;
  2012. var R2: TRect;
  2013. SB: PScrollBar;
  2014. begin
  2015. R2.Copy(R); R2.Move(0,1); R2.A.Y:=R2.B.Y-1;
  2016. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  2017. CreateHSB:=SB;
  2018. end;
  2019. begin
  2020. inherited Init(Bounds, FormatStrStr(dialog_browse,ATitle), ANumber);
  2021. New(BrowserLinked,Init(ATitle,ANumber,ASym,
  2022. AName,APrefix,ASymbols,AReferences,AInheritance,AMemInfo));
  2023. HelpCtx:=hcBrowserWindow;
  2024. Sym:=ASym;
  2025. Prefix:=NewStr(APrefix);
  2026. BrowserFlags:=DefaultDispayFlags shl 30 or DefaultSymbolFlags;
  2027. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  2028. {$ifndef NODEBUG}
  2029. if {assigned(Debugger) and Debugger^.IsRunning and}
  2030. assigned(Sym) and (Sym^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) then
  2031. begin
  2032. New(DebuggerValue,Init(ATitle,Sym));
  2033. New(ST, Init(R, ' '+DebuggerValue^.GetText));
  2034. end
  2035. else
  2036. {$endif NODEBUG}
  2037. begin
  2038. New(ST, Init(R, ' '+AName));
  2039. DebuggerValue:=nil;
  2040. end;
  2041. ST^.GrowMode:=gfGrowHiX;
  2042. Insert(ST);
  2043. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);
  2044. if assigned(ASymbols) and (ASymbols^.Count>0) then
  2045. begin
  2046. HSB:=CreateHSB(R);
  2047. Insert(HSB);
  2048. VSB:=CreateVSB(R);
  2049. Insert(VSB);
  2050. New(ScopeView, Init(R, ASymbols, HSB, VSB));
  2051. ScopeView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2052. Insert(ScopeView);
  2053. ScopeView^.MyBW:=@Self;
  2054. if assigned(AInheritance) then
  2055. begin
  2056. ScopeView^.Inh:=true;
  2057. ScopeView^.PullInInheritance;
  2058. end;
  2059. ScopeView^.SetGDBCol;
  2060. ScopeView^.FilterSymbols(true);
  2061. ScopeView^.SetRange(ScopeView^.FilteredSym^.Count);
  2062. end;
  2063. if assigned(AReferences) and (AReferences^.Count>0) then
  2064. begin
  2065. HSB:=CreateHSB(R);
  2066. Insert(HSB);
  2067. VSB:=CreateVSB(R);
  2068. Insert(VSB);
  2069. New(ReferenceView, Init(R, AReferences, HSB, VSB));
  2070. ReferenceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2071. Insert(ReferenceView);
  2072. ReferenceView^.MyBW:=@Self;
  2073. end;
  2074. if assigned(AInheritance) then
  2075. begin
  2076. HSB:=CreateHSB(R);
  2077. Insert(HSB);
  2078. VSB:=CreateVSB(R);
  2079. Insert(VSB);
  2080. New(InheritanceView, Init(R, HSB,VSB, AInheritance));
  2081. InheritanceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2082. Insert(InheritanceView);
  2083. InheritanceView^.MyBW:=@Self;
  2084. end;
  2085. if assigned(AMemInfo) then
  2086. begin
  2087. New(MemInfoView, Init(R, AMemInfo));
  2088. MemInfoView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2089. Insert(MemInfoView);
  2090. MemInfoView^.MyBW:=@Self;
  2091. end;
  2092. if Assigned(Asym) and (TypeOf(ASym^)=TypeOf(TModuleSymbol)) then
  2093. with PModuleSymbol(Sym)^ do
  2094. begin
  2095. New(UnitInfo, Init(R));
  2096. UnitInfo^.GetExtent(R3);
  2097. R2.Copy(R3);
  2098. R2.B.Y:=R2.A.Y+3;
  2099. if (Assigned(UsedUnits) or Assigned(DependentUnits))=false then
  2100. R2.B.Y:=R3.B.Y;
  2101. {HSB:=CreateHSB(R2);} {UnitInfo^.Insert(HSB); HSB:=nil;}
  2102. {VSB:=CreateVSB(R2);}
  2103. HSB:=nil; { It is for the best to not have HSB at all. M }
  2104. VSB:=nil;
  2105. {UnitInfo^.Insert(VSB);
  2106. VSB will be owned by UnitInfoText PM }
  2107. New(UnitInfoText, Init(R2,HSB,VSB, nil));
  2108. with UnitInfoText^ do
  2109. begin
  2110. GrowMode:=gfGrowHiX;
  2111. if Assigned(LoadedFrom) then {this will be false always because it is not set anymore in browcol unit}
  2112. AddLine(FormatStrStr2('%s : %s',msg_usedfirstin,GetStr(LoadedFrom)));
  2113. if Assigned(MainSource) then
  2114. begin
  2115. AddLine(FormatStrStr('%s : ',msg_mainsource));
  2116. AddLine(FormatStrStr(' %s',GetStr(MainSource)));
  2117. end;
  2118. if Assigned(SourceFiles) and (SourceFiles^.Count>1) then
  2119. begin
  2120. AddLine(FormatStrStr('%s : ',msg_sourcefiles));
  2121. for I:=0 to SourceFiles^.Count-1 do
  2122. AddLine(FormatStrStr(' %s',GetStr(SourceFiles^.At(I))));
  2123. end;
  2124. end;
  2125. UnitInfo^.Insert(UnitInfoText);
  2126. UnitInfo^.UnitInfoUsed:=nil;
  2127. if Assigned(UsedUnits) then
  2128. begin
  2129. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  2130. New(CST, Init(R2,#180' Used units '#195+CharStr(#196,255),ColorIndex(12),false));
  2131. CST^.GrowMode:=gfGrowHiX;
  2132. UnitInfo^.Insert(CST);
  2133. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+Max(3,Size.Y-12);
  2134. Dec(R2.B.X); { make space for VSB inside Panel }
  2135. if Assigned(DependentUnits)=false then R2.B.Y:=R3.B.Y;
  2136. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  2137. HSB:=nil;
  2138. VSB:=CreateVSB(R2);
  2139. {UnitInfo^.Insert(VSB); this created crashes,
  2140. that were difficult to findout PM }
  2141. { Maybe because it was outside Panel? M }
  2142. UnitInfo^.Insert(VSB); { lets try again with VSB inside Panel area }
  2143. New(UnitInfoUsed, Init(R2,UsedUnits,HSB,VSB));
  2144. Inc(R2.B.X); { restore R2 }
  2145. UnitInfoUsed^.GrowMode:=gfGrowHiY+gfGrowHiX;
  2146. UnitInfoUsed^.MyBW:=@Self;
  2147. UnitInfo^.Insert(UnitInfoUsed);
  2148. UnitInfo^.UnitInfoUsed:=UnitInfoUsed;
  2149. UnitInfo^.UsedVSB:=VSB;
  2150. UnitInfo^.UsedCST:=CST;
  2151. end;
  2152. UnitInfo^.UnitInfoDependent:=nil;
  2153. if Assigned(DependentUnits) then
  2154. begin
  2155. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  2156. New(CST, Init(R2,#180' Dependent units '#195+CharStr(#196,255),ColorIndex(12),false));
  2157. CST^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  2158. if not Assigned(UsedUnits) then CST^.GrowMode:=gfGrowHiX;
  2159. UnitInfo^.Insert(CST);
  2160. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R3.B.Y;
  2161. Dec(R2.B.X); { make space for VSB inside Panel }
  2162. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  2163. HSB:=nil;
  2164. VSB:=CreateVSB(R2);
  2165. { UnitInfo^.Insert(VSB); this created crashes,
  2166. that were difficult to findout PM }
  2167. { Maybe because it was outside Panel? M }
  2168. UnitInfo^.Insert(VSB); { lets try again with VSB inside Panel area }
  2169. if Assigned(UsedUnits) then
  2170. VSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowLoX+gfGrowHiY;
  2171. New(UnitInfoDependent, Init(R2,DependentUnits,HSB,VSB));
  2172. UnitInfoDependent^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  2173. if not Assigned(UsedUnits) then
  2174. UnitInfoDependent^.GrowMode:=gfGrowHiY+gfGrowHiX;
  2175. UnitInfoDependent^.MyBW:=@Self;
  2176. UnitInfo^.Insert(UnitInfoDependent);
  2177. UnitInfo^.UnitInfoDependent:=UnitInfoDependent;
  2178. UnitInfo^.DependVSB:=VSB;
  2179. UnitInfo^.DependCST:=CST;
  2180. end;
  2181. if Assigned(UnitInfoText) then
  2182. UnitInfoText^.Select;
  2183. PrevSize.Y:=0;
  2184. PrevSize.X:=0;
  2185. OnResize;
  2186. Insert(UnitInfo);
  2187. end;
  2188. PrevSize:=Size;
  2189. { hide not active pages so that scrollbars do not overlap }
  2190. if assigned(ScopeView) then ScopeView^.SetState(sfVisible,False);
  2191. if assigned(ReferenceView) then ReferenceView^.SetState(sfVisible,False);
  2192. if assigned(InheritanceView) then InheritanceView^.SetState(sfVisible,False);
  2193. if assigned(MemInfoView) then MemInfoView^.SetState(sfVisible,False);
  2194. if assigned(UnitInfo) then UnitInfo^.SetState(sfVisible,False);
  2195. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.B.Y:=R.A.Y+1;
  2196. New(PageTab, Init(R,
  2197. NewBrowserTabItem(label_browsertab_scope,ScopeView,
  2198. NewBrowserTabItem(label_browsertab_reference,ReferenceView,
  2199. NewBrowserTabItem(label_browsertab_inheritance,InheritanceView,
  2200. NewBrowserTabItem(label_browsertab_memory,MemInfoView,
  2201. NewBrowserTabItem(label_browsertab_unit,UnitInfo,
  2202. nil)))))));
  2203. PageTab^.GrowMode:=gfGrowHiX;
  2204. Insert(PageTab);
  2205. if assigned(ScopeView) {Scope assinged and chosen to be selected by default}
  2206. and ((DefaultBrowserPane=0) or not assigned(ReferenceView)) then
  2207. SelectTab(btScope)
  2208. else if assigned(ReferenceView) then
  2209. SelectTab(btReferences)
  2210. else if assigned(MemInfoView) then
  2211. SelectTab(btMemInfo)
  2212. else
  2213. if assigned(InheritanceView) then
  2214. SelectTab(btInheritance);
  2215. end;
  2216. destructor TBrowserWindow.Done;
  2217. begin
  2218. { UnitInfoText needs to be removed first
  2219. to avoid crashes within the UnitInfo destructor PM }
  2220. if Assigned(UnitInfoText) then
  2221. begin
  2222. UnitInfo^.Delete(UnitInfoText);
  2223. Dispose(UnitInfoText,Done);
  2224. UnitInfoText:=nil;
  2225. end;
  2226. if assigned(DebuggerValue) then
  2227. begin
  2228. Dispose(DebuggerValue,Done);
  2229. DebuggerValue:=nil;
  2230. end;
  2231. if assigned(Prefix) then
  2232. begin
  2233. DisposeStr(Prefix);
  2234. Prefix:=nil;
  2235. end;
  2236. inherited Done;
  2237. end;
  2238. procedure TBrowserWindow.HandleEvent(var Event: TEvent);
  2239. var DontClear: boolean;
  2240. S: PHollowSymbol;
  2241. Symbols: PSymbolCollection;
  2242. Anc: PObjectSymbol;
  2243. P,WH: TPoint;
  2244. begin
  2245. case Event.What of
  2246. evBroadcast :
  2247. case Event.Command of
  2248. cmDebuggerStopped :
  2249. begin
  2250. if Assigned(DebuggerValue) and
  2251. (DebuggerValue^.GDBI<>PtrInt(Event.InfoPtr)) then
  2252. begin
  2253. If Assigned(ST^.Text) then
  2254. DisposeStr(ST^.Text);
  2255. ST^.Text:=NewStr(DebuggerValue^.GetText);
  2256. ST^.DrawView;
  2257. end;
  2258. end;
  2259. cmSearchWindow :
  2260. ClearEvent(Event);
  2261. cmListItemSelected :
  2262. begin
  2263. S:=nil;
  2264. if (Event.InfoPtr=ScopeView) then
  2265. begin
  2266. S:=PHollowSymbol(ScopeView^.FilteredSym^.At(ScopeView^.Focused)^.Sym);
  2267. MakeGlobal(ScopeView^.Origin,P);
  2268. Desktop^.MakeLocal(P,P); Inc(P.Y,ScopeView^.Focused-ScopeView^.TopItem);
  2269. Inc(P.Y);
  2270. end;
  2271. if (Event.InfoPtr=UnitInfoUsed) then
  2272. begin
  2273. S:=PHollowSymbol(UnitInfoUsed^.FilteredSym^.At(UnitInfoUsed^.Focused)^.Sym);
  2274. MakeGlobal(UnitInfoUsed^.Origin,P);
  2275. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoUsed^.Focused-UnitInfoUsed^.TopItem);
  2276. Inc(P.Y);
  2277. end;
  2278. if (Event.InfoPtr=UnitInfoDependent) then
  2279. begin
  2280. S:=PHollowSymbol(UnitInfoDependent^.FilteredSym^.At(UnitInfoDependent^.Focused)^.Sym);
  2281. MakeGlobal(UnitInfoDependent^.Origin,P);
  2282. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoDependent^.Focused-UnitInfoDependent^.TopItem);
  2283. Inc(P.Y);
  2284. end;
  2285. if Assigned(S) then
  2286. begin
  2287. P.X:=Origin.X-1;WH.X:=0;WH.Y:=0;
  2288. if DefaultBrowserSub = ReplaceCurrent then begin
  2289. P.X:=Origin.X;P.Y:=Origin.Y;
  2290. WH.X:=Size.X;WH.Y:=Size.Y;
  2291. end;
  2292. if S^.Ancestor=nil then Anc:=nil else
  2293. Anc:=SearchObjectForSymbol(S^.Ancestor);
  2294. Symbols:=S^.Items;
  2295. if (not assigned(Symbols) or (symbols^.count=0)) then
  2296. if assigned(S^.Ancestor) then
  2297. Symbols:=S^.Ancestor^.Items;
  2298. if (S^.GetReferenceCount>0) or (assigned(Symbols) and (Symbols^.Count>0)) or (Anc<>nil) then
  2299. OpenSymbolBrowser(P.X,P.Y,WH.X,WH.Y,
  2300. S^.GetName,
  2301. S^.GetText {ScopeView^.GetText(ScopeView^.Focused,255)},
  2302. S^.Sym,@self,
  2303. Symbols,S^.References,Anc,S^.MemInfo);
  2304. ClearEvent(Event);
  2305. if DefaultBrowserSub = ReplaceCurrent then
  2306. if (S^.GetReferenceCount>0) or (assigned(Symbols) and (Symbols^.Count>0)) or (Anc<>nil) then
  2307. Message(@Self,evCommand,cmClose,nil);
  2308. end;
  2309. end;
  2310. end;
  2311. { evCommand :
  2312. begin
  2313. DontClear:=false;
  2314. case Event.Command of
  2315. cmGotoSymbol :
  2316. if Event.InfoPtr=ScopeView then
  2317. if ReferenceView<>nil then
  2318. if ReferenceView^.Range>0 then
  2319. ReferenceView^.GotoItem(0);
  2320. cmTrackSymbol :
  2321. if Event.InfoPtr=ScopeView then
  2322. if (ScopeView<>nil) and (ScopeView^.Range>0) then
  2323. begin
  2324. S:=ScopeView^.At(ScopeView^.Focused);
  2325. if (S^.References<>nil) and (S^.References^.Count>0) then
  2326. TrackItem(S^.References^.At(0));
  2327. else DontClear:=true;
  2328. end;
  2329. if DontClear=false then ClearEvent(Event);
  2330. end;}
  2331. evKeyDown :
  2332. begin
  2333. DontClear:=false;
  2334. case Event.KeyCode of
  2335. kbEsc :
  2336. Close;
  2337. kbAltI :
  2338. If not Disassemble then
  2339. DontClear:=true;
  2340. else DontClear:=true;
  2341. end;
  2342. if DontClear=false then ClearEvent(Event);
  2343. end;
  2344. evCommand :
  2345. begin
  2346. if Event.Command = cmSymPrevious then
  2347. begin
  2348. if assigned (BrowserLinked) then
  2349. BrowserLinked^.PreviousWindow;
  2350. ClearEvent(Event);
  2351. end else
  2352. if Event.Command = cmClose then
  2353. begin
  2354. if assigned (BrowserLinked) then begin
  2355. BrowserLinked^.LeaveTree;
  2356. BrowserLinked:=nil;
  2357. end;
  2358. { do not clear event because actual close will be handled later }
  2359. end;
  2360. end;
  2361. end;
  2362. inherited HandleEvent(Event);
  2363. end;
  2364. function TBrowserWindow.Disassemble : boolean;
  2365. begin
  2366. Disassemble:=false;
  2367. if not assigned(sym) or (sym^.typ<>procsym) then
  2368. exit;
  2369. { We need to load exefile }
  2370. {$ifndef NODEBUG}
  2371. InitGDBWindow;
  2372. if not assigned(Debugger) then
  2373. begin
  2374. new(Debugger,Init);
  2375. if assigned(Debugger) then
  2376. Debugger^.SetExe(ExeFile);
  2377. end;
  2378. if not assigned(Debugger) or not Debugger^.HasExe then
  2379. exit;
  2380. { goto source/assembly mixture }
  2381. InitDisassemblyWindow;
  2382. DisassemblyWindow^.LoadFunction(Sym^.GetName);
  2383. DisassemblyWindow^.SelectInDebugSession;
  2384. Disassemble:=true;
  2385. {$else NODEBUG}
  2386. NoDebugger;
  2387. {$endif NODEBUG}
  2388. end;
  2389. function TBrowserWindow.GetFlags: longint;
  2390. begin
  2391. GetFlags:=BrowserFlags;
  2392. end;
  2393. procedure TBrowserWindow.SetFlags(AFlags: longint);
  2394. begin
  2395. BrowserFlags:=AFlags;
  2396. if assigned(ScopeView) then
  2397. begin
  2398. ScopeView^.FilterSymbols(true);
  2399. ScopeView^.SetRange(ScopeView^.FilteredSym^.Count);
  2400. ScopeView^.DrawView;
  2401. end;
  2402. end;
  2403. procedure TBrowserWindow.UpdateCommands;
  2404. var Active, Visible: boolean;
  2405. begin
  2406. Visible:=GetState(sfVisible);
  2407. Active:=GetState(sfActive) and Visible;
  2408. SetCmdState([cmSaveAs,cmSymPrevious],Active);
  2409. if Active and assigned(BrowserLinked) then
  2410. if not assigned(BrowserLinked^.Previous) then
  2411. SetCmdState([cmSymPrevious],false) { parent is unknown yet }
  2412. else if not assigned(BrowserLinked^.Previous^.Previous) then
  2413. SetCmdState([cmSymPrevious],false); { those based in root have no Previous option }
  2414. {Message(Application,evBroadcast,cmCommandSetChanged,nil);}
  2415. end;
  2416. procedure TBrowserWindow.SizeLimits (Var Min, Max: TPoint);
  2417. begin
  2418. Min.X:=20;
  2419. Min.Y:=15; { Scrollbars in unit info page is still usable }
  2420. Max.X:=ScreenWidth;
  2421. Max.Y:=ScreenHeight-2;
  2422. if (PrevSize.X<>Size.X) or (PrevSize.Y<>Size.Y) then
  2423. begin
  2424. OnResize;
  2425. PrevSize:=Size;
  2426. end;
  2427. end;
  2428. procedure TBrowserWindow.OnResize;
  2429. var Y, uL,dL,tL: sw_integer;
  2430. uMi,dMi,tMi: sw_integer;
  2431. T,U,D : sw_integer;
  2432. TotalLinesNeed : sw_integer;
  2433. begin
  2434. if (PrevSize.Y<>Size.Y) then
  2435. begin
  2436. {-- unit info page resize manualy --}
  2437. if assigned(UnitInfo) then
  2438. begin
  2439. { get number of lines everyone needs }
  2440. Y:=UnitInfo^.Size.Y;
  2441. tL:=UnitInfoText^.GetLineCount;
  2442. tMi:=Min(tL,3);
  2443. uL:=0;dL:=0;uMi:=0;dMi:=0;
  2444. if assigned(UnitInfoUsed) then
  2445. begin
  2446. uMi:=4;
  2447. uL:=UnitInfoUsed^.FilteredSym^.Count+1;
  2448. end;
  2449. if assigned(UnitInfoDependent) then
  2450. begin
  2451. dMi:=4;
  2452. dL:=UnitInfoDependent^.FilteredSym^.Count+1;
  2453. end;
  2454. { proportional split amongst needy }
  2455. TotalLinesNeed:=Max(tL+uL+dL,1);
  2456. T:=Max(tMi,(tL*Y) div TotalLinesNeed);
  2457. T:=Min(T,Max(tMi,tL)); { don't give more than actual need }
  2458. TotalLinesNeed:=Max(uL+dL,1);
  2459. Y:=Y-T;
  2460. U:=Max(uMi,(uL*Y) div TotalLinesNeed);
  2461. Y:=Y-U;
  2462. D:=Y;
  2463. if D<dMi then
  2464. begin
  2465. U:=U-(dMi-D);
  2466. D:=dMi;
  2467. end;
  2468. { assign newly calculated positions and height for everyone }
  2469. UnitInfoText^.Size.Y:=T;
  2470. if assigned(UnitInfoUsed) then
  2471. begin
  2472. UnitInfo^.UsedCST^.Origin.Y:=T;
  2473. UnitInfoUsed^.Origin.Y:=T+1;
  2474. UnitInfo^.UsedVSB^.Origin.Y:=T+1;
  2475. UnitInfoUsed^.Size.Y:=U-1;
  2476. UnitInfo^.UsedVSB^.Size.Y:=U-1;
  2477. end;
  2478. if assigned(UnitInfoDependent) then
  2479. begin
  2480. UnitInfo^.DependCST^.Origin.Y:=T+U;
  2481. UnitInfoDependent^.Origin.Y:=T+U+1;
  2482. UnitInfo^.DependVSB^.Origin.Y:=T+U+1;
  2483. UnitInfoDependent^.Size.Y:=D-1;
  2484. UnitInfo^.DependVSB^.Size.Y:=D-1;
  2485. end;
  2486. end;
  2487. end;
  2488. end;
  2489. procedure TBrowserWindow.Close;
  2490. begin
  2491. inherited Close;
  2492. end;
  2493. procedure TBrowserWindow.SelectTab(BrowserTab: Sw_integer);
  2494. var Tabs: Sw_integer;
  2495. {$ifndef NODEBUG}
  2496. PB : PBreakpoint;
  2497. {$endif}
  2498. PS :PString;
  2499. l : longint;
  2500. begin
  2501. case BrowserTab of
  2502. btScope :
  2503. if assigned(ScopeView) then
  2504. ScopeView^.Select;
  2505. btReferences :
  2506. if assigned(ReferenceView) then
  2507. ReferenceView^.Select;
  2508. btMemInfo:
  2509. if assigned(MemInfoView) then
  2510. MemInfoView^.Select;
  2511. {$ifndef NODEBUG}
  2512. btBreakWatch :
  2513. begin
  2514. if Assigned(Sym) then
  2515. begin
  2516. if Pos('proc',Sym^.GetText)>0 then
  2517. { insert function breakpoint }
  2518. begin
  2519. { make it visible }
  2520. PS:=Sym^.Name;
  2521. l:=Length(PS^);
  2522. If PS^[l]='*' then
  2523. begin
  2524. PB:=BreakpointsCollection^.GetType(bt_function,copy(GetStr(PS),1,l-1));
  2525. If Assigned(PB) then
  2526. BreakpointsCollection^.Delete(PB);
  2527. Sym^.Name:=NewStr(copy(GetStr(PS),1,l-1));
  2528. DrawView;
  2529. DisposeStr(PS);
  2530. end
  2531. else
  2532. begin
  2533. Sym^.Name:=NewStr(GetStr(PS)+'*');
  2534. DrawView;
  2535. New(PB,init_function(GetStr(PS)));
  2536. DisposeStr(PS);
  2537. BreakpointsCollection^.Insert(PB);
  2538. BreakpointsCollection^.Update;
  2539. end;
  2540. end
  2541. else if pos('var',Sym^.GetText)>0 then
  2542. { insert watch point }
  2543. begin
  2544. { make it visible }
  2545. PS:=Sym^.Name;
  2546. l:=Length(PS^);
  2547. If PS^[l]='*' then
  2548. begin
  2549. PB:=BreakpointsCollection^.GetType(bt_awatch,copy(PS^,1,l-1));
  2550. If Assigned(PB) then
  2551. BreakpointsCollection^.Delete(PB);
  2552. Sym^.Name:=NewStr(copy(PS^,1,l-1));
  2553. DrawView;
  2554. DisposeStr(PS);
  2555. end
  2556. else
  2557. begin
  2558. Sym^.Name:=NewStr(GetStr(PS)+'*');
  2559. DrawView;
  2560. New(PB,init_type(bt_awatch,GetStr(PS)));
  2561. DisposeStr(PS);
  2562. BreakpointsCollection^.Insert(PB);
  2563. BreakpointsCollection^.Update;
  2564. end;
  2565. end;
  2566. end;
  2567. end;
  2568. {$endif NODEBUG}
  2569. end;
  2570. Tabs:=0;
  2571. if assigned(ScopeView) then
  2572. Tabs:=Tabs or (1 shl btScope);
  2573. if assigned(ReferenceView) then
  2574. Tabs:=Tabs or (1 shl btReferences);
  2575. if assigned(InheritanceView) then
  2576. Tabs:=Tabs or (1 shl btInheritance);
  2577. if assigned(MemInfoView) then
  2578. Tabs:=Tabs or (1 shl btMemInfo);
  2579. {$ifndef NODEBUG}
  2580. if Assigned(Sym) then
  2581. if (Pos('proc',Sym^.GetText)>0) or (Pos('var',Sym^.GetText)>0) then
  2582. Tabs:=Tabs or (1 shl btBreakWatch);
  2583. {$endif NODEBUG}
  2584. if assigned(UnitInfo) then
  2585. Tabs:=Tabs or (1 shl btUnitInfo);
  2586. if PageTab<>nil then PageTab^.SetParams(Tabs,BrowserTab);
  2587. end;
  2588. function TBrowserWindow.GetPalette: PPalette;
  2589. const S: string[length(CBrowserWindow)] = CBrowserWindow;
  2590. begin
  2591. GetPalette:=@S;
  2592. end;
  2593. function OpenSymbolBrowser(X,Y,W,H: Sw_integer;const Name,Line: string;S : PSymbol;
  2594. ParentBrowser : PBrowserWindow;
  2595. Symbols: PSymbolCollection; References: PReferenceCollection;
  2596. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo):PBrowserWindow;
  2597. var R: TRect;
  2598. PB : PBrowserWindow;
  2599. St,st2 : string;
  2600. begin
  2601. if X=0 then X:=Desktop^.Size.X-35;
  2602. R.A.X:=X; R.A.Y:=Y;
  2603. R.B.X:=R.A.X+35; R.B.Y:=R.A.Y+Max(15,(ScreenHeight * 3 div 5));
  2604. if W<>0 then R.B.X:=R.A.X+W;
  2605. if H<>0 then R.B.Y:=R.A.Y+H;
  2606. while (R.B.Y>Desktop^.Size.Y) do R.Move(0,-1);
  2607. if assigned(ParentBrowser) and assigned(ParentBrowser^.Prefix) and
  2608. assigned(ParentBrowser^.sym) and
  2609. (ParentBrowser^.sym^.typ<>unitsym)
  2610. then
  2611. begin
  2612. st:=GetStr(ParentBrowser^.Prefix)+' '+Name;
  2613. end
  2614. else
  2615. st:=Name;
  2616. st2:=st;
  2617. if assigned(S) and ((S^.Flags and sfPointer)<>0) then
  2618. begin
  2619. st:=st+'^';
  2620. if assigned(S^.Ancestor) and
  2621. ((S^.Ancestor^.Flags and sfRecord)<>0) then
  2622. st:=st+'.';
  2623. end
  2624. else if assigned(S) and ((S^.Flags and sfRecord)<>0) then
  2625. st:=st+'.';
  2626. PB:=New(PBrowserWindow, Init(R,
  2627. st2,SearchFreeWindowNo,S,Line,st,
  2628. Symbols,References,Inheritance,MemInfo));
  2629. if (assigned(S) and (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym])) or
  2630. (assigned(ParentBrowser) and ParentBrowser^.IsValid) then
  2631. PB^.IsValid:=true;
  2632. if assigned(ParentBrowser) then
  2633. ParentBrowser^.BrowserLinked^.InsertWindow(PB);
  2634. Desktop^.Insert(PB);
  2635. OpenSymbolBrowser:=PB;
  2636. end;
  2637. constructor TBrowserLinked.Init(ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  2638. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  2639. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemInfo);
  2640. begin
  2641. inherited init;
  2642. Title:=ATitle;
  2643. Number:=ANumber;
  2644. Sym:=ASym;
  2645. Name:=AName;
  2646. Prefix:=APrefix;
  2647. Symbols:= ASymbols;
  2648. References:=AReferences;
  2649. Inheritance:=AInheritance;
  2650. MemInfo:=AMemInfo;
  2651. New(Branches,Init(10,10));
  2652. end;
  2653. destructor TBrowserLinked.Done;
  2654. begin
  2655. if Assigned(Branches) then
  2656. begin
  2657. Dispose(Branches,Done);
  2658. Branches:=nil;
  2659. end;
  2660. Inherited Done;
  2661. end;
  2662. procedure TBrowserLinked.InsertWindow(BW : PBrowserWindow);
  2663. begin
  2664. BW^.BrowserLinked^.Previous:=@self;
  2665. BW^.BrowserLinked^.BrowserWindow:=BW;
  2666. Branches^.Insert(BW^.BrowserLinked);
  2667. end;
  2668. procedure TBrowserLinked.CreateNewWindow;
  2669. var R: TRect;
  2670. BW:PBrowserWindow;
  2671. begin
  2672. R.A.X:=Origin.X;
  2673. R.A.Y:=Origin.Y;
  2674. R.B.X:=Origin.X+Size.X;
  2675. R.B.Y:=Origin.Y+Size.Y;
  2676. New(BrowserWindow, Init(R,Title,Number,Sym,
  2677. Name,Prefix,Symbols,References,
  2678. Inheritance,MemInfo));
  2679. Dispose(BrowserWindow^.BrowserLinked,Done);
  2680. BrowserWindow^.BrowserLinked:=@self;
  2681. BW:=BrowserWindow;
  2682. BW^.SelectTab(Tab);
  2683. BW^.SetFlags(BrowserFlags);
  2684. if assigned(BW^.ScopeView) then
  2685. begin
  2686. BW^.ScopeView^.SetTopItem(ScopeTop);
  2687. BW^.ScopeView^.FocusItem(ScopeFocused);
  2688. end;
  2689. if assigned(BW^.ReferenceView) then
  2690. begin
  2691. BW^.ReferenceView^.SetTopItem(ReferenceTop);
  2692. BW^.ReferenceView^.FocusItem(ReferenceFocused);
  2693. end;
  2694. if assigned(BW^.InheritanceView) then
  2695. begin
  2696. {$ifdef HASOUTLINE}
  2697. BW^.InheritanceView^.Delta.Y:=InheritanceTop;
  2698. BW^.InheritanceView^.Focused(InheritanceFocused);
  2699. {$else}
  2700. BW^.InheritanceView^.SetTopItem(InheritanceTop);
  2701. BW^.InheritanceView^.FocusItem(InheritanceFocused);
  2702. {$endif}
  2703. end;
  2704. if assigned(BW^.UnitInfoUsed) then
  2705. begin
  2706. BW^.UnitInfoUsed^.SetTopItem(UnitInfoUsedTop);
  2707. BW^.UnitInfoUsed^.FocusItem(UnitInfoUsedFocused);
  2708. end;
  2709. if assigned(BW^.UnitInfoDependent) then
  2710. begin
  2711. BW^.UnitInfoDependent^.SetTopItem(UnitInfoDependentTop);
  2712. BW^.UnitInfoDependent^.FocusItem(UnitInfoDependentFocused);
  2713. end;
  2714. Desktop^.Insert(BrowserWindow);
  2715. end;
  2716. procedure TBrowserLinked.PreviousWindow;
  2717. begin
  2718. if assigned(Previous) then
  2719. begin
  2720. if not assigned(Previous^.Previous) then
  2721. exit; {root has no window to show}
  2722. if not assigned(Previous^.BrowserWindow) then
  2723. {window has been closed - recreate}
  2724. Previous^.CreateNewWindow;
  2725. if assigned(Previous^.BrowserWindow) then
  2726. begin
  2727. Previous^.BrowserWindow^.Show;
  2728. Previous^.BrowserWindow^.Focus;
  2729. if DefaultBrowserSub = ReplaceCurrent then
  2730. if assigned(BrowserWindow) then
  2731. Message(BrowserWindow,evCommand,cmClose,nil);
  2732. end;
  2733. end;
  2734. end;
  2735. function FreeIfEmpty(bl : PBrowserLinkedCollection):boolean;
  2736. var k : sw_integer;
  2737. p : PBrowserLinked;
  2738. begin
  2739. FreeIfEmpty:=true;
  2740. if bl^.Count > 0 then
  2741. for k:= bl^.Count-1 downto 0 do
  2742. begin
  2743. p:=bl^.at(k);
  2744. if FreeIfEmpty(p^.Branches) then
  2745. begin
  2746. if assigned(p^.BrowserWindow) then
  2747. FreeIfEmpty:=false
  2748. else
  2749. bl^.Free(P);
  2750. end
  2751. else
  2752. FreeIfEmpty:=false;
  2753. end;
  2754. end;
  2755. procedure TBrowserLinked.LeaveTree;
  2756. var k : sw_integer;
  2757. BW : PBrowserWindow;
  2758. begin
  2759. if assigned(BrowserWindow) then
  2760. begin
  2761. BW:=BrowserWindow;
  2762. Origin:=BW^.Origin;
  2763. Size:=BW^.Size;
  2764. Tab:=BW^.PageTab^.Current;
  2765. BrowserFlags:=BW^.GetFlags;
  2766. if assigned(BW^.ScopeView) then
  2767. begin
  2768. ScopeTop:=BW^.ScopeView^.TopItem;
  2769. ScopeFocused:=BW^.ScopeView^.Focused;
  2770. end;
  2771. if assigned(BW^.ReferenceView) then
  2772. begin
  2773. ReferenceTop:=BW^.ReferenceView^.TopItem;
  2774. ReferenceFocused:=BW^.ReferenceView^.Focused;
  2775. end;
  2776. if assigned(BW^.InheritanceView) then
  2777. begin
  2778. {$ifdef HASOUTLINE}
  2779. InheritanceTop:=BW^.InheritanceView^.Delta.Y;
  2780. InheritanceFocused:=BW^.InheritanceView^.Foc;
  2781. InheritanceFocused:=BW^.InheritanceView^.NodeCountToFoc(InheritanceFocused);
  2782. {$else}
  2783. InheritanceTop:=BW^.InheritanceView^.TopItem;
  2784. InheritanceFocused:=BW^.InheritanceView^.Focused;
  2785. {$endif}
  2786. end;
  2787. if assigned(BW^.UnitInfoUsed) then
  2788. begin
  2789. UnitInfoUsedTop:=BW^.UnitInfoUsed^.TopItem;
  2790. UnitInfoUsedFocused:=BW^.UnitInfoUsed^.Focused;
  2791. end;
  2792. if assigned(BW^.UnitInfoDependent) then
  2793. begin
  2794. UnitInfoDependentTop:=BW^.UnitInfoDependent^.TopItem;
  2795. UnitInfoDependentFocused:=BW^.UnitInfoDependent^.Focused;
  2796. end;
  2797. BrowserWindow^.BrowserLinked:=nil; {this is pulling rug under the feet, FreeAndNil style}
  2798. BrowserWindow:=nil;
  2799. end;
  2800. if FreeIfEmpty(Branches) then
  2801. begin
  2802. if assigned(Previous) then
  2803. Previous^.Branches^.Free(@self);
  2804. FreeIfEmpty(BrowserRoot^.Branches);
  2805. end;
  2806. end;
  2807. function TBrowserLinkedCollection.At(Index: sw_Integer): PBrowserLinked;
  2808. begin
  2809. At:=inherited At(Index);
  2810. end;
  2811. initialization
  2812. New(BrowserRoot,init('',0,nil,'','',nil,nil,nil,nil));
  2813. finalization
  2814. Dispose(BrowserRoot,Done);
  2815. END.