Editor.c 230 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: Editor.c /main/24 1999/10/14 16:38:25 mgreess $
  24. **********************************<+>*************************************
  25. ***************************************************************************
  26. **
  27. ** File: Editor.c
  28. **
  29. ** Project: Text Editor widget
  30. **
  31. ** Description:
  32. ** -----------
  33. ** This is the main source file for the Text Editor widget.
  34. **
  35. *******************************************************************
  36. * (c) Copyright 1996 Digital Equipment Corporation.
  37. * (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company.
  38. * (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
  39. * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
  40. * (c) Copyright 1996 Novell, Inc.
  41. * (c) Copyright 1996 FUJITSU LIMITED.
  42. * (c) Copyright 1996 Hitachi.
  43. * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
  44. ********************************************************************
  45. **
  46. **************************************************************************
  47. **********************************<+>*************************************/
  48. /*-------------------------------------------------------------
  49. ** Include Files
  50. */
  51. #include <ctype.h>
  52. #if defined(__hpux) || defined(__osf__) || defined(USL)
  53. # include <wchar.h>
  54. #elif defined(__uxp__)
  55. # include <widec.h>
  56. # include <wctype.h>
  57. #elif defined(sun)
  58. # if (_XOPEN_VERSION==3)
  59. # include <wctype.h>
  60. # else
  61. # include <wchar.h>
  62. # endif
  63. # include <libintl.h>
  64. #elif defined(linux)
  65. # include <wctype.h>
  66. # define NO_putwc
  67. #elif defined(CSRG_BASED)
  68. # include <wctype.h>
  69. # include <wchar.h>
  70. #endif /* linux */
  71. #include <sys/wait.h>
  72. #include "signal.h"
  73. #include <string.h>
  74. #include <limits.h> /* For LINE_MAX definition */
  75. #include <sys/errno.h> /* For Error handling */
  76. #include "EditorP.h"
  77. #include <Dt/Dnd.h>
  78. #include "X11/Xutil.h"
  79. #include <X11/StringDefs.h>
  80. #include <X11/keysymdef.h>
  81. #include <Xm/Form.h>
  82. #include <Xm/MessageB.h>
  83. #include <Xm/MwmUtil.h>
  84. #include <Xm/TextF.h>
  85. #include <Xm/LabelG.h>
  86. #include <Xm/SeparatoG.h>
  87. #include <Xm/PushBG.h>
  88. #include <Xm/ToggleBG.h>
  89. #include <Xm/RowColumn.h>
  90. /* Need the following for _DtOkString */
  91. #include <Dt/DtP.h>
  92. #include <Dt/DtMsgsP.h>
  93. #include <Dt/HourGlass.h>
  94. #include "DtWidgetI.h"
  95. /*
  96. * Private functions borrowed from Motif.
  97. */
  98. extern XmTextLineTable _XmTextGetLineTable(Widget widget, int *total_lines);
  99. extern char * _XmStringSourceGetString(XmTextWidget tw,
  100. XmTextPosition from,
  101. XmTextPosition to,
  102. #if NeedWidePrototypes
  103. int want_wchar);
  104. #else
  105. Boolean want_wchar);
  106. #endif /* NeedWidePrototypes */
  107. /*-------------------------------------------------------------
  108. ** Public Interface
  109. **-------------------------------------------------------------
  110. */
  111. /******** Public Function Declarations ********/
  112. /******** End Public Function Declarations ********/
  113. /*-------------------------------------------------------------
  114. ** Forward Declarations
  115. **-------------------------------------------------------------
  116. */
  117. /******** Static Function Declarations ********/
  118. static void ClassInitialize(void);
  119. static void Initialize(
  120. Widget rw,
  121. Widget nw,
  122. ArgList al,
  123. Cardinal *num_args) ;
  124. static void VariableInitialize(
  125. DtEditorWidget new);
  126. static void ValidateResources(
  127. DtEditorWidget new,
  128. DtEditorWidget request);
  129. static Widget CreateText(
  130. DtEditorWidget parent);
  131. static void extractFontMetrics(
  132. DtEditorWidget w,
  133. XmFontList fontlist,
  134. int *height,
  135. int *width);
  136. static void getFontMetrics(
  137. DtEditorWidget w);
  138. static void Destroy(
  139. Widget widget);
  140. static void SetStatusLine(
  141. DtEditorWidget ew,
  142. Boolean statusLineOn);
  143. static Widget CreateStatusLine(
  144. DtEditorWidget parent);
  145. static Boolean SetValues(
  146. Widget cw,
  147. Widget rw,
  148. Widget nw);
  149. static void _DtEditorGetCenterToggleLabel(
  150. Widget wid,
  151. int resource_offset,
  152. XtArgVal *value );
  153. static void _DtEditorGetChangeAllButtonLabel(
  154. Widget wid,
  155. int resource_offset,
  156. XtArgVal *value );
  157. static void _DtEditorGetChangeButtonLabel(
  158. Widget wid,
  159. int resource_offset,
  160. XtArgVal *value );
  161. static void _DtEditorGetChangeFieldLabel(
  162. Widget wid,
  163. int resource_offset,
  164. XtArgVal *value );
  165. static void _DtEditorGetColumns(
  166. Widget wid,
  167. int resource_offset,
  168. XtArgVal *value );
  169. static void _DtEditorGetCurrentLineLabel(
  170. Widget wid,
  171. int resource_offset,
  172. XtArgVal *value );
  173. static void _DtEditorGetCursorPosition(
  174. Widget wid,
  175. int resource_offset,
  176. XtArgVal *value );
  177. static void _DtEditorGetFindButtonLabel(
  178. Widget wid,
  179. int resource_offset,
  180. XtArgVal *value );
  181. static void _DtEditorGetFindFieldLabel(
  182. Widget wid,
  183. int resource_offset,
  184. XtArgVal *value );
  185. static void _DtEditorGetFormatAllButtonLabel(
  186. Widget wid,
  187. int resource_offset,
  188. XtArgVal *value );
  189. static void _DtEditorGetFormatParagraphButtonLabel(
  190. Widget wid,
  191. int resource_offset,
  192. XtArgVal *value );
  193. static void _DtEditorGetJustifyToggleLabel(
  194. Widget wid,
  195. int resource_offset,
  196. XtArgVal *value );
  197. static void _DtEditorGetLeftAlignToggleLabel(
  198. Widget wid,
  199. int resource_offset,
  200. XtArgVal *value );
  201. static void _DtEditorGetLeftMarginFieldLabel(
  202. Widget wid,
  203. int resource_offset,
  204. XtArgVal *value );
  205. static void _DtEditorGetMaxLength(
  206. Widget wid,
  207. int resource_offset,
  208. XtArgVal *value );
  209. static void _DtEditorGetMisspelledListLabel(
  210. Widget wid,
  211. int resource_offset,
  212. XtArgVal *value );
  213. static void _DtEditorGetRightAlignToggleLabel(
  214. Widget wid,
  215. int resource_offset,
  216. XtArgVal *value );
  217. static void _DtEditorGetRightMarginFieldLabel(
  218. Widget wid,
  219. int resource_offset,
  220. XtArgVal *value );
  221. static void _DtEditorGetRows(
  222. Widget wid,
  223. int resource_offset,
  224. XtArgVal *value );
  225. static void _DtEditorGetScrollLeftSide(
  226. Widget wid,
  227. int resource_offset,
  228. XtArgVal *value );
  229. static void _DtEditorGetScrollTopSide(
  230. Widget wid,
  231. int resource_offset,
  232. XtArgVal *value );
  233. static void _DtEditorGetTextBackground(
  234. Widget wid,
  235. int resource_offset,
  236. XtArgVal *value );
  237. static void _DtEditorGetTextForeground(
  238. Widget wid,
  239. int resource_offset,
  240. XtArgVal *value );
  241. static void _DtEditorGetTopCharacter(
  242. Widget wid,
  243. int resource_offset,
  244. XtArgVal *value );
  245. static void _DtEditorGetLineCountLabel(
  246. Widget wid,
  247. int resource_offset,
  248. XtArgVal *value );
  249. static void FixWordWrap( /* XXX Word Wrap workaround */
  250. Widget w, /* XXX Word Wrap workaround */
  251. Boolean wrapOn); /* XXX Word Wrap workaround */
  252. static void BackwardChar(
  253. Widget w,
  254. XEvent *event,
  255. char **params,
  256. Cardinal *num_params);
  257. static void BackwardPara(
  258. Widget w,
  259. XEvent *event,
  260. char **params,
  261. Cardinal *num_params);
  262. static void BackwardWord(
  263. Widget w,
  264. XEvent *event,
  265. char **params,
  266. Cardinal *num_params);
  267. static void BeginningOfFile(
  268. Widget w,
  269. XEvent *event,
  270. char **params,
  271. Cardinal *num_params);
  272. static void BeginningOfLine(
  273. Widget w,
  274. XEvent *event,
  275. char **params,
  276. Cardinal *num_params);
  277. static void ClearSelection(
  278. Widget w,
  279. XEvent *event,
  280. char **params,
  281. Cardinal *num_params);
  282. static void CopyClipboard(
  283. Widget w,
  284. XEvent *event,
  285. char **params,
  286. Cardinal *num_params);
  287. static void CutClipboard(
  288. Widget w,
  289. XEvent *event,
  290. char **params,
  291. Cardinal *num_params);
  292. static void DeleteNextChar(
  293. Widget w,
  294. XEvent *event,
  295. char **params,
  296. Cardinal *num_params);
  297. static void DeleteNextWord(
  298. Widget w,
  299. XEvent *event,
  300. char **params,
  301. Cardinal *num_params);
  302. static void DeletePrevChar(
  303. Widget w,
  304. XEvent *event,
  305. char **params,
  306. Cardinal *num_params);
  307. static void DeletePrevWord(
  308. Widget w,
  309. XEvent *event,
  310. char **params,
  311. Cardinal *num_params);
  312. static void DeleteToEOL(
  313. Widget w,
  314. XEvent *event,
  315. char **params,
  316. Cardinal *num_params);
  317. static void DeleteToSOL(
  318. Widget w,
  319. XEvent *event,
  320. char **params,
  321. Cardinal *num_params);
  322. static void DeselectAll(
  323. Widget w,
  324. XEvent *event,
  325. char **params,
  326. Cardinal *num_params);
  327. static void EndOfFile(
  328. Widget w,
  329. XEvent *event,
  330. char **params,
  331. Cardinal *num_params);
  332. static void EndOfLine(
  333. Widget w,
  334. XEvent *event,
  335. char **params,
  336. Cardinal *num_params);
  337. static void ForwardChar(
  338. Widget w,
  339. XEvent *event,
  340. char **params,
  341. Cardinal *num_params);
  342. static void ForwardPara(
  343. Widget w,
  344. XEvent *event,
  345. char **params,
  346. Cardinal *num_params);
  347. static void ForwardWord(
  348. Widget w,
  349. XEvent *event,
  350. char **params,
  351. Cardinal *num_params);
  352. static void GoToLine(
  353. Widget w,
  354. XEvent *event,
  355. char **params,
  356. Cardinal *num_params);
  357. static void GoToLine_I(
  358. Widget w,
  359. XEvent *event,
  360. char **params,
  361. Cardinal *num_params);
  362. static void Help(
  363. Widget w,
  364. XEvent *event,
  365. char **params,
  366. Cardinal *num_params);
  367. static void InsertString(
  368. Widget w,
  369. XEvent *event,
  370. char **params,
  371. Cardinal *num_params);
  372. static void KeySelect(
  373. Widget w,
  374. XEvent *event,
  375. char **params,
  376. Cardinal *num_params);
  377. static void NewlineAndBackup(
  378. Widget w,
  379. XEvent *event,
  380. char **params,
  381. Cardinal *num_params);
  382. static void NewlineAndIndent(
  383. Widget w,
  384. XEvent *event,
  385. char **params,
  386. Cardinal *num_params);
  387. static void NextPage(
  388. Widget w,
  389. XEvent *event,
  390. char **params,
  391. Cardinal *num_params);
  392. static void PageLeft(
  393. Widget w,
  394. XEvent *event,
  395. char **params,
  396. Cardinal *num_params);
  397. static void PageRight(
  398. Widget w,
  399. XEvent *event,
  400. char **params,
  401. Cardinal *num_params);
  402. static void PasteClipboard(
  403. Widget w,
  404. XEvent *event,
  405. char **params,
  406. Cardinal *num_params);
  407. static void PreviousPage(
  408. Widget w,
  409. XEvent *event,
  410. char **params,
  411. Cardinal *num_params);
  412. static void ProcessCancel(
  413. Widget w,
  414. XEvent *event,
  415. char **params,
  416. Cardinal *num_params);
  417. static void ProcessDown(
  418. Widget w,
  419. XEvent *event,
  420. char **params,
  421. Cardinal *num_params);
  422. static void ProcessShiftDown(
  423. Widget w,
  424. XEvent *event,
  425. char **params,
  426. Cardinal *num_params);
  427. static void ProcessShiftUp(
  428. Widget w,
  429. XEvent *event,
  430. char **params,
  431. Cardinal *num_params);
  432. static void ProcessUp(
  433. Widget w,
  434. XEvent *event,
  435. char **params,
  436. Cardinal *num_params);
  437. static void QuoteNextChar(
  438. Widget w,
  439. XEvent *event,
  440. char **params,
  441. Cardinal *num_params);
  442. static void QuoteNextChar_I(
  443. Widget w,
  444. XEvent *event,
  445. char **params,
  446. Cardinal *num_params);
  447. static void SelectAll(
  448. Widget w,
  449. XEvent *event,
  450. char **params,
  451. Cardinal *num_params);
  452. static void ToggleInsertMode(
  453. Widget w,
  454. XEvent *event,
  455. char **params,
  456. Cardinal *num_params);
  457. static void ToggleInsertMode_I(
  458. Widget w,
  459. XEvent *event,
  460. char **params,
  461. Cardinal *num_params);
  462. static void UndoEdit(
  463. Widget w,
  464. XEvent *event,
  465. char **params,
  466. Cardinal *num_params);
  467. static void UndoEdit_I(
  468. Widget w,
  469. XEvent *event,
  470. char **params,
  471. Cardinal *num_params);
  472. static void Call_TextSelectCallback(
  473. DtEditorWidget editor);
  474. static void Call_TextDeselectCallback(
  475. DtEditorWidget editor);
  476. static void Editor_SetSelectionProc(
  477. XmTextSource source,
  478. XmTextPosition left,
  479. XmTextPosition right,
  480. Time set_time );
  481. static void CallHelpCallback(
  482. DtEditorWidget editor,
  483. int reason);
  484. static void HelpEditWindowCB(
  485. Widget w,
  486. caddr_t client_data,
  487. caddr_t call_data );
  488. static void HelpStatusCurrentLineCB(
  489. Widget w,
  490. caddr_t client_data,
  491. caddr_t call_data );
  492. static void HelpStatusTotalLinesCB(
  493. Widget w,
  494. caddr_t client_data,
  495. caddr_t call_data );
  496. static void HelpStatusMessageCB(
  497. Widget w,
  498. caddr_t client_data,
  499. caddr_t call_data );
  500. static void HelpStatusOverstrikeCB(
  501. Widget w,
  502. caddr_t client_data,
  503. caddr_t call_data );
  504. static void RegisterDropZone(
  505. DtEditorWidget w );
  506. static void UnregisterDropZone(
  507. DtEditorWidget w );
  508. static void SetInfoDialogTitle(
  509. DtEditorWidget editor );
  510. static int FormatText (
  511. AdjRecPtr pAdjRec );
  512. static void AdjustParaCB(
  513. Widget w,
  514. caddr_t client_data,
  515. caddr_t call_data );
  516. static void AdjustAllCB(
  517. Widget w,
  518. caddr_t client_data,
  519. caddr_t call_data );
  520. static DtEditorErrorCode DoAdjust(
  521. DtEditorWidget editor,
  522. int leftMargin,
  523. int rightMargin,
  524. unsigned int alignment,
  525. XmTextPosition start,
  526. XmTextPosition end);
  527. static void SetFormatDialogTitle(
  528. DtEditorWidget editor);
  529. static void ResetFormatDialog(
  530. DtEditorWidget editor);
  531. static void CreateFormatDialog(
  532. DtEditorWidget editor);
  533. static void GetAdjustSettings(
  534. DtEditorWidget pPad,
  535. DtEditorFormatSettings *formatSettings);
  536. static void UpdateOverstrikeIndicator(
  537. DtEditorWidget widget,
  538. Boolean overstrikeOn );
  539. /******** End Static Function Declarations ********/
  540. /****************************************************************
  541. *
  542. * Compatability routines
  543. *
  544. ****************************************************************/
  545. #if defined(NO_putwc)
  546. static wint_t putwc(wint_t wc, FILE *stream)
  547. {
  548. int rc = putc((int) wc, stream);
  549. return (wint_t) rc;
  550. }
  551. static wint_t getwc(FILE *stream)
  552. {
  553. int rc = getc(stream);
  554. return (wint_t) rc;
  555. }
  556. #endif /* NO_putwc */
  557. /****************************************************************
  558. *
  559. * Translations and Actions
  560. *
  561. ****************************************************************/
  562. /*
  563. * The following are the translations which DtEditor places (overrides)
  564. * on the scrolled text widget. If the DtNtextTranslations resource is
  565. * set, it will also be added (in override mode) to the text widget.
  566. */
  567. static char EditorTranslationTable[] = "\
  568. ~s ~c ~m ~a <Key>Return: newline-and-indent()\n\
  569. ~s m<Key>osfBackSpace: I-undo-edit()\n\
  570. ~s c<Key>osfBackSpace: delete-previous-word()\n\
  571. s<Key>osfBackSpace: delete-to-start-of-line()\n\
  572. ~s ~c <Key>osfInsert: I-toggle-insert-mode()\n\
  573. <Key>osfUndo: I-undo-edit()\n\
  574. c<Key>g: I-go-to-line()\n\
  575. c<Key>q: I-quote-next-character()\n\
  576. c<Key>z: I-undo-edit()";
  577. /*
  578. * The following are DtEditor's actions. A few are internal only (_I
  579. * suffix) and will be called by the default translations DtEditor places
  580. * on the text widget (see previous comment). The rest will only be called
  581. * from an application with XtCallActionProc(). The main difference is
  582. * the internal ones will be passed a text widget ID, while the public
  583. * ones will be passed a DtEditor ID.
  584. */
  585. static XtActionsRec EditorActionTable[] = {
  586. {"I-go-to-line", (XtActionProc)GoToLine_I},
  587. {"I-toggle-insert-mode", (XtActionProc)ToggleInsertMode_I},
  588. {"I-undo-edit", (XtActionProc)UndoEdit_I},
  589. {"I-quote-next-character", (XtActionProc)QuoteNextChar_I},
  590. {"backward-character", (XtActionProc)BackwardChar},
  591. {"backward-paragraph", (XtActionProc)BackwardPara},
  592. {"backward-word", (XtActionProc)BackwardWord},
  593. {"beginning-of-file", (XtActionProc)BeginningOfFile},
  594. {"beginning-of-line", (XtActionProc)BeginningOfLine},
  595. {"clear-selection", (XtActionProc)ClearSelection},
  596. {"copy-clipboard", (XtActionProc)CopyClipboard},
  597. {"cut-clipboard", (XtActionProc)CutClipboard},
  598. {"delete-next-character", (XtActionProc)DeleteNextChar},
  599. {"delete-next-word", (XtActionProc)DeleteNextWord},
  600. {"delete-previous-character", (XtActionProc)DeletePrevChar},
  601. {"delete-previous-word", (XtActionProc)DeletePrevWord},
  602. {"delete-to-end-of-line", (XtActionProc)DeleteToEOL},
  603. {"delete-to-start-of-line", (XtActionProc)DeleteToSOL},
  604. {"deselect-all", (XtActionProc)DeselectAll},
  605. {"end-of-file", (XtActionProc)EndOfFile},
  606. {"end-of-line", (XtActionProc)EndOfLine},
  607. {"forward-character", (XtActionProc)ForwardChar},
  608. {"forward-paragraph", (XtActionProc)ForwardPara},
  609. {"forward-word", (XtActionProc)ForwardWord},
  610. {"go-to-line", (XtActionProc)GoToLine},
  611. {"Help", (XtActionProc)Help},
  612. {"insert-string", (XtActionProc)InsertString},
  613. {"key-select", (XtActionProc)KeySelect},
  614. {"newline-and-backup", (XtActionProc)NewlineAndBackup},
  615. {"newline-and-indent", (XtActionProc)NewlineAndIndent},
  616. {"next-page", (XtActionProc)NextPage},
  617. {"page-left", (XtActionProc)PageLeft},
  618. {"page-right", (XtActionProc)PageRight},
  619. {"paste-clipboard", (XtActionProc)PasteClipboard},
  620. {"previous-page", (XtActionProc)PreviousPage},
  621. {"process-cancel", (XtActionProc)ProcessCancel},
  622. {"process-down", (XtActionProc)ProcessDown},
  623. {"process-shift-down", (XtActionProc)ProcessShiftDown},
  624. {"process-shift-up", (XtActionProc)ProcessShiftUp},
  625. {"process-up", (XtActionProc)ProcessUp},
  626. {"quote-next-character", (XtActionProc)QuoteNextChar},
  627. {"select-all", (XtActionProc)SelectAll},
  628. {"toggle-insert-mode", (XtActionProc)ToggleInsertMode},
  629. {"undo-edit", (XtActionProc)UndoEdit},
  630. };
  631. /****************************************************************
  632. *
  633. * Defines
  634. *
  635. ****************************************************************/
  636. #define NL_SETN 1
  637. #ifdef _AIX
  638. #define iswctype(a,b) is_wctype(a,b)
  639. #define wctype(a) get_wctype(a)
  640. #endif /* _AIX */
  641. #if !(defined(sun) && (_XOPEN_VERSION==3))
  642. #if !(defined(__FreeBSD__))
  643. # define iswblank(wc) iswctype((wc),blnkclass)
  644. # undef getwc /* Use the libc function */
  645. #endif
  646. #if defined(__osf__) || defined(_AIX) /* __osf__ || _AIX */
  647. /* function prototype for wctype() was changed to meet spec1170 */
  648. /* digital compiler flagged warning */
  649. /* IBM defines wctype to get_wctype above - don't use const. */
  650. static char *blankString = "space";
  651. #elif defined(USL)
  652. # define wctype_t int
  653. #else /* __osf__ || _AIX */
  654. static const char *blankString = "space";
  655. #endif /* __osf__ || _AIX */
  656. static wctype_t _DtEditor_blankClass;
  657. #else
  658. # define wctype_t int
  659. # if defined(__uxp__)
  660. # if (OSMAJORVERSION < 2)
  661. typedef long wint_t ;
  662. # endif
  663. # define WEOF (-1)
  664. # endif /* uxp */
  665. # define iswblank(a) iswspace(a)
  666. # if !defined(__uxp__)
  667. # define iswctype(a,b) _iswctype(a,b)
  668. # endif
  669. # if defined(__uxp__)
  670. # define wcwidth(a) scrwidth(a)
  671. # else
  672. # define wcwidth(a) sun_wcwidth(a)
  673. # endif
  674. #endif /* not sun and not uxp */
  675. #define MAXTABSIZE 100 /* max legal tabsize */
  676. /****************************************************************
  677. *
  678. * Define misc data structures
  679. *
  680. ****************************************************************/
  681. static wctype_t ekinclass = 0; /* Prop value for "ekinsoku" class */
  682. static wctype_t bekinclass = 0; /* Prop value for "bekinsoku" class */
  683. static wctype_t blnkclass = 0; /* Prop value for "Blank" Class */
  684. /****************************************************************
  685. *
  686. * Resource List
  687. *
  688. ****************************************************************/
  689. static XmSyntheticResource syn_resources[] =
  690. {
  691. {
  692. DtNcolumns, sizeof(short),
  693. XtOffset (DtEditorWidget, editor.editStuff.columns),
  694. _DtEditorGetColumns, NULL
  695. },
  696. {
  697. DtNcenterToggleLabel, sizeof (XmString),
  698. XtOffset (DtEditorWidget, editor.formatStuff.centerToggleLabel),
  699. _DtEditorGetCenterToggleLabel, NULL
  700. },
  701. {
  702. DtNchangeAllButtonLabel, sizeof (XmString),
  703. XtOffset (DtEditorWidget,
  704. editor.searchStuff.changeAllButtonLabel),
  705. _DtEditorGetChangeAllButtonLabel, NULL
  706. },
  707. {
  708. DtNchangeButtonLabel, sizeof (XmString),
  709. XtOffset(DtEditorWidget, editor.searchStuff.changeButtonLabel),
  710. _DtEditorGetChangeButtonLabel, NULL
  711. },
  712. {
  713. DtNchangeFieldLabel, sizeof (XmString),
  714. XtOffset(DtEditorWidget, editor.searchStuff.changeFieldLabel),
  715. _DtEditorGetChangeFieldLabel, NULL
  716. },
  717. {
  718. DtNcurrentLineLabel, sizeof (XmString),
  719. XtOffset(DtEditorWidget, editor.statusStuff.currentLineLabel),
  720. _DtEditorGetCurrentLineLabel, NULL
  721. },
  722. {
  723. DtNcursorPosition, sizeof (XmTextPosition),
  724. XtOffset(DtEditorWidget, editor.editStuff.cursorPos),
  725. _DtEditorGetCursorPosition, NULL
  726. },
  727. {
  728. DtNfindButtonLabel, sizeof (XmString),
  729. XtOffset(DtEditorWidget, editor.searchStuff.findButtonLabel),
  730. _DtEditorGetFindButtonLabel, NULL
  731. },
  732. {
  733. DtNfindFieldLabel, sizeof (XmString),
  734. XtOffset(DtEditorWidget, editor.searchStuff.findFieldLabel),
  735. _DtEditorGetFindFieldLabel, NULL
  736. },
  737. {
  738. DtNformatAllButtonLabel, sizeof (XmString),
  739. XtOffset(DtEditorWidget,
  740. editor.formatStuff.formatAllButtonLabel),
  741. _DtEditorGetFormatAllButtonLabel, NULL
  742. },
  743. {
  744. DtNformatParagraphButtonLabel, sizeof (XmString),
  745. XtOffset(DtEditorWidget,
  746. editor.formatStuff.formatParaButtonLabel),
  747. _DtEditorGetFormatParagraphButtonLabel, NULL
  748. },
  749. {
  750. DtNjustifyToggleLabel, sizeof (XmString),
  751. XtOffset (DtEditorWidget,
  752. editor.formatStuff.justifyToggleLabel),
  753. _DtEditorGetJustifyToggleLabel, NULL
  754. },
  755. {
  756. DtNleftAlignToggleLabel, sizeof (XmString),
  757. XtOffset (DtEditorWidget,
  758. editor.formatStuff.leftAlignToggleLabel),
  759. _DtEditorGetLeftAlignToggleLabel, NULL
  760. },
  761. {
  762. DtNleftMarginFieldLabel, sizeof (XmString),
  763. XtOffset (DtEditorWidget,
  764. editor.formatStuff.leftMarginFieldLabel),
  765. _DtEditorGetLeftMarginFieldLabel, NULL
  766. },
  767. {
  768. DtNmaxLength, sizeof(int),
  769. XtOffset(DtEditorWidget, editor.editStuff.maxLength),
  770. _DtEditorGetMaxLength, NULL
  771. },
  772. {
  773. DtNmisspelledListLabel, sizeof (XmString),
  774. XtOffset (DtEditorWidget,
  775. editor.searchStuff.misspelledListLabel),
  776. _DtEditorGetMisspelledListLabel, NULL
  777. },
  778. {
  779. DtNrightAlignToggleLabel, sizeof (XmString),
  780. XtOffset (DtEditorWidget,
  781. editor.formatStuff.rightAlignToggleLabel),
  782. _DtEditorGetRightAlignToggleLabel, NULL
  783. },
  784. {
  785. DtNrightMarginFieldLabel, sizeof (XmString),
  786. XtOffset (DtEditorWidget,
  787. editor.formatStuff.rightMarginFieldLabel),
  788. _DtEditorGetRightMarginFieldLabel, NULL
  789. },
  790. {
  791. DtNrows, sizeof(short),
  792. XtOffset (DtEditorWidget, editor.editStuff.rows),
  793. _DtEditorGetRows, NULL
  794. },
  795. {
  796. DtNscrollLeftSide, sizeof (Boolean),
  797. XtOffset (DtEditorWidget, editor.editStuff.scrollLeft),
  798. _DtEditorGetScrollLeftSide, NULL
  799. },
  800. {
  801. DtNscrollTopSide, sizeof (Boolean),
  802. XtOffset (DtEditorWidget, editor.editStuff.scrollTop),
  803. _DtEditorGetScrollTopSide, NULL
  804. },
  805. {
  806. DtNtextBackground, sizeof(Pixel),
  807. XtOffset (DtEditorWidget, editor.editStuff.background),
  808. _DtEditorGetTextBackground, NULL
  809. },
  810. {
  811. DtNtextForeground, sizeof(Pixel),
  812. XtOffset (DtEditorWidget, editor.editStuff.foreground),
  813. _DtEditorGetTextForeground, NULL
  814. },
  815. {
  816. DtNtopCharacter, sizeof(XmTextPosition),
  817. XtOffset (DtEditorWidget, editor.editStuff.topCharacter),
  818. _DtEditorGetTopCharacter, NULL
  819. },
  820. {
  821. DtNtotalLineCountLabel, sizeof (XmString),
  822. XtOffset (DtEditorWidget, editor.statusStuff.totalLineLabel),
  823. _DtEditorGetLineCountLabel, NULL
  824. },
  825. };
  826. static XtResource resources[] =
  827. {
  828. {
  829. DtNautoShowCursorPosition,
  830. DtCAutoShowCursorPosition, XmRBoolean, sizeof (Boolean),
  831. XtOffset(DtEditorWidget,
  832. editor.editStuff.autoShowCursorPos),
  833. XmRImmediate, (XtPointer) True
  834. },
  835. {
  836. DtNbuttonFontList, DtCFontList, XmRFontList, sizeof(XmFontList),
  837. XtOffsetOf(struct _XmBulletinBoardRec,
  838. bulletin_board.button_font_list),
  839. XmRFontList, (XtPointer) NULL
  840. },
  841. {
  842. DtNblinkRate, DtCBlinkRate, XmRInt, sizeof(int),
  843. XtOffset(DtEditorWidget, editor.editStuff.blinkRate),
  844. XmRImmediate, (XtPointer) 500
  845. },
  846. {
  847. DtNcenterToggleLabel, DtCCenterToggleLabel,
  848. XmRXmString, sizeof (XmString),
  849. XtOffset (DtEditorWidget, editor.formatStuff.centerToggleLabel),
  850. XmRImmediate, (XtPointer) DtUNSPECIFIED
  851. },
  852. {
  853. DtNchangeAllButtonLabel, DtCChangeAllButtonLabel,
  854. XmRXmString, sizeof (XmString),
  855. XtOffset (DtEditorWidget,
  856. editor.searchStuff.changeAllButtonLabel),
  857. XmRImmediate, (XtPointer) DtUNSPECIFIED
  858. },
  859. {
  860. DtNchangeButtonLabel, DtCChangeButtonLabel,
  861. XmRXmString, sizeof (XmString),
  862. XtOffset(DtEditorWidget, editor.searchStuff.changeButtonLabel),
  863. XmRImmediate, (XtPointer) DtUNSPECIFIED
  864. },
  865. {
  866. DtNchangeFieldLabel, DtCChangeFieldLabel,
  867. XmRXmString, sizeof (XmString),
  868. XtOffset(DtEditorWidget, editor.searchStuff.changeFieldLabel),
  869. XmRImmediate, (XtPointer) DtUNSPECIFIED
  870. },
  871. {
  872. DtNcolumns, DtCColumns, XmRShort, sizeof(short),
  873. XtOffset (DtEditorWidget, editor.editStuff.columns),
  874. XmRImmediate, (XtPointer) DtUNSPECIFIED
  875. },
  876. {
  877. DtNcurrentLineLabel, DtCCurrentLineLabel,
  878. XmRXmString, sizeof (XmString),
  879. XtOffset(DtEditorWidget, editor.statusStuff.currentLineLabel),
  880. XmRImmediate, (XtPointer) DtUNSPECIFIED
  881. },
  882. {
  883. DtNcursorPosition, DtCCursorPosition, XmRTextPosition,
  884. sizeof (XmTextPosition),
  885. XtOffset(DtEditorWidget, editor.editStuff.cursorPos),
  886. XmRImmediate, (XtPointer) DtUNSPECIFIED
  887. },
  888. {
  889. DtNcursorPositionVisible, DtCCursorPositionVisible,
  890. XmRBoolean, sizeof (Boolean),
  891. XtOffset(DtEditorWidget,
  892. editor.editStuff.cursorPosVisible),
  893. XmRImmediate, (XtPointer) True
  894. },
  895. {
  896. DtNdialogTitle, DtCDialogTitle, XmRXmString, sizeof (XmString),
  897. XtOffsetOf(struct _XmBulletinBoardRec,
  898. bulletin_board.dialog_title),
  899. XmRString, (XtPointer) NULL
  900. },
  901. {
  902. DtNeditable, DtCEditable, XmRBoolean, sizeof (Boolean),
  903. XtOffset (DtEditorWidget, editor.editStuff.editable),
  904. XmRImmediate, (XtPointer) True
  905. },
  906. {
  907. DtNfindButtonLabel, DtCFindButtonLabel,
  908. XmRXmString, sizeof (XmString),
  909. XtOffset(DtEditorWidget, editor.searchStuff.findButtonLabel),
  910. XmRImmediate, (XtPointer) DtUNSPECIFIED
  911. },
  912. {
  913. DtNfindChangeDialogTitle, DtCFindChangeDialogTitle,
  914. XmRXmString, sizeof (XmString),
  915. XtOffset(DtEditorWidget, editor.searchStuff.fndChngTitle),
  916. XmRString, (XtPointer) NULL
  917. },
  918. {
  919. DtNfindFieldLabel, DtCFindFieldLabel,
  920. XmRXmString, sizeof (XmString),
  921. XtOffset(DtEditorWidget, editor.searchStuff.findFieldLabel),
  922. XmRImmediate, (XtPointer) DtUNSPECIFIED
  923. },
  924. {
  925. DtNformatAllButtonLabel, DtCFormatAllButtonLabel,
  926. XmRXmString, sizeof (XmString),
  927. XtOffset(DtEditorWidget,
  928. editor.formatStuff.formatAllButtonLabel),
  929. XmRImmediate, (XtPointer) DtUNSPECIFIED
  930. },
  931. {
  932. DtNformatParagraphButtonLabel, DtCFormatParagraphButtonLabel,
  933. XmRXmString, sizeof (XmString),
  934. XtOffset(DtEditorWidget,
  935. editor.formatStuff.formatParaButtonLabel),
  936. XmRImmediate, (XtPointer) DtUNSPECIFIED
  937. },
  938. {
  939. DtNformatSettingsDialogTitle, DtCFormatSettingsDialogTitle,
  940. XmRXmString, sizeof (XmString),
  941. XtOffset(DtEditorWidget, editor.formatStuff.formatDialogTitle),
  942. XmRString, (XtPointer) NULL
  943. },
  944. {
  945. DtNinformationDialogTitle, DtCInformationDialogTitle,
  946. XmRXmString, sizeof (XmString),
  947. XtOffset(DtEditorWidget, editor.warningStuff.infoDialogTitle),
  948. XmRString, (XtPointer) NULL
  949. },
  950. {
  951. DtNinsertLabel, DtCInsertLabel, XmRXmString, sizeof (XmString),
  952. XtOffset (DtEditorWidget, editor.statusStuff.ins),
  953. XmRImmediate, (XtPointer) DtUNSPECIFIED
  954. },
  955. {
  956. DtNjustifyToggleLabel, DtCJustifyToggleLabel,
  957. XmRXmString, sizeof (XmString),
  958. XtOffset(DtEditorWidget, editor.formatStuff.justifyToggleLabel),
  959. XmRImmediate, (XtPointer) DtUNSPECIFIED
  960. },
  961. {
  962. DtNlabelFontList, DtCFontList, XmRFontList, sizeof(XmFontList),
  963. XtOffsetOf(struct _XmBulletinBoardRec,
  964. bulletin_board.label_font_list),
  965. XmRFontList, (XtPointer) NULL
  966. },
  967. {
  968. DtNleftAlignToggleLabel, DtCLeftAlignToggleLabel,
  969. XmRXmString, sizeof (XmString),
  970. XtOffset(DtEditorWidget,
  971. editor.formatStuff.leftAlignToggleLabel),
  972. XmRImmediate, (XtPointer) DtUNSPECIFIED
  973. },
  974. {
  975. DtNleftMarginFieldLabel, DtCLeftMarginFieldLabel,
  976. XmRXmString, sizeof (XmString),
  977. XtOffset(DtEditorWidget,
  978. editor.formatStuff.leftMarginFieldLabel),
  979. XmRImmediate, (XtPointer) DtUNSPECIFIED
  980. },
  981. {
  982. DtNmaxLength, DtCMaxLength, XmRInt, sizeof(int),
  983. XtOffset(DtEditorWidget, editor.editStuff.maxLength),
  984. XmRImmediate, (XtPointer) DtUNSPECIFIED
  985. },
  986. {
  987. DtNmisspelledListLabel, DtCMisspelledListLabel,
  988. XmRXmString, sizeof (XmString),
  989. XtOffset (DtEditorWidget,
  990. editor.searchStuff.misspelledListLabel),
  991. XmRImmediate, (XtPointer) DtUNSPECIFIED
  992. },
  993. {
  994. DtNoverstrike, DtCOverstrike, XmRBoolean, sizeof (Boolean),
  995. XtOffset(DtEditorWidget, editor.editStuff.overstrikeMode),
  996. XmRImmediate, (XtPointer) False
  997. },
  998. {
  999. DtNoverstrikeLabel, DtCOverstrikeLabel,
  1000. XmRXmString, sizeof (XmString),
  1001. XtOffset (DtEditorWidget, editor.statusStuff.ovr),
  1002. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1003. },
  1004. {
  1005. DtNrightAlignToggleLabel, DtCRightAlignToggleLabel,
  1006. XmRXmString, sizeof (XmString),
  1007. XtOffset(DtEditorWidget,
  1008. editor.formatStuff.rightAlignToggleLabel),
  1009. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1010. },
  1011. {
  1012. DtNrightMarginFieldLabel, DtCRightMarginFieldLabel,
  1013. XmRXmString, sizeof (XmString),
  1014. XtOffset(DtEditorWidget,
  1015. editor.formatStuff.rightMarginFieldLabel),
  1016. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1017. },
  1018. {
  1019. DtNrows, DtCRows, XmRShort, sizeof(short),
  1020. XtOffset (DtEditorWidget, editor.editStuff.rows),
  1021. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1022. },
  1023. {
  1024. DtNscrollHorizontal, DtCScroll, XmRBoolean, sizeof (Boolean),
  1025. XtOffset (DtEditorWidget, editor.editStuff.scrollHorizontal),
  1026. XmRImmediate, (XtPointer) True
  1027. },
  1028. {
  1029. DtNscrollLeftSide, DtCScrollSide, XmRBoolean, sizeof (Boolean),
  1030. XtOffset (DtEditorWidget, editor.editStuff.scrollLeft),
  1031. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1032. },
  1033. {
  1034. DtNscrollTopSide, DtCScrollSide, XmRBoolean, sizeof (Boolean),
  1035. XtOffset (DtEditorWidget, editor.editStuff.scrollTop),
  1036. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1037. },
  1038. {
  1039. DtNscrollVertical, DtCScroll, XmRBoolean, sizeof (Boolean),
  1040. XtOffset (DtEditorWidget, editor.editStuff.scrollVertical),
  1041. XmRImmediate, (XtPointer) True
  1042. },
  1043. {
  1044. DtNshowStatusLine,
  1045. DtCShowStatusLine, XmRBoolean, sizeof (Boolean),
  1046. XtOffset (DtEditorWidget, editor.statusStuff.showStatusLine),
  1047. XmRImmediate, (XtPointer) False
  1048. },
  1049. {
  1050. DtNspellDialogTitle, DtCSpellDialogTitle,
  1051. XmRXmString, sizeof (XmString),
  1052. XtOffset(DtEditorWidget, editor.searchStuff.spellTitle),
  1053. XmRString, (XtPointer) NULL
  1054. },
  1055. {
  1056. DtNspellFilter, DtCSpellFilter, XmRString, sizeof(XmRString),
  1057. XtOffset (DtEditorWidget, editor.searchStuff.spellFilter),
  1058. XmRString, "spell"
  1059. },
  1060. {
  1061. DtNtextBackground, DtCBackground,
  1062. XmRPixel, sizeof(Pixel),
  1063. XtOffset (DtEditorWidget, editor.editStuff.background),
  1064. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1065. },
  1066. {
  1067. DtNtextDeselectCallback,
  1068. DtCCallback, XtRCallback, sizeof (XtCallbackList),
  1069. XtOffset (DtEditorWidget, editor.textDeselect),
  1070. XtRCallback, (XtPointer) NULL
  1071. },
  1072. {
  1073. DtNtextForeground, DtCForeground,
  1074. XmRPixel, sizeof(Pixel),
  1075. XtOffset (DtEditorWidget, editor.editStuff.foreground),
  1076. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1077. },
  1078. {
  1079. DtNtextFontList, DtCFontList, XmRFontList, sizeof(XmFontList),
  1080. XtOffsetOf(struct _XmBulletinBoardRec,
  1081. bulletin_board.text_font_list),
  1082. XmRFontList, (XtPointer) NULL
  1083. },
  1084. {
  1085. DtNtextSelectCallback,
  1086. DtCCallback, XtRCallback, sizeof (XtCallbackList),
  1087. XtOffset (DtEditorWidget, editor.textSelect),
  1088. XtRCallback, (XtPointer) NULL
  1089. },
  1090. {
  1091. DtNtextTranslations, DtCTranslations,
  1092. XmRTranslationTable, sizeof (XtTranslations),
  1093. XtOffsetOf(struct _XmBulletinBoardRec,
  1094. bulletin_board.text_translations),
  1095. XmRImmediate, (XtPointer) NULL
  1096. },
  1097. {
  1098. DtNtopCharacter, DtCTopCharacter,
  1099. XmRTextPosition, sizeof(XmTextPosition),
  1100. XtOffset (DtEditorWidget, editor.editStuff.topCharacter),
  1101. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1102. },
  1103. {
  1104. DtNtotalLineCountLabel, DtCTotalLineCountLabel,
  1105. XmRXmString, sizeof (XmString),
  1106. XtOffset (DtEditorWidget,
  1107. editor.statusStuff.totalLineLabel),
  1108. XmRImmediate, (XtPointer) DtUNSPECIFIED
  1109. },
  1110. {
  1111. DtNwordWrap,
  1112. DtCWordWrap, XmRBoolean, sizeof (Boolean),
  1113. XtOffset (DtEditorWidget, editor.editStuff.wordWrap),
  1114. XmRImmediate, (XtPointer) False
  1115. },
  1116. };
  1117. /****************************************************************
  1118. *
  1119. * Public Function Declarations
  1120. *
  1121. ****************************************************************/
  1122. /****************************************************************
  1123. *
  1124. * Class Record
  1125. *
  1126. ****************************************************************/
  1127. externaldef( dteditorclassrec ) DtEditorClassRec
  1128. dtEditorClassRec =
  1129. {
  1130. /* Core Part
  1131. */
  1132. {
  1133. (WidgetClass) &xmFormClassRec, /* superclass */
  1134. "DtEditor", /* class_name */
  1135. sizeof (DtEditorRec), /* widget_size */
  1136. ClassInitialize, /* class_initialize */
  1137. NULL, /* class_part_initialize*/
  1138. False, /* class_inited */
  1139. (XtInitProc) Initialize, /* initialize */
  1140. NULL, /* initialize_hook */
  1141. XtInheritRealize, /* realize */
  1142. (XtActionList)EditorActionTable,/* actions */
  1143. (Cardinal)XtNumber(EditorActionTable), /* num_actions */
  1144. resources, /* resources */
  1145. XtNumber (resources), /* num_resources */
  1146. NULLQUARK, /* xrm_class */
  1147. True, /* compress_motion */
  1148. XtExposeCompressMaximal, /* compress_exposure */
  1149. False, /* compress_enterleave */
  1150. False, /* visible_interest */
  1151. (XtWidgetProc) Destroy, /* destroy */
  1152. XtInheritResize, /* resize */
  1153. XtInheritExpose, /* expose */
  1154. (XtSetValuesFunc) SetValues, /* set_values */
  1155. NULL, /* set_values_hook */
  1156. XtInheritSetValuesAlmost, /* set_values_almost */
  1157. NULL, /* get_values_hook */
  1158. XtInheritAcceptFocus, /* accept_focus */
  1159. XtVersion, /* version */
  1160. NULL, /* callback private */
  1161. XtInheritTranslations, /* tm_table */
  1162. XtInheritQueryGeometry, /* query_geometry */
  1163. (XtStringProc)NULL, /* display_accelerator */
  1164. NULL, /* extension */
  1165. },
  1166. /* Composite Part
  1167. */
  1168. {
  1169. XtInheritGeometryManager, /* geometry_manager */
  1170. XtInheritChangeManaged, /* change_managed */
  1171. XtInheritInsertChild, /* insert_child */
  1172. XtInheritDeleteChild, /* delete_child */
  1173. NULL, /* extension */
  1174. },
  1175. /* Constraint Part
  1176. */
  1177. {
  1178. NULL, /* constraint_resources */
  1179. 0, /* num_constraint_resource */
  1180. sizeof(XmFormConstraintRec), /* size of constraint */
  1181. NULL, /* initialization */
  1182. NULL, /* constraint_destroy */
  1183. NULL, /* constraint_set_values */
  1184. NULL, /* extension */
  1185. },
  1186. /* XmManager Part
  1187. */
  1188. {
  1189. XmInheritTranslations, /* default_translations */
  1190. syn_resources, /* syn_resources */
  1191. XtNumber(syn_resources), /* num_syn_resources */
  1192. NULL, /* syn_cont_resources */
  1193. 0, /* num_syn_cont_resources */
  1194. XmInheritParentProcess, /* parent_process */
  1195. NULL, /* extension */
  1196. },
  1197. /* XmbulletinBoard Part
  1198. */
  1199. {
  1200. FALSE, /* always_install_accelerators */
  1201. (XmGeoCreateProc)NULL, /* geo_matrix_create */
  1202. XmInheritFocusMovedProc, /* focus_moved_proc */
  1203. NULL, /* extension */
  1204. },
  1205. /* XmForm Part
  1206. */
  1207. {
  1208. NULL, /* extension */
  1209. },
  1210. /* DtEditor Part
  1211. */
  1212. {
  1213. 0, /* extension */
  1214. }
  1215. };
  1216. WidgetClass dtEditorWidgetClass = (WidgetClass) &dtEditorClassRec;
  1217. /*-------------------------------------------------------------
  1218. ** Editor Procs
  1219. **-------------------------------------------------------------
  1220. */
  1221. /****************************************************************
  1222. *
  1223. * Private Procs
  1224. *
  1225. ****************************************************************/
  1226. /*-------------------------------------------------------------
  1227. ** Function: static void ClassInitialize (void);
  1228. **
  1229. ** Parameters:
  1230. **
  1231. ** Purpose: This is the Editor class initializzation routine.
  1232. ** It is called once, before the first instance
  1233. ** is created.
  1234. */
  1235. static void
  1236. ClassInitialize(void)
  1237. {
  1238. #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
  1239. _DtEditor_blankClass = wctype(blankString);
  1240. /*
  1241. ** These calls determine if the particular value is True for
  1242. ** the current locale. A value of -1 is returned if the locale
  1243. ** does not support the charclass. If the locale supports the
  1244. ** charclass, the return value is passed as a parameter to the
  1245. ** iswctype call.
  1246. */
  1247. ekinclass = wctype("ekinsoku");
  1248. bekinclass = wctype("bkinsoku");
  1249. blnkclass = wctype("blank");
  1250. #endif /* end not Sun */
  1251. }
  1252. /*-------------------------------------------------------------
  1253. ** Function: static void Initialize (
  1254. ** Widget rw,
  1255. ** Widget nw,
  1256. ** ArgList arg_list,
  1257. ** Cardinal *num_args)
  1258. **
  1259. ** Parameters:
  1260. **
  1261. ** Purpose: This is the Editor widget initialize routine.
  1262. ** It is responsible for the following:
  1263. ** 1) Validate all resources the user passed in,
  1264. ** 2) Override any invalid resources,
  1265. ** 3) Initialize the internal data structures,
  1266. ** 4) Create the edit area widget
  1267. ** 5) Create the status area widget, if requested
  1268. ** 6) Add any callbacks and actions
  1269. */
  1270. static void
  1271. Initialize(
  1272. Widget rw,
  1273. Widget nw,
  1274. ArgList arg_list,
  1275. Cardinal *num_args)
  1276. {
  1277. DtEditorWidget request = (DtEditorWidget) rw,
  1278. new = (DtEditorWidget) nw;
  1279. /* Initialize non-resource portion of the instance structure */
  1280. VariableInitialize (new);
  1281. /* Validate the incoming arguments to make sure they are OK */
  1282. ValidateResources (new, request);
  1283. /*
  1284. * Create & customize the scrolled text widget
  1285. */
  1286. M_text(new) = CreateText (new);
  1287. XtManageChild( M_text(new)) ;
  1288. /*
  1289. * If the widget is not "read only" then register it as a drop zone
  1290. */
  1291. if ( M_editable(new) == True )
  1292. RegisterDropZone( new );
  1293. /*
  1294. * Compute the width & height of the scrolled text's font. These values
  1295. * will be used when formatting and in calculating the window manager
  1296. * hints.
  1297. */
  1298. getFontMetrics(new);
  1299. /*
  1300. * Create the status line
  1301. */
  1302. SetStatusLine( new, M_status_showStatusLine(request) );
  1303. } /* end Initialize */
  1304. /*-------------------------------------------------------------
  1305. ** Function: static void VariableInitialize (
  1306. ** DtEditorWidget new )
  1307. **
  1308. ** Parameters: The Editor widget being created
  1309. **
  1310. ** Purpose: This routine:
  1311. ** 1) Initializes the widget's instance structure
  1312. */
  1313. static void
  1314. VariableInitialize(
  1315. DtEditorWidget new)
  1316. {
  1317. Widget thisParent;
  1318. /*
  1319. * Initialize the non-resource instance fields
  1320. */
  1321. M_display(new) = XtDisplayOfObject( (Widget)new->core.parent );
  1322. M_app_context(new) = XtDisplayToApplicationContext(M_display(new));
  1323. /*
  1324. * Empty 'for' walks up the widget tree to find a shell.
  1325. */
  1326. for (thisParent = new->core.parent;
  1327. thisParent != (Widget)NULL && XtIsShell(thisParent) == False;
  1328. thisParent = XtParent(thisParent));
  1329. M_topLevelShell(new) = thisParent;
  1330. /* Initialize edit area fields */
  1331. M_loadingAllNewData(new) = False;
  1332. M_unreadChanges(new) = False; /* There have not been any changes since */
  1333. /* the app requested the data */
  1334. M_deletionStart(new) = NO_DELETION_IN_PROGRESS;
  1335. M_deletedText(new) = (char *)NULL;
  1336. M_insertStart(new) = 0;
  1337. M_insertionLength(new) = 0;
  1338. M_textSelectCbCalled(new) = False;
  1339. M_fontWidth(new) = -1;
  1340. /* Initialize status line fields */
  1341. M_status_statusArea(new) = (Widget)NULL;
  1342. M_status_messageText(new) = (Widget)NULL;
  1343. M_status_currentLine(new) = -1;
  1344. M_status_lastLine(new) = -1;
  1345. /* Initialize search function data */
  1346. M_search_dialog(new) = (Widget) NULL;
  1347. M_search_dialogMode(new) = SPELL;
  1348. M_search_string(new) = (char *)NULL;
  1349. M_replace_string(new) = (char *)NULL;
  1350. M_misspelled_string(new) = (char *)NULL;
  1351. M_misspelled_found(new) = False;
  1352. /* Initialize format function data */
  1353. M_format_dialog(new) = (Widget)NULL;
  1354. /* Initialize warning dialogs data */
  1355. M_gen_warning(new) = (Widget)NULL;
  1356. } /* end VariableInitialize */
  1357. /*-------------------------------------------------------------
  1358. ** Function: static void ValidateResources (
  1359. ** DtEditorWidget new,
  1360. ** DtEditorWidget request )
  1361. **
  1362. ** Parameters: The Editor widget being created & its requested
  1363. ** resource values
  1364. **
  1365. ** Purpose: This routine:
  1366. ** 1) Validates the widget's requested resources
  1367. */
  1368. static void
  1369. ValidateResources(
  1370. DtEditorWidget new,
  1371. DtEditorWidget request)
  1372. {
  1373. /*
  1374. * Validate the requested values for the editor's resources
  1375. */
  1376. /*
  1377. * Make local copies of all resource strings assigned by the application.
  1378. */
  1379. if (M_spellFilter(request) != (char *) NULL)
  1380. M_spellFilter(new) = XtNewString( M_spellFilter(request) );
  1381. /*
  1382. * Copy the dialog titles if the application set them, otherwise,
  1383. * get their values from the message catalog.
  1384. */
  1385. if (M_spellTitle(request) != (XmString) NULL)
  1386. M_spellTitle(new) = XmStringCopy( M_spellTitle(request) );
  1387. else
  1388. M_spellTitle(new) = XmStringCreateLocalized(SPELL_TITLE);
  1389. if (M_fndChngTitle(request) != (XmString) NULL)
  1390. M_fndChngTitle(new) = XmStringCopy( M_fndChngTitle(request) );
  1391. else
  1392. M_fndChngTitle(new) = XmStringCreateLocalized(FIND_TITLE);
  1393. if (E_format_dialogTitle(request) != (XmString) NULL)
  1394. E_format_dialogTitle(new) = XmStringCopy( E_format_dialogTitle(request) );
  1395. else
  1396. E_format_dialogTitle(new) = XmStringCreateLocalized(FORMAT_SETTINGS);
  1397. if (E_infoDialogTitle(request) != (XmString) NULL)
  1398. E_infoDialogTitle(new) = XmStringCopy( E_infoDialogTitle(request) );
  1399. else
  1400. E_infoDialogTitle(new) = XmStringCreateLocalized(INFO_TITLE);
  1401. /*
  1402. * Copy the insert & overstrike label indicators if the appli-
  1403. * cation set them, otherwise, get their value from the message
  1404. * catalog.
  1405. * Check for DtUNSPECIFIED because NULL is a valid value.
  1406. */
  1407. if (M_status_insertLabel(request) != (XmString) DtUNSPECIFIED)
  1408. M_status_insertLabel(new) =
  1409. XmStringCopy( M_status_insertLabel(request) );
  1410. else
  1411. M_status_insertLabel(new) = XmStringCreateLocalized(INS);
  1412. if (M_status_overstrikeLabel(request) != (XmString) DtUNSPECIFIED)
  1413. M_status_overstrikeLabel(new) =
  1414. XmStringCopy( M_status_overstrikeLabel(request) );
  1415. else
  1416. M_status_overstrikeLabel(new) = XmStringCreateLocalized(OVR);
  1417. } /* end ValidateResources */
  1418. /*-------------------------------------------------------------
  1419. ** Function: static Widget CreateText (
  1420. ** DtEditorWidget parent)
  1421. **
  1422. ** Parameters: The parent of the text widget
  1423. **
  1424. ** Purpose: This routine creates the scrolled text widget which
  1425. ** lives inside the editor widget.
  1426. ** It is responsible for the following:
  1427. ** 1) Creating the scrolled text widget,
  1428. ** 2) Adding specific translations,
  1429. ** 3) Adding our own callbacks,
  1430. ** 4) Substituting our own set selection routine.
  1431. */
  1432. static Widget
  1433. CreateText(
  1434. DtEditorWidget parent)
  1435. {
  1436. register int ac; /* arg count */
  1437. Arg al[21]; /* arg list */
  1438. Widget text;
  1439. /*
  1440. * First, set up the hardwired scrolled text widget resource values.
  1441. * (Change these and you die! Aha! Ha! Ha! Ha! [evil laugh])
  1442. */
  1443. ac = 0;
  1444. XtSetArg (al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
  1445. XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  1446. XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  1447. XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  1448. XtSetArg(al[ac], XmNpendingDelete, True); ac++;
  1449. /*
  1450. * Now, set up the resource values which can vary (passed in from
  1451. * application or default values).
  1452. *
  1453. * If a synthetic resource is DtUNSPECIFIED don't set it, but let
  1454. * it default to the scrolled text default value.
  1455. * If it is specified, clear the data field after setting the
  1456. * resource because the value in the field will be out of sync
  1457. * with the real value.
  1458. */
  1459. XtSetArg(al[ac], XmNautoShowCursorPosition, M_autoShowCursorPos(parent));
  1460. ac++;
  1461. XtSetArg(al[ac], XmNblinkRate, M_blinkRate(parent)); ac++;
  1462. if ( M_columns(parent) != DtUNSPECIFIED) {
  1463. XtSetArg (al[ac], XmNcolumns, M_columns(parent) ); ac++;
  1464. M_columns(parent) = (short) DtUNSPECIFIED;
  1465. }
  1466. if ( M_cursorPos(parent) != DtUNSPECIFIED) {
  1467. XtSetArg (al[ac], XmNcursorPosition, M_cursorPos(parent)); ac++;
  1468. M_cursorPos(parent) = (XmTextPosition) DtUNSPECIFIED;
  1469. }
  1470. XtSetArg(al[ac], XmNcursorPositionVisible, M_cursorPosVisible(parent));
  1471. ac++;
  1472. XtSetArg(al[ac], XmNeditable, M_editable(parent)); ac++;
  1473. if ( E_textFontList(parent) != (XmFontList) NULL) {
  1474. XtSetArg (al[ac], XmNfontList, E_textFontList(parent)); ac++;
  1475. }
  1476. if ( M_maxLength(parent) != DtUNSPECIFIED) {
  1477. XtSetArg (al[ac], XmNmaxLength, M_maxLength(parent) ); ac++;
  1478. M_maxLength(parent) = (int) DtUNSPECIFIED;
  1479. }
  1480. if ( M_rows(parent) != DtUNSPECIFIED) {
  1481. XtSetArg (al[ac], XmNrows, M_rows(parent) ); ac++;
  1482. M_rows(parent) = (short) DtUNSPECIFIED;
  1483. }
  1484. XtSetArg (al[ac], XmNscrollHorizontal, M_scrollHorizontal(parent) ); ac++;
  1485. if ( M_scrollLeftSide(parent) != (Boolean)DtUNSPECIFIED) {
  1486. XtSetArg (al[ac], XmNscrollLeftSide, M_scrollLeftSide(parent) ); ac++;
  1487. M_scrollLeftSide(parent) = (Boolean)DtUNSPECIFIED;
  1488. }
  1489. if ( M_scrollTopSide(parent) != (Boolean)DtUNSPECIFIED) {
  1490. XtSetArg (al[ac], XmNscrollTopSide, M_scrollTopSide(parent) ); ac++;
  1491. M_scrollTopSide(parent) = (Boolean)DtUNSPECIFIED;
  1492. }
  1493. XtSetArg (al[ac], XmNscrollVertical, M_scrollVertical(parent) ); ac++;
  1494. if ( M_topCharacter(parent) != DtUNSPECIFIED) {
  1495. XtSetArg (al[ac], XmNtopCharacter, M_topCharacter(parent) ); ac++;
  1496. M_topCharacter(parent) = (XmTextPosition) DtUNSPECIFIED;
  1497. }
  1498. XtSetArg (al[ac], XmNwordWrap, M_wordWrap(parent) ); ac++;
  1499. /* Create text widget */
  1500. text = XmCreateScrolledText ( (Widget) parent, "text", al, ac );
  1501. /*
  1502. * Now, set the foreground & background of the text widget. Could not
  1503. * set it at create time because the scrolled window would have
  1504. * picked it up, too.
  1505. */
  1506. ac=0;
  1507. if ( M_textBackground(parent) != DtUNSPECIFIED) {
  1508. XtSetArg (al[ac], XmNbackground, M_textBackground(parent) ); ac++;
  1509. M_textBackground(parent) = (Pixel) DtUNSPECIFIED;
  1510. }
  1511. if ( M_textForeground(parent) != DtUNSPECIFIED) {
  1512. XtSetArg (al[ac], XmNforeground, M_textForeground(parent) ); ac++;
  1513. M_textForeground(parent) = (Pixel) DtUNSPECIFIED;
  1514. }
  1515. if (ac)
  1516. XtSetValues( text, al, ac);
  1517. /* XXX Word Wrap workaround. See comments for FixWordWrap() */
  1518. if ( M_scrollHorizontal(parent) ) /* XXX Word Wrap workaround */
  1519. FixWordWrap(text, M_wordWrap(parent)); /* XXX Word Wrap workaround */
  1520. /* Put the editor-specific translation routines in place. */
  1521. XtOverrideTranslations(text,
  1522. XtParseTranslationTable(EditorTranslationTable));
  1523. /* Add any translations set by the application. */
  1524. if ( E_textTranslations(parent) != (XtTranslations)NULL ) {
  1525. XtOverrideTranslations(text, E_textTranslations(parent));
  1526. }
  1527. /*
  1528. * Add modify verify callback
  1529. */
  1530. XtAddCallback(text, XmNmodifyVerifyCallback,
  1531. (XtCallbackProc) _DtEditorModifyVerifyCB,
  1532. (XtPointer) parent);
  1533. /*
  1534. * Add the Help callback
  1535. */
  1536. XtAddCallback( text, XmNhelpCallback, (XtCallbackProc) HelpEditWindowCB,
  1537. (XtPointer) parent );
  1538. /*
  1539. * Substitute our own Set Selection routine which can
  1540. * call the textSelect and textDeselect callback procs
  1541. */
  1542. if(((XmTextWidget)(text))->text.source->SetSelection !=
  1543. Editor_SetSelectionProc) {
  1544. M_setSelection(parent) =
  1545. ((XmTextWidget)(text))->text.source->SetSelection;
  1546. ((XmTextWidget)(text))->text.source->SetSelection =
  1547. Editor_SetSelectionProc;
  1548. }
  1549. XtSetSensitive (text, True);
  1550. return(text);
  1551. } /* end CreateText */
  1552. /*-------------------------------------------------------------
  1553. ** Function: static int extractFontMetrics (
  1554. ** XmFontList fontlist )
  1555. **
  1556. ** Purpose: Given a font list, determine the width & height
  1557. ** of the characters.
  1558. **
  1559. ** This routine is lifted almost straight out of
  1560. ** lib/Xm/TextOut.c (see LoadFontMetrics() ) so the editor will
  1561. ** select the same font the text widget is working with.
  1562. */
  1563. static void
  1564. extractFontMetrics(
  1565. DtEditorWidget w,
  1566. XmFontList fontlist,
  1567. int *height,
  1568. int *width)
  1569. {
  1570. XmFontContext context;
  1571. XmFontListEntry next_entry;
  1572. XmFontType type_return = XmFONT_IS_FONT;
  1573. XtPointer tmp_font;
  1574. XFontStruct *font;
  1575. Boolean have_font_struct = False;
  1576. Boolean have_font_set = False;
  1577. Boolean use_font_set = False;
  1578. XFontSetExtents *fs_extents;
  1579. unsigned long tmp_width = 0;
  1580. int font_descent, font_ascent;
  1581. char* font_tag = NULL;
  1582. *width = *height = 0;
  1583. if (XmFontListInitFontContext(&context, fontlist)) {
  1584. /*
  1585. * Look through the font list for a fontset with the default tag.
  1586. * If we do not find it, use the first font set we came to, otherwise,
  1587. * use the first font struct we came to.
  1588. */
  1589. do {
  1590. Boolean do_break = False;
  1591. next_entry = XmFontListNextEntry(context);
  1592. if (next_entry) {
  1593. tmp_font = XmFontListEntryGetFont(next_entry, &type_return);
  1594. if (type_return == XmFONT_IS_FONTSET) {
  1595. /*
  1596. * Have a font set
  1597. */
  1598. font_tag = XmFontListEntryGetTag(next_entry);
  1599. if (!have_font_set){
  1600. /*
  1601. * Save the first fontset found in case we don't find
  1602. * a default tag font set.
  1603. */
  1604. have_font_set = True; /* we have a font set. */
  1605. use_font_set = True;
  1606. font = (XFontStruct *)tmp_font;
  1607. /*
  1608. * We have a font set, so no need to consider future font
  1609. * structs
  1610. */
  1611. have_font_struct = True;
  1612. /*
  1613. * If this is the default font set break out, we've
  1614. * found the one we want.
  1615. */
  1616. if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag))
  1617. do_break = True;
  1618. }
  1619. else if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag)) {
  1620. /*
  1621. * If this is the default font set save it & break out,
  1622. * we've found the one we want.
  1623. */
  1624. font = (XFontStruct *)tmp_font;
  1625. have_font_set = True;
  1626. do_break = True;
  1627. }
  1628. if (NULL != font_tag)
  1629. XtFree(font_tag);
  1630. if (do_break)
  1631. break;
  1632. }
  1633. else if (!have_font_struct){
  1634. /*
  1635. * Have a font
  1636. */
  1637. use_font_set = False;
  1638. /*
  1639. * Save the first one in case no font set is found
  1640. */
  1641. font = (XFontStruct *)tmp_font;
  1642. use_font_set = False;
  1643. have_font_struct = True;
  1644. }
  1645. }
  1646. } while (next_entry != NULL);
  1647. XmFontListFreeFontContext(context);
  1648. /*
  1649. * Now, extract the font metrics from the font set or font that
  1650. * we chose.
  1651. */
  1652. if (use_font_set) {
  1653. /*
  1654. * Chose a font set
  1655. */
  1656. fs_extents = XExtentsOfFontSet((XFontSet)font);
  1657. if (XmDirectionMatch(w->manager.string_direction,
  1658. XmTOP_TO_BOTTOM_RIGHT_TO_LEFT)) {
  1659. tmp_width = (unsigned long)fs_extents->max_ink_extent.width;
  1660. } else {
  1661. tmp_width = (unsigned long)fs_extents->max_logical_extent.width;
  1662. }
  1663. /* max_logical_extent.y is number of pixels from origin to top of
  1664. * rectangle (i.e. y is negative) */
  1665. font_ascent = -fs_extents->max_logical_extent.y;
  1666. font_descent = fs_extents->max_logical_extent.height +
  1667. fs_extents->max_logical_extent.y;
  1668. }
  1669. else {
  1670. /*
  1671. * Chose a font struct
  1672. */
  1673. font_ascent = font->max_bounds.ascent;
  1674. font_descent = font->max_bounds.descent;
  1675. if ( (!XGetFontProperty(font, XA_QUAD_WIDTH, &tmp_width)) ||
  1676. tmp_width == 0 )
  1677. {
  1678. if ( font->per_char && font->min_char_or_byte2 <= '0' &&
  1679. font->max_char_or_byte2 >= '0' )
  1680. tmp_width = font->per_char['0' - font->min_char_or_byte2].width;
  1681. else
  1682. tmp_width = font->max_bounds.width;
  1683. }
  1684. }
  1685. if (tmp_width <= 0) tmp_width = 1;
  1686. *width = (int)tmp_width; /* This assumes there will be no truncation */
  1687. *height = font_descent + font_ascent;
  1688. }
  1689. } /* end extractFontMetrics */
  1690. /*-------------------------------------------------------------
  1691. ** Function: static void getFontMetrics (
  1692. ** DtEditorWidget w )
  1693. **
  1694. ** Parameters: An Editor widget
  1695. **
  1696. ** Purpose: Determine the height & width of the scrolled text
  1697. ** widget's font
  1698. **
  1699. */
  1700. static void
  1701. getFontMetrics(
  1702. DtEditorWidget w)
  1703. {
  1704. Arg al[10]; /* arg list */
  1705. XmFontList fontlist;
  1706. int width, height;
  1707. /*
  1708. * Get the text widget's font list
  1709. *
  1710. * Note, have to retrieve the fontList from the text widget rather
  1711. * than use the DtNtextFontList resource because the text widget may
  1712. * have rejected the font specified with DtNtextFontList. This way
  1713. * we will get the fontList actually used by the text widget.
  1714. */
  1715. XtSetArg(al[0], XmNfontList, &fontlist);
  1716. XtGetValues(M_text(w), al, 1);
  1717. /*
  1718. * Now, extract the height and width
  1719. */
  1720. extractFontMetrics( w, fontlist, &height, &width );
  1721. M_fontWidth(w) = width;
  1722. M_fontHeight(w) = height;
  1723. } /* end getFontMetrics */
  1724. /*-------------------------------------------------------------
  1725. ** Destroy
  1726. ** Release resources allocated for a widget instance.
  1727. */
  1728. static void
  1729. Destroy(
  1730. Widget widget )
  1731. {
  1732. DtEditorWidget editor = (DtEditorWidget) widget;
  1733. /*
  1734. * Cleanup the edit window
  1735. */
  1736. /*
  1737. * (Nothing to be done. Unregistering it as a drop site is handled
  1738. * automatically by the DnD library.)
  1739. */
  1740. /*
  1741. * Cleanup the status line
  1742. */
  1743. if (M_status_insertLabel(editor) != (XmString)DtUNSPECIFIED)
  1744. XmStringFree(M_status_insertLabel(editor));
  1745. if (M_status_overstrikeLabel(editor) != (XmString)DtUNSPECIFIED)
  1746. XmStringFree(M_status_overstrikeLabel(editor));
  1747. if (E_status_currentLineLabel(editor) != (XmString)DtUNSPECIFIED)
  1748. XmStringFree(E_status_currentLineLabel(editor));
  1749. if (E_status_totalLineCountLabel(editor) != (XmString)DtUNSPECIFIED)
  1750. XmStringFree(E_status_totalLineCountLabel(editor));
  1751. /*
  1752. * Cleanup the Find/Change & Spell dialogs
  1753. */
  1754. if (M_search_string(editor))
  1755. XtFree(M_search_string(editor));
  1756. if (M_replace_string(editor))
  1757. XtFree(M_replace_string(editor));
  1758. if (M_misspelled_string(editor))
  1759. XtFree(M_misspelled_string(editor));
  1760. if (M_spellFilter(editor))
  1761. XtFree(M_spellFilter(editor));
  1762. if (M_spellTitle(editor) != (XmString)NULL)
  1763. XmStringFree(M_spellTitle(editor));
  1764. if (E_misspelledListLabel(editor) != (XmString)DtUNSPECIFIED)
  1765. XmStringFree(E_misspelledListLabel(editor));
  1766. if (M_fndChngTitle(editor) != (XmString)NULL)
  1767. XmStringFree(M_fndChngTitle(editor));
  1768. if (E_findFieldLabel(editor) != (XmString)DtUNSPECIFIED)
  1769. XmStringFree(E_findFieldLabel(editor));
  1770. if (E_changeFieldLabel(editor) != (XmString)DtUNSPECIFIED)
  1771. XmStringFree(E_changeFieldLabel(editor));
  1772. if (E_findButtonLabel(editor) != (XmString)DtUNSPECIFIED)
  1773. XmStringFree(E_findButtonLabel(editor));
  1774. if (E_changeButtonLabel(editor) != (XmString)DtUNSPECIFIED)
  1775. XmStringFree(E_changeButtonLabel(editor));
  1776. if (E_changeAllButtonLabel(editor) != (XmString)DtUNSPECIFIED)
  1777. XmStringFree(E_changeAllButtonLabel(editor));
  1778. /*
  1779. * Cleanup the Format Settings dialog
  1780. */
  1781. if (E_format_dialogTitle(editor) != (XmString)NULL)
  1782. XmStringFree(E_format_dialogTitle(editor));
  1783. if (E_format_leftMarginFieldLabel(editor) != (XmString)DtUNSPECIFIED)
  1784. XmStringFree(E_format_leftMarginFieldLabel(editor));
  1785. if (E_format_rightMarginFieldLabel(editor) != (XmString)DtUNSPECIFIED)
  1786. XmStringFree(E_format_rightMarginFieldLabel(editor));
  1787. if (E_format_leftAlignToggleLabel(editor) != (XmString)DtUNSPECIFIED)
  1788. XmStringFree(E_format_leftAlignToggleLabel(editor));
  1789. if (E_format_rightAlignToggleLabel(editor) != (XmString)DtUNSPECIFIED)
  1790. XmStringFree(E_format_rightAlignToggleLabel(editor));
  1791. if (E_format_justifyToggleLabel(editor) != (XmString)DtUNSPECIFIED)
  1792. XmStringFree(E_format_justifyToggleLabel(editor));
  1793. if (E_format_centerToggleLabel(editor) != (XmString)DtUNSPECIFIED)
  1794. XmStringFree(E_format_centerToggleLabel(editor));
  1795. if (E_format_formatAllButtonLabel(editor) != (XmString)DtUNSPECIFIED)
  1796. XmStringFree(E_format_formatAllButtonLabel(editor));
  1797. if (E_format_formatParagraphButtonLabel(editor) != (XmString)DtUNSPECIFIED)
  1798. XmStringFree(E_format_formatParagraphButtonLabel(editor));
  1799. /*
  1800. * Cleanup the Information dialog
  1801. */
  1802. if (E_infoDialogTitle(editor) != (XmString)NULL)
  1803. XmStringFree(E_infoDialogTitle(editor));
  1804. /*
  1805. * Cleanup the Undo deletion context
  1806. */
  1807. _DtEditorResetUndo(editor);
  1808. } /* end Destroy */
  1809. /*-------------------------------------------------------------
  1810. ** SetValues
  1811. ** Handle changes in resource data.
  1812. */
  1813. static Boolean
  1814. SetValues(
  1815. Widget cw,
  1816. Widget rw,
  1817. Widget nw )
  1818. {
  1819. Boolean redisplay_flag = False;
  1820. Arg al[10]; /* arg list */
  1821. register int ac; /* arg count */
  1822. Boolean resetSpellTitle = False,
  1823. resetFormatTitle = False,
  1824. resetInfoTitle = False,
  1825. newButtonFontList = False,
  1826. newLabelFontList = False,
  1827. newTextFontList = False,
  1828. NeedToFixWordWrap = False; /* XXX Word Wrap workaround*/
  1829. DtEditorWidget current = (DtEditorWidget) cw;
  1830. DtEditorWidget request = (DtEditorWidget) rw;
  1831. DtEditorWidget new = (DtEditorWidget) nw;
  1832. /*
  1833. * XXX Need to propagate changes to Core resources, like XmNbackground,
  1834. * to the children.
  1835. */
  1836. /*
  1837. * If a synthetic resource is specified, clear the data field
  1838. * after setting the resource because the value in the field
  1839. * will be out of sync with the real value (contained in the
  1840. * child widget).
  1841. */
  1842. /*
  1843. * General changes, not directly affecting a child
  1844. */
  1845. /* Check for a new spell filter */
  1846. if ( strcmp(M_spellFilter(request), M_spellFilter(current)) != 0 )
  1847. {
  1848. XtFree( M_spellFilter(current) );
  1849. M_spellFilter(new) = XtNewString( M_spellFilter(request) );
  1850. }
  1851. /* Check for new font lists */
  1852. if ( E_buttonFontList(request) != E_buttonFontList(current) )
  1853. newButtonFontList = True;
  1854. if ( E_labelFontList(request) != E_labelFontList(current) )
  1855. newLabelFontList = True;
  1856. if ( E_textFontList(request) != E_textFontList(current) )
  1857. newTextFontList = True;
  1858. /*
  1859. * Check for any changes which affect the dialog titles
  1860. */
  1861. if (XmStringCompare(E_dialogTitle(request),E_dialogTitle(current)) == False) {
  1862. resetSpellTitle = resetFormatTitle = resetInfoTitle = True;
  1863. }
  1864. if (XmStringCompare(M_spellTitle(request),M_spellTitle(current)) == False) {
  1865. XmStringFree( M_spellTitle(current) );
  1866. M_spellTitle(new) = XmStringCopy( M_spellTitle(request) );
  1867. resetSpellTitle = True;
  1868. }
  1869. if (XmStringCompare(M_fndChngTitle(request),M_fndChngTitle(current)) == False)
  1870. {
  1871. XmStringFree( M_fndChngTitle(current) );
  1872. M_fndChngTitle(new) = XmStringCopy( M_fndChngTitle(request) );
  1873. resetSpellTitle = True;
  1874. }
  1875. if (XmStringCompare(E_format_dialogTitle(request),
  1876. E_format_dialogTitle(current) ) == False)
  1877. {
  1878. XmStringFree( E_format_dialogTitle(current) );
  1879. E_format_dialogTitle(new) = XmStringCopy( E_format_dialogTitle(request) );
  1880. resetFormatTitle = True;
  1881. }
  1882. if (XmStringCompare(E_infoDialogTitle(request),
  1883. E_infoDialogTitle(current) ) == False)
  1884. {
  1885. XmStringFree( E_infoDialogTitle(current) );
  1886. E_infoDialogTitle(new) = XmStringCopy( E_infoDialogTitle(request) );
  1887. resetInfoTitle = True;
  1888. }
  1889. /*
  1890. * Calculate new titles for the dialogs depending upon which resources
  1891. * changed.
  1892. */
  1893. if ( resetSpellTitle == True ) {
  1894. /*
  1895. * No need to do anything because the Spell and Find/Change dialog
  1896. * titles are recomputed every time.
  1897. */
  1898. redisplay_flag = True;
  1899. }
  1900. if ( resetFormatTitle == True ) {
  1901. SetFormatDialogTitle( new );
  1902. redisplay_flag = True;
  1903. }
  1904. if ( resetInfoTitle == True ) {
  1905. SetInfoDialogTitle( new );
  1906. redisplay_flag = True;
  1907. }
  1908. /*
  1909. * Check for any changes which affect the status line
  1910. */
  1911. if (M_status_showStatusLine(request) != M_status_showStatusLine(current)) {
  1912. SetStatusLine( new, M_status_showStatusLine(request) );
  1913. redisplay_flag = True;
  1914. }
  1915. if ( M_overstrikeMode(request) != M_overstrikeMode(current) ) {
  1916. UpdateOverstrikeIndicator( new, M_overstrikeMode(request) );
  1917. XtCallActionProc( (Widget) M_text(current), "toggle-overstrike",
  1918. (XEvent *)NULL, (String *)NULL, 0 );
  1919. redisplay_flag = True;
  1920. }
  1921. if ( M_status_statusArea(current) != (Widget)NULL ) {
  1922. if (newLabelFontList == True) {
  1923. XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
  1924. XtSetValues( (Widget) M_status_lineLabel(current), al, 1);
  1925. XtSetValues( (Widget) M_status_totalLabel(current), al, 1);
  1926. XtSetValues( (Widget) M_status_totalText(current), al, 1);
  1927. XtSetValues( (Widget) M_status_overstrikeWidget(current), al, 1);
  1928. }
  1929. ac=0;
  1930. if (newTextFontList == True) {
  1931. XtSetArg( al[ac], XmNfontList, E_textFontList(request) ); ac++;
  1932. }
  1933. if ( M_textBackground(request) != DtUNSPECIFIED) {
  1934. XtSetArg( al[ac], XmNbackground, M_textBackground(request) ); ac++;
  1935. }
  1936. if ( M_textForeground(request) != DtUNSPECIFIED) {
  1937. XtSetArg( al[ac], XmNforeground, M_textForeground(request) ); ac++;
  1938. }
  1939. if ( ac ) {
  1940. XtSetValues( (Widget) M_status_lineText(current), al, ac);
  1941. XtSetValues( (Widget) M_status_messageText(current), al, ac);
  1942. }
  1943. }
  1944. /*
  1945. * Check for any changes which affect the dialog boxes
  1946. */
  1947. /* Information dialog */
  1948. if ( M_gen_warning(current) != (Widget)NULL ) {
  1949. if ( newButtonFontList == True ) {
  1950. XtSetArg (al[0], XmNfontList, E_buttonFontList(request) );
  1951. XtSetValues(
  1952. XmMessageBoxGetChild(M_gen_warning(current), XmDIALOG_OK_BUTTON),
  1953. al, 1 );
  1954. }
  1955. if ( newLabelFontList == True ) {
  1956. XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
  1957. XtSetValues(
  1958. XmMessageBoxGetChild(M_gen_warning(current), XmDIALOG_MESSAGE_LABEL),
  1959. al, 1 );
  1960. }
  1961. }
  1962. /* Find/Change dialog */
  1963. if ( M_search_dialog(current) != (Widget)NULL )
  1964. {
  1965. if ( newButtonFontList == True ) {
  1966. XtSetArg (al[0], XmNfontList, E_buttonFontList(request));
  1967. XtSetValues( (Widget)M_search_findBtn(current), al, 1 );
  1968. XtSetValues( (Widget)M_search_replaceBtn(current), al, 1 );
  1969. XtSetValues( (Widget)M_search_replaceAllBtn(current), al, 1 );
  1970. XtSetValues( (Widget)M_search_closeBtn(current), al, 1 );
  1971. XtSetValues( (Widget)M_search_helpBtn(current), al, 1 );
  1972. }
  1973. if ( newLabelFontList == True ) {
  1974. XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
  1975. XtSetValues( (Widget)M_search_listLbl(current), al, 1 );
  1976. XtSetValues( (Widget)M_search_findLbl(current), al, 1 );
  1977. XtSetValues( (Widget)M_search_replaceLbl(current), al, 1);
  1978. }
  1979. if ( newTextFontList == True ) {
  1980. XtSetArg (al[0], XmNfontList, E_textFontList(request) );
  1981. XtSetValues( (Widget)M_search_spellList(current), al, 1);
  1982. XtSetValues( (Widget)M_findText(current), al, 1 );
  1983. XtSetValues( (Widget)M_replaceText(current), al, 1 );
  1984. }
  1985. ac=0;
  1986. if ( M_textBackground(request) != DtUNSPECIFIED) {
  1987. XtSetArg( al[ac], XmNbackground, M_textBackground(request) ); ac++;
  1988. }
  1989. if ( M_textForeground(request) != DtUNSPECIFIED) {
  1990. XtSetArg( al[ac], XmNforeground, M_textForeground(request) ); ac++;
  1991. }
  1992. if ( ac ) {
  1993. XtSetValues( (Widget) M_findText(current), al, ac);
  1994. XtSetValues( (Widget) M_replaceText(current), al, ac);
  1995. }
  1996. }
  1997. /* Format Settings dialog */
  1998. if ( M_format_dialog(current) != (Widget)NULL )
  1999. {
  2000. if ( newButtonFontList == True ) {
  2001. XtSetArg (al[0], XmNfontList, E_buttonFontList(request));
  2002. XtSetValues( (Widget)M_format_leftJust(current), al, 1 );
  2003. XtSetValues( (Widget)M_format_rightJust(current), al, 1);
  2004. XtSetValues( (Widget)M_format_bothJust(current), al, 1 );
  2005. XtSetValues( (Widget)M_format_center(current), al, 1 );
  2006. XtSetValues( (Widget)M_format_paragraph(current), al, 1);
  2007. XtSetValues( (Widget)M_format_all(current), al, 1 );
  2008. XtSetValues( (Widget)M_format_close(current), al, 1 );
  2009. XtSetValues( (Widget)M_format_help(current), al, 1 );
  2010. }
  2011. if ( newLabelFontList == True ) {
  2012. XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
  2013. XtSetValues( (Widget)M_format_leftLabel(current), al, 1 );
  2014. XtSetValues( (Widget)M_format_rightLabel(current), al, 1);
  2015. }
  2016. if ( newTextFontList == True ) {
  2017. XtSetArg (al[0], XmNfontList, E_textFontList(request) );
  2018. XtSetValues( (Widget)M_format_leftMarginField(current), al, 1 );
  2019. XtSetValues( (Widget)M_format_rightMarginField(current), al, 1);
  2020. }
  2021. ac=0;
  2022. if ( M_textBackground(request) != DtUNSPECIFIED) {
  2023. XtSetArg( al[ac], XmNbackground, M_textBackground(request) ); ac++;
  2024. }
  2025. if ( M_textForeground(request) != DtUNSPECIFIED) {
  2026. XtSetArg( al[ac], XmNforeground, M_textForeground(request) ); ac++;
  2027. }
  2028. if ( ac ) {
  2029. XtSetValues( (Widget) M_format_leftMarginField(current), al, ac);
  2030. XtSetValues( (Widget) M_format_rightMarginField(current), al, ac);
  2031. }
  2032. }
  2033. /*
  2034. * Check for any changes which affect the edit area (scrolled text widget)
  2035. */
  2036. ac=0;
  2037. if ( M_autoShowCursorPos(request) != M_autoShowCursorPos(current) ) {
  2038. XtSetArg( al[ac], XmNautoShowCursorPosition, M_autoShowCursorPos(request));
  2039. ac++;
  2040. }
  2041. if ( M_blinkRate(request) != M_blinkRate(current) ) {
  2042. XtSetArg( al[ac], XmNblinkRate, M_blinkRate(request)); ac++;
  2043. }
  2044. if ( M_columns(request) != DtUNSPECIFIED) {
  2045. XtSetArg (al[ac], XmNcolumns, M_columns(request) ); ac++;
  2046. M_columns(new) = (short) DtUNSPECIFIED;
  2047. redisplay_flag = True;
  2048. }
  2049. /* PERF - disable redisplay for all SetValues */
  2050. if ( M_cursorPos(request) != DtUNSPECIFIED) {
  2051. XmTextSetCursorPosition( M_text(new), M_topCharacter(request) );
  2052. M_cursorPos(new) = (XmTextPosition) DtUNSPECIFIED;
  2053. }
  2054. if ( M_cursorPosVisible(request) != M_cursorPosVisible(current) ) {
  2055. XtSetArg( al[ac], XmNcursorPositionVisible, M_cursorPosVisible(request));
  2056. ac++;
  2057. }
  2058. if ( M_editable(request) != M_editable(current) ) {
  2059. XtSetArg( al[ac], XmNeditable, M_editable(request)); ac++;
  2060. if( M_editable(request) ) {
  2061. /*
  2062. * If the widget is becoming editable, register it as a
  2063. * drop site and...
  2064. */
  2065. RegisterDropZone( new );
  2066. /*
  2067. * ...turn back on the Change To field in the Find/Change dialog
  2068. */
  2069. if ( M_search_dialog(current) != (Widget)NULL ) {
  2070. XtSetSensitive(M_search_replaceLbl(current), True);
  2071. XtSetSensitive(M_replaceText(current), True);
  2072. }
  2073. }
  2074. else
  2075. /*
  2076. * It's no longer available as a drop site.
  2077. */
  2078. UnregisterDropZone( current );
  2079. }
  2080. if ( M_maxLength(request) != DtUNSPECIFIED) {
  2081. XtSetArg (al[ac], XmNmaxLength, M_maxLength(request) ); ac++;
  2082. M_maxLength(new) = (int) DtUNSPECIFIED;
  2083. }
  2084. if ( M_rows(request) != DtUNSPECIFIED) {
  2085. XtSetArg (al[ac], XmNrows, M_rows(request) ); ac++;
  2086. M_rows(new) = (short) DtUNSPECIFIED;
  2087. redisplay_flag = True;
  2088. }
  2089. if ( M_textBackground(request) != DtUNSPECIFIED) {
  2090. XtSetArg (al[ac], XmNbackground, M_textBackground(request) ); ac++;
  2091. M_textBackground(new) = (XmTextPosition) DtUNSPECIFIED;
  2092. redisplay_flag = True;
  2093. }
  2094. if ( newTextFontList == True ) {
  2095. XtSetArg (al[ac], XmNfontList, E_textFontList(request) ); ac++;
  2096. redisplay_flag = True;
  2097. }
  2098. if ( M_textForeground(request) != DtUNSPECIFIED) {
  2099. XtSetArg (al[ac], XmNforeground, M_textForeground(request) ); ac++;
  2100. M_textForeground(new) = (XmTextPosition) DtUNSPECIFIED;
  2101. redisplay_flag = True;
  2102. }
  2103. /* PERF - disable redisplay for all SetValues */
  2104. if ( M_topCharacter(request) != DtUNSPECIFIED) {
  2105. XmTextSetTopCharacter( M_text(new), M_topCharacter(request) );
  2106. M_topCharacter(new) = (XmTextPosition) DtUNSPECIFIED;
  2107. }
  2108. if ( M_wordWrap(request) != M_wordWrap(current) ) {
  2109. XtSetArg( al[ac], XmNwordWrap, M_wordWrap(request)); ac++;
  2110. NeedToFixWordWrap=M_scrollHorizontal(current);/*XXX Word Wrap workaround*/
  2111. }
  2112. if ( NeedToFixWordWrap ) /*XXX Word Wrap workaround*/
  2113. FixWordWrap(M_text(new), M_wordWrap(request));/*XXX Word Wrap workaround*/
  2114. if ( ac )
  2115. XtSetValues( (Widget) M_text(new), al, ac);
  2116. if ( E_textTranslations(request) != E_textTranslations(current) ) {
  2117. XtOverrideTranslations(M_text(new), E_textTranslations(request));
  2118. }
  2119. if ( newTextFontList == True ) {
  2120. getFontMetrics(new);
  2121. }
  2122. return (redisplay_flag);
  2123. } /* end Set values */
  2124. /**************************************************************
  2125. **
  2126. ** Get values routines for synthetic resources
  2127. **
  2128. **/
  2129. static void
  2130. _DtEditorGetCenterToggleLabel(
  2131. Widget wid,
  2132. int resource_offset,
  2133. XtArgVal *value )
  2134. {
  2135. DtEditorWidget editor = (DtEditorWidget) wid;
  2136. XmString data;
  2137. Arg al[1];
  2138. /*
  2139. * Get the value directly from the field in the instance structure.
  2140. * If it is DtUNSPECIFIED then either:
  2141. * 1) the value has been assigned to the widget (so get it from
  2142. * there), or
  2143. * 2) the value has never been set (so return the default value).
  2144. */
  2145. if (E_format_centerToggleLabel(editor) != (XmString) DtUNSPECIFIED)
  2146. data = XmStringCopy( E_format_centerToggleLabel(editor) );
  2147. else if (M_format_dialog(editor) != (Widget)NULL)
  2148. {
  2149. XtSetArg( al[0], XmNlabelString, &data) ;
  2150. XtGetValues( (Widget) M_format_center(editor), al, 1) ;
  2151. }
  2152. else
  2153. data = XmStringCreateLocalized(CENTER);
  2154. *value = (XtArgVal) data ;
  2155. return;
  2156. } /* end _DtEditorGetCenterToggleLabel */
  2157. static void
  2158. _DtEditorGetChangeAllButtonLabel(
  2159. Widget wid,
  2160. int resource_offset,
  2161. XtArgVal *value )
  2162. {
  2163. DtEditorWidget editor = (DtEditorWidget) wid;
  2164. XmString data;
  2165. Arg al[1];
  2166. /*
  2167. * Get the value directly from the field in the instance structure.
  2168. * If it is DtUNSPECIFIED then either:
  2169. * 1) the value has been assigned to the widget (so get it from
  2170. * there), or
  2171. * 2) the value has never been set (so return the default value).
  2172. */
  2173. if (E_changeAllButtonLabel(editor) != (XmString) DtUNSPECIFIED)
  2174. data = XmStringCopy( E_changeAllButtonLabel(editor) );
  2175. else if (M_search_dialog(editor) != (Widget) NULL)
  2176. {
  2177. XtSetArg( al[0], XmNlabelString, &data) ;
  2178. XtGetValues( (Widget) M_search_replaceAllBtn(editor), al, 1) ;
  2179. }
  2180. else
  2181. data = XmStringCreateLocalized(CHNG_ALL_BUTTON);
  2182. *value = (XtArgVal) data ;
  2183. return;
  2184. } /* end _DtEditorGetChangeAllButtonLabel */
  2185. static void
  2186. _DtEditorGetChangeButtonLabel(
  2187. Widget wid,
  2188. int resource_offset,
  2189. XtArgVal *value )
  2190. {
  2191. DtEditorWidget editor = (DtEditorWidget) wid;
  2192. XmString data;
  2193. Arg al[1];
  2194. /*
  2195. * Get the value directly from the field in the instance structure.
  2196. * If it is DtUNSPECIFIED then either:
  2197. * 1) the value has been assigned to the widget (so get it from
  2198. * there), or
  2199. * 2) the value has never been set (so return the default value).
  2200. */
  2201. if (E_changeButtonLabel(editor) != (XmString) DtUNSPECIFIED)
  2202. data = XmStringCopy( E_changeButtonLabel(editor) );
  2203. else if (M_search_dialog(editor) != (Widget) NULL)
  2204. {
  2205. XtSetArg( al[0], XmNlabelString, &data) ;
  2206. XtGetValues( (Widget) M_search_replaceBtn(editor), al, 1) ;
  2207. }
  2208. else
  2209. data = XmStringCreateLocalized(CHANGE_BUTTON);
  2210. *value = (XtArgVal) data ;
  2211. return;
  2212. } /* end _DtEditorGetChangeButtonLabel */
  2213. static void
  2214. _DtEditorGetChangeFieldLabel(
  2215. Widget wid,
  2216. int resource_offset,
  2217. XtArgVal *value )
  2218. {
  2219. DtEditorWidget editor = (DtEditorWidget) wid;
  2220. XmString data;
  2221. Arg al[1];
  2222. /*
  2223. * Get the value directly from the field in the instance structure.
  2224. * If it is DtUNSPECIFIED then either:
  2225. * 1) the value has been assigned to the widget (so get it from
  2226. * there), or
  2227. * 2) the value has never been set (so return the default value).
  2228. */
  2229. if (E_changeFieldLabel(editor) != (XmString) DtUNSPECIFIED)
  2230. data = XmStringCopy( E_changeFieldLabel(editor) );
  2231. else if (M_search_dialog(editor) != (Widget) NULL)
  2232. {
  2233. XtSetArg( al[0], XmNlabelString, &data) ;
  2234. XtGetValues( (Widget) M_search_replaceLbl(editor), al, 1) ;
  2235. }
  2236. else
  2237. data = XmStringCreateLocalized(CHANGE_LABEL);
  2238. *value = (XtArgVal) data ;
  2239. return;
  2240. } /* end _DtEditorGetChangeFieldLabel */
  2241. static void
  2242. _DtEditorGetColumns(
  2243. Widget wid,
  2244. int resource_offset,
  2245. XtArgVal *value )
  2246. {
  2247. DtEditorWidget editor = (DtEditorWidget) wid;
  2248. short data;
  2249. Arg al[1];
  2250. XtSetArg( al[0], XmNcolumns, &data) ;
  2251. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2252. *value = (XtArgVal) data ;
  2253. return;
  2254. } /* end _DtEditorGetColumns */
  2255. static void
  2256. _DtEditorGetCurrentLineLabel(
  2257. Widget wid,
  2258. int resource_offset,
  2259. XtArgVal *value )
  2260. {
  2261. DtEditorWidget editor = (DtEditorWidget) wid;
  2262. XmString data;
  2263. Arg al[1];
  2264. /*
  2265. * Get the value directly from the field in the instance structure.
  2266. * If it is DtUNSPECIFIED then either:
  2267. * 1) the value has been assigned to the widget (so get it from
  2268. * there), or
  2269. * 2) the value has never been set (so return the default value).
  2270. */
  2271. if (E_status_currentLineLabel(editor) != (XmString) DtUNSPECIFIED)
  2272. data = XmStringCopy( E_status_currentLineLabel(editor) );
  2273. else if (M_status_statusArea(editor) != (Widget) NULL)
  2274. {
  2275. XtSetArg( al[0], XmNlabelString, &data) ;
  2276. XtGetValues( (Widget) M_status_lineLabel(editor), al, 1) ;
  2277. }
  2278. else
  2279. data = XmStringCreateLocalized(LINE);
  2280. *value = (XtArgVal) data ;
  2281. return;
  2282. } /* end _DtEditorGetCurrentLineLabel */
  2283. static void
  2284. _DtEditorGetCursorPosition(
  2285. Widget wid,
  2286. int resource_offset,
  2287. XtArgVal *value )
  2288. {
  2289. DtEditorWidget editor = (DtEditorWidget) wid;
  2290. XmTextPosition data;
  2291. Arg al[1];
  2292. XtSetArg( al[0], XmNcursorPosition, &data) ;
  2293. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2294. *value = (XtArgVal) data ;
  2295. return;
  2296. } /* end _DtEditorGetCursorPosition */
  2297. static void
  2298. _DtEditorGetFindButtonLabel(
  2299. Widget wid,
  2300. int resource_offset,
  2301. XtArgVal *value )
  2302. {
  2303. DtEditorWidget editor = (DtEditorWidget) wid;
  2304. XmString data;
  2305. Arg al[1];
  2306. /*
  2307. * Get the value directly from the field in the instance structure.
  2308. * If it is DtUNSPECIFIED then either:
  2309. * 1) the value has been assigned to the widget (so get it from
  2310. * there), or
  2311. * 2) the value has never been set (so return the default value).
  2312. */
  2313. if (E_findButtonLabel(editor) != (XmString) DtUNSPECIFIED)
  2314. data = XmStringCopy( E_findButtonLabel(editor) );
  2315. else if (M_search_dialog(editor) != (Widget) NULL)
  2316. {
  2317. XtSetArg( al[0], XmNlabelString, &data) ;
  2318. XtGetValues( (Widget) M_search_findBtn(editor), al, 1) ;
  2319. }
  2320. else
  2321. data = XmStringCreateLocalized(FIND_BUTTON);
  2322. *value = (XtArgVal) data ;
  2323. return;
  2324. } /* end _DtEditorGetFindButtonLabel */
  2325. static void
  2326. _DtEditorGetFindFieldLabel(
  2327. Widget wid,
  2328. int resource_offset,
  2329. XtArgVal *value )
  2330. {
  2331. DtEditorWidget editor = (DtEditorWidget) wid;
  2332. XmString data;
  2333. Arg al[1];
  2334. /*
  2335. * Get the value directly from the field in the instance structure.
  2336. * If it is DtUNSPECIFIED then either:
  2337. * 1) the value has been assigned to the widget (so get it from
  2338. * there), or
  2339. * 2) the value has never been set (so return the default value).
  2340. */
  2341. if (E_findFieldLabel(editor) != (XmString) DtUNSPECIFIED)
  2342. data = XmStringCopy( E_findFieldLabel(editor) );
  2343. else if (M_search_dialog(editor) != (Widget) NULL)
  2344. {
  2345. XtSetArg( al[0], XmNlabelString, &data) ;
  2346. XtGetValues( (Widget) M_search_findLbl(editor), al, 1) ;
  2347. }
  2348. else
  2349. data = XmStringCreateLocalized(FIND_LABEL);
  2350. *value = (XtArgVal) data ;
  2351. return;
  2352. } /* end _DtEditorGetFindFieldLabel */
  2353. static void
  2354. _DtEditorGetFormatAllButtonLabel(
  2355. Widget wid,
  2356. int resource_offset,
  2357. XtArgVal *value )
  2358. {
  2359. DtEditorWidget editor = (DtEditorWidget) wid;
  2360. XmString data;
  2361. Arg al[1];
  2362. /*
  2363. * Get the value directly from the field in the instance structure.
  2364. * If it is DtUNSPECIFIED then either:
  2365. * 1) the value has been assigned to the widget (so get it from
  2366. * there), or
  2367. * 2) the value has never been set (so return the default value).
  2368. */
  2369. if (E_format_formatAllButtonLabel(editor) != (XmString) DtUNSPECIFIED)
  2370. data = XmStringCopy( E_format_formatAllButtonLabel(editor) );
  2371. else if (M_format_dialog(editor) != (Widget)NULL)
  2372. {
  2373. XtSetArg( al[0], XmNlabelString, &data) ;
  2374. XtGetValues( (Widget) M_format_all(editor), al, 1) ;
  2375. }
  2376. else
  2377. data = XmStringCreateLocalized(ALL);
  2378. *value = (XtArgVal) data ;
  2379. return;
  2380. } /* end _DtEditorGetFormatAllButtonLabel */
  2381. static void
  2382. _DtEditorGetFormatParagraphButtonLabel(
  2383. Widget wid,
  2384. int resource_offset,
  2385. XtArgVal *value )
  2386. {
  2387. DtEditorWidget editor = (DtEditorWidget) wid;
  2388. XmString data;
  2389. Arg al[1];
  2390. /*
  2391. * Get the value directly from the field in the instance structure.
  2392. * If it is DtUNSPECIFIED then either:
  2393. * 1) the value has been assigned to the widget (so get it from
  2394. * there), or
  2395. * 2) the value has never been set (so return the default value).
  2396. */
  2397. if(E_format_formatParagraphButtonLabel(editor) != (XmString) DtUNSPECIFIED)
  2398. data = XmStringCopy( E_format_formatParagraphButtonLabel(editor) );
  2399. else if (M_format_dialog(editor) != (Widget)NULL)
  2400. {
  2401. XtSetArg( al[0], XmNlabelString, &data) ;
  2402. XtGetValues( (Widget) M_format_paragraph(editor), al, 1) ;
  2403. }
  2404. else
  2405. data = XmStringCreateLocalized(PARAGRAPH);
  2406. *value = (XtArgVal) data ;
  2407. return;
  2408. } /* end _DtEditorGetFormatParagraphButtonLabel */
  2409. static void
  2410. _DtEditorGetJustifyToggleLabel(
  2411. Widget wid,
  2412. int resource_offset,
  2413. XtArgVal *value )
  2414. {
  2415. DtEditorWidget editor = (DtEditorWidget) wid;
  2416. XmString data;
  2417. Arg al[1];
  2418. /*
  2419. * Get the value directly from the field in the instance structure.
  2420. * If it is DtUNSPECIFIED then either:
  2421. * 1) the value has been assigned to the widget (so get it from
  2422. * there), or
  2423. * 2) the value has never been set (so return the default value).
  2424. */
  2425. if (E_format_justifyToggleLabel(editor) != (XmString) DtUNSPECIFIED)
  2426. data = XmStringCopy( E_format_justifyToggleLabel(editor) );
  2427. else if (M_format_dialog(editor) != (Widget)NULL)
  2428. {
  2429. XtSetArg( al[0], XmNlabelString, &data) ;
  2430. XtGetValues( (Widget) M_format_bothJust(editor), al, 1) ;
  2431. }
  2432. else
  2433. data = XmStringCreateLocalized(JUSTIFY);
  2434. *value = (XtArgVal) data ;
  2435. return;
  2436. } /* end _DtEditorGetJustifyToggleLabel */
  2437. static void
  2438. _DtEditorGetLeftAlignToggleLabel(
  2439. Widget wid,
  2440. int resource_offset,
  2441. XtArgVal *value )
  2442. {
  2443. DtEditorWidget editor = (DtEditorWidget) wid;
  2444. XmString data;
  2445. Arg al[1];
  2446. /*
  2447. * Get the value directly from the field in the instance structure.
  2448. * If it is DtUNSPECIFIED then either:
  2449. * 1) the value has been assigned to the widget (so get it from
  2450. * there), or
  2451. * 2) the value has never been set (so return the default value).
  2452. */
  2453. if (E_format_leftAlignToggleLabel(editor) != (XmString) DtUNSPECIFIED)
  2454. data = XmStringCopy( E_format_leftAlignToggleLabel(editor) );
  2455. else if (M_format_dialog(editor) != (Widget)NULL)
  2456. {
  2457. XtSetArg( al[0], XmNlabelString, &data) ;
  2458. XtGetValues( (Widget) M_format_leftJust(editor), al, 1) ;
  2459. }
  2460. else
  2461. data = XmStringCreateLocalized(LEFT_ALIGN);
  2462. *value = (XtArgVal) data ;
  2463. return;
  2464. } /* end _DtEditorGetLeftAlignToggleLabel */
  2465. static void
  2466. _DtEditorGetLeftMarginFieldLabel(
  2467. Widget wid,
  2468. int resource_offset,
  2469. XtArgVal *value )
  2470. {
  2471. DtEditorWidget editor = (DtEditorWidget) wid;
  2472. XmString data;
  2473. Arg al[1];
  2474. /*
  2475. * Get the value directly from the field in the instance structure.
  2476. * If it is DtUNSPECIFIED then either:
  2477. * 1) the value has been assigned to the widget (so get it from
  2478. * there), or
  2479. * 2) the value has never been set (so return the default value).
  2480. */
  2481. if (E_format_leftMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED)
  2482. data = XmStringCopy( E_format_leftMarginFieldLabel(editor) );
  2483. else if (M_format_dialog(editor) != (Widget)NULL)
  2484. {
  2485. XtSetArg( al[0], XmNlabelString, &data) ;
  2486. XtGetValues( (Widget) M_format_leftLabel(editor), al, 1) ;
  2487. }
  2488. else
  2489. data = XmStringCreateLocalized(LEFT_MARGIN);
  2490. *value = (XtArgVal) data ;
  2491. return;
  2492. } /* end _DtEditorGetLeftMarginFieldLabel */
  2493. static void
  2494. _DtEditorGetMaxLength(
  2495. Widget wid,
  2496. int resource_offset,
  2497. XtArgVal *value )
  2498. {
  2499. DtEditorWidget editor = (DtEditorWidget) wid;
  2500. int data;
  2501. Arg al[1];
  2502. XtSetArg( al[0], XmNmaxLength, &data) ;
  2503. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2504. *value = (XtArgVal) data ;
  2505. return;
  2506. } /* end _DtEditorGetMaxLength */
  2507. static void
  2508. _DtEditorGetMisspelledListLabel(
  2509. Widget wid,
  2510. int resource_offset,
  2511. XtArgVal *value )
  2512. {
  2513. DtEditorWidget editor = (DtEditorWidget) wid;
  2514. XmString data;
  2515. Arg al[1];
  2516. /*
  2517. * Get the value directly from the field in the instance structure.
  2518. * If it is DtUNSPECIFIED then either:
  2519. * 1) the value has been assigned to the widget (so get it from
  2520. * there), or
  2521. * 2) the value has never been set (so return the default value).
  2522. */
  2523. if (E_misspelledListLabel(editor) != (XmString) DtUNSPECIFIED)
  2524. data = XmStringCopy( E_misspelledListLabel(editor) );
  2525. else if (M_search_dialog(editor) != (Widget) NULL)
  2526. {
  2527. XtSetArg( al[0], XmNlabelString, &data) ;
  2528. XtGetValues( (Widget) M_search_listLbl(editor), al, 1) ;
  2529. }
  2530. else
  2531. data = XmStringCreateLocalized(MISSPELLED);
  2532. *value = (XtArgVal) data ;
  2533. return;
  2534. } /* end _DtEditorGetMisspelledListLabel */
  2535. static void
  2536. _DtEditorGetRightAlignToggleLabel(
  2537. Widget wid,
  2538. int resource_offset,
  2539. XtArgVal *value )
  2540. {
  2541. DtEditorWidget editor = (DtEditorWidget) wid;
  2542. XmString data;
  2543. Arg al[1];
  2544. /*
  2545. * Get the value directly from the field in the instance structure.
  2546. * If it is DtUNSPECIFIED then either:
  2547. * 1) the value has been assigned to the widget (so get it from
  2548. * there), or
  2549. * 2) the value has never been set (so return the default value).
  2550. */
  2551. if (E_format_rightAlignToggleLabel(editor) != (XmString) DtUNSPECIFIED)
  2552. data = XmStringCopy( E_format_rightAlignToggleLabel(editor) );
  2553. else if (M_format_dialog(editor) != (Widget)NULL)
  2554. {
  2555. XtSetArg( al[0], XmNlabelString, &data) ;
  2556. XtGetValues( (Widget) M_format_rightJust(editor), al, 1) ;
  2557. }
  2558. else
  2559. data = XmStringCreateLocalized(RIGHT_ALIGN);
  2560. *value = (XtArgVal) data ;
  2561. return;
  2562. } /* end _DtEditorGetRightAlignToggleLabel */
  2563. static void
  2564. _DtEditorGetRightMarginFieldLabel(
  2565. Widget wid,
  2566. int resource_offset,
  2567. XtArgVal *value )
  2568. {
  2569. DtEditorWidget editor = (DtEditorWidget) wid;
  2570. XmString data;
  2571. Arg al[1];
  2572. /*
  2573. * Get the value directly from the field in the instance structure.
  2574. * If it is DtUNSPECIFIED then either:
  2575. * 1) the value has been assigned to the widget (so get it from
  2576. * there), or
  2577. * 2) the value has never been set (so return the default value).
  2578. */
  2579. if (E_format_rightMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED)
  2580. data = XmStringCopy( E_format_rightMarginFieldLabel(editor) );
  2581. else if (M_format_dialog(editor) != (Widget)NULL)
  2582. {
  2583. XtSetArg( al[0], XmNlabelString, &data) ;
  2584. XtGetValues( (Widget) M_format_rightLabel(editor), al, 1) ;
  2585. }
  2586. else
  2587. data = XmStringCreateLocalized(RIGHT_MARGIN);
  2588. *value = (XtArgVal) data ;
  2589. return;
  2590. } /* end _DtEditorGetRightMarginFieldLabel */
  2591. static void
  2592. _DtEditorGetRows(
  2593. Widget wid,
  2594. int resource_offset,
  2595. XtArgVal *value )
  2596. {
  2597. DtEditorWidget editor = (DtEditorWidget) wid;
  2598. short data;
  2599. Arg al[1];
  2600. XtSetArg( al[0], XmNrows, &data) ;
  2601. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2602. *value = (XtArgVal) data ;
  2603. return;
  2604. } /* end _DtEditorGetRows */
  2605. static void
  2606. _DtEditorGetScrollLeftSide(
  2607. Widget wid,
  2608. int resource_offset,
  2609. XtArgVal *value )
  2610. {
  2611. DtEditorWidget editor = (DtEditorWidget) wid;
  2612. Boolean data;
  2613. Arg al[1];
  2614. XtSetArg( al[0], XmNscrollLeftSide, &data) ;
  2615. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2616. *value = (XtArgVal) data ;
  2617. return;
  2618. } /* end _DtEditorGetScrollLeftSide */
  2619. static void
  2620. _DtEditorGetScrollTopSide(
  2621. Widget wid,
  2622. int resource_offset,
  2623. XtArgVal *value )
  2624. {
  2625. DtEditorWidget editor = (DtEditorWidget) wid;
  2626. Boolean data;
  2627. Arg al[1];
  2628. XtSetArg( al[0], XmNscrollTopSide, &data) ;
  2629. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2630. *value = (XtArgVal) data ;
  2631. return;
  2632. } /* end _DtEditorGetScrollTopSide */
  2633. static void
  2634. _DtEditorGetTextBackground(
  2635. Widget wid,
  2636. int resource_offset,
  2637. XtArgVal *value )
  2638. {
  2639. DtEditorWidget editor = (DtEditorWidget) wid;
  2640. Pixel data;
  2641. Arg al[1];
  2642. XtSetArg( al[0], XmNbackground, &data) ;
  2643. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2644. *value = (XtArgVal) data ;
  2645. return;
  2646. } /* end _DtEditorGetTextBackground */
  2647. static void
  2648. _DtEditorGetTextForeground(
  2649. Widget wid,
  2650. int resource_offset,
  2651. XtArgVal *value )
  2652. {
  2653. DtEditorWidget editor = (DtEditorWidget) wid;
  2654. Pixel data;
  2655. Arg al[1];
  2656. XtSetArg( al[0], XmNforeground, &data) ;
  2657. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2658. *value = (XtArgVal) data ;
  2659. return;
  2660. } /* end _DtEditorGetTextForeground */
  2661. static void
  2662. _DtEditorGetTopCharacter(
  2663. Widget wid,
  2664. int resource_offset,
  2665. XtArgVal *value )
  2666. {
  2667. DtEditorWidget editor = (DtEditorWidget) wid;
  2668. XmTextPosition data;
  2669. Arg al[1];
  2670. XtSetArg( al[0], XmNtopCharacter, &data) ;
  2671. XtGetValues( (Widget) M_text(editor), al, 1) ;
  2672. *value = (XtArgVal) data ;
  2673. return;
  2674. } /* end _DtEditorGetTopCharacter */
  2675. static void
  2676. _DtEditorGetLineCountLabel(
  2677. Widget wid,
  2678. int resource_offset,
  2679. XtArgVal *value )
  2680. {
  2681. DtEditorWidget editor = (DtEditorWidget) wid;
  2682. XmString data;
  2683. Arg al[1];
  2684. /*
  2685. * Get the value directly from the field in the instance structure.
  2686. * If it is DtUNSPECIFIED then either:
  2687. * 1) the value has been assigned to the widget (so get it from
  2688. * there), or
  2689. * 2) the value has never been set (so return the default value).
  2690. */
  2691. if (E_status_totalLineCountLabel(editor) != (XmString) DtUNSPECIFIED)
  2692. data = XmStringCopy( E_status_totalLineCountLabel(editor) );
  2693. else if (M_status_statusArea(editor) != (Widget) NULL)
  2694. {
  2695. XtSetArg( al[0], XmNlabelString, &data) ;
  2696. XtGetValues( (Widget) M_status_totalLabel(editor), al, 1) ;
  2697. }
  2698. else
  2699. data = XmStringCreateLocalized(TOTAL);
  2700. *value = (XtArgVal) data ;
  2701. return;
  2702. } /* end _DtEditorGetLineCountLabel */
  2703. /**************************************************************
  2704. **
  2705. ** Action Procedures
  2706. **
  2707. **/
  2708. /*
  2709. * The following are DtEditor's actions. A few are internal only (_I
  2710. * suffix) and will be called by the default translations DtEditor places
  2711. * on the text widget. The rest will be called from an application with
  2712. * XtCallActionProc(). The main difference is the internal ones will be
  2713. * passed a text widget ID, while the public ones will be passed a DtEditor ID.
  2714. */
  2715. static void
  2716. BackwardChar(
  2717. Widget w,
  2718. XEvent *event,
  2719. char **params,
  2720. Cardinal *num_params)
  2721. {
  2722. DtEditorWidget editor = (DtEditorWidget)w;
  2723. XtCallActionProc( M_text(editor), "backward-character", event,
  2724. params, *num_params );
  2725. }
  2726. static void
  2727. BackwardPara(
  2728. Widget w,
  2729. XEvent *event,
  2730. char **params,
  2731. Cardinal *num_params)
  2732. {
  2733. DtEditorWidget editor = (DtEditorWidget)w;
  2734. XtCallActionProc( M_text(editor), "backward-paragraph", event,
  2735. params, *num_params );
  2736. }
  2737. static void
  2738. BackwardWord(
  2739. Widget w,
  2740. XEvent *event,
  2741. char **params,
  2742. Cardinal *num_params)
  2743. {
  2744. DtEditorWidget editor = (DtEditorWidget)w;
  2745. XtCallActionProc( M_text(editor), "backward-word", event,
  2746. params, *num_params );
  2747. }
  2748. static void
  2749. BeginningOfFile(
  2750. Widget w,
  2751. XEvent *event,
  2752. char **params,
  2753. Cardinal *num_params)
  2754. {
  2755. DtEditorWidget editor = (DtEditorWidget)w;
  2756. XtCallActionProc( M_text(editor), "beginning-of-file", event,
  2757. params, *num_params );
  2758. }
  2759. static void
  2760. BeginningOfLine(
  2761. Widget w,
  2762. XEvent *event,
  2763. char **params,
  2764. Cardinal *num_params)
  2765. {
  2766. DtEditorWidget editor = (DtEditorWidget)w;
  2767. XtCallActionProc( M_text(editor), "beginning-of-line", event,
  2768. params, *num_params );
  2769. }
  2770. static void
  2771. ClearSelection(
  2772. Widget w,
  2773. XEvent *event,
  2774. char **params,
  2775. Cardinal *num_params)
  2776. {
  2777. DtEditorWidget editor = (DtEditorWidget)w;
  2778. XtCallActionProc( M_text(editor), "clear-selection", event,
  2779. params, *num_params );
  2780. /*
  2781. * Clearing selected text also deselects the selection, but for some
  2782. * reason the selection proc (Editor_SetSelectionProc) does not get
  2783. * called, therefore, we need to call the DtNtextDeselectCallback
  2784. * from here.
  2785. */
  2786. Call_TextDeselectCallback(editor);
  2787. }
  2788. static void
  2789. CopyClipboard(
  2790. Widget w,
  2791. XEvent *event,
  2792. char **params,
  2793. Cardinal *num_params)
  2794. {
  2795. DtEditorWidget editor = (DtEditorWidget)w;
  2796. XtCallActionProc( M_text(editor), "copy-clipboard", event,
  2797. params, *num_params );
  2798. }
  2799. static void
  2800. CutClipboard(
  2801. Widget w,
  2802. XEvent *event,
  2803. char **params,
  2804. Cardinal *num_params)
  2805. {
  2806. DtEditorWidget editor = (DtEditorWidget)w;
  2807. XtCallActionProc( M_text(editor), "cut-clipboard", event,
  2808. params, *num_params );
  2809. }
  2810. static void
  2811. DeleteNextChar(
  2812. Widget w,
  2813. XEvent *event,
  2814. char **params,
  2815. Cardinal *num_params)
  2816. {
  2817. DtEditorWidget editor = (DtEditorWidget)w;
  2818. XtCallActionProc( M_text(editor), "delete-next-character", event,
  2819. params, *num_params );
  2820. }
  2821. static void
  2822. DeleteNextWord(
  2823. Widget w,
  2824. XEvent *event,
  2825. char **params,
  2826. Cardinal *num_params)
  2827. {
  2828. DtEditorWidget editor = (DtEditorWidget)w;
  2829. XtCallActionProc( M_text(editor), "delete-next-word", event,
  2830. params, *num_params );
  2831. }
  2832. static void
  2833. DeletePrevChar(
  2834. Widget w,
  2835. XEvent *event,
  2836. char **params,
  2837. Cardinal *num_params)
  2838. {
  2839. DtEditorWidget editor = (DtEditorWidget)w;
  2840. XtCallActionProc( M_text(editor), "delete-previous-character", event,
  2841. params, *num_params );
  2842. }
  2843. static void
  2844. DeletePrevWord(
  2845. Widget w,
  2846. XEvent *event,
  2847. char **params,
  2848. Cardinal *num_params)
  2849. {
  2850. DtEditorWidget editor = (DtEditorWidget)w;
  2851. XtCallActionProc( M_text(editor), "delete-previous-word", event,
  2852. params, *num_params );
  2853. }
  2854. static void
  2855. DeleteToEOL(
  2856. Widget w,
  2857. XEvent *event,
  2858. char **params,
  2859. Cardinal *num_params)
  2860. {
  2861. DtEditorWidget editor = (DtEditorWidget)w;
  2862. XtCallActionProc( M_text(editor), "delete-to-end-of-line", event,
  2863. params, *num_params );
  2864. }
  2865. static void
  2866. DeleteToSOL(
  2867. Widget w,
  2868. XEvent *event,
  2869. char **params,
  2870. Cardinal *num_params)
  2871. {
  2872. DtEditorWidget editor = (DtEditorWidget)w;
  2873. XtCallActionProc( M_text(editor), "delete-to-start-of-line", event,
  2874. params, *num_params );
  2875. }
  2876. static void
  2877. DeselectAll(
  2878. Widget w,
  2879. XEvent *event,
  2880. char **params,
  2881. Cardinal *num_params)
  2882. {
  2883. DtEditorWidget editor = (DtEditorWidget)w;
  2884. XtCallActionProc( M_text(editor), "deselect-all", event,
  2885. params, *num_params );
  2886. }
  2887. static void
  2888. EndOfFile(
  2889. Widget w,
  2890. XEvent *event,
  2891. char **params,
  2892. Cardinal *num_params)
  2893. {
  2894. DtEditorWidget editor = (DtEditorWidget)w;
  2895. XtCallActionProc( M_text(editor), "end-of-file", event,
  2896. params, *num_params );
  2897. }
  2898. static void
  2899. EndOfLine(
  2900. Widget w,
  2901. XEvent *event,
  2902. char **params,
  2903. Cardinal *num_params)
  2904. {
  2905. DtEditorWidget editor = (DtEditorWidget)w;
  2906. XtCallActionProc( M_text(editor), "end-of-line", event,
  2907. params, *num_params );
  2908. }
  2909. static void
  2910. ForwardChar(
  2911. Widget w,
  2912. XEvent *event,
  2913. char **params,
  2914. Cardinal *num_params)
  2915. {
  2916. DtEditorWidget editor = (DtEditorWidget)w;
  2917. XtCallActionProc( M_text(editor), "forward-character", event,
  2918. params, *num_params );
  2919. }
  2920. static void
  2921. ForwardPara(
  2922. Widget w,
  2923. XEvent *event,
  2924. char **params,
  2925. Cardinal *num_params)
  2926. {
  2927. DtEditorWidget editor = (DtEditorWidget)w;
  2928. XtCallActionProc( M_text(editor), "forward-paragraph", event,
  2929. params, *num_params );
  2930. }
  2931. static void
  2932. ForwardWord(
  2933. Widget w,
  2934. XEvent *event,
  2935. char **params,
  2936. Cardinal *num_params)
  2937. {
  2938. DtEditorWidget editor = (DtEditorWidget)w;
  2939. XtCallActionProc( M_text(editor), "forward-word", event,
  2940. params, *num_params );
  2941. }
  2942. static void
  2943. GoToLine(
  2944. Widget w,
  2945. XEvent *event,
  2946. char **params,
  2947. Cardinal *num_params)
  2948. {
  2949. DtEditorWidget editor = (DtEditorWidget)w;
  2950. if( M_status_statusArea(editor) != (Widget)NULL &&
  2951. XtIsManaged(M_status_statusArea(editor)) == True )
  2952. {
  2953. /*
  2954. * Set the input focus to the "Line" text field.
  2955. */
  2956. XmProcessTraversal(M_status_lineText(editor), XmTRAVERSE_CURRENT);
  2957. /*
  2958. * Select the current contents to allow easy modification.
  2959. */
  2960. XtCallActionProc( (Widget)M_status_lineText(editor), "select-all",
  2961. event, (String *)NULL, 0 );
  2962. }
  2963. } /* end GoToLine */
  2964. /*
  2965. * Internal action called only from the scrolled text widget
  2966. */
  2967. static void
  2968. GoToLine_I(
  2969. Widget w,
  2970. XEvent *event,
  2971. char **params,
  2972. Cardinal *num_params)
  2973. {
  2974. XmTextWidget tw = (XmTextWidget)w;
  2975. DtEditorWidget editor = (DtEditorWidget)M_editor(tw);
  2976. GoToLine( (Widget)editor, event, params, num_params );
  2977. } /* end GoToLine_I */
  2978. static void
  2979. Help(
  2980. Widget w,
  2981. XEvent *event,
  2982. char **params,
  2983. Cardinal *num_params)
  2984. {
  2985. CallHelpCallback((DtEditorWidget)w, DtEDITOR_HELP_EDIT_WINDOW);
  2986. }
  2987. static void
  2988. InsertString(
  2989. Widget w,
  2990. XEvent *event,
  2991. char **params,
  2992. Cardinal *num_params)
  2993. {
  2994. DtEditorWidget editor = (DtEditorWidget)w;
  2995. XtCallActionProc( M_text(editor), "insert-string", event,
  2996. params, *num_params );
  2997. }
  2998. static void
  2999. KeySelect(
  3000. Widget w,
  3001. XEvent *event,
  3002. char **params,
  3003. Cardinal *num_params)
  3004. {
  3005. DtEditorWidget editor = (DtEditorWidget)w;
  3006. XtCallActionProc( M_text(editor), "key-select", event,
  3007. params, *num_params );
  3008. }
  3009. static void
  3010. NewlineAndBackup(
  3011. Widget w,
  3012. XEvent *event,
  3013. char **params,
  3014. Cardinal *num_params)
  3015. {
  3016. DtEditorWidget editor = (DtEditorWidget)w;
  3017. XtCallActionProc( M_text(editor), "newline-and-backup", event,
  3018. params, *num_params );
  3019. }
  3020. static void
  3021. NewlineAndIndent(
  3022. Widget w,
  3023. XEvent *event,
  3024. char **params,
  3025. Cardinal *num_params)
  3026. {
  3027. DtEditorWidget editor = (DtEditorWidget)w;
  3028. XtCallActionProc( M_text(editor), "newline-and-indent", event,
  3029. params, *num_params );
  3030. }
  3031. static void
  3032. NextPage(
  3033. Widget w,
  3034. XEvent *event,
  3035. char **params,
  3036. Cardinal *num_params)
  3037. {
  3038. DtEditorWidget editor = (DtEditorWidget)w;
  3039. XtCallActionProc( M_text(editor), "next-page", event,
  3040. params, *num_params );
  3041. }
  3042. static void
  3043. PageLeft(
  3044. Widget w,
  3045. XEvent *event,
  3046. char **params,
  3047. Cardinal *num_params)
  3048. {
  3049. DtEditorWidget editor = (DtEditorWidget)w;
  3050. XtCallActionProc( M_text(editor), "page-left", event,
  3051. params, *num_params );
  3052. }
  3053. static void
  3054. PageRight(
  3055. Widget w,
  3056. XEvent *event,
  3057. char **params,
  3058. Cardinal *num_params)
  3059. {
  3060. DtEditorWidget editor = (DtEditorWidget)w;
  3061. XtCallActionProc( M_text(editor), "page-right", event,
  3062. params, *num_params );
  3063. }
  3064. static void
  3065. PasteClipboard(
  3066. Widget w,
  3067. XEvent *event,
  3068. char **params,
  3069. Cardinal *num_params)
  3070. {
  3071. DtEditorWidget editor = (DtEditorWidget)w;
  3072. XtCallActionProc( M_text(editor), "paste-clipboard", event,
  3073. params, *num_params );
  3074. }
  3075. static void
  3076. PreviousPage(
  3077. Widget w,
  3078. XEvent *event,
  3079. char **params,
  3080. Cardinal *num_params)
  3081. {
  3082. DtEditorWidget editor = (DtEditorWidget)w;
  3083. XtCallActionProc( M_text(editor), "previous-page", event,
  3084. params, *num_params );
  3085. }
  3086. static void
  3087. ProcessCancel(
  3088. Widget w,
  3089. XEvent *event,
  3090. char **params,
  3091. Cardinal *num_params)
  3092. {
  3093. DtEditorWidget editor = (DtEditorWidget)w;
  3094. XtCallActionProc( M_text(editor), "process-cancel", event,
  3095. params, *num_params );
  3096. }
  3097. static void
  3098. ProcessDown(
  3099. Widget w,
  3100. XEvent *event,
  3101. char **params,
  3102. Cardinal *num_params)
  3103. {
  3104. DtEditorWidget editor = (DtEditorWidget)w;
  3105. XtCallActionProc( M_text(editor), "process-down", event,
  3106. params, *num_params );
  3107. }
  3108. static void
  3109. ProcessShiftDown(
  3110. Widget w,
  3111. XEvent *event,
  3112. char **params,
  3113. Cardinal *num_params)
  3114. {
  3115. DtEditorWidget editor = (DtEditorWidget)w;
  3116. XtCallActionProc( M_text(editor), "process-shift-down", event,
  3117. params, *num_params );
  3118. }
  3119. static void
  3120. ProcessShiftUp(
  3121. Widget w,
  3122. XEvent *event,
  3123. char **params,
  3124. Cardinal *num_params)
  3125. {
  3126. DtEditorWidget editor = (DtEditorWidget)w;
  3127. XtCallActionProc( M_text(editor), "process-shift-up", event,
  3128. params, *num_params );
  3129. }
  3130. static void
  3131. ProcessUp(
  3132. Widget w,
  3133. XEvent *event,
  3134. char **params,
  3135. Cardinal *num_params)
  3136. {
  3137. DtEditorWidget editor = (DtEditorWidget)w;
  3138. XtCallActionProc( M_text(editor), "process-up", event,
  3139. params, *num_params );
  3140. }
  3141. /************************************************************************
  3142. * GetModeSwitchModifier
  3143. * Find if any Mod<n> modifier is acting as the Group modifier - you
  3144. * can't assume Mod1Mask is always it.
  3145. * Returns the mask of the modifier key to which the Mode_switch
  3146. * keysym is attached.
  3147. *
  3148. ************************************************************************/
  3149. /* ARGSUSED */
  3150. static unsigned int
  3151. GetModeSwitchModifier(
  3152. Display *dpy)
  3153. {
  3154. register XModifierKeymap *pMap;
  3155. register int mapIndex, keyCol, mapSize;
  3156. KeySym keySym;
  3157. unsigned int modeSwitchModMask = 0;
  3158. pMap = XGetModifierMapping(dpy);
  3159. mapSize = 8*pMap->max_keypermod;
  3160. for (mapIndex = 3*pMap->max_keypermod; mapIndex < mapSize; mapIndex++) {
  3161. /* look only at the first 4 columns of key map */
  3162. for (keyCol = 0; keyCol < 4; keyCol++) {
  3163. keySym = XKeycodeToKeysym(dpy, pMap->modifiermap[mapIndex], keyCol);
  3164. if (keySym == XK_Mode_switch)
  3165. modeSwitchModMask |= 1 << (mapIndex / pMap->max_keypermod);
  3166. }
  3167. }
  3168. XFreeModifiermap(pMap);
  3169. return modeSwitchModMask;
  3170. }
  3171. /************************************************************************
  3172. *
  3173. * DtEditorQuoteNextChar
  3174. * This action routine circumvents the normal XtDispatchEvent
  3175. * mechanism, inserting the next control or extended character
  3176. * directly into text without processed by event handlers or the
  3177. * translation manager. This means, for
  3178. * example, that the next control or extended character will be
  3179. * inserted into text without being intrepreted as a Motif menu
  3180. * or text widget accelerator.
  3181. *
  3182. ************************************************************************/
  3183. /* ARGSUSED */
  3184. static void
  3185. QuoteNextChar(
  3186. Widget widget,
  3187. XEvent *event,
  3188. char **params,
  3189. Cardinal *num_params)
  3190. {
  3191. DtEditorWidget editor = (DtEditorWidget)widget;
  3192. static unsigned int ExtendcharMask = 0;
  3193. /* NOTE: ExtendcharMask could be a global set via a MappingNotify
  3194. * event handler. But it isn't...
  3195. */
  3196. if (! ExtendcharMask)
  3197. {
  3198. _DtProcessLock();
  3199. if (! ExtendcharMask)
  3200. ExtendcharMask = GetModeSwitchModifier( M_display(editor) );
  3201. _DtProcessUnlock();
  3202. }
  3203. for (;;)
  3204. {
  3205. XEvent next;
  3206. #ifdef XTHREADS
  3207. /*
  3208. * We cannot let XtAppNextEvent bloc, because the intrinsics
  3209. * will release locks and some other thread might dispatch
  3210. * the event we want to trap.
  3211. */
  3212. XtInputMask mask;
  3213. XtAppContext app = XtWidgetToApplicationContext(widget);
  3214. while ((mask = XtAppPending(app)) == 0)
  3215. {
  3216. if (XtAppGetExitFlag(app))
  3217. return;
  3218. }
  3219. if (mask & XtIMXEvent)
  3220. {
  3221. #endif
  3222. XtAppNextEvent(M_app_context(editor), &next);
  3223. if ((next.type == KeyPress) &&
  3224. (! IsModifierKey(XLookupKeysym((XKeyEvent *) &next, 0))) )
  3225. {
  3226. if (next.xkey.state & (ControlMask|ExtendcharMask))
  3227. XtCallActionProc(M_text(editor), "self-insert", &next, NULL, 0);
  3228. else
  3229. XtDispatchEvent(&next);
  3230. break;
  3231. }
  3232. else
  3233. XtDispatchEvent(&next);
  3234. #ifdef XTHREADS
  3235. }
  3236. else
  3237. {
  3238. /* Some (non-X) event is pending, so this should not block. */
  3239. XtAppProcessEvent(app, mask);
  3240. }
  3241. #endif
  3242. }
  3243. } /* end QuoteNextChar */
  3244. /*
  3245. * Internal action called only from the scrolled text widget
  3246. */
  3247. static void
  3248. QuoteNextChar_I(
  3249. Widget w,
  3250. XEvent *event,
  3251. char **params,
  3252. Cardinal *num_params)
  3253. {
  3254. XmTextWidget tw = (XmTextWidget)w;
  3255. DtEditorWidget editor = (DtEditorWidget) M_editor(tw);
  3256. QuoteNextChar( (Widget)editor, event, params, num_params );
  3257. } /* end QuoteNextChar_I */
  3258. static void
  3259. SelectAll(
  3260. Widget w,
  3261. XEvent *event,
  3262. char **params,
  3263. Cardinal *num_params)
  3264. {
  3265. DtEditorWidget editor = (DtEditorWidget)w;
  3266. XtCallActionProc( M_text(editor), "select-all", event,
  3267. params, *num_params );
  3268. }
  3269. static void
  3270. ToggleInsertMode(
  3271. Widget w,
  3272. XEvent *event,
  3273. char **params,
  3274. Cardinal *num_params)
  3275. {
  3276. DtEditorWidget editor = (DtEditorWidget)w;
  3277. /*
  3278. * Toggle the state of the DtNoverstrike resource
  3279. */
  3280. XtVaSetValues(w, DtNoverstrike, !M_overstrikeMode(editor), NULL);
  3281. } /* end ToggleInsertMode */
  3282. static void
  3283. ToggleInsertMode_I(
  3284. Widget w,
  3285. XEvent *event,
  3286. char **params,
  3287. Cardinal *num_params)
  3288. {
  3289. XmTextWidget tw = (XmTextWidget)w;
  3290. DtEditorWidget editor = (DtEditorWidget)M_editor(tw);
  3291. ToggleInsertMode( (Widget)editor, event, params, num_params );
  3292. } /* end ToggleInsertMode_I */
  3293. static void
  3294. UndoEdit(
  3295. Widget w,
  3296. XEvent *event,
  3297. char **params,
  3298. Cardinal *num_params)
  3299. {
  3300. DtEditorUndoEdit(w);
  3301. } /* end UndoEdit */
  3302. static void
  3303. UndoEdit_I(
  3304. Widget w,
  3305. XEvent *event,
  3306. char **params,
  3307. Cardinal *num_params)
  3308. {
  3309. XmTextWidget tw = (XmTextWidget)w;
  3310. UndoEdit( (Widget)M_editor(tw), event, params, num_params );
  3311. } /* end UndoEdit_I */
  3312. /*
  3313. * XXX All lines in this file marked "XXX Word Wrap workaround"
  3314. * XXX are related to a Motif 1.2 Text widget design defect regarding
  3315. * XXX word wrap. For Motif 1.2, the Text widget was designed so word
  3316. * XXX wrap will not function if the scrolled text widget has a
  3317. * XXX horizontal scroll bar ("a hscrollbar means the paper is infinite
  3318. * XXX so there is no edge to wrap at"). This change was made in
  3319. * XXX Xm/TextOut.c RCS version 1.71 checked in July, 1991. A
  3320. * XXX CMVC report was filed 9/8/94 & assigned number 4772.
  3321. */
  3322. #include <Xm/TextOutP.h> /* XXX Word Wrap workaround */
  3323. static void /* XXX Word Wrap workaround */
  3324. FixWordWrap( /* XXX Word Wrap workaround */
  3325. Widget w, /* XXX Word Wrap workaround */
  3326. Boolean wrapOn) /* XXX Word Wrap workaround */
  3327. { /* XXX Word Wrap workaround */
  3328. XmTextWidget tw = (XmTextWidget)w; /* XXX Word Wrap workaround */
  3329. OutputData data = tw->text.output->data; /* XXX Word Wrap workaround */
  3330. data->scrollhorizontal = !wrapOn; /* XXX Word Wrap workaround */
  3331. } /* XXX Word Wrap workaround */
  3332. static void
  3333. Call_TextSelectCallback(
  3334. DtEditorWidget editor)
  3335. {
  3336. DtEditorSelectCallbackStruct select_cb;
  3337. /*
  3338. * Call the Editor widget's DtNtextSelectCallback proc
  3339. * if it hasn't been called since the last select.
  3340. */
  3341. if ( !M_textSelectCbCalled(editor) ) {
  3342. M_textSelectCbCalled(editor) = True;
  3343. select_cb.reason = DtEDITOR_TEXT_SELECT;
  3344. select_cb.event = (XEvent *)NULL;
  3345. XtCallCallbackList ((Widget)editor, M_textSelect(editor),
  3346. (XtPointer) &select_cb);
  3347. }
  3348. } /* end Call_TextSelectCallback */
  3349. static void
  3350. Call_TextDeselectCallback(
  3351. DtEditorWidget editor)
  3352. {
  3353. DtEditorSelectCallbackStruct select_cb;
  3354. /*
  3355. * Call the Editor widget's DtNtextDeselectCallback proc
  3356. * if it hasn't been called since the last deselect.
  3357. */
  3358. if ( M_textSelectCbCalled(editor) ) {
  3359. M_textSelectCbCalled(editor) = False;
  3360. select_cb.reason = DtEDITOR_TEXT_DESELECT;
  3361. select_cb.event = (XEvent *)NULL;
  3362. XtCallCallbackList ((Widget)editor, M_textDeselect(editor),
  3363. (XtPointer) &select_cb);
  3364. }
  3365. } /* end Call_TextDeselectCallback */
  3366. /*
  3367. * Editor_SetSelectionProc
  3368. * is put into the widget->text.source->SetSelection.
  3369. * Used to call the DtEditor's select/unselect callbacks
  3370. */
  3371. static void
  3372. Editor_SetSelectionProc(
  3373. XmTextSource source,
  3374. XmTextPosition left,
  3375. XmTextPosition right,
  3376. Time set_time )
  3377. {
  3378. XmSourceData data = source->data;
  3379. Widget widget;
  3380. XmTextWidget tw;
  3381. DtEditorWidget editor;
  3382. /*
  3383. * Sanity check
  3384. */
  3385. if (!XtIsRealized((Widget)data->widgets[0]) ||
  3386. data->numwidgets <= 0)
  3387. return;
  3388. if (left < 0) left = right = 0;
  3389. widget = (Widget) data->widgets[0];
  3390. tw = (XmTextWidget)widget;
  3391. editor = M_editor(tw);
  3392. if (!editor->core.being_destroyed) {
  3393. if (left < right) {
  3394. /*
  3395. * There is a selected area if left < right so call the
  3396. * DtNtextSelectCallback.
  3397. */
  3398. Call_TextSelectCallback( editor );
  3399. }
  3400. else {
  3401. /*
  3402. * Left = Right so nothing is selected; call the
  3403. * DtNtextDeselectCallback.
  3404. */
  3405. Call_TextDeselectCallback( editor );
  3406. }
  3407. }
  3408. /*
  3409. * Now, call the text widget's real Set Selection proc
  3410. */
  3411. (*M_setSelection(editor))(source, left, right, set_time);
  3412. } /* end Editor_SetSelectionProc */
  3413. /**************************************************************
  3414. **
  3415. ** Drag and drop routines
  3416. **
  3417. **/
  3418. /*
  3419. * Handles drops of a file into the text editor, after validation in the
  3420. * transfer callback. Files are handled by reading their contents.
  3421. * Text is handled by Motif.
  3422. *
  3423. * Changing the contents of the text widget occurs here, rather than in
  3424. * the transfer callback, because of the visual changes which occur when
  3425. * changing the text widget.
  3426. */
  3427. static void
  3428. AnimateCallback(
  3429. Widget w,
  3430. XtPointer client_data,
  3431. XtPointer call_data )
  3432. {
  3433. int numItems, ii;
  3434. DtEditorErrorCode error;
  3435. DtDndDropAnimateCallbackStruct *animateInfo =
  3436. (DtDndDropAnimateCallbackStruct *) call_data;
  3437. DtEditorWidget editor = (DtEditorWidget) client_data;
  3438. /*
  3439. * XXX Only really needed if # of items is > 1
  3440. */
  3441. _DtTurnOnHourGlass( M_topLevelShell(editor) );
  3442. /*
  3443. * How many items are being dropped on us?
  3444. */
  3445. numItems = animateInfo->dropData->numItems;
  3446. switch (animateInfo->dropData->protocol)
  3447. {
  3448. case DtDND_FILENAME_TRANSFER:
  3449. {
  3450. /*
  3451. * OK, insert each file we are given
  3452. */
  3453. for (ii = 0; ii < numItems; ii++)
  3454. {
  3455. error = DtEditorInsertFromFile( (Widget)editor,
  3456. animateInfo->dropData->data.files[ii] );
  3457. /*
  3458. * If the file was not inserted successfully, then quit
  3459. * (don't care if the file is read only or if it contained
  3460. * nulls that were stripped out).
  3461. */
  3462. if( error != DtEDITOR_NO_ERRORS &&
  3463. error != DtEDITOR_READ_ONLY_FILE &&
  3464. error != DtEDITOR_NULLS_REMOVED )
  3465. {
  3466. ii = numItems; /* break out of loop */
  3467. }
  3468. } /* end for */
  3469. break;
  3470. } /* end file transfer case */
  3471. case DtDND_BUFFER_TRANSFER:
  3472. {
  3473. /*
  3474. * OK, insert each buffer we are given
  3475. */
  3476. DtDndBuffer *buffers = animateInfo->dropData->data.buffers;
  3477. DtEditorContentRec cr;
  3478. cr.type = DtEDITOR_DATA;
  3479. for (ii = 0; ii < numItems; ii++)
  3480. {
  3481. cr.value.data.buf = buffers[ii].bp;
  3482. cr.value.data.length = buffers[ii].size;
  3483. error = DtEditorInsert( (Widget)editor, &cr );
  3484. /*
  3485. * If the buffer was not inserted successfully, then quit
  3486. * (don't care if the file contained nulls that were stripped out).
  3487. */
  3488. if( error != DtEDITOR_NO_ERRORS && error != DtEDITOR_NULLS_REMOVED )
  3489. {
  3490. ii = numItems; /* break out of loop */
  3491. }
  3492. } /* end for */
  3493. break;
  3494. } /* end buffer transfer case */
  3495. case DtDND_TEXT_TRANSFER:
  3496. {
  3497. /*
  3498. * Receiving a text drop.
  3499. *
  3500. * Text drag and drop is handled by Motif so this switch
  3501. * will never be called.
  3502. *
  3503. */
  3504. break;
  3505. } /* end text transfer case */
  3506. default:
  3507. {
  3508. }
  3509. } /* end switch */
  3510. /*
  3511. * XXX Only really needed if # of items is > 1
  3512. */
  3513. _DtTurnOffHourGlass( M_topLevelShell(editor) );
  3514. } /* end AnimateCallback */
  3515. /*
  3516. * Validates a drop of a file into the text widget.
  3517. *
  3518. * Changing the contents of the text widget occurs in the animate
  3519. * callback, rather than here, because of the visual changes which
  3520. * occur when changing the text widget.
  3521. */
  3522. /* ARGSUSED */
  3523. static void
  3524. TransferCallback(
  3525. Widget w,
  3526. XtPointer client_data,
  3527. XtPointer call_data)
  3528. {
  3529. int numItems, ii;
  3530. DtEditorErrorCode error;
  3531. DtDndTransferCallbackStruct *transferInfo =
  3532. (DtDndTransferCallbackStruct *) call_data;
  3533. transferInfo->status = DtDND_SUCCESS;
  3534. /*
  3535. * How many items are being dropped on us?
  3536. */
  3537. numItems = transferInfo->dropData->numItems;
  3538. switch (transferInfo->dropData->protocol)
  3539. {
  3540. case DtDND_FILENAME_TRANSFER:
  3541. {
  3542. /*
  3543. * Check to see if we can read each file we are given
  3544. */
  3545. for (ii = 0; ii < numItems; ii++)
  3546. {
  3547. error = _DtEditorValidateFileAccess(
  3548. transferInfo->dropData->data.files[ii],
  3549. READ_ACCESS);
  3550. /*
  3551. * Can't access it for reading so reject drop
  3552. */
  3553. if ( error != DtEDITOR_NO_ERRORS ) {
  3554. transferInfo->status = DtDND_FAILURE;
  3555. ii = numItems; /* break out of loop */
  3556. }
  3557. } /* end for each file */
  3558. break;
  3559. } /* end file transfer case */
  3560. case DtDND_BUFFER_TRANSFER:
  3561. {
  3562. /*
  3563. * Receiving a buffer drop.
  3564. * -- do nothing in transfer
  3565. */
  3566. break;
  3567. } /* end buffer transfer case */
  3568. case DtDND_TEXT_TRANSFER:
  3569. {
  3570. /*
  3571. * Receiving a text drop.
  3572. *
  3573. * Text drag and drop is handled by Motif so this switch
  3574. * will never be called.
  3575. *
  3576. */
  3577. break;
  3578. } /* end text transfer case */
  3579. default:
  3580. {
  3581. transferInfo->status = DtDND_FAILURE;
  3582. break;
  3583. }
  3584. } /* end switch */
  3585. } /* end TransferCallback */
  3586. /*-------------------------------------------------------------
  3587. ** Function: static void RegisterDropZone (
  3588. ** DtEditorWidget w)
  3589. **
  3590. ** Parameters: A DtEditor widget
  3591. **
  3592. ** Purpose: This routine registers the edit window's text widget
  3593. ** as a drop site for file & buffer drops. Because it
  3594. ** is a text widget it will automatically accept text
  3595. ** drops.
  3596. */
  3597. static void
  3598. RegisterDropZone(
  3599. DtEditorWidget w)
  3600. {
  3601. int ac;
  3602. Arg al[2];
  3603. XtCallbackRec transferCB[] = { {TransferCallback, NULL}, {NULL, NULL} };
  3604. XtCallbackRec animateCB[] = { {AnimateCallback, NULL}, {NULL, NULL} };
  3605. transferCB[0].closure = (XtPointer) w;
  3606. animateCB[0].closure = (XtPointer) w;
  3607. /*
  3608. * Register file & buffer transfers... let Motif handle text DnD
  3609. */
  3610. ac=0;
  3611. XtSetArg( al[ac], DtNdropAnimateCallback, animateCB ); ac++;
  3612. DtDndDropRegister( M_text(w),
  3613. DtDND_FILENAME_TRANSFER|DtDND_BUFFER_TRANSFER,
  3614. XmDROP_COPY, transferCB, al, ac );
  3615. } /* end RegisterDropZone */
  3616. /*-------------------------------------------------------------
  3617. ** Function: static void UnregisterDropZone (
  3618. ** DtEditorWidget w)
  3619. **
  3620. ** Parameters: A DtEditor widget
  3621. **
  3622. ** Purpose: This routine unregisters the edit window
  3623. */
  3624. static void
  3625. UnregisterDropZone(
  3626. DtEditorWidget w)
  3627. {
  3628. DtDndDropUnregister( M_text(w) );
  3629. } /* end UnregisterDropZone */
  3630. /************************************************************************
  3631. *
  3632. * SetInfoDialogTitle - Change the title for the Information dialog
  3633. *
  3634. ************************************************************************/
  3635. static void
  3636. SetInfoDialogTitle(
  3637. DtEditorWidget editor)
  3638. {
  3639. Arg al[2];
  3640. /*
  3641. * If the Information dialog has been created, change its title
  3642. */
  3643. if( M_gen_warning(editor) != (Widget)NULL )
  3644. {
  3645. /*
  3646. * Prepend the DialogTitle resource, if it has been set
  3647. */
  3648. if( E_dialogTitle(editor) != (XmString)NULL ) {
  3649. XmString titleStr;
  3650. /*
  3651. * Add the "functional title" to the DialogTitle
  3652. */
  3653. titleStr = XmStringConcat( E_dialogTitle(editor),
  3654. E_infoDialogTitle(editor) );
  3655. XtSetArg( al[0], XmNdialogTitle, titleStr );
  3656. XtSetValues(M_gen_warning(editor), al, 1);
  3657. XmStringFree( titleStr );
  3658. }
  3659. else {
  3660. XtSetArg( al[0], XmNdialogTitle, E_infoDialogTitle(editor) );
  3661. XtSetValues(M_gen_warning(editor), al, 1);
  3662. }
  3663. }
  3664. } /* end SetInfoDialogTitle */
  3665. /************************************************************************
  3666. *
  3667. * _DtEditorWarning - get a message to the user
  3668. *
  3669. ************************************************************************/
  3670. void
  3671. _DtEditorWarning(
  3672. DtEditorWidget editor,
  3673. char *mess,
  3674. unsigned char dialogType)
  3675. {
  3676. Arg al[10];
  3677. int ac;
  3678. char *tmpMess;
  3679. XmString tmpStr;
  3680. tmpMess = strdup(mess);
  3681. /* create the dialog if it is the first time */
  3682. if(M_gen_warning(editor) == (Widget) NULL)
  3683. {
  3684. XmString titleStr = (XmString) NULL;
  3685. XmString okStr;
  3686. ac = 0;
  3687. /*
  3688. * First, create the dialog's title, prepending the
  3689. * DtNdialogTitle resource, if it is set
  3690. */
  3691. if( E_dialogTitle(editor) != (XmString)NULL ) {
  3692. /*
  3693. * Add the "functional title" to the DialogTitle
  3694. */
  3695. titleStr = XmStringConcat( E_dialogTitle(editor),
  3696. E_infoDialogTitle(editor) );
  3697. XtSetArg (al[ac], XmNdialogTitle, titleStr ); ac++;
  3698. }
  3699. else {
  3700. XtSetArg (al[ac], XmNdialogTitle, E_infoDialogTitle(editor)); ac++;
  3701. }
  3702. okStr = XmStringCreateLocalized((char*) _DtOkString);
  3703. XtSetArg (al[ac], XmNokLabelString, okStr); ac++;
  3704. M_gen_warning(editor) = (Widget) XmCreateMessageDialog(
  3705. M_topLevelShell(editor), "Warn",
  3706. al, ac);
  3707. if (titleStr != (XmString) NULL)
  3708. XmStringFree( titleStr );
  3709. XmStringFree(okStr);
  3710. /* Set the correct font lists for the message & OK button. */
  3711. XtSetArg (al[0], XmNfontList, E_buttonFontList(editor));
  3712. XtSetValues(
  3713. XmMessageBoxGetChild(M_gen_warning(editor), XmDIALOG_OK_BUTTON),
  3714. al, 1) ;
  3715. XtSetArg (al[0], XmNfontList, E_labelFontList(editor));
  3716. XtSetValues(
  3717. XmMessageBoxGetChild(M_gen_warning(editor), XmDIALOG_MESSAGE_LABEL),
  3718. al, 1) ;
  3719. /* Unmanage unneeded children. */
  3720. XtUnmanageChild ( XmMessageBoxGetChild(M_gen_warning(editor),
  3721. XmDIALOG_CANCEL_BUTTON) );
  3722. XtUnmanageChild ( XmMessageBoxGetChild(M_gen_warning(editor),
  3723. XmDIALOG_HELP_BUTTON) );
  3724. XtRealizeWidget (M_gen_warning(editor));
  3725. ac=0;
  3726. XtSetArg(al[ac], XmNmwmInputMode,
  3727. MWM_INPUT_PRIMARY_APPLICATION_MODAL);ac++;
  3728. XtSetValues(XtParent(M_gen_warning(editor)), al, ac);
  3729. }
  3730. tmpStr = XmStringCreateLocalized(tmpMess);
  3731. ac = 0;
  3732. XtSetArg(al[ac], XmNdialogType, dialogType); ac++;
  3733. XtSetArg(al[ac], XmNmessageString, tmpStr); ac++;
  3734. XtSetValues(M_gen_warning(editor), al, ac);
  3735. XmStringFree(tmpStr);
  3736. XtFree( (char *) tmpMess );
  3737. XtManageChild (M_gen_warning(editor));
  3738. } /* end _DtEditorWarning */
  3739. /*********************************************************************
  3740. *
  3741. * The following section contains the procedures related to the staus
  3742. * line
  3743. *
  3744. *********************************************************************/
  3745. #define FORCE True
  3746. #define DONT_FORCE False
  3747. /*
  3748. * PositionActivateCB is invoked when the user presses [Return] after
  3749. * (presumably) modifying the current line text field. It retrieves
  3750. * the user specified line number and calls DtEditorGoToLine().
  3751. */
  3752. /* ARGSUSED */
  3753. static void
  3754. PositionActivateCB(
  3755. Widget w,
  3756. caddr_t client_data,
  3757. caddr_t call_data )
  3758. {
  3759. DtEditorWidget editor = (DtEditorWidget)client_data;
  3760. char *lineStr = XmTextFieldGetString(M_status_lineText(editor));
  3761. int newLineNum = atoi(lineStr);
  3762. XtFree(lineStr);
  3763. DtEditorGoToLine ((Widget)editor, newLineNum);
  3764. XmProcessTraversal(M_text(editor), XmTRAVERSE_CURRENT);
  3765. } /* PositionActivateCB */
  3766. /*
  3767. * _DtEditorUpdateLineDisplay updates the current & total line displays
  3768. * in the status line, if needed. Normally, the displays are not changed
  3769. * if the correct numbers are (supposedly) displayed. Setting forceUpdate
  3770. * will cause the numbers to be updated anyways. This is primarily used
  3771. * when the user enters a number into the current line display to force
  3772. * display of the correct number.
  3773. */
  3774. void
  3775. _DtEditorUpdateLineDisplay(
  3776. DtEditorWidget editor,
  3777. int currentLine,
  3778. Boolean forceUpdate )
  3779. {
  3780. XmTextWidget tw = (XmTextWidget) M_text(editor);
  3781. Arg al[10];
  3782. char tmpChars[8];
  3783. int lastLine;
  3784. XmString tmpXmStr;
  3785. /*
  3786. * Only change the current & total lines displays if the status
  3787. * line is visible
  3788. */
  3789. if ( M_status_showStatusLine(editor) == True )
  3790. {
  3791. /*
  3792. * Current line
  3793. */
  3794. if (M_status_currentLine(editor) != currentLine || forceUpdate)
  3795. {
  3796. sprintf(tmpChars, "%d", currentLine);
  3797. XmTextFieldSetString(M_status_lineText(editor), tmpChars);
  3798. M_status_currentLine(editor) = currentLine;
  3799. }
  3800. /*
  3801. * Total lines
  3802. */
  3803. lastLine = tw->text.total_lines;
  3804. if(M_status_lastLine(editor) != lastLine )
  3805. {
  3806. sprintf(tmpChars, "%d", lastLine);
  3807. tmpXmStr = XmStringCreateLocalized(tmpChars);
  3808. XtSetArg(al[0], XmNlabelString, tmpXmStr);
  3809. XtSetValues( M_status_totalText(editor), al, 1 );
  3810. XmStringFree(tmpXmStr);
  3811. M_status_lastLine(editor) = lastLine;
  3812. }
  3813. }
  3814. } /* end _DtEditorUpdateLineDisplay */
  3815. static void
  3816. UpdateOverstrikeIndicator(
  3817. DtEditorWidget widget,
  3818. Boolean overstrikeOn )
  3819. {
  3820. Arg al[10];
  3821. register int ac;
  3822. DtEditorWidget ew = (DtEditorWidget) widget;
  3823. /*
  3824. * Only change the overstrike indicator if the status line is visible
  3825. */
  3826. if ( M_status_showStatusLine(ew) == True &&
  3827. M_status_overstrikeWidget(ew) != (Widget) NULL )
  3828. {
  3829. ac=0;
  3830. if ( overstrikeOn == True ) {
  3831. XtSetArg(al[ac], XmNlabelString, M_status_overstrikeLabel(ew)); ac++;
  3832. }
  3833. else {
  3834. XtSetArg(al[ac], XmNlabelString, M_status_insertLabel(ew)); ac++;
  3835. }
  3836. XtSetValues( M_status_overstrikeWidget(ew), al, ac );
  3837. }
  3838. } /* end UpdateOverstrikeIndicator */
  3839. int
  3840. _DtEditorGetLineIndex(
  3841. XmTextWidget tw,
  3842. XmTextPosition pos)
  3843. {
  3844. int startLine, lastLine, middleLine;
  3845. XmTextLineTable lineTab = tw->text.line_table;
  3846. startLine = 0;
  3847. lastLine = tw->text.total_lines - 1;
  3848. while(startLine != lastLine)
  3849. {
  3850. middleLine = (startLine + lastLine)/2;
  3851. if(middleLine == startLine || middleLine == lastLine)
  3852. {
  3853. /*
  3854. * We're down to 2 lines. It's gotta be on one of these
  3855. * two lines.
  3856. */
  3857. if(pos < (XmTextPosition) lineTab[lastLine].start_pos)
  3858. lastLine = startLine;
  3859. else
  3860. startLine = lastLine;
  3861. }
  3862. else
  3863. {
  3864. if (pos < (XmTextPosition) lineTab[middleLine].start_pos)
  3865. lastLine = middleLine;
  3866. else
  3867. startLine = middleLine;
  3868. }
  3869. }
  3870. return startLine;
  3871. } /* end _DtEditorGetLineIndex */
  3872. /*
  3873. * SetCursorPosStatus is called as an XmNmotionVerifyCallback on the
  3874. * text widget when the statusLine is turned on. It computes and
  3875. * displays the new line of the insert cursor.
  3876. */
  3877. static void
  3878. SetCursorPosStatus(
  3879. Widget w,
  3880. caddr_t client_data,
  3881. caddr_t call_data )
  3882. {
  3883. DtEditorWidget editor = (DtEditorWidget)client_data;
  3884. XmTextWidget tw = (XmTextWidget)w;
  3885. XmTextVerifyCallbackStruct * cb = (XmTextVerifyCallbackStruct *) call_data;
  3886. int startLine;
  3887. startLine = _DtEditorGetLineIndex(tw, cb->newInsert) + 1;
  3888. _DtEditorUpdateLineDisplay( editor, startLine, FORCE );
  3889. } /* end SetCursorPosStatus */
  3890. static void
  3891. SetStatusLine(
  3892. DtEditorWidget ew,
  3893. Boolean statusLineOn)
  3894. {
  3895. Arg al[10];
  3896. register int ac;
  3897. int currentLine;
  3898. XmTextPosition cursorPos;
  3899. M_status_showStatusLine(ew) = statusLineOn;
  3900. if( statusLineOn == True )
  3901. {
  3902. if( M_status_statusArea(ew) == (Widget)NULL )
  3903. M_status_statusArea(ew) = CreateStatusLine( ew );
  3904. /*
  3905. * Update the line counts
  3906. */
  3907. cursorPos = (XmTextPosition)DtEditorGetInsertionPosition( (Widget)ew );
  3908. currentLine = _DtEditorGetLineIndex( (XmTextWidget) M_text(ew),
  3909. cursorPos ) + 1;
  3910. _DtEditorUpdateLineDisplay( ew, currentLine, DONT_FORCE );
  3911. /*
  3912. * Update the overstrike indicator
  3913. */
  3914. UpdateOverstrikeIndicator( ew, M_overstrikeMode(ew) );
  3915. /*
  3916. * Show the status line
  3917. */
  3918. XtManageChild( M_status_statusArea(ew) );
  3919. /*
  3920. * Hook the scrolled text widget to the status line
  3921. */
  3922. ac = 0;
  3923. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_WIDGET ); ac++;
  3924. XtSetArg( al[ac], XmNbottomWidget, M_status_statusArea(ew) ); ac++;
  3925. XtSetValues( XtParent(M_text(ew)), al, ac );
  3926. XtAddCallback( M_text(ew), XmNmotionVerifyCallback,
  3927. (XtCallbackProc) SetCursorPosStatus, (XtPointer)ew);
  3928. }
  3929. else
  3930. {
  3931. /*
  3932. * Hook the scrolled text widget to the bottom of the form
  3933. */
  3934. ac = 0;
  3935. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  3936. XtSetValues( XtParent(M_text(ew)), al, ac );
  3937. XtRemoveCallback( M_text(ew), XmNmotionVerifyCallback,
  3938. (XtCallbackProc) SetCursorPosStatus, (XtPointer)ew);
  3939. /*
  3940. * Hide the status line
  3941. */
  3942. if( M_status_statusArea(ew) != (Widget)NULL )
  3943. XtUnmanageChild( M_status_statusArea(ew) );
  3944. }
  3945. } /* SetStatusLine */
  3946. /************************************************************************
  3947. *
  3948. * CreateStatusLine - Creates the status line
  3949. *
  3950. ************************************************************************/
  3951. static Widget
  3952. CreateStatusLine(
  3953. DtEditorWidget parent)
  3954. {
  3955. Arg al[20];
  3956. int ac;
  3957. Widget container;
  3958. XmString tmpStr;
  3959. Pixel background, foreground;
  3960. /*
  3961. * Match the background & foreground colors of the edit window
  3962. * Don't use DtNtextBackground/Foreground directly because they
  3963. * will be DtUNSPECIFIED.
  3964. */
  3965. ac = 0;
  3966. XtSetArg(al[ac], XmNforeground, &foreground); ac++;
  3967. XtSetArg(al[ac], XmNbackground, &background); ac++;
  3968. XtGetValues(M_text(parent), al, ac);
  3969. /*
  3970. * Create the status line container
  3971. */
  3972. ac = 0;
  3973. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  3974. XtSetArg( al[ac], XmNleftAttachment, XmATTACH_FORM ); ac++;
  3975. XtSetArg( al[ac], XmNrightAttachment, XmATTACH_FORM ); ac++;
  3976. XtSetArg( al[ac], XmNverticalSpacing, 3 ); ac++;
  3977. XtSetArg( al[ac], XmNhorizontalSpacing, 3 ); ac++;
  3978. container = (Widget) XmCreateForm( (Widget)parent, "statusLine",
  3979. al, ac );
  3980. /*
  3981. * Create the current line label and text field
  3982. */
  3983. ac = 0;
  3984. if (E_status_currentLineLabel(parent) != (XmString)DtUNSPECIFIED)
  3985. {
  3986. /*
  3987. * Use the resource value & clear it (to save space).
  3988. */
  3989. tmpStr = XmStringCopy(E_status_currentLineLabel(parent));
  3990. E_status_currentLineLabel(parent) = (XmString)DtUNSPECIFIED;
  3991. }
  3992. else {
  3993. /*
  3994. * The resource has not been set so use its default value
  3995. */
  3996. tmpStr = XmStringCreateLocalized(LINE);
  3997. }
  3998. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  3999. XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
  4000. XtSetArg( al[ac], XmNleftAttachment, XmATTACH_FORM ); ac++;
  4001. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  4002. XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
  4003. M_status_lineLabel(parent) = (Widget) XmCreateLabelGadget( container,
  4004. "lineLabel", al, ac);
  4005. XtManageChild(M_status_lineLabel(parent));
  4006. XtAddCallback(M_status_lineLabel(parent), XmNhelpCallback,
  4007. (XtCallbackProc)HelpStatusCurrentLineCB, parent);
  4008. XmStringFree(tmpStr);
  4009. ac = 0;
  4010. XtSetArg(al[ac], XmNcolumns, 6); ac++;
  4011. XtSetArg(al[ac], XmNforeground, foreground); ac++;
  4012. XtSetArg(al[ac], XmNbackground, background); ac++;
  4013. XtSetArg( al[ac], XmNfontList, E_textFontList(parent)); ac++;
  4014. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  4015. XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
  4016. XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
  4017. XtSetArg( al[ac], XmNleftWidget, M_status_lineLabel(parent) ); ac++;
  4018. M_status_lineText(parent) = XmCreateTextField( container, "lineText",
  4019. al, ac );
  4020. XtManageChild(M_status_lineText(parent));
  4021. XtAddCallback(M_status_lineText(parent), XmNactivateCallback,
  4022. (XtCallbackProc)PositionActivateCB, parent);
  4023. XtAddCallback(M_status_lineText(parent), XmNhelpCallback,
  4024. (XtCallbackProc)HelpStatusCurrentLineCB, parent);
  4025. /*
  4026. * Create the total lines labels
  4027. */
  4028. ac = 0;
  4029. if (E_status_totalLineCountLabel(parent) != (XmString)DtUNSPECIFIED)
  4030. {
  4031. /*
  4032. * Use the resource value & clear it (to save space).
  4033. */
  4034. tmpStr = XmStringCopy(E_status_totalLineCountLabel(parent));
  4035. E_status_totalLineCountLabel(parent) = (XmString)DtUNSPECIFIED;
  4036. }
  4037. else {
  4038. /*
  4039. * The resource has not been set so use its default value
  4040. */
  4041. tmpStr = XmStringCreateLocalized(TOTAL);
  4042. }
  4043. XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
  4044. XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
  4045. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  4046. XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
  4047. XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
  4048. XtSetArg( al[ac], XmNleftWidget, M_status_lineText(parent) ); ac++;
  4049. M_status_totalLabel(parent) = (Widget) XmCreateLabelGadget( container,
  4050. "totalLabel", al, ac);
  4051. XtManageChild(M_status_totalLabel(parent));
  4052. XtAddCallback(M_status_totalLabel(parent), XmNhelpCallback,
  4053. (XtCallbackProc)HelpStatusTotalLinesCB, parent);
  4054. XmStringFree(tmpStr);
  4055. ac = 0;
  4056. XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
  4057. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  4058. XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
  4059. XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
  4060. XtSetArg( al[ac], XmNleftWidget, M_status_totalLabel(parent) ); ac++;
  4061. M_status_totalText(parent) = (Widget) XmCreateLabelGadget( container,
  4062. "totalText", al, ac);
  4063. XtManageChild(M_status_totalText(parent));
  4064. XtAddCallback(M_status_totalText(parent), XmNhelpCallback,
  4065. (XtCallbackProc)HelpStatusTotalLinesCB, parent);
  4066. /*
  4067. * Create the overstrike indicator
  4068. */
  4069. ac = 0;
  4070. /*
  4071. XtSetArg(al[ac], XmNrecomputeSize, False); ac++;
  4072. */
  4073. XtSetArg(al[ac], XmNmarginLeft, 0); ac++;
  4074. XtSetArg(al[ac], XmNmarginRight, 0); ac++;
  4075. XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
  4076. XtSetArg( al[ac], XmNrightOffset, 3 ); ac++;
  4077. XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
  4078. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  4079. XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
  4080. XtSetArg( al[ac], XmNrightAttachment, XmATTACH_FORM ); ac++;
  4081. M_status_overstrikeWidget(parent) =
  4082. (Widget) XmCreateLabelGadget( container, "overstrikeLabel", al, ac);
  4083. XtManageChild(M_status_overstrikeWidget(parent));
  4084. XtAddCallback(M_status_overstrikeWidget(parent), XmNhelpCallback,
  4085. (XtCallbackProc)HelpStatusOverstrikeCB, parent);
  4086. /*
  4087. * Create the application message area
  4088. */
  4089. ac = 0;
  4090. XtSetArg(al[ac], XmNbackground, parent->core.background_pixel); ac++;
  4091. XtSetArg(al[ac], XmNforeground, foreground); ac++;
  4092. XtSetArg( al[ac], XmNfontList, E_textFontList(parent)); ac++;
  4093. XtSetArg(al[ac], XmNeditable, False); ac++;
  4094. XtSetArg(al[ac], XmNcursorPositionVisible, False); ac++;
  4095. XtSetArg(al[ac], XmNtraversalOn, False); ac++;
  4096. XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
  4097. XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
  4098. XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
  4099. XtSetArg( al[ac], XmNleftWidget, M_status_totalText(parent) ); ac++;
  4100. XtSetArg( al[ac], XmNleftOffset, 17 ); ac++;
  4101. XtSetArg( al[ac], XmNrightAttachment, XmATTACH_WIDGET ); ac++;
  4102. XtSetArg(al[ac], XmNrightWidget, M_status_overstrikeWidget(parent)); ac++;
  4103. M_status_messageText(parent) =
  4104. XmCreateTextField( container, "messageText", al, ac );
  4105. XtManageChild(M_status_messageText(parent));
  4106. XtAddCallback(M_status_messageText(parent), XmNhelpCallback,
  4107. (XtCallbackProc)HelpStatusMessageCB, parent);
  4108. return( container );
  4109. } /* end CreateStatusLine */
  4110. /*********************************************************************
  4111. *
  4112. * The following section contains the procedures related to help
  4113. *
  4114. *********************************************************************/
  4115. static void
  4116. CallHelpCallback(
  4117. DtEditorWidget editor,
  4118. int reason)
  4119. {
  4120. DtEditorHelpCallbackStruct help_cb;
  4121. help_cb.reason = reason;
  4122. help_cb.event = (XEvent *) NULL;
  4123. XtCallCallbackList( (Widget)editor, M_HelpCB(editor),
  4124. (XtPointer) &help_cb );
  4125. } /* end CallHelpCallback */
  4126. /****
  4127. * Edit window help callbacks
  4128. */
  4129. /* ARGSUSED */
  4130. static void
  4131. HelpEditWindowCB(
  4132. Widget w,
  4133. caddr_t client_data,
  4134. caddr_t call_data )
  4135. {
  4136. CallHelpCallback((DtEditorWidget)client_data, DtEDITOR_HELP_EDIT_WINDOW);
  4137. }
  4138. /****
  4139. * Status Line help callbacks
  4140. */
  4141. /* XXX
  4142. * Who uses this??
  4143. */
  4144. /* ARGSUSED */
  4145. static void
  4146. HelpStatusLineCB(
  4147. Widget w,
  4148. caddr_t client_data,
  4149. caddr_t call_data )
  4150. {
  4151. CallHelpCallback((DtEditorWidget)client_data, DtEDITOR_HELP_STATUS_LINE);
  4152. }
  4153. /* ARGSUSED */
  4154. static void
  4155. HelpStatusCurrentLineCB(
  4156. Widget w,
  4157. caddr_t client_data,
  4158. caddr_t call_data )
  4159. {
  4160. CallHelpCallback( (DtEditorWidget)client_data,
  4161. DtEDITOR_HELP_STATUS_CURRENT_LINE );
  4162. }
  4163. /* ARGSUSED */
  4164. static void
  4165. HelpStatusTotalLinesCB(
  4166. Widget w,
  4167. caddr_t client_data,
  4168. caddr_t call_data )
  4169. {
  4170. CallHelpCallback( (DtEditorWidget)client_data,
  4171. DtEDITOR_HELP_STATUS_TOTAL_LINES );
  4172. }
  4173. /* ARGSUSED */
  4174. static void
  4175. HelpStatusMessageCB(
  4176. Widget w,
  4177. caddr_t client_data,
  4178. caddr_t call_data )
  4179. {
  4180. CallHelpCallback( (DtEditorWidget)client_data,
  4181. DtEDITOR_HELP_STATUS_MESSAGE );
  4182. }
  4183. /* ARGSUSED */
  4184. static void
  4185. HelpStatusOverstrikeCB(
  4186. Widget w,
  4187. caddr_t client_data,
  4188. caddr_t call_data )
  4189. {
  4190. CallHelpCallback( (DtEditorWidget)client_data,
  4191. DtEDITOR_HELP_STATUS_OVERSTRIKE );
  4192. }
  4193. /****
  4194. * Format Settings dialog help callbacks
  4195. */
  4196. /* ARGSUSED */
  4197. static void
  4198. HelpFormatDialogCB(
  4199. Widget w,
  4200. caddr_t client_data,
  4201. caddr_t call_data )
  4202. {
  4203. CallHelpCallback((DtEditorWidget)client_data, DtEDITOR_HELP_FORMAT_DIALOG);
  4204. }
  4205. /* ARGSUSED */
  4206. static void
  4207. HelpFormatRightMarginCB(
  4208. Widget w,
  4209. caddr_t client_data,
  4210. caddr_t call_data )
  4211. {
  4212. CallHelpCallback( (DtEditorWidget)client_data,
  4213. DtEDITOR_HELP_FORMAT_RIGHT_MARGIN);
  4214. }
  4215. /* ARGSUSED */
  4216. static void
  4217. HelpFormatLeftMarginCB(
  4218. Widget w,
  4219. caddr_t client_data,
  4220. caddr_t call_data )
  4221. {
  4222. CallHelpCallback( (DtEditorWidget)client_data,
  4223. DtEDITOR_HELP_FORMAT_LEFT_MARGIN);
  4224. }
  4225. /* ARGSUSED */
  4226. static void
  4227. HelpFormatJustifyButtonsCB(
  4228. Widget w,
  4229. caddr_t client_data,
  4230. caddr_t call_data )
  4231. {
  4232. CallHelpCallback( (DtEditorWidget)client_data,
  4233. DtEDITOR_HELP_FORMAT_ALIGNMENT);
  4234. }
  4235. /****
  4236. * Find/Change & Spell dialogs help callbacks
  4237. */
  4238. /* ARGSUSED */
  4239. void
  4240. _DtEditorHelpSearchCB(
  4241. Widget w,
  4242. caddr_t client_data,
  4243. caddr_t call_data )
  4244. {
  4245. DtEditorWidget editor = (DtEditorWidget)client_data;
  4246. switch (M_search_dialogMode(editor))
  4247. {
  4248. case SPELL:
  4249. CallHelpCallback( (DtEditorWidget)client_data,
  4250. DtEDITOR_HELP_SPELL_DIALOG);
  4251. break;
  4252. case REPLACE:
  4253. default:
  4254. CallHelpCallback( (DtEditorWidget)client_data,
  4255. DtEDITOR_HELP_CHANGE_DIALOG);
  4256. break;
  4257. }
  4258. } /* _DtEditorHelpSearchCB */
  4259. /* ARGSUSED */
  4260. void
  4261. _DtEditorHelpSearchFindCB(
  4262. Widget w,
  4263. caddr_t client_data,
  4264. caddr_t call_data )
  4265. {
  4266. CallHelpCallback( (DtEditorWidget)client_data,
  4267. DtEDITOR_HELP_CHANGE_FIND);
  4268. }
  4269. /* ARGSUSED */
  4270. void
  4271. _DtEditorHelpSearchChangeCB(
  4272. Widget w,
  4273. caddr_t client_data,
  4274. caddr_t call_data )
  4275. {
  4276. DtEditorWidget editor = (DtEditorWidget)client_data;
  4277. switch (M_search_dialogMode(editor))
  4278. {
  4279. case SPELL:
  4280. CallHelpCallback( (DtEditorWidget)client_data,
  4281. DtEDITOR_HELP_SPELL_CHANGE);
  4282. break;
  4283. case REPLACE:
  4284. default:
  4285. CallHelpCallback( (DtEditorWidget)client_data,
  4286. DtEDITOR_HELP_CHANGE_CHANGE);
  4287. break;
  4288. }
  4289. } /* _DtEditorHelpSearchChangeCB */
  4290. /* ARGSUSED */
  4291. void
  4292. _DtEditorHelpSearchSpellCB(
  4293. Widget w,
  4294. caddr_t client_data,
  4295. caddr_t call_data )
  4296. {
  4297. CallHelpCallback( (DtEditorWidget)client_data,
  4298. DtEDITOR_HELP_SPELL_MISSPELLED_WORDS);
  4299. }
  4300. /*********************************************************************
  4301. *
  4302. * The following section contains the procedures related to formating
  4303. * text and the Format Settings dialog.
  4304. *
  4305. *********************************************************************/
  4306. /*
  4307. * Do simple formatting of paragraphs of text.
  4308. * Designed for speed, at some cost in complexity and redundancy.
  4309. *
  4310. * There is a minor undocumented bug in Dump(). It calls Justify() in the
  4311. * case where the last word of the last line of a paragraph is an end-of-
  4312. * sentence word (typical) and ends just one blank before the margin
  4313. * (rare). This results in one blank being inserted in the line when it's
  4314. * not necessary. It happens because the two trailing blanks after the
  4315. * word cause an "ordinary" line dump before Fill() sees the next line and
  4316. * knows it has an end of paragraph. WARNING: The situation would be
  4317. * aggravated if FillWord() ever set blanks to an even larger number.
  4318. */
  4319. /*
  4320. ** This section contains changes for EUC_4B compatibility.
  4321. ** WPI interface is used.
  4322. */
  4323. /* Global Variables and extern declarations */
  4324. typedef struct _WORD{ /* describe one word */
  4325. wint_t *cp; /* word location in buffer */
  4326. int inlinenum; /* word start line in input */
  4327. int incolumn; /* word start column in input */
  4328. int length; /* size of word */
  4329. int score; /* word + next for jflag */
  4330. int blanks; /* output trailing blanks need */
  4331. int wclen; /* Length of wide character word */
  4332. } WORD;
  4333. typedef struct {
  4334. wchar_t Blank;
  4335. AdjRecPtr pAdj;
  4336. /* FORMATTING CONTROL */
  4337. int m0flag;
  4338. long fillmargin;
  4339. long centermiddle;
  4340. int tabsize; /* tab size in use */
  4341. int centerstartpara; /* expect para. start? in "Center" */
  4342. /* Global/static vars used in "Fill" */
  4343. wint_t *wordbuf; /* see comments for "Fill" for discussion */
  4344. wint_t *wordcp;
  4345. wint_t *wordcpwrap;
  4346. WORD *word;
  4347. WORD *wordbase;
  4348. WORD *wordlimit;
  4349. WORD *wordfirst;
  4350. WORD *wordat;
  4351. WORD *wordnext;
  4352. int inlinenum;
  4353. int incolumn;
  4354. int outlinenum;
  4355. int pendchars;
  4356. int indent1, indent2;
  4357. } FormatData;
  4358. #define isekinsoku(wc) iswctype((wc),ekinclass)
  4359. #define isbekinsoku(wc) iswctype((wc),bekinclass)
  4360. #define LINESIZE BUFSIZ /* how big a line can be */
  4361. #define WORDMAX LINESIZE /* see above for discussion */
  4362. #define WORDNEXT(d,at) { if (++at == d->wordlimit) at = d->wordbase; } /* statement */
  4363. #define WORDPREV(d,at) (((at == d->wordbase) ? d->wordlimit : at) - 1) /* function */
  4364. #include <locale.h>
  4365. extern int _nl_space_alt;
  4366. /*
  4367. * Forward declarations
  4368. */
  4369. static int DoLine (FormatData *data, register FILE *filep);
  4370. static void Center (FormatData *data,
  4371. wint_t *in_line, register wint_t *inlinelim);
  4372. static void Fill (FormatData *data, wint_t *in_line, register wint_t *inlinelim);
  4373. static void FillWord (FormatData *data);
  4374. static void Dump (FormatData *data, int endpara);
  4375. static void PrintIndent (FormatData *data, int indent);
  4376. static void PrintTag (FormatData *data, WORD *wordpast);
  4377. static void PrintWords (FormatData *data, WORD *wordpast);
  4378. static void Justify (FormatData *data, register int blanks, WORD *wordpast);
  4379. static int CompareWords (const void *, const void *);
  4380. static int EkinBekinProc(FormatData *data, WORD **wordpast);
  4381. static void postEkinBekinProc(FormatData *data, int *poutchars, WORD *wordpast);
  4382. #if defined(sun)
  4383. /*
  4384. * A small workaround for systems that don't have wcwidth...
  4385. */
  4386. static int
  4387. sun_wcwidth(
  4388. const wchar_t wc)
  4389. {
  4390. int status;
  4391. char mbstr[MB_LEN_MAX + 1];
  4392. status = wctomb(mbstr, wc);
  4393. if (status > 0)
  4394. return(euccol(mbstr));
  4395. else
  4396. return(status);
  4397. }
  4398. #endif /* sun */
  4399. /*
  4400. * The following utilities: lineBlank, findNonBlank, and countBlanks all
  4401. * require the lineLen parameter to specify the number of characters, not
  4402. * bytes, in the line.
  4403. */
  4404. static Boolean
  4405. lineBlank(
  4406. char *pLine,
  4407. int lineLen)
  4408. {
  4409. int byteNum, charNum;
  4410. wchar_t wc;
  4411. size_t mbCurMax = MB_CUR_MAX;
  4412. for(byteNum = charNum = 0; charNum < lineLen;
  4413. byteNum += mblen(&pLine[byteNum], mbCurMax), charNum++)
  4414. {
  4415. (void) mbtowc(&wc, &pLine[byteNum], mbCurMax);
  4416. #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
  4417. if( !iswctype(wc, _DtEditor_blankClass) )
  4418. return False;
  4419. #else
  4420. if( !iswblank(wc) )
  4421. return False;
  4422. #endif /* not sun */
  4423. }
  4424. return True;
  4425. }
  4426. static char *
  4427. findNonBlank(
  4428. char *pLine,
  4429. int lineLen)
  4430. {
  4431. int byteNum, charNum;
  4432. wchar_t wc;
  4433. size_t mbCurMax = MB_CUR_MAX;
  4434. for(byteNum = charNum = 0; charNum < lineLen;
  4435. byteNum += mblen(&pLine[byteNum], mbCurMax), charNum++)
  4436. {
  4437. (void) mbtowc(&wc, &pLine[byteNum], mbCurMax);
  4438. #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
  4439. if( !iswctype(wc, _DtEditor_blankClass) )
  4440. return &pLine[byteNum];
  4441. #else
  4442. if(! iswblank(wc) )
  4443. return &pLine[byteNum];
  4444. #endif /* not sun */
  4445. }
  4446. return &pLine[byteNum];
  4447. }
  4448. static int
  4449. countBlanks(
  4450. char *pLine,
  4451. int lineLen)
  4452. {
  4453. int byteNum, charNum, count;
  4454. wchar_t wc;
  4455. size_t mbCurMax = MB_CUR_MAX;
  4456. for(byteNum = charNum = 0, count = 0; charNum < lineLen;
  4457. byteNum += mblen(&pLine[byteNum], mbCurMax), charNum++)
  4458. {
  4459. (void) mbtowc(&wc, &pLine[byteNum], mbCurMax);
  4460. if(iswcntrl(wc))
  4461. {
  4462. if(mblen(&pLine[byteNum], mbCurMax) == 1)
  4463. {
  4464. switch((int) pLine[byteNum])
  4465. {
  4466. /*
  4467. * I don't really know what to do with weird embedded chars.
  4468. * This is just a guess. In non-ascii locales this could
  4469. * screw up, but I don't know how else to deal with
  4470. * weird embedded control characters.
  4471. */
  4472. case '\n': /* newline */
  4473. case '\f': /* form feed */
  4474. count++;
  4475. continue;
  4476. case '\t': /* horizontal tab */
  4477. count += 8;
  4478. continue;
  4479. case '\b': /* backspace */
  4480. count--;
  4481. continue;
  4482. case '\r': /* carriage return */
  4483. count = 0;
  4484. continue;
  4485. default:
  4486. return count;
  4487. }
  4488. }
  4489. else
  4490. count++; /* multibyte control chars??? */
  4491. continue;
  4492. }
  4493. #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
  4494. if(!iswctype(wc, _DtEditor_blankClass))
  4495. return count;
  4496. #else
  4497. if(! iswblank(wc) )
  4498. return count;
  4499. #endif /* not sun */
  4500. count++;
  4501. }
  4502. return count;
  4503. }
  4504. /*
  4505. * fixLeftMarginAndNewlines - writes out a substring from the text widget,
  4506. * inserting leading blanks as needed to set the left margin, and adding
  4507. * newlines at all "virtual" (i.e. word-wrapped) lines. It assumes that the
  4508. * specified substring is an integer number of lines - i.e. the substring
  4509. * cannot begin or end in the middle of a line. Non-complying substrings
  4510. * are expanded to encompass whole lines.
  4511. */
  4512. static void
  4513. fixLeftMarginAndNewlines(
  4514. DtEditorWidget editor,
  4515. FILE *fp,
  4516. int leftMargin,
  4517. int rightMargin,
  4518. int startPos,
  4519. int endPos)
  4520. {
  4521. Widget widget = M_text(editor);
  4522. register XmTextLineTable lineTable;
  4523. register int i;
  4524. int lineIndex, lineLen, nextLen, lineIndent, lastIndex,
  4525. lineByteLen, total_lines;
  4526. Boolean newPara = True;
  4527. char *pLine, *pNext, *pFirstNonBlank, *pLastChar;
  4528. size_t mbCurMax = MB_CUR_MAX;
  4529. lineTable = _XmTextGetLineTable(widget, &total_lines);
  4530. if (leftMargin > rightMargin || leftMargin < 0)
  4531. leftMargin = 0;
  4532. lineIndent = leftMargin;
  4533. /*
  4534. * calculate the starting line number and ending line number
  4535. * for the [sub]string we're operating upon.
  4536. */
  4537. lineIndex = _DtEditorGetLineIndex((XmTextWidget)M_text(editor), startPos);
  4538. lastIndex = _DtEditorGetLineIndex((XmTextWidget)M_text(editor), endPos);
  4539. /*
  4540. * This loop terminates with one line unwritten. This is correct
  4541. * if we're not formatting the last line of the file, as that means
  4542. * that we must be formatting a paragraph, and the paragraph adjust
  4543. * code has trouble locating the end of a paragraph (as opposed to the
  4544. * beginning of the next paragraph. If the last line of the text is
  4545. * to be formatted, it is handled after this loop terminates.
  4546. */
  4547. for(; lineIndex < lastIndex; lineIndex++)
  4548. {
  4549. /*
  4550. * if the current line was word-wrapped, put out a nl.
  4551. */
  4552. if(lineTable[lineIndex].virt_line)
  4553. fwrite("\n", sizeof(char), 1, fp);
  4554. lineLen = lineTable[lineIndex + 1].start_pos -
  4555. lineTable[lineIndex].start_pos;
  4556. pLine = _XmStringSourceGetString((XmTextWidget)M_text(editor),
  4557. lineTable[lineIndex].start_pos,
  4558. lineTable[lineIndex + 1].start_pos, False);
  4559. pLastChar = _DtEditorGetPointer(pLine, lineLen - 1);
  4560. lineByteLen = pLastChar - pLine + mblen(pLastChar, mbCurMax);
  4561. if(lineBlank(pLine, lineLen))
  4562. {
  4563. /*
  4564. * Blank lines indicate the start of a new paragraph.
  4565. * They also don't require any indent adjustment so are
  4566. * quick/easy to write out.
  4567. */
  4568. fwrite( pLine, sizeof(char),
  4569. _DtEditorGetPointer(pLine, lineLen) - pLine, fp );
  4570. newPara = True;
  4571. XtFree(pLine);
  4572. continue;
  4573. }
  4574. if(newPara == True)
  4575. {
  4576. int firstIndent;
  4577. /*
  4578. * Calc the proper indent for the first line, and
  4579. * the indent for the rest of the lines
  4580. * in the paragraph. If there's only one line in the
  4581. * paragraph, then the proper indent is adjustStuff.left_margin.
  4582. */
  4583. /*
  4584. * Get the next line.
  4585. */
  4586. if((total_lines - lineIndex) > 2)
  4587. nextLen = lineTable[lineIndex + 2].start_pos -
  4588. lineTable[lineIndex + 1].start_pos;
  4589. else
  4590. nextLen = XmTextGetLastPosition(widget) -
  4591. lineTable[lineIndex + 1].start_pos;
  4592. pNext = _XmStringSourceGetString((XmTextWidget)M_text(editor),
  4593. lineTable[lineIndex + 1].start_pos,
  4594. lineTable[lineIndex + 1].start_pos + nextLen, False);
  4595. if(lineBlank(pNext, nextLen)) /* single line paragraph */
  4596. firstIndent = lineIndent = leftMargin;
  4597. else
  4598. {
  4599. int curFirstIndent, curSecondIndent, offset;
  4600. curFirstIndent = countBlanks(pLine, lineLen);
  4601. curSecondIndent = countBlanks(pNext, nextLen);
  4602. offset = curFirstIndent - curSecondIndent;
  4603. if(offset >= 0)
  4604. {
  4605. /* second line is closer to the left margin */
  4606. /*
  4607. * Note, the first line will still be indented even
  4608. * if the remaining words in the paragraph can
  4609. * all fit on the first line. The end result is a
  4610. * one line indented paragraph. I am mentioning
  4611. * this because some may think this is a defect.
  4612. */
  4613. firstIndent = leftMargin + offset;
  4614. lineIndent = leftMargin;
  4615. }
  4616. else
  4617. {
  4618. firstIndent = leftMargin;
  4619. lineIndent = leftMargin - offset;
  4620. }
  4621. }
  4622. for(i = firstIndent; i-- > 0;)
  4623. fwrite(" ", sizeof(char), 1, fp); /* that's a _space_ */
  4624. pFirstNonBlank = findNonBlank(pLine, lineLen);
  4625. fwrite(pFirstNonBlank, sizeof(char), lineByteLen -
  4626. (pFirstNonBlank - pLine), fp);
  4627. newPara = False;
  4628. XtFree(pLine);
  4629. continue;
  4630. }
  4631. for(i = lineIndent; i-- > 0;)
  4632. fwrite(" ", sizeof(char), 1, fp); /* that's a _space_ */
  4633. pFirstNonBlank = findNonBlank(pLine, lineLen);
  4634. fwrite(pFirstNonBlank, sizeof(char), lineByteLen -
  4635. (pFirstNonBlank - pLine), fp);
  4636. XtFree(pLine);
  4637. }
  4638. if((total_lines - lineIndex) == 1)
  4639. {
  4640. /*
  4641. * Now we have to handle the last line.
  4642. */
  4643. if(lineTable[lineIndex].virt_line)
  4644. fwrite("\n", sizeof(char), 1, fp);
  4645. if((total_lines - lineIndex) > 2)
  4646. lineLen = lineTable[lineIndex + 1].start_pos -
  4647. lineTable[lineIndex].start_pos;
  4648. else
  4649. lineLen = XmTextGetLastPosition(widget) -
  4650. lineTable[lineIndex].start_pos;
  4651. if(lineLen > 0)
  4652. {
  4653. for(i = lineIndent; i-- > 0;)
  4654. fwrite(" ", sizeof(char), 1, fp); /* that's a _space_ */
  4655. pLine = _XmStringSourceGetString((XmTextWidget)M_text(editor),
  4656. lineTable[lineIndex].start_pos,
  4657. lineTable[lineIndex].start_pos + lineLen, False);
  4658. pLastChar = _DtEditorGetPointer(pLine, lineLen - 1);
  4659. lineByteLen = pLastChar - pLine + mblen(pLastChar, mbCurMax);
  4660. if(lineBlank(pLine, lineLen))
  4661. {
  4662. fwrite(pLine, sizeof(char), lineByteLen, fp);
  4663. }
  4664. else
  4665. {
  4666. pFirstNonBlank = findNonBlank(pLine, lineLen);
  4667. fwrite(pFirstNonBlank, sizeof(char), lineByteLen -
  4668. (pFirstNonBlank - pLine), fp);
  4669. }
  4670. XtFree(pLine);
  4671. }
  4672. }
  4673. XtFree((XtPointer)lineTable);
  4674. }
  4675. /************************************************************************
  4676. * FormatText -
  4677. *
  4678. * Initialize, check arguments embedded in AdjRec, open and read files,
  4679. * and pass a series of lines to lower-level routines.
  4680. */
  4681. static int
  4682. FormatText (
  4683. AdjRecPtr
  4684. pAdjRec)
  4685. {
  4686. long maxmargin; /* max allowed */
  4687. register FILE *filep; /* file to read */
  4688. int retVal;
  4689. FormatData data;
  4690. /*
  4691. * INITIALIZE FOR NLS
  4692. */
  4693. mbtowc(&data.Blank," ",1);
  4694. /*
  4695. * Initialize global/statics.
  4696. */
  4697. if((data.wordbuf = malloc(sizeof(wint_t) * LINESIZE * 3)) == (wint_t *)NULL)
  4698. return 0;
  4699. if((data.word = malloc(sizeof(WORD) * WORDMAX)) == (WORD *)NULL)
  4700. {
  4701. retVal = 0;
  4702. goto CleanUp;
  4703. }
  4704. data.tabsize = 8; /* default tab size */
  4705. data.centerstartpara = True;
  4706. data.fillmargin = data.centermiddle = pAdjRec->margin;
  4707. data.m0flag = (data.fillmargin == 0L);
  4708. /*
  4709. * Initialize global/statics for "Fill".
  4710. */
  4711. data.wordcp = data.wordbuf;
  4712. data.wordcpwrap = data.wordbuf + (LINESIZE * 2);
  4713. data.wordbase = & data.word [0];
  4714. data.wordlimit = & data.word [WORDMAX];
  4715. data.wordfirst = & data.word [0];
  4716. data.wordnext = & data.word [0];
  4717. data.inlinenum = 0;
  4718. data.outlinenum = 1;
  4719. data.pendchars = 0;
  4720. /*
  4721. * CHECK ARGUMENTS:
  4722. */
  4723. if (pAdjRec->cflag + pAdjRec->jflag + pAdjRec->rflag > 1)
  4724. {
  4725. retVal = 0;
  4726. goto CleanUp;
  4727. }
  4728. maxmargin = pAdjRec->cflag? (LINESIZE / 2) : LINESIZE;
  4729. if ((data.fillmargin < 0L) || (data.fillmargin > maxmargin))
  4730. {
  4731. retVal = 0;
  4732. goto CleanUp;
  4733. }
  4734. if ((pAdjRec->tabsize > 0) && (pAdjRec->tabsize <= MAXTABSIZE))
  4735. data.tabsize = pAdjRec->tabsize;
  4736. /*
  4737. * OPEN AND READ INPUT FILE:
  4738. */
  4739. filep = pAdjRec->infp;
  4740. data.pAdj = pAdjRec; /* set (file) global var to passed in rec */
  4741. while (DoLine (&data, filep))
  4742. ;
  4743. /*
  4744. * DUMP LAST LINE AND EXIT:
  4745. */
  4746. if (! data.pAdj->cflag) /* not centering */
  4747. {
  4748. Dump (&data, True); /* force end paragraph */
  4749. }
  4750. retVal = 1;
  4751. CleanUp:
  4752. if(data.wordbuf != (wint_t *)NULL)
  4753. {
  4754. free(data.wordbuf);
  4755. }
  4756. if(data.word != (WORD *)NULL)
  4757. {
  4758. free(data.word);
  4759. }
  4760. return retVal;
  4761. }
  4762. /************************************************************************
  4763. * D O L I N E
  4764. *
  4765. * Read one input line and do generic processing (read chars from input
  4766. * to in_line, crunching backspaces). Return True if successful, else
  4767. * false at end of input file. This must be done before expanding tabs;
  4768. * pass half-processed line to Center() or Fill() for more work.
  4769. *
  4770. * Assumes getc() is efficient.
  4771. * in_line[] is static so it is only allocated once.
  4772. */
  4773. static int
  4774. DoLine (FormatData *data,
  4775. register FILE *filep) /* open file to read */
  4776. {
  4777. wint_t in_line [LINESIZE]; /* after reading in */
  4778. register wint_t *incp = in_line; /* place in in_line */
  4779. register wint_t *incplim = in_line + LINESIZE; /* limit of in_line */
  4780. register wint_t c;
  4781. /*
  4782. * READ LINE WITH BACKSPACE CRUNCHING:
  4783. */
  4784. while (incp < incplim) /* buffer not full */
  4785. {
  4786. c = getwc (filep); /* get and save wide char */
  4787. switch(c)
  4788. {
  4789. case WEOF:
  4790. if (incp == in_line) /* nothing read yet */
  4791. return (False);
  4792. case L'\0': /* fall through */
  4793. case L'\n': /* end of line */
  4794. incplim = incp; /* set limit (quit loop) */
  4795. break;
  4796. case L'\b': /* backspace */
  4797. if (incp > in_line) /* not at start */
  4798. incp--; /* just back up */
  4799. break;
  4800. default: /* any other char */
  4801. *incp++ = c;
  4802. break;
  4803. }
  4804. }
  4805. /* now incplim is correctly set to last char + 1 */
  4806. /*
  4807. * PASS LINE ON FOR MORE WORK:
  4808. */
  4809. if (data->pAdj->cflag) Center (data, in_line, incplim);
  4810. else Fill (data, in_line, incplim);
  4811. return (True); /* maybe more to read */
  4812. } /* DoLine */
  4813. /************************************************************************
  4814. * C E N T E R
  4815. *
  4816. * Center text (starting at in_line, ending before inlinelim). First copy
  4817. * chars from in_line to outline skipping nonprintables and expanding tabs.
  4818. * For efficiency (at the cost of simplicity), note and skip indentation
  4819. * at the same time. Then, print outline with indentation to center it.
  4820. *
  4821. * outline[] is static so it is only allocated once; startpara so it is
  4822. * used for successive lines.
  4823. */
  4824. static void
  4825. Center (FormatData *data,
  4826. wint_t *in_line, /* start of input line */
  4827. register wint_t *inlinelim) /* end of line + 1 */
  4828. {
  4829. register wint_t *incp; /* pointer in in_line */
  4830. wint_t outline [LINESIZE + MAXTABSIZE]; /* after generic work */
  4831. register wint_t *outcp = outline; /* place in outline */
  4832. register wint_t *outlinelim = outline + LINESIZE; /* limit of outline*/
  4833. int haveword = False; /* hit word in in_line? */
  4834. register wint_t ch; /* current working char */
  4835. register int needsp; /* spaces need for tab */
  4836. register int indent = 0; /* size of indentation */
  4837. int textwidth; /* size of text part */
  4838. int extwidth = 0; /* additional width for MBCS */
  4839. /*
  4840. * SCAN INPUT LINE:
  4841. */
  4842. for (incp = in_line; (incp < inlinelim) && (outcp < outlinelim); incp++)
  4843. {
  4844. ch = *incp;
  4845. /*
  4846. * SKIP WHITE SPACE:
  4847. */
  4848. if (iswspace(ch))
  4849. {
  4850. needsp = ((ch != L'\t') && (iswblank(ch))) ?
  4851. 1 : data->tabsize - ((indent + outcp - outline) % data->tabsize);
  4852. if (! haveword) /* indentation */
  4853. indent += needsp;
  4854. else /* past text */
  4855. for ( ; needsp > 0; needsp--)
  4856. *outcp++ = data->Blank;
  4857. }
  4858. /*
  4859. * CARRY OVER PRINTABLE CHARS AND NOTE INDENTATION:
  4860. */
  4861. else if (iswprint (ch)) /* note: ch != ' ' */
  4862. {
  4863. *outcp++ = ch; /* just copy it over */
  4864. haveword = True;
  4865. if(MB_CUR_MAX > 1 && wcwidth(ch) > 1)
  4866. extwidth += wcwidth(ch) - 1;
  4867. }
  4868. /* else do nothing, which tosses other chars */
  4869. } /* end for */
  4870. /* Now outcp is the new outlinelim */
  4871. /*
  4872. * HANDLE BLANK LINE (no text):
  4873. */
  4874. if (! haveword)
  4875. {
  4876. putc ('\n', data->pAdj->outfp); /* "eat" any whitespace */
  4877. data->centerstartpara = True; /* expect new paragraph */
  4878. }
  4879. /*
  4880. * EAT TRAILING BLANKS, SET TEXTWIDTH:
  4881. */
  4882. else
  4883. {
  4884. /* note that outcp > outline */
  4885. while ((outcp[-1] != L'\t') && iswblank(outcp [-1]))
  4886. outcp--;
  4887. textwidth = (outcp - outline); /* thus textwidth > 0 */
  4888. /*
  4889. * SET AUTOMARGIN AND PRINT CENTERED LINE:
  4890. *
  4891. * The equations used depend on truncating division:
  4892. *
  4893. * eqn. 1 eqn. 2
  4894. * Margin Middle Width Results
  4895. * odd exact odd exact centering
  4896. * odd exact even extra char to right
  4897. * even left odd extra char to left
  4898. * even left even exact centering (due to "extra" char to right)
  4899. *
  4900. * When centermiddle is default or given by user, it is the same as the
  4901. * first two lines above (middle exactly specified).
  4902. */
  4903. if (data->centerstartpara) /* start of paragraph */
  4904. {
  4905. data->centerstartpara = False;
  4906. if (data->m0flag) /* set automargin */
  4907. /* 1 */ data->centermiddle = (indent + textwidth + extwidth + 1) / 2;
  4908. }
  4909. /* 2 */ PrintIndent (data, data->centermiddle - ((textwidth + extwidth + 1) / 2));
  4910. {
  4911. int i;
  4912. for(i = 0; i < textwidth; i++)
  4913. {
  4914. putwc(outline[i], data->pAdj->outfp);
  4915. }
  4916. putc('\n', data->pAdj->outfp);
  4917. }
  4918. } /* else */
  4919. } /* Center */
  4920. /************************************************************************
  4921. * WORD DATA STRUCTURES USED TO TRACK WORDS WHILE FILLING:
  4922. *
  4923. * This complicated scheme is used to minimize the actual data moving
  4924. * and manipulation needed to do the job.
  4925. *
  4926. * Words are kept in wordbuf[] without trailing nulls. It is large enough
  4927. * to accomodate two lines' worth of words plus wrap around to start a new
  4928. * word (which might be as big as a line) without overwriting old words
  4929. * not yet dumped. wordcp -> next free location in wordbuf[];
  4930. * wordcpwrap -> last place a new word is allowed to start.
  4931. *
  4932. * Words are pointed to and described by word[] structures. The array is
  4933. * big enough to accomodate two lines' worth of words, assuming each word
  4934. * takes at least two characters (including separator). wordbase and
  4935. * wordlimit are the bounds of the array. wordfirst remembers the first
  4936. * word in the array not yet printed. wordat is the word being worked on
  4937. * after wordnext is advanced (and maybe wrapped around). New elements
  4938. * are "allocated" using wordnext, a pointer that is wrapped around as
  4939. * needed.
  4940. *
  4941. * inlinenum and incolumn track the current input line and column per
  4942. * paragraph. outlinenum tracks the next line to print. All are base 1,
  4943. * but inlinenum is preset to zero at the start of each paragraph.
  4944. *
  4945. * pendchars tracks the number of dumpable characters accrued so far, to
  4946. * trigger dumping. indent1 and indent2 remember the indentations seen
  4947. * for the first two lines of each paragraph.
  4948. */
  4949. /************************************************************************
  4950. * F I L L
  4951. *
  4952. * Parse an input line (in_line to inlinelim) into words and trigger
  4953. * FillWord() as needed to finish each word, which in turn can call
  4954. * Dump() to dump output lines. This routine sacrifices simplicity and
  4955. * clarity for efficiency. It uses shared global word data except
  4956. * outlinenum and pendchars.
  4957. */
  4958. static void
  4959. Fill (FormatData *data,
  4960. wint_t *in_line, /* start of input line */
  4961. register wint_t *inlinelim) /* end of line + 1 */
  4962. {
  4963. register wint_t *incp; /* place in in_line */
  4964. register wint_t ch; /* current working char */
  4965. int haveword = False; /* hit word in in_line? */
  4966. register int inword = False; /* currently in a word? */
  4967. /*
  4968. * SCAN INPUT LINE:
  4969. */
  4970. data->inlinenum++;
  4971. data->incolumn = 1; /* starting a line */
  4972. for (incp = in_line; incp < inlinelim; incp++)
  4973. {
  4974. ch = *incp;
  4975. /*
  4976. * AT WHITE SPACE; FINISH PREVIOUS WORD if any, then skip white space:
  4977. */
  4978. if (iswspace(ch))
  4979. {
  4980. if (inword) /* was skipping a word */
  4981. {
  4982. inword = False;
  4983. FillWord(data);
  4984. }
  4985. data->incolumn += ((ch != L'\t') && (iswblank(ch))) ?
  4986. 1 : data->tabsize - ((data->incolumn - 1) % data->tabsize);
  4987. }
  4988. /*
  4989. * AT PART OF WORD; START NEW ONE IF NEEDED:
  4990. */
  4991. else if (iswprint (ch))
  4992. {
  4993. if (! inword) /* start new word */
  4994. {
  4995. inword = True;
  4996. if (data->wordcp > data->wordcpwrap)/* past wrap point */
  4997. data->wordcp = data->wordbuf;/* wraparound buffer */
  4998. data->wordat = data->wordnext;
  4999. WORDNEXT (data,data->wordnext);
  5000. data->wordat->cp = data->wordcp; /* note start of word */
  5001. data->wordat->inlinenum = data->inlinenum; /* note input line */
  5002. data->wordat->incolumn = data->incolumn; /* note input column */
  5003. data->wordat->wclen = 0;
  5004. if (! haveword)
  5005. {
  5006. haveword = True;
  5007. switch (data->inlinenum)/* note indentations */
  5008. {
  5009. case 1:
  5010. data->indent1 = data->incolumn - 1;
  5011. break;
  5012. case 2:
  5013. data->indent2 = data->incolumn - 1;
  5014. break;
  5015. }
  5016. }
  5017. }
  5018. /*
  5019. * SAVE ONE CHAR OF WORD:
  5020. */
  5021. *(data->wordcp++) = ch;
  5022. {
  5023. int n = wcwidth(ch);
  5024. if (n > 0)
  5025. { /* == 0 for a null char */
  5026. data->incolumn += n;
  5027. data->wordat->wclen++;
  5028. }
  5029. }
  5030. } /* else */
  5031. /* else skip other chars by doing nothing */
  5032. } /* for */
  5033. /*
  5034. * END OF LINE; HANDLE BLANK LINE, OR FINISH WORD AND AUTOMARGIN:
  5035. */
  5036. if (! haveword) /* no text on line */
  5037. {
  5038. data->inlinenum--; /* don't count empty lines */
  5039. Dump (data, True); /* force end paragraph */
  5040. fputc ('\n', data->pAdj->outfp); /* put this empty line */
  5041. data->inlinenum = 0; /* start new paragraph */
  5042. }
  5043. else /* have text on line */
  5044. {
  5045. if (inword) /* line ends in word */
  5046. FillWord(data);
  5047. if (data->pendchars > data->fillmargin)
  5048. { /* time to dump line */
  5049. Dump (data, False); /* not end of paragraph */
  5050. }
  5051. if (data->m0flag && (data->inlinenum == 1)) /* need to note right margin */
  5052. data->fillmargin = data->wordat->incolumn + data->wordat->length - 1;
  5053. }
  5054. } /* Fill */
  5055. /************************************************************************
  5056. * F I L L W O R D
  5057. *
  5058. * Save values for the word just finished and dump the output line if
  5059. * needed. Uses shared global word values, but does not touch outlinenum,
  5060. * and only increments pendchars.
  5061. *
  5062. * Trailing blanks (1 or 2) needed after a word are figured here.
  5063. * wordlen is the total length (nonzero) and wordcp points to the char
  5064. * past the end of the word. Two blanks are needed after words ending in:
  5065. *
  5066. * <terminal>[<quote>][<close>]
  5067. *
  5068. * where <terminal> is any of . : ? !
  5069. * <quote> is any of ' "
  5070. * <close> is any of ) ] }
  5071. *
  5072. * For efficiency, this routine avoids calling others to do character
  5073. * matching; it does them in line.
  5074. */
  5075. static void
  5076. FillWord (FormatData *data)
  5077. {
  5078. int wordlen; /* length of word to fill */
  5079. int blanks = 1; /* trailing blanks needed */
  5080. register wint_t ch1, ch2, ch3; /* last chars of word */
  5081. data->wordat->length = (data->incolumn - data->wordat->incolumn);
  5082. wordlen = data->wordat->wclen;
  5083. /*
  5084. * CHECK FOR SPECIAL END OF WORD:
  5085. */
  5086. ch3 = data->wordcp [-1];
  5087. if ((ch3 == L'.') || (ch3 == L':') || (ch3 == L'?') || (ch3 ==L'!'))
  5088. {
  5089. blanks = 2; /* <terminal> */
  5090. }
  5091. else if (wordlen >= 2)
  5092. {
  5093. ch2 = data->wordcp [-2];
  5094. if( ((ch2 == L'.') || (ch2 == L':') || (ch2 ==L'?') || (ch2 == L'!')) &&
  5095. ((ch3 == L'\'') || (ch3 == L'"') || (ch3 ==L')') || (ch3 == L']')
  5096. || (ch3 == L'}'))
  5097. )
  5098. {
  5099. blanks = 2; /* <terminal><quote or close> */
  5100. }
  5101. else if (wordlen >= 3)
  5102. {
  5103. ch1 = data->wordcp [-3];
  5104. if( ((ch1 == L'.') || (ch1 == L':') || (ch1 == L'?') || (ch1 == L'!'))
  5105. && ((ch2 == L'\'') || (ch2 == L'"'))
  5106. && ((ch3 == L')') || (ch3 == L']') || (ch3 == L'}')) )
  5107. {
  5108. blanks = 2; /* <terminal><quote><close> */
  5109. }
  5110. }
  5111. } /* else */
  5112. /*
  5113. * SAVE VALUES
  5114. */
  5115. data->pendchars += wordlen + (data->wordat->blanks = blanks);
  5116. } /* FillWord */
  5117. /************************************************************************
  5118. * D U M P
  5119. *
  5120. * Print output line(s), with all necessary indentation and formatting,
  5121. * if required (at end of paragraph) or if permissible. If required,
  5122. * indent1 is used if indent2 is not set yet (not on second line of
  5123. * input). Otherwise, if not at end of paragraph, dumping is only
  5124. * permissible after beginning the second input line, so fillmargin and
  5125. * indent2 are known, so tagged paragraphs are done right.
  5126. *
  5127. * Whenever dumping, all "full" lines are dumped, which means more than
  5128. * just one may be printed per call. jflag or rflag formatting is
  5129. * applied to all lines, except that jflag is ignored for the last line
  5130. * of each paragraph.
  5131. *
  5132. * Uses shared global word data, but does not touch inlinenum, incolumn,
  5133. * indent1, or indent2.
  5134. */
  5135. static void
  5136. Dump (FormatData *data,
  5137. int endpara) /* end of paragraph? */
  5138. {
  5139. int haveindent2 = (data->inlinenum >= 2); /* indent2 known? */
  5140. int startpara; /* start of paragraph? */
  5141. int normal; /* non-tagged line? */
  5142. WORD *wordpast = data->wordfirst; /* past last to dump */
  5143. register int wordlen; /* length of one word */
  5144. int indent; /* local value */
  5145. register int outneed; /* chars need to dump */
  5146. int outchars; /* chars found to dump */
  5147. /*
  5148. * IF DUMPING NEEDED, DUMP LINES TILL DONE:
  5149. */
  5150. if (! (endpara || haveindent2)) /* not time to dump */
  5151. return;
  5152. while ( (data->pendchars > data->fillmargin) /* line is full */
  5153. || (endpara && (data->wordfirst != data->wordnext)) ) /* more to dump */
  5154. {
  5155. startpara = (data->outlinenum < 2);
  5156. indent = (startpara || (! haveindent2)) ? data->indent1 : data->indent2;
  5157. /*
  5158. * CHECK FOR TAGGED PARAGRAPH if needed:
  5159. */
  5160. normal = True; /* default == no tag */
  5161. if (startpara && haveindent2 && (data->indent1 < data->indent2))
  5162. {
  5163. int incol2 = data->indent2 + 1; /* column needed */
  5164. while ( (wordpast != data->wordnext) /* more words */
  5165. && (wordpast->inlinenum == 1)) /* from line 1 */
  5166. {
  5167. if (wordpast->incolumn == incol2) /* bingo */
  5168. {
  5169. normal = False;
  5170. break;
  5171. }
  5172. WORDNEXT (data,wordpast);
  5173. }
  5174. if (normal)
  5175. wordpast = data->wordfirst; /* reset value */
  5176. /*
  5177. * PRINT TAG PART OF TAGGED PARAGRAPH:
  5178. */
  5179. else
  5180. {
  5181. WORD *wordat = data->wordfirst; /* local value */
  5182. while (wordat != wordpast) /* decrement pendchars */
  5183. {
  5184. data->pendchars -= wordat->length + wordat->blanks;
  5185. WORDNEXT (data,wordat);
  5186. }
  5187. PrintIndent (data, indent);
  5188. PrintTag (data, wordpast); /* preceding words */
  5189. data->wordfirst = wordpast; /* do rest of line */
  5190. indent = data->indent2; /* as if second line */
  5191. }
  5192. } /* if */
  5193. /*
  5194. * FIND WORDS WHICH FIT ON [REST OF] LINE:
  5195. */
  5196. if (indent >= data->fillmargin) /* don't over indent */
  5197. indent = data->fillmargin - 1;
  5198. outneed = data->fillmargin - indent; /* always greater than zero */
  5199. outchars = 0;
  5200. wordlen = wordpast->length;
  5201. do { /* always consume one */
  5202. outchars += wordlen + wordpast->blanks;
  5203. WORDNEXT (data,wordpast);
  5204. } while ( (wordpast != data->wordnext) /* not last word */
  5205. && (outchars + (wordlen = wordpast->length) <= outneed)
  5206. );
  5207. /* next will fit */
  5208. /*
  5209. ** BEKINSOKU/EKINSOKU PROCESSING
  5210. */
  5211. if( EkinBekinProc(data, &wordpast) )
  5212. postEkinBekinProc(data, &outchars,wordpast);
  5213. data->pendchars -= outchars; /* pendchars to consume */
  5214. /* from now on, don't include trailing blanks on last word */
  5215. outchars -= (WORDPREV (data,wordpast) -> blanks);
  5216. /* now wordfirst and wordpast specify the words to dump */
  5217. /*
  5218. * PRINT INDENTATION AND PREPARE JUSTIFICATION:
  5219. */
  5220. if (data->pAdj->rflag) /* right-justify only */
  5221. {
  5222. if (normal) /* nothing printed yet */
  5223. PrintIndent (data, data->fillmargin - outchars);
  5224. else /* indent + tag printed */
  5225. {
  5226. int blanks = data->fillmargin - outchars - indent;
  5227. while (blanks-- > 0) /* can't use PrintIndent()*/
  5228. putwc(data->Blank, data->pAdj->outfp);
  5229. }
  5230. }
  5231. else
  5232. {
  5233. if (normal) /* not already done */
  5234. PrintIndent (data, indent);
  5235. if (data->pAdj->jflag && ! (endpara && (wordpast == data->wordnext)))
  5236. Justify (data, outneed - outchars, wordpast);
  5237. }
  5238. /*
  5239. * PRINT REST OF LINE:
  5240. */
  5241. PrintWords (data, wordpast);
  5242. putwc('\n', data->pAdj->outfp);
  5243. data->wordfirst = wordpast;
  5244. data->outlinenum++; /* affects startpara */
  5245. } /* while */
  5246. if (endpara)
  5247. data->outlinenum = 1;
  5248. } /* Dump */
  5249. /************************************************************************
  5250. * P R I N T I N D E N T
  5251. *
  5252. * Print line indentation (if > 0), optionally using tabs where possible.
  5253. * Does not print a newline.
  5254. */
  5255. static void
  5256. PrintIndent (FormatData *data,
  5257. int indent) /* leading indentation */
  5258. {
  5259. if (indent > 0) /* indentation needed */
  5260. {
  5261. if (! data->pAdj->bflag) /* unexpand leading blanks */
  5262. {
  5263. while (indent >= data->tabsize)
  5264. {
  5265. putc ('\t', data->pAdj->outfp);
  5266. indent -= data->tabsize;
  5267. }
  5268. }
  5269. fprintf (data->pAdj->outfp, "%*s", indent, "");/*[remaining] blanks */
  5270. }
  5271. } /* PrintIndent */
  5272. /************************************************************************
  5273. * P R I N T T A G
  5274. *
  5275. * Print paragraph tag words from word[] array beginning with (global)
  5276. * wordfirst and ending before (parameter) wordpast, using input column
  5277. * positions in each word's data. Assumes indentation of indent1 was
  5278. * already printed on the line. Assumes *wordpast is the next word on
  5279. * the line and its column position is valid, and appends spaces up to
  5280. * the start of that word. Doesn't print a newline.
  5281. *
  5282. * Line indentation must already be done, as this routine doesn't know
  5283. * how to print leading tabs, only blanks.
  5284. */
  5285. static void
  5286. PrintTag (FormatData *data,
  5287. WORD *wordpast) /* past last to print */
  5288. {
  5289. register WORD *wordat = data->wordfirst; /* local value */
  5290. register int outcol = data->indent1 + 1; /* next column */
  5291. int wordcol; /* desired column */
  5292. register wint_t *wordcp; /* place in word */
  5293. wint_t *wordcplim; /* limit of word */
  5294. while (True) /* till break */
  5295. {
  5296. wordcol = wordat->incolumn;
  5297. while (outcol < wordcol)/* space over to word */
  5298. {
  5299. putwc(data->Blank, data->pAdj->outfp);
  5300. outcol++;
  5301. }
  5302. if (wordat == wordpast) /* past last word */
  5303. break; /* quit the loop */
  5304. wordcp = wordat->cp;
  5305. wordcplim = wordcp + wordat->wclen;
  5306. while (wordcp < wordcplim) /* print word */
  5307. putwc(*wordcp++, data->pAdj->outfp);
  5308. outcol += wordat->length;
  5309. WORDNEXT (data,wordat);
  5310. }
  5311. } /* PrintTag */
  5312. /************************************************************************
  5313. * P R I N T W O R D S
  5314. *
  5315. * Print words from word[] array beginning with (global) wordfirst and
  5316. * ending before (parameter) wordpast, using word sizes and trailing
  5317. * blanks (except for last word on line). Doesn't print a newline.
  5318. */
  5319. static void
  5320. PrintWords (FormatData *data,
  5321. WORD *wordpast) /* past last to print */
  5322. {
  5323. register WORD *wordat = data->wordfirst; /* local value */
  5324. register wint_t *wordcp; /* place in word */
  5325. wint_t *wordcplim; /* limit of word */
  5326. register int blanks; /* after a word */
  5327. while (True) /* till break */
  5328. {
  5329. wordcp = wordat->cp;
  5330. wordcplim = wordcp + wordat->wclen;
  5331. blanks = wordat->blanks; /* set before do WORDNEXT() */
  5332. while (wordcp < wordcplim) /* print word */
  5333. {
  5334. putwc(*wordcp++, data->pAdj->outfp);
  5335. }
  5336. wordat->wclen = 0;
  5337. WORDNEXT (data,wordat);
  5338. if (wordat == wordpast) /* just did last word */
  5339. break;
  5340. while (blanks-- > 0) /* print trailing blanks */
  5341. putwc(data->Blank, data->pAdj->outfp);
  5342. }
  5343. } /* PrintWords */
  5344. /************************************************************************
  5345. * J U S T I F Y
  5346. *
  5347. * Do left/right justification of [part of] a line in the word[] array
  5348. * beginning with (global) wordfirst and ending before (parameter)
  5349. * wordpast, by figuring where to insert blanks.
  5350. *
  5351. * Gives each word (except the last on the line) a score based on its
  5352. * size plus the size of the next word. Quicksorts word indices into
  5353. * order of current trailing blanks (least first), then score (most
  5354. * first). Cycles through this list adding trailing blanks to word[]
  5355. * entries such that words will space out nicely when printed.
  5356. */
  5357. static void
  5358. Justify (FormatData *data,
  5359. register int blanks, /* blanks to insert */
  5360. WORD *wordpast) /* past last to print */
  5361. {
  5362. register WORD *wordat; /* local value */
  5363. register int sortat; /* place in sort[] */
  5364. register int wordlen; /* size of this word */
  5365. register int nextlen; /* size of next word */
  5366. int level; /* current blanks level */
  5367. WORD *sort [WORDMAX]; /* sorted pointers */
  5368. int words; /* words in sort[] */
  5369. wordat = WORDPREV (data,wordpast); /* last word on line */
  5370. if ((blanks < 1) || (wordat == data->wordfirst))
  5371. return; /* can't do anything */
  5372. /*
  5373. * COMPUTE SCORES FOR WORDS AND SORT INDICES:
  5374. *
  5375. * March backwards through the words on line, starting with next to last.
  5376. */
  5377. words = 0;
  5378. nextlen = wordat->length; /* length of last word */
  5379. do { /* always at least one */
  5380. wordat = WORDPREV (data,wordat);
  5381. wordlen = wordat->length;
  5382. wordat->score = wordlen + nextlen; /* this plus next */
  5383. nextlen = wordlen;
  5384. sort [words++] = wordat; /* prepare for sorting */
  5385. } while (wordat != data->wordfirst);
  5386. qsort ((wint_t *) sort, words, sizeof (WORD *), CompareWords);
  5387. /*
  5388. * ADD TRAILING BLANKS TO PAD OUT WORDS:
  5389. *
  5390. * Each pass through the sorted list adds one trailing blank to each word
  5391. * not already past the current level. Thus all one-blank words are brought
  5392. * up to two; then all twos up to three; etc.
  5393. */
  5394. level = 0;
  5395. while (True) /* till return */
  5396. {
  5397. level++;
  5398. for (sortat = 0; sortat < words; sortat++)
  5399. {
  5400. wordat = sort [sortat];
  5401. if (wordat->blanks > level) /* end of this level */
  5402. break; /* start next level */
  5403. wordat->blanks++;
  5404. if (--blanks <= 0) /* no more needed */
  5405. return;
  5406. }
  5407. }
  5408. } /* Justify */
  5409. /************************************************************************
  5410. * C O M P A R E W O R D S
  5411. *
  5412. * Compare two word[] entries based on pointers to (WORD *), as called
  5413. * from qsort(3). Tell which entry has priority for receiving inserted
  5414. * blanks (least trailing blanks first, then highest scores), by returning
  5415. * -1 for the first entry, +1 for second entry, or 0 if no difference.
  5416. * (-1 literally means first entry < second entry, so it sorts first.)
  5417. */
  5418. static int
  5419. CompareWords (const void *p1, const void *p2)
  5420. {
  5421. WORD *word1 = *((WORD **)p1); /* (WORD *) pointers */
  5422. WORD *word2 = *((WORD **)p2);
  5423. int blanks1 = word1->blanks; /* trailing blanks */
  5424. int blanks2 = word2->blanks;
  5425. if (blanks1 == blanks2) /* commonest case */
  5426. {
  5427. int score1 = word1->score; /* word scores */
  5428. int score2 = word2->score;
  5429. if (score1 > score2) return (-1); /* word1 has priority */
  5430. else if (score1 < score2) return ( 1);
  5431. else return (0);
  5432. }
  5433. else if (blanks1 < blanks2) return (-1); /* word1 has priority */
  5434. else return ( 1);
  5435. } /* CompareWords */
  5436. /*
  5437. ** BKINSOKU and EKINSOKU processing for Japanese text
  5438. **
  5439. ** The function scans the wordlist that are ready for printing
  5440. ** and updates the "wordpast" pointer based on the rules of
  5441. ** BKINSOKU and EKINSOKU characters.
  5442. **
  5443. ** The code does not split a line just after a "gyomatu kinsoku"
  5444. ** character and just before a "gyoto kinsoku" character.
  5445. ** "Gyomatsu kinsoku" (e-kinsoku) are characters which cannot be
  5446. ** placed at the end of a line. "Gyoto kinsoku" (b-kinsoku) are
  5447. ** characters which can not be placed at the top of a line.
  5448. **
  5449. ** Global variables used:
  5450. ** wordfirst - beginning the word list (buffer of pending lines)
  5451. ** wordnext - next available spot in the pending buffer (i.e.
  5452. ** end of the buffer).
  5453. **
  5454. ** Global variables modified:
  5455. ** None.
  5456. **
  5457. ** Return Values:
  5458. ** 0 - No Post processing is required.
  5459. ** 1 - Post processing is required
  5460. */
  5461. #if !(defined(sun) && (_XOPEN_VERSION==3))
  5462. static int
  5463. EkinBekinProc(FormatData *data,
  5464. WORD **wordpast)
  5465. {
  5466. WORD *curword,*compword,*prevword;
  5467. int ekinflag = False, margin;
  5468. /*
  5469. * curword points to the last word of the first line.
  5470. * compword points to the first word of the next line or to the next
  5471. * available spot if there is no next line.
  5472. */
  5473. compword = *wordpast;
  5474. curword = WORDPREV(data,compword);
  5475. /*
  5476. * If the length of the current word is > fillmargin
  5477. * or it is the only word then return.
  5478. */
  5479. if (curword->length > data->fillmargin || (curword == data->wordfirst))
  5480. return False;
  5481. /*
  5482. * EKINSOKU processing
  5483. * If this character set supports ekinclass (can't end a line) char,
  5484. * start at the end of the line and search back until
  5485. * 1) we find a non-ekinsoku character, or
  5486. * 2) come to the beginning of the pending buffer.
  5487. */
  5488. if (ekinclass)
  5489. {
  5490. while (isekinsoku(*(curword->cp+curword->wclen-1)))
  5491. {
  5492. ekinflag = True;
  5493. if (curword == data->wordfirst) /* Boundary Condition */
  5494. break;
  5495. curword = WORDPREV(data,curword);
  5496. }
  5497. /*
  5498. * Post EKIN processing (i.e. we found an ekinsoku character in
  5499. * the line before finding an non-ekinsoku).
  5500. */
  5501. if (ekinflag) {
  5502. if (curword != data->wordfirst) {
  5503. /*
  5504. * We found a non-ekinsoku after we found the ekinsoku.
  5505. * Move the end of line to just after the non-ekinsoku.
  5506. */
  5507. WORDNEXT(data,curword);
  5508. *wordpast = curword;
  5509. return True;
  5510. }
  5511. else { /* Boundary condition */
  5512. /*
  5513. * Reached the beginning of the buffer without finding a
  5514. * non-ekinsoku. If the last word in the line can begin
  5515. * a line (i.e. non-bkinsoku) make it the first word of
  5516. * the next line.
  5517. */
  5518. curword = WORDPREV(data,compword);
  5519. if (!isbekinsoku(*curword->cp)) {
  5520. *wordpast = curword;
  5521. return True;
  5522. }
  5523. return False;
  5524. }
  5525. }
  5526. }
  5527. /*
  5528. * If we reached this point then:
  5529. * 1) the character set does not support ekinclass characters, or
  5530. * 2) the last character in the line is non-ekinsoku.
  5531. * Now, need to see if we can begin the next line with the first
  5532. * character on that line.
  5533. */
  5534. /*
  5535. * BEKINSOKU processing
  5536. * If this character set supports bekinclass (can't begin a line) char,
  5537. * search forward from the begining of the next line (curword) to the
  5538. * end of the buffer (wordnext) until:
  5539. * 1) A non-bekinsoku word is found,
  5540. * 2) if the line limit exceeds the set value, or
  5541. * 3) we reach the end of the buffer.
  5542. */
  5543. if (bekinclass)
  5544. {
  5545. /*
  5546. * compword points to the first word of the next line.
  5547. */
  5548. curword = compword;
  5549. margin = data->indent2;
  5550. while (curword != data->wordnext)
  5551. {
  5552. if (!isbekinsoku(*curword->cp))
  5553. break;
  5554. margin += (curword->length + curword->blanks);
  5555. if (margin >= data->fillmargin)
  5556. return False;
  5557. WORDNEXT(data,curword);
  5558. }
  5559. if (curword != data->wordnext && curword != compword)
  5560. {
  5561. /*
  5562. * The first word of the second line is bekinsoku so search
  5563. * backwards from end of first line until we are:
  5564. * 1) not at the first word of the buffer, and
  5565. * 2) not in between either an ekinsoku or bekinsoku character.
  5566. */
  5567. /*
  5568. * compword points to the first word of the next line.
  5569. * curword points to the last word of the first line.
  5570. */
  5571. curword = WORDPREV(data,compword);
  5572. prevword = WORDPREV(data,curword);
  5573. while ( (curword != data->wordfirst) &&
  5574. (isbekinsoku(*curword->cp) ||
  5575. isekinsoku(*(prevword->cp+prevword->wclen-1)))
  5576. )
  5577. {
  5578. margin += curword->length + curword->blanks;
  5579. if (margin >= data->fillmargin)
  5580. return False;
  5581. curword = prevword;
  5582. prevword = WORDPREV(data,curword);
  5583. }
  5584. if (curword != data->wordfirst) {
  5585. /*
  5586. * Did not reach the beginning of the buffer so we are between
  5587. * two non-ekinsoku & non-bekinsoku characters. Move the end
  5588. * of the first line here.
  5589. */
  5590. *wordpast = curword;
  5591. return True;
  5592. }
  5593. }
  5594. return False;
  5595. }
  5596. return False;
  5597. } /* end EkinBekinProc */
  5598. #else
  5599. static int
  5600. EkinBekinProc(FormatData *data,
  5601. WORD **wordpast)
  5602. {
  5603. WORD *curword,*compword,*prevword,*nextword;
  5604. int margin = data->indent2;
  5605. /*
  5606. * prevword points to the last word of the first line.
  5607. * compword & curword point to the first word of the next line or
  5608. * to the next available spot in the buffer if there is no next line.
  5609. */
  5610. compword = *wordpast;
  5611. curword = compword;
  5612. prevword = WORDPREV(data,curword);
  5613. /*
  5614. * If the length of the previous word is > fillmargin
  5615. * or it is the only word in the line then return.
  5616. * wordfirst points to the beginning of the buffer of pending lines.
  5617. */
  5618. if (prevword->length > data->fillmargin || (prevword == data->wordfirst))
  5619. return False;
  5620. /*
  5621. * Starting at the beginning of the next line, search backwards
  5622. * until:
  5623. * 1) we find two words we can split between lines, or
  5624. * 2) we reach the beginning of the buffer.
  5625. *
  5626. * If there is no next line start with the last two words of this line
  5627. * (wordnext points to the next available space in the buffer (i.e
  5628. * the end of the buffer).
  5629. */
  5630. if (curword == data->wordnext) {
  5631. curword = prevword;
  5632. prevword = WORDPREV(data,curword);
  5633. }
  5634. while ( (curword != data->wordfirst) &&
  5635. (wdbindf(*(prevword->cp+prevword->wclen-1), *curword->cp, 1) >4)
  5636. )
  5637. {
  5638. curword = prevword;
  5639. prevword = WORDPREV(data,curword);
  5640. }
  5641. if (curword != data->wordfirst) {
  5642. /*
  5643. * Did not reach the beginning of the buffer so we are between
  5644. * two non-ekinsoku & non-bekinsoku characters. Move the end
  5645. * of the first line here.
  5646. */
  5647. *wordpast = curword;
  5648. return True;
  5649. }
  5650. else {
  5651. /*
  5652. * Reached the beginning of the buffer so search forward
  5653. * from the beginning of the second line until:
  5654. * 1) we find two words we can split between lines,
  5655. * 2) we reach the end of the buffer, or
  5656. * 3) the line becomes too long.
  5657. *
  5658. * If there is no next line then just exit.
  5659. */
  5660. /*
  5661. * compword points to the first word of the next line or to the
  5662. * next available spot in the buffer if there is no next line.
  5663. * nextword points to the second word of the next line.
  5664. * wordnext points to the next available space in the buffer (i.e
  5665. * the end of the buffer)
  5666. */
  5667. curword = compword;
  5668. nextword = compword;
  5669. WORDNEXT(data,nextword);
  5670. if (curword == data->wordnext)
  5671. return False;
  5672. while (nextword != data->wordnext)
  5673. {
  5674. if (wdbindf(*(curword->cp+curword->wclen-1), *nextword->cp, 1) < 5)
  5675. break;
  5676. margin += (curword->length + curword->blanks);
  5677. if (margin >= data->fillmargin)
  5678. return False;
  5679. curword = nextword;
  5680. WORDNEXT(data,nextword);
  5681. }
  5682. if (nextword != data->wordnext) {
  5683. /*
  5684. * Did not reach the end of the buffer so we are between
  5685. * two non-ekinsoku & non-bekinsoku characters. Move the end
  5686. * of the first line here.
  5687. */
  5688. *wordpast = nextword;
  5689. return True;
  5690. }
  5691. return False;
  5692. }
  5693. } /* end EkinBekinProc */
  5694. #endif /* not sun */
  5695. static void
  5696. postEkinBekinProc(FormatData *data,
  5697. int *poutchars,
  5698. WORD *wordpast)
  5699. {
  5700. WORD *curword;
  5701. int colvalue,curlineno;
  5702. /*
  5703. * Recompute the value of *poutchars
  5704. */
  5705. (*poutchars) = 0;
  5706. curword = data->wordfirst;
  5707. while (curword != wordpast)
  5708. {
  5709. (*poutchars) += curword->length + curword->blanks;
  5710. WORDNEXT(data,curword);
  5711. }
  5712. /*
  5713. ** Adjust the word parameters -
  5714. ** inlinenum,incolumn of all the words
  5715. ** from 'curword' till 'wordnext'
  5716. */
  5717. curword = wordpast;
  5718. curlineno = curword->inlinenum+1;
  5719. colvalue = data->indent2;
  5720. while (curword != data->wordnext)
  5721. {
  5722. curword->inlinenum = curlineno;
  5723. curword->incolumn = colvalue;
  5724. colvalue += curword->length + curword->blanks;
  5725. if (colvalue > data->fillmargin)
  5726. {
  5727. colvalue = data->indent2;
  5728. curlineno++;
  5729. }
  5730. WORDNEXT(data,curword);
  5731. }
  5732. data->incolumn = colvalue;
  5733. data->inlinenum = curlineno;
  5734. }
  5735. #ifdef DEBUG
  5736. static
  5737. prnword(pword)
  5738. WORD *pword;
  5739. {
  5740. int i = 0;
  5741. if (pword == NULL)
  5742. return;
  5743. for (i=0; i < pword->wclen; i++)
  5744. fprintf(stderr,(const char *)"%c",(char)*(pword->cp+i));
  5745. fprintf(stderr,"Word Length :%d\n",pword->wclen);
  5746. }
  5747. #endif /* DEBUG */
  5748. /* ARGSUSED */
  5749. static void
  5750. AdjustParaCB(
  5751. Widget w,
  5752. caddr_t client_data,
  5753. caddr_t call_data )
  5754. {
  5755. DtEditorFormat( (Widget)client_data, (DtEditorFormatSettings *)NULL,
  5756. DtEDITOR_FORMAT_PARAGRAPH );
  5757. } /* AdjustParaCB */
  5758. /* ARGSUSED */
  5759. static void
  5760. AdjustAllCB(
  5761. Widget w,
  5762. caddr_t client_data,
  5763. caddr_t call_data )
  5764. {
  5765. DtEditorFormat( (Widget)client_data, (DtEditorFormatSettings *)NULL,
  5766. DtEDITOR_FORMAT_ALL );
  5767. } /* AdjustAllCB */
  5768. /*********
  5769. *
  5770. * DoAdjust - given left & right margin values & an alignment style, formats
  5771. * the text from one specified text position to another.
  5772. *
  5773. * Returns:
  5774. * DtEDITOR_NO_ERRORS if the text was formatted successfully.
  5775. * DtEDITOR_ILLEGAL_SIZE if the left & right margins don't make
  5776. * sense.
  5777. * DtEDITOR_NO_TMP_FILE if the 2 temporary files cannot be
  5778. * created.
  5779. * DtEDITOR_INVALID_TYPE if specified alignment is
  5780. * unrecognized
  5781. *
  5782. */
  5783. static DtEditorErrorCode
  5784. DoAdjust(
  5785. DtEditorWidget editor,
  5786. int leftMargin,
  5787. int rightMargin,
  5788. unsigned int alignment,
  5789. XmTextPosition start,
  5790. XmTextPosition end)
  5791. {
  5792. char tempName1[L_tmpnam], tempName2[L_tmpnam];
  5793. DtEditorErrorCode returnVal;
  5794. AdjRec adjRec;
  5795. /*
  5796. * Check that valid margin values were passed in
  5797. */
  5798. if( leftMargin >= 0 &&
  5799. rightMargin > 0 &&
  5800. rightMargin < 1025 &&
  5801. leftMargin <= rightMargin )
  5802. {
  5803. /*
  5804. * Set up
  5805. */
  5806. _DtTurnOnHourGlass(M_topLevelShell(editor));
  5807. if (M_format_dialog(editor) != (Widget)NULL)
  5808. _DtTurnOnHourGlass(M_format_dialog(editor));
  5809. memset(&adjRec, 0, sizeof(AdjRec));
  5810. /* The adjust text formatting code works with a data
  5811. representation to the screen of 1 byte per column for
  5812. multibyte environment. The Motif text Widget has a data
  5813. representation of 2 bytes per column in multibyte, so we must
  5814. fool the adjust code into thinking the margins are twice the
  5815. size in a multibyte environment.
  5816. */
  5817. if (MB_CUR_MAX > 1)
  5818. {
  5819. rightMargin = rightMargin * 2;
  5820. leftMargin = leftMargin * 2;
  5821. }
  5822. switch (alignment)
  5823. {
  5824. case DtEDITOR_ALIGN_CENTER:
  5825. {
  5826. adjRec.cflag = 1;
  5827. adjRec.margin = (rightMargin + leftMargin) / 2;
  5828. break;
  5829. }
  5830. case DtEDITOR_ALIGN_JUSTIFY:
  5831. {
  5832. adjRec.jflag = 1;
  5833. adjRec.margin = rightMargin;
  5834. break;
  5835. }
  5836. case DtEDITOR_ALIGN_RIGHT:
  5837. {
  5838. adjRec.rflag = 1;
  5839. adjRec.margin = rightMargin;
  5840. break;
  5841. }
  5842. case DtEDITOR_ALIGN_LEFT:
  5843. {
  5844. adjRec.margin = rightMargin;
  5845. break;
  5846. }
  5847. default:
  5848. {
  5849. returnVal = DtEDITOR_INVALID_TYPE;
  5850. }
  5851. } /* end switch */
  5852. /*
  5853. * Turn off converting leading spaces into tabs if we are
  5854. * working in a multi-byte locale. This is necessary
  5855. * because a tab may not equal (be as wide as) 8 spaces in
  5856. * a multi-byte locale.
  5857. */
  5858. adjRec.tabsize = 8;
  5859. if (MB_CUR_MAX > 1)
  5860. adjRec.bflag = True;
  5861. else
  5862. adjRec.bflag = False;
  5863. /*
  5864. * Create the two temp files
  5865. */
  5866. (void)tmpnam(tempName1);
  5867. (void)tmpnam(tempName2);
  5868. if ((adjRec.infp = fopen(tempName1, "w+")) != (FILE *)NULL) {
  5869. /*
  5870. * Successfully opened the first temporary file
  5871. */
  5872. if((adjRec.outfp = fopen(tempName2, "w")) != (FILE *)NULL) {
  5873. /*
  5874. * Successfully opened the second temporary file, so do the
  5875. * formatting.
  5876. */
  5877. returnVal = DtEDITOR_NO_ERRORS;
  5878. fixLeftMarginAndNewlines( editor, adjRec.infp, leftMargin,
  5879. rightMargin, (int)start, (int)end );
  5880. fflush(adjRec.infp);
  5881. rewind(adjRec.infp);
  5882. FormatText(&adjRec);
  5883. fclose(adjRec.infp);
  5884. unlink(tempName1);
  5885. fclose(adjRec.outfp);
  5886. returnVal =
  5887. DtEditorReplaceFromFile( (Widget)editor, start, end, tempName2 );
  5888. unlink(tempName2);
  5889. }
  5890. else {
  5891. /*
  5892. * Could not open second temporary file, so clean up first one
  5893. */
  5894. fclose(adjRec.infp);
  5895. unlink(tempName1);
  5896. returnVal = DtEDITOR_NO_TMP_FILE;
  5897. }
  5898. } /* end creating temporary files */
  5899. else
  5900. returnVal = DtEDITOR_NO_TMP_FILE;
  5901. /*
  5902. * Clean up
  5903. */
  5904. _DtTurnOffHourGlass(M_topLevelShell(editor));
  5905. if (M_format_dialog(editor) != (Widget)NULL)
  5906. _DtTurnOffHourGlass(M_format_dialog(editor));
  5907. } /* end check for valid margins */
  5908. else
  5909. returnVal = DtEDITOR_ILLEGAL_SIZE;
  5910. return (returnVal);
  5911. }
  5912. /* ARGSUSED */
  5913. static void
  5914. AdjustCloseCB(
  5915. Widget w,
  5916. caddr_t client_data,
  5917. caddr_t call_data )
  5918. {
  5919. DtEditorWidget editor = (DtEditorWidget )client_data;
  5920. XtUnmanageChild (M_format_dialog(editor));
  5921. }
  5922. /* ARGSUSED */
  5923. static int
  5924. ComputeRightMargin(
  5925. DtEditorWidget editor)
  5926. {
  5927. Dimension text_width, highlight_thickness, shadow_thickness,
  5928. margin_width;
  5929. int rightMargin;
  5930. Arg al[5]; /* arg list */
  5931. register int ac; /* arg count */
  5932. ac=0;
  5933. XtSetArg(al[ac], XmNwidth, &text_width); ac++;
  5934. XtSetArg(al[ac], XmNhighlightThickness, &highlight_thickness); ac++;
  5935. XtSetArg(al[ac], XmNshadowThickness, &shadow_thickness); ac++;
  5936. XtSetArg(al[ac], XmNmarginWidth, &margin_width); ac++;
  5937. XtGetValues(M_text(editor), al, ac);
  5938. if (M_fontWidth(editor) != 0)
  5939. rightMargin = ( (int)text_width -
  5940. (2 * ((int)highlight_thickness +
  5941. (int)shadow_thickness + (int)margin_width))
  5942. ) / M_fontWidth(editor);
  5943. else
  5944. rightMargin = (int)text_width -
  5945. (2 * ((int)highlight_thickness +
  5946. (int)shadow_thickness + (int)margin_width));
  5947. return( rightMargin );
  5948. } /* end ComputeRightMargin */
  5949. /* ARGSUSED */
  5950. static void
  5951. UpdateAdjust(
  5952. Widget widget,
  5953. XtPointer *client_data,
  5954. XConfigureEvent *event )
  5955. {
  5956. Dimension width;
  5957. DtEditorWidget editor = (DtEditorWidget) client_data;
  5958. char orgnum[20]; /* original margin size string */
  5959. Arg al[2];
  5960. XtSetArg(al[0], XmNwidth, &width);
  5961. XtGetValues(M_text(editor), al, 1);
  5962. if (width == M_textWidth(editor))
  5963. return;
  5964. M_textWidth(editor) = width;
  5965. sprintf( orgnum, "%d", ComputeRightMargin(editor) );
  5966. XmTextFieldSetString(M_format_rightMarginField(editor), orgnum);
  5967. }
  5968. /************************************************************************
  5969. *
  5970. * SetFormatDialogTitle - Change the title for the Format Settings dialog
  5971. *
  5972. ************************************************************************/
  5973. static void
  5974. SetFormatDialogTitle(
  5975. DtEditorWidget editor)
  5976. {
  5977. Arg al[2];
  5978. /*
  5979. * If the Format Settings dialog has been created, change its title
  5980. */
  5981. if( M_format_dialog(editor) != (Widget)NULL )
  5982. {
  5983. /*
  5984. * Prepend the DialogTitle resource, if it has been set
  5985. */
  5986. if( E_dialogTitle(editor) != (XmString)NULL ) {
  5987. XmString titleStr;
  5988. /*
  5989. * Add the "functional title" to the DialogTitle
  5990. */
  5991. titleStr = XmStringConcat( E_dialogTitle(editor),
  5992. E_format_dialogTitle(editor) );
  5993. XtSetArg( al[0], XmNdialogTitle, titleStr );
  5994. XtSetValues(M_format_dialog(editor), al, 1);
  5995. XmStringFree( titleStr );
  5996. }
  5997. else {
  5998. XtSetArg( al[0], XmNdialogTitle, E_format_dialogTitle(editor) );
  5999. XtSetValues(M_format_dialog(editor), al, 1);
  6000. }
  6001. }
  6002. } /* end SetFormatDialogTitle */
  6003. /************************************************************************
  6004. *
  6005. * ResetFormatDialog - Reset margins & alignment of the Format Settings
  6006. * dialog
  6007. *
  6008. ************************************************************************/
  6009. static void
  6010. ResetFormatDialog(
  6011. DtEditorWidget editor)
  6012. {
  6013. char orgnum[20]; /* original margin size string */
  6014. /*
  6015. * Reset the margins to default values
  6016. */
  6017. /* Right margin default value */
  6018. sprintf( orgnum, "%d", ComputeRightMargin(editor) );
  6019. XmTextFieldSetString(M_format_rightMarginField(editor), orgnum);
  6020. /* Left margin default value */
  6021. sprintf(orgnum, "%d", 0);
  6022. XmTextFieldSetString(M_format_leftMarginField(editor), orgnum);
  6023. /*
  6024. * Reset the alignment style to default value
  6025. */
  6026. XmToggleButtonGadgetSetState(M_format_leftJust(editor), True, True);
  6027. } /* end ResetFormatDialog */
  6028. /************************************************************************
  6029. *
  6030. * CreateFormatDialog - Create & initialize the Format Settings dialog
  6031. *
  6032. ************************************************************************/
  6033. static void
  6034. CreateFormatDialog(
  6035. DtEditorWidget editor)
  6036. {
  6037. Arg al[15]; /* arg list */
  6038. register int ac; /* arg count */
  6039. Pixel textBackground, textForeground;
  6040. XmString tempString = (XmString)NULL;
  6041. /*
  6042. * Match the background & foreground colors of the edit window
  6043. * Don't use DtNtextBackground/Foreground directly because they
  6044. * will be DtUNSPECIFIED.
  6045. */
  6046. ac = 0;
  6047. XtSetArg(al[ac], XmNforeground, &textForeground); ac++;
  6048. XtSetArg(al[ac], XmNbackground, &textBackground); ac++;
  6049. XtGetValues(M_text(editor), al, ac);
  6050. ac = 0;
  6051. /*
  6052. * First, create the dialog's title, prepending the
  6053. * DtNdialogTitle resource, if it is set
  6054. */
  6055. if( E_dialogTitle(editor) != (XmString)NULL ) {
  6056. /*
  6057. * Add the "functional title" to the DialogTitle
  6058. */
  6059. tempString = XmStringConcat( E_dialogTitle(editor),
  6060. E_format_dialogTitle(editor) );
  6061. XtSetArg (al[ac], XmNdialogTitle, tempString ); ac++;
  6062. }
  6063. else {
  6064. XtSetArg(al[ac], XmNdialogTitle, E_format_dialogTitle(editor)); ac++;
  6065. }
  6066. XtSetArg (al[ac], XmNautoUnmanage, False); ac++;
  6067. XtSetArg (al[ac], XmNmarginWidth, 5); ac++;
  6068. XtSetArg (al[ac], XmNmarginHeight, 5); ac++;
  6069. XtSetArg (al[ac], XmNshadowThickness, 1); ac++;
  6070. XtSetArg (al[ac], XmNshadowType, XmSHADOW_OUT); ac++;
  6071. XtSetArg (al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
  6072. M_format_dialog(editor) = XmCreateFormDialog(
  6073. M_topLevelShell(editor), "ad_dial", al, ac);
  6074. if (tempString != (XmString)NULL)
  6075. XmStringFree( tempString );
  6076. XtAddCallback(M_format_dialog(editor), XmNhelpCallback,
  6077. (XtCallbackProc)HelpFormatDialogCB, (XtPointer)editor);
  6078. /*
  6079. * When creating the fields & buttons use the appropriate label
  6080. * resource (e.g. DtNcenterToggleLabel), if it has been set, then
  6081. * clear the resource to save space. The field or button widget
  6082. * will contain the actual value & it can be gotten from there,
  6083. * if it is needed.
  6084. *
  6085. * If the appropriate resource has not been set, use its default
  6086. * value from the message catalog.
  6087. */
  6088. /*
  6089. * create the left margin label and text field
  6090. */
  6091. ac = 0;
  6092. if (E_format_leftMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED) {
  6093. /*
  6094. * Use the resource value & clear it (to save space).
  6095. */
  6096. tempString = XmStringCopy(E_format_leftMarginFieldLabel(editor));
  6097. E_format_leftMarginFieldLabel(editor) = (XmString) DtUNSPECIFIED;
  6098. }
  6099. else {
  6100. /*
  6101. * The resource has not been set so use its default value
  6102. */
  6103. tempString = XmStringCreateLocalized(LEFT_MARGIN);
  6104. }
  6105. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6106. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  6107. XtSetArg (al[ac], XmNleftPosition, 2); ac++;
  6108. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  6109. XtSetArg (al[ac], XmNtopOffset, 10); ac++;
  6110. XtSetArg (al[ac], XmNfontList, E_labelFontList(editor)); ac++;
  6111. M_format_leftLabel(editor) = (Widget) XmCreateLabelGadget (
  6112. M_format_dialog(editor), "left_label", al, ac);
  6113. XtManageChild (M_format_leftLabel(editor));
  6114. XmStringFree (tempString);
  6115. XtAddCallback(M_format_leftLabel(editor), XmNhelpCallback,
  6116. (XtCallbackProc)HelpFormatLeftMarginCB, (XtPointer)editor);
  6117. ac = 0;
  6118. XtSetArg (al[ac], XmNbackground, textBackground); ac++;
  6119. XtSetArg (al[ac], XmNforeground, textForeground); ac++;
  6120. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
  6121. XtSetArg (al[ac], XmNleftWidget, M_format_leftLabel(editor)); ac++;
  6122. XtSetArg (al[ac], XmNleftOffset, 3); ac++;
  6123. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  6124. XtSetArg (al[ac], XmNrightPosition, 45); ac++;
  6125. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  6126. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6127. XtSetArg (al[ac], XmNtraversalOn, True); ac++;
  6128. XtSetArg (al[ac], XmNcolumns, 3); ac++;
  6129. XtSetArg (al[ac], XmNfontList, E_textFontList(editor)); ac++;
  6130. M_format_leftMarginField(editor) = (Widget) XmCreateTextField (
  6131. M_format_dialog(editor), "left_text", al, ac);
  6132. XtManageChild (M_format_leftMarginField(editor));
  6133. XtAddCallback(M_format_leftMarginField(editor), XmNhelpCallback,
  6134. (XtCallbackProc)HelpFormatLeftMarginCB, (XtPointer)editor);
  6135. /*
  6136. * create the right margin label and text field
  6137. */
  6138. ac = 0;
  6139. if (E_format_rightMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED)
  6140. {
  6141. /*
  6142. * Use the resource value & clear it (to save space).
  6143. */
  6144. tempString = XmStringCopy(E_format_rightMarginFieldLabel(editor));
  6145. E_format_rightMarginFieldLabel(editor) = (XmString) DtUNSPECIFIED;
  6146. }
  6147. else
  6148. {
  6149. /*
  6150. * The resource has not been set so use its default value
  6151. */
  6152. tempString = XmStringCreateLocalized(RIGHT_MARGIN);
  6153. }
  6154. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6155. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  6156. XtSetArg (al[ac], XmNleftPosition, 55); ac++;
  6157. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  6158. XtSetArg (al[ac], XmNtopOffset, 10); ac++;
  6159. XtSetArg (al[ac], XmNfontList, E_labelFontList(editor)); ac++;
  6160. M_format_rightLabel(editor)= (Widget) XmCreateLabelGadget (
  6161. M_format_dialog(editor), "right_label", al, ac);
  6162. XtManageChild (M_format_rightLabel(editor));
  6163. XmStringFree (tempString);
  6164. XtAddCallback(M_format_rightLabel(editor), XmNhelpCallback,
  6165. (XtCallbackProc)HelpFormatRightMarginCB,
  6166. (XtPointer)editor);
  6167. ac = 0;
  6168. XtSetArg (al[ac], XmNbackground, textBackground); ac++;
  6169. XtSetArg (al[ac], XmNforeground, textForeground); ac++;
  6170. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  6171. XtSetArg (al[ac], XmNrightPosition, 98); ac++;
  6172. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
  6173. XtSetArg (al[ac], XmNleftWidget, M_format_rightLabel(editor)); ac++;
  6174. XtSetArg (al[ac], XmNleftOffset, 3); ac++;
  6175. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  6176. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6177. XtSetArg (al[ac], XmNtraversalOn, True); ac++;
  6178. XtSetArg (al[ac], XmNcolumns, 3); ac++;
  6179. XtSetArg (al[ac], XmNfontList, E_textFontList(editor)); ac++;
  6180. M_format_rightMarginField(editor) = (Widget) XmCreateTextField (
  6181. M_format_dialog(editor),
  6182. "right_text", al, ac);
  6183. XtManageChild (M_format_rightMarginField(editor));
  6184. XtAddCallback(M_format_rightMarginField(editor), XmNhelpCallback,
  6185. (XtCallbackProc)HelpFormatRightMarginCB,
  6186. (XtPointer)editor);
  6187. /*
  6188. * create the radio box for justification choices
  6189. */
  6190. ac = 0;
  6191. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  6192. XtSetArg (al[ac], XmNleftOffset, 5); ac++;
  6193. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  6194. XtSetArg (al[ac], XmNtopWidget, M_format_leftMarginField(editor)); ac++;
  6195. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6196. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  6197. XtSetArg (al[ac], XmNrightOffset, 5); ac++;
  6198. XtSetArg (al[ac], XmNtraversalOn, True); ac++;
  6199. M_format_radioBox(editor) = (Widget) XmCreateRadioBox(
  6200. M_format_dialog(editor), "radioBox", al, ac);
  6201. XtAddCallback(M_format_radioBox(editor), XmNhelpCallback,
  6202. (XtCallbackProc)HelpFormatJustifyButtonsCB,
  6203. (XtPointer)editor);
  6204. XtManageChild(M_format_radioBox(editor));
  6205. /* Create Left Align toggle */
  6206. ac = 0;
  6207. if (E_format_leftAlignToggleLabel(editor) != (XmString) DtUNSPECIFIED) {
  6208. /*
  6209. * Use the resource value & clear it (to save space).
  6210. */
  6211. tempString = XmStringCopy(E_format_leftAlignToggleLabel(editor));
  6212. E_format_leftAlignToggleLabel(editor) = (XmString) DtUNSPECIFIED;
  6213. }
  6214. else {
  6215. /*
  6216. * The resource has not been set so use its default value
  6217. */
  6218. tempString = XmStringCreateLocalized(LEFT_ALIGN);
  6219. }
  6220. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6221. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6222. M_format_leftJust(editor) = (Widget) XmCreateToggleButtonGadget(
  6223. M_format_radioBox(editor), "left_just", al, ac);
  6224. XmStringFree (tempString);
  6225. XtManageChild(M_format_leftJust(editor));
  6226. /* Create Right Align toggle */
  6227. ac = 0;
  6228. if(E_format_rightAlignToggleLabel(editor) != (XmString)DtUNSPECIFIED) {
  6229. /*
  6230. * Use the resource value & clear it (to save space).
  6231. */
  6232. tempString = XmStringCopy(E_format_rightAlignToggleLabel(editor));
  6233. E_format_rightAlignToggleLabel(editor) = (XmString) DtUNSPECIFIED;
  6234. }
  6235. else {
  6236. /*
  6237. * The resource has not been set so use its default value
  6238. */
  6239. tempString = XmStringCreateLocalized(RIGHT_ALIGN);
  6240. }
  6241. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6242. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6243. M_format_rightJust(editor) = (Widget) XmCreateToggleButtonGadget(
  6244. M_format_radioBox(editor), "right_just", al, ac);
  6245. XmStringFree (tempString);
  6246. XtManageChild(M_format_rightJust(editor));
  6247. /* Create Justify toggle */
  6248. ac = 0;
  6249. if (E_format_justifyToggleLabel(editor) != (XmString) DtUNSPECIFIED) {
  6250. /*
  6251. * Use the resource value & clear it (to save space).
  6252. */
  6253. tempString = XmStringCopy(E_format_justifyToggleLabel(editor));
  6254. E_format_justifyToggleLabel(editor) = (XmString) DtUNSPECIFIED;
  6255. }
  6256. else {
  6257. /*
  6258. * The resource has not been set so use its default value
  6259. */
  6260. tempString = XmStringCreateLocalized( JUSTIFY );
  6261. }
  6262. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6263. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6264. M_format_bothJust(editor) = (Widget) XmCreateToggleButtonGadget(
  6265. M_format_radioBox(editor), "both_just", al, ac);
  6266. XmStringFree (tempString);
  6267. XtManageChild(M_format_bothJust(editor));
  6268. /* Create Center align toggle */
  6269. ac = 0;
  6270. if (E_format_centerToggleLabel(editor) != (XmString) DtUNSPECIFIED) {
  6271. /*
  6272. * Use the resource value & clear it (to save space).
  6273. */
  6274. tempString = XmStringCopy(E_format_centerToggleLabel(editor));
  6275. E_format_centerToggleLabel(editor) = (XmString) DtUNSPECIFIED;
  6276. }
  6277. else {
  6278. /*
  6279. * The resource has not been set so use its default value
  6280. */
  6281. tempString = XmStringCreateLocalized(CENTER);
  6282. }
  6283. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6284. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6285. M_format_center(editor) = (Widget) XmCreateToggleButtonGadget(
  6286. M_format_radioBox(editor), "center", al, ac);
  6287. XmStringFree(tempString);
  6288. XtManageChild(M_format_center(editor));
  6289. /* Create a separator between the radio box and buttons */
  6290. ac = 0;
  6291. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  6292. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  6293. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  6294. XtSetArg (al[ac], XmNtopWidget, M_format_radioBox(editor)); ac++;
  6295. XtSetArg (al[ac], XmNtopOffset, 15); ac++;
  6296. M_format_separator(editor) = (Widget) XmCreateSeparatorGadget (
  6297. M_format_dialog(editor), "separator", al, ac);
  6298. XtManageChild (M_format_separator(editor));
  6299. /* Create Format Paragraph button */
  6300. ac = 0;
  6301. if ( E_format_formatParagraphButtonLabel(editor) !=
  6302. (XmString) DtUNSPECIFIED ) {
  6303. /*
  6304. * Use the resource value & clear it (to save space).
  6305. */
  6306. tempString = XmStringCopy(E_format_formatParagraphButtonLabel(editor));
  6307. E_format_formatParagraphButtonLabel(editor) = (XmString) DtUNSPECIFIED;
  6308. }
  6309. else {
  6310. /*
  6311. * The resource has not been set so use its default value
  6312. */
  6313. tempString = XmStringCreateLocalized(PARAGRAPH);
  6314. }
  6315. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6316. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  6317. XtSetArg (al[ac], XmNleftPosition, 2); ac++;
  6318. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  6319. XtSetArg (al[ac], XmNrightPosition, 25); ac++;
  6320. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  6321. XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
  6322. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6323. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  6324. XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
  6325. XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
  6326. XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
  6327. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6328. M_format_paragraph(editor) = (Widget) XmCreatePushButtonGadget (
  6329. M_format_dialog(editor), "para", al, ac);
  6330. XtManageChild (M_format_paragraph(editor));
  6331. XmStringFree (tempString);
  6332. XtAddCallback (M_format_paragraph(editor), XmNactivateCallback,
  6333. (XtCallbackProc) AdjustParaCB, (XtPointer) editor);
  6334. /* Create Format All button */
  6335. ac = 0;
  6336. if (E_format_formatAllButtonLabel(editor) != (XmString)DtUNSPECIFIED) {
  6337. /*
  6338. * Use the resource value & clear it (to save space).
  6339. */
  6340. tempString = XmStringCopy(E_format_formatAllButtonLabel(editor));
  6341. E_format_formatAllButtonLabel(editor) = (XmString) DtUNSPECIFIED;
  6342. }
  6343. else {
  6344. /*
  6345. * The resource has not been set so use its default value
  6346. */
  6347. tempString = XmStringCreateLocalized(ALL);
  6348. }
  6349. XtSetArg(al[ac], XmNlabelString, tempString); ac++;
  6350. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  6351. XtSetArg (al[ac], XmNleftPosition, 27); ac++;
  6352. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  6353. XtSetArg (al[ac], XmNrightPosition, 49); ac++;
  6354. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  6355. XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
  6356. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6357. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  6358. XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
  6359. XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
  6360. XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
  6361. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6362. M_format_all(editor) = (Widget) XmCreatePushButtonGadget(
  6363. M_format_dialog(editor), "all", al, ac);
  6364. XtManageChild (M_format_all(editor));
  6365. XmStringFree (tempString);
  6366. XtAddCallback (M_format_all(editor), XmNactivateCallback,
  6367. (XtCallbackProc) AdjustAllCB, (XtPointer) editor);
  6368. /* Create Close button */
  6369. tempString = XmStringCreateLocalized(CLOSE_BUTTON);
  6370. ac = 0;
  6371. XtSetArg (al[ac], XmNlabelString, tempString); ac++;
  6372. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  6373. XtSetArg (al[ac], XmNleftPosition, 51); ac++;
  6374. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  6375. XtSetArg (al[ac], XmNrightPosition, 73); ac++;
  6376. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  6377. XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
  6378. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6379. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  6380. XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
  6381. XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
  6382. XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
  6383. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6384. M_format_close(editor) = (Widget) XmCreatePushButtonGadget (
  6385. M_format_dialog(editor), "close", al, ac);
  6386. XtManageChild (M_format_close(editor));
  6387. XmStringFree (tempString);
  6388. XtAddCallback (M_format_close(editor), XmNactivateCallback,
  6389. (XtCallbackProc) AdjustCloseCB, (XtPointer) editor);
  6390. tempString = XmStringCreateLocalized(HELP_BUTTON);
  6391. ac = 0;
  6392. XtSetArg (al[ac], XmNlabelString, tempString); ac++;
  6393. XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  6394. XtSetArg (al[ac], XmNleftPosition, 75); ac++;
  6395. XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  6396. XtSetArg (al[ac], XmNrightPosition, 98); ac++;
  6397. XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  6398. XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
  6399. XtSetArg (al[ac], XmNtopOffset, 5); ac++;
  6400. XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  6401. XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
  6402. XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
  6403. XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
  6404. XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
  6405. M_format_help(editor) = (Widget) XmCreatePushButtonGadget(
  6406. M_format_dialog(editor), "help", al, ac);
  6407. XtManageChild (M_format_help(editor));
  6408. XmStringFree (tempString);
  6409. XtAddCallback( M_format_help(editor), XmNactivateCallback,
  6410. (XtCallbackProc) HelpFormatDialogCB, (XtPointer) editor);
  6411. /*
  6412. * set the default/activation button.
  6413. */
  6414. XtSetArg(al[0], XmNdefaultButton, M_format_close(editor));
  6415. XtSetValues(M_format_dialog(editor), al, 1);
  6416. XtRealizeWidget (M_format_dialog(editor));
  6417. /*
  6418. * Initialize the margins & alignment toggles
  6419. */
  6420. ResetFormatDialog(editor);
  6421. XtSetArg(al[0], XmNwidth, &(M_textWidth(editor)));
  6422. XtGetValues(M_text(editor), al, 1);
  6423. XtAddEventHandler(M_text(editor), StructureNotifyMask, False,
  6424. (XtEventHandler) UpdateAdjust, (XtPointer) editor);
  6425. } /* end CreateFormatDialog */
  6426. /************************************************************************
  6427. *
  6428. * GetAdjustSettings - Read the alignment settings from the Format
  6429. * Settings dialog.
  6430. *
  6431. ************************************************************************/
  6432. static void
  6433. GetAdjustSettings(
  6434. DtEditorWidget editor,
  6435. DtEditorFormatSettings *formatSettings)
  6436. {
  6437. if( M_format_dialog(editor)!= (Widget)NULL ) {
  6438. /*
  6439. * Read the current alignment settings from the Format Settings
  6440. * dialog.
  6441. */
  6442. char *num;
  6443. /*
  6444. * Get current type of alignment
  6445. */
  6446. if (XmToggleButtonGadgetGetState(M_format_leftJust(editor)))
  6447. formatSettings->alignment = DtEDITOR_ALIGN_LEFT;
  6448. else if (XmToggleButtonGadgetGetState(M_format_rightJust(editor)))
  6449. formatSettings->alignment = DtEDITOR_ALIGN_RIGHT;
  6450. else if (XmToggleButtonGadgetGetState(M_format_bothJust(editor)))
  6451. formatSettings->alignment = DtEDITOR_ALIGN_JUSTIFY;
  6452. else
  6453. formatSettings->alignment = DtEDITOR_ALIGN_CENTER;
  6454. /*
  6455. * Get current margin settings
  6456. */
  6457. num = (char *) XmTextFieldGetString(
  6458. (Widget)M_format_rightMarginField(editor) );
  6459. formatSettings->rightMargin = atoi(num);
  6460. XtFree(num);
  6461. num = (char *) XmTextFieldGetString(
  6462. (Widget)M_format_leftMarginField(editor) );
  6463. formatSettings->leftMargin = atoi(num);
  6464. XtFree(num);
  6465. }
  6466. else {
  6467. /*
  6468. * The Format Settings dialog box has not been created so use the
  6469. * default values.
  6470. */
  6471. formatSettings->leftMargin = 0;
  6472. formatSettings->rightMargin = ComputeRightMargin(editor);
  6473. formatSettings->alignment = DtEDITOR_ALIGN_LEFT;
  6474. }
  6475. }
  6476. /****************************************************************
  6477. *
  6478. * Public Procs
  6479. *
  6480. ****************************************************************/
  6481. /*********************************************************
  6482. *
  6483. * DtCreateEditor
  6484. * Create an instance of an editor and return the widget id.
  6485. */
  6486. Widget
  6487. DtCreateEditor(
  6488. Widget parent,
  6489. char *name,
  6490. ArgList arglist,
  6491. Cardinal argcount )
  6492. {
  6493. return( XtCreateWidget(name,dtEditorWidgetClass,parent,arglist,argcount) );
  6494. }
  6495. Boolean
  6496. DtEditorCheckForUnsavedChanges(
  6497. Widget widget)
  6498. {
  6499. DtEditorWidget editor = (DtEditorWidget) widget;
  6500. Boolean result;
  6501. _DtWidgetToAppContext(widget);
  6502. _DtAppLock(app);
  6503. result = M_unreadChanges( editor );
  6504. _DtAppUnlock(app);
  6505. return result;
  6506. } /* end DtEditorCheckForUnsavedChanges */
  6507. Boolean
  6508. DtEditorDeleteSelection(
  6509. Widget widget)
  6510. {
  6511. XmTextPosition first, last;
  6512. DtEditorWidget editor = (DtEditorWidget) widget;
  6513. Boolean result;
  6514. _DtWidgetToAppContext(widget);
  6515. _DtAppLock(app);
  6516. /*
  6517. * Check for a non-null selection
  6518. */
  6519. if ( XmTextGetSelectionPosition(M_text(editor), &first, &last) &&
  6520. first != last )
  6521. {
  6522. XmTextRemove(M_text(editor));
  6523. result = True;
  6524. }
  6525. else
  6526. result = False;
  6527. _DtAppUnlock(app);
  6528. return result;
  6529. } /* end DtEditorDeleteSelection */
  6530. /*
  6531. * DtEditorClearSelection replaces the currently selected text with
  6532. * spaces. It requires an event because the underlying text widget
  6533. * routines require one to look at the time stamp within.
  6534. */
  6535. Boolean
  6536. DtEditorClearSelection(
  6537. Widget widget)
  6538. {
  6539. DtEditorWidget editor = (DtEditorWidget) widget;
  6540. char *params=(char *)NULL;
  6541. Cardinal num_params = 0;
  6542. XEvent event;
  6543. _DtWidgetToAppContext(widget);
  6544. _DtAppLock(app);
  6545. /*
  6546. * Create an event with a correct timestamp
  6547. */
  6548. event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
  6549. /*
  6550. * Call routine to clear primary selection
  6551. */
  6552. ClearSelection( widget, &event, &params, &num_params );
  6553. _DtAppUnlock(app);
  6554. return(True);
  6555. } /* end DtEditorClearSelection */
  6556. /*
  6557. *
  6558. * DtEditorDeselect - Unselects any selected text of an Editor widget
  6559. *
  6560. */
  6561. Boolean
  6562. DtEditorDeselect(
  6563. Widget widget)
  6564. {
  6565. DtEditorWidget editor = (DtEditorWidget) widget;
  6566. char *params=(char *)NULL;
  6567. Cardinal num_params = 0;
  6568. XEvent event;
  6569. _DtWidgetToAppContext(widget);
  6570. _DtAppLock(app);
  6571. /*
  6572. * Create an event with a correct timestamp
  6573. */
  6574. event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
  6575. DeselectAll( widget, &event, &params, &num_params );
  6576. _DtAppUnlock(app);
  6577. return(True);
  6578. } /* end DtEditorDeselect */
  6579. /*
  6580. *
  6581. * DtEditorDisableRedisplay - Temporarily prevent visual update of a
  6582. * Editor widget
  6583. *
  6584. */
  6585. void
  6586. DtEditorDisableRedisplay(
  6587. Widget widget)
  6588. {
  6589. DtEditorWidget editor = (DtEditorWidget) widget;
  6590. _DtWidgetToAppContext(widget);
  6591. _DtAppLock(app);
  6592. XmTextDisableRedisplay( M_text(editor) );
  6593. _DtAppUnlock(app);
  6594. } /* end DtEditorDisableRedisplay */
  6595. /*
  6596. *
  6597. * DtEditorEnableRedisplay - Force visual update of an Editor widget
  6598. *
  6599. */
  6600. void
  6601. DtEditorEnableRedisplay(
  6602. Widget widget)
  6603. {
  6604. DtEditorWidget editor = (DtEditorWidget) widget;
  6605. _DtWidgetToAppContext(widget);
  6606. _DtAppLock(app);
  6607. XmTextEnableRedisplay( M_text(editor) );
  6608. _DtAppUnlock(app);
  6609. } /* end DtEditorEnableRedisplay */
  6610. /*********
  6611. *
  6612. * DtEditorFormat
  6613. * Given left & right margin values & an alignment style,
  6614. * formats either the current paragraph or the entire document,
  6615. * as specified. If margin values & alignment style are not
  6616. * provided, DtEditorFormat will use the current values from
  6617. * the Format Settings dialog.
  6618. *
  6619. * Returns:
  6620. * DtEDITOR_NO_ERRORS if the text was formatted successfully.
  6621. * DtEDITOR_NO_TMP_FILE if the 2 temporary files cannot be
  6622. * created.
  6623. * DtEDITOR_ILLEGAL_SIZE if the left & right margins don't make
  6624. * sense.
  6625. * DtEDITOR_INVALID_RANGE if specified amount to format is
  6626. * unrecognized
  6627. * DtEDITOR_INVALID_TYPE if specified alignment is
  6628. * unrecognized
  6629. *
  6630. */
  6631. DtEditorErrorCode
  6632. DtEditorFormat(
  6633. Widget widget,
  6634. DtEditorFormatSettings *formatSettings,
  6635. unsigned int amountToFormat )
  6636. {
  6637. DtEditorWidget editor = (DtEditorWidget) widget;
  6638. DtEditorErrorCode error;
  6639. int leftMargin, rightMargin, alignment;
  6640. _DtWidgetToAppContext(widget);
  6641. _DtAppLock(app);
  6642. /*
  6643. * Check to see if we should use the format settings from the
  6644. * Format Settings dialog.
  6645. */
  6646. if( formatSettings == (DtEditorFormatSettings *) NULL )
  6647. {
  6648. DtEditorFormatSettings tmpFormatSettings;
  6649. /*
  6650. * Get the format settings from the Format Settings dialog
  6651. */
  6652. GetAdjustSettings(editor, &tmpFormatSettings);
  6653. /*
  6654. * Set up the correct format settings
  6655. */
  6656. leftMargin = tmpFormatSettings.leftMargin;
  6657. rightMargin = tmpFormatSettings.rightMargin;
  6658. alignment = tmpFormatSettings.alignment;
  6659. }
  6660. else {
  6661. leftMargin = formatSettings->leftMargin;
  6662. rightMargin = formatSettings->rightMargin;
  6663. alignment = formatSettings->alignment;
  6664. }
  6665. /*
  6666. * Now, do the formatting
  6667. */
  6668. switch (amountToFormat)
  6669. {
  6670. case DtEDITOR_FORMAT_ALL:
  6671. {
  6672. error = DoAdjust( editor, leftMargin, rightMargin, alignment,
  6673. 0, XmTextGetLastPosition(M_text(editor)) );
  6674. break;
  6675. }
  6676. case DtEDITOR_FORMAT_PARAGRAPH:
  6677. {
  6678. XmTextPosition start, end;
  6679. char *params=(char *)NULL;
  6680. Cardinal num_params = 0;
  6681. /*
  6682. * Create an event with a correct timestamp
  6683. */
  6684. XEvent event;
  6685. event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
  6686. /*
  6687. * Get the beginning & ending positions of the current paragraph
  6688. */
  6689. ForwardPara( widget, &event, &params, &num_params );
  6690. end = XmTextGetInsertionPosition(M_text(editor));
  6691. if( end != XmTextGetLastPosition(M_text(editor)) ) {
  6692. /*
  6693. * If we're not at the end, then we need to back up to the
  6694. * start of this line, otherwise we'll disturb the first line
  6695. * of the following paragraph. If we are at the end, then "end"
  6696. * must point to the end of the line, or we'll leave the last
  6697. * line along with the formatted text.
  6698. */
  6699. BeginningOfLine( widget, &event, &params, &num_params );
  6700. end = XmTextGetInsertionPosition(M_text(editor));
  6701. }
  6702. BackwardPara( widget, &event, &params, &num_params );
  6703. BeginningOfLine( widget, &event, &params, &num_params );
  6704. start = XmTextGetInsertionPosition(M_text(editor));
  6705. /*
  6706. * Pass in beginning & ending positions to adjust the current
  6707. * paragraph
  6708. */
  6709. error = DoAdjust( editor, leftMargin, rightMargin, alignment,
  6710. start, end );
  6711. break;
  6712. }
  6713. default: {
  6714. error = DtEDITOR_INVALID_RANGE;
  6715. }
  6716. } /* end switch */
  6717. _DtAppUnlock(app);
  6718. return( error );
  6719. } /* DtEditorFormat */
  6720. /*
  6721. *
  6722. * DtEditorGetMessageTextFieldID - Returns the widget ID of the Text
  6723. * Field used to display application status messages.
  6724. *
  6725. */
  6726. Widget
  6727. DtEditorGetMessageTextFieldID(
  6728. Widget widget)
  6729. {
  6730. DtEditorWidget editor = (DtEditorWidget) widget;
  6731. Widget result;
  6732. _DtWidgetToAppContext(widget);
  6733. _DtAppLock(app);
  6734. /*
  6735. * Create the status line if is does not exist
  6736. */
  6737. if( M_status_statusArea(editor) == (Widget) NULL )
  6738. M_status_statusArea(editor) = CreateStatusLine( editor );
  6739. result = M_status_messageText(editor);
  6740. _DtAppUnlock(app);
  6741. return result;
  6742. } /* end DtEditorGetMessageTextFieldID */
  6743. /*
  6744. * DtEditorGoToLine moves the insert cursor to the beginning of the
  6745. * line specified by lineNumber. It figures out the text character
  6746. * position corresponding to the specified line and sets the text
  6747. * widget's insertionPosition to that location. If this new
  6748. * insertionPosition is not currently on-screen, then the
  6749. * text widget's contents are scrolled to display the new position.
  6750. *
  6751. * The cursor can be moved to last line by specifying DtEDITOR_LAST_LINE
  6752. * as the line number.
  6753. * If lineNumber is less than one, the insert cursor will be placed
  6754. * at the beginning of the first line. If it is greater than the total
  6755. * number of lines, the cursor will be placed at the last line of text.
  6756. */
  6757. /* ARGSUSED */
  6758. void DtEditorGoToLine(
  6759. Widget widget,
  6760. int lineNumber)
  6761. {
  6762. DtEditorWidget editor = (DtEditorWidget)widget;
  6763. XmTextWidget tw;
  6764. XmTextLineTable lineTab;
  6765. XmTextPosition newPos;
  6766. _DtWidgetToAppContext(widget);
  6767. _DtAppLock(app);
  6768. tw = (XmTextWidget)M_text(editor);
  6769. lineTab = tw->text.line_table;
  6770. /*
  6771. * Validate the specified line number, check it is in range.
  6772. * If we adjust the line number, then update the current line display
  6773. * in the status line so it reflects where we are really going. This
  6774. * is only a problem if lineNumber is less/greater than the first/last
  6775. * line becausee we won't be moving the cursor so the status line will
  6776. * not be updated.
  6777. */
  6778. if (lineNumber > tw->text.total_lines || lineNumber == DtEDITOR_LAST_LINE)
  6779. {
  6780. lineNumber = tw->text.total_lines;
  6781. _DtEditorUpdateLineDisplay( editor, lineNumber, FORCE );
  6782. }
  6783. else if(lineNumber < 1)
  6784. {
  6785. lineNumber = 1;
  6786. _DtEditorUpdateLineDisplay( editor, lineNumber, FORCE );
  6787. }
  6788. /*
  6789. * Move the insertion cursor
  6790. */
  6791. newPos = lineTab[lineNumber - 1].start_pos;
  6792. XmTextSetInsertionPosition(M_text(editor), newPos);
  6793. /*
  6794. * Scroll the widget, if necessary
  6795. */
  6796. if (newPos < tw->text.top_character || newPos >= tw->text.bottom_position)
  6797. {
  6798. Arg al[5];
  6799. int ac;
  6800. Dimension height;
  6801. short rows;
  6802. Position x, y;
  6803. ac = 0;
  6804. XtSetArg(al[ac], XmNheight, &height); ac++;
  6805. XtSetArg(al[ac], XmNrows, &rows); ac++;
  6806. XtGetValues(M_text(editor), al, ac);
  6807. if(XmTextPosToXY(M_text(editor), newPos, &x, &y) == True)
  6808. {
  6809. int offset = (y - height/2) * rows;
  6810. XmTextScroll(M_text(editor), offset/(int) height);
  6811. }
  6812. }
  6813. _DtAppUnlock(app);
  6814. } /* end DtEditorGoToLine */
  6815. /*
  6816. * DtEditorGetEditorSizeHints - Set the resize increment, minimum window
  6817. * size, and base dimension properties in the supplied XSizeHints
  6818. * struct for the editor as a whole.
  6819. *
  6820. * NOTE: This routine returns data in the struct pointed to by pHints.
  6821. *
  6822. */
  6823. void
  6824. DtEditorGetSizeHints(
  6825. Widget widget,
  6826. XSizeHints *pHints) /* Return */
  6827. {
  6828. Arg al[10]; /* arg list */
  6829. register int ac; /* arg count */
  6830. Dimension FormWidth, FormHeight,
  6831. Twidth, Theight, statusHeight,
  6832. highlightThickness, shadowThickness,
  6833. marginWidth, marginHeight,
  6834. textRegionWidth, textRegionHeight;
  6835. DtEditorWidget editor = (DtEditorWidget) widget;
  6836. _DtWidgetToAppContext(widget);
  6837. _DtAppLock(app);
  6838. /*
  6839. * Window manager should resize in increments of a character or line.
  6840. */
  6841. pHints->width_inc = M_fontWidth(editor);
  6842. pHints->height_inc = M_fontHeight(editor);
  6843. /*
  6844. * Size of the Editor (Form)
  6845. */
  6846. FormWidth = editor->core.width + (2 * editor->core.border_width);
  6847. FormHeight = editor->core.height + (2 * editor->core.border_width);
  6848. /*
  6849. * Size of the Edit window (text widget)
  6850. */
  6851. ac=0;
  6852. XtSetArg(al[ac], XmNwidth, &Twidth); ac++;
  6853. XtSetArg(al[ac], XmNheight, &Theight); ac++;
  6854. XtSetArg(al[ac], XmNhighlightThickness, &highlightThickness); ac++;
  6855. XtSetArg(al[ac], XmNshadowThickness, &shadowThickness); ac++;
  6856. XtSetArg(al[ac], XmNmarginWidth, &marginWidth); ac++;
  6857. XtSetArg(al[ac], XmNmarginHeight, &marginHeight); ac++;
  6858. XtGetValues(M_text(editor), al, ac);
  6859. /*
  6860. * Calculate the width & height of the area within the text widget
  6861. * which can actually display characters.
  6862. */
  6863. textRegionWidth = (int)Twidth -
  6864. (2 * ((int)highlightThickness +
  6865. (int)shadowThickness + (int)marginWidth));
  6866. textRegionHeight = (int)Theight -
  6867. (2 * ((int)highlightThickness +
  6868. (int)shadowThickness + (int)marginHeight));
  6869. /*
  6870. * Set the base width/height to the size of the area which will not
  6871. * display characters.
  6872. *
  6873. * The base width/height is used by the window manager in concert
  6874. * with the height & width increments to display the current size
  6875. * (rows & columns) of edit window (text widget) while resizing the
  6876. * editor.
  6877. */
  6878. pHints->base_width = FormWidth - textRegionWidth;
  6879. pHints->base_height = FormHeight - textRegionHeight;
  6880. /*
  6881. * Get the height of the status line, if it is turned on.
  6882. * Remember, the border width is not included in the height of the
  6883. * status line so add it in to account for the border between the
  6884. * edit window (text widget) and the status line.
  6885. */
  6886. /* XXX Actually, the statusHeight should already be included in the
  6887. * FormHeight, so it should not be necessary to add it in again.
  6888. * However, the numbers don't come out right otherwise. Hmmm? */
  6889. if( M_status_showStatusLine(editor) == True )
  6890. {
  6891. XtSetArg( al[0], XmNheight, &statusHeight );
  6892. XtGetValues( M_status_statusArea(editor), al, 1 );
  6893. statusHeight = statusHeight + editor->core.border_width;
  6894. }
  6895. else
  6896. statusHeight = 0;
  6897. /*
  6898. * What is being returned here is the minimum width & height of the
  6899. * editor. Leave room for the scrollbars, shadows, etc., plus one
  6900. * character.
  6901. */
  6902. pHints->min_width = pHints->base_width + pHints->width_inc;
  6903. pHints->min_height = pHints->base_width + pHints->height_inc +
  6904. statusHeight;
  6905. pHints->flags = PMinSize | PResizeInc | PBaseSize;
  6906. _DtAppUnlock(app);
  6907. } /* end DtEditorGetSizeHints */
  6908. void
  6909. DtEditorInvokeFormatDialog(
  6910. Widget widget)
  6911. {
  6912. DtEditorWidget editor = (DtEditorWidget) widget;
  6913. _DtWidgetToAppContext(widget);
  6914. _DtAppLock(app);
  6915. /*
  6916. * Create the dialog if it is the first time
  6917. */
  6918. if (M_format_dialog(editor) == (Widget)NULL)
  6919. CreateFormatDialog( editor );
  6920. /*
  6921. * Post the dialog
  6922. */
  6923. XtUnmanageChild (M_format_dialog(editor));
  6924. XtManageChild (M_format_dialog(editor));
  6925. XmProcessTraversal(M_format_paragraph(editor), XmTRAVERSE_CURRENT);
  6926. _DtAppUnlock(app);
  6927. } /* DtEditorInvokeFormatDialog */
  6928. void
  6929. DtEditorReset(
  6930. Widget widget)
  6931. {
  6932. DtEditorContentRec cr;
  6933. DtEditorWidget editor = (DtEditorWidget) widget;
  6934. _DtWidgetToAppContext(widget);
  6935. _DtAppLock(app);
  6936. /*
  6937. * Reset the edit window (includes the Undo context)
  6938. */
  6939. cr.type = DtEDITOR_TEXT;
  6940. cr.value.string = "";
  6941. DtEditorSetContents( widget, &cr );
  6942. /*
  6943. * Reset the status line
  6944. * Note, the current & total line displays are reset by DtEditorSetContents()
  6945. */
  6946. if( M_status_statusArea(editor) != (Widget) NULL ) {
  6947. XmTextFieldSetString( M_status_messageText(editor), "" );
  6948. }
  6949. /*
  6950. * Reset the Find/Change & Spell dialogs
  6951. */
  6952. if ( M_search_string(editor) )
  6953. XtFree(M_search_string(editor));
  6954. M_search_string(editor) = (char *)NULL;
  6955. if ( M_replace_string(editor) )
  6956. XtFree(M_replace_string(editor));
  6957. M_replace_string(editor) = (char *)NULL;
  6958. if (M_misspelled_string(editor))
  6959. XtFree(M_misspelled_string(editor));
  6960. M_misspelled_string(editor) = (char *)NULL;
  6961. /*
  6962. * Reset the Format Settings dialog
  6963. */
  6964. if (M_format_dialog(editor) != (Widget)NULL)
  6965. ResetFormatDialog(editor);
  6966. _DtAppUnlock(app);
  6967. } /* end DtEditorReset */
  6968. /*
  6969. *
  6970. * DtEditorSelectAll - Selects the contents of an Editor widget
  6971. *
  6972. */
  6973. Boolean
  6974. DtEditorSelectAll(
  6975. Widget widget)
  6976. {
  6977. DtEditorWidget editor = (DtEditorWidget) widget;
  6978. char *params=(char *)NULL;
  6979. Cardinal num_params = 0;
  6980. XEvent event;
  6981. _DtWidgetToAppContext(widget);
  6982. _DtAppLock(app);
  6983. /*
  6984. * Create an event with a correct timestamp
  6985. */
  6986. event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
  6987. SelectAll( widget, &event, &params, &num_params );
  6988. _DtAppUnlock(app);
  6989. return(True);
  6990. } /* end DtEditorSelectAll */
  6991. void
  6992. DtEditorTraverseToEditor(
  6993. Widget widget)
  6994. {
  6995. DtEditorWidget editor = (DtEditorWidget) widget;
  6996. _DtWidgetToAppContext(widget);
  6997. _DtAppLock(app);
  6998. XmProcessTraversal(M_text(editor), XmTRAVERSE_CURRENT);
  6999. _DtAppUnlock(app);
  7000. } /* end DtEditorTraverseToEditor */