fpviews.pas 126 KB

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