weditor.pas 199 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Code editor template objects
  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. {$I globdir.inc}
  12. unit WEditor;
  13. interface
  14. {tes}
  15. uses
  16. Dos,Objects,Drivers,Views,Dialogs,Menus,
  17. FVConsts,
  18. WUtils,WViews;
  19. const
  20. cmFileNameChanged = 51234;
  21. cmASCIIChar = 51235;
  22. cmClearLineHighlights = 51236;
  23. cmSaveCancelled = 51237;
  24. cmBreakLine = 51238;
  25. cmSelStart = 51239;
  26. cmSelEnd = 51240;
  27. cmLastCursorPos = 51241;
  28. cmIndentBlock = 51242;
  29. cmUnIndentBlock = 51243;
  30. cmSelectLine = 51244;
  31. cmWriteBlock = 51245;
  32. cmReadBlock = 51246;
  33. cmPrintBlock = 51247;
  34. cmResetDebuggerRow = 51248;
  35. cmAddChar = 51249;
  36. cmExpandCodeTemplate = 51250;
  37. cmUpperCase = 51251;
  38. cmLowerCase = 51252;
  39. cmWindowStart = 51253;
  40. cmWindowEnd = 51254;
  41. cmFindMatchingDelimiter= 51255;
  42. cmFindMatchingDelimiterBack=51256;
  43. cmActivateMenu = 51257;
  44. cmWordLowerCase = 51258;
  45. cmWordUpperCase = 51259;
  46. cmOpenAtCursor = 51260;
  47. cmBrowseAtCursor = 51261;
  48. cmInsertOptions = 51262;
  49. cmToggleCase = 51263;
  50. cmCreateFold = 51264;
  51. cmToggleFold = 51265;
  52. cmCollapseFold = 51266;
  53. cmExpandFold = 51267;
  54. cmDelToEndOfWord = 51268;
  55. cmInputLineLen = 51269;
  56. EditorTextBufSize = 32768;
  57. MaxLineLength = 255;
  58. MaxLineCount = 2000000;
  59. CodeTemplateCursorChar = '|'; { char to signal cursor pos in templates }
  60. efBackupFiles = $00000001;
  61. efInsertMode = $00000002;
  62. efAutoIndent = $00000004;
  63. efUseTabCharacters = $00000008;
  64. efBackSpaceUnindents = $00000010;
  65. efPersistentBlocks = $00000020;
  66. efSyntaxHighlight = $00000040;
  67. efBlockInsCursor = $00000080;
  68. efVerticalBlocks = $00000100;
  69. efHighlightColumn = $00000200;
  70. efHighlightRow = $00000400;
  71. efAutoBrackets = $00000800;
  72. efExpandAllTabs = $00001000;
  73. efKeepTrailingSpaces = $00002000;
  74. efCodeComplete = $00004000;
  75. efFolds = $00008000;
  76. efNoIndent = $00010000;
  77. efKeepLineAttr = $00020000;
  78. efStoreContent = $80000000;
  79. attrAsm = 1;
  80. attrComment = 2;
  81. attrForceFull = 128;
  82. attrAll = attrAsm+attrComment;
  83. edOutOfMemory = 0;
  84. edReadError = 1;
  85. edWriteError = 2;
  86. edCreateError = 3;
  87. edSaveModify = 4;
  88. edSaveUntitled = 5;
  89. edSaveAs = 6;
  90. edFind = 7;
  91. edSearchFailed = 8;
  92. edReplace = 9;
  93. edReplacePrompt = 10;
  94. edTooManyLines = 11;
  95. edGotoLine = 12;
  96. edReplaceFile = 13;
  97. edWriteBlock = 14;
  98. edReadBlock = 15;
  99. edFileOnDiskChanged = 16;
  100. edChangedOnloading = 17;
  101. edSaveError = 18;
  102. edReloadDiskmodifiedFile = 19;
  103. edReloadDiskAndIDEModifiedFile = 20;
  104. ffmOptions = $0007; ffsOptions = 0;
  105. ffmDirection = $0008; ffsDirection = 3;
  106. ffmScope = $0010; ffsScope = 4;
  107. ffmOrigin = $0020; ffsOrigin = 5;
  108. ffDoReplace = $0040;
  109. ffReplaceAll = $0080;
  110. ffCaseSensitive = $0001;
  111. ffWholeWordsOnly = $0002;
  112. ffPromptOnReplace = $0004;
  113. ffForward = $0000;
  114. ffBackward = $0008;
  115. ffGlobal = $0000;
  116. ffSelectedText = $0010;
  117. ffFromCursor = $0000;
  118. ffEntireScope = $0020;
  119. {$ifdef TEST_REGEXP}
  120. ffUseRegExp = $0100;
  121. ffmUseRegExpFind = $0004;
  122. ffmOptionsFind = $0003;
  123. ffsUseRegExpFind = 8 - 2;
  124. ffmUseRegExpReplace = $0008;
  125. ffsUseRegExpReplace = 8 - 3;
  126. {$endif TEST_REGEXP}
  127. coTextColor = 0;
  128. coWhiteSpaceColor = 1;
  129. coCommentColor = 2;
  130. coReservedWordColor = 3;
  131. coIdentifierColor = 4;
  132. coStringColor = 5;
  133. coNumberColor = 6;
  134. coAssemblerColor = 7;
  135. coSymbolColor = 8;
  136. coDirectiveColor = 9;
  137. coHexNumberColor = 10;
  138. coTabColor = 11;
  139. coAsmReservedColor = 12;
  140. coBreakColor = 13;
  141. coFirstColor = 0;
  142. coLastColor = coBreakColor;
  143. lfBreakpoint = $0001;
  144. lfHighlightRow = $0002;
  145. lfDebuggerRow = $0004;
  146. lfSpecialRow = $0008;
  147. eaMoveCursor = 1;
  148. eaInsertLine = 2;
  149. eaInsertText = 3;
  150. eaDeleteLine = 4;
  151. eaDeleteText = 5;
  152. eaSelectionChanged = 6;
  153. eaCut = 7;
  154. eaPaste = 8;
  155. eaPasteWin = 9;
  156. eaDelChar = 10;
  157. eaClear = 11;
  158. eaCopyBlock = 12;
  159. eaMoveBlock = 13;
  160. eaDelBlock = 14;
  161. eaReadBlock = 15;
  162. eaIndentBlock = 16;
  163. eaUnindentBlock = 17;
  164. eaOverwriteText = 18;
  165. eaUpperCase = 19;
  166. eaLowerCase = 20;
  167. eaToggleCase = 21;
  168. eaDummy = 22;
  169. LastAction = eaDummy;
  170. ActionString : array [0..LastAction-1] of string[13] =
  171. ('','Move','InsLine','InsText','DelLine','DelText',
  172. 'SelChange','Cut','Paste','PasteWin','DelChar','Clear',
  173. 'CopyBlock','MoveBlock','DelBlock',
  174. 'ReadBlock','IndentBlock','UnindentBlock','Overwrite',
  175. 'UpperCase','LowerCase','ToggleCase');
  176. CIndicator = #2#3#1;
  177. CEditor = #33#34#35#36#37#38#39#40#41#42#43#44#45#46#47#48#49#50;
  178. TAB = #9;
  179. FindStrSize = 79;
  180. type
  181. Tcentre = (do_not_centre,do_centre);
  182. PCustomCodeEditor = ^TCustomCodeEditor;
  183. PEditorLineInfo = ^TEditorLineInfo;
  184. PFoldCollection = ^TFoldCollection;
  185. PFold = ^TFold;
  186. TFold = object(TObject)
  187. constructor Init(AEditor: PCustomCodeEditor; AParentFold: PFold; ACollapsed: boolean);
  188. procedure AddReference(P: PObject);
  189. procedure RemoveReference(P: PObject);
  190. procedure AddLineReference(Line: PEditorLineInfo);
  191. procedure RemoveLineReference(Line: PEditorLineInfo);
  192. procedure AddChildReference(Fold: PFold);
  193. procedure RemoveChildReference(Fold: PFold);
  194. function CanDispose: boolean;
  195. function IsCollapsed: boolean;
  196. function IsParent(AFold: PFold): boolean;
  197. function GetLineCount: sw_integer;
  198. procedure Collapse(ACollapse: boolean);
  199. procedure Changed;
  200. function GetLevel: sw_integer;
  201. destructor Done; virtual;
  202. public
  203. ParentFold: PFold;
  204. Collapsed_: boolean;
  205. ReferenceCount: sw_integer;
  206. Editor: PCustomCodeEditor;
  207. LineCount_: sw_integer;
  208. Childs: PFoldCollection;
  209. end;
  210. TFoldCollection = object(TCollection)
  211. function At(Index: sw_Integer): PFold;
  212. end;
  213. TEditorLineInfo = object(TObject)
  214. Editor: PCustomCodeEditor;
  215. Format : PString;
  216. BeginsWithAsm,
  217. EndsWithAsm : boolean;
  218. BeginsWithComment,
  219. EndsInSingleLineComment,
  220. EndsWithComment : boolean;
  221. BeginsWithDirective,
  222. EndsWithDirective : boolean;
  223. BeginCommentType,EndCommentType : byte;
  224. Fold: PFold;
  225. constructor Init(AEditor: PCustomCodeEditor);
  226. destructor Done; virtual;
  227. function GetFormat: string;
  228. procedure SetFormat(const AFormat: string);
  229. procedure SetFold(AFold: PFold);
  230. { Syntax information is now generated separately for each editor instance.
  231. This is not neccessary for a one-language IDE, but this unit contains
  232. a _generic_ editor object, which should be (and is) as flexible as
  233. possible.
  234. The overhead caused by generating the same syntax info for ex.
  235. twice isn't so much... - Gabor }
  236. end;
  237. PEditorLineInfoCollection = ^TEditorLineInfoCollection;
  238. TEditorLineInfoCollection = object(TCollection)
  239. function At(Index: sw_Integer): PEditorLineInfo;
  240. end;
  241. PCustomLine = ^TCustomLine;
  242. TCustomLine = object(TObject)
  243. constructor Init(const AText: string; AFlags: longint);
  244. {a}function GetText: string; virtual;
  245. {a}procedure SetText(const AText: string); virtual;
  246. {a}function GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual;
  247. {a}function GetFlags: longint; virtual;
  248. {a}procedure SetFlags(AFlags: longint); virtual;
  249. function IsFlagSet(AFlag: longint): boolean; {$ifdef USEINLINE}inline;{$endif}
  250. procedure SetFlagState(AFlag: longint; ASet: boolean);
  251. destructor Done; virtual;
  252. public { internal use only! }
  253. {a}procedure AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor); virtual;
  254. {a}procedure RemoveEditorInfo(AEditor: PCustomCodeEditor); virtual;
  255. end;
  256. PLineCollection = ^TLineCollection;
  257. TLineCollection = object(TCollection)
  258. function At(Index: sw_Integer): PCustomLine;
  259. end;
  260. PEditorAction = ^TEditorAction;
  261. TEditorAction = object(TObject)
  262. StartPos : TPoint;
  263. EndPos : TPoint;
  264. Text : PString;
  265. ActionCount : longint;
  266. Flags : longint;
  267. Action : byte;
  268. IsGrouped : boolean;
  269. TimeStamp : longint; { this is needed to keep track of line number &
  270. position changes (for ex. for symbol browser)
  271. the line&pos references (eg. symbol info) should
  272. also contain such a timestamp. this will enable
  273. to determine which changes have been made since
  274. storage of the information and thus calculate
  275. the (probably) changed line & position information,
  276. so, we can still jump to the right position in the
  277. editor even when it is heavily modified - Gabor }
  278. constructor init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint);
  279. constructor init_group(act:byte);
  280. function is_grouped_action : boolean;
  281. destructor done; virtual;
  282. end;
  283. PEditorActionCollection = ^TEditorActionCollection;
  284. TEditorActionCollection = object(TCollection)
  285. CurrentGroupedAction : PEditorAction;
  286. GroupLevel : longint;
  287. function At(Idx : sw_integer) : PEditorAction;
  288. end;
  289. TSpecSymbolClass =
  290. (ssCommentPrefix,ssCommentSingleLinePrefix,ssCommentSuffix,ssStringPrefix,ssStringSuffix,
  291. ssDirectivePrefix,ssDirectiveSuffix,ssAsmPrefix,ssAsmSuffix);
  292. TEditorBookMark = record
  293. Valid : boolean;
  294. Pos : TPoint;
  295. end;
  296. TCompleteState = (csInactive,csOffering,csDenied);
  297. PEditorBinding = ^TEditorBinding;
  298. PEditorBindingCollection = ^TEditorBindingCollection;
  299. TEditorBindingCollection = object(TCollection)
  300. function At(Index: sw_Integer): PEditorBinding;
  301. end;
  302. TEditorBinding = object(TObject)
  303. Editor : PCustomCodeEditor;
  304. constructor Init(AEditor: PCustomCodeEditor);
  305. destructor Done; virtual;
  306. end;
  307. PCustomCodeEditorCore = ^TCustomCodeEditorCore;
  308. TCustomCodeEditorCore = object(TObject)
  309. protected
  310. Bindings : PEditorBindingCollection;
  311. LockFlag : sw_integer;
  312. ChangedLine : sw_integer;
  313. ContentsChangedCalled : boolean;
  314. LimitsChangedCalled : boolean;
  315. ModifiedChangedCalled : boolean;
  316. TabSizeChangedCalled : boolean;
  317. StoreUndoChangedCalled : boolean;
  318. {$ifdef TEST_PARTIAL_SYNTAX}
  319. LastSyntaxedLine : sw_integer;
  320. SyntaxComplete : boolean;
  321. {$endif TEST_PARTIAL_SYNTAX}
  322. public
  323. constructor Init;
  324. procedure BindEditor(AEditor: PCustomCodeEditor);
  325. procedure UnBindEditor(AEditor: PCustomCodeEditor);
  326. function IsEditorBound(AEditor: PCustomCodeEditor): boolean;
  327. function GetBindingCount: sw_integer;
  328. function GetBindingIndex(AEditor: PCustomCodeEditor): sw_integer;
  329. function SearchBinding(AEditor: PCustomCodeEditor): PEditorBinding;
  330. function CanDispose: boolean;
  331. destructor Done; virtual;
  332. public
  333. {a}function GetModified: boolean; virtual;
  334. function GetChangedLine: sw_integer;
  335. {a}procedure SetModified(AModified: boolean); virtual;
  336. {a}function GetStoreUndo: boolean; virtual;
  337. {a}procedure SetStoreUndo(AStore: boolean); virtual;
  338. {a}function GetSyntaxCompleted: boolean; virtual;
  339. {a}procedure SetSyntaxCompleted(SC: boolean); virtual;
  340. {a}function GetTabSize: integer; virtual;
  341. {a}procedure SetTabSize(ATabSize: integer); virtual;
  342. {a}function GetIndentSize: integer; virtual;
  343. {a}procedure SetIndentSize(AIndentSize: integer); virtual;
  344. function IsClipboard: Boolean;
  345. public
  346. { Notifications }
  347. procedure BindingsChanged;
  348. procedure ContentsChanged;
  349. procedure LimitsChanged;
  350. procedure ModifiedChanged;
  351. procedure TabSizeChanged;
  352. procedure StoreUndoChanged;
  353. {a}procedure DoContentsChanged; virtual;
  354. {a}procedure DoLimitsChanged; virtual;
  355. {a}procedure DoModifiedChanged; virtual;
  356. {a}procedure DoTabSizeChanged; virtual;
  357. {a}procedure DoStoreUndoChanged; virtual;
  358. {a}procedure DoSyntaxStateChanged; virtual;
  359. function GetLastVisibleLine : sw_integer;
  360. public
  361. { Storage }
  362. function LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean; virtual;
  363. function SaveToStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; virtual;
  364. function SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean; virtual;
  365. protected
  366. { Text & info storage abstraction }
  367. {a}procedure ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual;
  368. {a}procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); virtual;
  369. {a}function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; virtual;
  370. {a}procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); virtual;
  371. public
  372. { Text & info storage abstraction }
  373. function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer;
  374. function LinePosToCharIdx(Line,X: sw_integer): sw_integer;
  375. {a}function GetLineCount: sw_integer; virtual;
  376. {a}function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  377. {a}function GetLineText(LineNo: sw_integer): string; virtual;
  378. {a}procedure SetDisplayText(I: sw_integer;const S: string); virtual;
  379. {a}function GetDisplayText(I: sw_integer): string; virtual;
  380. {a}procedure SetLineText(I: sw_integer;const S: string); virtual;
  381. procedure GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:string); virtual;
  382. function GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): string; virtual;
  383. procedure SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer;const S: string); virtual;
  384. {a}procedure DeleteAllLines; virtual;
  385. {a}procedure DeleteLine(I: sw_integer); virtual;
  386. {a}function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  387. {a}procedure AddLine(const S: string); virtual;
  388. {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual;
  389. {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual;
  390. public
  391. procedure Lock(AEditor: PCustomCodeEditor);
  392. procedure UnLock(AEditor: PCustomCodeEditor);
  393. function Locked: boolean;
  394. public
  395. { Syntax highlight }
  396. function UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  397. function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
  398. function DoUpdateAttrs(Editor: PCustomCodeEditor; FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  399. function DoUpdateAttrsRange(Editor: PCustomCodeEditor; FromLine, ToLine: sw_integer;
  400. Attrs: byte): sw_integer; virtual;
  401. public
  402. { Undo info storage }
  403. {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
  404. {a}procedure AddGroupedAction(AAction : byte); virtual;
  405. {a}procedure CloseGroupedAction(AAction : byte); virtual;
  406. {a}function GetUndoActionCount: sw_integer; virtual;
  407. {a}function GetRedoActionCount: sw_integer; virtual;
  408. procedure UpdateUndoRedo(cm : word; action : byte);virtual;
  409. end;
  410. TCaseAction = (caToLowerCase,caToUpperCase,caToggleCase);
  411. TCustomCodeEditor = object(TScroller)
  412. SelStart : TPoint;
  413. SelEnd : TPoint;
  414. Highlight : TRect;
  415. CurPos : TPoint;
  416. ELockFlag : integer;
  417. NoSelect : Boolean;
  418. AlwaysShowScrollBars: boolean;
  419. public
  420. { constructor Load(var S: TStream);
  421. procedure Store(var S: TStream);}
  422. procedure ConvertEvent(var Event: TEvent); virtual;
  423. procedure HandleEvent(var Event: TEvent); virtual;
  424. procedure SetState(AState: Word; Enable: Boolean); virtual;
  425. procedure LocalMenu(P: TPoint); virtual;
  426. function GetLocalMenu: PMenu; virtual;
  427. function GetCommandTarget: PView; virtual;
  428. function CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup; virtual;
  429. function GetPalette: PPalette; virtual;
  430. public
  431. procedure Draw; virtual;
  432. procedure DrawCursor; virtual;
  433. { this is the only way I found to avoid
  434. having the cursor being updated if lock is on PM }
  435. procedure ResetCursor; virtual;
  436. procedure DrawIndicator; virtual;
  437. public
  438. {a}function GetFlags: longint; virtual;
  439. {a}procedure SetFlags(AFlags: longint); virtual;
  440. {a}function GetModified: boolean; virtual;
  441. {a}procedure SetModified(AModified: boolean); virtual;
  442. {a}function GetStoreUndo: boolean; virtual;
  443. {a}procedure SetStoreUndo(AStore: boolean); virtual;
  444. {a}function GetSyntaxCompleted: boolean; virtual;
  445. {a}procedure SetSyntaxCompleted(SC: boolean); virtual;
  446. {a}function GetLastSyntaxedLine: sw_integer; virtual;
  447. {a}procedure SetLastSyntaxedLine(ALine: sw_integer); virtual;
  448. function IsFlagSet(AFlag: longint): boolean;{$ifdef USEINLINE}inline;{$endif}
  449. function GetReservedColCount: sw_integer; virtual;
  450. {a}function GetTabSize: integer; virtual;
  451. {a}procedure SetTabSize(ATabSize: integer); virtual;
  452. {a}function GetIndentSize: integer; virtual;
  453. {a}procedure SetIndentSize(AIndentSize: integer); virtual;
  454. {a}function IsReadOnly: boolean; virtual;
  455. {a}function IsClipboard: Boolean; virtual;
  456. {a}function GetInsertMode: boolean; virtual;
  457. {a}procedure SetInsertMode(InsertMode: boolean); virtual;
  458. procedure SetCurPtr(X,Y: sw_integer); virtual;
  459. procedure GetSelectionArea(var StartP,EndP: TPoint); virtual;
  460. procedure SetSelection(A, B: TPoint); virtual;
  461. procedure SetHighlight(A, B: TPoint); virtual;
  462. procedure ChangeCaseArea(StartP,EndP: TPoint; CaseAction: TCaseAction); virtual;
  463. procedure SetLineFlagState(LineNo: sw_integer; Flags: longint; ASet: boolean);
  464. procedure SetLineFlagExclusive(Flags: longint; LineNo: sw_integer);
  465. procedure Update; virtual;
  466. procedure ScrollTo(X, Y: sw_Integer);
  467. procedure TrackCursor(centre:Tcentre); virtual;
  468. procedure Lock; virtual;
  469. procedure UnLock; virtual;
  470. public
  471. { Text & info storage abstraction }
  472. {a}function GetLineCount: sw_integer; virtual;
  473. {a}function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  474. {a}function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
  475. {a}function LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual;
  476. {a}function GetLineText(I: sw_integer): string; virtual;
  477. {a}procedure SetDisplayText(I: sw_integer;const S: string); virtual;
  478. {a}function GetDisplayText(I: sw_integer): string; virtual;
  479. {a}procedure SetLineText(I: sw_integer;const S: string); virtual;
  480. {a}procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:string); virtual;
  481. {a}function GetLineFormat(I: sw_integer): string; virtual;
  482. {a}procedure SetLineFormat(I: sw_integer;const S: string); virtual;
  483. {a}procedure DeleteAllLines; virtual;
  484. {a}procedure DeleteLine(I: sw_integer); virtual;
  485. {a}function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  486. {a}procedure AddLine(const S: string); virtual;
  487. {a}function GetErrorMessage: string; virtual;
  488. {a}procedure SetErrorMessage(const S: string); virtual;
  489. {a}procedure AdjustSelection(DeltaX, DeltaY: sw_integer);
  490. {a}procedure AdjustSelectionBefore(DeltaX, DeltaY: sw_integer);
  491. {a}procedure AdjustSelectionPos(OldCurPosX, OldCurPosY: sw_integer; DeltaX, DeltaY: sw_integer);
  492. {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual;
  493. {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual;
  494. {a}function LoadFromStream(Stream: PFastBufStream): boolean; virtual;
  495. {a}function SaveToStream(Stream: PStream): boolean; virtual;
  496. {a}function SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual;
  497. function LoadFromFile(const AFileName: string): boolean; virtual;
  498. function SaveToFile(const AFileName: string): boolean; virtual;
  499. public
  500. {a}function InsertFrom(Editor: PCustomCodeEditor): Boolean; virtual;
  501. {a}function InsertText(const S: string): Boolean; virtual;
  502. public
  503. procedure FlagsChanged(OldFlags: longint); virtual;
  504. {a}procedure BindingsChanged; virtual;
  505. procedure ContentsChanged; virtual;
  506. procedure LimitsChanged; virtual;
  507. procedure ModifiedChanged; virtual;
  508. procedure PositionChanged; virtual;
  509. procedure TabSizeChanged; virtual;
  510. procedure SyntaxStateChanged; virtual;
  511. procedure StoreUndoChanged; virtual;
  512. procedure SelectionChanged; virtual;
  513. procedure HighlightChanged; virtual;
  514. {a}procedure DoLimitsChanged; virtual;
  515. public
  516. { Syntax highlight support }
  517. {a}function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  518. {a}function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  519. {a}function IsReservedWord(const S: string): boolean; virtual;
  520. {a}function IsAsmReservedWord(const S: string): boolean; virtual;
  521. public
  522. { CodeTemplate support }
  523. {a}function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual;
  524. function SelectCodeTemplate(var ShortCut: string): boolean; virtual;
  525. { CodeComplete support }
  526. {a}function CompleteCodeWord(const WordS: string; var Text: string): boolean; virtual;
  527. {a}function GetCodeCompleteWord: string; virtual;
  528. {a}procedure SetCodeCompleteWord(const S: string); virtual;
  529. {a}function GetCodeCompleteFrag: string; virtual;
  530. {a}procedure SetCodeCompleteFrag(const S: string); virtual;
  531. function GetCompleteState: TCompleteState; virtual;
  532. procedure SetCompleteState(AState: TCompleteState); virtual;
  533. procedure ClearCodeCompleteWord; virtual;
  534. { Fold support }
  535. function GetMaxFoldLevel: sw_integer; virtual;
  536. function GetFoldStringWidth: sw_integer; virtual;
  537. procedure GetFoldStrings(EditorLine: sw_integer; var Prefix, Suffix: openstring); virtual;
  538. {a}function GetFoldCount: sw_integer; virtual;
  539. {a}function GetFold(Index: sw_integer): PFold; virtual;
  540. {a}procedure RegisterFold(AFold: PFold); virtual;
  541. {a}procedure UnRegisterFold(AFold: PFold); virtual;
  542. function ViewToEditorLine(ViewLine: sw_integer): sw_integer;
  543. function EditorToViewLine(EditorLine: sw_integer): sw_integer;
  544. procedure ViewToEditorPoint(P: TPoint; var NP: TPoint);
  545. procedure EditorToViewPoint(P: TPoint; var NP: TPoint);
  546. { Fold support }
  547. function CreateFold(StartY,EndY: sw_integer; Collapsed: boolean): boolean; virtual;
  548. procedure FoldChanged(Fold: PFold); virtual;
  549. procedure RemoveAllFolds; virtual;
  550. public
  551. { Syntax highlight }
  552. {a}function UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  553. {a}function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
  554. public
  555. { Undo info storage }
  556. {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
  557. {a}procedure AddGroupedAction(AAction : byte); virtual;
  558. {a}procedure CloseGroupedAction(AAction : byte); virtual;
  559. {a}function GetUndoActionCount: sw_integer; virtual;
  560. {a}function GetRedoActionCount: sw_integer; virtual;
  561. protected
  562. LastLocalCmd: word;
  563. KeyState : Integer;
  564. Bookmarks : array[0..9] of TEditorBookmark;
  565. DrawCalled,
  566. DrawCursorCalled: boolean;
  567. CurEvent : PEvent;
  568. procedure DrawLines(FirstLine: sw_integer);
  569. function Overwrite: boolean;
  570. function IsModal: boolean;
  571. procedure CheckSels;
  572. procedure CodeCompleteCheck;
  573. procedure CodeCompleteApply;
  574. procedure CodeCompleteCancel;
  575. procedure UpdateUndoRedo(cm : word; action : byte);
  576. procedure HideHighlight;
  577. function ShouldExtend: boolean;
  578. function ValidBlock: boolean;
  579. function GetLineFold(EditorLine: sw_integer): PFold;
  580. function IsLineVisible(EditorLine: sw_integer): boolean; virtual;
  581. function NextVisibleLine(StartLine: sw_integer; Down: boolean): sw_integer;
  582. procedure PushInfo(Const st : string);virtual;
  583. procedure PopInfo;virtual;
  584. public
  585. { Editor primitives }
  586. procedure SelectAll(Enable: boolean); virtual;
  587. public
  588. { Editor commands }
  589. SearchRunCount: integer;
  590. InASCIIMode: boolean;
  591. procedure Indent; virtual;
  592. procedure CharLeft; virtual;
  593. procedure CharRight; virtual;
  594. procedure WordLeft; virtual;
  595. procedure WordRight; virtual;
  596. procedure LineStart; virtual;
  597. procedure LineEnd; virtual;
  598. procedure LineUp; virtual;
  599. procedure LineDown; virtual;
  600. procedure PageUp; virtual;
  601. procedure PageDown; virtual;
  602. procedure TextStart; virtual;
  603. procedure TextEnd; virtual;
  604. procedure WindowStart; virtual;
  605. procedure WindowEnd; virtual;
  606. procedure JumpSelStart; virtual;
  607. procedure JumpSelEnd; virtual;
  608. procedure JumpMark(MarkIdx: integer); virtual;
  609. procedure DefineMark(MarkIdx: integer); virtual;
  610. procedure JumpToLastCursorPos; virtual;
  611. procedure FindMatchingDelimiter(ScanForward: boolean); virtual;
  612. procedure CreateFoldFromBlock; virtual;
  613. procedure ToggleFold; virtual;
  614. procedure CollapseFold; virtual;
  615. procedure ExpandFold; virtual;
  616. procedure UpperCase; virtual;
  617. procedure LowerCase; virtual;
  618. procedure WordLowerCase; virtual;
  619. procedure WordUpperCase; virtual;
  620. procedure InsertOptions; virtual;
  621. procedure ToggleCase; virtual;
  622. function InsertNewLine: Sw_integer; virtual;
  623. procedure BreakLine; virtual;
  624. procedure BackSpace; virtual;
  625. procedure DelChar; virtual;
  626. procedure DelWord; virtual;
  627. procedure DelToEndOfWord; virtual;
  628. procedure DelStart; virtual;
  629. procedure DelEnd; virtual;
  630. procedure DelLine; virtual;
  631. procedure InsMode; virtual;
  632. procedure StartSelect; virtual;
  633. procedure EndSelect; virtual;
  634. procedure DelSelect; virtual;
  635. procedure HideSelect; virtual;
  636. procedure CopyBlock; virtual;
  637. procedure MoveBlock; virtual;
  638. procedure IndentBlock; virtual;
  639. procedure UnindentBlock; virtual;
  640. procedure SelectWord; virtual;
  641. procedure SelectLine; virtual;
  642. procedure WriteBlock; virtual;
  643. procedure ReadBlock; virtual;
  644. procedure PrintBlock; virtual;
  645. procedure ExpandCodeTemplate; virtual;
  646. procedure AddChar(C: char); virtual;
  647. {$ifdef WinClipSupported}
  648. function ClipCopyWin: Boolean; virtual;
  649. function ClipPasteWin: Boolean; virtual;
  650. {$endif WinClipSupported}
  651. function ClipCopy: Boolean; virtual;
  652. procedure ClipCut; virtual;
  653. procedure ClipPaste; virtual;
  654. function GetCurrentWord : string;
  655. function GetCurrentWordArea(var StartP,EndP: TPoint): boolean;
  656. procedure Undo; virtual;
  657. procedure Redo; virtual;
  658. procedure Find; virtual;
  659. procedure Replace; virtual;
  660. procedure DoSearchReplace; virtual;
  661. procedure GotoLine; virtual;
  662. end;
  663. TCodeEditorDialog = function(Dialog: Integer; Info: Pointer): Word;
  664. TEditorInputLine = object(TInputLine)
  665. Procedure HandleEvent(var Event : TEvent);virtual;
  666. end;
  667. PEditorInputLine = ^TEditorInputLine;
  668. TSearchHelperDialog = object(TDialog)
  669. OkButton: PButton;
  670. Procedure HandleEvent(var Event : TEvent);virtual;
  671. end;
  672. PSearchHelperDialog = ^TSearchHelperDialog;
  673. const
  674. { used for ShiftDel and ShiftIns to avoid
  675. GetShiftState to be considered for extending
  676. selection (PM) }
  677. DontConsiderShiftState: boolean = false;
  678. CodeCompleteMinLen : byte = 4; { minimum length of text to try to complete }
  679. ToClipCmds : TCommandSet = ([cmCut,cmCopy,cmCopyWin,
  680. { cmUnselect should because like cut, copy, copywin:
  681. if there is a selection, it is active, else it isn't }
  682. cmUnselect]);
  683. FromClipCmds : TCommandSet = ([cmPaste]);
  684. NulClipCmds : TCommandSet = ([cmClear]);
  685. UndoCmd : TCommandSet = ([cmUndo]);
  686. RedoCmd : TCommandSet = ([cmRedo]);
  687. function ExtractTabs(S: string; TabSize: Sw_integer): string;
  688. function StdEditorDialog(Dialog: Integer; Info: Pointer): word;
  689. const
  690. DefaultSaveExt : string[12] = '.pas';
  691. FileDir : DirStr = '';
  692. EditorDialog : TCodeEditorDialog = {$ifdef fpc}@{$endif}StdEditorDialog;
  693. Clipboard : PCustomCodeEditor = nil;
  694. FindStr : String[FindStrSize] = '';
  695. ReplaceStr : String[FindStrSize] = '';
  696. FindReplaceEditor : PCustomCodeEditor = nil;
  697. FindFlags : word = ffPromptOnReplace;
  698. {$ifndef NO_UNTYPEDSET}
  699. {$define USE_UNTYPEDSET}
  700. {$endif ndef NO_UNTYPEDSET}
  701. WhiteSpaceChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = [#0,#32,#255];
  702. TabChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = [#9];
  703. HashChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['#'];
  704. AlphaChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['A'..'Z','a'..'z','_'];
  705. NumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['0'..'9'];
  706. HexNumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['0'..'9','A'..'F','a'..'f'];
  707. RealNumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['E','e','.'{,'+','-'}];
  708. procedure RegisterWEditor;
  709. implementation
  710. uses
  711. Strings,Video,MsgBox,App,StdDlg,Validate,
  712. {$ifdef WinClipSupported}
  713. WinClip,
  714. {$endif WinClipSupported}
  715. {$ifdef TEST_REGEXP}
  716. {$ifdef USE_OLD_REGEXP}
  717. oldregexpr,
  718. {$else not USE_OLD_REGEXP}
  719. regexpr,
  720. {$endif not USE_OLD_REGEXP}
  721. {$endif TEST_REGEXP}
  722. WConsts,WCEdit;
  723. type
  724. RecordWord = sw_word;
  725. TFindDialogRec = packed record
  726. Find : String[FindStrSize];
  727. Options : RecordWord{longint};
  728. { checkboxes need 32 bits PM }
  729. { reverted to word in dialogs.TCluster for TP compatibility (PM) }
  730. { anyhow its complete nonsense : you can only have 16 fields
  731. but use a longint to store it !! }
  732. Direction: RecordWord;{ and tcluster has word size }
  733. Scope : RecordWord;
  734. Origin : RecordWord;
  735. end;
  736. TReplaceDialogRec = packed record
  737. Find : String[FindStrSize];
  738. Replace : String[FindStrSize];
  739. Options : RecordWord{longint};
  740. Direction: RecordWord;
  741. Scope : RecordWord;
  742. Origin : RecordWord;
  743. end;
  744. TGotoLineDialogRec = packed record
  745. LineNo : string[5];
  746. Lines : sw_integer;
  747. end;
  748. const
  749. kbShift = kbLeftShift+kbRightShift;
  750. const
  751. FirstKeyCount = 46;
  752. FirstKeys: array[0..FirstKeyCount * 2] of Word = (FirstKeyCount,
  753. Ord(^A), cmWordLeft, Ord(^B), cmJumpLine, Ord(^C), cmPageDown,
  754. Ord(^D), cmCharRight, Ord(^E), cmLineUp,
  755. Ord(^F), cmWordRight, Ord(^G), cmDelChar,
  756. Ord(^H), cmBackSpace, Ord(^J), cmExpandCodeTemplate,
  757. Ord(^K), $FF02, Ord(^L), cmSearchAgain,
  758. Ord(^M), cmNewLine, Ord(^N), cmBreakLine,
  759. Ord(^O), $FF03,
  760. Ord(^P), cmASCIIChar, Ord(^Q), $FF01,
  761. Ord(^R), cmPageUp, Ord(^S), cmCharLeft,
  762. Ord(^T), cmDelToEndOfWord, Ord(^U), cmUndo,
  763. Ord(^V), cmInsMode, Ord(^X), cmLineDown,
  764. Ord(^Y), cmDelLine, kbLeft, cmCharLeft,
  765. kbRight, cmCharRight, kbCtrlLeft, cmWordLeft,
  766. kbCtrlRight, cmWordRight, kbHome, cmLineStart,
  767. kbCtrlHome, cmWindowStart, kbCtrlEnd, cmWindowEnd,
  768. kbEnd, cmLineEnd, kbUp, cmLineUp,
  769. kbDown, cmLineDown, kbPgUp, cmPageUp,
  770. kbPgDn, cmPageDown, kbCtrlPgUp, cmTextStart,
  771. kbCtrlPgDn, cmTextEnd, kbIns, cmInsMode,
  772. kbDel, cmDelChar, kbShiftIns, cmPaste,
  773. kbShiftDel, cmCut, kbCtrlIns, cmCopy,
  774. kbCtrlDel, cmClear,
  775. kbCtrlGrayMul, cmToggleFold, kbCtrlGrayMinus, cmCollapseFold, kbCtrlGrayPlus, cmExpandFold);
  776. QuickKeyCount = 29;
  777. QuickKeys: array[0..QuickKeyCount * 2] of Word = (QuickKeyCount,
  778. Ord('A'), cmReplace, Ord('C'), cmTextEnd,
  779. Ord('D'), cmLineEnd, Ord('F'), cmFind,
  780. Ord('H'), cmDelStart, Ord('R'), cmTextStart,
  781. Ord('S'), cmLineStart, Ord('Y'), cmDelEnd,
  782. Ord('G'), cmJumpLine, Ord('A'), cmReplace,
  783. Ord('B'), cmSelStart, Ord('K'), cmSelEnd,
  784. Ord('P'), cmLastCursorPos,
  785. Ord('E'), cmWindowStart, Ord('T'), cmWindowStart,
  786. Ord('U'), cmWindowEnd, Ord('X'), cmWindowEnd,
  787. Ord('['), cmFindMatchingDelimiter, Ord(']'), cmFindMatchingDelimiterBack,
  788. Ord('0'), cmJumpMark0, Ord('1'), cmJumpMark1, Ord('2'), cmJumpMark2,
  789. Ord('3'), cmJumpMark3, Ord('4'), cmJumpMark4, Ord('5'), cmJumpMark5,
  790. Ord('6'), cmJumpMark6, Ord('7'), cmJumpMark7, Ord('8'), cmJumpMark8,
  791. Ord('9'), cmJumpMark9);
  792. BlockKeyCount = 30;
  793. BlockKeys: array[0..BlockKeyCount * 2] of Word = (BlockKeyCount,
  794. Ord('B'), cmStartSelect, Ord('C'), cmCopyBlock,
  795. Ord('H'), cmHideSelect, Ord('K'), cmEndSelect,
  796. Ord('Y'), cmDelSelect, Ord('V'), cmMoveBlock,
  797. Ord('I'), cmIndentBlock, Ord('U'), cmUnindentBlock,
  798. Ord('T'), cmSelectWord, Ord('L'), cmSelectLine,
  799. Ord('W'), cmWriteBlock, Ord('R'), cmReadBlock,
  800. Ord('P'), cmPrintBlock,
  801. Ord('N'), cmUpperCase, Ord('O'), cmLowerCase,
  802. Ord('D'), cmActivateMenu,
  803. Ord('E'), cmWordLowerCase, Ord('F'), cmWordUpperCase,
  804. Ord('S'), cmSave, Ord('A'), cmCreateFold,
  805. Ord('0'), cmSetMark0, Ord('1'), cmSetMark1, Ord('2'), cmSetMark2,
  806. Ord('3'), cmSetMark3, Ord('4'), cmSetMark4, Ord('5'), cmSetMark5,
  807. Ord('6'), cmSetMark6, Ord('7'), cmSetMark7, Ord('8'), cmSetMark8,
  808. Ord('9'), cmSetMark9);
  809. MiscKeyCount = 6;
  810. MiscKeys: array[0..MiscKeyCount * 2] of Word = (MiscKeyCount,
  811. Ord('A'), cmOpenAtCursor, Ord('B'), cmBrowseAtCursor,
  812. Ord('G'), cmJumpLine, Ord('O'), cmInsertOptions,
  813. Ord('U'), cmToggleCase, Ord('L'), cmSelectLine);
  814. KeyMap: array[0..3] of Pointer = (@FirstKeys, @QuickKeys, @BlockKeys, @MiscKeys);
  815. function ScanKeyMap(KeyMap: Pointer; KeyCode: Word): Word;
  816. type
  817. pword = ^word;
  818. var
  819. p : pword;
  820. count : sw_word;
  821. begin
  822. p:=keymap;
  823. count:=p^;
  824. inc(p);
  825. while (count>0) do
  826. begin
  827. if (lo(p^)=lo(keycode)) and
  828. ((hi(p^)=0) or (hi(p^)=hi(keycode))) then
  829. begin
  830. inc(p);
  831. scankeymap:=p^;
  832. Exit;
  833. end;
  834. inc(p,2);
  835. dec(count);
  836. end;
  837. scankeymap:=0;
  838. end;
  839. function IsWordSeparator(C: char): boolean;
  840. begin
  841. IsWordSeparator:=C in
  842. [' ',#0,#255,':','=','''','"',
  843. '.',',','/',';','$','#',
  844. '(',')','<','>','^','*',
  845. '+','-','?','&','[',']',
  846. '{','}','@','~','%','\',
  847. '!'];
  848. end;
  849. {function IsSpace(C: char): boolean;
  850. begin
  851. IsSpace:=C in[' ',#0,#255];
  852. end;}
  853. function LTrim(S: string): string;
  854. begin
  855. while (length(S)>0) and (S[1] in [#0,TAB,#32]) do
  856. Delete(S,1,1);
  857. LTrim:=S;
  858. end;
  859. { TAB are not same as spaces if UseTabs is set PM }
  860. function RTrim(S: string;cut_tabs : boolean): string;
  861. begin
  862. while (length(S)>0) and
  863. ((S[length(S)] in [#0,#32]) or
  864. ((S[Length(S)]=TAB) and cut_tabs)) do
  865. Delete(S,length(S),1);
  866. RTrim:=S;
  867. end;
  868. function Trim(S: string): string;
  869. begin
  870. Trim:=RTrim(LTrim(S),true);
  871. end;
  872. function EatIO: integer;
  873. begin
  874. EatIO:=IOResult;
  875. end;
  876. function ExistsFile(const FileName: string): boolean;
  877. var f: file;
  878. Exists: boolean;
  879. begin
  880. if FileName='' then Exists:=false else
  881. begin
  882. {$I-}
  883. Assign(f,FileName);
  884. Reset(f,1);
  885. Exists:=EatIO=0;
  886. Close(f);
  887. EatIO;
  888. {$I+}
  889. end;
  890. ExistsFile:=Exists;
  891. end;
  892. function StrToInt(const S: string): longint;
  893. var L: longint;
  894. C: integer;
  895. begin
  896. Val(S,L,C); if C<>0 then L:=-1;
  897. StrToInt:=L;
  898. end;
  899. function RExpand(const S: string; MinLen: byte): string;
  900. begin
  901. if length(S)<MinLen then
  902. RExpand:=S+CharStr(' ',MinLen-length(S))
  903. else
  904. RExpand:=S;
  905. end;
  906. {
  907. function upper(const s : string) : string;
  908. var
  909. i : Sw_word;
  910. begin
  911. for i:=1 to length(s) do
  912. if s[i] in ['a'..'z'] then
  913. upper[i]:=char(byte(s[i])-32)
  914. else
  915. upper[i]:=s[i];
  916. upper[0]:=s[0];
  917. end;
  918. }
  919. type TPosOfs = int64;
  920. function PosToOfs(const X,Y: sw_integer): TPosOfs;
  921. begin
  922. PosToOfs:=TPosOfs(y) shl (sizeof(sw_integer)*8) or x;
  923. end;
  924. function PosToOfsP(const P: TPoint): TPosOfs;
  925. begin
  926. PosToOfsP:=PosToOfs(P.X,P.Y);
  927. end;
  928. function PointOfs(P: TPoint): TPosOfs;
  929. begin
  930. PointOfs:={longint(P.Y)*MaxLineLength+P.X}PosToOfsP(P);
  931. end;
  932. function ExtractTabs(S: string; TabSize: Sw_integer): string;
  933. var
  934. P,PAdd: Sw_integer;
  935. begin
  936. p:=0;
  937. while p<length(s) do
  938. begin
  939. inc(p);
  940. if s[p]=TAB then
  941. begin
  942. PAdd:=TabSize-((p-1) mod TabSize);
  943. s:=copy(S,1,P-1)+CharStr(' ',PAdd)+copy(S,P+1,High(s));
  944. inc(P,PAdd-1);
  945. end;
  946. end;
  947. ExtractTabs:=S;
  948. end;
  949. {function CompressUsingTabs(S: string; TabSize: byte): string;
  950. var TabS: string;
  951. P: byte;
  952. begin
  953. TabS:=CharStr(' ',TabSize);
  954. repeat
  955. P:=Pos(TabS,S);
  956. if P>0 then
  957. S:=copy(S,1,P-1)+TAB+copy(S,P+TabSize,High(S));
  958. until P=0;
  959. CompressUsingTabs:=S;
  960. end;}
  961. {*****************************************************************************
  962. Forward/Backward Scanning
  963. *****************************************************************************}
  964. Const
  965. MaxBufLength = $7fffff00;
  966. NotFoundValue = -1;
  967. Type
  968. Btable = Array[0..255] of Byte;
  969. Procedure BMFMakeTable(const s:string; Var t : Btable);
  970. Var
  971. x : sw_integer;
  972. begin
  973. FillChar(t,sizeof(t),length(s));
  974. For x := length(s) downto 1 do
  975. if (t[ord(s[x])] = length(s)) then
  976. t[ord(s[x])] := length(s) - x;
  977. end;
  978. function BMFScan(var Block; Size: Sw_Word;const Str: String;const bt:BTable): Sw_Integer;
  979. Var
  980. buffer : Array[0..MaxBufLength-1] of Byte Absolute block;
  981. s2 : String;
  982. len,
  983. numb : Sw_Word;
  984. found : Boolean;
  985. begin
  986. len:=length(str);
  987. if len>size then
  988. begin
  989. BMFScan := NotFoundValue;
  990. exit;
  991. end;
  992. SetLength(s2,len); { sets the length to that of the search String }
  993. found:=False;
  994. numb:=pred(len);
  995. While (not found) and (numb<size) do
  996. begin
  997. { partial match }
  998. if buffer[numb] = ord(str[len]) then
  999. begin
  1000. { less partial! }
  1001. if buffer[numb-pred(len)] = ord(str[1]) then
  1002. begin
  1003. move(buffer[numb-pred(len)],s2[1],len);
  1004. if (str=s2) then
  1005. begin
  1006. found:=true;
  1007. break;
  1008. end;
  1009. end;
  1010. inc(numb);
  1011. end
  1012. else
  1013. inc(numb,Bt[buffer[numb]]);
  1014. end;
  1015. if not found then
  1016. BMFScan := NotFoundValue
  1017. else
  1018. BMFScan := numb - pred(len);
  1019. end;
  1020. function BMFIScan(var Block; Size: Sw_Word;const Str: String;const bt:BTable): Sw_Integer;
  1021. Var
  1022. buffer : Array[0..MaxBufLength-1] of Char Absolute block;
  1023. len,
  1024. numb,
  1025. x : Sw_Word;
  1026. found : Boolean;
  1027. p : pchar;
  1028. c : char;
  1029. begin
  1030. len:=length(str);
  1031. if (len=0) or (len>size) then
  1032. begin
  1033. BMFIScan := NotFoundValue;
  1034. exit;
  1035. end;
  1036. found:=False;
  1037. numb:=pred(len);
  1038. While (not found) and (numb<size) do
  1039. begin
  1040. { partial match }
  1041. c:=buffer[numb];
  1042. if c in ['a'..'z'] then
  1043. c:=chr(ord(c)-32);
  1044. if (c=str[len]) then
  1045. begin
  1046. { less partial! }
  1047. p:=@buffer[numb-pred(len)];
  1048. x:=1;
  1049. while (x<=len) do
  1050. begin
  1051. if not(((p^ in ['a'..'z']) and (chr(ord(p^)-32)=str[x])) or
  1052. (p^=str[x])) then
  1053. break;
  1054. inc(p);
  1055. inc(x);
  1056. end;
  1057. if (x>len) then
  1058. begin
  1059. found:=true;
  1060. break;
  1061. end;
  1062. inc(numb);
  1063. end
  1064. else
  1065. inc(numb,Bt[ord(c)]);
  1066. end;
  1067. if not found then
  1068. BMFIScan := NotFoundValue
  1069. else
  1070. BMFIScan := numb - pred(len);
  1071. end;
  1072. Procedure BMBMakeTable(const s:string; Var t : Btable);
  1073. Var
  1074. x : sw_integer;
  1075. begin
  1076. FillChar(t,sizeof(t),length(s));
  1077. For x := 1 to length(s)do
  1078. if (t[ord(s[x])] = length(s)) then
  1079. t[ord(s[x])] := x-1;
  1080. end;
  1081. function BMBScan(var Block; Size: Sw_Word;const Str: String;const bt:BTable): Sw_Integer;
  1082. Var
  1083. buffer : Array[0..MaxBufLength-1] of Byte Absolute block;
  1084. s2 : String;
  1085. len : Sw_Word;
  1086. numb : Sw_Integer;
  1087. found : Boolean;
  1088. begin
  1089. len:=length(str);
  1090. if len>size then
  1091. begin
  1092. BMBScan := NotFoundValue;
  1093. exit;
  1094. end;
  1095. SetLength(S2,len); { sets the length to that of the search String }
  1096. found:=False;
  1097. numb:=size-len;
  1098. While (not found) and (numb>=0) do
  1099. begin
  1100. { partial match }
  1101. if buffer[numb] = ord(str[1]) then
  1102. begin
  1103. { less partial! }
  1104. if buffer[numb+pred(len)] = ord(str[len]) then
  1105. begin
  1106. move(buffer[numb],s2[1],len);
  1107. if (str=s2) then
  1108. begin
  1109. found:=true;
  1110. break;
  1111. end;
  1112. end;
  1113. dec(numb);
  1114. end
  1115. else
  1116. dec(numb,Bt[buffer[numb]]);
  1117. end;
  1118. if not found then
  1119. BMBScan := NotFoundValue
  1120. else
  1121. BMBScan := numb;
  1122. end;
  1123. function BMBIScan(var Block; Size: Sw_Word;const Str: String;const bt:BTable): Sw_Integer;
  1124. Var
  1125. buffer : Array[0..MaxBufLength-1] of Char Absolute block;
  1126. len,
  1127. x : Sw_Word;
  1128. numb : Sw_Integer;
  1129. found : Boolean;
  1130. p : pchar;
  1131. c : char;
  1132. begin
  1133. len:=length(str);
  1134. if (len=0) or (len>size) then
  1135. begin
  1136. BMBIScan := NotFoundValue;
  1137. exit;
  1138. end;
  1139. found:=False;
  1140. numb:=size-len;
  1141. While (not found) and (numb>=0) do
  1142. begin
  1143. { partial match }
  1144. c:=buffer[numb];
  1145. if c in ['a'..'z'] then
  1146. c:=chr(ord(c)-32);
  1147. if (c=str[1]) then
  1148. begin
  1149. { less partial! }
  1150. p:=@buffer[numb];
  1151. x:=1;
  1152. while (x<=len) do
  1153. begin
  1154. if not(((p^ in ['a'..'z']) and (chr(ord(p^)-32)=str[x])) or
  1155. (p^=str[x])) then
  1156. break;
  1157. inc(p);
  1158. inc(x);
  1159. end;
  1160. if (x>len) then
  1161. begin
  1162. found:=true;
  1163. break;
  1164. end;
  1165. dec(numb);
  1166. end
  1167. else
  1168. dec(numb,Bt[ord(c)]);
  1169. end;
  1170. if not found then
  1171. BMBIScan := NotFoundValue
  1172. else
  1173. BMBIScan := numb;
  1174. end;
  1175. {*****************************************************************************
  1176. PLine,TLineCollection
  1177. *****************************************************************************}
  1178. constructor TCustomLine.Init(const AText: string; AFlags: longint);
  1179. begin
  1180. inherited Init;
  1181. SetText(AText);
  1182. end;
  1183. function TCustomLine.GetText: string;
  1184. begin
  1185. Abstract;GetText:='';
  1186. end;
  1187. procedure TCustomLine.SetText(const AText: string);
  1188. begin
  1189. Abstract;
  1190. end;
  1191. function TCustomLine.GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo;
  1192. begin
  1193. Abstract;
  1194. GetEditorInfo:=nil;
  1195. end;
  1196. function TCustomLine.GetFlags: longint;
  1197. begin
  1198. Abstract;
  1199. GetFlags:=0;
  1200. end;
  1201. procedure TCustomLine.SetFlags(AFlags: longint);
  1202. begin
  1203. Abstract;
  1204. end;
  1205. function TCustomLine.IsFlagSet(AFlag: longint): boolean;{$ifdef USEINLINE}inline;{$endif}
  1206. begin
  1207. IsFlagSet:=(GetFlags and AFlag)=AFlag;
  1208. end;
  1209. procedure TCustomLine.SetFlagState(AFlag: longint; ASet: boolean);
  1210. var N,O: longint;
  1211. begin
  1212. O:=GetFlags; N:=O;
  1213. if ASet then
  1214. N:=N or AFlag
  1215. else
  1216. N:=N and (not AFlag);
  1217. if N<>O then
  1218. SetFlags(N);
  1219. end;
  1220. procedure TCustomLine.AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor);
  1221. begin
  1222. { Abstract }
  1223. end;
  1224. procedure TCustomLine.RemoveEditorInfo(AEditor: PCustomCodeEditor);
  1225. begin
  1226. { Abstract }
  1227. end;
  1228. destructor TCustomLine.Done;
  1229. begin
  1230. inherited Done;
  1231. end;
  1232. function TLineCollection.At(Index: sw_Integer): PCustomLine;
  1233. begin
  1234. At:=inherited At(Index);
  1235. end;
  1236. constructor TFold.Init(AEditor: PCustomCodeEditor; AParentFold: PFold; ACollapsed: boolean);
  1237. begin
  1238. inherited Init;
  1239. New(Childs, Init(10,10));
  1240. Editor:=AEditor;
  1241. ParentFold:=AParentFold;
  1242. if Assigned(ParentFold) then
  1243. ParentFold^.AddChildReference(@Self);
  1244. Collapsed_:=ACollapsed;
  1245. if Assigned(AEditor) then
  1246. Editor^.RegisterFold(@Self);
  1247. end;
  1248. procedure TFold.AddReference(P: PObject);
  1249. begin
  1250. Inc(ReferenceCount);
  1251. end;
  1252. procedure TFold.RemoveReference(P: PObject);
  1253. begin
  1254. Dec(ReferenceCount);
  1255. if CanDispose then
  1256. Free;
  1257. end;
  1258. procedure TFold.AddLineReference(Line: PEditorLineInfo);
  1259. begin
  1260. Inc(LineCount_);
  1261. AddReference(Line);
  1262. end;
  1263. procedure TFold.RemoveLineReference(Line: PEditorLineInfo);
  1264. begin
  1265. Dec(LineCount_);
  1266. RemoveReference(Line);
  1267. end;
  1268. procedure TFold.AddChildReference(Fold: PFold);
  1269. begin
  1270. Childs^.Insert(Fold);
  1271. AddReference(Fold);
  1272. end;
  1273. procedure TFold.RemoveChildReference(Fold: PFold);
  1274. begin
  1275. Childs^.Delete(Fold);
  1276. RemoveReference(Fold);
  1277. end;
  1278. function TFold.CanDispose: boolean;
  1279. begin
  1280. CanDispose:=ReferenceCount<=0;
  1281. end;
  1282. function TFold.IsCollapsed: boolean;
  1283. var C: boolean;
  1284. begin
  1285. C:=Collapsed_;
  1286. if Assigned(ParentFold) then C:=C or ParentFold^.IsCollapsed;
  1287. IsCollapsed:=C;
  1288. end;
  1289. function TFold.IsParent(AFold: PFold): boolean;
  1290. var P: boolean;
  1291. begin
  1292. P:=(ParentFold=AFold);
  1293. if Assigned(ParentFold) then P:=P or ParentFold^.IsParent(AFold);
  1294. IsParent:=P;
  1295. end;
  1296. function TFold.GetLineCount: sw_integer;
  1297. var Count: sw_integer;
  1298. procedure AddIt(P: PFold);
  1299. begin
  1300. Inc(Count,P^.GetLineCount);
  1301. end;
  1302. begin
  1303. Count:=LineCount_;
  1304. if assigned(Childs) then Childs^.ForEach(@AddIt);
  1305. GetLineCount:=Count;
  1306. end;
  1307. procedure TFold.Collapse(ACollapse: boolean);
  1308. begin
  1309. if ACollapse<>Collapsed_ then
  1310. begin
  1311. Collapsed_:=ACollapse;
  1312. if (not Collapsed_) and Assigned(ParentFold) then
  1313. ParentFold^.Collapse(false);
  1314. Changed;
  1315. end;
  1316. end;
  1317. procedure TFold.Changed;
  1318. begin
  1319. if Assigned(Editor) then
  1320. Editor^.FoldChanged(@Self);
  1321. end;
  1322. function TFold.GetLevel: sw_integer;
  1323. var Level: sw_integer;
  1324. begin
  1325. Level:=0;
  1326. if Assigned(ParentFold) then
  1327. Inc(Level,1+ParentFold^.GetLevel);
  1328. GetLevel:=Level;
  1329. end;
  1330. destructor TFold.Done;
  1331. begin
  1332. if Assigned(ParentFold) then
  1333. ParentFold^.RemoveChildReference(@Self);
  1334. if Assigned(Editor) then
  1335. Editor^.UnRegisterFold(@Self);
  1336. Childs^.DeleteAll; Dispose(Childs, Done);
  1337. inherited Done;
  1338. end;
  1339. function TFoldCollection.At(Index: sw_Integer): PFold;
  1340. begin
  1341. At:=inherited At(Index);
  1342. end;
  1343. constructor TEditorLineInfo.Init(AEditor: PCustomCodeEditor);
  1344. begin
  1345. inherited Init;
  1346. Editor:=AEditor;
  1347. end;
  1348. function TEditorLineInfo.GetFormat: string;
  1349. begin
  1350. GetFormat:=GetStr(Format);
  1351. end;
  1352. procedure TEditorLineInfo.SetFormat(const AFormat: string);
  1353. begin
  1354. SetStr(Format,AFormat);
  1355. end;
  1356. procedure TEditorLineInfo.SetFold(AFold: PFold);
  1357. begin
  1358. if Assigned(Fold) then
  1359. Fold^.RemoveLineReference(@Self);
  1360. Fold:=AFold;
  1361. if Assigned(Fold) then
  1362. Fold^.AddLineReference(@Self);
  1363. end;
  1364. destructor TEditorLineInfo.Done;
  1365. begin
  1366. if Format<>nil then
  1367. DisposeStr(Format);
  1368. Format:=nil;
  1369. SetFold(nil);
  1370. inherited Done;
  1371. end;
  1372. function TEditorLineInfoCollection.At(Index: sw_Integer): PEditorLineInfo;
  1373. begin
  1374. At:=inherited At(Index);
  1375. end;
  1376. function TEditorBindingCollection.At(Index: sw_Integer): PEditorBinding;
  1377. begin
  1378. At:=inherited At(Index);
  1379. end;
  1380. constructor TEditorBinding.Init(AEditor: PCustomCodeEditor);
  1381. begin
  1382. inherited Init;
  1383. Editor:=AEditor;
  1384. end;
  1385. destructor TEditorBinding.Done;
  1386. begin
  1387. inherited Done;
  1388. end;
  1389. constructor TCustomCodeEditorCore.Init;
  1390. begin
  1391. inherited Init;
  1392. New(Bindings, Init(10,10));
  1393. end;
  1394. procedure TCustomCodeEditorCore.BindEditor(AEditor: PCustomCodeEditor);
  1395. var B: PEditorBinding;
  1396. Count,I,Idx: sw_integer;
  1397. L: PCustomLine;
  1398. begin
  1399. assert(Aeditor<>nil);
  1400. New(B, Init(AEditor));
  1401. Bindings^.Insert(B);
  1402. Idx:=Bindings^.IndexOf(B);
  1403. Count:=GetLineCount;
  1404. for I:=0 to Count-1 do
  1405. begin
  1406. L:=GetLine(I);
  1407. if Assigned(L) then
  1408. L^.AddEditorInfo(Idx,AEditor);
  1409. end;
  1410. BindingsChanged;
  1411. end;
  1412. procedure TCustomCodeEditorCore.UnBindEditor(AEditor: PCustomCodeEditor);
  1413. var B: PEditorBinding;
  1414. Count,I: sw_integer;
  1415. L: PCustomLine;
  1416. begin
  1417. assert(Aeditor<>nil);
  1418. B:=SearchBinding(AEditor);
  1419. if Assigned(B) then
  1420. begin
  1421. Count:=GetLineCount;
  1422. for I:=0 to Count-1 do
  1423. begin
  1424. L:=GetLine(I);
  1425. if Assigned(L) then
  1426. L^.RemoveEditorInfo(AEditor);
  1427. end;
  1428. Bindings^.Free(B);
  1429. BindingsChanged;
  1430. end;
  1431. end;
  1432. function TCustomCodeEditorCore.IsEditorBound(AEditor: PCustomCodeEditor): boolean;
  1433. begin
  1434. IsEditorBound:=SearchBinding(AEditor)<>nil;
  1435. end;
  1436. function TCustomCodeEditorCore.GetBindingCount: sw_integer;
  1437. begin
  1438. GetBindingCount:=Bindings^.Count;
  1439. end;
  1440. function TCustomCodeEditorCore.GetBindingIndex(AEditor: PCustomCodeEditor): sw_integer;
  1441. var B: PEditorBinding;
  1442. begin
  1443. B:=SearchBinding(AEditor);
  1444. GetBindingIndex:=Bindings^.IndexOf(B);
  1445. end;
  1446. function TCustomCodeEditorCore.SearchBinding(AEditor: PCustomCodeEditor): PEditorBinding;
  1447. function SearchEditor(P: PEditorBinding): boolean;
  1448. begin
  1449. SearchEditor:=P^.Editor=AEditor;
  1450. end;
  1451. begin
  1452. SearchBinding:=Bindings^.FirstThat(@SearchEditor);
  1453. end;
  1454. function TCustomCodeEditorCore.CanDispose: boolean;
  1455. begin
  1456. CanDispose:=Assigned(Bindings) and (Bindings^.Count=0);
  1457. end;
  1458. function TCustomCodeEditorCore.GetModified: boolean;
  1459. begin
  1460. Abstract;
  1461. GetModified:=true;
  1462. end;
  1463. function TCustomCodeEditorCore.GetChangedLine: sw_integer;
  1464. begin
  1465. GetChangedLine:=ChangedLine;
  1466. end;
  1467. procedure TCustomCodeEditorCore.SetModified(AModified: boolean);
  1468. begin
  1469. Abstract;
  1470. end;
  1471. function TCustomCodeEditorCore.GetStoreUndo: boolean;
  1472. begin
  1473. Abstract;
  1474. GetStoreUndo:=false;
  1475. end;
  1476. procedure TCustomCodeEditorCore.SetStoreUndo(AStore: boolean);
  1477. begin
  1478. Abstract;
  1479. end;
  1480. function TCustomCodeEditorCore.GetSyntaxCompleted: boolean;
  1481. begin
  1482. Abstract;
  1483. GetSyntaxCompleted:=true;
  1484. end;
  1485. procedure TCustomCodeEditorCore.SetSyntaxCompleted(SC : boolean);
  1486. begin
  1487. Abstract;
  1488. end;
  1489. function TCustomCodeEditorCore.IsClipboard: Boolean;
  1490. function IsClip(P: PEditorBinding): boolean;
  1491. begin
  1492. IsClip:=(P^.Editor=Clipboard);
  1493. end;
  1494. begin
  1495. IsClipBoard:=Bindings^.FirstThat(@IsClip)<>nil;
  1496. end;
  1497. function TCustomCodeEditorCore.GetTabSize: integer;
  1498. begin
  1499. Abstract;
  1500. GetTabSize:=0;
  1501. end;
  1502. procedure TCustomCodeEditorCore.SetTabSize(ATabSize: integer);
  1503. begin
  1504. Abstract;
  1505. end;
  1506. function TCustomCodeEditorCore.GetIndentSize: integer;
  1507. begin
  1508. Abstract;
  1509. GetIndentSize:=0;
  1510. end;
  1511. procedure TCustomCodeEditorCore.SetIndentSize(AIndentSize: integer);
  1512. begin
  1513. Abstract;
  1514. end;
  1515. procedure TCustomCodeEditorCore.LimitsChanged;
  1516. begin
  1517. if Locked then
  1518. LimitsChangedCalled:=true
  1519. else
  1520. DoLimitsChanged;
  1521. end;
  1522. procedure TCustomCodeEditorCore.ContentsChanged;
  1523. begin
  1524. if Locked then
  1525. ContentsChangedCalled:=true
  1526. else
  1527. DoContentsChanged;
  1528. end;
  1529. procedure TCustomCodeEditorCore.ModifiedChanged;
  1530. begin
  1531. if Locked then
  1532. ModifiedChangedCalled:=true
  1533. else
  1534. DoModifiedChanged;
  1535. end;
  1536. procedure TCustomCodeEditorCore.TabSizeChanged;
  1537. begin
  1538. if Locked then
  1539. TabSizeChangedCalled:=true
  1540. else
  1541. DoTabSizeChanged;
  1542. end;
  1543. procedure TCustomCodeEditorCore.StoreUndoChanged;
  1544. begin
  1545. if Locked then
  1546. StoreUndoChangedCalled:=true
  1547. else
  1548. DoStoreUndoChanged;
  1549. end;
  1550. procedure TCustomCodeEditorCore.BindingsChanged;
  1551. procedure CallIt(P: PEditorBinding);
  1552. begin
  1553. P^.Editor^.BindingsChanged;
  1554. end;
  1555. begin
  1556. Bindings^.ForEach(@CallIt);
  1557. end;
  1558. procedure TCustomCodeEditorCore.DoLimitsChanged;
  1559. procedure CallIt(P: PEditorBinding);
  1560. begin
  1561. P^.Editor^.DoLimitsChanged;
  1562. end;
  1563. begin
  1564. Bindings^.ForEach(@CallIt);
  1565. end;
  1566. procedure TCustomCodeEditorCore.DoContentsChanged;
  1567. procedure CallIt(P: PEditorBinding);
  1568. begin
  1569. P^.Editor^.ContentsChanged;
  1570. end;
  1571. begin
  1572. Bindings^.ForEach(@CallIt);
  1573. end;
  1574. procedure TCustomCodeEditorCore.DoModifiedChanged;
  1575. procedure CallIt(P: PEditorBinding);
  1576. begin
  1577. P^.Editor^.ModifiedChanged;
  1578. end;
  1579. begin
  1580. Bindings^.ForEach(@CallIt);
  1581. end;
  1582. procedure TCustomCodeEditorCore.DoTabSizeChanged;
  1583. procedure CallIt(P: PEditorBinding);
  1584. begin
  1585. P^.Editor^.TabSizeChanged;
  1586. end;
  1587. begin
  1588. Bindings^.ForEach(@CallIt);
  1589. end;
  1590. procedure TCustomCodeEditorCore.UpdateUndoRedo(cm : word; action : byte);
  1591. procedure CallIt(P: PEditorBinding);
  1592. begin
  1593. if (P^.Editor^.State and sfActive)<>0 then
  1594. begin
  1595. P^.Editor^.UpdateUndoRedo(cm,action);
  1596. if cm=cmUndo then
  1597. begin
  1598. P^.Editor^.SetCmdState(UndoCmd,true);
  1599. P^.Editor^.SetCmdState(RedoCmd,false);
  1600. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  1601. end;
  1602. end;
  1603. end;
  1604. begin
  1605. Bindings^.ForEach(@CallIt);
  1606. end;
  1607. procedure TCustomCodeEditorCore.DoStoreUndoChanged;
  1608. procedure CallIt(P: PEditorBinding);
  1609. begin
  1610. P^.Editor^.StoreUndoChanged;
  1611. end;
  1612. begin
  1613. Bindings^.ForEach(@CallIt);
  1614. end;
  1615. procedure TCustomCodeEditorCore.DoSyntaxStateChanged;
  1616. procedure CallIt(P: PEditorBinding);
  1617. begin
  1618. P^.Editor^.SyntaxStateChanged;
  1619. end;
  1620. begin
  1621. Bindings^.ForEach(@CallIt);
  1622. end;
  1623. function TCustomCodeEditorCore.GetLastVisibleLine : sw_integer;
  1624. var
  1625. y : sw_integer;
  1626. procedure CallIt(P: PEditorBinding);
  1627. begin
  1628. if y < P^.Editor^.Delta.Y+P^.Editor^.Size.Y then
  1629. y:=P^.Editor^.Delta.Y+P^.Editor^.Size.Y;
  1630. end;
  1631. begin
  1632. y:=0;
  1633. Bindings^.ForEach(@CallIt);
  1634. GetLastVisibleLine:=y;
  1635. end;
  1636. function TCustomCodeEditorCore.SaveToStream(Editor: PCustomCodeEditor; Stream: PStream): boolean;
  1637. var A,B: TPoint;
  1638. begin
  1639. A.Y:=0; A.X:=0;
  1640. B.Y:=GetLineCount-1;
  1641. if GetLineCount>0 then
  1642. B.X:=length(GetDisplayText(B.Y))
  1643. else
  1644. B.X:=0;
  1645. SaveToStream:=SaveAreaToStream(Editor,Stream,A,B);
  1646. end;
  1647. procedure TCustomCodeEditorCore.ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean);
  1648. begin
  1649. Abstract;
  1650. end;
  1651. procedure TCustomCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string);
  1652. begin
  1653. Abstract;
  1654. end;
  1655. function TCustomCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string;
  1656. begin
  1657. Abstract;
  1658. IGetLineFormat:='';
  1659. end;
  1660. procedure TCustomCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string);
  1661. begin
  1662. Abstract;
  1663. end;
  1664. function TCustomCodeEditorCore.CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer;
  1665. var S: string;
  1666. TabSize,CP,RX,NextInc: sw_integer;
  1667. begin
  1668. S:=GetLineText(Line);
  1669. (* this would fasten the code
  1670. but UseTabCharacters is set for Editor not for EditorCore
  1671. objects,which is dangerous anyway and should be changed ... PM
  1672. if not IsFlagSet(efUseTabCharacters) then
  1673. begin
  1674. if CharIdx<=Length(S) then
  1675. CharIdxToLinePos:=CharIdx-1
  1676. else
  1677. CharIdxToLinePos:=Length(S)-1;
  1678. exit;
  1679. end; *)
  1680. TabSize:=GetTabSize;
  1681. CP:=1; RX:=0;
  1682. NextInc:=0;
  1683. while {(CP<=length(S)) and }(CP<=CharIdx) do
  1684. begin
  1685. if NextInc>0 then
  1686. Inc(RX,NextInc);
  1687. if (CP<=length(S)) and (S[CP]=TAB) then
  1688. NextInc:=TabSize-(RX mod TabSize) -1
  1689. else
  1690. NextInc:=0;
  1691. Inc(RX);
  1692. Inc(CP);
  1693. end;
  1694. CharIdxToLinePos:=RX-1;
  1695. end;
  1696. function TCustomCodeEditorCore.LinePosToCharIdx(Line,X: sw_integer): sw_integer;
  1697. var S: string;
  1698. TabSize,CP,RX: sw_integer;
  1699. begin
  1700. TabSize:=GetTabSize;
  1701. S:=GetLineText(Line);
  1702. (*
  1703. if not IsFlagSet(efUseTabCharacters) then
  1704. begin
  1705. if S='' then
  1706. CP:=0
  1707. else if (Line<Length(S)) then
  1708. LinePosToCharIdx:=Line+1
  1709. else
  1710. LinePosToCharIdx:=Length(S);
  1711. exit;
  1712. end; *)
  1713. if S='' then
  1714. CP:=0
  1715. else
  1716. begin
  1717. CP:=0; RX:=0;
  1718. while (RX<=X) and (CP<=length(S)) do
  1719. begin
  1720. Inc(CP);
  1721. if (CP<=length(S)) and
  1722. (S[CP]=TAB) then
  1723. Inc(RX,TabSize-(RX mod TabSize))
  1724. else
  1725. Inc(RX);
  1726. end;
  1727. end;
  1728. LinePosToCharIdx:=CP;
  1729. end;
  1730. function TCustomCodeEditorCore.GetLineCount: sw_integer;
  1731. begin
  1732. Abstract;
  1733. GetLineCount:=0;
  1734. end;
  1735. function TCustomCodeEditorCore.GetLine(LineNo: sw_integer): PCustomLine;
  1736. begin
  1737. Abstract;
  1738. GetLine:=nil;
  1739. end;
  1740. function TCustomCodeEditorCore.GetLineText(LineNo: sw_integer): string;
  1741. begin
  1742. Abstract;
  1743. GetLineText:='';
  1744. end;
  1745. procedure TCustomCodeEditorCore.SetDisplayText(I: sw_integer;const S: string);
  1746. begin
  1747. Abstract;
  1748. end;
  1749. function TCustomCodeEditorCore.GetDisplayText(I: sw_integer): string;
  1750. begin
  1751. Abstract;
  1752. GetDisplayText:='';
  1753. end;
  1754. procedure TCustomCodeEditorCore.SetLineText(I: sw_integer;const S: string);
  1755. begin
  1756. Abstract;
  1757. end;
  1758. procedure TCustomCodeEditorCore.GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:string);
  1759. begin
  1760. IGetDisplayTextFormat(SearchBinding(Editor),I,DT,DF);
  1761. end;
  1762. function TCustomCodeEditorCore.GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): string;
  1763. begin
  1764. GetLineFormat:=IGetLineFormat(SearchBinding(Editor),I);
  1765. end;
  1766. procedure TCustomCodeEditorCore.SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer; const S: string);
  1767. begin
  1768. ISetLineFormat(SearchBinding(Editor),I,S);
  1769. end;
  1770. procedure TCustomCodeEditorCore.DeleteAllLines;
  1771. begin
  1772. Abstract;
  1773. end;
  1774. procedure TCustomCodeEditorCore.DeleteLine(I: sw_integer);
  1775. begin
  1776. Abstract;
  1777. end;
  1778. function TCustomCodeEditorCore.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
  1779. begin
  1780. Abstract;
  1781. InsertLine:=nil; { eliminate compiler warning }
  1782. end;
  1783. procedure TCustomCodeEditorCore.AddLine(const S: string);
  1784. begin
  1785. Abstract;
  1786. end;
  1787. procedure TCustomCodeEditorCore.GetContent(ALines: PUnsortedStringCollection);
  1788. begin
  1789. Abstract;
  1790. end;
  1791. procedure TCustomCodeEditorCore.SetContent(ALines: PUnsortedStringCollection);
  1792. begin
  1793. Abstract;
  1794. end;
  1795. function TCustomCodeEditorCore.Locked: boolean;
  1796. begin
  1797. Locked:=LockFlag>0;
  1798. end;
  1799. procedure TCustomCodeEditorCore.Lock(AEditor: PCustomCodeEditor);
  1800. begin
  1801. Inc(LockFlag);
  1802. end;
  1803. procedure TCustomCodeEditorCore.UnLock(AEditor: PCustomCodeEditor);
  1804. begin
  1805. {$ifdef DEBUG}
  1806. if LockFlag=0 then
  1807. Bug('negative lockflag',nil)
  1808. else
  1809. {$endif DEBUG}
  1810. Dec(LockFlag);
  1811. if (LockFlag>0) then
  1812. Exit;
  1813. if LimitsChangedCalled then
  1814. begin
  1815. DoLimitsChanged;
  1816. LimitsChangedCalled:=false;
  1817. end;
  1818. if ModifiedChangedCalled then
  1819. begin
  1820. DoModifiedChanged;
  1821. ModifiedChangedCalled:=false;
  1822. end;
  1823. if TabSizeChangedCalled then
  1824. begin
  1825. DoTabSizeChanged;
  1826. TabSizeChangedCalled:=false;
  1827. end;
  1828. if StoreUndoChangedCalled then
  1829. begin
  1830. DoStoreUndoChanged;
  1831. StoreUndoChangedCalled:=false;
  1832. end;
  1833. if ContentsChangedCalled then
  1834. begin
  1835. DoContentsChanged;
  1836. ContentsChangedCalled:=false;
  1837. end;
  1838. end;
  1839. function TCustomCodeEditorCore.UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer;
  1840. var MinLine: sw_integer;
  1841. procedure CallIt(P: PEditorBinding);
  1842. var I: sw_integer;
  1843. begin
  1844. I:=DoUpdateAttrs(P^.Editor,FromLine,Attrs);
  1845. if (I<MinLine) or (MinLine=-1) then MinLine:=I;
  1846. end;
  1847. begin
  1848. MinLine:=-1;
  1849. Bindings^.ForEach(@CallIt);
  1850. UpdateAttrs:=MinLine;
  1851. end;
  1852. function TCustomCodeEditorCore.UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer;
  1853. var MinLine: sw_integer;
  1854. procedure CallIt(P: PEditorBinding);
  1855. var I: sw_integer;
  1856. begin
  1857. I:=DoUpdateAttrsRange(P^.Editor,FromLine,ToLine,Attrs);
  1858. if (I<MinLine) or (MinLine=-1) then MinLine:=I;
  1859. end;
  1860. begin
  1861. MinLine:=-1;
  1862. Bindings^.ForEach(@CallIt);
  1863. UpdateAttrsRange:=MinLine;
  1864. end;
  1865. function TCustomCodeEditorCore.DoUpdateAttrs(Editor: PCustomCodeEditor; FromLine: sw_integer; Attrs: byte): sw_integer;
  1866. type
  1867. TCharClass = (ccWhiteSpace,ccTab,ccAlpha,
  1868. ccNumber,ccHexNumber,ccRealNumber,
  1869. ccHash,ccSymbol);
  1870. var
  1871. SymbolIndex: Sw_integer;
  1872. CurrentCommentType : Byte;
  1873. FirstCC,LastCC: TCharClass;
  1874. InAsm,InComment,InSingleLineComment,InDirective,InString: boolean;
  1875. X,ClassStart: Sw_integer;
  1876. SymbolConcat: string;
  1877. LineText,Format: string;
  1878. function MatchSymbol(const What, S: string): boolean;
  1879. var Match: boolean;
  1880. begin
  1881. Match:=false;
  1882. if length(What)>=length(S) then
  1883. if copy(What,1+length(What)-length(S),length(S))=S then
  1884. Match:=true;
  1885. MatchSymbol:=Match;
  1886. end;
  1887. var MatchedSymbol: boolean;
  1888. MatchingSymbol: string;
  1889. type TPartialType = (pmNone,pmLeft,pmRight,pmAny);
  1890. function MatchesAnySpecSymbol(SClass: TSpecSymbolClass; PartialMatch: TPartialType): boolean;
  1891. var S: pstring;
  1892. I: Sw_integer;
  1893. Match,Found: boolean;
  1894. begin
  1895. Found:=false;
  1896. if SymbolConcat<>'' then
  1897. for I:=1 to Editor^.GetSpecSymbolCount(SClass) do
  1898. begin
  1899. SymbolIndex:=I;
  1900. S:=Editor^.GetSpecSymbol(SClass,I-1);
  1901. if (length(SymbolConcat)<length(S^)) or
  1902. ((PartialMatch=pmNone) and (length(S^)<>length(SymbolConcat)))
  1903. then
  1904. Match:=false
  1905. else
  1906. begin
  1907. case PartialMatch of
  1908. pmNone : Match:=SymbolConcat=S^;
  1909. pmRight:
  1910. Match:=copy(SymbolConcat,length(SymbolConcat)-length(S^)+1,length(S^))=S^;
  1911. else Match:=MatchSymbol(SymbolConcat,S^);
  1912. end;
  1913. end;
  1914. if Match then
  1915. begin
  1916. MatchingSymbol:=S^; Found:=true; Break;
  1917. end;
  1918. end;
  1919. MatchedSymbol:=MatchedSymbol or Found;
  1920. MatchesAnySpecSymbol:=Found;
  1921. end;
  1922. function MatchesAsmSpecSymbol(Const OrigWhat: string; SClass: TSpecSymbolClass): boolean;
  1923. var What : String;
  1924. S: pstring;
  1925. I: Sw_integer;
  1926. Match,Found: boolean;
  1927. begin
  1928. Found:=false;
  1929. What:=UpcaseStr(OrigWhat);
  1930. if What<>'' then
  1931. for I:=1 to Editor^.GetSpecSymbolCount(SClass) do
  1932. begin
  1933. SymbolIndex:=I;
  1934. S:=Editor^.GetSpecSymbol(SClass,I-1);
  1935. if (length(S^)<>length(What)) then
  1936. Match:=false
  1937. else
  1938. begin
  1939. {if CaseInsensitive then
  1940. S:=UpcaseStr(S); asm symbols need to be uppercased PM }
  1941. {case PartialMatch of
  1942. pmNone : }
  1943. Match:=What=S^;
  1944. { pmRight:
  1945. Match:=copy(What,length(What)-length(S)+1,length(S))=S;
  1946. else Match:=MatchSymbol(What,S);
  1947. end; }
  1948. end;
  1949. if Match then
  1950. begin
  1951. MatchingSymbol:=S^;
  1952. Found:=true;
  1953. Break;
  1954. end;
  1955. end;
  1956. // MatchedSymbol:=MatchedSymbol or Found;
  1957. MatchesAsmSpecSymbol:=Found;
  1958. end;
  1959. function IsCommentPrefix: boolean;
  1960. begin
  1961. IsCommentPrefix:=MatchesAnySpecSymbol(ssCommentPrefix,pmLeft);
  1962. end;
  1963. {** **}
  1964. function IsSingleLineCommentPrefix: boolean;
  1965. begin
  1966. IsSingleLineCommentPrefix:=MatchesAnySpecSymbol(ssCommentSingleLinePrefix,pmLeft);
  1967. end;
  1968. function IsCommentSuffix: boolean;
  1969. begin
  1970. IsCommentSuffix:=(MatchesAnySpecSymbol(ssCommentSuffix,pmRight))
  1971. and (CurrentCommentType=SymbolIndex);
  1972. end;
  1973. function IsStringPrefix: boolean;
  1974. begin
  1975. IsStringPrefix:=MatchesAnySpecSymbol(ssStringPrefix,pmLeft);
  1976. end;
  1977. function IsStringSuffix: boolean;
  1978. begin
  1979. IsStringSuffix:=MatchesAnySpecSymbol(ssStringSuffix,pmRight);
  1980. end;
  1981. function IsDirectivePrefix: boolean;
  1982. begin
  1983. IsDirectivePrefix:=MatchesAnySpecSymbol(ssDirectivePrefix,pmLeft);
  1984. end;
  1985. function IsDirectiveSuffix: boolean;
  1986. begin
  1987. IsDirectiveSuffix:=MatchesAnySpecSymbol(ssDirectiveSuffix,pmRight);
  1988. end;
  1989. function IsAsmPrefix(const WordS: string): boolean;
  1990. { var
  1991. StoredMatchedSymbol : boolean;}
  1992. begin
  1993. {StoredMatchedSymbol:=MatchedSymbol;}
  1994. IsAsmPrefix:=MatchesAsmSpecSymbol(WordS,ssAsmPrefix);
  1995. {MatchedSymbol:=StoredMatchedSymbol;}
  1996. end;
  1997. function IsAsmSuffix(const WordS: string): boolean;
  1998. {var
  1999. StoredMatchedSymbol : boolean;}
  2000. begin
  2001. {StoredMatchedSymbol:=MatchedSymbol;}
  2002. IsAsmSuffix:=MatchesAsmSpecSymbol(WordS,ssAsmSuffix);
  2003. {MatchedSymbol:=StoredMatchedSymbol;}
  2004. end;
  2005. function GetCharClass(C: char): TCharClass;
  2006. var CC: TCharClass;
  2007. begin
  2008. (*
  2009. WhiteSpaceChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = [#0,#32,#255];
  2010. TabChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = [#9];
  2011. HashChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['#'];
  2012. AlphaChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['A'..'Z','a'..'z','_'];
  2013. NumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['0'..'9'];
  2014. HexNumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['0'..'9','A'..'F','a'..'f'];
  2015. RealNumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['E','e','.'{,'+','-'}];
  2016. *)
  2017. if C in {$ifdef USE_UNTYPEDSET}[#0,#32,#255]{$else}WhiteSpaceChars{$endif} then
  2018. CC:=ccWhiteSpace
  2019. else if C in {$ifdef USE_UNTYPEDSET}[#9]{$else}TabChars{$endif} then
  2020. CC:=ccTab
  2021. else if C in {$ifdef USE_UNTYPEDSET}['#']{$else}HashChars{$endif} then
  2022. CC:=ccHash
  2023. else if (LastCC=ccHexNumber) and (C in {$ifdef USE_UNTYPEDSET}['0'..'9','A'..'F','a'..'f']{$else}HexNumberChars{$endif}) then
  2024. CC:=ccHexNumber
  2025. else if C in {$ifdef USE_UNTYPEDSET}['0'..'9']{$else}NumberChars{$endif} then
  2026. CC:=ccNumber
  2027. else if (LastCC=ccNumber) and (C in {$ifdef USE_UNTYPEDSET}['E','e','.']{$else}RealNumberChars{$endif}) then
  2028. begin
  2029. if (C='.') then
  2030. begin
  2031. if (X>=length(LineText)) or
  2032. (LineText[X+1]='.') then
  2033. cc:=ccSymbol
  2034. else
  2035. cc:=ccRealNumber;
  2036. end
  2037. else {'E','e'}
  2038. begin
  2039. if (X>=length(LineText)) or
  2040. (LineText[X+1]in ['+','-','0'..'9']) then
  2041. cc:=ccRealNumber
  2042. else
  2043. cc:=ccAlpha
  2044. end;
  2045. end
  2046. else if C in {$ifdef USE_UNTYPEDSET}['A'..'Z','a'..'z','_']{$else}AlphaChars{$endif} then CC:=ccAlpha else
  2047. CC:=ccSymbol;
  2048. GetCharClass:=CC;
  2049. end;
  2050. procedure FormatWord(SClass: TCharClass; StartX:Sw_integer;EndX: Sw_integer);
  2051. var
  2052. C: byte;
  2053. WordS: string;
  2054. begin
  2055. C:=0;
  2056. WordS:=copy(LineText,StartX,EndX-StartX+1);
  2057. if (InAsm=true) and (InComment=false) and (InString=false) and
  2058. (InDirective=false) and (SClass=ccAlpha) and IsAsmSuffix(WordS) then InAsm:=false;
  2059. if InDirective then C:=coDirectiveColor else
  2060. if InComment then C:=coCommentColor else
  2061. if InString then C:=coStringColor else
  2062. if InAsm then
  2063. begin
  2064. if (SClass=ccAlpha) and Editor^.IsAsmReservedWord(WordS) then
  2065. C:=coReservedWordColor
  2066. else
  2067. C:=coAssemblerColor;
  2068. end
  2069. else
  2070. case SClass of
  2071. ccWhiteSpace :
  2072. C:=coWhiteSpaceColor;
  2073. ccTab :
  2074. C:=coTabColor;
  2075. ccHexNumber:
  2076. C:=coHexNumberColor;
  2077. ccNumber,
  2078. ccRealNumber :
  2079. C:=coNumberColor;
  2080. ccHash :
  2081. C:=coStringColor;
  2082. ccSymbol :
  2083. C:=coSymbolColor;
  2084. ccAlpha :
  2085. begin
  2086. if Editor^.IsReservedWord(WordS) then
  2087. C:=coReservedWordColor
  2088. else
  2089. C:=coIdentifierColor;
  2090. end;
  2091. end;
  2092. if EndX+1>=StartX then
  2093. FillChar(Format[StartX],EndX+1-StartX,C);
  2094. if (InString=false) and (InAsm=false) and (InComment=false) and
  2095. (InDirective=false) and (SClass=ccAlpha) and IsAsmPrefix(WordS) then
  2096. InAsm:=true;
  2097. end;
  2098. procedure ProcessChar(C: char);
  2099. var CC: TCharClass;
  2100. EX: Sw_integer;
  2101. EndComment: pstring;
  2102. begin
  2103. CC:=GetCharClass(C);
  2104. if ClassStart=X then
  2105. FirstCC:=CC;
  2106. if ( (CC<>LastCC) and
  2107. (
  2108. ((FirstCC=ccNumber) and (CC<>ccRealNumber) {and (CC<>ccNumber)}) or
  2109. (((CC<>ccAlpha) or (LastCC<>ccNumber) ) and
  2110. ( (CC<>ccNumber) or (LastCC<>ccAlpha) ) and
  2111. ( (CC<>ccNumber) or (LastCC<>ccHash) ) and
  2112. ( (CC<>ccRealNumber) or (LastCC<>ccNumber))
  2113. ))) or
  2114. (X>length(LineText)) or (CC=ccSymbol) then
  2115. begin
  2116. MatchedSymbol:=false;
  2117. EX:=X-1;
  2118. if (CC=ccSymbol) then
  2119. begin
  2120. if length(SymbolConcat)>=High(SymbolConcat) then
  2121. Delete(SymbolConcat,1,1);
  2122. SymbolConcat:=SymbolConcat+C;
  2123. if InComment and IsCommentSuffix then
  2124. Inc(EX) else
  2125. if InString and IsStringSuffix then
  2126. Inc(EX) else
  2127. if InDirective and IsDirectiveSuffix then
  2128. Inc(EX);
  2129. end;
  2130. if CC=ccRealNumber then
  2131. Inc(EX);
  2132. if (C='$') and (MatchedSymbol=false) and (IsDirectivePrefix=false) then
  2133. CC:=ccHexNumber;
  2134. if CC<>ccSymbol then SymbolConcat:='';
  2135. FormatWord(LastCC,ClassStart,EX);
  2136. ClassStart:=EX+1;
  2137. if ClassStart=X then
  2138. FirstCC:=CC;
  2139. case CC of
  2140. ccAlpha : ;
  2141. ccNumber :
  2142. if (LastCC<>ccAlpha) then;
  2143. ccSymbol :
  2144. if (InComment=true) and (CurrentCommentType=1) and
  2145. (InDirective=false) and IsDirectivePrefix then
  2146. begin
  2147. InDirective:=true;
  2148. InComment:=false;
  2149. Dec(ClassStart,length(MatchingSymbol)-1);
  2150. end
  2151. else if (InComment=false) and
  2152. (InDirective=true) and IsDirectiveSuffix then
  2153. InDirective:=false
  2154. else if (InComment=false) and
  2155. (InString=false) and (InDirective=false) and IsCommentPrefix then
  2156. begin
  2157. InComment:=true;
  2158. CurrentCommentType:=SymbolIndex;
  2159. InSingleLineComment:=IsSingleLineCommentPrefix;
  2160. {InString:=false; }
  2161. Dec(ClassStart,length(MatchingSymbol)-1);
  2162. { Remove (* from SymbolConcat to avoid problem with (*) PM }
  2163. { fixes part of bug 1617 }
  2164. { but removed proper directive prefix detection ... }
  2165. EndComment:=Editor^.GetSpecSymbol(ssCommentSuffix,SymbolIndex);
  2166. if MatchingSymbol[length(MatchingSymbol)]=EndComment^[1] then
  2167. Delete(SymbolConcat,1,length(MatchingSymbol));
  2168. end
  2169. else if InComment and IsCommentSuffix then
  2170. begin
  2171. InComment:=false;
  2172. InString:=false;
  2173. end
  2174. else if (InComment=false) and (InString=false) and IsStringPrefix then
  2175. begin
  2176. InString:=true;
  2177. Dec(ClassStart,length(MatchingSymbol)-1);
  2178. end
  2179. else if (InComment=false) and (InString=true) and IsStringSuffix then
  2180. InString:=false;
  2181. end;
  2182. if MatchedSymbol and (InComment=false) then
  2183. SymbolConcat:='';
  2184. LastCC:=CC;
  2185. end;
  2186. end;
  2187. var CurLineNr: Sw_integer;
  2188. Line,NextLine,PrevLine{,OldLine}: PCustomLine;
  2189. PrevLI,LI,nextLI: PEditorLineInfo;
  2190. begin
  2191. if (not Editor^.IsFlagSet(efSyntaxHighlight)) or (FromLine>=GetLineCount) then
  2192. begin
  2193. SetLineFormat(Editor,FromLine,'');
  2194. DoUpdateAttrs:=GetLineCount;
  2195. {$ifdef TEST_PARTIAL_SYNTAX}
  2196. LastSyntaxedLine:=GetLineCount;
  2197. if not SyntaxComplete then
  2198. begin
  2199. SyntaxComplete:=true;
  2200. DoSyntaxStateChanged;
  2201. end;
  2202. (* { no Idle necessary }
  2203. EventMask:=EventMask and not evIdle;*)
  2204. {$endif TEST_PARTIAL_SYNTAX}
  2205. Editor^.SyntaxStateChanged;
  2206. Exit;
  2207. end;
  2208. {$ifdef TEST_PARTIAL_SYNTAX}
  2209. If Editor^.IsFlagSet(efSyntaxHighlight) and (LastSyntaxedLine<FromLine)
  2210. and (FromLine<GetLineCount) then
  2211. CurLineNr:=LastSyntaxedLine
  2212. else
  2213. {$endif TEST_PARTIAL_SYNTAX}
  2214. CurLineNr:=FromLine;
  2215. if CurLineNr>0 then
  2216. PrevLine:=GetLine(CurLineNr-1)
  2217. else
  2218. PrevLine:=nil;
  2219. repeat
  2220. Line:=GetLine(CurLineNr);
  2221. if Assigned(PrevLine) then PrevLI:=PrevLine^.GetEditorInfo(Editor) else PrevLI:=nil;
  2222. if Assigned(Line) then LI:=Line^.GetEditorInfo(Editor) else LI:=nil;
  2223. InSingleLineComment:=false;
  2224. if PrevLI<>nil then
  2225. begin
  2226. InAsm:=PrevLI^.EndsWithAsm;
  2227. InComment:=PrevLI^.EndsWithComment and not PrevLI^.EndsInSingleLineComment;
  2228. CurrentCommentType:=PrevLI^.EndCommentType;
  2229. InDirective:=PrevLI^.EndsWithDirective;
  2230. end
  2231. else
  2232. begin
  2233. InAsm:=false;
  2234. InComment:=false;
  2235. CurrentCommentType:=0;
  2236. InDirective:=false;
  2237. end;
  2238. { OldLine:=Line;}
  2239. if (not Editor^.IsFlagSet(efKeepLineAttr)) then
  2240. begin
  2241. LI^.BeginsWithAsm:=InAsm;
  2242. LI^.BeginsWithComment:=InComment;
  2243. LI^.BeginsWithDirective:=InDirective;
  2244. LI^.BeginCommentType:=CurrentCommentType;
  2245. end
  2246. else
  2247. begin
  2248. InAsm:=LI^.BeginsWithAsm;
  2249. InComment:=LI^.BeginsWithComment;
  2250. InDirective:=LI^.BeginsWithDirective;
  2251. CurrentCommentType:=LI^.BeginCommentType;
  2252. end;
  2253. LineText:=GetLineText(CurLineNr);
  2254. Format:=CharStr(chr(coTextColor),length(LineText));
  2255. LastCC:=ccWhiteSpace;
  2256. ClassStart:=1;
  2257. SymbolConcat:='';
  2258. InString:=false;
  2259. if LineText<>'' then
  2260. begin
  2261. for X:=1 to length(LineText) do
  2262. ProcessChar(LineText[X]);
  2263. Inc(X);
  2264. ProcessChar(' ');
  2265. end;
  2266. SetLineFormat(Editor,CurLineNr,Format);
  2267. LI^.EndsWithAsm:=InAsm;
  2268. LI^.EndsWithComment:=InComment;
  2269. LI^.EndsInSingleLineComment:=InSingleLineComment;
  2270. LI^.EndCommentType:=CurrentCommentType;
  2271. LI^.EndsWithDirective:=InDirective;
  2272. Inc(CurLineNr);
  2273. if CurLineNr>=GetLineCount then
  2274. Break;
  2275. NextLine:=GetLine(CurLineNr);
  2276. if Assigned(NextLine) then NextLI:=NextLine^.GetEditorInfo(Editor) else NextLI:=nil;
  2277. if ((Attrs and attrForceFull)=0) then
  2278. if (* Why should we go
  2279. (InAsm=false) and (NextLI^.BeginsWithAsm=false) and
  2280. (InComment=false) and (NextLI^.BeginsWithComment=false) and
  2281. (InDirective=false) and (NextLI^.BeginsWithDirective=false) and
  2282. { OldLine = Line so this is nonsense}
  2283. (PrevLI^.EndsWithComment=LI^.EndsWithComment) and
  2284. (PrevLI^.EndsWithAsm=LI^.EndsWithAsm) and
  2285. (PrevLI^.EndsWithDirective=LI^.EndsWithDirective) and *)
  2286. {$ifdef TEST_PARTIAL_SYNTAX}
  2287. (CurLineNr>FromLine) and
  2288. {$endif TEST_PARTIAL_SYNTAX}
  2289. (NextLI^.BeginsWithAsm=LI^.EndsWithAsm) and
  2290. (NextLI^.BeginsWithComment=LI^.EndsWithComment) and
  2291. (NextLI^.BeginsWithDirective=LI^.EndsWithDirective) and
  2292. (NextLI^.BeginCommentType=LI^.EndCommentType) and
  2293. (NextLI^.Format<>nil) then
  2294. Break;
  2295. {$ifdef TEST_PARTIAL_SYNTAX}
  2296. if (CurLineNr<GetLineCount) and
  2297. (CurLineNr>FromLine) and
  2298. ((Attrs and attrForceFull)=0) and
  2299. (CurLineNr>GetLastVisibleLine) then
  2300. begin
  2301. If SyntaxComplete then
  2302. begin
  2303. SyntaxComplete:=false;
  2304. DoSyntaxStateChanged;
  2305. end;
  2306. LastSyntaxedLine:=CurLineNr-1;
  2307. break;
  2308. end;
  2309. {$endif TEST_PARTIAL_SYNTAX}
  2310. PrevLine:=Line;
  2311. until false;
  2312. DoUpdateAttrs:=CurLineNr;
  2313. {$ifdef TEST_PARTIAL_SYNTAX}
  2314. If LastSyntaxedLine<CurLineNr-1 then
  2315. LastSyntaxedLine:=CurLineNr-1;
  2316. if CurLineNr=GetLineCount then
  2317. begin
  2318. SyntaxComplete:=true;
  2319. DoSyntaxStateChanged;
  2320. end;
  2321. {$endif TEST_PARTIAL_SYNTAX}
  2322. end;
  2323. function TCustomCodeEditorCore.DoUpdateAttrsRange(Editor: PCustomCodeEditor; FromLine, ToLine: sw_integer;
  2324. Attrs: byte): sw_integer;
  2325. var Line: Sw_integer;
  2326. begin
  2327. Lock(Editor);
  2328. Line:=FromLine;
  2329. repeat
  2330. Line:=DoUpdateAttrs(Editor,Line,Attrs);
  2331. until (Line>=GetLineCount) or (Line>ToLine);
  2332. DoUpdateAttrsRange:=Line;
  2333. Unlock(Editor);
  2334. end;
  2335. procedure TCustomCodeEditorCore.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
  2336. begin
  2337. Abstract;
  2338. end;
  2339. procedure TCustomCodeEditorCore.AddGroupedAction(AAction : byte);
  2340. begin
  2341. Abstract;
  2342. end;
  2343. procedure TCustomCodeEditorCore.CloseGroupedAction(AAction : byte);
  2344. begin
  2345. Abstract;
  2346. end;
  2347. function TCustomCodeEditorCore.GetUndoActionCount: sw_integer;
  2348. begin
  2349. Abstract;
  2350. GetUndoActionCount:=0;
  2351. end;
  2352. function TCustomCodeEditorCore.GetRedoActionCount: sw_integer;
  2353. begin
  2354. Abstract;
  2355. GetRedoActionCount:=0;
  2356. end;
  2357. destructor TCustomCodeEditorCore.Done;
  2358. begin
  2359. {$ifdef DEBUG}
  2360. if Bindings^.Count>0 then
  2361. ErrorBox('Internal error: there are still '+IntToStr(Bindings^.Count)+' editors '+
  2362. 'registered at TCodeEditorCode.Done!!!',nil);
  2363. {$endif}
  2364. if Assigned(Bindings) then Dispose(Bindings, Done); Bindings:=nil;
  2365. inherited Done;
  2366. end;
  2367. procedure TCustomCodeEditor.Lock;
  2368. begin
  2369. Inc(ELockFlag);
  2370. LockScreenUpdate;
  2371. end;
  2372. procedure TCustomCodeEditor.UnLock;
  2373. begin
  2374. {$ifdef DEBUG}
  2375. if Elockflag=0 then
  2376. Bug('negative lockflag',nil)
  2377. else
  2378. {$endif DEBUG}
  2379. UnlockScreenUpdate;
  2380. Dec(ELockFlag);
  2381. if (ELockFlag>0) then
  2382. Exit;
  2383. if DrawCalled then
  2384. DrawView;
  2385. If DrawCursorCalled then
  2386. Begin
  2387. DrawCursor;
  2388. DrawCursorCalled:=false;
  2389. End;
  2390. end;
  2391. procedure TCustomCodeEditor.DrawIndicator;
  2392. begin
  2393. { Abstract }
  2394. end;
  2395. procedure TCustomCodeEditor.AdjustSelectionPos(OldCurPosX, OldCurPosY: sw_integer; DeltaX, DeltaY: sw_integer);
  2396. var CP: TPoint;
  2397. begin
  2398. if ValidBlock=false then Exit;
  2399. CP.X:=OldCurPosX; CP.Y:=OldCurPosY;
  2400. if (PosToOfsP(SelStart)<=PosToOfsP(CP)) and (PosToOfsP(CP)<PosToOfsP(SelEnd)) then
  2401. begin
  2402. { OldCurPos is IN selection }
  2403. if (CP.Y=SelEnd.Y) then
  2404. begin
  2405. if ((SelStart.Y<>SelEnd.Y) or (SelStart.X<=CP.X)) and
  2406. (CP.X<=SelEnd.X) then
  2407. Inc(SelEnd.X,DeltaX);
  2408. end
  2409. else if (CP.Y=SelEnd.Y+DeltaY) then
  2410. Inc(SelEnd.X,DeltaX);
  2411. Inc(SelEnd.Y,DeltaY);
  2412. SelectionChanged;
  2413. end
  2414. else
  2415. if (PosToOfsP(CP)<=PosToOfsP(SelStart)) then
  2416. begin
  2417. { OldCurPos is BEFORE selection }
  2418. if (CP.Y=SelStart.Y) and (CP.Y=SelEnd.Y) and (DeltaY<0) then
  2419. begin
  2420. SelStart:=CurPos; SelEnd:=CurPos;
  2421. end
  2422. else
  2423. if (CP.Y=SelStart.Y) then
  2424. begin
  2425. if CP.X<SelStart.X then
  2426. Inc(SelStart.X,DeltaX);
  2427. end;
  2428. { else}
  2429. begin
  2430. Inc(SelStart.Y,DeltaY);
  2431. Inc(SelEnd.Y,DeltaY);
  2432. end;
  2433. if SelEnd.Y=CurPos.Y then Inc(SelEnd.X,DeltaX);
  2434. SelectionChanged;
  2435. end
  2436. else
  2437. begin
  2438. { OldCurPos is AFTER selection }
  2439. { actually we don't have to do anything here }
  2440. end;
  2441. end;
  2442. function TCustomCodeEditor.GetFlags: longint;
  2443. begin
  2444. { Abstract }
  2445. GetFlags:=0;
  2446. end;
  2447. procedure TCustomCodeEditor.SetFlags(AFlags: longint);
  2448. begin
  2449. { Abstract }
  2450. end;
  2451. function TCustomCodeEditor.GetModified: boolean;
  2452. begin
  2453. { Abstract }
  2454. GetModified:=true;
  2455. end;
  2456. procedure TCustomCodeEditor.SetModified(AModified: boolean);
  2457. begin
  2458. { Abstract }
  2459. end;
  2460. function TCustomCodeEditor.GetStoreUndo: boolean;
  2461. begin
  2462. { Abstract }
  2463. GetStoreUndo:=false;
  2464. end;
  2465. procedure TCustomCodeEditor.SetStoreUndo(AStore: boolean);
  2466. begin
  2467. { Abstract }
  2468. end;
  2469. function TCustomCodeEditor.GetSyntaxCompleted: boolean;
  2470. begin
  2471. { Abstract }
  2472. GetSyntaxCompleted:=true;
  2473. end;
  2474. procedure TCustomCodeEditor.SetSyntaxCompleted(SC : boolean);
  2475. begin
  2476. { Abstract }
  2477. end;
  2478. function TCustomCodeEditor.GetLastSyntaxedLine: sw_integer;
  2479. begin
  2480. Abstract;
  2481. GetLastSyntaxedLine:=0;
  2482. end;
  2483. procedure TCustomCodeEditor.SetLastSyntaxedLine(ALine: sw_integer);
  2484. begin
  2485. Abstract;
  2486. end;
  2487. function TCustomCodeEditor.IsFlagSet(AFlag: longint): boolean;{$ifdef USEINLINE}inline;{$endif}
  2488. begin
  2489. IsFlagSet:=(GetFlags and AFlag)=AFlag;
  2490. end;
  2491. function TCustomCodeEditor.GetTabSize: integer;
  2492. begin
  2493. { Abstract }
  2494. GetTabSize:=5;
  2495. end;
  2496. procedure TCustomCodeEditor.SetTabSize(ATabSize: integer);
  2497. begin
  2498. { Abstract }
  2499. end;
  2500. function TCustomCodeEditor.GetIndentSize: integer;
  2501. begin
  2502. { Abstract }
  2503. GetIndentSize:=1;
  2504. end;
  2505. procedure TCustomCodeEditor.SetIndentSize(AIndentSize: integer);
  2506. begin
  2507. { Abstract }
  2508. end;
  2509. function TCustomCodeEditor.IsReadOnly: boolean;
  2510. begin
  2511. { Abstract }
  2512. IsReadOnly:=false;
  2513. end;
  2514. function TCustomCodeEditor.IsClipboard: Boolean;
  2515. begin
  2516. { Abstract }
  2517. IsClipboard:=false;
  2518. end;
  2519. function TCustomCodeEditor.GetLineCount: sw_integer;
  2520. begin
  2521. Abstract;
  2522. GetLineCount:=0;
  2523. end;
  2524. function TCustomCodeEditor.GetLine(LineNo: sw_integer): PCustomLine;
  2525. begin
  2526. Abstract;
  2527. GetLine:=nil;
  2528. end;
  2529. function TCustomCodeEditor.CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer;
  2530. begin
  2531. Abstract;
  2532. CharIdxToLinePos:=0;
  2533. end;
  2534. function TCustomCodeEditor.LinePosToCharIdx(Line,X: sw_integer): sw_integer;
  2535. begin
  2536. Abstract;
  2537. LinePosToCharIdx:=0;
  2538. end;
  2539. function TCustomCodeEditor.GetLineText(I: sw_integer): string;
  2540. begin
  2541. Abstract;
  2542. GetLineText:='';
  2543. end;
  2544. procedure TCustomCodeEditor.SetDisplayText(I: sw_integer;const S: string);
  2545. begin
  2546. Abstract;
  2547. end;
  2548. function TCustomCodeEditor.GetDisplayText(I: sw_integer): string;
  2549. begin
  2550. Abstract;
  2551. GetDisplayText:='';
  2552. end;
  2553. procedure TCustomCodeEditor.SetLineText(I: sw_integer;const S: string);
  2554. begin
  2555. Abstract;
  2556. end;
  2557. procedure TCustomCodeEditor.GetDisplayTextFormat(I: sw_integer;var DT,DF:string);
  2558. begin
  2559. Abstract;
  2560. end;
  2561. function TCustomCodeEditor.GetLineFormat(I: sw_integer): string;
  2562. begin
  2563. { Abstract }
  2564. GetLineFormat:='';
  2565. end;
  2566. procedure TCustomCodeEditor.SetLineFormat(I: sw_integer;const S: string);
  2567. begin
  2568. { Abstract }
  2569. end;
  2570. procedure TCustomCodeEditor.DeleteAllLines;
  2571. begin
  2572. Abstract;
  2573. end;
  2574. procedure TCustomCodeEditor.DeleteLine(I: sw_integer);
  2575. begin
  2576. Abstract;
  2577. end;
  2578. function TCustomCodeEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
  2579. begin
  2580. Abstract;
  2581. InsertLine:=nil; { eliminate compiler warning }
  2582. end;
  2583. procedure TCustomCodeEditor.AddLine(const S: string);
  2584. begin
  2585. Abstract;
  2586. end;
  2587. function TCustomCodeEditor.GetErrorMessage: string;
  2588. begin
  2589. Abstract;
  2590. GetErrorMessage:='';
  2591. end;
  2592. procedure TCustomCodeEditor.SetErrorMessage(const S: string);
  2593. begin
  2594. Abstract;
  2595. end;
  2596. procedure TCustomCodeEditor.GetContent(ALines: PUnsortedStringCollection);
  2597. begin
  2598. Abstract;
  2599. end;
  2600. procedure TCustomCodeEditor.SetContent(ALines: PUnsortedStringCollection);
  2601. begin
  2602. Abstract;
  2603. end;
  2604. function TCustomCodeEditor.LoadFromStream(Stream: PFastBufStream): boolean;
  2605. begin
  2606. Abstract;
  2607. LoadFromStream:=false;
  2608. end;
  2609. function TCustomCodeEditor.SaveToStream(Stream: PStream): boolean;
  2610. var A,B: TPoint;
  2611. begin
  2612. A.Y:=0; A.X:=0;
  2613. B.Y:=GetLineCount-1;
  2614. if GetLineCount>0 then
  2615. B.X:=length(GetDisplayText(B.Y))
  2616. else
  2617. B.X:=0;
  2618. SaveToStream:=SaveAreaToStream(Stream,A,B);
  2619. end;
  2620. function TCustomCodeEditor.SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;
  2621. begin
  2622. Abstract;
  2623. SaveAreaToStream:=false;
  2624. end;
  2625. function TCustomCodeEditor.LoadFromFile(const AFileName: string): boolean;
  2626. var S: PFastBufStream;
  2627. OK: boolean;
  2628. begin
  2629. New(S, Init(AFileName,stOpenRead,EditorTextBufSize));
  2630. OK:=Assigned(S);
  2631. {$ifdef TEST_PARTIAL_SYNTAX}
  2632. SetSyntaxCompleted(false);
  2633. { Idle necessary }
  2634. EventMask:=EventMask or evIdle;
  2635. {$endif TEST_PARTIAL_SYNTAX}
  2636. if OK then OK:=LoadFromStream(S);
  2637. if Assigned(S) then Dispose(S, Done);
  2638. LoadFromFile:=OK;
  2639. end;
  2640. function TCustomCodeEditor.SaveToFile(const AFileName: string): boolean;
  2641. var OK: boolean;
  2642. S: PBufStream;
  2643. begin
  2644. New(S, Init(AFileName,stCreate,EditorTextBufSize));
  2645. OK:=Assigned(S) and (S^.Status=stOK);
  2646. if OK then OK:=SaveToStream(S);
  2647. if Assigned(S) then Dispose(S, Done);
  2648. SaveToFile:=OK;
  2649. end;
  2650. function TCustomCodeEditor.InsertFrom(Editor: PCustomCodeEditor): Boolean;
  2651. var OK: boolean;
  2652. CP,RX,RSX,LineDelta,LineCount: Sw_integer;
  2653. StartPos,DestPos,BPos,EPos: TPoint;
  2654. LineStartX,LineEndX: Sw_integer;
  2655. TabSize,CharIdxStart,CharIdxEnd: Sw_integer;
  2656. S,DS,BeforeS,OrigS,AfterS: string;
  2657. VerticalBlock: boolean;
  2658. SEnd: TPoint;
  2659. begin
  2660. if Editor^.IsFlagSet(efVerticalBlocks) then
  2661. begin
  2662. NotImplemented;
  2663. Exit;
  2664. end;
  2665. Lock;
  2666. { every data in the clipboard gets a new line }
  2667. if (Clipboard=@Self) and (CurPos.X>0) then
  2668. InsertNewLine;
  2669. OK:=(Editor^.SelStart.X<>Editor^.SelEnd.X) or (Editor^.SelStart.Y<>Editor^.SelEnd.Y);
  2670. if OK then
  2671. begin
  2672. StartPos:=CurPos; DestPos:=CurPos;
  2673. EPos:=CurPos;
  2674. VerticalBlock:=Editor^.IsFlagSet(efVerticalBlocks);
  2675. LineDelta:=0; LineCount:=(Editor^.SelEnd.Y-Editor^.SelStart.Y)+1;
  2676. OK:=GetLineCount<MaxLineCount;
  2677. OrigS:=GetLineText(DestPos.Y);
  2678. BeforeS:=Copy(OrigS,1,LinePosToCharIdx(DestPos.Y,DestPos.X-1));
  2679. { we might need to add some spaces here,
  2680. but how many ? }
  2681. TabSize:=GetTabSize;
  2682. CP:=1; RX:=0;
  2683. while (CP<=length(BeforeS)) do
  2684. begin
  2685. if (BeforeS[CP]=TAB) then
  2686. Inc(RX,TabSize-(RX mod TabSize))
  2687. else
  2688. Inc(RX);
  2689. Inc(CP);
  2690. end;
  2691. BeforeS:=BeforeS+CharStr(' ',DestPos.X-RX);
  2692. AfterS:=Copy(OrigS,LinePosToCharIdx(DestPos.Y,DestPos.X),High(OrigS));
  2693. BPos:=CurPos;
  2694. while OK and (LineDelta<LineCount) do
  2695. begin
  2696. if (LineDelta>0) and (VerticalBlock=false) then
  2697. begin
  2698. InsertLine(DestPos.Y,'');
  2699. EPOS.X:=0;EPos.Y:=DestPos.Y;
  2700. AddAction(eaInsertLine,BPos,EPos,'',GetFlags);
  2701. LimitsChanged;
  2702. end;
  2703. If LineDelta>0 then
  2704. BeforeS:='';
  2705. if (LineDelta=0) or VerticalBlock then
  2706. LineStartX:=Editor^.SelStart.X
  2707. else
  2708. LineStartX:=0;
  2709. if (LineDelta=LineCount-1) or VerticalBlock then
  2710. LineEndX:=Editor^.SelEnd.X-1
  2711. else
  2712. LineEndX:=High(S);
  2713. CharIdxStart:=Editor^.LinePosToCharIdx(Editor^.SelStart.Y+LineDelta,LineStartX);
  2714. CharIdxEnd:=Editor^.LinePosToCharIdx(Editor^.SelStart.Y+LineDelta,LineEndX);
  2715. if LineEndX<LineStartX then
  2716. S:=''
  2717. else if VerticalBlock then
  2718. S:=RExpand(copy(Editor^.GetLineText(Editor^.SelStart.Y+LineDelta),CharIdxStart,CharIdxEnd-CharIdxStart+1),
  2719. Min(CharIdxEnd-CharIdxStart+1,High(S)))
  2720. else
  2721. S:=copy(Editor^.GetLineText(Editor^.SelStart.Y+LineDelta),CharIdxStart,CharIdxEnd-CharIdxStart+1);
  2722. if VerticalBlock=false then
  2723. begin
  2724. DS:=BeforeS+S;
  2725. CP:=1; RX:=0;
  2726. RSX :=0;
  2727. while (CP<=length(DS)) do
  2728. begin
  2729. if (DS[CP]=TAB) then
  2730. Inc(RX,TabSize-(RX mod TabSize))
  2731. else
  2732. Inc(RX);
  2733. if CP=length(BeforeS) then
  2734. RSX:=RX;
  2735. Inc(CP);
  2736. end;
  2737. if LineDelta=LineCount-1 then
  2738. begin
  2739. SetLineText(DestPos.Y,DS+AfterS);
  2740. BPos.X:=DestPos.X;BPos.Y:=DestPos.Y;
  2741. EPOS.X:=DestPos.X+RX-RSX;EPos.Y:=DestPos.Y;
  2742. AddAction(eaInsertText,BPos,EPos,S,GetFlags);
  2743. end
  2744. else
  2745. begin
  2746. SetLineText(DestPos.Y,DS);
  2747. BPos.X:=DestPos.X;BPos.Y:=DestPos.Y;
  2748. EPOS.X:=DestPos.X+RX-RSX;EPos.Y:=DestPos.Y;
  2749. AddAction(eaInsertText,BPos,EPos,S,GetFlags);
  2750. end;
  2751. BPos.X:=EPos.X;
  2752. if LineDelta=LineCount-1 then
  2753. begin
  2754. SEnd.Y:=DestPos.Y;
  2755. SEnd.X:=DestPos.X+RX-RSX;
  2756. end
  2757. else
  2758. begin
  2759. Inc(DestPos.Y);
  2760. DestPos.X:=0;
  2761. end;
  2762. end
  2763. else { if VerticalBlock=false then .. else }
  2764. begin
  2765. { this is not yet implemented !! PM }
  2766. S:=RExpand(S,LineEndX-LineStartX+1);
  2767. end;
  2768. Inc(LineDelta);
  2769. OK:=GetLineCount<MaxLineCount;
  2770. end;
  2771. if not OK then EditorDialog(edTooManyLines,nil);
  2772. { mainly to force eaMove insertion }
  2773. if not IsClipboard then
  2774. SetCurPtr(EPos.X,EPos.Y);
  2775. SetCurPtr(StartPos.X,StartPos.Y);
  2776. UpdateAttrs(StartPos.Y,attrAll);
  2777. SetModified(true);
  2778. LimitsChanged;
  2779. SetSelection(CurPos,SEnd);
  2780. if IsClipboard then
  2781. begin
  2782. Inc(DestPos.X,length(S));
  2783. SetCurPtr(DestPos.X,DestPos.Y);
  2784. end;
  2785. DrawView;
  2786. end;
  2787. UnLock;
  2788. InsertFrom:=OK;
  2789. end;
  2790. function TCustomCodeEditor.InsertText(const S: string): Boolean;
  2791. var I: sw_integer;
  2792. OldPos: TPoint;
  2793. HoldUndo : boolean;
  2794. begin
  2795. Lock;
  2796. OldPos:=CurPos;
  2797. HoldUndo:=GetStoreUndo;
  2798. SetStoreUndo(false);
  2799. for I:=1 to length(S) do
  2800. AddChar(S[I]);
  2801. InsertText:=true;
  2802. SetStoreUndo(HoldUndo);
  2803. AddAction(eaInsertText,OldPos,CurPos,S,GetFlags);
  2804. UnLock;
  2805. end;
  2806. procedure TCustomCodeEditor.ModifiedChanged;
  2807. begin
  2808. { Abstract }
  2809. end;
  2810. procedure TCustomCodeEditor.PositionChanged;
  2811. begin
  2812. { Abstract }
  2813. end;
  2814. procedure TCustomCodeEditor.TabSizeChanged;
  2815. begin
  2816. { Abstract }
  2817. end;
  2818. procedure TCustomCodeEditor.SyntaxStateChanged;
  2819. begin
  2820. { Abstract }
  2821. end;
  2822. procedure TCustomCodeEditor.StoreUndoChanged;
  2823. begin
  2824. { Abstract }
  2825. end;
  2826. function TCustomCodeEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  2827. begin
  2828. { Abstract }
  2829. GetSpecSymbolCount:=0;
  2830. end;
  2831. function TCustomCodeEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  2832. begin
  2833. Abstract;
  2834. GetSpecSymbol:=nil;
  2835. end;
  2836. function TCustomCodeEditor.IsReservedWord(const S: string): boolean;
  2837. begin
  2838. { Abstract }
  2839. IsReservedWord:=false;
  2840. end;
  2841. function TCustomCodeEditor.IsAsmReservedWord(const S: string): boolean;
  2842. begin
  2843. { Abstract }
  2844. IsAsmReservedWord:=false;
  2845. end;
  2846. function TCustomCodeEditor.TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean;
  2847. begin
  2848. { Abstract }
  2849. TranslateCodeTemplate:=false;
  2850. end;
  2851. function TCustomCodeEditor.CompleteCodeWord(const WordS: string; var Text: string): boolean;
  2852. begin
  2853. { Abstract }
  2854. Text:='';
  2855. CompleteCodeWord:=false;
  2856. end;
  2857. function TCustomCodeEditor.GetCodeCompleteWord: string;
  2858. begin
  2859. { Abstract }
  2860. GetCodeCompleteWord:='';
  2861. end;
  2862. function TCustomCodeEditor.CreateFold(StartY,EndY: sw_integer; Collapsed: boolean): boolean;
  2863. var F,ParentF: PFold;
  2864. L: PCustomLine;
  2865. EI: PEditorLineInfo;
  2866. Y: sw_integer;
  2867. OK: boolean;
  2868. begin
  2869. OK:=true;
  2870. Lock;
  2871. for Y:=StartY to EndY do
  2872. begin
  2873. L:=GetLine(Y);
  2874. if assigned(L) then
  2875. EI:=L^.GetEditorInfo(@Self)
  2876. else
  2877. begin
  2878. CreateFold:=False;
  2879. exit;
  2880. end;
  2881. if Y=StartY then
  2882. ParentF:=EI^.Fold
  2883. else
  2884. OK:=OK and (EI^.Fold=ParentF);
  2885. if not OK then
  2886. Break;
  2887. end;
  2888. if OK then
  2889. begin
  2890. New(F, Init(@Self,ParentF,Collapsed));
  2891. for Y:=StartY to EndY do
  2892. GetLine(Y)^.GetEditorInfo(@Self)^.SetFold(F);
  2893. DrawView;
  2894. end;
  2895. UnLock;
  2896. CreateFold:=OK;
  2897. end;
  2898. procedure TCustomCodeEditor.FoldChanged(Fold: PFold);
  2899. var F: PFold;
  2900. I: sw_integer;
  2901. begin
  2902. for I:=0 to GetFoldCount-1 do
  2903. begin
  2904. F:=GetFold(I);
  2905. if F^.ParentFold=Fold then
  2906. FoldChanged(F);
  2907. end;
  2908. if Fold^.IsCollapsed then
  2909. begin
  2910. F:=GetLineFold(CurPos.Y); I:=CurPos.Y;
  2911. if F=Fold then
  2912. begin
  2913. while GetLineFold(I-1)=Fold do
  2914. Dec(I);
  2915. if I<>CurPos.Y then
  2916. SetCurPtr(CurPos.X,I);
  2917. end;
  2918. end;
  2919. DrawView;
  2920. end;
  2921. procedure TCustomCodeEditor.RemoveAllFolds;
  2922. var I: sw_integer;
  2923. L: PCustomLine;
  2924. begin
  2925. for I:=0 to GetLineCount-1 do
  2926. begin
  2927. L:=GetLine(I);
  2928. if not assigned(L) then exit;
  2929. with L^ do
  2930. with GetEditorInfo(@Self)^ do
  2931. SetFold(nil);
  2932. end;
  2933. DrawView;
  2934. end;
  2935. { to be called if CurPos has already been changed }
  2936. procedure TCustomCodeEditor.AdjustSelection(DeltaX, DeltaY: sw_integer);
  2937. begin
  2938. AdjustSelectionPos(CurPos.X-DeltaX,CurPos.Y-DeltaY,DeltaX,DeltaY);
  2939. end;
  2940. { to be called if CurPos has not yet been changed }
  2941. procedure TCustomCodeEditor.AdjustSelectionBefore(DeltaX, DeltaY: sw_integer);
  2942. begin
  2943. AdjustSelectionPos(CurPos.X,CurPos.Y,DeltaX,DeltaY);
  2944. end;
  2945. procedure TCustomCodeEditor.TrackCursor(centre:Tcentre);
  2946. var D,CP: TPoint;
  2947. begin
  2948. D:=Delta;
  2949. EditorToViewPoint(D,D); EditorToViewPoint(CurPos,CP);
  2950. if CP.Y<Delta.Y then D.Y:=CP.Y else
  2951. if CP.Y>Delta.Y+Size.Y-1 then D.Y:=CP.Y-Size.Y+1;
  2952. if CP.X<Delta.X then D.X:=CP.X else
  2953. if CP.X>Delta.X+Size.X-1 then D.X:=CP.X-Size.X+1;
  2954. if {((Delta.X<>D.X) or (Delta.Y<>D.Y)) and }centre=do_centre then
  2955. begin
  2956. { loose centering for debugger PM }
  2957. while (CP.Y-D.Y)<(Size.Y div 3) do Dec(D.Y);
  2958. while (CP.Y-D.Y)>2*(Size.Y div 3) do Inc(D.Y);
  2959. end;
  2960. ViewToEditorPoint(D,D);
  2961. if (Delta.X<>D.X) or (Delta.Y<>D.Y) then
  2962. ScrollTo(D.X,D.Y);
  2963. DrawCursor;
  2964. end;
  2965. procedure TCustomCodeEditor.ScrollTo(X, Y: sw_Integer);
  2966. begin
  2967. inherited ScrollTo(X,Y);
  2968. if (HScrollBar=nil) or (VScrollBar=nil) then
  2969. begin Delta.X:=X; Delta.Y:=Y; end;
  2970. DrawView;
  2971. end;
  2972. function TCustomCodeEditor.IsModal: boolean;
  2973. var IsM: boolean;
  2974. begin
  2975. IsM:=GetState(sfModal);
  2976. if Assigned(Owner) then
  2977. IsM:=IsM or Owner^.GetState(sfModal);
  2978. IsModal:=IsM;
  2979. end;
  2980. procedure TCustomCodeEditor.FlagsChanged(OldFlags: longint);
  2981. var I: sw_integer;
  2982. begin
  2983. Lock;
  2984. if ((OldFlags xor GetFlags) and efCodeComplete)<>0 then
  2985. ClearCodeCompleteWord;
  2986. SetInsertMode(IsFlagSet(efInsertMode));
  2987. if ((OldFlags xor GetFlags) and efFolds)<>0 then
  2988. if not IsFlagSet(efFolds) then
  2989. RemoveAllFolds;
  2990. if IsFlagSet(efSyntaxHighlight) then
  2991. UpdateAttrs(0,attrAll) else
  2992. for I:=0 to GetLineCount-1 do
  2993. SetLineFormat(I,'');
  2994. DrawView;
  2995. UnLock;
  2996. end;
  2997. procedure TCustomCodeEditor.LimitsChanged;
  2998. begin
  2999. Abstract;
  3000. end;
  3001. procedure TCustomCodeEditor.DoLimitsChanged;
  3002. begin
  3003. SetLimit(MaxLineLength+1,EditorToViewLine(GetLineCount));
  3004. end;
  3005. procedure TCustomCodeEditor.BindingsChanged;
  3006. begin
  3007. { Abstract }
  3008. end;
  3009. procedure TCustomCodeEditor.ContentsChanged;
  3010. begin
  3011. DrawView;
  3012. end;
  3013. procedure TCustomCodeEditor.ConvertEvent(var Event: TEvent);
  3014. var
  3015. Key: Word;
  3016. begin
  3017. if Event.What = evKeyDown then
  3018. begin
  3019. if (Event.KeyShift and kbShift <> 0) and
  3020. (Event.ScanCode >= $47) and (Event.ScanCode <= $51) then
  3021. Event.CharCode := #0;
  3022. Key := Event.KeyCode;
  3023. if KeyState <> 0 then
  3024. begin
  3025. if (Lo(Key) >= $01) and (Lo(Key) <= $1A) then Inc(Key, $40);
  3026. if (Lo(Key) >= $61) and (Lo(Key) <= $7A) then Dec(Key, $20);
  3027. end;
  3028. Key := ScanKeyMap(KeyMap[KeyState], Key);
  3029. if (KeyState<>0) and (Key=0) then
  3030. ClearEvent(Event); { eat second key if unrecognized after ^Q or ^K }
  3031. KeyState := 0;
  3032. if Key <> 0 then
  3033. if Hi(Key) = $FF then
  3034. begin
  3035. KeyState := Lo(Key);
  3036. ClearEvent(Event);
  3037. end
  3038. else
  3039. begin
  3040. Event.What := evCommand;
  3041. Event.Command := Key;
  3042. end;
  3043. end;
  3044. end;
  3045. procedure TCustomCodeEditor.SetLineFlagState(LineNo: sw_integer; Flags: longint; ASet: boolean);
  3046. var L: PCustomLine;
  3047. begin
  3048. { Avoid crashes if file was shorten for instance }
  3049. if LineNo>=GetLineCount then
  3050. exit;
  3051. L:=GetLine(LineNo);
  3052. if Assigned(L) then
  3053. with L^ do
  3054. if ASet then
  3055. SetFlags(GetFlags or Flags)
  3056. else
  3057. SetFlags(GetFlags and not Flags);
  3058. end;
  3059. procedure TCustomCodeEditor.SetLineFlagExclusive(Flags: longint; LineNo: sw_integer);
  3060. var I,Count: sw_integer;
  3061. L: PCustomLine;
  3062. begin
  3063. Lock;
  3064. Count:=GetLineCount;
  3065. for I:=0 to Count-1 do
  3066. begin
  3067. L:=GetLine(I);
  3068. if not assigned(L) then break;
  3069. if I=LineNo then
  3070. L^.SetFlags(L^.GetFlags or Flags)
  3071. else
  3072. L^.SetFlags(L^.GetFlags and (not Flags));
  3073. end;
  3074. UnLock;
  3075. end;
  3076. procedure TCustomCodeEditor.HandleEvent(var Event: TEvent);
  3077. var DontClear : boolean;
  3078. procedure CheckScrollBar(P: PScrollBar; var D: Sw_Integer);
  3079. begin
  3080. if (Event.InfoPtr = P) and (P^.Value <> D) then
  3081. begin
  3082. D := P^.Value;
  3083. DrawView;
  3084. end;
  3085. end;
  3086. procedure GetMousePos(var P: TPoint);
  3087. begin
  3088. MakeLocal(Event.Where,P);
  3089. Inc(P.X,Delta.X); Inc(P.Y,Delta.Y);
  3090. Dec(P.X,GetReservedColCount);
  3091. if P.X<0 then P.X:=0;
  3092. if P.Y<0 then P.Y:=0;
  3093. end;
  3094. type TCCAction = (ccCheck,ccClear,ccDontCare);
  3095. var
  3096. StartP,P: TPoint;
  3097. E: TEvent;
  3098. OldEvent : PEvent;
  3099. CCAction: TCCAction;
  3100. LinesScroll : sw_integer;
  3101. begin
  3102. CCAction:=ccClear;
  3103. E:=Event;
  3104. OldEvent:=CurEvent;
  3105. if (E.What and (evMouse or evKeyboard))<>0 then
  3106. CurEvent:=@E;
  3107. if (InASCIIMode=false) or (Event.What<>evKeyDown) then
  3108. if (Event.What<>evKeyDown) or (Event.KeyCode<>kbEnter) or (IsReadOnly=false) then
  3109. if (Event.What<>evKeyDown) or
  3110. ((Event.KeyCode<>kbEnter) and (Event.KeyCode<>kbEsc)) or
  3111. (GetCompleteState<>csOffering) then
  3112. ConvertEvent(Event);
  3113. case Event.What of
  3114. evMouseDown :
  3115. if MouseInView(Event.Where) then
  3116. if (Event.Buttons=mbScrollWheelUp) then { mouse scroll up}
  3117. begin
  3118. LinesScroll:=1;
  3119. if Event.Double then LinesScroll:=LinesScroll+4;
  3120. ScrollTo(Delta.X, Delta.Y + LinesScroll);
  3121. end else
  3122. if (Event.Buttons=mbScrollWheelDown) then { mouse scroll down }
  3123. begin
  3124. LinesScroll:=-1;
  3125. if Event.Double then LinesScroll:=LinesScroll-4;
  3126. ScrollTo(Delta.X, Delta.Y + LinesScroll);
  3127. end else
  3128. if (Event.Buttons=mbRightButton) then
  3129. begin
  3130. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  3131. LocalMenu(P);
  3132. ClearEvent(Event);
  3133. end else
  3134. if Event.Buttons=mbLeftButton then
  3135. begin
  3136. GetMousePos(P);
  3137. StartP:=P;
  3138. SetCurPtr(P.X,P.Y);
  3139. repeat
  3140. GetMousePos(P);
  3141. if PointOfs(P)<PointOfs(StartP)
  3142. then SetSelection(P,StartP)
  3143. else SetSelection(StartP,P);
  3144. SetCurPtr(P.X,P.Y);
  3145. DrawView;
  3146. until not MouseEvent(Event, evMouseMove+evMouseAuto);
  3147. DrawView;
  3148. end;
  3149. evKeyDown :
  3150. begin
  3151. { Scancode is almost never zero PM }
  3152. { this is supposed to enable entering of ASCII chars below 32,
  3153. which are normally interpreted as control chars. So, when you enter
  3154. Alt+24 (on the numeric pad) then this will normally move the cursor
  3155. one line down, but if you do it in ASCII mode (also after Ctrl+B)
  3156. then this will insert the ASCII #24 char (upper arrow) in the
  3157. source code. - Gabor }
  3158. if InASCIIMode {and (Event.CharCode<>0)} then
  3159. begin
  3160. AddChar(Event.CharCode);
  3161. if (GetCompleteState<>csDenied) or (Event.CharCode=#32) then
  3162. CCAction:=ccCheck
  3163. else
  3164. CCAction:=ccClear;
  3165. end
  3166. else
  3167. begin
  3168. DontClear:=false;
  3169. case Event.KeyCode of
  3170. kbAltF10 :
  3171. Message(@Self,evCommand,cmLocalMenu,@Self);
  3172. kbEnter :
  3173. if IsReadOnly then
  3174. DontClear:=true else
  3175. if GetCompleteState=csOffering then
  3176. CodeCompleteApply
  3177. else
  3178. Message(@Self,evCommand,cmNewLine,nil);
  3179. kbEsc :
  3180. if GetCompleteState=csOffering then
  3181. CodeCompleteCancel else
  3182. if IsModal then
  3183. DontClear:=true;
  3184. else
  3185. case Event.CharCode of
  3186. #9,#32..#255 :
  3187. if (Event.CharCode=#9) and IsModal then
  3188. DontClear:=true
  3189. else
  3190. begin
  3191. NoSelect:=true;
  3192. AddChar(Event.CharCode);
  3193. NoSelect:=false;
  3194. if (GetCompleteState<>csDenied) or (Event.CharCode=#32) then
  3195. CCAction:=ccCheck
  3196. else
  3197. CCAction:=ccClear;
  3198. end;
  3199. else
  3200. DontClear:=true;
  3201. end; { case Event.CharCode .. }
  3202. end; { case Event.KeyCode .. }
  3203. if not DontClear then
  3204. ClearEvent(Event);
  3205. end;
  3206. InASCIIMode:=false;
  3207. end;
  3208. evCommand :
  3209. begin
  3210. DontClear:=false;
  3211. case Event.Command of
  3212. cmASCIIChar : InASCIIMode:=not InASCIIMode;
  3213. cmAddChar : AddChar(chr(longint(Event.InfoPtr)));
  3214. cmCharLeft : CharLeft;
  3215. cmCharRight : CharRight;
  3216. cmWordLeft : WordLeft;
  3217. cmWordRight : WordRight;
  3218. cmLineStart : LineStart;
  3219. cmLineEnd : LineEnd;
  3220. cmLineUp : LineUp;
  3221. cmLineDown : LineDown;
  3222. cmPageUp : PageUp;
  3223. cmPageDown : PageDown;
  3224. cmTextStart : TextStart;
  3225. cmTextEnd : TextEnd;
  3226. cmWindowStart : WindowStart;
  3227. cmWindowEnd : WindowEnd;
  3228. cmNewLine : begin
  3229. InsertNewLine;
  3230. TrackCursor(do_not_centre);
  3231. end;
  3232. cmBreakLine : BreakLine;
  3233. cmBackSpace : BackSpace;
  3234. cmDelChar : DelChar;
  3235. cmDelWord : DelWord;
  3236. cmDelToEndOfWord : DelToEndOfWord;
  3237. cmDelStart : DelStart;
  3238. cmDelEnd : DelEnd;
  3239. cmDelLine : DelLine;
  3240. cmInsMode : InsMode;
  3241. cmStartSelect : StartSelect;
  3242. cmHideSelect : HideSelect;
  3243. cmUpdateTitle : ;
  3244. cmEndSelect : EndSelect;
  3245. cmDelSelect : DelSelect;
  3246. cmCopyBlock : CopyBlock;
  3247. cmMoveBlock : MoveBlock;
  3248. cmIndentBlock : IndentBlock;
  3249. cmUnindentBlock : UnindentBlock;
  3250. cmSelStart : JumpSelStart;
  3251. cmSelEnd : JumpSelEnd;
  3252. cmLastCursorPos : JumpToLastCursorPos;
  3253. cmFindMatchingDelimiter : FindMatchingDelimiter(true);
  3254. cmFindMatchingDelimiterBack : FindMatchingDelimiter(false);
  3255. cmUpperCase : UpperCase;
  3256. cmLowerCase : LowerCase;
  3257. cmWordLowerCase : WordLowerCase;
  3258. cmWordUpperCase : WordUpperCase;
  3259. cmInsertOptions : InsertOptions;
  3260. cmToggleCase : ToggleCase;
  3261. cmCreateFold : CreateFoldFromBlock;
  3262. cmToggleFold : ToggleFold;
  3263. cmExpandFold : ExpandFold;
  3264. cmCollapseFold : CollapseFold;
  3265. cmJumpMark0..cmJumpMark9 : JumpMark(Event.Command-cmJumpMark0);
  3266. cmSetMark0..cmSetMark9 : DefineMark(Event.Command-cmSetMark0);
  3267. cmSelectWord : SelectWord;
  3268. cmSelectLine : SelectLine;
  3269. cmWriteBlock : WriteBlock;
  3270. cmReadBlock : ReadBlock;
  3271. cmPrintBlock : PrintBlock;
  3272. { ------ }
  3273. cmFind : Find;
  3274. cmReplace : Replace;
  3275. cmSearchAgain : DoSearchReplace;
  3276. cmJumpLine : GotoLine;
  3277. { ------ }
  3278. cmCut : ClipCut;
  3279. cmCopy : ClipCopy;
  3280. cmPaste : ClipPaste;
  3281. cmSelectAll : SelectAll(true);
  3282. cmUnselect : SelectAll(false);
  3283. {$ifdef WinClipSupported}
  3284. cmCopyWin : ClipCopyWin;
  3285. cmPasteWin : ClipPasteWin;
  3286. {$endif WinClipSupported}
  3287. cmUndo : Undo;
  3288. cmRedo : Redo;
  3289. cmClear : DelSelect;
  3290. cmExpandCodeTemplate: ExpandCodeTemplate;
  3291. cmLocalMenu :
  3292. begin
  3293. P:=CurPos; Inc(P.X); Inc(P.Y);
  3294. LocalMenu(P);
  3295. end;
  3296. cmActivateMenu :
  3297. Message(Application,evCommand,cmMenu,nil);
  3298. else
  3299. begin
  3300. DontClear:=true;
  3301. CCAction:=ccDontCare;
  3302. end;
  3303. end;
  3304. if DontClear=false then
  3305. ClearEvent(Event);
  3306. end;
  3307. {$ifdef TEST_PARTIAL_SYNTAX}
  3308. evIdle :
  3309. begin
  3310. CCAction:=ccDontCare;
  3311. { Complete syntax by 20 lines increment }
  3312. { could already be quite lengthy on slow systems }
  3313. if not GetSyntaxCompleted then
  3314. UpdateAttrsRange(GetLastSyntaxedLine,GetLastSyntaxedLine+20,AttrAll);
  3315. end;
  3316. {$endif TEST_PARTIAL_SYNTAX}
  3317. evBroadcast :
  3318. begin
  3319. CCAction:=ccDontCare;
  3320. case Event.Command of
  3321. cmUpdate :
  3322. Update;
  3323. cmClearLineHighlights :
  3324. SetLineFlagExclusive(lfHighlightRow,-1);
  3325. cmResetDebuggerRow :
  3326. SetLineFlagExclusive(lfDebuggerRow,-1);
  3327. cmScrollBarChanged:
  3328. if (Event.InfoPtr = HScrollBar) or
  3329. (Event.InfoPtr = VScrollBar) then
  3330. begin
  3331. CheckScrollBar(HScrollBar, Delta.X);
  3332. CheckScrollBar(VScrollBar, Delta.Y);
  3333. end;
  3334. end;
  3335. end;
  3336. else CCAction:=ccDontCare;
  3337. end;
  3338. inherited HandleEvent(Event);
  3339. CurEvent:=OldEvent;
  3340. case CCAction of
  3341. ccCheck : CodeCompleteCheck;
  3342. ccClear : ClearCodeCompleteWord;
  3343. end;
  3344. end;
  3345. procedure TCustomCodeEditor.UpdateUndoRedo(cm : word; action : byte);
  3346. var UndoMenu : PMenuItem;
  3347. begin
  3348. UndoMenu:=PAdvancedMenuBar(MenuBar)^.GetMenuItem(cm);
  3349. if assigned(UndoMenu) then
  3350. begin
  3351. If assigned(UndoMenu^.Param) then
  3352. DisposeStr(UndoMenu^.Param);
  3353. if action<lastaction then
  3354. UndoMenu^.Param:=NewStr(ActionString[action]);
  3355. end;
  3356. end;
  3357. procedure TCustomCodeEditor.Update;
  3358. begin
  3359. Lock;
  3360. LimitsChanged;
  3361. SelectionChanged;
  3362. HighlightChanged;
  3363. UnLock;
  3364. end;
  3365. function TCustomCodeEditor.GetLocalMenu: PMenu;
  3366. begin
  3367. GetLocalMenu:=nil;
  3368. end;
  3369. function TCustomCodeEditor.GetCommandTarget: PView;
  3370. begin
  3371. GetCommandTarget:=@Self;
  3372. end;
  3373. function TCustomCodeEditor.CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup;
  3374. var MV: PMenuPopup;
  3375. begin
  3376. New(MV, Init(Bounds, M));
  3377. CreateLocalMenuView:=MV;
  3378. end;
  3379. procedure TCustomCodeEditor.LocalMenu(P: TPoint);
  3380. var M: PMenu;
  3381. MV: PMenuPopUp;
  3382. R: TRect;
  3383. Re: word;
  3384. begin
  3385. M:=GetLocalMenu;
  3386. if M=nil then Exit;
  3387. if LastLocalCmd<>0 then
  3388. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  3389. Desktop^.GetExtent(R);
  3390. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  3391. MV:=CreateLocalMenuView(R,M);
  3392. Re:=Application^.ExecView(MV);
  3393. if M^.Default=nil then LastLocalCmd:=0
  3394. else LastLocalCmd:=M^.Default^.Command;
  3395. Dispose(MV, Done);
  3396. if Re<>0 then
  3397. Message(GetCommandTarget,evCommand,Re,@Self);
  3398. end;
  3399. function TCustomCodeEditor.GetReservedColCount: sw_integer;
  3400. var LSX: sw_integer;
  3401. begin
  3402. if IsFlagSet(efFolds) then LSX:=GetFoldStringWidth else LSX:=0;
  3403. GetReservedColCount:=LSX;
  3404. end;
  3405. procedure TCustomCodeEditor.Draw;
  3406. function GetEIFold(EI: PEditorLineInfo): PFold;
  3407. begin
  3408. if Assigned(EI) then GetEIFold:=EI^.Fold else GetEIFold:=nil;
  3409. end;
  3410. var SelectColor,
  3411. HighlightColColor,
  3412. HighlightRowColor,
  3413. ErrorMessageColor : word;
  3414. B: TDrawBuffer;
  3415. X,Y,AX,AY,MaxX,LSX: sw_integer;
  3416. PX: TPoint;
  3417. LineCount: sw_integer;
  3418. Line: PCustomLine;
  3419. LineText,Format: string;
  3420. isBreak : boolean;
  3421. C: char;
  3422. FreeFormat: array[0..MaxLineLength] of boolean;
  3423. Color: word;
  3424. ColorTab: array[coFirstColor..coLastColor] of word;
  3425. ErrorLine: integer;
  3426. ErrorMsg: string[MaxViewWidth];
  3427. function CombineColors(Orig,Modifier: byte): byte;
  3428. var Color: byte;
  3429. begin
  3430. if (Modifier and $0f)=0 then
  3431. Color:=(Orig and $0f) or (Modifier and $f0)
  3432. else
  3433. Color:=(Orig and $f0) or (Modifier and $0f);
  3434. { do not allow invisible }
  3435. { use white as foreground in this case }
  3436. if (Color and $f) = ((Color div $10) and $7) then
  3437. Color:=(Color and $F0) or $F;
  3438. CombineColors:=Color;
  3439. end;
  3440. var
  3441. FoldPrefix,FoldSuffix: string;
  3442. { SkipLine: boolean;}
  3443. { FoldStartLine: sw_integer;}
  3444. begin
  3445. if ELockFlag>0 then
  3446. begin
  3447. DrawCalled:=true;
  3448. Exit;
  3449. end;
  3450. DrawCalled:=false;
  3451. ErrorMsg:=copy(GetErrorMessage,1,MaxViewWidth);
  3452. if ErrorMsg='' then ErrorLine:=-1 else
  3453. if (CurPos.Y-Delta.Y)<(Size.Y div 2) then ErrorLine:=Size.Y-1
  3454. else ErrorLine:=0;
  3455. LineCount:=GetLineCount;
  3456. ColorTab[coTextColor]:=GetColor(1);
  3457. ColorTab[coWhiteSpaceColor]:=GetColor(2);
  3458. ColorTab[coCommentColor]:=GetColor(3);
  3459. ColorTab[coReservedWordColor]:=GetColor(4);
  3460. ColorTab[coIdentifierColor]:=GetColor(5);
  3461. ColorTab[coStringColor]:=GetColor(6);
  3462. ColorTab[coNumberColor]:=GetColor(7);
  3463. ColorTab[coAssemblerColor]:=GetColor(8);
  3464. ColorTab[coSymbolColor]:=GetColor(9);
  3465. ColorTab[coDirectiveColor]:=GetColor(13);
  3466. ColorTab[coHexNumberColor]:=GetColor(14);
  3467. ColorTab[coTabColor]:=GetColor(15);
  3468. { break same as error }
  3469. ColorTab[coBreakColor]:=GetColor(16);
  3470. ColorTab[coAsmReservedColor]:=GetColor(17);
  3471. SelectColor:=GetColor(10);
  3472. HighlightColColor:=GetColor(11);
  3473. HighlightRowColor:=GetColor(12);
  3474. ErrorMessageColor:=GetColor(16);
  3475. {$ifdef TEST_PARTIAL_SYNTAX}
  3476. If (not GetSyntaxCompleted) and (GetLastSyntaxedLine<Delta.Y+Size.Y) then
  3477. UpdateAttrsRange(GetLastSyntaxedLine,Delta.Y+Size.Y,AttrAll);
  3478. {$endif TEST_PARTIAL_SYNTAX}
  3479. LSX:=GetReservedColCount;
  3480. Y:=0; AY:=Delta.Y;
  3481. for Y:=0 to Size.Y-1 do
  3482. begin
  3483. if Y=ErrorLine then
  3484. begin
  3485. MoveChar(B,' ',ErrorMessageColor,Size.X);
  3486. MoveStr(B,ErrorMsg,ErrorMessageColor);
  3487. WriteLine(0,Y,Size.X,1,B);
  3488. end
  3489. else
  3490. begin
  3491. AY:=ViewToEditorLine(Delta.Y+Y);
  3492. if (0<=AY) and (AY<LineCount) then
  3493. begin
  3494. Line:=GetLine(AY);
  3495. if assigned(Line) then
  3496. begin
  3497. IsBreak:=Line^.IsFlagSet(lfBreakpoint);
  3498. end
  3499. else
  3500. begin
  3501. IsBreak:=false;
  3502. end;
  3503. end
  3504. else
  3505. begin
  3506. Line:=nil;
  3507. IsBreak:=false;
  3508. end;
  3509. begin
  3510. Color:=ColorTab[coTextColor];
  3511. FillChar(FreeFormat,SizeOf(FreeFormat),1);
  3512. MoveChar(B,' ',Color,Size.X);
  3513. GetDisplayTextFormat(AY,LineText,Format);
  3514. { if FlagSet(efSyntaxHighlight) then MaxX:=length(LineText)+1
  3515. else }MaxX:=Size.X+Delta.X;
  3516. for X:=1 to Min(MaxX,High(LineText)) do
  3517. begin
  3518. AX:=Delta.X+X-1;
  3519. if X<=length(LineText) then C:=LineText[X] else C:=' ';
  3520. PX.X:=AX-Delta.X; PX.Y:=AY;
  3521. if (Highlight.A.X<>Highlight.B.X) or (Highlight.A.Y<>Highlight.B.Y) then
  3522. { there's a highlight }
  3523. begin
  3524. if (PointOfs(Highlight.A)<=PointOfs(PX)) and (PointOfs(PX)<PointOfs(Highlight.B)) then
  3525. begin
  3526. Color:=SelectColor;
  3527. FreeFormat[X]:=false;
  3528. end;
  3529. end
  3530. else
  3531. { no highlight }
  3532. begin
  3533. if IsFlagSet(efVerticalBlocks) then
  3534. begin
  3535. if (SelStart.X<=AX) and (AX<=SelEnd.X) and
  3536. (SelStart.Y<=AY) and (AY<=SelEnd.Y) then
  3537. begin
  3538. Color:=SelectColor; FreeFormat[X]:=false;
  3539. end;
  3540. end
  3541. else
  3542. if PointOfs(SelStart)<>PointOfs(SelEnd) then
  3543. if (PointOfs(SelStart)<=PointOfs(PX)) and (PointOfs(PX)<PointOfs(SelEnd)) then
  3544. begin
  3545. Color:=SelectColor; FreeFormat[X]:=false;
  3546. end;
  3547. end; { no highlight }
  3548. if FreeFormat[X] then
  3549. if X<=length(Format) then
  3550. {Color:=ColorTab[ord(Format[X])] else Color:=ColorTab[coTextColor];
  3551. this give BoundsCheckError with -Cr quite often PM }
  3552. Color:=ColorTab[ord(Format[X]) mod (coLastColor + 1)] else Color:=ColorTab[coTextColor];
  3553. if IsFlagSet(efHighlightRow) and
  3554. (PX.Y=CurPos.Y) then
  3555. begin
  3556. Color:=CombineColors(Color,HighlightRowColor);
  3557. FreeFormat[X]:=false;
  3558. end;
  3559. if IsFlagSet(efHighlightColumn) and (PX.X=CurPos.X) then
  3560. begin
  3561. Color:=CombineColors(Color,HighlightColColor);
  3562. FreeFormat[X]:=false;
  3563. end;
  3564. if Assigned(Line) and Line^.IsFlagSet(lfHighlightRow) then
  3565. begin
  3566. Color:=CombineColors(Color,HighlightRowColor);
  3567. FreeFormat[X]:=false;
  3568. end;
  3569. if isbreak then
  3570. begin
  3571. Color:=ColorTab[coBreakColor];
  3572. FreeFormat[X]:=false;
  3573. end;
  3574. if Assigned(Line) and Line^.isFlagSet(lfDebuggerRow) then
  3575. begin
  3576. Color:=CombineColors(Color,HighlightRowColor);
  3577. FreeFormat[X]:=false;
  3578. end;
  3579. if (0<=LSX+X-1-Delta.X) and (LSX+X-1-Delta.X<MaxViewWidth) then
  3580. MoveChar(B[LSX+X-1-Delta.X],C,Color,1);
  3581. end; { for X:=1 to ... }
  3582. if IsFlagSet(efFolds) then
  3583. begin
  3584. GetFoldStrings(AY,FoldPrefix,FoldSuffix);
  3585. MoveStr(B[0],FoldPrefix,ColorTab[coTextColor]);
  3586. if FoldSuffix<>'' then
  3587. MoveStr(B[Size.X-1-length(FoldSuffix)],FoldSuffix,ColorTab[coTextColor]);
  3588. end;
  3589. WriteLine(0,Y,Size.X,1,B);
  3590. end; { if not SkipLine ... }
  3591. end; { not errorline }
  3592. end; { while (Y<Size.Y) ... }
  3593. DrawCursor;
  3594. end;
  3595. procedure TCustomCodeEditor.DrawCursor;
  3596. begin
  3597. if Elockflag>0 then
  3598. DrawCursorCalled:=true
  3599. else
  3600. begin
  3601. SetCursor(GetReservedColCount+CurPos.X-Delta.X,EditorToViewLine(CurPos.Y)-Delta.Y);
  3602. SetState(sfCursorIns,Overwrite);
  3603. end;
  3604. end;
  3605. procedure TCustomCodeEditor.ResetCursor;
  3606. begin
  3607. if Elockflag>0 then
  3608. begin
  3609. DrawCursorCalled:=true;
  3610. exit;
  3611. end
  3612. else
  3613. inherited ResetCursor;
  3614. end;
  3615. function TCustomCodeEditor.Overwrite: boolean;
  3616. begin
  3617. Overwrite:=not IsFlagSet(efInsertMode);
  3618. end;
  3619. procedure TCustomCodeEditor.SetCodeCompleteWord(const S: string);
  3620. begin
  3621. if S<>'' then
  3622. SetCompleteState(csOffering)
  3623. else
  3624. SetCompleteState(csInactive);
  3625. end;
  3626. procedure TCustomCodeEditor.ClearCodeCompleteWord;
  3627. begin
  3628. SetCodeCompleteWord('');
  3629. SetCompleteState(csInactive);
  3630. end;
  3631. function TCustomCodeEditor.GetCompleteState: TCompleteState;
  3632. begin
  3633. { Abstract }
  3634. GetCompleteState:=csInactive;
  3635. end;
  3636. procedure TCustomCodeEditor.SetCompleteState(AState: TCompleteState);
  3637. begin
  3638. { Abstract }
  3639. end;
  3640. function TCustomCodeEditor.UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer;
  3641. begin
  3642. Abstract;
  3643. UpdateAttrs:=-1;
  3644. end;
  3645. function TCustomCodeEditor.UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer;
  3646. begin
  3647. Abstract;
  3648. UpdateAttrsRange:=-1;
  3649. end;
  3650. procedure TCustomCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
  3651. begin
  3652. { Abstract }
  3653. end;
  3654. procedure TCustomCodeEditor.AddGroupedAction(AAction : byte);
  3655. begin
  3656. { Abstract }
  3657. end;
  3658. procedure TCustomCodeEditor.CloseGroupedAction(AAction : byte);
  3659. begin
  3660. { Abstract }
  3661. end;
  3662. function TCustomCodeEditor.GetUndoActionCount: sw_integer;
  3663. begin
  3664. { Abstract }
  3665. GetUndoActionCount:=0;
  3666. end;
  3667. function TCustomCodeEditor.GetRedoActionCount: sw_integer;
  3668. begin
  3669. { Abstract }
  3670. GetRedoActionCount:=0;
  3671. end;
  3672. function TCustomCodeEditor.GetMaxFoldLevel: sw_integer;
  3673. var Max,L,I: sw_integer;
  3674. begin
  3675. Max:=0;
  3676. for I:=0 to GetFoldCount-1 do
  3677. begin
  3678. L:=GetFold(I)^.GetLevel;
  3679. if L>Max then Max:=L;
  3680. end;
  3681. GetMaxFoldLevel:=Max;
  3682. end;
  3683. function TCustomCodeEditor.GetFoldStringWidth: sw_integer;
  3684. begin
  3685. GetFoldStringWidth:=GetMaxFoldLevel;
  3686. end;
  3687. procedure TCustomCodeEditor.GetFoldStrings(EditorLine: sw_integer; var Prefix, Suffix: openstring);
  3688. var F: PFold;
  3689. C: char;
  3690. begin
  3691. Prefix:=CharStr(' ',GetFoldStringWidth); Suffix:='';
  3692. F:=GetLineFold(EditorLine);
  3693. if Assigned(F) then
  3694. begin
  3695. if F^.Collapsed_ then C:=#27 else C:=#26;
  3696. Prefix[1+F^.GetLevel]:=C;
  3697. if F^.Collapsed_ then
  3698. Suffix:='('+IntToStr(F^.GetLineCount)+')';
  3699. end;
  3700. end;
  3701. function TCustomCodeEditor.GetFoldCount: sw_integer;
  3702. begin
  3703. GetFoldCount:=0;
  3704. end;
  3705. function TCustomCodeEditor.GetFold(Index: sw_integer): PFold;
  3706. begin
  3707. GetFold:=nil;
  3708. end;
  3709. procedure TCustomCodeEditor.RegisterFold(AFold: PFold);
  3710. begin
  3711. Abstract;
  3712. end;
  3713. procedure TCustomCodeEditor.UnRegisterFold(AFold: PFold);
  3714. begin
  3715. Abstract;
  3716. end;
  3717. procedure TCustomCodeEditor.Indent;
  3718. var S, PreS: string;
  3719. Shift: integer;
  3720. begin
  3721. S:=GetLineText(CurPos.Y);
  3722. if CurPos.Y>0 then
  3723. PreS:=RTrim(GetLineText(CurPos.Y-1),not IsFlagSet(efUseTabCharacters))
  3724. else
  3725. PreS:='';
  3726. if CurPos.X>=length(PreS) then
  3727. Shift:=GetTabSize
  3728. else
  3729. begin
  3730. Shift:=1;
  3731. while (CurPos.X+Shift<length(PreS)) and (PreS[CurPos.X+Shift]<>' ') do
  3732. Inc(Shift);
  3733. end;
  3734. SetLineText(CurPos.Y,RExpand(copy(S,1,CurPos.X+1),CurPos.X+1)+CharStr(' ',Shift)+copy(S,CurPos.X+2,High(S)));
  3735. SetCurPtr(CurPos.X+Shift,CurPos.Y);
  3736. UpdateAttrs(CurPos.Y,attrAll);
  3737. DrawLines(CurPos.Y);
  3738. SetModified(true);
  3739. end;
  3740. procedure TCustomCodeEditor.CharLeft;
  3741. begin
  3742. if CurPos.X=0 then Exit;
  3743. SetCurPtr(CurPos.X-1,CurPos.Y);
  3744. end;
  3745. procedure TCustomCodeEditor.CharRight;
  3746. begin
  3747. if CurPos.X>=MaxLineLength then
  3748. Exit;
  3749. SetCurPtr(CurPos.X+1,CurPos.Y);
  3750. end;
  3751. procedure TCustomCodeEditor.WordLeft;
  3752. var X, Y: sw_integer;
  3753. Line: string;
  3754. GotIt,FoundNonSeparator: boolean;
  3755. begin
  3756. X:=CurPos.X;
  3757. Y:=CurPos.Y;
  3758. GotIt:=false;
  3759. FoundNonSeparator:=false;
  3760. while (Y>=0) do
  3761. begin
  3762. if Y=CurPos.Y then
  3763. begin
  3764. X:=length(GetDisplayText(Y));
  3765. if CurPos.X<X then
  3766. X:=CurPos.X; Dec(X);
  3767. if (X=-1) then
  3768. begin
  3769. Dec(Y);
  3770. if Y>=0 then
  3771. X:=length(GetDisplayText(Y));
  3772. Break;
  3773. end;
  3774. end
  3775. else
  3776. X:=length(GetDisplayText(Y))-1;
  3777. Line:=GetDisplayText(Y);
  3778. while (X>=0) and (GotIt=false) do
  3779. begin
  3780. if FoundNonSeparator then
  3781. begin
  3782. if IsWordSeparator(Line[X+1]) then
  3783. begin
  3784. Inc(X);
  3785. GotIt:=true;
  3786. Break;
  3787. end;
  3788. end
  3789. else
  3790. if not IsWordSeparator(Line[X+1]) then
  3791. FoundNonSeparator:=true;
  3792. Dec(X);
  3793. if (X=0) and (IsWordSeparator(Line[1])=false) then
  3794. begin
  3795. GotIt:=true;
  3796. Break;
  3797. end;
  3798. end;
  3799. if GotIt then
  3800. Break;
  3801. X:=0;
  3802. Dec(Y);
  3803. if Y>=0 then
  3804. begin
  3805. X:=length(GetDisplayText(Y));
  3806. Break;
  3807. end;
  3808. end;
  3809. if Y<0 then Y:=0; if X<0 then X:=0;
  3810. SetCurPtr(X,Y);
  3811. end;
  3812. procedure TCustomCodeEditor.WordRight;
  3813. var X, Y: sw_integer;
  3814. Line: string;
  3815. GotIt: boolean;
  3816. begin
  3817. X:=CurPos.X; Y:=CurPos.Y; GotIt:=false;
  3818. while (Y<GetLineCount) do
  3819. begin
  3820. if Y=CurPos.Y then
  3821. begin
  3822. X:=CurPos.X; Inc(X);
  3823. if (X>length(GetDisplayText(Y))-1) then
  3824. begin Inc(Y); X:=0; end;
  3825. end else X:=0;
  3826. Line:=GetDisplayText(Y);
  3827. while (X<=length(Line)+1) and (GotIt=false) and (Line<>'') do
  3828. begin
  3829. if X=length(Line)+1 then begin GotIt:=true; Dec(X); Break end;
  3830. if IsWordSeparator(Line[X]) then
  3831. begin
  3832. while (Y<GetLineCount) and
  3833. (X<=length(Line)) and (IsWordSeparator(Line[X])) do
  3834. begin
  3835. Inc(X);
  3836. if X>=length(Line) then
  3837. begin GotIt:=true; Dec(X); Break; end;
  3838. end;
  3839. if (GotIt=false) and (X<length(Line)) then
  3840. begin
  3841. Dec(X);
  3842. GotIt:=true;
  3843. Break;
  3844. end;
  3845. end;
  3846. Inc(X);
  3847. end;
  3848. if GotIt then Break;
  3849. X:=0;
  3850. Inc(Y);
  3851. if (Y<GetLineCount) then
  3852. begin
  3853. Line:=GetDisplayText(Y);
  3854. if (Line<>'') and (IsWordSeparator(Line[1])=false) then Break;
  3855. end;
  3856. end;
  3857. if Y=GetLineCount then Y:=GetLineCount-1;
  3858. SetCurPtr(X,Y);
  3859. end;
  3860. procedure TCustomCodeEditor.LineStart;
  3861. begin
  3862. SetCurPtr(0,CurPos.Y);
  3863. end;
  3864. procedure TCustomCodeEditor.LineEnd;
  3865. var
  3866. s : string;
  3867. i : longint;
  3868. begin
  3869. if CurPos.Y<GetLineCount then
  3870. begin
  3871. s:=GetDisplayText(CurPos.Y);
  3872. i:=length(s);
  3873. while (i>0) and (s[i]=' ') do
  3874. dec(i);
  3875. SetCurPtr(i,CurPos.Y);
  3876. end
  3877. else
  3878. SetCurPtr(0,CurPos.Y);
  3879. end;
  3880. function TCustomCodeEditor.NextVisibleLine(StartLine: sw_integer; Down: boolean): sw_integer;
  3881. var Count,NL: sw_integer;
  3882. begin
  3883. if Down then
  3884. begin
  3885. Count:=GetLineCount;
  3886. NL:=StartLine;
  3887. while (NL<Count-1) and not IsLineVisible(NL) do
  3888. Inc(NL);
  3889. if NL>=Count then
  3890. NL:=-1;
  3891. end
  3892. else
  3893. begin
  3894. NL:=StartLine;
  3895. while (NL>0) and not IsLineVisible(NL) do
  3896. Dec(NL);
  3897. end;
  3898. if not IsLineVisible(NL) then
  3899. NL:=-1;
  3900. NextVisibleLine:=NL;
  3901. end;
  3902. procedure TCustomCodeEditor.LineUp;
  3903. var NL: sw_integer;
  3904. begin
  3905. NL:=NextVisibleLine(CurPos.Y-1,false);
  3906. if NL<>-1 then
  3907. SetCurPtr(CurPos.X,NL);
  3908. end;
  3909. procedure TCustomCodeEditor.LineDown;
  3910. var NL: sw_integer;
  3911. begin
  3912. NL:=NextVisibleLine(CurPos.Y+1,true);
  3913. if NL<>-1 then
  3914. SetCurPtr(CurPos.X,NL);
  3915. end;
  3916. procedure TCustomCodeEditor.PageUp;
  3917. var NL: sw_integer;
  3918. begin
  3919. ScrollTo(Delta.X,Max(Delta.Y-Size.Y,0));
  3920. NL:=Max(CurPos.Y-(Size.Y),0);
  3921. if not IsLineVisible(NL) then
  3922. NL:=NextVisibleLine(NL,false);
  3923. if NL>=0 then
  3924. SetCurPtr(CurPos.X,Max(0,NL));
  3925. end;
  3926. procedure TCustomCodeEditor.PageDown;
  3927. var NL: sw_integer;
  3928. begin
  3929. ScrollTo(Delta.X,Min(Delta.Y+Size.Y,GetLineCount-1));
  3930. NL:=Min(CurPos.Y+(Size.Y{-1}),GetLineCount-1);
  3931. if not IsLineVisible(NL) then
  3932. NL:=NextVisibleLine(NL,true);
  3933. if NL>=0 then
  3934. SetCurPtr(CurPos.X,Min(GetLineCount-1,NL));
  3935. end;
  3936. procedure TCustomCodeEditor.TextStart;
  3937. begin
  3938. SetCurPtr(0,0);
  3939. end;
  3940. procedure TCustomCodeEditor.TextEnd;
  3941. var s : string;
  3942. i : longint;
  3943. begin
  3944. s:=GetDisplayText(GetLineCount-1);
  3945. i:=length(s);
  3946. while (i>0) and (s[i]=' ') do
  3947. dec(i);
  3948. SetCurPtr(i,GetLineCount-1);
  3949. end;
  3950. procedure TCustomCodeEditor.WindowStart;
  3951. begin
  3952. SetCurPtr(CurPos.X,Delta.Y);
  3953. end;
  3954. procedure TCustomCodeEditor.WindowEnd;
  3955. begin
  3956. SetCurPtr(CurPos.X,Delta.Y+Size.Y-1);
  3957. end;
  3958. procedure TCustomCodeEditor.JumpSelStart;
  3959. begin
  3960. if ValidBlock then
  3961. SetCurPtr(SelStart.X,SelStart.Y);
  3962. end;
  3963. procedure TCustomCodeEditor.JumpSelEnd;
  3964. begin
  3965. if ValidBlock then
  3966. SetCurPtr(SelEnd.X,SelEnd.Y);
  3967. end;
  3968. procedure TCustomCodeEditor.JumpMark(MarkIdx: integer);
  3969. begin
  3970. DontConsiderShiftState:=true;
  3971. if (MarkIdx<Low(Bookmarks)) or (MarkIdx>High(Bookmarks)) then
  3972. begin ErrorBox(FormatStrInt(msg_invalidmarkindex,MarkIdx),nil); Exit; end;
  3973. with Bookmarks[MarkIdx] do
  3974. if Valid=false then
  3975. InformationBox(FormatStrInt(msg_marknotset,MarkIdx),nil)
  3976. else
  3977. SetCurPtr(Pos.X,Pos.Y);
  3978. DontConsiderShiftState:=false;
  3979. end;
  3980. procedure TCustomCodeEditor.DefineMark(MarkIdx: integer);
  3981. begin
  3982. if (MarkIdx<Low(Bookmarks)) or (MarkIdx>High(Bookmarks)) then
  3983. begin
  3984. ErrorBox(FormatStrInt(msg_invalidmarkindex,MarkIdx),nil);
  3985. Exit;
  3986. end;
  3987. with Bookmarks[MarkIdx] do
  3988. begin
  3989. Pos:=CurPos;
  3990. Valid:=true;
  3991. end;
  3992. end;
  3993. procedure TCustomCodeEditor.JumpToLastCursorPos;
  3994. begin
  3995. NotImplemented;
  3996. end;
  3997. procedure TCustomCodeEditor.UpperCase;
  3998. var StartP,EndP: TPoint;
  3999. begin
  4000. if ValidBlock=false then Exit;
  4001. GetSelectionArea(StartP,EndP);
  4002. AddGroupedAction(eaUpperCase);
  4003. ChangeCaseArea(StartP,EndP,caToUpperCase);
  4004. CloseGroupedAction(eaUpperCase);
  4005. end;
  4006. procedure TCustomCodeEditor.LowerCase;
  4007. var StartP,EndP: TPoint;
  4008. begin
  4009. if ValidBlock=false then Exit;
  4010. GetSelectionArea(StartP,EndP);
  4011. AddGroupedAction(eaLowerCase);
  4012. ChangeCaseArea(StartP,EndP,caToLowerCase);
  4013. CloseGroupedAction(eaLowerCase);
  4014. end;
  4015. procedure TCustomCodeEditor.ToggleCase;
  4016. var StartP,EndP: TPoint;
  4017. begin
  4018. if ValidBlock=false then Exit;
  4019. GetSelectionArea(StartP,EndP);
  4020. AddGroupedAction(eaToggleCase);
  4021. ChangeCaseArea(StartP,EndP,caToggleCase);
  4022. CloseGroupedAction(eaToggleCase);
  4023. end;
  4024. procedure TCustomCodeEditor.WordLowerCase;
  4025. var StartP,EndP: TPoint;
  4026. begin
  4027. if GetCurrentWordArea(StartP,EndP)=false then Exit;
  4028. AddGroupedAction(eaLowerCase);
  4029. ChangeCaseArea(StartP,EndP,caToLowerCase);
  4030. CloseGroupedAction(eaLowerCase);
  4031. end;
  4032. procedure TCustomCodeEditor.WordUpperCase;
  4033. var StartP,EndP: TPoint;
  4034. begin
  4035. if GetCurrentWordArea(StartP,EndP)=false then Exit;
  4036. AddGroupedAction(eaUpperCase);
  4037. ChangeCaseArea(StartP,EndP,caToUpperCase);
  4038. CloseGroupedAction(eaUpperCase);
  4039. end;
  4040. procedure TCustomCodeEditor.CreateFoldFromBlock;
  4041. var StartY,EndY: sw_integer;
  4042. begin
  4043. if not IsFlagSet(efFolds) then Exit;
  4044. if not ValidBlock then Exit;
  4045. StartY:=SelStart.Y; EndY:=SelEnd.Y;
  4046. if SelEnd.X=0 then Dec(EndY);
  4047. if CreateFold(StartY,EndY,false)=false then
  4048. ErrorBox(msg_foldboundsarenotvalid,nil);
  4049. end;
  4050. procedure TCustomCodeEditor.ToggleFold;
  4051. var F: PFold;
  4052. begin
  4053. if not IsFlagSet(efFolds) then Exit;
  4054. F:=GetLineFold(CurPos.Y);
  4055. if Assigned(F) then
  4056. F^.Collapse(not F^.Collapsed_);
  4057. end;
  4058. procedure TCustomCodeEditor.ExpandFold;
  4059. var F: PFold;
  4060. begin
  4061. if not IsFlagSet(efFolds) then Exit;
  4062. F:=GetLineFold(CurPos.Y);
  4063. if Assigned(F) then
  4064. F^.Collapse(false);
  4065. end;
  4066. procedure TCustomCodeEditor.CollapseFold;
  4067. var F: PFold;
  4068. begin
  4069. if not IsFlagSet(efFolds) then Exit;
  4070. F:=GetLineFold(CurPos.Y);
  4071. if Assigned(F) then
  4072. F^.Collapse(true);
  4073. end;
  4074. procedure TCustomCodeEditor.ChangeCaseArea(StartP,EndP: TPoint; CaseAction: TCaseAction);
  4075. var Y,X: sw_integer;
  4076. X1,X2: sw_integer;
  4077. S: string;
  4078. C: char;
  4079. StartPos : TPoint;
  4080. HoldUndo : boolean;
  4081. begin
  4082. Lock;
  4083. HoldUndo:=GetStoreUndo;
  4084. SetStoreUndo(false);
  4085. for Y:=StartP.Y to EndP.Y do
  4086. begin
  4087. S:=GetDisplayText(Y);
  4088. { Pierre, please implement undo here! Gabor }
  4089. X1:=0; X2:=length(S)-1;
  4090. if Y=StartP.Y then X1:=StartP.X;
  4091. if Y=EndP.Y then X2:=EndP.X;
  4092. SetStoreUndo(HoldUndo);
  4093. StartPos.X:=X1;
  4094. StartPos.Y:=Y;
  4095. { the only drawback is that we keep
  4096. the original text even if Toggle where
  4097. it is not really necessary PM }
  4098. Addaction(eaOverwriteText,StartPos,StartPos,Copy(S,X1+1,X2-X1+1),GetFlags);
  4099. SetStoreUndo(false);
  4100. for X:=X1 to X2 do
  4101. begin
  4102. C:=S[X+1];
  4103. case CaseAction of
  4104. caToLowerCase : C:=LowCase(C);
  4105. caToUpperCase : C:=UpCase(C);
  4106. caToggleCase : if C in['a'..'z'] then
  4107. C:=Upcase(C)
  4108. else
  4109. C:=LowCase(C);
  4110. end;
  4111. S[X+1]:=C;
  4112. end;
  4113. SetDisplayText(Y,S);
  4114. end;
  4115. UpdateAttrsRange(StartP.Y,EndP.Y,attrAll);
  4116. DrawLines(CurPos.Y);
  4117. SetModified(true);
  4118. Addaction(eaMoveCursor,StartPos,CurPos,'',GetFlags);
  4119. SetStoreUndo(HoldUndo);
  4120. UnLock;
  4121. end;
  4122. procedure TCustomCodeEditor.PushInfo(Const st : string);
  4123. begin
  4124. { Dummies }
  4125. end;
  4126. procedure TCustomCodeEditor.PopInfo;
  4127. begin
  4128. { Dummies }
  4129. end;
  4130. procedure TCustomCodeEditor.InsertOptions;
  4131. begin
  4132. { Abstract }
  4133. NotImplemented;
  4134. end;
  4135. function TCustomCodeEditor.GetLineFold(EditorLine: sw_integer): PFold;
  4136. var L: PCustomLine;
  4137. LI: PEditorLineInfo;
  4138. F: PFold;
  4139. begin
  4140. F:=nil;
  4141. if IsFlagSet(efFolds) then
  4142. if (0<=EditorLine) and (EditorLine<GetLineCount) then
  4143. begin
  4144. L:=GetLine(EditorLine);
  4145. if Assigned(L) then
  4146. LI:=L^.GetEditorInfo(@Self)
  4147. else
  4148. LI:=nil;
  4149. if Assigned(LI) then
  4150. F:=LI^.Fold;
  4151. end;
  4152. GetLineFold:=F;
  4153. end;
  4154. function TCustomCodeEditor.IsLineVisible(EditorLine: sw_integer): boolean;
  4155. var V: boolean;
  4156. F,PrevF: PFold;
  4157. FoldHeadline: boolean;
  4158. begin
  4159. V:=true;
  4160. if IsFlagSet(efFolds) then
  4161. begin
  4162. F:=GetLineFold(EditorLine);
  4163. if Assigned(F) then
  4164. begin
  4165. PrevF:=GetLineFold(EditorLine-1);
  4166. FoldHeadline:=false;
  4167. if (PrevF<>F) and ((PrevF=nil) or (not PrevF^.IsParent(F))) then
  4168. FoldHeadline:=true;
  4169. if FoldHeadline then
  4170. begin
  4171. if Assigned(F^.ParentFold) and (F^.ParentFold^.IsCollapsed) then
  4172. V:=false;
  4173. end
  4174. else
  4175. if F^.IsCollapsed then
  4176. V:=false;
  4177. end;
  4178. end;
  4179. IsLineVisible:=V;
  4180. end;
  4181. function TCustomCodeEditor.ViewToEditorLine(ViewLine: sw_integer): sw_integer;
  4182. var I,Line,Count: sw_integer;
  4183. begin
  4184. if not IsFlagSet(efFolds) then
  4185. Line:=ViewLine
  4186. else
  4187. begin
  4188. Count:=GetLineCount;
  4189. I:=0; Line:=-1;
  4190. while (Line<ViewLine) and (I<Count) do
  4191. begin
  4192. if IsLineVisible(I) then
  4193. Inc(Line);
  4194. Inc(I);
  4195. end;
  4196. if Line<>ViewLine then
  4197. Line:=-1
  4198. else
  4199. Line:=I-1;
  4200. end;
  4201. ViewToEditorLine:=Line;
  4202. end;
  4203. function TCustomCodeEditor.EditorToViewLine(EditorLine: sw_integer): sw_integer;
  4204. var I,Line: sw_integer;
  4205. begin
  4206. if not IsFlagSet(efFolds) then
  4207. Line:=EditorLine
  4208. else
  4209. begin
  4210. Line:=-1;
  4211. for I:=0 to EditorLine do
  4212. if IsLineVisible(I) then
  4213. Inc(Line);
  4214. end;
  4215. EditorToViewLine:=Line;
  4216. end;
  4217. procedure TCustomCodeEditor.ViewToEditorPoint(P: TPoint; var NP: TPoint);
  4218. begin
  4219. NP.X:=P.X-GetReservedColCount;
  4220. NP.Y:=ViewToEditorLine(P.Y);
  4221. end;
  4222. procedure TCustomCodeEditor.EditorToViewPoint(P: TPoint; var NP: TPoint);
  4223. begin
  4224. NP.X:=P.X+GetReservedColCount;
  4225. NP.Y:=EditorToViewLine(P.Y);
  4226. end;
  4227. procedure TCustomCodeEditor.FindMatchingDelimiter(ScanForward: boolean);
  4228. const OpenSymbols : string[6] = '[{(<''"';
  4229. CloseSymbols : string[6] = ']})>''"';
  4230. var SymIdx: integer;
  4231. LineText,LineAttr: string;
  4232. CurChar: char;
  4233. X,Y: sw_integer;
  4234. LineCount: sw_integer;
  4235. JumpPos: TPoint;
  4236. BracketLevel: integer;
  4237. begin
  4238. JumpPos.X:=-1; JumpPos.Y:=-1;
  4239. LineText:=GetDisplayText(CurPos.Y);
  4240. LineText:=copy(LineText,CurPos.X+1,1);
  4241. if LineText='' then Exit;
  4242. CurChar:=LineText[1];
  4243. Y:=CurPos.Y; X:=CurPos.X; LineCount:=0;
  4244. BracketLevel:=1;
  4245. if ScanForward then
  4246. begin
  4247. SymIdx:=Pos(CurChar,OpenSymbols);
  4248. if SymIdx=0 then Exit;
  4249. repeat
  4250. Inc(LineCount);
  4251. GetDisplayTextFormat(Y,LineText,LineAttr);
  4252. if LineCount<>1 then X:=-1;
  4253. repeat
  4254. Inc(X);
  4255. if X<length(LineText) then
  4256. if copy(LineAttr,X+1,1)<>chr(attrComment) then
  4257. if (LineText[X+1]=CloseSymbols[SymIdx]) and (BracketLevel=1) then
  4258. begin
  4259. JumpPos.X:=X; JumpPos.Y:=Y;
  4260. end
  4261. else
  4262. if LineText[X+1]=OpenSymbols[SymIdx] then
  4263. Inc(BracketLevel)
  4264. else
  4265. if LineText[X+1]=CloseSymbols[SymIdx] then
  4266. if BracketLevel>1 then
  4267. Dec(BracketLevel);
  4268. until (X>=length(LineText)) or (JumpPos.X<>-1);
  4269. Inc(Y);
  4270. until (Y>=GetLineCount) or (JumpPos.X<>-1);
  4271. end
  4272. else
  4273. begin
  4274. SymIdx:=Pos(CurChar,CloseSymbols);
  4275. if SymIdx=0 then Exit;
  4276. repeat
  4277. Inc(LineCount);
  4278. GetDisplayTextFormat(Y,LineText,LineAttr);
  4279. if LineCount<>1 then X:=length(LineText);
  4280. repeat
  4281. Dec(X);
  4282. if X>0 then
  4283. if copy(LineAttr,X+1,1)<>chr(attrComment) then
  4284. if (LineText[X+1]=OpenSymbols[SymIdx]) and (BracketLevel=1) then
  4285. begin
  4286. JumpPos.X:=X; JumpPos.Y:=Y;
  4287. end
  4288. else
  4289. if LineText[X+1]=CloseSymbols[SymIdx] then
  4290. Inc(BracketLevel)
  4291. else
  4292. if LineText[X+1]=OpenSymbols[SymIdx] then
  4293. if BracketLevel>1 then
  4294. Dec(BracketLevel);
  4295. until (X<0) or (JumpPos.X<>-1);
  4296. Dec(Y);
  4297. until (Y<0) or (JumpPos.X<>-1);
  4298. end;
  4299. if JumpPos.X<>-1 then
  4300. begin
  4301. SetCurPtr(JumpPos.X,JumpPos.Y);
  4302. TrackCursor(do_centre);
  4303. end;
  4304. end;
  4305. function TCustomCodeEditor.InsertNewLine: Sw_integer;
  4306. var i,Ind: Sw_integer;
  4307. S,IndentStr: string;
  4308. procedure CalcIndent(LineOver: Sw_integer);
  4309. begin
  4310. if (LineOver<0) or (LineOver>GetLineCount) or ((GetFlags and efNoIndent)<>0) then
  4311. Ind:=0 else
  4312. begin
  4313. repeat
  4314. IndentStr:=GetDisplayText(LineOver);
  4315. Dec(LineOver);
  4316. until (LineOver<0) or (IndentStr<>'');
  4317. Ind:=0;
  4318. while (Ind<length(IndentStr)) and (IndentStr[Ind+1]=' ') do
  4319. Inc(Ind);
  4320. end;
  4321. IndentStr:=CharStr(' ',Ind);
  4322. end;
  4323. var {SelBack: sw_integer;}
  4324. SCP: TPoint;
  4325. CI : sw_integer;
  4326. HoldUndo : Boolean;
  4327. L,NewL: PCustomLine;
  4328. EI,NewEI: PEditorLineInfo;
  4329. begin
  4330. if IsReadOnly then begin InsertNewLine:=-1; Exit; end;
  4331. Lock;
  4332. SCP:=CurPos;
  4333. HoldUndo:=GetStoreUndo;
  4334. SetStoreUndo(false);
  4335. if CurPos.Y<GetLineCount then S:=GetLineText(CurPos.Y) else S:='';
  4336. if Overwrite=false then
  4337. begin
  4338. if CurPos.Y<GetLineCount then
  4339. begin
  4340. L:=GetLine(CurPos.Y);
  4341. if not assigned(L) then
  4342. EI:=nil
  4343. else
  4344. EI:=L^.GetEditorInfo(@Self);
  4345. end
  4346. else
  4347. EI:=nil;
  4348. { SelBack:=0;}
  4349. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4350. if GetLineCount>0 then
  4351. begin
  4352. S:=GetLineText(CurPos.Y);
  4353. { SelBack:=length(S)-SelEnd.X;}
  4354. SetLineText(CurPos.Y,RTrim(S,not IsFlagSet(efUseTabCharacters)));
  4355. end;
  4356. SetLineText(CurPos.Y,copy(S,1,CI-1));
  4357. CalcIndent(CurPos.Y);
  4358. S:=copy(S,CI,High(S));
  4359. i:=1;
  4360. while (i<=length(s)) and (i<=length(IndentStr)) and (s[i]=' ') do
  4361. inc(i);
  4362. if i>1 then
  4363. Delete(IndentStr,1,i-1);
  4364. NewL:=InsertLine(CurPos.Y+1,IndentStr+S);
  4365. LimitsChanged;
  4366. (* if PointOfs(SelStart)<>PointOfs(SelEnd) then { !!! check it - it's buggy !!! }
  4367. begin SelEnd.Y:=CurPos.Y+1; SelEnd.X:=length(GetLineText(CurPos.Y+1))-SelBack; end;*)
  4368. UpdateAttrs(CurPos.Y,attrAll);
  4369. SetCurPtr(Ind,CurPos.Y+1);
  4370. NewEI:=NewL^.GetEditorInfo(@Self);
  4371. if Assigned(EI) and Assigned(NewEI) then
  4372. begin
  4373. NewEI^.SetFold(EI^.Fold);
  4374. if Assigned(EI^.Fold) then
  4375. if EI^.Fold^.IsCollapsed then
  4376. EI^.Fold^.Collapse(false);
  4377. end;
  4378. SetStoreUndo(HoldUndo);
  4379. { obsolete IndentStr is taken care of by the Flags PM }
  4380. Addaction(eaInsertLine,SCP,CurPos,CharStr(' ',i-1){IndentStr},GetFlags);
  4381. SetStoreUndo(false);
  4382. AdjustSelectionPos(SCP.X,SCP.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4383. end else
  4384. begin
  4385. CalcIndent(CurPos.Y);
  4386. if CurPos.Y=GetLineCount-1 then
  4387. begin
  4388. AddLine(IndentStr);
  4389. AdjustSelectionBefore(0,1);
  4390. LimitsChanged;
  4391. SetStoreUndo(HoldUndo);
  4392. UpdateAttrs(CurPos.Y,attrAll);
  4393. SetCurPtr(Ind,CurPos.Y+1);
  4394. { obsolete IndentStr is taken care of by the Flags PM }
  4395. Addaction(eaInsertLine,SCP,CurPos,''{IndentStr},GetFlags);
  4396. SetStoreUndo(false);
  4397. end
  4398. else
  4399. begin
  4400. UpdateAttrs(CurPos.Y,attrAll);
  4401. SetStoreUndo(HoldUndo);
  4402. SetCurPtr(Ind,CurPos.Y+1);
  4403. AddAction(eaMoveCursor,SCP,CurPos,'',GetFlags);
  4404. SetStoreUndo(false);
  4405. end;
  4406. end;
  4407. DrawLines(CurPos.Y);
  4408. SetStoreUndo(HoldUndo);
  4409. SetModified(true);
  4410. Unlock;
  4411. end;
  4412. procedure TCustomCodeEditor.BreakLine;
  4413. var
  4414. SCP: TPoint;
  4415. begin
  4416. { Like insert new line, but leave current pos unchanged }
  4417. SCP:=CurPos;
  4418. InsertNewLine;
  4419. SetCurPtr(SCP.X,SCP.Y);
  4420. end;
  4421. procedure TCustomCodeEditor.BackSpace;
  4422. var S,PreS: string;
  4423. OI,CI,CP,Y,TX: Sw_integer;
  4424. SCP,SC1 : TPoint;
  4425. HoldUndo : Boolean;
  4426. begin
  4427. if IsReadOnly then Exit;
  4428. Lock;
  4429. SCP:=CurPos;
  4430. HoldUndo:=GetStoreUndo;
  4431. SetStoreUndo(false);
  4432. if CurPos.X=0 then
  4433. begin
  4434. if CurPos.Y>0 then
  4435. begin
  4436. CI:=Length(GetDisplayText(CurPos.Y-1));
  4437. S:=GetLineText(CurPos.Y-1);
  4438. SetLineText(CurPos.Y-1,S+GetLineText(CurPos.Y));
  4439. SC1.X:=Length(S);SC1.Y:=CurPOS.Y-1;
  4440. SetStoreUndo(HoldUndo);
  4441. AddAction(eaDeleteLine,SCP,SC1,GetLineText(CurPos.Y),GetFlags);
  4442. SetStoreUndo(false);
  4443. DeleteLine(CurPos.Y);
  4444. LimitsChanged;
  4445. SetCurPtr(CI,CurPos.Y-1);
  4446. AdjustSelectionPos(Ci,CurPos.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4447. end;
  4448. end
  4449. else
  4450. begin
  4451. CP:=CurPos.X-1;
  4452. S:=GetLineText(CurPos.Y);
  4453. CI:=LinePosToCharIdx(CurPos.Y,CP);
  4454. if (s[ci]=TAB) and (CharIdxToLinePos(Curpos.y,ci)=cp) then
  4455. CP:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  4456. if IsFlagSet(efBackspaceUnindents) then
  4457. begin
  4458. S:=GetDisplayText(CurPos.Y);
  4459. if Trim(copy(S,1,CP+1))='' then
  4460. begin
  4461. Y:=CurPos.Y;
  4462. while (Y>0) do
  4463. begin
  4464. Dec(Y);
  4465. PreS:=GetDisplayText(Y);
  4466. if Trim(copy(PreS,1,CP+1))<>'' then Break;
  4467. end;
  4468. if Y<0 then PreS:='';
  4469. TX:=0;
  4470. while (TX<length(PreS)) and (PreS[TX+1]=' ') do
  4471. Inc(TX);
  4472. if TX<CP then CP:=TX;
  4473. end;
  4474. end;
  4475. S:=GetLineText(CurPos.Y);
  4476. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4477. CI:=LinePosToCharIdx(CurPos.Y,CP);
  4478. SetLineText(CurPos.Y,copy(S,1,CI-1)+copy(S,OI,High(S)));
  4479. SetCurPtr(CP,CurPos.Y);
  4480. SetStoreUndo(HoldUndo);
  4481. Addaction(eaDeleteText,SCP,CurPos,Copy(S,CI,OI-CI),GetFlags);
  4482. SetStoreUndo(false);
  4483. AdjustSelectionPos(SCP.X-1,SCP.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4484. end;
  4485. UpdateAttrs(CurPos.Y,attrAll);
  4486. DrawLines(CurPos.Y);
  4487. SetStoreUndo(HoldUndo);
  4488. SetModified(true);
  4489. Unlock;
  4490. end;
  4491. procedure TCustomCodeEditor.DelChar;
  4492. var S: string;
  4493. SDX,SDY,CI : sw_integer;
  4494. HoldUndo : boolean;
  4495. SCP : TPoint;
  4496. begin
  4497. if IsReadOnly then Exit;
  4498. Lock;
  4499. HoldUndo:=GetStoreUndo;
  4500. SetStoreUndo(false);
  4501. S:=GetLineText(CurPos.Y);
  4502. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4503. if (CI>length(S)) or (S='') then
  4504. begin
  4505. if CurPos.Y<GetLineCount-1 then
  4506. begin
  4507. SetLineText(CurPos.Y,S+CharStr(' ',CurPOS.X-Length(S))+GetLineText(CurPos.Y+1));
  4508. SDX:=CurPos.X;
  4509. SetStoreUndo(HoldUndo);
  4510. SCP.X:=0;SCP.Y:=CurPos.Y+1;
  4511. AddGroupedAction(eaDelChar);
  4512. AddAction(eaMoveCursor,CurPos,SCP,'',GetFlags);
  4513. S:=GetLineText(CurPos.Y+1);
  4514. AddAction(eaDeleteLine,SCP,CurPos,S,GetFlags);
  4515. CloseGroupedAction(eaDelChar);
  4516. SetStoreUndo(false);
  4517. DeleteLine(CurPos.Y+1);
  4518. LimitsChanged;
  4519. SDY:=-1;
  4520. SetCurPtr(CurPos.X,CurPos.Y);
  4521. UpdateAttrs(CurPos.Y,attrAll);
  4522. AdjustSelectionPos(CurPos.X,CurPos.Y,SDX,SDY);
  4523. end;
  4524. end
  4525. else
  4526. begin
  4527. SCP:=CurPos;
  4528. { Problem if S[CurPos.X+1]=TAB !! PM }
  4529. if S[CI]=TAB then
  4530. begin
  4531. { we want to remove the tab if we are at the first place
  4532. of the tab, but the following test was true for the last position
  4533. in tab
  4534. if CharIdxToLinePos(Curpos.y,ci)=Curpos.x then }
  4535. if CharIdxToLinePos(Curpos.y,ci-1)=Curpos.x-1 then
  4536. Delete(S,Ci,1)
  4537. else
  4538. S:=Copy(S,1,CI-1)+CharStr(' ',GetTabSize-1)+Copy(S,CI+1,High(S));
  4539. SetStoreUndo(HoldUndo);
  4540. Addaction(eaDeleteText,CurPos,CurPos,#9,GetFlags);
  4541. SDX:=-1;
  4542. SetStoreUndo(false);
  4543. end
  4544. else
  4545. begin
  4546. SetStoreUndo(HoldUndo);
  4547. Addaction(eaDeleteText,CurPos,CurPos,S[CI],GetFlags);
  4548. SetStoreUndo(false);
  4549. SDX:=-1;
  4550. Delete(S,CI,1);
  4551. end;
  4552. SetLineText(CurPos.Y,S);
  4553. SDY:=0;
  4554. SetCurPtr(CurPos.X,CurPos.Y);
  4555. UpdateAttrs(CurPos.Y,attrAll);
  4556. AdjustSelectionPos(SCP.X,SCP.Y,SDX,SDY);
  4557. end;
  4558. DrawLines(CurPos.Y);
  4559. SetStoreUndo(HoldUndo);
  4560. SetModified(true);
  4561. Unlock;
  4562. end;
  4563. procedure TCustomCodeEditor.DelWord;
  4564. var
  4565. SP,EP : TPoint;
  4566. SelSize : sw_integer;
  4567. begin
  4568. if IsReadOnly then Exit;
  4569. Lock;
  4570. SP:=SelStart;
  4571. EP:=SelEnd;
  4572. SetSelection(SelStart,SelStart);
  4573. SelectWord;
  4574. SelSize:=SelEnd.X-SelStart.X;
  4575. DelSelect;
  4576. SetSelection(SP,EP);
  4577. AdjustSelectionPos(CurPos.X,CurPos.Y,-SelSize,0);
  4578. if SelSize>0 then
  4579. SetModified(true);
  4580. Unlock;
  4581. end;
  4582. procedure TCustomCodeEditor.DelToEndOfWord;
  4583. var
  4584. SP,EP : TPoint;
  4585. S : String;
  4586. SelSize : sw_integer;
  4587. begin
  4588. if IsReadOnly then Exit;
  4589. Lock;
  4590. SP:=SelStart;
  4591. EP:=SelEnd;
  4592. SetSelection(SelStart,SelStart);
  4593. SelectWord;
  4594. S:=GetDisplayText(CurPos.Y);
  4595. if ((SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y)) then
  4596. begin
  4597. if (Length(S) <= CurPos.X) then
  4598. begin
  4599. SetSelection(SP,EP);
  4600. DelChar;
  4601. Unlock;
  4602. exit;
  4603. end
  4604. else
  4605. begin
  4606. SelEnd.X:=CurPos.X+1;
  4607. SelEnd.Y:=CurPos.Y;
  4608. end;
  4609. end;
  4610. while (length(S)>= SelEnd.X+1) and
  4611. ((S[SelEnd.X+1]=' ') or (S[SelEnd.X+1]=TAB)) do
  4612. inc(SelEnd.X);
  4613. SetSelection(CurPos,SelEnd);
  4614. SelSize:=SelEnd.X-SelStart.X;
  4615. DelSelect;
  4616. SetSelection(SP,EP);
  4617. AdjustSelectionPos(CurPos.X,CurPos.Y,-SelSize,0);
  4618. if SelSize>0 then
  4619. SetModified(true);
  4620. Unlock;
  4621. end;
  4622. procedure TCustomCodeEditor.DelStart;
  4623. var S: string;
  4624. OI: Sw_integer;
  4625. HoldUndo : Boolean;
  4626. SCP : TPoint;
  4627. begin
  4628. if IsReadOnly then Exit;
  4629. Lock;
  4630. HoldUndo:=GetStoreUndo;
  4631. SetStoreUndo(false);
  4632. SCP:=CurPos;
  4633. S:=GetLineText(CurPos.Y);
  4634. if (S<>'') and (CurPos.X<>0) then
  4635. begin
  4636. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4637. SetLineText(CurPos.Y,copy(S,OI,High(S)));
  4638. SetCurPtr(0,CurPos.Y);
  4639. SetStoreUndo(HoldUndo);
  4640. Addaction(eaDeleteText,SCP,CurPos,copy(S,1,OI-1),GetFlags);
  4641. SetStoreUndo(false);
  4642. AdjustSelectionPos(CurPos.X,CurPos.Y,-length(copy(S,1,OI-1)),0);
  4643. UpdateAttrs(CurPos.Y,attrAll);
  4644. DrawLines(CurPos.Y);
  4645. SetModified(true);
  4646. end;
  4647. SetStoreUndo(HoldUndo);
  4648. Unlock;
  4649. end;
  4650. procedure TCustomCodeEditor.DelEnd;
  4651. var S: string;
  4652. OI: Sw_integer;
  4653. HoldUndo : Boolean;
  4654. SCP : TPoint;
  4655. begin
  4656. if IsReadOnly then Exit;
  4657. Lock;
  4658. HoldUndo:=GetStoreUndo;
  4659. SetStoreUndo(false);
  4660. SCP:=CurPos;
  4661. S:=GetLineText(CurPos.Y);
  4662. if (S<>'') and (CurPos.X<>length(S)) then
  4663. begin
  4664. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4665. SetLineText(CurPos.Y,copy(S,1,OI-1));
  4666. SetCurPtr(CurPos.X,CurPos.Y);
  4667. SetStoreUndo(HoldUndo);
  4668. Addaction(eaDeleteText,SCP,CurPos,copy(S,OI,High(S)),GetFlags);
  4669. SetStoreUndo(false);
  4670. AdjustSelectionPos(CurPos.X+1,CurPos.Y,-length(copy(S,OI,High(S)))+1,0);
  4671. UpdateAttrs(CurPos.Y,attrAll);
  4672. DrawLines(CurPos.Y);
  4673. SetModified(true);
  4674. end;
  4675. SetStoreUndo(HoldUndo);
  4676. Unlock;
  4677. end;
  4678. procedure TCustomCodeEditor.DelLine;
  4679. var
  4680. HoldUndo : boolean;
  4681. SP : TPoint;
  4682. S : String;
  4683. begin
  4684. if IsReadOnly then Exit;
  4685. Lock;
  4686. if GetLineCount>0 then
  4687. begin
  4688. SP:=CurPos;
  4689. S:=GetLineText(CurPos.Y);
  4690. HoldUndo:=GetStoreUndo;
  4691. SetStoreUndo(false);
  4692. DeleteLine(CurPos.Y);
  4693. LimitsChanged;
  4694. AdjustSelectionBefore(0,-1);
  4695. SetCurPtr(0,CurPos.Y);
  4696. UpdateAttrs(Max(0,CurPos.Y-1),attrAll);
  4697. DrawLines(CurPos.Y);
  4698. SetStoreUndo(HoldUndo);
  4699. AddAction(eaDeleteLine,SP,CurPos,S,GetFlags);
  4700. SetModified(true);
  4701. end;
  4702. Unlock;
  4703. end;
  4704. procedure TCustomCodeEditor.InsMode;
  4705. begin
  4706. SetInsertMode(Overwrite);
  4707. end;
  4708. function TCustomCodeEditor.GetCurrentWordArea(var StartP,EndP: TPoint): boolean;
  4709. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  4710. var P : TPoint;
  4711. S : String;
  4712. StartPos,EndPos : byte;
  4713. OK: boolean;
  4714. begin
  4715. P:=CurPos;
  4716. S:=GetLineText(P.Y);
  4717. StartPos:=P.X+1;
  4718. EndPos:=StartPos;
  4719. OK:=(S[StartPos] in WordChars);
  4720. if OK then
  4721. begin
  4722. While (StartPos>1) and (S[StartPos-1] in WordChars) do
  4723. Dec(StartPos);
  4724. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  4725. Inc(EndPos);
  4726. StartP.X:=StartPos-1; StartP.Y:=CurPos.Y;
  4727. EndP.X:=EndPos-1; EndP.Y:=CurPos.Y;
  4728. end;
  4729. GetCurrentWordArea:=OK;
  4730. end;
  4731. function TCustomCodeEditor.GetCurrentWord : string;
  4732. var S: string;
  4733. StartP,EndP: TPoint;
  4734. begin
  4735. if GetCurrentWordArea(StartP,EndP)=false then
  4736. S:=''
  4737. else
  4738. begin
  4739. S:=GetLineText(StartP.Y);
  4740. S:=copy(S,StartP.X+1,EndP.X-StartP.X+1);
  4741. end;
  4742. GetCurrentWord:=S;
  4743. end;
  4744. procedure TCustomCodeEditor.StartSelect;
  4745. var P1,P2: TPoint;
  4746. begin
  4747. if ValidBlock=false then
  4748. begin
  4749. { SetSelection(SelStart,Limit);}
  4750. P1:=CurPos; P1.X:=0; P2:=CurPos; {P2.X:=length(GetLineText(P2.Y))+1;}
  4751. SetSelection(P1,P2);
  4752. end
  4753. else
  4754. SetSelection(CurPos,SelEnd);
  4755. if PointOfs(SelEnd)<PointOfs(SelStart) then
  4756. SetSelection(SelStart,SelStart);
  4757. CheckSels;
  4758. DrawView;
  4759. end;
  4760. procedure TCustomCodeEditor.EndSelect;
  4761. var P: TPoint;
  4762. LS: sw_integer;
  4763. begin
  4764. P:=CurPos;
  4765. { P.X:=Min(SelEnd.X,length(GetLineText(SelEnd.Y)));}
  4766. LS:=length(GetLineText(SelEnd.Y));
  4767. if LS<P.X then P.X:=LS;
  4768. CheckSels;
  4769. SetSelection(SelStart,P);
  4770. DrawView;
  4771. end;
  4772. procedure TCustomCodeEditor.DelSelect;
  4773. var LineDelta, LineCount, CurLine: Sw_integer;
  4774. StartX,EndX,LastX: Sw_integer;
  4775. S: string;
  4776. SPos : TPoint;
  4777. begin
  4778. if IsReadOnly or (ValidBlock=false) then Exit;
  4779. Lock;
  4780. AddGroupedAction(eaDelBlock);
  4781. LineCount:=(SelEnd.Y-SelStart.Y)+1;
  4782. LineDelta:=0; LastX:=CurPos.X;
  4783. CurLine:=SelStart.Y;
  4784. { single line : easy }
  4785. if LineCount=1 then
  4786. begin
  4787. S:=GetDisplayText(CurLine);
  4788. StartX:=SelStart.X;
  4789. EndX:=SelEnd.X;
  4790. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4791. +copy(S,EndX+1,High(S)));
  4792. if GetStoreUndo then
  4793. begin
  4794. SPos.X:=StartX;
  4795. SPos.Y:=CurLine;
  4796. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,EndX-StartX),GetFlags);
  4797. end;
  4798. Inc(CurLine);
  4799. LastX:=SelStart.X;
  4800. end
  4801. { several lines : a bit less easy }
  4802. else
  4803. begin
  4804. S:=GetDisplayText(CurLine);
  4805. StartX:=SelStart.X;
  4806. EndX:=SelEnd.X;
  4807. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4808. +copy(GetDisplayText(CurLine+LineCount-1),EndX+1,High(S)));
  4809. if GetStoreUndo then
  4810. begin
  4811. SPos.X:=StartX;
  4812. SPos.Y:=CurLine;
  4813. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,High(S)),GetFlags);
  4814. S:=GetDisplayText(CurLine+LineCount-1);
  4815. end;
  4816. Inc(CurLine);
  4817. Inc(LineDelta);
  4818. LastX:=SelStart.X;
  4819. while (LineDelta<LineCount) do
  4820. begin
  4821. { delete the complete line }
  4822. DeleteLine(CurLine);
  4823. Inc(LineDelta);
  4824. end;
  4825. if GetStoreUndo then
  4826. begin
  4827. AddAction(eaInsertText,SPos,SPos,Copy(S,EndX+1,High(S)),GetFlags);
  4828. end;
  4829. end;
  4830. HideSelect;
  4831. SetCurPtr(LastX,CurLine-1);
  4832. UpdateAttrs(CurPos.Y,attrAll);
  4833. DrawLines(CurPos.Y);
  4834. SetModified(true);
  4835. CloseGroupedAction(eaDelBlock);
  4836. UnLock;
  4837. end;
  4838. procedure TCustomCodeEditor.HideSelect;
  4839. begin
  4840. SetSelection(CurPos,CurPos);
  4841. DrawLines(Delta.Y);
  4842. end;
  4843. procedure TCustomCodeEditor.CopyBlock;
  4844. var Temp: PCodeEditor;
  4845. R: TRect;
  4846. begin
  4847. if IsReadOnly or (ValidBlock=false) then Exit;
  4848. Lock;
  4849. GetExtent(R);
  4850. AddGroupedAction(eaCopyBlock);
  4851. New(Temp, Init(R, nil, nil, nil,nil));
  4852. Temp^.InsertFrom(@Self);
  4853. (* Temp^.SelectAll(true);
  4854. { this selects one line too much because
  4855. we have a empty line at creation to avoid
  4856. negative line problems so we need to decrease SelEnd.Y }
  4857. Dec(Temp^.SelEnd.Y);*)
  4858. InsertFrom(Temp);
  4859. Dispose(Temp, Done);
  4860. CloseGroupedAction(eaCopyBlock);
  4861. UnLock;
  4862. end;
  4863. procedure TCustomCodeEditor.MoveBlock;
  4864. var Temp: PCodeEditor;
  4865. R: TRect;
  4866. OldPos: TPoint;
  4867. begin
  4868. if IsReadOnly then Exit;
  4869. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4870. Lock;
  4871. AddGroupedAction(eaMoveBlock);
  4872. GetExtent(R);
  4873. New(Temp, Init(R, nil, nil, nil,nil));
  4874. Temp^.InsertFrom(@Self);
  4875. OldPos:=CurPos;
  4876. if CurPos.Y>SelStart.Y then
  4877. Dec(OldPos.Y,Temp^.GetLineCount-1);
  4878. DelSelect;
  4879. SetCurPtr(OldPos.X,OldPos.Y);
  4880. InsertFrom(Temp);
  4881. Dispose(Temp, Done);
  4882. CloseGroupedAction(eaMoveBlock);
  4883. UnLock;
  4884. end;
  4885. procedure TCustomCodeEditor.IndentBlock;
  4886. var
  4887. ey,i{,indlen} : Sw_integer;
  4888. S,Ind : String;
  4889. Pos : Tpoint;
  4890. begin
  4891. if IsReadOnly then Exit;
  4892. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4893. Lock;
  4894. AddGroupedAction(eaIndentBlock);
  4895. ey:=selend.y;
  4896. if selend.x=0 then
  4897. dec(ey);
  4898. S:='';
  4899. { If AutoIndent try to align first line to
  4900. last line before selection }
  4901. { DISABLED created problems PM
  4902. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4903. begin
  4904. i:=SelStart.Y-1;
  4905. while (S='') and (i>=0) do
  4906. begin
  4907. S:=GetDisplayText(i);
  4908. dec(i);
  4909. end;
  4910. if (S='') or (S[1]<>' ') then
  4911. Ind:=' '
  4912. else
  4913. begin
  4914. i:=1;
  4915. while (i<=Length(S)) and (S[i]=' ') do
  4916. inc(i);
  4917. indlen:=i;
  4918. S:=GetDisplayText(SelStart.Y);
  4919. i:=1;
  4920. while (i<=Length(S)) and (S[i]=' ') do
  4921. inc(i);
  4922. indlen:=indlen-i;
  4923. if indlen<=0 then
  4924. indlen:=1;
  4925. Ind:=CharStr(' ',indlen);
  4926. end;
  4927. end
  4928. else
  4929. Ind:=' ';}
  4930. Ind:=CharStr(' ',GetIndentSize);
  4931. for i:=selstart.y to ey do
  4932. begin
  4933. S:=GetLineText(i);
  4934. SetLineText(i,Ind+S);
  4935. Pos.X:=0;Pos.Y:=i;
  4936. AddAction(eaInsertText,Pos,Pos,Ind,GetFlags);
  4937. end;
  4938. SetCurPtr(CurPos.X,CurPos.Y);
  4939. { must be added manually here PM }
  4940. AddAction(eaMoveCursor,Pos,CurPos,'',GetFlags);
  4941. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  4942. DrawLines(CurPos.Y);
  4943. SetModified(true);
  4944. CloseGroupedAction(eaIndentBlock);
  4945. UnLock;
  4946. end;
  4947. procedure TCustomCodeEditor.UnindentBlock;
  4948. var
  4949. ey,i,j,k,indlen : Sw_integer;
  4950. S : String;
  4951. Pos : TPoint;
  4952. begin
  4953. if IsReadOnly then Exit;
  4954. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4955. Lock;
  4956. AddGroupedAction(eaUnindentBlock);
  4957. ey:=selend.y;
  4958. if selend.x=0 then
  4959. dec(ey);
  4960. { If AutoIndent try to align first line to
  4961. last line before selection }
  4962. { Disabled created problems
  4963. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4964. begin
  4965. S:=GetDisplayText(SelStart.Y);
  4966. i:=1;
  4967. while (i<=Length(S)) and (S[i]=' ') do
  4968. inc(i);
  4969. indlen:=i-1;
  4970. i:=SelStart.Y-1;
  4971. S:='';
  4972. while (S='') and (i>=0) do
  4973. begin
  4974. if Trim(Copy(GetDisplayText(i),1,indlen))='' then
  4975. S:=''
  4976. else
  4977. S:=GetDisplayText(i);
  4978. dec(i);
  4979. end;
  4980. if (S='') then
  4981. Indlen:=1
  4982. else
  4983. begin
  4984. i:=1;
  4985. while (i<=Length(S)) and (S[i]=' ') do
  4986. inc(i);
  4987. indlen:=indlen-i+1;
  4988. if indlen<=0 then
  4989. indlen:=1;
  4990. end;
  4991. end
  4992. else
  4993. Indlen:=1;}
  4994. Indlen:=GetIndentSize;
  4995. for i:=selstart.y to ey do
  4996. begin
  4997. S:=GetLineText(i);
  4998. k:=0;
  4999. for j:=1 to indlen do
  5000. if (length(s)>1) and (S[1]=' ') then
  5001. begin
  5002. Delete(s,1,1);
  5003. inc(k);
  5004. end;
  5005. SetLineText(i,S);
  5006. if k>0 then
  5007. begin
  5008. Pos.Y:=i;
  5009. Pos.X:=0;
  5010. AddAction(eaDeleteText,Pos,Pos,CharStr(' ',k),GetFlags);
  5011. end;
  5012. end;
  5013. SetCurPtr(CurPos.X,CurPos.Y);
  5014. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  5015. DrawLines(CurPos.Y);
  5016. SetModified(true);
  5017. CloseGroupedAction(eaUnindentBlock);
  5018. UnLock;
  5019. end;
  5020. procedure TCustomCodeEditor.SelectWord;
  5021. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  5022. var S : String;
  5023. StartPos,EndPos : byte;
  5024. A,B: TPoint;
  5025. begin
  5026. A:=CurPos;
  5027. B:=CurPos;
  5028. S:=GetDisplayText(A.Y);
  5029. StartPos:=A.X+1;
  5030. EndPos:=StartPos;
  5031. if not (S[StartPos] in WordChars) then
  5032. exit
  5033. else
  5034. begin
  5035. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  5036. Dec(StartPos);
  5037. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  5038. Inc(EndPos);
  5039. A.X:=StartPos-1;
  5040. B.X:=EndPos;
  5041. SetSelection(A,B);
  5042. end;
  5043. end;
  5044. procedure TCustomCodeEditor.SelectLine;
  5045. var A,B: TPoint;
  5046. begin
  5047. if CurPos.Y<GetLineCount then
  5048. begin
  5049. A.Y:=CurPos.Y; A.X:=0;
  5050. B.Y:=CurPos.Y+1; B.X:=0;
  5051. SetSelection(A,B);
  5052. end;
  5053. end;
  5054. procedure TCustomCodeEditor.WriteBlock;
  5055. var FileName: string;
  5056. S: PBufStream;
  5057. begin
  5058. if ValidBlock=false then Exit;
  5059. FileName:='';
  5060. if EditorDialog(edWriteBlock, @FileName) <> cmCancel then
  5061. begin
  5062. FileName := FExpand(FileName);
  5063. New(S, Init(FileName, stCreate, 4096));
  5064. if (S=nil) or (S^.Status<>stOK) then
  5065. EditorDialog(edCreateError,@FileName)
  5066. else
  5067. if SaveAreaToStream(S,SelStart,SelEnd)=false then
  5068. EditorDialog(edWriteError,@FileName);
  5069. if Assigned(S) then Dispose(S, Done);
  5070. end;
  5071. end;
  5072. procedure TCustomCodeEditor.ReadBlock;
  5073. var FileName: string;
  5074. S: PFastBufStream;
  5075. E: PCodeEditor;
  5076. R: TRect;
  5077. begin
  5078. if IsReadOnly then Exit;
  5079. FileName:='';
  5080. if EditorDialog(edReadBlock, @FileName) <> cmCancel then
  5081. begin
  5082. FileName := FExpand(FileName);
  5083. New(S, Init(FileName, stOpenRead, 4096));
  5084. if (S=nil) or (S^.Status<>stOK) then
  5085. EditorDialog(edReadError,@FileName)
  5086. else
  5087. begin
  5088. R.Assign(0,0,0,0);
  5089. New(E, Init(R,nil,nil,nil,nil));
  5090. AddGroupedAction(eaReadBlock);
  5091. if E^.LoadFromStream(S)=false then
  5092. EditorDialog(edReadError,@FileName)
  5093. else
  5094. begin
  5095. E^.SelectAll(true);
  5096. Self.InsertFrom(E);
  5097. end;
  5098. CloseGroupedAction(eaReadBlock);
  5099. Dispose(E, Done);
  5100. end;
  5101. if Assigned(S) then Dispose(S, Done);
  5102. end;
  5103. end;
  5104. procedure TCustomCodeEditor.PrintBlock;
  5105. begin
  5106. NotImplemented; Exit;
  5107. end;
  5108. function TCustomCodeEditor.SelectCodeTemplate(var ShortCut: string): boolean;
  5109. begin
  5110. { Abstract }
  5111. SelectCodeTemplate:=false;
  5112. end;
  5113. procedure TCustomCodeEditor.ExpandCodeTemplate;
  5114. var Line,ShortCutInEditor,ShortCut: string;
  5115. X,Y,I,LineIndent: sw_integer;
  5116. CodeLines: PUnsortedStringCollection;
  5117. CanJump: boolean;
  5118. CP: TPoint;
  5119. begin
  5120. {
  5121. The usage of editing primitives in this routine make it pretty slow, but
  5122. its speed is still acceptable and they make the implementation of Undo
  5123. much easier... - Gabor
  5124. }
  5125. if IsReadOnly then Exit;
  5126. Lock;
  5127. CP.X:=-1; CP.Y:=-1;
  5128. Line:=GetDisplayText(CurPos.Y);
  5129. X:=CurPos.X; ShortCut:='';
  5130. if X<=length(Line) then
  5131. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  5132. begin
  5133. ShortCut:=Line[X]+ShortCut;
  5134. Dec(X);
  5135. end;
  5136. ShortCutInEditor:=ShortCut;
  5137. New(CodeLines, Init(10,10));
  5138. if (ShortCut='') or (not TranslateCodeTemplate(ShortCut,CodeLines)) then
  5139. if SelectCodeTemplate(ShortCut) then
  5140. TranslateCodeTemplate(ShortCut,CodeLines);
  5141. if CodeLines^.Count>0 then
  5142. begin
  5143. LineIndent:=X;
  5144. SetCurPtr(X,CurPos.Y);
  5145. if Copy(ShortCut,1,length(ShortCutInEditor))=ShortCutInEditor then
  5146. begin
  5147. for I:=1 to length(ShortCutInEditor) do
  5148. DelChar;
  5149. end
  5150. else
  5151. { restore correct position }
  5152. SetCurPtr(X+Length(ShortCutInEditor),CurPos.Y);
  5153. for Y:=0 to CodeLines^.Count-1 do
  5154. begin
  5155. Line:=GetStr(CodeLines^.At(Y));
  5156. CanJump:=false;
  5157. if (Y>0) then
  5158. begin
  5159. CanJump:=Trim(GetLineText(CurPos.Y))='';
  5160. if CanJump=false then
  5161. begin
  5162. (* for X:=1 to LineIndent do { indent template lines to align }
  5163. AddChar(' '); { them to the first line }*)
  5164. InsertText(CharStr(' ',LineIndent));
  5165. end
  5166. else
  5167. SetCurPtr(CurPos.X+LineIndent,CurPos.Y);
  5168. end;
  5169. I:=Pos(CodeTemplateCursorChar,Line);
  5170. if I>0 then
  5171. begin
  5172. Delete(Line,I,1);
  5173. CP.X:=CurPos.X+I-1;
  5174. CP.Y:=CurPos.Y;
  5175. end;
  5176. InsertText(Line);
  5177. if Y<CodeLines^.Count-1 then
  5178. begin
  5179. InsertNewLine; { line break }
  5180. if CanJump=false then
  5181. begin
  5182. while CurPos.X>0 do { unindent }
  5183. begin
  5184. SetCurPtr(CurPos.X-1,CurPos.Y);
  5185. DelChar;
  5186. end;
  5187. end
  5188. else
  5189. SetCurPtr(0,CurPos.Y);
  5190. end;
  5191. end;
  5192. end;
  5193. Dispose(CodeLines, Done);
  5194. if (CP.X<>-1) and (CP.Y<>-1) then
  5195. SetCurPtr(CP.X,CP.Y);
  5196. UnLock;
  5197. end;
  5198. procedure TCustomCodeEditor.AddChar(C: char);
  5199. const OpenBrackets : string[10] = '[({';
  5200. CloseBrackets : string[10] = '])}';
  5201. var S,SC,TabS: string;
  5202. BI: byte;
  5203. CI,TabStart,LocTabSize : Sw_integer;
  5204. SP: TPoint;
  5205. HoldUndo : boolean;
  5206. begin
  5207. if IsReadOnly then Exit;
  5208. Lock;
  5209. SP:=CurPos;
  5210. HoldUndo:=GetStoreUndo;
  5211. SetStoreUndo(false);
  5212. if (C<>TAB) or IsFlagSet(efUseTabCharacters) then
  5213. SC:=C
  5214. else
  5215. begin
  5216. LocTabSize:=GetTabSize - (CurPos.X mod GetTabSize);
  5217. if (CurPos.Y<=1) or not IsFlagSet(efAutoIndent) then
  5218. SC:=CharStr(' ',LocTabSize)
  5219. else
  5220. begin
  5221. S:=GetLineText(CurPos.Y-1);
  5222. BI:=CurPos.X+1;
  5223. while (BI<=Length(S)) and (S[BI]=' ') do
  5224. inc(BI);
  5225. if (BI=CurPos.X+1) or (BI>Length(S)) then
  5226. SC:=CharStr(' ',LocTabSize)
  5227. else
  5228. SC:=CharStr(' ',BI-CurPos.X-1);
  5229. end;
  5230. end;
  5231. S:=GetLineText(CurPos.Y);
  5232. if CharIdxToLinePos(CurPos.Y,length(S))<CurPos.X then
  5233. begin
  5234. S:=S+CharStr(' ',CurPos.X-CharIdxToLinePos(CurPos.Y,length(S)){-1});
  5235. SetLineText(CurPos.Y,S);
  5236. end;
  5237. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  5238. if CI>High(S) then
  5239. begin
  5240. Unlock;
  5241. exit;
  5242. end;
  5243. if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then
  5244. begin
  5245. if CI=1 then
  5246. TabStart:=0
  5247. else
  5248. TabStart:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  5249. if SC=Tab then TabS:=Tab else
  5250. TabS:=CharStr(' ',CurPos.X-TabStart);
  5251. SetLineText(CurPos.Y,copy(S,1,CI-1)+TabS+SC+copy(S,CI+1,High(S)));
  5252. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(TabS)+length(SC)),CurPos.Y);
  5253. end
  5254. else
  5255. begin
  5256. if Overwrite and (CI<=length(S)) then
  5257. begin
  5258. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI+length(SC),High(S)));
  5259. end
  5260. else
  5261. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI,High(S)));
  5262. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(SC)),CurPos.Y);
  5263. end;
  5264. { must be before CloseBrackets !! }
  5265. SetStoreUndo(HoldUndo);
  5266. if Overwrite then
  5267. Addaction(eaOverwriteText,SP,CurPos,Copy(S,CI,length(SC)),GetFlags)
  5268. else
  5269. Addaction(eaInsertText,SP,CurPos,SC,GetFlags);
  5270. SetStoreUndo(false);
  5271. if IsFlagSet(efAutoBrackets) then
  5272. begin
  5273. BI:=Pos(C,OpenBrackets);
  5274. if (BI>0) then
  5275. begin
  5276. SetStoreUndo(HoldUndo);
  5277. AddChar(CloseBrackets[BI]);
  5278. SetStoreUndo(false);
  5279. SetCurPtr(CurPos.X-1,CurPos.Y);
  5280. end;
  5281. end;
  5282. UpdateAttrs(CurPos.Y,attrAll);
  5283. if GetInsertMode then
  5284. AdjustSelection(CurPos.X-SP.X,CurPos.Y-SP.Y);
  5285. DrawLines(CurPos.Y);
  5286. SetStoreUndo(HoldUndo);
  5287. SetModified(true);
  5288. UnLock;
  5289. end;
  5290. {$ifdef WinClipSupported}
  5291. const
  5292. linelimit = 200;
  5293. function TCustomCodeEditor.ClipPasteWin: Boolean;
  5294. var
  5295. StorePos : TPoint;
  5296. first : boolean;
  5297. procedure InsertStringWrap(const s: string; var i : Longint);
  5298. var
  5299. BPos,EPos: TPoint;
  5300. begin
  5301. if first then
  5302. begin
  5303. { we need to cut the line in two
  5304. if not at end of line PM }
  5305. InsertNewLine;
  5306. SetCurPtr(StorePos.X,StorePos.Y);
  5307. InsertText(s);
  5308. first:=false;
  5309. end
  5310. else
  5311. begin
  5312. Inc(i);
  5313. InsertLine(i,s);
  5314. BPos.X:=0;BPos.Y:=i;
  5315. EPOS.X:=Length(s);EPos.Y:=i;
  5316. AddAction(eaInsertLine,BPos,EPos,GetDisplayText(i),GetFlags);
  5317. end;
  5318. end;
  5319. var
  5320. OK: boolean;
  5321. l,i,len,len10 : longint;
  5322. p,p10,p2,p13 : pchar;
  5323. s : string;
  5324. begin
  5325. Lock;
  5326. OK:=WinClipboardSupported;
  5327. if OK then
  5328. begin
  5329. first:=true;
  5330. StorePos:=CurPos;
  5331. i:=CurPos.Y;
  5332. l:=GetTextWinClipboardSize;
  5333. if l=0 then
  5334. OK:=false
  5335. else
  5336. OK:=GetTextWinClipBoardData(p,l);
  5337. if OK then
  5338. begin
  5339. if l>500 then
  5340. PushInfo(msg_readingwinclipboard);
  5341. AddGroupedAction(eaPasteWin);
  5342. p2:=p;
  5343. len:=strlen(p2);
  5344. // issue lines ((#13)#10 terminated) of maximally "linelimit" chars.
  5345. // does not take initial X position into account
  5346. repeat
  5347. p13:=strpos(p2,#13);
  5348. p10:=strpos(p2,#10);
  5349. if len> linelimit then
  5350. len:=linelimit;
  5351. if assigned(p10) then
  5352. begin
  5353. len10:=p10-p2;
  5354. if len10<len then
  5355. begin
  5356. if p13+1=p10 then
  5357. dec(len10);
  5358. len:=len10;
  5359. end
  5360. else
  5361. p10:=nil; // signal no cleanup
  5362. end;
  5363. setlength(s,len);
  5364. if len>0 then
  5365. move(p2^,s[1],len);
  5366. // cleanup
  5367. if assigned(p10) then
  5368. p2:=p10+1
  5369. else
  5370. inc(p2,len);
  5371. insertstringwrap(s,i);
  5372. len:=strlen(p2);
  5373. until len=0;
  5374. SetCurPtr(StorePos.X,StorePos.Y); // y+i to get after paste?
  5375. SetModified(true);
  5376. UpdateAttrs(StorePos.Y,attrAll);
  5377. CloseGroupedAction(eaPasteWin);
  5378. Update;
  5379. if l>500 then
  5380. PopInfo;
  5381. { we must free the allocated memory }
  5382. freemem(p,l);
  5383. DrawView;
  5384. end;
  5385. end;
  5386. ClipPasteWin:=OK;
  5387. UnLock;
  5388. end;
  5389. function TCustomCodeEditor.ClipCopyWin: Boolean;
  5390. var OK,ShowInfo: boolean;
  5391. p,p2 : pchar;
  5392. s : string;
  5393. i,str_begin,str_end,NumLines,PcLength : longint;
  5394. begin
  5395. NumLines:=SelEnd.Y-SelStart.Y;
  5396. if (NumLines>0) or (SelEnd.X>SelStart.X) then
  5397. Inc(NumLines);
  5398. if NumLines=0 then
  5399. exit;
  5400. Lock;
  5401. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5402. if ShowInfo then
  5403. PushInfo(msg_copyingwinclipboard);
  5404. { First calculate needed size }
  5405. { for newlines first + 1 for terminal #0 }
  5406. PcLength:=Length(EOL)*(NumLines-1)+1;
  5407. { overestimated but can not be that big PM }
  5408. for i:=SelStart.Y to SelEnd.Y do
  5409. PCLength:=PCLength+Length(GetLineText(i));
  5410. getmem(p,PCLength);
  5411. i:=SelStart.Y;
  5412. s:=GetLineText(i);
  5413. str_begin:=LinePosToCharIdx(i,SelStart.X);
  5414. if SelEnd.Y>SelStart.Y then
  5415. str_end:=High(S)
  5416. else
  5417. str_end:=LinePosToCharIdx(i,SelEnd.X)-1;
  5418. s:=copy(s,str_begin,str_end-str_begin+1);
  5419. strpcopy(p,s);
  5420. p2:=strend(p);
  5421. inc(i);
  5422. while i<SelEnd.Y do
  5423. begin
  5424. strpcopy(p2,EOL+GetLineText(i));
  5425. p2:=strend(p2);
  5426. Inc(i);
  5427. end;
  5428. if SelEnd.Y>SelStart.Y then
  5429. begin
  5430. s:=copy(GetLineText(i),1,LinePosToCharIdx(i,SelEnd.X)-1);
  5431. strpcopy(p2,EOL+s);
  5432. end;
  5433. OK:=WinClipboardSupported;
  5434. if OK then
  5435. begin
  5436. OK:=SetTextWinClipBoardData(p,strlen(p));
  5437. end;
  5438. ClipCopyWin:=OK;
  5439. if ShowInfo then
  5440. PopInfo;
  5441. Freemem(p,PCLength);
  5442. UnLock;
  5443. end;
  5444. {$endif WinClipSupported}
  5445. function TCustomCodeEditor.ClipCopy: Boolean;
  5446. var ShowInfo,CanPaste: boolean;
  5447. begin
  5448. Lock;
  5449. {AddGroupedAction(eaCopy);
  5450. can we undo a copy ??
  5451. maybe as an Undo Paste in Clipboard !! }
  5452. clipcopy:=false;
  5453. showinfo:=false;
  5454. if (clipboard<>nil) and (clipboard<>@self) then
  5455. begin
  5456. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5457. if ShowInfo then
  5458. PushInfo(msg_copyingclipboard);
  5459. clipcopy:=Clipboard^.InsertFrom(@Self);
  5460. if ShowInfo then
  5461. PopInfo;
  5462. {Enable paste command.}
  5463. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5464. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5465. SetCmdState(FromClipCmds,CanPaste);
  5466. end;
  5467. UnLock;
  5468. end;
  5469. procedure TCustomCodeEditor.ClipCut;
  5470. var
  5471. ShowInfo,CanPaste : boolean;
  5472. begin
  5473. if IsReadOnly then Exit;
  5474. Lock;
  5475. AddGroupedAction(eaCut);
  5476. DontConsiderShiftState:=true;
  5477. if (clipboard<>nil) and (clipboard<>@self) then
  5478. begin
  5479. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5480. if ShowInfo then
  5481. PushInfo(msg_cutting);
  5482. if Clipboard^.InsertFrom(@Self) then
  5483. begin
  5484. if not IsClipBoard then
  5485. DelSelect;
  5486. SetModified(true);
  5487. end;
  5488. if ShowInfo then
  5489. PopInfo;
  5490. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5491. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5492. SetCmdState(FromClipCmds,CanPaste);
  5493. end;
  5494. CloseGroupedAction(eaCut);
  5495. UnLock;
  5496. DontConsiderShiftState:=false;
  5497. end;
  5498. procedure TCustomCodeEditor.ClipPaste;
  5499. var
  5500. ShowInfo : boolean;
  5501. begin
  5502. if IsReadOnly then Exit;
  5503. DontConsiderShiftState:=true;
  5504. Lock;
  5505. AddGroupedAction(eaPaste);
  5506. if Clipboard<>nil then
  5507. begin
  5508. ShowInfo:=Clipboard^.SelEnd.Y-Clipboard^.SelStart.Y>50;
  5509. if ShowInfo then
  5510. PushInfo(msg_pastingclipboard);
  5511. InsertFrom(Clipboard);
  5512. if ShowInfo then
  5513. PopInfo;
  5514. end;
  5515. CloseGroupedAction(eaPaste);
  5516. UnLock;
  5517. DontConsiderShiftState:=false;
  5518. end;
  5519. procedure TCustomCodeEditor.Undo;
  5520. begin
  5521. NotImplemented; Exit;
  5522. end;
  5523. procedure TCustomCodeEditor.Redo;
  5524. begin
  5525. NotImplemented; Exit;
  5526. end;
  5527. procedure TCustomCodeEditor.GotoLine;
  5528. const
  5529. GotoRec: TGotoLineDialogRec = (LineNo:'1';Lines:0); {keep previous goto line number}
  5530. begin
  5531. with GotoRec do
  5532. begin
  5533. Lines:=GetLineCount;
  5534. {Linecount can be 0, but in that case there still is a cursor blinking in top
  5535. of the window, which will become line 1 as soon as sometype hits a key.}
  5536. if lines=0 then
  5537. lines:=1;
  5538. if EditorDialog(edGotoLine, @GotoRec) <> cmCancel then
  5539. begin
  5540. Lock;
  5541. SetCurPtr(0,StrToInt(LineNo)-1);
  5542. TrackCursor(do_centre);
  5543. UnLock;
  5544. end;
  5545. end;
  5546. end;
  5547. procedure TCustomCodeEditor.Find;
  5548. var
  5549. FindRec: TFindDialogRec;
  5550. DoConf: boolean;
  5551. begin
  5552. with FindRec do
  5553. begin
  5554. Find := FindStr;
  5555. if GetCurrentWord<>'' then
  5556. Find:=GetCurrentWord;
  5557. {$ifdef TEST_REGEXP}
  5558. Options := ((FindFlags and ffmOptionsFind) shr ffsOptions) or
  5559. ((FindFlags and ffUseRegExp) shr ffsUseRegExpFind);
  5560. {$else not TEST_REGEXP}
  5561. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5562. {$endif TEST_REGEXP}
  5563. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5564. Scope := (FindFlags and ffmScope) shr ffsScope;
  5565. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5566. DoConf:= (FindFlags and ffPromptOnReplace)<>0;
  5567. FindReplaceEditor:=@self;
  5568. if EditorDialog(edFind, @FindRec) <> cmCancel then
  5569. begin
  5570. FindStr := Find;
  5571. {$ifdef TEST_REGEXP}
  5572. FindFlags := ((Options and ffmOptionsFind) shl ffsOptions) or (Direction shl ffsDirection) or
  5573. ((Options and ffmUseRegExpFind) shl ffsUseRegExpFind) or
  5574. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5575. {$else : not TEST_REGEXP}
  5576. FindFlags := ((Options and ffmOptions) shl ffsOptions) or (Direction shl ffsDirection) or
  5577. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5578. {$endif TEST_REGEXP}
  5579. FindFlags := FindFlags and not ffDoReplace;
  5580. if DoConf then
  5581. FindFlags := (FindFlags or ffPromptOnReplace);
  5582. SearchRunCount:=0;
  5583. if FindStr<>'' then
  5584. DoSearchReplace
  5585. else
  5586. EditorDialog(edSearchFailed,nil);
  5587. end;
  5588. FindReplaceEditor:=nil;
  5589. end;
  5590. end;
  5591. procedure TCustomCodeEditor.Replace;
  5592. var
  5593. ReplaceRec: TReplaceDialogRec;
  5594. Re: word;
  5595. begin
  5596. if IsReadOnly then Exit;
  5597. with ReplaceRec do
  5598. begin
  5599. Find := FindStr;
  5600. if GetCurrentWord<>'' then
  5601. Find:=GetCurrentWord;
  5602. Replace := ReplaceStr;
  5603. {$ifdef TEST_REGEXP}
  5604. Options := (FindFlags and ffmOptions) shr ffsOptions or
  5605. (FindFlags and ffUseRegExp) shr ffsUseRegExpReplace;
  5606. {$else not TEST_REGEXP}
  5607. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5608. {$endif TEST_REGEXP}
  5609. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5610. Scope := (FindFlags and ffmScope) shr ffsScope;
  5611. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5612. FindReplaceEditor:=@self;
  5613. Re:=EditorDialog(edReplace, @ReplaceRec);
  5614. FindReplaceEditor:=nil;
  5615. if Re <> cmCancel then
  5616. begin
  5617. FindStr := Find;
  5618. ReplaceStr := Replace;
  5619. FindFlags := (Options shl ffsOptions) or (Direction shl ffsDirection) or
  5620. {$ifdef TEST_REGEXP}
  5621. ((Options and ffmUseRegExpReplace) shl ffsUseRegExpReplace) or
  5622. {$endif TEST_REGEXP}
  5623. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5624. FindFlags := FindFlags or ffDoReplace;
  5625. if Re = cmYes then
  5626. FindFlags := FindFlags or ffReplaceAll;
  5627. SearchRunCount:=0;
  5628. if FindStr<>'' then
  5629. DoSearchReplace
  5630. else
  5631. EditorDialog(edSearchFailed,nil);
  5632. end;
  5633. end;
  5634. end;
  5635. procedure TCustomCodeEditor.DoSearchReplace;
  5636. var S: string;
  5637. DX,DY,P,Y,X: sw_integer;
  5638. Count: sw_integer;
  5639. Found,CanExit: boolean;
  5640. SForward,DoReplace,DoReplaceAll: boolean;
  5641. {$ifdef TEST_REGEXP}
  5642. UseRegExp : boolean;
  5643. RegExpEngine : TRegExprEngine;
  5644. RegExpFlags : tregexprflags;
  5645. regexpindex,regexplen : longint;
  5646. findstrpchar : pchar;
  5647. {$endif TEST_REGEXP}
  5648. LeftOK,RightOK: boolean;
  5649. FoundCount: sw_integer;
  5650. A,B: TPoint;
  5651. AreaStart,AreaEnd: TPoint;
  5652. CanReplace,Confirm: boolean;
  5653. Re: word;
  5654. IFindStr : string;
  5655. BT : BTable;
  5656. Overwriting : boolean;
  5657. function ContainsText(const SubS:string;var S: string; Start: Sw_integer): Sw_integer;
  5658. var
  5659. P: Sw_Integer;
  5660. begin
  5661. if Start<=0 then
  5662. P:=0
  5663. else
  5664. begin
  5665. if SForward then
  5666. begin
  5667. if Start>length(s) then
  5668. P:=0
  5669. else if FindFlags and ffCaseSensitive<>0 then
  5670. P:=BMFScan(S[Start],length(s)+1-Start,FindStr,Bt)+1
  5671. else
  5672. P:=BMFIScan(S[Start],length(s)+1-Start,IFindStr,Bt)+1;
  5673. if P>0 then
  5674. Inc(P,Start-1);
  5675. end
  5676. else
  5677. begin
  5678. if start>length(s) then
  5679. start:=length(s);
  5680. if FindFlags and ffCaseSensitive<>0 then
  5681. P:=BMBScan(S[1],Start,FindStr,Bt)+1
  5682. else
  5683. P:=BMBIScan(S[1],Start,IFindStr,Bt)+1;
  5684. end;
  5685. end;
  5686. ContainsText:=P;
  5687. end;
  5688. function InArea(X,Y: sw_integer): boolean;
  5689. begin
  5690. InArea:=((AreaStart.Y=Y) and (AreaStart.X<=X)) or
  5691. ((AreaStart.Y<Y) and (Y<AreaEnd.Y)) or
  5692. ((AreaEnd.Y=Y) and (X<=AreaEnd.X));
  5693. end;
  5694. var CurDY: sw_integer;
  5695. begin
  5696. if FindStr='' then
  5697. begin
  5698. Find;
  5699. { Find will call DoFindReplace at end again
  5700. so we need to exit directly now PM }
  5701. exit;
  5702. end;
  5703. Inc(SearchRunCount);
  5704. SForward:=(FindFlags and ffmDirection)=ffForward;
  5705. DoReplace:=(FindFlags and ffDoReplace)<>0;
  5706. Confirm:=(FindFlags and ffPromptOnReplace)<>0;
  5707. DoReplaceAll:=(FindFlags and ffReplaceAll)<>0;
  5708. {$ifdef TEST_REGEXP}
  5709. UseRegExp:=(FindFlags and ffUseRegExp)<>0;
  5710. if UseRegExp then
  5711. begin
  5712. if FindFlags and ffCaseSensitive<>0 then
  5713. RegExpFlags:=[ref_caseinsensitive]
  5714. else
  5715. RegExpFlags:=[];
  5716. getmem(findstrpchar,length(findstr)+1);
  5717. strpcopy(findstrpchar,findstr);
  5718. RegExpEngine:=GenerateRegExprEngine(findstrpchar,RegExpFlags);
  5719. strdispose(findstrpchar);
  5720. end;
  5721. {$endif TEST_REGEXP}
  5722. Count:=GetLineCount;
  5723. FoundCount:=0;
  5724. { Empty file ? }
  5725. if Count=0 then
  5726. begin
  5727. EditorDialog(edSearchFailed,nil);
  5728. exit;
  5729. end;
  5730. if SForward then
  5731. DY:=1
  5732. else
  5733. DY:=-1;
  5734. DX:=DY;
  5735. if FindStr<>'' then
  5736. PushInfo('Looking for "'+FindStr+'"');
  5737. if (FindFlags and ffmScope)=ffGlobal then
  5738. begin
  5739. AreaStart.X:=0;
  5740. AreaStart.Y:=0;
  5741. AreaEnd.X:=length(GetDisplayText(Count-1));
  5742. AreaEnd.Y:=Count-1;
  5743. end
  5744. else
  5745. begin
  5746. AreaStart:=SelStart;
  5747. AreaEnd:=SelEnd;
  5748. end;
  5749. { set a y value being inside the areal }
  5750. Y:=Min(CurPos.Y,Count-1);
  5751. if sForward then
  5752. X:=CurPos.X-1
  5753. else
  5754. { if you change this, pleas check that repeated backward searching for single chars still works
  5755. and that data is still found if searching starts outside the current line }
  5756. X:=Min(CurPos.X,length(GetDisplayText(Y)));
  5757. if SearchRunCount=1 then
  5758. if (FindFlags and ffmOrigin)=ffEntireScope then
  5759. if SForward then
  5760. begin
  5761. X:=AreaStart.X-1;
  5762. Y:=AreaStart.Y;
  5763. end
  5764. else
  5765. begin
  5766. X:=AreaEnd.X+1;
  5767. Y:=AreaEnd.Y;
  5768. end;
  5769. if FindFlags and ffCaseSensitive<>0 then
  5770. begin
  5771. if SForward then
  5772. BMFMakeTable(FindStr,bt)
  5773. else
  5774. BMBMakeTable(FindStr,bt);
  5775. end
  5776. else
  5777. begin
  5778. IFindStr:=upcase(FindStr);
  5779. if SForward then
  5780. BMFMakeTable(IFindStr,bt)
  5781. else
  5782. BMBMakeTable(IFindStr,bt);
  5783. end;
  5784. inc(X,DX);
  5785. CanExit:=false;
  5786. if not DoReplace or (not Confirm and (Owner<>nil)) then
  5787. Owner^.Lock;
  5788. if InArea(X,Y) then
  5789. repeat
  5790. CurDY:=DY;
  5791. S:=GetDisplayText(Y);
  5792. if X>length(S)-1 then
  5793. X:=length(S)-1;
  5794. {$ifdef TEST_REGEXP}
  5795. if UseRegExp then
  5796. begin
  5797. getmem(findstrpchar,length(Copy(S,X+1,high(S)))+1);
  5798. strpcopy(findstrpchar,Copy(S,X+1,high(S)));
  5799. { If start of line is required do check other positions PM }
  5800. if (FindStr[1]='^') and (X<>0) then
  5801. Found:=false
  5802. else
  5803. Found:=RegExprPos(RegExpEngine,findstrpchar,regexpindex,regexplen);
  5804. strdispose(findstrpchar);
  5805. P:=regexpindex+X+1;
  5806. end
  5807. else
  5808. {$endif TEST_REGEXP}
  5809. begin
  5810. P:=ContainsText(FindStr,S,X+1);
  5811. Found:=P<>0;
  5812. end;
  5813. if Found then
  5814. begin
  5815. A.X:=P-1;
  5816. A.Y:=Y;
  5817. B.Y:=Y;
  5818. {$ifdef TEST_REGEXP}
  5819. if UseRegExp then
  5820. B.X:=A.X+regexplen
  5821. else
  5822. {$endif TEST_REGEXP}
  5823. B.X:=A.X+length(FindStr);
  5824. end;
  5825. Found:=Found and InArea(A.X,A.Y);
  5826. if Found and ((FindFlags and ffWholeWordsOnly)<>0) then
  5827. begin
  5828. LeftOK:=(A.X<=0) or (not( (S[A.X] in AlphaChars+NumberChars) ));
  5829. RightOK:=(B.X>=length(S)) or (not( (S[B.X+1] in AlphaChars+NumberChars) ));
  5830. Found:=LeftOK and RightOK;
  5831. if not Found then
  5832. begin
  5833. CurDY:=0;
  5834. If SForward then
  5835. begin
  5836. X:=B.X+1;
  5837. if X>length(S) then
  5838. CurDY:=DY;
  5839. end
  5840. else
  5841. begin
  5842. X:=A.X-1;
  5843. if X<0 then
  5844. CurDY:=DY;
  5845. end;
  5846. end;
  5847. end;
  5848. if Found then
  5849. begin
  5850. Inc(FoundCount);
  5851. Lock;
  5852. if SForward then
  5853. SetCurPtr(B.X,B.Y)
  5854. else
  5855. SetCurPtr(A.X,A.Y);
  5856. TrackCursor(do_centre);
  5857. SetHighlight(A,B);
  5858. UnLock;
  5859. CurDY:=0;
  5860. if not DoReplace then
  5861. begin
  5862. CanExit:=true;
  5863. If SForward then
  5864. begin
  5865. X:=B.X;
  5866. Y:=B.Y;
  5867. end
  5868. else
  5869. begin
  5870. X:=A.X;
  5871. Y:=A.Y;
  5872. end;
  5873. end
  5874. else
  5875. begin
  5876. if not confirm then
  5877. CanReplace:=true
  5878. else
  5879. begin
  5880. Re:=EditorDialog(edReplacePrompt,@CurPos);
  5881. case Re of
  5882. cmYes :
  5883. CanReplace:=true;
  5884. cmNo :
  5885. CanReplace:=false;
  5886. else {cmCancel}
  5887. begin
  5888. CanReplace:=false;
  5889. CanExit:=true;
  5890. end;
  5891. end;
  5892. end;
  5893. if CanReplace then
  5894. begin
  5895. Lock;
  5896. { don't use SetInsertMode here because it changes the cursor shape }
  5897. overwriting:=(GetFlags and efInsertMode)=0;
  5898. SetFlags(GetFlags or efInsertMode);
  5899. SetSelection(A,B);
  5900. DelSelect;
  5901. InsertText(ReplaceStr);
  5902. if SForward then
  5903. begin
  5904. X:=CurPos.X;
  5905. Y:=CurPos.Y;
  5906. end
  5907. else
  5908. begin
  5909. X:=A.X;
  5910. Y:=A.Y;
  5911. end;
  5912. if overwriting then
  5913. SetFlags(GetFlags and (not efInsertMode));
  5914. UnLock;
  5915. end
  5916. else
  5917. begin
  5918. If SForward then
  5919. begin
  5920. X:=B.X;
  5921. Y:=B.Y;
  5922. end
  5923. else
  5924. begin
  5925. X:=A.X;
  5926. Y:=A.Y;
  5927. end;
  5928. end;
  5929. if (DoReplaceAll=false) then
  5930. CanExit:=true;
  5931. end;
  5932. end;
  5933. if (CanExit=false) and (CurDY<>0) then
  5934. begin
  5935. inc(Y,CurDY);
  5936. if SForward then
  5937. X:=0
  5938. else
  5939. X:=254;
  5940. CanExit:=((Y>=Count) and sForward) or (Y<0);
  5941. end;
  5942. if not CanExit then
  5943. CanExit:=(not InArea(X,Y)) and sForward;
  5944. until CanExit;
  5945. if (FoundCount=0) or (DoReplace) then
  5946. SetHighlight(CurPos,CurPos);
  5947. if (DoReplace=false) or ((Confirm=false) and (Owner<>nil)) then
  5948. Owner^.UnLock;
  5949. {if (DoReplace=false) or (Confirm=false) then
  5950. UnLock;}
  5951. if (FoundCount=0) then
  5952. EditorDialog(edSearchFailed,nil);
  5953. if FindStr<>'' then
  5954. PopInfo;
  5955. {$ifdef TEST_REGEXP}
  5956. if UseRegExp then
  5957. DestroyRegExprEngine(RegExpEngine);
  5958. {$endif TEST_REGEXP}
  5959. if (FindFlags and ffmScope)=ffSelectedText then
  5960. { restore selection PM }
  5961. begin
  5962. SetSelection(AreaStart,AreaEnd);
  5963. end;
  5964. end;
  5965. function TCustomCodeEditor.GetInsertMode: boolean;
  5966. begin
  5967. GetInsertMode:=(GetFlags and efInsertMode)<>0;
  5968. end;
  5969. procedure TCustomCodeEditor.SetInsertMode(InsertMode: boolean);
  5970. begin
  5971. if InsertMode then
  5972. SetFlags(GetFlags or efInsertMode)
  5973. else
  5974. SetFlags(GetFlags and (not efInsertMode));
  5975. DrawCursor;
  5976. end;
  5977. { there is a problem with ShiftDel here
  5978. because GetShitState tells to extend the
  5979. selection which gives wrong results (PM) }
  5980. function TCustomCodeEditor.ShouldExtend: boolean;
  5981. var ShiftInEvent: boolean;
  5982. begin
  5983. ShiftInEvent:=false;
  5984. if Assigned(CurEvent) then
  5985. if CurEvent^.What=evKeyDown then
  5986. ShiftInEvent:=((CurEvent^.KeyShift and kbShift)<>0);
  5987. ShouldExtend:=ShiftInEvent and
  5988. not DontConsiderShiftState;
  5989. end;
  5990. procedure TCustomCodeEditor.SetCurPtr(X,Y: sw_integer);
  5991. var OldPos{,OldSEnd,OldSStart}: TPoint;
  5992. Extended: boolean;
  5993. F: PFold;
  5994. begin
  5995. Lock;
  5996. X:=Max(0,Min(MaxLineLength+1,X));
  5997. Y:=Max(0,Min(GetLineCount-1,Y));
  5998. OldPos:=CurPos;
  5999. { OldSEnd:=SelEnd;
  6000. OldSStart:=SelStart;}
  6001. CurPos.X:=X;
  6002. CurPos.Y:=Y;
  6003. TrackCursor(do_not_centre);
  6004. if not IsLineVisible(CurPos.Y) then
  6005. begin
  6006. F:=GetLineFold(CurPos.Y);
  6007. if Assigned(F) then
  6008. F^.Collapse(false);
  6009. end;
  6010. if not NoSelect and ShouldExtend then
  6011. begin
  6012. CheckSels;
  6013. Extended:=false;
  6014. if PointOfs(OldPos)=PointOfs(SelStart) then
  6015. begin
  6016. SetSelection(CurPos,SelEnd);
  6017. Extended:=true;
  6018. end;
  6019. CheckSels;
  6020. if Extended=false then
  6021. if PointOfs(OldPos)=PointOfs(SelEnd) then
  6022. begin
  6023. if not ValidBlock then
  6024. SetSelection(CurPos,CurPos);
  6025. SetSelection(SelStart,CurPos); Extended:=true;
  6026. end;
  6027. CheckSels;
  6028. if not Extended then
  6029. if PointOfs(OldPos)<=PointOfs(CurPos) then
  6030. begin
  6031. SetSelection(OldPos,CurPos);
  6032. Extended:=true;
  6033. end
  6034. else
  6035. begin
  6036. SetSelection(CurPos,OldPos);
  6037. Extended:=true;
  6038. end;
  6039. DrawView;
  6040. end
  6041. else if not IsFlagSet(efPersistentBlocks) then
  6042. begin
  6043. HideSelect;
  6044. DrawView;
  6045. end;
  6046. { if PointOfs(SelStart)=PointOfs(SelEnd) then
  6047. SetSelection(CurPos,CurPos);}
  6048. if (GetFlags and (efHighlightColumn+efHighlightRow))<>0 then
  6049. DrawView;
  6050. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and
  6051. ((Highlight.A.X<>HighLight.B.X) or (Highlight.A.Y<>HighLight.B.Y)) then
  6052. HideHighlight;
  6053. if (OldPos.Y<>CurPos.Y) and (0<=OldPos.Y) and (OldPos.Y<GetLineCount) then
  6054. SetLineText(OldPos.Y,RTrim(GetLineText(OldPos.Y),not IsFlagSet(efUseTabCharacters)));
  6055. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (GetErrorMessage<>'') then
  6056. SetErrorMessage('');
  6057. { if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (HighlightRow<>-1) then
  6058. SetHighlightRow(-1);}
  6059. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6060. AddAction(eaMoveCursor,OldPos,CurPos,'',GetFlags);
  6061. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6062. PositionChanged;{UpdateIndicator;}
  6063. UnLock;
  6064. end;
  6065. procedure TCustomCodeEditor.CheckSels;
  6066. begin
  6067. if (SelStart.Y>SelEnd.Y) or
  6068. ( (SelStart.Y=SelEnd.Y) and (SelStart.X>SelEnd.X) ) then
  6069. SetSelection(SelEnd,SelStart);
  6070. end;
  6071. procedure TCustomCodeEditor.CodeCompleteApply;
  6072. var S: string;
  6073. FragLen,
  6074. I: integer;
  6075. begin
  6076. Lock;
  6077. { here should be some kind or "mark" or "break" inserted in the Undo
  6078. information, so activating it "undoes" only the completition first and
  6079. doesn't delete the complete word at once... - Gabor }
  6080. FragLen:=Length(GetCodeCompleteFrag);
  6081. S:=GetCodeCompleteWord;
  6082. for I:=FragLen+1 to length(S) do
  6083. AddChar(S[I]);
  6084. UnLock;
  6085. SetCompleteState(csInactive);
  6086. end;
  6087. procedure TCustomCodeEditor.CodeCompleteCancel;
  6088. begin
  6089. SetCompleteState(csDenied);
  6090. end;
  6091. procedure TCustomCodeEditor.CodeCompleteCheck;
  6092. var Line: string;
  6093. X: sw_integer;
  6094. CurWord,NewWord: string;
  6095. begin
  6096. SetCodeCompleteFrag('');
  6097. if (not IsFlagSet(efCodeComplete)) or (IsReadOnly=true) then Exit;
  6098. Lock;
  6099. Line:=GetDisplayText(CurPos.Y);
  6100. X:=CurPos.X; CurWord:='';
  6101. if X<=length(Line) then
  6102. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  6103. begin
  6104. CurWord:=Line[X]+CurWord;
  6105. Dec(X);
  6106. end;
  6107. if (length(CurWord)>=CodeCompleteMinLen) and CompleteCodeWord(CurWord,NewWord) then
  6108. begin
  6109. SetCodeCompleteFrag(CurWord);
  6110. SetCodeCompleteWord(NewWord);
  6111. end
  6112. else
  6113. ClearCodeCompleteWord;
  6114. UnLock;
  6115. end;
  6116. function TCustomCodeEditor.GetCodeCompleteFrag: string;
  6117. begin
  6118. { Abstract }
  6119. GetCodeCompleteFrag:='';
  6120. end;
  6121. procedure TCustomCodeEditor.SetCodeCompleteFrag(const S: string);
  6122. begin
  6123. { Abstract }
  6124. end;
  6125. procedure TCustomCodeEditor.DrawLines(FirstLine: sw_integer);
  6126. begin
  6127. if FirstLine>=(Delta.Y+Size.Y) then Exit; { falls outside of the screen }
  6128. DrawView;
  6129. end;
  6130. procedure TCustomCodeEditor.HideHighlight;
  6131. begin
  6132. SetHighlight(CurPos,CurPos);
  6133. end;
  6134. procedure TCustomCodeEditor.GetSelectionArea(var StartP,EndP: TPoint);
  6135. begin
  6136. StartP:=SelStart; EndP:=SelEnd;
  6137. if EndP.X=0 then
  6138. begin
  6139. Dec(EndP.Y);
  6140. EndP.X:=length(GetDisplayText(EndP.Y))-1;
  6141. end
  6142. else
  6143. Dec(EndP.X);
  6144. end;
  6145. function TCustomCodeEditor.ValidBlock: boolean;
  6146. begin
  6147. ValidBlock:=(SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y);
  6148. end;
  6149. procedure TCustomCodeEditor.SetSelection(A, B: TPoint);
  6150. var WV: boolean;
  6151. OS,OE: TPoint;
  6152. begin
  6153. WV:=ValidBlock;
  6154. OS:=SelStart; OE:=SelEnd;
  6155. SelStart:=A; SelEnd:=B;
  6156. if (WV=false) and (ValidBlock=false) then { do nothing } else
  6157. if (OS.X<>SelStart.X) or (OS.Y<>SelStart.Y) or
  6158. (OE.X<>SelEnd.X) or (OE.Y<>SelEnd.Y) then
  6159. SelectionChanged;
  6160. end;
  6161. procedure TCustomCodeEditor.SetHighlight(A, B: TPoint);
  6162. begin
  6163. Highlight.A:=A; Highlight.B:=B;
  6164. HighlightChanged;
  6165. end;
  6166. {procedure TCustomCodeEditor.SetHighlightRow(Row: sw_integer);
  6167. begin
  6168. HighlightRow:=Row;
  6169. DrawView;
  6170. end;}
  6171. {procedure TCodeEditor.SetDebuggerRow(Row: sw_integer);
  6172. begin
  6173. DebuggerRow:=Row;
  6174. DrawView;
  6175. end;}
  6176. procedure TCustomCodeEditor.SelectAll(Enable: boolean);
  6177. var A,B: TPoint;
  6178. begin
  6179. if (Enable=false) or (GetLineCount=0) then
  6180. begin A:=CurPos; B:=CurPos end
  6181. else
  6182. begin
  6183. A.X:=0; A.Y:=0;
  6184. { B.Y:=GetLineCount-1;
  6185. B.X:=length(GetLineText(B.Y));}
  6186. B.Y:=GetLineCount; B.X:=0;
  6187. end;
  6188. SetSelection(A,B);
  6189. DrawView;
  6190. end;
  6191. procedure TCustomCodeEditor.SelectionChanged;
  6192. var Enable,CanPaste: boolean;
  6193. begin
  6194. if GetLineCount=0 then
  6195. begin
  6196. SelStart.X:=0; SelStart.Y:=0; SelEnd:=SelStart;
  6197. end
  6198. else
  6199. if SelEnd.Y>GetLineCount-1 then
  6200. if (SelEnd.Y<>GetLineCount) or (SelEnd.X<>0) then
  6201. begin
  6202. SelEnd.Y:=GetLineCount-1;
  6203. SelEnd.X:=length(GetDisplayText(SelEnd.Y));
  6204. end;
  6205. { we change the CurCommandSet, but only if we are top view }
  6206. if ((State and sfFocused)<>0) then
  6207. begin
  6208. Enable:=((SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y)) and (Clipboard<>nil);
  6209. SetCmdState(ToClipCmds,Enable and (Clipboard<>@Self));
  6210. SetCmdState(NulClipCmds,Enable);
  6211. CanPaste:=(Clipboard<>nil) and ((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  6212. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  6213. SetCmdState(FromClipCmds,CanPaste and (Clipboard<>@Self));
  6214. SetCmdState(UndoCmd,(GetUndoActionCount>0));
  6215. SetCmdState(RedoCmd,(GetRedoActionCount>0));
  6216. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  6217. end;
  6218. DrawView;
  6219. end;
  6220. procedure TCustomCodeEditor.HighlightChanged;
  6221. begin
  6222. DrawView;
  6223. end;
  6224. procedure TCustomCodeEditor.SetState(AState: Word; Enable: Boolean);
  6225. procedure ShowSBar(SBar: PScrollBar);
  6226. begin
  6227. if Assigned(SBar) and (SBar^.GetState(sfVisible)=false) then
  6228. SBar^.Show;
  6229. end;
  6230. begin
  6231. inherited SetState(AState,Enable);
  6232. if AlwaysShowScrollBars then
  6233. begin
  6234. ShowSBar(HScrollBar);
  6235. ShowSBar(VScrollBar);
  6236. end;
  6237. if (AState and (sfActive+sfSelected+sfFocused))<>0 then
  6238. begin
  6239. SelectionChanged;
  6240. if ((State and sfFocused)=0) and (GetCompleteState=csOffering) then
  6241. ClearCodeCompleteWord;
  6242. end;
  6243. end;
  6244. function TCustomCodeEditor.GetPalette: PPalette;
  6245. const P: string[length(CEditor)] = CEditor;
  6246. begin
  6247. GetPalette:=@P;
  6248. end;
  6249. function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean;
  6250. var S: string;
  6251. AllLinesComplete,LineComplete,hasCR,OK: boolean;
  6252. begin
  6253. DeleteAllLines;
  6254. ChangedLine:=-1;
  6255. AllLinesComplete:=true;
  6256. OK:=(Stream^.Status=stOK);
  6257. if eofstream(Stream) then
  6258. AddLine('')
  6259. else
  6260. begin
  6261. while OK and (eofstream(Stream)=false) and (GetLineCount<MaxLineCount) do
  6262. begin
  6263. if not UseOldBufStreamMethod then
  6264. Stream^.Readline(S,LineComplete,hasCR)
  6265. else
  6266. ReadlnFromStream(Stream,S,LineComplete,hasCR);
  6267. AllLinesComplete:=AllLinesComplete and LineComplete;
  6268. OK:=OK and (Stream^.Status=stOK);
  6269. if OK then AddLine(S);
  6270. if not LineComplete and (ChangedLine=-1) then
  6271. ChangedLine:=GetLineCount;
  6272. end;
  6273. { Do not remove the final newline if it exists PM }
  6274. if hasCR then
  6275. AddLine('');
  6276. end;
  6277. LimitsChanged;
  6278. if not AllLinesComplete then
  6279. SetModified(true);
  6280. if (GetLineCount=MaxLineCount) and not eofstream(stream) then
  6281. EditorDialog(edTooManyLines,nil);
  6282. LoadFromStream:=OK;
  6283. end;
  6284. function TCustomCodeEditorCore.SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean;
  6285. var S: string;
  6286. OK: boolean;
  6287. Line: Sw_integer;
  6288. begin
  6289. if EndP.X=0 then
  6290. begin
  6291. if EndP.Y>0 then
  6292. begin
  6293. EndP.X:=length(GetDisplayText(EndP.Y));
  6294. end
  6295. else
  6296. EndP.X:=0;
  6297. end
  6298. else
  6299. Dec(EndP.X);
  6300. OK:=(Stream^.Status=stOK); Line:=StartP.Y;
  6301. while OK and (Line<=EndP.Y) and (Line<GetLineCount) do
  6302. begin
  6303. S:=GetLineText(Line);
  6304. { Remove all traling spaces PM }
  6305. if not Editor^.IsFlagSet(efKeepTrailingSpaces) then
  6306. s:=RTrim(S,False); // removes trailing #0 too
  6307. { if FlagSet(efUseTabCharacters) then
  6308. S:=CompressUsingTabs(S,TabSize);
  6309. }
  6310. if Line=EndP.Y then S:=copy(S,1,LinePosToCharIdx(Line,EndP.X));
  6311. if Line=StartP.Y then S:=copy(S,LinePosToCharIdx(Line,StartP.X),High(S));
  6312. Stream^.Write(S[1],length(S));
  6313. if Line<EndP.Y then
  6314. Stream^.Write(EOL[1],length(EOL));
  6315. Inc(Line);
  6316. OK:=OK and (Stream^.Status=stOK);
  6317. end;
  6318. SaveAreaToStream:=OK;
  6319. end;
  6320. constructor TEditorAction.init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint);
  6321. begin
  6322. Action:=act;
  6323. StartPos:=StartP;
  6324. EndPos:=EndP;
  6325. Text:=NewStr(txt);
  6326. ActionCount:=0;
  6327. Flags:=AFlags;
  6328. TimeStamp:=Now;
  6329. IsGrouped:=false;
  6330. end;
  6331. constructor TEditorAction.init_group(act:byte);
  6332. begin
  6333. Action:=act;
  6334. ActionCount:=0;
  6335. Flags:=0;
  6336. IsGrouped:=true;
  6337. end;
  6338. function TEditorAction.Is_grouped_action : boolean;
  6339. begin
  6340. Is_grouped_action:=IsGrouped;
  6341. end;
  6342. destructor TEditorAction.done;
  6343. begin
  6344. DisposeStr(Text);
  6345. inherited done;
  6346. end;
  6347. function TEditorActionCollection.At(Idx : sw_integer) : PEditorAction;
  6348. begin
  6349. At:=PEditorAction(Inherited At(Idx));
  6350. end;
  6351. procedure TEditorInputLine.HandleEvent(var Event : TEvent);
  6352. var
  6353. s,s2 : string;
  6354. i : longint;
  6355. begin
  6356. If (Event.What=evKeyDown) then
  6357. begin
  6358. if (Event.KeyCode=kbRight) and
  6359. (CurPos = Length(Data^)) and
  6360. Assigned(FindReplaceEditor) then
  6361. Begin
  6362. s:=FindReplaceEditor^.GetDisplayText(FindReplaceEditor^.CurPos.Y);
  6363. s:=Copy(s,FindReplaceEditor^.CurPos.X + 1 -length(Data^),high(s));
  6364. i:=pos(Data^,s);
  6365. if i>0 then
  6366. begin
  6367. s:=Data^+s[i+length(Data^)];
  6368. If not assigned(validator) or
  6369. Validator^.IsValidInput(s,False) then
  6370. Begin
  6371. Event.CharCode:=s[length(s)];
  6372. Event.Scancode:=0;
  6373. Inherited HandleEvent(Event);
  6374. End;
  6375. end;
  6376. ClearEvent(Event);
  6377. End
  6378. else if (Event.KeyCode=kbShiftIns) and
  6379. Assigned(Clipboard) and (Clipboard^.ValidBlock) then
  6380. { paste from clipboard }
  6381. begin
  6382. i:=Clipboard^.SelStart.Y;
  6383. s:=Clipboard^.GetDisplayText(i);
  6384. i:=Clipboard^.SelStart.X;
  6385. if i>0 then
  6386. s:=copy(s,i+1,high(s));
  6387. if (Clipboard^.SelStart.Y=Clipboard^.SelEnd.Y) then
  6388. begin
  6389. i:=Clipboard^.SelEnd.X-i;
  6390. s:=copy(s,1,i);
  6391. end;
  6392. for i:=1 to length(s) do
  6393. begin
  6394. s2:=Data^+s[i];
  6395. If not assigned(validator) or
  6396. Validator^.IsValidInput(s2,False) then
  6397. Begin
  6398. Event.What:=evKeyDown;
  6399. Event.CharCode:=s[i];
  6400. Event.Scancode:=0;
  6401. Inherited HandleEvent(Event);
  6402. End;
  6403. end;
  6404. ClearEvent(Event);
  6405. end
  6406. else if (Event.KeyCode=kbCtrlIns) and
  6407. Assigned(Clipboard) then
  6408. { Copy to clipboard }
  6409. begin
  6410. s:=GetStr(Data);
  6411. s:=copy(s,selstart+1,selend-selstart);
  6412. Clipboard^.SelStart:=Clipboard^.CurPos;
  6413. Clipboard^.InsertText(s);
  6414. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6415. ClearEvent(Event);
  6416. end
  6417. else if (Event.KeyCode=kbShiftDel) and
  6418. Assigned(Clipboard) then
  6419. { Cut to clipboard }
  6420. begin
  6421. s:=GetStr(Data);
  6422. s:=copy(s,selstart+1,selend-selstart);
  6423. Clipboard^.SelStart:=Clipboard^.CurPos;
  6424. Clipboard^.InsertText(s);
  6425. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6426. s2:=GetStr(Data);
  6427. { now remove the selected part }
  6428. Event.keyCode:=kbDel;
  6429. inherited HandleEvent(Event);
  6430. ClearEvent(Event);
  6431. end
  6432. else
  6433. Inherited HandleEvent(Event);
  6434. End
  6435. else
  6436. Inherited HandleEvent(Event);
  6437. s:=getstr(data);
  6438. Message(Owner,evBroadCast,cminputlinelen,pointer(length(s)));
  6439. end;
  6440. procedure TSearchHelperDialog.HandleEvent(var Event : TEvent);
  6441. begin
  6442. case Event.What of
  6443. evBroadcast :
  6444. case Event.Command of
  6445. cminputlinelen : begin
  6446. if PtrInt(Event.InfoPtr)=0 then
  6447. okbutton^.DisableCommands([cmok])
  6448. else
  6449. okbutton^.EnableCommands([cmok]);
  6450. clearevent(event);
  6451. end;
  6452. end;
  6453. end;
  6454. inherited HandleEvent(Event);
  6455. end;
  6456. function CreateFindDialog: PDialog;
  6457. var R,R1,R2: TRect;
  6458. D: PSearchHelperDialog;
  6459. IL1: PEditorInputLine;
  6460. Control : PView;
  6461. CB1: PCheckBoxes;
  6462. RB1,RB2,RB3: PRadioButtons;
  6463. but : PButton;
  6464. begin
  6465. R.Assign(0,0,56,15);
  6466. New(D, Init(R, dialog_find));
  6467. with D^ do
  6468. begin
  6469. Options:=Options or ofCentered;
  6470. GetExtent(R); R.Grow(-3,-2);
  6471. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6472. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6473. New(IL1, Init(R2, FindStrSize));
  6474. IL1^.Data^:=FindStr;
  6475. Insert(IL1);
  6476. Insert(New(PLabel, Init(R1, label_find_texttofind, IL1)));
  6477. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6478. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6479. Insert(Control);
  6480. R1.Copy(R); Inc(R1.A.Y,2); R1.B.Y:=R1.A.Y+1; R1.B.X:=R1.A.X+(R1.B.X-R1.A.X) div 2-1;
  6481. R2.Copy(R1); R2.Move(0,1);
  6482. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}3{$else}2{$endif};
  6483. New(CB1, Init(R2,
  6484. NewSItem(label_find_casesensitive,
  6485. NewSItem(label_find_wholewordsonly,
  6486. {$ifdef TEST_REGEXP}
  6487. NewSItem(label_find_useregexp,
  6488. {$endif TEST_REGEXP}
  6489. nil)))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6490. Insert(CB1);
  6491. Insert(New(PLabel, Init(R1, label_find_options, CB1)));
  6492. R1.Copy(R); Inc(R1.A.Y,2); R1.B.Y:=R1.A.Y+1; R1.A.X:=R1.B.X-(R1.B.X-R1.A.X) div 2+1;
  6493. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6494. New(RB1, Init(R2,
  6495. NewSItem(label_find_forward,
  6496. NewSItem(label_find_backward,
  6497. nil))));
  6498. Insert(RB1);
  6499. Insert(New(PLabel, Init(R1, label_find_direction, RB1)));
  6500. R1.Copy(R); Inc(R1.A.Y,6); R1.B.Y:=R1.A.Y+1; R1.B.X:=R1.A.X+(R1.B.X-R1.A.X) div 2-1;
  6501. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6502. New(RB2, Init(R2,
  6503. NewSItem(label_find_global,
  6504. NewSItem(label_find_selectedtext,
  6505. nil))));
  6506. Insert(RB2);
  6507. Insert(New(PLabel, Init(R1, label_find_scope, RB2)));
  6508. R1.Copy(R); Inc(R1.A.Y,6); R1.B.Y:=R1.A.Y+1; R1.A.X:=R1.B.X-(R1.B.X-R1.A.X) div 2+1;
  6509. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6510. New(RB3, Init(R2,
  6511. NewSItem(label_find_fromcursor,
  6512. NewSItem(label_find_entirescope,
  6513. nil))));
  6514. Insert(RB3);
  6515. Insert(New(PLabel, Init(R1, label_find_origin, RB3)));
  6516. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6517. Okbutton:=New(PButton, Init(R, btn_OK, cmOK, bfDefault));
  6518. Insert(OkButton);
  6519. R.Move(19,0);
  6520. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6521. end;
  6522. IL1^.Select;
  6523. CreateFindDialog := D;
  6524. end;
  6525. function CreateReplaceDialog: PDialog;
  6526. var R,R1,R2: TRect;
  6527. D: PDialog;
  6528. Control : PView;
  6529. IL1: PEditorInputLine;
  6530. IL2: PEditorInputLine;
  6531. CB1: PCheckBoxes;
  6532. RB1,RB2,RB3: PRadioButtons;
  6533. begin
  6534. R.Assign(0,0,56,18);
  6535. New(D, Init(R, dialog_replace));
  6536. with D^ do
  6537. begin
  6538. Options:=Options or ofCentered;
  6539. GetExtent(R); R.Grow(-3,-2);
  6540. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6541. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6542. New(IL1, Init(R2, FindStrSize));
  6543. IL1^.Data^:=FindStr;
  6544. Insert(IL1);
  6545. Insert(New(PLabel, Init(R1, label_replace_texttofind, IL1)));
  6546. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6547. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6548. Insert(Control);
  6549. R1.Copy(R); R1.Move(0,2); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6550. R2.Copy(R); R2.Move(0,2);R2.B.X:=R2.B.X-3;
  6551. R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6552. New(IL2, Init(R2, FindStrSize));
  6553. IL2^.Data^:=ReplaceStr;
  6554. Insert(IL2);
  6555. Insert(New(PLabel, Init(R1, label_replace_newtext, IL2)));
  6556. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6557. Control := New(PHistory, Init(R1, IL2, TextReplaceId));
  6558. Insert(Control);
  6559. R1.Copy(R); Inc(R1.A.Y,4); R1.B.Y:=R1.A.Y+1; R1.B.X:=R1.A.X+(R1.B.X-R1.A.X) div 2-1;
  6560. R2.Copy(R1); R2.Move(0,1);
  6561. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}4{$else}3{$endif};
  6562. New(CB1, Init(R2,
  6563. NewSItem(label_replace_casesensitive,
  6564. NewSItem(label_replace_wholewordsonly,
  6565. NewSItem(label_replace_promptonreplace,
  6566. {$ifdef TEST_REGEXP}
  6567. NewSItem(label_find_useregexp,
  6568. {$endif TEST_REGEXP}
  6569. nil))))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6570. Insert(CB1);
  6571. Insert(New(PLabel, Init(R1, label_replace_options, CB1)));
  6572. R1.Copy(R); Inc(R1.A.Y,4); R1.B.Y:=R1.A.Y+1; R1.A.X:=R1.B.X-(R1.B.X-R1.A.X) div 2+1;
  6573. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6574. New(RB1, Init(R2,
  6575. NewSItem(label_replace_forward,
  6576. NewSItem(label_replace_backward,
  6577. nil))));
  6578. Insert(RB1);
  6579. Insert(New(PLabel, Init(R1, label_replace_direction, RB1)));
  6580. R1.Copy(R); Inc(R1.A.Y,9); R1.B.Y:=R1.A.Y+1; R1.B.X:=R1.A.X+(R1.B.X-R1.A.X) div 2-1;
  6581. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6582. New(RB2, Init(R2,
  6583. NewSItem(label_replace_global,
  6584. NewSItem(label_replace_selectedtext,
  6585. nil))));
  6586. Insert(RB2);
  6587. Insert(New(PLabel, Init(R1, label_replace_scope, RB2)));
  6588. R1.Copy(R); Inc(R1.A.Y,9); R1.B.Y:=R1.A.Y+1; R1.A.X:=R1.B.X-(R1.B.X-R1.A.X) div 2+1;
  6589. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6590. New(RB3, Init(R2,
  6591. NewSItem(label_replace_fromcursor,
  6592. NewSItem(label_replace_entirescope,
  6593. nil))));
  6594. Insert(RB3);
  6595. Insert(New(PLabel, Init(R1, label_replace_origin, RB3)));
  6596. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10; R.Move(-10,0);
  6597. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6598. R.Move(11,0); R.B.X:=R.A.X+14;
  6599. Insert(New(PButton, Init(R, btn_replace_changeall, cmYes, bfNormal)));
  6600. R.Move(15,0); R.B.X:=R.A.X+10;
  6601. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6602. end;
  6603. IL1^.Select;
  6604. CreateReplaceDialog := D;
  6605. end;
  6606. function CreateGotoLineDialog(Info: pointer): PDialog;
  6607. var D: PDialog;
  6608. R,R1,R2: TRect;
  6609. Control : PView;
  6610. IL: PEditorInputLine;
  6611. begin
  6612. R.Assign(0,0,40,7);
  6613. New(D, Init(R, dialog_gotoline));
  6614. with D^ do
  6615. begin
  6616. Options:=Options or ofCentered;
  6617. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  6618. R1.Copy(R); R1.B.X:=27; R2.Copy(R);
  6619. R2.B.X:=R2.B.X-3;R2.A.X:=27;
  6620. New(IL, Init(R2,5));
  6621. with TGotoLineDialogRec(Info^) do
  6622. IL^.SetValidator(New(PRangeValidator, Init(1, Lines)));
  6623. Insert(IL);
  6624. Insert(New(PLabel, Init(R1, label_gotoline_linenumber, IL)));
  6625. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6626. Control := New(PHistory, Init(R1, IL, GotoId));
  6627. Insert(Control);
  6628. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6629. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6630. R.Move(15,0);
  6631. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6632. end;
  6633. IL^.Select;
  6634. CreateGotoLineDialog:=D;
  6635. end;
  6636. function StdEditorDialog(Dialog: Integer; Info: Pointer): Word;
  6637. var
  6638. R: TRect;
  6639. T: TPoint;
  6640. Re: word;
  6641. Name: string;
  6642. DriveNumber : byte;
  6643. StoreDir,StoreDir2 : DirStr;
  6644. Title,DefExt: string;
  6645. AskOW: boolean;
  6646. begin
  6647. case Dialog of
  6648. edOutOfMemory:
  6649. StdEditorDialog := AdvMessageBox(msg_notenoughmemoryforthisoperation,
  6650. nil, mfInsertInApp+ mfError + mfOkButton);
  6651. edReadError:
  6652. StdEditorDialog := AdvMessageBox(msg_errorreadingfile,
  6653. @Info, mfInsertInApp+ mfError + mfOkButton);
  6654. edWriteError:
  6655. StdEditorDialog := AdvMessageBox(msg_errorwritingfile,
  6656. @Info, mfInsertInApp+ mfError + mfOkButton);
  6657. edSaveError:
  6658. StdEditorDialog := AdvMessageBox(msg_errorsavingfile,
  6659. @Info, mfInsertInApp+ mfError + mfOkButton);
  6660. edCreateError:
  6661. StdEditorDialog := AdvMessageBox(msg_errorcreatingfile,
  6662. @Info, mfInsertInApp+ mfError + mfOkButton);
  6663. edSaveModify:
  6664. StdEditorDialog := AdvMessageBox(msg_filehasbeenmodifiedsave,
  6665. @Info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6666. edSaveUntitled:
  6667. StdEditorDialog := AdvMessageBox(msg_saveuntitledfile,
  6668. nil, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6669. edChangedOnloading:
  6670. StdEditorDialog := AdvMessageBox(msg_filehadtoolonglines,
  6671. Info, mfInsertInApp+ mfOKButton + mfInformation);
  6672. edFileOnDiskChanged:
  6673. StdEditorDialog := AdvMessageBox(msg_filewasmodified,
  6674. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6675. edReloadDiskmodifiedFile:
  6676. StdEditorDialog := AdvMessageBox(msg_reloaddiskmodifiedfile,
  6677. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6678. edReloadDiskAndIDEModifiedFile:
  6679. StdEditorDialog := AdvMessageBox(msg_reloaddiskandidemodifiedfile,
  6680. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6681. edSaveAs,edWriteBlock,edReadBlock:
  6682. begin
  6683. Name:=PString(Info)^;
  6684. GetDir(0,StoreDir);
  6685. DriveNumber:=0;
  6686. if (Length(FileDir)>1) and (FileDir[2]=':') then
  6687. begin
  6688. { does not assume that lowercase are greater then uppercase ! }
  6689. if (FileDir[1]>='a') and (FileDir[1]<='z') then
  6690. DriveNumber:=Ord(FileDir[1])-ord('a')+1
  6691. else
  6692. DriveNumber:=Ord(FileDir[1])-ord('A')+1;
  6693. GetDir(DriveNumber,StoreDir2);
  6694. {$I-}
  6695. ChDir(Copy(FileDir,1,2));
  6696. EatIO;
  6697. {$I+}
  6698. end;
  6699. if FileDir<>'' then
  6700. begin
  6701. {$I-}
  6702. ChDir(TrimEndSlash(FileDir));
  6703. EatIO;
  6704. {$I+}
  6705. end;
  6706. case Dialog of
  6707. edSaveAs :
  6708. begin
  6709. Title:=dialog_savefileas;
  6710. DefExt:='*'+DefaultSaveExt;
  6711. end;
  6712. edWriteBlock :
  6713. begin
  6714. Title:=dialog_writeblocktofile;
  6715. DefExt:='*.*';
  6716. end;
  6717. edReadBlock :
  6718. begin
  6719. Title:=dialog_readblockfromfile;
  6720. DefExt:='*.*';
  6721. end;
  6722. else begin Title:='???'; DefExt:=''; end;
  6723. end;
  6724. Re:=Application^.ExecuteDialog(New(PFileDialog, Init(DefExt,
  6725. Title, label_name, fdOkButton, FileId)), @Name);
  6726. case Dialog of
  6727. edSaveAs :
  6728. begin
  6729. if ExtOf(Name)='' then
  6730. Name:=Name+DefaultSaveExt;
  6731. AskOW:=(Name<>PString(Info)^);
  6732. end;
  6733. edWriteBlock :
  6734. begin
  6735. if ExtOf(Name)='' then
  6736. Name:=Name+DefaultSaveExt;
  6737. AskOW:=true;
  6738. end;
  6739. edReadBlock : AskOW:=false;
  6740. else AskOW:=true;
  6741. end;
  6742. if (Re<>cmCancel) and AskOW then
  6743. begin
  6744. FileDir:=DirOf(FExpand(Name));
  6745. if ExistsFile(Name) then
  6746. if EditorDialog(edReplaceFile,@Name)<>cmYes then
  6747. Re:=cmCancel;
  6748. end;
  6749. if DriveNumber<>0 then
  6750. ChDir(StoreDir2);
  6751. if StoreDir<>'' then
  6752. ChDir(TrimEndSlash(StoreDir));
  6753. if Re<>cmCancel then
  6754. PString(Info)^:=Name;
  6755. StdEditorDialog := Re;
  6756. end;
  6757. edGotoLine:
  6758. StdEditorDialog :=
  6759. Application^.ExecuteDialog(CreateGotoLineDialog(Info), Info);
  6760. edFind:
  6761. StdEditorDialog :=
  6762. Application^.ExecuteDialog(CreateFindDialog, Info);
  6763. edSearchFailed:
  6764. StdEditorDialog := AdvMessageBox(msg_searchstringnotfound,
  6765. nil, mfInsertInApp+ mfError + mfOkButton);
  6766. edReplace:
  6767. StdEditorDialog :=
  6768. Application^.ExecuteDialog(CreateReplaceDialog, Info);
  6769. edReplacePrompt:
  6770. begin
  6771. { Avoid placing the dialog on the same line as the cursor }
  6772. R.Assign(0, 1, 40, 8);
  6773. R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  6774. Desktop^.MakeGlobal(R.B, T);
  6775. Inc(T.Y);
  6776. if PPoint(Info)^.Y <= T.Y then
  6777. R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  6778. StdEditorDialog := AdvMessageBoxRect(R, msg_replacethisoccourence,
  6779. nil, mfInsertInApp+ mfYesNoCancel + mfInformation);
  6780. end;
  6781. edReplaceFile :
  6782. StdEditorDialog :=
  6783. AdvMessageBox(msg_fileexistsoverwrite,@Info,mfInsertInApp+mfConfirmation+
  6784. mfYesButton+mfNoButton);
  6785. end;
  6786. end;
  6787. procedure RegisterWEditor;
  6788. begin
  6789. {$ifndef NOOBJREG}
  6790. {$endif}
  6791. end;
  6792. END.