weditor.pas 192 KB

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