weditor.pas 198 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Code editor template objects
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$I globdir.inc}
  12. unit WEditor;
  13. interface
  14. {tes}
  15. uses
  16. Dos,Objects,Drivers,Views,Dialogs,Menus,
  17. FVConsts,
  18. WUtils,WViews;
  19. const
  20. cmFileNameChanged = 51234;
  21. cmASCIIChar = 51235;
  22. cmClearLineHighlights = 51236;
  23. cmSaveCancelled = 51237;
  24. cmBreakLine = 51238;
  25. cmSelStart = 51239;
  26. cmSelEnd = 51240;
  27. cmLastCursorPos = 51241;
  28. cmIndentBlock = 51242;
  29. cmUnIndentBlock = 51243;
  30. cmSelectLine = 51244;
  31. cmWriteBlock = 51245;
  32. cmReadBlock = 51246;
  33. cmPrintBlock = 51247;
  34. cmResetDebuggerRow = 51248;
  35. cmAddChar = 51249;
  36. cmExpandCodeTemplate = 51250;
  37. cmUpperCase = 51251;
  38. cmLowerCase = 51252;
  39. cmWindowStart = 51253;
  40. cmWindowEnd = 51254;
  41. cmFindMatchingDelimiter= 51255;
  42. cmFindMatchingDelimiterBack=51256;
  43. cmActivateMenu = 51257;
  44. cmWordLowerCase = 51258;
  45. cmWordUpperCase = 51259;
  46. cmOpenAtCursor = 51260;
  47. cmBrowseAtCursor = 51261;
  48. cmInsertOptions = 51262;
  49. cmToggleCase = 51263;
  50. cmCreateFold = 51264;
  51. cmToggleFold = 51265;
  52. cmCollapseFold = 51266;
  53. cmExpandFold = 51267;
  54. cmDelToEndOfWord = 51268;
  55. cmInputLineLen = 51269;
  56. EditorTextBufSize = 32768;
  57. MaxLineLength = 255;
  58. MaxLineCount = 2000000;
  59. CodeTemplateCursorChar = '|'; { char to signal cursor pos in templates }
  60. efBackupFiles = $00000001;
  61. efInsertMode = $00000002;
  62. efAutoIndent = $00000004;
  63. efUseTabCharacters = $00000008;
  64. efBackSpaceUnindents = $00000010;
  65. efPersistentBlocks = $00000020;
  66. efSyntaxHighlight = $00000040;
  67. efBlockInsCursor = $00000080;
  68. efVerticalBlocks = $00000100;
  69. efHighlightColumn = $00000200;
  70. efHighlightRow = $00000400;
  71. efAutoBrackets = $00000800;
  72. efExpandAllTabs = $00001000;
  73. efKeepTrailingSpaces = $00002000;
  74. efCodeComplete = $00004000;
  75. efFolds = $00008000;
  76. efNoIndent = $00010000;
  77. efKeepLineAttr = $00020000;
  78. efStoreContent = $80000000;
  79. attrAsm = 1;
  80. attrComment = 2;
  81. attrForceFull = 128;
  82. attrAll = attrAsm+attrComment;
  83. edOutOfMemory = 0;
  84. edReadError = 1;
  85. edWriteError = 2;
  86. edCreateError = 3;
  87. edSaveModify = 4;
  88. edSaveUntitled = 5;
  89. edSaveAs = 6;
  90. edFind = 7;
  91. edSearchFailed = 8;
  92. edReplace = 9;
  93. edReplacePrompt = 10;
  94. edTooManyLines = 11;
  95. edGotoLine = 12;
  96. edReplaceFile = 13;
  97. edWriteBlock = 14;
  98. edReadBlock = 15;
  99. edFileOnDiskChanged = 16;
  100. edChangedOnloading = 17;
  101. edSaveError = 18;
  102. edReloadDiskmodifiedFile = 19;
  103. edReloadDiskAndIDEModifiedFile = 20;
  104. ffmOptions = $0007; ffsOptions = 0;
  105. ffmDirection = $0008; ffsDirection = 3;
  106. ffmScope = $0010; ffsScope = 4;
  107. ffmOrigin = $0020; ffsOrigin = 5;
  108. ffDoReplace = $0040;
  109. ffReplaceAll = $0080;
  110. ffCaseSensitive = $0001;
  111. ffWholeWordsOnly = $0002;
  112. ffPromptOnReplace = $0004;
  113. ffForward = $0000;
  114. ffBackward = $0008;
  115. ffGlobal = $0000;
  116. ffSelectedText = $0010;
  117. ffFromCursor = $0000;
  118. ffEntireScope = $0020;
  119. {$ifdef TEST_REGEXP}
  120. ffUseRegExp = $0100;
  121. ffmUseRegExpFind = $0004;
  122. ffmOptionsFind = $0003;
  123. ffsUseRegExpFind = 8 - 2;
  124. ffmUseRegExpReplace = $0008;
  125. ffsUseRegExpReplace = 8 - 3;
  126. {$endif TEST_REGEXP}
  127. coTextColor = 0;
  128. coWhiteSpaceColor = 1;
  129. coCommentColor = 2;
  130. coReservedWordColor = 3;
  131. coIdentifierColor = 4;
  132. coStringColor = 5;
  133. coNumberColor = 6;
  134. coAssemblerColor = 7;
  135. coSymbolColor = 8;
  136. coDirectiveColor = 9;
  137. coHexNumberColor = 10;
  138. coTabColor = 11;
  139. coAsmReservedColor = 12;
  140. coBreakColor = 13;
  141. coFirstColor = 0;
  142. coLastColor = coBreakColor;
  143. lfBreakpoint = $0001;
  144. lfHighlightRow = $0002;
  145. lfDebuggerRow = $0004;
  146. lfSpecialRow = $0008;
  147. eaMoveCursor = 1;
  148. eaInsertLine = 2;
  149. eaInsertText = 3;
  150. eaDeleteLine = 4;
  151. eaDeleteText = 5;
  152. eaSelectionChanged = 6;
  153. eaCut = 7;
  154. eaPaste = 8;
  155. eaPasteWin = 9;
  156. eaDelChar = 10;
  157. eaClear = 11;
  158. eaCopyBlock = 12;
  159. eaMoveBlock = 13;
  160. eaDelBlock = 14;
  161. eaReadBlock = 15;
  162. eaIndentBlock = 16;
  163. eaUnindentBlock = 17;
  164. eaOverwriteText = 18;
  165. eaUpperCase = 19;
  166. eaLowerCase = 20;
  167. eaToggleCase = 21;
  168. eaDummy = 22;
  169. LastAction = eaDummy;
  170. ActionString : array [0..LastAction-1] of string[13] =
  171. ('','Move','InsLine','InsText','DelLine','DelText',
  172. 'SelChange','Cut','Paste','PasteWin','DelChar','Clear',
  173. 'CopyBlock','MoveBlock','DelBlock',
  174. 'ReadBlock','IndentBlock','UnindentBlock','Overwrite',
  175. 'UpperCase','LowerCase','ToggleCase');
  176. CIndicator = #2#3#1;
  177. CEditor = #33#34#35#36#37#38#39#40#41#42#43#44#45#46#47#48#49#50;
  178. TAB = #9;
  179. FindStrSize = 79;
  180. type
  181. Tcentre = (do_not_centre,do_centre);
  182. PCustomCodeEditor = ^TCustomCodeEditor;
  183. PEditorLineInfo = ^TEditorLineInfo;
  184. PFoldCollection = ^TFoldCollection;
  185. PFold = ^TFold;
  186. TFold = object(TObject)
  187. constructor Init(AEditor: PCustomCodeEditor; AParentFold: PFold; ACollapsed: boolean);
  188. procedure AddReference(P: PObject);
  189. procedure RemoveReference(P: PObject);
  190. procedure AddLineReference(Line: PEditorLineInfo);
  191. procedure RemoveLineReference(Line: PEditorLineInfo);
  192. procedure AddChildReference(Fold: PFold);
  193. procedure RemoveChildReference(Fold: PFold);
  194. function CanDispose: boolean;
  195. function IsCollapsed: boolean;
  196. function IsParent(AFold: PFold): boolean;
  197. function GetLineCount: sw_integer;
  198. procedure Collapse(ACollapse: boolean);
  199. procedure Changed;
  200. function GetLevel: sw_integer;
  201. destructor Done; virtual;
  202. public
  203. ParentFold: PFold;
  204. Collapsed_: boolean;
  205. ReferenceCount: sw_integer;
  206. Editor: PCustomCodeEditor;
  207. LineCount_: sw_integer;
  208. Childs: PFoldCollection;
  209. end;
  210. TFoldCollection = object(TCollection)
  211. function At(Index: sw_Integer): PFold;
  212. end;
  213. TEditorLineInfo = object(TObject)
  214. Editor: PCustomCodeEditor;
  215. Format : PString;
  216. BeginsWithAsm,
  217. EndsWithAsm : boolean;
  218. BeginsWithComment,
  219. EndsInSingleLineComment,
  220. EndsWithComment : boolean;
  221. BeginsWithDirective,
  222. EndsWithDirective : boolean;
  223. BeginCommentType,EndCommentType : byte;
  224. Fold: PFold;
  225. constructor Init(AEditor: PCustomCodeEditor);
  226. destructor Done; virtual;
  227. function GetFormat: string;
  228. procedure SetFormat(const AFormat: string);
  229. procedure SetFold(AFold: PFold);
  230. { Syntax information is now generated separately for each editor instance.
  231. This is not neccessary for a one-language IDE, but this unit contains
  232. a _generic_ editor object, which should be (and is) as flexible as
  233. possible.
  234. The overhead caused by generating the same syntax info for ex.
  235. twice isn't so much... - Gabor }
  236. end;
  237. PEditorLineInfoCollection = ^TEditorLineInfoCollection;
  238. TEditorLineInfoCollection = object(TCollection)
  239. function At(Index: sw_Integer): PEditorLineInfo;
  240. end;
  241. PCustomLine = ^TCustomLine;
  242. TCustomLine = object(TObject)
  243. constructor Init(const AText: string; AFlags: longint);
  244. {a}function GetText: string; virtual;
  245. {a}procedure SetText(const AText: string); virtual;
  246. {a}function GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual;
  247. {a}function GetFlags: longint; virtual;
  248. {a}procedure SetFlags(AFlags: longint); virtual;
  249. function IsFlagSet(AFlag: longint): boolean; {$ifdef USEINLINE}inline;{$endif}
  250. procedure SetFlagState(AFlag: longint; ASet: boolean);
  251. destructor Done; virtual;
  252. public { internal use only! }
  253. {a}procedure AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor); virtual;
  254. {a}procedure RemoveEditorInfo(AEditor: PCustomCodeEditor); virtual;
  255. end;
  256. PLineCollection = ^TLineCollection;
  257. TLineCollection = object(TCollection)
  258. function At(Index: sw_Integer): PCustomLine;
  259. end;
  260. PEditorAction = ^TEditorAction;
  261. TEditorAction = object(TObject)
  262. StartPos : TPoint;
  263. EndPos : TPoint;
  264. Text : PString;
  265. ActionCount : longint;
  266. Flags : longint;
  267. Action : byte;
  268. IsGrouped : boolean;
  269. TimeStamp : longint; { this is needed to keep track of line number &
  270. position changes (for ex. for symbol browser)
  271. the line&pos references (eg. symbol info) should
  272. also contain such a timestamp. this will enable
  273. to determine which changes have been made since
  274. storage of the information and thus calculate
  275. the (probably) changed line & position information,
  276. so, we can still jump to the right position in the
  277. editor even when it is heavily modified - Gabor }
  278. constructor init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint);
  279. constructor init_group(act:byte);
  280. function is_grouped_action : boolean;
  281. destructor done; virtual;
  282. end;
  283. PEditorActionCollection = ^TEditorActionCollection;
  284. TEditorActionCollection = object(TCollection)
  285. CurrentGroupedAction : PEditorAction;
  286. GroupLevel : longint;
  287. function At(Idx : sw_integer) : PEditorAction;
  288. end;
  289. TSpecSymbolClass =
  290. (ssCommentPrefix,ssCommentSingleLinePrefix,ssCommentSuffix,ssStringPrefix,ssStringSuffix,
  291. ssDirectivePrefix,ssDirectiveSuffix,ssAsmPrefix,ssAsmSuffix);
  292. TEditorBookMark = record
  293. Valid : boolean;
  294. Pos : TPoint;
  295. end;
  296. TCompleteState = (csInactive,csOffering,csDenied);
  297. PEditorBinding = ^TEditorBinding;
  298. PEditorBindingCollection = ^TEditorBindingCollection;
  299. TEditorBindingCollection = object(TCollection)
  300. function At(Index: sw_Integer): PEditorBinding;
  301. end;
  302. TEditorBinding = object(TObject)
  303. Editor : PCustomCodeEditor;
  304. constructor Init(AEditor: PCustomCodeEditor);
  305. destructor Done; virtual;
  306. end;
  307. PCustomCodeEditorCore = ^TCustomCodeEditorCore;
  308. TCustomCodeEditorCore = object(TObject)
  309. protected
  310. Bindings : PEditorBindingCollection;
  311. LockFlag : sw_integer;
  312. ChangedLine : sw_integer;
  313. ContentsChangedCalled : boolean;
  314. LimitsChangedCalled : boolean;
  315. ModifiedChangedCalled : boolean;
  316. TabSizeChangedCalled : boolean;
  317. StoreUndoChangedCalled : boolean;
  318. {$ifdef TEST_PARTIAL_SYNTAX}
  319. LastSyntaxedLine : sw_integer;
  320. SyntaxComplete : boolean;
  321. {$endif TEST_PARTIAL_SYNTAX}
  322. public
  323. constructor Init;
  324. procedure BindEditor(AEditor: PCustomCodeEditor);
  325. procedure UnBindEditor(AEditor: PCustomCodeEditor);
  326. function IsEditorBound(AEditor: PCustomCodeEditor): boolean;
  327. function GetBindingCount: sw_integer;
  328. function GetBindingIndex(AEditor: PCustomCodeEditor): sw_integer;
  329. function SearchBinding(AEditor: PCustomCodeEditor): PEditorBinding;
  330. function CanDispose: boolean;
  331. destructor Done; virtual;
  332. public
  333. {a}function GetModified: boolean; virtual;
  334. function GetChangedLine: sw_integer;
  335. {a}procedure SetModified(AModified: boolean); virtual;
  336. {a}function GetStoreUndo: boolean; virtual;
  337. {a}procedure SetStoreUndo(AStore: boolean); virtual;
  338. {a}function GetSyntaxCompleted: boolean; virtual;
  339. {a}procedure SetSyntaxCompleted(SC: boolean); virtual;
  340. {a}function GetTabSize: integer; virtual;
  341. {a}procedure SetTabSize(ATabSize: integer); virtual;
  342. {a}function GetIndentSize: integer; virtual;
  343. {a}procedure SetIndentSize(AIndentSize: integer); virtual;
  344. function IsClipboard: Boolean;
  345. public
  346. { Notifications }
  347. procedure BindingsChanged;
  348. procedure ContentsChanged;
  349. procedure LimitsChanged;
  350. procedure ModifiedChanged;
  351. procedure TabSizeChanged;
  352. procedure StoreUndoChanged;
  353. {a}procedure DoContentsChanged; virtual;
  354. {a}procedure DoLimitsChanged; virtual;
  355. {a}procedure DoModifiedChanged; virtual;
  356. {a}procedure DoTabSizeChanged; virtual;
  357. {a}procedure DoStoreUndoChanged; virtual;
  358. {a}procedure DoSyntaxStateChanged; virtual;
  359. function GetLastVisibleLine : sw_integer;
  360. public
  361. { Storage }
  362. function LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean; virtual;
  363. function SaveToStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; virtual;
  364. function SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean; virtual;
  365. protected
  366. { Text & info storage abstraction }
  367. {a}procedure ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual;
  368. {a}procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); virtual;
  369. {a}function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; virtual;
  370. {a}procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); virtual;
  371. public
  372. { Text & info storage abstraction }
  373. function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer;
  374. function LinePosToCharIdx(Line,X: sw_integer): sw_integer;
  375. {a}function GetLineCount: sw_integer; virtual;
  376. {a}function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  377. {a}function GetLineText(LineNo: sw_integer): string; virtual;
  378. {a}procedure SetDisplayText(I: sw_integer;const S: string); virtual;
  379. {a}function GetDisplayText(I: sw_integer): string; virtual;
  380. {a}procedure SetLineText(I: sw_integer;const S: string); virtual;
  381. procedure GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:string); virtual;
  382. function GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): string; virtual;
  383. procedure SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer;const S: string); virtual;
  384. {a}procedure DeleteAllLines; virtual;
  385. {a}procedure DeleteLine(I: sw_integer); virtual;
  386. {a}function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  387. {a}procedure AddLine(const S: string); virtual;
  388. {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual;
  389. {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual;
  390. public
  391. procedure Lock(AEditor: PCustomCodeEditor);
  392. procedure UnLock(AEditor: PCustomCodeEditor);
  393. function Locked: boolean;
  394. public
  395. { Syntax highlight }
  396. function UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  397. function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
  398. function DoUpdateAttrs(Editor: PCustomCodeEditor; FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  399. function DoUpdateAttrsRange(Editor: PCustomCodeEditor; FromLine, ToLine: sw_integer;
  400. Attrs: byte): sw_integer; virtual;
  401. public
  402. { Undo info storage }
  403. {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
  404. {a}procedure AddGroupedAction(AAction : byte); virtual;
  405. {a}procedure CloseGroupedAction(AAction : byte); virtual;
  406. {a}function GetUndoActionCount: sw_integer; virtual;
  407. {a}function GetRedoActionCount: sw_integer; virtual;
  408. procedure UpdateUndoRedo(cm : word; action : byte);virtual;
  409. end;
  410. TCaseAction = (caToLowerCase,caToUpperCase,caToggleCase);
  411. TCustomCodeEditor = object(TScroller)
  412. SelStart : TPoint;
  413. SelEnd : TPoint;
  414. Highlight : TRect;
  415. CurPos : TPoint;
  416. ELockFlag : integer;
  417. NoSelect : Boolean;
  418. AlwaysShowScrollBars: boolean;
  419. public
  420. { constructor Load(var S: TStream);
  421. procedure Store(var S: TStream);}
  422. procedure ConvertEvent(var Event: TEvent); virtual;
  423. procedure HandleEvent(var Event: TEvent); virtual;
  424. procedure SetState(AState: Word; Enable: Boolean); virtual;
  425. procedure LocalMenu(P: TPoint); virtual;
  426. function GetLocalMenu: PMenu; virtual;
  427. function GetCommandTarget: PView; virtual;
  428. function CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup; virtual;
  429. function GetPalette: PPalette; virtual;
  430. public
  431. procedure Draw; virtual;
  432. procedure DrawCursor; virtual;
  433. { this is the only way I found to avoid
  434. having the cursor being updated if lock is on PM }
  435. procedure ResetCursor; virtual;
  436. procedure DrawIndicator; virtual;
  437. public
  438. {a}function GetFlags: longint; virtual;
  439. {a}procedure SetFlags(AFlags: longint); virtual;
  440. {a}function GetModified: boolean; virtual;
  441. {a}procedure SetModified(AModified: boolean); virtual;
  442. {a}function GetStoreUndo: boolean; virtual;
  443. {a}procedure SetStoreUndo(AStore: boolean); virtual;
  444. {a}function GetSyntaxCompleted: boolean; virtual;
  445. {a}procedure SetSyntaxCompleted(SC: boolean); virtual;
  446. {a}function GetLastSyntaxedLine: sw_integer; virtual;
  447. {a}procedure SetLastSyntaxedLine(ALine: sw_integer); virtual;
  448. function IsFlagSet(AFlag: longint): boolean;{$ifdef USEINLINE}inline;{$endif}
  449. function GetReservedColCount: sw_integer; virtual;
  450. {a}function GetTabSize: integer; virtual;
  451. {a}procedure SetTabSize(ATabSize: integer); virtual;
  452. {a}function GetIndentSize: integer; virtual;
  453. {a}procedure SetIndentSize(AIndentSize: integer); virtual;
  454. {a}function IsReadOnly: boolean; virtual;
  455. {a}function IsClipboard: Boolean; virtual;
  456. {a}function GetInsertMode: boolean; virtual;
  457. {a}procedure SetInsertMode(InsertMode: boolean); virtual;
  458. procedure SetCurPtr(X,Y: sw_integer); virtual;
  459. procedure GetSelectionArea(var StartP,EndP: TPoint); virtual;
  460. procedure SetSelection(A, B: TPoint); virtual;
  461. procedure SetHighlight(A, B: TPoint); virtual;
  462. procedure ChangeCaseArea(StartP,EndP: TPoint; CaseAction: TCaseAction); virtual;
  463. procedure SetLineFlagState(LineNo: sw_integer; Flags: longint; ASet: boolean);
  464. procedure SetLineFlagExclusive(Flags: longint; LineNo: sw_integer);
  465. procedure Update; virtual;
  466. procedure ScrollTo(X, Y: sw_Integer);
  467. procedure TrackCursor(centre:Tcentre); virtual;
  468. procedure Lock; virtual;
  469. procedure UnLock; virtual;
  470. public
  471. { Text & info storage abstraction }
  472. {a}function GetLineCount: sw_integer; virtual;
  473. {a}function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  474. {a}function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
  475. {a}function LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual;
  476. {a}function GetLineText(I: sw_integer): string; virtual;
  477. {a}procedure SetDisplayText(I: sw_integer;const S: string); virtual;
  478. {a}function GetDisplayText(I: sw_integer): string; virtual;
  479. {a}procedure SetLineText(I: sw_integer;const S: string); virtual;
  480. {a}procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:string); virtual;
  481. {a}function GetLineFormat(I: sw_integer): string; virtual;
  482. {a}procedure SetLineFormat(I: sw_integer;const S: string); virtual;
  483. {a}procedure DeleteAllLines; virtual;
  484. {a}procedure DeleteLine(I: sw_integer); virtual;
  485. {a}function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  486. {a}procedure AddLine(const S: string); virtual;
  487. {a}function GetErrorMessage: string; virtual;
  488. {a}procedure SetErrorMessage(const S: string); virtual;
  489. {a}procedure AdjustSelection(DeltaX, DeltaY: sw_integer);
  490. {a}procedure AdjustSelectionBefore(DeltaX, DeltaY: sw_integer);
  491. {a}procedure AdjustSelectionPos(OldCurPosX, OldCurPosY: sw_integer; DeltaX, DeltaY: sw_integer);
  492. {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual;
  493. {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual;
  494. {a}function LoadFromStream(Stream: PFastBufStream): boolean; virtual;
  495. {a}function SaveToStream(Stream: PStream): boolean; virtual;
  496. {a}function SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual;
  497. function LoadFromFile(const AFileName: string): boolean; virtual;
  498. function SaveToFile(const AFileName: string): boolean; virtual;
  499. public
  500. {a}function InsertFrom(Editor: PCustomCodeEditor): Boolean; virtual;
  501. {a}function InsertText(const S: string): Boolean; virtual;
  502. public
  503. procedure FlagsChanged(OldFlags: longint); virtual;
  504. {a}procedure BindingsChanged; virtual;
  505. procedure ContentsChanged; virtual;
  506. procedure LimitsChanged; virtual;
  507. procedure ModifiedChanged; virtual;
  508. procedure PositionChanged; virtual;
  509. procedure TabSizeChanged; virtual;
  510. procedure SyntaxStateChanged; virtual;
  511. procedure StoreUndoChanged; virtual;
  512. procedure SelectionChanged; virtual;
  513. procedure HighlightChanged; virtual;
  514. {a}procedure DoLimitsChanged; virtual;
  515. public
  516. { Syntax highlight support }
  517. {a}function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  518. {a}function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  519. {a}function IsReservedWord(const S: string): boolean; virtual;
  520. {a}function IsAsmReservedWord(const S: string): boolean; virtual;
  521. public
  522. { CodeTemplate support }
  523. {a}function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual;
  524. function SelectCodeTemplate(var ShortCut: string): boolean; virtual;
  525. { CodeComplete support }
  526. {a}function CompleteCodeWord(const WordS: string; var Text: string): boolean; virtual;
  527. {a}function GetCodeCompleteWord: string; virtual;
  528. {a}procedure SetCodeCompleteWord(const S: string); virtual;
  529. {a}function GetCodeCompleteFrag: string; virtual;
  530. {a}procedure SetCodeCompleteFrag(const S: string); virtual;
  531. function GetCompleteState: TCompleteState; virtual;
  532. procedure SetCompleteState(AState: TCompleteState); virtual;
  533. procedure ClearCodeCompleteWord; virtual;
  534. { Fold support }
  535. function GetMaxFoldLevel: sw_integer; virtual;
  536. function GetFoldStringWidth: sw_integer; virtual;
  537. procedure GetFoldStrings(EditorLine: sw_integer; var Prefix, Suffix: openstring); virtual;
  538. {a}function GetFoldCount: sw_integer; virtual;
  539. {a}function GetFold(Index: sw_integer): PFold; virtual;
  540. {a}procedure RegisterFold(AFold: PFold); virtual;
  541. {a}procedure UnRegisterFold(AFold: PFold); virtual;
  542. function ViewToEditorLine(ViewLine: sw_integer): sw_integer;
  543. function EditorToViewLine(EditorLine: sw_integer): sw_integer;
  544. procedure ViewToEditorPoint(P: TPoint; var NP: TPoint);
  545. procedure EditorToViewPoint(P: TPoint; var NP: TPoint);
  546. { Fold support }
  547. function CreateFold(StartY,EndY: sw_integer; Collapsed: boolean): boolean; virtual;
  548. procedure FoldChanged(Fold: PFold); virtual;
  549. procedure RemoveAllFolds; virtual;
  550. public
  551. { Syntax highlight }
  552. {a}function UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  553. {a}function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
  554. public
  555. { Undo info storage }
  556. {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
  557. {a}procedure AddGroupedAction(AAction : byte); virtual;
  558. {a}procedure CloseGroupedAction(AAction : byte); virtual;
  559. {a}function GetUndoActionCount: sw_integer; virtual;
  560. {a}function GetRedoActionCount: sw_integer; virtual;
  561. protected
  562. LastLocalCmd: word;
  563. KeyState : Integer;
  564. Bookmarks : array[0..9] of TEditorBookmark;
  565. DrawCalled,
  566. DrawCursorCalled: boolean;
  567. CurEvent : PEvent;
  568. procedure DrawLines(FirstLine: sw_integer);
  569. function Overwrite: boolean;
  570. function IsModal: boolean;
  571. procedure CheckSels;
  572. procedure CodeCompleteCheck;
  573. procedure CodeCompleteApply;
  574. procedure CodeCompleteCancel;
  575. procedure UpdateUndoRedo(cm : word; action : byte);
  576. procedure HideHighlight;
  577. function ShouldExtend: boolean;
  578. function ValidBlock: boolean;
  579. function GetLineFold(EditorLine: sw_integer): PFold;
  580. function IsLineVisible(EditorLine: sw_integer): boolean; virtual;
  581. function NextVisibleLine(StartLine: sw_integer; Down: boolean): sw_integer;
  582. procedure PushInfo(Const st : string);virtual;
  583. procedure PopInfo;virtual;
  584. public
  585. { Editor primitives }
  586. procedure SelectAll(Enable: boolean); virtual;
  587. public
  588. { Editor commands }
  589. SearchRunCount: integer;
  590. InASCIIMode: boolean;
  591. procedure Indent; virtual;
  592. procedure CharLeft; virtual;
  593. procedure CharRight; virtual;
  594. procedure WordLeft; virtual;
  595. procedure WordRight; virtual;
  596. procedure LineStart; virtual;
  597. procedure LineEnd; virtual;
  598. procedure LineUp; virtual;
  599. procedure LineDown; virtual;
  600. procedure PageUp; virtual;
  601. procedure PageDown; virtual;
  602. procedure TextStart; virtual;
  603. procedure TextEnd; virtual;
  604. procedure WindowStart; virtual;
  605. procedure WindowEnd; virtual;
  606. procedure JumpSelStart; virtual;
  607. procedure JumpSelEnd; virtual;
  608. procedure JumpMark(MarkIdx: integer); virtual;
  609. procedure DefineMark(MarkIdx: integer); virtual;
  610. procedure JumpToLastCursorPos; virtual;
  611. procedure FindMatchingDelimiter(ScanForward: boolean); virtual;
  612. procedure CreateFoldFromBlock; virtual;
  613. procedure ToggleFold; virtual;
  614. procedure CollapseFold; virtual;
  615. procedure ExpandFold; virtual;
  616. procedure UpperCase; virtual;
  617. procedure LowerCase; virtual;
  618. procedure WordLowerCase; virtual;
  619. procedure WordUpperCase; virtual;
  620. procedure InsertOptions; virtual;
  621. procedure ToggleCase; virtual;
  622. function InsertNewLine: Sw_integer; virtual;
  623. procedure BreakLine; virtual;
  624. procedure BackSpace; virtual;
  625. procedure DelChar; virtual;
  626. procedure DelWord; virtual;
  627. procedure DelToEndOfWord; virtual;
  628. procedure DelStart; virtual;
  629. procedure DelEnd; virtual;
  630. procedure DelLine; virtual;
  631. procedure InsMode; virtual;
  632. procedure StartSelect; virtual;
  633. procedure EndSelect; virtual;
  634. procedure DelSelect; virtual;
  635. procedure HideSelect; virtual;
  636. procedure CopyBlock; virtual;
  637. procedure MoveBlock; virtual;
  638. procedure IndentBlock; virtual;
  639. procedure UnindentBlock; virtual;
  640. procedure SelectWord; virtual;
  641. procedure SelectLine; virtual;
  642. procedure WriteBlock; virtual;
  643. procedure ReadBlock; virtual;
  644. procedure PrintBlock; virtual;
  645. procedure ExpandCodeTemplate; virtual;
  646. procedure AddChar(C: char); virtual;
  647. {$ifdef WinClipSupported}
  648. function ClipCopyWin: Boolean; virtual;
  649. function ClipPasteWin: Boolean; virtual;
  650. {$endif WinClipSupported}
  651. function ClipCopy: Boolean; virtual;
  652. procedure ClipCut; virtual;
  653. procedure ClipPaste; virtual;
  654. function GetCurrentWord : string;
  655. function GetCurrentWordArea(var StartP,EndP: TPoint): boolean;
  656. procedure Undo; virtual;
  657. procedure Redo; virtual;
  658. procedure Find; virtual;
  659. procedure Replace; virtual;
  660. procedure DoSearchReplace; virtual;
  661. procedure GotoLine; virtual;
  662. end;
  663. TCodeEditorDialog = function(Dialog: Integer; Info: Pointer): Word;
  664. TEditorInputLine = object(TInputLine)
  665. Procedure HandleEvent(var Event : TEvent);virtual;
  666. end;
  667. PEditorInputLine = ^TEditorInputLine;
  668. TSearchHelperDialog = object(TDialog)
  669. OkButton: PButton;
  670. Procedure HandleEvent(var Event : TEvent);virtual;
  671. end;
  672. PSearchHelperDialog = ^TSearchHelperDialog;
  673. const
  674. { used for ShiftDel and ShiftIns to avoid
  675. GetShiftState to be considered for extending
  676. selection (PM) }
  677. DontConsiderShiftState: boolean = false;
  678. CodeCompleteMinLen : byte = 4; { minimum length of text to try to complete }
  679. ToClipCmds : TCommandSet = ([cmCut,cmCopy,cmCopyWin,
  680. { cmUnselect should because like cut, copy, copywin:
  681. if there is a selection, it is active, else it isn't }
  682. cmUnselect]);
  683. FromClipCmds : TCommandSet = ([cmPaste]);
  684. NulClipCmds : TCommandSet = ([cmClear]);
  685. UndoCmd : TCommandSet = ([cmUndo]);
  686. RedoCmd : TCommandSet = ([cmRedo]);
  687. function ExtractTabs(S: string; TabSize: Sw_integer): string;
  688. function StdEditorDialog(Dialog: Integer; Info: Pointer): word;
  689. const
  690. DefaultSaveExt : string[12] = '.pas';
  691. FileDir : DirStr = '';
  692. EditorDialog : TCodeEditorDialog = {$ifdef fpc}@{$endif}StdEditorDialog;
  693. Clipboard : PCustomCodeEditor = nil;
  694. FindStr : String[FindStrSize] = '';
  695. ReplaceStr : String[FindStrSize] = '';
  696. FindReplaceEditor : PCustomCodeEditor = nil;
  697. FindFlags : word = ffPromptOnReplace;
  698. {$ifndef NO_UNTYPEDSET}
  699. {$define USE_UNTYPEDSET}
  700. {$endif ndef NO_UNTYPEDSET}
  701. WhiteSpaceChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = [#0,#32,#255];
  702. TabChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = [#9];
  703. HashChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['#'];
  704. AlphaChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['A'..'Z','a'..'z','_'];
  705. NumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['0'..'9'];
  706. HexNumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['0'..'9','A'..'F','a'..'f'];
  707. RealNumberChars {$ifdef USE_UNTYPEDSET}: set of char {$endif} = ['E','e','.'{,'+','-'}];
  708. procedure RegisterWEditor;
  709. implementation
  710. uses
  711. Strings,Video,MsgBox,App,StdDlg,Validate,
  712. {$ifdef WinClipSupported}
  713. WinClip,
  714. {$endif WinClipSupported}
  715. {$ifdef TEST_REGEXP}
  716. regexpr,
  717. {$endif TEST_REGEXP}
  718. WConsts,WCEdit;
  719. type
  720. RecordWord = sw_word;
  721. TFindDialogRec = packed record
  722. Find : String[FindStrSize];
  723. Options : RecordWord{longint};
  724. { checkboxes need 32 bits PM }
  725. { reverted to word in dialogs.TCluster for TP compatibility (PM) }
  726. { anyhow its complete nonsense : you can only have 16 fields
  727. but use a longint to store it !! }
  728. Direction: RecordWord;{ and tcluster has word size }
  729. Scope : RecordWord;
  730. Origin : RecordWord;
  731. end;
  732. TReplaceDialogRec = packed record
  733. Find : String[FindStrSize];
  734. Replace : String[FindStrSize];
  735. Options : RecordWord{longint};
  736. Direction: RecordWord;
  737. Scope : RecordWord;
  738. Origin : RecordWord;
  739. end;
  740. TGotoLineDialogRec = packed record
  741. LineNo : string[5];
  742. Lines : sw_integer;
  743. end;
  744. const
  745. kbShift = kbLeftShift+kbRightShift;
  746. const
  747. FirstKeyCount = 46;
  748. FirstKeys: array[0..FirstKeyCount * 2] of Word = (FirstKeyCount,
  749. Ord(^A), cmWordLeft, Ord(^B), cmJumpLine, Ord(^C), cmPageDown,
  750. Ord(^D), cmCharRight, Ord(^E), cmLineUp,
  751. Ord(^F), cmWordRight, Ord(^G), cmDelChar,
  752. Ord(^H), cmBackSpace, Ord(^J), cmExpandCodeTemplate,
  753. Ord(^K), $FF02, Ord(^L), cmSearchAgain,
  754. Ord(^M), cmNewLine, Ord(^N), cmBreakLine,
  755. Ord(^O), $FF03,
  756. Ord(^P), cmASCIIChar, Ord(^Q), $FF01,
  757. Ord(^R), cmPageUp, Ord(^S), cmCharLeft,
  758. Ord(^T), cmDelToEndOfWord, Ord(^U), cmUndo,
  759. Ord(^V), cmInsMode, Ord(^X), cmLineDown,
  760. Ord(^Y), cmDelLine, kbLeft, cmCharLeft,
  761. kbRight, cmCharRight, kbCtrlLeft, cmWordLeft,
  762. kbCtrlRight, cmWordRight, kbHome, cmLineStart,
  763. kbCtrlHome, cmWindowStart, kbCtrlEnd, cmWindowEnd,
  764. kbEnd, cmLineEnd, kbUp, cmLineUp,
  765. kbDown, cmLineDown, kbPgUp, cmPageUp,
  766. kbPgDn, cmPageDown, kbCtrlPgUp, cmTextStart,
  767. kbCtrlPgDn, cmTextEnd, kbIns, cmInsMode,
  768. kbDel, cmDelChar, kbShiftIns, cmPaste,
  769. kbShiftDel, cmCut, kbCtrlIns, cmCopy,
  770. kbCtrlDel, cmClear,
  771. kbCtrlGrayMul, cmToggleFold, kbCtrlGrayMinus, cmCollapseFold, kbCtrlGrayPlus, cmExpandFold);
  772. QuickKeyCount = 29;
  773. QuickKeys: array[0..QuickKeyCount * 2] of Word = (QuickKeyCount,
  774. Ord('A'), cmReplace, Ord('C'), cmTextEnd,
  775. Ord('D'), cmLineEnd, Ord('F'), cmFind,
  776. Ord('H'), cmDelStart, Ord('R'), cmTextStart,
  777. Ord('S'), cmLineStart, Ord('Y'), cmDelEnd,
  778. Ord('G'), cmJumpLine, Ord('A'), cmReplace,
  779. Ord('B'), cmSelStart, Ord('K'), cmSelEnd,
  780. Ord('P'), cmLastCursorPos,
  781. Ord('E'), cmWindowStart, Ord('T'), cmWindowStart,
  782. Ord('U'), cmWindowEnd, Ord('X'), cmWindowEnd,
  783. Ord('['), cmFindMatchingDelimiter, Ord(']'), cmFindMatchingDelimiterBack,
  784. Ord('0'), cmJumpMark0, Ord('1'), cmJumpMark1, Ord('2'), cmJumpMark2,
  785. Ord('3'), cmJumpMark3, Ord('4'), cmJumpMark4, Ord('5'), cmJumpMark5,
  786. Ord('6'), cmJumpMark6, Ord('7'), cmJumpMark7, Ord('8'), cmJumpMark8,
  787. Ord('9'), cmJumpMark9);
  788. BlockKeyCount = 30;
  789. BlockKeys: array[0..BlockKeyCount * 2] of Word = (BlockKeyCount,
  790. Ord('B'), cmStartSelect, Ord('C'), cmCopyBlock,
  791. Ord('H'), cmHideSelect, Ord('K'), cmEndSelect,
  792. Ord('Y'), cmDelSelect, Ord('V'), cmMoveBlock,
  793. Ord('I'), cmIndentBlock, Ord('U'), cmUnindentBlock,
  794. Ord('T'), cmSelectWord, Ord('L'), cmSelectLine,
  795. Ord('W'), cmWriteBlock, Ord('R'), cmReadBlock,
  796. Ord('P'), cmPrintBlock,
  797. Ord('N'), cmUpperCase, Ord('O'), cmLowerCase,
  798. Ord('D'), cmActivateMenu,
  799. Ord('E'), cmWordLowerCase, Ord('F'), cmWordUpperCase,
  800. Ord('S'), cmSave, Ord('A'), cmCreateFold,
  801. Ord('0'), cmSetMark0, Ord('1'), cmSetMark1, Ord('2'), cmSetMark2,
  802. Ord('3'), cmSetMark3, Ord('4'), cmSetMark4, Ord('5'), cmSetMark5,
  803. Ord('6'), cmSetMark6, Ord('7'), cmSetMark7, Ord('8'), cmSetMark8,
  804. Ord('9'), cmSetMark9);
  805. MiscKeyCount = 6;
  806. MiscKeys: array[0..MiscKeyCount * 2] of Word = (MiscKeyCount,
  807. Ord('A'), cmOpenAtCursor, Ord('B'), cmBrowseAtCursor,
  808. Ord('G'), cmJumpLine, Ord('O'), cmInsertOptions,
  809. Ord('U'), cmToggleCase, Ord('L'), cmSelectLine);
  810. KeyMap: array[0..3] of Pointer = (@FirstKeys, @QuickKeys, @BlockKeys, @MiscKeys);
  811. function ScanKeyMap(KeyMap: Pointer; KeyCode: Word): Word;
  812. type
  813. pword = ^word;
  814. var
  815. p : pword;
  816. count : sw_word;
  817. begin
  818. p:=keymap;
  819. count:=p^;
  820. inc(p);
  821. while (count>0) do
  822. begin
  823. if (lo(p^)=lo(keycode)) and
  824. ((hi(p^)=0) or (hi(p^)=hi(keycode))) then
  825. begin
  826. inc(p);
  827. scankeymap:=p^;
  828. Exit;
  829. end;
  830. inc(p,2);
  831. dec(count);
  832. end;
  833. scankeymap:=0;
  834. end;
  835. function IsWordSeparator(C: char): boolean;
  836. begin
  837. IsWordSeparator:=C in
  838. [' ',#0,#255,':','=','''','"',
  839. '.',',','/',';','$','#',
  840. '(',')','<','>','^','*',
  841. '+','-','?','&','[',']',
  842. '{','}','@','~','%','\',
  843. '!'];
  844. end;
  845. {function IsSpace(C: char): boolean;
  846. begin
  847. IsSpace:=C in[' ',#0,#255];
  848. end;}
  849. function LTrim(S: string): string;
  850. begin
  851. while (length(S)>0) and (S[1] in [#0,TAB,#32]) do
  852. Delete(S,1,1);
  853. LTrim:=S;
  854. end;
  855. { TAB are not same as spaces if UseTabs is set PM }
  856. function RTrim(S: string;cut_tabs : boolean): string;
  857. begin
  858. while (length(S)>0) and
  859. ((S[length(S)] in [#0,#32]) or
  860. ((S[Length(S)]=TAB) and cut_tabs)) do
  861. Delete(S,length(S),1);
  862. RTrim:=S;
  863. end;
  864. function Trim(S: string): string;
  865. begin
  866. Trim:=RTrim(LTrim(S),true);
  867. end;
  868. function EatIO: integer;
  869. begin
  870. EatIO:=IOResult;
  871. end;
  872. function ExistsFile(const FileName: string): boolean;
  873. var f: file;
  874. Exists: boolean;
  875. begin
  876. if FileName='' then Exists:=false else
  877. begin
  878. {$I-}
  879. Assign(f,FileName);
  880. Reset(f,1);
  881. Exists:=EatIO=0;
  882. Close(f);
  883. EatIO;
  884. {$I+}
  885. end;
  886. ExistsFile:=Exists;
  887. end;
  888. function StrToInt(const S: string): longint;
  889. var L: longint;
  890. C: integer;
  891. begin
  892. Val(S,L,C); if C<>0 then L:=-1;
  893. StrToInt:=L;
  894. end;
  895. function RExpand(const S: string; MinLen: byte): string;
  896. begin
  897. if length(S)<MinLen then
  898. RExpand:=S+CharStr(' ',MinLen-length(S))
  899. else
  900. RExpand:=S;
  901. end;
  902. {
  903. function upper(const s : string) : string;
  904. var
  905. i : Sw_word;
  906. begin
  907. for i:=1 to length(s) do
  908. if s[i] in ['a'..'z'] then
  909. upper[i]:=char(byte(s[i])-32)
  910. else
  911. upper[i]:=s[i];
  912. upper[0]:=s[0];
  913. end;
  914. }
  915. type TPosOfs = int64;
  916. function PosToOfs(const X,Y: sw_integer): TPosOfs;
  917. begin
  918. PosToOfs:=TPosOfs(y) shl (sizeof(sw_integer)*8) or x;
  919. end;
  920. function PosToOfsP(const P: TPoint): TPosOfs;
  921. begin
  922. PosToOfsP:=PosToOfs(P.X,P.Y);
  923. end;
  924. function PointOfs(P: TPoint): TPosOfs;
  925. begin
  926. PointOfs:={longint(P.Y)*MaxLineLength+P.X}PosToOfsP(P);
  927. end;
  928. function ExtractTabs(S: string; TabSize: Sw_integer): string;
  929. var
  930. P,PAdd: Sw_integer;
  931. begin
  932. p:=0;
  933. while p<length(s) do
  934. begin
  935. inc(p);
  936. if s[p]=TAB then
  937. begin
  938. PAdd:=TabSize-((p-1) mod TabSize);
  939. s:=copy(S,1,P-1)+CharStr(' ',PAdd)+copy(S,P+1,High(s));
  940. inc(P,PAdd-1);
  941. end;
  942. end;
  943. ExtractTabs:=S;
  944. end;
  945. {function CompressUsingTabs(S: string; TabSize: byte): string;
  946. var TabS: string;
  947. P: byte;
  948. begin
  949. TabS:=CharStr(' ',TabSize);
  950. repeat
  951. P:=Pos(TabS,S);
  952. if P>0 then
  953. S:=copy(S,1,P-1)+TAB+copy(S,P+TabSize,High(S));
  954. until P=0;
  955. CompressUsingTabs:=S;
  956. end;}
  957. {*****************************************************************************
  958. Forward/Backward Scanning
  959. *****************************************************************************}
  960. Const
  961. MaxBufLength = $7fffff00;
  962. NotFoundValue = -1;
  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);
  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;
  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;
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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. OI: Sw_integer;
  4603. HoldUndo : Boolean;
  4604. SCP : TPoint;
  4605. begin
  4606. if IsReadOnly then Exit;
  4607. Lock;
  4608. HoldUndo:=GetStoreUndo;
  4609. SetStoreUndo(false);
  4610. SCP:=CurPos;
  4611. S:=GetLineText(CurPos.Y);
  4612. if (S<>'') and (CurPos.X<>0) then
  4613. begin
  4614. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4615. SetLineText(CurPos.Y,copy(S,OI,High(S)));
  4616. SetCurPtr(0,CurPos.Y);
  4617. SetStoreUndo(HoldUndo);
  4618. Addaction(eaDeleteText,SCP,CurPos,copy(S,1,OI-1),GetFlags);
  4619. SetStoreUndo(false);
  4620. AdjustSelectionPos(CurPos.X,CurPos.Y,-length(copy(S,1,OI-1)),0);
  4621. UpdateAttrs(CurPos.Y,attrAll);
  4622. DrawLines(CurPos.Y);
  4623. SetModified(true);
  4624. end;
  4625. SetStoreUndo(HoldUndo);
  4626. Unlock;
  4627. end;
  4628. procedure TCustomCodeEditor.DelEnd;
  4629. var S: string;
  4630. OI: Sw_integer;
  4631. HoldUndo : Boolean;
  4632. SCP : TPoint;
  4633. begin
  4634. if IsReadOnly then Exit;
  4635. Lock;
  4636. HoldUndo:=GetStoreUndo;
  4637. SetStoreUndo(false);
  4638. SCP:=CurPos;
  4639. S:=GetLineText(CurPos.Y);
  4640. if (S<>'') and (CurPos.X<>length(S)) then
  4641. begin
  4642. OI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  4643. SetLineText(CurPos.Y,copy(S,1,OI-1));
  4644. SetCurPtr(CurPos.X,CurPos.Y);
  4645. SetStoreUndo(HoldUndo);
  4646. Addaction(eaDeleteText,SCP,CurPos,copy(S,OI,High(S)),GetFlags);
  4647. SetStoreUndo(false);
  4648. AdjustSelectionPos(CurPos.X+1,CurPos.Y,-length(copy(S,OI,High(S)))+1,0);
  4649. UpdateAttrs(CurPos.Y,attrAll);
  4650. DrawLines(CurPos.Y);
  4651. SetModified(true);
  4652. end;
  4653. SetStoreUndo(HoldUndo);
  4654. Unlock;
  4655. end;
  4656. procedure TCustomCodeEditor.DelLine;
  4657. var
  4658. HoldUndo : boolean;
  4659. SP : TPoint;
  4660. S : String;
  4661. begin
  4662. if IsReadOnly then Exit;
  4663. Lock;
  4664. if GetLineCount>0 then
  4665. begin
  4666. SP:=CurPos;
  4667. S:=GetLineText(CurPos.Y);
  4668. HoldUndo:=GetStoreUndo;
  4669. SetStoreUndo(false);
  4670. DeleteLine(CurPos.Y);
  4671. LimitsChanged;
  4672. AdjustSelectionBefore(0,-1);
  4673. SetCurPtr(0,CurPos.Y);
  4674. UpdateAttrs(Max(0,CurPos.Y-1),attrAll);
  4675. DrawLines(CurPos.Y);
  4676. SetStoreUndo(HoldUndo);
  4677. AddAction(eaDeleteLine,SP,CurPos,S,GetFlags);
  4678. SetModified(true);
  4679. end;
  4680. Unlock;
  4681. end;
  4682. procedure TCustomCodeEditor.InsMode;
  4683. begin
  4684. SetInsertMode(Overwrite);
  4685. end;
  4686. function TCustomCodeEditor.GetCurrentWordArea(var StartP,EndP: TPoint): boolean;
  4687. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  4688. var P : TPoint;
  4689. S : String;
  4690. StartPos,EndPos : byte;
  4691. OK: boolean;
  4692. begin
  4693. P:=CurPos;
  4694. S:=GetLineText(P.Y);
  4695. StartPos:=P.X+1;
  4696. EndPos:=StartPos;
  4697. OK:=(S[StartPos] in WordChars);
  4698. if OK then
  4699. begin
  4700. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  4701. Dec(StartPos);
  4702. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  4703. Inc(EndPos);
  4704. StartP.X:=StartPos-1; StartP.Y:=CurPos.Y;
  4705. EndP.X:=EndPos-1; EndP.Y:=CurPos.Y;
  4706. end;
  4707. GetCurrentWordArea:=OK;
  4708. end;
  4709. function TCustomCodeEditor.GetCurrentWord : string;
  4710. var S: string;
  4711. StartP,EndP: TPoint;
  4712. begin
  4713. if GetCurrentWordArea(StartP,EndP)=false then
  4714. S:=''
  4715. else
  4716. begin
  4717. S:=GetLineText(StartP.Y);
  4718. S:=copy(S,StartP.X+1,EndP.X-StartP.X+1);
  4719. end;
  4720. GetCurrentWord:=S;
  4721. end;
  4722. procedure TCustomCodeEditor.StartSelect;
  4723. var P1,P2: TPoint;
  4724. begin
  4725. if ValidBlock=false then
  4726. begin
  4727. { SetSelection(SelStart,Limit);}
  4728. P1:=CurPos; P1.X:=0; P2:=CurPos; {P2.X:=length(GetLineText(P2.Y))+1;}
  4729. SetSelection(P1,P2);
  4730. end
  4731. else
  4732. SetSelection(CurPos,SelEnd);
  4733. if PointOfs(SelEnd)<PointOfs(SelStart) then
  4734. SetSelection(SelStart,SelStart);
  4735. CheckSels;
  4736. DrawView;
  4737. end;
  4738. procedure TCustomCodeEditor.EndSelect;
  4739. var P: TPoint;
  4740. LS: sw_integer;
  4741. begin
  4742. P:=CurPos;
  4743. { P.X:=Min(SelEnd.X,length(GetLineText(SelEnd.Y)));}
  4744. LS:=length(GetLineText(SelEnd.Y));
  4745. if LS<P.X then P.X:=LS;
  4746. CheckSels;
  4747. SetSelection(SelStart,P);
  4748. DrawView;
  4749. end;
  4750. procedure TCustomCodeEditor.DelSelect;
  4751. var LineDelta, LineCount, CurLine: Sw_integer;
  4752. StartX,EndX,LastX: Sw_integer;
  4753. S: string;
  4754. SPos : TPoint;
  4755. begin
  4756. if IsReadOnly or (ValidBlock=false) then Exit;
  4757. Lock;
  4758. AddGroupedAction(eaDelBlock);
  4759. LineCount:=(SelEnd.Y-SelStart.Y)+1;
  4760. LineDelta:=0; LastX:=CurPos.X;
  4761. CurLine:=SelStart.Y;
  4762. { single line : easy }
  4763. if LineCount=1 then
  4764. begin
  4765. S:=GetDisplayText(CurLine);
  4766. StartX:=SelStart.X;
  4767. EndX:=SelEnd.X;
  4768. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4769. +copy(S,EndX+1,High(S)));
  4770. if GetStoreUndo then
  4771. begin
  4772. SPos.X:=StartX;
  4773. SPos.Y:=CurLine;
  4774. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,EndX-StartX),GetFlags);
  4775. end;
  4776. Inc(CurLine);
  4777. LastX:=SelStart.X;
  4778. end
  4779. { several lines : a bit less easy }
  4780. else
  4781. begin
  4782. S:=GetDisplayText(CurLine);
  4783. StartX:=SelStart.X;
  4784. EndX:=SelEnd.X;
  4785. SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX)
  4786. +copy(GetDisplayText(CurLine+LineCount-1),EndX+1,High(S)));
  4787. if GetStoreUndo then
  4788. begin
  4789. SPos.X:=StartX;
  4790. SPos.Y:=CurLine;
  4791. AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,High(S)),GetFlags);
  4792. S:=GetDisplayText(CurLine+LineCount-1);
  4793. end;
  4794. Inc(CurLine);
  4795. Inc(LineDelta);
  4796. LastX:=SelStart.X;
  4797. while (LineDelta<LineCount) do
  4798. begin
  4799. { delete the complete line }
  4800. DeleteLine(CurLine);
  4801. Inc(LineDelta);
  4802. end;
  4803. if GetStoreUndo then
  4804. begin
  4805. AddAction(eaInsertText,SPos,SPos,Copy(S,EndX+1,High(S)),GetFlags);
  4806. end;
  4807. end;
  4808. HideSelect;
  4809. SetCurPtr(LastX,CurLine-1);
  4810. UpdateAttrs(CurPos.Y,attrAll);
  4811. DrawLines(CurPos.Y);
  4812. SetModified(true);
  4813. CloseGroupedAction(eaDelBlock);
  4814. UnLock;
  4815. end;
  4816. procedure TCustomCodeEditor.HideSelect;
  4817. begin
  4818. SetSelection(CurPos,CurPos);
  4819. DrawLines(Delta.Y);
  4820. end;
  4821. procedure TCustomCodeEditor.CopyBlock;
  4822. var Temp: PCodeEditor;
  4823. R: TRect;
  4824. begin
  4825. if IsReadOnly or (ValidBlock=false) then Exit;
  4826. Lock;
  4827. GetExtent(R);
  4828. AddGroupedAction(eaCopyBlock);
  4829. New(Temp, Init(R, nil, nil, nil,nil));
  4830. Temp^.InsertFrom(@Self);
  4831. (* Temp^.SelectAll(true);
  4832. { this selects one line too much because
  4833. we have a empty line at creation to avoid
  4834. negative line problems so we need to decrease SelEnd.Y }
  4835. Dec(Temp^.SelEnd.Y);*)
  4836. InsertFrom(Temp);
  4837. Dispose(Temp, Done);
  4838. CloseGroupedAction(eaCopyBlock);
  4839. UnLock;
  4840. end;
  4841. procedure TCustomCodeEditor.MoveBlock;
  4842. var Temp: PCodeEditor;
  4843. R: TRect;
  4844. OldPos: TPoint;
  4845. begin
  4846. if IsReadOnly then Exit;
  4847. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4848. Lock;
  4849. AddGroupedAction(eaMoveBlock);
  4850. GetExtent(R);
  4851. New(Temp, Init(R, nil, nil, nil,nil));
  4852. Temp^.InsertFrom(@Self);
  4853. OldPos:=CurPos;
  4854. if CurPos.Y>SelStart.Y then
  4855. Dec(OldPos.Y,Temp^.GetLineCount-1);
  4856. DelSelect;
  4857. SetCurPtr(OldPos.X,OldPos.Y);
  4858. InsertFrom(Temp);
  4859. Dispose(Temp, Done);
  4860. CloseGroupedAction(eaMoveBlock);
  4861. UnLock;
  4862. end;
  4863. procedure TCustomCodeEditor.IndentBlock;
  4864. var
  4865. ey,i{,indlen} : Sw_integer;
  4866. S,Ind : String;
  4867. Pos : Tpoint;
  4868. begin
  4869. if IsReadOnly then Exit;
  4870. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4871. Lock;
  4872. AddGroupedAction(eaIndentBlock);
  4873. ey:=selend.y;
  4874. if selend.x=0 then
  4875. dec(ey);
  4876. S:='';
  4877. { If AutoIndent try to align first line to
  4878. last line before selection }
  4879. { DISABLED created problems PM
  4880. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4881. begin
  4882. i:=SelStart.Y-1;
  4883. while (S='') and (i>=0) do
  4884. begin
  4885. S:=GetDisplayText(i);
  4886. dec(i);
  4887. end;
  4888. if (S='') or (S[1]<>' ') then
  4889. Ind:=' '
  4890. else
  4891. begin
  4892. i:=1;
  4893. while (i<=Length(S)) and (S[i]=' ') do
  4894. inc(i);
  4895. indlen:=i;
  4896. S:=GetDisplayText(SelStart.Y);
  4897. i:=1;
  4898. while (i<=Length(S)) and (S[i]=' ') do
  4899. inc(i);
  4900. indlen:=indlen-i;
  4901. if indlen<=0 then
  4902. indlen:=1;
  4903. Ind:=CharStr(' ',indlen);
  4904. end;
  4905. end
  4906. else
  4907. Ind:=' ';}
  4908. Ind:=CharStr(' ',GetIndentSize);
  4909. for i:=selstart.y to ey do
  4910. begin
  4911. S:=GetLineText(i);
  4912. SetLineText(i,Ind+S);
  4913. Pos.X:=0;Pos.Y:=i;
  4914. AddAction(eaInsertText,Pos,Pos,Ind,GetFlags);
  4915. end;
  4916. SetCurPtr(CurPos.X,CurPos.Y);
  4917. { must be added manually here PM }
  4918. AddAction(eaMoveCursor,Pos,CurPos,'',GetFlags);
  4919. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  4920. DrawLines(CurPos.Y);
  4921. SetModified(true);
  4922. CloseGroupedAction(eaIndentBlock);
  4923. UnLock;
  4924. end;
  4925. procedure TCustomCodeEditor.UnindentBlock;
  4926. var
  4927. ey,i,j,k,indlen : Sw_integer;
  4928. S : String;
  4929. Pos : TPoint;
  4930. begin
  4931. if IsReadOnly then Exit;
  4932. if (SelStart.X=SelEnd.X) and (SelStart.Y=SelEnd.Y) then Exit;
  4933. Lock;
  4934. AddGroupedAction(eaUnindentBlock);
  4935. ey:=selend.y;
  4936. if selend.x=0 then
  4937. dec(ey);
  4938. { If AutoIndent try to align first line to
  4939. last line before selection }
  4940. { Disabled created problems
  4941. if IsFlagSet(efAutoIndent) and (SelStart.Y>0) then
  4942. begin
  4943. S:=GetDisplayText(SelStart.Y);
  4944. i:=1;
  4945. while (i<=Length(S)) and (S[i]=' ') do
  4946. inc(i);
  4947. indlen:=i-1;
  4948. i:=SelStart.Y-1;
  4949. S:='';
  4950. while (S='') and (i>=0) do
  4951. begin
  4952. if Trim(Copy(GetDisplayText(i),1,indlen))='' then
  4953. S:=''
  4954. else
  4955. S:=GetDisplayText(i);
  4956. dec(i);
  4957. end;
  4958. if (S='') then
  4959. Indlen:=1
  4960. else
  4961. begin
  4962. i:=1;
  4963. while (i<=Length(S)) and (S[i]=' ') do
  4964. inc(i);
  4965. indlen:=indlen-i+1;
  4966. if indlen<=0 then
  4967. indlen:=1;
  4968. end;
  4969. end
  4970. else
  4971. Indlen:=1;}
  4972. Indlen:=GetIndentSize;
  4973. for i:=selstart.y to ey do
  4974. begin
  4975. S:=GetLineText(i);
  4976. k:=0;
  4977. for j:=1 to indlen do
  4978. if (length(s)>1) and (S[1]=' ') then
  4979. begin
  4980. Delete(s,1,1);
  4981. inc(k);
  4982. end;
  4983. SetLineText(i,S);
  4984. if k>0 then
  4985. begin
  4986. Pos.Y:=i;
  4987. Pos.X:=0;
  4988. AddAction(eaDeleteText,Pos,Pos,CharStr(' ',k),GetFlags);
  4989. end;
  4990. end;
  4991. SetCurPtr(CurPos.X,CurPos.Y);
  4992. UpdateAttrsRange(SelStart.Y,SelEnd.Y,attrAll);
  4993. DrawLines(CurPos.Y);
  4994. SetModified(true);
  4995. CloseGroupedAction(eaUnindentBlock);
  4996. UnLock;
  4997. end;
  4998. procedure TCustomCodeEditor.SelectWord;
  4999. const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
  5000. var S : String;
  5001. StartPos,EndPos : byte;
  5002. A,B: TPoint;
  5003. begin
  5004. A:=CurPos;
  5005. B:=CurPos;
  5006. S:=GetDisplayText(A.Y);
  5007. StartPos:=A.X+1;
  5008. EndPos:=StartPos;
  5009. if not (S[StartPos] in WordChars) then
  5010. exit
  5011. else
  5012. begin
  5013. While (StartPos>0) and (S[StartPos-1] in WordChars) do
  5014. Dec(StartPos);
  5015. While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
  5016. Inc(EndPos);
  5017. A.X:=StartPos-1;
  5018. B.X:=EndPos;
  5019. SetSelection(A,B);
  5020. end;
  5021. end;
  5022. procedure TCustomCodeEditor.SelectLine;
  5023. var A,B: TPoint;
  5024. begin
  5025. if CurPos.Y<GetLineCount then
  5026. begin
  5027. A.Y:=CurPos.Y; A.X:=0;
  5028. B.Y:=CurPos.Y+1; B.X:=0;
  5029. SetSelection(A,B);
  5030. end;
  5031. end;
  5032. procedure TCustomCodeEditor.WriteBlock;
  5033. var FileName: string;
  5034. S: PBufStream;
  5035. begin
  5036. if ValidBlock=false then Exit;
  5037. FileName:='';
  5038. if EditorDialog(edWriteBlock, @FileName) <> cmCancel then
  5039. begin
  5040. FileName := FExpand(FileName);
  5041. New(S, Init(FileName, stCreate, 4096));
  5042. if (S=nil) or (S^.Status<>stOK) then
  5043. EditorDialog(edCreateError,@FileName)
  5044. else
  5045. if SaveAreaToStream(S,SelStart,SelEnd)=false then
  5046. EditorDialog(edWriteError,@FileName);
  5047. if Assigned(S) then Dispose(S, Done);
  5048. end;
  5049. end;
  5050. procedure TCustomCodeEditor.ReadBlock;
  5051. var FileName: string;
  5052. S: PFastBufStream;
  5053. E: PCodeEditor;
  5054. R: TRect;
  5055. begin
  5056. if IsReadOnly then Exit;
  5057. FileName:='';
  5058. if EditorDialog(edReadBlock, @FileName) <> cmCancel then
  5059. begin
  5060. FileName := FExpand(FileName);
  5061. New(S, Init(FileName, stOpenRead, 4096));
  5062. if (S=nil) or (S^.Status<>stOK) then
  5063. EditorDialog(edReadError,@FileName)
  5064. else
  5065. begin
  5066. R.Assign(0,0,0,0);
  5067. New(E, Init(R,nil,nil,nil,nil));
  5068. AddGroupedAction(eaReadBlock);
  5069. if E^.LoadFromStream(S)=false then
  5070. EditorDialog(edReadError,@FileName)
  5071. else
  5072. begin
  5073. E^.SelectAll(true);
  5074. Self.InsertFrom(E);
  5075. end;
  5076. CloseGroupedAction(eaReadBlock);
  5077. Dispose(E, Done);
  5078. end;
  5079. if Assigned(S) then Dispose(S, Done);
  5080. end;
  5081. end;
  5082. procedure TCustomCodeEditor.PrintBlock;
  5083. begin
  5084. NotImplemented; Exit;
  5085. end;
  5086. function TCustomCodeEditor.SelectCodeTemplate(var ShortCut: string): boolean;
  5087. begin
  5088. { Abstract }
  5089. SelectCodeTemplate:=false;
  5090. end;
  5091. procedure TCustomCodeEditor.ExpandCodeTemplate;
  5092. var Line,ShortCutInEditor,ShortCut: string;
  5093. X,Y,I,LineIndent: sw_integer;
  5094. CodeLines: PUnsortedStringCollection;
  5095. CanJump: boolean;
  5096. CP: TPoint;
  5097. begin
  5098. {
  5099. The usage of editing primitives in this routine make it pretty slow, but
  5100. its speed is still acceptable and they make the implementation of Undo
  5101. much easier... - Gabor
  5102. }
  5103. if IsReadOnly then Exit;
  5104. Lock;
  5105. CP.X:=-1; CP.Y:=-1;
  5106. Line:=GetDisplayText(CurPos.Y);
  5107. X:=CurPos.X; ShortCut:='';
  5108. if X<=length(Line) then
  5109. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  5110. begin
  5111. ShortCut:=Line[X]+ShortCut;
  5112. Dec(X);
  5113. end;
  5114. ShortCutInEditor:=ShortCut;
  5115. New(CodeLines, Init(10,10));
  5116. if (ShortCut='') or (not TranslateCodeTemplate(ShortCut,CodeLines)) then
  5117. if SelectCodeTemplate(ShortCut) then
  5118. TranslateCodeTemplate(ShortCut,CodeLines);
  5119. if CodeLines^.Count>0 then
  5120. begin
  5121. LineIndent:=X;
  5122. SetCurPtr(X,CurPos.Y);
  5123. if Copy(ShortCut,1,length(ShortCutInEditor))=ShortCutInEditor then
  5124. begin
  5125. for I:=1 to length(ShortCutInEditor) do
  5126. DelChar;
  5127. end
  5128. else
  5129. { restore correct position }
  5130. SetCurPtr(X+Length(ShortCutInEditor),CurPos.Y);
  5131. for Y:=0 to CodeLines^.Count-1 do
  5132. begin
  5133. Line:=GetStr(CodeLines^.At(Y));
  5134. CanJump:=false;
  5135. if (Y>0) then
  5136. begin
  5137. CanJump:=Trim(GetLineText(CurPos.Y))='';
  5138. if CanJump=false then
  5139. begin
  5140. (* for X:=1 to LineIndent do { indent template lines to align }
  5141. AddChar(' '); { them to the first line }*)
  5142. InsertText(CharStr(' ',LineIndent));
  5143. end
  5144. else
  5145. SetCurPtr(CurPos.X+LineIndent,CurPos.Y);
  5146. end;
  5147. I:=Pos(CodeTemplateCursorChar,Line);
  5148. if I>0 then
  5149. begin
  5150. Delete(Line,I,1);
  5151. CP.X:=CurPos.X+I-1;
  5152. CP.Y:=CurPos.Y;
  5153. end;
  5154. InsertText(Line);
  5155. if Y<CodeLines^.Count-1 then
  5156. begin
  5157. InsertNewLine; { line break }
  5158. if CanJump=false then
  5159. begin
  5160. while CurPos.X>0 do { unindent }
  5161. begin
  5162. SetCurPtr(CurPos.X-1,CurPos.Y);
  5163. DelChar;
  5164. end;
  5165. end
  5166. else
  5167. SetCurPtr(0,CurPos.Y);
  5168. end;
  5169. end;
  5170. end;
  5171. Dispose(CodeLines, Done);
  5172. if (CP.X<>-1) and (CP.Y<>-1) then
  5173. SetCurPtr(CP.X,CP.Y);
  5174. UnLock;
  5175. end;
  5176. procedure TCustomCodeEditor.AddChar(C: char);
  5177. const OpenBrackets : string[10] = '[({';
  5178. CloseBrackets : string[10] = '])}';
  5179. var S,SC,TabS: string;
  5180. BI: byte;
  5181. CI,TabStart,LocTabSize : Sw_integer;
  5182. SP: TPoint;
  5183. HoldUndo : boolean;
  5184. begin
  5185. if IsReadOnly then Exit;
  5186. Lock;
  5187. SP:=CurPos;
  5188. HoldUndo:=GetStoreUndo;
  5189. SetStoreUndo(false);
  5190. if (C<>TAB) or IsFlagSet(efUseTabCharacters) then
  5191. SC:=C
  5192. else
  5193. begin
  5194. LocTabSize:=GetTabSize - (CurPos.X mod GetTabSize);
  5195. if (CurPos.Y<=1) or not IsFlagSet(efAutoIndent) then
  5196. SC:=CharStr(' ',LocTabSize)
  5197. else
  5198. begin
  5199. S:=GetLineText(CurPos.Y-1);
  5200. BI:=CurPos.X+1;
  5201. while (BI<=Length(S)) and (S[BI]=' ') do
  5202. inc(BI);
  5203. if (BI=CurPos.X+1) or (BI>Length(S)) then
  5204. SC:=CharStr(' ',LocTabSize)
  5205. else
  5206. SC:=CharStr(' ',BI-CurPos.X-1);
  5207. end;
  5208. end;
  5209. S:=GetLineText(CurPos.Y);
  5210. if CharIdxToLinePos(CurPos.Y,length(S))<CurPos.X then
  5211. begin
  5212. S:=S+CharStr(' ',CurPos.X-CharIdxToLinePos(CurPos.Y,length(S)){-1});
  5213. SetLineText(CurPos.Y,S);
  5214. end;
  5215. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  5216. if CI>High(S) then
  5217. begin
  5218. Unlock;
  5219. exit;
  5220. end;
  5221. if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then
  5222. begin
  5223. if CI=1 then
  5224. TabStart:=0
  5225. else
  5226. TabStart:=CharIdxToLinePos(CurPos.Y,CI-1)+1;
  5227. if SC=Tab then TabS:=Tab else
  5228. TabS:=CharStr(' ',CurPos.X-TabStart);
  5229. SetLineText(CurPos.Y,copy(S,1,CI-1)+TabS+SC+copy(S,CI+1,High(S)));
  5230. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(TabS)+length(SC)),CurPos.Y);
  5231. end
  5232. else
  5233. begin
  5234. if Overwrite and (CI<=length(S)) then
  5235. begin
  5236. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI+length(SC),High(S)));
  5237. end
  5238. else
  5239. SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI,High(S)));
  5240. SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(SC)),CurPos.Y);
  5241. end;
  5242. { must be before CloseBrackets !! }
  5243. SetStoreUndo(HoldUndo);
  5244. if Overwrite then
  5245. Addaction(eaOverwriteText,SP,CurPos,Copy(S,CI,length(SC)),GetFlags)
  5246. else
  5247. Addaction(eaInsertText,SP,CurPos,SC,GetFlags);
  5248. SetStoreUndo(false);
  5249. if IsFlagSet(efAutoBrackets) then
  5250. begin
  5251. BI:=Pos(C,OpenBrackets);
  5252. if (BI>0) then
  5253. begin
  5254. SetStoreUndo(HoldUndo);
  5255. AddChar(CloseBrackets[BI]);
  5256. SetStoreUndo(false);
  5257. SetCurPtr(CurPos.X-1,CurPos.Y);
  5258. end;
  5259. end;
  5260. UpdateAttrs(CurPos.Y,attrAll);
  5261. if GetInsertMode then
  5262. AdjustSelection(CurPos.X-SP.X,CurPos.Y-SP.Y);
  5263. DrawLines(CurPos.Y);
  5264. SetStoreUndo(HoldUndo);
  5265. SetModified(true);
  5266. UnLock;
  5267. end;
  5268. {$ifdef WinClipSupported}
  5269. const
  5270. linelimit = 200;
  5271. function TCustomCodeEditor.ClipPasteWin: Boolean;
  5272. var
  5273. StorePos : TPoint;
  5274. first : boolean;
  5275. procedure InsertStringWrap(const s: string; var i : Longint);
  5276. var
  5277. BPos,EPos: TPoint;
  5278. begin
  5279. if first then
  5280. begin
  5281. { we need to cut the line in two
  5282. if not at end of line PM }
  5283. InsertNewLine;
  5284. SetCurPtr(StorePos.X,StorePos.Y);
  5285. InsertText(s);
  5286. first:=false;
  5287. end
  5288. else
  5289. begin
  5290. Inc(i);
  5291. InsertLine(i,s);
  5292. BPos.X:=0;BPos.Y:=i;
  5293. EPOS.X:=Length(s);EPos.Y:=i;
  5294. AddAction(eaInsertLine,BPos,EPos,GetDisplayText(i),GetFlags);
  5295. end;
  5296. end;
  5297. var
  5298. OK: boolean;
  5299. l,i,len,len10 : longint;
  5300. p,p10,p2,p13 : pchar;
  5301. s : string;
  5302. begin
  5303. Lock;
  5304. OK:=WinClipboardSupported;
  5305. if OK then
  5306. begin
  5307. first:=true;
  5308. StorePos:=CurPos;
  5309. i:=CurPos.Y;
  5310. l:=GetTextWinClipboardSize;
  5311. if l=0 then
  5312. OK:=false
  5313. else
  5314. OK:=GetTextWinClipBoardData(p,l);
  5315. if OK then
  5316. begin
  5317. if l>500 then
  5318. PushInfo(msg_readingwinclipboard);
  5319. AddGroupedAction(eaPasteWin);
  5320. p2:=p;
  5321. len:=strlen(p2);
  5322. // issue lines ((#13)#10 terminated) of maximally "linelimit" chars.
  5323. // does not take initial X position into account
  5324. repeat
  5325. p13:=strpos(p2,#13);
  5326. p10:=strpos(p2,#10);
  5327. if len> linelimit then
  5328. len:=linelimit;
  5329. if assigned(p10) then
  5330. begin
  5331. len10:=p10-p2;
  5332. if len10<len then
  5333. begin
  5334. if p13+1=p10 then
  5335. dec(len10);
  5336. len:=len10;
  5337. end
  5338. else
  5339. p10:=nil; // signal no cleanup
  5340. end;
  5341. setlength(s,len);
  5342. if len>0 then
  5343. move(p2^,s[1],len);
  5344. // cleanup
  5345. if assigned(p10) then
  5346. p2:=p10+1
  5347. else
  5348. inc(p2,len);
  5349. insertstringwrap(s,i);
  5350. len:=strlen(p2);
  5351. until len=0;
  5352. SetCurPtr(StorePos.X,StorePos.Y); // y+i to get after paste?
  5353. SetModified(true);
  5354. UpdateAttrs(StorePos.Y,attrAll);
  5355. CloseGroupedAction(eaPasteWin);
  5356. Update;
  5357. if l>500 then
  5358. PopInfo;
  5359. { we must free the allocated memory }
  5360. freemem(p,l);
  5361. DrawView;
  5362. end;
  5363. end;
  5364. ClipPasteWin:=OK;
  5365. UnLock;
  5366. end;
  5367. function TCustomCodeEditor.ClipCopyWin: Boolean;
  5368. var OK,ShowInfo: boolean;
  5369. p,p2 : pchar;
  5370. s : string;
  5371. i,str_begin,str_end,NumLines,PcLength : longint;
  5372. begin
  5373. NumLines:=SelEnd.Y-SelStart.Y;
  5374. if (NumLines>0) or (SelEnd.X>SelStart.X) then
  5375. Inc(NumLines);
  5376. if NumLines=0 then
  5377. exit;
  5378. Lock;
  5379. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5380. if ShowInfo then
  5381. PushInfo(msg_copyingwinclipboard);
  5382. { First calculate needed size }
  5383. { for newlines first + 1 for terminal #0 }
  5384. PcLength:=Length(EOL)*(NumLines-1)+1;
  5385. { overestimated but can not be that big PM }
  5386. for i:=SelStart.Y to SelEnd.Y do
  5387. PCLength:=PCLength+Length(GetLineText(i));
  5388. getmem(p,PCLength);
  5389. i:=SelStart.Y;
  5390. s:=GetLineText(i);
  5391. str_begin:=LinePosToCharIdx(i,SelStart.X);
  5392. if SelEnd.Y>SelStart.Y then
  5393. str_end:=High(S)
  5394. else
  5395. str_end:=LinePosToCharIdx(i,SelEnd.X)-1;
  5396. s:=copy(s,str_begin,str_end-str_begin+1);
  5397. strpcopy(p,s);
  5398. p2:=strend(p);
  5399. inc(i);
  5400. while i<SelEnd.Y do
  5401. begin
  5402. strpcopy(p2,EOL+GetLineText(i));
  5403. p2:=strend(p2);
  5404. Inc(i);
  5405. end;
  5406. if SelEnd.Y>SelStart.Y then
  5407. begin
  5408. s:=copy(GetLineText(i),1,LinePosToCharIdx(i,SelEnd.X)-1);
  5409. strpcopy(p2,EOL+s);
  5410. end;
  5411. OK:=WinClipboardSupported;
  5412. if OK then
  5413. begin
  5414. OK:=SetTextWinClipBoardData(p,strlen(p));
  5415. end;
  5416. ClipCopyWin:=OK;
  5417. if ShowInfo then
  5418. PopInfo;
  5419. Freemem(p,PCLength);
  5420. UnLock;
  5421. end;
  5422. {$endif WinClipSupported}
  5423. function TCustomCodeEditor.ClipCopy: Boolean;
  5424. var ShowInfo,CanPaste: boolean;
  5425. begin
  5426. Lock;
  5427. {AddGroupedAction(eaCopy);
  5428. can we undo a copy ??
  5429. maybe as an Undo Paste in Clipboard !! }
  5430. clipcopy:=false;
  5431. showinfo:=false;
  5432. if (clipboard<>nil) and (clipboard<>@self) then
  5433. begin
  5434. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5435. if ShowInfo then
  5436. PushInfo(msg_copyingclipboard);
  5437. clipcopy:=Clipboard^.InsertFrom(@Self);
  5438. if ShowInfo then
  5439. PopInfo;
  5440. {Enable paste command.}
  5441. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5442. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5443. SetCmdState(FromClipCmds,CanPaste);
  5444. end;
  5445. UnLock;
  5446. end;
  5447. procedure TCustomCodeEditor.ClipCut;
  5448. var
  5449. ShowInfo,CanPaste : boolean;
  5450. begin
  5451. if IsReadOnly then Exit;
  5452. Lock;
  5453. AddGroupedAction(eaCut);
  5454. DontConsiderShiftState:=true;
  5455. if (clipboard<>nil) and (clipboard<>@self) then
  5456. begin
  5457. ShowInfo:=SelEnd.Y-SelStart.Y>50;
  5458. if ShowInfo then
  5459. PushInfo(msg_cutting);
  5460. if Clipboard^.InsertFrom(@Self) then
  5461. begin
  5462. if not IsClipBoard then
  5463. DelSelect;
  5464. SetModified(true);
  5465. end;
  5466. if ShowInfo then
  5467. PopInfo;
  5468. CanPaste:=((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  5469. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  5470. SetCmdState(FromClipCmds,CanPaste);
  5471. end;
  5472. CloseGroupedAction(eaCut);
  5473. UnLock;
  5474. DontConsiderShiftState:=false;
  5475. end;
  5476. procedure TCustomCodeEditor.ClipPaste;
  5477. var
  5478. ShowInfo : boolean;
  5479. begin
  5480. if IsReadOnly then Exit;
  5481. DontConsiderShiftState:=true;
  5482. Lock;
  5483. AddGroupedAction(eaPaste);
  5484. if Clipboard<>nil then
  5485. begin
  5486. ShowInfo:=Clipboard^.SelEnd.Y-Clipboard^.SelStart.Y>50;
  5487. if ShowInfo then
  5488. PushInfo(msg_pastingclipboard);
  5489. InsertFrom(Clipboard);
  5490. if ShowInfo then
  5491. PopInfo;
  5492. end;
  5493. CloseGroupedAction(eaPaste);
  5494. UnLock;
  5495. DontConsiderShiftState:=false;
  5496. end;
  5497. procedure TCustomCodeEditor.Undo;
  5498. begin
  5499. NotImplemented; Exit;
  5500. end;
  5501. procedure TCustomCodeEditor.Redo;
  5502. begin
  5503. NotImplemented; Exit;
  5504. end;
  5505. procedure TCustomCodeEditor.GotoLine;
  5506. var
  5507. GotoRec: TGotoLineDialogRec;
  5508. begin
  5509. with GotoRec do
  5510. begin
  5511. LineNo:='1';
  5512. Lines:=GetLineCount;
  5513. {Linecount can be 0, but in that case there still is a cursor blinking in top
  5514. of the window, which will become line 1 as soon as sometype hits a key.}
  5515. if lines=0 then
  5516. lines:=1;
  5517. if EditorDialog(edGotoLine, @GotoRec) <> cmCancel then
  5518. begin
  5519. Lock;
  5520. SetCurPtr(0,StrToInt(LineNo)-1);
  5521. TrackCursor(do_centre);
  5522. UnLock;
  5523. end;
  5524. end;
  5525. end;
  5526. procedure TCustomCodeEditor.Find;
  5527. var
  5528. FindRec: TFindDialogRec;
  5529. DoConf: boolean;
  5530. begin
  5531. with FindRec do
  5532. begin
  5533. Find := FindStr;
  5534. if GetCurrentWord<>'' then
  5535. Find:=GetCurrentWord;
  5536. {$ifdef TEST_REGEXP}
  5537. Options := ((FindFlags and ffmOptionsFind) shr ffsOptions) or
  5538. ((FindFlags and ffUseRegExp) shr ffsUseRegExpFind);
  5539. {$else not TEST_REGEXP}
  5540. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5541. {$endif TEST_REGEXP}
  5542. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5543. Scope := (FindFlags and ffmScope) shr ffsScope;
  5544. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5545. DoConf:= (FindFlags and ffPromptOnReplace)<>0;
  5546. FindReplaceEditor:=@self;
  5547. if EditorDialog(edFind, @FindRec) <> cmCancel then
  5548. begin
  5549. FindStr := Find;
  5550. {$ifdef TEST_REGEXP}
  5551. FindFlags := ((Options and ffmOptionsFind) shl ffsOptions) or (Direction shl ffsDirection) or
  5552. ((Options and ffmUseRegExpFind) shl ffsUseRegExpFind) or
  5553. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5554. {$else : not TEST_REGEXP}
  5555. FindFlags := ((Options and ffmOptions) shl ffsOptions) or (Direction shl ffsDirection) or
  5556. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5557. {$endif TEST_REGEXP}
  5558. FindFlags := FindFlags and not ffDoReplace;
  5559. if DoConf then
  5560. FindFlags := (FindFlags or ffPromptOnReplace);
  5561. SearchRunCount:=0;
  5562. if FindStr<>'' then
  5563. DoSearchReplace
  5564. else
  5565. EditorDialog(edSearchFailed,nil);
  5566. end;
  5567. FindReplaceEditor:=nil;
  5568. end;
  5569. end;
  5570. procedure TCustomCodeEditor.Replace;
  5571. var
  5572. ReplaceRec: TReplaceDialogRec;
  5573. Re: word;
  5574. begin
  5575. if IsReadOnly then Exit;
  5576. with ReplaceRec do
  5577. begin
  5578. Find := FindStr;
  5579. if GetCurrentWord<>'' then
  5580. Find:=GetCurrentWord;
  5581. Replace := ReplaceStr;
  5582. {$ifdef TEST_REGEXP}
  5583. Options := (FindFlags and ffmOptions) shr ffsOptions or
  5584. (FindFlags and ffUseRegExp) shr ffsUseRegExpReplace;
  5585. {$else not TEST_REGEXP}
  5586. Options := (FindFlags and ffmOptions) shr ffsOptions;
  5587. {$endif TEST_REGEXP}
  5588. Direction := (FindFlags and ffmDirection) shr ffsDirection;
  5589. Scope := (FindFlags and ffmScope) shr ffsScope;
  5590. Origin := (FindFlags and ffmOrigin) shr ffsOrigin;
  5591. FindReplaceEditor:=@self;
  5592. Re:=EditorDialog(edReplace, @ReplaceRec);
  5593. FindReplaceEditor:=nil;
  5594. if Re <> cmCancel then
  5595. begin
  5596. FindStr := Find;
  5597. ReplaceStr := Replace;
  5598. FindFlags := (Options shl ffsOptions) or (Direction shl ffsDirection) or
  5599. {$ifdef TEST_REGEXP}
  5600. ((Options and ffmUseRegExpReplace) shl ffsUseRegExpReplace) or
  5601. {$endif TEST_REGEXP}
  5602. (Scope shl ffsScope) or (Origin shl ffsOrigin);
  5603. FindFlags := FindFlags or ffDoReplace;
  5604. if Re = cmYes then
  5605. FindFlags := FindFlags or ffReplaceAll;
  5606. SearchRunCount:=0;
  5607. if FindStr<>'' then
  5608. DoSearchReplace
  5609. else
  5610. EditorDialog(edSearchFailed,nil);
  5611. end;
  5612. end;
  5613. end;
  5614. procedure TCustomCodeEditor.DoSearchReplace;
  5615. var S: string;
  5616. DX,DY,P,Y,X: sw_integer;
  5617. Count: sw_integer;
  5618. Found,CanExit: boolean;
  5619. SForward,DoReplace,DoReplaceAll: boolean;
  5620. {$ifdef TEST_REGEXP}
  5621. UseRegExp : boolean;
  5622. RegExpEngine : TRegExprEngine;
  5623. RegExpFlags : tregexprflags;
  5624. regexpindex,regexplen : longint;
  5625. findstrpchar : pchar;
  5626. {$endif TEST_REGEXP}
  5627. LeftOK,RightOK: boolean;
  5628. FoundCount: sw_integer;
  5629. A,B: TPoint;
  5630. AreaStart,AreaEnd: TPoint;
  5631. CanReplace,Confirm: boolean;
  5632. Re: word;
  5633. IFindStr : string;
  5634. BT : BTable;
  5635. Overwriting : boolean;
  5636. function ContainsText(const SubS:string;var S: string; Start: Sw_integer): Sw_integer;
  5637. var
  5638. P: Sw_Integer;
  5639. begin
  5640. if Start<=0 then
  5641. P:=0
  5642. else
  5643. begin
  5644. if SForward then
  5645. begin
  5646. if Start>length(s) then
  5647. P:=0
  5648. else if FindFlags and ffCaseSensitive<>0 then
  5649. P:=BMFScan(S[Start],length(s)+1-Start,FindStr,Bt)+1
  5650. else
  5651. P:=BMFIScan(S[Start],length(s)+1-Start,IFindStr,Bt)+1;
  5652. if P>0 then
  5653. Inc(P,Start-1);
  5654. end
  5655. else
  5656. begin
  5657. if start>length(s) then
  5658. start:=length(s);
  5659. if FindFlags and ffCaseSensitive<>0 then
  5660. P:=BMBScan(S[1],Start,FindStr,Bt)+1
  5661. else
  5662. P:=BMBIScan(S[1],Start,IFindStr,Bt)+1;
  5663. end;
  5664. end;
  5665. ContainsText:=P;
  5666. end;
  5667. function InArea(X,Y: sw_integer): boolean;
  5668. begin
  5669. InArea:=((AreaStart.Y=Y) and (AreaStart.X<=X)) or
  5670. ((AreaStart.Y<Y) and (Y<AreaEnd.Y)) or
  5671. ((AreaEnd.Y=Y) and (X<=AreaEnd.X));
  5672. end;
  5673. var CurDY: sw_integer;
  5674. begin
  5675. if FindStr='' then
  5676. begin
  5677. Find;
  5678. { Find will call DoFindReplace at end again
  5679. so we need to exit directly now PM }
  5680. exit;
  5681. end;
  5682. Inc(SearchRunCount);
  5683. SForward:=(FindFlags and ffmDirection)=ffForward;
  5684. DoReplace:=(FindFlags and ffDoReplace)<>0;
  5685. Confirm:=(FindFlags and ffPromptOnReplace)<>0;
  5686. DoReplaceAll:=(FindFlags and ffReplaceAll)<>0;
  5687. {$ifdef TEST_REGEXP}
  5688. UseRegExp:=(FindFlags and ffUseRegExp)<>0;
  5689. if UseRegExp then
  5690. begin
  5691. if FindFlags and ffCaseSensitive<>0 then
  5692. RegExpFlags:=[ref_caseinsensitive]
  5693. else
  5694. RegExpFlags:=[];
  5695. getmem(findstrpchar,length(findstr)+1);
  5696. strpcopy(findstrpchar,findstr);
  5697. RegExpEngine:=GenerateRegExprEngine(findstrpchar,RegExpFlags);
  5698. strdispose(findstrpchar);
  5699. end;
  5700. {$endif TEST_REGEXP}
  5701. Count:=GetLineCount;
  5702. FoundCount:=0;
  5703. { Empty file ? }
  5704. if Count=0 then
  5705. begin
  5706. EditorDialog(edSearchFailed,nil);
  5707. exit;
  5708. end;
  5709. if SForward then
  5710. DY:=1
  5711. else
  5712. DY:=-1;
  5713. DX:=DY;
  5714. if FindStr<>'' then
  5715. PushInfo('Looking for "'+FindStr+'"');
  5716. if (FindFlags and ffmScope)=ffGlobal then
  5717. begin
  5718. AreaStart.X:=0;
  5719. AreaStart.Y:=0;
  5720. AreaEnd.X:=length(GetDisplayText(Count-1));
  5721. AreaEnd.Y:=Count-1;
  5722. end
  5723. else
  5724. begin
  5725. AreaStart:=SelStart;
  5726. AreaEnd:=SelEnd;
  5727. end;
  5728. { set a y value being inside the areal }
  5729. Y:=Min(CurPos.Y,Count-1);
  5730. if sForward then
  5731. X:=CurPos.X-1
  5732. else
  5733. { if you change this, pleas check that repeated backward searching for single chars still works
  5734. and that data is still found if searching starts outside the current line }
  5735. X:=Min(CurPos.X,length(GetDisplayText(Y)));
  5736. if SearchRunCount=1 then
  5737. if (FindFlags and ffmOrigin)=ffEntireScope then
  5738. if SForward then
  5739. begin
  5740. X:=AreaStart.X-1;
  5741. Y:=AreaStart.Y;
  5742. end
  5743. else
  5744. begin
  5745. X:=AreaEnd.X+1;
  5746. Y:=AreaEnd.Y;
  5747. end;
  5748. if FindFlags and ffCaseSensitive<>0 then
  5749. begin
  5750. if SForward then
  5751. BMFMakeTable(FindStr,bt)
  5752. else
  5753. BMBMakeTable(FindStr,bt);
  5754. end
  5755. else
  5756. begin
  5757. IFindStr:=upcase(FindStr);
  5758. if SForward then
  5759. BMFMakeTable(IFindStr,bt)
  5760. else
  5761. BMBMakeTable(IFindStr,bt);
  5762. end;
  5763. inc(X,DX);
  5764. CanExit:=false;
  5765. if not DoReplace or (not Confirm and (Owner<>nil)) then
  5766. Owner^.Lock;
  5767. if InArea(X,Y) then
  5768. repeat
  5769. CurDY:=DY;
  5770. S:=GetDisplayText(Y);
  5771. if X>length(S)-1 then
  5772. X:=length(S)-1;
  5773. {$ifdef TEST_REGEXP}
  5774. if UseRegExp then
  5775. begin
  5776. getmem(findstrpchar,length(Copy(S,X+1,high(S)))+1);
  5777. strpcopy(findstrpchar,Copy(S,X+1,high(S)));
  5778. { If start of line is required do check other positions PM }
  5779. if (FindStr[1]='^') and (X<>0) then
  5780. Found:=false
  5781. else
  5782. Found:=RegExprPos(RegExpEngine,findstrpchar,regexpindex,regexplen);
  5783. strdispose(findstrpchar);
  5784. P:=regexpindex+X+1;
  5785. end
  5786. else
  5787. {$endif TEST_REGEXP}
  5788. begin
  5789. P:=ContainsText(FindStr,S,X+1);
  5790. Found:=P<>0;
  5791. end;
  5792. if Found then
  5793. begin
  5794. A.X:=P-1;
  5795. A.Y:=Y;
  5796. B.Y:=Y;
  5797. {$ifdef TEST_REGEXP}
  5798. if UseRegExp then
  5799. B.X:=A.X+regexplen
  5800. else
  5801. {$endif TEST_REGEXP}
  5802. B.X:=A.X+length(FindStr);
  5803. end;
  5804. Found:=Found and InArea(A.X,A.Y);
  5805. if Found and ((FindFlags and ffWholeWordsOnly)<>0) then
  5806. begin
  5807. LeftOK:=(A.X<=0) or (not( (S[A.X] in AlphaChars+NumberChars) ));
  5808. RightOK:=(B.X>=length(S)) or (not( (S[B.X+1] in AlphaChars+NumberChars) ));
  5809. Found:=LeftOK and RightOK;
  5810. if not Found then
  5811. begin
  5812. CurDY:=0;
  5813. If SForward then
  5814. begin
  5815. X:=B.X+1;
  5816. if X>length(S) then
  5817. CurDY:=DY;
  5818. end
  5819. else
  5820. begin
  5821. X:=A.X-1;
  5822. if X<0 then
  5823. CurDY:=DY;
  5824. end;
  5825. end;
  5826. end;
  5827. if Found then
  5828. begin
  5829. Inc(FoundCount);
  5830. Lock;
  5831. if SForward then
  5832. SetCurPtr(B.X,B.Y)
  5833. else
  5834. SetCurPtr(A.X,A.Y);
  5835. TrackCursor(do_centre);
  5836. SetHighlight(A,B);
  5837. UnLock;
  5838. CurDY:=0;
  5839. if not DoReplace then
  5840. begin
  5841. CanExit:=true;
  5842. If SForward then
  5843. begin
  5844. X:=B.X;
  5845. Y:=B.Y;
  5846. end
  5847. else
  5848. begin
  5849. X:=A.X;
  5850. Y:=A.Y;
  5851. end;
  5852. end
  5853. else
  5854. begin
  5855. if not confirm then
  5856. CanReplace:=true
  5857. else
  5858. begin
  5859. Re:=EditorDialog(edReplacePrompt,@CurPos);
  5860. case Re of
  5861. cmYes :
  5862. CanReplace:=true;
  5863. cmNo :
  5864. CanReplace:=false;
  5865. else {cmCancel}
  5866. begin
  5867. CanReplace:=false;
  5868. CanExit:=true;
  5869. end;
  5870. end;
  5871. end;
  5872. if CanReplace then
  5873. begin
  5874. Lock;
  5875. { don't use SetInsertMode here because it changes the cursor shape }
  5876. overwriting:=(GetFlags and efInsertMode)=0;
  5877. SetFlags(GetFlags or efInsertMode);
  5878. SetSelection(A,B);
  5879. DelSelect;
  5880. InsertText(ReplaceStr);
  5881. if SForward then
  5882. begin
  5883. X:=CurPos.X;
  5884. Y:=CurPos.Y;
  5885. end
  5886. else
  5887. begin
  5888. X:=A.X;
  5889. Y:=A.Y;
  5890. end;
  5891. if overwriting then
  5892. SetFlags(GetFlags and (not efInsertMode));
  5893. UnLock;
  5894. end
  5895. else
  5896. begin
  5897. If SForward then
  5898. begin
  5899. X:=B.X;
  5900. Y:=B.Y;
  5901. end
  5902. else
  5903. begin
  5904. X:=A.X;
  5905. Y:=A.Y;
  5906. end;
  5907. end;
  5908. if (DoReplaceAll=false) then
  5909. CanExit:=true;
  5910. end;
  5911. end;
  5912. if (CanExit=false) and (CurDY<>0) then
  5913. begin
  5914. inc(Y,CurDY);
  5915. if SForward then
  5916. X:=0
  5917. else
  5918. X:=254;
  5919. CanExit:=((Y>=Count) and sForward) or (Y<0);
  5920. end;
  5921. if not CanExit then
  5922. CanExit:=(not InArea(X,Y)) and sForward;
  5923. until CanExit;
  5924. if (FoundCount=0) or (DoReplace) then
  5925. SetHighlight(CurPos,CurPos);
  5926. if (DoReplace=false) or ((Confirm=false) and (Owner<>nil)) then
  5927. Owner^.UnLock;
  5928. {if (DoReplace=false) or (Confirm=false) then
  5929. UnLock;}
  5930. if (FoundCount=0) then
  5931. EditorDialog(edSearchFailed,nil);
  5932. if FindStr<>'' then
  5933. PopInfo;
  5934. {$ifdef TEST_REGEXP}
  5935. if UseRegExp then
  5936. DestroyRegExprEngine(RegExpEngine);
  5937. {$endif TEST_REGEXP}
  5938. if (FindFlags and ffmScope)=ffSelectedText then
  5939. { restore selection PM }
  5940. begin
  5941. SetSelection(AreaStart,AreaEnd);
  5942. end;
  5943. end;
  5944. function TCustomCodeEditor.GetInsertMode: boolean;
  5945. begin
  5946. GetInsertMode:=(GetFlags and efInsertMode)<>0;
  5947. end;
  5948. procedure TCustomCodeEditor.SetInsertMode(InsertMode: boolean);
  5949. begin
  5950. if InsertMode then
  5951. SetFlags(GetFlags or efInsertMode)
  5952. else
  5953. SetFlags(GetFlags and (not efInsertMode));
  5954. DrawCursor;
  5955. end;
  5956. { there is a problem with ShiftDel here
  5957. because GetShitState tells to extend the
  5958. selection which gives wrong results (PM) }
  5959. function TCustomCodeEditor.ShouldExtend: boolean;
  5960. var ShiftInEvent: boolean;
  5961. begin
  5962. ShiftInEvent:=false;
  5963. if Assigned(CurEvent) then
  5964. if CurEvent^.What=evKeyDown then
  5965. ShiftInEvent:=((CurEvent^.KeyShift and kbShift)<>0);
  5966. ShouldExtend:=ShiftInEvent and
  5967. not DontConsiderShiftState;
  5968. end;
  5969. procedure TCustomCodeEditor.SetCurPtr(X,Y: sw_integer);
  5970. var OldPos{,OldSEnd,OldSStart}: TPoint;
  5971. Extended: boolean;
  5972. F: PFold;
  5973. begin
  5974. Lock;
  5975. X:=Max(0,Min(MaxLineLength+1,X));
  5976. Y:=Max(0,Min(GetLineCount-1,Y));
  5977. OldPos:=CurPos;
  5978. { OldSEnd:=SelEnd;
  5979. OldSStart:=SelStart;}
  5980. CurPos.X:=X;
  5981. CurPos.Y:=Y;
  5982. TrackCursor(do_not_centre);
  5983. if not IsLineVisible(CurPos.Y) then
  5984. begin
  5985. F:=GetLineFold(CurPos.Y);
  5986. if Assigned(F) then
  5987. F^.Collapse(false);
  5988. end;
  5989. if not NoSelect and ShouldExtend then
  5990. begin
  5991. CheckSels;
  5992. Extended:=false;
  5993. if PointOfs(OldPos)=PointOfs(SelStart) then
  5994. begin
  5995. SetSelection(CurPos,SelEnd);
  5996. Extended:=true;
  5997. end;
  5998. CheckSels;
  5999. if Extended=false then
  6000. if PointOfs(OldPos)=PointOfs(SelEnd) then
  6001. begin
  6002. if not ValidBlock then
  6003. SetSelection(CurPos,CurPos);
  6004. SetSelection(SelStart,CurPos); Extended:=true;
  6005. end;
  6006. CheckSels;
  6007. if not Extended then
  6008. if PointOfs(OldPos)<=PointOfs(CurPos) then
  6009. begin
  6010. SetSelection(OldPos,CurPos);
  6011. Extended:=true;
  6012. end
  6013. else
  6014. begin
  6015. SetSelection(CurPos,OldPos);
  6016. Extended:=true;
  6017. end;
  6018. DrawView;
  6019. end
  6020. else if not IsFlagSet(efPersistentBlocks) then
  6021. begin
  6022. HideSelect;
  6023. DrawView;
  6024. end;
  6025. { if PointOfs(SelStart)=PointOfs(SelEnd) then
  6026. SetSelection(CurPos,CurPos);}
  6027. if (GetFlags and (efHighlightColumn+efHighlightRow))<>0 then
  6028. DrawView;
  6029. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and
  6030. ((Highlight.A.X<>HighLight.B.X) or (Highlight.A.Y<>HighLight.B.Y)) then
  6031. HideHighlight;
  6032. if (OldPos.Y<>CurPos.Y) and (0<=OldPos.Y) and (OldPos.Y<GetLineCount) then
  6033. SetLineText(OldPos.Y,RTrim(GetLineText(OldPos.Y),not IsFlagSet(efUseTabCharacters)));
  6034. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (GetErrorMessage<>'') then
  6035. SetErrorMessage('');
  6036. { if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) and (HighlightRow<>-1) then
  6037. SetHighlightRow(-1);}
  6038. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6039. AddAction(eaMoveCursor,OldPos,CurPos,'',GetFlags);
  6040. if ((CurPos.X<>OldPos.X) or (CurPos.Y<>OldPos.Y)) then
  6041. PositionChanged;{UpdateIndicator;}
  6042. UnLock;
  6043. end;
  6044. procedure TCustomCodeEditor.CheckSels;
  6045. begin
  6046. if (SelStart.Y>SelEnd.Y) or
  6047. ( (SelStart.Y=SelEnd.Y) and (SelStart.X>SelEnd.X) ) then
  6048. SetSelection(SelEnd,SelStart);
  6049. end;
  6050. procedure TCustomCodeEditor.CodeCompleteApply;
  6051. var S: string;
  6052. FragLen,
  6053. I: integer;
  6054. begin
  6055. Lock;
  6056. { here should be some kind or "mark" or "break" inserted in the Undo
  6057. information, so activating it "undoes" only the completition first and
  6058. doesn't delete the complete word at once... - Gabor }
  6059. FragLen:=Length(GetCodeCompleteFrag);
  6060. S:=GetCodeCompleteWord;
  6061. for I:=FragLen+1 to length(S) do
  6062. AddChar(S[I]);
  6063. UnLock;
  6064. SetCompleteState(csInactive);
  6065. end;
  6066. procedure TCustomCodeEditor.CodeCompleteCancel;
  6067. begin
  6068. SetCompleteState(csDenied);
  6069. end;
  6070. procedure TCustomCodeEditor.CodeCompleteCheck;
  6071. var Line: string;
  6072. X: sw_integer;
  6073. CurWord,NewWord: string;
  6074. begin
  6075. SetCodeCompleteFrag('');
  6076. if (not IsFlagSet(efCodeComplete)) or (IsReadOnly=true) then Exit;
  6077. Lock;
  6078. Line:=GetDisplayText(CurPos.Y);
  6079. X:=CurPos.X; CurWord:='';
  6080. if X<=length(Line) then
  6081. while (X>0) and (Line[X] in (NumberChars+AlphaChars)) do
  6082. begin
  6083. CurWord:=Line[X]+CurWord;
  6084. Dec(X);
  6085. end;
  6086. if (length(CurWord)>=CodeCompleteMinLen) and CompleteCodeWord(CurWord,NewWord) then
  6087. begin
  6088. SetCodeCompleteFrag(CurWord);
  6089. SetCodeCompleteWord(NewWord);
  6090. end
  6091. else
  6092. ClearCodeCompleteWord;
  6093. UnLock;
  6094. end;
  6095. function TCustomCodeEditor.GetCodeCompleteFrag: string;
  6096. begin
  6097. { Abstract }
  6098. GetCodeCompleteFrag:='';
  6099. end;
  6100. procedure TCustomCodeEditor.SetCodeCompleteFrag(const S: string);
  6101. begin
  6102. { Abstract }
  6103. end;
  6104. procedure TCustomCodeEditor.DrawLines(FirstLine: sw_integer);
  6105. begin
  6106. if FirstLine>=(Delta.Y+Size.Y) then Exit; { falls outside of the screen }
  6107. DrawView;
  6108. end;
  6109. procedure TCustomCodeEditor.HideHighlight;
  6110. begin
  6111. SetHighlight(CurPos,CurPos);
  6112. end;
  6113. procedure TCustomCodeEditor.GetSelectionArea(var StartP,EndP: TPoint);
  6114. begin
  6115. StartP:=SelStart; EndP:=SelEnd;
  6116. if EndP.X=0 then
  6117. begin
  6118. Dec(EndP.Y);
  6119. EndP.X:=length(GetDisplayText(EndP.Y))-1;
  6120. end
  6121. else
  6122. Dec(EndP.X);
  6123. end;
  6124. function TCustomCodeEditor.ValidBlock: boolean;
  6125. begin
  6126. ValidBlock:=(SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y);
  6127. end;
  6128. procedure TCustomCodeEditor.SetSelection(A, B: TPoint);
  6129. var WV: boolean;
  6130. OS,OE: TPoint;
  6131. begin
  6132. WV:=ValidBlock;
  6133. OS:=SelStart; OE:=SelEnd;
  6134. SelStart:=A; SelEnd:=B;
  6135. if (WV=false) and (ValidBlock=false) then { do nothing } else
  6136. if (OS.X<>SelStart.X) or (OS.Y<>SelStart.Y) or
  6137. (OE.X<>SelEnd.X) or (OE.Y<>SelEnd.Y) then
  6138. SelectionChanged;
  6139. end;
  6140. procedure TCustomCodeEditor.SetHighlight(A, B: TPoint);
  6141. begin
  6142. Highlight.A:=A; Highlight.B:=B;
  6143. HighlightChanged;
  6144. end;
  6145. {procedure TCustomCodeEditor.SetHighlightRow(Row: sw_integer);
  6146. begin
  6147. HighlightRow:=Row;
  6148. DrawView;
  6149. end;}
  6150. {procedure TCodeEditor.SetDebuggerRow(Row: sw_integer);
  6151. begin
  6152. DebuggerRow:=Row;
  6153. DrawView;
  6154. end;}
  6155. procedure TCustomCodeEditor.SelectAll(Enable: boolean);
  6156. var A,B: TPoint;
  6157. begin
  6158. if (Enable=false) or (GetLineCount=0) then
  6159. begin A:=CurPos; B:=CurPos end
  6160. else
  6161. begin
  6162. A.X:=0; A.Y:=0;
  6163. { B.Y:=GetLineCount-1;
  6164. B.X:=length(GetLineText(B.Y));}
  6165. B.Y:=GetLineCount; B.X:=0;
  6166. end;
  6167. SetSelection(A,B);
  6168. DrawView;
  6169. end;
  6170. procedure TCustomCodeEditor.SelectionChanged;
  6171. var Enable,CanPaste: boolean;
  6172. begin
  6173. if GetLineCount=0 then
  6174. begin
  6175. SelStart.X:=0; SelStart.Y:=0; SelEnd:=SelStart;
  6176. end
  6177. else
  6178. if SelEnd.Y>GetLineCount-1 then
  6179. if (SelEnd.Y<>GetLineCount) or (SelEnd.X<>0) then
  6180. begin
  6181. SelEnd.Y:=GetLineCount-1;
  6182. SelEnd.X:=length(GetDisplayText(SelEnd.Y));
  6183. end;
  6184. { we change the CurCommandSet, but only if we are top view }
  6185. if ((State and sfFocused)<>0) then
  6186. begin
  6187. Enable:=((SelStart.X<>SelEnd.X) or (SelStart.Y<>SelEnd.Y)) and (Clipboard<>nil);
  6188. SetCmdState(ToClipCmds,Enable and (Clipboard<>@Self));
  6189. SetCmdState(NulClipCmds,Enable);
  6190. CanPaste:=(Clipboard<>nil) and ((Clipboard^.SelStart.X<>Clipboard^.SelEnd.X) or
  6191. (Clipboard^.SelStart.Y<>Clipboard^.SelEnd.Y));
  6192. SetCmdState(FromClipCmds,CanPaste and (Clipboard<>@Self));
  6193. SetCmdState(UndoCmd,(GetUndoActionCount>0));
  6194. SetCmdState(RedoCmd,(GetRedoActionCount>0));
  6195. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  6196. end;
  6197. DrawView;
  6198. end;
  6199. procedure TCustomCodeEditor.HighlightChanged;
  6200. begin
  6201. DrawView;
  6202. end;
  6203. procedure TCustomCodeEditor.SetState(AState: Word; Enable: Boolean);
  6204. procedure ShowSBar(SBar: PScrollBar);
  6205. begin
  6206. if Assigned(SBar) and (SBar^.GetState(sfVisible)=false) then
  6207. SBar^.Show;
  6208. end;
  6209. begin
  6210. inherited SetState(AState,Enable);
  6211. if AlwaysShowScrollBars then
  6212. begin
  6213. ShowSBar(HScrollBar);
  6214. ShowSBar(VScrollBar);
  6215. end;
  6216. if (AState and (sfActive+sfSelected+sfFocused))<>0 then
  6217. begin
  6218. SelectionChanged;
  6219. if ((State and sfFocused)=0) and (GetCompleteState=csOffering) then
  6220. ClearCodeCompleteWord;
  6221. end;
  6222. end;
  6223. function TCustomCodeEditor.GetPalette: PPalette;
  6224. const P: string[length(CEditor)] = CEditor;
  6225. begin
  6226. GetPalette:=@P;
  6227. end;
  6228. function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean;
  6229. var S: string;
  6230. AllLinesComplete,LineComplete,hasCR,OK: boolean;
  6231. begin
  6232. DeleteAllLines;
  6233. ChangedLine:=-1;
  6234. AllLinesComplete:=true;
  6235. OK:=(Stream^.Status=stOK);
  6236. if eofstream(Stream) then
  6237. AddLine('')
  6238. else
  6239. begin
  6240. while OK and (eofstream(Stream)=false) and (GetLineCount<MaxLineCount) do
  6241. begin
  6242. if not UseOldBufStreamMethod then
  6243. Stream^.Readline(S,LineComplete,hasCR)
  6244. else
  6245. ReadlnFromStream(Stream,S,LineComplete,hasCR);
  6246. AllLinesComplete:=AllLinesComplete and LineComplete;
  6247. OK:=OK and (Stream^.Status=stOK);
  6248. if OK then AddLine(S);
  6249. if not LineComplete and (ChangedLine=-1) then
  6250. ChangedLine:=GetLineCount;
  6251. end;
  6252. { Do not remove the final newline if it exists PM }
  6253. if hasCR then
  6254. AddLine('');
  6255. end;
  6256. LimitsChanged;
  6257. if not AllLinesComplete then
  6258. SetModified(true);
  6259. if (GetLineCount=MaxLineCount) and not eofstream(stream) then
  6260. EditorDialog(edTooManyLines,nil);
  6261. LoadFromStream:=OK;
  6262. end;
  6263. function TCustomCodeEditorCore.SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean;
  6264. var S: string;
  6265. OK: boolean;
  6266. Line: Sw_integer;
  6267. begin
  6268. if EndP.X=0 then
  6269. begin
  6270. if EndP.Y>0 then
  6271. begin
  6272. EndP.X:=length(GetDisplayText(EndP.Y));
  6273. end
  6274. else
  6275. EndP.X:=0;
  6276. end
  6277. else
  6278. Dec(EndP.X);
  6279. OK:=(Stream^.Status=stOK); Line:=StartP.Y;
  6280. while OK and (Line<=EndP.Y) and (Line<GetLineCount) do
  6281. begin
  6282. S:=GetLineText(Line);
  6283. { Remove all traling spaces PM }
  6284. if not Editor^.IsFlagSet(efKeepTrailingSpaces) then
  6285. While (Length(S)>0) and (S[Length(S)]=' ') do
  6286. Dec(S[0]);
  6287. { if FlagSet(efUseTabCharacters) then
  6288. S:=CompressUsingTabs(S,TabSize);
  6289. }
  6290. if Line=EndP.Y then S:=copy(S,1,LinePosToCharIdx(Line,EndP.X));
  6291. if Line=StartP.Y then S:=copy(S,LinePosToCharIdx(Line,StartP.X),High(S));
  6292. Stream^.Write(S[1],length(S));
  6293. if Line<EndP.Y then
  6294. Stream^.Write(EOL[1],length(EOL));
  6295. Inc(Line);
  6296. OK:=OK and (Stream^.Status=stOK);
  6297. end;
  6298. SaveAreaToStream:=OK;
  6299. end;
  6300. constructor TEditorAction.init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint);
  6301. begin
  6302. Action:=act;
  6303. StartPos:=StartP;
  6304. EndPos:=EndP;
  6305. Text:=NewStr(txt);
  6306. ActionCount:=0;
  6307. Flags:=AFlags;
  6308. TimeStamp:=Now;
  6309. IsGrouped:=false;
  6310. end;
  6311. constructor TEditorAction.init_group(act:byte);
  6312. begin
  6313. Action:=act;
  6314. ActionCount:=0;
  6315. Flags:=0;
  6316. IsGrouped:=true;
  6317. end;
  6318. function TEditorAction.Is_grouped_action : boolean;
  6319. begin
  6320. Is_grouped_action:=IsGrouped;
  6321. end;
  6322. destructor TEditorAction.done;
  6323. begin
  6324. DisposeStr(Text);
  6325. inherited done;
  6326. end;
  6327. function TEditorActionCollection.At(Idx : sw_integer) : PEditorAction;
  6328. begin
  6329. At:=PEditorAction(Inherited At(Idx));
  6330. end;
  6331. procedure TEditorInputLine.HandleEvent(var Event : TEvent);
  6332. var
  6333. s,s2 : string;
  6334. i : longint;
  6335. begin
  6336. If (Event.What=evKeyDown) then
  6337. begin
  6338. if (Event.KeyCode=kbRight) and
  6339. (CurPos = Length(Data^)) and
  6340. Assigned(FindReplaceEditor) then
  6341. Begin
  6342. s:=FindReplaceEditor^.GetDisplayText(FindReplaceEditor^.CurPos.Y);
  6343. s:=Copy(s,FindReplaceEditor^.CurPos.X + 1 -length(Data^),high(s));
  6344. i:=pos(Data^,s);
  6345. if i>0 then
  6346. begin
  6347. s:=Data^+s[i+length(Data^)];
  6348. If not assigned(validator) or
  6349. Validator^.IsValidInput(s,False) then
  6350. Begin
  6351. Event.CharCode:=s[length(s)];
  6352. Event.Scancode:=0;
  6353. Inherited HandleEvent(Event);
  6354. End;
  6355. end;
  6356. ClearEvent(Event);
  6357. End
  6358. else if (Event.KeyCode=kbShiftIns) and
  6359. Assigned(Clipboard) and (Clipboard^.ValidBlock) then
  6360. { paste from clipboard }
  6361. begin
  6362. i:=Clipboard^.SelStart.Y;
  6363. s:=Clipboard^.GetDisplayText(i);
  6364. i:=Clipboard^.SelStart.X;
  6365. if i>0 then
  6366. s:=copy(s,i+1,high(s));
  6367. if (Clipboard^.SelStart.Y=Clipboard^.SelEnd.Y) then
  6368. begin
  6369. i:=Clipboard^.SelEnd.X-i;
  6370. s:=copy(s,1,i);
  6371. end;
  6372. for i:=1 to length(s) do
  6373. begin
  6374. s2:=Data^+s[i];
  6375. If not assigned(validator) or
  6376. Validator^.IsValidInput(s2,False) then
  6377. Begin
  6378. Event.What:=evKeyDown;
  6379. Event.CharCode:=s[i];
  6380. Event.Scancode:=0;
  6381. Inherited HandleEvent(Event);
  6382. End;
  6383. end;
  6384. ClearEvent(Event);
  6385. end
  6386. else if (Event.KeyCode=kbCtrlIns) and
  6387. Assigned(Clipboard) then
  6388. { Copy to clipboard }
  6389. begin
  6390. s:=GetStr(Data);
  6391. s:=copy(s,selstart+1,selend-selstart);
  6392. Clipboard^.SelStart:=Clipboard^.CurPos;
  6393. Clipboard^.InsertText(s);
  6394. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6395. ClearEvent(Event);
  6396. end
  6397. else if (Event.KeyCode=kbShiftDel) and
  6398. Assigned(Clipboard) then
  6399. { Cut to clipboard }
  6400. begin
  6401. s:=GetStr(Data);
  6402. s:=copy(s,selstart+1,selend-selstart);
  6403. Clipboard^.SelStart:=Clipboard^.CurPos;
  6404. Clipboard^.InsertText(s);
  6405. Clipboard^.SelEnd:=Clipboard^.CurPos;
  6406. s2:=GetStr(Data);
  6407. { now remove the selected part }
  6408. Event.keyCode:=kbDel;
  6409. inherited HandleEvent(Event);
  6410. ClearEvent(Event);
  6411. end
  6412. else
  6413. Inherited HandleEvent(Event);
  6414. End
  6415. else
  6416. Inherited HandleEvent(Event);
  6417. s:=getstr(data);
  6418. Message(Owner,evBroadCast,cminputlinelen,pointer(length(s)));
  6419. end;
  6420. procedure TSearchHelperDialog.HandleEvent(var Event : TEvent);
  6421. begin
  6422. case Event.What of
  6423. evBroadcast :
  6424. case Event.Command of
  6425. cminputlinelen : begin
  6426. if Event.InfoLong=0 then
  6427. okbutton^.DisableCommands([cmok])
  6428. else
  6429. okbutton^.EnableCommands([cmok]);
  6430. clearevent(event);
  6431. end;
  6432. end;
  6433. end;
  6434. inherited HandleEvent(Event);
  6435. end;
  6436. function CreateFindDialog: PDialog;
  6437. var R,R1,R2: TRect;
  6438. D: PSearchHelperDialog;
  6439. IL1: PEditorInputLine;
  6440. Control : PView;
  6441. CB1: PCheckBoxes;
  6442. RB1,RB2,RB3: PRadioButtons;
  6443. but : PButton;
  6444. begin
  6445. R.Assign(0,0,56,15);
  6446. New(D, Init(R, dialog_find));
  6447. with D^ do
  6448. begin
  6449. Options:=Options or ofCentered;
  6450. GetExtent(R); R.Grow(-3,-2);
  6451. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6452. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6453. New(IL1, Init(R2, FindStrSize));
  6454. IL1^.Data^:=FindStr;
  6455. Insert(IL1);
  6456. Insert(New(PLabel, Init(R1, label_find_texttofind, IL1)));
  6457. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6458. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6459. Insert(Control);
  6460. 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;
  6461. R2.Copy(R1); R2.Move(0,1);
  6462. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}3{$else}2{$endif};
  6463. New(CB1, Init(R2,
  6464. NewSItem(label_find_casesensitive,
  6465. NewSItem(label_find_wholewordsonly,
  6466. {$ifdef TEST_REGEXP}
  6467. NewSItem(label_find_useregexp,
  6468. {$endif TEST_REGEXP}
  6469. nil)))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6470. Insert(CB1);
  6471. Insert(New(PLabel, Init(R1, label_find_options, CB1)));
  6472. 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;
  6473. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6474. New(RB1, Init(R2,
  6475. NewSItem(label_find_forward,
  6476. NewSItem(label_find_backward,
  6477. nil))));
  6478. Insert(RB1);
  6479. Insert(New(PLabel, Init(R1, label_find_direction, RB1)));
  6480. 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;
  6481. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6482. New(RB2, Init(R2,
  6483. NewSItem(label_find_global,
  6484. NewSItem(label_find_selectedtext,
  6485. nil))));
  6486. Insert(RB2);
  6487. Insert(New(PLabel, Init(R1, label_find_scope, RB2)));
  6488. 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;
  6489. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6490. New(RB3, Init(R2,
  6491. NewSItem(label_find_fromcursor,
  6492. NewSItem(label_find_entirescope,
  6493. nil))));
  6494. Insert(RB3);
  6495. Insert(New(PLabel, Init(R1, label_find_origin, RB3)));
  6496. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6497. Okbutton:=New(PButton, Init(R, btn_OK, cmOK, bfDefault));
  6498. Insert(OkButton);
  6499. R.Move(19,0);
  6500. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6501. end;
  6502. IL1^.Select;
  6503. CreateFindDialog := D;
  6504. end;
  6505. function CreateReplaceDialog: PDialog;
  6506. var R,R1,R2: TRect;
  6507. D: PDialog;
  6508. Control : PView;
  6509. IL1: PEditorInputLine;
  6510. IL2: PEditorInputLine;
  6511. CB1: PCheckBoxes;
  6512. RB1,RB2,RB3: PRadioButtons;
  6513. begin
  6514. R.Assign(0,0,56,18);
  6515. New(D, Init(R, dialog_replace));
  6516. with D^ do
  6517. begin
  6518. Options:=Options or ofCentered;
  6519. GetExtent(R); R.Grow(-3,-2);
  6520. R1.Copy(R); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6521. R2.Copy(R); R2.B.X:=R2.B.X-3;R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6522. New(IL1, Init(R2, FindStrSize));
  6523. IL1^.Data^:=FindStr;
  6524. Insert(IL1);
  6525. Insert(New(PLabel, Init(R1, label_replace_texttofind, IL1)));
  6526. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6527. Control := New(PHistory, Init(R1, IL1, TextFindId));
  6528. Insert(Control);
  6529. R1.Copy(R); R1.Move(0,2); R1.B.X:=17; R1.B.Y:=R1.A.Y+1;
  6530. R2.Copy(R); R2.Move(0,2);R2.B.X:=R2.B.X-3;
  6531. R2.A.X:=17; R2.B.Y:=R2.A.Y+1;
  6532. New(IL2, Init(R2, FindStrSize));
  6533. IL2^.Data^:=ReplaceStr;
  6534. Insert(IL2);
  6535. Insert(New(PLabel, Init(R1, label_replace_newtext, IL2)));
  6536. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6537. Control := New(PHistory, Init(R1, IL2, TextReplaceId));
  6538. Insert(Control);
  6539. 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;
  6540. R2.Copy(R1); R2.Move(0,1);
  6541. R2.B.Y:=R2.A.Y+{$ifdef TEST_REGEXP}4{$else}3{$endif};
  6542. New(CB1, Init(R2,
  6543. NewSItem(label_replace_casesensitive,
  6544. NewSItem(label_replace_wholewordsonly,
  6545. NewSItem(label_replace_promptonreplace,
  6546. {$ifdef TEST_REGEXP}
  6547. NewSItem(label_find_useregexp,
  6548. {$endif TEST_REGEXP}
  6549. nil))))){$ifdef TEST_REGEXP}){$endif TEST_REGEXP};
  6550. Insert(CB1);
  6551. Insert(New(PLabel, Init(R1, label_replace_options, CB1)));
  6552. 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;
  6553. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6554. New(RB1, Init(R2,
  6555. NewSItem(label_replace_forward,
  6556. NewSItem(label_replace_backward,
  6557. nil))));
  6558. Insert(RB1);
  6559. Insert(New(PLabel, Init(R1, label_replace_direction, RB1)));
  6560. 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;
  6561. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6562. New(RB2, Init(R2,
  6563. NewSItem(label_replace_global,
  6564. NewSItem(label_replace_selectedtext,
  6565. nil))));
  6566. Insert(RB2);
  6567. Insert(New(PLabel, Init(R1, label_replace_scope, RB2)));
  6568. 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;
  6569. R2.Copy(R1); R2.Move(0,1); R2.B.Y:=R2.A.Y+2;
  6570. New(RB3, Init(R2,
  6571. NewSItem(label_replace_fromcursor,
  6572. NewSItem(label_replace_entirescope,
  6573. nil))));
  6574. Insert(RB3);
  6575. Insert(New(PLabel, Init(R1, label_replace_origin, RB3)));
  6576. GetExtent(R); R.Grow(-13,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10; R.Move(-10,0);
  6577. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6578. R.Move(11,0); R.B.X:=R.A.X+14;
  6579. Insert(New(PButton, Init(R, btn_replace_changeall, cmYes, bfNormal)));
  6580. R.Move(15,0); R.B.X:=R.A.X+10;
  6581. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6582. end;
  6583. IL1^.Select;
  6584. CreateReplaceDialog := D;
  6585. end;
  6586. function CreateGotoLineDialog(Info: pointer): PDialog;
  6587. var D: PDialog;
  6588. R,R1,R2: TRect;
  6589. Control : PView;
  6590. IL: PEditorInputLine;
  6591. begin
  6592. R.Assign(0,0,40,7);
  6593. New(D, Init(R, dialog_gotoline));
  6594. with D^ do
  6595. begin
  6596. Options:=Options or ofCentered;
  6597. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  6598. R1.Copy(R); R1.B.X:=27; R2.Copy(R);
  6599. R2.B.X:=R2.B.X-3;R2.A.X:=27;
  6600. New(IL, Init(R2,5));
  6601. with TGotoLineDialogRec(Info^) do
  6602. IL^.SetValidator(New(PRangeValidator, Init(1, Lines)));
  6603. Insert(IL);
  6604. Insert(New(PLabel, Init(R1, label_gotoline_linenumber, IL)));
  6605. R1.Assign(R2.B.X, R2.A.Y, R2.B.X+3, R2.B.Y);
  6606. Control := New(PHistory, Init(R1, IL, GotoId));
  6607. Insert(Control);
  6608. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  6609. Insert(New(PButton, Init(R, btn_OK, cmOK, bfDefault)));
  6610. R.Move(15,0);
  6611. Insert(New(PButton, Init(R, btn_Cancel, cmCancel, bfNormal)));
  6612. end;
  6613. IL^.Select;
  6614. CreateGotoLineDialog:=D;
  6615. end;
  6616. function StdEditorDialog(Dialog: Integer; Info: Pointer): Word;
  6617. var
  6618. R: TRect;
  6619. T: TPoint;
  6620. Re: word;
  6621. Name: string;
  6622. DriveNumber : byte;
  6623. StoreDir,StoreDir2 : DirStr;
  6624. Title,DefExt: string;
  6625. AskOW: boolean;
  6626. begin
  6627. case Dialog of
  6628. edOutOfMemory:
  6629. StdEditorDialog := AdvMessageBox(msg_notenoughmemoryforthisoperation,
  6630. nil, mfInsertInApp+ mfError + mfOkButton);
  6631. edReadError:
  6632. StdEditorDialog := AdvMessageBox(msg_errorreadingfile,
  6633. @Info, mfInsertInApp+ mfError + mfOkButton);
  6634. edWriteError:
  6635. StdEditorDialog := AdvMessageBox(msg_errorwritingfile,
  6636. @Info, mfInsertInApp+ mfError + mfOkButton);
  6637. edSaveError:
  6638. StdEditorDialog := AdvMessageBox(msg_errorsavingfile,
  6639. @Info, mfInsertInApp+ mfError + mfOkButton);
  6640. edCreateError:
  6641. StdEditorDialog := AdvMessageBox(msg_errorcreatingfile,
  6642. @Info, mfInsertInApp+ mfError + mfOkButton);
  6643. edSaveModify:
  6644. StdEditorDialog := AdvMessageBox(msg_filehasbeenmodifiedsave,
  6645. @Info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6646. edSaveUntitled:
  6647. StdEditorDialog := AdvMessageBox(msg_saveuntitledfile,
  6648. nil, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6649. edChangedOnloading:
  6650. StdEditorDialog := AdvMessageBox(msg_filehadtoolonglines,
  6651. Info, mfInsertInApp+ mfOKButton + mfInformation);
  6652. edFileOnDiskChanged:
  6653. StdEditorDialog := AdvMessageBox(msg_filewasmodified,
  6654. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6655. edReloadDiskmodifiedFile:
  6656. StdEditorDialog := AdvMessageBox(msg_reloaddiskmodifiedfile,
  6657. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6658. edReloadDiskAndIDEModifiedFile:
  6659. StdEditorDialog := AdvMessageBox(msg_reloaddiskandidemodifiedfile,
  6660. @info, mfInsertInApp+ mfInformation + mfYesNoCancel);
  6661. edSaveAs,edWriteBlock,edReadBlock:
  6662. begin
  6663. Name:=PString(Info)^;
  6664. GetDir(0,StoreDir);
  6665. DriveNumber:=0;
  6666. if (Length(FileDir)>1) and (FileDir[2]=':') then
  6667. begin
  6668. { does not assume that lowercase are greater then uppercase ! }
  6669. if (FileDir[1]>='a') and (FileDir[1]<='z') then
  6670. DriveNumber:=Ord(FileDir[1])-ord('a')+1
  6671. else
  6672. DriveNumber:=Ord(FileDir[1])-ord('A')+1;
  6673. GetDir(DriveNumber,StoreDir2);
  6674. {$I-}
  6675. ChDir(Copy(FileDir,1,2));
  6676. EatIO;
  6677. {$I+}
  6678. end;
  6679. if FileDir<>'' then
  6680. begin
  6681. {$I-}
  6682. ChDir(TrimEndSlash(FileDir));
  6683. EatIO;
  6684. {$I+}
  6685. end;
  6686. case Dialog of
  6687. edSaveAs :
  6688. begin
  6689. Title:=dialog_savefileas;
  6690. DefExt:='*'+DefaultSaveExt;
  6691. end;
  6692. edWriteBlock :
  6693. begin
  6694. Title:=dialog_writeblocktofile;
  6695. DefExt:='*.*';
  6696. end;
  6697. edReadBlock :
  6698. begin
  6699. Title:=dialog_readblockfromfile;
  6700. DefExt:='*.*';
  6701. end;
  6702. else begin Title:='???'; DefExt:=''; end;
  6703. end;
  6704. Re:=Application^.ExecuteDialog(New(PFileDialog, Init(DefExt,
  6705. Title, label_name, fdOkButton, FileId)), @Name);
  6706. case Dialog of
  6707. edSaveAs :
  6708. begin
  6709. if ExtOf(Name)='' then
  6710. Name:=Name+DefaultSaveExt;
  6711. AskOW:=(Name<>PString(Info)^);
  6712. end;
  6713. edWriteBlock :
  6714. begin
  6715. if ExtOf(Name)='' then
  6716. Name:=Name+DefaultSaveExt;
  6717. AskOW:=true;
  6718. end;
  6719. edReadBlock : AskOW:=false;
  6720. else AskOW:=true;
  6721. end;
  6722. if (Re<>cmCancel) and AskOW then
  6723. begin
  6724. FileDir:=DirOf(FExpand(Name));
  6725. if ExistsFile(Name) then
  6726. if EditorDialog(edReplaceFile,@Name)<>cmYes then
  6727. Re:=cmCancel;
  6728. end;
  6729. if DriveNumber<>0 then
  6730. ChDir(StoreDir2);
  6731. if StoreDir<>'' then
  6732. ChDir(TrimEndSlash(StoreDir));
  6733. if Re<>cmCancel then
  6734. PString(Info)^:=Name;
  6735. StdEditorDialog := Re;
  6736. end;
  6737. edGotoLine:
  6738. StdEditorDialog :=
  6739. Application^.ExecuteDialog(CreateGotoLineDialog(Info), Info);
  6740. edFind:
  6741. StdEditorDialog :=
  6742. Application^.ExecuteDialog(CreateFindDialog, Info);
  6743. edSearchFailed:
  6744. StdEditorDialog := AdvMessageBox(msg_searchstringnotfound,
  6745. nil, mfInsertInApp+ mfError + mfOkButton);
  6746. edReplace:
  6747. StdEditorDialog :=
  6748. Application^.ExecuteDialog(CreateReplaceDialog, Info);
  6749. edReplacePrompt:
  6750. begin
  6751. { Avoid placing the dialog on the same line as the cursor }
  6752. R.Assign(0, 1, 40, 8);
  6753. R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  6754. Desktop^.MakeGlobal(R.B, T);
  6755. Inc(T.Y);
  6756. if PPoint(Info)^.Y <= T.Y then
  6757. R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  6758. StdEditorDialog := AdvMessageBoxRect(R, msg_replacethisoccourence,
  6759. nil, mfInsertInApp+ mfYesNoCancel + mfInformation);
  6760. end;
  6761. edReplaceFile :
  6762. StdEditorDialog :=
  6763. AdvMessageBox(msg_fileexistsoverwrite,@Info,mfInsertInApp+mfConfirmation+
  6764. mfYesButton+mfNoButton);
  6765. end;
  6766. end;
  6767. procedure RegisterWEditor;
  6768. begin
  6769. {$ifndef NOOBJREG}
  6770. {$endif}
  6771. end;
  6772. END.