fpviews.pas 120 KB

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