weditor.pas 198 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323
  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. begin
  3101. CCAction:=ccClear;
  3102. E:=Event;
  3103. OldEvent:=CurEvent;
  3104. if (E.What and (evMouse or evKeyboard))<>0 then
  3105. CurEvent:=@E;
  3106. if (InASCIIMode=false) or (Event.What<>evKeyDown) then
  3107. if (Event.What<>evKeyDown) or (Event.KeyCode<>kbEnter) or (IsReadOnly=false) then
  3108. if (Event.What<>evKeyDown) or
  3109. ((Event.KeyCode<>kbEnter) and (Event.KeyCode<>kbEsc)) or
  3110. (GetCompleteState<>csOffering) then
  3111. ConvertEvent(Event);
  3112. case Event.What of
  3113. evMouseDown :
  3114. if MouseInView(Event.Where) then
  3115. if (Event.Buttons=mbRightButton) then
  3116. begin
  3117. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  3118. LocalMenu(P);
  3119. ClearEvent(Event);
  3120. end else
  3121. if Event.Buttons=mbLeftButton then
  3122. begin
  3123. GetMousePos(P);
  3124. StartP:=P;
  3125. SetCurPtr(P.X,P.Y);
  3126. repeat
  3127. GetMousePos(P);
  3128. if PointOfs(P)<PointOfs(StartP)
  3129. then SetSelection(P,StartP)
  3130. else SetSelection(StartP,P);
  3131. SetCurPtr(P.X,P.Y);
  3132. DrawView;
  3133. until not MouseEvent(Event, evMouseMove+evMouseAuto);
  3134. DrawView;
  3135. end;
  3136. evKeyDown :
  3137. begin
  3138. { Scancode is almost never zero PM }
  3139. { this is supposed to enable entering of ASCII chars below 32,
  3140. which are normally interpreted as control chars. So, when you enter
  3141. Alt+24 (on the numeric pad) then this will normally move the cursor
  3142. one line down, but if you do it in ASCII mode (also after Ctrl+B)
  3143. then this will insert the ASCII #24 char (upper arrow) in the
  3144. source code. - Gabor }
  3145. if InASCIIMode {and (Event.CharCode<>0)} then
  3146. begin
  3147. AddChar(Event.CharCode);
  3148. if (GetCompleteState<>csDenied) or (Event.CharCode=#32) then
  3149. CCAction:=ccCheck
  3150. else
  3151. CCAction:=ccClear;
  3152. end
  3153. else
  3154. begin
  3155. DontClear:=false;
  3156. case Event.KeyCode of
  3157. kbAltF10 :
  3158. Message(@Self,evCommand,cmLocalMenu,@Self);
  3159. kbEnter :
  3160. if IsReadOnly then
  3161. DontClear:=true else
  3162. if GetCompleteState=csOffering then
  3163. CodeCompleteApply
  3164. else
  3165. Message(@Self,evCommand,cmNewLine,nil);
  3166. kbEsc :
  3167. if GetCompleteState=csOffering then
  3168. CodeCompleteCancel else
  3169. if IsModal then
  3170. DontClear:=true;
  3171. else
  3172. case Event.CharCode of
  3173. #9,#32..#255 :
  3174. if (Event.CharCode=#9) and IsModal then
  3175. DontClear:=true
  3176. else
  3177. begin
  3178. NoSelect:=true;
  3179. AddChar(Event.CharCode);
  3180. NoSelect:=false;
  3181. if (GetCompleteState<>csDenied) or (Event.CharCode=#32) then
  3182. CCAction:=ccCheck
  3183. else
  3184. CCAction:=ccClear;
  3185. end;
  3186. else
  3187. DontClear:=true;
  3188. end; { case Event.CharCode .. }
  3189. end; { case Event.KeyCode .. }
  3190. if not DontClear then
  3191. ClearEvent(Event);
  3192. end;
  3193. InASCIIMode:=false;
  3194. end;
  3195. evCommand :
  3196. begin
  3197. DontClear:=false;
  3198. case Event.Command of
  3199. cmASCIIChar : InASCIIMode:=not InASCIIMode;
  3200. cmAddChar : AddChar(chr(longint(Event.InfoPtr)));
  3201. cmCharLeft : CharLeft;
  3202. cmCharRight : CharRight;
  3203. cmWordLeft : WordLeft;
  3204. cmWordRight : WordRight;
  3205. cmLineStart : LineStart;
  3206. cmLineEnd : LineEnd;
  3207. cmLineUp : LineUp;
  3208. cmLineDown : LineDown;
  3209. cmPageUp : PageUp;
  3210. cmPageDown : PageDown;
  3211. cmTextStart : TextStart;
  3212. cmTextEnd : TextEnd;
  3213. cmWindowStart : WindowStart;
  3214. cmWindowEnd : WindowEnd;
  3215. cmNewLine : begin
  3216. InsertNewLine;
  3217. TrackCursor(do_not_centre);
  3218. end;
  3219. cmBreakLine : BreakLine;
  3220. cmBackSpace : BackSpace;
  3221. cmDelChar : DelChar;
  3222. cmDelWord : DelWord;
  3223. cmDelToEndOfWord : DelToEndOfWord;
  3224. cmDelStart : DelStart;
  3225. cmDelEnd : DelEnd;
  3226. cmDelLine : DelLine;
  3227. cmInsMode : InsMode;
  3228. cmStartSelect : StartSelect;
  3229. cmHideSelect : HideSelect;
  3230. cmUpdateTitle : ;
  3231. cmEndSelect : EndSelect;
  3232. cmDelSelect : DelSelect;
  3233. cmCopyBlock : CopyBlock;
  3234. cmMoveBlock : MoveBlock;
  3235. cmIndentBlock : IndentBlock;
  3236. cmUnindentBlock : UnindentBlock;
  3237. cmSelStart : JumpSelStart;
  3238. cmSelEnd : JumpSelEnd;
  3239. cmLastCursorPos : JumpToLastCursorPos;
  3240. cmFindMatchingDelimiter : FindMatchingDelimiter(true);
  3241. cmFindMatchingDelimiterBack : FindMatchingDelimiter(false);
  3242. cmUpperCase : UpperCase;
  3243. cmLowerCase : LowerCase;
  3244. cmWordLowerCase : WordLowerCase;
  3245. cmWordUpperCase : WordUpperCase;
  3246. cmInsertOptions : InsertOptions;
  3247. cmToggleCase : ToggleCase;
  3248. cmCreateFold : CreateFoldFromBlock;
  3249. cmToggleFold : ToggleFold;
  3250. cmExpandFold : ExpandFold;
  3251. cmCollapseFold : CollapseFold;
  3252. cmJumpMark0..cmJumpMark9 : JumpMark(Event.Command-cmJumpMark0);
  3253. cmSetMark0..cmSetMark9 : DefineMark(Event.Command-cmSetMark0);
  3254. cmSelectWord : SelectWord;
  3255. cmSelectLine : SelectLine;
  3256. cmWriteBlock : WriteBlock;
  3257. cmReadBlock : ReadBlock;
  3258. cmPrintBlock : PrintBlock;
  3259. { ------ }
  3260. cmFind : Find;
  3261. cmReplace : Replace;
  3262. cmSearchAgain : DoSearchReplace;
  3263. cmJumpLine : GotoLine;
  3264. { ------ }
  3265. cmCut : ClipCut;
  3266. cmCopy : ClipCopy;
  3267. cmPaste : ClipPaste;
  3268. cmSelectAll : SelectAll(true);
  3269. cmUnselect : SelectAll(false);
  3270. {$ifdef WinClipSupported}
  3271. cmCopyWin : ClipCopyWin;
  3272. cmPasteWin : ClipPasteWin;
  3273. {$endif WinClipSupported}
  3274. cmUndo : Undo;
  3275. cmRedo : Redo;
  3276. cmClear : DelSelect;
  3277. cmExpandCodeTemplate: ExpandCodeTemplate;
  3278. cmLocalMenu :
  3279. begin
  3280. P:=CurPos; Inc(P.X); Inc(P.Y);
  3281. LocalMenu(P);
  3282. end;
  3283. cmActivateMenu :
  3284. Message(Application,evCommand,cmMenu,nil);
  3285. else
  3286. begin
  3287. DontClear:=true;
  3288. CCAction:=ccDontCare;
  3289. end;
  3290. end;
  3291. if DontClear=false then
  3292. ClearEvent(Event);
  3293. end;
  3294. {$ifdef TEST_PARTIAL_SYNTAX}
  3295. evIdle :
  3296. begin
  3297. CCAction:=ccDontCare;
  3298. { Complete syntax by 20 lines increment }
  3299. { could already be quite lengthy on slow systems }
  3300. if not GetSyntaxCompleted then
  3301. UpdateAttrsRange(GetLastSyntaxedLine,GetLastSyntaxedLine+20,AttrAll);
  3302. end;
  3303. {$endif TEST_PARTIAL_SYNTAX}
  3304. evBroadcast :
  3305. begin
  3306. CCAction:=ccDontCare;
  3307. case Event.Command of
  3308. cmUpdate :
  3309. Update;
  3310. cmClearLineHighlights :
  3311. SetLineFlagExclusive(lfHighlightRow,-1);
  3312. cmResetDebuggerRow :
  3313. SetLineFlagExclusive(lfDebuggerRow,-1);
  3314. cmScrollBarChanged:
  3315. if (Event.InfoPtr = HScrollBar) or
  3316. (Event.InfoPtr = VScrollBar) then
  3317. begin
  3318. CheckScrollBar(HScrollBar, Delta.X);
  3319. CheckScrollBar(VScrollBar, Delta.Y);
  3320. end;
  3321. end;
  3322. end;
  3323. else CCAction:=ccDontCare;
  3324. end;
  3325. inherited HandleEvent(Event);
  3326. CurEvent:=OldEvent;
  3327. case CCAction of
  3328. ccCheck : CodeCompleteCheck;
  3329. ccClear : ClearCodeCompleteWord;
  3330. end;
  3331. end;
  3332. procedure TCustomCodeEditor.UpdateUndoRedo(cm : word; action : byte);
  3333. var UndoMenu : PMenuItem;
  3334. begin
  3335. UndoMenu:=PAdvancedMenuBar(MenuBar)^.GetMenuItem(cm);
  3336. if assigned(UndoMenu) then
  3337. begin
  3338. If assigned(UndoMenu^.Param) then
  3339. DisposeStr(UndoMenu^.Param);
  3340. if action<lastaction then
  3341. UndoMenu^.Param:=NewStr(ActionString[action]);
  3342. end;
  3343. end;
  3344. procedure TCustomCodeEditor.Update;
  3345. begin
  3346. Lock;
  3347. LimitsChanged;
  3348. SelectionChanged;
  3349. HighlightChanged;
  3350. UnLock;
  3351. end;
  3352. function TCustomCodeEditor.GetLocalMenu: PMenu;
  3353. begin
  3354. GetLocalMenu:=nil;
  3355. end;
  3356. function TCustomCodeEditor.GetCommandTarget: PView;
  3357. begin
  3358. GetCommandTarget:=@Self;
  3359. end;
  3360. function TCustomCodeEditor.CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup;
  3361. var MV: PMenuPopup;
  3362. begin
  3363. New(MV, Init(Bounds, M));
  3364. CreateLocalMenuView:=MV;
  3365. end;
  3366. procedure TCustomCodeEditor.LocalMenu(P: TPoint);
  3367. var M: PMenu;
  3368. MV: PMenuPopUp;
  3369. R: TRect;
  3370. Re: word;
  3371. begin
  3372. M:=GetLocalMenu;
  3373. if M=nil then Exit;
  3374. if LastLocalCmd<>0 then
  3375. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  3376. Desktop^.GetExtent(R);
  3377. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  3378. MV:=CreateLocalMenuView(R,M);
  3379. Re:=Application^.ExecView(MV);
  3380. if M^.Default=nil then LastLocalCmd:=0
  3381. else LastLocalCmd:=M^.Default^.Command;
  3382. Dispose(MV, Done);
  3383. if Re<>0 then
  3384. Message(GetCommandTarget,evCommand,Re,@Self);
  3385. end;
  3386. function TCustomCodeEditor.GetReservedColCount: sw_integer;
  3387. var LSX: sw_integer;
  3388. begin
  3389. if IsFlagSet(efFolds) then LSX:=GetFoldStringWidth else LSX:=0;
  3390. GetReservedColCount:=LSX;
  3391. end;
  3392. procedure TCustomCodeEditor.Draw;
  3393. function GetEIFold(EI: PEditorLineInfo): PFold;
  3394. begin
  3395. if Assigned(EI) then GetEIFold:=EI^.Fold else GetEIFold:=nil;
  3396. end;
  3397. var SelectColor,
  3398. HighlightColColor,
  3399. HighlightRowColor,
  3400. ErrorMessageColor : word;
  3401. B: TDrawBuffer;
  3402. X,Y,AX,AY,MaxX,LSX: sw_integer;
  3403. PX: TPoint;
  3404. LineCount: sw_integer;
  3405. Line: PCustomLine;
  3406. LineText,Format: string;
  3407. isBreak : boolean;
  3408. C: char;
  3409. FreeFormat: array[0..MaxLineLength] of boolean;
  3410. Color: word;
  3411. ColorTab: array[coFirstColor..coLastColor] of word;
  3412. ErrorLine: integer;
  3413. ErrorMsg: string[MaxViewWidth];
  3414. function CombineColors(Orig,Modifier: byte): byte;
  3415. var Color: byte;
  3416. begin
  3417. if (Modifier and $0f)=0 then
  3418. Color:=(Orig and $0f) or (Modifier and $f0)
  3419. else
  3420. Color:=(Orig and $f0) or (Modifier and $0f);
  3421. { do not allow invisible }
  3422. { use white as foreground in this case }
  3423. if (Color and $f) = ((Color div $10) and $7) then
  3424. Color:=(Color and $F0) or $F;
  3425. CombineColors:=Color;
  3426. end;
  3427. var
  3428. FoldPrefix,FoldSuffix: string;
  3429. { SkipLine: boolean;}
  3430. { FoldStartLine: sw_integer;}
  3431. begin
  3432. if ELockFlag>0 then
  3433. begin
  3434. DrawCalled:=true;
  3435. Exit;
  3436. end;
  3437. DrawCalled:=false;
  3438. ErrorMsg:=copy(GetErrorMessage,1,MaxViewWidth);
  3439. if ErrorMsg='' then ErrorLine:=-1 else
  3440. if (CurPos.Y-Delta.Y)<(Size.Y div 2) then ErrorLine:=Size.Y-1
  3441. else ErrorLine:=0;
  3442. LineCount:=GetLineCount;
  3443. ColorTab[coTextColor]:=GetColor(1);
  3444. ColorTab[coWhiteSpaceColor]:=GetColor(2);
  3445. ColorTab[coCommentColor]:=GetColor(3);
  3446. ColorTab[coReservedWordColor]:=GetColor(4);
  3447. ColorTab[coIdentifierColor]:=GetColor(5);
  3448. ColorTab[coStringColor]:=GetColor(6);
  3449. ColorTab[coNumberColor]:=GetColor(7);
  3450. ColorTab[coAssemblerColor]:=GetColor(8);
  3451. ColorTab[coSymbolColor]:=GetColor(9);
  3452. ColorTab[coDirectiveColor]:=GetColor(13);
  3453. ColorTab[coHexNumberColor]:=GetColor(14);
  3454. ColorTab[coTabColor]:=GetColor(15);
  3455. { break same as error }
  3456. ColorTab[coBreakColor]:=GetColor(16);
  3457. ColorTab[coAsmReservedColor]:=GetColor(17);
  3458. SelectColor:=GetColor(10);
  3459. HighlightColColor:=GetColor(11);
  3460. HighlightRowColor:=GetColor(12);
  3461. ErrorMessageColor:=GetColor(16);
  3462. {$ifdef TEST_PARTIAL_SYNTAX}
  3463. If (not GetSyntaxCompleted) and (GetLastSyntaxedLine<Delta.Y+Size.Y) then
  3464. UpdateAttrsRange(GetLastSyntaxedLine,Delta.Y+Size.Y,AttrAll);
  3465. {$endif TEST_PARTIAL_SYNTAX}
  3466. LSX:=GetReservedColCount;
  3467. Y:=0; AY:=Delta.Y;
  3468. for Y:=0 to Size.Y-1 do
  3469. begin
  3470. if Y=ErrorLine then
  3471. begin
  3472. MoveChar(B,' ',ErrorMessageColor,Size.X);
  3473. MoveStr(B,ErrorMsg,ErrorMessageColor);
  3474. WriteLine(0,Y,Size.X,1,B);
  3475. end
  3476. else
  3477. begin
  3478. AY:=ViewToEditorLine(Delta.Y+Y);
  3479. if (0<=AY) and (AY<LineCount) then
  3480. begin
  3481. Line:=GetLine(AY);
  3482. if assigned(Line) then
  3483. begin
  3484. IsBreak:=Line^.IsFlagSet(lfBreakpoint);
  3485. end
  3486. else
  3487. begin
  3488. IsBreak:=false;
  3489. end;
  3490. end
  3491. else
  3492. begin
  3493. Line:=nil;
  3494. IsBreak:=false;
  3495. end;
  3496. begin
  3497. Color:=ColorTab[coTextColor];
  3498. FillChar(FreeFormat,SizeOf(FreeFormat),1);
  3499. MoveChar(B,' ',Color,Size.X);
  3500. GetDisplayTextFormat(AY,LineText,Format);
  3501. { if FlagSet(efSyntaxHighlight) then MaxX:=length(LineText)+1
  3502. else }MaxX:=Size.X+Delta.X;
  3503. for X:=1 to Min(MaxX,High(LineText)) do
  3504. begin
  3505. AX:=Delta.X+X-1;
  3506. if X<=length(LineText) then C:=LineText[X] else C:=' ';
  3507. PX.X:=AX-Delta.X; PX.Y:=AY;
  3508. if (Highlight.A.X<>Highlight.B.X) or (Highlight.A.Y<>Highlight.B.Y) then
  3509. { there's a highlight }
  3510. begin
  3511. if (PointOfs(Highlight.A)<=PointOfs(PX)) and (PointOfs(PX)<PointOfs(Highlight.B)) then
  3512. begin
  3513. Color:=SelectColor;
  3514. FreeFormat[X]:=false;
  3515. end;
  3516. end
  3517. else
  3518. { no highlight }
  3519. begin
  3520. if IsFlagSet(efVerticalBlocks) then
  3521. begin
  3522. if (SelStart.X<=AX) and (AX<=SelEnd.X) and
  3523. (SelStart.Y<=AY) and (AY<=SelEnd.Y) then
  3524. begin
  3525. Color:=SelectColor; FreeFormat[X]:=false;
  3526. end;
  3527. end
  3528. else
  3529. if PointOfs(SelStart)<>PointOfs(SelEnd) then
  3530. if (PointOfs(SelStart)<=PointOfs(PX)) and (PointOfs(PX)<PointOfs(SelEnd)) then
  3531. begin
  3532. Color:=SelectColor; FreeFormat[X]:=false;
  3533. end;
  3534. end; { no highlight }
  3535. if FreeFormat[X] then
  3536. if X<=length(Format) then
  3537. {Color:=ColorTab[ord(Format[X])] else Color:=ColorTab[coTextColor];
  3538. this give BoundsCheckError with -Cr quite often PM }
  3539. Color:=ColorTab[ord(Format[X]) mod (coLastColor + 1)] else Color:=ColorTab[coTextColor];
  3540. if IsFlagSet(efHighlightRow) and
  3541. (PX.Y=CurPos.Y) then
  3542. begin
  3543. Color:=CombineColors(Color,HighlightRowColor);
  3544. FreeFormat[X]:=false;
  3545. end;
  3546. if IsFlagSet(efHighlightColumn) and (PX.X=CurPos.X) then
  3547. begin
  3548. Color:=CombineColors(Color,HighlightColColor);
  3549. FreeFormat[X]:=false;
  3550. end;
  3551. if Assigned(Line) and Line^.IsFlagSet(lfHighlightRow) then
  3552. begin
  3553. Color:=CombineColors(Color,HighlightRowColor);
  3554. FreeFormat[X]:=false;
  3555. end;
  3556. if isbreak then
  3557. begin
  3558. Color:=ColorTab[coBreakColor];
  3559. FreeFormat[X]:=false;
  3560. end;
  3561. if Assigned(Line) and Line^.isFlagSet(lfDebuggerRow) then
  3562. begin
  3563. Color:=CombineColors(Color,HighlightRowColor);
  3564. FreeFormat[X]:=false;
  3565. end;
  3566. if (0<=LSX+X-1-Delta.X) and (LSX+X-1-Delta.X<MaxViewWidth) then
  3567. MoveChar(B[LSX+X-1-Delta.X],C,Color,1);
  3568. end; { for X:=1 to ... }
  3569. if IsFlagSet(efFolds) then
  3570. begin
  3571. GetFoldStrings(AY,FoldPrefix,FoldSuffix);
  3572. MoveStr(B[0],FoldPrefix,ColorTab[coTextColor]);
  3573. if FoldSuffix<>'' then
  3574. MoveStr(B[Size.X-1-length(FoldSuffix)],FoldSuffix,ColorTab[coTextColor]);
  3575. end;
  3576. WriteLine(0,Y,Size.X,1,B);
  3577. end; { if not SkipLine ... }
  3578. end; { not errorline }
  3579. end; { while (Y<Size.Y) ... }
  3580. DrawCursor;
  3581. end;
  3582. procedure TCustomCodeEditor.DrawCursor;
  3583. begin
  3584. if Elockflag>0 then
  3585. DrawCursorCalled:=true
  3586. else
  3587. begin
  3588. SetCursor(GetReservedColCount+CurPos.X-Delta.X,EditorToViewLine(CurPos.Y)-Delta.Y);
  3589. SetState(sfCursorIns,Overwrite);
  3590. end;
  3591. end;
  3592. procedure TCustomCodeEditor.ResetCursor;
  3593. begin
  3594. if Elockflag>0 then
  3595. begin
  3596. DrawCursorCalled:=true;
  3597. exit;
  3598. end
  3599. else
  3600. inherited ResetCursor;
  3601. end;
  3602. function TCustomCodeEditor.Overwrite: boolean;
  3603. begin
  3604. Overwrite:=not IsFlagSet(efInsertMode);
  3605. end;
  3606. procedure TCustomCodeEditor.SetCodeCompleteWord(const S: string);
  3607. begin
  3608. if S<>'' then
  3609. SetCompleteState(csOffering)
  3610. else
  3611. SetCompleteState(csInactive);
  3612. end;
  3613. procedure TCustomCodeEditor.ClearCodeCompleteWord;
  3614. begin
  3615. SetCodeCompleteWord('');
  3616. SetCompleteState(csInactive);
  3617. end;
  3618. function TCustomCodeEditor.GetCompleteState: TCompleteState;
  3619. begin
  3620. { Abstract }
  3621. GetCompleteState:=csInactive;
  3622. end;
  3623. procedure TCustomCodeEditor.SetCompleteState(AState: TCompleteState);
  3624. begin
  3625. { Abstract }
  3626. end;
  3627. function TCustomCodeEditor.UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer;
  3628. begin
  3629. Abstract;
  3630. UpdateAttrs:=-1;
  3631. end;
  3632. function TCustomCodeEditor.UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer;
  3633. begin
  3634. Abstract;
  3635. UpdateAttrsRange:=-1;
  3636. end;
  3637. procedure TCustomCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
  3638. begin
  3639. { Abstract }
  3640. end;
  3641. procedure TCustomCodeEditor.AddGroupedAction(AAction : byte);
  3642. begin
  3643. { Abstract }
  3644. end;
  3645. procedure TCustomCodeEditor.CloseGroupedAction(AAction : byte);
  3646. begin
  3647. { Abstract }
  3648. end;
  3649. function TCustomCodeEditor.GetUndoActionCount: sw_integer;
  3650. begin
  3651. { Abstract }
  3652. GetUndoActionCount:=0;
  3653. end;
  3654. function TCustomCodeEditor.GetRedoActionCount: sw_integer;
  3655. begin
  3656. { Abstract }
  3657. GetRedoActionCount:=0;
  3658. end;
  3659. function TCustomCodeEditor.GetMaxFoldLevel: sw_integer;
  3660. var Max,L,I: sw_integer;
  3661. begin
  3662. Max:=0;
  3663. for I:=0 to GetFoldCount-1 do
  3664. begin
  3665. L:=GetFold(I)^.GetLevel;
  3666. if L>Max then Max:=L;
  3667. end;
  3668. GetMaxFoldLevel:=Max;
  3669. end;
  3670. function TCustomCodeEditor.GetFoldStringWidth: sw_integer;
  3671. begin
  3672. GetFoldStringWidth:=GetMaxFoldLevel;
  3673. end;
  3674. procedure TCustomCodeEditor.GetFoldStrings(EditorLine: sw_integer; var Prefix, Suffix: openstring);
  3675. var F: PFold;
  3676. C: char;
  3677. begin
  3678. Prefix:=CharStr(' ',GetFoldStringWidth); Suffix:='';
  3679. F:=GetLineFold(EditorLine);
  3680. if Assigned(F) then
  3681. begin
  3682. if F^.Collapsed_ then C:=#27 else C:=#26;
  3683. Prefix[1+F^.GetLevel]:=C;
  3684. if F^.Collapsed_ then
  3685. Suffix:='('+IntToStr(F^.GetLineCount)+')';
  3686. end;
  3687. end;
  3688. function TCustomCodeEditor.GetFoldCount: sw_integer;
  3689. begin
  3690. GetFoldCount:=0;
  3691. end;
  3692. function TCustomCodeEditor.GetFold(Index: sw_integer): PFold;
  3693. begin
  3694. GetFold:=nil;
  3695. end;
  3696. procedure TCustomCodeEditor.RegisterFold(AFold: PFold);
  3697. begin
  3698. Abstract;
  3699. end;
  3700. procedure TCustomCodeEditor.UnRegisterFold(AFold: PFold);
  3701. begin
  3702. Abstract;
  3703. end;
  3704. procedure TCustomCodeEditor.Indent;
  3705. var S, PreS: string;
  3706. Shift: integer;
  3707. begin
  3708. S:=GetLineText(CurPos.Y);
  3709. if CurPos.Y>0 then
  3710. PreS:=RTrim(GetLineText(CurPos.Y-1),not IsFlagSet(efUseTabCharacters))
  3711. else
  3712. PreS:='';
  3713. if CurPos.X>=length(PreS) then
  3714. Shift:=GetTabSize
  3715. else
  3716. begin
  3717. Shift:=1;
  3718. while (CurPos.X+Shift<length(PreS)) and (PreS[CurPos.X+Shift]<>' ') do
  3719. Inc(Shift);
  3720. end;
  3721. SetLineText(CurPos.Y,RExpand(copy(S,1,CurPos.X+1),CurPos.X+1)+CharStr(' ',Shift)+copy(S,CurPos.X+2,High(S)));
  3722. SetCurPtr(CurPos.X+Shift,CurPos.Y);
  3723. UpdateAttrs(CurPos.Y,attrAll);
  3724. DrawLines(CurPos.Y);
  3725. SetModified(true);
  3726. end;
  3727. procedure TCustomCodeEditor.CharLeft;
  3728. begin
  3729. if CurPos.X=0 then Exit;
  3730. SetCurPtr(CurPos.X-1,CurPos.Y);
  3731. end;
  3732. procedure TCustomCodeEditor.CharRight;
  3733. begin
  3734. if CurPos.X>=MaxLineLength then
  3735. Exit;
  3736. SetCurPtr(CurPos.X+1,CurPos.Y);
  3737. end;
  3738. procedure TCustomCodeEditor.WordLeft;
  3739. var X, Y: sw_integer;
  3740. Line: string;
  3741. GotIt,FoundNonSeparator: boolean;
  3742. begin
  3743. X:=CurPos.X;
  3744. Y:=CurPos.Y;
  3745. GotIt:=false;
  3746. FoundNonSeparator:=false;
  3747. while (Y>=0) do
  3748. begin
  3749. if Y=CurPos.Y then
  3750. begin
  3751. X:=length(GetDisplayText(Y));
  3752. if CurPos.X<X then
  3753. X:=CurPos.X; Dec(X);
  3754. if (X=-1) then
  3755. begin
  3756. Dec(Y);
  3757. if Y>=0 then
  3758. X:=length(GetDisplayText(Y));
  3759. Break;
  3760. end;
  3761. end
  3762. else
  3763. X:=length(GetDisplayText(Y))-1;
  3764. Line:=GetDisplayText(Y);
  3765. while (X>=0) and (GotIt=false) do
  3766. begin
  3767. if FoundNonSeparator then
  3768. begin
  3769. if IsWordSeparator(Line[X+1]) then
  3770. begin
  3771. Inc(X);
  3772. GotIt:=true;
  3773. Break;
  3774. end;
  3775. end
  3776. else
  3777. if not IsWordSeparator(Line[X+1]) then
  3778. FoundNonSeparator:=true;
  3779. Dec(X);
  3780. if (X=0) and (IsWordSeparator(Line[1])=false) then
  3781. begin
  3782. GotIt:=true;
  3783. Break;
  3784. end;
  3785. end;
  3786. if GotIt then
  3787. Break;
  3788. X:=0;
  3789. Dec(Y);
  3790. if Y>=0 then
  3791. begin
  3792. X:=length(GetDisplayText(Y));
  3793. Break;
  3794. end;
  3795. end;
  3796. if Y<0 then Y:=0; if X<0 then X:=0;
  3797. SetCurPtr(X,Y);
  3798. end;
  3799. procedure TCustomCodeEditor.WordRight;
  3800. var X, Y: sw_integer;
  3801. Line: string;
  3802. GotIt: boolean;
  3803. begin
  3804. X:=CurPos.X; Y:=CurPos.Y; GotIt:=false;
  3805. while (Y<GetLineCount) do
  3806. begin
  3807. if Y=CurPos.Y then
  3808. begin
  3809. X:=CurPos.X; Inc(X);
  3810. if (X>length(GetDisplayText(Y))-1) then
  3811. begin Inc(Y); X:=0; end;
  3812. end else X:=0;
  3813. Line:=GetDisplayText(Y);
  3814. while (X<=length(Line)+1) and (GotIt=false) and (Line<>'') do
  3815. begin
  3816. if X=length(Line)+1 then begin GotIt:=true; Dec(X); Break end;
  3817. if IsWordSeparator(Line[X]) then
  3818. begin
  3819. while (Y<GetLineCount) and
  3820. (X<=length(Line)) and (IsWordSeparator(Line[X])) do
  3821. begin
  3822. Inc(X);
  3823. if X>=length(Line) then
  3824. begin GotIt:=true; Dec(X); Break; end;
  3825. end;
  3826. if (GotIt=false) and (X<length(Line)) then
  3827. begin
  3828. Dec(X);
  3829. GotIt:=true;
  3830. Break;
  3831. end;
  3832. end;
  3833. Inc(X);
  3834. end;
  3835. if GotIt then Break;
  3836. X:=0;
  3837. Inc(Y);
  3838. if (Y<GetLineCount) then
  3839. begin
  3840. Line:=GetDisplayText(Y);
  3841. if (Line<>'') and (IsWordSeparator(Line[1])=false) then Break;
  3842. end;
  3843. end;
  3844. if Y=GetLineCount then Y:=GetLineCount-1;
  3845. SetCurPtr(X,Y);
  3846. end;
  3847. procedure TCustomCodeEditor.LineStart;
  3848. begin
  3849. SetCurPtr(0,CurPos.Y);
  3850. end;
  3851. procedure TCustomCodeEditor.LineEnd;
  3852. var
  3853. s : string;
  3854. i : longint;
  3855. begin
  3856. if CurPos.Y<GetLineCount then
  3857. begin
  3858. s:=GetDisplayText(CurPos.Y);
  3859. i:=length(s);
  3860. while (i>0) and (s[i]=' ') do
  3861. dec(i);
  3862. SetCurPtr(i,CurPos.Y);
  3863. end
  3864. else
  3865. SetCurPtr(0,CurPos.Y);
  3866. end;
  3867. function TCustomCodeEditor.NextVisibleLine(StartLine: sw_integer; Down: boolean): sw_integer;
  3868. var Count,NL: sw_integer;
  3869. begin
  3870. if Down then
  3871. begin
  3872. Count:=GetLineCount;
  3873. NL:=StartLine;
  3874. while (NL<Count-1) and not IsLineVisible(NL) do
  3875. Inc(NL);
  3876. if NL>=Count then
  3877. NL:=-1;
  3878. end
  3879. else
  3880. begin
  3881. NL:=StartLine;
  3882. while (NL>0) and not IsLineVisible(NL) do
  3883. Dec(NL);
  3884. end;
  3885. if not IsLineVisible(NL) then
  3886. NL:=-1;
  3887. NextVisibleLine:=NL;
  3888. end;
  3889. procedure TCustomCodeEditor.LineUp;
  3890. var NL: sw_integer;
  3891. begin
  3892. NL:=NextVisibleLine(CurPos.Y-1,false);
  3893. if NL<>-1 then
  3894. SetCurPtr(CurPos.X,NL);
  3895. end;
  3896. procedure TCustomCodeEditor.LineDown;
  3897. var NL: sw_integer;
  3898. begin
  3899. NL:=NextVisibleLine(CurPos.Y+1,true);
  3900. if NL<>-1 then
  3901. SetCurPtr(CurPos.X,NL);
  3902. end;
  3903. procedure TCustomCodeEditor.PageUp;
  3904. var NL: sw_integer;
  3905. begin
  3906. ScrollTo(Delta.X,Max(Delta.Y-Size.Y,0));
  3907. NL:=Max(CurPos.Y-(Size.Y),0);
  3908. if not IsLineVisible(NL) then
  3909. NL:=NextVisibleLine(NL,false);
  3910. if NL>=0 then
  3911. SetCurPtr(CurPos.X,Max(0,NL));
  3912. end;
  3913. procedure TCustomCodeEditor.PageDown;
  3914. var NL: sw_integer;
  3915. begin
  3916. ScrollTo(Delta.X,Min(Delta.Y+Size.Y,GetLineCount-1));
  3917. NL:=Min(CurPos.Y+(Size.Y{-1}),GetLineCount-1);
  3918. if not IsLineVisible(NL) then
  3919. NL:=NextVisibleLine(NL,true);
  3920. if NL>=0 then
  3921. SetCurPtr(CurPos.X,Min(GetLineCount-1,NL));
  3922. end;
  3923. procedure TCustomCodeEditor.TextStart;
  3924. begin
  3925. SetCurPtr(0,0);
  3926. end;
  3927. procedure TCustomCodeEditor.TextEnd;
  3928. var s : string;
  3929. i : longint;
  3930. begin
  3931. s:=GetDisplayText(GetLineCount-1);
  3932. i:=length(s);
  3933. while (i>0) and (s[i]=' ') do
  3934. dec(i);
  3935. SetCurPtr(i,GetLineCount-1);
  3936. end;
  3937. procedure TCustomCodeEditor.WindowStart;
  3938. begin
  3939. SetCurPtr(CurPos.X,Delta.Y);
  3940. end;
  3941. procedure TCustomCodeEditor.WindowEnd;
  3942. begin
  3943. SetCurPtr(CurPos.X,Delta.Y+Size.Y-1);
  3944. end;
  3945. procedure TCustomCodeEditor.JumpSelStart;
  3946. begin
  3947. if ValidBlock then
  3948. SetCurPtr(SelStart.X,SelStart.Y);
  3949. end;
  3950. procedure TCustomCodeEditor.JumpSelEnd;
  3951. begin
  3952. if ValidBlock then
  3953. SetCurPtr(SelEnd.X,SelEnd.Y);
  3954. end;
  3955. procedure TCustomCodeEditor.JumpMark(MarkIdx: integer);
  3956. begin
  3957. DontConsiderShiftState:=true;
  3958. if (MarkIdx<Low(Bookmarks)) or (MarkIdx>High(Bookmarks)) then
  3959. begin ErrorBox(FormatStrInt(msg_invalidmarkindex,MarkIdx),nil); Exit; end;
  3960. with Bookmarks[MarkIdx] do
  3961. if Valid=false then
  3962. InformationBox(FormatStrInt(msg_marknotset,MarkIdx),nil)
  3963. else
  3964. SetCurPtr(Pos.X,Pos.Y);
  3965. DontConsiderShiftState:=false;
  3966. end;
  3967. procedure TCustomCodeEditor.DefineMark(MarkIdx: integer);
  3968. begin
  3969. if (MarkIdx<Low(Bookmarks)) or (MarkIdx>High(Bookmarks)) then
  3970. begin
  3971. ErrorBox(FormatStrInt(msg_invalidmarkindex,MarkIdx),nil);
  3972. Exit;
  3973. end;
  3974. with Bookmarks[MarkIdx] do
  3975. begin
  3976. Pos:=CurPos;
  3977. Valid:=true;
  3978. end;
  3979. end;
  3980. procedure TCustomCodeEditor.JumpToLastCursorPos;
  3981. begin
  3982. NotImplemented;
  3983. end;
  3984. procedure TCustomCodeEditor.UpperCase;
  3985. var StartP,EndP: TPoint;
  3986. begin
  3987. if ValidBlock=false then Exit;
  3988. GetSelectionArea(StartP,EndP);
  3989. AddGroupedAction(eaUpperCase);
  3990. ChangeCaseArea(StartP,EndP,caToUpperCase);
  3991. CloseGroupedAction(eaUpperCase);
  3992. end;
  3993. procedure TCustomCodeEditor.LowerCase;
  3994. var StartP,EndP: TPoint;
  3995. begin
  3996. if ValidBlock=false then Exit;
  3997. GetSelectionArea(StartP,EndP);
  3998. AddGroupedAction(eaLowerCase);
  3999. ChangeCaseArea(StartP,EndP,caToLowerCase);
  4000. CloseGroupedAction(eaLowerCase);
  4001. end;
  4002. procedure TCustomCodeEditor.ToggleCase;
  4003. var StartP,EndP: TPoint;
  4004. begin
  4005. if ValidBlock=false then Exit;
  4006. GetSelectionArea(StartP,EndP);
  4007. AddGroupedAction(eaToggleCase);
  4008. ChangeCaseArea(StartP,EndP,caToggleCase);
  4009. CloseGroupedAction(eaToggleCase);
  4010. end;
  4011. procedure TCustomCodeEditor.WordLowerCase;
  4012. var StartP,EndP: TPoint;
  4013. begin
  4014. if GetCurrentWordArea(StartP,EndP)=false then Exit;
  4015. AddGroupedAction(eaLowerCase);
  4016. ChangeCaseArea(StartP,EndP,caToLowerCase);
  4017. CloseGroupedAction(eaLowerCase);
  4018. end;
  4019. procedure TCustomCodeEditor.WordUpperCase;
  4020. var StartP,EndP: TPoint;
  4021. begin
  4022. if GetCurrentWordArea(StartP,EndP)=false then Exit;
  4023. AddGroupedAction(eaUpperCase);
  4024. ChangeCaseArea(StartP,EndP,caToUpperCase);
  4025. CloseGroupedAction(eaUpperCase);
  4026. end;
  4027. procedure TCustomCodeEditor.CreateFoldFromBlock;
  4028. var StartY,EndY: sw_integer;
  4029. begin
  4030. if not IsFlagSet(efFolds) then Exit;
  4031. if not ValidBlock then Exit;
  4032. StartY:=SelStart.Y; EndY:=SelEnd.Y;
  4033. if SelEnd.X=0 then Dec(EndY);
  4034. if CreateFold(StartY,EndY,false)=false then
  4035. ErrorBox(msg_foldboundsarenotvalid,nil);
  4036. end;
  4037. procedure TCustomCodeEditor.ToggleFold;
  4038. var F: PFold;
  4039. begin
  4040. if not IsFlagSet(efFolds) then Exit;
  4041. F:=GetLineFold(CurPos.Y);
  4042. if Assigned(F) then
  4043. F^.Collapse(not F^.Collapsed_);
  4044. end;
  4045. procedure TCustomCodeEditor.ExpandFold;
  4046. var F: PFold;
  4047. begin
  4048. if not IsFlagSet(efFolds) then Exit;
  4049. F:=GetLineFold(CurPos.Y);
  4050. if Assigned(F) then
  4051. F^.Collapse(false);
  4052. end;
  4053. procedure TCustomCodeEditor.CollapseFold;
  4054. var F: PFold;
  4055. begin
  4056. if not IsFlagSet(efFolds) then Exit;
  4057. F:=GetLineFold(CurPos.Y);
  4058. if Assigned(F) then
  4059. F^.Collapse(true);
  4060. end;
  4061. procedure TCustomCodeEditor.ChangeCaseArea(StartP,EndP: TPoint; CaseAction: TCaseAction);
  4062. var Y,X: sw_integer;
  4063. X1,X2: sw_integer;
  4064. S: string;
  4065. C: char;
  4066. StartPos : TPoint;
  4067. HoldUndo : boolean;
  4068. begin
  4069. Lock;
  4070. HoldUndo:=GetStoreUndo;
  4071. SetStoreUndo(false);
  4072. for Y:=StartP.Y to EndP.Y do
  4073. begin
  4074. S:=GetDisplayText(Y);
  4075. { Pierre, please implement undo here! Gabor }
  4076. X1:=0; X2:=length(S)-1;
  4077. if Y=StartP.Y then X1:=StartP.X;
  4078. if Y=EndP.Y then X2:=EndP.X;
  4079. SetStoreUndo(HoldUndo);
  4080. StartPos.X:=X1;
  4081. StartPos.Y:=Y;
  4082. { the only drawback is that we keep
  4083. the original text even if Toggle where
  4084. it is not really necessary PM }
  4085. Addaction(eaOverwriteText,StartPos,StartPos,Copy(S,X1+1,X2-X1+1),GetFlags);
  4086. SetStoreUndo(false);
  4087. for X:=X1 to X2 do
  4088. begin
  4089. C:=S[X+1];
  4090. case CaseAction of
  4091. caToLowerCase : C:=LowCase(C);
  4092. caToUpperCase : C:=UpCase(C);
  4093. caToggleCase : if C in['a'..'z'] then
  4094. C:=Upcase(C)
  4095. else
  4096. C:=LowCase(C);
  4097. end;
  4098. S[X+1]:=C;
  4099. end;
  4100. SetDisplayText(Y,S);
  4101. end;
  4102. UpdateAttrsRange(StartP.Y,EndP.Y,attrAll);
  4103. DrawLines(CurPos.Y);
  4104. SetModified(true);
  4105. Addaction(eaMoveCursor,StartPos,CurPos,'',GetFlags);
  4106. SetStoreUndo(HoldUndo);
  4107. UnLock;
  4108. end;
  4109. procedure TCustomCodeEditor.PushInfo(Const st : string);
  4110. begin
  4111. { Dummies }
  4112. end;
  4113. procedure TCustomCodeEditor.PopInfo;
  4114. begin
  4115. { Dummies }
  4116. end;
  4117. procedure TCustomCodeEditor.InsertOptions;
  4118. begin
  4119. { Abstract }
  4120. NotImplemented;
  4121. end;
  4122. function TCustomCodeEditor.GetLineFold(EditorLine: sw_integer): PFold;
  4123. var L: PCustomLine;
  4124. LI: PEditorLineInfo;
  4125. F: PFold;
  4126. begin
  4127. F:=nil;
  4128. if IsFlagSet(efFolds) then
  4129. if (0<=EditorLine) and (EditorLine<GetLineCount) then
  4130. begin
  4131. L:=GetLine(EditorLine);
  4132. if Assigned(L) then
  4133. LI:=L^.GetEditorInfo(@Self)
  4134. else
  4135. LI:=nil;
  4136. if Assigned(LI) then
  4137. F:=LI^.Fold;
  4138. end;
  4139. GetLineFold:=F;
  4140. end;
  4141. function TCustomCodeEditor.IsLineVisible(EditorLine: sw_integer): boolean;
  4142. var V: boolean;
  4143. F,PrevF: PFold;
  4144. FoldHeadline: boolean;
  4145. begin
  4146. V:=true;
  4147. if IsFlagSet(efFolds) then
  4148. begin
  4149. F:=GetLineFold(EditorLine);
  4150. if Assigned(F) then
  4151. begin
  4152. PrevF:=GetLineFold(EditorLine-1);
  4153. FoldHeadline:=false;
  4154. if (PrevF<>F) and ((PrevF=nil) or (not PrevF^.IsParent(F))) then
  4155. FoldHeadline:=true;
  4156. if FoldHeadline then
  4157. begin
  4158. if Assigned(F^.ParentFold) and (F^.ParentFold^.IsCollapsed) then
  4159. V:=false;
  4160. end
  4161. else
  4162. if F^.IsCollapsed then
  4163. V:=false;
  4164. end;
  4165. end;
  4166. IsLineVisible:=V;
  4167. end;
  4168. function TCustomCodeEditor.ViewToEditorLine(ViewLine: sw_integer): sw_integer;
  4169. var I,Line,Count: sw_integer;
  4170. begin
  4171. if not IsFlagSet(efFolds) then
  4172. Line:=ViewLine
  4173. else
  4174. begin
  4175. Count:=GetLineCount;
  4176. I:=0; Line:=-1;
  4177. while (Line<ViewLine) and (I<Count) do
  4178. begin
  4179. if IsLineVisible(I) then
  4180. Inc(Line);
  4181. Inc(I);
  4182. end;
  4183. if Line<>ViewLine then
  4184. Line:=-1
  4185. else
  4186. Line:=I-1;
  4187. end;
  4188. ViewToEditorLine:=Line;
  4189. end;
  4190. function TCustomCodeEditor.EditorToViewLine(EditorLine: sw_integer): sw_integer;
  4191. var I,Line: sw_integer;
  4192. begin
  4193. if not IsFlagSet(efFolds) then
  4194. Line:=EditorLine
  4195. else
  4196. begin
  4197. Line:=-1;
  4198. for I:=0 to EditorLine do
  4199. if IsLineVisible(I) then
  4200. Inc(Line);
  4201. end;
  4202. EditorToViewLine:=Line;
  4203. end;
  4204. procedure TCustomCodeEditor.ViewToEditorPoint(P: TPoint; var NP: TPoint);
  4205. begin
  4206. NP.X:=P.X-GetReservedColCount;
  4207. NP.Y:=ViewToEditorLine(P.Y);
  4208. end;
  4209. procedure TCustomCodeEditor.EditorToViewPoint(P: TPoint; var NP: TPoint);
  4210. begin
  4211. NP.X:=P.X+GetReservedColCount;
  4212. NP.Y:=EditorToViewLine(P.Y);
  4213. end;
  4214. procedure TCustomCodeEditor.FindMatchingDelimiter(ScanForward: boolean);
  4215. const OpenSymbols : string[6] = '[{(<''"';
  4216. CloseSymbols : string[6] = ']})>''"';
  4217. var SymIdx: integer;
  4218. LineText,LineAttr: string;
  4219. CurChar: char;
  4220. X,Y: sw_integer;
  4221. LineCount: sw_integer;
  4222. JumpPos: TPoint;
  4223. BracketLevel: integer;
  4224. begin
  4225. JumpPos.X:=-1; JumpPos.Y:=-1;
  4226. LineText:=GetDisplayText(CurPos.Y);
  4227. LineText:=copy(LineText,CurPos.X+1,1);
  4228. if LineText='' then Exit;
  4229. CurChar:=LineText[1];
  4230. Y:=CurPos.Y; X:=CurPos.X; LineCount:=0;
  4231. BracketLevel:=1;
  4232. if ScanForward then
  4233. begin
  4234. SymIdx:=Pos(CurChar,OpenSymbols);
  4235. if SymIdx=0 then Exit;
  4236. repeat
  4237. Inc(LineCount);
  4238. GetDisplayTextFormat(Y,LineText,LineAttr);
  4239. if LineCount<>1 then X:=-1;
  4240. repeat
  4241. Inc(X);
  4242. if X<length(LineText) then
  4243. if copy(LineAttr,X+1,1)<>chr(attrComment) then
  4244. if (LineText[X+1]=CloseSymbols[SymIdx]) and (BracketLevel=1) then
  4245. begin
  4246. JumpPos.X:=X; JumpPos.Y:=Y;
  4247. end
  4248. else
  4249. if LineText[X+1]=OpenSymbols[SymIdx] then
  4250. Inc(BracketLevel)
  4251. else
  4252. if LineText[X+1]=CloseSymbols[SymIdx] then
  4253. if BracketLevel>1 then
  4254. Dec(BracketLevel);
  4255. until (X>=length(LineText)) or (JumpPos.X<>-1);
  4256. Inc(Y);
  4257. until (Y>=GetLineCount) or (JumpPos.X<>-1);
  4258. end
  4259. else
  4260. begin
  4261. SymIdx:=Pos(CurChar,CloseSymbols);
  4262. if SymIdx=0 then Exit;
  4263. repeat
  4264. Inc(LineCount);
  4265. GetDisplayTextFormat(Y,LineText,LineAttr);
  4266. if LineCount<>1 then X:=length(LineText);
  4267. repeat
  4268. Dec(X);
  4269. if X>0 then
  4270. if copy(LineAttr,X+1,1)<>chr(attrComment) then
  4271. if (LineText[X+1]=OpenSymbols[SymIdx]) and (BracketLevel=1) then
  4272. begin
  4273. JumpPos.X:=X; JumpPos.Y:=Y;
  4274. end
  4275. else
  4276. if LineText[X+1]=CloseSymbols[SymIdx] then
  4277. Inc(BracketLevel)
  4278. else
  4279. if LineText[X+1]=OpenSymbols[SymIdx] then
  4280. if BracketLevel>1 then
  4281. Dec(BracketLevel);
  4282. until (X<0) or (JumpPos.X<>-1);
  4283. Dec(Y);
  4284. until (Y<0) or (JumpPos.X<>-1);
  4285. end;
  4286. if JumpPos.X<>-1 then
  4287. begin
  4288. SetCurPtr(JumpPos.X,JumpPos.Y);
  4289. TrackCursor(do_centre);
  4290. end;
  4291. end;
  4292. function TCustomCodeEditor.InsertNewLine: Sw_integer;
  4293. var i,Ind: Sw_integer;
  4294. S,IndentStr: string;
  4295. procedure CalcIndent(LineOver: Sw_integer);
  4296. begin
  4297. if (LineOver<0) or (LineOver>GetLineCount) or ((GetFlags and efNoIndent)<>0) then
  4298. Ind:=0 else
  4299. begin
  4300. repeat
  4301. IndentStr:=GetDisplayText(LineOver);
  4302. Dec(LineOver);
  4303. until (LineOver<0) or (IndentStr<>'');
  4304. Ind:=0;
  4305. while (Ind<length(IndentStr)) and (IndentStr[Ind+1]=' ') do
  4306. Inc(Ind);
  4307. end;
  4308. IndentStr:=CharStr(' ',Ind);
  4309. end;
  4310. var {SelBack: sw_integer;}
  4311. SCP: TPoint;
  4312. CI : sw_integer;
  4313. HoldUndo : Boolean;
  4314. L,NewL: PCustomLine;
  4315. EI,NewEI: PEditorLineInfo;
  4316. begin
  4317. if IsReadOnly then begin InsertNewLine:=-1; Exit; end;
  4318. Lock;
  4319. SCP:=CurPos;
  4320. HoldUndo:=GetStoreUndo;
  4321. SetStoreUndo(false);
  4322. if CurPos.Y<GetLineCount then S:=GetLineText(CurPos.Y) else S:='';
  4323. if Overwrite=false then
  4324. begin
  4325. if CurPos.Y<GetLineCount then
  4326. begin
  4327. L:=GetLine(CurPos.Y);
  4328. if not assigned(L) then
  4329. EI:=nil
  4330. else
  4331. EI:=L^.GetEditorInfo(@Self);
  4332. end
  4333. else
  4334. EI:=nil;
  4335. { SelBack:=0;}
  4336. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4337. if GetLineCount>0 then
  4338. begin
  4339. S:=GetLineText(CurPos.Y);
  4340. { SelBack:=length(S)-SelEnd.X;}
  4341. SetLineText(CurPos.Y,RTrim(S,not IsFlagSet(efUseTabCharacters)));
  4342. end;
  4343. SetLineText(CurPos.Y,copy(S,1,CI-1));
  4344. CalcIndent(CurPos.Y);
  4345. S:=copy(S,CI,High(S));
  4346. i:=1;
  4347. while (i<=length(s)) and (i<=length(IndentStr)) and (s[i]=' ') do
  4348. inc(i);
  4349. if i>1 then
  4350. Delete(IndentStr,1,i-1);
  4351. NewL:=InsertLine(CurPos.Y+1,IndentStr+S);
  4352. LimitsChanged;
  4353. (* if PointOfs(SelStart)<>PointOfs(SelEnd) then { !!! check it - it's buggy !!! }
  4354. begin SelEnd.Y:=CurPos.Y+1; SelEnd.X:=length(GetLineText(CurPos.Y+1))-SelBack; end;*)
  4355. UpdateAttrs(CurPos.Y,attrAll);
  4356. SetCurPtr(Ind,CurPos.Y+1);
  4357. NewEI:=NewL^.GetEditorInfo(@Self);
  4358. if Assigned(EI) and Assigned(NewEI) then
  4359. begin
  4360. NewEI^.SetFold(EI^.Fold);
  4361. if Assigned(EI^.Fold) then
  4362. if EI^.Fold^.IsCollapsed then
  4363. EI^.Fold^.Collapse(false);
  4364. end;
  4365. SetStoreUndo(HoldUndo);
  4366. { obsolete IndentStr is taken care of by the Flags PM }
  4367. Addaction(eaInsertLine,SCP,CurPos,CharStr(' ',i-1){IndentStr},GetFlags);
  4368. SetStoreUndo(false);
  4369. AdjustSelectionPos(SCP.X,SCP.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4370. end else
  4371. begin
  4372. CalcIndent(CurPos.Y);
  4373. if CurPos.Y=GetLineCount-1 then
  4374. begin
  4375. AddLine(IndentStr);
  4376. AdjustSelectionBefore(0,1);
  4377. LimitsChanged;
  4378. SetStoreUndo(HoldUndo);
  4379. UpdateAttrs(CurPos.Y,attrAll);
  4380. SetCurPtr(Ind,CurPos.Y+1);
  4381. { obsolete IndentStr is taken care of by the Flags PM }
  4382. Addaction(eaInsertLine,SCP,CurPos,''{IndentStr},GetFlags);
  4383. SetStoreUndo(false);
  4384. end
  4385. else
  4386. begin
  4387. UpdateAttrs(CurPos.Y,attrAll);
  4388. SetStoreUndo(HoldUndo);
  4389. SetCurPtr(Ind,CurPos.Y+1);
  4390. AddAction(eaMoveCursor,SCP,CurPos,'',GetFlags);
  4391. SetStoreUndo(false);
  4392. end;
  4393. end;
  4394. DrawLines(CurPos.Y);
  4395. SetStoreUndo(HoldUndo);
  4396. SetModified(true);
  4397. Unlock;
  4398. end;
  4399. procedure TCustomCodeEditor.BreakLine;
  4400. var
  4401. SCP: TPoint;
  4402. begin
  4403. { Like insert new line, but leave current pos unchanged }
  4404. SCP:=CurPos;
  4405. InsertNewLine;
  4406. SetCurPtr(SCP.X,SCP.Y);
  4407. end;
  4408. procedure TCustomCodeEditor.BackSpace;
  4409. var S,PreS: string;
  4410. OI,CI,CP,Y,TX: Sw_integer;
  4411. SCP,SC1 : TPoint;
  4412. HoldUndo : Boolean;
  4413. begin
  4414. if IsReadOnly then Exit;
  4415. Lock;
  4416. SCP:=CurPos;
  4417. HoldUndo:=GetStoreUndo;
  4418. SetStoreUndo(false);
  4419. if CurPos.X=0 then
  4420. begin
  4421. if CurPos.Y>0 then
  4422. begin
  4423. CI:=Length(GetDisplayText(CurPos.Y-1));
  4424. S:=GetLineText(CurPos.Y-1);
  4425. SetLineText(CurPos.Y-1,S+GetLineText(CurPos.Y));
  4426. SC1.X:=Length(S);SC1.Y:=CurPOS.Y-1;
  4427. SetStoreUndo(HoldUndo);
  4428. AddAction(eaDeleteLine,SCP,SC1,GetLineText(CurPos.Y),GetFlags);
  4429. SetStoreUndo(false);
  4430. DeleteLine(CurPos.Y);
  4431. LimitsChanged;
  4432. SetCurPtr(CI,CurPos.Y-1);
  4433. AdjustSelectionPos(Ci,CurPos.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4434. end;
  4435. end
  4436. else
  4437. begin
  4438. CP:=CurPos.X-1;
  4439. S:=GetLineText(CurPos.Y);
  4440. CI:=LinePosToCharIdx(CurPos.Y,CP);
  4441. if (s[ci]=TAB) and (CharIdxToLinePos(Curpos.y,ci)=cp) then
  4442. CP:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  4443. if IsFlagSet(efBackspaceUnindents) then
  4444. begin
  4445. S:=GetDisplayText(CurPos.Y);
  4446. if Trim(copy(S,1,CP+1))='' then
  4447. begin
  4448. Y:=CurPos.Y;
  4449. while (Y>0) do
  4450. begin
  4451. Dec(Y);
  4452. PreS:=GetDisplayText(Y);
  4453. if Trim(copy(PreS,1,CP+1))<>'' then Break;
  4454. end;
  4455. if Y<0 then PreS:='';
  4456. TX:=0;
  4457. while (TX<length(PreS)) and (PreS[TX+1]=' ') do
  4458. Inc(TX);
  4459. if TX<CP then CP:=TX;
  4460. end;
  4461. end;
  4462. S:=GetLineText(CurPos.Y);
  4463. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4464. CI:=LinePosToCharIdx(CurPos.Y,CP);
  4465. SetLineText(CurPos.Y,copy(S,1,CI-1)+copy(S,OI,High(S)));
  4466. SetCurPtr(CP,CurPos.Y);
  4467. SetStoreUndo(HoldUndo);
  4468. Addaction(eaDeleteText,SCP,CurPos,Copy(S,CI,OI-CI),GetFlags);
  4469. SetStoreUndo(false);
  4470. AdjustSelectionPos(SCP.X-1,SCP.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4471. end;
  4472. UpdateAttrs(CurPos.Y,attrAll);
  4473. DrawLines(CurPos.Y);
  4474. SetStoreUndo(HoldUndo);
  4475. SetModified(true);
  4476. Unlock;
  4477. end;
  4478. procedure TCustomCodeEditor.DelChar;
  4479. var S: string;
  4480. SDX,SDY,CI : sw_integer;
  4481. HoldUndo : boolean;
  4482. SCP : TPoint;
  4483. begin
  4484. if IsReadOnly then Exit;
  4485. Lock;
  4486. HoldUndo:=GetStoreUndo;
  4487. SetStoreUndo(false);
  4488. S:=GetLineText(CurPos.Y);
  4489. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4490. if (CI>length(S)) or (S='') then
  4491. begin
  4492. if CurPos.Y<GetLineCount-1 then
  4493. begin
  4494. SetLineText(CurPos.Y,S+CharStr(' ',CurPOS.X-Length(S))+GetLineText(CurPos.Y+1));
  4495. SDX:=CurPos.X;
  4496. SetStoreUndo(HoldUndo);
  4497. SCP.X:=0;SCP.Y:=CurPos.Y+1;
  4498. AddGroupedAction(eaDelChar);
  4499. AddAction(eaMoveCursor,CurPos,SCP,'',GetFlags);
  4500. S:=GetLineText(CurPos.Y+1);
  4501. AddAction(eaDeleteLine,SCP,CurPos,S,GetFlags);
  4502. CloseGroupedAction(eaDelChar);
  4503. SetStoreUndo(false);
  4504. DeleteLine(CurPos.Y+1);
  4505. LimitsChanged;
  4506. SDY:=-1;
  4507. SetCurPtr(CurPos.X,CurPos.Y);
  4508. UpdateAttrs(CurPos.Y,attrAll);
  4509. AdjustSelectionPos(CurPos.X,CurPos.Y,SDX,SDY);
  4510. end;
  4511. end
  4512. else
  4513. begin
  4514. SCP:=CurPos;
  4515. { Problem if S[CurPos.X+1]=TAB !! PM }
  4516. if S[CI]=TAB then
  4517. begin
  4518. { we want to remove the tab if we are at the first place
  4519. of the tab, but the following test was true for the last position
  4520. in tab
  4521. if CharIdxToLinePos(Curpos.y,ci)=Curpos.x then }
  4522. if CharIdxToLinePos(Curpos.y,ci-1)=Curpos.x-1 then
  4523. Delete(S,Ci,1)
  4524. else
  4525. S:=Copy(S,1,CI-1)+CharStr(' ',GetTabSize-1)+Copy(S,CI+1,High(S));
  4526. SetStoreUndo(HoldUndo);
  4527. Addaction(eaDeleteText,CurPos,CurPos,#9,GetFlags);
  4528. SDX:=-1;
  4529. SetStoreUndo(false);
  4530. end
  4531. else
  4532. begin
  4533. SetStoreUndo(HoldUndo);
  4534. Addaction(eaDeleteText,CurPos,CurPos,S[CI],GetFlags);
  4535. SetStoreUndo(false);
  4536. SDX:=-1;
  4537. Delete(S,CI,1);
  4538. end;
  4539. SetLineText(CurPos.Y,S);
  4540. SDY:=0;
  4541. SetCurPtr(CurPos.X,CurPos.Y);
  4542. UpdateAttrs(CurPos.Y,attrAll);
  4543. AdjustSelectionPos(SCP.X,SCP.Y,SDX,SDY);
  4544. end;
  4545. DrawLines(CurPos.Y);
  4546. SetStoreUndo(HoldUndo);
  4547. SetModified(true);
  4548. Unlock;
  4549. end;
  4550. procedure TCustomCodeEditor.DelWord;
  4551. var
  4552. SP,EP : TPoint;
  4553. SelSize : sw_integer;
  4554. begin
  4555. if IsReadOnly then Exit;
  4556. Lock;
  4557. SP:=SelStart;
  4558. EP:=SelEnd;
  4559. SetSelection(SelStart,SelStart);
  4560. SelectWord;
  4561. SelSize:=SelEnd.X-SelStart.X;
  4562. DelSelect;
  4563. SetSelection(SP,EP);
  4564. AdjustSelectionPos(CurPos.X,CurPos.Y,-SelSize,0);
  4565. if SelSize>0 then
  4566. SetModified(true);
  4567. Unlock;
  4568. end;
  4569. procedure TCustomCodeEditor.DelToEndOfWord;
  4570. var
  4571. SP,EP : TPoint;
  4572. S : String;
  4573. SelSize : sw_integer;
  4574. begin
  4575. if IsReadOnly then Exit;
  4576. Lock;
  4577. SP:=SelStart;
  4578. EP:=SelEnd;
  4579. SetSelection(SelStart,SelStart);
  4580. SelectWord;
  4581. S:=GetDisplayText(CurPos.Y);
  4582. if ((SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y)) then
  4583. begin
  4584. if (Length(S) <= CurPos.X) then
  4585. begin
  4586. SetSelection(SP,EP);
  4587. DelChar;
  4588. Unlock;
  4589. exit;
  4590. end
  4591. else
  4592. begin
  4593. SelEnd.X:=CurPos.X+1;
  4594. SelEnd.Y:=CurPos.Y;
  4595. end;
  4596. end;
  4597. while (length(S)>= SelEnd.X+1) and
  4598. ((S[SelEnd.X+1]=' ') or (S[SelEnd.X+1]=TAB)) do
  4599. inc(SelEnd.X);
  4600. SetSelection(CurPos,SelEnd);
  4601. SelSize:=SelEnd.X-SelStart.X;
  4602. DelSelect;
  4603. SetSelection(SP,EP);
  4604. AdjustSelectionPos(CurPos.X,CurPos.Y,-SelSize,0);
  4605. if SelSize>0 then
  4606. SetModified(true);
  4607. Unlock;
  4608. end;
  4609. procedure TCustomCodeEditor.DelStart;
  4610. var S: string;
  4611. OI: Sw_integer;
  4612. HoldUndo : Boolean;
  4613. SCP : TPoint;
  4614. begin
  4615. if IsReadOnly then Exit;
  4616. Lock;
  4617. HoldUndo:=GetStoreUndo;
  4618. SetStoreUndo(false);
  4619. SCP:=CurPos;
  4620. S:=GetLineText(CurPos.Y);
  4621. if (S<>'') and (CurPos.X<>0) then
  4622. begin
  4623. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4624. SetLineText(CurPos.Y,copy(S,OI,High(S)));
  4625. SetCurPtr(0,CurPos.Y);
  4626. SetStoreUndo(HoldUndo);
  4627. Addaction(eaDeleteText,SCP,CurPos,copy(S,1,OI-1),GetFlags);
  4628. SetStoreUndo(false);
  4629. AdjustSelectionPos(CurPos.X,CurPos.Y,-length(copy(S,1,OI-1)),0);
  4630. UpdateAttrs(CurPos.Y,attrAll);
  4631. DrawLines(CurPos.Y);
  4632. SetModified(true);
  4633. end;
  4634. SetStoreUndo(HoldUndo);
  4635. Unlock;
  4636. end;
  4637. procedure TCustomCodeEditor.DelEnd;
  4638. var S: string;
  4639. OI: Sw_integer;
  4640. HoldUndo : Boolean;
  4641. SCP : TPoint;
  4642. begin
  4643. if IsReadOnly then Exit;
  4644. Lock;
  4645. HoldUndo:=GetStoreUndo;
  4646. SetStoreUndo(false);
  4647. SCP:=CurPos;
  4648. S:=GetLineText(CurPos.Y);
  4649. if (S<>'') and (CurPos.X<>length(S)) then
  4650. begin
  4651. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4652. SetLineText(CurPos.Y,copy(S,1,OI-1));
  4653. SetCurPtr(CurPos.X,CurPos.Y);
  4654. SetStoreUndo(HoldUndo);
  4655. Addaction(eaDeleteText,SCP,CurPos,copy(S,OI,High(S)),GetFlags);
  4656. SetStoreUndo(false);
  4657. AdjustSelectionPos(CurPos.X+1,CurPos.Y,-length(copy(S,OI,High(S)))+1,0);
  4658. UpdateAttrs(CurPos.Y,attrAll);
  4659. DrawLines(CurPos.Y);
  4660. SetModified(true);
  4661. end;
  4662. SetStoreUndo(HoldUndo);
  4663. Unlock;
  4664. end;
  4665. procedure TCustomCodeEditor.DelLine;
  4666. var
  4667. HoldUndo : boolean;
  4668. SP : TPoint;
  4669. S : String;
  4670. begin
  4671. if IsReadOnly then Exit;
  4672. Lock;
  4673. if GetLineCount>0 then
  4674. begin
  4675. SP:=CurPos;
  4676. S:=GetLineText(CurPos.Y);
  4677. HoldUndo:=GetStoreUndo;
  4678. SetStoreUndo(false);
  4679. DeleteLine(CurPos.Y);
  4680. LimitsChanged;
  4681. AdjustSelectionBefore(0,-1);
  4682. SetCurPtr(0,CurPos.Y);
  4683. UpdateAttrs(Max(0,CurPos.Y-1),attrAll);
  4684. DrawLines(CurPos.Y);
  4685. SetStoreUndo(HoldUndo);
  4686. AddAction(eaDeleteLine,SP,CurPos,S,GetFlags);
  4687. SetModified(true);
  4688. end;
  4689. Unlock;
  4690. end;
  4691. procedure TCustomCodeEditor.InsMode;
  4692. begin
  4693. SetInsertMode(Overwrite);
  4694. end;
  4695. function TCustomCodeEditor.GetCurrentWordArea(var StartP,EndP: TPoint): boolean;
  4696. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  4697. var P : TPoint;
  4698. S : String;
  4699. StartPos,EndPos : byte;
  4700. OK: boolean;
  4701. begin
  4702. P:=CurPos;
  4703. S:=GetLineText(P.Y);
  4704. StartPos:=P.X+1;
  4705. EndPos:=StartPos;
  4706. OK:=(S[StartPos] in WordChars);
  4707. if OK then
  4708. begin
  4709. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  4710. Dec(StartPos);
  4711. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  4712. Inc(EndPos);
  4713. StartP.X:=StartPos-1; StartP.Y:=CurPos.Y;
  4714. EndP.X:=EndPos-1; EndP.Y:=CurPos.Y;
  4715. end;
  4716. GetCurrentWordArea:=OK;
  4717. end;
  4718. function TCustomCodeEditor.GetCurrentWord : string;
  4719. var S: string;
  4720. StartP,EndP: TPoint;
  4721. begin
  4722. if GetCurrentWordArea(StartP,EndP)=false then
  4723. S:=''
  4724. else
  4725. begin
  4726. S:=GetLineText(StartP.Y);
  4727. S:=copy(S,StartP.X+1,EndP.X-StartP.X+1);
  4728. end;
  4729. GetCurrentWord:=S;
  4730. end;
  4731. procedure TCustomCodeEditor.StartSelect;
  4732. var P1,P2: TPoint;
  4733. begin
  4734. if ValidBlock=false then
  4735. begin
  4736. { SetSelection(SelStart,Limit);}
  4737. P1:=CurPos; P1.X:=0; P2:=CurPos; {P2.X:=length(GetLineText(P2.Y))+1;}
  4738. SetSelection(P1,P2);
  4739. end
  4740. else
  4741. SetSelection(CurPos,SelEnd);
  4742. if PointOfs(SelEnd)<PointOfs(SelStart) then
  4743. SetSelection(SelStart,SelStart);
  4744. CheckSels;
  4745. DrawView;
  4746. end;
  4747. procedure TCustomCodeEditor.EndSelect;
  4748. var P: TPoint;
  4749. LS: sw_integer;
  4750. begin
  4751. P:=CurPos;
  4752. { P.X:=Min(SelEnd.X,length(GetLineText(SelEnd.Y)));}
  4753. LS:=length(GetLineText(SelEnd.Y));
  4754. if LS<P.X then P.X:=LS;
  4755. CheckSels;
  4756. SetSelection(SelStart,P);
  4757. DrawView;
  4758. end;
  4759. procedure TCustomCodeEditor.DelSelect;
  4760. var LineDelta, LineCount, CurLine: Sw_integer;
  4761. StartX,EndX,LastX: Sw_integer;
  4762. S: string;
  4763. SPos : TPoint;
  4764. begin
  4765. if IsReadOnly or (ValidBlock=false) then Exit;
  4766. Lock;
  4767. AddGroupedAction(eaDelBlock);
  4768. LineCount:=(SelEnd.Y-SelStart.Y)+1;
  4769. LineDelta:=0; LastX:=CurPos.X;
  4770. CurLine:=SelStart.Y;
  4771. { single line : easy }
  4772. if LineCount=1 then
  4773. begin
  4774. S:=GetDisplayText(CurLine);
  4775. StartX:=SelStart.X;
  4776. EndX:=SelEnd.X;
  4777. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4778. +copy(S,EndX+1,High(S)));
  4779. if GetStoreUndo then
  4780. begin
  4781. SPos.X:=StartX;
  4782. SPos.Y:=CurLine;
  4783. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,EndX-StartX),GetFlags);
  4784. end;
  4785. Inc(CurLine);
  4786. LastX:=SelStart.X;
  4787. end
  4788. { several lines : a bit less easy }
  4789. else
  4790. begin
  4791. S:=GetDisplayText(CurLine);
  4792. StartX:=SelStart.X;
  4793. EndX:=SelEnd.X;
  4794. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4795. +copy(GetDisplayText(CurLine+LineCount-1),EndX+1,High(S)));
  4796. if GetStoreUndo then
  4797. begin
  4798. SPos.X:=StartX;
  4799. SPos.Y:=CurLine;
  4800. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,High(S)),GetFlags);
  4801. S:=GetDisplayText(CurLine+LineCount-1);
  4802. end;
  4803. Inc(CurLine);
  4804. Inc(LineDelta);
  4805. LastX:=SelStart.X;
  4806. while (LineDelta<LineCount) do
  4807. begin
  4808. { delete the complete line }
  4809. DeleteLine(CurLine);
  4810. Inc(LineDelta);
  4811. end;
  4812. if GetStoreUndo then
  4813. begin
  4814. AddAction(eaInsertText,SPos,SPos,Copy(S,EndX+1,High(S)),GetFlags);
  4815. end;
  4816. end;
  4817. HideSelect;
  4818. SetCurPtr(LastX,CurLine-1);
  4819. UpdateAttrs(CurPos.Y,attrAll);
  4820. DrawLines(CurPos.Y);
  4821. SetModified(true);
  4822. CloseGroupedAction(eaDelBlock);
  4823. UnLock;
  4824. end;
  4825. procedure TCustomCodeEditor.HideSelect;
  4826. begin
  4827. SetSelection(CurPos,CurPos);
  4828. DrawLines(Delta.Y);
  4829. end;
  4830. procedure TCustomCodeEditor.CopyBlock;
  4831. var Temp: PCodeEditor;
  4832. R: TRect;
  4833. begin
  4834. if IsReadOnly or (ValidBlock=false) then Exit;
  4835. Lock;
  4836. GetExtent(R);
  4837. AddGroupedAction(eaCopyBlock);
  4838. New(Temp, Init(R, nil, nil, nil,nil));
  4839. Temp^.InsertFrom(@Self);
  4840. (* Temp^.SelectAll(true);
  4841. { this selects one line too much because
  4842. we have a empty line at creation to avoid
  4843. negative line problems so we need to decrease SelEnd.Y }
  4844. Dec(Temp^.SelEnd.Y);*)
  4845. InsertFrom(Temp);
  4846. Dispose(Temp, Done);
  4847. CloseGroupedAction(eaCopyBlock);
  4848. UnLock;
  4849. end;
  4850. procedure TCustomCodeEditor.MoveBlock;
  4851. var Temp: PCodeEditor;
  4852. R: TRect;
  4853. OldPos: TPoint;
  4854. begin
  4855. if IsReadOnly then Exit;
  4856. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4857. Lock;
  4858. AddGroupedAction(eaMoveBlock);
  4859. GetExtent(R);
  4860. New(Temp, Init(R, nil, nil, nil,nil));
  4861. Temp^.InsertFrom(@Self);
  4862. OldPos:=CurPos;
  4863. if CurPos.Y>SelStart.Y then
  4864. Dec(OldPos.Y,Temp^.GetLineCount-1);
  4865. DelSelect;
  4866. SetCurPtr(OldPos.X,OldPos.Y);
  4867. InsertFrom(Temp);
  4868. Dispose(Temp, Done);
  4869. CloseGroupedAction(eaMoveBlock);
  4870. UnLock;
  4871. end;
  4872. procedure TCustomCodeEditor.IndentBlock;
  4873. var
  4874. ey,i{,indlen} : Sw_integer;
  4875. S,Ind : String;
  4876. Pos : Tpoint;
  4877. begin
  4878. if IsReadOnly then Exit;
  4879. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4880. Lock;
  4881. AddGroupedAction(eaIndentBlock);
  4882. ey:=selend.y;
  4883. if selend.x=0 then
  4884. dec(ey);
  4885. S:='';
  4886. { If AutoIndent try to align first line to
  4887. last line before selection }
  4888. { DISABLED created problems PM
  4889. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4890. begin
  4891. i:=SelStart.Y-1;
  4892. while (S='') and (i>=0) do
  4893. begin
  4894. S:=GetDisplayText(i);
  4895. dec(i);
  4896. end;
  4897. if (S='') or (S[1]<>' ') then
  4898. Ind:=' '
  4899. else
  4900. begin
  4901. i:=1;
  4902. while (i<=Length(S)) and (S[i]=' ') do
  4903. inc(i);
  4904. indlen:=i;
  4905. S:=GetDisplayText(SelStart.Y);
  4906. i:=1;
  4907. while (i<=Length(S)) and (S[i]=' ') do
  4908. inc(i);
  4909. indlen:=indlen-i;
  4910. if indlen<=0 then
  4911. indlen:=1;
  4912. Ind:=CharStr(' ',indlen);
  4913. end;
  4914. end
  4915. else
  4916. Ind:=' ';}
  4917. Ind:=CharStr(' ',GetIndentSize);
  4918. for i:=selstart.y to ey do
  4919. begin
  4920. S:=GetLineText(i);
  4921. SetLineText(i,Ind+S);
  4922. Pos.X:=0;Pos.Y:=i;
  4923. AddAction(eaInsertText,Pos,Pos,Ind,GetFlags);
  4924. end;
  4925. SetCurPtr(CurPos.X,CurPos.Y);
  4926. { must be added manually here PM }
  4927. AddAction(eaMoveCursor,Pos,CurPos,'',GetFlags);
  4928. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  4929. DrawLines(CurPos.Y);
  4930. SetModified(true);
  4931. CloseGroupedAction(eaIndentBlock);
  4932. UnLock;
  4933. end;
  4934. procedure TCustomCodeEditor.UnindentBlock;
  4935. var
  4936. ey,i,j,k,indlen : Sw_integer;
  4937. S : String;
  4938. Pos : TPoint;
  4939. begin
  4940. if IsReadOnly then Exit;
  4941. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4942. Lock;
  4943. AddGroupedAction(eaUnindentBlock);
  4944. ey:=selend.y;
  4945. if selend.x=0 then
  4946. dec(ey);
  4947. { If AutoIndent try to align first line to
  4948. last line before selection }
  4949. { Disabled created problems
  4950. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4951. begin
  4952. S:=GetDisplayText(SelStart.Y);
  4953. i:=1;
  4954. while (i<=Length(S)) and (S[i]=' ') do
  4955. inc(i);
  4956. indlen:=i-1;
  4957. i:=SelStart.Y-1;
  4958. S:='';
  4959. while (S='') and (i>=0) do
  4960. begin
  4961. if Trim(Copy(GetDisplayText(i),1,indlen))='' then
  4962. S:=''
  4963. else
  4964. S:=GetDisplayText(i);
  4965. dec(i);
  4966. end;
  4967. if (S='') then
  4968. Indlen:=1
  4969. else
  4970. begin
  4971. i:=1;
  4972. while (i<=Length(S)) and (S[i]=' ') do
  4973. inc(i);
  4974. indlen:=indlen-i+1;
  4975. if indlen<=0 then
  4976. indlen:=1;
  4977. end;
  4978. end
  4979. else
  4980. Indlen:=1;}
  4981. Indlen:=GetIndentSize;
  4982. for i:=selstart.y to ey do
  4983. begin
  4984. S:=GetLineText(i);
  4985. k:=0;
  4986. for j:=1 to indlen do
  4987. if (length(s)>1) and (S[1]=' ') then
  4988. begin
  4989. Delete(s,1,1);
  4990. inc(k);
  4991. end;
  4992. SetLineText(i,S);
  4993. if k>0 then
  4994. begin
  4995. Pos.Y:=i;
  4996. Pos.X:=0;
  4997. AddAction(eaDeleteText,Pos,Pos,CharStr(' ',k),GetFlags);
  4998. end;
  4999. end;
  5000. SetCurPtr(CurPos.X,CurPos.Y);
  5001. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  5002. DrawLines(CurPos.Y);
  5003. SetModified(true);
  5004. CloseGroupedAction(eaUnindentBlock);
  5005. UnLock;
  5006. end;
  5007. procedure TCustomCodeEditor.SelectWord;
  5008. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  5009. var S : String;
  5010. StartPos,EndPos : byte;
  5011. A,B: TPoint;
  5012. begin
  5013. A:=CurPos;
  5014. B:=CurPos;
  5015. S:=GetDisplayText(A.Y);
  5016. StartPos:=A.X+1;
  5017. EndPos:=StartPos;
  5018. if not (S[StartPos] in WordChars) then
  5019. exit
  5020. else
  5021. begin
  5022. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  5023. Dec(StartPos);
  5024. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  5025. Inc(EndPos);
  5026. A.X:=StartPos-1;
  5027. B.X:=EndPos;
  5028. SetSelection(A,B);
  5029. end;
  5030. end;
  5031. procedure TCustomCodeEditor.SelectLine;
  5032. var A,B: TPoint;
  5033. begin
  5034. if CurPos.Y<GetLineCount then
  5035. begin
  5036. A.Y:=CurPos.Y; A.X:=0;
  5037. B.Y:=CurPos.Y+1; B.X:=0;
  5038. SetSelection(A,B);
  5039. end;
  5040. end;
  5041. procedure TCustomCodeEditor.WriteBlock;
  5042. var FileName: string;
  5043. S: PBufStream;
  5044. begin
  5045. if ValidBlock=false then Exit;
  5046. FileName:='';
  5047. if EditorDialog(edWriteBlock, @FileName) <> cmCancel then
  5048. begin
  5049. FileName := FExpand(FileName);
  5050. New(S, Init(FileName, stCreate, 4096));
  5051. if (S=nil) or (S^.Status<>stOK) then
  5052. EditorDialog(edCreateError,@FileName)
  5053. else
  5054. if SaveAreaToStream(S,SelStart,SelEnd)=false then
  5055. EditorDialog(edWriteError,@FileName);
  5056. if Assigned(S) then Dispose(S, Done);
  5057. end;
  5058. end;
  5059. procedure TCustomCodeEditor.ReadBlock;
  5060. var FileName: string;
  5061. S: PFastBufStream;
  5062. E: PCodeEditor;
  5063. R: TRect;
  5064. begin
  5065. if IsReadOnly then Exit;
  5066. FileName:='';
  5067. if EditorDialog(edReadBlock, @FileName) <> cmCancel then
  5068. begin
  5069. FileName := FExpand(FileName);
  5070. New(S, Init(FileName, stOpenRead, 4096));
  5071. if (S=nil) or (S^.Status<>stOK) then
  5072. EditorDialog(edReadError,@FileName)
  5073. else
  5074. begin
  5075. R.Assign(0,0,0,0);
  5076. New(E, Init(R,nil,nil,nil,nil));
  5077. AddGroupedAction(eaReadBlock);
  5078. if E^.LoadFromStream(S)=false then
  5079. EditorDialog(edReadError,@FileName)
  5080. else
  5081. begin
  5082. E^.SelectAll(true);
  5083. Self.InsertFrom(E);
  5084. end;
  5085. CloseGroupedAction(eaReadBlock);
  5086. Dispose(E, Done);
  5087. end;
  5088. if Assigned(S) then Dispose(S, Done);
  5089. end;
  5090. end;
  5091. procedure TCustomCodeEditor.PrintBlock;
  5092. begin
  5093. NotImplemented; Exit;
  5094. end;
  5095. function TCustomCodeEditor.SelectCodeTemplate(var ShortCut: string): boolean;
  5096. begin
  5097. { Abstract }
  5098. SelectCodeTemplate:=false;
  5099. end;
  5100. procedure TCustomCodeEditor.ExpandCodeTemplate;
  5101. var Line,ShortCutInEditor,ShortCut: string;
  5102. X,Y,I,LineIndent: sw_integer;
  5103. CodeLines: PUnsortedStringCollection;
  5104. CanJump: boolean;
  5105. CP: TPoint;
  5106. begin
  5107. {
  5108. The usage of editing primitives in this routine make it pretty slow, but
  5109. its speed is still acceptable and they make the implementation of Undo
  5110. much easier... - Gabor
  5111. }
  5112. if IsReadOnly then Exit;
  5113. Lock;
  5114. CP.X:=-1; CP.Y:=-1;
  5115. Line:=GetDisplayText(CurPos.Y);
  5116. X:=CurPos.X; ShortCut:='';
  5117. if X<=length(Line) then
  5118. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  5119. begin
  5120. ShortCut:=Line[X]+ShortCut;
  5121. Dec(X);
  5122. end;
  5123. ShortCutInEditor:=ShortCut;
  5124. New(CodeLines, Init(10,10));
  5125. if (ShortCut='') or (not TranslateCodeTemplate(ShortCut,CodeLines)) then
  5126. if SelectCodeTemplate(ShortCut) then
  5127. TranslateCodeTemplate(ShortCut,CodeLines);
  5128. if CodeLines^.Count>0 then
  5129. begin
  5130. LineIndent:=X;
  5131. SetCurPtr(X,CurPos.Y);
  5132. if Copy(ShortCut,1,length(ShortCutInEditor))=ShortCutInEditor then
  5133. begin
  5134. for I:=1 to length(ShortCutInEditor) do
  5135. DelChar;
  5136. end
  5137. else
  5138. { restore correct position }
  5139. SetCurPtr(X+Length(ShortCutInEditor),CurPos.Y);
  5140. for Y:=0 to CodeLines^.Count-1 do
  5141. begin
  5142. Line:=GetStr(CodeLines^.At(Y));
  5143. CanJump:=false;
  5144. if (Y>0) then
  5145. begin
  5146. CanJump:=Trim(GetLineText(CurPos.Y))='';
  5147. if CanJump=false then
  5148. begin
  5149. (* for X:=1 to LineIndent do { indent template lines to align }
  5150. AddChar(' '); { them to the first line }*)
  5151. InsertText(CharStr(' ',LineIndent));
  5152. end
  5153. else
  5154. SetCurPtr(CurPos.X+LineIndent,CurPos.Y);
  5155. end;
  5156. I:=Pos(CodeTemplateCursorChar,Line);
  5157. if I>0 then
  5158. begin
  5159. Delete(Line,I,1);
  5160. CP.X:=CurPos.X+I-1;
  5161. CP.Y:=CurPos.Y;
  5162. end;
  5163. InsertText(Line);
  5164. if Y<CodeLines^.Count-1 then
  5165. begin
  5166. InsertNewLine; { line break }
  5167. if CanJump=false then
  5168. begin
  5169. while CurPos.X>0 do { unindent }
  5170. begin
  5171. SetCurPtr(CurPos.X-1,CurPos.Y);
  5172. DelChar;
  5173. end;
  5174. end
  5175. else
  5176. SetCurPtr(0,CurPos.Y);
  5177. end;
  5178. end;
  5179. end;
  5180. Dispose(CodeLines, Done);
  5181. if (CP.X<>-1) and (CP.Y<>-1) then
  5182. SetCurPtr(CP.X,CP.Y);
  5183. UnLock;
  5184. end;
  5185. procedure TCustomCodeEditor.AddChar(C: char);
  5186. const OpenBrackets : string[10] = '[({';
  5187. CloseBrackets : string[10] = '])}';
  5188. var S,SC,TabS: string;
  5189. BI: byte;
  5190. CI,TabStart,LocTabSize : Sw_integer;
  5191. SP: TPoint;
  5192. HoldUndo : boolean;
  5193. begin
  5194. if IsReadOnly then Exit;
  5195. Lock;
  5196. SP:=CurPos;
  5197. HoldUndo:=GetStoreUndo;
  5198. SetStoreUndo(false);
  5199. if (C<>TAB) or IsFlagSet(efUseTabCharacters) then
  5200. SC:=C
  5201. else
  5202. begin
  5203. LocTabSize:=GetTabSize - (CurPos.X mod GetTabSize);
  5204. if (CurPos.Y<=1) or not IsFlagSet(efAutoIndent) then
  5205. SC:=CharStr(' ',LocTabSize)
  5206. else
  5207. begin
  5208. S:=GetLineText(CurPos.Y-1);
  5209. BI:=CurPos.X+1;
  5210. while (BI<=Length(S)) and (S[BI]=' ') do
  5211. inc(BI);
  5212. if (BI=CurPos.X+1) or (BI>Length(S)) then
  5213. SC:=CharStr(' ',LocTabSize)
  5214. else
  5215. SC:=CharStr(' ',BI-CurPos.X-1);
  5216. end;
  5217. end;
  5218. S:=GetLineText(CurPos.Y);
  5219. if CharIdxToLinePos(CurPos.Y,length(S))<CurPos.X then
  5220. begin
  5221. S:=S+CharStr(' ',CurPos.X-CharIdxToLinePos(CurPos.Y,length(S)){-1});
  5222. SetLineText(CurPos.Y,S);
  5223. end;
  5224. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  5225. if CI>High(S) then
  5226. begin
  5227. Unlock;
  5228. exit;
  5229. end;
  5230. if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then
  5231. begin
  5232. if CI=1 then
  5233. TabStart:=0
  5234. else
  5235. TabStart:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  5236. if SC=Tab then TabS:=Tab else
  5237. TabS:=CharStr(' ',CurPos.X-TabStart);
  5238. SetLineText(CurPos.Y,copy(S,1,CI-1)+TabS+SC+copy(S,CI+1,High(S)));
  5239. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(TabS)+length(SC)),CurPos.Y);
  5240. end
  5241. else
  5242. begin
  5243. if Overwrite and (CI<=length(S)) then
  5244. begin
  5245. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI+length(SC),High(S)));
  5246. end
  5247. else
  5248. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI,High(S)));
  5249. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(SC)),CurPos.Y);
  5250. end;
  5251. { must be before CloseBrackets !! }
  5252. SetStoreUndo(HoldUndo);
  5253. if Overwrite then
  5254. Addaction(eaOverwriteText,SP,CurPos,Copy(S,CI,length(SC)),GetFlags)
  5255. else
  5256. Addaction(eaInsertText,SP,CurPos,SC,GetFlags);
  5257. SetStoreUndo(false);
  5258. if IsFlagSet(efAutoBrackets) then
  5259. begin
  5260. BI:=Pos(C,OpenBrackets);
  5261. if (BI>0) then
  5262. begin
  5263. SetStoreUndo(HoldUndo);
  5264. AddChar(CloseBrackets[BI]);
  5265. SetStoreUndo(false);
  5266. SetCurPtr(CurPos.X-1,CurPos.Y);
  5267. end;
  5268. end;
  5269. UpdateAttrs(CurPos.Y,attrAll);
  5270. if GetInsertMode then
  5271. AdjustSelection(CurPos.X-SP.X,CurPos.Y-SP.Y);
  5272. DrawLines(CurPos.Y);
  5273. SetStoreUndo(HoldUndo);
  5274. SetModified(true);
  5275. UnLock;
  5276. end;
  5277. {$ifdef WinClipSupported}
  5278. const
  5279. linelimit = 200;
  5280. function TCustomCodeEditor.ClipPasteWin: Boolean;
  5281. var
  5282. StorePos : TPoint;
  5283. first : boolean;
  5284. procedure InsertStringWrap(const s: string; var i : Longint);
  5285. var
  5286. BPos,EPos: TPoint;
  5287. begin
  5288. if first then
  5289. begin
  5290. { we need to cut the line in two
  5291. if not at end of line PM }
  5292. InsertNewLine;
  5293. SetCurPtr(StorePos.X,StorePos.Y);
  5294. InsertText(s);
  5295. first:=false;
  5296. end
  5297. else
  5298. begin
  5299. Inc(i);
  5300. InsertLine(i,s);
  5301. BPos.X:=0;BPos.Y:=i;
  5302. EPOS.X:=Length(s);EPos.Y:=i;
  5303. AddAction(eaInsertLine,BPos,EPos,GetDisplayText(i),GetFlags);
  5304. end;
  5305. end;
  5306. var
  5307. OK: boolean;
  5308. l,i,len,len10 : longint;
  5309. p,p10,p2,p13 : pchar;
  5310. s : string;
  5311. begin
  5312. Lock;
  5313. OK:=WinClipboardSupported;
  5314. if OK then
  5315. begin
  5316. first:=true;
  5317. StorePos:=CurPos;
  5318. i:=CurPos.Y;
  5319. l:=GetTextWinClipboardSize;
  5320. if l=0 then
  5321. OK:=false
  5322. else
  5323. OK:=GetTextWinClipBoardData(p,l);
  5324. if OK then
  5325. begin
  5326. if l>500 then
  5327. PushInfo(msg_readingwinclipboard);
  5328. AddGroupedAction(eaPasteWin);
  5329. p2:=p;
  5330. len:=strlen(p2);
  5331. // issue lines ((#13)#10 terminated) of maximally "linelimit" chars.
  5332. // does not take initial X position into account
  5333. repeat
  5334. p13:=strpos(p2,#13);
  5335. p10:=strpos(p2,#10);
  5336. if len> linelimit then
  5337. len:=linelimit;
  5338. if assigned(p10) then
  5339. begin
  5340. len10:=p10-p2;
  5341. if len10<len then
  5342. begin
  5343. if p13+1=p10 then
  5344. dec(len10);
  5345. len:=len10;
  5346. end
  5347. else
  5348. p10:=nil; // signal no cleanup
  5349. end;
  5350. setlength(s,len);
  5351. if len>0 then
  5352. move(p2^,s[1],len);
  5353. // cleanup
  5354. if assigned(p10) then
  5355. p2:=p10+1
  5356. else
  5357. inc(p2,len);
  5358. insertstringwrap(s,i);
  5359. len:=strlen(p2);
  5360. until len=0;
  5361. SetCurPtr(StorePos.X,StorePos.Y); // y+i to get after paste?
  5362. SetModified(true);
  5363. UpdateAttrs(StorePos.Y,attrAll);
  5364. CloseGroupedAction(eaPasteWin);
  5365. Update;
  5366. if l>500 then
  5367. PopInfo;
  5368. { we must free the allocated memory }
  5369. freemem(p,l);
  5370. DrawView;
  5371. end;
  5372. end;
  5373. ClipPasteWin:=OK;
  5374. UnLock;
  5375. end;
  5376. function TCustomCodeEditor.ClipCopyWin: Boolean;
  5377. var OK,ShowInfo: boolean;
  5378. p,p2 : pchar;
  5379. s : string;
  5380. i,str_begin,str_end,NumLines,PcLength : longint;
  5381. begin
  5382. NumLines:=SelEnd.Y-SelStart.Y;
  5383. if (NumLines>0) or (SelEnd.X>SelStart.X) then
  5384. Inc(NumLines);
  5385. if NumLines=0 then
  5386. exit;
  5387. Lock;
  5388. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5389. if ShowInfo then
  5390. PushInfo(msg_copyingwinclipboard);
  5391. { First calculate needed size }
  5392. { for newlines first + 1 for terminal #0 }
  5393. PcLength:=Length(EOL)*(NumLines-1)+1;
  5394. { overestimated but can not be that big PM }
  5395. for i:=SelStart.Y to SelEnd.Y do
  5396. PCLength:=PCLength+Length(GetLineText(i));
  5397. getmem(p,PCLength);
  5398. i:=SelStart.Y;
  5399. s:=GetLineText(i);
  5400. str_begin:=LinePosToCharIdx(i,SelStart.X);
  5401. if SelEnd.Y>SelStart.Y then
  5402. str_end:=High(S)
  5403. else
  5404. str_end:=LinePosToCharIdx(i,SelEnd.X)-1;
  5405. s:=copy(s,str_begin,str_end-str_begin+1);
  5406. strpcopy(p,s);
  5407. p2:=strend(p);
  5408. inc(i);
  5409. while i<SelEnd.Y do
  5410. begin
  5411. strpcopy(p2,EOL+GetLineText(i));
  5412. p2:=strend(p2);
  5413. Inc(i);
  5414. end;
  5415. if SelEnd.Y>SelStart.Y then
  5416. begin
  5417. s:=copy(GetLineText(i),1,LinePosToCharIdx(i,SelEnd.X)-1);
  5418. strpcopy(p2,EOL+s);
  5419. end;
  5420. OK:=WinClipboardSupported;
  5421. if OK then
  5422. begin
  5423. OK:=SetTextWinClipBoardData(p,strlen(p));
  5424. end;
  5425. ClipCopyWin:=OK;
  5426. if ShowInfo then
  5427. PopInfo;
  5428. Freemem(p,PCLength);
  5429. UnLock;
  5430. end;
  5431. {$endif WinClipSupported}
  5432. function TCustomCodeEditor.ClipCopy: Boolean;
  5433. var ShowInfo,CanPaste: boolean;
  5434. begin
  5435. Lock;
  5436. {AddGroupedAction(eaCopy);
  5437. can we undo a copy ??
  5438. maybe as an Undo Paste in Clipboard !! }
  5439. clipcopy:=false;
  5440. showinfo:=false;
  5441. if (clipboard<>nil) and (clipboard<>@self) then
  5442. begin
  5443. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5444. if ShowInfo then
  5445. PushInfo(msg_copyingclipboard);
  5446. clipcopy:=Clipboard^.InsertFrom(@Self);
  5447. if ShowInfo then
  5448. PopInfo;
  5449. {Enable paste command.}
  5450. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5451. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5452. SetCmdState(FromClipCmds,CanPaste);
  5453. end;
  5454. UnLock;
  5455. end;
  5456. procedure TCustomCodeEditor.ClipCut;
  5457. var
  5458. ShowInfo,CanPaste : boolean;
  5459. begin
  5460. if IsReadOnly then Exit;
  5461. Lock;
  5462. AddGroupedAction(eaCut);
  5463. DontConsiderShiftState:=true;
  5464. if (clipboard<>nil) and (clipboard<>@self) then
  5465. begin
  5466. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5467. if ShowInfo then
  5468. PushInfo(msg_cutting);
  5469. if Clipboard^.InsertFrom(@Self) then
  5470. begin
  5471. if not IsClipBoard then
  5472. DelSelect;
  5473. SetModified(true);
  5474. end;
  5475. if ShowInfo then
  5476. PopInfo;
  5477. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5478. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5479. SetCmdState(FromClipCmds,CanPaste);
  5480. end;
  5481. CloseGroupedAction(eaCut);
  5482. UnLock;
  5483. DontConsiderShiftState:=false;
  5484. end;
  5485. procedure TCustomCodeEditor.ClipPaste;
  5486. var
  5487. ShowInfo : boolean;
  5488. begin
  5489. if IsReadOnly then Exit;
  5490. DontConsiderShiftState:=true;
  5491. Lock;
  5492. AddGroupedAction(eaPaste);
  5493. if Clipboard<>nil then
  5494. begin
  5495. ShowInfo:=Clipboard^.SelEnd.Y-Clipboard^.SelStart.Y>50;
  5496. if ShowInfo then
  5497. PushInfo(msg_pastingclipboard);
  5498. InsertFrom(Clipboard);
  5499. if ShowInfo then
  5500. PopInfo;
  5501. end;
  5502. CloseGroupedAction(eaPaste);
  5503. UnLock;
  5504. DontConsiderShiftState:=false;
  5505. end;
  5506. procedure TCustomCodeEditor.Undo;
  5507. begin
  5508. NotImplemented; Exit;
  5509. end;
  5510. procedure TCustomCodeEditor.Redo;
  5511. begin
  5512. NotImplemented; Exit;
  5513. end;
  5514. procedure TCustomCodeEditor.GotoLine;
  5515. var
  5516. GotoRec: TGotoLineDialogRec;
  5517. begin
  5518. with GotoRec do
  5519. begin
  5520. LineNo:='1';
  5521. Lines:=GetLineCount;
  5522. {Linecount can be 0, but in that case there still is a cursor blinking in top
  5523. of the window, which will become line 1 as soon as sometype hits a key.}
  5524. if lines=0 then
  5525. lines:=1;
  5526. if EditorDialog(edGotoLine, @GotoRec) <> cmCancel then
  5527. begin
  5528. Lock;
  5529. SetCurPtr(0,StrToInt(LineNo)-1);
  5530. TrackCursor(do_centre);
  5531. UnLock;
  5532. end;
  5533. end;
  5534. end;
  5535. procedure TCustomCodeEditor.Find;
  5536. var
  5537. FindRec: TFindDialogRec;
  5538. DoConf: boolean;
  5539. begin
  5540. with FindRec do
  5541. begin
  5542. Find := FindStr;
  5543. if GetCurrentWord<>'' then
  5544. Find:=GetCurrentWord;
  5545. {$ifdef TEST_REGEXP}
  5546. Options := ((FindFlags and ffmOptionsFind) shr ffsOptions) or
  5547. ((FindFlags and ffUseRegExp) shr ffsUseRegExpFind);
  5548. {$else not TEST_REGEXP}
  5549. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5550. {$endif TEST_REGEXP}
  5551. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5552. Scope := (FindFlags and ffmScope) shr ffsScope;
  5553. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5554. DoConf:= (FindFlags and ffPromptOnReplace)<>0;
  5555. FindReplaceEditor:=@self;
  5556. if EditorDialog(edFind, @FindRec) <> cmCancel then
  5557. begin
  5558. FindStr := Find;
  5559. {$ifdef TEST_REGEXP}
  5560. FindFlags := ((Options and ffmOptionsFind) shl ffsOptions) or (Direction shl ffsDirection) or
  5561. ((Options and ffmUseRegExpFind) shl ffsUseRegExpFind) or
  5562. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5563. {$else : not TEST_REGEXP}
  5564. FindFlags := ((Options and ffmOptions) shl ffsOptions) or (Direction shl ffsDirection) or
  5565. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5566. {$endif TEST_REGEXP}
  5567. FindFlags := FindFlags and not ffDoReplace;
  5568. if DoConf then
  5569. FindFlags := (FindFlags or ffPromptOnReplace);
  5570. SearchRunCount:=0;
  5571. if FindStr<>'' then
  5572. DoSearchReplace
  5573. else
  5574. EditorDialog(edSearchFailed,nil);
  5575. end;
  5576. FindReplaceEditor:=nil;
  5577. end;
  5578. end;
  5579. procedure TCustomCodeEditor.Replace;
  5580. var
  5581. ReplaceRec: TReplaceDialogRec;
  5582. Re: word;
  5583. begin
  5584. if IsReadOnly then Exit;
  5585. with ReplaceRec do
  5586. begin
  5587. Find := FindStr;
  5588. if GetCurrentWord<>'' then
  5589. Find:=GetCurrentWord;
  5590. Replace := ReplaceStr;
  5591. {$ifdef TEST_REGEXP}
  5592. Options := (FindFlags and ffmOptions) shr ffsOptions or
  5593. (FindFlags and ffUseRegExp) shr ffsUseRegExpReplace;
  5594. {$else not TEST_REGEXP}
  5595. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5596. {$endif TEST_REGEXP}
  5597. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5598. Scope := (FindFlags and ffmScope) shr ffsScope;
  5599. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5600. FindReplaceEditor:=@self;
  5601. Re:=EditorDialog(edReplace, @ReplaceRec);
  5602. FindReplaceEditor:=nil;
  5603. if Re <> cmCancel then
  5604. begin
  5605. FindStr := Find;
  5606. ReplaceStr := Replace;
  5607. FindFlags := (Options shl ffsOptions) or (Direction shl ffsDirection) or
  5608. {$ifdef TEST_REGEXP}
  5609. ((Options and ffmUseRegExpReplace) shl ffsUseRegExpReplace) or
  5610. {$endif TEST_REGEXP}
  5611. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5612. FindFlags := FindFlags or ffDoReplace;
  5613. if Re = cmYes then
  5614. FindFlags := FindFlags or ffReplaceAll;
  5615. SearchRunCount:=0;
  5616. if FindStr<>'' then
  5617. DoSearchReplace
  5618. else
  5619. EditorDialog(edSearchFailed,nil);
  5620. end;
  5621. end;
  5622. end;
  5623. procedure TCustomCodeEditor.DoSearchReplace;
  5624. var S: string;
  5625. DX,DY,P,Y,X: sw_integer;
  5626. Count: sw_integer;
  5627. Found,CanExit: boolean;
  5628. SForward,DoReplace,DoReplaceAll: boolean;
  5629. {$ifdef TEST_REGEXP}
  5630. UseRegExp : boolean;
  5631. RegExpEngine : TRegExprEngine;
  5632. RegExpFlags : tregexprflags;
  5633. regexpindex,regexplen : longint;
  5634. findstrpchar : pchar;
  5635. {$endif TEST_REGEXP}
  5636. LeftOK,RightOK: boolean;
  5637. FoundCount: sw_integer;
  5638. A,B: TPoint;
  5639. AreaStart,AreaEnd: TPoint;
  5640. CanReplace,Confirm: boolean;
  5641. Re: word;
  5642. IFindStr : string;
  5643. BT : BTable;
  5644. Overwriting : boolean;
  5645. function ContainsText(const SubS:string;var S: string; Start: Sw_integer): Sw_integer;
  5646. var
  5647. P: Sw_Integer;
  5648. begin
  5649. if Start<=0 then
  5650. P:=0
  5651. else
  5652. begin
  5653. if SForward then
  5654. begin
  5655. if Start>length(s) then
  5656. P:=0
  5657. else if FindFlags and ffCaseSensitive<>0 then
  5658. P:=BMFScan(S[Start],length(s)+1-Start,FindStr,Bt)+1
  5659. else
  5660. P:=BMFIScan(S[Start],length(s)+1-Start,IFindStr,Bt)+1;
  5661. if P>0 then
  5662. Inc(P,Start-1);
  5663. end
  5664. else
  5665. begin
  5666. if start>length(s) then
  5667. start:=length(s);
  5668. if FindFlags and ffCaseSensitive<>0 then
  5669. P:=BMBScan(S[1],Start,FindStr,Bt)+1
  5670. else
  5671. P:=BMBIScan(S[1],Start,IFindStr,Bt)+1;
  5672. end;
  5673. end;
  5674. ContainsText:=P;
  5675. end;
  5676. function InArea(X,Y: sw_integer): boolean;
  5677. begin
  5678. InArea:=((AreaStart.Y=Y) and (AreaStart.X<=X)) or
  5679. ((AreaStart.Y<Y) and (Y<AreaEnd.Y)) or
  5680. ((AreaEnd.Y=Y) and (X<=AreaEnd.X));
  5681. end;
  5682. var CurDY: sw_integer;
  5683. begin
  5684. if FindStr='' then
  5685. begin
  5686. Find;
  5687. { Find will call DoFindReplace at end again
  5688. so we need to exit directly now PM }
  5689. exit;
  5690. end;
  5691. Inc(SearchRunCount);
  5692. SForward:=(FindFlags and ffmDirection)=ffForward;
  5693. DoReplace:=(FindFlags and ffDoReplace)<>0;
  5694. Confirm:=(FindFlags and ffPromptOnReplace)<>0;
  5695. DoReplaceAll:=(FindFlags and ffReplaceAll)<>0;
  5696. {$ifdef TEST_REGEXP}
  5697. UseRegExp:=(FindFlags and ffUseRegExp)<>0;
  5698. if UseRegExp then
  5699. begin
  5700. if FindFlags and ffCaseSensitive<>0 then
  5701. RegExpFlags:=[ref_caseinsensitive]
  5702. else
  5703. RegExpFlags:=[];
  5704. getmem(findstrpchar,length(findstr)+1);
  5705. strpcopy(findstrpchar,findstr);
  5706. RegExpEngine:=GenerateRegExprEngine(findstrpchar,RegExpFlags);
  5707. strdispose(findstrpchar);
  5708. end;
  5709. {$endif TEST_REGEXP}
  5710. Count:=GetLineCount;
  5711. FoundCount:=0;
  5712. { Empty file ? }
  5713. if Count=0 then
  5714. begin
  5715. EditorDialog(edSearchFailed,nil);
  5716. exit;
  5717. end;
  5718. if SForward then
  5719. DY:=1
  5720. else
  5721. DY:=-1;
  5722. DX:=DY;
  5723. if FindStr<>'' then
  5724. PushInfo('Looking for "'+FindStr+'"');
  5725. if (FindFlags and ffmScope)=ffGlobal then
  5726. begin
  5727. AreaStart.X:=0;
  5728. AreaStart.Y:=0;
  5729. AreaEnd.X:=length(GetDisplayText(Count-1));
  5730. AreaEnd.Y:=Count-1;
  5731. end
  5732. else
  5733. begin
  5734. AreaStart:=SelStart;
  5735. AreaEnd:=SelEnd;
  5736. end;
  5737. { set a y value being inside the areal }
  5738. Y:=Min(CurPos.Y,Count-1);
  5739. if sForward then
  5740. X:=CurPos.X-1
  5741. else
  5742. { if you change this, pleas check that repeated backward searching for single chars still works
  5743. and that data is still found if searching starts outside the current line }
  5744. X:=Min(CurPos.X,length(GetDisplayText(Y)));
  5745. if SearchRunCount=1 then
  5746. if (FindFlags and ffmOrigin)=ffEntireScope then
  5747. if SForward then
  5748. begin
  5749. X:=AreaStart.X-1;
  5750. Y:=AreaStart.Y;
  5751. end
  5752. else
  5753. begin
  5754. X:=AreaEnd.X+1;
  5755. Y:=AreaEnd.Y;
  5756. end;
  5757. if FindFlags and ffCaseSensitive<>0 then
  5758. begin
  5759. if SForward then
  5760. BMFMakeTable(FindStr,bt)
  5761. else
  5762. BMBMakeTable(FindStr,bt);
  5763. end
  5764. else
  5765. begin
  5766. IFindStr:=upcase(FindStr);
  5767. if SForward then
  5768. BMFMakeTable(IFindStr,bt)
  5769. else
  5770. BMBMakeTable(IFindStr,bt);
  5771. end;
  5772. inc(X,DX);
  5773. CanExit:=false;
  5774. if not DoReplace or (not Confirm and (Owner<>nil)) then
  5775. Owner^.Lock;
  5776. if InArea(X,Y) then
  5777. repeat
  5778. CurDY:=DY;
  5779. S:=GetDisplayText(Y);
  5780. if X>length(S)-1 then
  5781. X:=length(S)-1;
  5782. {$ifdef TEST_REGEXP}
  5783. if UseRegExp then
  5784. begin
  5785. getmem(findstrpchar,length(Copy(S,X+1,high(S)))+1);
  5786. strpcopy(findstrpchar,Copy(S,X+1,high(S)));
  5787. { If start of line is required do check other positions PM }
  5788. if (FindStr[1]='^') and (X<>0) then
  5789. Found:=false
  5790. else
  5791. Found:=RegExprPos(RegExpEngine,findstrpchar,regexpindex,regexplen);
  5792. strdispose(findstrpchar);
  5793. P:=regexpindex+X+1;
  5794. end
  5795. else
  5796. {$endif TEST_REGEXP}
  5797. begin
  5798. P:=ContainsText(FindStr,S,X+1);
  5799. Found:=P<>0;
  5800. end;
  5801. if Found then
  5802. begin
  5803. A.X:=P-1;
  5804. A.Y:=Y;
  5805. B.Y:=Y;
  5806. {$ifdef TEST_REGEXP}
  5807. if UseRegExp then
  5808. B.X:=A.X+regexplen
  5809. else
  5810. {$endif TEST_REGEXP}
  5811. B.X:=A.X+length(FindStr);
  5812. end;
  5813. Found:=Found and InArea(A.X,A.Y);
  5814. if Found and ((FindFlags and ffWholeWordsOnly)<>0) then
  5815. begin
  5816. LeftOK:=(A.X<=0) or (not( (S[A.X] in AlphaChars+NumberChars) ));
  5817. RightOK:=(B.X>=length(S)) or (not( (S[B.X+1] in AlphaChars+NumberChars) ));
  5818. Found:=LeftOK and RightOK;
  5819. if not Found then
  5820. begin
  5821. CurDY:=0;
  5822. If SForward then
  5823. begin
  5824. X:=B.X+1;
  5825. if X>length(S) then
  5826. CurDY:=DY;
  5827. end
  5828. else
  5829. begin
  5830. X:=A.X-1;
  5831. if X<0 then
  5832. CurDY:=DY;
  5833. end;
  5834. end;
  5835. end;
  5836. if Found then
  5837. begin
  5838. Inc(FoundCount);
  5839. Lock;
  5840. if SForward then
  5841. SetCurPtr(B.X,B.Y)
  5842. else
  5843. SetCurPtr(A.X,A.Y);
  5844. TrackCursor(do_centre);
  5845. SetHighlight(A,B);
  5846. UnLock;
  5847. CurDY:=0;
  5848. if not DoReplace then
  5849. begin
  5850. CanExit:=true;
  5851. If SForward then
  5852. begin
  5853. X:=B.X;
  5854. Y:=B.Y;
  5855. end
  5856. else
  5857. begin
  5858. X:=A.X;
  5859. Y:=A.Y;
  5860. end;
  5861. end
  5862. else
  5863. begin
  5864. if not confirm then
  5865. CanReplace:=true
  5866. else
  5867. begin
  5868. Re:=EditorDialog(edReplacePrompt,@CurPos);
  5869. case Re of
  5870. cmYes :
  5871. CanReplace:=true;
  5872. cmNo :
  5873. CanReplace:=false;
  5874. else {cmCancel}
  5875. begin
  5876. CanReplace:=false;
  5877. CanExit:=true;
  5878. end;
  5879. end;
  5880. end;
  5881. if CanReplace then
  5882. begin
  5883. Lock;
  5884. { don't use SetInsertMode here because it changes the cursor shape }
  5885. overwriting:=(GetFlags and efInsertMode)=0;
  5886. SetFlags(GetFlags or efInsertMode);
  5887. SetSelection(A,B);
  5888. DelSelect;
  5889. InsertText(ReplaceStr);
  5890. if SForward then
  5891. begin
  5892. X:=CurPos.X;
  5893. Y:=CurPos.Y;
  5894. end
  5895. else
  5896. begin
  5897. X:=A.X;
  5898. Y:=A.Y;
  5899. end;
  5900. if overwriting then
  5901. SetFlags(GetFlags and (not efInsertMode));
  5902. UnLock;
  5903. end
  5904. else
  5905. begin
  5906. If SForward then
  5907. begin
  5908. X:=B.X;
  5909. Y:=B.Y;
  5910. end
  5911. else
  5912. begin
  5913. X:=A.X;
  5914. Y:=A.Y;
  5915. end;
  5916. end;
  5917. if (DoReplaceAll=false) then
  5918. CanExit:=true;
  5919. end;
  5920. end;
  5921. if (CanExit=false) and (CurDY<>0) then
  5922. begin
  5923. inc(Y,CurDY);
  5924. if SForward then
  5925. X:=0
  5926. else
  5927. X:=254;
  5928. CanExit:=((Y>=Count) and sForward) or (Y<0);
  5929. end;
  5930. if not CanExit then
  5931. CanExit:=(not InArea(X,Y)) and sForward;
  5932. until CanExit;
  5933. if (FoundCount=0) or (DoReplace) then
  5934. SetHighlight(CurPos,CurPos);
  5935. if (DoReplace=false) or ((Confirm=false) and (Owner<>nil)) then
  5936. Owner^.UnLock;
  5937. {if (DoReplace=false) or (Confirm=false) then
  5938. UnLock;}
  5939. if (FoundCount=0) then
  5940. EditorDialog(edSearchFailed,nil);
  5941. if FindStr<>'' then
  5942. PopInfo;
  5943. {$ifdef TEST_REGEXP}
  5944. if UseRegExp then
  5945. DestroyRegExprEngine(RegExpEngine);
  5946. {$endif TEST_REGEXP}
  5947. if (FindFlags and ffmScope)=ffSelectedText then
  5948. { restore selection PM }
  5949. begin
  5950. SetSelection(AreaStart,AreaEnd);
  5951. end;
  5952. end;
  5953. function TCustomCodeEditor.GetInsertMode: boolean;
  5954. begin
  5955. GetInsertMode:=(GetFlags and efInsertMode)<>0;
  5956. end;
  5957. procedure TCustomCodeEditor.SetInsertMode(InsertMode: boolean);
  5958. begin
  5959. if InsertMode then
  5960. SetFlags(GetFlags or efInsertMode)
  5961. else
  5962. SetFlags(GetFlags and (not efInsertMode));
  5963. DrawCursor;
  5964. end;
  5965. { there is a problem with ShiftDel here
  5966. because GetShitState tells to extend the
  5967. selection which gives wrong results (PM) }
  5968. function TCustomCodeEditor.ShouldExtend: boolean;
  5969. var ShiftInEvent: boolean;
  5970. begin
  5971. ShiftInEvent:=false;
  5972. if Assigned(CurEvent) then
  5973. if CurEvent^.What=evKeyDown then
  5974. ShiftInEvent:=((CurEvent^.KeyShift and kbShift)<>0);
  5975. ShouldExtend:=ShiftInEvent and
  5976. not DontConsiderShiftState;
  5977. end;
  5978. procedure TCustomCodeEditor.SetCurPtr(X,Y: sw_integer);
  5979. var OldPos{,OldSEnd,OldSStart}: TPoint;
  5980. Extended: boolean;
  5981. F: PFold;
  5982. begin
  5983. Lock;
  5984. X:=Max(0,Min(MaxLineLength+1,X));
  5985. Y:=Max(0,Min(GetLineCount-1,Y));
  5986. OldPos:=CurPos;
  5987. { OldSEnd:=SelEnd;
  5988. OldSStart:=SelStart;}
  5989. CurPos.X:=X;
  5990. CurPos.Y:=Y;
  5991. TrackCursor(do_not_centre);
  5992. if not IsLineVisible(CurPos.Y) then
  5993. begin
  5994. F:=GetLineFold(CurPos.Y);
  5995. if Assigned(F) then
  5996. F^.Collapse(false);
  5997. end;
  5998. if not NoSelect and ShouldExtend then
  5999. begin
  6000. CheckSels;
  6001. Extended:=false;
  6002. if PointOfs(OldPos)=PointOfs(SelStart) then
  6003. begin
  6004. SetSelection(CurPos,SelEnd);
  6005. Extended:=true;
  6006. end;
  6007. CheckSels;
  6008. if Extended=false then
  6009. if PointOfs(OldPos)=PointOfs(SelEnd) then
  6010. begin
  6011. if not ValidBlock then
  6012. SetSelection(CurPos,CurPos);
  6013. SetSelection(SelStart,CurPos); Extended:=true;
  6014. end;
  6015. CheckSels;
  6016. if not Extended then
  6017. if PointOfs(OldPos)<=PointOfs(CurPos) then
  6018. begin
  6019. SetSelection(OldPos,CurPos);
  6020. Extended:=true;
  6021. end
  6022. else
  6023. begin
  6024. SetSelection(CurPos,OldPos);
  6025. Extended:=true;
  6026. end;
  6027. DrawView;
  6028. end
  6029. else if not IsFlagSet(efPersistentBlocks) then
  6030. begin
  6031. HideSelect;
  6032. DrawView;
  6033. end;
  6034. { if PointOfs(SelStart)=PointOfs(SelEnd) then
  6035. SetSelection(CurPos,CurPos);}
  6036. if (GetFlags and (efHighlightColumn+efHighlightRow))<>0 then
  6037. DrawView;
  6038. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and
  6039. ((Highlight.A.X<>HighLight.B.X) or (Highlight.A.Y<>HighLight.B.Y)) then
  6040. HideHighlight;
  6041. if (OldPos.Y<>CurPos.Y) and (0<=OldPos.Y) and (OldPos.Y<GetLineCount) then
  6042. SetLineText(OldPos.Y,RTrim(GetLineText(OldPos.Y),not IsFlagSet(efUseTabCharacters)));
  6043. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (GetErrorMessage<>'') then
  6044. SetErrorMessage('');
  6045. { if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (HighlightRow<>-1) then
  6046. SetHighlightRow(-1);}
  6047. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6048. AddAction(eaMoveCursor,OldPos,CurPos,'',GetFlags);
  6049. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6050. PositionChanged;{UpdateIndicator;}
  6051. UnLock;
  6052. end;
  6053. procedure TCustomCodeEditor.CheckSels;
  6054. begin
  6055. if (SelStart.Y>SelEnd.Y) or
  6056. ( (SelStart.Y=SelEnd.Y) and (SelStart.X>SelEnd.X) ) then
  6057. SetSelection(SelEnd,SelStart);
  6058. end;
  6059. procedure TCustomCodeEditor.CodeCompleteApply;
  6060. var S: string;
  6061. FragLen,
  6062. I: integer;
  6063. begin
  6064. Lock;
  6065. { here should be some kind or "mark" or "break" inserted in the Undo
  6066. information, so activating it "undoes" only the completition first and
  6067. doesn't delete the complete word at once... - Gabor }
  6068. FragLen:=Length(GetCodeCompleteFrag);
  6069. S:=GetCodeCompleteWord;
  6070. for I:=FragLen+1 to length(S) do
  6071. AddChar(S[I]);
  6072. UnLock;
  6073. SetCompleteState(csInactive);
  6074. end;
  6075. procedure TCustomCodeEditor.CodeCompleteCancel;
  6076. begin
  6077. SetCompleteState(csDenied);
  6078. end;
  6079. procedure TCustomCodeEditor.CodeCompleteCheck;
  6080. var Line: string;
  6081. X: sw_integer;
  6082. CurWord,NewWord: string;
  6083. begin
  6084. SetCodeCompleteFrag('');
  6085. if (not IsFlagSet(efCodeComplete)) or (IsReadOnly=true) then Exit;
  6086. Lock;
  6087. Line:=GetDisplayText(CurPos.Y);
  6088. X:=CurPos.X; CurWord:='';
  6089. if X<=length(Line) then
  6090. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  6091. begin
  6092. CurWord:=Line[X]+CurWord;
  6093. Dec(X);
  6094. end;
  6095. if (length(CurWord)>=CodeCompleteMinLen) and CompleteCodeWord(CurWord,NewWord) then
  6096. begin
  6097. SetCodeCompleteFrag(CurWord);
  6098. SetCodeCompleteWord(NewWord);
  6099. end
  6100. else
  6101. ClearCodeCompleteWord;
  6102. UnLock;
  6103. end;
  6104. function TCustomCodeEditor.GetCodeCompleteFrag: string;
  6105. begin
  6106. { Abstract }
  6107. GetCodeCompleteFrag:='';
  6108. end;
  6109. procedure TCustomCodeEditor.SetCodeCompleteFrag(const S: string);
  6110. begin
  6111. { Abstract }
  6112. end;
  6113. procedure TCustomCodeEditor.DrawLines(FirstLine: sw_integer);
  6114. begin
  6115. if FirstLine>=(Delta.Y+Size.Y) then Exit; { falls outside of the screen }
  6116. DrawView;
  6117. end;
  6118. procedure TCustomCodeEditor.HideHighlight;
  6119. begin
  6120. SetHighlight(CurPos,CurPos);
  6121. end;
  6122. procedure TCustomCodeEditor.GetSelectionArea(var StartP,EndP: TPoint);
  6123. begin
  6124. StartP:=SelStart; EndP:=SelEnd;
  6125. if EndP.X=0 then
  6126. begin
  6127. Dec(EndP.Y);
  6128. EndP.X:=length(GetDisplayText(EndP.Y))-1;
  6129. end
  6130. else
  6131. Dec(EndP.X);
  6132. end;
  6133. function TCustomCodeEditor.ValidBlock: boolean;
  6134. begin
  6135. ValidBlock:=(SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y);
  6136. end;
  6137. procedure TCustomCodeEditor.SetSelection(A, B: TPoint);
  6138. var WV: boolean;
  6139. OS,OE: TPoint;
  6140. begin
  6141. WV:=ValidBlock;
  6142. OS:=SelStart; OE:=SelEnd;
  6143. SelStart:=A; SelEnd:=B;
  6144. if (WV=false) and (ValidBlock=false) then { do nothing } else
  6145. if (OS.X<>SelStart.X) or (OS.Y<>SelStart.Y) or
  6146. (OE.X<>SelEnd.X) or (OE.Y<>SelEnd.Y) then
  6147. SelectionChanged;
  6148. end;
  6149. procedure TCustomCodeEditor.SetHighlight(A, B: TPoint);
  6150. begin
  6151. Highlight.A:=A; Highlight.B:=B;
  6152. HighlightChanged;
  6153. end;
  6154. {procedure TCustomCodeEditor.SetHighlightRow(Row: sw_integer);
  6155. begin
  6156. HighlightRow:=Row;
  6157. DrawView;
  6158. end;}
  6159. {procedure TCodeEditor.SetDebuggerRow(Row: sw_integer);
  6160. begin
  6161. DebuggerRow:=Row;
  6162. DrawView;
  6163. end;}
  6164. procedure TCustomCodeEditor.SelectAll(Enable: boolean);
  6165. var A,B: TPoint;
  6166. begin
  6167. if (Enable=false) or (GetLineCount=0) then
  6168. begin A:=CurPos; B:=CurPos end
  6169. else
  6170. begin
  6171. A.X:=0; A.Y:=0;
  6172. { B.Y:=GetLineCount-1;
  6173. B.X:=length(GetLineText(B.Y));}
  6174. B.Y:=GetLineCount; B.X:=0;
  6175. end;
  6176. SetSelection(A,B);
  6177. DrawView;
  6178. end;
  6179. procedure TCustomCodeEditor.SelectionChanged;
  6180. var Enable,CanPaste: boolean;
  6181. begin
  6182. if GetLineCount=0 then
  6183. begin
  6184. SelStart.X:=0; SelStart.Y:=0; SelEnd:=SelStart;
  6185. end
  6186. else
  6187. if SelEnd.Y>GetLineCount-1 then
  6188. if (SelEnd.Y<>GetLineCount) or (SelEnd.X<>0) then
  6189. begin
  6190. SelEnd.Y:=GetLineCount-1;
  6191. SelEnd.X:=length(GetDisplayText(SelEnd.Y));
  6192. end;
  6193. { we change the CurCommandSet, but only if we are top view }
  6194. if ((State and sfFocused)<>0) then
  6195. begin
  6196. Enable:=((SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y)) and (Clipboard<>nil);
  6197. SetCmdState(ToClipCmds,Enable and (Clipboard<>@Self));
  6198. SetCmdState(NulClipCmds,Enable);
  6199. CanPaste:=(Clipboard<>nil) and ((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  6200. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  6201. SetCmdState(FromClipCmds,CanPaste and (Clipboard<>@Self));
  6202. SetCmdState(UndoCmd,(GetUndoActionCount>0));
  6203. SetCmdState(RedoCmd,(GetRedoActionCount>0));
  6204. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  6205. end;
  6206. DrawView;
  6207. end;
  6208. procedure TCustomCodeEditor.HighlightChanged;
  6209. begin
  6210. DrawView;
  6211. end;
  6212. procedure TCustomCodeEditor.SetState(AState: Word; Enable: Boolean);
  6213. procedure ShowSBar(SBar: PScrollBar);
  6214. begin
  6215. if Assigned(SBar) and (SBar^.GetState(sfVisible)=false) then
  6216. SBar^.Show;
  6217. end;
  6218. begin
  6219. inherited SetState(AState,Enable);
  6220. if AlwaysShowScrollBars then
  6221. begin
  6222. ShowSBar(HScrollBar);
  6223. ShowSBar(VScrollBar);
  6224. end;
  6225. if (AState and (sfActive+sfSelected+sfFocused))<>0 then
  6226. begin
  6227. SelectionChanged;
  6228. if ((State and sfFocused)=0) and (GetCompleteState=csOffering) then
  6229. ClearCodeCompleteWord;
  6230. end;
  6231. end;
  6232. function TCustomCodeEditor.GetPalette: PPalette;
  6233. const P: string[length(CEditor)] = CEditor;
  6234. begin
  6235. GetPalette:=@P;
  6236. end;
  6237. function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean;
  6238. var S: string;
  6239. AllLinesComplete,LineComplete,hasCR,OK: boolean;
  6240. begin
  6241. DeleteAllLines;
  6242. ChangedLine:=-1;
  6243. AllLinesComplete:=true;
  6244. OK:=(Stream^.Status=stOK);
  6245. if eofstream(Stream) then
  6246. AddLine('')
  6247. else
  6248. begin
  6249. while OK and (eofstream(Stream)=false) and (GetLineCount<MaxLineCount) do
  6250. begin
  6251. if not UseOldBufStreamMethod then
  6252. Stream^.Readline(S,LineComplete,hasCR)
  6253. else
  6254. ReadlnFromStream(Stream,S,LineComplete,hasCR);
  6255. AllLinesComplete:=AllLinesComplete and LineComplete;
  6256. OK:=OK and (Stream^.Status=stOK);
  6257. if OK then AddLine(S);
  6258. if not LineComplete and (ChangedLine=-1) then
  6259. ChangedLine:=GetLineCount;
  6260. end;
  6261. { Do not remove the final newline if it exists PM }
  6262. if hasCR then
  6263. AddLine('');
  6264. end;
  6265. LimitsChanged;
  6266. if not AllLinesComplete then
  6267. SetModified(true);
  6268. if (GetLineCount=MaxLineCount) and not eofstream(stream) then
  6269. EditorDialog(edTooManyLines,nil);
  6270. LoadFromStream:=OK;
  6271. end;
  6272. function TCustomCodeEditorCore.SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean;
  6273. var S: string;
  6274. OK: boolean;
  6275. Line: Sw_integer;
  6276. begin
  6277. if EndP.X=0 then
  6278. begin
  6279. if EndP.Y>0 then
  6280. begin
  6281. EndP.X:=length(GetDisplayText(EndP.Y));
  6282. end
  6283. else
  6284. EndP.X:=0;
  6285. end
  6286. else
  6287. Dec(EndP.X);
  6288. OK:=(Stream^.Status=stOK); Line:=StartP.Y;
  6289. while OK and (Line<=EndP.Y) and (Line<GetLineCount) do
  6290. begin
  6291. S:=GetLineText(Line);
  6292. { Remove all traling spaces PM }
  6293. if not Editor^.IsFlagSet(efKeepTrailingSpaces) then
  6294. s:=RTrim(S,False); // removes trailing #0 too
  6295. { if FlagSet(efUseTabCharacters) then
  6296. S:=CompressUsingTabs(S,TabSize);
  6297. }
  6298. if Line=EndP.Y then S:=copy(S,1,LinePosToCharIdx(Line,EndP.X));
  6299. if Line=StartP.Y then S:=copy(S,LinePosToCharIdx(Line,StartP.X),High(S));
  6300. Stream^.Write(S[1],length(S));
  6301. if Line<EndP.Y then
  6302. Stream^.Write(EOL[1],length(EOL));
  6303. Inc(Line);
  6304. OK:=OK and (Stream^.Status=stOK);
  6305. end;
  6306. SaveAreaToStream:=OK;
  6307. end;
  6308. constructor TEditorAction.init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint);
  6309. begin
  6310. Action:=act;
  6311. StartPos:=StartP;
  6312. EndPos:=EndP;
  6313. Text:=NewStr(txt);
  6314. ActionCount:=0;
  6315. Flags:=AFlags;
  6316. TimeStamp:=Now;
  6317. IsGrouped:=false;
  6318. end;
  6319. constructor TEditorAction.init_group(act:byte);
  6320. begin
  6321. Action:=act;
  6322. ActionCount:=0;
  6323. Flags:=0;
  6324. IsGrouped:=true;
  6325. end;
  6326. function TEditorAction.Is_grouped_action : boolean;
  6327. begin
  6328. Is_grouped_action:=IsGrouped;
  6329. end;
  6330. destructor TEditorAction.done;
  6331. begin
  6332. DisposeStr(Text);
  6333. inherited done;
  6334. end;
  6335. function TEditorActionCollection.At(Idx : sw_integer) : PEditorAction;
  6336. begin
  6337. At:=PEditorAction(Inherited At(Idx));
  6338. end;
  6339. procedure TEditorInputLine.HandleEvent(var Event : TEvent);
  6340. var
  6341. s,s2 : string;
  6342. i : longint;
  6343. begin
  6344. If (Event.What=evKeyDown) then
  6345. begin
  6346. if (Event.KeyCode=kbRight) and
  6347. (CurPos = Length(Data^)) and
  6348. Assigned(FindReplaceEditor) then
  6349. Begin
  6350. s:=FindReplaceEditor^.GetDisplayText(FindReplaceEditor^.CurPos.Y);
  6351. s:=Copy(s,FindReplaceEditor^.CurPos.X + 1 -length(Data^),high(s));
  6352. i:=pos(Data^,s);
  6353. if i>0 then
  6354. begin
  6355. s:=Data^+s[i+length(Data^)];
  6356. If not assigned(validator) or
  6357. Validator^.IsValidInput(s,False) then
  6358. Begin
  6359. Event.CharCode:=s[length(s)];
  6360. Event.Scancode:=0;
  6361. Inherited HandleEvent(Event);
  6362. End;
  6363. end;
  6364. ClearEvent(Event);
  6365. End
  6366. else if (Event.KeyCode=kbShiftIns) and
  6367. Assigned(Clipboard) and (Clipboard^.ValidBlock) then
  6368. { paste from clipboard }
  6369. begin
  6370. i:=Clipboard^.SelStart.Y;
  6371. s:=Clipboard^.GetDisplayText(i);
  6372. i:=Clipboard^.SelStart.X;
  6373. if i>0 then
  6374. s:=copy(s,i+1,high(s));
  6375. if (Clipboard^.SelStart.Y=Clipboard^.SelEnd.Y) then
  6376. begin
  6377. i:=Clipboard^.SelEnd.X-i;
  6378. s:=copy(s,1,i);
  6379. end;
  6380. for i:=1 to length(s) do
  6381. begin
  6382. s2:=Data^+s[i];
  6383. If not assigned(validator) or
  6384. Validator^.IsValidInput(s2,False) then
  6385. Begin
  6386. Event.What:=evKeyDown;
  6387. Event.CharCode:=s[i];
  6388. Event.Scancode:=0;
  6389. Inherited HandleEvent(Event);
  6390. End;
  6391. end;
  6392. ClearEvent(Event);
  6393. end
  6394. else if (Event.KeyCode=kbCtrlIns) and
  6395. Assigned(Clipboard) then
  6396. { Copy to clipboard }
  6397. begin
  6398. s:=GetStr(Data);
  6399. s:=copy(s,selstart+1,selend-selstart);
  6400. Clipboard^.SelStart:=Clipboard^.CurPos;
  6401. Clipboard^.InsertText(s);
  6402. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6403. ClearEvent(Event);
  6404. end
  6405. else if (Event.KeyCode=kbShiftDel) and
  6406. Assigned(Clipboard) then
  6407. { Cut to clipboard }
  6408. begin
  6409. s:=GetStr(Data);
  6410. s:=copy(s,selstart+1,selend-selstart);
  6411. Clipboard^.SelStart:=Clipboard^.CurPos;
  6412. Clipboard^.InsertText(s);
  6413. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6414. s2:=GetStr(Data);
  6415. { now remove the selected part }
  6416. Event.keyCode:=kbDel;
  6417. inherited HandleEvent(Event);
  6418. ClearEvent(Event);
  6419. end
  6420. else
  6421. Inherited HandleEvent(Event);
  6422. End
  6423. else
  6424. Inherited HandleEvent(Event);
  6425. s:=getstr(data);
  6426. Message(Owner,evBroadCast,cminputlinelen,pointer(length(s)));
  6427. end;
  6428. procedure TSearchHelperDialog.HandleEvent(var Event : TEvent);
  6429. begin
  6430. case Event.What of
  6431. evBroadcast :
  6432. case Event.Command of
  6433. cminputlinelen : begin
  6434. if PtrInt(Event.InfoPtr)=0 then
  6435. okbutton^.DisableCommands([cmok])
  6436. else
  6437. okbutton^.EnableCommands([cmok]);
  6438. clearevent(event);
  6439. end;
  6440. end;
  6441. end;
  6442. inherited HandleEvent(Event);
  6443. end;
  6444. function CreateFindDialog: PDialog;
  6445. var R,R1,R2: TRect;
  6446. D: PSearchHelperDialog;
  6447. IL1: PEditorInputLine;
  6448. Control : PView;
  6449. CB1: PCheckBoxes;
  6450. RB1,RB2,RB3: PRadioButtons;
  6451. but : PButton;
  6452. begin
  6453. R.Assign(0,0,56,15);
  6454. New(D, Init(R, dialog_find));
  6455. with D^ do
  6456. begin
  6457. Options:=Options or ofCentered;
  6458. GetExtent(R); R.Grow(-3,-2);
  6459. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6460. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6461. New(IL1, Init(R2, FindStrSize));
  6462. IL1^.Data^:=FindStr;
  6463. Insert(IL1);
  6464. Insert(New(PLabel, Init(R1, label_find_texttofind, IL1)));
  6465. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6466. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6467. Insert(Control);
  6468. 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;
  6469. R2.Copy(R1); R2.Move(0,1);
  6470. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}3{$else}2{$endif};
  6471. New(CB1, Init(R2,
  6472. NewSItem(label_find_casesensitive,
  6473. NewSItem(label_find_wholewordsonly,
  6474. {$ifdef TEST_REGEXP}
  6475. NewSItem(label_find_useregexp,
  6476. {$endif TEST_REGEXP}
  6477. nil)))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6478. Insert(CB1);
  6479. Insert(New(PLabel, Init(R1, label_find_options, CB1)));
  6480. 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;
  6481. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6482. New(RB1, Init(R2,
  6483. NewSItem(label_find_forward,
  6484. NewSItem(label_find_backward,
  6485. nil))));
  6486. Insert(RB1);
  6487. Insert(New(PLabel, Init(R1, label_find_direction, RB1)));
  6488. 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;
  6489. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6490. New(RB2, Init(R2,
  6491. NewSItem(label_find_global,
  6492. NewSItem(label_find_selectedtext,
  6493. nil))));
  6494. Insert(RB2);
  6495. Insert(New(PLabel, Init(R1, label_find_scope, RB2)));
  6496. 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;
  6497. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6498. New(RB3, Init(R2,
  6499. NewSItem(label_find_fromcursor,
  6500. NewSItem(label_find_entirescope,
  6501. nil))));
  6502. Insert(RB3);
  6503. Insert(New(PLabel, Init(R1, label_find_origin, RB3)));
  6504. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6505. Okbutton:=New(PButton, Init(R, btn_OK, cmOK, bfDefault));
  6506. Insert(OkButton);
  6507. R.Move(19,0);
  6508. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6509. end;
  6510. IL1^.Select;
  6511. CreateFindDialog := D;
  6512. end;
  6513. function CreateReplaceDialog: PDialog;
  6514. var R,R1,R2: TRect;
  6515. D: PDialog;
  6516. Control : PView;
  6517. IL1: PEditorInputLine;
  6518. IL2: PEditorInputLine;
  6519. CB1: PCheckBoxes;
  6520. RB1,RB2,RB3: PRadioButtons;
  6521. begin
  6522. R.Assign(0,0,56,18);
  6523. New(D, Init(R, dialog_replace));
  6524. with D^ do
  6525. begin
  6526. Options:=Options or ofCentered;
  6527. GetExtent(R); R.Grow(-3,-2);
  6528. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6529. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6530. New(IL1, Init(R2, FindStrSize));
  6531. IL1^.Data^:=FindStr;
  6532. Insert(IL1);
  6533. Insert(New(PLabel, Init(R1, label_replace_texttofind, IL1)));
  6534. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6535. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6536. Insert(Control);
  6537. R1.Copy(R); R1.Move(0,2); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6538. R2.Copy(R); R2.Move(0,2);R2.B.X:=R2.B.X-3;
  6539. R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6540. New(IL2, Init(R2, FindStrSize));
  6541. IL2^.Data^:=ReplaceStr;
  6542. Insert(IL2);
  6543. Insert(New(PLabel, Init(R1, label_replace_newtext, IL2)));
  6544. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6545. Control := New(PHistory, Init(R1, IL2, TextReplaceId));
  6546. Insert(Control);
  6547. 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;
  6548. R2.Copy(R1); R2.Move(0,1);
  6549. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}4{$else}3{$endif};
  6550. New(CB1, Init(R2,
  6551. NewSItem(label_replace_casesensitive,
  6552. NewSItem(label_replace_wholewordsonly,
  6553. NewSItem(label_replace_promptonreplace,
  6554. {$ifdef TEST_REGEXP}
  6555. NewSItem(label_find_useregexp,
  6556. {$endif TEST_REGEXP}
  6557. nil))))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6558. Insert(CB1);
  6559. Insert(New(PLabel, Init(R1, label_replace_options, CB1)));
  6560. 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;
  6561. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6562. New(RB1, Init(R2,
  6563. NewSItem(label_replace_forward,
  6564. NewSItem(label_replace_backward,
  6565. nil))));
  6566. Insert(RB1);
  6567. Insert(New(PLabel, Init(R1, label_replace_direction, RB1)));
  6568. 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;
  6569. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6570. New(RB2, Init(R2,
  6571. NewSItem(label_replace_global,
  6572. NewSItem(label_replace_selectedtext,
  6573. nil))));
  6574. Insert(RB2);
  6575. Insert(New(PLabel, Init(R1, label_replace_scope, RB2)));
  6576. 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;
  6577. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6578. New(RB3, Init(R2,
  6579. NewSItem(label_replace_fromcursor,
  6580. NewSItem(label_replace_entirescope,
  6581. nil))));
  6582. Insert(RB3);
  6583. Insert(New(PLabel, Init(R1, label_replace_origin, RB3)));
  6584. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10; R.Move(-10,0);
  6585. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6586. R.Move(11,0); R.B.X:=R.A.X+14;
  6587. Insert(New(PButton, Init(R, btn_replace_changeall, cmYes, bfNormal)));
  6588. R.Move(15,0); R.B.X:=R.A.X+10;
  6589. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6590. end;
  6591. IL1^.Select;
  6592. CreateReplaceDialog := D;
  6593. end;
  6594. function CreateGotoLineDialog(Info: pointer): PDialog;
  6595. var D: PDialog;
  6596. R,R1,R2: TRect;
  6597. Control : PView;
  6598. IL: PEditorInputLine;
  6599. begin
  6600. R.Assign(0,0,40,7);
  6601. New(D, Init(R, dialog_gotoline));
  6602. with D^ do
  6603. begin
  6604. Options:=Options or ofCentered;
  6605. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  6606. R1.Copy(R); R1.B.X:=27; R2.Copy(R);
  6607. R2.B.X:=R2.B.X-3;R2.A.X:=27;
  6608. New(IL, Init(R2,5));
  6609. with TGotoLineDialogRec(Info^) do
  6610. IL^.SetValidator(New(PRangeValidator, Init(1, Lines)));
  6611. Insert(IL);
  6612. Insert(New(PLabel, Init(R1, label_gotoline_linenumber, IL)));
  6613. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6614. Control := New(PHistory, Init(R1, IL, GotoId));
  6615. Insert(Control);
  6616. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6617. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6618. R.Move(15,0);
  6619. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6620. end;
  6621. IL^.Select;
  6622. CreateGotoLineDialog:=D;
  6623. end;
  6624. function StdEditorDialog(Dialog: Integer; Info: Pointer): Word;
  6625. var
  6626. R: TRect;
  6627. T: TPoint;
  6628. Re: word;
  6629. Name: string;
  6630. DriveNumber : byte;
  6631. StoreDir,StoreDir2 : DirStr;
  6632. Title,DefExt: string;
  6633. AskOW: boolean;
  6634. begin
  6635. case Dialog of
  6636. edOutOfMemory:
  6637. StdEditorDialog := AdvMessageBox(msg_notenoughmemoryforthisoperation,
  6638. nil, mfInsertInApp+ mfError + mfOkButton);
  6639. edReadError:
  6640. StdEditorDialog := AdvMessageBox(msg_errorreadingfile,
  6641. @Info, mfInsertInApp+ mfError + mfOkButton);
  6642. edWriteError:
  6643. StdEditorDialog := AdvMessageBox(msg_errorwritingfile,
  6644. @Info, mfInsertInApp+ mfError + mfOkButton);
  6645. edSaveError:
  6646. StdEditorDialog := AdvMessageBox(msg_errorsavingfile,
  6647. @Info, mfInsertInApp+ mfError + mfOkButton);
  6648. edCreateError:
  6649. StdEditorDialog := AdvMessageBox(msg_errorcreatingfile,
  6650. @Info, mfInsertInApp+ mfError + mfOkButton);
  6651. edSaveModify:
  6652. StdEditorDialog := AdvMessageBox(msg_filehasbeenmodifiedsave,
  6653. @Info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6654. edSaveUntitled:
  6655. StdEditorDialog := AdvMessageBox(msg_saveuntitledfile,
  6656. nil, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6657. edChangedOnloading:
  6658. StdEditorDialog := AdvMessageBox(msg_filehadtoolonglines,
  6659. Info, mfInsertInApp+ mfOKButton + mfInformation);
  6660. edFileOnDiskChanged:
  6661. StdEditorDialog := AdvMessageBox(msg_filewasmodified,
  6662. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6663. edReloadDiskmodifiedFile:
  6664. StdEditorDialog := AdvMessageBox(msg_reloaddiskmodifiedfile,
  6665. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6666. edReloadDiskAndIDEModifiedFile:
  6667. StdEditorDialog := AdvMessageBox(msg_reloaddiskandidemodifiedfile,
  6668. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6669. edSaveAs,edWriteBlock,edReadBlock:
  6670. begin
  6671. Name:=PString(Info)^;
  6672. GetDir(0,StoreDir);
  6673. DriveNumber:=0;
  6674. if (Length(FileDir)>1) and (FileDir[2]=':') then
  6675. begin
  6676. { does not assume that lowercase are greater then uppercase ! }
  6677. if (FileDir[1]>='a') and (FileDir[1]<='z') then
  6678. DriveNumber:=Ord(FileDir[1])-ord('a')+1
  6679. else
  6680. DriveNumber:=Ord(FileDir[1])-ord('A')+1;
  6681. GetDir(DriveNumber,StoreDir2);
  6682. {$I-}
  6683. ChDir(Copy(FileDir,1,2));
  6684. EatIO;
  6685. {$I+}
  6686. end;
  6687. if FileDir<>'' then
  6688. begin
  6689. {$I-}
  6690. ChDir(TrimEndSlash(FileDir));
  6691. EatIO;
  6692. {$I+}
  6693. end;
  6694. case Dialog of
  6695. edSaveAs :
  6696. begin
  6697. Title:=dialog_savefileas;
  6698. DefExt:='*'+DefaultSaveExt;
  6699. end;
  6700. edWriteBlock :
  6701. begin
  6702. Title:=dialog_writeblocktofile;
  6703. DefExt:='*.*';
  6704. end;
  6705. edReadBlock :
  6706. begin
  6707. Title:=dialog_readblockfromfile;
  6708. DefExt:='*.*';
  6709. end;
  6710. else begin Title:='???'; DefExt:=''; end;
  6711. end;
  6712. Re:=Application^.ExecuteDialog(New(PFileDialog, Init(DefExt,
  6713. Title, label_name, fdOkButton, FileId)), @Name);
  6714. case Dialog of
  6715. edSaveAs :
  6716. begin
  6717. if ExtOf(Name)='' then
  6718. Name:=Name+DefaultSaveExt;
  6719. AskOW:=(Name<>PString(Info)^);
  6720. end;
  6721. edWriteBlock :
  6722. begin
  6723. if ExtOf(Name)='' then
  6724. Name:=Name+DefaultSaveExt;
  6725. AskOW:=true;
  6726. end;
  6727. edReadBlock : AskOW:=false;
  6728. else AskOW:=true;
  6729. end;
  6730. if (Re<>cmCancel) and AskOW then
  6731. begin
  6732. FileDir:=DirOf(FExpand(Name));
  6733. if ExistsFile(Name) then
  6734. if EditorDialog(edReplaceFile,@Name)<>cmYes then
  6735. Re:=cmCancel;
  6736. end;
  6737. if DriveNumber<>0 then
  6738. ChDir(StoreDir2);
  6739. if StoreDir<>'' then
  6740. ChDir(TrimEndSlash(StoreDir));
  6741. if Re<>cmCancel then
  6742. PString(Info)^:=Name;
  6743. StdEditorDialog := Re;
  6744. end;
  6745. edGotoLine:
  6746. StdEditorDialog :=
  6747. Application^.ExecuteDialog(CreateGotoLineDialog(Info), Info);
  6748. edFind:
  6749. StdEditorDialog :=
  6750. Application^.ExecuteDialog(CreateFindDialog, Info);
  6751. edSearchFailed:
  6752. StdEditorDialog := AdvMessageBox(msg_searchstringnotfound,
  6753. nil, mfInsertInApp+ mfError + mfOkButton);
  6754. edReplace:
  6755. StdEditorDialog :=
  6756. Application^.ExecuteDialog(CreateReplaceDialog, Info);
  6757. edReplacePrompt:
  6758. begin
  6759. { Avoid placing the dialog on the same line as the cursor }
  6760. R.Assign(0, 1, 40, 8);
  6761. R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  6762. Desktop^.MakeGlobal(R.B, T);
  6763. Inc(T.Y);
  6764. if PPoint(Info)^.Y <= T.Y then
  6765. R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  6766. StdEditorDialog := AdvMessageBoxRect(R, msg_replacethisoccourence,
  6767. nil, mfInsertInApp+ mfYesNoCancel + mfInformation);
  6768. end;
  6769. edReplaceFile :
  6770. StdEditorDialog :=
  6771. AdvMessageBox(msg_fileexistsoverwrite,@Info,mfInsertInApp+mfConfirmation+
  6772. mfYesButton+mfNoButton);
  6773. end;
  6774. end;
  6775. procedure RegisterWEditor;
  6776. begin
  6777. {$ifndef NOOBJREG}
  6778. {$endif}
  6779. end;
  6780. END.