fpviews.pas 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Views and view-related functions for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPViews;
  12. {$i globdir.inc}
  13. interface
  14. uses
  15. Dos,Objects,Drivers,
  16. FVConsts,
  17. Views,Menus,Dialogs,App,Gadgets,Tabs,
  18. ASCIITAB,
  19. WEditor,WCEdit,
  20. WUtils,WHelp,WHlpView,WViews,WANSI,
  21. Comphook,
  22. FPConst,FPUsrScr;
  23. type
  24. TEditor = TCodeEditor;
  25. PEditor = PCodeEditor;
  26. PStoreCollection = ^TStoreCollection;
  27. TStoreCollection = object(TStringCollection)
  28. function Add(const S: string): PString;
  29. end;
  30. PIntegerLine = ^TIntegerLine;
  31. TIntegerLine = object(TInputLine)
  32. constructor Init(var Bounds: TRect; AMin, AMax: longint);
  33. end;
  34. PFPHeapView = ^TFPHeapView;
  35. TFPHeapView = object(THeapView)
  36. constructor Init(var Bounds: TRect);
  37. constructor InitKb(var Bounds: TRect);
  38. procedure HandleEvent(var Event: TEvent); virtual;
  39. end;
  40. PFPClockView = ^TFPClockView;
  41. TFPClockView = object(TClockView)
  42. constructor Init(var Bounds: TRect);
  43. procedure HandleEvent(var Event: TEvent); virtual;
  44. function GetPalette: PPalette; virtual;
  45. end;
  46. PFPWindow = ^TFPWindow;
  47. TFPWindow = object(TWindow)
  48. AutoNumber: boolean;
  49. procedure HandleEvent(var Event: TEvent); virtual;
  50. procedure SetState(AState: Word; Enable: Boolean); virtual;
  51. procedure UpdateCommands; virtual;
  52. constructor Load(var S: TStream);
  53. procedure Store(var S: TStream);
  54. procedure Update; virtual;
  55. procedure SelectInDebugSession;
  56. end;
  57. PFPHelpViewer = ^TFPHelpViewer;
  58. TFPHelpViewer = object(THelpViewer)
  59. function GetLocalMenu: PMenu; virtual;
  60. function GetCommandTarget: PView; virtual;
  61. end;
  62. PFPHelpWindow = ^TFPHelpWindow;
  63. TFPHelpWindow = object(THelpWindow)
  64. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word; AContext: THelpCtx; ANumber: Integer);
  65. destructor Done;virtual;
  66. procedure InitHelpView; virtual;
  67. procedure Show; {virtual;}
  68. procedure Hide; {virtual;}
  69. procedure HandleEvent(var Event: TEvent); virtual;
  70. function GetPalette: PPalette; virtual;
  71. constructor Load(var S: TStream);
  72. procedure Store(var S: TStream);
  73. end;
  74. PTextScroller = ^TTextScroller;
  75. TTextScroller = object(TStaticText)
  76. TopLine: integer;
  77. Speed : integer;
  78. Lines : PUnsortedStringCollection;
  79. constructor Init(var Bounds: TRect; ASpeed: integer; AText: PUnsortedStringCollection);
  80. function GetLineCount: integer; virtual;
  81. function GetLine(I: integer): string; virtual;
  82. procedure HandleEvent(var Event: TEvent); virtual;
  83. procedure Update; virtual;
  84. procedure Reset; virtual;
  85. procedure Scroll; virtual;
  86. procedure Draw; virtual;
  87. destructor Done; virtual;
  88. private
  89. LastTT: longint;
  90. end;
  91. TAlign = (alLeft,alCenter,alRight);
  92. PFPToolTip = ^TFPToolTip;
  93. TFPToolTip = object(TView)
  94. constructor Init(var Bounds: TRect; const AText: string; AAlign: TAlign);
  95. procedure Draw; virtual;
  96. function GetText: string;
  97. procedure SetText(const AText: string);
  98. function GetAlign: TAlign;
  99. procedure SetAlign(AAlign: TAlign);
  100. function GetPalette: PPalette; virtual;
  101. destructor Done; virtual;
  102. private
  103. Text: PString;
  104. Align: TAlign;
  105. end;
  106. PSourceEditor = ^TSourceEditor;
  107. TSourceEditor = object(TFileEditor)
  108. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  109. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  110. CompileStamp : longint;
  111. CodeCompleteTip: PFPToolTip;
  112. {$ifndef NODEBUG}
  113. private
  114. ShouldHandleBreakpoints : boolean;
  115. {$endif NODEBUG}
  116. public
  117. { Syntax highlight }
  118. function IsReservedWord(const S: string): boolean; virtual;
  119. function IsAsmReservedWord(const S: string): boolean; virtual;
  120. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  121. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  122. { CodeTemplates }
  123. function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual;
  124. function SelectCodeTemplate(var ShortCut: string): boolean; virtual;
  125. { CodeComplete }
  126. function CompleteCodeWord(const WordS: string; var Text: string): boolean; virtual;
  127. procedure FindMatchingDelimiter(ScanForward: boolean); virtual;
  128. procedure SetCodeCompleteWord(const S: string); virtual;
  129. procedure AlignCodeCompleteTip;
  130. procedure HandleEvent(var Event: TEvent); virtual;
  131. {$ifdef DebugUndo}
  132. procedure DumpUndo;
  133. procedure UndoAll;
  134. procedure RedoAll;
  135. {$endif DebugUndo}
  136. function Valid(Command: Word): Boolean;virtual;
  137. function GetLocalMenu: PMenu; virtual;
  138. function GetCommandTarget: PView; virtual;
  139. function CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup; virtual;
  140. procedure ModifiedChanged; virtual;
  141. procedure InsertOptions; virtual;
  142. procedure PushInfo(Const st : string);virtual;
  143. procedure PopInfo;virtual;
  144. procedure DeleteLine(I: sw_integer); virtual;
  145. procedure BackSpace; virtual;
  146. procedure DelChar; virtual;
  147. procedure DelSelect; virtual;
  148. function InsertNewLine : Sw_integer;virtual;
  149. function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  150. procedure AddLine(const S: string); virtual;
  151. end;
  152. PSourceWindow = ^TSourceWindow;
  153. TSourceWindow = object(TFPWindow)
  154. Editor : PSourceEditor;
  155. Indicator : PIndicator;
  156. NoNameCount : longint;
  157. constructor Init(var Bounds: TRect; AFileName: string);
  158. function GetTitle(MaxSize: sw_Integer): TTitleStr; virtual;
  159. procedure SetTitle(ATitle: string); virtual;
  160. procedure UpdateTitle; virtual;
  161. procedure HandleEvent(var Event: TEvent); virtual;
  162. procedure Update; virtual;
  163. procedure UpdateCommands; virtual;
  164. function GetPalette: PPalette; virtual;
  165. constructor Load(var S: TStream);
  166. procedure Store(var S: TStream);
  167. procedure Close; virtual;
  168. destructor Done; virtual;
  169. end;
  170. {$ifndef NODEBUG}
  171. PGDBSourceEditor = ^TGDBSourceEditor;
  172. TGDBSourceEditor = object(TSourceEditor)
  173. function InsertNewLine : Sw_integer;virtual;
  174. function Valid(Command: Word): Boolean; virtual;
  175. procedure AddLine(const S: string); virtual;
  176. procedure AddErrorLine(const S: string); virtual;
  177. { Syntax highlight }
  178. function IsReservedWord(const S: string): boolean; virtual;
  179. private
  180. Silent,
  181. AutoRepeat,
  182. IgnoreStringAtEnd : boolean;
  183. LastCommand : String;
  184. end;
  185. PGDBWindow = ^TGDBWindow;
  186. TGDBWindow = object(TFPWindow)
  187. Editor : PGDBSourceEditor;
  188. Indicator : PIndicator;
  189. constructor Init(var Bounds: TRect);
  190. procedure HandleEvent(var Event: TEvent); virtual;
  191. procedure WriteText(Buf : pchar;IsError : boolean);
  192. procedure WriteString(Const S : string);
  193. procedure WriteErrorString(Const S : string);
  194. procedure WriteOutputText(Buf : pchar);
  195. procedure WriteErrorText(Buf : pchar);
  196. function GetPalette: PPalette;virtual;
  197. constructor Load(var S: TStream);
  198. procedure Store(var S: TStream);
  199. procedure UpdateCommands; virtual;
  200. destructor Done; virtual;
  201. end;
  202. PDisasLine = ^TDisasLine;
  203. TDisasLine = object(TLine)
  204. address : cardinal;{ should be target size of address for cross debuggers }
  205. end;
  206. PDisasLineCollection = ^TDisasLineCollection;
  207. TDisasLineCollection = object(TLineCollection)
  208. function At(Index: sw_Integer): PDisasLine;
  209. end;
  210. PDisassemblyEditor = ^TDisassemblyEditor;
  211. TDisassemblyEditor = object(TSourceEditor)
  212. CurrentSource : String;
  213. CurrentLine : longint;
  214. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  215. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  216. procedure ReleaseSource;
  217. destructor Done;virtual;
  218. procedure AddSourceLine(const AFileName: string;line : longint); virtual;
  219. procedure AddAssemblyLine(const S: string;AAddress : cardinal); virtual;
  220. function GetCurrentLine(address : cardinal) : PDisasLine;
  221. private
  222. Source : PSourceWindow;
  223. OwnsSource : Boolean;
  224. DisasLines : PDisasLineCollection;
  225. MinAddress,MaxAddress : cardinal;
  226. CurL : PDisasLine;
  227. end;
  228. PDisassemblyWindow = ^TDisassemblyWindow;
  229. TDisassemblyWindow = object(TFPWindow)
  230. Editor : PDisassemblyEditor;
  231. Indicator : PIndicator;
  232. constructor Init(var Bounds: TRect);
  233. procedure LoadFunction(Const FuncName : string);
  234. procedure LoadAddress(Addr : cardinal);
  235. function ProcessPChar(p : pchar) : boolean;
  236. procedure HandleEvent(var Event: TEvent); virtual;
  237. procedure WriteSourceString(Const S : string;line : longint);
  238. procedure WriteDisassemblyString(Const S : string;address : cardinal);
  239. procedure SetCurAddress(address : cardinal);
  240. procedure UpdateCommands; virtual;
  241. function GetPalette: PPalette;virtual;
  242. destructor Done; virtual;
  243. end;
  244. {$endif NODEBUG}
  245. PClipboardWindow = ^TClipboardWindow;
  246. TClipboardWindow = object(TSourceWindow)
  247. constructor Init;
  248. procedure Close; virtual;
  249. constructor Load(var S: TStream);
  250. procedure Store(var S: TStream);
  251. destructor Done; virtual;
  252. end;
  253. PMessageItem = ^TMessageItem;
  254. TMessageItem = object(TObject)
  255. TClass : longint;
  256. Text : PString;
  257. Module : PString;
  258. Row,Col : sw_integer;
  259. constructor Init(AClass: longint; const AText: string; AModule: PString; ARow, ACol: sw_integer);
  260. function GetText(MaxLen: Sw_integer): string; virtual;
  261. procedure Selected; virtual;
  262. function GetModuleName: string; virtual;
  263. destructor Done; virtual;
  264. end;
  265. PMessageListBox = ^TMessageListBox;
  266. TMessageListBox = object(THSListBox)
  267. Transparent : boolean;
  268. NoSelection : boolean;
  269. MaxWidth : Sw_integer;
  270. ModuleNames : PStoreCollection;
  271. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  272. procedure SetState(AState: Word; Enable: Boolean); virtual;
  273. procedure AddItem(P: PMessageItem); virtual;
  274. function AddModuleName(const Name: string): PString; virtual;
  275. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  276. procedure Clear; virtual;
  277. procedure TrackSource; virtual;
  278. procedure GotoSource; virtual;
  279. procedure Draw; virtual;
  280. procedure HandleEvent(var Event: TEvent); virtual;
  281. function GetLocalMenu: PMenu; virtual;
  282. constructor Load(var S: TStream);
  283. procedure Store(var S: TStream);
  284. destructor Done; virtual;
  285. end;
  286. PFPDlgWindow = ^TFPDlgWindow;
  287. TFPDlgWindow = object(TDlgWindow)
  288. procedure HandleEvent(var Event: TEvent); virtual;
  289. end;
  290. (*
  291. PTabItem = ^TTabItem;
  292. TTabItem = record
  293. Next : PTabItem;
  294. View : PView;
  295. Dis : boolean;
  296. end;
  297. PTabDef = ^TTabDef;
  298. TTabDef = record
  299. Next : PTabDef;
  300. Name : PString;
  301. Items : PTabItem;
  302. DefItem : PView;
  303. ShortCut : char;
  304. end;
  305. PTab = ^TTab;
  306. TTab = object(TGroup)
  307. TabDefs : PTabDef;
  308. ActiveDef : integer;
  309. DefCount : word;
  310. constructor Init(var Bounds: TRect; ATabDef: PTabDef);
  311. function AtTab(Index: integer): PTabDef; virtual;
  312. procedure SelectTab(Index: integer); virtual;
  313. function TabCount: integer;
  314. procedure SelectNextTab(Forwards: boolean);
  315. function Valid(Command: Word): Boolean; virtual;
  316. procedure ChangeBounds(var Bounds: TRect); virtual;
  317. procedure HandleEvent(var Event: TEvent); virtual;
  318. function GetPalette: PPalette; virtual;
  319. procedure Draw; virtual;
  320. procedure SetState(AState: Word; Enable: Boolean); virtual;
  321. destructor Done; virtual;
  322. private
  323. InDraw: boolean;
  324. end;
  325. *)
  326. PScreenView = ^TScreenView;
  327. TScreenView = object(TScroller)
  328. Screen: PScreen;
  329. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  330. AScreen: PScreen);
  331. procedure Draw; virtual;
  332. procedure Update; virtual;
  333. procedure HandleEvent(var Event: TEvent); virtual;
  334. end;
  335. PScreenWindow = ^TScreenWindow;
  336. TScreenWindow = object(TFPWindow)
  337. ScreenView : PScreenView;
  338. constructor Init(AScreen: PScreen; ANumber: integer);
  339. destructor Done; virtual;
  340. end;
  341. PFPAboutDialog = ^TFPAboutDialog;
  342. TFPAboutDialog = object(TCenterDialog)
  343. constructor Init;
  344. procedure ToggleInfo;
  345. procedure HandleEvent(var Event: TEvent); virtual;
  346. private
  347. Scroller: PTextScroller;
  348. TitleST : PStaticText;
  349. end;
  350. PFPASCIIChart = ^TFPASCIIChart;
  351. TFPASCIIChart = object(TASCIIChart)
  352. constructor Init;
  353. constructor Load(var S: TStream);
  354. procedure Store(var S: TStream);
  355. procedure HandleEvent(var Event: TEvent); virtual;
  356. destructor Done; virtual;
  357. end;
  358. PVideoModeListBox = ^TVideoModeListBox;
  359. TVideoModeListBox = object(TDropDownListBox)
  360. function GetText(Item: pointer; MaxLen: sw_integer): string; virtual;
  361. end;
  362. PFPDesktop = ^TFPDesktop;
  363. TFPDesktop = object(TDesktop)
  364. constructor Init(var Bounds: TRect);
  365. procedure InitBackground; virtual;
  366. constructor Load(var S: TStream);
  367. procedure Store(var S: TStream);
  368. end;
  369. PFPMemo = ^TFPMemo;
  370. TFPMemo = object(TCodeEditor)
  371. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  372. PScrollBar; AIndicator: PIndicator);
  373. function IsReservedWord(const S: string): boolean; virtual;
  374. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  375. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  376. function GetPalette: PPalette; virtual;
  377. procedure HandleEvent(var Event: TEvent); virtual;
  378. end;
  379. PFPCodeMemo = ^TFPCodeMemo;
  380. TFPCodeMemo = object(TFPMemo)
  381. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  382. PScrollBar; AIndicator: PIndicator);
  383. function IsReservedWord(const S: string): boolean; virtual;
  384. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  385. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  386. end;
  387. function SearchFreeWindowNo: integer;
  388. function IsWindow(P: PView): boolean;
  389. function IsThereAnyEditor: boolean;
  390. function IsThereAnyWindow: boolean;
  391. function IsThereAnyVisibleWindow: boolean;
  392. function IsThereAnyNumberedWindow: boolean;
  393. function FirstEditorWindow: PSourceWindow;
  394. function EditorWindowFile(const Name : String): PSourceWindow;
  395. procedure AskToReloadAllModifiedFiles;
  396. {$ifndef NODEBUG}
  397. function InDisassemblyWindow :boolean;
  398. {$endif NODEBUG}
  399. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  400. procedure DisposeTabItem(P: PTabItem);
  401. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  402. procedure DisposeTabDef(P: PTabDef);
  403. function GetEditorCurWord(Editor: PEditor; ValidSpecChars: TCharSet): string;
  404. procedure InitReservedWords;
  405. procedure DoneReservedWords;
  406. function GetReservedWordCount: integer;
  407. function GetReservedWord(Index: integer): string;
  408. function GetAsmReservedWordCount: integer;
  409. function GetAsmReservedWord(Index: integer): string;
  410. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  411. function GetNextEditorBounds(var Bounds: TRect): boolean;
  412. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer): PSourceWindow;
  413. function IOpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer; ShowIt: boolean): PSourceWindow;
  414. function LastSourceEditor : PSourceWindow;
  415. function SearchOnDesktop(FileName : string;tryexts:boolean) : PSourceWindow;
  416. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts: boolean): PSourceWindow;
  417. function ITryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts, ShowIt,
  418. ForceNewWindow:boolean): PSourceWindow;
  419. function LocateSourceFile(const FileName: string; tryexts: boolean): string;
  420. function SearchWindow(const Title: string): PWindow;
  421. function StartEditor(Editor: PCodeEditor; FileName: string): boolean;
  422. {$ifdef VESA}
  423. procedure InitVESAScreenModes;
  424. procedure DoneVESAScreenModes;
  425. {$endif}
  426. procedure NoDebugger;
  427. const
  428. SourceCmds : TCommandSet =
  429. ([cmSave,cmSaveAs,cmCompile,cmHide,cmDoReload]);
  430. EditorCmds : TCommandSet =
  431. ([cmFind,cmReplace,cmSearchAgain,cmJumpLine,cmHelpTopicSearch,cmSelectAll,cmUnselect]);
  432. CompileCmds : TCommandSet =
  433. ([cmMake,cmBuild,cmRun]);
  434. CalcClipboard : extended = 0;
  435. OpenFileName : string = '';
  436. OpenFileLastExt : string[12] = '*.pas';
  437. NewEditorOpened : boolean = false;
  438. var MsgParms : array[1..10] of
  439. record
  440. case byte of
  441. 0 : (Ptr : pointer);
  442. 1 : (Long: longint);
  443. end;
  444. const menu_key_common_copy_borland = 'Ctrl+Ins';
  445. menu_key_common_copy_microsoft = 'Ctrl+C';
  446. menu_key_edit_undo = 'Alt+BkSp';
  447. menu_key_edit_cut_borland = 'Shift+Del';
  448. menu_key_edit_copy_borland = menu_key_common_copy_borland;
  449. menu_key_edit_paste_borland = 'Shift+Ins';
  450. menu_key_edit_cut_microsoft = 'Ctrl+X';
  451. menu_key_edit_copy_microsoft = menu_key_common_copy_microsoft;
  452. menu_key_edit_paste_microsoft = 'Ctrl+V';
  453. menu_key_edit_clear = 'Ctrl+Del';
  454. menu_key_common_helpindex = 'Shift+F1';
  455. menu_key_common_topicsearch = 'Ctrl+F1';
  456. menu_key_common_prevtopic = 'Alt+F1';
  457. menu_key_help_helpindex= menu_key_common_helpindex;
  458. menu_key_help_topicsearch = menu_key_common_topicsearch;
  459. menu_key_help_prevtopic= menu_key_common_prevtopic;
  460. menu_key_hlplocal_index = menu_key_common_helpindex;
  461. menu_key_hlplocal_topicsearch = menu_key_common_topicsearch;
  462. menu_key_hlplocal_prevtopic = menu_key_common_prevtopic;
  463. menu_key_hlplocal_copy_borland = menu_key_common_copy_borland;
  464. menu_key_hlplocal_copy_microsoft = menu_key_common_copy_microsoft;
  465. {Configurable keys.}
  466. const menu_key_edit_cut:string[63]=menu_key_edit_cut_borland;
  467. menu_key_edit_copy:string[63]=menu_key_edit_copy_borland;
  468. menu_key_edit_paste:string[63]=menu_key_edit_paste_borland;
  469. menu_key_hlplocal_copy:string[63]=menu_key_hlplocal_copy_borland;
  470. cut_key:word=kbShiftDel;
  471. copy_key:word=kbCtrlIns;
  472. paste_key:word=kbShiftIns;
  473. procedure RegisterFPViews;
  474. implementation
  475. uses
  476. Video,Strings,Keyboard,Validate,
  477. globtype,Tokens,Version,
  478. systems,cpubase,
  479. {$if defined(I386) or defined(x64_86)}
  480. rax86,
  481. {$endif}
  482. {$ifdef USE_EXTERNAL_COMPILER}
  483. fpintf, { superseeds version_string of version unit }
  484. {$endif USE_EXTERNAL_COMPILER}
  485. {$ifndef NODEBUG}
  486. gdbint,
  487. {$endif NODEBUG}
  488. {$ifdef VESA}Vesa,{$endif}
  489. FPSwitch,FPSymbol,FPDebug,FPVars,FPUtils,FPCompil,FPHelp,
  490. FPTools,FPIDE,FPCodTmp,FPCodCmp;
  491. const
  492. RSourceEditor: TStreamRec = (
  493. ObjType: 1500;
  494. VmtLink: Ofs(TypeOf(TSourceEditor)^);
  495. Load: @TSourceEditor.Load;
  496. Store: @TSourceEditor.Store
  497. );
  498. RSourceWindow: TStreamRec = (
  499. ObjType: 1501;
  500. VmtLink: Ofs(TypeOf(TSourceWindow)^);
  501. Load: @TSourceWindow.Load;
  502. Store: @TSourceWindow.Store
  503. );
  504. RFPHelpViewer: TStreamRec = (
  505. ObjType: 1502;
  506. VmtLink: Ofs(TypeOf(TFPHelpViewer)^);
  507. Load: @TFPHelpViewer.Load;
  508. Store: @TFPHelpViewer.Store
  509. );
  510. RFPHelpWindow: TStreamRec = (
  511. ObjType: 1503;
  512. VmtLink: Ofs(TypeOf(TFPHelpWindow)^);
  513. Load: @TFPHelpWindow.Load;
  514. Store: @TFPHelpWindow.Store
  515. );
  516. RClipboardWindow: TStreamRec = (
  517. ObjType: 1504;
  518. VmtLink: Ofs(TypeOf(TClipboardWindow)^);
  519. Load: @TClipboardWindow.Load;
  520. Store: @TClipboardWindow.Store
  521. );
  522. RMessageListBox: TStreamRec = (
  523. ObjType: 1505;
  524. VmtLink: Ofs(TypeOf(TMessageListBox)^);
  525. Load: @TMessageListBox.Load;
  526. Store: @TMessageListBox.Store
  527. );
  528. RFPDesktop: TStreamRec = (
  529. ObjType: 1506;
  530. VmtLink: Ofs(TypeOf(TFPDesktop)^);
  531. Load: @TFPDesktop.Load;
  532. Store: @TFPDesktop.Store
  533. );
  534. RFPASCIIChart: TStreamRec = (
  535. ObjType: 1509;
  536. VmtLink: Ofs(TypeOf(TFPASCIIChart)^);
  537. Load: @TFPASCIIChart.Load;
  538. Store: @TFPASCIIChart.Store
  539. );
  540. RFPDlgWindow: TStreamRec = (
  541. ObjType: 1511;
  542. VmtLink: Ofs(TypeOf(TFPDlgWindow)^);
  543. Load: @TFPDlgWindow.Load;
  544. Store: @TFPDlgWindow.Store
  545. );
  546. {$ifndef NODEBUG}
  547. RGDBWindow: TStreamRec = (
  548. ObjType: 1508;
  549. VmtLink: Ofs(TypeOf(TGDBWindow)^);
  550. Load: @TGDBWindow.Load;
  551. Store: @TGDBWindow.Store
  552. );
  553. RGDBSourceEditor: TStreamRec = (
  554. ObjType: 1507;
  555. VmtLink: Ofs(TypeOf(TGDBSourceEditor)^);
  556. Load: @TGDBSourceEditor.Load;
  557. Store: @TGDBSourceEditor.Store
  558. );
  559. RDisassemblyEditor: TStreamRec = (
  560. ObjType: 1512;
  561. VmtLink: Ofs(TypeOf(TDisassemblyEditor)^);
  562. Load: @TDisassemblyEditor.Load;
  563. Store: @TDisassemblyEditor.Store
  564. );
  565. RDisassemblyWindow: TStreamRec = (
  566. ObjType: 1513;
  567. VmtLink: Ofs(TypeOf(TDisassemblyWindow)^);
  568. Load: @TDisassemblyWindow.Load;
  569. Store: @TDisassemblyWindow.Store
  570. );
  571. {$endif NODEBUG}
  572. const
  573. GlobalNoNameCount : integer = 0;
  574. var
  575. ReservedWords : array[1..ReservedWordMaxLen] of PStringCollection;
  576. AsmReservedWords : array[1..ReservedWordMaxLen] of PStringCollection;
  577. {$ifdef useresstrings}
  578. resourcestring
  579. {$else}
  580. const
  581. {$endif}
  582. { Source editor local menu items }
  583. menu_srclocal_openfileatcursor = 'Open ~f~ile at cursor';
  584. menu_srclocal_browseatcursor = '~B~rowse symbol at cursor';
  585. menu_srclocal_topicsearch = 'Topic ~s~earch';
  586. menu_srclocal_options = '~O~ptions...';
  587. menu_srclocal_reload = '~R~eload modified file';
  588. { Help viewer local menu items }
  589. menu_hlplocal_debug = 'Debug infos';
  590. menu_hlplocal_contents = '~C~ontents';
  591. menu_hlplocal_index = '~I~ndex';
  592. menu_hlplocal_topicsearch = '~T~opic search';
  593. menu_hlplocal_prevtopic = '~P~revious topic';
  594. menu_hlplocal_copy = '~C~opy';
  595. { Messages local menu items }
  596. menu_msglocal_clear = '~C~lear';
  597. menu_msglocal_gotosource = '~G~oto source';
  598. menu_msglocal_tracksource = '~T~rack source';
  599. menu_edit_cut = 'Cu~t~';
  600. menu_edit_copy = '~C~opy';
  601. menu_edit_paste = '~P~aste';
  602. menu_edit_clear = 'C~l~ear';
  603. msg_errorreadingfile = 'Error reading file %s';
  604. msg_loadingfile = 'Loading %s';
  605. msg_storingfile = 'Storing %s';
  606. msg_closingfile = 'Closing %s';
  607. dialog_gdbwindow = 'GDB window';
  608. dialog_disaswindow = 'Disassembly window';
  609. dialog_clipboard = 'Clipboard';
  610. dialog_userscreen = 'User screen';
  611. dialog_about = 'About';
  612. label_about_compilerversion = 'Compiler Version';
  613. label_about_debugger = 'Debugger';
  614. menu_msglocal_saveas = 'Save ~a~s';
  615. msg_openingsourcefile = 'Opening source file... (%s)';
  616. msg_readingfileineditor = 'Reading %s into editor...';
  617. msg_nodebuggersupportavailable = 'No debugger support available.';
  618. {****************************************************************************
  619. TStoreCollection
  620. ****************************************************************************}
  621. function TStoreCollection.Add(const S: string): PString;
  622. var P: PString;
  623. Index: Sw_integer;
  624. begin
  625. if S='' then P:=nil else
  626. if Search(@S,Index) then P:=At(Index) else
  627. begin
  628. P:=NewStr(S);
  629. Insert(P);
  630. end;
  631. Add:=P;
  632. end;
  633. function IsThereAnyEditor: boolean;
  634. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  635. begin
  636. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  637. end;
  638. begin
  639. IsThereAnyEditor:=Desktop^.FirstThat(@EditorWindow)<>nil;
  640. end;
  641. procedure AskToReloadAllModifiedFiles;
  642. procedure EditorWindowModifiedOnDisk(P: PView); {$ifndef FPC}far;{$endif}
  643. begin
  644. if (P^.HelpCtx=hcSourceWindow) then
  645. PSourceWindow(P)^.Editor^.ReloadFile;
  646. end;
  647. begin
  648. Desktop^.ForEach(@EditorWindowModifiedOnDisk);
  649. end;
  650. function IsThereAnyHelpWindow: boolean;
  651. begin
  652. IsThereAnyHelpWindow:=(HelpWindow<>nil) and (HelpWindow^.GetState(sfVisible));
  653. end;
  654. function IsThereAnyNumberedWindow: boolean;
  655. var _Is: boolean;
  656. begin
  657. _Is:=Message(Desktop,evBroadcast,cmSearchWindow,nil)<>nil;
  658. _Is:=_Is or ( (ClipboardWindow<>nil) and ClipboardWindow^.GetState(sfVisible));
  659. IsThereAnyNumberedWindow:=_Is;
  660. end;
  661. function IsWindow(P: PView): boolean;
  662. var OK: boolean;
  663. begin
  664. OK:=false;
  665. if (P^.HelpCtx=hcSourceWindow) or
  666. (P^.HelpCtx=hcHelpWindow) or
  667. (P^.HelpCtx=hcClipboardWindow) or
  668. (P^.HelpCtx=hcCalcWindow) or
  669. (P^.HelpCtx=hcInfoWindow) or
  670. (P^.HelpCtx=hcBrowserWindow) or
  671. (P^.HelpCtx=hcMessagesWindow) or
  672. (P^.HelpCtx=hcCompilerMessagesWindow) or
  673. (P^.HelpCtx=hcGDBWindow) or
  674. (P^.HelpCtx=hcdisassemblyWindow) or
  675. (P^.HelpCtx=hcWatchesWindow) or
  676. (P^.HelpCtx=hcRegistersWindow) or
  677. (P^.HelpCtx=hcFPURegisters) or
  678. (P^.HelpCtx=hcVectorRegisters) or
  679. (P^.HelpCtx=hcStackWindow) or
  680. (P^.HelpCtx=hcBreakpointListWindow) or
  681. (P^.HelpCtx=hcASCIITableWindow)
  682. then
  683. OK:=true;
  684. IsWindow:=OK;
  685. end;
  686. function IsThereAnyWindow: boolean;
  687. function CheckIt(P: PView): boolean; {$ifndef FPC}far;{$endif}
  688. begin
  689. CheckIt:=IsWindow(P);
  690. end;
  691. begin
  692. IsThereAnyWindow:=Desktop^.FirstThat(@CheckIt)<>nil;
  693. end;
  694. function IsThereAnyVisibleWindow: boolean;
  695. function CheckIt(P: PView): boolean; {$ifndef FPC}far;{$endif}
  696. begin
  697. CheckIt:=IsWindow(P) and P^.GetState(sfVisible);
  698. end;
  699. begin
  700. IsThereAnyVisibleWindow:=Desktop^.FirstThat(@CheckIt)<>nil;
  701. end;
  702. function FirstEditorWindow: PSourceWindow;
  703. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  704. begin
  705. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  706. end;
  707. begin
  708. FirstEditorWindow:=pointer(Desktop^.FirstThat(@EditorWindow));
  709. end;
  710. function EditorWindowFile(const Name : String): PSourceWindow;
  711. var
  712. SName : string;
  713. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  714. begin
  715. EditorWindow:=(TypeOf(P^)=TypeOf(TSourceWindow)) and
  716. (FixFileName(PSourceWindow(P)^.Editor^.FileName)=SName);
  717. end;
  718. begin
  719. SName:=FixFileName(FExpand(Name));
  720. EditorWindowFile:=pointer(Desktop^.FirstThat(@EditorWindow));
  721. end;
  722. {$ifndef NODEBUG}
  723. function InDisassemblyWindow :boolean;
  724. var
  725. PW : PWindow;
  726. function CheckIt(P: PView): boolean; {$ifndef FPC}far;{$endif}
  727. begin
  728. CheckIt:=IsWindow(P) and P^.GetState(sfVisible) and
  729. (P^.HelpCtx <> hcWatchesWindow) and
  730. (P^.HelpCtx <> hcStackWindow) and
  731. (P^.HelpCtx <> hcRegistersWindow) and
  732. (P^.HelpCtx <> hcVectorRegisters) and
  733. (P^.HelpCtx <> hcFPURegisters);
  734. end;
  735. begin
  736. PW:=PWindow(Desktop^.FirstThat(@CheckIt));
  737. InDisassemblyWindow:=Assigned(PW) and
  738. (TypeOf(PW^)=TypeOf(TDisassemblyWindow));
  739. end;
  740. {$endif NODEBUG}
  741. function GetEditorCurWord(Editor: PEditor; ValidSpecChars: TCharSet): string;
  742. var S: string;
  743. PS,PE: byte;
  744. function Trim(S: string): string;
  745. const TrimChars : set of char = [#0,#9,' ',#255];
  746. begin
  747. while (length(S)>0) and (S[1] in TrimChars) do Delete(S,1,1);
  748. while (length(S)>0) and (S[length(S)] in TrimChars) do Delete(S,length(S),1);
  749. Trim:=S;
  750. end;
  751. const AlphaNum : set of char = ['A'..'Z','0'..'9','_'];
  752. begin
  753. with Editor^ do
  754. begin
  755. S:=GetDisplayText(CurPos.Y);
  756. PS:=CurPos.X; while (PS>0) and (Upcase(S[PS]) in AlphaNum) do Dec(PS);
  757. PE:=CurPos.X; while (PE<length(S)) and (Upcase(S[PE+1]) in (AlphaNum+ValidSpecChars)) do Inc(PE);
  758. S:=Trim(copy(S,PS+1,PE-PS));
  759. end;
  760. GetEditorCurWord:=S;
  761. end;
  762. {*****************************************************************************
  763. Tab
  764. *****************************************************************************}
  765. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  766. var P: PTabItem;
  767. begin
  768. New(P); FillChar(P^,SizeOf(P^),0);
  769. P^.Next:=ANext; P^.View:=AView;
  770. NewTabItem:=P;
  771. end;
  772. procedure DisposeTabItem(P: PTabItem);
  773. begin
  774. if P<>nil then
  775. begin
  776. if P^.View<>nil then Dispose(P^.View, Done);
  777. Dispose(P);
  778. end;
  779. end;
  780. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  781. var P: PTabDef;
  782. x: byte;
  783. begin
  784. New(P);
  785. P^.Next:=ANext; P^.Name:=NewStr(AName); P^.Items:=AItems;
  786. x:=pos('~',AName);
  787. if (x<>0) and (x<length(AName)) then P^.ShortCut:=Upcase(AName[x+1])
  788. else P^.ShortCut:=#0;
  789. P^.DefItem:=ADefItem;
  790. NewTabDef:=P;
  791. end;
  792. procedure DisposeTabDef(P: PTabDef);
  793. var PI,X: PTabItem;
  794. begin
  795. DisposeStr(P^.Name);
  796. PI:=P^.Items;
  797. while PI<>nil do
  798. begin
  799. X:=PI^.Next;
  800. DisposeTabItem(PI);
  801. PI:=X;
  802. end;
  803. Dispose(P);
  804. end;
  805. {*****************************************************************************
  806. Reserved Words
  807. *****************************************************************************}
  808. function GetReservedWordCount: integer;
  809. var
  810. Count,I: integer;
  811. begin
  812. Count:=0;
  813. for I:=ord(Low(tToken)) to ord(High(tToken)) do
  814. with TokenInfo^[TToken(I)] do
  815. if (str<>'') and (str[1] in['A'..'Z']) and (length(str)>1) then
  816. Inc(Count);
  817. GetReservedWordCount:=Count;
  818. end;
  819. function GetReservedWord(Index: integer): string;
  820. var
  821. Count,Idx,I: integer;
  822. S: string;
  823. begin
  824. Idx:=-1;
  825. Count:=-1;
  826. I:=ord(Low(tToken));
  827. while (I<=ord(High(tToken))) and (Idx=-1) do
  828. with TokenInfo^[TToken(I)] do
  829. begin
  830. if (str<>'') and (str[1] in['A'..'Z']) and (length(str)>1) then
  831. begin
  832. Inc(Count);
  833. if Count=Index then
  834. Idx:=I;
  835. end;
  836. Inc(I);
  837. end;
  838. if Idx=-1 then
  839. S:=''
  840. else
  841. S:=TokenInfo^[TToken(Idx)].str;
  842. GetReservedWord:=S;
  843. end;
  844. function GetAsmReservedWordCount: integer;
  845. begin
  846. GetAsmReservedWordCount:=ord(lastop) - ord(firstop)
  847. {$ifndef x86_64}
  848. {$ifndef powerpc}
  849. {$ifndef powerpc64}
  850. {$ifndef arm}
  851. + CondAsmOps*(ord(high(TasmCond))-ord(low(TasmCond)));
  852. {$else arm}
  853. { the arm has an incredible amount of combinations of opcodes,
  854. we've to solve this different }
  855. ;
  856. {$endif arm}
  857. {$else powerpc64}
  858. + CondAsmOps*(ord(high(TAsmCondFlag))-ord(low(TAsmCondFlag)));
  859. {$endif powerpc64}
  860. {$else powerpc}
  861. + CondAsmOps*(ord(high(TAsmCondFlag))-ord(low(TAsmCondFlag)));
  862. {$endif powerpc}
  863. {$endif x86_64}
  864. end;
  865. function GetAsmReservedWord(Index: integer): string;
  866. var
  867. CondNum,CondOpNum : integer;
  868. begin
  869. {$ifdef I386}
  870. if index <= ord(lastop) - ord(firstop) then
  871. GetAsmReservedWord:=std_op2str[tasmop(Index+ord(firstop))]
  872. else
  873. begin
  874. index:=index - (ord(lastop) - ord(firstop) );
  875. CondOpNum:= index div (ord(high(TasmCond))-ord(low(TasmCond)));
  876. CondNum:=index - (CondOpNum * (ord(high(TasmCond))-ord(low(TasmCond))));
  877. GetAsmReservedWord:=CondAsmOpStr[CondOpNum]+cond2str[TasmCond(CondNum+ord(low(TAsmCond))+1)];
  878. end;
  879. {$else not I386}
  880. {$ifdef m68k}
  881. if index <= ord(lastop) - ord(firstop) then
  882. GetAsmReservedWord:=mot_op2str[tasmop(Index+ord(firstop))]
  883. else
  884. begin
  885. index:=index - (ord(lastop) - ord(firstop) );
  886. CondOpNum:= index div (ord(high(TasmCond))-ord(low(TasmCond)));
  887. CondNum:=index - (CondOpNum * (ord(high(TasmCond))-ord(low(TasmCond))));
  888. GetAsmReservedWord:=CondAsmOpStr[CondOpNum]+cond2str[TasmCond(CondNum+ord(low(TAsmCond))+1)];
  889. end;
  890. {$else not m68k}
  891. GetAsmReservedWord:='';
  892. {$endif m68k}
  893. {$endif I386}
  894. end;
  895. procedure InitReservedWords;
  896. var WordS: string;
  897. Idx,I,J : sw_integer;
  898. begin
  899. InitTokens;
  900. for I:=Low(ReservedWords) to High(ReservedWords) do
  901. New(ReservedWords[I], Init(50,10));
  902. for I:=1 to GetReservedWordCount do
  903. begin
  904. WordS:=GetReservedWord(I-1); Idx:=length(WordS);
  905. if (Idx>=Low(ReservedWords)) and (Idx<=High(ReservedWords)) then
  906. ReservedWords[Idx]^.Insert(NewStr(WordS));
  907. end;
  908. for I:=Low(AsmReservedWords) to High(AsmReservedWords) do
  909. New(AsmReservedWords[I], Init(50,10));
  910. for I:=1 to GetAsmReservedWordCount do
  911. begin
  912. WordS:=UpcaseStr(GetAsmReservedWord(I-1)); Idx:=length(WordS);
  913. if (Idx>=Low(AsmReservedWords)) and (Idx<=High(AsmReservedWords)) then
  914. begin
  915. if not AsmReservedWords[Idx]^.Search(@WordS, J) then
  916. AsmReservedWords[Idx]^.Insert(NewStr(WordS));
  917. end;
  918. end;
  919. end;
  920. procedure DoneReservedWords;
  921. var I: integer;
  922. begin
  923. for I:=Low(ReservedWords) to High(ReservedWords) do
  924. if assigned(ReservedWords[I]) then
  925. begin
  926. dispose(ReservedWords[I],done);
  927. ReservedWords[I]:=nil;
  928. end;
  929. for I:=Low(AsmReservedWords) to High(AsmReservedWords) do
  930. if assigned(AsmReservedWords[I]) then
  931. begin
  932. dispose(AsmReservedWords[I],done);
  933. ReservedWords[I]:=nil;
  934. end;
  935. DoneTokens;
  936. end;
  937. function IsFPReservedWord(const S: string): boolean;
  938. var _Is: boolean;
  939. Idx,Item: sw_integer;
  940. UpS: string;
  941. begin
  942. Idx:=length(S); _Is:=false;
  943. if (Low(ReservedWords)<=Idx) and (Idx<=High(ReservedWords)) and
  944. (ReservedWords[Idx]<>nil) and (ReservedWords[Idx]^.Count<>0) then
  945. begin
  946. UpS:=UpcaseStr(S);
  947. _Is:=ReservedWords[Idx]^.Search(@UpS,Item);
  948. end;
  949. IsFPReservedWord:=_Is;
  950. end;
  951. function IsFPAsmReservedWord(S: string): boolean;
  952. var _Is: boolean;
  953. Idx,Item,Len: sw_integer;
  954. LastC : Char;
  955. LastTwo : String[2];
  956. begin
  957. Idx:=length(S); _Is:=false;
  958. if (Low(AsmReservedWords)<=Idx) and (Idx<=High(AsmReservedWords)) and
  959. (AsmReservedWords[Idx]<>nil) and (AsmReservedWords[Idx]^.Count<>0) then
  960. begin
  961. S:=UpcaseStr(S);
  962. _Is:=AsmReservedWords[Idx]^.Search(@S,Item);
  963. {$ifdef i386}
  964. if not _Is and (Length(S)>1) then
  965. begin
  966. LastC:=S[Length(S)];
  967. if LastC in ['B','D','L','Q','S','T','V','W'] then
  968. begin
  969. Delete(S,Length(S),1);
  970. Dec(Idx);
  971. if (AsmReservedWords[Idx]<>nil) and (AsmReservedWords[Idx]^.Count<>0) then
  972. _Is:=AsmReservedWords[Idx]^.Search(@S,Item);
  973. if not _Is and (Length(S)>1) then
  974. begin
  975. LastTwo:=S[Length(S)]+LastC;
  976. if (LastTwo='BL') or
  977. (LastTwo='WL') or
  978. (LastTwo='BW') then
  979. begin
  980. Delete(S,Length(S),1);
  981. Dec(Idx);
  982. if (AsmReservedWords[Idx]<>nil) and (AsmReservedWords[Idx]^.Count<>0) then
  983. _Is:=AsmReservedWords[Idx]^.Search(@S,Item);
  984. end;
  985. end;
  986. end;
  987. end;
  988. {$endif i386}
  989. end;
  990. IsFPAsmReservedWord:=_Is;
  991. end;
  992. {*****************************************************************************
  993. SearchWindow
  994. *****************************************************************************}
  995. function SearchWindowWithNo(No: integer): PWindow;
  996. var P: PWindow;
  997. begin
  998. P:=Message(Desktop,evBroadcast,cmSearchWindow+No,nil);
  999. if pointer(P)=pointer(Desktop) then P:=nil;
  1000. SearchWindowWithNo:=P;
  1001. end;
  1002. function SearchWindow(const Title: string): PWindow;
  1003. function Match(P: PView): boolean; {$ifndef FPC}far;{$endif}
  1004. var W: PWindow;
  1005. OK: boolean;
  1006. begin
  1007. W:=nil;
  1008. { we have a crash here because of the TStatusLine
  1009. that can also have one of these values
  1010. but is not a Window object PM }
  1011. if P<>pointer(StatusLine) then
  1012. if IsWindow(P) then
  1013. W:=PWindow(P);
  1014. OK:=(W<>nil);
  1015. if OK then
  1016. begin
  1017. OK:=CompareText(W^.GetTitle(255),Title)=0;
  1018. end;
  1019. Match:=OK;
  1020. end;
  1021. var W: PView;
  1022. begin
  1023. W:=Application^.FirstThat(@Match);
  1024. { This is wrong because TStatusLine is also considered PM }
  1025. if not Assigned(W) then W:=Desktop^.FirstThat(@Match);
  1026. { But why do we need to check all ??
  1027. Probably because of the ones which were not inserted into
  1028. Desktop as the Messages view
  1029. Exactly. Some windows are inserted directly in the Application and not
  1030. in the Desktop. btw. Does TStatusLine.HelpCtx really change? Why?
  1031. Only GetHelpCtx should return different values depending on the
  1032. focused view (and it's helpctx), but TStatusLine's HelpCtx field
  1033. shouldn't change... Gabor
  1034. if Assigned(W)=false then W:=Desktop^.FirstThat(@Match);}
  1035. SearchWindow:=PWindow(W);
  1036. end;
  1037. function SearchFreeWindowNo: integer;
  1038. var No: integer;
  1039. begin
  1040. No:=1;
  1041. while (No<100) and (SearchWindowWithNo(No)<>nil) do
  1042. Inc(No);
  1043. if No=100 then No:=0;
  1044. SearchFreeWindowNo:=No;
  1045. end;
  1046. {*****************************************************************************
  1047. TIntegerLine
  1048. *****************************************************************************}
  1049. constructor TIntegerLine.Init(var Bounds: TRect; AMin, AMax: longint);
  1050. begin
  1051. if inherited Init(Bounds, Bounds.B.X-Bounds.A.X-1)=false then
  1052. Fail;
  1053. Validator:=New(PRangeValidator, Init(AMin, AMax));
  1054. end;
  1055. {*****************************************************************************
  1056. SourceEditor
  1057. *****************************************************************************}
  1058. function SearchCoreForFileName(AFileName: string): PCodeEditorCore;
  1059. var EC: PCodeEditorCore;
  1060. function Check(P: PView): boolean; {$ifndef FPC}far;{$endif}
  1061. var OK: boolean;
  1062. begin
  1063. OK:=P^.HelpCtx=hcSourceWindow;
  1064. if OK then
  1065. with PSourceWindow(P)^ do
  1066. if FixFileName(Editor^.FileName)=AFileName then
  1067. begin
  1068. EC:=Editor^.Core;
  1069. OK:=true;
  1070. end
  1071. else
  1072. OK:=false;
  1073. Check:=OK;
  1074. end;
  1075. begin
  1076. EC:=nil;
  1077. AFileName:=FixFileName(AFileName);
  1078. { do not use the same core for all new files }
  1079. if AFileName<>'' then
  1080. Desktop^.FirstThat(@Check);
  1081. SearchCoreForFileName:=EC;
  1082. end;
  1083. constructor TSourceEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  1084. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  1085. var EC: PCodeEditorCore;
  1086. begin
  1087. EC:=SearchCoreForFileName(AFileName);
  1088. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,EC,AFileName);
  1089. SetStoreUndo(true);
  1090. CompileStamp:=0;
  1091. end;
  1092. Const
  1093. FreePascalSpecSymbolCount : array [TSpecSymbolClass] of integer =
  1094. (
  1095. 3,{ssCommentPrefix}
  1096. 1,{ssCommentSingleLinePrefix}
  1097. 2,{ssCommentSuffix}
  1098. 1,{ssStringPrefix}
  1099. 1,{ssStringSuffix}
  1100. 1,{ssDirectivePrefix}
  1101. 1,{ssDirectiveSuffix}
  1102. 1,{ssAsmPrefix}
  1103. 1 {ssAsmSuffix}
  1104. );
  1105. FreePascalEmptyString : string[1] = '';
  1106. FreePascalCommentPrefix1 : string[1] = '{';
  1107. FreePascalCommentPrefix2 : string[2] = '(*';
  1108. FreePascalCommentPrefix3 : string[2] = '//';
  1109. FreePascalCommentSingleLinePrefix : string[2] = '//';
  1110. FreePascalCommentSuffix1 : string[1] = '}';
  1111. FreePascalCommentSuffix2 : string[2] = '*)';
  1112. FreePascalStringPrefix : string[1] = '''';
  1113. FreePascalStringSuffix : string[1] = '''';
  1114. FreePascalDirectivePrefix : string[2] = '{$';
  1115. FreePascalDirectiveSuffix : string[1] = '}';
  1116. FreePascalAsmPrefix : string[3] = 'ASM';
  1117. FreePascalAsmSuffix : string[3] = 'END';
  1118. function TSourceEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  1119. begin
  1120. GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
  1121. end;
  1122. function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  1123. begin
  1124. GetSpecSymbol:=@FreePascalEmptyString;
  1125. case SpecClass of
  1126. ssCommentPrefix :
  1127. case Index of
  1128. 0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
  1129. 1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
  1130. 2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
  1131. end;
  1132. ssCommentSingleLinePrefix :
  1133. case Index of
  1134. 0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
  1135. end;
  1136. ssCommentSuffix :
  1137. case Index of
  1138. 0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
  1139. 1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
  1140. end;
  1141. ssStringPrefix :
  1142. GetSpecSymbol:=@FreePascalStringPrefix;
  1143. ssStringSuffix :
  1144. GetSpecSymbol:=@FreePascalStringSuffix;
  1145. { must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
  1146. ssAsmPrefix :
  1147. GetSpecSymbol:=@FreePascalAsmPrefix;
  1148. ssAsmSuffix :
  1149. GetSpecSymbol:=@FreePascalAsmSuffix;
  1150. ssDirectivePrefix :
  1151. GetSpecSymbol:=@FreePascalDirectivePrefix;
  1152. ssDirectiveSuffix :
  1153. GetSpecSymbol:=@FreePascalDirectiveSuffix;
  1154. end;
  1155. end;
  1156. function TSourceEditor.IsReservedWord(const S: string): boolean;
  1157. begin
  1158. IsReservedWord:=IsFPReservedWord(S);
  1159. end;
  1160. function TSourceEditor.IsAsmReservedWord(const S: string): boolean;
  1161. begin
  1162. IsAsmReservedWord:=IsFPAsmReservedWord(S);
  1163. end;
  1164. function TSourceEditor.TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean;
  1165. begin
  1166. TranslateCodeTemplate:=FPTranslateCodeTemplate(ShortCut,ALines);
  1167. end;
  1168. function TSourceEditor.SelectCodeTemplate(var ShortCut: string): boolean;
  1169. var D: PCodeTemplatesDialog;
  1170. OK: boolean;
  1171. begin
  1172. New(D, Init(true,ShortCut));
  1173. OK:=Desktop^.ExecView(D)=cmOK;
  1174. if OK then ShortCut:=D^.GetSelectedShortCut;
  1175. Dispose(D, Done);
  1176. SelectCodeTemplate:=OK;
  1177. end;
  1178. function TSourceEditor.CompleteCodeWord(const WordS: string; var Text: string): boolean;
  1179. begin
  1180. CompleteCodeWord:=FPCompleteCodeWord(WordS,Text);
  1181. end;
  1182. procedure TSourceEditor.FindMatchingDelimiter(ScanForward: boolean);
  1183. var
  1184. St,nextResWord : String;
  1185. LineText,LineAttr: string;
  1186. Res,found,addit : boolean;
  1187. JumpPos: TPoint;
  1188. X,Y,lexchange,curlevel,linecount : sw_integer;
  1189. function GetLexChange(const S : string) : sw_integer;
  1190. begin
  1191. if (S='END') or (S='THEN') or (S='UNTIL') then
  1192. GetLexChange:=-1
  1193. else if (S='ASM') or (S='BEGIN') or (S='CASE') or (S='CLASS') or
  1194. (S='IF') or (S='OBJECT') or (S='RECORD') or (S='REPEAT') then
  1195. GetLexChange:=+1
  1196. else
  1197. GetLexChange:=0;
  1198. end;
  1199. begin
  1200. st:=UpcaseStr(GetCurrentWord);
  1201. if st<>'' then
  1202. Res:=IsReservedWord(St)
  1203. else
  1204. Res:=false;
  1205. LexChange:=GetLexChange(St);
  1206. if not res or (LexChange=0) or not
  1207. IsFlagSet(efSyntaxHighlight) then
  1208. Inherited FindMatchingDelimiter(ScanForward)
  1209. else
  1210. begin
  1211. JumpPos.X:=-1; JumpPos.Y:=-1;
  1212. Y:=CurPos.Y; X:=CurPos.X;
  1213. found:=false;
  1214. LineCount:=0;
  1215. curlevel:=lexchange;
  1216. if LexChange>0 then
  1217. begin
  1218. repeat
  1219. Inc(LineCount);
  1220. NextResWord:='';
  1221. GetDisplayTextFormat(Y,LineText,LineAttr);
  1222. if LineCount<>1 then X:=-1
  1223. else if ord(LineAttr[X+1])<>coReservedWordColor then
  1224. exit;
  1225. repeat
  1226. Inc(X);
  1227. if X<length(LineText) then
  1228. begin
  1229. AddIt:=ord(LineAttr[X+1])=coReservedWordColor;
  1230. if AddIt then
  1231. NextResWord:=NextResWord+UpCase(LineText[X+1]);
  1232. end;
  1233. if ((X=length(LineText)) or (Not AddIt)) and
  1234. (NextResWord<>'') and
  1235. IsReservedWord(NextResWord) then
  1236. begin
  1237. LexChange:=GetLexChange(NextResWord);
  1238. CurLevel:=CurLevel+LexChange;
  1239. if CurLevel=0 then
  1240. begin
  1241. JumpPos.X:=X-Length(NextResWord);
  1242. JumpPos.Y:=Y;
  1243. end;
  1244. NextResWord:='';
  1245. end;
  1246. until (X>=length(LineText)) or (JumpPos.X<>-1);
  1247. Inc(Y);
  1248. until (Y>=GetLineCount) or (JumpPos.X<>-1);
  1249. if (Y=GetLineCount) and (JumpPos.X=-1) then
  1250. begin
  1251. ErrorBox('No match',nil);
  1252. exit;
  1253. end;
  1254. end
  1255. else if (LexChange<0) then
  1256. begin
  1257. repeat
  1258. Inc(LineCount);
  1259. NextResWord:='';
  1260. GetDisplayTextFormat(Y,LineText,LineAttr);
  1261. if LineCount<>1 then
  1262. X:=Length(LineText)
  1263. else if ord(LineAttr[X+1])<>coReservedWordColor then
  1264. exit;
  1265. repeat
  1266. Dec(X);
  1267. if X>=0 then
  1268. begin
  1269. AddIt:=ord(LineAttr[X+1])=coReservedWordColor;
  1270. if AddIt then
  1271. NextResWord:=UpCase(LineText[X+1])+NextResWord;
  1272. end;
  1273. if ((X=0) or (Not AddIt)) and
  1274. (NextResWord<>'') and
  1275. IsReservedWord(NextResWord) then
  1276. begin
  1277. LexChange:=GetLexChange(NextResWord);
  1278. CurLevel:=CurLevel+LexChange;
  1279. if CurLevel=0 then
  1280. begin
  1281. if AddIt then
  1282. JumpPos.X:=X
  1283. else
  1284. JumpPos.X:=X+1;
  1285. JumpPos.Y:=Y;
  1286. end;
  1287. NextResWord:='';
  1288. end;
  1289. until (X<=0) or (JumpPos.X<>-1);
  1290. Dec(Y);
  1291. until (Y<0) or (JumpPos.X<>-1);
  1292. if (Y<0) and (JumpPos.X=-1) then
  1293. begin
  1294. ErrorBox('No match',nil);
  1295. exit;
  1296. end;
  1297. end;
  1298. if JumpPos.X<>-1 then
  1299. begin
  1300. SetCurPtr(JumpPos.X,JumpPos.Y);
  1301. TrackCursor(do_centre);
  1302. end;
  1303. end;
  1304. end;
  1305. procedure TSourceEditor.SetCodeCompleteWord(const S: string);
  1306. var R: TRect;
  1307. begin
  1308. inherited SetCodeCompleteWord(S);
  1309. if S='' then
  1310. begin
  1311. if Assigned(CodeCompleteTip) then Dispose(CodeCompleteTip, Done);
  1312. CodeCompleteTip:=nil;
  1313. end
  1314. else
  1315. begin
  1316. R.Assign(0,0,20,1);
  1317. if Assigned(CodeCompleteTip)=false then
  1318. begin
  1319. New(CodeCompleteTip, Init(R, S, alCenter));
  1320. CodeCompleteTip^.Hide;
  1321. Application^.Insert(CodeCompleteTip);
  1322. end
  1323. else
  1324. CodeCompleteTip^.SetText(S);
  1325. AlignCodeCompleteTip;
  1326. end;
  1327. end;
  1328. procedure TSourceEditor.AlignCodeCompleteTip;
  1329. var P: TPoint;
  1330. S: string;
  1331. R: TRect;
  1332. begin
  1333. if Assigned(CodeCompleteTip)=false then Exit;
  1334. S:=CodeCompleteTip^.GetText;
  1335. P.Y:=CurPos.Y;
  1336. { determine the center of current word fragment }
  1337. P.X:=CurPos.X-(length(GetCodeCompleteFrag) div 2);
  1338. { calculate position for centering the complete word over/below the current }
  1339. P.X:=P.X-(length(S) div 2);
  1340. P.X:=P.X-Delta.X;
  1341. P.Y:=P.Y-Delta.Y;
  1342. MakeGlobal(P,P);
  1343. if Assigned(CodeCompleteTip^.Owner) then
  1344. CodeCompleteTip^.Owner^.MakeLocal(P,P);
  1345. { ensure that the tooltip stays in screen }
  1346. P.X:=Min(Max(0,P.X),ScreenWidth-length(S)-2-1);
  1347. { align it vertically }
  1348. if P.Y>round(ScreenHeight*3/4) then
  1349. Dec(P.Y)
  1350. else
  1351. Inc(P.Y);
  1352. R.Assign(P.X,P.Y,P.X+1+length(S)+1,P.Y+1);
  1353. CodeCompleteTip^.Locate(R);
  1354. if CodeCompleteTip^.GetState(sfVisible)=false then
  1355. CodeCompleteTip^.Show;
  1356. end;
  1357. procedure TSourceEditor.ModifiedChanged;
  1358. begin
  1359. inherited ModifiedChanged;
  1360. if (@Self<>Clipboard) and GetModified then
  1361. begin
  1362. { global flags }
  1363. EditorModified:=true;
  1364. { reset compile flags as the file is
  1365. not the same as at the compilation anymore }
  1366. CompileStamp:=-1;
  1367. end;
  1368. end;
  1369. procedure TSourceEditor.InsertOptions;
  1370. var C: PUnsortedStringCollection;
  1371. Y: sw_integer;
  1372. S: string;
  1373. begin
  1374. Lock;
  1375. New(C, Init(10,10));
  1376. GetCompilerOptionLines(C);
  1377. if C^.Count>0 then
  1378. begin
  1379. for Y:=0 to C^.Count-1 do
  1380. begin
  1381. S:=C^.At(Y)^;
  1382. InsertLine(Y,S);
  1383. end;
  1384. AdjustSelectionPos(0,0,0,C^.Count);
  1385. UpdateAttrs(0,attrAll);
  1386. DrawLines(0);
  1387. SetModified(true);
  1388. end;
  1389. Dispose(C, Done);
  1390. UnLock;
  1391. end;
  1392. procedure TSourceEditor.PushInfo(Const st : string);
  1393. begin
  1394. PushStatus(st);
  1395. end;
  1396. procedure TSourceEditor.PopInfo;
  1397. begin
  1398. PopStatus;
  1399. end;
  1400. procedure TSourceEditor.DeleteLine(I: sw_integer);
  1401. begin
  1402. inherited DeleteLine(I);
  1403. {$ifndef NODEBUG}
  1404. If ShouldHandleBreakpoints then
  1405. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-1);
  1406. {$endif NODEBUG}
  1407. end;
  1408. procedure TSourceEditor.BackSpace;
  1409. {$ifndef NODEBUG}
  1410. var
  1411. MoveBreakpointToPreviousLine,WasEnabled : boolean;
  1412. PBStart,PBEnd : PBreakpoint;
  1413. I : longint;
  1414. {$endif NODEBUG}
  1415. begin
  1416. {$ifdef NODEBUG}
  1417. inherited Backspace;
  1418. {$else}
  1419. MoveBreakpointToPreviousLine:=(CurPos.X=0) and (CurPos.Y>0);
  1420. If MoveBreakpointToPreviousLine then
  1421. begin
  1422. ShouldHandleBreakpoints:=false;
  1423. I:=CurPos.Y+1;
  1424. PBEnd:=BreakpointsCollection^.FindBreakpointAt(@Self,I);
  1425. PBStart:=BreakpointsCollection^.FindBreakpointAt(@Self,I-1);
  1426. end;
  1427. inherited Backspace;
  1428. if MoveBreakpointToPreviousLine then
  1429. begin
  1430. ShouldHandleBreakpoints:=true;
  1431. if assigned(PBEnd) then
  1432. begin
  1433. if assigned(PBStart) then
  1434. begin
  1435. if PBEnd^.state=bs_enabled then
  1436. PBStart^.state:=bs_enabled;
  1437. BreakpointsCollection^.Free(PBEnd);
  1438. end
  1439. else
  1440. begin
  1441. WasEnabled:=PBEnd^.state=bs_enabled;
  1442. if WasEnabled then
  1443. begin
  1444. PBEnd^.state:=bs_disabled;
  1445. PBEnd^.UpdateSource;
  1446. end;
  1447. PBEnd^.line:=I-1;
  1448. if WasEnabled then
  1449. begin
  1450. PBEnd^.state:=bs_enabled;
  1451. PBEnd^.UpdateSource;
  1452. end;
  1453. end;
  1454. end;
  1455. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-1);
  1456. end;
  1457. {$endif NODEBUG}
  1458. end;
  1459. function TSourceEditor.InsertNewLine : Sw_integer;
  1460. {$ifndef NODEBUG}
  1461. var
  1462. MoveBreakpointToNextLine : boolean;
  1463. I : longint;
  1464. {$endif NODEBUG}
  1465. begin
  1466. {$ifdef NODEBUG}
  1467. InsertNewLine:=inherited InsertNewLine;
  1468. {$else}
  1469. ShouldHandleBreakpoints:=false;
  1470. MoveBreakpointToNextLine:=Cursor.x<Length(RTrim(GetDisplayText(CurPos.Y)));
  1471. I:=CurPos.Y+1;
  1472. InsertNewLine:=inherited InsertNewLine;
  1473. if MoveBreakpointToNextLine then
  1474. BreakpointsCollection^.AdaptBreakpoints(@Self,I-1,1)
  1475. else
  1476. BreakpointsCollection^.AdaptBreakpoints(@Self,I,1);
  1477. ShouldHandleBreakpoints:=true;
  1478. {$endif NODEBUG}
  1479. end;
  1480. procedure TSourceEditor.DelChar;
  1481. var
  1482. S: string;
  1483. I,CI : sw_integer;
  1484. {$ifndef NODEBUG}
  1485. PBStart,PBEnd : PBreakpoint;
  1486. MoveBreakpointOneLineUp,WasEnabled : boolean;
  1487. {$endif NODEBUG}
  1488. begin
  1489. if IsReadOnly then Exit;
  1490. S:=GetLineText(CurPos.Y);
  1491. I:=CurPos.Y+1;
  1492. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  1493. {$ifndef NODEBUG}
  1494. if ((CI>length(S)) or (S='')) and (CurPos.Y<GetLineCount-1) then
  1495. begin
  1496. MoveBreakpointOneLineUp:=true;
  1497. ShouldHandleBreakpoints:=false;
  1498. PBEnd:=BreakpointsCollection^.FindBreakpointAt(@Self,I+1);
  1499. PBStart:=BreakpointsCollection^.FindBreakpointAt(@Self,I);
  1500. end
  1501. else
  1502. MoveBreakpointOneLineUp:=false;
  1503. {$endif NODEBUG}
  1504. Inherited DelChar;
  1505. {$ifndef NODEBUG}
  1506. if MoveBreakpointOneLineUp then
  1507. begin
  1508. ShouldHandleBreakpoints:=true;
  1509. if assigned(PBEnd) then
  1510. begin
  1511. if assigned(PBStart) then
  1512. begin
  1513. if PBEnd^.state=bs_enabled then
  1514. PBStart^.state:=bs_enabled;
  1515. BreakpointsCollection^.Free(PBEnd);
  1516. end
  1517. else
  1518. begin
  1519. WasEnabled:=PBEnd^.state=bs_enabled;
  1520. if WasEnabled then
  1521. begin
  1522. PBEnd^.state:=bs_disabled;
  1523. PBEnd^.UpdateSource;
  1524. end;
  1525. PBEnd^.line:=I;
  1526. if WasEnabled then
  1527. begin
  1528. PBEnd^.state:=bs_enabled;
  1529. PBEnd^.UpdateSource;
  1530. end;
  1531. end;
  1532. end;
  1533. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-1);
  1534. end;
  1535. {$endif NODEBUG}
  1536. end;
  1537. procedure TSourceEditor.DelSelect;
  1538. {$ifndef NODEBUG}
  1539. var
  1540. MoveBreakpointToFirstLine,WasEnabled : boolean;
  1541. PBStart,PBEnd : PBreakpoint;
  1542. I,J : longint;
  1543. {$endif NODEBUG}
  1544. begin
  1545. {$ifdef NODEBUG}
  1546. inherited DelSelect;
  1547. {$else}
  1548. ShouldHandleBreakpoints:=false;
  1549. J:=SelEnd.Y-SelStart.Y;
  1550. MoveBreakpointToFirstLine:=J>0;
  1551. PBEnd:=BreakpointsCollection^.FindBreakpointAt(@Self,SelEnd.Y);
  1552. PBStart:=BreakpointsCollection^.FindBreakpointAt(@Self,SelEnd.Y);
  1553. I:=SelStart.Y;
  1554. inherited DelSelect;
  1555. if MoveBreakpointToFirstLine and assigned(PBEnd) then
  1556. begin
  1557. If assigned(PBStart) then
  1558. begin
  1559. if PBEnd^.state=bs_enabled then
  1560. PBStart^.state:=bs_enabled;
  1561. BreakpointsCollection^.Free(PBEnd);
  1562. end
  1563. else
  1564. begin
  1565. WasEnabled:=PBEnd^.state=bs_enabled;
  1566. if WasEnabled then
  1567. begin
  1568. PBEnd^.state:=bs_disabled;
  1569. PBEnd^.UpdateSource;
  1570. end;
  1571. PBEnd^.line:=I;
  1572. if WasEnabled then
  1573. begin
  1574. PBEnd^.state:=bs_enabled;
  1575. PBEnd^.UpdateSource;
  1576. end;
  1577. end;
  1578. end;
  1579. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-J);
  1580. ShouldHandleBreakpoints:=true;
  1581. {$endif NODEBUG}
  1582. end;
  1583. function TSourceEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
  1584. begin
  1585. InsertLine := inherited InsertLine(LineNo,S);
  1586. {$ifndef NODEBUG}
  1587. If ShouldHandleBreakpoints then
  1588. BreakpointsCollection^.AdaptBreakpoints(@Self,LineNo,1);
  1589. {$endif NODEBUG}
  1590. end;
  1591. procedure TSourceEditor.AddLine(const S: string);
  1592. begin
  1593. inherited AddLine(S);
  1594. {$ifndef NODEBUG}
  1595. BreakpointsCollection^.AdaptBreakpoints(@Self,GetLineCount,1);
  1596. {$endif NODEBUG}
  1597. end;
  1598. function TSourceEditor.GetLocalMenu: PMenu;
  1599. var M: PMenu;
  1600. MI: PMenuItem;
  1601. begin
  1602. MI:=
  1603. NewItem(menu_edit_cut,menu_key_edit_cut,cut_key,cmCut,hcCut,
  1604. NewItem(menu_edit_copy,menu_key_edit_copy,copy_key,cmCopy,hcCopy,
  1605. NewItem(menu_edit_paste,menu_key_edit_paste,paste_key,cmPaste,hcPaste,
  1606. NewItem(menu_edit_clear,menu_key_edit_clear,kbCtrlDel,cmClear,hcClear,
  1607. NewLine(
  1608. NewItem(menu_srclocal_openfileatcursor,'',kbNoKey,cmOpenAtCursor,hcOpenAtCursor,
  1609. NewItem(menu_srclocal_browseatcursor,'',kbNoKey,cmBrowseAtCursor,hcBrowseAtCursor,
  1610. NewItem(menu_srclocal_topicsearch,menu_key_help_topicsearch,kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  1611. NewLine(
  1612. NewItem(menu_srclocal_options,'',kbNoKey,cmEditorOptions,hcEditorOptions,
  1613. nil))))))))));
  1614. if IsChangedOnDisk then
  1615. MI:=NewItem(menu_srclocal_reload,'',kbNoKey,cmDoReload,hcDoReload,
  1616. MI);
  1617. M:=NewMenu(MI);
  1618. GetLocalMenu:=M;
  1619. end;
  1620. function TSourceEditor.GetCommandTarget: PView;
  1621. begin
  1622. GetCommandTarget:=@Self;
  1623. end;
  1624. function TSourceEditor.CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup;
  1625. var MV: PAdvancedMenuPopup;
  1626. begin
  1627. New(MV, Init(Bounds,M));
  1628. CreateLocalMenuView:=MV;
  1629. end;
  1630. {$ifdef DebugUndo}
  1631. procedure TSourceEditor.DumpUndo;
  1632. var
  1633. i : sw_integer;
  1634. begin
  1635. ClearToolMessages;
  1636. AddToolCommand('UndoList Dump');
  1637. for i:=0 to Core^.UndoList^.count-1 do
  1638. with Core^.UndoList^.At(i)^ do
  1639. begin
  1640. if is_grouped_action then
  1641. AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
  1642. else
  1643. AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
  1644. ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
  1645. end;
  1646. if Core^.RedoList^.count>0 then
  1647. AddToolCommand('RedoList Dump');
  1648. for i:=0 to Core^.RedoList^.count-1 do
  1649. with Core^.RedoList^.At(i)^ do
  1650. begin
  1651. if is_grouped_action then
  1652. AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
  1653. else
  1654. AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
  1655. ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
  1656. end;
  1657. UpdateToolMessages;
  1658. if Assigned(MessagesWindow) then
  1659. MessagesWindow^.Focus;
  1660. end;
  1661. procedure TSourceEditor.UndoAll;
  1662. begin
  1663. While Core^.UndoList^.count>0 do
  1664. Undo;
  1665. end;
  1666. procedure TSourceEditor.RedoAll;
  1667. begin
  1668. While Core^.RedoList^.count>0 do
  1669. Redo;
  1670. end;
  1671. {$endif DebugUndo}
  1672. function TSourceEditor.Valid(Command: Word): Boolean;
  1673. var OK: boolean;
  1674. begin
  1675. OK:=inherited Valid(Command);
  1676. if OK and ({(Command=cmClose) or already handled in TFileEditor.Valid PM }
  1677. (Command=cmAskSaveAll)) then
  1678. if IsClipboard=false then
  1679. OK:=SaveAsk(false);
  1680. Valid:=OK;
  1681. end;
  1682. procedure TSourceEditor.HandleEvent(var Event: TEvent);
  1683. var DontClear: boolean;
  1684. S: string;
  1685. begin
  1686. TranslateMouseClick(@Self,Event);
  1687. case Event.What of
  1688. evKeyDown :
  1689. begin
  1690. DontClear:=false;
  1691. case Event.KeyCode of
  1692. kbCtrlEnter :
  1693. Message(@Self,evCommand,cmOpenAtCursor,nil);
  1694. else DontClear:=true;
  1695. end;
  1696. if not DontClear then ClearEvent(Event);
  1697. end;
  1698. end;
  1699. inherited HandleEvent(Event);
  1700. case Event.What of
  1701. evBroadcast :
  1702. case Event.Command of
  1703. cmCalculatorPaste :
  1704. begin
  1705. InsertText(FloatToStr(CalcClipboard,0));
  1706. ClearEvent(Event);
  1707. end;
  1708. end;
  1709. evCommand :
  1710. begin
  1711. DontClear:=false;
  1712. case Event.Command of
  1713. {$ifdef DebugUndo}
  1714. cmDumpUndo : DumpUndo;
  1715. cmUndoAll : UndoAll;
  1716. cmRedoAll : RedoAll;
  1717. {$endif DebugUndo}
  1718. cmDoReload : ReloadFile;
  1719. cmBrowseAtCursor:
  1720. begin
  1721. S:=LowerCaseStr(GetEditorCurWord(@Self,[]));
  1722. OpenOneSymbolBrowser(S);
  1723. end;
  1724. cmOpenAtCursor :
  1725. begin
  1726. S:=LowerCaseStr(GetEditorCurWord(@Self,['.']));
  1727. if Pos('.',S)<>0 then
  1728. OpenFileName:=S else
  1729. OpenFileName:=S+'.pp'+ListSeparator+
  1730. S+'.pas'+ListSeparator+
  1731. S+'.inc';
  1732. Message(Application,evCommand,cmOpen,nil);
  1733. end;
  1734. cmEditorOptions :
  1735. Message(Application,evCommand,cmEditorOptions,@Self);
  1736. cmHelp :
  1737. Message(@Self,evCommand,cmHelpTopicSearch,@Self);
  1738. cmHelpTopicSearch :
  1739. HelpTopicSearch(@Self);
  1740. else DontClear:=true;
  1741. end;
  1742. if not DontClear then ClearEvent(Event);
  1743. end;
  1744. end;
  1745. end;
  1746. constructor TFPHeapView.Init(var Bounds: TRect);
  1747. begin
  1748. if inherited Init(Bounds)=false then Fail;
  1749. Options:=Options or gfGrowHiX or gfGrowHiY;
  1750. EventMask:=EventMask or evIdle;
  1751. GrowMode:=gfGrowAll;
  1752. end;
  1753. constructor TFPHeapView.InitKb(var Bounds: TRect);
  1754. begin
  1755. if inherited InitKb(Bounds)=false then Fail;
  1756. Options:=Options or gfGrowHiX or gfGrowHiY;
  1757. EventMask:=EventMask or evIdle;
  1758. GrowMode:=gfGrowAll;
  1759. end;
  1760. procedure TFPHeapView.HandleEvent(var Event: TEvent);
  1761. begin
  1762. case Event.What of
  1763. evIdle :
  1764. Update;
  1765. end;
  1766. inherited HandleEvent(Event);
  1767. end;
  1768. constructor TFPClockView.Init(var Bounds: TRect);
  1769. begin
  1770. inherited Init(Bounds);
  1771. EventMask:=EventMask or evIdle;
  1772. end;
  1773. procedure TFPClockView.HandleEvent(var Event: TEvent);
  1774. begin
  1775. case Event.What of
  1776. evIdle :
  1777. Update;
  1778. end;
  1779. inherited HandleEvent(Event);
  1780. end;
  1781. function TFPClockView.GetPalette: PPalette;
  1782. const P: string[length(CFPClockView)] = CFPClockView;
  1783. begin
  1784. GetPalette:=@P;
  1785. end;
  1786. procedure TFPWindow.SetState(AState: Word; Enable: Boolean);
  1787. var OldState: word;
  1788. begin
  1789. OldState:=State;
  1790. inherited SetState(AState,Enable);
  1791. if AutoNumber then
  1792. if (AState and (sfVisible+sfExposed))<>0 then
  1793. if GetState(sfVisible+sfExposed) then
  1794. begin
  1795. if Number=0 then
  1796. Number:=SearchFreeWindowNo;
  1797. ReDraw;
  1798. end
  1799. else
  1800. Number:=0;
  1801. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  1802. UpdateCommands;
  1803. end;
  1804. procedure TFPWindow.UpdateCommands;
  1805. begin
  1806. end;
  1807. procedure TFPWindow.Update;
  1808. begin
  1809. ReDraw;
  1810. end;
  1811. procedure TFPWindow.SelectInDebugSession;
  1812. var
  1813. F,PrevCurrent : PView;
  1814. begin
  1815. DeskTop^.Lock;
  1816. PrevCurrent:=Desktop^.Current;
  1817. F:=PrevCurrent;
  1818. While assigned(F) and
  1819. ((F^.HelpCtx = hcGDBWindow) or
  1820. (F^.HelpCtx = hcdisassemblyWindow) or
  1821. (F^.HelpCtx = hcWatchesWindow) or
  1822. (F^.HelpCtx = hcStackWindow) or
  1823. (F^.HelpCtx = hcRegistersWindow) or
  1824. (F^.HelpCtx = hcVectorRegisters) or
  1825. (F^.HelpCtx = hcFPURegisters)) do
  1826. F:=F^.NextView;
  1827. if F<>@Self then
  1828. Select;
  1829. if PrevCurrent<>F then
  1830. Begin
  1831. Desktop^.InsertBefore(@self,F);
  1832. PrevCurrent^.Select;
  1833. End;
  1834. DeskTop^.Unlock;
  1835. end;
  1836. procedure TFPWindow.HandleEvent(var Event: TEvent);
  1837. begin
  1838. case Event.What of
  1839. evBroadcast :
  1840. case Event.Command of
  1841. cmUpdate :
  1842. Update;
  1843. cmSearchWindow+1..cmSearchWindow+99 :
  1844. if (Event.Command-cmSearchWindow=Number) then
  1845. ClearEvent(Event);
  1846. end;
  1847. end;
  1848. inherited HandleEvent(Event);
  1849. end;
  1850. constructor TFPWindow.Load(var S: TStream);
  1851. begin
  1852. inherited Load(S);
  1853. S.Read(AutoNumber,SizeOf(AutoNumber));
  1854. end;
  1855. procedure TFPWindow.Store(var S: TStream);
  1856. begin
  1857. inherited Store(S);
  1858. S.Write(AutoNumber,SizeOf(AutoNumber));
  1859. end;
  1860. function TFPHelpViewer.GetLocalMenu: PMenu;
  1861. var M: PMenu;
  1862. begin
  1863. M:=NewMenu(
  1864. {$ifdef DEBUG}
  1865. NewItem(menu_hlplocal_debug,'',kbNoKey,cmHelpDebug,hcHelpDebug,
  1866. {$endif DEBUG}
  1867. NewItem(menu_hlplocal_contents,'',kbNoKey,cmHelpContents,hcHelpContents,
  1868. NewItem(menu_hlplocal_index,menu_key_hlplocal_index,kbShiftF1,cmHelpIndex,hcHelpIndex,
  1869. NewItem(menu_hlplocal_topicsearch,menu_key_hlplocal_topicsearch,kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  1870. NewItem(menu_hlplocal_prevtopic,menu_key_hlplocal_prevtopic,kbAltF1,cmHelpPrevTopic,hcHelpPrevTopic,
  1871. NewLine(
  1872. NewItem(menu_hlplocal_copy,menu_key_hlplocal_copy,copy_key,cmCopy,hcCopy,
  1873. nil)))))))
  1874. {$ifdef DEBUG}
  1875. )
  1876. {$endif DEBUG}
  1877. ;
  1878. GetLocalMenu:=M;
  1879. end;
  1880. function TFPHelpViewer.GetCommandTarget: PView;
  1881. begin
  1882. GetCommandTarget:=Application;
  1883. end;
  1884. constructor TFPHelpWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word;
  1885. AContext: THelpCtx; ANumber: Integer);
  1886. begin
  1887. inherited Init(Bounds,ATitle,ASourceFileID,AContext,ANumber);
  1888. HelpCtx:=hcHelpWindow;
  1889. HideOnClose:=true;
  1890. end;
  1891. destructor TFPHelpWindow.Done;
  1892. begin
  1893. if HelpWindow=@Self then
  1894. HelpWindow:=nil;
  1895. Inherited Done;
  1896. end;
  1897. procedure TFPHelpWindow.InitHelpView;
  1898. var R: TRect;
  1899. begin
  1900. GetExtent(R); R.Grow(-1,-1);
  1901. HelpView:=New(PFPHelpViewer, Init(R, HSB, VSB));
  1902. HelpView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1903. end;
  1904. procedure TFPHelpWindow.Show;
  1905. begin
  1906. inherited Show;
  1907. if GetState(sfVisible) and (Number=0) then
  1908. begin
  1909. Number:=SearchFreeWindowNo;
  1910. ReDraw;
  1911. end;
  1912. end;
  1913. procedure TFPHelpWindow.Hide;
  1914. begin
  1915. inherited Hide;
  1916. if GetState(sfVisible)=false then
  1917. Number:=0;
  1918. end;
  1919. procedure TFPHelpWindow.HandleEvent(var Event: TEvent);
  1920. begin
  1921. case Event.What of
  1922. evBroadcast :
  1923. case Event.Command of
  1924. cmUpdate :
  1925. ReDraw;
  1926. cmSearchWindow+1..cmSearchWindow+99 :
  1927. if (Event.Command-cmSearchWindow=Number) then
  1928. ClearEvent(Event);
  1929. end;
  1930. end;
  1931. inherited HandleEvent(Event);
  1932. end;
  1933. function TFPHelpWindow.GetPalette: PPalette;
  1934. const P: string[length(CIDEHelpDialog)] = CIDEHelpDialog;
  1935. begin
  1936. GetPalette:=@P;
  1937. end;
  1938. constructor TFPHelpWindow.Load(var S: TStream);
  1939. begin
  1940. Abstract;
  1941. end;
  1942. procedure TFPHelpWindow.Store(var S: TStream);
  1943. begin
  1944. Abstract;
  1945. end;
  1946. constructor TSourceWindow.Init(var Bounds: TRect; AFileName: string);
  1947. var HSB,VSB: PScrollBar;
  1948. R: TRect;
  1949. PA : Array[1..2] of pointer;
  1950. LoadFile: boolean;
  1951. begin
  1952. inherited Init(Bounds,AFileName,{SearchFreeWindowNo}0);
  1953. AutoNumber:=true;
  1954. Options:=Options or ofTileAble;
  1955. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  1956. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  1957. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  1958. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  1959. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  1960. New(Indicator, Init(R));
  1961. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  1962. Insert(Indicator);
  1963. GetExtent(R); R.Grow(-1,-1);
  1964. LoadFile:=(AFileName<>'') and (AFileName<>'*');
  1965. if (AFileName='') then
  1966. begin
  1967. Inc(GlobalNoNameCount);
  1968. NoNameCount:=GlobalNoNameCount;
  1969. end
  1970. else
  1971. NoNameCount:=-1;
  1972. if AFileName='*' then
  1973. AFileName:='';
  1974. New(Editor, Init(R, HSB, VSB, Indicator,AFileName));
  1975. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1976. if LoadFile then
  1977. begin
  1978. if Editor^.LoadFile=false then
  1979. ErrorBox(FormatStrStr(msg_errorreadingfile,AFileName),nil)
  1980. { warn if modified, but not if modified in another
  1981. already open window PM }
  1982. else if Editor^.GetModified and (Editor^.Core^.GetBindingCount=1) then
  1983. begin
  1984. PA[1]:=@AFileName;
  1985. Ptrint(PA[2]):={Editor^.ChangedLine}-1;
  1986. EditorDialog(edChangedOnloading,@PA);
  1987. end;
  1988. end;
  1989. Insert(Editor);
  1990. {$ifndef NODEBUG}
  1991. If assigned(BreakpointsCollection) then
  1992. BreakpointsCollection^.ShowBreakpoints(@Self);
  1993. {$endif NODEBUG}
  1994. UpdateTitle;
  1995. end;
  1996. procedure TSourceWindow.UpdateTitle;
  1997. var Name: string;
  1998. Count: sw_integer;
  1999. begin
  2000. if Editor^.FileName<>'' then
  2001. begin
  2002. Name:=SmartPath(Editor^.FileName);
  2003. Count:=Editor^.Core^.GetBindingCount;
  2004. if Count>1 then
  2005. begin
  2006. Name:=Name+':'+IntToStr(Editor^.Core^.GetBindingIndex(Editor)+1);
  2007. end;
  2008. SetTitle(Name);
  2009. end
  2010. else if NoNameCount>=0 then
  2011. begin
  2012. SetTitle('noname'+IntToStrZ(NonameCount,2)+'.pas');
  2013. end;
  2014. end;
  2015. function TSourceWindow.GetTitle(MaxSize: sw_Integer): TTitleStr;
  2016. begin
  2017. GetTitle:=OptimizePath(inherited GetTitle(255),MaxSize);
  2018. end;
  2019. procedure TSourceWindow.SetTitle(ATitle: string);
  2020. begin
  2021. if Title<>nil then DisposeStr(Title);
  2022. Title:=NewStr(ATitle);
  2023. Frame^.DrawView;
  2024. end;
  2025. procedure TSourceWindow.HandleEvent(var Event: TEvent);
  2026. var DontClear: boolean;
  2027. begin
  2028. case Event.What of
  2029. evBroadcast :
  2030. case Event.Command of
  2031. cmUpdate :
  2032. Update;
  2033. cmUpdateTitle :
  2034. UpdateTitle;
  2035. cmSearchWindow :
  2036. if @Self<>ClipboardWindow then
  2037. ClearEvent(Event);
  2038. end;
  2039. evCommand :
  2040. begin
  2041. DontClear:=false;
  2042. case Event.Command of
  2043. cmHide :
  2044. Hide;
  2045. cmSave :
  2046. if Editor^.IsClipboard=false then
  2047. if (Editor^.FileName='') and Editor^.GetModified then
  2048. Editor^.SaveAs
  2049. else
  2050. Editor^.Save;
  2051. cmSaveAs :
  2052. if Editor^.IsClipboard=false then
  2053. Editor^.SaveAs;
  2054. else DontClear:=true;
  2055. end;
  2056. if DontClear=false then ClearEvent(Event);
  2057. end;
  2058. end;
  2059. inherited HandleEvent(Event);
  2060. end;
  2061. procedure TSourceWindow.UpdateCommands;
  2062. var Active: boolean;
  2063. begin
  2064. Active:=GetState(sfActive);
  2065. if Editor^.IsClipboard=false then
  2066. begin
  2067. SetCmdState(SourceCmds+CompileCmds,Active);
  2068. SetCmdState(EditorCmds,Active);
  2069. end;
  2070. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,Active);
  2071. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  2072. end;
  2073. procedure TSourceWindow.Update;
  2074. begin
  2075. ReDraw;
  2076. end;
  2077. function TSourceWindow.GetPalette: PPalette;
  2078. const P: string[length(CSourceWindow)] = CSourceWindow;
  2079. begin
  2080. GetPalette:=@P;
  2081. end;
  2082. constructor TSourceWindow.Load(var S: TStream);
  2083. begin
  2084. Title:=S.ReadStr;
  2085. PushStatus(FormatStrStr(msg_loadingfile,GetStr(Title)));
  2086. inherited Load(S);
  2087. GetSubViewPtr(S,Indicator);
  2088. GetSubViewPtr(S,Editor);
  2089. {$ifndef NODEBUG}
  2090. If assigned(BreakpointsCollection) then
  2091. BreakpointsCollection^.ShowBreakpoints(@Self);
  2092. {$endif NODEBUG}
  2093. PopStatus;
  2094. end;
  2095. procedure TSourceWindow.Store(var S: TStream);
  2096. begin
  2097. S.WriteStr(Title);
  2098. PushStatus(FormatStrStr(msg_storingfile,GetStr(Title)));
  2099. inherited Store(S);
  2100. PutSubViewPtr(S,Indicator);
  2101. PutSubViewPtr(S,Editor);
  2102. PopStatus;
  2103. end;
  2104. procedure TSourceWindow.Close;
  2105. begin
  2106. inherited Close;
  2107. end;
  2108. destructor TSourceWindow.Done;
  2109. begin
  2110. PushStatus(FormatStrStr(msg_closingfile,GetStr(Title)));
  2111. if not IDEApp.IsClosing then
  2112. Message(Application,evBroadcast,cmSourceWndClosing,@Self);
  2113. inherited Done;
  2114. IDEApp.SourceWindowClosed;
  2115. { if not IDEApp.IsClosing then
  2116. Message(Application,evBroadcast,cmUpdate,@Self);}
  2117. PopStatus;
  2118. end;
  2119. {$ifndef NODEBUG}
  2120. function TGDBSourceEditor.Valid(Command: Word): Boolean;
  2121. var OK: boolean;
  2122. begin
  2123. OK:=TCodeEditor.Valid(Command);
  2124. { do NOT ask for save !!
  2125. if OK and ((Command=cmClose) or (Command=cmQuit)) then
  2126. if IsClipboard=false then
  2127. OK:=SaveAsk; }
  2128. Valid:=OK;
  2129. end;
  2130. procedure TGDBSourceEditor.AddLine(const S: string);
  2131. begin
  2132. if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
  2133. inherited AddLine(S);
  2134. LimitsChanged;
  2135. end;
  2136. procedure TGDBSourceEditor.AddErrorLine(const S: string);
  2137. begin
  2138. if Silent then exit;
  2139. inherited AddLine(S);
  2140. { display like breakpoints in red }
  2141. SetLineFlagState(GetLineCount-1,lfBreakpoint,true);
  2142. LimitsChanged;
  2143. end;
  2144. const
  2145. GDBReservedCount = 6;
  2146. GDBReservedLongest = 3;
  2147. GDBReserved : array[1..GDBReservedCount] of String[GDBReservedLongest] =
  2148. ('gdb','b','n','s','f','bt');
  2149. function IsGDBReservedWord(const S : string) : boolean;
  2150. var
  2151. i : longint;
  2152. begin
  2153. for i:=1 to GDBReservedCount do
  2154. if (S=GDBReserved[i]) then
  2155. begin
  2156. IsGDBReservedWord:=true;
  2157. exit;
  2158. end;
  2159. IsGDBReservedWord:=false;
  2160. end;
  2161. function TGDBSourceEditor.IsReservedWord(const S: string): boolean;
  2162. begin
  2163. IsReservedWord:=IsGDBReservedWord(S);
  2164. end;
  2165. function TGDBSourceEditor.InsertNewLine: Sw_integer;
  2166. Var
  2167. S : string;
  2168. CommandCalled : boolean;
  2169. begin
  2170. if IsReadOnly then begin InsertNewLine:=-1; Exit; end;
  2171. if CurPos.Y<GetLineCount then S:=GetDisplayText(CurPos.Y) else S:='';
  2172. s:=Copy(S,1,CurPos.X);
  2173. CommandCalled:=false;
  2174. if Pos(GDBPrompt,S)=1 then
  2175. Delete(S,1,length(GDBPrompt));
  2176. {$ifndef NODEBUG}
  2177. if assigned(Debugger) then
  2178. if S<>'' then
  2179. begin
  2180. LastCommand:=S;
  2181. { should be true only if we are at the end ! }
  2182. IgnoreStringAtEnd:=(CurPos.Y=GetLineCount-1) and
  2183. (CurPos.X>=length(RTrim(GetDisplayText(GetLineCount-1))));
  2184. Debugger^.Command(S);
  2185. CommandCalled:=true;
  2186. IgnoreStringAtEnd:=false;
  2187. end
  2188. else if AutoRepeat and (CurPos.Y=GetLineCount-1) then
  2189. begin
  2190. Debugger^.Command(LastCommand);
  2191. CommandCalled:=true;
  2192. end;
  2193. {$endif NODEBUG}
  2194. InsertNewLine:=inherited InsertNewLine;
  2195. If CommandCalled then
  2196. InsertText(GDBPrompt);
  2197. end;
  2198. constructor TGDBWindow.Init(var Bounds: TRect);
  2199. var HSB,VSB: PScrollBar;
  2200. R: TRect;
  2201. begin
  2202. inherited Init(Bounds,dialog_gdbwindow,0);
  2203. Options:=Options or ofTileAble;
  2204. AutoNumber:=true;
  2205. HelpCtx:=hcGDBWindow;
  2206. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2207. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2208. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2209. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2210. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2211. New(Indicator, Init(R));
  2212. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2213. Insert(Indicator);
  2214. GetExtent(R); R.Grow(-1,-1);
  2215. New(Editor, Init(R, HSB, VSB, Indicator, GDBOutputFile));
  2216. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2217. Editor^.SetFlags(efInsertMode+efSyntaxHighlight+efNoIndent+efExpandAllTabs);
  2218. if ExistsFile(GDBOutputFile) then
  2219. begin
  2220. if Editor^.LoadFile=false then
  2221. ErrorBox(FormatStrStr(msg_errorreadingfile,GDBOutputFile),nil);
  2222. end
  2223. else
  2224. { Empty files are buggy !! }
  2225. Editor^.AddLine('');
  2226. Insert(Editor);
  2227. {$ifndef NODEBUG}
  2228. if assigned(Debugger) then
  2229. Debugger^.SetWidth(Size.X-1);
  2230. {$endif NODEBUG}
  2231. Editor^.silent:=false;
  2232. Editor^.AutoRepeat:=true;
  2233. Editor^.InsertText(GDBPrompt);
  2234. end;
  2235. procedure TGDBWindow.HandleEvent(var Event: TEvent);
  2236. var DontClear: boolean;
  2237. begin
  2238. case Event.What of
  2239. evCommand :
  2240. begin
  2241. DontClear:=false;
  2242. case Event.Command of
  2243. cmSaveAs :
  2244. Editor^.SaveAs;
  2245. else DontClear:=true;
  2246. end;
  2247. if DontClear=false then ClearEvent(Event);
  2248. end;
  2249. end;
  2250. inherited HandleEvent(Event);
  2251. end;
  2252. destructor TGDBWindow.Done;
  2253. begin
  2254. if @Self=GDBWindow then
  2255. GDBWindow:=nil;
  2256. inherited Done;
  2257. end;
  2258. constructor TGDBWindow.Load(var S: TStream);
  2259. begin
  2260. inherited Load(S);
  2261. GetSubViewPtr(S,Indicator);
  2262. GetSubViewPtr(S,Editor);
  2263. GDBWindow:=@self;
  2264. end;
  2265. procedure TGDBWindow.Store(var S: TStream);
  2266. begin
  2267. inherited Store(S);
  2268. PutSubViewPtr(S,Indicator);
  2269. PutSubViewPtr(S,Editor);
  2270. end;
  2271. function TGDBWindow.GetPalette: PPalette;
  2272. const P: string[length(CSourceWindow)] = CSourceWindow;
  2273. begin
  2274. GetPalette:=@P;
  2275. end;
  2276. procedure TGDBWindow.WriteOutputText(Buf : pchar);
  2277. begin
  2278. {selected normal color ?}
  2279. WriteText(Buf,false);
  2280. end;
  2281. procedure TGDBWindow.WriteErrorText(Buf : pchar);
  2282. begin
  2283. {selected normal color ?}
  2284. WriteText(Buf,true);
  2285. end;
  2286. procedure TGDBWindow.WriteString(Const S : string);
  2287. begin
  2288. Editor^.AddLine(S);
  2289. end;
  2290. procedure TGDBWindow.WriteErrorString(Const S : string);
  2291. begin
  2292. Editor^.AddErrorLine(S);
  2293. end;
  2294. procedure TGDBWindow.WriteText(Buf : pchar;IsError : boolean);
  2295. var p,pe : pchar;
  2296. s : string;
  2297. begin
  2298. p:=buf;
  2299. DeskTop^.Lock;
  2300. While assigned(p) and (p^<>#0) do
  2301. begin
  2302. pe:=strscan(p,#10);
  2303. if pe<>nil then
  2304. pe^:=#0;
  2305. s:=strpas(p);
  2306. If IsError then
  2307. Editor^.AddErrorLine(S)
  2308. else
  2309. Editor^.AddLine(S);
  2310. { restore for dispose }
  2311. if pe<>nil then
  2312. pe^:=#10;
  2313. if pe=nil then
  2314. p:=nil
  2315. else
  2316. begin
  2317. if pe-p > High(s) then
  2318. p:=p+High(s)-1
  2319. else
  2320. begin
  2321. p:=pe;
  2322. inc(p);
  2323. end;
  2324. end;
  2325. end;
  2326. DeskTop^.Unlock;
  2327. Editor^.Draw;
  2328. end;
  2329. procedure TGDBWindow.UpdateCommands;
  2330. var Active: boolean;
  2331. begin
  2332. Active:=GetState(sfActive);
  2333. SetCmdState([cmSaveAs,cmHide,cmRun],Active);
  2334. SetCmdState(EditorCmds,Active);
  2335. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,Active);
  2336. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  2337. end;
  2338. function TDisasLineCollection.At(Index: sw_Integer): PDisasLine;
  2339. begin
  2340. At := PDisasLine(Inherited At(Index));
  2341. end;
  2342. constructor TDisassemblyEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  2343. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  2344. begin
  2345. Inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,AFileName);
  2346. GrowMode:=gfGrowHiX+gfGrowHiY;
  2347. SetFlags(efInsertMode+efSyntaxHighlight+efNoIndent+efExpandAllTabs{+efHighlightRow});
  2348. New(DisasLines,Init(500,1000));
  2349. Core^.ChangeLinesTo(DisasLines);
  2350. { do not allow to write into that window }
  2351. ReadOnly:=true;
  2352. AddLine('');
  2353. MinAddress:=0;
  2354. MaxAddress:=0;
  2355. CurL:=nil;
  2356. OwnsSource:=false;
  2357. Source:=nil;
  2358. end;
  2359. destructor TDisassemblyEditor.Done;
  2360. begin
  2361. ReleaseSource;
  2362. Inherited Done;
  2363. end;
  2364. procedure TDisassemblyEditor.ReleaseSource;
  2365. begin
  2366. if OwnsSource and assigned(source) then
  2367. begin
  2368. Desktop^.Delete(Source);
  2369. Dispose(Source,Done);
  2370. end;
  2371. OwnsSource:=false;
  2372. Source:=nil;
  2373. CurrentSource:='';
  2374. end;
  2375. procedure TDisassemblyEditor.AddSourceLine(const AFileName: string;line : longint);
  2376. var
  2377. S : String;
  2378. begin
  2379. if AFileName<>CurrentSource then
  2380. begin
  2381. ReleaseSource;
  2382. Source:=SearchOnDesktop(FileName,false);
  2383. if not assigned(Source) then
  2384. begin
  2385. Source:=ITryToOpenFile(nil,AFileName,0,line,false,false,true);
  2386. OwnsSource:=true;
  2387. end
  2388. else
  2389. OwnsSource:=false;
  2390. CurrentSource:=AFileName;
  2391. end;
  2392. if Assigned(Source) and (line>0) then
  2393. S:=Trim(Source^.Editor^.GetLineText(line-1))
  2394. else
  2395. S:='<source not found>';
  2396. CurrentLine:=Line;
  2397. inherited AddLine(AFileName+':'+IntToStr(line)+' '+S);
  2398. { display differently }
  2399. SetLineFlagState(GetLineCount-1,lfSpecialRow,true);
  2400. LimitsChanged;
  2401. end;
  2402. procedure TDisassemblyEditor.AddAssemblyLine(const S: string;AAddress : cardinal);
  2403. var
  2404. PL : PDisasLine;
  2405. LI : PEditorLineInfo;
  2406. begin
  2407. if AAddress<>0 then
  2408. inherited AddLine('$'+hexstr(AAddress,8)+S)
  2409. else
  2410. inherited AddLine(S);
  2411. PL:=DisasLines^.At(DisasLines^.count-1);
  2412. PL^.Address:=AAddress;
  2413. LI:=PL^.GetEditorInfo(@Self);
  2414. if AAddress<>0 then
  2415. LI^.BeginsWithAsm:=true;
  2416. LimitsChanged;
  2417. if ((AAddress<minaddress) or (minaddress=0)) and (AAddress<>0) then
  2418. MinAddress:=AAddress;
  2419. if (AAddress>maxaddress) or (maxaddress=0) then
  2420. MaxAddress:=AAddress;
  2421. end;
  2422. function TDisassemblyEditor.GetCurrentLine(address : cardinal) : PDisasLine;
  2423. function IsCorrectLine(PL : PDisasLine) : boolean;
  2424. begin
  2425. IsCorrectLine:=PL^.Address=Address;
  2426. end;
  2427. Var
  2428. PL : PDisasLine;
  2429. begin
  2430. PL:=DisasLines^.FirstThat(@IsCorrectLine);
  2431. if Assigned(PL) then
  2432. begin
  2433. if assigned(CurL) then
  2434. CurL^.SetFlagState(lfDebuggerRow,false);
  2435. SetCurPtr(0,DisasLines^.IndexOf(PL));
  2436. PL^.SetFlags(lfDebuggerRow);
  2437. CurL:=PL;
  2438. TrackCursor(do_not_centre);
  2439. end;
  2440. GetCurrentLine:=PL;
  2441. end;
  2442. { PDisassemblyWindow = ^TDisassemblyWindow;
  2443. TDisassemblyWindow = object(TFPWindow)
  2444. Editor : PDisassemblyEditor;
  2445. Indicator : PIndicator; }
  2446. constructor TDisassemblyWindow.Init(var Bounds: TRect);
  2447. var HSB,VSB: PScrollBar;
  2448. R: TRect;
  2449. begin
  2450. inherited Init(Bounds,dialog_disaswindow,0);
  2451. Options:=Options or ofTileAble;
  2452. AutoNumber:=true;
  2453. HelpCtx:=hcDisassemblyWindow;
  2454. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2455. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2456. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2457. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2458. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2459. New(Indicator, Init(R));
  2460. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2461. Insert(Indicator);
  2462. GetExtent(R); R.Grow(-1,-1);
  2463. New(Editor, Init(R, HSB, VSB, nil, GDBOutputFile));
  2464. Insert(Editor);
  2465. DisassemblyWindow:=@Self;
  2466. end;
  2467. procedure TDisassemblyWindow.LoadFunction(Const FuncName : string);
  2468. var
  2469. p : pchar;
  2470. begin
  2471. {$ifndef NODEBUG}
  2472. If not assigned(Debugger) then Exit;
  2473. Debugger^.Command('set print sym on');
  2474. Debugger^.Command('set width 0xffffffff');
  2475. Debugger^.Command('disas '+FuncName);
  2476. p:=StrNew(Debugger^.GetOutput);
  2477. ProcessPChar(p);
  2478. if (Debugger^.IsRunning) and (FuncName='') then
  2479. Editor^.GetCurrentLine(Debugger^.current_pc);
  2480. {$endif NODEBUG}
  2481. end;
  2482. procedure TDisassemblyWindow.LoadAddress(Addr : cardinal);
  2483. var
  2484. p : pchar;
  2485. begin
  2486. {$ifndef NODEBUG}
  2487. If not assigned(Debugger) then Exit;
  2488. Debugger^.Command('set print sym on');
  2489. Debugger^.Command('set width 0xffffffff');
  2490. Debugger^.Command('disas 0x'+HexStr(Addr,8));
  2491. p:=StrNew(Debugger^.GetOutput);
  2492. ProcessPChar(p);
  2493. if Debugger^.IsRunning and
  2494. (Debugger^.current_pc>=Editor^.MinAddress) and
  2495. (Debugger^.current_pc<=Editor^.MaxAddress) then
  2496. Editor^.GetCurrentLine(Debugger^.current_pc);
  2497. {$endif NODEBUG}
  2498. end;
  2499. function TDisassemblyWindow.ProcessPChar(p : pchar) : boolean;
  2500. var
  2501. p1: pchar;
  2502. pline : pchar;
  2503. pos1, pos2, CurLine, PrevLine : longint;
  2504. CurAddr : cardinal;
  2505. err : word;
  2506. curaddress, cursymofs, CurFile,
  2507. PrevFile, line : string;
  2508. begin
  2509. ProcessPChar:=true;
  2510. Lock;
  2511. Editor^.DisasLines^.FreeAll;
  2512. Editor^.SetFlags(Editor^.GetFlags or efSyntaxHighlight or efKeepLineAttr);
  2513. Editor^.MinAddress:=0;
  2514. Editor^.MaxAddress:=0;
  2515. Editor^.CurL:=nil;
  2516. p1:=p;
  2517. PrevFile:='';
  2518. PrevLine:=0;
  2519. while assigned(p) do
  2520. begin
  2521. pline:=strscan(p,#10);
  2522. if assigned(pline) then
  2523. pline^:=#0;
  2524. line:=strpas(p);
  2525. CurAddr:=0;
  2526. if assigned(pline) then
  2527. begin
  2528. pline^:=#10;
  2529. p:=pline+1;
  2530. end
  2531. else
  2532. p:=nil;
  2533. { now process the line }
  2534. { line is hexaddr <symbol+sym_offset at filename:line> assembly }
  2535. pos1:=pos('<',line);
  2536. if pos1>0 then
  2537. begin
  2538. curaddress:=copy(line,1,pos1-1);
  2539. if copy(curaddress,1,2)='0x' then
  2540. curaddress:='$'+copy(curaddress,3,length(curaddress)-2);
  2541. val(curaddress,CurAddr,err);
  2542. if err>0 then
  2543. val(copy(curaddress,1,err-1),CurAddr,err);
  2544. system.delete(line,1,pos1);
  2545. end;
  2546. pos1:=pos(' at ',line);
  2547. pos2:=pos('>',line);
  2548. if (pos1>0) and (pos1 < pos2) then
  2549. begin
  2550. cursymofs:=copy(line,1,pos1-1);
  2551. CurFile:=copy(line,pos1+4,pos2-pos1-4);
  2552. pos1:=pos(':',CurFile);
  2553. if pos1>0 then
  2554. begin
  2555. val(copy(CurFile,pos1+1,high(CurFile)),CurLine,err);
  2556. system.delete(CurFile,pos1,high(CurFile));
  2557. end
  2558. else
  2559. CurLine:=0;
  2560. system.delete(line,1,pos2);
  2561. end
  2562. else { no ' at ' found before '>' }
  2563. begin
  2564. cursymofs:=copy(line,1,pos2-1);
  2565. CurFile:='';
  2566. system.delete(line,1,pos2);
  2567. end;
  2568. if (CurFile<>'') and ((CurFile<>PrevFile) or (CurLine<>PrevLine)) then
  2569. begin
  2570. WriteSourceString(CurFile,CurLine);
  2571. PrevLine:=CurLine;
  2572. PrevFile:=CurFile;
  2573. end;
  2574. WriteDisassemblyString(line,curaddr);
  2575. end;
  2576. StrDispose(p1);
  2577. Editor^.ReleaseSource;
  2578. Editor^.UpdateAttrs(0,attrForceFull);
  2579. If assigned(BreakpointsCollection) then
  2580. BreakpointsCollection^.ShowBreakpoints(@Self);
  2581. Unlock;
  2582. ReDraw;
  2583. end;
  2584. procedure TDisassemblyWindow.HandleEvent(var Event: TEvent);
  2585. begin
  2586. inherited HandleEvent(Event);
  2587. end;
  2588. procedure TDisassemblyWindow.WriteSourceString(Const S : string;line : longint);
  2589. begin
  2590. Editor^.AddSourceLine(S,line);
  2591. end;
  2592. procedure TDisassemblyWindow.WriteDisassemblyString(Const S : string;address : cardinal);
  2593. begin
  2594. Editor^.AddAssemblyLine(S,address);
  2595. end;
  2596. procedure TDisassemblyWindow.SetCurAddress(address : cardinal);
  2597. begin
  2598. if (address<Editor^.MinAddress) or (address>Editor^.MaxAddress) then
  2599. LoadAddress(address);
  2600. Editor^.GetCurrentLine(address);
  2601. end;
  2602. procedure TDisassemblyWindow.UpdateCommands;
  2603. var Active: boolean;
  2604. begin
  2605. Active:=GetState(sfActive);
  2606. SetCmdState(SourceCmds+CompileCmds,Active);
  2607. SetCmdState(EditorCmds,Active);
  2608. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,false);
  2609. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  2610. end;
  2611. function TDisassemblyWindow.GetPalette: PPalette;
  2612. const P: string[length(CSourceWindow)] = CSourceWindow;
  2613. begin
  2614. GetPalette:=@P;
  2615. end;
  2616. destructor TDisassemblyWindow.Done;
  2617. begin
  2618. if @Self=DisassemblyWindow then
  2619. DisassemblyWindow:=nil;
  2620. inherited Done;
  2621. end;
  2622. {$endif NODEBUG}
  2623. constructor TClipboardWindow.Init;
  2624. var R: TRect;
  2625. HSB,VSB: PScrollBar;
  2626. begin
  2627. Desktop^.GetExtent(R);
  2628. inherited Init(R, '*');
  2629. SetTitle(dialog_clipboard);
  2630. HelpCtx:=hcClipboardWindow;
  2631. Number:=wnNoNumber;
  2632. AutoNumber:=true;
  2633. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2634. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2635. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2636. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2637. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2638. New(Indicator, Init(R));
  2639. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2640. Insert(Indicator);
  2641. GetExtent(R); R.Grow(-1,-1);
  2642. New(Editor, Init(R, HSB, VSB, Indicator, ''));
  2643. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2644. Insert(Editor);
  2645. Editor^.SetFlags(Editor^.GetFlags or efUseTabCharacters);
  2646. Hide;
  2647. Clipboard:=Editor;
  2648. end;
  2649. procedure TClipboardWindow.Close;
  2650. begin
  2651. Hide;
  2652. end;
  2653. constructor TClipboardWindow.Load(var S: TStream);
  2654. begin
  2655. inherited Load(S);
  2656. Clipboard:=Editor;
  2657. end;
  2658. procedure TClipboardWindow.Store(var S: TStream);
  2659. begin
  2660. inherited Store(S);
  2661. end;
  2662. destructor TClipboardWindow.Done;
  2663. begin
  2664. inherited Done;
  2665. Clipboard:=nil;
  2666. ClipboardWindow:=nil;
  2667. end;
  2668. constructor TMessageListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  2669. begin
  2670. inherited Init(Bounds,1,AHScrollBar, AVScrollBar);
  2671. GrowMode:=gfGrowHiX+gfGrowHiY;
  2672. New(ModuleNames, Init(50,100));
  2673. NoSelection:=true;
  2674. end;
  2675. function TMessageListBox.GetLocalMenu: PMenu;
  2676. var M: PMenu;
  2677. begin
  2678. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  2679. M:=NewMenu(
  2680. NewItem(menu_msglocal_clear,'',kbNoKey,cmMsgClear,hcMsgClear,
  2681. NewLine(
  2682. NewItem(menu_msglocal_gotosource,'',kbNoKey,cmMsgGotoSource,hcMsgGotoSource,
  2683. NewItem(menu_msglocal_tracksource,'',kbNoKey,cmMsgTrackSource,hcMsgTrackSource,
  2684. NewLine(
  2685. NewItem(menu_msglocal_saveas,'',kbNoKey,cmSaveAs,hcSaveAs,
  2686. nil)))))));
  2687. GetLocalMenu:=M;
  2688. end;
  2689. procedure TMessageListBox.SetState(AState: Word; Enable: Boolean);
  2690. var OldState: word;
  2691. begin
  2692. OldState:=State;
  2693. inherited SetState(AState,Enable);
  2694. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  2695. SetCmdState([cmSaveAs],Enable);
  2696. end;
  2697. procedure TMessageListBox.HandleEvent(var Event: TEvent);
  2698. var DontClear: boolean;
  2699. begin
  2700. case Event.What of
  2701. evKeyDown :
  2702. begin
  2703. DontClear:=false;
  2704. case Event.KeyCode of
  2705. kbEnter :
  2706. begin
  2707. Message(@Self,evCommand,cmMsgGotoSource,nil);
  2708. ClearEvent(Event);
  2709. exit;
  2710. end;
  2711. else
  2712. DontClear:=true;
  2713. end;
  2714. if not DontClear then
  2715. ClearEvent(Event);
  2716. end;
  2717. evBroadcast :
  2718. case Event.Command of
  2719. cmListItemSelected :
  2720. if Event.InfoPtr=@Self then
  2721. Message(@Self,evCommand,cmMsgTrackSource,nil);
  2722. end;
  2723. evCommand :
  2724. begin
  2725. DontClear:=false;
  2726. case Event.Command of
  2727. cmMsgGotoSource :
  2728. if Range>0 then
  2729. begin
  2730. GotoSource;
  2731. ClearEvent(Event);
  2732. exit;
  2733. end;
  2734. cmMsgTrackSource :
  2735. if Range>0 then
  2736. TrackSource;
  2737. cmMsgClear :
  2738. Clear;
  2739. cmSaveAs :
  2740. SaveAs;
  2741. else
  2742. DontClear:=true;
  2743. end;
  2744. if not DontClear then
  2745. ClearEvent(Event);
  2746. end;
  2747. end;
  2748. inherited HandleEvent(Event);
  2749. end;
  2750. procedure TMessageListBox.AddItem(P: PMessageItem);
  2751. var W : integer;
  2752. begin
  2753. if List=nil then New(List, Init(500,500));
  2754. W:=length(P^.GetText(255));
  2755. if W>MaxWidth then
  2756. begin
  2757. MaxWidth:=W;
  2758. if HScrollBar<>nil then
  2759. HScrollBar^.SetRange(0,MaxWidth);
  2760. end;
  2761. List^.Insert(P);
  2762. SetRange(List^.Count);
  2763. if Focused=List^.Count-1-1 then
  2764. FocusItem(List^.Count-1);
  2765. DrawView;
  2766. end;
  2767. function TMessageListBox.AddModuleName(const Name: string): PString;
  2768. var P: PString;
  2769. begin
  2770. if ModuleNames<>nil then
  2771. P:=ModuleNames^.Add(Name)
  2772. else
  2773. P:=nil;
  2774. AddModuleName:=P;
  2775. end;
  2776. function TMessageListBox.GetText(Item,MaxLen: Sw_Integer): String;
  2777. var P: PMessageItem;
  2778. S: string;
  2779. begin
  2780. P:=List^.At(Item);
  2781. S:=P^.GetText(MaxLen);
  2782. GetText:=copy(S,1,MaxLen);
  2783. end;
  2784. procedure TMessageListBox.Clear;
  2785. begin
  2786. if assigned(List) then
  2787. Dispose(List, Done);
  2788. List:=nil;
  2789. MaxWidth:=0;
  2790. if assigned(ModuleNames) then
  2791. ModuleNames^.FreeAll;
  2792. SetRange(0); DrawView;
  2793. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  2794. end;
  2795. procedure TMessageListBox.TrackSource;
  2796. var W: PSourceWindow;
  2797. P: PMessageItem;
  2798. R: TRect;
  2799. Row,Col: sw_integer;
  2800. Found : boolean;
  2801. begin
  2802. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  2803. if Range=0 then Exit;
  2804. P:=List^.At(Focused);
  2805. if P^.Row=0 then Exit;
  2806. Desktop^.Lock;
  2807. GetNextEditorBounds(R);
  2808. R.B.Y:=Owner^.Origin.Y;
  2809. if P^.Row>0 then Row:=P^.Row-1 else Row:=0;
  2810. if P^.Col>0 then Col:=P^.Col-1 else Col:=0;
  2811. W:=EditorWindowFile(P^.GetModuleName);
  2812. if assigned(W) then
  2813. begin
  2814. W^.GetExtent(R);
  2815. R.B.Y:=Owner^.Origin.Y;
  2816. W^.ChangeBounds(R);
  2817. W^.Editor^.SetCurPtr(Col,Row);
  2818. end
  2819. else
  2820. W:=TryToOpenFile(@R,P^.GetModuleName,Col,Row,true);
  2821. { Try to find it by browsing }
  2822. if W=nil then
  2823. begin
  2824. Desktop^.UnLock;
  2825. Found:=IDEApp.OpenSearch(P^.GetModuleName+'*');
  2826. if found then
  2827. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  2828. Desktop^.Lock;
  2829. end;
  2830. if W<>nil then
  2831. begin
  2832. W^.Select;
  2833. W^.Editor^.TrackCursor(do_centre);
  2834. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,Row);
  2835. end;
  2836. if Assigned(Owner) then
  2837. Owner^.Select;
  2838. Desktop^.UnLock;
  2839. end;
  2840. procedure TMessageListBox.GotoSource;
  2841. var W: PSourceWindow;
  2842. P: PMessageItem;
  2843. R:TRect;
  2844. Row,Col: sw_integer;
  2845. Found : boolean;
  2846. Event : TEvent;
  2847. begin
  2848. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  2849. if Range=0 then Exit;
  2850. P:=List^.At(Focused);
  2851. if P^.Row=0 then Exit;
  2852. Desktop^.Lock;
  2853. if P^.Row>0 then Row:=P^.Row-1 else Row:=0;
  2854. if P^.Col>0 then Col:=P^.Col-1 else Col:=0;
  2855. W:=EditorWindowFile(P^.GetModuleName);
  2856. if assigned(W) then
  2857. begin
  2858. W^.GetExtent(R);
  2859. if Owner^.Origin.Y>R.A.Y+4 then
  2860. R.B.Y:=Owner^.Origin.Y;
  2861. W^.ChangeBounds(R);
  2862. W^.Editor^.SetCurPtr(Col,Row);
  2863. end
  2864. else
  2865. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  2866. { Try to find it by browsing }
  2867. if W=nil then
  2868. begin
  2869. Desktop^.UnLock;
  2870. Found:=IDEApp.OpenSearch(P^.GetModuleName+'*');
  2871. if found then
  2872. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  2873. Desktop^.Lock;
  2874. end;
  2875. if assigned(W) then
  2876. begin
  2877. { Message(Owner,evCommand,cmClose,nil);
  2878. This calls close on StackWindow
  2879. rendering P invalid
  2880. so postpone it PM }
  2881. W^.GetExtent(R);
  2882. if (P^.TClass<>0) then
  2883. W^.Editor^.SetErrorMessage(P^.GetText(R.B.X-R.A.X));
  2884. W^.Select;
  2885. Owner^.Hide;
  2886. end;
  2887. Desktop^.UnLock;
  2888. if assigned(W) then
  2889. begin
  2890. Event.What:=evCommand;
  2891. Event.command:=cmClose;
  2892. Event.InfoPtr:=nil;
  2893. fpide.PutEvent(Owner,Event);
  2894. end;
  2895. end;
  2896. procedure TMessageListBox.Draw;
  2897. var
  2898. I, J, Item: Sw_Integer;
  2899. NormalColor, SelectedColor, FocusedColor, Color: Word;
  2900. ColWidth, CurCol, Indent: Integer;
  2901. B: TDrawBuffer;
  2902. Text: String;
  2903. SCOff: Byte;
  2904. TC: byte;
  2905. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  2906. begin
  2907. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  2908. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2909. begin
  2910. NormalColor := GetColor(1);
  2911. FocusedColor := GetColor(3);
  2912. SelectedColor := GetColor(4);
  2913. end else
  2914. begin
  2915. NormalColor := GetColor(2);
  2916. SelectedColor := GetColor(4);
  2917. end;
  2918. if Transparent then
  2919. begin MT(NormalColor); MT(SelectedColor); end;
  2920. if NoSelection then
  2921. SelectedColor:=NormalColor;
  2922. if HScrollBar <> nil then Indent := HScrollBar^.Value
  2923. else Indent := 0;
  2924. ColWidth := Size.X div NumCols + 1;
  2925. for I := 0 to Size.Y - 1 do
  2926. begin
  2927. for J := 0 to NumCols-1 do
  2928. begin
  2929. Item := J*Size.Y + I + TopItem;
  2930. CurCol := J*ColWidth;
  2931. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  2932. (Focused = Item) and (Range > 0) then
  2933. begin
  2934. Color := FocusedColor;
  2935. SetCursor(CurCol+1,I);
  2936. SCOff := 0;
  2937. end
  2938. else if (Item < Range) and IsSelected(Item) then
  2939. begin
  2940. Color := SelectedColor;
  2941. SCOff := 2;
  2942. end
  2943. else
  2944. begin
  2945. Color := NormalColor;
  2946. SCOff := 4;
  2947. end;
  2948. MoveChar(B[CurCol], ' ', Color, ColWidth);
  2949. if Item < Range then
  2950. begin
  2951. Text := GetText(Item, ColWidth + Indent);
  2952. Text := Copy(Text,Indent,ColWidth);
  2953. MoveStr(B[CurCol+1], Text, Color);
  2954. if ShowMarkers then
  2955. begin
  2956. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  2957. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  2958. end;
  2959. end;
  2960. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  2961. end;
  2962. WriteLine(0, I, Size.X, 1, B);
  2963. end;
  2964. end;
  2965. constructor TMessageListBox.Load(var S: TStream);
  2966. begin
  2967. inherited Load(S);
  2968. New(ModuleNames, Init(50,100));
  2969. NoSelection:=true;
  2970. end;
  2971. procedure TMessageListBox.Store(var S: TStream);
  2972. var OL: PCollection;
  2973. ORV: sw_integer;
  2974. begin
  2975. OL:=List; ORV:=Range;
  2976. New(List, Init(1,1)); Range:=0;
  2977. inherited Store(S);
  2978. Dispose(List, Done);
  2979. List:=OL; Range:=ORV;
  2980. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  2981. collection? Pasting here a modified version of TListBox.Store+
  2982. TAdvancedListBox.Store isn't a better solution, since by eventually
  2983. changing the obj-hierarchy you'll always have to modify this, too - BG }
  2984. end;
  2985. destructor TMessageListBox.Done;
  2986. begin
  2987. inherited Done;
  2988. if List<>nil then Dispose(List, Done);
  2989. if ModuleNames<>nil then Dispose(ModuleNames, Done);
  2990. end;
  2991. constructor TMessageItem.Init(AClass: longint; const AText: string; AModule: PString; ARow, ACol: sw_integer);
  2992. begin
  2993. inherited Init;
  2994. TClass:=AClass;
  2995. Text:=NewStr(AText);
  2996. Module:=AModule;
  2997. Row:=ARow; Col:=ACol;
  2998. end;
  2999. function TMessageItem.GetText(MaxLen: Sw_integer): string;
  3000. var S: string;
  3001. begin
  3002. if Text=nil then S:='' else S:=Text^;
  3003. if (Module<>nil) then
  3004. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+S;
  3005. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  3006. GetText:=S;
  3007. end;
  3008. procedure TMessageItem.Selected;
  3009. begin
  3010. end;
  3011. function TMessageItem.GetModuleName: string;
  3012. begin
  3013. GetModuleName:=GetStr(Module);
  3014. end;
  3015. destructor TMessageItem.Done;
  3016. begin
  3017. inherited Done;
  3018. if Text<>nil then DisposeStr(Text);
  3019. { if Module<>nil then DisposeStr(Module);}
  3020. end;
  3021. procedure TFPDlgWindow.HandleEvent(var Event: TEvent);
  3022. begin
  3023. case Event.What of
  3024. evBroadcast :
  3025. case Event.Command of
  3026. cmSearchWindow+1..cmSearchWindow+99 :
  3027. if (Event.Command-cmSearchWindow=Number) then
  3028. ClearEvent(Event);
  3029. end;
  3030. end;
  3031. inherited HandleEvent(Event);
  3032. end;
  3033. (*
  3034. constructor TTab.Init(var Bounds: TRect; ATabDef: PTabDef);
  3035. begin
  3036. inherited Init(Bounds);
  3037. Options:=Options or ofSelectable or ofFirstClick or ofPreProcess or ofPostProcess;
  3038. GrowMode:=gfGrowHiX+gfGrowHiY+gfGrowRel;
  3039. TabDefs:=ATabDef;
  3040. ActiveDef:=-1;
  3041. SelectTab(0);
  3042. ReDraw;
  3043. end;
  3044. function TTab.TabCount: integer;
  3045. var i: integer;
  3046. P: PTabDef;
  3047. begin
  3048. I:=0; P:=TabDefs;
  3049. while (P<>nil) do
  3050. begin
  3051. Inc(I);
  3052. P:=P^.Next;
  3053. end;
  3054. TabCount:=I;
  3055. end;
  3056. function TTab.AtTab(Index: integer): PTabDef;
  3057. var i: integer;
  3058. P: PTabDef;
  3059. begin
  3060. i:=0; P:=TabDefs;
  3061. while (I<Index) do
  3062. begin
  3063. if P=nil then RunError($AA);
  3064. P:=P^.Next;
  3065. Inc(i);
  3066. end;
  3067. AtTab:=P;
  3068. end;
  3069. procedure TTab.SelectTab(Index: integer);
  3070. var P: PTabItem;
  3071. V: PView;
  3072. begin
  3073. if ActiveDef<>Index then
  3074. begin
  3075. if Owner<>nil then Owner^.Lock;
  3076. Lock;
  3077. { --- Update --- }
  3078. if TabDefs<>nil then
  3079. begin
  3080. DefCount:=1;
  3081. while AtTab(DefCount-1)^.Next<>nil do Inc(DefCount);
  3082. end
  3083. else DefCount:=0;
  3084. if ActiveDef<>-1 then
  3085. begin
  3086. P:=AtTab(ActiveDef)^.Items;
  3087. while P<>nil do
  3088. begin
  3089. if P^.View<>nil then Delete(P^.View);
  3090. P:=P^.Next;
  3091. end;
  3092. end;
  3093. ActiveDef:=Index;
  3094. P:=AtTab(ActiveDef)^.Items;
  3095. while P<>nil do
  3096. begin
  3097. if P^.View<>nil then Insert(P^.View);
  3098. P:=P^.Next;
  3099. end;
  3100. V:=AtTab(ActiveDef)^.DefItem;
  3101. if V<>nil then V^.Select;
  3102. ReDraw;
  3103. { --- Update --- }
  3104. UnLock;
  3105. if Owner<>nil then Owner^.UnLock;
  3106. DrawView;
  3107. end;
  3108. end;
  3109. procedure TTab.ChangeBounds(var Bounds: TRect);
  3110. var D: TPoint;
  3111. procedure DoCalcChange(P: PView); {$ifndef FPC}far;{$endif}
  3112. var
  3113. R: TRect;
  3114. begin
  3115. if P^.Owner=nil then Exit; { it think this is a bug in TV }
  3116. P^.CalcBounds(R, D);
  3117. P^.ChangeBounds(R);
  3118. end;
  3119. var
  3120. P: PTabItem;
  3121. I: integer;
  3122. begin
  3123. D.X := Bounds.B.X - Bounds.A.X - Size.X;
  3124. D.Y := Bounds.B.Y - Bounds.A.Y - Size.Y;
  3125. inherited ChangeBounds(Bounds);
  3126. for I:=0 to TabCount-1 do
  3127. if I<>ActiveDef then
  3128. begin
  3129. P:=AtTab(I)^.Items;
  3130. while P<>nil do
  3131. begin
  3132. if P^.View<>nil then DoCalcChange(P^.View);
  3133. P:=P^.Next;
  3134. end;
  3135. end;
  3136. end;
  3137. procedure TTab.SelectNextTab(Forwards: boolean);
  3138. var Index: integer;
  3139. begin
  3140. Index:=ActiveDef;
  3141. if Index=-1 then Exit;
  3142. if Forwards then Inc(Index) else Dec(Index);
  3143. if Index<0 then Index:=DefCount-1 else
  3144. if Index>DefCount-1 then Index:=0;
  3145. SelectTab(Index);
  3146. end;
  3147. procedure TTab.HandleEvent(var Event: TEvent);
  3148. var Index : integer;
  3149. I : integer;
  3150. X : integer;
  3151. Len : byte;
  3152. P : TPoint;
  3153. V : PView;
  3154. CallOrig: boolean;
  3155. LastV : PView;
  3156. FirstV: PView;
  3157. function FirstSelectable: PView;
  3158. var
  3159. FV : PView;
  3160. begin
  3161. FV := First;
  3162. while (FV<>nil) and ((FV^.Options and ofSelectable)=0) and (FV<>Last) do
  3163. FV:=FV^.Next;
  3164. if FV<>nil then
  3165. if (FV^.Options and ofSelectable)=0 then FV:=nil;
  3166. FirstSelectable:=FV;
  3167. end;
  3168. function LastSelectable: PView;
  3169. var
  3170. LV : PView;
  3171. begin
  3172. LV := Last;
  3173. while (LV<>nil) and ((LV^.Options and ofSelectable)=0) and (LV<>First) do
  3174. LV:=LV^.Prev;
  3175. if LV<>nil then
  3176. if (LV^.Options and ofSelectable)=0 then LV:=nil;
  3177. LastSelectable:=LV;
  3178. end;
  3179. begin
  3180. if (Event.What and evMouseDown)<>0 then
  3181. begin
  3182. MakeLocal(Event.Where,P);
  3183. if P.Y<3 then
  3184. begin
  3185. Index:=-1; X:=1;
  3186. for i:=0 to DefCount-1 do
  3187. begin
  3188. Len:=CStrLen(AtTab(i)^.Name^);
  3189. if (P.X>=X) and (P.X<=X+Len+1) then Index:=i;
  3190. X:=X+Len+3;
  3191. end;
  3192. if Index<>-1 then
  3193. SelectTab(Index);
  3194. end;
  3195. end;
  3196. if Event.What=evKeyDown then
  3197. begin
  3198. Index:=-1;
  3199. case Event.KeyCode of
  3200. kbCtrlTab :
  3201. begin
  3202. SelectNextTab((Event.KeyShift and kbShift)=0);
  3203. ClearEvent(Event);
  3204. end;
  3205. kbTab,kbShiftTab :
  3206. if GetState(sfSelected) then
  3207. begin
  3208. if Current<>nil then
  3209. begin
  3210. LastV:=LastSelectable; FirstV:=FirstSelectable;
  3211. if ((Current=LastV) or (Current=PLabel(LastV)^.Link)) and (Event.KeyCode=kbShiftTab) then
  3212. begin
  3213. if Owner<>nil then Owner^.SelectNext(true);
  3214. end else
  3215. if ((Current=FirstV) or (Current=PLabel(FirstV)^.Link)) and (Event.KeyCode=kbTab) then
  3216. begin
  3217. Lock;
  3218. if Owner<>nil then Owner^.SelectNext(false);
  3219. UnLock;
  3220. end else
  3221. SelectNext(Event.KeyCode=kbShiftTab);
  3222. ClearEvent(Event);
  3223. end;
  3224. end;
  3225. else
  3226. for I:=0 to DefCount-1 do
  3227. begin
  3228. if Upcase(GetAltChar(Event.KeyCode))=AtTab(I)^.ShortCut
  3229. then begin
  3230. Index:=I;
  3231. ClearEvent(Event);
  3232. Break;
  3233. end;
  3234. end;
  3235. end;
  3236. if Index<>-1 then
  3237. begin
  3238. Select;
  3239. SelectTab(Index);
  3240. V:=AtTab(ActiveDef)^.DefItem;
  3241. if V<>nil then V^.Focus;
  3242. end;
  3243. end;
  3244. CallOrig:=true;
  3245. if Event.What=evKeyDown then
  3246. begin
  3247. if ((Owner<>nil) and (Owner^.Phase=phPostProcess) and (GetAltChar(Event.KeyCode)<>#0)) or GetState(sfFocused)
  3248. then
  3249. else CallOrig:=false;
  3250. end;
  3251. if CallOrig then inherited HandleEvent(Event);
  3252. end;
  3253. function TTab.GetPalette: PPalette;
  3254. begin
  3255. GetPalette:=nil;
  3256. end;
  3257. procedure TTab.Draw;
  3258. var B : TDrawBuffer;
  3259. i : integer;
  3260. C1,C2,C3,C : word;
  3261. HeaderLen : integer;
  3262. X,X2 : integer;
  3263. Name : PString;
  3264. ActiveKPos : integer;
  3265. ActiveVPos : integer;
  3266. FC : char;
  3267. ClipR : TRect;
  3268. procedure SWriteBuf(X,Y,W,H: integer; var Buf);
  3269. var i: integer;
  3270. begin
  3271. if Y+H>Size.Y then H:=Size.Y-Y;
  3272. if X+W>Size.X then W:=Size.X-X;
  3273. if Buffer=nil then WriteBuf(X,Y,W,H,Buf)
  3274. else for i:=1 to H do
  3275. Move(Buf,Buffer^[X+(Y+i-1)*Size.X],W*2);
  3276. end;
  3277. procedure ClearBuf;
  3278. begin
  3279. MoveChar(B,' ',C1,Size.X);
  3280. end;
  3281. begin
  3282. if InDraw then Exit;
  3283. InDraw:=true;
  3284. { - Start of TGroup.Draw - }
  3285. { if Buffer = nil then
  3286. begin
  3287. GetBuffer;
  3288. end; }
  3289. { - Start of TGroup.Draw - }
  3290. C1:=GetColor(1); C2:=(GetColor(7) and $f0 or $08)+GetColor(9)*256; C3:=GetColor(8)+GetColor({9}8)*256;
  3291. HeaderLen:=0; for i:=0 to DefCount-1 do HeaderLen:=HeaderLen+CStrLen(AtTab(i)^.Name^)+3; Dec(HeaderLen);
  3292. if HeaderLen>Size.X-2 then HeaderLen:=Size.X-2;
  3293. { --- 1. sor --- }
  3294. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[HeaderLen+1],'³',C1,1);
  3295. X:=1;
  3296. for i:=0 to DefCount-1 do
  3297. begin
  3298. Name:=AtTab(i)^.Name; X2:=CStrLen(Name^);
  3299. if i=ActiveDef
  3300. then begin
  3301. ActiveKPos:=X-1;
  3302. ActiveVPos:=X+X2+2;
  3303. if GetState(sfFocused) then C:=C3 else C:=C2;
  3304. end
  3305. else C:=C2;
  3306. MoveCStr(B[X],' '+Name^+' ',C); X:=X+X2+3;
  3307. MoveChar(B[X-1],'³',C1,1);
  3308. end;
  3309. SWriteBuf(0,1,Size.X,1,B);
  3310. { --- 0. sor --- }
  3311. ClearBuf; MoveChar(B[0],'Ú',C1,1);
  3312. X:=1;
  3313. for i:=0 to DefCount-1 do
  3314. begin
  3315. if I<ActiveDef then FC:='Ú'
  3316. else FC:='¿';
  3317. X2:=CStrLen(AtTab(i)^.Name^)+2;
  3318. MoveChar(B[X+X2],{'Â'}FC,C1,1);
  3319. if i=DefCount-1 then X2:=X2+1;
  3320. if X2>0 then
  3321. MoveChar(B[X],'Ä',C1,X2);
  3322. X:=X+X2+1;
  3323. end;
  3324. MoveChar(B[HeaderLen+1],'¿',C1,1);
  3325. MoveChar(B[ActiveKPos],'Ú',C1,1); MoveChar(B[ActiveVPos],'¿',C1,1);
  3326. SWriteBuf(0,0,Size.X,1,B);
  3327. { --- 2. sor --- }
  3328. MoveChar(B[1],'Ä',C1,Max(HeaderLen,0)); MoveChar(B[HeaderLen+2],'Ä',C1,Max(Size.X-HeaderLen-3,0));
  3329. MoveChar(B[Size.X-1],'¿',C1,1);
  3330. MoveChar(B[ActiveKPos],'Ù',C1,1);
  3331. if ActiveDef=0 then MoveChar(B[0],'³',C1,1)
  3332. else MoveChar(B[0],{'Ã'}'Ú',C1,1);
  3333. MoveChar(B[HeaderLen+1],'Ä'{'Á'},C1,1); MoveChar(B[ActiveVPos],'À',C1,1);
  3334. MoveChar(B[ActiveKPos+1],' ',C1,Max(ActiveVPos-ActiveKPos-1,0));
  3335. SWriteBuf(0,2,Size.X,1,B);
  3336. { --- marad‚k sor --- }
  3337. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[Size.X-1],'³',C1,1);
  3338. for i:=3 to Size.Y-1 do
  3339. SWriteBuf(0,i,Size.X,1,B);
  3340. { SWriteBuf(0,3,Size.X,Size.Y-4,B); this was wrong
  3341. because WriteBuf then expect a buffer of size size.x*(size.y-4)*2 PM }
  3342. { --- Size.X . sor --- }
  3343. MoveChar(B[0],'À',C1,1); MoveChar(B[1],'Ä',C1,Max(Size.X-2,0)); MoveChar(B[Size.X-1],'Ù',C1,1);
  3344. SWriteBuf(0,Size.Y-1,Size.X,1,B);
  3345. { - End of TGroup.Draw - }
  3346. if Buffer <> nil then
  3347. begin
  3348. Lock;
  3349. Redraw;
  3350. UnLock;
  3351. end;
  3352. if Buffer <> nil then WriteBuf(0, 0, Size.X, Size.Y, Buffer^) else
  3353. begin
  3354. GetClipRect(ClipR);
  3355. Redraw;
  3356. GetExtent(ClipR);
  3357. end;
  3358. { - End of TGroup.Draw - }
  3359. InDraw:=false;
  3360. end;
  3361. function TTab.Valid(Command: Word): Boolean;
  3362. var PT : PTabDef;
  3363. PI : PTabItem;
  3364. OK : boolean;
  3365. begin
  3366. OK:=true;
  3367. PT:=TabDefs;
  3368. while (PT<>nil) and (OK=true) do
  3369. begin
  3370. PI:=PT^.Items;
  3371. while (PI<>nil) and (OK=true) do
  3372. begin
  3373. if PI^.View<>nil then OK:=OK and PI^.View^.Valid(Command);
  3374. PI:=PI^.Next;
  3375. end;
  3376. PT:=PT^.Next;
  3377. end;
  3378. Valid:=OK;
  3379. end;
  3380. procedure TTab.SetState(AState: Word; Enable: Boolean);
  3381. begin
  3382. inherited SetState(AState,Enable);
  3383. if (AState and sfFocused)<>0 then DrawView;
  3384. end;
  3385. destructor TTab.Done;
  3386. var P,X: PTabDef;
  3387. procedure DeleteViews(P: PView); {$ifndef FPC}far;{$endif}
  3388. begin
  3389. if P<>nil then Delete(P);
  3390. end;
  3391. begin
  3392. ForEach(@DeleteViews);
  3393. inherited Done;
  3394. P:=TabDefs;
  3395. while P<>nil do
  3396. begin
  3397. X:=P^.Next;
  3398. DisposeTabDef(P);
  3399. P:=X;
  3400. end;
  3401. end;
  3402. *)
  3403. constructor TScreenView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  3404. AScreen: PScreen);
  3405. begin
  3406. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  3407. Screen:=AScreen;
  3408. if Screen=nil then
  3409. Fail;
  3410. SetState(sfCursorVis,true);
  3411. Update;
  3412. end;
  3413. procedure TScreenView.Update;
  3414. begin
  3415. SetLimit(UserScreen^.GetWidth,UserScreen^.GetHeight);
  3416. DrawView;
  3417. end;
  3418. procedure TScreenView.HandleEvent(var Event: TEvent);
  3419. begin
  3420. case Event.What of
  3421. evBroadcast :
  3422. case Event.Command of
  3423. cmUpdate : Update;
  3424. end;
  3425. end;
  3426. inherited HandleEvent(Event);
  3427. end;
  3428. procedure TScreenView.Draw;
  3429. var B: TDrawBuffer;
  3430. X,Y: integer;
  3431. Text,Attr: string;
  3432. P: TPoint;
  3433. begin
  3434. Screen^.GetCursorPos(P);
  3435. for Y:=Delta.Y to Delta.Y+Size.Y-1 do
  3436. begin
  3437. if Y<Screen^.GetHeight then
  3438. Screen^.GetLine(Y,Text,Attr)
  3439. else
  3440. begin Text:=''; Attr:=''; end;
  3441. Text:=copy(Text,Delta.X+1,255); Attr:=copy(Attr,Delta.X+1,255);
  3442. MoveChar(B,' ',GetColor(1),Size.X);
  3443. for X:=1 to length(Text) do
  3444. MoveChar(B[X-1],Text[X],ord(Attr[X]),1);
  3445. WriteLine(0,Y-Delta.Y,Size.X,1,B);
  3446. end;
  3447. SetCursor(P.X-Delta.X,P.Y-Delta.Y);
  3448. end;
  3449. constructor TScreenWindow.Init(AScreen: PScreen; ANumber: integer);
  3450. var R: TRect;
  3451. VSB,HSB: PScrollBar;
  3452. begin
  3453. Desktop^.GetExtent(R);
  3454. inherited Init(R, dialog_userscreen, ANumber);
  3455. Options:=Options or ofTileAble;
  3456. GetExtent(R); R.Grow(-1,-1); R.Move(1,0); R.A.X:=R.B.X-1;
  3457. New(VSB, Init(R)); VSB^.Options:=VSB^.Options or ofPostProcess;
  3458. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  3459. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.A.Y:=R.B.Y-1;
  3460. New(HSB, Init(R)); HSB^.Options:=HSB^.Options or ofPostProcess;
  3461. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  3462. GetExtent(R); R.Grow(-1,-1);
  3463. New(ScreenView, Init(R, HSB, VSB, AScreen));
  3464. ScreenView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  3465. Insert(ScreenView);
  3466. UserScreenWindow:=@Self;
  3467. end;
  3468. destructor TScreenWindow.Done;
  3469. begin
  3470. inherited Done;
  3471. UserScreenWindow:=nil;
  3472. end;
  3473. const InTranslate : boolean = false;
  3474. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  3475. procedure TranslateAction(Action: integer);
  3476. var E: TEvent;
  3477. begin
  3478. if Action<>acNone then
  3479. begin
  3480. E:=Event;
  3481. E.What:=evMouseDown; E.Buttons:=mbLeftButton;
  3482. View^.HandleEvent(E);
  3483. Event.What:=evCommand;
  3484. Event.Command:=ActionCommands[Action];
  3485. end;
  3486. end;
  3487. begin
  3488. if InTranslate then Exit;
  3489. InTranslate:=true;
  3490. case Event.What of
  3491. evMouseDown :
  3492. if (GetShiftState and kbAlt)<>0 then
  3493. TranslateAction(AltMouseAction) else
  3494. if (GetShiftState and kbCtrl)<>0 then
  3495. TranslateAction(CtrlMouseAction);
  3496. end;
  3497. InTranslate:=false;
  3498. end;
  3499. function GetNextEditorBounds(var Bounds: TRect): boolean;
  3500. var P: PView;
  3501. begin
  3502. P:=Desktop^.Current;
  3503. while P<>nil do
  3504. begin
  3505. if P^.HelpCtx=hcSourceWindow then Break;
  3506. P:=P^.NextView;
  3507. if P=Desktop^.Current then
  3508. begin
  3509. P:=nil;
  3510. break;
  3511. end;
  3512. end;
  3513. if P=nil then Desktop^.GetExtent(Bounds) else
  3514. begin
  3515. P^.GetBounds(Bounds);
  3516. Inc(Bounds.A.X); Inc(Bounds.A.Y);
  3517. end;
  3518. GetNextEditorBounds:=P<>nil;
  3519. end;
  3520. function IOpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer; ShowIt: boolean): PSourceWindow;
  3521. var R: TRect;
  3522. W: PSourceWindow;
  3523. begin
  3524. if Assigned(Bounds) then R.Copy(Bounds^) else
  3525. GetNextEditorBounds(R);
  3526. PushStatus(FormatStrStr(msg_openingsourcefile,SmartPath(FileName)));
  3527. New(W, Init(R, FileName));
  3528. if ShowIt=false then
  3529. W^.Hide;
  3530. if W<>nil then
  3531. begin
  3532. if (CurX<>0) or (CurY<>0) then
  3533. with W^.Editor^ do
  3534. begin
  3535. SetCurPtr(CurX,CurY);
  3536. TrackCursor(do_centre);
  3537. end;
  3538. W^.HelpCtx:=hcSourceWindow;
  3539. Desktop^.Insert(W);
  3540. Message(Application,evBroadcast,cmUpdate,nil);
  3541. end;
  3542. PopStatus;
  3543. IOpenEditorWindow:=W;
  3544. end;
  3545. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer): PSourceWindow;
  3546. begin
  3547. OpenEditorWindow:=IOpenEditorWindow(Bounds,FileName,CurX,CurY,true);
  3548. end;
  3549. function LastSourceEditor : PSourceWindow;
  3550. function IsSearchedSource(P: PView) : boolean; {$ifndef FPC}far;{$endif}
  3551. begin
  3552. if assigned(P) and
  3553. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  3554. IsSearchedSource:=true
  3555. else
  3556. IsSearchedSource:=false;
  3557. end;
  3558. begin
  3559. LastSourceEditor:=PSourceWindow(Desktop^.FirstThat(@IsSearchedSource));
  3560. end;
  3561. function SearchOnDesktop(FileName : string;tryexts:boolean) : PSourceWindow;
  3562. var
  3563. D,DS : DirStr;
  3564. N,NS : NameStr;
  3565. E,ES : ExtStr;
  3566. SName : string;
  3567. function IsSearchedFile(W : PSourceWindow) : boolean;
  3568. var Found: boolean;
  3569. begin
  3570. Found:=false;
  3571. if (W<>nil) and (W^.HelpCtx=hcSourceWindow) then
  3572. begin
  3573. if (D='') then
  3574. SName:=NameAndExtOf(PSourceWindow(W)^.Editor^.FileName)
  3575. else
  3576. SName:=PSourceWindow(W)^.Editor^.FileName;
  3577. FSplit(SName,DS,NS,ES);
  3578. SName:=UpcaseStr(NS+ES);
  3579. if (E<>'') or (not tryexts) then
  3580. begin
  3581. if D<>'' then
  3582. Found:=UpCaseStr(DS)+SName=UpcaseStr(D+N+E)
  3583. else
  3584. Found:=SName=UpcaseStr(N+E);
  3585. end
  3586. else
  3587. begin
  3588. Found:=SName=UpcaseStr(N+'.pp');
  3589. if Found=false then
  3590. Found:=SName=UpcaseStr(N+'.pas');
  3591. end;
  3592. end;
  3593. IsSearchedFile:=found;
  3594. end;
  3595. function IsSearchedSource(P: PView) : boolean; {$ifndef FPC}far;{$endif}
  3596. begin
  3597. if assigned(P) and
  3598. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  3599. IsSearchedSource:=IsSearchedFile(PSourceWindow(P))
  3600. else
  3601. IsSearchedSource:=false;
  3602. end;
  3603. begin
  3604. FSplit(FileName,D,N,E);
  3605. SearchOnDesktop:=PSourceWindow(Desktop^.FirstThat(@IsSearchedSource));
  3606. end;
  3607. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean): PSourceWindow;
  3608. begin
  3609. TryToOpenFile:=ITryToOpenFile(Bounds,FileName,CurX,CurY,tryexts,true,false);
  3610. end;
  3611. function LocateSingleSourceFile(const FileName: string; tryexts: boolean): string;
  3612. var D : DirStr;
  3613. N : NameStr;
  3614. E : ExtStr;
  3615. function CheckDir(NewDir: DirStr; NewName: NameStr; NewExt: ExtStr): boolean;
  3616. var OK: boolean;
  3617. begin
  3618. NewDir:=CompleteDir(NewDir);
  3619. OK:=ExistsFile(NewDir+NewName+NewExt);
  3620. if OK then begin D:=NewDir; N:=NewName; E:=NewExt; end;
  3621. CheckDir:=OK;
  3622. end;
  3623. function CheckExt(NewExt: ExtStr): boolean;
  3624. var OK: boolean;
  3625. begin
  3626. OK:=false;
  3627. if D<>'' then OK:=CheckDir(D,N,NewExt) else
  3628. if CheckDir('.'+DirSep,N,NewExt) then OK:=true;
  3629. CheckExt:=OK;
  3630. end;
  3631. function TryToLocateIn(const DD : dirstr): boolean;
  3632. var Found: boolean;
  3633. begin
  3634. D:=CompleteDir(DD);
  3635. Found:=true;
  3636. if (E<>'') or (not tryexts) then
  3637. Found:=CheckExt(E)
  3638. else
  3639. if CheckExt('.pp') then
  3640. Found:=true
  3641. else
  3642. if CheckExt('.pas') then
  3643. Found:=true
  3644. else
  3645. if CheckExt('.inc') then
  3646. Found:=true
  3647. { try also without extension if no other exist }
  3648. else
  3649. if CheckExt('') then
  3650. Found:=true
  3651. else
  3652. Found:=false;
  3653. TryToLocateIn:=Found;
  3654. end;
  3655. var Path,DrStr: string;
  3656. Found: boolean;
  3657. begin
  3658. FSplit(FileName,D,N,E);
  3659. Found:=CheckDir(D,N,E);
  3660. if not found then
  3661. Found:=TryToLocateIn('.');
  3662. DrStr:=GetSourceDirectories;
  3663. if not Found then
  3664. While pos(ListSeparator,DrStr)>0 do
  3665. Begin
  3666. Found:=TryToLocateIn(Copy(DrStr,1,pos(ListSeparator,DrStr)-1));
  3667. if Found then
  3668. break;
  3669. DrStr:=Copy(DrStr,pos(ListSeparator,DrStr)+1,High(DrStr));
  3670. End;
  3671. if Found then Path:=FExpand(D+N+E) else Path:='';
  3672. LocateSingleSourceFile:=Path;
  3673. end;
  3674. function LocateSourceFile(const FileName: string; tryexts: boolean): string;
  3675. var P: integer;
  3676. FN,S: string;
  3677. FFN: string;
  3678. begin
  3679. FN:=FileName;
  3680. repeat
  3681. P:=Pos(ListSeparator,FN); if P=0 then P:=length(FN)+1;
  3682. S:=copy(FN,1,P-1); Delete(FN,1,P);
  3683. FFN:=LocateSingleSourceFile(S,tryexts);
  3684. until (FFN<>'') or (FN='');
  3685. LocateSourceFile:=FFN;
  3686. end;
  3687. function ITryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean;
  3688. ShowIt,ForceNewWindow: boolean): PSourceWindow;
  3689. var
  3690. W : PSourceWindow;
  3691. DrStr: string;
  3692. begin
  3693. W:=nil;
  3694. if ForceNewWindow then
  3695. W:=nil
  3696. else
  3697. W:=SearchOnDesktop(FileName,tryexts);
  3698. if W<>nil then
  3699. begin
  3700. NewEditorOpened:=false;
  3701. { if assigned(Bounds) then
  3702. W^.ChangeBounds(Bounds^);}
  3703. W^.Editor^.SetCurPtr(CurX,CurY);
  3704. end
  3705. else
  3706. begin
  3707. DrStr:=LocateSourceFile(FileName,tryexts);
  3708. if DrStr<>'' then
  3709. W:=IOpenEditorWindow(Bounds,DrStr,CurX,CurY,ShowIt);
  3710. NewEditorOpened:=W<>nil;
  3711. if assigned(W) then
  3712. W^.Editor^.SetCurPtr(CurX,CurY);
  3713. end;
  3714. ITryToOpenFile:=W;
  3715. end;
  3716. function StartEditor(Editor: PCodeEditor; FileName: string): boolean;
  3717. var OK: boolean;
  3718. E: PFileEditor;
  3719. R: TRect;
  3720. begin
  3721. R.Assign(0,0,0,0);
  3722. New(E, Init(R,nil,nil,nil,nil,FileName));
  3723. OK:=E<>nil;
  3724. if OK then
  3725. begin
  3726. PushStatus(FormatStrStr(msg_readingfileineditor,FileName));
  3727. OK:=E^.LoadFile;
  3728. PopStatus;
  3729. end;
  3730. if OK then
  3731. begin
  3732. Editor^.Lock;
  3733. E^.SelectAll(true);
  3734. Editor^.InsertFrom(E);
  3735. Editor^.SetCurPtr(0,0);
  3736. Editor^.SelectAll(false);
  3737. Editor^.UnLock;
  3738. Dispose(E, Done);
  3739. end;
  3740. StartEditor:=OK;
  3741. end;
  3742. constructor TTextScroller.Init(var Bounds: TRect; ASpeed: integer; AText: PUnsortedStringCollection);
  3743. begin
  3744. inherited Init(Bounds,'');
  3745. EventMask:=EventMask or evIdle;
  3746. Speed:=ASpeed; Lines:=AText;
  3747. end;
  3748. function TTextScroller.GetLineCount: integer;
  3749. var Count: integer;
  3750. begin
  3751. if Lines=nil then Count:=0 else
  3752. Count:=Lines^.Count;
  3753. GetLineCount:=Count;
  3754. end;
  3755. function TTextScroller.GetLine(I: integer): string;
  3756. var S: string;
  3757. begin
  3758. if I<Lines^.Count then
  3759. S:=GetStr(Lines^.At(I))
  3760. else
  3761. S:='';
  3762. GetLine:=S;
  3763. end;
  3764. procedure TTextScroller.HandleEvent(var Event: TEvent);
  3765. begin
  3766. case Event.What of
  3767. evIdle :
  3768. Update;
  3769. end;
  3770. inherited HandleEvent(Event);
  3771. end;
  3772. procedure TTextScroller.Update;
  3773. begin
  3774. if abs(GetDosTicks-LastTT)<Speed then Exit;
  3775. Scroll;
  3776. LastTT:=GetDosTicks;
  3777. end;
  3778. procedure TTextScroller.Reset;
  3779. begin
  3780. TopLine:=0;
  3781. LastTT:=GetDosTicks;
  3782. DrawView;
  3783. end;
  3784. procedure TTextScroller.Scroll;
  3785. begin
  3786. Inc(TopLine);
  3787. if TopLine>=GetLineCount then
  3788. Reset;
  3789. DrawView;
  3790. end;
  3791. procedure TTextScroller.Draw;
  3792. var B: TDrawBuffer;
  3793. C: word;
  3794. Count,Y: integer;
  3795. S: string;
  3796. begin
  3797. C:=GetColor(1);
  3798. Count:=GetLineCount;
  3799. for Y:=0 to Size.Y-1 do
  3800. begin
  3801. if Count=0 then S:='' else
  3802. S:=GetLine((TopLine+Y) mod Count);
  3803. if copy(S,1,1)=^C then
  3804. S:=CharStr(' ',Max(0,(Size.X-(length(S)-1)) div 2))+copy(S,2,255);
  3805. MoveChar(B,' ',C,Size.X);
  3806. MoveStr(B,S,C);
  3807. WriteLine(0,Y,Size.X,1,B);
  3808. end;
  3809. end;
  3810. destructor TTextScroller.Done;
  3811. begin
  3812. inherited Done;
  3813. if Lines<>nil then Dispose(Lines, Done);
  3814. end;
  3815. constructor TFPAboutDialog.Init;
  3816. var R,R2: TRect;
  3817. C: PUnsortedStringCollection;
  3818. I: integer;
  3819. OSStr: string;
  3820. procedure AddLine(S: string);
  3821. begin
  3822. C^.Insert(NewStr(S));
  3823. end;
  3824. begin
  3825. R.Assign(0,0,58,14{$ifdef NODEBUG}-1{$endif});
  3826. inherited Init(R, dialog_about);
  3827. HelpCtx:=hcAbout;
  3828. GetExtent(R); R.Grow(-3,-2);
  3829. R2.Copy(R); R2.B.Y:=R2.A.Y+1;
  3830. Insert(New(PStaticText, Init(R2, ^C'FreePascal IDE for '+source_info.name)));
  3831. R2.Move(0,1);
  3832. Insert(New(PStaticText, Init(R2, ^C'Target CPU: '+target_cpu_string)));
  3833. R2.Move(0,1);
  3834. Insert(New(PStaticText, Init(R2, ^C'Version '+VersionStr+' '+{$i %date%})));
  3835. R2.Move(0,1);
  3836. {$ifdef USE_GRAPH_SWITCH}
  3837. Insert(New(PStaticText, Init(R2, ^C'With Graphic Support')));
  3838. R2.Move(0,1);
  3839. {$endif USE_GRAPH_SWITCH}
  3840. Insert(New(PStaticText, Init(R2, FormatStrStr2(^C'(%s %s)',label_about_compilerversion,Full_Version_String))));
  3841. {$ifndef NODEBUG}
  3842. if pos('Fake',GDBVersion)=0 then
  3843. begin
  3844. R2.Move(0,1);
  3845. Insert(New(PStaticText, Init(R2, FormatStrStr2(^C'(%s %s)',label_about_debugger,GDBVersion))));
  3846. R2.Move(0,1);
  3847. end
  3848. else
  3849. {$endif NODEBUG}
  3850. R2.Move(0,2);
  3851. Insert(New(PStaticText, Init(R2, ^C'Copyright (C) 1998-2006 by')));
  3852. R2.Move(0,2);
  3853. Insert(New(PStaticText, Init(R2, ^C'B‚rczi G bor')));
  3854. R2.Move(0,1);
  3855. Insert(New(PStaticText, Init(R2, ^C'Pierre Muller')));
  3856. R2.Move(0,1);
  3857. Insert(New(PStaticText, Init(R2, ^C'and')));
  3858. R2.Move(0,1);
  3859. Insert(New(PStaticText, Init(R2, ^C'Peter Vreman')));
  3860. New(C, Init(50,10));
  3861. for I:=1 to 7 do
  3862. AddLine('');
  3863. AddLine(^C'< Original concept >');
  3864. AddLine(^C'Borland International, Inc.');
  3865. AddLine('');
  3866. AddLine(^C'< Compiler development >');
  3867. AddLine(^C'Carl-Eric Codere');
  3868. AddLine(^C'Daniel Mantione');
  3869. AddLine(^C'Florian Kl„mpfl');
  3870. AddLine(^C'Jonas Maebe');
  3871. AddLine(^C'Mich„el Van Canneyt');
  3872. AddLine(^C'Peter Vreman');
  3873. AddLine(^C'Pierre Muller');
  3874. AddLine('');
  3875. AddLine(^C'< IDE development >');
  3876. AddLine(^C'B‚rczi G bor');
  3877. AddLine(^C'Peter Vreman');
  3878. AddLine(^C'Pierre Muller');
  3879. AddLine('');
  3880. GetExtent(R);
  3881. R.Grow(-1,-1); Inc(R.A.Y,3);
  3882. New(Scroller, Init(R, 10, C));
  3883. Scroller^.Hide;
  3884. Insert(Scroller);
  3885. R.Move(0,-1); R.B.Y:=R.A.Y+1;
  3886. New(TitleST, Init(R, ^C'Team'));
  3887. TitleST^.Hide;
  3888. Insert(TitleST);
  3889. InsertOK(@Self);
  3890. end;
  3891. procedure TFPAboutDialog.ToggleInfo;
  3892. begin
  3893. if Scroller=nil then Exit;
  3894. if Scroller^.GetState(sfVisible) then
  3895. begin
  3896. Scroller^.Hide;
  3897. TitleST^.Hide;
  3898. end
  3899. else
  3900. begin
  3901. Scroller^.Reset;
  3902. Scroller^.Show;
  3903. TitleST^.Show;
  3904. end;
  3905. end;
  3906. procedure TFPAboutDialog.HandleEvent(var Event: TEvent);
  3907. begin
  3908. case Event.What of
  3909. evKeyDown :
  3910. case Event.KeyCode of
  3911. kbAltI : { just like in BP }
  3912. begin
  3913. ToggleInfo;
  3914. ClearEvent(Event);
  3915. end;
  3916. end;
  3917. end;
  3918. inherited HandleEvent(Event);
  3919. end;
  3920. constructor TFPASCIIChart.Init;
  3921. begin
  3922. inherited Init;
  3923. HelpCtx:=hcASCIITableWindow;
  3924. Number:=SearchFreeWindowNo;
  3925. ASCIIChart:=@Self;
  3926. end;
  3927. procedure TFPASCIIChart.Store(var S: TStream);
  3928. begin
  3929. inherited Store(S);
  3930. end;
  3931. constructor TFPASCIIChart.Load(var S: TStream);
  3932. begin
  3933. inherited Load(S);
  3934. end;
  3935. procedure TFPASCIIChart.HandleEvent(var Event: TEvent);
  3936. var W: PSourceWindow;
  3937. begin
  3938. case Event.What of
  3939. evKeyDown :
  3940. case Event.KeyCode of
  3941. kbEsc :
  3942. begin
  3943. Close;
  3944. ClearEvent(Event);
  3945. end;
  3946. end;
  3947. evCommand :
  3948. case Event.Command of
  3949. cmTransfer :
  3950. begin
  3951. W:=FirstEditorWindow;
  3952. if Assigned(W) and Assigned(Report) then
  3953. Message(W,evCommand,cmAddChar,pointer(ptrint(ord(Report^.AsciiChar))));
  3954. ClearEvent(Event);
  3955. end;
  3956. cmSearchWindow+1..cmSearchWindow+99 :
  3957. if (Event.Command-cmSearchWindow=Number) then
  3958. ClearEvent(Event);
  3959. end;
  3960. end;
  3961. inherited HandleEvent(Event);
  3962. end;
  3963. destructor TFPASCIIChart.Done;
  3964. begin
  3965. ASCIIChart:=nil;
  3966. inherited Done;
  3967. end;
  3968. function TVideoModeListBox.GetText(Item: pointer; MaxLen: sw_integer): string;
  3969. var P: PVideoMode;
  3970. S: string;
  3971. begin
  3972. P:=Item;
  3973. S:=IntToStr(P^.Col)+'x'+IntToStr(P^.Row)+' ';
  3974. if P^.Color then
  3975. S:=S+'color'
  3976. else
  3977. S:=S+'mono';
  3978. GetText:=copy(S,1,MaxLen);
  3979. end;
  3980. constructor TFPDesktop.Init(var Bounds: TRect);
  3981. begin
  3982. inherited Init(Bounds);
  3983. end;
  3984. procedure TFPDesktop.InitBackground;
  3985. var AV: PANSIBackground;
  3986. FileName: string;
  3987. R: TRect;
  3988. begin
  3989. AV:=nil;
  3990. FileName:=LocateFile(BackgroundPath);
  3991. if FileName<>'' then
  3992. begin
  3993. GetExtent(R);
  3994. New(AV, Init(R));
  3995. AV^.GrowMode:=gfGrowHiX+gfGrowHiY;
  3996. if AV^.LoadFile(FileName)=false then
  3997. begin
  3998. Dispose(AV, Done); AV:=nil;
  3999. end;
  4000. if Assigned(AV) then
  4001. Insert(AV);
  4002. end;
  4003. Background:=AV;
  4004. if Assigned(Background)=false then
  4005. inherited InitBackground;
  4006. end;
  4007. constructor TFPDesktop.Load(var S: TStream);
  4008. begin
  4009. inherited Load(S);
  4010. end;
  4011. procedure TFPDesktop.Store(var S: TStream);
  4012. begin
  4013. inherited Store(S);
  4014. end;
  4015. constructor TFPToolTip.Init(var Bounds: TRect; const AText: string; AAlign: TAlign);
  4016. begin
  4017. inherited Init(Bounds);
  4018. SetAlign(AAlign);
  4019. SetText(AText);
  4020. end;
  4021. procedure TFPToolTip.Draw;
  4022. var C: word;
  4023. procedure DrawLine(Y: integer; S: string);
  4024. var B: TDrawBuffer;
  4025. begin
  4026. S:=copy(S,1,Size.X-2);
  4027. case Align of
  4028. alLeft : S:=' '+S;
  4029. alRight : S:=LExpand(' '+S,Size.X);
  4030. alCenter : S:=Center(S,Size.X);
  4031. end;
  4032. MoveChar(B,' ',C,Size.X);
  4033. MoveStr(B,S,C);
  4034. WriteLine(0,Y,Size.X,1,B);
  4035. end;
  4036. var S: string;
  4037. Y: integer;
  4038. begin
  4039. C:=GetColor(1);
  4040. S:=GetText;
  4041. for Y:=0 to Size.Y-1 do
  4042. DrawLine(Y,S);
  4043. end;
  4044. function TFPToolTip.GetText: string;
  4045. begin
  4046. GetText:=GetStr(Text);
  4047. end;
  4048. procedure TFPToolTip.SetText(const AText: string);
  4049. begin
  4050. if AText<>GetText then
  4051. begin
  4052. if Assigned(Text) then DisposeStr(Text);
  4053. Text:=NewStr(AText);
  4054. DrawView;
  4055. end;
  4056. end;
  4057. function TFPToolTip.GetAlign: TAlign;
  4058. begin
  4059. GetAlign:=Align;
  4060. end;
  4061. procedure TFPToolTip.SetAlign(AAlign: TAlign);
  4062. begin
  4063. if AAlign<>Align then
  4064. begin
  4065. Align:=AAlign;
  4066. DrawView;
  4067. end;
  4068. end;
  4069. destructor TFPToolTip.Done;
  4070. begin
  4071. if Assigned(Text) then DisposeStr(Text); Text:=nil;
  4072. inherited Done;
  4073. end;
  4074. function TFPToolTip.GetPalette: PPalette;
  4075. const S: string[length(CFPToolTip)] = CFPToolTip;
  4076. begin
  4077. GetPalette:=@S;
  4078. end;
  4079. constructor TFPMemo.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  4080. PScrollBar; AIndicator: PIndicator);
  4081. begin
  4082. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,nil);
  4083. SetFlags(Flags and not (efPersistentBlocks) or efSyntaxHighlight);
  4084. end;
  4085. procedure TFPMemo.HandleEvent(var Event: TEvent);
  4086. var DontClear: boolean;
  4087. S: string;
  4088. begin
  4089. case Event.What of
  4090. evKeyDown :
  4091. begin
  4092. DontClear:=false;
  4093. case Event.KeyCode of
  4094. kbEsc:
  4095. Message(Owner,evCommand,cmCancel,nil);
  4096. else DontClear:=true;
  4097. end;
  4098. if not DontClear then ClearEvent(Event);
  4099. end;
  4100. end;
  4101. inherited HandleEvent(Event);
  4102. end;
  4103. function TFPMemo.GetPalette: PPalette;
  4104. const P: string[length(CFPMemo)] = CFPMemo;
  4105. begin
  4106. GetPalette:=@P;
  4107. end;
  4108. function TFPMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  4109. begin
  4110. GetSpecSymbolCount:=0;
  4111. end;
  4112. function TFPMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  4113. begin
  4114. Abstract;
  4115. GetSpecSymbol:=nil;
  4116. end;
  4117. function TFPMemo.IsReservedWord(const S: string): boolean;
  4118. begin
  4119. IsReservedWord:=false;
  4120. end;
  4121. constructor TFPCodeMemo.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  4122. PScrollBar; AIndicator: PIndicator);
  4123. begin
  4124. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator);
  4125. end;
  4126. function TFPCodeMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  4127. begin
  4128. GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
  4129. end;
  4130. function TFPCodeMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  4131. begin
  4132. GetSpecSymbol:=@FreePascalEmptyString;
  4133. case SpecClass of
  4134. ssCommentPrefix :
  4135. case Index of
  4136. 0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
  4137. 1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
  4138. 2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
  4139. end;
  4140. ssCommentSingleLinePrefix :
  4141. case Index of
  4142. 0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
  4143. end;
  4144. ssCommentSuffix :
  4145. case Index of
  4146. 0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
  4147. 1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
  4148. end;
  4149. ssStringPrefix :
  4150. GetSpecSymbol:=@FreePascalStringPrefix;
  4151. ssStringSuffix :
  4152. GetSpecSymbol:=@FreePascalStringSuffix;
  4153. { must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
  4154. ssAsmPrefix :
  4155. GetSpecSymbol:=@FreePascalAsmPrefix;
  4156. ssAsmSuffix :
  4157. GetSpecSymbol:=@FreePascalAsmSuffix;
  4158. ssDirectivePrefix :
  4159. GetSpecSymbol:=@FreePascalDirectivePrefix;
  4160. ssDirectiveSuffix :
  4161. GetSpecSymbol:=@FreePascalDirectiveSuffix;
  4162. end;
  4163. end;
  4164. function TFPCodeMemo.IsReservedWord(const S: string): boolean;
  4165. begin
  4166. IsReservedWord:=IsFPReservedWord(S);
  4167. end;
  4168. {$ifdef VESA}
  4169. function VESASetVideoModeProc(const VideoMode: TVideoMode; Params: Longint): Boolean; {$ifndef FPC}far;{$endif}
  4170. begin
  4171. VESASetVideoModeProc:=VESASetMode(Params);
  4172. end;
  4173. procedure InitVESAScreenModes;
  4174. var ML: TVESAModeList;
  4175. MI: TVESAModeInfoBlock;
  4176. I: integer;
  4177. begin
  4178. if VESAInit=false then Exit;
  4179. if VESAGetModeList(ML)=false then Exit;
  4180. for I:=1 to ML.Count do
  4181. begin
  4182. if VESAGetModeInfo(ML.Modes[I],MI) then
  4183. with MI do
  4184. {$ifndef DEBUG}
  4185. if (Attributes and vesa_vma_GraphicsMode)=0 then
  4186. {$else DEBUG}
  4187. if ((Attributes and vesa_vma_GraphicsMode)=0) or
  4188. { only allow 4 bit i.e. 16 color modes }
  4189. (((Attributes and vesa_vma_CanBeSetInCurrentConfig)<>0) and
  4190. (BitsPerPixel=8)) then
  4191. {$endif DEBUG}
  4192. RegisterVesaVideoMode(ML.Modes[I]);
  4193. end;
  4194. end;
  4195. procedure DoneVESAScreenModes;
  4196. begin
  4197. FreeVesaModes;
  4198. end;
  4199. {$endif}
  4200. procedure NoDebugger;
  4201. begin
  4202. InformationBox(msg_nodebuggersupportavailable,nil);
  4203. end;
  4204. procedure RegisterFPViews;
  4205. begin
  4206. RegisterType(RSourceEditor);
  4207. RegisterType(RSourceWindow);
  4208. RegisterType(RFPHelpViewer);
  4209. RegisterType(RFPHelpWindow);
  4210. RegisterType(RClipboardWindow);
  4211. RegisterType(RMessageListBox);
  4212. RegisterType(RFPDesktop);
  4213. RegisterType(RFPASCIIChart);
  4214. RegisterType(RFPDlgWindow);
  4215. {$ifndef NODEBUG}
  4216. RegisterType(RGDBWindow);
  4217. RegisterType(RGDBSourceEditor);
  4218. {$endif NODEBUG}
  4219. end;
  4220. END.