weditor.pas 196 KB

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