fpviews.pas 119 KB

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