fpviews.pas 119 KB

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