weditor.pas 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319
  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. s2[0]:=chr(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. s2[0]:=chr(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. begin
  4401. NotImplemented; Exit;
  4402. end;
  4403. procedure TCustomCodeEditor.BackSpace;
  4404. var S,PreS: string;
  4405. OI,CI,CP,Y,TX: Sw_integer;
  4406. SCP,SC1 : TPoint;
  4407. HoldUndo : Boolean;
  4408. begin
  4409. if IsReadOnly then Exit;
  4410. Lock;
  4411. SCP:=CurPos;
  4412. HoldUndo:=GetStoreUndo;
  4413. SetStoreUndo(false);
  4414. if CurPos.X=0 then
  4415. begin
  4416. if CurPos.Y>0 then
  4417. begin
  4418. CI:=Length(GetDisplayText(CurPos.Y-1));
  4419. S:=GetLineText(CurPos.Y-1);
  4420. SetLineText(CurPos.Y-1,S+GetLineText(CurPos.Y));
  4421. SC1.X:=Length(S);SC1.Y:=CurPOS.Y-1;
  4422. SetStoreUndo(HoldUndo);
  4423. AddAction(eaDeleteLine,SCP,SC1,GetLineText(CurPos.Y),GetFlags);
  4424. SetStoreUndo(false);
  4425. DeleteLine(CurPos.Y);
  4426. LimitsChanged;
  4427. SetCurPtr(CI,CurPos.Y-1);
  4428. AdjustSelectionPos(Ci,CurPos.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4429. end;
  4430. end
  4431. else
  4432. begin
  4433. CP:=CurPos.X-1;
  4434. S:=GetLineText(CurPos.Y);
  4435. CI:=LinePosToCharIdx(CurPos.Y,CP);
  4436. if (s[ci]=TAB) and (CharIdxToLinePos(Curpos.y,ci)=cp) then
  4437. CP:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  4438. if IsFlagSet(efBackspaceUnindents) then
  4439. begin
  4440. S:=GetDisplayText(CurPos.Y);
  4441. if Trim(copy(S,1,CP+1))='' then
  4442. begin
  4443. Y:=CurPos.Y;
  4444. while (Y>0) do
  4445. begin
  4446. Dec(Y);
  4447. PreS:=GetDisplayText(Y);
  4448. if Trim(copy(PreS,1,CP+1))<>'' then Break;
  4449. end;
  4450. if Y<0 then PreS:='';
  4451. TX:=0;
  4452. while (TX<length(PreS)) and (PreS[TX+1]=' ') do
  4453. Inc(TX);
  4454. if TX<CP then CP:=TX;
  4455. end;
  4456. end;
  4457. S:=GetLineText(CurPos.Y);
  4458. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4459. CI:=LinePosToCharIdx(CurPos.Y,CP);
  4460. SetLineText(CurPos.Y,copy(S,1,CI-1)+copy(S,OI,High(S)));
  4461. SetCurPtr(CP,CurPos.Y);
  4462. SetStoreUndo(HoldUndo);
  4463. Addaction(eaDeleteText,SCP,CurPos,Copy(S,CI,OI-CI),GetFlags);
  4464. SetStoreUndo(false);
  4465. AdjustSelectionPos(SCP.X-1,SCP.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y);
  4466. end;
  4467. UpdateAttrs(CurPos.Y,attrAll);
  4468. DrawLines(CurPos.Y);
  4469. SetStoreUndo(HoldUndo);
  4470. SetModified(true);
  4471. Unlock;
  4472. end;
  4473. procedure TCustomCodeEditor.DelChar;
  4474. var S: string;
  4475. SDX,SDY,CI : sw_integer;
  4476. HoldUndo : boolean;
  4477. SCP : TPoint;
  4478. begin
  4479. if IsReadOnly then Exit;
  4480. Lock;
  4481. HoldUndo:=GetStoreUndo;
  4482. SetStoreUndo(false);
  4483. S:=GetLineText(CurPos.Y);
  4484. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4485. if (CI>length(S)) or (S='') then
  4486. begin
  4487. if CurPos.Y<GetLineCount-1 then
  4488. begin
  4489. SetLineText(CurPos.Y,S+CharStr(' ',CurPOS.X-Length(S))+GetLineText(CurPos.Y+1));
  4490. SDX:=CurPos.X;
  4491. SetStoreUndo(HoldUndo);
  4492. SCP.X:=0;SCP.Y:=CurPos.Y+1;
  4493. AddGroupedAction(eaDelChar);
  4494. AddAction(eaMoveCursor,CurPos,SCP,'',GetFlags);
  4495. S:=GetLineText(CurPos.Y+1);
  4496. AddAction(eaDeleteLine,SCP,CurPos,S,GetFlags);
  4497. CloseGroupedAction(eaDelChar);
  4498. SetStoreUndo(false);
  4499. DeleteLine(CurPos.Y+1);
  4500. LimitsChanged;
  4501. SDY:=-1;
  4502. SetCurPtr(CurPos.X,CurPos.Y);
  4503. UpdateAttrs(CurPos.Y,attrAll);
  4504. AdjustSelectionPos(CurPos.X,CurPos.Y,SDX,SDY);
  4505. end;
  4506. end
  4507. else
  4508. begin
  4509. SCP:=CurPos;
  4510. { Problem if S[CurPos.X+1]=TAB !! PM }
  4511. if S[CI]=TAB then
  4512. begin
  4513. { we want to remove the tab if we are at the first place
  4514. of the tab, but the following test was true for the last position
  4515. in tab
  4516. if CharIdxToLinePos(Curpos.y,ci)=Curpos.x then }
  4517. if CharIdxToLinePos(Curpos.y,ci-1)=Curpos.x-1 then
  4518. Delete(S,Ci,1)
  4519. else
  4520. S:=Copy(S,1,CI-1)+CharStr(' ',GetTabSize-1)+Copy(S,CI+1,High(S));
  4521. SetStoreUndo(HoldUndo);
  4522. Addaction(eaDeleteText,CurPos,CurPos,#9,GetFlags);
  4523. SDX:=-1;
  4524. SetStoreUndo(false);
  4525. end
  4526. else
  4527. begin
  4528. SetStoreUndo(HoldUndo);
  4529. Addaction(eaDeleteText,CurPos,CurPos,S[CI],GetFlags);
  4530. SetStoreUndo(false);
  4531. SDX:=-1;
  4532. Delete(S,CI,1);
  4533. end;
  4534. SetLineText(CurPos.Y,S);
  4535. SDY:=0;
  4536. SetCurPtr(CurPos.X,CurPos.Y);
  4537. UpdateAttrs(CurPos.Y,attrAll);
  4538. AdjustSelectionPos(SCP.X,SCP.Y,SDX,SDY);
  4539. end;
  4540. DrawLines(CurPos.Y);
  4541. SetStoreUndo(HoldUndo);
  4542. SetModified(true);
  4543. Unlock;
  4544. end;
  4545. procedure TCustomCodeEditor.DelWord;
  4546. var
  4547. SP,EP : TPoint;
  4548. SelSize : sw_integer;
  4549. begin
  4550. if IsReadOnly then Exit;
  4551. Lock;
  4552. SP:=SelStart;
  4553. EP:=SelEnd;
  4554. SetSelection(SelStart,SelStart);
  4555. SelectWord;
  4556. SelSize:=SelEnd.X-SelStart.X;
  4557. DelSelect;
  4558. SetSelection(SP,EP);
  4559. AdjustSelectionPos(CurPos.X,CurPos.Y,-SelSize,0);
  4560. if SelSize>0 then
  4561. SetModified(true);
  4562. Unlock;
  4563. end;
  4564. procedure TCustomCodeEditor.DelToEndOfWord;
  4565. var
  4566. SP,EP : TPoint;
  4567. S : String;
  4568. SelSize : sw_integer;
  4569. begin
  4570. if IsReadOnly then Exit;
  4571. Lock;
  4572. SP:=SelStart;
  4573. EP:=SelEnd;
  4574. SetSelection(SelStart,SelStart);
  4575. SelectWord;
  4576. S:=GetDisplayText(CurPos.Y);
  4577. if ((SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y)) then
  4578. begin
  4579. if (Length(S) <= CurPos.X) then
  4580. begin
  4581. SetSelection(SP,EP);
  4582. DelChar;
  4583. Unlock;
  4584. exit;
  4585. end
  4586. else
  4587. begin
  4588. SelEnd.X:=CurPos.X+1;
  4589. SelEnd.Y:=CurPos.Y;
  4590. end;
  4591. end;
  4592. while (length(S)>= SelEnd.X+1) and
  4593. ((S[SelEnd.X+1]=' ') or (S[SelEnd.X+1]=TAB)) do
  4594. inc(SelEnd.X);
  4595. SetSelection(CurPos,SelEnd);
  4596. SelSize:=SelEnd.X-SelStart.X;
  4597. DelSelect;
  4598. SetSelection(SP,EP);
  4599. AdjustSelectionPos(CurPos.X,CurPos.Y,-SelSize,0);
  4600. if SelSize>0 then
  4601. SetModified(true);
  4602. Unlock;
  4603. end;
  4604. procedure TCustomCodeEditor.DelStart;
  4605. var S: string;
  4606. OI: Sw_integer;
  4607. HoldUndo : Boolean;
  4608. SCP : TPoint;
  4609. begin
  4610. if IsReadOnly then Exit;
  4611. Lock;
  4612. HoldUndo:=GetStoreUndo;
  4613. SetStoreUndo(false);
  4614. SCP:=CurPos;
  4615. S:=GetLineText(CurPos.Y);
  4616. if (S<>'') and (CurPos.X<>0) then
  4617. begin
  4618. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4619. SetLineText(CurPos.Y,copy(S,OI,High(S)));
  4620. SetCurPtr(0,CurPos.Y);
  4621. SetStoreUndo(HoldUndo);
  4622. Addaction(eaDeleteText,SCP,CurPos,copy(S,1,OI-1),GetFlags);
  4623. SetStoreUndo(false);
  4624. AdjustSelectionPos(CurPos.X,CurPos.Y,-length(copy(S,1,OI-1)),0);
  4625. UpdateAttrs(CurPos.Y,attrAll);
  4626. DrawLines(CurPos.Y);
  4627. SetModified(true);
  4628. end;
  4629. SetStoreUndo(HoldUndo);
  4630. Unlock;
  4631. end;
  4632. procedure TCustomCodeEditor.DelEnd;
  4633. var S: string;
  4634. OI: Sw_integer;
  4635. HoldUndo : Boolean;
  4636. SCP : TPoint;
  4637. begin
  4638. if IsReadOnly then Exit;
  4639. Lock;
  4640. HoldUndo:=GetStoreUndo;
  4641. SetStoreUndo(false);
  4642. SCP:=CurPos;
  4643. S:=GetLineText(CurPos.Y);
  4644. if (S<>'') and (CurPos.X<>length(S)) then
  4645. begin
  4646. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4647. SetLineText(CurPos.Y,copy(S,1,OI-1));
  4648. SetCurPtr(CurPos.X,CurPos.Y);
  4649. SetStoreUndo(HoldUndo);
  4650. Addaction(eaDeleteText,SCP,CurPos,copy(S,OI,High(S)),GetFlags);
  4651. SetStoreUndo(false);
  4652. AdjustSelectionPos(CurPos.X+1,CurPos.Y,-length(copy(S,OI,High(S)))+1,0);
  4653. UpdateAttrs(CurPos.Y,attrAll);
  4654. DrawLines(CurPos.Y);
  4655. SetModified(true);
  4656. end;
  4657. SetStoreUndo(HoldUndo);
  4658. Unlock;
  4659. end;
  4660. procedure TCustomCodeEditor.DelLine;
  4661. var
  4662. HoldUndo : boolean;
  4663. SP : TPoint;
  4664. S : String;
  4665. begin
  4666. if IsReadOnly then Exit;
  4667. Lock;
  4668. if GetLineCount>0 then
  4669. begin
  4670. SP:=CurPos;
  4671. S:=GetLineText(CurPos.Y);
  4672. HoldUndo:=GetStoreUndo;
  4673. SetStoreUndo(false);
  4674. DeleteLine(CurPos.Y);
  4675. LimitsChanged;
  4676. AdjustSelectionBefore(0,-1);
  4677. SetCurPtr(0,CurPos.Y);
  4678. UpdateAttrs(Max(0,CurPos.Y-1),attrAll);
  4679. DrawLines(CurPos.Y);
  4680. SetStoreUndo(HoldUndo);
  4681. AddAction(eaDeleteLine,SP,CurPos,S,GetFlags);
  4682. SetModified(true);
  4683. end;
  4684. Unlock;
  4685. end;
  4686. procedure TCustomCodeEditor.InsMode;
  4687. begin
  4688. SetInsertMode(Overwrite);
  4689. end;
  4690. function TCustomCodeEditor.GetCurrentWordArea(var StartP,EndP: TPoint): boolean;
  4691. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  4692. var P : TPoint;
  4693. S : String;
  4694. StartPos,EndPos : byte;
  4695. OK: boolean;
  4696. begin
  4697. P:=CurPos;
  4698. S:=GetLineText(P.Y);
  4699. StartPos:=P.X+1;
  4700. EndPos:=StartPos;
  4701. OK:=(S[StartPos] in WordChars);
  4702. if OK then
  4703. begin
  4704. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  4705. Dec(StartPos);
  4706. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  4707. Inc(EndPos);
  4708. StartP.X:=StartPos-1; StartP.Y:=CurPos.Y;
  4709. EndP.X:=EndPos-1; EndP.Y:=CurPos.Y;
  4710. end;
  4711. GetCurrentWordArea:=OK;
  4712. end;
  4713. function TCustomCodeEditor.GetCurrentWord : string;
  4714. var S: string;
  4715. StartP,EndP: TPoint;
  4716. begin
  4717. if GetCurrentWordArea(StartP,EndP)=false then
  4718. S:=''
  4719. else
  4720. begin
  4721. S:=GetLineText(StartP.Y);
  4722. S:=copy(S,StartP.X+1,EndP.X-StartP.X+1);
  4723. end;
  4724. GetCurrentWord:=S;
  4725. end;
  4726. procedure TCustomCodeEditor.StartSelect;
  4727. var P1,P2: TPoint;
  4728. begin
  4729. if ValidBlock=false then
  4730. begin
  4731. { SetSelection(SelStart,Limit);}
  4732. P1:=CurPos; P1.X:=0; P2:=CurPos; {P2.X:=length(GetLineText(P2.Y))+1;}
  4733. SetSelection(P1,P2);
  4734. end
  4735. else
  4736. SetSelection(CurPos,SelEnd);
  4737. if PointOfs(SelEnd)<PointOfs(SelStart) then
  4738. SetSelection(SelStart,SelStart);
  4739. CheckSels;
  4740. DrawView;
  4741. end;
  4742. procedure TCustomCodeEditor.EndSelect;
  4743. var P: TPoint;
  4744. LS: sw_integer;
  4745. begin
  4746. P:=CurPos;
  4747. { P.X:=Min(SelEnd.X,length(GetLineText(SelEnd.Y)));}
  4748. LS:=length(GetLineText(SelEnd.Y));
  4749. if LS<P.X then P.X:=LS;
  4750. CheckSels;
  4751. SetSelection(SelStart,P);
  4752. DrawView;
  4753. end;
  4754. procedure TCustomCodeEditor.DelSelect;
  4755. var LineDelta, LineCount, CurLine: Sw_integer;
  4756. StartX,EndX,LastX: Sw_integer;
  4757. S: string;
  4758. SPos : TPoint;
  4759. begin
  4760. if IsReadOnly or (ValidBlock=false) then Exit;
  4761. Lock;
  4762. AddGroupedAction(eaDelBlock);
  4763. LineCount:=(SelEnd.Y-SelStart.Y)+1;
  4764. LineDelta:=0; LastX:=CurPos.X;
  4765. CurLine:=SelStart.Y;
  4766. { single line : easy }
  4767. if LineCount=1 then
  4768. begin
  4769. S:=GetDisplayText(CurLine);
  4770. StartX:=SelStart.X;
  4771. EndX:=SelEnd.X;
  4772. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4773. +copy(S,EndX+1,High(S)));
  4774. if GetStoreUndo then
  4775. begin
  4776. SPos.X:=StartX;
  4777. SPos.Y:=CurLine;
  4778. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,EndX-StartX),GetFlags);
  4779. end;
  4780. Inc(CurLine);
  4781. LastX:=SelStart.X;
  4782. end
  4783. { several lines : a bit less easy }
  4784. else
  4785. begin
  4786. S:=GetDisplayText(CurLine);
  4787. StartX:=SelStart.X;
  4788. EndX:=SelEnd.X;
  4789. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4790. +copy(GetDisplayText(CurLine+LineCount-1),EndX+1,High(S)));
  4791. if GetStoreUndo then
  4792. begin
  4793. SPos.X:=StartX;
  4794. SPos.Y:=CurLine;
  4795. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,High(S)),GetFlags);
  4796. S:=GetDisplayText(CurLine+LineCount-1);
  4797. end;
  4798. Inc(CurLine);
  4799. Inc(LineDelta);
  4800. LastX:=SelStart.X;
  4801. while (LineDelta<LineCount) do
  4802. begin
  4803. { delete the complete line }
  4804. DeleteLine(CurLine);
  4805. Inc(LineDelta);
  4806. end;
  4807. if GetStoreUndo then
  4808. begin
  4809. AddAction(eaInsertText,SPos,SPos,Copy(S,EndX+1,High(S)),GetFlags);
  4810. end;
  4811. end;
  4812. HideSelect;
  4813. SetCurPtr(LastX,CurLine-1);
  4814. UpdateAttrs(CurPos.Y,attrAll);
  4815. DrawLines(CurPos.Y);
  4816. SetModified(true);
  4817. CloseGroupedAction(eaDelBlock);
  4818. UnLock;
  4819. end;
  4820. procedure TCustomCodeEditor.HideSelect;
  4821. begin
  4822. SetSelection(CurPos,CurPos);
  4823. DrawLines(Delta.Y);
  4824. end;
  4825. procedure TCustomCodeEditor.CopyBlock;
  4826. var Temp: PCodeEditor;
  4827. R: TRect;
  4828. begin
  4829. if IsReadOnly or (ValidBlock=false) then Exit;
  4830. Lock;
  4831. GetExtent(R);
  4832. AddGroupedAction(eaCopyBlock);
  4833. New(Temp, Init(R, nil, nil, nil,nil));
  4834. Temp^.InsertFrom(@Self);
  4835. (* Temp^.SelectAll(true);
  4836. { this selects one line too much because
  4837. we have a empty line at creation to avoid
  4838. negative line problems so we need to decrease SelEnd.Y }
  4839. Dec(Temp^.SelEnd.Y);*)
  4840. InsertFrom(Temp);
  4841. Dispose(Temp, Done);
  4842. CloseGroupedAction(eaCopyBlock);
  4843. UnLock;
  4844. end;
  4845. procedure TCustomCodeEditor.MoveBlock;
  4846. var Temp: PCodeEditor;
  4847. R: TRect;
  4848. OldPos: TPoint;
  4849. begin
  4850. if IsReadOnly then Exit;
  4851. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4852. Lock;
  4853. AddGroupedAction(eaMoveBlock);
  4854. GetExtent(R);
  4855. New(Temp, Init(R, nil, nil, nil,nil));
  4856. Temp^.InsertFrom(@Self);
  4857. OldPos:=CurPos;
  4858. if CurPos.Y>SelStart.Y then
  4859. Dec(OldPos.Y,Temp^.GetLineCount-1);
  4860. DelSelect;
  4861. SetCurPtr(OldPos.X,OldPos.Y);
  4862. InsertFrom(Temp);
  4863. Dispose(Temp, Done);
  4864. CloseGroupedAction(eaMoveBlock);
  4865. UnLock;
  4866. end;
  4867. procedure TCustomCodeEditor.IndentBlock;
  4868. var
  4869. ey,i{,indlen} : Sw_integer;
  4870. S,Ind : String;
  4871. Pos : Tpoint;
  4872. begin
  4873. if IsReadOnly then Exit;
  4874. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4875. Lock;
  4876. AddGroupedAction(eaIndentBlock);
  4877. ey:=selend.y;
  4878. if selend.x=0 then
  4879. dec(ey);
  4880. S:='';
  4881. { If AutoIndent try to align first line to
  4882. last line before selection }
  4883. { DISABLED created problems PM
  4884. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4885. begin
  4886. i:=SelStart.Y-1;
  4887. while (S='') and (i>=0) do
  4888. begin
  4889. S:=GetDisplayText(i);
  4890. dec(i);
  4891. end;
  4892. if (S='') or (S[1]<>' ') then
  4893. Ind:=' '
  4894. else
  4895. begin
  4896. i:=1;
  4897. while (i<=Length(S)) and (S[i]=' ') do
  4898. inc(i);
  4899. indlen:=i;
  4900. S:=GetDisplayText(SelStart.Y);
  4901. i:=1;
  4902. while (i<=Length(S)) and (S[i]=' ') do
  4903. inc(i);
  4904. indlen:=indlen-i;
  4905. if indlen<=0 then
  4906. indlen:=1;
  4907. Ind:=CharStr(' ',indlen);
  4908. end;
  4909. end
  4910. else
  4911. Ind:=' ';}
  4912. Ind:=CharStr(' ',GetIndentSize);
  4913. for i:=selstart.y to ey do
  4914. begin
  4915. S:=GetLineText(i);
  4916. SetLineText(i,Ind+S);
  4917. Pos.X:=0;Pos.Y:=i;
  4918. AddAction(eaInsertText,Pos,Pos,Ind,GetFlags);
  4919. end;
  4920. SetCurPtr(CurPos.X,CurPos.Y);
  4921. { must be added manually here PM }
  4922. AddAction(eaMoveCursor,Pos,CurPos,'',GetFlags);
  4923. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  4924. DrawLines(CurPos.Y);
  4925. SetModified(true);
  4926. CloseGroupedAction(eaIndentBlock);
  4927. UnLock;
  4928. end;
  4929. procedure TCustomCodeEditor.UnindentBlock;
  4930. var
  4931. ey,i,j,k,indlen : Sw_integer;
  4932. S : String;
  4933. Pos : TPoint;
  4934. begin
  4935. if IsReadOnly then Exit;
  4936. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4937. Lock;
  4938. AddGroupedAction(eaUnindentBlock);
  4939. ey:=selend.y;
  4940. if selend.x=0 then
  4941. dec(ey);
  4942. { If AutoIndent try to align first line to
  4943. last line before selection }
  4944. { Disabled created problems
  4945. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4946. begin
  4947. S:=GetDisplayText(SelStart.Y);
  4948. i:=1;
  4949. while (i<=Length(S)) and (S[i]=' ') do
  4950. inc(i);
  4951. indlen:=i-1;
  4952. i:=SelStart.Y-1;
  4953. S:='';
  4954. while (S='') and (i>=0) do
  4955. begin
  4956. if Trim(Copy(GetDisplayText(i),1,indlen))='' then
  4957. S:=''
  4958. else
  4959. S:=GetDisplayText(i);
  4960. dec(i);
  4961. end;
  4962. if (S='') then
  4963. Indlen:=1
  4964. else
  4965. begin
  4966. i:=1;
  4967. while (i<=Length(S)) and (S[i]=' ') do
  4968. inc(i);
  4969. indlen:=indlen-i+1;
  4970. if indlen<=0 then
  4971. indlen:=1;
  4972. end;
  4973. end
  4974. else
  4975. Indlen:=1;}
  4976. Indlen:=GetIndentSize;
  4977. for i:=selstart.y to ey do
  4978. begin
  4979. S:=GetLineText(i);
  4980. k:=0;
  4981. for j:=1 to indlen do
  4982. if (length(s)>1) and (S[1]=' ') then
  4983. begin
  4984. Delete(s,1,1);
  4985. inc(k);
  4986. end;
  4987. SetLineText(i,S);
  4988. if k>0 then
  4989. begin
  4990. Pos.Y:=i;
  4991. Pos.X:=0;
  4992. AddAction(eaDeleteText,Pos,Pos,CharStr(' ',k),GetFlags);
  4993. end;
  4994. end;
  4995. SetCurPtr(CurPos.X,CurPos.Y);
  4996. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  4997. DrawLines(CurPos.Y);
  4998. SetModified(true);
  4999. CloseGroupedAction(eaUnindentBlock);
  5000. UnLock;
  5001. end;
  5002. procedure TCustomCodeEditor.SelectWord;
  5003. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  5004. var S : String;
  5005. StartPos,EndPos : byte;
  5006. A,B: TPoint;
  5007. begin
  5008. A:=CurPos;
  5009. B:=CurPos;
  5010. S:=GetDisplayText(A.Y);
  5011. StartPos:=A.X+1;
  5012. EndPos:=StartPos;
  5013. if not (S[StartPos] in WordChars) then
  5014. exit
  5015. else
  5016. begin
  5017. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  5018. Dec(StartPos);
  5019. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  5020. Inc(EndPos);
  5021. A.X:=StartPos-1;
  5022. B.X:=EndPos;
  5023. SetSelection(A,B);
  5024. end;
  5025. end;
  5026. procedure TCustomCodeEditor.SelectLine;
  5027. var A,B: TPoint;
  5028. begin
  5029. if CurPos.Y<GetLineCount then
  5030. begin
  5031. A.Y:=CurPos.Y; A.X:=0;
  5032. B.Y:=CurPos.Y+1; B.X:=0;
  5033. SetSelection(A,B);
  5034. end;
  5035. end;
  5036. procedure TCustomCodeEditor.WriteBlock;
  5037. var FileName: string;
  5038. S: PBufStream;
  5039. begin
  5040. if ValidBlock=false then Exit;
  5041. FileName:='';
  5042. if EditorDialog(edWriteBlock, @FileName) <> cmCancel then
  5043. begin
  5044. FileName := FExpand(FileName);
  5045. New(S, Init(FileName, stCreate, 4096));
  5046. if (S=nil) or (S^.Status<>stOK) then
  5047. EditorDialog(edCreateError,@FileName)
  5048. else
  5049. if SaveAreaToStream(S,SelStart,SelEnd)=false then
  5050. EditorDialog(edWriteError,@FileName);
  5051. if Assigned(S) then Dispose(S, Done);
  5052. end;
  5053. end;
  5054. procedure TCustomCodeEditor.ReadBlock;
  5055. var FileName: string;
  5056. S: PFastBufStream;
  5057. E: PCodeEditor;
  5058. R: TRect;
  5059. begin
  5060. if IsReadOnly then Exit;
  5061. FileName:='';
  5062. if EditorDialog(edReadBlock, @FileName) <> cmCancel then
  5063. begin
  5064. FileName := FExpand(FileName);
  5065. New(S, Init(FileName, stOpenRead, 4096));
  5066. if (S=nil) or (S^.Status<>stOK) then
  5067. EditorDialog(edReadError,@FileName)
  5068. else
  5069. begin
  5070. R.Assign(0,0,0,0);
  5071. New(E, Init(R,nil,nil,nil,nil));
  5072. AddGroupedAction(eaReadBlock);
  5073. if E^.LoadFromStream(S)=false then
  5074. EditorDialog(edReadError,@FileName)
  5075. else
  5076. begin
  5077. E^.SelectAll(true);
  5078. Self.InsertFrom(E);
  5079. end;
  5080. CloseGroupedAction(eaReadBlock);
  5081. Dispose(E, Done);
  5082. end;
  5083. if Assigned(S) then Dispose(S, Done);
  5084. end;
  5085. end;
  5086. procedure TCustomCodeEditor.PrintBlock;
  5087. begin
  5088. NotImplemented; Exit;
  5089. end;
  5090. function TCustomCodeEditor.SelectCodeTemplate(var ShortCut: string): boolean;
  5091. begin
  5092. { Abstract }
  5093. SelectCodeTemplate:=false;
  5094. end;
  5095. procedure TCustomCodeEditor.ExpandCodeTemplate;
  5096. var Line,ShortCutInEditor,ShortCut: string;
  5097. X,Y,I,LineIndent: sw_integer;
  5098. CodeLines: PUnsortedStringCollection;
  5099. CanJump: boolean;
  5100. CP: TPoint;
  5101. begin
  5102. {
  5103. The usage of editing primitives in this routine make it pretty slow, but
  5104. its speed is still acceptable and they make the implementation of Undo
  5105. much easier... - Gabor
  5106. }
  5107. if IsReadOnly then Exit;
  5108. Lock;
  5109. CP.X:=-1; CP.Y:=-1;
  5110. Line:=GetDisplayText(CurPos.Y);
  5111. X:=CurPos.X; ShortCut:='';
  5112. if X<=length(Line) then
  5113. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  5114. begin
  5115. ShortCut:=Line[X]+ShortCut;
  5116. Dec(X);
  5117. end;
  5118. ShortCutInEditor:=ShortCut;
  5119. New(CodeLines, Init(10,10));
  5120. if (ShortCut='') or (not TranslateCodeTemplate(ShortCut,CodeLines)) then
  5121. if SelectCodeTemplate(ShortCut) then
  5122. TranslateCodeTemplate(ShortCut,CodeLines);
  5123. if CodeLines^.Count>0 then
  5124. begin
  5125. LineIndent:=X;
  5126. SetCurPtr(X,CurPos.Y);
  5127. if Copy(ShortCut,1,length(ShortCutInEditor))=ShortCutInEditor then
  5128. begin
  5129. for I:=1 to length(ShortCutInEditor) do
  5130. DelChar;
  5131. end
  5132. else
  5133. { restore correct position }
  5134. SetCurPtr(X+Length(ShortCutInEditor),CurPos.Y);
  5135. for Y:=0 to CodeLines^.Count-1 do
  5136. begin
  5137. Line:=GetStr(CodeLines^.At(Y));
  5138. CanJump:=false;
  5139. if (Y>0) then
  5140. begin
  5141. CanJump:=Trim(GetLineText(CurPos.Y))='';
  5142. if CanJump=false then
  5143. begin
  5144. (* for X:=1 to LineIndent do { indent template lines to align }
  5145. AddChar(' '); { them to the first line }*)
  5146. InsertText(CharStr(' ',LineIndent));
  5147. end
  5148. else
  5149. SetCurPtr(CurPos.X+LineIndent,CurPos.Y);
  5150. end;
  5151. I:=Pos(CodeTemplateCursorChar,Line);
  5152. if I>0 then
  5153. begin
  5154. Delete(Line,I,1);
  5155. CP.X:=CurPos.X+I-1;
  5156. CP.Y:=CurPos.Y;
  5157. end;
  5158. InsertText(Line);
  5159. if Y<CodeLines^.Count-1 then
  5160. begin
  5161. InsertNewLine; { line break }
  5162. if CanJump=false then
  5163. begin
  5164. while CurPos.X>0 do { unindent }
  5165. begin
  5166. SetCurPtr(CurPos.X-1,CurPos.Y);
  5167. DelChar;
  5168. end;
  5169. end
  5170. else
  5171. SetCurPtr(0,CurPos.Y);
  5172. end;
  5173. end;
  5174. end;
  5175. Dispose(CodeLines, Done);
  5176. if (CP.X<>-1) and (CP.Y<>-1) then
  5177. SetCurPtr(CP.X,CP.Y);
  5178. UnLock;
  5179. end;
  5180. procedure TCustomCodeEditor.AddChar(C: char);
  5181. const OpenBrackets : string[10] = '[({';
  5182. CloseBrackets : string[10] = '])}';
  5183. var S,SC,TabS: string;
  5184. BI: byte;
  5185. CI,TabStart,LocTabSize : Sw_integer;
  5186. SP: TPoint;
  5187. HoldUndo : boolean;
  5188. begin
  5189. if IsReadOnly then Exit;
  5190. Lock;
  5191. SP:=CurPos;
  5192. HoldUndo:=GetStoreUndo;
  5193. SetStoreUndo(false);
  5194. if (C<>TAB) or IsFlagSet(efUseTabCharacters) then
  5195. SC:=C
  5196. else
  5197. begin
  5198. LocTabSize:=GetTabSize - (CurPos.X mod GetTabSize);
  5199. if (CurPos.Y<=1) or not IsFlagSet(efAutoIndent) then
  5200. SC:=CharStr(' ',LocTabSize)
  5201. else
  5202. begin
  5203. S:=GetLineText(CurPos.Y-1);
  5204. BI:=CurPos.X+1;
  5205. while (BI<=Length(S)) and (S[BI]=' ') do
  5206. inc(BI);
  5207. if (BI=CurPos.X+1) or (BI>Length(S)) then
  5208. SC:=CharStr(' ',LocTabSize)
  5209. else
  5210. SC:=CharStr(' ',BI-CurPos.X-1);
  5211. end;
  5212. end;
  5213. S:=GetLineText(CurPos.Y);
  5214. if CharIdxToLinePos(CurPos.Y,length(S))<CurPos.X then
  5215. begin
  5216. S:=S+CharStr(' ',CurPos.X-CharIdxToLinePos(CurPos.Y,length(S)){-1});
  5217. SetLineText(CurPos.Y,S);
  5218. end;
  5219. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  5220. if CI>High(S) then
  5221. begin
  5222. Unlock;
  5223. exit;
  5224. end;
  5225. if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then
  5226. begin
  5227. if CI=1 then
  5228. TabStart:=0
  5229. else
  5230. TabStart:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  5231. if SC=Tab then TabS:=Tab else
  5232. TabS:=CharStr(' ',CurPos.X-TabStart);
  5233. SetLineText(CurPos.Y,copy(S,1,CI-1)+TabS+SC+copy(S,CI+1,High(S)));
  5234. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(TabS)+length(SC)),CurPos.Y);
  5235. end
  5236. else
  5237. begin
  5238. if Overwrite and (CI<=length(S)) then
  5239. begin
  5240. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI+length(SC),High(S)));
  5241. end
  5242. else
  5243. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI,High(S)));
  5244. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(SC)),CurPos.Y);
  5245. end;
  5246. { must be before CloseBrackets !! }
  5247. SetStoreUndo(HoldUndo);
  5248. if Overwrite then
  5249. Addaction(eaOverwriteText,SP,CurPos,Copy(S,CI,length(SC)),GetFlags)
  5250. else
  5251. Addaction(eaInsertText,SP,CurPos,SC,GetFlags);
  5252. SetStoreUndo(false);
  5253. if IsFlagSet(efAutoBrackets) then
  5254. begin
  5255. BI:=Pos(C,OpenBrackets);
  5256. if (BI>0) then
  5257. begin
  5258. SetStoreUndo(HoldUndo);
  5259. AddChar(CloseBrackets[BI]);
  5260. SetStoreUndo(false);
  5261. SetCurPtr(CurPos.X-1,CurPos.Y);
  5262. end;
  5263. end;
  5264. UpdateAttrs(CurPos.Y,attrAll);
  5265. if GetInsertMode then
  5266. AdjustSelection(CurPos.X-SP.X,CurPos.Y-SP.Y);
  5267. DrawLines(CurPos.Y);
  5268. SetStoreUndo(HoldUndo);
  5269. SetModified(true);
  5270. UnLock;
  5271. end;
  5272. {$ifdef WinClipSupported}
  5273. const
  5274. linelimit = 200;
  5275. function TCustomCodeEditor.ClipPasteWin: Boolean;
  5276. var
  5277. StorePos : TPoint;
  5278. first : boolean;
  5279. procedure InsertStringWrap(const s: string; var i : Longint);
  5280. var
  5281. BPos,EPos: TPoint;
  5282. begin
  5283. if first then
  5284. begin
  5285. { we need to cut the line in two
  5286. if not at end of line PM }
  5287. InsertNewLine;
  5288. SetCurPtr(StorePos.X,StorePos.Y);
  5289. InsertText(s);
  5290. first:=false;
  5291. end
  5292. else
  5293. begin
  5294. Inc(i);
  5295. InsertLine(i,s);
  5296. BPos.X:=0;BPos.Y:=i;
  5297. EPOS.X:=Length(s);EPos.Y:=i;
  5298. AddAction(eaInsertLine,BPos,EPos,GetDisplayText(i),GetFlags);
  5299. end;
  5300. end;
  5301. var
  5302. OK: boolean;
  5303. l,i,len,len10 : longint;
  5304. p,p10,p2,p13 : pchar;
  5305. s : string;
  5306. begin
  5307. Lock;
  5308. OK:=WinClipboardSupported;
  5309. if OK then
  5310. begin
  5311. first:=true;
  5312. StorePos:=CurPos;
  5313. i:=CurPos.Y;
  5314. l:=GetTextWinClipboardSize;
  5315. if l=0 then
  5316. OK:=false
  5317. else
  5318. OK:=GetTextWinClipBoardData(p,l);
  5319. if OK then
  5320. begin
  5321. if l>500 then
  5322. PushInfo(msg_readingwinclipboard);
  5323. AddGroupedAction(eaPasteWin);
  5324. p2:=p;
  5325. len:=strlen(p2);
  5326. // issue lines ((#13)#10 terminated) of maximally "linelimit" chars.
  5327. // does not take initial X position into account
  5328. repeat
  5329. p13:=strpos(p2,#13);
  5330. p10:=strpos(p2,#10);
  5331. if len> linelimit then
  5332. len:=linelimit;
  5333. if assigned(p10) then
  5334. begin
  5335. len10:=p10-p2;
  5336. if len10<len then
  5337. begin
  5338. if p13+1=p10 then
  5339. dec(len10);
  5340. len:=len10;
  5341. end
  5342. else
  5343. p10:=nil; // signal no cleanup
  5344. end;
  5345. setlength(s,len);
  5346. if len>0 then
  5347. move(p2^,s[1],len);
  5348. // cleanup
  5349. if assigned(p10) then
  5350. p2:=p10+1
  5351. else
  5352. inc(p2,len);
  5353. insertstringwrap(s,i);
  5354. len:=strlen(p2);
  5355. until len=0;
  5356. SetCurPtr(StorePos.X,StorePos.Y); // y+i to get after paste?
  5357. SetModified(true);
  5358. UpdateAttrs(StorePos.Y,attrAll);
  5359. CloseGroupedAction(eaPasteWin);
  5360. Update;
  5361. if l>500 then
  5362. PopInfo;
  5363. { we must free the allocated memory }
  5364. freemem(p,l);
  5365. DrawView;
  5366. end;
  5367. end;
  5368. ClipPasteWin:=OK;
  5369. UnLock;
  5370. end;
  5371. function TCustomCodeEditor.ClipCopyWin: Boolean;
  5372. var OK,ShowInfo: boolean;
  5373. p,p2 : pchar;
  5374. s : string;
  5375. i,str_begin,str_end,NumLines,PcLength : longint;
  5376. begin
  5377. NumLines:=SelEnd.Y-SelStart.Y;
  5378. if (NumLines>0) or (SelEnd.X>SelStart.X) then
  5379. Inc(NumLines);
  5380. if NumLines=0 then
  5381. exit;
  5382. Lock;
  5383. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5384. if ShowInfo then
  5385. PushInfo(msg_copyingwinclipboard);
  5386. { First calculate needed size }
  5387. { for newlines first + 1 for terminal #0 }
  5388. PcLength:=Length(EOL)*(NumLines-1)+1;
  5389. { overestimated but can not be that big PM }
  5390. for i:=SelStart.Y to SelEnd.Y do
  5391. PCLength:=PCLength+Length(GetLineText(i));
  5392. getmem(p,PCLength);
  5393. i:=SelStart.Y;
  5394. s:=GetLineText(i);
  5395. str_begin:=LinePosToCharIdx(i,SelStart.X);
  5396. if SelEnd.Y>SelStart.Y then
  5397. str_end:=High(S)
  5398. else
  5399. str_end:=LinePosToCharIdx(i,SelEnd.X)-1;
  5400. s:=copy(s,str_begin,str_end-str_begin+1);
  5401. strpcopy(p,s);
  5402. p2:=strend(p);
  5403. inc(i);
  5404. while i<SelEnd.Y do
  5405. begin
  5406. strpcopy(p2,EOL+GetLineText(i));
  5407. p2:=strend(p2);
  5408. Inc(i);
  5409. end;
  5410. if SelEnd.Y>SelStart.Y then
  5411. begin
  5412. s:=copy(GetLineText(i),1,LinePosToCharIdx(i,SelEnd.X)-1);
  5413. strpcopy(p2,EOL+s);
  5414. end;
  5415. OK:=WinClipboardSupported;
  5416. if OK then
  5417. begin
  5418. OK:=SetTextWinClipBoardData(p,strlen(p));
  5419. end;
  5420. ClipCopyWin:=OK;
  5421. if ShowInfo then
  5422. PopInfo;
  5423. Freemem(p,PCLength);
  5424. UnLock;
  5425. end;
  5426. {$endif WinClipSupported}
  5427. function TCustomCodeEditor.ClipCopy: Boolean;
  5428. var ShowInfo,CanPaste: boolean;
  5429. begin
  5430. Lock;
  5431. {AddGroupedAction(eaCopy);
  5432. can we undo a copy ??
  5433. maybe as an Undo Paste in Clipboard !! }
  5434. clipcopy:=false;
  5435. showinfo:=false;
  5436. if (clipboard<>nil) and (clipboard<>@self) then
  5437. begin
  5438. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5439. if ShowInfo then
  5440. PushInfo(msg_copyingclipboard);
  5441. clipcopy:=Clipboard^.InsertFrom(@Self);
  5442. if ShowInfo then
  5443. PopInfo;
  5444. {Enable paste command.}
  5445. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5446. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5447. SetCmdState(FromClipCmds,CanPaste);
  5448. end;
  5449. UnLock;
  5450. end;
  5451. procedure TCustomCodeEditor.ClipCut;
  5452. var
  5453. ShowInfo,CanPaste : boolean;
  5454. begin
  5455. if IsReadOnly then Exit;
  5456. Lock;
  5457. AddGroupedAction(eaCut);
  5458. DontConsiderShiftState:=true;
  5459. if (clipboard<>nil) and (clipboard<>@self) then
  5460. begin
  5461. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5462. if ShowInfo then
  5463. PushInfo(msg_cutting);
  5464. if Clipboard^.InsertFrom(@Self) then
  5465. begin
  5466. if not IsClipBoard then
  5467. DelSelect;
  5468. SetModified(true);
  5469. end;
  5470. if ShowInfo then
  5471. PopInfo;
  5472. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5473. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5474. SetCmdState(FromClipCmds,CanPaste);
  5475. end;
  5476. CloseGroupedAction(eaCut);
  5477. UnLock;
  5478. DontConsiderShiftState:=false;
  5479. end;
  5480. procedure TCustomCodeEditor.ClipPaste;
  5481. var
  5482. ShowInfo : boolean;
  5483. begin
  5484. if IsReadOnly then Exit;
  5485. DontConsiderShiftState:=true;
  5486. Lock;
  5487. AddGroupedAction(eaPaste);
  5488. if Clipboard<>nil then
  5489. begin
  5490. ShowInfo:=Clipboard^.SelEnd.Y-Clipboard^.SelStart.Y>50;
  5491. if ShowInfo then
  5492. PushInfo(msg_pastingclipboard);
  5493. InsertFrom(Clipboard);
  5494. if ShowInfo then
  5495. PopInfo;
  5496. end;
  5497. CloseGroupedAction(eaPaste);
  5498. UnLock;
  5499. DontConsiderShiftState:=false;
  5500. end;
  5501. procedure TCustomCodeEditor.Undo;
  5502. begin
  5503. NotImplemented; Exit;
  5504. end;
  5505. procedure TCustomCodeEditor.Redo;
  5506. begin
  5507. NotImplemented; Exit;
  5508. end;
  5509. procedure TCustomCodeEditor.GotoLine;
  5510. var
  5511. GotoRec: TGotoLineDialogRec;
  5512. begin
  5513. with GotoRec do
  5514. begin
  5515. LineNo:='1';
  5516. Lines:=GetLineCount;
  5517. {Linecount can be 0, but in that case there still is a cursor blinking in top
  5518. of the window, which will become line 1 as soon as sometype hits a key.}
  5519. if lines=0 then
  5520. lines:=1;
  5521. if EditorDialog(edGotoLine, @GotoRec) <> cmCancel then
  5522. begin
  5523. Lock;
  5524. SetCurPtr(0,StrToInt(LineNo)-1);
  5525. TrackCursor(do_centre);
  5526. UnLock;
  5527. end;
  5528. end;
  5529. end;
  5530. procedure TCustomCodeEditor.Find;
  5531. var
  5532. FindRec: TFindDialogRec;
  5533. DoConf: boolean;
  5534. begin
  5535. with FindRec do
  5536. begin
  5537. Find := FindStr;
  5538. if GetCurrentWord<>'' then
  5539. Find:=GetCurrentWord;
  5540. {$ifdef TEST_REGEXP}
  5541. Options := ((FindFlags and ffmOptionsFind) shr ffsOptions) or
  5542. ((FindFlags and ffUseRegExp) shr ffsUseRegExpFind);
  5543. {$else not TEST_REGEXP}
  5544. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5545. {$endif TEST_REGEXP}
  5546. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5547. Scope := (FindFlags and ffmScope) shr ffsScope;
  5548. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5549. DoConf:= (FindFlags and ffPromptOnReplace)<>0;
  5550. FindReplaceEditor:=@self;
  5551. if EditorDialog(edFind, @FindRec) <> cmCancel then
  5552. begin
  5553. FindStr := Find;
  5554. {$ifdef TEST_REGEXP}
  5555. FindFlags := ((Options and ffmOptionsFind) shl ffsOptions) or (Direction shl ffsDirection) or
  5556. ((Options and ffmUseRegExpFind) shl ffsUseRegExpFind) or
  5557. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5558. {$else : not TEST_REGEXP}
  5559. FindFlags := ((Options and ffmOptions) shl ffsOptions) or (Direction shl ffsDirection) or
  5560. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5561. {$endif TEST_REGEXP}
  5562. FindFlags := FindFlags and not ffDoReplace;
  5563. if DoConf then
  5564. FindFlags := (FindFlags or ffPromptOnReplace);
  5565. SearchRunCount:=0;
  5566. if FindStr<>'' then
  5567. DoSearchReplace
  5568. else
  5569. EditorDialog(edSearchFailed,nil);
  5570. end;
  5571. FindReplaceEditor:=nil;
  5572. end;
  5573. end;
  5574. procedure TCustomCodeEditor.Replace;
  5575. var
  5576. ReplaceRec: TReplaceDialogRec;
  5577. Re: word;
  5578. begin
  5579. if IsReadOnly then Exit;
  5580. with ReplaceRec do
  5581. begin
  5582. Find := FindStr;
  5583. if GetCurrentWord<>'' then
  5584. Find:=GetCurrentWord;
  5585. Replace := ReplaceStr;
  5586. {$ifdef TEST_REGEXP}
  5587. Options := (FindFlags and ffmOptions) shr ffsOptions or
  5588. (FindFlags and ffUseRegExp) shr ffsUseRegExpReplace;
  5589. {$else not TEST_REGEXP}
  5590. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5591. {$endif TEST_REGEXP}
  5592. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5593. Scope := (FindFlags and ffmScope) shr ffsScope;
  5594. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5595. FindReplaceEditor:=@self;
  5596. Re:=EditorDialog(edReplace, @ReplaceRec);
  5597. FindReplaceEditor:=nil;
  5598. if Re <> cmCancel then
  5599. begin
  5600. FindStr := Find;
  5601. ReplaceStr := Replace;
  5602. FindFlags := (Options shl ffsOptions) or (Direction shl ffsDirection) or
  5603. {$ifdef TEST_REGEXP}
  5604. ((Options and ffmUseRegExpReplace) shl ffsUseRegExpReplace) or
  5605. {$endif TEST_REGEXP}
  5606. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5607. FindFlags := FindFlags or ffDoReplace;
  5608. if Re = cmYes then
  5609. FindFlags := FindFlags or ffReplaceAll;
  5610. SearchRunCount:=0;
  5611. if FindStr<>'' then
  5612. DoSearchReplace
  5613. else
  5614. EditorDialog(edSearchFailed,nil);
  5615. end;
  5616. end;
  5617. end;
  5618. procedure TCustomCodeEditor.DoSearchReplace;
  5619. var S: string;
  5620. DX,DY,P,Y,X: sw_integer;
  5621. Count: sw_integer;
  5622. Found,CanExit: boolean;
  5623. SForward,DoReplace,DoReplaceAll: boolean;
  5624. {$ifdef TEST_REGEXP}
  5625. UseRegExp : boolean;
  5626. RegExpEngine : TRegExprEngine;
  5627. RegExpFlags : tregexprflags;
  5628. regexpindex,regexplen : longint;
  5629. findstrpchar : pchar;
  5630. {$endif TEST_REGEXP}
  5631. LeftOK,RightOK: boolean;
  5632. FoundCount: sw_integer;
  5633. A,B: TPoint;
  5634. AreaStart,AreaEnd: TPoint;
  5635. CanReplace,Confirm: boolean;
  5636. Re: word;
  5637. IFindStr : string;
  5638. BT : BTable;
  5639. Overwriting : boolean;
  5640. function ContainsText(const SubS:string;var S: string; Start: Sw_integer): Sw_integer;
  5641. var
  5642. P: Sw_Integer;
  5643. begin
  5644. if Start<=0 then
  5645. P:=0
  5646. else
  5647. begin
  5648. if SForward then
  5649. begin
  5650. if Start>length(s) then
  5651. P:=0
  5652. else if FindFlags and ffCaseSensitive<>0 then
  5653. P:=BMFScan(S[Start],length(s)+1-Start,FindStr,Bt)+1
  5654. else
  5655. P:=BMFIScan(S[Start],length(s)+1-Start,IFindStr,Bt)+1;
  5656. if P>0 then
  5657. Inc(P,Start-1);
  5658. end
  5659. else
  5660. begin
  5661. if start>length(s) then
  5662. start:=length(s);
  5663. if FindFlags and ffCaseSensitive<>0 then
  5664. P:=BMBScan(S[1],Start,FindStr,Bt)+1
  5665. else
  5666. P:=BMBIScan(S[1],Start,IFindStr,Bt)+1;
  5667. end;
  5668. end;
  5669. ContainsText:=P;
  5670. end;
  5671. function InArea(X,Y: sw_integer): boolean;
  5672. begin
  5673. InArea:=((AreaStart.Y=Y) and (AreaStart.X<=X)) or
  5674. ((AreaStart.Y<Y) and (Y<AreaEnd.Y)) or
  5675. ((AreaEnd.Y=Y) and (X<=AreaEnd.X));
  5676. end;
  5677. var CurDY: sw_integer;
  5678. begin
  5679. if FindStr='' then
  5680. begin
  5681. Find;
  5682. { Find will call DoFindReplace at end again
  5683. so we need to exit directly now PM }
  5684. exit;
  5685. end;
  5686. Inc(SearchRunCount);
  5687. SForward:=(FindFlags and ffmDirection)=ffForward;
  5688. DoReplace:=(FindFlags and ffDoReplace)<>0;
  5689. Confirm:=(FindFlags and ffPromptOnReplace)<>0;
  5690. DoReplaceAll:=(FindFlags and ffReplaceAll)<>0;
  5691. {$ifdef TEST_REGEXP}
  5692. UseRegExp:=(FindFlags and ffUseRegExp)<>0;
  5693. if UseRegExp then
  5694. begin
  5695. if FindFlags and ffCaseSensitive<>0 then
  5696. RegExpFlags:=[ref_caseinsensitive]
  5697. else
  5698. RegExpFlags:=[];
  5699. getmem(findstrpchar,length(findstr)+1);
  5700. strpcopy(findstrpchar,findstr);
  5701. RegExpEngine:=GenerateRegExprEngine(findstrpchar,RegExpFlags);
  5702. strdispose(findstrpchar);
  5703. end;
  5704. {$endif TEST_REGEXP}
  5705. Count:=GetLineCount;
  5706. FoundCount:=0;
  5707. { Empty file ? }
  5708. if Count=0 then
  5709. begin
  5710. EditorDialog(edSearchFailed,nil);
  5711. exit;
  5712. end;
  5713. if SForward then
  5714. DY:=1
  5715. else
  5716. DY:=-1;
  5717. DX:=DY;
  5718. if FindStr<>'' then
  5719. PushInfo('Looking for "'+FindStr+'"');
  5720. if (FindFlags and ffmScope)=ffGlobal then
  5721. begin
  5722. AreaStart.X:=0;
  5723. AreaStart.Y:=0;
  5724. AreaEnd.X:=length(GetDisplayText(Count-1));
  5725. AreaEnd.Y:=Count-1;
  5726. end
  5727. else
  5728. begin
  5729. AreaStart:=SelStart;
  5730. AreaEnd:=SelEnd;
  5731. end;
  5732. { set a y value being inside the areal }
  5733. Y:=Min(CurPos.Y,Count-1);
  5734. if sForward then
  5735. X:=CurPos.X-1
  5736. else
  5737. { if you change this, pleas check that repeated backward searching for single chars still works
  5738. and that data is still found if searching starts outside the current line }
  5739. X:=Min(CurPos.X,length(GetDisplayText(Y)));
  5740. if SearchRunCount=1 then
  5741. if (FindFlags and ffmOrigin)=ffEntireScope then
  5742. if SForward then
  5743. begin
  5744. X:=AreaStart.X-1;
  5745. Y:=AreaStart.Y;
  5746. end
  5747. else
  5748. begin
  5749. X:=AreaEnd.X+1;
  5750. Y:=AreaEnd.Y;
  5751. end;
  5752. if FindFlags and ffCaseSensitive<>0 then
  5753. begin
  5754. if SForward then
  5755. BMFMakeTable(FindStr,bt)
  5756. else
  5757. BMBMakeTable(FindStr,bt);
  5758. end
  5759. else
  5760. begin
  5761. IFindStr:=upcase(FindStr);
  5762. if SForward then
  5763. BMFMakeTable(IFindStr,bt)
  5764. else
  5765. BMBMakeTable(IFindStr,bt);
  5766. end;
  5767. inc(X,DX);
  5768. CanExit:=false;
  5769. if not DoReplace or (not Confirm and (Owner<>nil)) then
  5770. Owner^.Lock;
  5771. if InArea(X,Y) then
  5772. repeat
  5773. CurDY:=DY;
  5774. S:=GetDisplayText(Y);
  5775. if X>length(S)-1 then
  5776. X:=length(S)-1;
  5777. {$ifdef TEST_REGEXP}
  5778. if UseRegExp then
  5779. begin
  5780. getmem(findstrpchar,length(Copy(S,X+1,high(S)))+1);
  5781. strpcopy(findstrpchar,Copy(S,X+1,high(S)));
  5782. { If start of line is required do check other positions PM }
  5783. if (FindStr[1]='^') and (X<>0) then
  5784. Found:=false
  5785. else
  5786. Found:=RegExprPos(RegExpEngine,findstrpchar,regexpindex,regexplen);
  5787. strdispose(findstrpchar);
  5788. P:=regexpindex+X+1;
  5789. end
  5790. else
  5791. {$endif TEST_REGEXP}
  5792. begin
  5793. P:=ContainsText(FindStr,S,X+1);
  5794. Found:=P<>0;
  5795. end;
  5796. if Found then
  5797. begin
  5798. A.X:=P-1;
  5799. A.Y:=Y;
  5800. B.Y:=Y;
  5801. {$ifdef TEST_REGEXP}
  5802. if UseRegExp then
  5803. B.X:=A.X+regexplen
  5804. else
  5805. {$endif TEST_REGEXP}
  5806. B.X:=A.X+length(FindStr);
  5807. end;
  5808. Found:=Found and InArea(A.X,A.Y);
  5809. if Found and ((FindFlags and ffWholeWordsOnly)<>0) then
  5810. begin
  5811. LeftOK:=(A.X<=0) or (not( (S[A.X] in AlphaChars+NumberChars) ));
  5812. RightOK:=(B.X>=length(S)) or (not( (S[B.X+1] in AlphaChars+NumberChars) ));
  5813. Found:=LeftOK and RightOK;
  5814. if not Found then
  5815. begin
  5816. CurDY:=0;
  5817. If SForward then
  5818. begin
  5819. X:=B.X+1;
  5820. if X>length(S) then
  5821. CurDY:=DY;
  5822. end
  5823. else
  5824. begin
  5825. X:=A.X-1;
  5826. if X<0 then
  5827. CurDY:=DY;
  5828. end;
  5829. end;
  5830. end;
  5831. if Found then
  5832. begin
  5833. Inc(FoundCount);
  5834. Lock;
  5835. if SForward then
  5836. SetCurPtr(B.X,B.Y)
  5837. else
  5838. SetCurPtr(A.X,A.Y);
  5839. TrackCursor(do_centre);
  5840. SetHighlight(A,B);
  5841. UnLock;
  5842. CurDY:=0;
  5843. if not DoReplace then
  5844. begin
  5845. CanExit:=true;
  5846. If SForward then
  5847. begin
  5848. X:=B.X;
  5849. Y:=B.Y;
  5850. end
  5851. else
  5852. begin
  5853. X:=A.X;
  5854. Y:=A.Y;
  5855. end;
  5856. end
  5857. else
  5858. begin
  5859. if not confirm then
  5860. CanReplace:=true
  5861. else
  5862. begin
  5863. Re:=EditorDialog(edReplacePrompt,@CurPos);
  5864. case Re of
  5865. cmYes :
  5866. CanReplace:=true;
  5867. cmNo :
  5868. CanReplace:=false;
  5869. else {cmCancel}
  5870. begin
  5871. CanReplace:=false;
  5872. CanExit:=true;
  5873. end;
  5874. end;
  5875. end;
  5876. if CanReplace then
  5877. begin
  5878. Lock;
  5879. { don't use SetInsertMode here because it changes the cursor shape }
  5880. overwriting:=(GetFlags and efInsertMode)=0;
  5881. SetFlags(GetFlags or efInsertMode);
  5882. SetSelection(A,B);
  5883. DelSelect;
  5884. InsertText(ReplaceStr);
  5885. if SForward then
  5886. begin
  5887. X:=CurPos.X;
  5888. Y:=CurPos.Y;
  5889. end
  5890. else
  5891. begin
  5892. X:=A.X;
  5893. Y:=A.Y;
  5894. end;
  5895. if overwriting then
  5896. SetFlags(GetFlags and (not efInsertMode));
  5897. UnLock;
  5898. end
  5899. else
  5900. begin
  5901. If SForward then
  5902. begin
  5903. X:=B.X;
  5904. Y:=B.Y;
  5905. end
  5906. else
  5907. begin
  5908. X:=A.X;
  5909. Y:=A.Y;
  5910. end;
  5911. end;
  5912. if (DoReplaceAll=false) then
  5913. CanExit:=true;
  5914. end;
  5915. end;
  5916. if (CanExit=false) and (CurDY<>0) then
  5917. begin
  5918. inc(Y,CurDY);
  5919. if SForward then
  5920. X:=0
  5921. else
  5922. X:=254;
  5923. CanExit:=((Y>=Count) and sForward) or (Y<0);
  5924. end;
  5925. if not CanExit then
  5926. CanExit:=(not InArea(X,Y)) and sForward;
  5927. until CanExit;
  5928. if (FoundCount=0) or (DoReplace) then
  5929. SetHighlight(CurPos,CurPos);
  5930. if (DoReplace=false) or ((Confirm=false) and (Owner<>nil)) then
  5931. Owner^.UnLock;
  5932. {if (DoReplace=false) or (Confirm=false) then
  5933. UnLock;}
  5934. if (FoundCount=0) then
  5935. EditorDialog(edSearchFailed,nil);
  5936. if FindStr<>'' then
  5937. PopInfo;
  5938. {$ifdef TEST_REGEXP}
  5939. if UseRegExp then
  5940. DestroyRegExprEngine(RegExpEngine);
  5941. {$endif TEST_REGEXP}
  5942. if (FindFlags and ffmScope)=ffSelectedText then
  5943. { restore selection PM }
  5944. begin
  5945. SetSelection(AreaStart,AreaEnd);
  5946. end;
  5947. end;
  5948. function TCustomCodeEditor.GetInsertMode: boolean;
  5949. begin
  5950. GetInsertMode:=(GetFlags and efInsertMode)<>0;
  5951. end;
  5952. procedure TCustomCodeEditor.SetInsertMode(InsertMode: boolean);
  5953. begin
  5954. if InsertMode then
  5955. SetFlags(GetFlags or efInsertMode)
  5956. else
  5957. SetFlags(GetFlags and (not efInsertMode));
  5958. DrawCursor;
  5959. end;
  5960. { there is a problem with ShiftDel here
  5961. because GetShitState tells to extend the
  5962. selection which gives wrong results (PM) }
  5963. function TCustomCodeEditor.ShouldExtend: boolean;
  5964. var ShiftInEvent: boolean;
  5965. begin
  5966. ShiftInEvent:=false;
  5967. if Assigned(CurEvent) then
  5968. if CurEvent^.What=evKeyDown then
  5969. ShiftInEvent:=((CurEvent^.KeyShift and kbShift)<>0);
  5970. ShouldExtend:=ShiftInEvent and
  5971. not DontConsiderShiftState;
  5972. end;
  5973. procedure TCustomCodeEditor.SetCurPtr(X,Y: sw_integer);
  5974. var OldPos{,OldSEnd,OldSStart}: TPoint;
  5975. Extended: boolean;
  5976. F: PFold;
  5977. begin
  5978. Lock;
  5979. X:=Max(0,Min(MaxLineLength+1,X));
  5980. Y:=Max(0,Min(GetLineCount-1,Y));
  5981. OldPos:=CurPos;
  5982. { OldSEnd:=SelEnd;
  5983. OldSStart:=SelStart;}
  5984. CurPos.X:=X;
  5985. CurPos.Y:=Y;
  5986. TrackCursor(do_not_centre);
  5987. if not IsLineVisible(CurPos.Y) then
  5988. begin
  5989. F:=GetLineFold(CurPos.Y);
  5990. if Assigned(F) then
  5991. F^.Collapse(false);
  5992. end;
  5993. if not NoSelect and ShouldExtend then
  5994. begin
  5995. CheckSels;
  5996. Extended:=false;
  5997. if PointOfs(OldPos)=PointOfs(SelStart) then
  5998. begin
  5999. SetSelection(CurPos,SelEnd);
  6000. Extended:=true;
  6001. end;
  6002. CheckSels;
  6003. if Extended=false then
  6004. if PointOfs(OldPos)=PointOfs(SelEnd) then
  6005. begin
  6006. if not ValidBlock then
  6007. SetSelection(CurPos,CurPos);
  6008. SetSelection(SelStart,CurPos); Extended:=true;
  6009. end;
  6010. CheckSels;
  6011. if not Extended then
  6012. if PointOfs(OldPos)<=PointOfs(CurPos) then
  6013. begin
  6014. SetSelection(OldPos,CurPos);
  6015. Extended:=true;
  6016. end
  6017. else
  6018. begin
  6019. SetSelection(CurPos,OldPos);
  6020. Extended:=true;
  6021. end;
  6022. DrawView;
  6023. end
  6024. else if not IsFlagSet(efPersistentBlocks) then
  6025. begin
  6026. HideSelect;
  6027. DrawView;
  6028. end;
  6029. { if PointOfs(SelStart)=PointOfs(SelEnd) then
  6030. SetSelection(CurPos,CurPos);}
  6031. if (GetFlags and (efHighlightColumn+efHighlightRow))<>0 then
  6032. DrawView;
  6033. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and
  6034. ((Highlight.A.X<>HighLight.B.X) or (Highlight.A.Y<>HighLight.B.Y)) then
  6035. HideHighlight;
  6036. if (OldPos.Y<>CurPos.Y) and (0<=OldPos.Y) and (OldPos.Y<GetLineCount) then
  6037. SetLineText(OldPos.Y,RTrim(GetLineText(OldPos.Y),not IsFlagSet(efUseTabCharacters)));
  6038. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (GetErrorMessage<>'') then
  6039. SetErrorMessage('');
  6040. { if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (HighlightRow<>-1) then
  6041. SetHighlightRow(-1);}
  6042. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6043. AddAction(eaMoveCursor,OldPos,CurPos,'',GetFlags);
  6044. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6045. PositionChanged;{UpdateIndicator;}
  6046. UnLock;
  6047. end;
  6048. procedure TCustomCodeEditor.CheckSels;
  6049. begin
  6050. if (SelStart.Y>SelEnd.Y) or
  6051. ( (SelStart.Y=SelEnd.Y) and (SelStart.X>SelEnd.X) ) then
  6052. SetSelection(SelEnd,SelStart);
  6053. end;
  6054. procedure TCustomCodeEditor.CodeCompleteApply;
  6055. var S: string;
  6056. FragLen,
  6057. I: integer;
  6058. begin
  6059. Lock;
  6060. { here should be some kind or "mark" or "break" inserted in the Undo
  6061. information, so activating it "undoes" only the completition first and
  6062. doesn't delete the complete word at once... - Gabor }
  6063. FragLen:=Length(GetCodeCompleteFrag);
  6064. S:=GetCodeCompleteWord;
  6065. for I:=FragLen+1 to length(S) do
  6066. AddChar(S[I]);
  6067. UnLock;
  6068. SetCompleteState(csInactive);
  6069. end;
  6070. procedure TCustomCodeEditor.CodeCompleteCancel;
  6071. begin
  6072. SetCompleteState(csDenied);
  6073. end;
  6074. procedure TCustomCodeEditor.CodeCompleteCheck;
  6075. var Line: string;
  6076. X: sw_integer;
  6077. CurWord,NewWord: string;
  6078. begin
  6079. SetCodeCompleteFrag('');
  6080. if (not IsFlagSet(efCodeComplete)) or (IsReadOnly=true) then Exit;
  6081. Lock;
  6082. Line:=GetDisplayText(CurPos.Y);
  6083. X:=CurPos.X; CurWord:='';
  6084. if X<=length(Line) then
  6085. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  6086. begin
  6087. CurWord:=Line[X]+CurWord;
  6088. Dec(X);
  6089. end;
  6090. if (length(CurWord)>=CodeCompleteMinLen) and CompleteCodeWord(CurWord,NewWord) then
  6091. begin
  6092. SetCodeCompleteFrag(CurWord);
  6093. SetCodeCompleteWord(NewWord);
  6094. end
  6095. else
  6096. ClearCodeCompleteWord;
  6097. UnLock;
  6098. end;
  6099. function TCustomCodeEditor.GetCodeCompleteFrag: string;
  6100. begin
  6101. { Abstract }
  6102. GetCodeCompleteFrag:='';
  6103. end;
  6104. procedure TCustomCodeEditor.SetCodeCompleteFrag(const S: string);
  6105. begin
  6106. { Abstract }
  6107. end;
  6108. procedure TCustomCodeEditor.DrawLines(FirstLine: sw_integer);
  6109. begin
  6110. if FirstLine>=(Delta.Y+Size.Y) then Exit; { falls outside of the screen }
  6111. DrawView;
  6112. end;
  6113. procedure TCustomCodeEditor.HideHighlight;
  6114. begin
  6115. SetHighlight(CurPos,CurPos);
  6116. end;
  6117. procedure TCustomCodeEditor.GetSelectionArea(var StartP,EndP: TPoint);
  6118. begin
  6119. StartP:=SelStart; EndP:=SelEnd;
  6120. if EndP.X=0 then
  6121. begin
  6122. Dec(EndP.Y);
  6123. EndP.X:=length(GetDisplayText(EndP.Y))-1;
  6124. end
  6125. else
  6126. Dec(EndP.X);
  6127. end;
  6128. function TCustomCodeEditor.ValidBlock: boolean;
  6129. begin
  6130. ValidBlock:=(SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y);
  6131. end;
  6132. procedure TCustomCodeEditor.SetSelection(A, B: TPoint);
  6133. var WV: boolean;
  6134. OS,OE: TPoint;
  6135. begin
  6136. WV:=ValidBlock;
  6137. OS:=SelStart; OE:=SelEnd;
  6138. SelStart:=A; SelEnd:=B;
  6139. if (WV=false) and (ValidBlock=false) then { do nothing } else
  6140. if (OS.X<>SelStart.X) or (OS.Y<>SelStart.Y) or
  6141. (OE.X<>SelEnd.X) or (OE.Y<>SelEnd.Y) then
  6142. SelectionChanged;
  6143. end;
  6144. procedure TCustomCodeEditor.SetHighlight(A, B: TPoint);
  6145. begin
  6146. Highlight.A:=A; Highlight.B:=B;
  6147. HighlightChanged;
  6148. end;
  6149. {procedure TCustomCodeEditor.SetHighlightRow(Row: sw_integer);
  6150. begin
  6151. HighlightRow:=Row;
  6152. DrawView;
  6153. end;}
  6154. {procedure TCodeEditor.SetDebuggerRow(Row: sw_integer);
  6155. begin
  6156. DebuggerRow:=Row;
  6157. DrawView;
  6158. end;}
  6159. procedure TCustomCodeEditor.SelectAll(Enable: boolean);
  6160. var A,B: TPoint;
  6161. begin
  6162. if (Enable=false) or (GetLineCount=0) then
  6163. begin A:=CurPos; B:=CurPos end
  6164. else
  6165. begin
  6166. A.X:=0; A.Y:=0;
  6167. { B.Y:=GetLineCount-1;
  6168. B.X:=length(GetLineText(B.Y));}
  6169. B.Y:=GetLineCount; B.X:=0;
  6170. end;
  6171. SetSelection(A,B);
  6172. DrawView;
  6173. end;
  6174. procedure TCustomCodeEditor.SelectionChanged;
  6175. var Enable,CanPaste: boolean;
  6176. begin
  6177. if GetLineCount=0 then
  6178. begin
  6179. SelStart.X:=0; SelStart.Y:=0; SelEnd:=SelStart;
  6180. end
  6181. else
  6182. if SelEnd.Y>GetLineCount-1 then
  6183. if (SelEnd.Y<>GetLineCount) or (SelEnd.X<>0) then
  6184. begin
  6185. SelEnd.Y:=GetLineCount-1;
  6186. SelEnd.X:=length(GetDisplayText(SelEnd.Y));
  6187. end;
  6188. { we change the CurCommandSet, but only if we are top view }
  6189. if ((State and sfFocused)<>0) then
  6190. begin
  6191. Enable:=((SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y)) and (Clipboard<>nil);
  6192. SetCmdState(ToClipCmds,Enable and (Clipboard<>@Self));
  6193. SetCmdState(NulClipCmds,Enable);
  6194. CanPaste:=(Clipboard<>nil) and ((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  6195. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  6196. SetCmdState(FromClipCmds,CanPaste and (Clipboard<>@Self));
  6197. SetCmdState(UndoCmd,(GetUndoActionCount>0));
  6198. SetCmdState(RedoCmd,(GetRedoActionCount>0));
  6199. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  6200. end;
  6201. DrawView;
  6202. end;
  6203. procedure TCustomCodeEditor.HighlightChanged;
  6204. begin
  6205. DrawView;
  6206. end;
  6207. procedure TCustomCodeEditor.SetState(AState: Word; Enable: Boolean);
  6208. procedure ShowSBar(SBar: PScrollBar);
  6209. begin
  6210. if Assigned(SBar) and (SBar^.GetState(sfVisible)=false) then
  6211. SBar^.Show;
  6212. end;
  6213. begin
  6214. inherited SetState(AState,Enable);
  6215. if AlwaysShowScrollBars then
  6216. begin
  6217. ShowSBar(HScrollBar);
  6218. ShowSBar(VScrollBar);
  6219. end;
  6220. if (AState and (sfActive+sfSelected+sfFocused))<>0 then
  6221. begin
  6222. SelectionChanged;
  6223. if ((State and sfFocused)=0) and (GetCompleteState=csOffering) then
  6224. ClearCodeCompleteWord;
  6225. end;
  6226. end;
  6227. function TCustomCodeEditor.GetPalette: PPalette;
  6228. const P: string[length(CEditor)] = CEditor;
  6229. begin
  6230. GetPalette:=@P;
  6231. end;
  6232. function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean;
  6233. var S: string;
  6234. AllLinesComplete,LineComplete,hasCR,OK: boolean;
  6235. begin
  6236. DeleteAllLines;
  6237. ChangedLine:=-1;
  6238. AllLinesComplete:=true;
  6239. OK:=(Stream^.Status=stOK);
  6240. if eofstream(Stream) then
  6241. AddLine('')
  6242. else
  6243. begin
  6244. while OK and (eofstream(Stream)=false) and (GetLineCount<MaxLineCount) do
  6245. begin
  6246. if not UseOldBufStreamMethod then
  6247. Stream^.Readline(S,LineComplete,hasCR)
  6248. else
  6249. ReadlnFromStream(Stream,S,LineComplete,hasCR);
  6250. AllLinesComplete:=AllLinesComplete and LineComplete;
  6251. OK:=OK and (Stream^.Status=stOK);
  6252. if OK then AddLine(S);
  6253. if not LineComplete and (ChangedLine=-1) then
  6254. ChangedLine:=GetLineCount;
  6255. end;
  6256. { Do not remove the final newline if it exists PM }
  6257. if hasCR then
  6258. AddLine('');
  6259. end;
  6260. LimitsChanged;
  6261. if not AllLinesComplete then
  6262. SetModified(true);
  6263. if (GetLineCount=MaxLineCount) and not eofstream(stream) then
  6264. EditorDialog(edTooManyLines,nil);
  6265. LoadFromStream:=OK;
  6266. end;
  6267. function TCustomCodeEditorCore.SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean;
  6268. var S: string;
  6269. OK: boolean;
  6270. Line: Sw_integer;
  6271. begin
  6272. if EndP.X=0 then
  6273. begin
  6274. if EndP.Y>0 then
  6275. begin
  6276. EndP.X:=length(GetDisplayText(EndP.Y));
  6277. end
  6278. else
  6279. EndP.X:=0;
  6280. end
  6281. else
  6282. Dec(EndP.X);
  6283. OK:=(Stream^.Status=stOK); Line:=StartP.Y;
  6284. while OK and (Line<=EndP.Y) and (Line<GetLineCount) do
  6285. begin
  6286. S:=GetLineText(Line);
  6287. { Remove all traling spaces PM }
  6288. if not Editor^.IsFlagSet(efKeepTrailingSpaces) then
  6289. While (Length(S)>0) and (S[Length(S)]=' ') do
  6290. Dec(S[0]);
  6291. { if FlagSet(efUseTabCharacters) then
  6292. S:=CompressUsingTabs(S,TabSize);
  6293. }
  6294. if Line=EndP.Y then S:=copy(S,1,LinePosToCharIdx(Line,EndP.X));
  6295. if Line=StartP.Y then S:=copy(S,LinePosToCharIdx(Line,StartP.X),High(S));
  6296. Stream^.Write(S[1],length(S));
  6297. if Line<EndP.Y then
  6298. Stream^.Write(EOL[1],length(EOL));
  6299. Inc(Line);
  6300. OK:=OK and (Stream^.Status=stOK);
  6301. end;
  6302. SaveAreaToStream:=OK;
  6303. end;
  6304. constructor TEditorAction.init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint);
  6305. begin
  6306. Action:=act;
  6307. StartPos:=StartP;
  6308. EndPos:=EndP;
  6309. Text:=NewStr(txt);
  6310. ActionCount:=0;
  6311. Flags:=AFlags;
  6312. TimeStamp:=Now;
  6313. IsGrouped:=false;
  6314. end;
  6315. constructor TEditorAction.init_group(act:byte);
  6316. begin
  6317. Action:=act;
  6318. ActionCount:=0;
  6319. Flags:=0;
  6320. IsGrouped:=true;
  6321. end;
  6322. function TEditorAction.Is_grouped_action : boolean;
  6323. begin
  6324. Is_grouped_action:=IsGrouped;
  6325. end;
  6326. destructor TEditorAction.done;
  6327. begin
  6328. DisposeStr(Text);
  6329. inherited done;
  6330. end;
  6331. function TEditorActionCollection.At(Idx : sw_integer) : PEditorAction;
  6332. begin
  6333. At:=PEditorAction(Inherited At(Idx));
  6334. end;
  6335. procedure TEditorInputLine.HandleEvent(var Event : TEvent);
  6336. var
  6337. s,s2 : string;
  6338. i : longint;
  6339. begin
  6340. If (Event.What=evKeyDown) then
  6341. begin
  6342. if (Event.KeyCode=kbRight) and
  6343. (CurPos = Length(Data^)) and
  6344. Assigned(FindReplaceEditor) then
  6345. Begin
  6346. s:=FindReplaceEditor^.GetDisplayText(FindReplaceEditor^.CurPos.Y);
  6347. s:=Copy(s,FindReplaceEditor^.CurPos.X + 1 -length(Data^),high(s));
  6348. i:=pos(Data^,s);
  6349. if i>0 then
  6350. begin
  6351. s:=Data^+s[i+length(Data^)];
  6352. If not assigned(validator) or
  6353. Validator^.IsValidInput(s,False) then
  6354. Begin
  6355. Event.CharCode:=s[length(s)];
  6356. Event.Scancode:=0;
  6357. Inherited HandleEvent(Event);
  6358. End;
  6359. end;
  6360. ClearEvent(Event);
  6361. End
  6362. else if (Event.KeyCode=kbShiftIns) and
  6363. Assigned(Clipboard) and (Clipboard^.ValidBlock) then
  6364. { paste from clipboard }
  6365. begin
  6366. i:=Clipboard^.SelStart.Y;
  6367. s:=Clipboard^.GetDisplayText(i);
  6368. i:=Clipboard^.SelStart.X;
  6369. if i>0 then
  6370. s:=copy(s,i+1,high(s));
  6371. if (Clipboard^.SelStart.Y=Clipboard^.SelEnd.Y) then
  6372. begin
  6373. i:=Clipboard^.SelEnd.X-i;
  6374. s:=copy(s,1,i);
  6375. end;
  6376. for i:=1 to length(s) do
  6377. begin
  6378. s2:=Data^+s[i];
  6379. If not assigned(validator) or
  6380. Validator^.IsValidInput(s2,False) then
  6381. Begin
  6382. Event.What:=evKeyDown;
  6383. Event.CharCode:=s[i];
  6384. Event.Scancode:=0;
  6385. Inherited HandleEvent(Event);
  6386. End;
  6387. end;
  6388. ClearEvent(Event);
  6389. end
  6390. else if (Event.KeyCode=kbCtrlIns) and
  6391. Assigned(Clipboard) then
  6392. { Copy to clipboard }
  6393. begin
  6394. s:=GetStr(Data);
  6395. s:=copy(s,selstart+1,selend-selstart);
  6396. Clipboard^.SelStart:=Clipboard^.CurPos;
  6397. Clipboard^.InsertText(s);
  6398. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6399. ClearEvent(Event);
  6400. end
  6401. else if (Event.KeyCode=kbShiftDel) and
  6402. Assigned(Clipboard) then
  6403. { Cut to clipboard }
  6404. begin
  6405. s:=GetStr(Data);
  6406. s:=copy(s,selstart+1,selend-selstart);
  6407. Clipboard^.SelStart:=Clipboard^.CurPos;
  6408. Clipboard^.InsertText(s);
  6409. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6410. s2:=GetStr(Data);
  6411. { now remove the selected part }
  6412. Event.keyCode:=kbDel;
  6413. inherited HandleEvent(Event);
  6414. ClearEvent(Event);
  6415. end
  6416. else
  6417. Inherited HandleEvent(Event);
  6418. End
  6419. else
  6420. Inherited HandleEvent(Event);
  6421. s:=getstr(data);
  6422. Message(Owner,evBroadCast,cminputlinelen,pointer(length(s)));
  6423. end;
  6424. procedure TSearchHelperDialog.HandleEvent(var Event : TEvent);
  6425. begin
  6426. case Event.What of
  6427. evBroadcast :
  6428. case Event.Command of
  6429. cminputlinelen : begin
  6430. if PtrInt(Event.InfoPtr)=0 then
  6431. okbutton^.DisableCommands([cmok])
  6432. else
  6433. okbutton^.EnableCommands([cmok]);
  6434. clearevent(event);
  6435. end;
  6436. end;
  6437. end;
  6438. inherited HandleEvent(Event);
  6439. end;
  6440. function CreateFindDialog: PDialog;
  6441. var R,R1,R2: TRect;
  6442. D: PSearchHelperDialog;
  6443. IL1: PEditorInputLine;
  6444. Control : PView;
  6445. CB1: PCheckBoxes;
  6446. RB1,RB2,RB3: PRadioButtons;
  6447. but : PButton;
  6448. begin
  6449. R.Assign(0,0,56,15);
  6450. New(D, Init(R, dialog_find));
  6451. with D^ do
  6452. begin
  6453. Options:=Options or ofCentered;
  6454. GetExtent(R); R.Grow(-3,-2);
  6455. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6456. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6457. New(IL1, Init(R2, FindStrSize));
  6458. IL1^.Data^:=FindStr;
  6459. Insert(IL1);
  6460. Insert(New(PLabel, Init(R1, label_find_texttofind, IL1)));
  6461. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6462. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6463. Insert(Control);
  6464. 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;
  6465. R2.Copy(R1); R2.Move(0,1);
  6466. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}3{$else}2{$endif};
  6467. New(CB1, Init(R2,
  6468. NewSItem(label_find_casesensitive,
  6469. NewSItem(label_find_wholewordsonly,
  6470. {$ifdef TEST_REGEXP}
  6471. NewSItem(label_find_useregexp,
  6472. {$endif TEST_REGEXP}
  6473. nil)))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6474. Insert(CB1);
  6475. Insert(New(PLabel, Init(R1, label_find_options, CB1)));
  6476. 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;
  6477. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6478. New(RB1, Init(R2,
  6479. NewSItem(label_find_forward,
  6480. NewSItem(label_find_backward,
  6481. nil))));
  6482. Insert(RB1);
  6483. Insert(New(PLabel, Init(R1, label_find_direction, RB1)));
  6484. 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;
  6485. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6486. New(RB2, Init(R2,
  6487. NewSItem(label_find_global,
  6488. NewSItem(label_find_selectedtext,
  6489. nil))));
  6490. Insert(RB2);
  6491. Insert(New(PLabel, Init(R1, label_find_scope, RB2)));
  6492. 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;
  6493. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6494. New(RB3, Init(R2,
  6495. NewSItem(label_find_fromcursor,
  6496. NewSItem(label_find_entirescope,
  6497. nil))));
  6498. Insert(RB3);
  6499. Insert(New(PLabel, Init(R1, label_find_origin, RB3)));
  6500. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6501. Okbutton:=New(PButton, Init(R, btn_OK, cmOK, bfDefault));
  6502. Insert(OkButton);
  6503. R.Move(19,0);
  6504. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6505. end;
  6506. IL1^.Select;
  6507. CreateFindDialog := D;
  6508. end;
  6509. function CreateReplaceDialog: PDialog;
  6510. var R,R1,R2: TRect;
  6511. D: PDialog;
  6512. Control : PView;
  6513. IL1: PEditorInputLine;
  6514. IL2: PEditorInputLine;
  6515. CB1: PCheckBoxes;
  6516. RB1,RB2,RB3: PRadioButtons;
  6517. begin
  6518. R.Assign(0,0,56,18);
  6519. New(D, Init(R, dialog_replace));
  6520. with D^ do
  6521. begin
  6522. Options:=Options or ofCentered;
  6523. GetExtent(R); R.Grow(-3,-2);
  6524. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6525. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6526. New(IL1, Init(R2, FindStrSize));
  6527. IL1^.Data^:=FindStr;
  6528. Insert(IL1);
  6529. Insert(New(PLabel, Init(R1, label_replace_texttofind, IL1)));
  6530. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6531. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6532. Insert(Control);
  6533. R1.Copy(R); R1.Move(0,2); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6534. R2.Copy(R); R2.Move(0,2);R2.B.X:=R2.B.X-3;
  6535. R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6536. New(IL2, Init(R2, FindStrSize));
  6537. IL2^.Data^:=ReplaceStr;
  6538. Insert(IL2);
  6539. Insert(New(PLabel, Init(R1, label_replace_newtext, IL2)));
  6540. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6541. Control := New(PHistory, Init(R1, IL2, TextReplaceId));
  6542. Insert(Control);
  6543. 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;
  6544. R2.Copy(R1); R2.Move(0,1);
  6545. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}4{$else}3{$endif};
  6546. New(CB1, Init(R2,
  6547. NewSItem(label_replace_casesensitive,
  6548. NewSItem(label_replace_wholewordsonly,
  6549. NewSItem(label_replace_promptonreplace,
  6550. {$ifdef TEST_REGEXP}
  6551. NewSItem(label_find_useregexp,
  6552. {$endif TEST_REGEXP}
  6553. nil))))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6554. Insert(CB1);
  6555. Insert(New(PLabel, Init(R1, label_replace_options, CB1)));
  6556. 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;
  6557. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6558. New(RB1, Init(R2,
  6559. NewSItem(label_replace_forward,
  6560. NewSItem(label_replace_backward,
  6561. nil))));
  6562. Insert(RB1);
  6563. Insert(New(PLabel, Init(R1, label_replace_direction, RB1)));
  6564. 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;
  6565. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6566. New(RB2, Init(R2,
  6567. NewSItem(label_replace_global,
  6568. NewSItem(label_replace_selectedtext,
  6569. nil))));
  6570. Insert(RB2);
  6571. Insert(New(PLabel, Init(R1, label_replace_scope, RB2)));
  6572. 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;
  6573. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6574. New(RB3, Init(R2,
  6575. NewSItem(label_replace_fromcursor,
  6576. NewSItem(label_replace_entirescope,
  6577. nil))));
  6578. Insert(RB3);
  6579. Insert(New(PLabel, Init(R1, label_replace_origin, RB3)));
  6580. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10; R.Move(-10,0);
  6581. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6582. R.Move(11,0); R.B.X:=R.A.X+14;
  6583. Insert(New(PButton, Init(R, btn_replace_changeall, cmYes, bfNormal)));
  6584. R.Move(15,0); R.B.X:=R.A.X+10;
  6585. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6586. end;
  6587. IL1^.Select;
  6588. CreateReplaceDialog := D;
  6589. end;
  6590. function CreateGotoLineDialog(Info: pointer): PDialog;
  6591. var D: PDialog;
  6592. R,R1,R2: TRect;
  6593. Control : PView;
  6594. IL: PEditorInputLine;
  6595. begin
  6596. R.Assign(0,0,40,7);
  6597. New(D, Init(R, dialog_gotoline));
  6598. with D^ do
  6599. begin
  6600. Options:=Options or ofCentered;
  6601. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  6602. R1.Copy(R); R1.B.X:=27; R2.Copy(R);
  6603. R2.B.X:=R2.B.X-3;R2.A.X:=27;
  6604. New(IL, Init(R2,5));
  6605. with TGotoLineDialogRec(Info^) do
  6606. IL^.SetValidator(New(PRangeValidator, Init(1, Lines)));
  6607. Insert(IL);
  6608. Insert(New(PLabel, Init(R1, label_gotoline_linenumber, IL)));
  6609. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6610. Control := New(PHistory, Init(R1, IL, GotoId));
  6611. Insert(Control);
  6612. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6613. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6614. R.Move(15,0);
  6615. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6616. end;
  6617. IL^.Select;
  6618. CreateGotoLineDialog:=D;
  6619. end;
  6620. function StdEditorDialog(Dialog: Integer; Info: Pointer): Word;
  6621. var
  6622. R: TRect;
  6623. T: TPoint;
  6624. Re: word;
  6625. Name: string;
  6626. DriveNumber : byte;
  6627. StoreDir,StoreDir2 : DirStr;
  6628. Title,DefExt: string;
  6629. AskOW: boolean;
  6630. begin
  6631. case Dialog of
  6632. edOutOfMemory:
  6633. StdEditorDialog := AdvMessageBox(msg_notenoughmemoryforthisoperation,
  6634. nil, mfInsertInApp+ mfError + mfOkButton);
  6635. edReadError:
  6636. StdEditorDialog := AdvMessageBox(msg_errorreadingfile,
  6637. @Info, mfInsertInApp+ mfError + mfOkButton);
  6638. edWriteError:
  6639. StdEditorDialog := AdvMessageBox(msg_errorwritingfile,
  6640. @Info, mfInsertInApp+ mfError + mfOkButton);
  6641. edSaveError:
  6642. StdEditorDialog := AdvMessageBox(msg_errorsavingfile,
  6643. @Info, mfInsertInApp+ mfError + mfOkButton);
  6644. edCreateError:
  6645. StdEditorDialog := AdvMessageBox(msg_errorcreatingfile,
  6646. @Info, mfInsertInApp+ mfError + mfOkButton);
  6647. edSaveModify:
  6648. StdEditorDialog := AdvMessageBox(msg_filehasbeenmodifiedsave,
  6649. @Info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6650. edSaveUntitled:
  6651. StdEditorDialog := AdvMessageBox(msg_saveuntitledfile,
  6652. nil, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6653. edChangedOnloading:
  6654. StdEditorDialog := AdvMessageBox(msg_filehadtoolonglines,
  6655. Info, mfInsertInApp+ mfOKButton + mfInformation);
  6656. edFileOnDiskChanged:
  6657. StdEditorDialog := AdvMessageBox(msg_filewasmodified,
  6658. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6659. edReloadDiskmodifiedFile:
  6660. StdEditorDialog := AdvMessageBox(msg_reloaddiskmodifiedfile,
  6661. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6662. edReloadDiskAndIDEModifiedFile:
  6663. StdEditorDialog := AdvMessageBox(msg_reloaddiskandidemodifiedfile,
  6664. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6665. edSaveAs,edWriteBlock,edReadBlock:
  6666. begin
  6667. Name:=PString(Info)^;
  6668. GetDir(0,StoreDir);
  6669. DriveNumber:=0;
  6670. if (Length(FileDir)>1) and (FileDir[2]=':') then
  6671. begin
  6672. { does not assume that lowercase are greater then uppercase ! }
  6673. if (FileDir[1]>='a') and (FileDir[1]<='z') then
  6674. DriveNumber:=Ord(FileDir[1])-ord('a')+1
  6675. else
  6676. DriveNumber:=Ord(FileDir[1])-ord('A')+1;
  6677. GetDir(DriveNumber,StoreDir2);
  6678. {$I-}
  6679. ChDir(Copy(FileDir,1,2));
  6680. EatIO;
  6681. {$I+}
  6682. end;
  6683. if FileDir<>'' then
  6684. begin
  6685. {$I-}
  6686. ChDir(TrimEndSlash(FileDir));
  6687. EatIO;
  6688. {$I+}
  6689. end;
  6690. case Dialog of
  6691. edSaveAs :
  6692. begin
  6693. Title:=dialog_savefileas;
  6694. DefExt:='*'+DefaultSaveExt;
  6695. end;
  6696. edWriteBlock :
  6697. begin
  6698. Title:=dialog_writeblocktofile;
  6699. DefExt:='*.*';
  6700. end;
  6701. edReadBlock :
  6702. begin
  6703. Title:=dialog_readblockfromfile;
  6704. DefExt:='*.*';
  6705. end;
  6706. else begin Title:='???'; DefExt:=''; end;
  6707. end;
  6708. Re:=Application^.ExecuteDialog(New(PFileDialog, Init(DefExt,
  6709. Title, label_name, fdOkButton, FileId)), @Name);
  6710. case Dialog of
  6711. edSaveAs :
  6712. begin
  6713. if ExtOf(Name)='' then
  6714. Name:=Name+DefaultSaveExt;
  6715. AskOW:=(Name<>PString(Info)^);
  6716. end;
  6717. edWriteBlock :
  6718. begin
  6719. if ExtOf(Name)='' then
  6720. Name:=Name+DefaultSaveExt;
  6721. AskOW:=true;
  6722. end;
  6723. edReadBlock : AskOW:=false;
  6724. else AskOW:=true;
  6725. end;
  6726. if (Re<>cmCancel) and AskOW then
  6727. begin
  6728. FileDir:=DirOf(FExpand(Name));
  6729. if ExistsFile(Name) then
  6730. if EditorDialog(edReplaceFile,@Name)<>cmYes then
  6731. Re:=cmCancel;
  6732. end;
  6733. if DriveNumber<>0 then
  6734. ChDir(StoreDir2);
  6735. if StoreDir<>'' then
  6736. ChDir(TrimEndSlash(StoreDir));
  6737. if Re<>cmCancel then
  6738. PString(Info)^:=Name;
  6739. StdEditorDialog := Re;
  6740. end;
  6741. edGotoLine:
  6742. StdEditorDialog :=
  6743. Application^.ExecuteDialog(CreateGotoLineDialog(Info), Info);
  6744. edFind:
  6745. StdEditorDialog :=
  6746. Application^.ExecuteDialog(CreateFindDialog, Info);
  6747. edSearchFailed:
  6748. StdEditorDialog := AdvMessageBox(msg_searchstringnotfound,
  6749. nil, mfInsertInApp+ mfError + mfOkButton);
  6750. edReplace:
  6751. StdEditorDialog :=
  6752. Application^.ExecuteDialog(CreateReplaceDialog, Info);
  6753. edReplacePrompt:
  6754. begin
  6755. { Avoid placing the dialog on the same line as the cursor }
  6756. R.Assign(0, 1, 40, 8);
  6757. R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  6758. Desktop^.MakeGlobal(R.B, T);
  6759. Inc(T.Y);
  6760. if PPoint(Info)^.Y <= T.Y then
  6761. R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  6762. StdEditorDialog := AdvMessageBoxRect(R, msg_replacethisoccourence,
  6763. nil, mfInsertInApp+ mfYesNoCancel + mfInformation);
  6764. end;
  6765. edReplaceFile :
  6766. StdEditorDialog :=
  6767. AdvMessageBox(msg_fileexistsoverwrite,@Info,mfInsertInApp+mfConfirmation+
  6768. mfYesButton+mfNoButton);
  6769. end;
  6770. end;
  6771. procedure RegisterWEditor;
  6772. begin
  6773. {$ifndef NOOBJREG}
  6774. {$endif}
  6775. end;
  6776. END.